@sixb/core 0.1.16 → 0.1.17
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 +25 -25
- package/dist/actions/types/context.d.ts +2 -2
- package/dist/actions/types/context.d.ts.map +1 -1
- package/dist/actions/worker.js +1 -1
- package/dist/agents/index.js +41 -40
- package/dist/agents/index.js.map +1 -1
- package/dist/auth/index.js +5 -5
- package/dist/authorization/index.js +2 -2
- package/dist/blob-storage/download-urls.d.ts +41 -0
- package/dist/blob-storage/download-urls.d.ts.map +1 -0
- package/dist/blob-storage/execution.d.ts +9 -1
- package/dist/blob-storage/execution.d.ts.map +1 -1
- package/dist/blob-storage/index.js +5 -3
- package/dist/blob-storage/index.js.map +1 -1
- package/dist/blob-storage/internal.d.ts +2 -0
- package/dist/blob-storage/internal.d.ts.map +1 -0
- package/dist/blob-storage/internal.js +11 -0
- package/dist/blob-storage/internal.js.map +9 -0
- package/dist/bootstrap/index.js +45 -44
- package/dist/bootstrap/index.js.map +1 -1
- package/dist/{chunk-8x74221e.js → chunk-10styjgk.js} +18 -13
- package/dist/{chunk-8x74221e.js.map → chunk-10styjgk.js.map} +3 -3
- package/dist/{chunk-hgqpcmyr.js → chunk-1hqwggsn.js} +47 -19
- package/dist/chunk-1hqwggsn.js.map +12 -0
- package/dist/{chunk-zb47r1c8.js → chunk-23xs4qp9.js} +2 -2
- package/dist/{chunk-gmdvns8f.js → chunk-2am3db31.js} +2 -2
- package/dist/{chunk-fj1dvp37.js → chunk-2vhg6ysa.js} +1 -1
- package/dist/{chunk-dp7yk20b.js → chunk-33saed7g.js} +1 -1
- package/dist/{chunk-mdnw7nj8.js → chunk-3rrezgyc.js} +33 -8
- package/dist/chunk-3rrezgyc.js.map +15 -0
- package/dist/{chunk-jgwb25gc.js → chunk-4as3wt1c.js} +13 -5
- package/dist/chunk-4as3wt1c.js.map +12 -0
- package/dist/chunk-4ra628t7.js +88 -0
- package/dist/chunk-4ra628t7.js.map +10 -0
- package/dist/{chunk-chdg6eqq.js → chunk-52c5zb0z.js} +2 -2
- package/dist/{chunk-69kt9q43.js → chunk-5be2ath4.js} +1 -1
- package/dist/{chunk-qnd7ehe5.js → chunk-5thzcb8g.js} +2 -2
- package/dist/{chunk-6z1q7j19.js → chunk-5yd8cchh.js} +1126 -780
- package/dist/chunk-5yd8cchh.js.map +66 -0
- package/dist/{chunk-3q7z9hd4.js → chunk-6wbm6ymz.js} +234 -40
- package/dist/{chunk-3q7z9hd4.js.map → chunk-6wbm6ymz.js.map} +8 -6
- package/dist/{chunk-kvysp909.js → chunk-7ecp4v7a.js} +26 -19
- package/dist/chunk-7ecp4v7a.js.map +17 -0
- package/dist/{chunk-f85hpqnm.js → chunk-99nd4rc1.js} +3 -3
- package/dist/{chunk-f85hpqnm.js.map → chunk-99nd4rc1.js.map} +3 -3
- package/dist/{chunk-dsv8kdgk.js → chunk-9g6jz9kk.js} +5 -5
- package/dist/{chunk-39tqv9hz.js → chunk-9se093qz.js} +5 -6
- package/dist/{chunk-39tqv9hz.js.map → chunk-9se093qz.js.map} +3 -4
- package/dist/{chunk-7g2gjvah.js → chunk-a7er86jd.js} +1 -1
- package/dist/{chunk-zdkcdshk.js → chunk-aq39q04r.js} +41 -3
- package/dist/{chunk-zdkcdshk.js.map → chunk-aq39q04r.js.map} +4 -3
- package/dist/chunk-b9affek3.js +261 -0
- package/dist/chunk-b9affek3.js.map +12 -0
- package/dist/{chunk-b9y8hcm2.js → chunk-c2rga5cx.js} +1 -1
- package/dist/{chunk-f72rbvsb.js → chunk-cnb5kv05.js} +2 -2
- package/dist/chunk-d62kjtbg.js.map +2 -2
- package/dist/{chunk-vjqt7q3a.js → chunk-dam456ve.js} +233 -34
- package/dist/{chunk-vjqt7q3a.js.map → chunk-dam456ve.js.map} +7 -5
- package/dist/{chunk-sbcm1b92.js → chunk-e67ynxcr.js} +3 -3
- package/dist/{chunk-xnx96gfy.js → chunk-ere85b8y.js} +17 -8
- package/dist/chunk-ere85b8y.js.map +15 -0
- package/dist/{chunk-k4kkp58d.js → chunk-ewqa58h9.js} +12 -2
- package/dist/chunk-ewqa58h9.js.map +11 -0
- package/dist/{chunk-cq44v1a6.js → chunk-f1xh7a32.js} +3 -3
- package/dist/{chunk-h4138ww2.js → chunk-fggq3d9k.js} +450 -799
- package/dist/chunk-fggq3d9k.js.map +49 -0
- package/dist/{chunk-kttr5ftm.js → chunk-gf7yht60.js} +3 -3
- package/dist/chunk-h8teetr0.js +9 -0
- package/dist/chunk-h8teetr0.js.map +10 -0
- package/dist/chunk-hn2r7z41.js.map +1 -1
- package/dist/{chunk-nj0020ay.js → chunk-jjrn5v0p.js} +1 -1
- package/dist/{chunk-nvymebc1.js → chunk-jnfxmr3f.js} +1 -1
- package/dist/{chunk-nkbev3tr.js → chunk-k4g51s47.js} +3 -3
- package/dist/{chunk-a0073121.js → chunk-kpx7jrmn.js} +3 -1
- package/dist/chunk-kpx7jrmn.js.map +12 -0
- package/dist/{chunk-h044jb97.js → chunk-pja9jfz6.js} +172 -10
- package/dist/chunk-pja9jfz6.js.map +19 -0
- package/dist/chunk-pqajwytd.js.map +1 -1
- package/dist/{chunk-mr60an99.js → chunk-qczk96d9.js} +22 -2
- package/dist/{chunk-mr60an99.js.map → chunk-qczk96d9.js.map} +3 -3
- package/dist/{chunk-s3csryxe.js → chunk-rj69qcrd.js} +8 -2
- package/dist/chunk-rj69qcrd.js.map +11 -0
- package/dist/{chunk-swxzncrv.js → chunk-rpxz486p.js} +32 -5
- package/dist/{chunk-swxzncrv.js.map → chunk-rpxz486p.js.map} +4 -4
- package/dist/{chunk-tkdbge6v.js → chunk-rx7h5fdx.js} +1 -1
- package/dist/{chunk-tnvafr7g.js → chunk-s7ftxrdr.js} +105 -7
- package/dist/chunk-s7ftxrdr.js.map +22 -0
- package/dist/{chunk-h866d223.js → chunk-sk0hcjsz.js} +1 -1
- package/dist/{chunk-2xvgy3x5.js → chunk-svabwqdq.js} +2 -2
- package/dist/{chunk-667x4drs.js → chunk-t9shqx3w.js} +2 -2
- package/dist/{chunk-40qb8wpe.js → chunk-tjjgy3z4.js} +26 -23
- package/dist/{chunk-40qb8wpe.js.map → chunk-tjjgy3z4.js.map} +3 -3
- package/dist/{chunk-gkxsenvp.js → chunk-vp3z1ckh.js} +31 -7
- package/dist/{chunk-gkxsenvp.js.map → chunk-vp3z1ckh.js.map} +5 -4
- package/dist/{chunk-cxj8y8t0.js → chunk-vre348sb.js} +2 -2
- package/dist/{chunk-vsvrv7n8.js → chunk-w9yycd3t.js} +1 -1
- package/dist/{chunk-g4rbm4a6.js → chunk-wt4szfec.js} +379 -331
- package/dist/chunk-wt4szfec.js.map +14 -0
- package/dist/{chunk-a7ne02hk.js → chunk-xcy5ddha.js} +6 -6
- package/dist/{chunk-zvmr2hqk.js → chunk-xyvy73tj.js} +4 -3
- package/dist/{chunk-zvmr2hqk.js.map → chunk-xyvy73tj.js.map} +3 -3
- package/dist/datasets/write.js +1 -1
- package/dist/execution/agent.js +38 -37
- package/dist/execution/agent.js.map +1 -1
- package/dist/execution/authorized-object-reader.d.ts +3 -1
- package/dist/execution/authorized-object-reader.d.ts.map +1 -1
- package/dist/execution/primitive.js +36 -35
- package/dist/execution/primitive.js.map +2 -2
- package/dist/execution/request.js +37 -36
- package/dist/execution/request.js.map +2 -2
- package/dist/index.d.ts +8 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +62 -59
- package/dist/index.js.map +1 -1
- package/dist/lake-storage/in-memory.d.ts +5 -1
- package/dist/lake-storage/in-memory.d.ts.map +1 -1
- package/dist/lake-storage/index.d.ts +1 -1
- package/dist/lake-storage/index.d.ts.map +1 -1
- package/dist/lake-storage/index.js +2 -2
- package/dist/lake-storage/types.d.ts +26 -0
- package/dist/lake-storage/types.d.ts.map +1 -1
- package/dist/maintenance/ontology-maintenance.d.ts +5 -1
- package/dist/maintenance/ontology-maintenance.d.ts.map +1 -1
- package/dist/maintenance/types.d.ts +1 -4
- package/dist/maintenance/types.d.ts.map +1 -1
- package/dist/materialization/event-envelopes.d.ts +20 -0
- package/dist/materialization/event-envelopes.d.ts.map +1 -0
- package/dist/materialization/events.d.ts +29 -3
- package/dist/materialization/events.d.ts.map +1 -1
- package/dist/materialization/index.d.ts +4 -1
- package/dist/materialization/index.d.ts.map +1 -1
- package/dist/materialization/index.js +9 -3
- package/dist/materialization/index.js.map +1 -1
- package/dist/materializer/edits/plan.d.ts +2 -10
- package/dist/materializer/edits/plan.d.ts.map +1 -1
- package/dist/materializer/effective/build-events.d.ts +5 -21
- package/dist/materializer/effective/build-events.d.ts.map +1 -1
- package/dist/materializer/effective/vector-indexing.d.ts +2 -3
- package/dist/materializer/effective/vector-indexing.d.ts.map +1 -1
- package/dist/materializer/effective/vectors.d.ts +2 -3
- package/dist/materializer/effective/vectors.d.ts.map +1 -1
- package/dist/materializer/execution/scope.d.ts +1 -11
- package/dist/materializer/execution/scope.d.ts.map +1 -1
- package/dist/materializer/execution/work-executor.d.ts +5 -7
- package/dist/materializer/execution/work-executor.d.ts.map +1 -1
- package/dist/materializer/execution/work-records.d.ts +1 -3
- package/dist/materializer/execution/work-records.d.ts.map +1 -1
- package/dist/materializer/index.js +31 -32
- package/dist/materializer/index.js.map +1 -1
- package/dist/materializer/projections/replace.d.ts.map +1 -1
- package/dist/materializer/projections/replacement-plan.d.ts +8 -11
- package/dist/materializer/projections/replacement-plan.d.ts.map +1 -1
- package/dist/materializer/shared/batching.d.ts +5 -0
- package/dist/materializer/shared/batching.d.ts.map +1 -1
- package/dist/materializer/telemetry/plan.d.ts +2 -8
- package/dist/materializer/telemetry/plan.d.ts.map +1 -1
- package/dist/models/audio/catalog.d.ts +20 -0
- package/dist/models/audio/catalog.d.ts.map +1 -0
- package/dist/models/audio/errors.d.ts +8 -0
- package/dist/models/audio/errors.d.ts.map +1 -0
- package/dist/models/audio/file.d.ts +9 -0
- package/dist/models/audio/file.d.ts.map +1 -0
- package/dist/models/audio/runtime.d.ts +8 -0
- package/dist/models/audio/runtime.d.ts.map +1 -0
- package/dist/models/audio/types.d.ts +60 -0
- package/dist/models/audio/types.d.ts.map +1 -0
- package/dist/models/catalog.d.ts +23 -1
- package/dist/models/catalog.d.ts.map +1 -1
- package/dist/models/definitions.d.ts +1 -1
- package/dist/models/definitions.d.ts.map +1 -1
- package/dist/models/events.d.ts +3 -0
- package/dist/models/events.d.ts.map +1 -1
- package/dist/models/execution/index.js +22 -22
- package/dist/models/execution/model-call-admission.d.ts +6 -1
- package/dist/models/execution/model-call-admission.d.ts.map +1 -1
- package/dist/models/execution/model-call-limits.d.ts.map +1 -1
- package/dist/models/execution/model-call-recorder.d.ts.map +1 -1
- package/dist/models/execution/reranking.d.ts +4 -0
- package/dist/models/execution/reranking.d.ts.map +1 -0
- package/dist/models/execution/usage.d.ts.map +1 -1
- package/dist/models/execution.d.ts +2 -1
- package/dist/models/execution.d.ts.map +1 -1
- package/dist/models/generation-types.d.ts +2 -0
- package/dist/models/generation-types.d.ts.map +1 -1
- package/dist/models/index.d.ts +7 -1
- package/dist/models/index.d.ts.map +1 -1
- package/dist/models/index.js +6 -2
- package/dist/models/index.js.map +1 -1
- package/dist/models/pricing.d.ts +2 -2
- package/dist/models/pricing.d.ts.map +1 -1
- package/dist/models/reranking-model.d.ts +49 -0
- package/dist/models/reranking-model.d.ts.map +1 -0
- package/dist/objects/index.js +25 -25
- package/dist/objects/query/executor.d.ts +2 -1
- package/dist/objects/query/executor.d.ts.map +1 -1
- package/dist/objects/query/index.d.ts +1 -1
- package/dist/objects/query/index.d.ts.map +1 -1
- package/dist/objects/query/index.js +22 -22
- package/dist/objects/query/ir.d.ts +8 -1
- package/dist/objects/query/ir.d.ts.map +1 -1
- package/dist/objects/query/normalize.d.ts.map +1 -1
- package/dist/objects/query/planner.d.ts +1 -1
- package/dist/objects/query/planner.d.ts.map +1 -1
- package/dist/objects/query/primary-id.d.ts +7 -0
- package/dist/objects/query/primary-id.d.ts.map +1 -0
- package/dist/objects/query/reranking-executor.d.ts +13 -0
- package/dist/objects/query/reranking-executor.d.ts.map +1 -0
- package/dist/objects/query/reranking-limits.d.ts +3 -0
- package/dist/objects/query/reranking-limits.d.ts.map +1 -0
- package/dist/objects/query/reranking-query.d.ts +4 -0
- package/dist/objects/query/reranking-query.d.ts.map +1 -0
- package/dist/objects/query/validate.d.ts.map +1 -1
- package/dist/objects/sdk/query-builder.d.ts +8 -0
- package/dist/objects/sdk/query-builder.d.ts.map +1 -1
- package/dist/objects/sdk/query-executor.d.ts +2 -2
- package/dist/objects/sdk/query-executor.d.ts.map +1 -1
- package/dist/objects/sdk/runtime-query-executor.d.ts.map +1 -1
- package/dist/objects/vectors/indexing-dispatch.d.ts +21 -0
- package/dist/objects/vectors/indexing-dispatch.d.ts.map +1 -0
- package/dist/objects/vectors/query.d.ts.map +1 -1
- package/dist/ontology/builders.d.ts.map +1 -1
- package/dist/ontology/index.d.ts +1 -1
- package/dist/ontology/index.d.ts.map +1 -1
- package/dist/ontology/index.js +3 -3
- package/dist/ontology/internal.js +2 -2
- package/dist/ontology/query-capabilities.d.ts +1 -0
- package/dist/ontology/query-capabilities.d.ts.map +1 -1
- package/dist/ontology/types.d.ts +20 -0
- package/dist/ontology/types.d.ts.map +1 -1
- package/dist/ontology/validation/query.d.ts.map +1 -1
- package/dist/pipelines/index.js +23 -23
- package/dist/projections/internal.js +22 -22
- package/dist/query.d.ts +4 -2
- package/dist/query.d.ts.map +1 -1
- package/dist/query.js +2 -2
- package/dist/queues/in-memory.d.ts +3 -0
- package/dist/queues/in-memory.d.ts.map +1 -1
- package/dist/queues/index.js +1 -1
- package/dist/queues/types.d.ts +4 -0
- package/dist/queues/types.d.ts.map +1 -1
- package/dist/runtime/host.d.ts +1 -0
- package/dist/runtime/host.d.ts.map +1 -1
- package/dist/runtime/index.d.ts +1 -1
- package/dist/runtime/index.d.ts.map +1 -1
- package/dist/runtime/internal.d.ts +1 -0
- package/dist/runtime/internal.d.ts.map +1 -1
- package/dist/runtime/internal.js +28 -26
- package/dist/runtime/internal.js.map +1 -1
- package/dist/runtime/public-origin.d.ts +10 -0
- package/dist/runtime/public-origin.d.ts.map +1 -0
- package/dist/runtime/sixb.d.ts +1 -0
- package/dist/runtime/sixb.d.ts.map +1 -1
- package/dist/runtime/types.d.ts +12 -2
- package/dist/runtime/types.d.ts.map +1 -1
- package/dist/sandboxes/index.js +5 -5
- package/dist/shares/internal.js +19 -19
- package/dist/storage/agents/provider.js +2 -2
- package/dist/storage/ai-cost/analytics.d.ts +1 -0
- package/dist/storage/ai-cost/analytics.d.ts.map +1 -1
- package/dist/storage/ai-cost/provider.js +3 -3
- package/dist/storage/ai-cost/types.d.ts +1 -1
- package/dist/storage/ai-cost/types.d.ts.map +1 -1
- package/dist/storage/ai-cost/validation.d.ts.map +1 -1
- package/dist/storage/ai-limits/enforcement.js +2 -2
- package/dist/storage/ai-limits/in-memory.d.ts.map +1 -1
- package/dist/storage/ai-limits/provider.d.ts +7 -2
- package/dist/storage/ai-limits/provider.d.ts.map +1 -1
- package/dist/storage/ai-limits/provider.js +4 -2
- package/dist/storage/ai-limits/provider.js.map +1 -1
- package/dist/storage/ai-limits/types.d.ts +3 -0
- package/dist/storage/ai-limits/types.d.ts.map +1 -1
- package/dist/storage/ai-usage/record.d.ts.map +1 -1
- package/dist/storage/ai-usage/types.d.ts +8 -4
- package/dist/storage/ai-usage/types.d.ts.map +1 -1
- package/dist/storage/ai-usage/usage.d.ts.map +1 -1
- package/dist/storage/file-download-grants/in-memory.d.ts +11 -0
- package/dist/storage/file-download-grants/in-memory.d.ts.map +1 -0
- package/dist/storage/file-download-grants/index.d.ts +3 -0
- package/dist/storage/file-download-grants/index.d.ts.map +1 -0
- package/dist/storage/file-download-grants/record.d.ts +11 -0
- package/dist/storage/file-download-grants/record.d.ts.map +1 -0
- package/dist/storage/file-download-grants/types.d.ts +44 -0
- package/dist/storage/file-download-grants/types.d.ts.map +1 -0
- package/dist/storage/file-upload-sessions/provider.js +6 -6
- package/dist/storage/in-memory/index.d.ts +4 -0
- package/dist/storage/in-memory/index.d.ts.map +1 -1
- package/dist/storage/index.d.ts +5 -3
- package/dist/storage/index.d.ts.map +1 -1
- package/dist/storage/index.js +30 -30
- package/dist/storage/index.js.map +1 -1
- package/dist/storage/internal.d.ts +1 -0
- package/dist/storage/internal.d.ts.map +1 -1
- package/dist/storage/internal.js +8 -4
- package/dist/storage/internal.js.map +1 -1
- package/dist/storage/migrations/index.d.ts +1 -1
- package/dist/storage/migrations/index.d.ts.map +1 -1
- package/dist/storage/migrations/migrate-storage.d.ts +3 -3
- package/dist/storage/migrations/migrate-storage.d.ts.map +1 -1
- package/dist/storage/migrations/types.d.ts +7 -0
- package/dist/storage/migrations/types.d.ts.map +1 -1
- package/dist/storage/objects/in-memory/query.d.ts.map +1 -1
- package/dist/storage/objects/in-memory/selected-reader.d.ts.map +1 -1
- package/dist/storage/objects/in-memory/storage.d.ts.map +1 -1
- package/dist/storage/objects/query-preparation.d.ts +39 -0
- package/dist/storage/objects/query-preparation.d.ts.map +1 -0
- package/dist/storage/objects/types.d.ts +2 -0
- package/dist/storage/objects/types.d.ts.map +1 -1
- package/dist/storage/ontology/commits.d.ts +1 -6
- package/dist/storage/ontology/commits.d.ts.map +1 -1
- package/dist/storage/ontology/in-memory/index.d.ts +4 -2
- package/dist/storage/ontology/in-memory/index.d.ts.map +1 -1
- package/dist/storage/ontology/in-memory/materializations-state.d.ts +0 -2
- package/dist/storage/ontology/in-memory/materializations-state.d.ts.map +1 -1
- package/dist/storage/ontology/in-memory/materializations-work.d.ts +1 -3
- package/dist/storage/ontology/in-memory/materializations-work.d.ts.map +1 -1
- package/dist/storage/ontology/in-memory/materializations.d.ts +23 -57
- package/dist/storage/ontology/in-memory/materializations.d.ts.map +1 -1
- package/dist/storage/ontology/in-memory/outbox.d.ts +3 -2
- package/dist/storage/ontology/in-memory/outbox.d.ts.map +1 -1
- package/dist/storage/ontology/in-memory/replacement-plans.d.ts +104 -0
- package/dist/storage/ontology/in-memory/replacement-plans.d.ts.map +1 -0
- package/dist/storage/ontology/in-memory/shared-state.d.ts +17 -2
- package/dist/storage/ontology/in-memory/shared-state.d.ts.map +1 -1
- package/dist/storage/ontology/in-memory/source-roots.d.ts +3 -1
- package/dist/storage/ontology/in-memory/source-roots.d.ts.map +1 -1
- package/dist/storage/ontology/in-memory/sources.d.ts +1 -2
- package/dist/storage/ontology/in-memory/sources.d.ts.map +1 -1
- package/dist/storage/ontology/in-memory/state-reader.d.ts +25 -0
- package/dist/storage/ontology/in-memory/state-reader.d.ts.map +1 -0
- package/dist/storage/ontology/index.d.ts +6 -3
- package/dist/storage/ontology/index.d.ts.map +1 -1
- package/dist/storage/ontology/materializations.d.ts +40 -59
- package/dist/storage/ontology/materializations.d.ts.map +1 -1
- package/dist/storage/ontology/outbox.d.ts +4 -6
- package/dist/storage/ontology/outbox.d.ts.map +1 -1
- package/dist/storage/ontology/provider-work.d.ts +114 -3
- package/dist/storage/ontology/provider-work.d.ts.map +1 -1
- package/dist/storage/ontology/provider.d.ts +14 -39
- package/dist/storage/ontology/provider.d.ts.map +1 -1
- package/dist/storage/ontology/provider.js +26 -12
- package/dist/storage/ontology/provider.js.map +1 -1
- package/dist/storage/ontology/replacement-plans.d.ts +103 -0
- package/dist/storage/ontology/replacement-plans.d.ts.map +1 -0
- package/dist/storage/ontology/sources.d.ts +0 -8
- package/dist/storage/ontology/sources.d.ts.map +1 -1
- package/dist/storage/operation-scope.d.ts.map +1 -1
- package/dist/storage/operation-scope.js +1 -1
- package/dist/storage/projection-runs/in-memory.d.ts.map +1 -1
- package/dist/storage/projection-runs/types.d.ts +2 -0
- package/dist/storage/projection-runs/types.d.ts.map +1 -1
- package/dist/storage/types.d.ts +2 -0
- package/dist/storage/types.d.ts.map +1 -1
- package/dist/storage/workflow-runs/provider.js +6 -6
- package/dist/syncs/index.js +24 -24
- package/dist/testing/ai-cost-storage-contract.d.ts.map +1 -1
- package/dist/testing/ai-limit-storage-contract.d.ts.map +1 -1
- package/dist/testing/ai-usage-storage-contract.d.ts.map +1 -1
- package/dist/testing/file-download-grant-storage-contract.d.ts +9 -0
- package/dist/testing/file-download-grant-storage-contract.d.ts.map +1 -0
- package/dist/testing/index.d.ts +1 -0
- package/dist/testing/index.d.ts.map +1 -1
- package/dist/testing/index.js +2549 -1490
- package/dist/testing/index.js.map +14 -13
- package/dist/testing/lake-storage-contract.d.ts.map +1 -1
- package/dist/testing/materializer-storage-contract.d.ts +14 -0
- package/dist/testing/materializer-storage-contract.d.ts.map +1 -1
- package/dist/testing/object-read-scope-contract.d.ts.map +1 -1
- package/dist/testing/ontology-contract-fixture.d.ts +5 -1
- package/dist/testing/ontology-contract-fixture.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/testing/queues-contract.d.ts.map +1 -1
- package/dist/webhooks/internal.js +20 -20
- package/dist/workers/index.js +15 -17
- package/dist/workers/index.js.map +3 -3
- package/dist/workers/queue-worker.d.ts +3 -2
- package/dist/workers/queue-worker.d.ts.map +1 -1
- package/dist/workflows/index.js +42 -41
- package/dist/workflows/index.js.map +1 -1
- package/package.json +7 -1
- package/src/actions/types/context.ts +5 -2
- package/src/blob-storage/download-urls.ts +138 -0
- package/src/blob-storage/execution.ts +32 -1
- package/src/blob-storage/internal.ts +1 -0
- package/src/execution/authorized-object-reader.ts +8 -1
- package/src/index.ts +25 -0
- package/src/lake-storage/in-memory.ts +38 -9
- package/src/lake-storage/index.ts +2 -0
- package/src/lake-storage/types.ts +30 -0
- package/src/maintenance/ontology-maintenance.ts +50 -23
- package/src/maintenance/types.ts +1 -4
- package/src/materialization/event-envelopes.ts +168 -0
- package/src/materialization/events.ts +40 -4
- package/src/materialization/index.ts +9 -1
- package/src/materializer/README.md +55 -10
- package/src/materializer/edits/commit.ts +3 -19
- package/src/materializer/edits/plan.ts +20 -71
- package/src/materializer/effective/build-events.ts +42 -136
- package/src/materializer/effective/vector-indexing.ts +2 -3
- package/src/materializer/effective/vectors.ts +2 -3
- package/src/materializer/execution/scope.ts +1 -38
- package/src/materializer/execution/work-executor.ts +21 -115
- package/src/materializer/execution/work-records.ts +0 -15
- package/src/materializer/projections/replace.ts +106 -63
- package/src/materializer/projections/replacement-plan.ts +73 -218
- package/src/materializer/shared/batching.ts +7 -0
- package/src/materializer/telemetry/append.ts +2 -14
- package/src/materializer/telemetry/plan.ts +6 -43
- package/src/models/audio/catalog.ts +90 -0
- package/src/models/audio/errors.ts +19 -0
- package/src/models/audio/file.ts +78 -0
- package/src/models/audio/runtime.ts +182 -0
- package/src/models/audio/types.ts +69 -0
- package/src/models/catalog.ts +52 -5
- package/src/models/definitions.ts +8 -1
- package/src/models/events.ts +3 -0
- package/src/models/execution/README.md +20 -1
- package/src/models/execution/model-call-admission.ts +6 -1
- package/src/models/execution/model-call-limits.ts +21 -11
- package/src/models/execution/model-call-recorder.ts +1 -0
- package/src/models/execution/model-call-recovery.ts +1 -0
- package/src/models/execution/reranking.ts +137 -0
- package/src/models/execution/usage.ts +1 -0
- package/src/models/execution.ts +5 -1
- package/src/models/generation-types.ts +2 -0
- package/src/models/index.ts +32 -0
- package/src/models/pricing.ts +2 -1
- package/src/models/reranking-model.ts +114 -0
- package/src/objects/query/executor.ts +42 -2
- package/src/objects/query/explain.ts +8 -0
- package/src/objects/query/index.ts +1 -0
- package/src/objects/query/ir.ts +10 -0
- package/src/objects/query/normalize.ts +2 -0
- package/src/objects/query/planner.ts +12 -1
- package/src/objects/query/primary-id.ts +56 -0
- package/src/objects/query/reranking-executor.ts +91 -0
- package/src/objects/query/reranking-limits.ts +3 -0
- package/src/objects/query/reranking-query.ts +8 -0
- package/src/objects/query/validate.ts +33 -1
- package/src/objects/sdk/query-builder.ts +15 -2
- package/src/objects/sdk/query-executor.ts +2 -2
- package/src/objects/sdk/runtime-query-executor.ts +7 -4
- package/src/objects/vectors/README.md +6 -2
- package/src/objects/vectors/indexing-dispatch.ts +83 -0
- package/src/objects/vectors/query.ts +3 -0
- package/src/ontology/builders.ts +1 -0
- package/src/ontology/index.ts +2 -0
- package/src/ontology/query-capabilities.ts +1 -1
- package/src/ontology/types.ts +21 -0
- package/src/ontology/validation/query.ts +57 -0
- package/src/query.ts +4 -0
- package/src/queues/in-memory.ts +54 -19
- package/src/queues/types.ts +4 -0
- package/src/runtime/host.ts +28 -1
- package/src/runtime/index.ts +1 -0
- package/src/runtime/internal.ts +1 -0
- package/src/runtime/public-origin.ts +33 -0
- package/src/runtime/sixb.ts +13 -2
- package/src/runtime/types.ts +12 -2
- package/src/storage/ai-cost/analytics.ts +2 -0
- package/src/storage/ai-cost/codec.ts +2 -1
- package/src/storage/ai-cost/types.ts +1 -0
- package/src/storage/ai-cost/validation.ts +21 -8
- package/src/storage/ai-limits/in-memory.ts +10 -2
- package/src/storage/ai-limits/provider.ts +29 -2
- package/src/storage/ai-limits/types.ts +3 -0
- package/src/storage/ai-usage/record.ts +9 -0
- package/src/storage/ai-usage/types.ts +8 -4
- package/src/storage/ai-usage/usage.ts +2 -0
- package/src/storage/file-download-grants/in-memory.ts +73 -0
- package/src/storage/file-download-grants/index.ts +8 -0
- package/src/storage/file-download-grants/record.ts +47 -0
- package/src/storage/file-download-grants/types.ts +48 -0
- package/src/storage/in-memory/index.ts +13 -2
- package/src/storage/index.ts +31 -13
- package/src/storage/internal.ts +1 -0
- package/src/storage/migrations/index.ts +1 -0
- package/src/storage/migrations/migrate-storage.ts +36 -12
- package/src/storage/migrations/types.ts +8 -0
- package/src/storage/objects/in-memory/query.ts +2 -0
- package/src/storage/objects/in-memory/selected-reader.ts +1 -0
- package/src/storage/objects/in-memory/storage.ts +1 -0
- package/src/storage/objects/query-preparation.ts +77 -0
- package/src/storage/objects/types.ts +2 -0
- package/src/storage/ontology/commits.ts +1 -6
- package/src/storage/ontology/in-memory/index.ts +28 -9
- package/src/storage/ontology/in-memory/materializations-finalization.ts +35 -68
- package/src/storage/ontology/in-memory/materializations-state.ts +0 -22
- package/src/storage/ontology/in-memory/materializations-work.ts +0 -45
- package/src/storage/ontology/in-memory/materializations.ts +172 -653
- package/src/storage/ontology/in-memory/outbox.ts +37 -29
- package/src/storage/ontology/in-memory/replacement-plans.ts +697 -0
- package/src/storage/ontology/in-memory/shared-state.ts +24 -2
- package/src/storage/ontology/in-memory/source-roots.ts +7 -2
- package/src/storage/ontology/in-memory/sources.ts +7 -33
- package/src/storage/ontology/in-memory/state-reader.ts +245 -0
- package/src/storage/ontology/index.ts +19 -13
- package/src/storage/ontology/materializations.ts +45 -74
- package/src/storage/ontology/outbox.ts +4 -7
- package/src/storage/ontology/provider-header-validation.ts +0 -57
- package/src/storage/ontology/provider-work.ts +381 -90
- package/src/storage/ontology/provider.ts +74 -171
- package/src/storage/ontology/replacement-plans.ts +117 -0
- package/src/storage/ontology/sources.ts +0 -12
- package/src/storage/operation-scope.ts +33 -1
- package/src/storage/projection-runs/in-memory.ts +7 -1
- package/src/storage/projection-runs/types.ts +2 -0
- package/src/storage/types.ts +2 -0
- package/src/testing/ai-cost-storage-contract.ts +1 -0
- package/src/testing/ai-limit-storage-contract.ts +62 -0
- package/src/testing/ai-usage-storage-contract.ts +31 -0
- package/src/testing/file-download-grant-storage-contract.ts +139 -0
- package/src/testing/index.ts +4 -0
- package/src/testing/lake-storage-contract.ts +87 -1
- package/src/testing/materializer-storage-contract.ts +1008 -1
- package/src/testing/object-read-scope-contract.ts +1 -0
- package/src/testing/ontology-contract-fixture.ts +11 -87
- package/src/testing/ontology-storage-contract.ts +70 -39
- package/src/testing/projection-run-storage-contract.ts +14 -0
- package/src/testing/queues-contract.ts +59 -0
- package/src/workers/queue-worker.ts +19 -16
- package/dist/chunk-6z1q7j19.js.map +0 -62
- package/dist/chunk-7ytf06d3.js +0 -113
- package/dist/chunk-7ytf06d3.js.map +0 -10
- package/dist/chunk-a0073121.js.map +0 -12
- package/dist/chunk-g4rbm4a6.js.map +0 -15
- package/dist/chunk-h044jb97.js.map +0 -15
- package/dist/chunk-h4138ww2.js.map +0 -50
- package/dist/chunk-hgqpcmyr.js.map +0 -12
- package/dist/chunk-jgwb25gc.js.map +0 -12
- package/dist/chunk-k4kkp58d.js.map +0 -11
- package/dist/chunk-kvysp909.js.map +0 -17
- package/dist/chunk-mdnw7nj8.js.map +0 -15
- package/dist/chunk-s3csryxe.js.map +0 -11
- package/dist/chunk-tnvafr7g.js.map +0 -19
- package/dist/chunk-xnx96gfy.js.map +0 -15
- package/dist/materializer/execution/plan-stream.d.ts +0 -8
- package/dist/materializer/execution/plan-stream.d.ts.map +0 -1
- package/src/materializer/execution/plan-stream.ts +0 -121
- /package/dist/{chunk-zb47r1c8.js.map → chunk-23xs4qp9.js.map} +0 -0
- /package/dist/{chunk-gmdvns8f.js.map → chunk-2am3db31.js.map} +0 -0
- /package/dist/{chunk-fj1dvp37.js.map → chunk-2vhg6ysa.js.map} +0 -0
- /package/dist/{chunk-dp7yk20b.js.map → chunk-33saed7g.js.map} +0 -0
- /package/dist/{chunk-chdg6eqq.js.map → chunk-52c5zb0z.js.map} +0 -0
- /package/dist/{chunk-69kt9q43.js.map → chunk-5be2ath4.js.map} +0 -0
- /package/dist/{chunk-qnd7ehe5.js.map → chunk-5thzcb8g.js.map} +0 -0
- /package/dist/{chunk-dsv8kdgk.js.map → chunk-9g6jz9kk.js.map} +0 -0
- /package/dist/{chunk-7g2gjvah.js.map → chunk-a7er86jd.js.map} +0 -0
- /package/dist/{chunk-b9y8hcm2.js.map → chunk-c2rga5cx.js.map} +0 -0
- /package/dist/{chunk-f72rbvsb.js.map → chunk-cnb5kv05.js.map} +0 -0
- /package/dist/{chunk-sbcm1b92.js.map → chunk-e67ynxcr.js.map} +0 -0
- /package/dist/{chunk-cq44v1a6.js.map → chunk-f1xh7a32.js.map} +0 -0
- /package/dist/{chunk-kttr5ftm.js.map → chunk-gf7yht60.js.map} +0 -0
- /package/dist/{chunk-nj0020ay.js.map → chunk-jjrn5v0p.js.map} +0 -0
- /package/dist/{chunk-nvymebc1.js.map → chunk-jnfxmr3f.js.map} +0 -0
- /package/dist/{chunk-nkbev3tr.js.map → chunk-k4g51s47.js.map} +0 -0
- /package/dist/{chunk-tkdbge6v.js.map → chunk-rx7h5fdx.js.map} +0 -0
- /package/dist/{chunk-h866d223.js.map → chunk-sk0hcjsz.js.map} +0 -0
- /package/dist/{chunk-2xvgy3x5.js.map → chunk-svabwqdq.js.map} +0 -0
- /package/dist/{chunk-667x4drs.js.map → chunk-t9shqx3w.js.map} +0 -0
- /package/dist/{chunk-cxj8y8t0.js.map → chunk-vre348sb.js.map} +0 -0
- /package/dist/{chunk-vsvrv7n8.js.map → chunk-w9yycd3t.js.map} +0 -0
- /package/dist/{chunk-a7ne02hk.js.map → chunk-xcy5ddha.js.map} +0 -0
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { stableJsonStringify } from "../../../json"
|
|
2
1
|
import {
|
|
3
2
|
MaterializationConflictError,
|
|
4
3
|
MaterializationValidationError,
|
|
@@ -16,7 +15,6 @@ import {
|
|
|
16
15
|
linkScopeSortKey,
|
|
17
16
|
objectRefKey,
|
|
18
17
|
objectRefSortKey,
|
|
19
|
-
projectionEntityKey,
|
|
20
18
|
telemetryPointKey,
|
|
21
19
|
telemetryPointSortKey,
|
|
22
20
|
} from "../../../materialization/refs"
|
|
@@ -24,14 +22,14 @@ import {
|
|
|
24
22
|
getInMemoryObjectMaterializerAdapter,
|
|
25
23
|
type InMemoryObjectStorage,
|
|
26
24
|
} from "../../objects/in-memory"
|
|
27
|
-
import type { ObjectLinkRow } from "../../objects/types"
|
|
28
25
|
import {
|
|
29
26
|
getInMemoryTimeseriesMaterializerAdapter,
|
|
30
27
|
type InMemoryTimeseriesStorage,
|
|
31
28
|
} from "../../timeseries/store"
|
|
32
29
|
import type { OntologyCommitRecord } from "../commits"
|
|
33
30
|
import type {
|
|
34
|
-
|
|
31
|
+
AppliedMaterialization,
|
|
32
|
+
ApplyMaterializationInput,
|
|
35
33
|
ApplyMaterializationResult,
|
|
36
34
|
ExpectedSourceRevision,
|
|
37
35
|
ExpectedTimeseriesPointRevision,
|
|
@@ -41,85 +39,71 @@ import type {
|
|
|
41
39
|
MaterializationLinkScopeRevision,
|
|
42
40
|
MaterializationLinkScopeState,
|
|
43
41
|
MaterializationLinkState,
|
|
44
|
-
MaterializationObjectExistence,
|
|
45
|
-
MaterializationObjectExistenceWorkRecord,
|
|
46
42
|
MaterializationObjectState,
|
|
47
43
|
MaterializationPlanHeader,
|
|
48
44
|
MaterializationPlanWorkRecord,
|
|
49
45
|
MaterializationSession,
|
|
50
46
|
MaterializationStatePage,
|
|
51
|
-
|
|
47
|
+
MaterializationVectorChange,
|
|
48
|
+
MaterializationVectorChangePage,
|
|
52
49
|
MaterializationWorkRecord,
|
|
53
50
|
OntologyMaterializationStorage,
|
|
54
|
-
ReadMaterializationObjectExistenceInput,
|
|
55
|
-
SourceReplacementLinkState,
|
|
56
|
-
SourceReplacementObjectState,
|
|
57
|
-
SourceReplacementStatePage,
|
|
58
51
|
StageMaterializationWorkInput,
|
|
59
52
|
StoredTelemetryPoint,
|
|
60
53
|
StreamMaterializationStateInput,
|
|
61
|
-
|
|
62
|
-
StreamSourceReplacementStateInput,
|
|
54
|
+
StreamMaterializationVectorChangesInput,
|
|
63
55
|
} from "../materializations"
|
|
64
|
-
import type { OntologyMaterializationEvent } from "../outbox"
|
|
65
56
|
import {
|
|
66
|
-
appendScopeSnapshot,
|
|
67
57
|
assertExpectedLinkRevision,
|
|
68
58
|
assertExpectedLinkScopeRevision,
|
|
69
59
|
assertExpectedObjectRevision,
|
|
70
60
|
assertMaterializationHeader,
|
|
71
|
-
|
|
61
|
+
beginMaterializationApply,
|
|
62
|
+
beginMaterializationVectorChanges,
|
|
63
|
+
duplicateMaterializationWork,
|
|
72
64
|
type ProviderMaterializationTransactionLifecycle,
|
|
73
|
-
|
|
65
|
+
prepareMaterializationWork,
|
|
74
66
|
uniqueSorted,
|
|
75
67
|
} from "../provider"
|
|
76
|
-
import type {
|
|
77
|
-
StoredSourceAssertion,
|
|
78
|
-
StoredSourceLinkAssertion,
|
|
79
|
-
StoredSourceObjectAssertion,
|
|
80
|
-
} from "../sources"
|
|
81
68
|
import { assertFinalizationCorrelations } from "./materializations-finalization"
|
|
69
|
+
import { findActiveSourceMaterialization, storedPoint, uniqueBy } from "./materializations-state"
|
|
82
70
|
import {
|
|
83
|
-
addReplacementLink,
|
|
84
|
-
findActiveSourceMaterialization,
|
|
85
|
-
linkRef,
|
|
86
|
-
linkSnapshot,
|
|
87
|
-
objectSnapshot,
|
|
88
|
-
publicLinkOverride,
|
|
89
|
-
publicLinkSlotOverride,
|
|
90
|
-
publicObjectOverride,
|
|
91
|
-
storedPoint,
|
|
92
|
-
storedSourceLink,
|
|
93
|
-
storedSourceObject,
|
|
94
|
-
uniqueBy,
|
|
95
|
-
} from "./materializations-state"
|
|
96
|
-
import {
|
|
97
|
-
assertChunkSequence,
|
|
98
71
|
assertLastCommit,
|
|
99
72
|
assertPageRows,
|
|
100
|
-
assertPlanChunkCorrelations,
|
|
101
|
-
assertWorkRecord,
|
|
102
73
|
compareCardinalityWork,
|
|
103
74
|
compareEventWork,
|
|
104
75
|
comparePlanWork,
|
|
76
|
+
createCardinalityValidator,
|
|
77
|
+
invalidCorrelation,
|
|
78
|
+
type MaterializationPlanChunk,
|
|
105
79
|
materializationChunkRows,
|
|
106
|
-
|
|
80
|
+
materializationOutboxWrite,
|
|
81
|
+
materializationPlanChunk,
|
|
82
|
+
type OntologyOutboxWrite,
|
|
107
83
|
workUniquenessKey,
|
|
108
84
|
} from "./materializations-work"
|
|
85
|
+
import {
|
|
86
|
+
emptyCommitTouches,
|
|
87
|
+
type InMemoryReplacementPlan,
|
|
88
|
+
replacementPlanKey,
|
|
89
|
+
touchPlanItem,
|
|
90
|
+
} from "./replacement-plans"
|
|
109
91
|
import {
|
|
110
92
|
assertTimestamp,
|
|
111
93
|
commitKey,
|
|
112
94
|
commitOriginKey,
|
|
95
|
+
type InMemoryExecutionReader,
|
|
113
96
|
type InMemoryOntologyState,
|
|
114
97
|
type InMemoryOntologyStorageTestHooks,
|
|
115
|
-
type InMemorySourceMaterialization,
|
|
116
98
|
idempotencyKey,
|
|
117
99
|
ontologyCommitOriginSelector,
|
|
118
100
|
outboxKey,
|
|
119
101
|
projectEntityKey,
|
|
120
102
|
sourceMaterializationKey,
|
|
121
103
|
} from "./shared-state"
|
|
122
|
-
import { activateSourceRoots
|
|
104
|
+
import { activateSourceRoots } from "./source-roots"
|
|
105
|
+
import type { InMemoryMaterializationStateReader } from "./state-reader"
|
|
106
|
+
import { vectorObjectKey } from "./vectors"
|
|
123
107
|
|
|
124
108
|
export interface SessionState {
|
|
125
109
|
readonly providerToken: object
|
|
@@ -133,49 +117,15 @@ export interface SessionState {
|
|
|
133
117
|
readonly applyWork: MaterializationPlanWorkRecord[]
|
|
134
118
|
readonly cardinalityWork: MaterializationCardinalityOccupantWorkRecord[]
|
|
135
119
|
readonly eventWork: MaterializationEventWorkRecord[]
|
|
136
|
-
readonly
|
|
137
|
-
readonly outboxEnvelopes: Map<number, OntologyMaterializationEvent>
|
|
138
|
-
readonly workStreams: Record<StreamMaterializationWorkInput["order"], WorkStreamState>
|
|
120
|
+
readonly outboxWrites: Map<number, OntologyOutboxWrite>
|
|
139
121
|
workSealed: boolean
|
|
122
|
+
vectorChangesStreamed: boolean
|
|
123
|
+
applied: boolean
|
|
124
|
+
appliedEventCount: number
|
|
140
125
|
incidentLinksByObject: Map<string, readonly OntologyLinkRef[]> | null
|
|
141
126
|
linkSlotStates: Map<string, MaterializationLinkScopeState> | null
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
export interface WorkStreamState {
|
|
147
|
-
started: boolean
|
|
148
|
-
completed: boolean
|
|
149
|
-
emittedCount: number
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
export interface ReplacementObjectWork {
|
|
153
|
-
readonly ref: OntologyObjectRef
|
|
154
|
-
readonly sortKey: string
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
export interface ReplacementLinkWork {
|
|
158
|
-
readonly ref: OntologyLinkRef
|
|
159
|
-
readonly sortKey: string
|
|
160
|
-
diffRequired: boolean
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
export interface ReplacementSessionState {
|
|
164
|
-
readonly sourceId: string
|
|
165
|
-
readonly candidateMaterializationId: string
|
|
166
|
-
readonly owned: Set<string>
|
|
167
|
-
readonly candidate: InMemorySourceMaterialization
|
|
168
|
-
readonly objects: Map<string, ReplacementObjectWork>
|
|
169
|
-
readonly links: Map<string, ReplacementLinkWork>
|
|
170
|
-
orderedObjects: ReplacementObjectWork[]
|
|
171
|
-
orderedLinks: ReplacementLinkWork[] | null
|
|
172
|
-
readonly affectedScopes: Set<string>
|
|
173
|
-
readonly incidentObjects: Map<string, OntologyObjectRef>
|
|
174
|
-
objectStreamStarted: boolean
|
|
175
|
-
objectStreamCompleted: boolean
|
|
176
|
-
linkStreamStarted: boolean
|
|
177
|
-
linkStreamCompleted: boolean
|
|
178
|
-
linksExpanded: boolean
|
|
127
|
+
/** The durable replacement plan this session applies instead of staged work. */
|
|
128
|
+
readonly plan: InMemoryReplacementPlan | null
|
|
179
129
|
}
|
|
180
130
|
|
|
181
131
|
export class InMemoryOntologyMaterializationStorage implements OntologyMaterializationStorage {
|
|
@@ -186,9 +136,10 @@ export class InMemoryOntologyMaterializationStorage implements OntologyMateriali
|
|
|
186
136
|
private readonly state: InMemoryOntologyState,
|
|
187
137
|
private readonly objects: InMemoryObjectStorage,
|
|
188
138
|
private readonly timeseries: InMemoryTimeseriesStorage,
|
|
139
|
+
private readonly reader: InMemoryMaterializationStateReader,
|
|
189
140
|
private readonly getTransactionToken: () => object | null,
|
|
190
141
|
private readonly getMaterializationLifecycle: () => ProviderMaterializationTransactionLifecycle | null,
|
|
191
|
-
private readonly
|
|
142
|
+
private readonly readExecution: InMemoryExecutionReader,
|
|
192
143
|
private readonly hooks: InMemoryOntologyStorageTestHooks = {}
|
|
193
144
|
) {}
|
|
194
145
|
|
|
@@ -201,7 +152,7 @@ export class InMemoryOntologyMaterializationStorage implements OntologyMateriali
|
|
|
201
152
|
)
|
|
202
153
|
}
|
|
203
154
|
assertMaterializationHeader(input)
|
|
204
|
-
if (!(await this.
|
|
155
|
+
if (!(await this.readExecution(input.commit.projectId, input.commit.executionId))) {
|
|
205
156
|
throw new MaterializationValidationError(
|
|
206
157
|
`Ontology commit execution '${input.commit.executionId}' does not exist in project '${input.commit.projectId}'.`
|
|
207
158
|
)
|
|
@@ -218,11 +169,12 @@ export class InMemoryOntologyMaterializationStorage implements OntologyMateriali
|
|
|
218
169
|
const key = linkScopeSortKey(expected.source, expected.linkId)
|
|
219
170
|
const current =
|
|
220
171
|
expectedScopeRevisions.get(key) ??
|
|
221
|
-
this.
|
|
172
|
+
this.reader.effectiveLinkScope(input.commit.projectId, expected.source, expected.linkId)
|
|
222
173
|
expectedScopeRevisions.set(key, current)
|
|
223
174
|
assertExpectedLinkScopeRevision(current.fingerprint, expected)
|
|
224
175
|
}
|
|
225
176
|
for (const expected of input.expected.points) this.assertPoint(expected, input.commit.projectId)
|
|
177
|
+
const plan = input.plan ? this.requirePlan(input) : null
|
|
226
178
|
|
|
227
179
|
const providerToken = {}
|
|
228
180
|
const session = {
|
|
@@ -237,18 +189,19 @@ export class InMemoryOntologyMaterializationStorage implements OntologyMateriali
|
|
|
237
189
|
applyWork: [],
|
|
238
190
|
cardinalityWork: [],
|
|
239
191
|
eventWork: [],
|
|
240
|
-
|
|
241
|
-
outboxEnvelopes: new Map<number, OntologyMaterializationEvent>(),
|
|
242
|
-
workStreams: {
|
|
243
|
-
apply: { started: false, completed: false, emittedCount: 0 },
|
|
244
|
-
cardinality: { started: false, completed: false, emittedCount: 0 },
|
|
245
|
-
event: { started: false, completed: false, emittedCount: 0 },
|
|
246
|
-
},
|
|
192
|
+
outboxWrites: new Map<number, OntologyOutboxWrite>(),
|
|
247
193
|
workSealed: false,
|
|
194
|
+
vectorChangesStreamed: false,
|
|
195
|
+
applied: false,
|
|
196
|
+
appliedEventCount: 0,
|
|
248
197
|
incidentLinksByObject: null,
|
|
249
198
|
linkSlotStates: new Map(),
|
|
250
|
-
|
|
251
|
-
|
|
199
|
+
plan,
|
|
200
|
+
}
|
|
201
|
+
if (plan) {
|
|
202
|
+
for (const identity of plan.identities.values()) {
|
|
203
|
+
for (const record of structuredClone(identity.records)) this.addWork(session, record)
|
|
204
|
+
}
|
|
252
205
|
}
|
|
253
206
|
this.sessions.set(providerToken, session)
|
|
254
207
|
this.liveSessions.add(session)
|
|
@@ -271,12 +224,9 @@ export class InMemoryOntologyMaterializationStorage implements OntologyMateriali
|
|
|
271
224
|
session.applyWork.length = 0
|
|
272
225
|
session.cardinalityWork.length = 0
|
|
273
226
|
session.eventWork.length = 0
|
|
274
|
-
session.
|
|
275
|
-
session.outboxEnvelopes.clear()
|
|
227
|
+
session.outboxWrites.clear()
|
|
276
228
|
session.incidentLinksByObject = null
|
|
277
229
|
session.linkSlotStates = null
|
|
278
|
-
session.objectExistence.clear()
|
|
279
|
-
session.replacement = null
|
|
280
230
|
this.liveSessions.delete(session)
|
|
281
231
|
session.lifecycle.complete(session.providerToken)
|
|
282
232
|
}
|
|
@@ -294,7 +244,7 @@ export class InMemoryOntologyMaterializationStorage implements OntologyMateriali
|
|
|
294
244
|
this.requireSession(input.session)
|
|
295
245
|
const objects: MaterializationObjectState[] = []
|
|
296
246
|
for (const ref of objectRefs.slice(offset, offset + input.pageRows)) {
|
|
297
|
-
objects.push(await this.objectState(session, ref))
|
|
247
|
+
objects.push(await this.reader.objectState(session.header.commit.projectId, ref))
|
|
298
248
|
}
|
|
299
249
|
this.requireSession(input.session)
|
|
300
250
|
this.hooks.observeBuffer?.("state.object.page", objects.length)
|
|
@@ -306,7 +256,7 @@ export class InMemoryOntologyMaterializationStorage implements OntologyMateriali
|
|
|
306
256
|
this.requireSession(input.session)
|
|
307
257
|
const links: MaterializationLinkState[] = []
|
|
308
258
|
for (const ref of linkRefs.slice(offset, offset + input.pageRows)) {
|
|
309
|
-
links.push(await this.linkState(session, ref))
|
|
259
|
+
links.push(await this.reader.linkState(session.header.commit.projectId, ref))
|
|
310
260
|
}
|
|
311
261
|
this.requireSession(input.session)
|
|
312
262
|
this.hooks.observeBuffer?.("state.link.page", links.length)
|
|
@@ -318,7 +268,8 @@ export class InMemoryOntologyMaterializationStorage implements OntologyMateriali
|
|
|
318
268
|
this.requireSession(input.session)
|
|
319
269
|
const refs = incidentRefs.slice(offset, offset + input.pageRows)
|
|
320
270
|
const links: MaterializationLinkState[] = []
|
|
321
|
-
for (const ref of refs)
|
|
271
|
+
for (const ref of refs)
|
|
272
|
+
links.push(await this.reader.linkState(session.header.commit.projectId, ref))
|
|
322
273
|
this.requireSession(input.session)
|
|
323
274
|
this.hooks.observeBuffer?.("state.incident-link.page", links.length)
|
|
324
275
|
yield { objects: [], links, linkScopes: [], points: [] }
|
|
@@ -358,221 +309,81 @@ export class InMemoryOntologyMaterializationStorage implements OntologyMateriali
|
|
|
358
309
|
}
|
|
359
310
|
}
|
|
360
311
|
|
|
361
|
-
async *streamSourceReplacementState(
|
|
362
|
-
input: StreamSourceReplacementStateInput
|
|
363
|
-
): AsyncIterable<SourceReplacementStatePage> {
|
|
364
|
-
const session = this.requireSession(input.session)
|
|
365
|
-
assertPageRows(input.pageRows)
|
|
366
|
-
const replacement = this.requireReplacement(session, input)
|
|
367
|
-
if (input.entityKind === "object") {
|
|
368
|
-
if (replacement.candidate.projectionKind !== "object") {
|
|
369
|
-
throw new MaterializationConflictError(
|
|
370
|
-
"source-materialization",
|
|
371
|
-
"Link projection replacement cannot stream object state."
|
|
372
|
-
)
|
|
373
|
-
}
|
|
374
|
-
if (replacement.objectStreamStarted)
|
|
375
|
-
throw new MaterializationConflictError(
|
|
376
|
-
"effective-state",
|
|
377
|
-
"Replacement object state may only be streamed once per session."
|
|
378
|
-
)
|
|
379
|
-
replacement.objectStreamStarted = true
|
|
380
|
-
this.hooks.beforeRead?.("source-replacement.object")
|
|
381
|
-
for (let offset = 0; offset < replacement.orderedObjects.length; offset += input.pageRows) {
|
|
382
|
-
this.requireSession(input.session)
|
|
383
|
-
const selected = replacement.orderedObjects.slice(offset, offset + input.pageRows)
|
|
384
|
-
const objects: SourceReplacementObjectState[] = []
|
|
385
|
-
for (const entry of selected) {
|
|
386
|
-
const key = projectionEntityKey({ kind: "object", ref: entry.ref })
|
|
387
|
-
const base = await this.objectState(session, entry.ref)
|
|
388
|
-
objects.push({
|
|
389
|
-
ref: base.ref,
|
|
390
|
-
candidateSource: storedSourceObject(
|
|
391
|
-
input.source.projectionId,
|
|
392
|
-
replacement.candidate.materializationId,
|
|
393
|
-
replacement.candidate.rowsByEntity.get(key)
|
|
394
|
-
),
|
|
395
|
-
override: base.override,
|
|
396
|
-
effective: base.effective,
|
|
397
|
-
latestTelemetry: base.latestTelemetry,
|
|
398
|
-
})
|
|
399
|
-
}
|
|
400
|
-
this.requireSession(input.session)
|
|
401
|
-
this.hooks.observeBuffer?.("replacement.object.page", objects.length)
|
|
402
|
-
yield { objects, links: [] }
|
|
403
|
-
}
|
|
404
|
-
this.requireSession(input.session)
|
|
405
|
-
replacement.objectStreamCompleted = true
|
|
406
|
-
return
|
|
407
|
-
}
|
|
408
|
-
|
|
409
|
-
if (replacement.candidate.projectionKind === "object" && !replacement.objectStreamCompleted) {
|
|
410
|
-
throw new MaterializationConflictError(
|
|
411
|
-
"effective-state",
|
|
412
|
-
"Object projection replacement must fully stream object state before link state."
|
|
413
|
-
)
|
|
414
|
-
}
|
|
415
|
-
if (replacement.linkStreamStarted)
|
|
416
|
-
throw new MaterializationConflictError(
|
|
417
|
-
"effective-state",
|
|
418
|
-
"Replacement link state may only be streamed once per session."
|
|
419
|
-
)
|
|
420
|
-
replacement.linkStreamStarted = true
|
|
421
|
-
this.hooks.beforeRead?.("source-replacement.link")
|
|
422
|
-
this.expandReplacementLinks(session, replacement)
|
|
423
|
-
replacement.orderedLinks ??= [...replacement.links.values()].sort((left, right) =>
|
|
424
|
-
left.sortKey.localeCompare(right.sortKey)
|
|
425
|
-
)
|
|
426
|
-
for (let offset = 0; offset < replacement.orderedLinks.length; offset += input.pageRows) {
|
|
427
|
-
this.requireSession(input.session)
|
|
428
|
-
const selected = replacement.orderedLinks.slice(offset, offset + input.pageRows)
|
|
429
|
-
const links: SourceReplacementLinkState[] = []
|
|
430
|
-
for (const entry of selected) {
|
|
431
|
-
const key = projectionEntityKey({ kind: "link", ref: entry.ref })
|
|
432
|
-
const base = await this.linkState(session, entry.ref)
|
|
433
|
-
const ownedByReplacement = replacement.owned.has(key)
|
|
434
|
-
links.push({
|
|
435
|
-
ref: base.ref,
|
|
436
|
-
candidateSource: ownedByReplacement
|
|
437
|
-
? storedSourceLink(
|
|
438
|
-
input.source.projectionId,
|
|
439
|
-
replacement.candidate.materializationId,
|
|
440
|
-
replacement.candidate.rowsByEntity.get(key)
|
|
441
|
-
)
|
|
442
|
-
: base.source,
|
|
443
|
-
override: base.override,
|
|
444
|
-
slotOverride: base.slotOverride,
|
|
445
|
-
effective: base.effective,
|
|
446
|
-
diffRequired: entry.diffRequired,
|
|
447
|
-
})
|
|
448
|
-
}
|
|
449
|
-
this.requireSession(input.session)
|
|
450
|
-
this.hooks.observeBuffer?.("replacement.link.page", links.length)
|
|
451
|
-
yield { objects: [], links }
|
|
452
|
-
}
|
|
453
|
-
this.requireSession(input.session)
|
|
454
|
-
replacement.linkStreamCompleted = true
|
|
455
|
-
}
|
|
456
|
-
|
|
457
312
|
async stageWork(input: StageMaterializationWorkInput): Promise<void> {
|
|
458
313
|
const session = this.requireSession(input.session)
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
"Materialization work cannot be staged after draining begins."
|
|
463
|
-
)
|
|
464
|
-
}
|
|
465
|
-
const batchKeys = new Set<string>()
|
|
466
|
-
const batchUniqueKeys = new Set<string>()
|
|
467
|
-
for (const record of input.records) {
|
|
468
|
-
assertWorkRecord(record, session.header)
|
|
469
|
-
const uniqueKey = workUniquenessKey(record)
|
|
470
|
-
if (
|
|
471
|
-
batchKeys.has(record.recordKey) ||
|
|
472
|
-
session.work.has(record.recordKey) ||
|
|
473
|
-
batchUniqueKeys.has(uniqueKey) ||
|
|
474
|
-
session.workUniqueKeys.has(uniqueKey)
|
|
475
|
-
) {
|
|
476
|
-
throw new MaterializationConflictError(
|
|
477
|
-
"effective-state",
|
|
478
|
-
`Duplicate materialization work key '${record.recordKey}'.`
|
|
479
|
-
)
|
|
480
|
-
}
|
|
481
|
-
if (
|
|
482
|
-
record.kind === "incident-object" &&
|
|
483
|
-
(!session.replacement || session.replacement.linkStreamStarted)
|
|
484
|
-
) {
|
|
485
|
-
throw new MaterializationConflictError(
|
|
486
|
-
"effective-state",
|
|
487
|
-
"Incident replacement work must be staged before link state is streamed."
|
|
488
|
-
)
|
|
314
|
+
for (const { record, uniqueKey } of prepareMaterializationWork(session, input)) {
|
|
315
|
+
if (session.work.has(record.recordKey) || session.workUniqueKeys.has(uniqueKey)) {
|
|
316
|
+
throw duplicateMaterializationWork(record.recordKey)
|
|
489
317
|
}
|
|
490
|
-
batchKeys.add(record.recordKey)
|
|
491
|
-
batchUniqueKeys.add(uniqueKey)
|
|
492
318
|
}
|
|
493
319
|
const cloned = input.records.map((record) => structuredClone(record))
|
|
494
320
|
this.hooks.observeWork?.(cloned)
|
|
495
|
-
for (const record of cloned)
|
|
496
|
-
session.work.set(record.recordKey, record)
|
|
497
|
-
session.workUniqueKeys.add(workUniquenessKey(record))
|
|
498
|
-
if (record.kind === "plan") session.applyWork.push(record)
|
|
499
|
-
if (record.kind === "cardinality") session.cardinalityWork.push(record)
|
|
500
|
-
if (record.kind === "event") session.eventWork.push(record)
|
|
501
|
-
if (record.kind === "object-existence") {
|
|
502
|
-
session.objectExistence.set(objectRefKey(record.ref), record)
|
|
503
|
-
}
|
|
504
|
-
if (record.kind === "incident-object") {
|
|
505
|
-
const replacement = session.replacement
|
|
506
|
-
if (replacement) {
|
|
507
|
-
replacement.incidentObjects.set(objectRefKey(record.ref), record.ref)
|
|
508
|
-
replacement.linksExpanded = false
|
|
509
|
-
replacement.orderedLinks = null
|
|
510
|
-
}
|
|
511
|
-
}
|
|
512
|
-
}
|
|
321
|
+
for (const record of cloned) this.addWork(session, record)
|
|
513
322
|
this.hooks.observeBuffer?.("work.stage", cloned.length)
|
|
514
323
|
}
|
|
515
324
|
|
|
516
|
-
|
|
325
|
+
private addWork(session: SessionState, record: MaterializationWorkRecord): void {
|
|
326
|
+
session.work.set(record.recordKey, record)
|
|
327
|
+
session.workUniqueKeys.add(workUniquenessKey(record))
|
|
328
|
+
if (record.kind === "plan") session.applyWork.push(record)
|
|
329
|
+
if (record.kind === "cardinality") session.cardinalityWork.push(record)
|
|
330
|
+
if (record.kind === "event") session.eventWork.push(record)
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
async *streamVectorChanges(
|
|
334
|
+
input: StreamMaterializationVectorChangesInput
|
|
335
|
+
): AsyncIterable<MaterializationVectorChangePage> {
|
|
517
336
|
const session = this.requireSession(input.session)
|
|
518
337
|
assertPageRows(input.pageRows)
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
)
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
}
|
|
533
|
-
const records =
|
|
534
|
-
input.order === "apply"
|
|
535
|
-
? session.applyWork
|
|
536
|
-
: input.order === "cardinality"
|
|
537
|
-
? session.cardinalityWork
|
|
538
|
-
: session.eventWork
|
|
539
|
-
for (let offset = 0; offset < records.length; offset += input.pageRows) {
|
|
338
|
+
this.sealWork(session, beginMaterializationVectorChanges)
|
|
339
|
+
const projectId = session.header.commit.projectId
|
|
340
|
+
const profiled = new Set(input.objectTypeIds)
|
|
341
|
+
const changes = session.applyWork.flatMap((record): MaterializationVectorChange[] => {
|
|
342
|
+
const item = record.item
|
|
343
|
+
if (item.kind !== "object-upsert" && item.kind !== "object-delete") return []
|
|
344
|
+
const ref = item.kind === "object-upsert" ? item.value.row.ref : item.value.ref
|
|
345
|
+
return profiled.has(ref.objectTypeId) ||
|
|
346
|
+
(this.state.vectors.get(vectorObjectKey(projectId, ref))?.size ?? 0) > 0
|
|
347
|
+
? [item]
|
|
348
|
+
: []
|
|
349
|
+
})
|
|
350
|
+
for (let offset = 0; offset < changes.length; offset += input.pageRows) {
|
|
540
351
|
this.requireSession(input.session)
|
|
541
|
-
|
|
542
|
-
this.hooks.observeBuffer?.(`work.${input.order}.page`, selected.length)
|
|
543
|
-
stream.emittedCount = offset + selected.length
|
|
544
|
-
yield { records: structuredClone(selected) }
|
|
352
|
+
yield { items: structuredClone(changes.slice(offset, offset + input.pageRows)) }
|
|
545
353
|
}
|
|
546
354
|
this.requireSession(input.session)
|
|
547
|
-
stream.completed = true
|
|
548
355
|
}
|
|
549
356
|
|
|
550
|
-
async
|
|
551
|
-
input: ReadMaterializationObjectExistenceInput
|
|
552
|
-
): Promise<readonly MaterializationObjectExistence[]> {
|
|
357
|
+
async apply(input: ApplyMaterializationInput): Promise<AppliedMaterialization> {
|
|
553
358
|
const session = this.requireSession(input.session)
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
359
|
+
this.sealWork(session, beginMaterializationApply)
|
|
360
|
+
const cardinality = createCardinalityValidator()
|
|
361
|
+
for (const record of session.cardinalityWork) cardinality.accept(record)
|
|
362
|
+
for (let start = 0; start < session.applyWork.length; ) {
|
|
363
|
+
const phase = session.applyWork[start]!.applyPhase
|
|
364
|
+
let end = start
|
|
365
|
+
while (session.applyWork[end]?.applyPhase === phase) end += 1
|
|
366
|
+
const items = session.applyWork.slice(start, end).map((record) => record.item)
|
|
367
|
+
this.writeChunk(session, materializationPlanChunk(items))
|
|
368
|
+
start = end
|
|
369
|
+
}
|
|
370
|
+
const outbox = session.eventWork.map((record, ordinal) =>
|
|
371
|
+
materializationOutboxWrite(session.header.commit, record.draft, ordinal)
|
|
372
|
+
)
|
|
373
|
+
this.writeChunk(session, materializationPlanChunk([], outbox))
|
|
374
|
+
session.appliedEventCount = outbox.length
|
|
375
|
+
return { eventCount: outbox.length }
|
|
562
376
|
}
|
|
563
377
|
|
|
564
|
-
|
|
565
|
-
const session = this.requireSession(input.session)
|
|
378
|
+
private writeChunk(session: SessionState, chunk: MaterializationPlanChunk): void {
|
|
566
379
|
const projectId = session.header.commit.projectId
|
|
567
|
-
|
|
568
|
-
assertChunkSequence(session, input.chunk)
|
|
569
|
-
this.hooks.observeBuffer?.("apply.chunk", materializationChunkRows(input.chunk))
|
|
380
|
+
this.hooks.observeBuffer?.("apply.chunk", materializationChunkRows(chunk))
|
|
570
381
|
const write = (boundary: string, apply: () => void): void => {
|
|
571
382
|
this.hooks.beforeWrite?.(boundary, session.writeOrdinal++)
|
|
572
383
|
apply()
|
|
573
384
|
}
|
|
574
385
|
|
|
575
|
-
for (const item of
|
|
386
|
+
for (const item of chunk.overrides.objects.upserts)
|
|
576
387
|
write("override.object.upsert", () => {
|
|
577
388
|
const key = projectEntityKey(projectId, objectRefKey(item.ref))
|
|
578
389
|
assertLastCommit(
|
|
@@ -592,7 +403,7 @@ export class InMemoryOntologyMaterializationStorage implements OntologyMateriali
|
|
|
592
403
|
})
|
|
593
404
|
)
|
|
594
405
|
})
|
|
595
|
-
for (const item of
|
|
406
|
+
for (const item of chunk.overrides.objects.deletes)
|
|
596
407
|
write("override.object.delete", () => {
|
|
597
408
|
const key = projectEntityKey(projectId, objectRefKey(item.ref))
|
|
598
409
|
assertLastCommit(
|
|
@@ -602,7 +413,7 @@ export class InMemoryOntologyMaterializationStorage implements OntologyMateriali
|
|
|
602
413
|
)
|
|
603
414
|
this.state.objectOverrides.delete(key)
|
|
604
415
|
})
|
|
605
|
-
for (const item of
|
|
416
|
+
for (const item of chunk.overrides.links.edges.upserts)
|
|
606
417
|
write("override.link.upsert", () => {
|
|
607
418
|
const key = projectEntityKey(projectId, linkRefKey(item.ref))
|
|
608
419
|
assertLastCommit(
|
|
@@ -621,7 +432,7 @@ export class InMemoryOntologyMaterializationStorage implements OntologyMateriali
|
|
|
621
432
|
})
|
|
622
433
|
)
|
|
623
434
|
})
|
|
624
|
-
for (const item of
|
|
435
|
+
for (const item of chunk.overrides.links.edges.deletes)
|
|
625
436
|
write("override.link.delete", () => {
|
|
626
437
|
const key = projectEntityKey(projectId, linkRefKey(item.ref))
|
|
627
438
|
assertLastCommit(
|
|
@@ -631,7 +442,7 @@ export class InMemoryOntologyMaterializationStorage implements OntologyMateriali
|
|
|
631
442
|
)
|
|
632
443
|
this.state.linkOverrides.delete(key)
|
|
633
444
|
})
|
|
634
|
-
for (const item of
|
|
445
|
+
for (const item of chunk.overrides.links.slots.upserts)
|
|
635
446
|
write("override.link-slot.upsert", () => {
|
|
636
447
|
const key = projectEntityKey(projectId, linkScopeKey(item.ref.source, item.ref.linkId))
|
|
637
448
|
assertLastCommit(
|
|
@@ -650,7 +461,7 @@ export class InMemoryOntologyMaterializationStorage implements OntologyMateriali
|
|
|
650
461
|
})
|
|
651
462
|
)
|
|
652
463
|
})
|
|
653
|
-
for (const item of
|
|
464
|
+
for (const item of chunk.overrides.links.slots.deletes)
|
|
654
465
|
write("override.link-slot.delete", () => {
|
|
655
466
|
const key = projectEntityKey(projectId, linkScopeKey(item.ref.source, item.ref.linkId))
|
|
656
467
|
assertLastCommit(
|
|
@@ -661,7 +472,7 @@ export class InMemoryOntologyMaterializationStorage implements OntologyMateriali
|
|
|
661
472
|
this.state.linkSlotOverrides.delete(key)
|
|
662
473
|
})
|
|
663
474
|
|
|
664
|
-
for (const item of
|
|
475
|
+
for (const item of chunk.effective.linkDeletes)
|
|
665
476
|
write("effective.link.delete", () => {
|
|
666
477
|
this.assertLinkSync(item.expected, projectId)
|
|
667
478
|
getInMemoryObjectMaterializerAdapter(this.objects).deleteExactLink({
|
|
@@ -673,7 +484,7 @@ export class InMemoryOntologyMaterializationStorage implements OntologyMateriali
|
|
|
673
484
|
targetId: item.ref.target.primaryId,
|
|
674
485
|
})
|
|
675
486
|
})
|
|
676
|
-
for (const item of
|
|
487
|
+
for (const item of chunk.effective.objectDeletes)
|
|
677
488
|
write("effective.object.delete", () => {
|
|
678
489
|
this.assertObjectSync(item.expected, projectId)
|
|
679
490
|
getInMemoryObjectMaterializerAdapter(this.objects).deleteExactObject(
|
|
@@ -682,17 +493,17 @@ export class InMemoryOntologyMaterializationStorage implements OntologyMateriali
|
|
|
682
493
|
item.ref.primaryId
|
|
683
494
|
)
|
|
684
495
|
})
|
|
685
|
-
for (const item of
|
|
496
|
+
for (const item of chunk.effective.objectUpserts)
|
|
686
497
|
write("effective.object.upsert", () => {
|
|
687
498
|
this.assertObjectSync(item.expected, projectId)
|
|
688
499
|
getInMemoryObjectMaterializerAdapter(this.objects).applyExactObject(item.row, projectId)
|
|
689
500
|
})
|
|
690
|
-
for (const item of
|
|
501
|
+
for (const item of chunk.effective.linkUpserts)
|
|
691
502
|
write("effective.link.upsert", () => {
|
|
692
503
|
this.assertLinkSync(item.expected, projectId)
|
|
693
504
|
getInMemoryObjectMaterializerAdapter(this.objects).applyExactLink(item.row, projectId)
|
|
694
505
|
})
|
|
695
|
-
for (const item of
|
|
506
|
+
for (const item of chunk.timeseries.pointUpserts)
|
|
696
507
|
write("timeseries.point.upsert", () => {
|
|
697
508
|
this.assertPoint(item.expected, projectId)
|
|
698
509
|
getInMemoryTimeseriesMaterializerAdapter(this.timeseries).applyExactPoint(
|
|
@@ -700,32 +511,28 @@ export class InMemoryOntologyMaterializationStorage implements OntologyMateriali
|
|
|
700
511
|
item.point
|
|
701
512
|
)
|
|
702
513
|
})
|
|
703
|
-
for (const item of
|
|
514
|
+
for (const item of chunk.outbox)
|
|
704
515
|
write("outbox.insert", () => {
|
|
705
|
-
const envelope = item.envelope
|
|
706
|
-
if (envelope.projectId !== projectId || envelope.commitId !== session.header.commit.id) {
|
|
707
|
-
throw new MaterializationValidationError(
|
|
708
|
-
"Outbox event does not correlate with its materialization commit."
|
|
709
|
-
)
|
|
710
|
-
}
|
|
711
|
-
assertTimestamp(item.availableAt, "Outbox availableAt")
|
|
712
516
|
assertTimestamp(item.createdAt, "Outbox createdAt")
|
|
713
|
-
|
|
714
|
-
const key = outboxKey(projectId, envelope.id)
|
|
517
|
+
const key = outboxKey(projectId, item.id)
|
|
715
518
|
if (this.state.outbox.has(key)) {
|
|
716
519
|
throw new MaterializationConflictError(
|
|
717
520
|
"effective-state",
|
|
718
|
-
`Duplicate outbox event '${
|
|
521
|
+
`Duplicate outbox event '${item.id}'.`
|
|
719
522
|
)
|
|
720
523
|
}
|
|
721
|
-
if (session.
|
|
524
|
+
if (session.outboxWrites.has(item.commitOrdinal))
|
|
722
525
|
throw new MaterializationConflictError(
|
|
723
526
|
"effective-state",
|
|
724
527
|
"Duplicate outbox commit ordinal."
|
|
725
528
|
)
|
|
726
529
|
this.state.outbox.set(key, {
|
|
727
|
-
|
|
728
|
-
|
|
530
|
+
projectId,
|
|
531
|
+
id: item.id,
|
|
532
|
+
commitId: session.header.commit.id,
|
|
533
|
+
commitOrdinal: item.commitOrdinal,
|
|
534
|
+
event: structuredClone(item.event),
|
|
535
|
+
availableAt: item.createdAt,
|
|
729
536
|
attempts: 0,
|
|
730
537
|
leaseId: null,
|
|
731
538
|
leaseExpiresAt: null,
|
|
@@ -733,11 +540,8 @@ export class InMemoryOntologyMaterializationStorage implements OntologyMateriali
|
|
|
733
540
|
lastFailure: null,
|
|
734
541
|
createdAt: item.createdAt,
|
|
735
542
|
})
|
|
736
|
-
session.
|
|
543
|
+
session.outboxWrites.set(item.commitOrdinal, structuredClone(item))
|
|
737
544
|
})
|
|
738
|
-
for (const item of materializationPlanItems(input.chunk)) {
|
|
739
|
-
session.appliedPlanItems.push(stableJsonStringify(item))
|
|
740
|
-
}
|
|
741
545
|
}
|
|
742
546
|
|
|
743
547
|
async finalize(input: FinalizeMaterializationInput): Promise<ApplyMaterializationResult> {
|
|
@@ -748,6 +552,8 @@ export class InMemoryOntologyMaterializationStorage implements OntologyMateriali
|
|
|
748
552
|
this.assertCommitAbsent(session.header)
|
|
749
553
|
assertFinalizationCorrelations(session, input.finalization, this.state, this.objects)
|
|
750
554
|
this.hooks.beforeWrite?.("finalize", session.writeOrdinal++)
|
|
555
|
+
const touches = emptyCommitTouches(commit.projectId)
|
|
556
|
+
for (const record of session.applyWork) touchPlanItem(touches, record.item)
|
|
751
557
|
for (const activation of input.finalization.sourceActivations) {
|
|
752
558
|
this.hooks.beforeWrite?.("source.activate", session.writeOrdinal++)
|
|
753
559
|
assertTimestamp(activation.datasetVersion.createdAt, "Source dataset version createdAt")
|
|
@@ -785,7 +591,7 @@ export class InMemoryOntologyMaterializationStorage implements OntologyMateriali
|
|
|
785
591
|
}
|
|
786
592
|
)
|
|
787
593
|
}
|
|
788
|
-
activateSourceRoots(this.state, candidate, activation)
|
|
594
|
+
activateSourceRoots(this.state, candidate, activation, touches)
|
|
789
595
|
this.state.sourceMaterializations.set(candidateKey, {
|
|
790
596
|
...candidate,
|
|
791
597
|
status: "active",
|
|
@@ -795,11 +601,21 @@ export class InMemoryOntologyMaterializationStorage implements OntologyMateriali
|
|
|
795
601
|
updatedAt: activation.updatedAt,
|
|
796
602
|
})
|
|
797
603
|
}
|
|
604
|
+
if (session.plan) {
|
|
605
|
+
this.state.replacementPlans.delete(
|
|
606
|
+
replacementPlanKey({
|
|
607
|
+
projectId: commit.projectId,
|
|
608
|
+
source: { projectionId: session.plan.sourceId },
|
|
609
|
+
materializationId: session.plan.materializationId,
|
|
610
|
+
})
|
|
611
|
+
)
|
|
612
|
+
}
|
|
798
613
|
const record = {
|
|
799
614
|
...structuredClone(commit),
|
|
800
615
|
result: structuredClone(input.finalization.result),
|
|
801
616
|
} as OntologyCommitRecord
|
|
802
617
|
this.state.commitsById.set(commitKey(commit.projectId, commit.id), record)
|
|
618
|
+
this.state.commitTouches.set(this.state.commitsById.size, touches)
|
|
803
619
|
this.state.commitIdByIdempotency.set(
|
|
804
620
|
idempotencyKey(commit.projectId, commit.idempotencyKey),
|
|
805
621
|
commit.id
|
|
@@ -825,6 +641,40 @@ export class InMemoryOntologyMaterializationStorage implements OntologyMateriali
|
|
|
825
641
|
}
|
|
826
642
|
}
|
|
827
643
|
|
|
644
|
+
/** Begins a sealing step, and puts the work in canonical order the first time it seals. */
|
|
645
|
+
private sealWork(session: SessionState, begin: (state: SessionState) => void): void {
|
|
646
|
+
const sealed = session.workSealed
|
|
647
|
+
begin(session)
|
|
648
|
+
if (sealed) return
|
|
649
|
+
session.applyWork.sort(comparePlanWork)
|
|
650
|
+
session.cardinalityWork.sort(compareCardinalityWork)
|
|
651
|
+
session.eventWork.sort(compareEventWork)
|
|
652
|
+
}
|
|
653
|
+
|
|
654
|
+
/** The fresh, fully planned plan a projection commit applies, with exactly its commit. */
|
|
655
|
+
private requirePlan(header: MaterializationPlanHeader): InMemoryReplacementPlan {
|
|
656
|
+
const { commit, plan: ref } = header
|
|
657
|
+
const plan = ref
|
|
658
|
+
? this.state.replacementPlans.get(replacementPlanKey({ projectId: commit.projectId, ...ref }))
|
|
659
|
+
: undefined
|
|
660
|
+
if (!plan || commit.intent.kind !== "projection") {
|
|
661
|
+
throw new MaterializationConflictError(
|
|
662
|
+
"source-materialization",
|
|
663
|
+
"A plan-bound session needs the open plan of a projection candidate."
|
|
664
|
+
)
|
|
665
|
+
}
|
|
666
|
+
if (plan.commitId !== commit.id || plan.committedAt !== commit.committedAt) {
|
|
667
|
+
invalidCorrelation("A plan-bound session must begin with the commit its plan carries.")
|
|
668
|
+
}
|
|
669
|
+
if (
|
|
670
|
+
plan.watermark !== this.state.commitsById.size ||
|
|
671
|
+
[...plan.identities.values()].some((identity) => identity.plannedRevision === null)
|
|
672
|
+
) {
|
|
673
|
+
invalidCorrelation("A replacement plan applies only fully planned and just refreshed.")
|
|
674
|
+
}
|
|
675
|
+
return plan
|
|
676
|
+
}
|
|
677
|
+
|
|
828
678
|
private requireSession(session: MaterializationSession): SessionState {
|
|
829
679
|
const value = this.sessions.get(session.providerToken)
|
|
830
680
|
if (
|
|
@@ -841,146 +691,6 @@ export class InMemoryOntologyMaterializationStorage implements OntologyMateriali
|
|
|
841
691
|
return value
|
|
842
692
|
}
|
|
843
693
|
|
|
844
|
-
private requireReplacement(
|
|
845
|
-
session: SessionState,
|
|
846
|
-
input: StreamSourceReplacementStateInput
|
|
847
|
-
): ReplacementSessionState {
|
|
848
|
-
if (session.replacement) {
|
|
849
|
-
if (
|
|
850
|
-
session.replacement.sourceId !== input.source.projectionId ||
|
|
851
|
-
session.replacement.candidateMaterializationId !== input.candidateMaterializationId
|
|
852
|
-
) {
|
|
853
|
-
throw new MaterializationConflictError(
|
|
854
|
-
"source-materialization",
|
|
855
|
-
"Materialization session already owns another replacement union."
|
|
856
|
-
)
|
|
857
|
-
}
|
|
858
|
-
return session.replacement
|
|
859
|
-
}
|
|
860
|
-
const projectId = session.header.commit.projectId
|
|
861
|
-
const sourceId = input.source.projectionId
|
|
862
|
-
const candidate = this.state.sourceMaterializations.get(
|
|
863
|
-
sourceMaterializationKey(projectId, sourceId, input.candidateMaterializationId)
|
|
864
|
-
)
|
|
865
|
-
if (!candidate || candidate.status !== "ready") {
|
|
866
|
-
throw new MaterializationConflictError(
|
|
867
|
-
"source-materialization",
|
|
868
|
-
`Candidate source materialization '${input.candidateMaterializationId}' is missing or is not ready.`
|
|
869
|
-
)
|
|
870
|
-
}
|
|
871
|
-
const previous = findActiveSourceMaterialization(this.state, projectId, sourceId)
|
|
872
|
-
if (
|
|
873
|
-
candidate.protocol !== "replacement" ||
|
|
874
|
-
(previous &&
|
|
875
|
-
(previous.protocol !== candidate.protocol ||
|
|
876
|
-
previous.projectionKind !== candidate.projectionKind))
|
|
877
|
-
) {
|
|
878
|
-
throw new MaterializationConflictError(
|
|
879
|
-
"source-materialization",
|
|
880
|
-
"Source replacement kind or protocol does not match its active materialization."
|
|
881
|
-
)
|
|
882
|
-
}
|
|
883
|
-
const replacement: ReplacementSessionState = {
|
|
884
|
-
sourceId,
|
|
885
|
-
candidateMaterializationId: input.candidateMaterializationId,
|
|
886
|
-
owned: new Set(),
|
|
887
|
-
candidate,
|
|
888
|
-
objects: new Map(),
|
|
889
|
-
links: new Map(),
|
|
890
|
-
orderedObjects: [],
|
|
891
|
-
orderedLinks: null,
|
|
892
|
-
affectedScopes: new Set(),
|
|
893
|
-
incidentObjects: new Map(),
|
|
894
|
-
objectStreamStarted: false,
|
|
895
|
-
objectStreamCompleted: false,
|
|
896
|
-
linkStreamStarted: false,
|
|
897
|
-
linkStreamCompleted: false,
|
|
898
|
-
linksExpanded: false,
|
|
899
|
-
}
|
|
900
|
-
for (const rows of [
|
|
901
|
-
previousSourceRows(this.state, candidate),
|
|
902
|
-
candidate.rowsByEntity.values(),
|
|
903
|
-
]) {
|
|
904
|
-
for (const row of rows) {
|
|
905
|
-
replacement.owned.add(projectionEntityKey(row.assertion))
|
|
906
|
-
if (row.assertion.kind === "object") {
|
|
907
|
-
const ref = row.assertion.ref
|
|
908
|
-
replacement.objects.set(objectRefKey(ref), { ref, sortKey: objectRefSortKey(ref) })
|
|
909
|
-
} else {
|
|
910
|
-
addReplacementLink(replacement, row.assertion.ref, true)
|
|
911
|
-
}
|
|
912
|
-
}
|
|
913
|
-
}
|
|
914
|
-
replacement.orderedObjects = [...replacement.objects.values()].sort((left, right) =>
|
|
915
|
-
left.sortKey.localeCompare(right.sortKey)
|
|
916
|
-
)
|
|
917
|
-
session.replacement = replacement
|
|
918
|
-
return replacement
|
|
919
|
-
}
|
|
920
|
-
|
|
921
|
-
private expandReplacementLinks(
|
|
922
|
-
session: SessionState,
|
|
923
|
-
replacement: ReplacementSessionState
|
|
924
|
-
): void {
|
|
925
|
-
if (replacement.linksExpanded) return
|
|
926
|
-
const projectId = session.header.commit.projectId
|
|
927
|
-
const incident = replacement.incidentObjects
|
|
928
|
-
const touchesIncident = (ref: OntologyLinkRef): boolean =>
|
|
929
|
-
incident.has(objectRefKey(ref.source)) || incident.has(objectRefKey(ref.target))
|
|
930
|
-
|
|
931
|
-
const adapter = getInMemoryObjectMaterializerAdapter(this.objects)
|
|
932
|
-
if (incident.size > 0) {
|
|
933
|
-
adapter.visitExactLinks(projectId, (row) => {
|
|
934
|
-
const ref = linkRef(row)
|
|
935
|
-
if (touchesIncident(ref)) addReplacementLink(replacement, ref, true)
|
|
936
|
-
})
|
|
937
|
-
for (const override of this.state.linkOverrides.values()) {
|
|
938
|
-
if (override.projectId !== projectId) continue
|
|
939
|
-
if (touchesIncident(override.ref)) addReplacementLink(replacement, override.ref, true)
|
|
940
|
-
}
|
|
941
|
-
for (const override of this.state.linkSlotOverrides.values()) {
|
|
942
|
-
if (override.projectId !== projectId) continue
|
|
943
|
-
const ref = {
|
|
944
|
-
source: override.ref.source,
|
|
945
|
-
linkId: override.ref.linkId,
|
|
946
|
-
target: override.value.target,
|
|
947
|
-
}
|
|
948
|
-
if (touchesIncident(ref)) addReplacementLink(replacement, ref, true)
|
|
949
|
-
}
|
|
950
|
-
for (const [scopeKey, rows] of this.state.activeSourceLinkScopes) {
|
|
951
|
-
if (JSON.parse(scopeKey)[0] !== projectId) continue
|
|
952
|
-
for (const row of rows.values()) {
|
|
953
|
-
if (row.assertion.kind === "link" && touchesIncident(row.assertion.ref)) {
|
|
954
|
-
addReplacementLink(replacement, row.assertion.ref, true)
|
|
955
|
-
}
|
|
956
|
-
}
|
|
957
|
-
}
|
|
958
|
-
}
|
|
959
|
-
const scopes = new Map<string, { source: OntologyObjectRef; linkId: string }>()
|
|
960
|
-
for (const { ref } of replacement.links.values()) {
|
|
961
|
-
const key = linkScopeSortKey(ref.source, ref.linkId)
|
|
962
|
-
if (replacement.affectedScopes.has(key)) scopes.set(key, ref)
|
|
963
|
-
}
|
|
964
|
-
for (const scope of scopes.values()) {
|
|
965
|
-
adapter.visitExactScopeLinks(
|
|
966
|
-
projectId,
|
|
967
|
-
scope.source.objectTypeId,
|
|
968
|
-
scope.source.primaryId,
|
|
969
|
-
scope.linkId,
|
|
970
|
-
(row) => {
|
|
971
|
-
addReplacementLink(replacement, linkRef(row), false)
|
|
972
|
-
}
|
|
973
|
-
)
|
|
974
|
-
const override = this.state.linkSlotOverrides.get(
|
|
975
|
-
projectEntityKey(projectId, linkScopeKey(scope.source, scope.linkId))
|
|
976
|
-
)
|
|
977
|
-
if (override)
|
|
978
|
-
addReplacementLink(replacement, { ...scope, target: override.value.target }, false)
|
|
979
|
-
}
|
|
980
|
-
replacement.linksExpanded = true
|
|
981
|
-
replacement.orderedLinks = null
|
|
982
|
-
}
|
|
983
|
-
|
|
984
694
|
private assertCommitAbsent(header: MaterializationPlanHeader): void {
|
|
985
695
|
if (this.state.commitsById.has(commitKey(header.commit.projectId, header.commit.id))) {
|
|
986
696
|
throw new MaterializationConflictError(
|
|
@@ -1069,62 +779,6 @@ export class InMemoryOntologyMaterializationStorage implements OntologyMateriali
|
|
|
1069
779
|
}
|
|
1070
780
|
}
|
|
1071
781
|
|
|
1072
|
-
private async objectState(
|
|
1073
|
-
session: SessionState,
|
|
1074
|
-
ref: OntologyObjectRef
|
|
1075
|
-
): Promise<MaterializationObjectState> {
|
|
1076
|
-
const projectId = session.header.commit.projectId
|
|
1077
|
-
const row = await this.objects.getByPrimaryId({
|
|
1078
|
-
projectId,
|
|
1079
|
-
objectTypeId: ref.objectTypeId,
|
|
1080
|
-
primaryId: ref.primaryId,
|
|
1081
|
-
})
|
|
1082
|
-
return {
|
|
1083
|
-
ref: structuredClone(ref),
|
|
1084
|
-
source: this.findActiveObjectSource(projectId, ref),
|
|
1085
|
-
override: structuredClone(
|
|
1086
|
-
publicObjectOverride(
|
|
1087
|
-
this.state.objectOverrides.get(projectEntityKey(projectId, objectRefKey(ref)))
|
|
1088
|
-
)
|
|
1089
|
-
),
|
|
1090
|
-
effective: row ? objectSnapshot(row) : null,
|
|
1091
|
-
latestTelemetry: getInMemoryTimeseriesMaterializerAdapter(this.timeseries)
|
|
1092
|
-
.listLatestForObject(projectId, ref.objectTypeId, ref.primaryId)
|
|
1093
|
-
.map(storedPoint),
|
|
1094
|
-
}
|
|
1095
|
-
}
|
|
1096
|
-
|
|
1097
|
-
private async linkState(
|
|
1098
|
-
session: SessionState,
|
|
1099
|
-
ref: OntologyLinkRef
|
|
1100
|
-
): Promise<MaterializationLinkState> {
|
|
1101
|
-
const projectId = session.header.commit.projectId
|
|
1102
|
-
const row = getInMemoryObjectMaterializerAdapter(this.objects).getExactLinkRow(projectId, {
|
|
1103
|
-
sourceTypeId: ref.source.objectTypeId,
|
|
1104
|
-
sourceId: ref.source.primaryId,
|
|
1105
|
-
linkId: ref.linkId,
|
|
1106
|
-
targetTypeId: ref.target.objectTypeId,
|
|
1107
|
-
targetId: ref.target.primaryId,
|
|
1108
|
-
})
|
|
1109
|
-
return {
|
|
1110
|
-
ref: structuredClone(ref),
|
|
1111
|
-
source: this.findActiveLinkSource(projectId, ref),
|
|
1112
|
-
override: structuredClone(
|
|
1113
|
-
publicLinkOverride(
|
|
1114
|
-
this.state.linkOverrides.get(projectEntityKey(projectId, linkRefKey(ref)))
|
|
1115
|
-
)
|
|
1116
|
-
),
|
|
1117
|
-
slotOverride: structuredClone(
|
|
1118
|
-
publicLinkSlotOverride(
|
|
1119
|
-
this.state.linkSlotOverrides.get(
|
|
1120
|
-
projectEntityKey(projectId, linkScopeKey(ref.source, ref.linkId))
|
|
1121
|
-
)
|
|
1122
|
-
)
|
|
1123
|
-
),
|
|
1124
|
-
effective: row ? linkSnapshot(row) : null,
|
|
1125
|
-
}
|
|
1126
|
-
}
|
|
1127
|
-
|
|
1128
782
|
private linkSlotState(
|
|
1129
783
|
session: SessionState,
|
|
1130
784
|
source: OntologyObjectRef,
|
|
@@ -1134,109 +788,17 @@ export class InMemoryOntologyMaterializationStorage implements OntologyMateriali
|
|
|
1134
788
|
const key = linkScopeSortKey(source, linkId)
|
|
1135
789
|
const existing = session.linkSlotStates.get(key)
|
|
1136
790
|
if (existing) return structuredClone(existing)
|
|
1137
|
-
const computed = this.
|
|
791
|
+
const computed = this.reader.linkSlotState(session.header.commit.projectId, source, linkId)
|
|
1138
792
|
session.linkSlotStates.set(key, computed)
|
|
1139
793
|
return structuredClone(computed)
|
|
1140
794
|
}
|
|
1141
795
|
|
|
1142
|
-
private computeLinkSlotState(
|
|
1143
|
-
projectId: string,
|
|
1144
|
-
source: OntologyObjectRef,
|
|
1145
|
-
linkId: string
|
|
1146
|
-
): MaterializationLinkScopeState {
|
|
1147
|
-
const value = this.computeEffectiveLinkScope(projectId, source, linkId)
|
|
1148
|
-
return {
|
|
1149
|
-
...value,
|
|
1150
|
-
sourceAssertion: this.findActiveLinkScopeSource(projectId, source, linkId),
|
|
1151
|
-
override: structuredClone(
|
|
1152
|
-
publicLinkSlotOverride(
|
|
1153
|
-
this.state.linkSlotOverrides.get(
|
|
1154
|
-
projectEntityKey(projectId, linkScopeKey(source, linkId))
|
|
1155
|
-
)
|
|
1156
|
-
)
|
|
1157
|
-
),
|
|
1158
|
-
}
|
|
1159
|
-
}
|
|
1160
|
-
|
|
1161
|
-
private computeEffectiveLinkScope(
|
|
1162
|
-
projectId: string,
|
|
1163
|
-
source: OntologyObjectRef,
|
|
1164
|
-
linkId: string
|
|
1165
|
-
): MaterializationLinkScopeRevision & Pick<MaterializationLinkScopeState, "effective"> {
|
|
1166
|
-
const rows: ObjectLinkRow[] = []
|
|
1167
|
-
getInMemoryObjectMaterializerAdapter(this.objects).visitExactScopeLinks(
|
|
1168
|
-
projectId,
|
|
1169
|
-
source.objectTypeId,
|
|
1170
|
-
source.primaryId,
|
|
1171
|
-
linkId,
|
|
1172
|
-
(row) => rows.push(row)
|
|
1173
|
-
)
|
|
1174
|
-
rows.sort((left, right) =>
|
|
1175
|
-
linkRefSortKey(linkRef(left)).localeCompare(linkRefSortKey(linkRef(right)))
|
|
1176
|
-
)
|
|
1177
|
-
const accumulator = startScopeAccumulator(source, linkId)
|
|
1178
|
-
for (let offset = 0; offset < rows.length; offset += 1_000) {
|
|
1179
|
-
const page = rows.slice(offset, offset + 1_000)
|
|
1180
|
-
this.hooks.observeBuffer?.("state.link-scope.page", page.length)
|
|
1181
|
-
for (const row of page) {
|
|
1182
|
-
appendScopeSnapshot(accumulator, linkSnapshot(row))
|
|
1183
|
-
}
|
|
1184
|
-
}
|
|
1185
|
-
const effective = rows.length === 1 ? linkSnapshot(rows[0]!) : null
|
|
1186
|
-
return {
|
|
1187
|
-
...finishScopeAccumulator(accumulator),
|
|
1188
|
-
effective,
|
|
1189
|
-
}
|
|
1190
|
-
}
|
|
1191
|
-
|
|
1192
|
-
private findActiveLinkScopeSource(
|
|
1193
|
-
projectId: string,
|
|
1194
|
-
source: OntologyObjectRef,
|
|
1195
|
-
linkId: string
|
|
1196
|
-
): StoredSourceLinkAssertion | null {
|
|
1197
|
-
const rows = this.state.activeSourceLinkScopes.get(
|
|
1198
|
-
projectEntityKey(projectId, linkScopeSortKey(source, linkId))
|
|
1199
|
-
)
|
|
1200
|
-
if (rows && rows.size > 1)
|
|
1201
|
-
throw new MaterializationConflictError(
|
|
1202
|
-
"source-materialization",
|
|
1203
|
-
`Multiple active source links assert cardinality-one scope '${source.objectTypeId}.${linkId}'.`
|
|
1204
|
-
)
|
|
1205
|
-
return structuredClone(rows?.values().next().value ?? null)
|
|
1206
|
-
}
|
|
1207
|
-
|
|
1208
|
-
private findActiveObjectSource(
|
|
1209
|
-
projectId: string,
|
|
1210
|
-
ref: OntologyObjectRef
|
|
1211
|
-
): StoredSourceObjectAssertion | null {
|
|
1212
|
-
const found = this.findActiveSource(projectId, projectionEntityKey({ kind: "object", ref }))
|
|
1213
|
-
return found?.assertion.kind === "object" ? (found as StoredSourceObjectAssertion) : null
|
|
1214
|
-
}
|
|
1215
|
-
|
|
1216
|
-
private findActiveLinkSource(
|
|
1217
|
-
projectId: string,
|
|
1218
|
-
ref: OntologyLinkRef
|
|
1219
|
-
): StoredSourceLinkAssertion | null {
|
|
1220
|
-
const found = this.findActiveSource(projectId, projectionEntityKey({ kind: "link", ref }))
|
|
1221
|
-
return found?.assertion.kind === "link" ? (found as StoredSourceLinkAssertion) : null
|
|
1222
|
-
}
|
|
1223
|
-
|
|
1224
|
-
private findActiveSource(projectId: string, entityKey: string): StoredSourceAssertion | null {
|
|
1225
|
-
const rows = this.state.activeSourceRows.get(projectEntityKey(projectId, entityKey))
|
|
1226
|
-
if (rows && rows.size > 1)
|
|
1227
|
-
throw new MaterializationConflictError(
|
|
1228
|
-
"source-materialization",
|
|
1229
|
-
`Multiple active sources assert ${entityKey}.`
|
|
1230
|
-
)
|
|
1231
|
-
return structuredClone(rows?.values().next().value ?? null)
|
|
1232
|
-
}
|
|
1233
|
-
|
|
1234
796
|
private incidentLinkRefs(
|
|
1235
797
|
session: SessionState,
|
|
1236
798
|
objects: readonly OntologyObjectRef[]
|
|
1237
799
|
): readonly OntologyLinkRef[] {
|
|
1238
800
|
if (objects.length === 0) return []
|
|
1239
|
-
session.incidentLinksByObject ??= this.
|
|
801
|
+
session.incidentLinksByObject ??= this.reader.incidentLinkIndex(session.header.commit.projectId)
|
|
1240
802
|
const selected = new Map<string, OntologyLinkRef>()
|
|
1241
803
|
for (const object of objects) {
|
|
1242
804
|
for (const ref of session.incidentLinksByObject.get(objectRefKey(object)) ?? []) {
|
|
@@ -1247,47 +809,4 @@ export class InMemoryOntologyMaterializationStorage implements OntologyMateriali
|
|
|
1247
809
|
.sort(([left], [right]) => left.localeCompare(right))
|
|
1248
810
|
.map(([, ref]) => ref)
|
|
1249
811
|
}
|
|
1250
|
-
|
|
1251
|
-
private buildIncidentLinkIndex(projectId: string): Map<string, readonly OntologyLinkRef[]> {
|
|
1252
|
-
const mutable = new Map<string, Map<string, OntologyLinkRef>>()
|
|
1253
|
-
const consider = (ref: OntologyLinkRef): void => {
|
|
1254
|
-
const sortKey = linkRefSortKey(ref)
|
|
1255
|
-
for (const endpoint of [ref.source, ref.target]) {
|
|
1256
|
-
const key = objectRefKey(endpoint)
|
|
1257
|
-
const links = mutable.get(key) ?? new Map<string, OntologyLinkRef>()
|
|
1258
|
-
links.set(sortKey, structuredClone(ref))
|
|
1259
|
-
mutable.set(key, links)
|
|
1260
|
-
}
|
|
1261
|
-
}
|
|
1262
|
-
getInMemoryObjectMaterializerAdapter(this.objects).visitExactLinks(projectId, (row) =>
|
|
1263
|
-
consider(linkRef(row))
|
|
1264
|
-
)
|
|
1265
|
-
for (const override of this.state.linkOverrides.values()) {
|
|
1266
|
-
if (override.projectId === projectId) consider(override.ref)
|
|
1267
|
-
}
|
|
1268
|
-
for (const override of this.state.linkSlotOverrides.values()) {
|
|
1269
|
-
if (override.projectId !== projectId) continue
|
|
1270
|
-
consider({
|
|
1271
|
-
source: override.ref.source,
|
|
1272
|
-
linkId: override.ref.linkId,
|
|
1273
|
-
target: override.value.target,
|
|
1274
|
-
})
|
|
1275
|
-
}
|
|
1276
|
-
for (const [scopeKey, rows] of this.state.activeSourceLinkScopes) {
|
|
1277
|
-
if (JSON.parse(scopeKey)[0] !== projectId) continue
|
|
1278
|
-
for (const row of rows.values()) {
|
|
1279
|
-
if (row.assertion.kind === "link") consider(row.assertion.ref)
|
|
1280
|
-
}
|
|
1281
|
-
}
|
|
1282
|
-
const index = new Map<string, readonly OntologyLinkRef[]>()
|
|
1283
|
-
for (const [objectKey, refs] of mutable) {
|
|
1284
|
-
index.set(
|
|
1285
|
-
objectKey,
|
|
1286
|
-
[...refs.entries()]
|
|
1287
|
-
.sort(([left], [right]) => left.localeCompare(right))
|
|
1288
|
-
.map(([, ref]) => ref)
|
|
1289
|
-
)
|
|
1290
|
-
}
|
|
1291
|
-
return index
|
|
1292
|
-
}
|
|
1293
812
|
}
|