(items: NonEmptyReadonlyArray<PM>, ns: string)
| 191 | yield* cached |
| 192 | }) |
| 193 | const bulkSetInternal = (items: NonEmptyReadonlyArray<PM>, ns: string) => |
| 194 | Effect |
| 195 | .gen(function*() { |
| 196 | // TODO: disable batching if need atomicity |
| 197 | // we delay and batch to keep low amount of RUs |
| 198 | const b = [...items] |
| 199 | .map( |
| 200 | (x) => |
| 201 | [ |
| 202 | x, |
| 203 | Option.match(Option.fromNullishOr(x._etag), { |
| 204 | onNone: () => |
| 205 | dropUndefinedT({ |
| 206 | operationType: "Create" as const, |
| 207 | resourceBody: { |
| 208 | ...Struct.omit(x, ["_etag", idKey]), |
| 209 | id: x[idKey], |
| 210 | _partitionKey: nsPartitionValue(ns, x) |
| 211 | } |
| 212 | // don't use this or we get an error that the request and some item partition key dont match - makese no sense |
| 213 | // partitionKey: config?.partitionValue(x) |
| 214 | }), |
| 215 | onSome: (eTag) => |
| 216 | dropUndefinedT({ |
| 217 | operationType: "Replace" as const, |
| 218 | id: x[idKey], |
| 219 | resourceBody: { |
| 220 | ...Struct.omit(x, ["_etag", idKey]), |
| 221 | id: x[idKey], |
| 222 | _partitionKey: nsPartitionValue(ns, x) |
| 223 | }, |
| 224 | ifMatch: eTag |
| 225 | // don't use this or we get an error that the request and some item partition key dont match - makese no sense |
| 226 | // partitionKey: config?.partitionValue(x) |
| 227 | }) |
| 228 | }) |
| 229 | ] as const |
| 230 | ) |
| 231 | const batches = Array.chunksOf(b, config?.maxBulkSize ?? 10) |
| 232 | |
| 233 | const batchResult = yield* Effect.forEach( |
| 234 | batches |
| 235 | .map((x, i) => [i, x] as const), |
| 236 | ([i, batch]) => |
| 237 | tryCosmos(() => bulk(batch.map(([, op]) => op))) |
| 238 | .pipe( |
| 239 | Effect |
| 240 | .delay(Duration.millis(i === 0 ? 0 : 150)), |
| 241 | Effect |
| 242 | .flatMap((responses) => |
| 243 | Effect.gen(function*() { |
| 244 | const r = responses.find((x) => |
| 245 | x.statusCode === 412 || x.statusCode === 404 || x.statusCode === 409 |
| 246 | ) |
| 247 | if (r) { |
| 248 | return yield* Effect.fail( |
| 249 | new OptimisticConcurrencyException( |
| 250 | { |
no test coverage detected
searching dependent graphs…