@sixb/core 0.1.9 → 0.1.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/actions/index.js +8 -8
- package/dist/agents/index.js +16 -15
- package/dist/agents/index.js.map +1 -1
- package/dist/bootstrap/index.js +20 -19
- package/dist/bootstrap/index.js.map +1 -1
- package/dist/broker/in-memory.d.ts +8 -2
- package/dist/broker/in-memory.d.ts.map +1 -1
- package/dist/broker/index.d.ts +4 -2
- package/dist/broker/index.d.ts.map +1 -1
- package/dist/broker/index.js +7 -3
- package/dist/broker/index.js.map +1 -1
- package/dist/broker/retention.d.ts +4 -0
- package/dist/broker/retention.d.ts.map +1 -0
- package/dist/broker/subscriber.d.ts +10 -0
- package/dist/broker/subscriber.d.ts.map +1 -0
- package/dist/broker/types.d.ts +14 -1
- package/dist/broker/types.d.ts.map +1 -1
- package/dist/{chunk-k3cqkkn2.js → chunk-1824gssz.js} +30 -65
- package/dist/chunk-1824gssz.js.map +12 -0
- package/dist/{chunk-h1gfhhbh.js → chunk-28ja2cjs.js} +1 -1
- package/dist/chunk-2c4j899j.js.map +1 -1
- package/dist/{chunk-ppytyr6w.js → chunk-358caqf5.js} +4 -4
- package/dist/chunk-358caqf5.js.map +12 -0
- package/dist/{chunk-kxwa347f.js → chunk-3qms4nax.js} +2 -2
- package/dist/{chunk-kxwa347f.js.map → chunk-3qms4nax.js.map} +3 -3
- package/dist/{chunk-emyyk7dx.js → chunk-5c7ga8zz.js} +22 -145
- package/dist/chunk-5c7ga8zz.js.map +12 -0
- package/dist/{chunk-hpr1r6av.js → chunk-5p1v802y.js} +46 -39
- package/dist/{chunk-hpr1r6av.js.map → chunk-5p1v802y.js.map} +4 -4
- package/dist/{chunk-zcnq6105.js → chunk-85cd7e8c.js} +2 -1
- package/dist/chunk-85cd7e8c.js.map +10 -0
- package/dist/{chunk-1enhpacz.js → chunk-976rxdpx.js} +5 -5
- package/dist/{chunk-3f7veca0.js → chunk-9x8dybsb.js} +3 -3
- package/dist/chunk-9x8dybsb.js.map +10 -0
- package/dist/{chunk-r29fxdhn.js → chunk-aa6z4a19.js} +160 -44
- package/dist/chunk-aa6z4a19.js.map +12 -0
- package/dist/{chunk-r4tfx1sf.js → chunk-agbbygvh.js} +4 -4
- package/dist/{chunk-jjy0fhrn.js → chunk-b0ec55a1.js} +20 -3
- package/dist/chunk-b0ec55a1.js.map +12 -0
- package/dist/{chunk-xfbydgzy.js → chunk-bn138h9w.js} +7 -8
- package/dist/{chunk-xfbydgzy.js.map → chunk-bn138h9w.js.map} +3 -3
- package/dist/{chunk-an5tt9y0.js → chunk-ftv470j8.js} +42 -4
- package/dist/{chunk-an5tt9y0.js.map → chunk-ftv470j8.js.map} +7 -7
- package/dist/{chunk-0w35wavj.js → chunk-g7knyczr.js} +1 -1
- package/dist/{chunk-x57ycxq0.js → chunk-gqh45d2n.js} +42 -3
- package/dist/{chunk-x57ycxq0.js.map → chunk-gqh45d2n.js.map} +3 -3
- package/dist/{chunk-0rdrecsb.js → chunk-kfee1h52.js} +116 -32
- package/dist/chunk-kfee1h52.js.map +13 -0
- package/dist/{chunk-ypbtykv6.js → chunk-nmbxcaqx.js} +1 -1
- package/dist/{chunk-3tgwrcyh.js → chunk-nt99sxd6.js} +2 -2
- package/dist/{chunk-3tgwrcyh.js.map → chunk-nt99sxd6.js.map} +3 -3
- package/dist/{chunk-vf691g1r.js → chunk-p5vcsw9c.js} +2 -2
- package/dist/{chunk-mjbk2djy.js → chunk-p6a4npdx.js} +211 -106
- package/dist/{chunk-mjbk2djy.js.map → chunk-p6a4npdx.js.map} +9 -8
- package/dist/{chunk-3frsnm7x.js → chunk-qma80ych.js} +4 -6
- package/dist/chunk-qma80ych.js.map +11 -0
- package/dist/{chunk-qhcpj9wc.js → chunk-qyeptdyv.js} +96 -2
- package/dist/chunk-qyeptdyv.js.map +15 -0
- package/dist/{chunk-52hbv0ak.js → chunk-r7fj830t.js} +101 -48
- package/dist/chunk-r7fj830t.js.map +36 -0
- package/dist/{chunk-xyr8kppc.js → chunk-rtk71jzp.js} +1 -1
- package/dist/{chunk-m3z3x9v0.js → chunk-t1f4f1ve.js} +1 -1
- package/dist/chunk-v2vcg0w6.js +151 -0
- package/dist/chunk-v2vcg0w6.js.map +11 -0
- package/dist/connectors/connections/authorizations.d.ts.map +1 -1
- package/dist/connectors/connections/contracts.d.ts +3 -0
- package/dist/connectors/connections/contracts.d.ts.map +1 -1
- package/dist/connectors/connections/internal.js +1 -1
- package/dist/connectors/connections/request.d.ts +3 -1
- package/dist/connectors/connections/request.d.ts.map +1 -1
- package/dist/connectors/connections/runs.d.ts.map +1 -1
- package/dist/connectors/connections/tokens.d.ts.map +1 -1
- package/dist/connectors/connections/validation.d.ts +5 -1
- package/dist/connectors/connections/validation.d.ts.map +1 -1
- package/dist/connectors/types.d.ts +19 -4
- package/dist/connectors/types.d.ts.map +1 -1
- package/dist/events/execution.d.ts +1 -1
- package/dist/events/execution.d.ts.map +1 -1
- package/dist/events/index.js +1 -1
- package/dist/events/service.d.ts +2 -2
- package/dist/events/service.d.ts.map +1 -1
- package/dist/execution/agent.js +16 -15
- package/dist/execution/agent.js.map +1 -1
- package/dist/execution/primitive.js +16 -15
- package/dist/execution/primitive.js.map +2 -2
- package/dist/execution/request.js +16 -15
- package/dist/execution/request.js.map +2 -2
- package/dist/index.d.ts +3 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +30 -28
- package/dist/index.js.map +1 -1
- package/dist/lake-storage/changes.d.ts +5 -0
- package/dist/lake-storage/changes.d.ts.map +1 -0
- package/dist/lake-storage/in-memory.d.ts +2 -1
- package/dist/lake-storage/in-memory.d.ts.map +1 -1
- package/dist/lake-storage/index.d.ts +2 -1
- package/dist/lake-storage/index.d.ts.map +1 -1
- package/dist/lake-storage/index.js +4 -2
- package/dist/lake-storage/index.js.map +1 -1
- package/dist/lake-storage/types.d.ts +36 -0
- package/dist/lake-storage/types.d.ts.map +1 -1
- package/dist/logging/internal.js +1 -1
- package/dist/materialization/index.d.ts +1 -1
- package/dist/materialization/index.d.ts.map +1 -1
- package/dist/materialization/model.d.ts +12 -1
- package/dist/materialization/model.d.ts.map +1 -1
- package/dist/materializer/index.d.ts +1 -1
- package/dist/materializer/index.d.ts.map +1 -1
- package/dist/materializer/index.js +5 -5
- package/dist/materializer/materializer.d.ts +5 -1
- package/dist/materializer/materializer.d.ts.map +1 -1
- package/dist/materializer/projections/entry-validator.d.ts +2 -1
- package/dist/materializer/projections/entry-validator.d.ts.map +1 -1
- package/dist/materializer/projections/replace.d.ts.map +1 -1
- package/dist/materializer/projections/source-materialization.d.ts +4 -3
- package/dist/materializer/projections/source-materialization.d.ts.map +1 -1
- package/dist/materializer/shared/normalize.d.ts +2 -1
- package/dist/materializer/shared/normalize.d.ts.map +1 -1
- package/dist/models/execution/index.js +5 -5
- package/dist/objects/index.js +9 -9
- package/dist/objects/query/index.js +5 -5
- package/dist/pipelines/index.js +6 -6
- package/dist/pipelines/run-dispatch.d.ts.map +1 -1
- package/dist/projections/internal.js +6 -8
- package/dist/projections/internal.js.map +1 -1
- package/dist/projections/run-dispatch.d.ts.map +1 -1
- package/dist/queues/in-memory.d.ts +7 -3
- package/dist/queues/in-memory.d.ts.map +1 -1
- package/dist/queues/index.js +1 -1
- package/dist/queues/indexed-heap.d.ts +15 -0
- package/dist/queues/indexed-heap.d.ts.map +1 -0
- package/dist/runtime/host.d.ts.map +1 -1
- package/dist/runtime/internal.js +1 -1
- package/dist/runtime/ontology-mutations.d.ts +3 -1
- package/dist/runtime/ontology-mutations.d.ts.map +1 -1
- package/dist/shares/internal.js +4 -4
- package/dist/storage/connector-connections/in-memory.d.ts.map +1 -1
- package/dist/storage/connector-connections/provider/runs.d.ts.map +1 -1
- package/dist/storage/connector-connections/provider.js +2 -2
- package/dist/storage/connector-connections/provider.js.map +3 -3
- package/dist/storage/connector-connections/types.d.ts +3 -2
- package/dist/storage/connector-connections/types.d.ts.map +1 -1
- package/dist/storage/index.d.ts +1 -1
- package/dist/storage/index.d.ts.map +1 -1
- package/dist/storage/index.js +4 -4
- package/dist/storage/internal.js +1 -1
- package/dist/storage/ontology/in-memory/materializations-state.d.ts.map +1 -1
- package/dist/storage/ontology/in-memory/materializations.d.ts +1 -1
- package/dist/storage/ontology/in-memory/materializations.d.ts.map +1 -1
- package/dist/storage/ontology/in-memory/shared-state.d.ts +15 -2
- package/dist/storage/ontology/in-memory/shared-state.d.ts.map +1 -1
- package/dist/storage/ontology/in-memory/source-roots.d.ts +6 -0
- package/dist/storage/ontology/in-memory/source-roots.d.ts.map +1 -0
- package/dist/storage/ontology/in-memory/sources.d.ts.map +1 -1
- package/dist/storage/ontology/index.d.ts +1 -1
- package/dist/storage/ontology/index.d.ts.map +1 -1
- package/dist/storage/ontology/provider.d.ts +16 -0
- package/dist/storage/ontology/provider.d.ts.map +1 -1
- package/dist/storage/ontology/provider.js +4 -2
- package/dist/storage/ontology/provider.js.map +1 -1
- package/dist/storage/ontology/sources.d.ts +13 -4
- package/dist/storage/ontology/sources.d.ts.map +1 -1
- package/dist/storage/projection-runs/lifecycle.d.ts.map +1 -1
- package/dist/storage/projection-runs/provider.js +2 -2
- package/dist/storage/projection-runs/types.d.ts +2 -0
- package/dist/storage/projection-runs/types.d.ts.map +1 -1
- package/dist/syncs/index.js +8 -7
- package/dist/syncs/index.js.map +1 -1
- package/dist/syncs/run-dispatch.d.ts.map +1 -1
- package/dist/testing/broker-contract.d.ts.map +1 -1
- package/dist/testing/connector-connection-storage-contract.d.ts.map +1 -1
- package/dist/testing/index.d.ts +1 -0
- package/dist/testing/index.d.ts.map +1 -1
- package/dist/testing/index.js +1459 -951
- package/dist/testing/index.js.map +9 -8
- package/dist/testing/lake-changes-contract.d.ts +6 -0
- package/dist/testing/lake-changes-contract.d.ts.map +1 -0
- package/dist/testing/materializer-storage-contract.d.ts.map +1 -1
- package/dist/testing/ontology-storage-contract.d.ts.map +1 -1
- package/dist/testing/projection-run-storage-contract.d.ts.map +1 -1
- package/dist/webhooks/connections.d.ts +6 -0
- package/dist/webhooks/connections.d.ts.map +1 -0
- package/dist/webhooks/index.d.ts +1 -1
- package/dist/webhooks/index.d.ts.map +1 -1
- package/dist/webhooks/internal.d.ts +2 -0
- package/dist/webhooks/internal.d.ts.map +1 -1
- package/dist/webhooks/internal.js +54 -9
- package/dist/webhooks/internal.js.map +4 -3
- package/dist/webhooks/registry.d.ts +1 -1
- package/dist/webhooks/registry.d.ts.map +1 -1
- package/dist/webhooks/types.d.ts +15 -4
- package/dist/webhooks/types.d.ts.map +1 -1
- package/dist/workflows/index.js +17 -16
- package/dist/workflows/index.js.map +1 -1
- package/dist/workflows/run-dispatch.d.ts +3 -1
- package/dist/workflows/run-dispatch.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/broker/in-memory.ts +104 -39
- package/src/broker/index.ts +4 -1
- package/src/broker/retention.ts +28 -0
- package/src/broker/subscriber.ts +21 -0
- package/src/broker/types.ts +15 -1
- package/src/connectors/builders.ts +0 -6
- package/src/connectors/connections/authorizations.ts +11 -5
- package/src/connectors/connections/contracts.ts +3 -0
- package/src/connectors/connections/request.ts +56 -22
- package/src/connectors/connections/runs.ts +1 -0
- package/src/connectors/connections/tokens.ts +4 -0
- package/src/connectors/connections/validation.ts +91 -5
- package/src/connectors/types.ts +19 -4
- package/src/events/execution.ts +2 -2
- package/src/events/service.ts +3 -3
- package/src/index.ts +10 -2
- package/src/lake-storage/changes.ts +43 -0
- package/src/lake-storage/in-memory.ts +73 -0
- package/src/lake-storage/index.ts +4 -0
- package/src/lake-storage/types.ts +40 -0
- package/src/logging/service.ts +1 -1
- package/src/materialization/index.ts +2 -0
- package/src/materialization/model.ts +14 -1
- package/src/materializer/index.ts +2 -0
- package/src/materializer/materializer.ts +10 -0
- package/src/materializer/projections/entry-validator.ts +19 -1
- package/src/materializer/projections/replace.ts +36 -1
- package/src/materializer/projections/source-materialization.ts +26 -6
- package/src/materializer/shared/normalize.ts +1 -1
- package/src/pipelines/run-dispatch.ts +21 -1
- package/src/projections/run-dispatch.ts +30 -68
- package/src/queues/in-memory.ts +105 -62
- package/src/queues/indexed-heap.ts +74 -0
- package/src/runtime/host.ts +0 -14
- package/src/runtime/ontology-mutations.ts +4 -0
- package/src/storage/connector-connections/in-memory.ts +3 -1
- package/src/storage/connector-connections/provider/runs.ts +3 -1
- package/src/storage/connector-connections/types.ts +3 -2
- package/src/storage/index.ts +1 -0
- package/src/storage/ontology/in-memory/materializations-state.ts +5 -18
- package/src/storage/ontology/in-memory/materializations.ts +73 -92
- package/src/storage/ontology/in-memory/shared-state.ts +26 -1
- package/src/storage/ontology/in-memory/source-roots.ts +123 -0
- package/src/storage/ontology/in-memory/sources.ts +78 -23
- package/src/storage/ontology/index.ts +1 -0
- package/src/storage/ontology/provider.ts +70 -0
- package/src/storage/ontology/sources.ts +14 -3
- package/src/storage/projection-runs/lifecycle.ts +5 -2
- package/src/storage/projection-runs/types.ts +4 -3
- package/src/syncs/run-dispatch.ts +19 -1
- package/src/testing/broker-contract.ts +95 -0
- package/src/testing/connector-connection-storage-contract.ts +18 -1
- package/src/testing/index.ts +1 -0
- package/src/testing/lake-changes-contract.ts +240 -0
- package/src/testing/materializer-storage-contract.ts +172 -1
- package/src/testing/ontology-storage-contract.ts +7 -0
- package/src/testing/projection-run-storage-contract.ts +34 -0
- package/src/webhooks/connections.ts +56 -0
- package/src/webhooks/index.ts +2 -0
- package/src/webhooks/internal.ts +2 -0
- package/src/webhooks/registry.ts +3 -4
- package/src/webhooks/types.ts +17 -4
- package/src/workflows/run-dispatch.ts +42 -29
- package/dist/chunk-0rdrecsb.js.map +0 -11
- package/dist/chunk-3f7veca0.js.map +0 -10
- package/dist/chunk-3frsnm7x.js.map +0 -11
- package/dist/chunk-52hbv0ak.js.map +0 -36
- package/dist/chunk-emyyk7dx.js.map +0 -14
- package/dist/chunk-jjy0fhrn.js.map +0 -12
- package/dist/chunk-k3cqkkn2.js.map +0 -12
- package/dist/chunk-ppytyr6w.js.map +0 -12
- package/dist/chunk-qhcpj9wc.js.map +0 -14
- package/dist/chunk-r29fxdhn.js.map +0 -11
- package/dist/chunk-zcnq6105.js.map +0 -10
- /package/dist/{chunk-h1gfhhbh.js.map → chunk-28ja2cjs.js.map} +0 -0
- /package/dist/{chunk-1enhpacz.js.map → chunk-976rxdpx.js.map} +0 -0
- /package/dist/{chunk-r4tfx1sf.js.map → chunk-agbbygvh.js.map} +0 -0
- /package/dist/{chunk-0w35wavj.js.map → chunk-g7knyczr.js.map} +0 -0
- /package/dist/{chunk-ypbtykv6.js.map → chunk-nmbxcaqx.js.map} +0 -0
- /package/dist/{chunk-vf691g1r.js.map → chunk-p5vcsw9c.js.map} +0 -0
- /package/dist/{chunk-xyr8kppc.js.map → chunk-rtk71jzp.js.map} +0 -0
- /package/dist/{chunk-m3z3x9v0.js.map → chunk-t1f4f1ve.js.map} +0 -0
|
@@ -57,6 +57,8 @@ interface DispatchWorkflowRunInput {
|
|
|
57
57
|
readonly source?: WorkflowRunSource
|
|
58
58
|
readonly metadata?: Readonly<Record<string, string>>
|
|
59
59
|
readonly queueJobId?: string
|
|
60
|
+
/** Automatic callers own publication retries; validate provenance before any replay effect. */
|
|
61
|
+
readonly validateExistingRun?: (run: WorkflowRunRecord) => Promise<void>
|
|
60
62
|
readonly createExecution: (executionId: string, runId: string) => Promise<CreateExecutionInput>
|
|
61
63
|
}
|
|
62
64
|
|
|
@@ -88,7 +90,7 @@ export class WorkflowRunDispatcher implements WorkflowRunDispatchPort {
|
|
|
88
90
|
throw new WorkflowValidationError(`[Sixb] Unknown workflow '${input.workflowId}'`)
|
|
89
91
|
}
|
|
90
92
|
|
|
91
|
-
|
|
93
|
+
return dispatchWorkflowRun({
|
|
92
94
|
errorReporterHost: this.dependencies,
|
|
93
95
|
projectId: this.dependencies.id,
|
|
94
96
|
workflow,
|
|
@@ -106,6 +108,7 @@ export class WorkflowRunDispatcher implements WorkflowRunDispatchPort {
|
|
|
106
108
|
},
|
|
107
109
|
metadata: input.metadata,
|
|
108
110
|
queueJobId: input.runId,
|
|
111
|
+
validateExistingRun: (run) => assertAutomaticExecutionIdentity(this.dependencies, input, run),
|
|
109
112
|
createExecution: async (executionId, runId) =>
|
|
110
113
|
createPrimitiveExecutionRecord({
|
|
111
114
|
id: executionId,
|
|
@@ -118,10 +121,6 @@ export class WorkflowRunDispatcher implements WorkflowRunDispatchPort {
|
|
|
118
121
|
},
|
|
119
122
|
}),
|
|
120
123
|
})
|
|
121
|
-
if (!result.created) {
|
|
122
|
-
await assertAutomaticExecutionIdentity(this.dependencies, input, result.runId)
|
|
123
|
-
}
|
|
124
|
-
return result
|
|
125
124
|
}
|
|
126
125
|
}
|
|
127
126
|
|
|
@@ -131,7 +130,15 @@ export async function dispatchWorkflowRun(
|
|
|
131
130
|
): Promise<WorkflowRunRequestResult> {
|
|
132
131
|
const request = prepareWorkflowRun(input)
|
|
133
132
|
const persisted = await persistWorkflowRun(input, request)
|
|
134
|
-
if (!persisted.created)
|
|
133
|
+
if (!persisted.created) {
|
|
134
|
+
await input.validateExistingRun?.(persisted.run)
|
|
135
|
+
if (input.validateExistingRun && persisted.run.status === "queued") {
|
|
136
|
+
// A queued run is also the recoverable intent when publication never completed.
|
|
137
|
+
// Reuse the provider job identity, including after a successful but unacknowledged enqueue.
|
|
138
|
+
await enqueueWorkflowRun(input, persisted.run)
|
|
139
|
+
}
|
|
140
|
+
return existingWorkflowRunResult(persisted.run)
|
|
141
|
+
}
|
|
135
142
|
return publishWorkflowRun(input, persisted)
|
|
136
143
|
}
|
|
137
144
|
|
|
@@ -213,20 +220,11 @@ async function publishWorkflowRun(
|
|
|
213
220
|
): Promise<WorkflowRunRequestResult> {
|
|
214
221
|
let job: Awaited<ReturnType<Queues["workflows"]["enqueue"]>>[number] | undefined
|
|
215
222
|
try {
|
|
216
|
-
|
|
217
|
-
projectId: input.projectId,
|
|
218
|
-
jobs: [
|
|
219
|
-
{
|
|
220
|
-
...(input.queueJobId === undefined ? {} : { id: input.queueJobId }),
|
|
221
|
-
type: "workflow.run.requested",
|
|
222
|
-
payload: { runId: persisted.run.id },
|
|
223
|
-
...(input.metadata === undefined ? {} : { metadata: input.metadata }),
|
|
224
|
-
},
|
|
225
|
-
],
|
|
226
|
-
})
|
|
227
|
-
job = jobs[0]
|
|
223
|
+
job = await enqueueWorkflowRun(input, persisted.run)
|
|
228
224
|
} catch (error) {
|
|
229
|
-
|
|
225
|
+
// Automatic dispatch retries the same run. Do not turn an uncertain enqueue into
|
|
226
|
+
// a terminal business failure: the queue may have accepted it before losing the reply.
|
|
227
|
+
if (!input.validateExistingRun) await failWorkflowRunPublication(input, persisted.run, error)
|
|
230
228
|
throw error
|
|
231
229
|
}
|
|
232
230
|
|
|
@@ -258,6 +256,27 @@ async function publishWorkflowRun(
|
|
|
258
256
|
}
|
|
259
257
|
}
|
|
260
258
|
|
|
259
|
+
async function enqueueWorkflowRun(
|
|
260
|
+
input: DispatchWorkflowRunInput,
|
|
261
|
+
run: WorkflowRunRecord
|
|
262
|
+
): Promise<Awaited<ReturnType<Queues["workflows"]["enqueue"]>>[number]> {
|
|
263
|
+
const [job] = await input.queue.enqueue({
|
|
264
|
+
projectId: input.projectId,
|
|
265
|
+
jobs: [
|
|
266
|
+
{
|
|
267
|
+
...(input.queueJobId === undefined ? {} : { id: input.queueJobId }),
|
|
268
|
+
type: "workflow.run.requested",
|
|
269
|
+
payload: { runId: run.id },
|
|
270
|
+
...(input.metadata === undefined ? {} : { metadata: input.metadata }),
|
|
271
|
+
},
|
|
272
|
+
],
|
|
273
|
+
})
|
|
274
|
+
if (!job || (input.queueJobId !== undefined && job.id !== input.queueJobId)) {
|
|
275
|
+
throw new WorkflowRunError(`[Sixb] Queue did not acknowledge workflow run '${run.id}'.`)
|
|
276
|
+
}
|
|
277
|
+
return job
|
|
278
|
+
}
|
|
279
|
+
|
|
261
280
|
async function failWorkflowRunPublication(
|
|
262
281
|
input: DispatchWorkflowRunInput,
|
|
263
282
|
run: WorkflowRunRecord,
|
|
@@ -326,18 +345,12 @@ function assertAutomaticDispatchInput(input: AutomaticWorkflowRunDispatchInput):
|
|
|
326
345
|
async function assertAutomaticExecutionIdentity(
|
|
327
346
|
dependencies: WorkflowRunDispatcherDependencies,
|
|
328
347
|
input: AutomaticWorkflowRunDispatchInput,
|
|
329
|
-
|
|
348
|
+
run: WorkflowRunRecord
|
|
330
349
|
): Promise<void> {
|
|
331
|
-
const
|
|
350
|
+
const execution = await dependencies.storage.executions.getById({
|
|
332
351
|
projectId: dependencies.id,
|
|
333
|
-
id:
|
|
352
|
+
id: run.executionId,
|
|
334
353
|
})
|
|
335
|
-
const execution = run
|
|
336
|
-
? await dependencies.storage.executions.getById({
|
|
337
|
-
projectId: dependencies.id,
|
|
338
|
-
id: run.executionId,
|
|
339
|
-
})
|
|
340
|
-
: null
|
|
341
354
|
if (
|
|
342
355
|
!execution ||
|
|
343
356
|
execution.source.type !== input.source.type ||
|
|
@@ -346,7 +359,7 @@ async function assertAutomaticExecutionIdentity(
|
|
|
346
359
|
execution.requestedBy !== undefined
|
|
347
360
|
) {
|
|
348
361
|
throw new WorkflowValidationError(
|
|
349
|
-
`[Sixb] Workflow run '${
|
|
362
|
+
`[Sixb] Workflow run '${run.id}' already exists with different automatic provenance.`
|
|
350
363
|
)
|
|
351
364
|
}
|
|
352
365
|
}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../src/broker/errors.ts", "../src/broker/in-memory.ts"],
|
|
4
|
-
"sourcesContent": [
|
|
5
|
-
"export class BrokerError extends Error {\n readonly name: string = \"BrokerError\"\n\n constructor(message: string, options?: ErrorOptions) {\n super(`[Broker] ${message}`, options)\n }\n}\n\n/**\n * Raised when retention has removed the cursor a consumer wants to resume\n * from. Transports use this provider-independent type to request a reset.\n */\nexport class BrokerCursorExpiredError extends BrokerError {\n override readonly name = \"BrokerCursorExpiredError\"\n}\n",
|
|
6
|
-
"import { getInvalidJsonValueReason, type JsonValue } from \"../json\"\nimport { BrokerCursorExpiredError, BrokerError } from \"./errors\"\nimport type {\n Broker,\n BrokerPage,\n BrokerRecord,\n BrokerRecordInput,\n BrokerStreamDefinition,\n} from \"./types\"\n\n// Payloads are validated by assertBrokerPayload above the call site, so we can\n// skip the redundant validity walk that cloneJsonValue performs.\nfunction cloneValidatedPayload(value: JsonValue): JsonValue {\n return JSON.parse(JSON.stringify(value)) as JsonValue\n}\n\n// Records stored internally carry a numeric publishedAtMs alongside the public\n// ISO publishedAt string so retention sweeps can avoid Date.parse on every\n// record on every append/read.\ninterface StoredRecord extends BrokerRecord {\n readonly publishedAtMs: number\n readonly byteSize: number\n}\n\ninterface StoredStream {\n definition: BrokerStreamDefinition\n nextSequence: bigint\n records: StoredRecord[]\n retainedBytes: number\n}\n\ninterface Subscription {\n readonly projectId: string\n readonly streamId: string\n readonly names?: readonly string[]\n readonly keys?: readonly string[]\n readonly handler: (records: readonly BrokerRecord[]) => void\n}\n\nexport class InMemoryBroker implements Broker {\n readonly scope = \"process\" as const\n private readonly streams = new Map<string, StoredStream>()\n private readonly subscriptions = new Set<Subscription>()\n\n async ensureStream(params: { projectId: string; stream: BrokerStreamDefinition }): Promise<void> {\n assertProjectId(params.projectId)\n assertStream(params.stream)\n this.getOrCreateStream(params.projectId, params.stream)\n }\n\n async append(params: {\n projectId: string\n streamId: string\n records: readonly BrokerRecordInput[]\n }): Promise<readonly BrokerRecord[]> {\n assertProjectId(params.projectId)\n assertStreamId(params.streamId)\n\n if (params.records.length === 0) {\n return []\n }\n\n for (const record of params.records) {\n assertBrokerPayload(record.payload)\n }\n\n const storedStream = this.getEnsuredStream(params.projectId, params.streamId)\n const stored: StoredRecord[] = []\n\n for (const record of params.records) {\n const cursor = storedStream.nextSequence.toString()\n storedStream.nextSequence += 1n\n const publishedAtMs = Date.now()\n const storedRecord = {\n streamId: params.streamId,\n cursor,\n name: record.name,\n key: record.key,\n payload: cloneValidatedPayload(record.payload as JsonValue),\n publishedAt: new Date(publishedAtMs).toISOString(),\n publishedAtMs,\n }\n stored.push({\n ...storedRecord,\n byteSize: utf8Bytes(JSON.stringify(storedRecord)),\n })\n }\n\n storedStream.records.push(...stored)\n storedStream.retainedBytes += stored.reduce((total, record) => total + record.byteSize, 0)\n this.applyRetention(storedStream)\n const records = stored.map(toBrokerRecord)\n this.notify(params.projectId, params.streamId, stored)\n return records\n }\n\n async read(params: {\n projectId: string\n streamId: string\n afterCursor?: string\n limit?: number\n names?: readonly string[]\n keys?: readonly string[]\n }): Promise<BrokerPage> {\n assertProjectId(params.projectId)\n assertStreamId(params.streamId)\n assertCursor(params.afterCursor)\n\n if (params.limit !== undefined && params.limit <= 0) {\n return { records: [], cursor: params.afterCursor, hasMore: false }\n }\n\n const storedStream = this.streams.get(streamKey(params.projectId, params.streamId))\n if (!storedStream) {\n return { records: [], cursor: params.afterCursor, hasMore: false }\n }\n\n this.applyRetention(storedStream)\n this.assertCursorInRetainedRange(storedStream, params.afterCursor)\n return this.readForward(storedStream.records, {\n afterCursor: params.afterCursor,\n limit: params.limit,\n names: params.names,\n keys: params.keys,\n })\n }\n\n async tail(params: {\n projectId: string\n streamId: string\n beforeCursor?: string\n limit?: number\n names?: readonly string[]\n keys?: readonly string[]\n }): Promise<BrokerPage> {\n assertProjectId(params.projectId)\n assertStreamId(params.streamId)\n assertCursor(params.beforeCursor)\n\n if (params.limit !== undefined && params.limit <= 0) {\n return { records: [], cursor: params.beforeCursor, hasMore: false }\n }\n\n const storedStream = this.streams.get(streamKey(params.projectId, params.streamId))\n if (!storedStream) {\n return { records: [], cursor: params.beforeCursor, hasMore: false }\n }\n\n this.applyRetention(storedStream)\n this.assertTailCursorInRetainedRange(storedStream, params.beforeCursor)\n return this.readBackward(storedStream.records, params)\n }\n\n async latestCursor(params: { projectId: string; streamId: string }): Promise<string | undefined> {\n assertProjectId(params.projectId)\n assertStreamId(params.streamId)\n\n const storedStream = this.streams.get(streamKey(params.projectId, params.streamId))\n if (!storedStream) {\n return undefined\n }\n\n this.applyRetention(storedStream)\n return storedStream.records.at(-1)?.cursor\n }\n\n async subscribe(\n params: {\n projectId: string\n streamId: string\n from?: \"latest\" | \"earliest\"\n afterCursor?: string\n names?: readonly string[]\n keys?: readonly string[]\n },\n handler: (records: readonly BrokerRecord[]) => void\n ): Promise<() => void> {\n assertProjectId(params.projectId)\n assertStreamId(params.streamId)\n assertCursor(params.afterCursor)\n const storedStream = this.getEnsuredStream(params.projectId, params.streamId)\n\n // Retention may have trimmed past the caller's cursor. Reject that here rather than let\n // `readForward` skip silently to the oldest retained record: a resuming subscriber would be\n // fast-forwarded over the gap and would believe it had seen everything. `read` and `tail`\n // already reject it, and so does the Redis provider, so this keeps the three consistent.\n // Checked before the subscription is registered so a throw cannot leave one behind.\n this.applyRetention(storedStream)\n this.assertCursorInRetainedRange(storedStream, params.afterCursor)\n\n const subscription: Subscription = {\n projectId: params.projectId,\n streamId: params.streamId,\n names: params.names,\n keys: params.keys,\n handler,\n }\n this.subscriptions.add(subscription)\n\n const startMode = params.afterCursor !== undefined ? undefined : (params.from ?? \"latest\")\n if (params.afterCursor !== undefined || startMode === \"earliest\") {\n const initial = this.readForward(storedStream.records, {\n afterCursor: params.afterCursor,\n names: params.names,\n keys: params.keys,\n }).records\n this.deliver(subscription, initial)\n }\n\n return () => {\n this.subscriptions.delete(subscription)\n }\n }\n\n private getOrCreateStream(projectId: string, stream: BrokerStreamDefinition): StoredStream {\n const key = streamKey(projectId, stream.id)\n let storedStream = this.streams.get(key)\n if (!storedStream) {\n storedStream = {\n definition: stream,\n nextSequence: 1n,\n records: [],\n retainedBytes: 0,\n }\n this.streams.set(key, storedStream)\n }\n this.applyRetention(storedStream)\n return storedStream\n }\n\n private getEnsuredStream(projectId: string, streamId: string): StoredStream {\n const storedStream = this.streams.get(streamKey(projectId, streamId))\n if (!storedStream) {\n throw new BrokerError(\n `stream '${streamId}' has not been ensured for project '${projectId}'. Call ensureStream() before append or subscribe.`\n )\n }\n return storedStream\n }\n\n private applyRetention(storedStream: StoredStream): void {\n const { retention } = storedStream.definition\n if (!retention) {\n return\n }\n\n let removeCount = 0\n const records = storedStream.records\n\n if (retention.maxAgeMs !== undefined) {\n if (retention.maxAgeMs <= 0) {\n removeCount = records.length\n } else {\n const oldestAllowed = Date.now() - retention.maxAgeMs\n // Records are appended in chronological order, so we only need to find\n // the first record that is still in range and slice off the prefix —\n // avoids walking the entire retained set on every sweep.\n let firstInRange = 0\n while (\n firstInRange < records.length &&\n records[firstInRange].publishedAtMs < oldestAllowed\n ) {\n firstInRange += 1\n }\n removeCount = Math.max(removeCount, firstInRange)\n }\n }\n\n if (retention.maxRecords !== undefined) {\n if (retention.maxRecords <= 0) {\n removeCount = records.length\n } else if (records.length - removeCount > retention.maxRecords) {\n removeCount = records.length - retention.maxRecords\n }\n }\n\n if (retention.maxBytes !== undefined) {\n if (retention.maxBytes <= 0) {\n removeCount = records.length\n } else {\n let bytes = storedStream.retainedBytes\n for (let index = 0; index < removeCount; index += 1) {\n bytes -= records[index]!.byteSize\n }\n while (removeCount < records.length && bytes > retention.maxBytes) {\n bytes -= records[removeCount]!.byteSize\n removeCount += 1\n }\n }\n }\n\n if (removeCount > 0) {\n for (let index = 0; index < removeCount; index += 1) {\n storedStream.retainedBytes -= records[index]!.byteSize\n }\n storedStream.records = records.slice(removeCount)\n }\n }\n\n private assertCursorInRetainedRange(\n storedStream: StoredStream,\n afterCursor: string | undefined\n ): void {\n if (afterCursor === undefined) {\n return\n }\n\n const requestedNextSequence = BigInt(afterCursor) + 1n\n const firstRecord = storedStream.records[0]\n const firstAvailableSequence =\n firstRecord === undefined ? storedStream.nextSequence : BigInt(firstRecord.cursor)\n\n if (requestedNextSequence < firstAvailableSequence) {\n throw new BrokerCursorExpiredError(\n `afterCursor '${afterCursor}' is outside the retained range for stream '${storedStream.definition.id}'. ` +\n `The next requested cursor sequence is '${requestedNextSequence}', but the earliest ` +\n `available cursor sequence is '${firstAvailableSequence}'.`\n )\n }\n }\n\n private assertTailCursorInRetainedRange(\n storedStream: StoredStream,\n beforeCursor: string | undefined\n ): void {\n if (beforeCursor === undefined || storedStream.records.length === 0) {\n return\n }\n const firstAvailableSequence = BigInt(storedStream.records[0]!.cursor)\n if (BigInt(beforeCursor) < firstAvailableSequence) {\n throw new BrokerCursorExpiredError(\n `beforeCursor '${beforeCursor}' is outside the retained range for stream '${storedStream.definition.id}'. ` +\n `The earliest available cursor sequence is '${firstAvailableSequence}'.`\n )\n }\n }\n\n private notify(projectId: string, streamId: string, records: readonly StoredRecord[]): void {\n for (const subscription of this.subscriptions) {\n if (subscription.projectId !== projectId || subscription.streamId !== streamId) {\n continue\n }\n this.deliver(\n subscription,\n this.readForward(records, {\n names: subscription.names,\n keys: subscription.keys,\n }).records\n )\n }\n }\n\n private deliver(subscription: Subscription, records: readonly BrokerRecord[]): void {\n if (records.length === 0) {\n return\n }\n\n try {\n subscription.handler(records)\n } catch {\n // Broker subscriptions are live fan-out; handler failures should not break publishers.\n }\n }\n\n private readForward(\n records: readonly StoredRecord[],\n filters: {\n afterCursor?: string\n limit?: number\n names?: readonly string[]\n keys?: readonly string[]\n }\n ): BrokerPage {\n const names = filters.names && filters.names.length > 0 ? new Set(filters.names) : undefined\n const keys = filters.keys && filters.keys.length > 0 ? new Set(filters.keys) : undefined\n const afterCursor = filters.afterCursor ? BigInt(filters.afterCursor) : undefined\n const result: BrokerRecord[] = []\n let cursor = filters.afterCursor\n let stoppedAt = records.length\n\n for (let index = 0; index < records.length; index += 1) {\n const record = records[index]!\n if (afterCursor !== undefined && BigInt(record.cursor) <= afterCursor) {\n continue\n }\n cursor = record.cursor\n if (!matchesFilters(record, names, keys)) {\n continue\n }\n result.push(toBrokerRecord(record))\n if (filters.limit !== undefined && result.length >= filters.limit) {\n stoppedAt = index + 1\n break\n }\n }\n\n return {\n records: result,\n cursor,\n hasMore: records.slice(stoppedAt).some((record) => matchesFilters(record, names, keys)),\n }\n }\n\n private readBackward(\n records: readonly StoredRecord[],\n filters: {\n beforeCursor?: string\n limit?: number\n names?: readonly string[]\n keys?: readonly string[]\n }\n ): BrokerPage {\n const names = filters.names && filters.names.length > 0 ? new Set(filters.names) : undefined\n const keys = filters.keys && filters.keys.length > 0 ? new Set(filters.keys) : undefined\n const beforeCursor = filters.beforeCursor ? BigInt(filters.beforeCursor) : undefined\n const reversed: BrokerRecord[] = []\n let cursor = filters.beforeCursor\n let stoppedAt = -1\n\n for (let index = records.length - 1; index >= 0; index -= 1) {\n const record = records[index]!\n if (beforeCursor !== undefined && BigInt(record.cursor) >= beforeCursor) {\n continue\n }\n cursor = record.cursor\n if (!matchesFilters(record, names, keys)) {\n continue\n }\n reversed.push(toBrokerRecord(record))\n if (filters.limit !== undefined && reversed.length >= filters.limit) {\n stoppedAt = index - 1\n break\n }\n }\n\n return {\n records: reversed.reverse(),\n cursor,\n hasMore:\n stoppedAt >= 0 &&\n records.slice(0, stoppedAt + 1).some((record) => matchesFilters(record, names, keys)),\n }\n }\n}\n\nfunction matchesFilters(\n record: BrokerRecord,\n names: ReadonlySet<string> | undefined,\n keys: ReadonlySet<string> | undefined\n): boolean {\n return (\n (!names || (!!record.name && names.has(record.name))) &&\n (!keys || (!!record.key && keys.has(record.key)))\n )\n}\n\nfunction streamKey(projectId: string, streamId: string): string {\n return `${projectId}\\0${streamId}`\n}\n\nfunction toBrokerRecord(record: StoredRecord): BrokerRecord {\n return {\n streamId: record.streamId,\n cursor: record.cursor,\n name: record.name,\n key: record.key,\n payload: record.payload,\n publishedAt: record.publishedAt,\n }\n}\n\nfunction utf8Bytes(value: string): number {\n return new TextEncoder().encode(value).byteLength\n}\n\nfunction assertProjectId(projectId: string): void {\n if (projectId.trim().length === 0) {\n throw new BrokerError(\"projectId must be a non-empty string\")\n }\n}\n\nfunction assertStream(stream: BrokerStreamDefinition): void {\n if (stream.id.trim().length === 0) {\n throw new BrokerError(\"stream.id must be a non-empty string\")\n }\n}\n\nfunction assertStreamId(streamId: string): void {\n if (streamId.trim().length === 0) {\n throw new BrokerError(\"streamId must be a non-empty string\")\n }\n}\n\nfunction assertBrokerPayload(payload: unknown): void {\n const reason = getInvalidJsonValueReason(payload, \"record.payload\")\n if (reason) {\n throw new BrokerError(`record.payload must be a JSON value; ${reason}`)\n }\n}\n\nfunction assertCursor(cursor: string | undefined): void {\n if (cursor === undefined) {\n return\n }\n\n try {\n if (BigInt(cursor) < 0n) {\n throw new BrokerError(\"cursor must be non-negative\")\n }\n } catch (error) {\n if (error instanceof BrokerError) {\n throw error\n }\n throw new BrokerError(\"cursor must be a numeric in-memory broker cursor\", {\n cause: error,\n })\n }\n}\n"
|
|
7
|
-
],
|
|
8
|
-
"mappings": ";;;;;;AAAO,MAAM,qBAAoB,MAAM;AAAA,EAC5B,OAAe;AAAA,EAExB,WAAW,CAAC,SAAiB,SAAwB;AAAA,IACnD,MAAM,YAAY,WAAW,OAAO;AAAA;AAExC;AAAA;AAMO,MAAM,kCAAiC,aAAY;AAAA,EACtC,OAAO;AAC3B;;ACFA,SAAS,qBAAqB,CAAC,OAA6B;AAAA,EAC1D,OAAO,KAAK,MAAM,KAAK,UAAU,KAAK,CAAC;AAAA;AAAA;AA0BlC,MAAM,gBAAiC;AAAA,EACnC,QAAQ;AAAA,EACA,UAAU,IAAI;AAAA,EACd,gBAAgB,IAAI;AAAA,OAE/B,aAAY,CAAC,QAA8E;AAAA,IAC/F,gBAAgB,OAAO,SAAS;AAAA,IAChC,aAAa,OAAO,MAAM;AAAA,IAC1B,KAAK,kBAAkB,OAAO,WAAW,OAAO,MAAM;AAAA;AAAA,OAGlD,OAAM,CAAC,QAIwB;AAAA,IACnC,gBAAgB,OAAO,SAAS;AAAA,IAChC,eAAe,OAAO,QAAQ;AAAA,IAE9B,IAAI,OAAO,QAAQ,WAAW,GAAG;AAAA,MAC/B,OAAO,CAAC;AAAA,IACV;AAAA,IAEA,WAAW,UAAU,OAAO,SAAS;AAAA,MACnC,oBAAoB,OAAO,OAAO;AAAA,IACpC;AAAA,IAEA,MAAM,eAAe,KA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OAAO;AAAA,IACT,CAAC;AAAA;AAAA;",
|
|
9
|
-
"debugId": "356153004EE6A88A64756E2164756E21",
|
|
10
|
-
"names": []
|
|
11
|
-
}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../src/connectors/types.ts"],
|
|
4
|
-
"sourcesContent": [
|
|
5
|
-
"import type { WebhookDefinition } from \"../webhooks/types\"\n\n/**\n * Runtime context passed to connector adapters when Sixb establishes a connection.\n *\n * Connectors can use this to scope logs, build cache keys, or attach cancellation\n * to long-running startup work.\n */\nexport interface ConnectorContext {\n readonly projectId: string\n readonly connectorId: string\n readonly signal: AbortSignal\n}\n\n/**\n * Minimal contract for a Sixb connector adapter.\n *\n * Adapters are responsible for creating and optionally tearing down a client for an\n * external system. They should return the client shape that feels natural for that system.\n */\nexport interface ConnectorAdapter<TType extends string = string, TClient = unknown> {\n readonly type: TType\n readonly authentication?: never\n readonly webhooks?: readonly WebhookDefinition<unknown, TClient>[]\n connect(context: ConnectorContext): Promise<TClient> | TClient\n disconnect?(client: TClient): Promise<void> | void\n}\n\n/** One OAuth token set normalized by an OAuth connector adapter. */\nexport interface ConnectorOAuthCredentials {\n readonly accessToken: string\n readonly refreshToken?: string\n readonly tokenType?: string\n readonly scopes?: readonly string[]\n readonly expiresAt?: Date\n}\n\n/** Public, non-secret account information returned for framework-owned selection UI. */\nexport interface ConnectorAccountCandidate {\n readonly id: string\n readonly label: string\n readonly description?: string\n readonly avatarUrl?: string\n}\n\n/** V1 intentionally supports project-owned connector connections only. */\nexport interface ProjectConnectorConnectionOwner {\n readonly type: \"project\"\n}\n\nexport type ConnectorConnectionOwner = ProjectConnectorConnectionOwner\n\n/** Stable application-defined lookup key for one connector connection. */\nexport interface ConnectorConnectionSelector {\n readonly owner: ConnectorConnectionOwner\n readonly slot: string\n}\n\n/** Stable, non-secret metadata shared by connector connection consumers. */\nexport interface ConnectorConnectionMetadata extends ConnectorConnectionSelector {\n readonly id: string\n readonly connectorId: string\n readonly account: ConnectorAccountCandidate\n}\n\n/** Credential protection required when an OAuth connector uses durable connection storage. */\nexport interface ConnectorConnectionOptions {\n /** Canonical base64url encoding of exactly 32 random bytes, shared by storage replicas. */\n readonly encryptionKey: string\n}\n\nexport interface OAuthConnectorAuthorizationContext extends ConnectorContext {\n readonly redirectUri: string\n}\n\nexport interface OAuthConnectorAuthorizationUrlInput {\n readonly state: string\n readonly codeChallenge: string\n readonly codeChallengeMethod: \"S256\"\n}\n\nexport interface OAuthConnectorCodeExchangeInput {\n readonly code: string\n readonly codeVerifier: string\n}\n\nexport interface ConnectorConnectionClientContext extends ConnectorContext {\n readonly connectionId: string\n readonly account: ConnectorAccountCandidate\n readonly tokenSource: ConnectorTokenSource\n}\n\n/** One delivered token, bound to the credential revision that produced it. */\nexport interface ConnectorAccessToken {\n readonly accessToken: string\n readonly tokenType?: string\n /** Report this exact token as rejected so Sixb can refresh only its credential revision. */\n invalidate(): void\n}\n\n/** Live credential source owned by Sixb. Adapters must resolve a token for each request. */\nexport interface ConnectorTokenSource {\n get(): Promise<ConnectorAccessToken>\n}\n\n/**\n * OAuth-backed connector adapter. Sixb owns persistence, OAuth state, refresh coordination and UI;\n * the adapter owns provider protocol details and typed client creation.\n */\nexport interface ConnectorOAuth2Authentication {\n readonly type: \"oauth2\"\n authorizationUrl(\n context: OAuthConnectorAuthorizationContext,\n input: OAuthConnectorAuthorizationUrlInput\n ): Promise<string | URL> | string | URL\n exchangeCode(\n context: OAuthConnectorAuthorizationContext,\n input: OAuthConnectorCodeExchangeInput\n ): Promise<ConnectorOAuthCredentials> | ConnectorOAuthCredentials\n refresh(\n context: ConnectorContext,\n credentials: ConnectorOAuthCredentials\n ): Promise<ConnectorOAuthCredentials> | ConnectorOAuthCredentials\n /**\n * Revokes the grant idempotently. An already revoked or invalid grant must resolve successfully\n * so Sixb can converge after losing an earlier provider response.\n */\n revoke?(context: ConnectorContext, credentials: ConnectorOAuthCredentials): Promise<void> | void\n}\n\nexport interface OAuthConnectorAdapter<TType extends string = string, TClient = unknown> {\n readonly type: TType\n readonly authentication: ConnectorOAuth2Authentication\n readonly webhooks?: undefined\n discoverAccounts(\n context: ConnectorContext,\n credentials: ConnectorOAuthCredentials\n ): Promise<readonly ConnectorAccountCandidate[]> | readonly ConnectorAccountCandidate[]\n connect(context: ConnectorConnectionClientContext): Promise<TClient> | TClient\n}\n\nexport type AnyConnectorAdapter = ConnectorAdapter | OAuthConnectorAdapter\n\n/**\n * Inert connector definition registered with Sixb.\n *\n * Definitions are safe to export from `connectors/` modules. The runtime turns them into\n * live clients when `sixb.connector(...)` is called.\n */\nexport interface ConnectorDefinition<\n TId extends string = string,\n TAdapter extends AnyConnectorAdapter = AnyConnectorAdapter,\n> {\n readonly kind: \"connector\"\n readonly id: TId\n readonly adapter: TAdapter\n}\n\nexport type StaticConnectorDefinition = ConnectorDefinition<string, ConnectorAdapter>\n\n/** Infer the connected client type returned by a connector adapter. */\nexport type ConnectorClient<TAdapter extends AnyConnectorAdapter> = Awaited<\n ReturnType<TAdapter[\"connect\"]>\n>\n\nexport function isOAuthConnectorAdapter(\n value: AnyConnectorAdapter\n): value is OAuthConnectorAdapter {\n return \"authentication\" in value && value.authentication?.type === \"oauth2\"\n}\n\nexport function isOAuthConnectorDefinition(\n value: ConnectorDefinition\n): value is ConnectorDefinition<string, OAuthConnectorAdapter> {\n return isOAuthConnectorAdapter(value.adapter)\n}\n\nexport function isStaticConnectorDefinition(\n value: ConnectorDefinition\n): value is StaticConnectorDefinition {\n return !isOAuthConnectorDefinition(value)\n}\n\nexport function isConnectorDefinition(value: unknown): value is ConnectorDefinition {\n if (!isRecord(value)) {\n return false\n }\n\n const adapter = value.adapter\n if (\n value.kind === \"connector\" &&\n typeof value.id === \"string\" &&\n isRecord(adapter) &&\n typeof adapter.type === \"string\" &&\n typeof adapter.connect === \"function\"\n ) {\n if (adapter.authentication === undefined) return true\n const authentication = adapter.authentication\n if (!isRecord(authentication) || authentication.type !== \"oauth2\") return false\n return (\n typeof authentication.authorizationUrl === \"function\" &&\n typeof authentication.exchangeCode === \"function\" &&\n typeof authentication.refresh === \"function\" &&\n typeof adapter.discoverAccounts === \"function\"\n )\n }\n\n return false\n}\n\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n return typeof value === \"object\" && value !== null && !Array.isArray(value)\n}\n"
|
|
6
|
-
],
|
|
7
|
-
"mappings": ";;AAqKO,SAAS,uBAAuB,CACrC,OACgC;AAAA,EAChC,OAAO,oBAAoB,SAAS,MAAM,gBAAgB,SAAS;AAAA;AAG9D,SAAS,2BAA0B,CACxC,OAC6D;AAAA,EAC7D,OAAO,wBAAwB,MAAM,OAAO;AAAA;AAGvC,SAAS,2BAA2B,CACzC,OACoC;AAAA,EACpC,OAAO,CAAC,4BAA2B,KAAK;AAAA;AAGnC,SAAS,qBAAqB,CAAC,OAA8C;AAAA,EAClF,IAAI,CAAC,SAAS,KAAK,GAAG;AAAA,IACpB,OAAO;AAAA,EACT;AAAA,EAEA,MAAM,UAAU,MAAM;AAAA,EACtB,IACE,MAAM,SAAS,eACf,OAAO,MAAM,OAAO,YACpB,SAAS,OAAO,KAChB,OAAO,QAAQ,SAAS,YACxB,OAAO,QAAQ,YAAY,YAC3B;AAAA,IACA,IAAI,QAAQ,mBAAmB;AAAA,MAAW,OAAO;AAAA,IACjD,MAAM,iBAAiB,QAAQ;AAAA,IAC/B,IAAI,CAAC,SAAS,cAAc,KAAK,eAAe,SAAS;AAAA,MAAU,OAAO;AAAA,IAC1E,OACE,OAAO,eAAe,qBAAqB,cAC3C,OAAO,eAAe,iBAAiB,cACvC,OAAO,eAAe,YAAY,cAClC,OAAO,QAAQ,qBAAqB;AAAA,EAExC;AAAA,EAEA,OAAO;AAAA;AAGT,SAAS,QAAQ,CAAC,OAAkD;AAAA,EAClE,OAAO,OAAO,UAAU,YAAY,UAAU,QAAQ,CAAC,MAAM,QAAQ,KAAK;AAAA;",
|
|
8
|
-
"debugId": "30BD1F10D764311164756E2164756E21",
|
|
9
|
-
"names": []
|
|
10
|
-
}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../src/projections/types.ts", "../src/storage/projection-runs/types.ts"],
|
|
4
|
-
"sourcesContent": [
|
|
5
|
-
"import type { SixbErrorCode } from \"../errors/types\"\n\n/** Error codes a projection run can persist and expose through its public contract. */\nexport const PROJECTION_RUN_FAILURE_CODES = [\n \"internal.unexpected\",\n \"runtime.cancelled\",\n \"queue.enqueue_failed\",\n \"projection.execution_failed\",\n] as const satisfies readonly [SixbErrorCode, ...SixbErrorCode[]]\n\nexport type ProjectionRunFailureCode = (typeof PROJECTION_RUN_FAILURE_CODES)[number]\n\n/**\n * Lowered, serializable definition interfaces for projection DSL.\n *\n * These are the runtime-inspectable data structures that projection builders\n * lower into. They use plain string ids (no tokens, no methods) so they can\n * be stored, serialized, and introspected by tooling.\n */\n\n/**\n * Describes how a foreign key column in a dataset resolves to a link target.\n *\n * The source can be either a projected source property or a raw dataset field.\n * Its value equals the target object's primary property value, creating an\n * implicit link between source and target.\n *\n * `targetObjectTypeId` declares the concrete target type for this projection.\n * It must be the same type or a subtype (via `extends`) of the link's declared\n * target at the ontology level. Validation of the subtype relationship happens\n * at Sixb startup (Increment 7), not at DSL build time.\n */\nexport interface ForeignKeyDescriptor {\n readonly linkId: string\n /** Object property holding the target id. Mutually exclusive with sourceField. */\n readonly sourcePropertyId?: string\n /** Dataset column holding the target id. Mutually exclusive with sourcePropertyId. */\n readonly sourceField?: string\n readonly targetObjectTypeId: string\n}\n\n/** Resolves competing source-projection and managed-edit values for projected properties. */\nexport type SourceEditConflictResolution =\n | { readonly strategy: \"editsWin\" }\n | { readonly strategy: \"mostRecent\"; readonly sourceTimestamp: string }\n\n/**\n * Lowered, serializable definition for projecting a dataset into object instances.\n *\n * Each row contributes one complete object root to an authoritative replacement snapshot, with\n * properties mapped from dataset columns to object type properties. Duplicate roots are rejected.\n * FK links are resolved from source property or dataset field values to target object primary\n * values.\n */\nexport interface ObjectProjectionDefinition {\n readonly _tag: \"ObjectProjectionDefinition\"\n readonly id: string\n readonly objectTypeId: string\n readonly datasetId: string\n /** Maps object type property id -> dataset column name. */\n readonly properties: Readonly<Record<string, string>>\n /** Maps link id -> FK descriptor. Empty `{}` when no FK links are projected. */\n readonly links: Readonly<Record<string, ForeignKeyDescriptor>>\n /** Defaults to `editsWin` when omitted by a legacy lowered definition. */\n readonly conflictResolution?: SourceEditConflictResolution\n}\n\n/**\n * Lowered, serializable definition for projecting a join dataset into link instances.\n *\n * Each row in the join dataset contributes one complete link root to an authoritative replacement\n * snapshot, identified by its source, link id, and target. Duplicate roots are rejected.\n */\nexport interface LinkProjectionDefinition {\n readonly _tag: \"LinkProjectionDefinition\"\n readonly id: string\n readonly linkId: string\n readonly sourceObjectTypeId: string\n readonly targetObjectTypeId: string\n readonly datasetId: string\n /** Dataset column holding the source object's primary property value. */\n readonly sourceField: string\n /** Dataset column holding the target object's primary property value. */\n readonly targetField: string\n}\n\n/** Dataset columns that produce one telemetry property value. */\nexport interface TelemetryProjectionPropertyMapping {\n /** Dataset column holding the telemetry value. */\n readonly valueField: string\n /** Dataset column holding the telemetry unit, when the property requires one. */\n readonly unitField?: string\n}\n\n/**\n * Lowered, serializable definition for projecting dataset rows into telemetry history.\n *\n * Each row shares one target object id and observation timestamp, then contributes up to one\n * telemetry point for every mapped property. A property-token projection is lowered to the same\n * shape with one entry, so execution and ownership have one canonical contract.\n */\nexport interface TelemetryProjectionDefinition {\n readonly _tag: \"TelemetryProjectionDefinition\"\n readonly id: string\n readonly objectTypeId: string\n readonly datasetId: string\n /** Dataset column holding the target object's primary id. */\n readonly objectIdField: string\n /** Dataset column holding the telemetry observation timestamp. */\n readonly atField: string\n /** Maps telemetry property id -> value and optional unit dataset columns. */\n readonly properties: Readonly<Record<string, TelemetryProjectionPropertyMapping>>\n}\n\n/** Union of all projection definition types. */\nexport type ProjectionDefinition =\n | ObjectProjectionDefinition\n | LinkProjectionDefinition\n | TelemetryProjectionDefinition\n\nexport interface ProjectionOwnership {\n readonly objects: readonly {\n readonly objectTypeId: string\n readonly existence: boolean\n readonly propertyIds: readonly string[]\n }[]\n readonly links: readonly {\n readonly sourceObjectTypeId: string\n readonly linkId: string\n }[]\n readonly telemetry: readonly {\n readonly objectTypeId: string\n readonly propertyId: string\n }[]\n}\n\n/** Canonical correlation between a projection kind and its materialization protocol. */\nexport type ProjectionProtocolIdentity =\n | { readonly projectionKind: \"object\"; readonly protocol: \"replacement\" }\n | { readonly projectionKind: \"link\"; readonly protocol: \"replacement\" }\n | { readonly projectionKind: \"telemetry\"; readonly protocol: \"telemetry\" }\n\nexport type ProjectionKind = ProjectionProtocolIdentity[\"projectionKind\"]\n\nexport interface ObjectProjectionTarget {\n readonly objectTypeId: string\n}\n\nexport interface LinkProjectionTarget {\n readonly sourceObjectTypeId: string\n readonly targetObjectTypeId: string\n}\n\nexport interface ProjectionTargetByKind {\n readonly object: ObjectProjectionTarget\n readonly link: LinkProjectionTarget\n readonly telemetry: ObjectProjectionTarget\n}\n\n/** Object types affected by one projection, correlated with its projection kind. */\nexport type ProjectionTarget<TKind extends ProjectionKind = ProjectionKind> =\n ProjectionTargetByKind[TKind]\n\n/**\n * Frozen semantic identity used to dispatch one registered projection.\n *\n * Dataset version metadata is attached only when a committed dataset event is routed. Keeping the\n * registry-owned fields together prevents the orchestrator from recomputing ontology semantics.\n */\nexport type ProjectionDispatchDescriptor = ProjectionDispatchDescriptorBase &\n ProjectionProtocolIdentity\n\ninterface ProjectionDispatchDescriptorBase {\n readonly projectionId: string\n readonly datasetId: string\n readonly ontologyRevision: string\n readonly projectionRevision: string\n readonly ownershipHash: string\n}\n\nexport interface ResolvedProjection<TDefinition extends ProjectionDefinition> {\n readonly projectionId: string\n readonly datasetId: string\n readonly projectionRevision: string\n readonly ownershipHash: string\n readonly ownership: ProjectionOwnership\n readonly definition: TDefinition\n}\n",
|
|
6
|
-
"import type { SixbFailure } from \"../../errors/types\"\nimport type {\n PinnedDatasetVersion,\n ProjectionExecution,\n ProjectionMaterializationIdentity,\n ProjectionRunTerminalDecision,\n} from \"../../materialization/model\"\nimport type {\n LinkProjectionTarget,\n ObjectProjectionTarget,\n ProjectionKind,\n ProjectionRunFailureCode,\n ProjectionTarget,\n} from \"../../projections/types\"\n\nexport type { ProjectionRunFailureCode } from \"../../projections/types\"\nexport { PROJECTION_RUN_FAILURE_CODES } from \"../../projections/types\"\n\nexport type ProjectionRunStatus = \"queued\" | \"running\" | \"succeeded\" | \"failed\" | \"cancelled\"\n\nexport interface ProjectionRunProgress {\n /** Physical immutable-version rows consumed, before normalization or semantic materialization. */\n readonly sourceRowsRead: number\n /** Physical rows intentionally skipped because a required mapped value was blank. */\n readonly sourceRowsSkipped: number\n}\n\nconst progressKeyFlags: Record<keyof ProjectionRunProgress, true> = {\n sourceRowsRead: true,\n sourceRowsSkipped: true,\n}\n\nexport const PROJECTION_RUN_PROGRESS_KEYS = Object.keys(\n progressKeyFlags\n) as readonly (keyof ProjectionRunProgress)[]\n\nexport function zeroProjectionRunProgress(): ProjectionRunProgress {\n const progress = {} as Record<keyof ProjectionRunProgress, number>\n for (const key of PROJECTION_RUN_PROGRESS_KEYS) progress[key] = 0\n return progress\n}\n\nexport interface ProjectionTelemetryCheckpoint {\n readonly fixedBatchSize: number\n readonly nextBatchOrdinal: number\n readonly nextRowOffset: number\n readonly inputExhausted: boolean\n}\n\n/**\n * The object a telemetry batch is waiting for, and when this run first found it missing.\n *\n * A projection's dataset can legitimately be materialized before the objects it references, so\n * the run waits instead of failing. The wait needs a start, and the run has no other durable one:\n * `startedAt` is when the run began, which on a batched projection is long before the batch that\n * cannot commit, and `attempt` counts every reclaim including the ones an unreachable queue caused.\n *\n * Cleared by any committed batch, so a run that is making progress never carries a stale wait.\n */\nexport interface ProjectionMissingTarget {\n readonly objectTypeId: string\n readonly objectId: string\n /** The batch that could not commit because of it. */\n readonly batchOrdinal: number\n readonly firstSeenAt: Date\n}\n\ninterface ProjectionRunRecordBase {\n readonly id: string\n readonly projectId: string\n readonly executionId: string\n readonly status: ProjectionRunStatus\n readonly attempt: number\n readonly progress: ProjectionRunProgress\n readonly queuedAt: Date\n readonly startedAt?: Date\n readonly finishedAt?: Date\n readonly error?: SixbFailure<ProjectionRunFailureCode>\n}\n\ntype ProjectionIdentity<TKind extends ProjectionKind> = Extract<\n ProjectionMaterializationIdentity,\n { readonly projectionKind: TKind }\n>\n\nexport type ObjectProjectionRunRecord = ProjectionRunRecordBase & {\n readonly identity: ProjectionIdentity<\"object\">\n readonly target: ObjectProjectionTarget\n readonly telemetryCheckpoint?: never\n readonly missingTarget?: never\n}\n\nexport type LinkProjectionRunRecord = ProjectionRunRecordBase & {\n readonly identity: ProjectionIdentity<\"link\">\n readonly target: LinkProjectionTarget\n readonly telemetryCheckpoint?: never\n readonly missingTarget?: never\n}\n\nexport type TelemetryProjectionRunRecord = ProjectionRunRecordBase & {\n readonly identity: ProjectionIdentity<\"telemetry\">\n readonly target: ObjectProjectionTarget\n readonly telemetryCheckpoint: ProjectionTelemetryCheckpoint\n /**\n * Only telemetry carries this: `MaterializationObjectNotFoundError` is raised by telemetry\n * validation alone, and only a batched protocol has a checkpoint to anchor the wait to.\n */\n readonly missingTarget?: ProjectionMissingTarget\n}\n\n/** Durable projection lifecycle state. The execution token is deliberately returned separately. */\nexport type ProjectionRunRecord =\n | ObjectProjectionRunRecord\n | LinkProjectionRunRecord\n | TelemetryProjectionRunRecord\n\nexport function projectionRunObjectTypesVisible(\n run: ProjectionRunRecord,\n canView: (objectTypeId: string) => boolean\n): boolean {\n const target: ProjectionTarget = run.target\n if (\"sourceObjectTypeId\" in target) {\n return canView(target.sourceObjectTypeId) && canView(target.targetObjectTypeId)\n }\n return canView(target.objectTypeId)\n}\n\ninterface ProjectionRunAdmissionBase {\n readonly id: string\n readonly projectId: string\n readonly executionId: string\n readonly queuedAt?: Date\n}\n\nexport type QueueProjectionRunInput =\n | (ProjectionRunAdmissionBase & {\n readonly identity: ProjectionIdentity<\"object\">\n readonly target: ObjectProjectionRunRecord[\"target\"]\n readonly fixedBatchSize?: never\n })\n | (ProjectionRunAdmissionBase & {\n readonly identity: ProjectionIdentity<\"link\">\n readonly target: LinkProjectionRunRecord[\"target\"]\n readonly fixedBatchSize?: never\n })\n | (ProjectionRunAdmissionBase & {\n readonly identity: ProjectionIdentity<\"telemetry\">\n readonly target: TelemetryProjectionRunRecord[\"target\"]\n readonly fixedBatchSize: number\n })\n\nexport type StartOrReclaimProjectionRunInput = QueueProjectionRunInput extends infer TInput\n ? TInput extends QueueProjectionRunInput\n ? Omit<TInput, \"executionId\" | \"queuedAt\"> & { readonly startedAt?: Date }\n : never\n : never\n\nexport interface FailProjectionRunEnqueueInput {\n readonly id: string\n readonly projectId: string\n readonly finishedAt?: Date\n readonly error: SixbFailure<ProjectionRunFailureCode>\n}\n\nexport interface ProjectionRunClaim {\n readonly run: ProjectionRunRecord\n readonly execution: ProjectionExecution\n}\n\nexport interface LockProjectionRunForMaterializationInput {\n readonly id: string\n readonly projectId: string\n readonly executionToken: string\n readonly identity: ProjectionMaterializationIdentity\n}\n\nexport interface UpdateProjectionRunInput extends LockProjectionRunForMaterializationInput {\n readonly progress: Partial<ProjectionRunProgress>\n}\n\nexport type FinishProjectionRunInput = ProjectionRunTerminalDecision &\n LockProjectionRunForMaterializationInput & {\n readonly finishedAt?: Date\n readonly progress?: Partial<ProjectionRunProgress>\n }\n\nexport interface AdvanceProjectionTelemetryCheckpointInput\n extends LockProjectionRunForMaterializationInput {\n /** Must equal the run's current nextBatchOrdinal. */\n readonly batchOrdinal: number\n /** Physical dataset rows consumed by this batch, including skipped rows. */\n readonly batchRowCount: number\n /** Physical rows intentionally skipped inside this batch. */\n readonly batchRowsSkipped: number\n /** True when this batch consumed the final row of the immutable dataset version. */\n readonly inputExhausted: boolean\n}\n\nexport interface RecordProjectionMissingTargetInput\n extends LockProjectionRunForMaterializationInput {\n readonly missingTarget: ProjectionMissingTarget\n}\n\nexport interface ListProjectionRunsInput {\n readonly projectId: string\n readonly projectionId?: string\n readonly projectionKind?: ProjectionKind\n readonly datasetId?: string\n readonly datasetVersionId?: string\n /**\n * Viewable object type ids. A run is included only if every target type is present. Omit for an\n * unrestricted internal execution; an empty set matches no runs.\n */\n readonly objectTypeIds?: readonly string[]\n readonly statuses?: readonly ProjectionRunStatus[]\n readonly startedAfter?: Date\n readonly startedBefore?: Date\n readonly limit?: number\n readonly offset?: number\n readonly order?: \"asc\" | \"desc\"\n}\n\nexport interface ListProjectionRunsResult {\n readonly runs: readonly ProjectionRunRecord[]\n readonly hasMore: boolean\n readonly total: number\n}\n\nexport interface ListLatestProjectionRunsInput {\n readonly projectId: string\n readonly projectionIds: readonly string[]\n}\n\nexport interface ListLatestProjectionRunsResult {\n readonly runs: readonly ProjectionRunRecord[]\n}\n\nexport interface ProjectionRunStorage {\n queue(input: QueueProjectionRunInput): Promise<ProjectionRunRecord>\n startOrReclaim(input: StartOrReclaimProjectionRunInput): Promise<ProjectionRunClaim>\n failEnqueue(input: FailProjectionRunEnqueueInput): Promise<ProjectionRunRecord>\n /** Transactionally fences the current execution before ontology materialization writes. */\n lockForMaterialization(\n input: LockProjectionRunForMaterializationInput\n ): Promise<ProjectionRunRecord>\n /** Updates physical source progress only. */\n update(input: UpdateProjectionRunInput): Promise<ProjectionRunRecord>\n /**\n * Advances telemetry progress atomically with the corresponding ontology commit.\n *\n * Clears any recorded missing target: a batch that commits is a batch that was not waiting.\n */\n advanceTelemetryCheckpoint(\n input: AdvanceProjectionTelemetryCheckpointInput\n ): Promise<TelemetryProjectionRunRecord>\n /** Records the object a telemetry batch is waiting for, so the wait has a durable start. */\n recordMissingTarget(\n input: RecordProjectionMissingTargetInput\n ): Promise<TelemetryProjectionRunRecord>\n /** Telemetry success also records the worker's EOF observation atomically. */\n finish(input: FinishProjectionRunInput): Promise<ProjectionRunRecord>\n getById(params: { projectId: string; id: string }): Promise<ProjectionRunRecord | null>\n list(input: ListProjectionRunsInput): Promise<ListProjectionRunsResult>\n listLatestByProjectionIds(\n input: ListLatestProjectionRunsInput\n ): Promise<ListLatestProjectionRunsResult>\n}\n\nexport type {\n LinkProjectionTarget,\n ObjectProjectionTarget,\n PinnedDatasetVersion,\n ProjectionExecution,\n ProjectionKind,\n ProjectionMaterializationIdentity,\n ProjectionTarget,\n}\n"
|
|
7
|
-
],
|
|
8
|
-
"mappings": ";;AAGO,IAAM,gCAA+B;AAAA,EAC1C;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;;;ACmBA,IAAM,mBAA8D;AAAA,EAClE,gBAAgB;AAAA,EAChB,mBAAmB;AACrB;AAEO,IAAM,gCAA+B,OAAO,KACjD,gBACF;AAEO,SAAS,0BAAyB,GAA0B;AAAA,EACjE,MAAM,WAAW,CAAC;AAAA,EAClB,WAAW,OAAO;AAAA,IAA8B,SAAS,OAAO;AAAA,EAChE,OAAO;AAAA;AA6EF,SAAS,gCAA+B,CAC7C,KACA,SACS;AAAA,EACT,MAAM,SAA2B,IAAI;AAAA,EACrC,IAAI,wBAAwB,QAAQ;AAAA,IAClC,OAAO,QAAQ,OAAO,kBAAkB,KAAK,QAAQ,OAAO,kBAAkB;AAAA,EAChF;AAAA,EACA,OAAO,QAAQ,OAAO,YAAY;AAAA;",
|
|
9
|
-
"debugId": "6C744C0A44910E5264756E2164756E21",
|
|
10
|
-
"names": []
|
|
11
|
-
}
|