(
body: T
)
| 262 | |
| 263 | // Atomic create-or-noop using a single-op batch — returns true if created. |
| 264 | const createIfMissing = <T extends { readonly id: string; readonly _partitionKey: string }>( |
| 265 | body: T |
| 266 | ): Effect.Effect<boolean> => |
| 267 | Effect.gen(function*() { |
| 268 | const resp = yield* Effect.promise(() => |
| 269 | container.items.batch( |
| 270 | [{ operationType: "Create" as const, resourceBody: body }], |
| 271 | body._partitionKey |
| 272 | ) |
| 273 | ) |
| 274 | const r = resp.result?.[0] |
| 275 | const code = r?.statusCode ?? 0 |
| 276 | if (code === 201) return true |
| 277 | if (code === 409) return false |
| 278 | return yield* Effect.die( |
| 279 | new Error(`workflow-engine cosmos createIfMissing for ${body.id} failed: ${code}`) |
| 280 | ) |
| 281 | }) |
| 282 | |
| 283 | // Last-writer-wins upsert — used to overwrite a persisted *suspended* activity |
| 284 | // result once it finally completes (create-only ops can't transition it). |
no outgoing calls
no test coverage detected
searching dependent graphs…