MCPcopy Create free account
hub / github.com/effect-app/libs / batchDocs

Function batchDocs

packages/infra/src/ClusterCosmos.ts:430–456  ·  view source on GitHub ↗
(
    docs: ReadonlyArray<A>,
    operation: (doc: A) => OperationInput,
    fallback: (doc: A) => Effect.Effect<void, unknown, never>
  )

Source from the content-addressed store, hash-verified

428 )
429
430 const batchDocs = <A extends { readonly id: string; readonly _partitionKey: string }>(
431 docs: ReadonlyArray<A>,
432 operation: (doc: A) => OperationInput,
433 fallback: (doc: A) => Effect.Effect<void, unknown, never>
434 ): Effect.Effect<void, unknown, never> =>
435 Effect.forEach(
436 Arr.groupByT(docs, (doc) => doc._partitionKey),
437 ([partitionKey, partitionDocs]) =>
438 Effect.forEach(
439 Arr.chunksOf(partitionDocs, maxCosmosBatchOperations),
440 (chunk) => {
441 const operations: Array<OperationInput> = chunk.map(operation)
442 return Effect
443 .tryPromise(() => container.items.batch(operations, partitionKey))
444 .pipe(
445 Effect.tap(annotateItem),
446 Effect.flatMap((resp) => {
447 const failed = resp.result?.find((result) => !isSuccessfulStatus(result.statusCode))
448 return failed === undefined ? Effect.void : Effect.fail(failed.statusCode)
449 }),
450 Effect.catchIf(() => true, () => Effect.forEach(chunk, fallback, { discard: true }))
451 )
452 },
453 { discard: true }
454 ),
455 { discard: true }
456 )
457
458 const patchDoc = <A extends { readonly id: string; readonly _partitionKey: string }>(
459 doc: A,

Callers 2

patchDocsFunction · 0.85
deleteDocsFunction · 0.85

Calls 5

isSuccessfulStatusFunction · 0.85
forEachMethod · 0.65
mapMethod · 0.65
pipeMethod · 0.65
failMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…