@sixb/core 0.1.16 → 0.1.18
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 +30 -27
- package/dist/actions/index.js.map +1 -1
- package/dist/actions/read-facade.d.ts +1 -1
- package/dist/actions/types/context.d.ts +2 -2
- package/dist/actions/types/context.d.ts.map +1 -1
- package/dist/actions/validation.d.ts.map +1 -1
- package/dist/actions/worker.js +6 -2
- package/dist/actions/worker.js.map +3 -3
- package/dist/agents/adapters.d.ts +7 -0
- package/dist/agents/adapters.d.ts.map +1 -1
- package/dist/agents/authority.d.ts +7 -0
- package/dist/agents/authority.d.ts.map +1 -1
- package/dist/agents/context/entries.d.ts +10 -1
- package/dist/agents/context/entries.d.ts.map +1 -1
- package/dist/agents/context/index.d.ts +1 -1
- package/dist/agents/context/index.d.ts.map +1 -1
- package/dist/agents/context/index.js +4 -2
- package/dist/agents/context/index.js.map +1 -1
- package/dist/agents/context-compaction.d.ts.map +1 -1
- package/dist/agents/errors.d.ts +1 -1
- package/dist/agents/errors.d.ts.map +1 -1
- package/dist/agents/index.d.ts +6 -4
- package/dist/agents/index.d.ts.map +1 -1
- package/dist/agents/index.js +54 -46
- package/dist/agents/index.js.map +1 -1
- package/dist/agents/message.d.ts +8 -1
- package/dist/agents/message.d.ts.map +1 -1
- package/dist/agents/request.d.ts +19 -5
- package/dist/agents/request.d.ts.map +1 -1
- package/dist/agents/skills.d.ts +41 -0
- package/dist/agents/skills.d.ts.map +1 -0
- package/dist/agents/streams/index.js +1 -1
- package/dist/agents/streams/internal.js +1 -1
- package/dist/agents/types.d.ts +33 -4
- package/dist/agents/types.d.ts.map +1 -1
- package/dist/auth/index.js +9 -6
- package/dist/auth/index.js.map +1 -1
- package/dist/auth/runtime.d.ts.map +1 -1
- package/dist/auth/types.d.ts +6 -0
- package/dist/auth/types.d.ts.map +1 -1
- package/dist/authorization/index.js +5 -3
- package/dist/authorization/index.js.map +1 -1
- package/dist/authorization/resolve.d.ts +1 -1
- package/dist/authorization/resolve.d.ts.map +1 -1
- package/dist/authorization/types.d.ts +7 -0
- package/dist/authorization/types.d.ts.map +1 -1
- package/dist/blob-storage/browser.js +1 -1
- 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/file-content.d.ts +18 -0
- package/dist/blob-storage/file-content.d.ts.map +1 -0
- package/dist/blob-storage/index.d.ts +1 -1
- package/dist/blob-storage/index.d.ts.map +1 -1
- package/dist/blob-storage/index.js +6 -4
- package/dist/blob-storage/index.js.map +1 -1
- package/dist/blob-storage/internal.d.ts +4 -0
- package/dist/blob-storage/internal.d.ts.map +1 -0
- package/dist/blob-storage/internal.js +23 -0
- package/dist/blob-storage/internal.js.map +9 -0
- package/dist/blob-storage/media-type.d.ts +8 -0
- package/dist/blob-storage/media-type.d.ts.map +1 -0
- package/dist/blob-storage/types.d.ts +12 -1
- package/dist/blob-storage/types.d.ts.map +1 -1
- package/dist/blob-storage/validation.d.ts +6 -0
- package/dist/blob-storage/validation.d.ts.map +1 -1
- package/dist/bootstrap/agent-context.d.ts +33 -0
- package/dist/bootstrap/agent-context.d.ts.map +1 -0
- package/dist/bootstrap/discovery.d.ts +23 -3
- package/dist/bootstrap/discovery.d.ts.map +1 -1
- package/dist/bootstrap/index.d.ts +2 -1
- package/dist/bootstrap/index.d.ts.map +1 -1
- package/dist/bootstrap/index.js +287 -75
- package/dist/bootstrap/index.js.map +4 -3
- package/dist/bootstrap/ontology-type-manifest.d.ts.map +1 -1
- package/dist/{chunk-kttr5ftm.js → chunk-1b1f2d5f.js} +23 -6
- package/dist/chunk-1b1f2d5f.js.map +12 -0
- package/dist/{chunk-hgqpcmyr.js → chunk-1hqwggsn.js} +47 -19
- package/dist/chunk-1hqwggsn.js.map +12 -0
- package/dist/{chunk-9vx5e9g1.js → chunk-1sr8ryzk.js} +3 -3
- package/dist/chunk-1sr8ryzk.js.map +11 -0
- package/dist/{chunk-4gmng3vf.js → chunk-22v5bpz3.js} +1 -1
- package/dist/{chunk-tnvafr7g.js → chunk-29yx306f.js} +124 -9
- package/dist/chunk-29yx306f.js.map +22 -0
- package/dist/{chunk-fj1dvp37.js → chunk-2vhg6ysa.js} +1 -1
- package/dist/chunk-3zxk45er.js +152 -0
- package/dist/chunk-3zxk45er.js.map +11 -0
- package/dist/{chunk-gmdvns8f.js → chunk-48e3cn2d.js} +2 -2
- package/dist/{chunk-jgwb25gc.js → chunk-4as3wt1c.js} +13 -5
- package/dist/chunk-4as3wt1c.js.map +12 -0
- package/dist/{chunk-91kcnbf0.js → chunk-6gmfggss.js} +22 -9
- package/dist/chunk-6gmfggss.js.map +10 -0
- package/dist/{chunk-2xvgy3x5.js → chunk-6h5m9xjx.js} +43 -415
- package/dist/{chunk-2xvgy3x5.js.map → chunk-6h5m9xjx.js.map} +7 -11
- package/dist/{chunk-cq44v1a6.js → chunk-7hpdd6r9.js} +3 -3
- 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-b9affek3.js +261 -0
- package/dist/chunk-b9affek3.js.map +12 -0
- package/dist/{chunk-zvmr2hqk.js → chunk-bs7sqkre.js} +10 -4
- package/dist/chunk-bs7sqkre.js.map +12 -0
- package/dist/{chunk-rb143ggb.js → chunk-bwjcehza.js} +1 -1
- package/dist/{chunk-667x4drs.js → chunk-d0eb5yy6.js} +143 -7
- package/dist/chunk-d0eb5yy6.js.map +14 -0
- package/dist/chunk-d62kjtbg.js.map +2 -2
- package/dist/{chunk-gkxsenvp.js → chunk-de4z2bj6.js} +31 -7
- package/dist/{chunk-gkxsenvp.js.map → chunk-de4z2bj6.js.map} +5 -4
- package/dist/{chunk-mdnw7nj8.js → chunk-dnmadg9k.js} +35 -10
- package/dist/chunk-dnmadg9k.js.map +15 -0
- package/dist/chunk-enpsx8k5.js +127 -0
- package/dist/chunk-enpsx8k5.js.map +10 -0
- 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-7g2gjvah.js → chunk-ex496vct.js} +1 -1
- package/dist/{chunk-nvymebc1.js → chunk-f1zxad2t.js} +1 -1
- package/dist/{chunk-3q7z9hd4.js → chunk-fe52eczz.js} +483 -101
- package/dist/chunk-fe52eczz.js.map +49 -0
- package/dist/{chunk-8x74221e.js → chunk-fx93hd2n.js} +79 -32
- package/dist/chunk-fx93hd2n.js.map +20 -0
- package/dist/{chunk-39tqv9hz.js → chunk-gc4ntf7d.js} +6 -7
- package/dist/{chunk-39tqv9hz.js.map → chunk-gc4ntf7d.js.map} +3 -4
- package/dist/chunk-h8teetr0.js +9 -0
- package/dist/chunk-h8teetr0.js.map +10 -0
- package/dist/{chunk-98cw09sw.js → chunk-hkc3jct7.js} +4 -2
- package/dist/chunk-hkc3jct7.js.map +10 -0
- package/dist/chunk-hn2r7z41.js.map +1 -1
- package/dist/{chunk-h044jb97.js → chunk-htr6wjmv.js} +282 -58
- package/dist/chunk-htr6wjmv.js.map +19 -0
- package/dist/{chunk-h3v76ams.js → chunk-jhm3zsa7.js} +25 -2
- package/dist/chunk-jhm3zsa7.js.map +12 -0
- package/dist/{chunk-chdg6eqq.js → chunk-k6hrnf35.js} +5 -5
- package/dist/chunk-k6hrnf35.js.map +10 -0
- package/dist/{chunk-a0073121.js → chunk-kpx7jrmn.js} +3 -1
- package/dist/chunk-kpx7jrmn.js.map +12 -0
- package/dist/{chunk-b9y8hcm2.js → chunk-mfs23znk.js} +1 -1
- package/dist/{chunk-kvysp909.js → chunk-ny3xyvcn.js} +32 -19
- package/dist/chunk-ny3xyvcn.js.map +17 -0
- package/dist/{chunk-h4138ww2.js → chunk-p0dqwj3n.js} +450 -799
- package/dist/chunk-p0dqwj3n.js.map +49 -0
- package/dist/{chunk-f72rbvsb.js → chunk-p844e0rn.js} +23 -8
- package/dist/chunk-p844e0rn.js.map +19 -0
- package/dist/{chunk-dmn70ztd.js → chunk-pfp1txq2.js} +25 -6
- package/dist/chunk-pfp1txq2.js.map +11 -0
- package/dist/chunk-pqajwytd.js.map +3 -3
- 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-69kt9q43.js → chunk-qkbx3tf6.js} +17 -128
- package/dist/{chunk-69kt9q43.js.map → chunk-qkbx3tf6.js.map} +6 -7
- package/dist/{chunk-h866d223.js → chunk-qkvz64nd.js} +2 -2
- package/dist/{chunk-vsvrv7n8.js → chunk-qmnnhde6.js} +4 -8
- package/dist/{chunk-vsvrv7n8.js.map → chunk-qmnnhde6.js.map} +3 -3
- package/dist/{chunk-6z1q7j19.js → chunk-qq90g05n.js} +1128 -782
- package/dist/chunk-qq90g05n.js.map +66 -0
- package/dist/{chunk-40qb8wpe.js → chunk-qxvp5epv.js} +84 -29
- package/dist/{chunk-40qb8wpe.js.map → chunk-qxvp5epv.js.map} +10 -9
- package/dist/chunk-rdghfsss.js.map +2 -2
- package/dist/{chunk-s3csryxe.js → chunk-rj69qcrd.js} +8 -2
- package/dist/chunk-rj69qcrd.js.map +11 -0
- package/dist/{chunk-tkdbge6v.js → chunk-rt9p8m9t.js} +1 -1
- package/dist/{chunk-cd234ba4.js → chunk-rz53yb4v.js} +10 -5
- package/dist/chunk-rz53yb4v.js.map +14 -0
- package/dist/{chunk-a7ne02hk.js → chunk-s4jhg8a3.js} +351 -296
- package/dist/chunk-s4jhg8a3.js.map +15 -0
- package/dist/{chunk-69266efg.js → chunk-s54c868q.js} +12 -4
- package/dist/chunk-s54c868q.js.map +12 -0
- package/dist/{chunk-dsv8kdgk.js → chunk-tffvfy6s.js} +8 -7
- package/dist/{chunk-dsv8kdgk.js.map → chunk-tffvfy6s.js.map} +3 -3
- package/dist/{chunk-sbcm1b92.js → chunk-v6xpd60t.js} +3 -3
- package/dist/{chunk-nj0020ay.js → chunk-vgk3hknm.js} +1 -1
- package/dist/{chunk-qnd7ehe5.js → chunk-vx2yp45y.js} +2 -2
- package/dist/{chunk-vjqt7q3a.js → chunk-vz3gc1tm.js} +607 -45
- package/dist/chunk-vz3gc1tm.js.map +41 -0
- package/dist/{chunk-g4rbm4a6.js → chunk-wt4szfec.js} +379 -331
- package/dist/chunk-wt4szfec.js.map +14 -0
- package/dist/chunk-xt1zt7gv.js +471 -0
- package/dist/chunk-xt1zt7gv.js.map +13 -0
- package/dist/{chunk-swxzncrv.js → chunk-y05543x6.js} +51 -8
- package/dist/{chunk-swxzncrv.js.map → chunk-y05543x6.js.map} +5 -5
- package/dist/{chunk-zdkcdshk.js → chunk-y9jmd7e5.js} +41 -3
- package/dist/{chunk-zdkcdshk.js.map → chunk-y9jmd7e5.js.map} +4 -3
- package/dist/{chunk-nkbev3tr.js → chunk-yv9czyfr.js} +3 -3
- package/dist/{chunk-z5rnrmz1.js → chunk-yw9pyg66.js} +5 -3
- package/dist/chunk-yw9pyg66.js.map +11 -0
- package/dist/{chunk-cxj8y8t0.js → chunk-za5yd58j.js} +2 -2
- package/dist/{chunk-zb47r1c8.js → chunk-zb77kjth.js} +3 -3
- package/dist/{chunk-dp7yk20b.js → chunk-zxawp1n2.js} +1 -1
- package/dist/datasets/builders.d.ts +12 -1
- package/dist/datasets/builders.d.ts.map +1 -1
- package/dist/datasets/execution.d.ts +27 -1
- package/dist/datasets/execution.d.ts.map +1 -1
- package/dist/datasets/index.d.ts +1 -1
- package/dist/datasets/index.d.ts.map +1 -1
- package/dist/datasets/types.d.ts +2 -0
- package/dist/datasets/types.d.ts.map +1 -1
- package/dist/datasets/write.d.ts +5 -0
- package/dist/datasets/write.d.ts.map +1 -1
- package/dist/datasets/write.js +10 -5
- package/dist/datasets/write.js.map +1 -1
- package/dist/edits/properties.d.ts.map +1 -1
- package/dist/events/execution.d.ts +2 -1
- package/dist/events/execution.d.ts.map +1 -1
- package/dist/events/types/objects.d.ts +5 -0
- package/dist/events/types/objects.d.ts.map +1 -1
- package/dist/execution/agent.d.ts +10 -0
- package/dist/execution/agent.d.ts.map +1 -1
- package/dist/execution/agent.js +49 -43
- package/dist/execution/agent.js.map +1 -1
- package/dist/execution/authorized-object-reader.d.ts +9 -2
- package/dist/execution/authorized-object-reader.d.ts.map +1 -1
- package/dist/execution/primitive.js +45 -41
- package/dist/execution/primitive.js.map +2 -2
- package/dist/execution/request.js +46 -42
- package/dist/execution/request.js.map +2 -2
- package/dist/http/api-routes.d.ts.map +1 -1
- package/dist/http/index.js +1 -1
- package/dist/index.d.ts +16 -11
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +79 -71
- 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 +8 -5
- package/dist/lake-storage/index.js.map +1 -1
- 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 +35 -33
- 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 +24 -2
- 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/binding.d.ts +6 -0
- package/dist/models/execution/binding.d.ts.map +1 -1
- package/dist/models/execution/index.js +27 -24
- package/dist/models/execution/index.js.map +1 -1
- 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 +4 -0
- 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/language-model.d.ts +6 -0
- package/dist/models/language-model.d.ts.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/context/index.d.ts +1 -1
- package/dist/objects/context/index.d.ts.map +1 -1
- package/dist/objects/context/types.d.ts +6 -0
- package/dist/objects/context/types.d.ts.map +1 -1
- package/dist/objects/execution.d.ts +2 -1
- package/dist/objects/execution.d.ts.map +1 -1
- package/dist/objects/index.js +31 -27
- package/dist/objects/index.js.map +1 -1
- package/dist/objects/materializer-adapter.d.ts.map +1 -1
- package/dist/objects/object/upsert-batch.d.ts.map +1 -1
- package/dist/objects/object/upsert.d.ts.map +1 -1
- package/dist/objects/property-clearance.d.ts +41 -0
- package/dist/objects/property-clearance.d.ts.map +1 -0
- package/dist/objects/query/executor.d.ts +5 -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 +27 -24
- package/dist/objects/query/index.js.map +1 -1
- 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 +10 -1
- package/dist/objects/query/validate.d.ts.map +1 -1
- package/dist/objects/sdk/file-handle.d.ts +6 -0
- package/dist/objects/sdk/file-handle.d.ts.map +1 -0
- package/dist/objects/sdk/object-handle.d.ts +2 -2
- package/dist/objects/sdk/object-handle.d.ts.map +1 -1
- package/dist/objects/sdk/object-set.d.ts +2 -0
- package/dist/objects/sdk/object-set.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 +12 -1
- package/dist/ontology/builders.d.ts.map +1 -1
- package/dist/ontology/docs-markdown.d.ts +35 -0
- package/dist/ontology/docs-markdown.d.ts.map +1 -0
- package/dist/ontology/docs.d.ts +50 -0
- package/dist/ontology/docs.d.ts.map +1 -0
- package/dist/ontology/index.d.ts +1 -1
- package/dist/ontology/index.d.ts.map +1 -1
- package/dist/ontology/index.js +7 -4
- package/dist/ontology/index.js.map +1 -1
- package/dist/ontology/inference/index.d.ts +19 -0
- package/dist/ontology/inference/index.d.ts.map +1 -1
- package/dist/ontology/internal.d.ts +3 -1
- package/dist/ontology/internal.d.ts.map +1 -1
- package/dist/ontology/internal.js +276 -3
- package/dist/ontology/internal.js.map +4 -3
- package/dist/ontology/query-capabilities.d.ts +1 -0
- package/dist/ontology/query-capabilities.d.ts.map +1 -1
- package/dist/ontology/tokens.d.ts +8 -1
- package/dist/ontology/tokens.d.ts.map +1 -1
- package/dist/ontology/types.d.ts +25 -0
- package/dist/ontology/types.d.ts.map +1 -1
- package/dist/ontology/validation/index.d.ts +1 -1
- package/dist/ontology/validation/index.d.ts.map +1 -1
- package/dist/ontology/validation/query.d.ts.map +1 -1
- package/dist/ontology/validation/schema.d.ts +7 -0
- package/dist/ontology/validation/schema.d.ts.map +1 -1
- package/dist/pipelines/index.js +29 -26
- package/dist/pipelines/index.js.map +1 -1
- package/dist/projections/internal.js +27 -24
- package/dist/projections/internal.js.map +1 -1
- 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/create.d.ts +11 -2
- package/dist/runtime/create.d.ts.map +1 -1
- package/dist/runtime/definitions.d.ts +3 -1
- package/dist/runtime/definitions.d.ts.map +1 -1
- package/dist/runtime/host.d.ts +14 -2
- 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 +32 -27
- package/dist/runtime/internal.js.map +1 -1
- package/dist/runtime/locale.d.ts +9 -0
- package/dist/runtime/locale.d.ts.map +1 -0
- package/dist/runtime/public-origin.d.ts +10 -0
- package/dist/runtime/public-origin.d.ts.map +1 -0
- package/dist/runtime/resolve-definitions.d.ts +4 -2
- package/dist/runtime/resolve-definitions.d.ts.map +1 -1
- package/dist/runtime/sixb.d.ts +1 -0
- package/dist/runtime/sixb.d.ts.map +1 -1
- package/dist/runtime/types.d.ts +42 -5
- package/dist/runtime/types.d.ts.map +1 -1
- package/dist/sandboxes/index.js +7 -6
- package/dist/sandboxes/index.js.map +1 -1
- package/dist/scheduler/index.js +1 -1
- package/dist/scheduler/runtime.d.ts +3 -0
- package/dist/scheduler/runtime.d.ts.map +1 -1
- package/dist/security/builders.d.ts +11 -2
- package/dist/security/builders.d.ts.map +1 -1
- package/dist/security/index.d.ts +4 -4
- package/dist/security/index.d.ts.map +1 -1
- package/dist/security/markings.d.ts +19 -0
- package/dist/security/markings.d.ts.map +1 -0
- package/dist/security/redactions.d.ts +4 -0
- package/dist/security/redactions.d.ts.map +1 -0
- package/dist/security/registry.d.ts +7 -1
- package/dist/security/registry.d.ts.map +1 -1
- package/dist/security/types.d.ts +25 -0
- package/dist/security/types.d.ts.map +1 -1
- package/dist/security/validation.d.ts +4 -1
- package/dist/security/validation.d.ts.map +1 -1
- package/dist/shares/internal.js +24 -21
- package/dist/shares/internal.js.map +2 -2
- package/dist/storage/agents/provider.d.ts.map +1 -1
- package/dist/storage/agents/provider.js +5 -4
- package/dist/storage/agents/provider.js.map +1 -1
- package/dist/storage/agents/types.d.ts +15 -9
- package/dist/storage/agents/types.d.ts.map +1 -1
- 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 +10 -7
- package/dist/storage/file-upload-sessions/provider.js.map +1 -1
- 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 +6 -3
- package/dist/storage/index.d.ts.map +1 -1
- package/dist/storage/index.js +35 -32
- 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 +9 -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 +9 -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 +10 -7
- package/dist/storage/workflow-runs/provider.js.map +1 -1
- package/dist/syncs/index.js +30 -27
- package/dist/syncs/index.js.map +1 -1
- 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 +2556 -1495
- 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 +25 -22
- package/dist/webhooks/internal.js.map +2 -2
- 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/builders.d.ts.map +1 -1
- package/dist/workflows/index.js +51 -47
- package/dist/workflows/index.js.map +1 -1
- package/dist/workflows/request.d.ts.map +1 -1
- package/dist/workflows/types.d.ts +6 -3
- package/dist/workflows/types.d.ts.map +1 -1
- package/dist/workflows/validation.d.ts +2 -1
- package/dist/workflows/validation.d.ts.map +1 -1
- package/package.json +7 -1
- package/src/actions/read-facade.ts +2 -1
- package/src/actions/types/context.ts +5 -2
- package/src/actions/validation.ts +4 -1
- package/src/agents/adapters.ts +15 -0
- package/src/agents/authority.ts +15 -0
- package/src/agents/context/entries.ts +48 -4
- package/src/agents/context/index.ts +1 -0
- package/src/agents/context-compaction.ts +6 -0
- package/src/agents/errors.ts +3 -0
- package/src/agents/index.ts +13 -1
- package/src/agents/message.ts +9 -0
- package/src/agents/request.ts +178 -22
- package/src/agents/skills.ts +63 -0
- package/src/agents/types.ts +35 -5
- package/src/auth/runtime.ts +14 -0
- package/src/auth/types.ts +6 -0
- package/src/authorization/resolve.ts +6 -1
- package/src/authorization/types.ts +7 -0
- package/src/blob-storage/download-urls.ts +138 -0
- package/src/blob-storage/execution.ts +44 -1
- package/src/blob-storage/file-content.ts +106 -0
- package/src/blob-storage/index.ts +1 -0
- package/src/blob-storage/internal.ts +8 -0
- package/src/blob-storage/media-type.ts +29 -0
- package/src/blob-storage/types.ts +13 -1
- package/src/blob-storage/validation.ts +13 -0
- package/src/bootstrap/agent-context.ts +356 -0
- package/src/bootstrap/discovery.ts +100 -33
- package/src/bootstrap/index.ts +1 -1
- package/src/bootstrap/ontology-type-manifest.ts +3 -38
- package/src/datasets/builders.ts +17 -1
- package/src/datasets/execution.ts +110 -2
- package/src/datasets/index.ts +7 -1
- package/src/datasets/types.ts +2 -0
- package/src/datasets/write.ts +21 -2
- package/src/edits/properties.ts +3 -0
- package/src/events/execution.ts +15 -16
- package/src/events/types/objects.ts +5 -0
- package/src/execution/agent.ts +27 -0
- package/src/execution/authorization.ts +1 -0
- package/src/execution/authorized-object-reader.ts +104 -35
- package/src/execution/scopes.ts +2 -6
- package/src/http/api-routes.ts +4 -3
- package/src/index.ts +52 -2
- 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 +78 -7
- package/src/models/definitions.ts +8 -1
- package/src/models/events.ts +3 -0
- package/src/models/execution/README.md +24 -4
- package/src/models/execution/binding.ts +6 -0
- 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 +11 -0
- package/src/models/execution/model-call-recovery.ts +1 -0
- package/src/models/execution/reranking.ts +137 -0
- package/src/models/execution/session.ts +2 -2
- package/src/models/execution/usage.ts +1 -0
- package/src/models/execution.ts +11 -3
- package/src/models/generation-types.ts +2 -0
- package/src/models/index.ts +32 -0
- package/src/models/language-model.ts +6 -0
- package/src/models/pricing.ts +2 -1
- package/src/models/reranking-model.ts +114 -0
- package/src/objects/context/index.ts +1 -0
- package/src/objects/context/types.ts +7 -0
- package/src/objects/execution.ts +4 -1
- package/src/objects/materializer-adapter.ts +3 -0
- package/src/objects/object/upsert-batch.ts +4 -1
- package/src/objects/object/upsert.ts +3 -1
- package/src/objects/property-clearance.ts +209 -0
- package/src/objects/query/executor.ts +85 -38
- 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 +166 -15
- package/src/objects/sdk/file-handle.ts +77 -0
- package/src/objects/sdk/object-handle.ts +8 -4
- package/src/objects/sdk/object-set.ts +5 -2
- 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 +19 -2
- package/src/ontology/docs-markdown.ts +394 -0
- package/src/ontology/docs.ts +196 -0
- package/src/ontology/index.ts +2 -0
- package/src/ontology/inference/index.ts +25 -0
- package/src/ontology/internal.ts +7 -0
- package/src/ontology/query-capabilities.ts +1 -1
- package/src/ontology/tokens.ts +13 -2
- package/src/ontology/types.ts +26 -0
- package/src/ontology/validation/index.ts +1 -0
- package/src/ontology/validation/query.ts +57 -0
- package/src/ontology/validation/schema.ts +26 -1
- package/src/query.ts +4 -0
- package/src/queues/in-memory.ts +54 -19
- package/src/queues/types.ts +4 -0
- package/src/runtime/create.ts +34 -4
- package/src/runtime/definitions.ts +3 -1
- package/src/runtime/host.ts +73 -2
- package/src/runtime/index.ts +4 -0
- package/src/runtime/internal.ts +1 -0
- package/src/runtime/locale.ts +26 -0
- package/src/runtime/public-origin.ts +33 -0
- package/src/runtime/resolve-definitions.ts +28 -1
- package/src/runtime/sixb.ts +14 -3
- package/src/runtime/types.ts +51 -5
- package/src/scheduler/runtime.ts +11 -2
- package/src/security/builders.ts +49 -5
- package/src/security/index.ts +6 -1
- package/src/security/markings.ts +313 -0
- package/src/security/redactions.ts +6 -0
- package/src/security/registry.ts +21 -1
- package/src/security/types.ts +26 -0
- package/src/security/validation.ts +59 -2
- package/src/storage/agents/provider.ts +11 -0
- package/src/storage/agents/types.ts +15 -7
- 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 +32 -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 +9 -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/src/workflows/builders.ts +24 -1
- package/src/workflows/request.ts +3 -0
- package/src/workflows/types.ts +6 -3
- package/src/workflows/validation.ts +32 -4
- package/dist/chunk-3q7z9hd4.js.map +0 -46
- package/dist/chunk-667x4drs.js.map +0 -12
- package/dist/chunk-69266efg.js.map +0 -12
- 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-8x74221e.js.map +0 -20
- package/dist/chunk-91kcnbf0.js.map +0 -10
- package/dist/chunk-98cw09sw.js.map +0 -10
- package/dist/chunk-9vx5e9g1.js.map +0 -11
- package/dist/chunk-a0073121.js.map +0 -12
- package/dist/chunk-a7ne02hk.js.map +0 -15
- package/dist/chunk-cd234ba4.js.map +0 -14
- package/dist/chunk-chdg6eqq.js.map +0 -10
- package/dist/chunk-dmn70ztd.js.map +0 -11
- package/dist/chunk-f72rbvsb.js.map +0 -19
- package/dist/chunk-g4rbm4a6.js.map +0 -15
- package/dist/chunk-h044jb97.js.map +0 -15
- package/dist/chunk-h3v76ams.js.map +0 -11
- 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-kttr5ftm.js.map +0 -12
- 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-vjqt7q3a.js.map +0 -36
- package/dist/chunk-xnx96gfy.js.map +0 -15
- package/dist/chunk-z5rnrmz1.js.map +0 -11
- package/dist/chunk-zvmr2hqk.js.map +0 -12
- 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-4gmng3vf.js.map → chunk-22v5bpz3.js.map} +0 -0
- /package/dist/{chunk-fj1dvp37.js.map → chunk-2vhg6ysa.js.map} +0 -0
- /package/dist/{chunk-gmdvns8f.js.map → chunk-48e3cn2d.js.map} +0 -0
- /package/dist/{chunk-cq44v1a6.js.map → chunk-7hpdd6r9.js.map} +0 -0
- /package/dist/{chunk-rb143ggb.js.map → chunk-bwjcehza.js.map} +0 -0
- /package/dist/{chunk-7g2gjvah.js.map → chunk-ex496vct.js.map} +0 -0
- /package/dist/{chunk-nvymebc1.js.map → chunk-f1zxad2t.js.map} +0 -0
- /package/dist/{chunk-b9y8hcm2.js.map → chunk-mfs23znk.js.map} +0 -0
- /package/dist/{chunk-h866d223.js.map → chunk-qkvz64nd.js.map} +0 -0
- /package/dist/{chunk-tkdbge6v.js.map → chunk-rt9p8m9t.js.map} +0 -0
- /package/dist/{chunk-sbcm1b92.js.map → chunk-v6xpd60t.js.map} +0 -0
- /package/dist/{chunk-nj0020ay.js.map → chunk-vgk3hknm.js.map} +0 -0
- /package/dist/{chunk-qnd7ehe5.js.map → chunk-vx2yp45y.js.map} +0 -0
- /package/dist/{chunk-nkbev3tr.js.map → chunk-yv9czyfr.js.map} +0 -0
- /package/dist/{chunk-cxj8y8t0.js.map → chunk-za5yd58j.js.map} +0 -0
- /package/dist/{chunk-zb47r1c8.js.map → chunk-zb77kjth.js.map} +0 -0
- /package/dist/{chunk-dp7yk20b.js.map → chunk-zxawp1n2.js.map} +0 -0
|
@@ -15,16 +15,21 @@ import {
|
|
|
15
15
|
paginate,
|
|
16
16
|
InMemoryAuthStorage2,
|
|
17
17
|
principalsEqual2
|
|
18
|
-
} from "./chunk-
|
|
18
|
+
} from "./chunk-6h5m9xjx.js";
|
|
19
19
|
import {
|
|
20
20
|
ObjectReadLimitExceededError2,
|
|
21
21
|
snapshotObjectReadExecutionLimits2,
|
|
22
22
|
assertObjectReadFacetCount2,
|
|
23
23
|
assertObjectReadOutputWithinLimit2
|
|
24
|
-
} from "./chunk-
|
|
24
|
+
} from "./chunk-qkbx3tf6.js";
|
|
25
25
|
import {
|
|
26
26
|
assertObjectReaderProject2
|
|
27
27
|
} from "./chunk-v4jbb3rs.js";
|
|
28
|
+
import {
|
|
29
|
+
queryScalarKindForSchema,
|
|
30
|
+
resolvePropertyQueryCapabilities2,
|
|
31
|
+
resolveQuerySchema
|
|
32
|
+
} from "./chunk-y05543x6.js";
|
|
28
33
|
import {
|
|
29
34
|
AgentStorageError2,
|
|
30
35
|
transitionAgentThreadSandbox2,
|
|
@@ -39,7 +44,7 @@ import {
|
|
|
39
44
|
assertAgentContextCheckpointAnchors2,
|
|
40
45
|
assertAgentContextCheckpointReplayState2,
|
|
41
46
|
agentContextCheckpointMatchesCreateInput2
|
|
42
|
-
} from "./chunk-
|
|
47
|
+
} from "./chunk-s54c868q.js";
|
|
43
48
|
import {
|
|
44
49
|
InMemoryAiUsageStorage2,
|
|
45
50
|
buildAiAccountingOverview,
|
|
@@ -48,10 +53,11 @@ import {
|
|
|
48
53
|
buildAiModelCallGroups,
|
|
49
54
|
normalizeAiModelCallCostRecord2,
|
|
50
55
|
aiModelCallCostMatchesUsage2
|
|
51
|
-
} from "./chunk-
|
|
56
|
+
} from "./chunk-ere85b8y.js";
|
|
52
57
|
import {
|
|
53
58
|
AiLimitStorageError2,
|
|
54
59
|
aiLimitCalendarMonth2,
|
|
60
|
+
aiLimitMeterApplies2,
|
|
55
61
|
AiLimitOperationLock2,
|
|
56
62
|
aiLimitSubjectKey2,
|
|
57
63
|
normalizeAiLimitAmount2,
|
|
@@ -73,42 +79,63 @@ import {
|
|
|
73
79
|
cloneAiLimitPolicy2,
|
|
74
80
|
assertNonBlank2,
|
|
75
81
|
cloneValidDate2
|
|
76
|
-
} from "./chunk-
|
|
82
|
+
} from "./chunk-4as3wt1c.js";
|
|
77
83
|
import {
|
|
78
84
|
isAbandonedFileUploadSession,
|
|
79
85
|
shouldDeleteFileUploadSession
|
|
80
86
|
} from "./chunk-h89wz928.js";
|
|
81
87
|
import {
|
|
82
88
|
DurableFileUploadSessions2
|
|
83
|
-
} from "./chunk-
|
|
89
|
+
} from "./chunk-zxawp1n2.js";
|
|
84
90
|
import {
|
|
85
91
|
ExecutionStorageError2,
|
|
86
92
|
prepareExecutionRecord2,
|
|
87
93
|
cloneExecutionRecord
|
|
88
94
|
} from "./chunk-tw03bsmb.js";
|
|
89
95
|
import {
|
|
96
|
+
objectRefKey2,
|
|
97
|
+
linkRefKey2,
|
|
98
|
+
projectionEntityKey2,
|
|
99
|
+
telemetryPointKey2,
|
|
100
|
+
objectRefSortKey2,
|
|
101
|
+
linkRefSortKey2,
|
|
102
|
+
linkScopeKey,
|
|
103
|
+
linkScopeSortKey2,
|
|
104
|
+
telemetryPointSortKey2,
|
|
90
105
|
sha256Canonical2,
|
|
91
|
-
createEventId2
|
|
106
|
+
createEventId2
|
|
107
|
+
} from "./chunk-b9affek3.js";
|
|
108
|
+
import {
|
|
109
|
+
assertNonblank2,
|
|
110
|
+
assertPositiveInteger2,
|
|
92
111
|
assertTimestamp2,
|
|
93
112
|
invalidCorrelation2,
|
|
113
|
+
assertMaterializationHeader2,
|
|
94
114
|
assertPageRows2,
|
|
95
115
|
materializationChunkRows2,
|
|
96
|
-
|
|
97
|
-
|
|
116
|
+
materializationPlanChunk2,
|
|
117
|
+
materializationOutboxWrite2,
|
|
118
|
+
claimedOutboxRows2,
|
|
119
|
+
assertReplacementPlanCommit2,
|
|
120
|
+
prepareReplacementIdentities2,
|
|
121
|
+
projectionChangeCounts,
|
|
122
|
+
createCardinalityValidator2,
|
|
98
123
|
workUniquenessKey2,
|
|
99
124
|
comparePlanWork2,
|
|
100
125
|
compareCardinalityWork2,
|
|
101
126
|
compareEventWork2,
|
|
102
|
-
assertPlanChunkCorrelations2,
|
|
103
|
-
assertMaterializationHeader2,
|
|
104
127
|
startScopeAccumulator2,
|
|
105
128
|
appendScopeSnapshot2,
|
|
106
129
|
finishScopeAccumulator2,
|
|
130
|
+
beginMaterializationVectorChanges2,
|
|
131
|
+
beginMaterializationApply2,
|
|
107
132
|
ProviderMaterializationTransactionLifecycle2,
|
|
133
|
+
prepareMaterializationWork2,
|
|
108
134
|
uniqueSorted2,
|
|
109
135
|
assertExpectedObjectRevision2,
|
|
110
136
|
assertExpectedLinkRevision2,
|
|
111
137
|
assertExpectedLinkScopeRevision2,
|
|
138
|
+
duplicateMaterializationWork2,
|
|
112
139
|
sourceStageRoots2,
|
|
113
140
|
sourceMaterializationIdentity2,
|
|
114
141
|
assertSourceBeginInput2,
|
|
@@ -119,18 +146,7 @@ import {
|
|
|
119
146
|
assertSourceStagedRow2,
|
|
120
147
|
isExactStagingManifest2,
|
|
121
148
|
sourceConflict2
|
|
122
|
-
} from "./chunk-
|
|
123
|
-
import {
|
|
124
|
-
objectRefKey2,
|
|
125
|
-
linkRefKey2,
|
|
126
|
-
projectionEntityKey2,
|
|
127
|
-
telemetryPointKey2,
|
|
128
|
-
objectRefSortKey2,
|
|
129
|
-
linkRefSortKey2,
|
|
130
|
-
linkScopeKey,
|
|
131
|
-
linkScopeSortKey2,
|
|
132
|
-
telemetryPointSortKey2
|
|
133
|
-
} from "./chunk-7ytf06d3.js";
|
|
149
|
+
} from "./chunk-wt4szfec.js";
|
|
134
150
|
import {
|
|
135
151
|
createStorageOperationScope2,
|
|
136
152
|
createOperationScopedFacade2,
|
|
@@ -139,7 +155,7 @@ import {
|
|
|
139
155
|
createOntologyOperationScope2,
|
|
140
156
|
createObjectOperationScope2,
|
|
141
157
|
createWorkflowRunOperationScope2
|
|
142
|
-
} from "./chunk-
|
|
158
|
+
} from "./chunk-qczk96d9.js";
|
|
143
159
|
import {
|
|
144
160
|
PipelineRunError2,
|
|
145
161
|
assertPipelineRunExecution2
|
|
@@ -187,7 +203,7 @@ import {
|
|
|
187
203
|
WorkflowRunError2,
|
|
188
204
|
assertWorkflowRunExecution2,
|
|
189
205
|
assertWorkflowAgentNodeRunExecution2
|
|
190
|
-
} from "./chunk-
|
|
206
|
+
} from "./chunk-d0eb5yy6.js";
|
|
191
207
|
import {
|
|
192
208
|
ShareGrantStorageError2,
|
|
193
209
|
normalizeShareGrantCreate2,
|
|
@@ -206,21 +222,22 @@ import {
|
|
|
206
222
|
normalizeRevokeShareSessionInput2,
|
|
207
223
|
cloneShareSessionRecord2
|
|
208
224
|
} from "./chunk-z8fx5cgb.js";
|
|
225
|
+
import {
|
|
226
|
+
ConnectorConnectionStorageError2,
|
|
227
|
+
CONNECTOR_CONNECTION_RUN_FAILURE_CODES2
|
|
228
|
+
} from "./chunk-2c4j899j.js";
|
|
209
229
|
import {
|
|
210
230
|
actionSubjectsEqual2,
|
|
211
231
|
actionRunPhaseRecordsEqual2,
|
|
212
232
|
canRequeueActionRunAfterEnqueueFailure2,
|
|
213
233
|
isTerminalActionRun2,
|
|
214
234
|
StorageTransactionError2,
|
|
235
|
+
cloneFileDownloadGrantRecord,
|
|
215
236
|
canRequeuePipelineRunAfterEnqueueFailure2,
|
|
216
237
|
canRequeueSyncRunAfterEnqueueFailure2,
|
|
217
238
|
createTransactionStorageProxy2,
|
|
218
239
|
throwNestedStorageTransaction2
|
|
219
|
-
} from "./chunk-
|
|
220
|
-
import {
|
|
221
|
-
ConnectorConnectionStorageError2,
|
|
222
|
-
CONNECTOR_CONNECTION_RUN_FAILURE_CODES2
|
|
223
|
-
} from "./chunk-2c4j899j.js";
|
|
240
|
+
} from "./chunk-y9jmd7e5.js";
|
|
224
241
|
import {
|
|
225
242
|
assertPinnedDatasetWatermark2
|
|
226
243
|
} from "./chunk-6aawea28.js";
|
|
@@ -230,7 +247,7 @@ import {
|
|
|
230
247
|
} from "./chunk-96yw3pwd.js";
|
|
231
248
|
import {
|
|
232
249
|
AGENT_RUN_FAILURE_CODES2
|
|
233
|
-
} from "./chunk-
|
|
250
|
+
} from "./chunk-hkc3jct7.js";
|
|
234
251
|
import {
|
|
235
252
|
compareDecimalValues2
|
|
236
253
|
} from "./chunk-3bh94gbw.js";
|
|
@@ -1264,8 +1281,9 @@ class InMemoryAiLimitStorage2 {
|
|
|
1264
1281
|
const unavailablePolicies = [];
|
|
1265
1282
|
const unavailableReasons = new Set;
|
|
1266
1283
|
for (const policy of enabledPolicies) {
|
|
1267
|
-
if (!subjectKeys.has(aiLimitSubjectKey2(policy.subject)))
|
|
1284
|
+
if (!subjectKeys.has(aiLimitSubjectKey2(policy.subject)) || !aiLimitMeterApplies2(policy.limit.meter, request.modelKind)) {
|
|
1268
1285
|
continue;
|
|
1286
|
+
}
|
|
1269
1287
|
const limit = normalizeAiLimitAmount2(policy.limit);
|
|
1270
1288
|
const estimate = estimates.get(aiLimitAmountKey2(limit));
|
|
1271
1289
|
const status = await this.policyStatus(policy, request.period);
|
|
@@ -1301,7 +1319,7 @@ class InMemoryAiLimitStorage2 {
|
|
|
1301
1319
|
resetAt: new Date(Math.min(...exhaustedPolicies.map((status) => status.period.resetAt.getTime())))
|
|
1302
1320
|
};
|
|
1303
1321
|
}
|
|
1304
|
-
const buckets = aiLimitReservationBuckets2(enabledPolicies, request.subjects, request.estimates);
|
|
1322
|
+
const buckets = aiLimitReservationBuckets2(enabledPolicies, request.subjects, request.estimates, request.modelKind);
|
|
1305
1323
|
if (buckets.length === 0)
|
|
1306
1324
|
return { status: "notRequired" };
|
|
1307
1325
|
for (const bucket of buckets) {
|
|
@@ -1541,6 +1559,7 @@ class InMemoryAiLimitStorage2 {
|
|
|
1541
1559
|
attempt: record.attempt,
|
|
1542
1560
|
callId: record.callId,
|
|
1543
1561
|
occurredAt: new Date(record.occurredAt),
|
|
1562
|
+
...record.modelKind === undefined ? {} : { modelKind: record.modelKind },
|
|
1544
1563
|
...record.usage.totalTokens === undefined ? {} : { totalTokens: record.usage.totalTokens },
|
|
1545
1564
|
requesterGroupIds: [...record.requesterGroupIds],
|
|
1546
1565
|
...requester?.type === "user" || requester?.type === "serviceAccount" ? { requester: { type: requester.type, id: requester.id } } : {},
|
|
@@ -2561,6 +2580,50 @@ class InMemoryExecutionStorage {
|
|
|
2561
2580
|
}
|
|
2562
2581
|
}
|
|
2563
2582
|
|
|
2583
|
+
// src/storage/file-download-grants/in-memory.ts
|
|
2584
|
+
class InMemoryFileDownloadGrantStorage {
|
|
2585
|
+
rows = new Map;
|
|
2586
|
+
async create(record) {
|
|
2587
|
+
const duplicate = [...this.rows.values()].some((current) => current.projectId === record.projectId && (current.id === record.id || current.tokenHash === record.tokenHash));
|
|
2588
|
+
if (duplicate) {
|
|
2589
|
+
throw new Error(`[Sixb] File download grant '${record.id}' conflicts with an existing one.`);
|
|
2590
|
+
}
|
|
2591
|
+
this.rows.set(rowKey(record.projectId, record.id), cloneFileDownloadGrantRecord(record));
|
|
2592
|
+
}
|
|
2593
|
+
async findByTokenHash(input) {
|
|
2594
|
+
for (const record of this.rows.values()) {
|
|
2595
|
+
if (record.projectId === input.projectId && record.tokenHash === input.tokenHash) {
|
|
2596
|
+
return cloneFileDownloadGrantRecord(record);
|
|
2597
|
+
}
|
|
2598
|
+
}
|
|
2599
|
+
return null;
|
|
2600
|
+
}
|
|
2601
|
+
async revoke(input) {
|
|
2602
|
+
const key = rowKey(input.projectId, input.id);
|
|
2603
|
+
const current = this.rows.get(key);
|
|
2604
|
+
if (!current)
|
|
2605
|
+
return null;
|
|
2606
|
+
if (!current.revokedAt) {
|
|
2607
|
+
this.rows.set(key, { ...current, revokedAt: new Date(input.revokedAt) });
|
|
2608
|
+
}
|
|
2609
|
+
return cloneFileDownloadGrantRecord(this.rows.get(key));
|
|
2610
|
+
}
|
|
2611
|
+
async deleteExpired(input) {
|
|
2612
|
+
const expired = [...this.rows.entries()].filter(([, record]) => record.projectId === input.projectId && record.expiresAt.getTime() < input.expiredBefore.getTime()).slice(0, input.limit);
|
|
2613
|
+
for (const [key] of expired)
|
|
2614
|
+
this.rows.delete(key);
|
|
2615
|
+
return expired.length;
|
|
2616
|
+
}
|
|
2617
|
+
snapshot() {
|
|
2618
|
+
return new Map([...this.rows].map(([key, record]) => [key, cloneFileDownloadGrantRecord(record)]));
|
|
2619
|
+
}
|
|
2620
|
+
restore(snapshot) {
|
|
2621
|
+
this.rows = new Map([...snapshot].map(([key, record]) => [key, cloneFileDownloadGrantRecord(record)]));
|
|
2622
|
+
}
|
|
2623
|
+
}
|
|
2624
|
+
function rowKey(projectId, id) {
|
|
2625
|
+
return `${projectId}\x00${id}`;
|
|
2626
|
+
}
|
|
2564
2627
|
// src/objects/vectors/query.ts
|
|
2565
2628
|
function hasVectorProfile2(query) {
|
|
2566
2629
|
if (query.kind === "vector")
|
|
@@ -2572,6 +2635,9 @@ function hasVectorProfile2(query) {
|
|
|
2572
2635
|
function isVectorProfileQuery2(query) {
|
|
2573
2636
|
if (query.kind === "limit" || query.kind === "project")
|
|
2574
2637
|
return isVectorProfileQuery2(query.input);
|
|
2638
|
+
if (query.kind === "rerank") {
|
|
2639
|
+
return query.input.kind === "vector" && isVectorProfileQuery2(query.input);
|
|
2640
|
+
}
|
|
2575
2641
|
if (query.kind !== "vector" || !query.profile)
|
|
2576
2642
|
return false;
|
|
2577
2643
|
return isVectorCandidateQuery(query.input);
|
|
@@ -2863,6 +2929,8 @@ function assertLinkQueryLimit(limit) {
|
|
|
2863
2929
|
}
|
|
2864
2930
|
function evaluateObjectQuery(query, source) {
|
|
2865
2931
|
switch (query.kind) {
|
|
2932
|
+
case "rerank":
|
|
2933
|
+
throw new Error("[Sixb] Reranking must execute in the model runtime, not storage.");
|
|
2866
2934
|
case "start":
|
|
2867
2935
|
return evaluateStart(query.objectTypeId, source);
|
|
2868
2936
|
case "refs":
|
|
@@ -3534,6 +3602,7 @@ function createInMemorySelectedReader(source, params, queryCapabilities) {
|
|
|
3534
3602
|
const universe = resolveSelectedReadUniverse(source, plan, limits);
|
|
3535
3603
|
const result = evaluateObjectQuery(stripOuterRowShape(input.query), universe);
|
|
3536
3604
|
return visible(structuredClone({
|
|
3605
|
+
total: result.entries.length,
|
|
3537
3606
|
facets: buildFacetResults(result.entries.map((entry) => entry.row), input.facets)
|
|
3538
3607
|
}));
|
|
3539
3608
|
},
|
|
@@ -3772,6 +3841,7 @@ class InMemoryObjectStorage {
|
|
|
3772
3841
|
async facetObjects(params) {
|
|
3773
3842
|
const result = evaluateObjectQuery(stripOuterRowShape(params.query), this.readSource(params.projectId));
|
|
3774
3843
|
return {
|
|
3844
|
+
total: result.entries.length,
|
|
3775
3845
|
facets: buildFacetResults(result.entries.map((entry) => entry.row), params.facets)
|
|
3776
3846
|
};
|
|
3777
3847
|
}
|
|
@@ -3958,7 +4028,9 @@ function createInMemoryOntologyState() {
|
|
|
3958
4028
|
objectOverrides: new Map,
|
|
3959
4029
|
linkOverrides: new Map,
|
|
3960
4030
|
linkSlotOverrides: new Map,
|
|
3961
|
-
outbox: new Map
|
|
4031
|
+
outbox: new Map,
|
|
4032
|
+
replacementPlans: new Map,
|
|
4033
|
+
commitTouches: new Map
|
|
3962
4034
|
};
|
|
3963
4035
|
}
|
|
3964
4036
|
function projectEntityKey(projectId, entityKey) {
|
|
@@ -4346,55 +4418,8 @@ function storedSourceLink(sourceId, materializationId, row) {
|
|
|
4346
4418
|
return null;
|
|
4347
4419
|
return storedSource(sourceId, materializationId, row);
|
|
4348
4420
|
}
|
|
4349
|
-
function addReplacementLink(replacement, ref, diffRequired) {
|
|
4350
|
-
const key = linkRefKey2(ref);
|
|
4351
|
-
const existing = replacement.links.get(key);
|
|
4352
|
-
if (existing) {
|
|
4353
|
-
existing.diffRequired ||= diffRequired;
|
|
4354
|
-
if (diffRequired)
|
|
4355
|
-
replacement.affectedScopes.add(linkScopeSortKey2(ref.source, ref.linkId));
|
|
4356
|
-
return;
|
|
4357
|
-
}
|
|
4358
|
-
replacement.links.set(key, {
|
|
4359
|
-
ref: structuredClone(ref),
|
|
4360
|
-
sortKey: linkRefSortKey2(ref),
|
|
4361
|
-
diffRequired
|
|
4362
|
-
});
|
|
4363
|
-
if (diffRequired)
|
|
4364
|
-
replacement.affectedScopes.add(linkScopeSortKey2(ref.source, ref.linkId));
|
|
4365
|
-
}
|
|
4366
4421
|
|
|
4367
4422
|
// src/storage/ontology/in-memory/materializations-work.ts
|
|
4368
|
-
function assertChunkSequence(session, chunk) {
|
|
4369
|
-
const planItems = materializationPlanItems2(chunk);
|
|
4370
|
-
const applyStream = session.workStreams.apply;
|
|
4371
|
-
const appliedStart = session.appliedPlanItems.length;
|
|
4372
|
-
if (planItems.length > 0 && (!applyStream.started || appliedStart + planItems.length > applyStream.emittedCount)) {
|
|
4373
|
-
invalidCorrelation2("Materialization plan items cannot be applied before they are streamed.");
|
|
4374
|
-
}
|
|
4375
|
-
for (let offset = 0;offset < planItems.length; offset += 1) {
|
|
4376
|
-
const expected = session.applyWork[appliedStart + offset]?.item;
|
|
4377
|
-
if (!expected || stableJsonStringify2(planItems[offset]) !== stableJsonStringify2(expected)) {
|
|
4378
|
-
invalidCorrelation2("Materialization plan items must be applied in exact streamed order.");
|
|
4379
|
-
}
|
|
4380
|
-
}
|
|
4381
|
-
const eventStream = session.workStreams.event;
|
|
4382
|
-
const appliedOutboxCount = session.outboxEnvelopes.size;
|
|
4383
|
-
if (chunk.outbox.length > 0 && (!eventStream.started || appliedOutboxCount + chunk.outbox.length > eventStream.emittedCount)) {
|
|
4384
|
-
invalidCorrelation2("Materialization events cannot be applied before they are streamed.");
|
|
4385
|
-
}
|
|
4386
|
-
for (let offset = 0;offset < chunk.outbox.length; offset += 1) {
|
|
4387
|
-
const expected = session.eventWork[appliedOutboxCount + offset];
|
|
4388
|
-
const actual = chunk.outbox[offset]?.envelope;
|
|
4389
|
-
if (!expected || !actual) {
|
|
4390
|
-
invalidCorrelation2("Materialization outbox events must follow exact streamed order.");
|
|
4391
|
-
}
|
|
4392
|
-
const { id: _id, commitOrdinal, ...actualDraft } = actual;
|
|
4393
|
-
if (commitOrdinal !== appliedOutboxCount + offset || stableJsonStringify2(actualDraft) !== stableJsonStringify2(expected.draft)) {
|
|
4394
|
-
invalidCorrelation2("Materialization outbox events must follow exact streamed order.");
|
|
4395
|
-
}
|
|
4396
|
-
}
|
|
4397
|
-
}
|
|
4398
4423
|
function assertLastCommit(value, expected, label) {
|
|
4399
4424
|
if ((value?.lastCommitId ?? null) !== expected) {
|
|
4400
4425
|
throw new MaterializationConflictError2("effective-state", `Expected ${label} changed.`);
|
|
@@ -4405,11 +4430,11 @@ function assertLastCommit(value, expected, label) {
|
|
|
4405
4430
|
function assertFinalizationCorrelations(session, finalization, state, objects) {
|
|
4406
4431
|
const { commit } = session.header;
|
|
4407
4432
|
const { result, sourceActivations } = finalization;
|
|
4408
|
-
if (result.commitId !== commit.id || result.kind !== commit.intent.kind || result.committedAt !== commit.committedAt || result.created !== true || !Number.isSafeInteger(result.eventCount) || result.eventCount < 0 || result.eventCount !== session.
|
|
4433
|
+
if (result.commitId !== commit.id || result.kind !== commit.intent.kind || result.committedAt !== commit.committedAt || result.created !== true || !Number.isSafeInteger(result.eventCount) || result.eventCount < 0 || result.eventCount !== session.outboxWrites.size) {
|
|
4409
4434
|
invalidCorrelation2("Materialization result does not correlate with its commit intent.");
|
|
4410
4435
|
}
|
|
4411
4436
|
for (let ordinal = 0;ordinal < result.eventCount; ordinal += 1) {
|
|
4412
|
-
if (!session.
|
|
4437
|
+
if (!session.outboxWrites.has(ordinal)) {
|
|
4413
4438
|
invalidCorrelation2("Outbox event ordinals must be contiguous from zero.");
|
|
4414
4439
|
}
|
|
4415
4440
|
}
|
|
@@ -4431,7 +4456,7 @@ function assertFinalizationCorrelations(session, finalization, state, objects) {
|
|
|
4431
4456
|
assertSourceActivationCorrelation(activation, session, state);
|
|
4432
4457
|
}
|
|
4433
4458
|
if (sourceActivations[0]) {
|
|
4434
|
-
|
|
4459
|
+
assertPlanCoverage(session, sourceActivations[0]);
|
|
4435
4460
|
}
|
|
4436
4461
|
assertFinalizedWork(session, state, objects);
|
|
4437
4462
|
if (commit.intent.kind === "projection") {
|
|
@@ -4571,16 +4596,8 @@ function assertSourceDatasetWatermark(active, next) {
|
|
|
4571
4596
|
assertPinnedDatasetWatermark2(active, next, "Source activation");
|
|
4572
4597
|
}
|
|
4573
4598
|
function assertFinalizedWork(session, state, objects) {
|
|
4574
|
-
|
|
4575
|
-
|
|
4576
|
-
if (expectedPlanItems.length > 0 && !session.workStreams.apply.completed) {
|
|
4577
|
-
invalidCorrelation2("Materialization plan work was not fully streamed.");
|
|
4578
|
-
}
|
|
4579
|
-
if (stableJsonStringify2(appliedPlanItems) !== stableJsonStringify2(expectedPlanItems)) {
|
|
4580
|
-
invalidCorrelation2("Materialization plan work was not applied exactly once.");
|
|
4581
|
-
}
|
|
4582
|
-
if (session.cardinalityWork.length > 0 && !session.workStreams.cardinality.completed) {
|
|
4583
|
-
invalidCorrelation2("Materialization cardinality work was not fully validated.");
|
|
4599
|
+
if (!session.applied) {
|
|
4600
|
+
invalidCorrelation2("A materialization plan must apply before it finalizes.");
|
|
4584
4601
|
}
|
|
4585
4602
|
assertFinalCardinality(session.cardinalityWork, session.header.commit.projectId, objects);
|
|
4586
4603
|
if (session.header.commit.intent.kind === "telemetry") {
|
|
@@ -4590,24 +4607,20 @@ function assertFinalizedWork(session, state, objects) {
|
|
|
4590
4607
|
}
|
|
4591
4608
|
}
|
|
4592
4609
|
const expectedEvents = [...session.eventWork].sort(compareEventWork2);
|
|
4593
|
-
if (
|
|
4594
|
-
invalidCorrelation2("Materialization event work was not fully drained.");
|
|
4595
|
-
}
|
|
4596
|
-
if (session.outboxEnvelopes.size !== expectedEvents.length) {
|
|
4610
|
+
if (session.outboxWrites.size !== expectedEvents.length) {
|
|
4597
4611
|
invalidCorrelation2("Materialization event work was not fully written to the outbox.");
|
|
4598
4612
|
}
|
|
4599
4613
|
for (let ordinal = 0;ordinal < expectedEvents.length; ordinal += 1) {
|
|
4600
4614
|
const expected = expectedEvents[ordinal];
|
|
4601
|
-
const actual = session.
|
|
4615
|
+
const actual = session.outboxWrites.get(ordinal);
|
|
4602
4616
|
if (!expected || !actual) {
|
|
4603
4617
|
invalidCorrelation2("Materialization event work was not fully written to the outbox.");
|
|
4604
4618
|
}
|
|
4605
|
-
|
|
4606
|
-
if (commitOrdinal !== ordinal || id !== createEventId2(session.header.commit.projectId, session.header.commit.id, ordinal) || stableJsonStringify2(actualDraft) !== stableJsonStringify2(expected.draft)) {
|
|
4619
|
+
if (actual.commitOrdinal !== ordinal || actual.id !== createEventId2(session.header.commit.projectId, session.header.commit.id, ordinal) || stableJsonStringify2(actual.event) !== stableJsonStringify2(expected.draft)) {
|
|
4607
4620
|
invalidCorrelation2("Materialization outbox event does not match its staged event work.");
|
|
4608
4621
|
}
|
|
4609
4622
|
const persisted = state.outbox.get(outboxKey(session.header.commit.projectId, actual.id));
|
|
4610
|
-
if (!persisted || stableJsonStringify2(persisted.
|
|
4623
|
+
if (!persisted || stableJsonStringify2(persisted.event) !== stableJsonStringify2(actual.event)) {
|
|
4611
4624
|
invalidCorrelation2("Materialization outbox event was not persisted.");
|
|
4612
4625
|
}
|
|
4613
4626
|
}
|
|
@@ -4615,26 +4628,15 @@ function assertFinalizedWork(session, state, objects) {
|
|
|
4615
4628
|
function assertFinalCardinality(records, projectId, objects) {
|
|
4616
4629
|
const effectiveOccupants = records.filter((record) => record.view === "effective");
|
|
4617
4630
|
const scopes = new Map;
|
|
4618
|
-
let currentScope = null;
|
|
4619
|
-
let occupiedCount = 0;
|
|
4620
4631
|
for (const record of effectiveOccupants) {
|
|
4621
|
-
if (record.scopeSortKey !== currentScope) {
|
|
4622
|
-
currentScope = record.scopeSortKey;
|
|
4623
|
-
occupiedCount = 0;
|
|
4624
|
-
}
|
|
4625
4632
|
const scope = scopes.get(record.scopeSortKey) ?? {
|
|
4626
4633
|
source: structuredClone(record.ref.source),
|
|
4627
4634
|
linkId: record.ref.linkId,
|
|
4628
4635
|
occupiedLinkKeys: new Set
|
|
4629
4636
|
};
|
|
4630
4637
|
scopes.set(record.scopeSortKey, scope);
|
|
4631
|
-
if (record.occupied)
|
|
4632
|
-
occupiedCount += 1;
|
|
4638
|
+
if (record.occupied)
|
|
4633
4639
|
scope.occupiedLinkKeys.add(record.linkSortKey);
|
|
4634
|
-
if (occupiedCount > 1) {
|
|
4635
|
-
invalidCorrelation2("Materialization cardinality work violates cardinality-one.");
|
|
4636
|
-
}
|
|
4637
|
-
}
|
|
4638
4640
|
}
|
|
4639
4641
|
const adapter = getInMemoryObjectMaterializerAdapter(objects);
|
|
4640
4642
|
for (const scope of scopes.values()) {
|
|
@@ -4647,21 +4649,14 @@ function assertFinalCardinality(records, projectId, objects) {
|
|
|
4647
4649
|
}
|
|
4648
4650
|
}
|
|
4649
4651
|
}
|
|
4650
|
-
function
|
|
4651
|
-
const
|
|
4652
|
-
if (!
|
|
4653
|
-
invalidCorrelation2("Source activation does not match the replacement
|
|
4654
|
-
}
|
|
4655
|
-
if (activation.projectionKind === "object" && (!replacement.objectStreamCompleted || !replacement.linkStreamCompleted)) {
|
|
4656
|
-
invalidCorrelation2("Object projection replacement state was not fully streamed.");
|
|
4652
|
+
function assertPlanCoverage(session, activation) {
|
|
4653
|
+
const plan = session.plan;
|
|
4654
|
+
if (!plan || plan.sourceId !== activation.source.projectionId || plan.materializationId !== activation.materializationId || plan.projectionKind !== activation.projectionKind) {
|
|
4655
|
+
invalidCorrelation2("Source activation does not match the replacement plan the session applies.");
|
|
4657
4656
|
}
|
|
4658
|
-
|
|
4659
|
-
|
|
4660
|
-
|
|
4661
|
-
const expectedObjectKeys = activation.projectionKind === "object" ? [...replacement.objects.keys()].sort() : [];
|
|
4662
|
-
const expectedLinkKeys = [...replacement.links.entries()].filter(([, value]) => value.diffRequired).map(([key]) => key).sort();
|
|
4663
|
-
if (stableJsonStringify2(classificationKeys(session, "object")) !== stableJsonStringify2(expectedObjectKeys) || stableJsonStringify2(classificationKeys(session, "link")) !== stableJsonStringify2(expectedLinkKeys) || classificationKeys(session, "point").length > 0) {
|
|
4664
|
-
invalidCorrelation2("Projection replacement classification coverage does not match its streamed state.");
|
|
4657
|
+
const expected = (kind) => [...plan.identities.values()].filter((identity) => identity.entity.kind === kind && identity.diffRequired).map((identity) => identity.entity.kind === "object" ? objectRefKey2(identity.entity.ref) : linkRefKey2(identity.entity.ref)).sort();
|
|
4658
|
+
if (stableJsonStringify2(classificationKeys(session, "object")) !== stableJsonStringify2(expected("object")) || stableJsonStringify2(classificationKeys(session, "link")) !== stableJsonStringify2(expected("link")) || classificationKeys(session, "point").length > 0) {
|
|
4659
|
+
invalidCorrelation2("Projection replacement classification coverage does not match its plan.");
|
|
4665
4660
|
}
|
|
4666
4661
|
}
|
|
4667
4662
|
function classificationKeys(session, entityKind) {
|
|
@@ -4688,7 +4683,7 @@ function* previousSourceRows(state, candidate) {
|
|
|
4688
4683
|
}
|
|
4689
4684
|
}
|
|
4690
4685
|
}
|
|
4691
|
-
function activateSourceRoots(state, candidate, activation) {
|
|
4686
|
+
function activateSourceRoots(state, candidate, activation, touches) {
|
|
4692
4687
|
if (candidate.base && (candidate.base.materializationId !== activation.expected.activeMaterializationId || candidate.base.lastCommitId !== activation.expected.lastCommitId)) {
|
|
4693
4688
|
throw new MaterializationConflictError2("projection-fence", "Source delta base changed before activation.");
|
|
4694
4689
|
}
|
|
@@ -4711,6 +4706,7 @@ function activateSourceRoots(state, candidate, activation) {
|
|
|
4711
4706
|
if (sources.size === 0)
|
|
4712
4707
|
state.activeSourceRows.delete(indexKey);
|
|
4713
4708
|
if (row.assertion.kind === "link") {
|
|
4709
|
+
touches.links.add(linkRefKey2(row.assertion.ref));
|
|
4714
4710
|
const scopeKey = projectEntityKey(candidate.projectId, linkScopeSortKey2(row.assertion.ref.source, row.assertion.ref.linkId));
|
|
4715
4711
|
const scope = state.activeSourceLinkScopes.get(scopeKey);
|
|
4716
4712
|
scope.delete(JSON.stringify([candidate.source.projectionId, entityKey]));
|
|
@@ -4736,6 +4732,7 @@ function activateSourceRoots(state, candidate, activation) {
|
|
|
4736
4732
|
sources.set(candidate.source.projectionId, row);
|
|
4737
4733
|
state.activeSourceRows.set(indexKey, sources);
|
|
4738
4734
|
if (row.assertion.kind === "link") {
|
|
4735
|
+
touches.links.add(linkRefKey2(row.assertion.ref));
|
|
4739
4736
|
const scopeKey = projectEntityKey(candidate.projectId, linkScopeSortKey2(row.assertion.ref.source, row.assertion.ref.linkId));
|
|
4740
4737
|
const scope = state.activeSourceLinkScopes.get(scopeKey) ?? new Map;
|
|
4741
4738
|
scope.set(JSON.stringify([candidate.source.projectionId, entityKey]), row);
|
|
@@ -4747,325 +4744,749 @@ function activateSourceRoots(state, candidate, activation) {
|
|
|
4747
4744
|
state.activeSourceHeads.set(sourceKey, candidate.materializationId);
|
|
4748
4745
|
}
|
|
4749
4746
|
|
|
4750
|
-
// src/storage/ontology/in-memory/
|
|
4751
|
-
|
|
4747
|
+
// src/storage/ontology/in-memory/replacement-plans.ts
|
|
4748
|
+
function emptyCommitTouches(projectId) {
|
|
4749
|
+
return { projectId, objects: new Set, links: new Set, scopes: new Set };
|
|
4750
|
+
}
|
|
4751
|
+
function touchPlanItem(touches, item) {
|
|
4752
|
+
switch (item.kind) {
|
|
4753
|
+
case "object-override-upsert":
|
|
4754
|
+
case "object-override-delete":
|
|
4755
|
+
case "object-delete":
|
|
4756
|
+
touches.objects.add(objectRefKey2(item.value.ref));
|
|
4757
|
+
return;
|
|
4758
|
+
case "object-upsert":
|
|
4759
|
+
touches.objects.add(objectRefKey2(item.value.row.ref));
|
|
4760
|
+
return;
|
|
4761
|
+
case "point-upsert":
|
|
4762
|
+
touches.objects.add(objectRefKey2(item.value.point.series.object));
|
|
4763
|
+
return;
|
|
4764
|
+
case "link-override-upsert":
|
|
4765
|
+
case "link-override-delete":
|
|
4766
|
+
case "link-delete":
|
|
4767
|
+
touches.links.add(linkRefKey2(item.value.ref));
|
|
4768
|
+
return;
|
|
4769
|
+
case "link-upsert":
|
|
4770
|
+
touches.links.add(linkRefKey2(item.value.row.ref));
|
|
4771
|
+
return;
|
|
4772
|
+
case "link-slot-override-upsert":
|
|
4773
|
+
case "link-slot-override-delete":
|
|
4774
|
+
touches.scopes.add(linkScopeKey(item.value.ref.source, item.value.ref.linkId));
|
|
4775
|
+
return;
|
|
4776
|
+
}
|
|
4777
|
+
}
|
|
4778
|
+
function replacementPlanKey(input) {
|
|
4779
|
+
return sourceMaterializationKey(input.projectId, input.source.projectionId, input.materializationId);
|
|
4780
|
+
}
|
|
4781
|
+
|
|
4782
|
+
class InMemoryOntologyReplacementPlanStorage {
|
|
4752
4783
|
state;
|
|
4753
4784
|
objects;
|
|
4754
|
-
|
|
4755
|
-
|
|
4756
|
-
|
|
4757
|
-
executionExists;
|
|
4785
|
+
reader;
|
|
4786
|
+
runRootOperation;
|
|
4787
|
+
assertExecution;
|
|
4758
4788
|
hooks;
|
|
4759
|
-
|
|
4760
|
-
liveSessions = new Set;
|
|
4761
|
-
constructor(state, objects, timeseries, getTransactionToken, getMaterializationLifecycle, executionExists, hooks = {}) {
|
|
4789
|
+
constructor(state, objects, reader, runRootOperation, assertExecution, hooks = {}) {
|
|
4762
4790
|
this.state = state;
|
|
4763
4791
|
this.objects = objects;
|
|
4764
|
-
this.
|
|
4765
|
-
this.
|
|
4766
|
-
this.
|
|
4767
|
-
this.executionExists = executionExists;
|
|
4792
|
+
this.reader = reader;
|
|
4793
|
+
this.runRootOperation = runRootOperation;
|
|
4794
|
+
this.assertExecution = assertExecution;
|
|
4768
4795
|
this.hooks = hooks;
|
|
4769
4796
|
}
|
|
4770
|
-
async
|
|
4771
|
-
|
|
4772
|
-
|
|
4773
|
-
|
|
4774
|
-
|
|
4775
|
-
|
|
4776
|
-
|
|
4777
|
-
|
|
4778
|
-
|
|
4779
|
-
|
|
4780
|
-
|
|
4781
|
-
for (const expected of input.expected.sources)
|
|
4782
|
-
this.assertSource(expected, input.commit.projectId);
|
|
4783
|
-
for (const expected of input.expected.objects)
|
|
4784
|
-
await this.assertObject(expected, input.commit.projectId);
|
|
4785
|
-
for (const expected of input.expected.links)
|
|
4786
|
-
await this.assertLink(expected, input.commit.projectId);
|
|
4787
|
-
const expectedScopeRevisions = new Map;
|
|
4788
|
-
for (const expected of input.expected.linkScopes) {
|
|
4789
|
-
const key = linkScopeSortKey2(expected.source, expected.linkId);
|
|
4790
|
-
const current = expectedScopeRevisions.get(key) ?? this.computeEffectiveLinkScope(input.commit.projectId, expected.source, expected.linkId);
|
|
4791
|
-
expectedScopeRevisions.set(key, current);
|
|
4792
|
-
assertExpectedLinkScopeRevision2(current.fingerprint, expected);
|
|
4793
|
-
}
|
|
4794
|
-
for (const expected of input.expected.points)
|
|
4795
|
-
this.assertPoint(expected, input.commit.projectId);
|
|
4796
|
-
const providerToken = {};
|
|
4797
|
-
const session = {
|
|
4798
|
-
providerToken,
|
|
4799
|
-
header: structuredClone(input),
|
|
4800
|
-
transactionToken,
|
|
4801
|
-
lifecycle,
|
|
4802
|
-
active: true,
|
|
4803
|
-
writeOrdinal: 0,
|
|
4804
|
-
work: new Map,
|
|
4805
|
-
workUniqueKeys: new Set,
|
|
4806
|
-
applyWork: [],
|
|
4807
|
-
cardinalityWork: [],
|
|
4808
|
-
eventWork: [],
|
|
4809
|
-
appliedPlanItems: [],
|
|
4810
|
-
outboxEnvelopes: new Map,
|
|
4811
|
-
workStreams: {
|
|
4812
|
-
apply: { started: false, completed: false, emittedCount: 0 },
|
|
4813
|
-
cardinality: { started: false, completed: false, emittedCount: 0 },
|
|
4814
|
-
event: { started: false, completed: false, emittedCount: 0 }
|
|
4815
|
-
},
|
|
4816
|
-
workSealed: false,
|
|
4817
|
-
incidentLinksByObject: null,
|
|
4818
|
-
linkSlotStates: new Map,
|
|
4819
|
-
objectExistence: new Map,
|
|
4820
|
-
replacement: null
|
|
4821
|
-
};
|
|
4822
|
-
this.sessions.set(providerToken, session);
|
|
4823
|
-
this.liveSessions.add(session);
|
|
4824
|
-
lifecycle.register(providerToken);
|
|
4825
|
-
return { providerToken };
|
|
4826
|
-
}
|
|
4827
|
-
deactivateTransaction(transactionToken) {
|
|
4828
|
-
for (const session of this.liveSessions) {
|
|
4829
|
-
if (session.transactionToken !== transactionToken)
|
|
4830
|
-
continue;
|
|
4831
|
-
this.releaseSession(session);
|
|
4832
|
-
}
|
|
4833
|
-
}
|
|
4834
|
-
releaseSession(session) {
|
|
4835
|
-
session.active = false;
|
|
4836
|
-
session.work.clear();
|
|
4837
|
-
session.workUniqueKeys.clear();
|
|
4838
|
-
session.applyWork.length = 0;
|
|
4839
|
-
session.cardinalityWork.length = 0;
|
|
4840
|
-
session.eventWork.length = 0;
|
|
4841
|
-
session.appliedPlanItems.length = 0;
|
|
4842
|
-
session.outboxEnvelopes.clear();
|
|
4843
|
-
session.incidentLinksByObject = null;
|
|
4844
|
-
session.linkSlotStates = null;
|
|
4845
|
-
session.objectExistence.clear();
|
|
4846
|
-
session.replacement = null;
|
|
4847
|
-
this.liveSessions.delete(session);
|
|
4848
|
-
session.lifecycle.complete(session.providerToken);
|
|
4849
|
-
}
|
|
4850
|
-
async* streamState(input) {
|
|
4851
|
-
const session = this.requireSession(input.session);
|
|
4852
|
-
assertPageRows2(input.pageRows);
|
|
4853
|
-
for await (const request of input.requests) {
|
|
4854
|
-
this.requireSession(input.session);
|
|
4855
|
-
this.hooks.beforeRead?.("state.read");
|
|
4856
|
-
const objectRefs = uniqueSorted2(request.objects, objectRefKey2, objectRefSortKey2);
|
|
4857
|
-
for (let offset = 0;offset < objectRefs.length; offset += input.pageRows) {
|
|
4858
|
-
this.requireSession(input.session);
|
|
4859
|
-
const objects = [];
|
|
4860
|
-
for (const ref of objectRefs.slice(offset, offset + input.pageRows)) {
|
|
4861
|
-
objects.push(await this.objectState(session, ref));
|
|
4862
|
-
}
|
|
4863
|
-
this.requireSession(input.session);
|
|
4864
|
-
this.hooks.observeBuffer?.("state.object.page", objects.length);
|
|
4865
|
-
yield { objects, links: [], linkScopes: [], points: [] };
|
|
4866
|
-
}
|
|
4867
|
-
const linkRefs = uniqueSorted2(request.links, linkRefKey2, linkRefSortKey2);
|
|
4868
|
-
for (let offset = 0;offset < linkRefs.length; offset += input.pageRows) {
|
|
4869
|
-
this.requireSession(input.session);
|
|
4870
|
-
const links = [];
|
|
4871
|
-
for (const ref of linkRefs.slice(offset, offset + input.pageRows)) {
|
|
4872
|
-
links.push(await this.linkState(session, ref));
|
|
4873
|
-
}
|
|
4874
|
-
this.requireSession(input.session);
|
|
4875
|
-
this.hooks.observeBuffer?.("state.link.page", links.length);
|
|
4876
|
-
yield { objects: [], links, linkScopes: [], points: [] };
|
|
4877
|
-
}
|
|
4878
|
-
const incidentRefs = this.incidentLinkRefs(session, request.incidentObjects);
|
|
4879
|
-
for (let offset = 0;offset < incidentRefs.length; offset += input.pageRows) {
|
|
4880
|
-
this.requireSession(input.session);
|
|
4881
|
-
const refs = incidentRefs.slice(offset, offset + input.pageRows);
|
|
4882
|
-
const links = [];
|
|
4883
|
-
for (const ref of refs)
|
|
4884
|
-
links.push(await this.linkState(session, ref));
|
|
4885
|
-
this.requireSession(input.session);
|
|
4886
|
-
this.hooks.observeBuffer?.("state.incident-link.page", links.length);
|
|
4887
|
-
yield { objects: [], links, linkScopes: [], points: [] };
|
|
4888
|
-
}
|
|
4889
|
-
for (const scope of uniqueBy(request.linkScopes, (value) => linkScopeSortKey2(value.source, value.linkId))) {
|
|
4890
|
-
this.requireSession(input.session);
|
|
4891
|
-
const value = this.linkSlotState(session, scope.source, scope.linkId);
|
|
4892
|
-
yield { objects: [], links: [], linkScopes: [value], points: [] };
|
|
4797
|
+
async open(input) {
|
|
4798
|
+
return this.runRootOperation(async () => {
|
|
4799
|
+
assertReplacementPlanCommit2(input.commit);
|
|
4800
|
+
const candidate = await this.requireCandidate(input);
|
|
4801
|
+
const key = replacementPlanKey(input);
|
|
4802
|
+
const active = findActiveSourceMaterialization(this.state, input.projectId, input.source.projectionId);
|
|
4803
|
+
const replacedMaterializationId = active?.materializationId ?? null;
|
|
4804
|
+
const replacedLastCommitId = active?.lastCommitId ?? null;
|
|
4805
|
+
const existing = this.state.replacementPlans.get(key);
|
|
4806
|
+
if (existing?.replacedMaterializationId === replacedMaterializationId && existing.replacedLastCommitId === replacedLastCommitId) {
|
|
4807
|
+
return { committedAt: existing.committedAt };
|
|
4893
4808
|
}
|
|
4894
|
-
const
|
|
4895
|
-
|
|
4896
|
-
|
|
4897
|
-
|
|
4898
|
-
|
|
4899
|
-
|
|
4900
|
-
|
|
4901
|
-
|
|
4809
|
+
const plan = {
|
|
4810
|
+
projectId: input.projectId,
|
|
4811
|
+
sourceId: input.source.projectionId,
|
|
4812
|
+
materializationId: input.materializationId,
|
|
4813
|
+
projectionKind: candidate.projectionKind,
|
|
4814
|
+
commitId: input.commit.id,
|
|
4815
|
+
committedAt: input.commit.committedAt,
|
|
4816
|
+
replacedMaterializationId,
|
|
4817
|
+
replacedLastCommitId,
|
|
4818
|
+
watermark: this.state.commitsById.size,
|
|
4819
|
+
owned: new Set,
|
|
4820
|
+
identities: new Map,
|
|
4821
|
+
workKeys: new Set
|
|
4822
|
+
};
|
|
4823
|
+
for (const rows of [
|
|
4824
|
+
previousSourceRows(this.state, candidate),
|
|
4825
|
+
candidate.rowsByEntity.values()
|
|
4826
|
+
]) {
|
|
4827
|
+
for (const row of rows) {
|
|
4828
|
+
plan.owned.add(projectionEntityKey2(row.assertion));
|
|
4829
|
+
addIdentity(plan, row.assertion, true);
|
|
4902
4830
|
}
|
|
4903
|
-
this.requireSession(input.session);
|
|
4904
|
-
this.hooks.observeBuffer?.("state.point.page", points.length);
|
|
4905
|
-
if (points.length > 0)
|
|
4906
|
-
yield { objects: [], links: [], linkScopes: [], points };
|
|
4907
4831
|
}
|
|
4908
|
-
|
|
4832
|
+
this.state.replacementPlans.set(key, plan);
|
|
4833
|
+
return { committedAt: plan.committedAt };
|
|
4834
|
+
});
|
|
4909
4835
|
}
|
|
4910
|
-
async*
|
|
4911
|
-
const session = this.requireSession(input.session);
|
|
4836
|
+
async* streamState(input) {
|
|
4912
4837
|
assertPageRows2(input.pageRows);
|
|
4913
|
-
|
|
4914
|
-
|
|
4915
|
-
|
|
4838
|
+
this.hooks.beforeRead?.(`replacement-plan.${input.entityKind}`);
|
|
4839
|
+
const pending = await this.runRootOperation(async () => {
|
|
4840
|
+
const { plan } = await this.requirePlan(input);
|
|
4841
|
+
if (input.entityKind === "object" && plan.projectionKind !== "object") {
|
|
4916
4842
|
throw new MaterializationConflictError2("source-materialization", "Link projection replacement cannot stream object state.");
|
|
4917
4843
|
}
|
|
4918
|
-
if (
|
|
4919
|
-
|
|
4920
|
-
|
|
4921
|
-
this.hooks.beforeRead?.("source-replacement.object");
|
|
4922
|
-
for (let offset = 0;offset < replacement.orderedObjects.length; offset += input.pageRows) {
|
|
4923
|
-
this.requireSession(input.session);
|
|
4924
|
-
const selected = replacement.orderedObjects.slice(offset, offset + input.pageRows);
|
|
4925
|
-
const objects = [];
|
|
4926
|
-
for (const entry of selected) {
|
|
4927
|
-
const key = projectionEntityKey2({ kind: "object", ref: entry.ref });
|
|
4928
|
-
const base = await this.objectState(session, entry.ref);
|
|
4929
|
-
objects.push({
|
|
4930
|
-
ref: base.ref,
|
|
4931
|
-
candidateSource: storedSourceObject(input.source.projectionId, replacement.candidate.materializationId, replacement.candidate.rowsByEntity.get(key)),
|
|
4932
|
-
override: base.override,
|
|
4933
|
-
effective: base.effective,
|
|
4934
|
-
latestTelemetry: base.latestTelemetry
|
|
4935
|
-
});
|
|
4844
|
+
if (input.entityKind === "link") {
|
|
4845
|
+
if (unplanned(plan, "object").length > 0) {
|
|
4846
|
+
throw new MaterializationConflictError2("effective-state", "Object projection replacement must plan every object before its links.");
|
|
4936
4847
|
}
|
|
4937
|
-
this.
|
|
4938
|
-
this.hooks.observeBuffer?.("replacement.object.page", objects.length);
|
|
4939
|
-
yield { objects, links: [] };
|
|
4848
|
+
this.expandLinks(plan);
|
|
4940
4849
|
}
|
|
4941
|
-
|
|
4942
|
-
|
|
4943
|
-
|
|
4944
|
-
|
|
4945
|
-
|
|
4946
|
-
|
|
4947
|
-
|
|
4948
|
-
|
|
4949
|
-
|
|
4950
|
-
replacement.linkStreamStarted = true;
|
|
4951
|
-
this.hooks.beforeRead?.("source-replacement.link");
|
|
4952
|
-
this.expandReplacementLinks(session, replacement);
|
|
4953
|
-
replacement.orderedLinks ??= [...replacement.links.values()].sort((left, right) => left.sortKey.localeCompare(right.sortKey));
|
|
4954
|
-
for (let offset = 0;offset < replacement.orderedLinks.length; offset += input.pageRows) {
|
|
4955
|
-
this.requireSession(input.session);
|
|
4956
|
-
const selected = replacement.orderedLinks.slice(offset, offset + input.pageRows);
|
|
4957
|
-
const links = [];
|
|
4958
|
-
for (const entry of selected) {
|
|
4959
|
-
const key = projectionEntityKey2({ kind: "link", ref: entry.ref });
|
|
4960
|
-
const base = await this.linkState(session, entry.ref);
|
|
4961
|
-
const ownedByReplacement = replacement.owned.has(key);
|
|
4962
|
-
links.push({
|
|
4963
|
-
ref: base.ref,
|
|
4964
|
-
candidateSource: ownedByReplacement ? storedSourceLink(input.source.projectionId, replacement.candidate.materializationId, replacement.candidate.rowsByEntity.get(key)) : base.source,
|
|
4965
|
-
override: base.override,
|
|
4966
|
-
slotOverride: base.slotOverride,
|
|
4967
|
-
effective: base.effective,
|
|
4968
|
-
diffRequired: entry.diffRequired
|
|
4850
|
+
return unplanned(plan, input.entityKind).map((identity) => projectionEntityKey2(identity.entity));
|
|
4851
|
+
});
|
|
4852
|
+
for (let offset = 0;offset < pending.length; offset += input.pageRows) {
|
|
4853
|
+
const keys = pending.slice(offset, offset + input.pageRows);
|
|
4854
|
+
const page = await this.runRootOperation(async () => {
|
|
4855
|
+
const { plan, candidate } = await this.requirePlan(input);
|
|
4856
|
+
const selected = keys.flatMap((key) => {
|
|
4857
|
+
const identity = plan.identities.get(key);
|
|
4858
|
+
return identity?.plannedRevision === null ? [identity] : [];
|
|
4969
4859
|
});
|
|
4970
|
-
|
|
4971
|
-
|
|
4972
|
-
|
|
4973
|
-
|
|
4860
|
+
if (selected.length === 0)
|
|
4861
|
+
return null;
|
|
4862
|
+
return input.entityKind === "object" ? this.objectPage(plan, candidate, selected) : this.linkPage(plan, candidate, selected);
|
|
4863
|
+
});
|
|
4864
|
+
if (!page)
|
|
4865
|
+
continue;
|
|
4866
|
+
this.hooks.observeBuffer?.(`replacement.${input.entityKind}.page`, page.objects.length + page.links.length);
|
|
4867
|
+
yield page;
|
|
4974
4868
|
}
|
|
4975
|
-
this.requireSession(input.session);
|
|
4976
|
-
replacement.linkStreamCompleted = true;
|
|
4977
4869
|
}
|
|
4978
|
-
async
|
|
4979
|
-
|
|
4980
|
-
|
|
4981
|
-
|
|
4982
|
-
|
|
4983
|
-
|
|
4984
|
-
|
|
4985
|
-
|
|
4986
|
-
|
|
4987
|
-
|
|
4988
|
-
|
|
4989
|
-
|
|
4990
|
-
|
|
4991
|
-
|
|
4992
|
-
|
|
4870
|
+
async stage(input) {
|
|
4871
|
+
await this.runRootOperation(async () => {
|
|
4872
|
+
const { plan } = await this.requirePlan(input);
|
|
4873
|
+
const updates = prepareReplacementIdentities2(input, plan).map((prepared) => {
|
|
4874
|
+
const current = plan.identities.get(prepared.entityKey);
|
|
4875
|
+
if (!current || current.readRevision === null || current.plannedRevision !== null) {
|
|
4876
|
+
throw new MaterializationValidationError2(`Replacement identity ${prepared.entityKey} is not streamed and still to plan.`);
|
|
4877
|
+
}
|
|
4878
|
+
return { current, records: structuredClone(prepared.records) };
|
|
4879
|
+
});
|
|
4880
|
+
const claimed = new Set;
|
|
4881
|
+
for (const { records } of updates) {
|
|
4882
|
+
for (const record of records) {
|
|
4883
|
+
for (const key of workKeys(record)) {
|
|
4884
|
+
if (claimed.has(key) || plan.workKeys.has(key)) {
|
|
4885
|
+
throw duplicateMaterializationWork2(record.recordKey);
|
|
4886
|
+
}
|
|
4887
|
+
claimed.add(key);
|
|
4888
|
+
}
|
|
4889
|
+
}
|
|
4993
4890
|
}
|
|
4994
|
-
|
|
4995
|
-
|
|
4996
|
-
|
|
4997
|
-
|
|
4998
|
-
|
|
4999
|
-
for (const record of cloned) {
|
|
5000
|
-
session.work.set(record.recordKey, record);
|
|
5001
|
-
session.workUniqueKeys.add(workUniquenessKey2(record));
|
|
5002
|
-
if (record.kind === "plan")
|
|
5003
|
-
session.applyWork.push(record);
|
|
5004
|
-
if (record.kind === "cardinality")
|
|
5005
|
-
session.cardinalityWork.push(record);
|
|
5006
|
-
if (record.kind === "event")
|
|
5007
|
-
session.eventWork.push(record);
|
|
5008
|
-
if (record.kind === "object-existence") {
|
|
5009
|
-
session.objectExistence.set(objectRefKey2(record.ref), record);
|
|
4891
|
+
const staged = updates.flatMap(({ records }) => records);
|
|
4892
|
+
this.hooks.observeWork?.(staged);
|
|
4893
|
+
for (const { current, records } of updates) {
|
|
4894
|
+
current.records = records;
|
|
4895
|
+
current.plannedRevision = current.readRevision;
|
|
5010
4896
|
}
|
|
5011
|
-
|
|
5012
|
-
|
|
5013
|
-
|
|
5014
|
-
|
|
5015
|
-
|
|
5016
|
-
|
|
4897
|
+
for (const key of claimed)
|
|
4898
|
+
plan.workKeys.add(key);
|
|
4899
|
+
this.hooks.observeBuffer?.("plan.stage", updates.length);
|
|
4900
|
+
});
|
|
4901
|
+
}
|
|
4902
|
+
async refresh(input) {
|
|
4903
|
+
const { plan } = await this.requirePlan(input);
|
|
4904
|
+
const pending = [...plan.identities.values()].filter((identity) => identity.plannedRevision === null);
|
|
4905
|
+
if (pending.length > 0)
|
|
4906
|
+
return { fresh: false, unplanned: pending.length };
|
|
4907
|
+
let unplannedCount = 0;
|
|
4908
|
+
if (this.state.commitsById.size !== plan.watermark) {
|
|
4909
|
+
const touched = emptyCommitTouches(plan.projectId);
|
|
4910
|
+
for (let ordinal = plan.watermark + 1;ordinal <= this.state.commitsById.size; ordinal += 1) {
|
|
4911
|
+
const touches = this.state.commitTouches.get(ordinal);
|
|
4912
|
+
if (touches?.projectId !== plan.projectId)
|
|
4913
|
+
continue;
|
|
4914
|
+
for (const kind of ["objects", "links", "scopes"]) {
|
|
4915
|
+
for (const key of touches[kind])
|
|
4916
|
+
touched[kind].add(key);
|
|
5017
4917
|
}
|
|
5018
4918
|
}
|
|
4919
|
+
for (const identity of plan.identities.values()) {
|
|
4920
|
+
if (!touchesIdentity(touched, identity.entity))
|
|
4921
|
+
continue;
|
|
4922
|
+
if (this.revision(plan, identity) === identity.plannedRevision)
|
|
4923
|
+
continue;
|
|
4924
|
+
unplan(plan, identity);
|
|
4925
|
+
unplannedCount += 1;
|
|
4926
|
+
}
|
|
4927
|
+
unplannedCount += this.expandTouched(plan, touched);
|
|
4928
|
+
plan.watermark = this.state.commitsById.size;
|
|
5019
4929
|
}
|
|
5020
|
-
|
|
4930
|
+
if (unplannedCount > 0)
|
|
4931
|
+
return { fresh: false, unplanned: unplannedCount };
|
|
4932
|
+
return {
|
|
4933
|
+
fresh: true,
|
|
4934
|
+
counts: projectionChangeCounts([...plan.identities.values()].flatMap((identity) => identity.records))
|
|
4935
|
+
};
|
|
5021
4936
|
}
|
|
5022
|
-
async
|
|
4937
|
+
async purge(input) {
|
|
4938
|
+
assertNonblank2(input.projectId, "Replacement plan purge project id");
|
|
4939
|
+
assertPositiveInteger2(input.limit, "Replacement plan purge limit");
|
|
4940
|
+
return this.runRootOperation(() => {
|
|
4941
|
+
let horizon = this.state.commitsById.size;
|
|
4942
|
+
for (const plan of this.state.replacementPlans.values()) {
|
|
4943
|
+
if (plan.projectId === input.projectId)
|
|
4944
|
+
horizon = Math.min(horizon, plan.watermark);
|
|
4945
|
+
}
|
|
4946
|
+
let deleted = 0;
|
|
4947
|
+
for (const [ordinal, touches] of this.state.commitTouches) {
|
|
4948
|
+
if (deleted === input.limit)
|
|
4949
|
+
break;
|
|
4950
|
+
if (ordinal > horizon || touches.projectId !== input.projectId)
|
|
4951
|
+
continue;
|
|
4952
|
+
this.state.commitTouches.delete(ordinal);
|
|
4953
|
+
deleted += 1;
|
|
4954
|
+
}
|
|
4955
|
+
return deleted;
|
|
4956
|
+
});
|
|
4957
|
+
}
|
|
4958
|
+
async objectPage(plan, candidate, selected) {
|
|
4959
|
+
const objects = [];
|
|
4960
|
+
for (const identity of selected) {
|
|
4961
|
+
const ref = identity.entity.ref;
|
|
4962
|
+
const base = await this.reader.objectState(plan.projectId, ref);
|
|
4963
|
+
objects.push({
|
|
4964
|
+
ref: base.ref,
|
|
4965
|
+
candidateSource: storedSourceObject(plan.sourceId, plan.materializationId, candidate.rowsByEntity.get(projectionEntityKey2(identity.entity))),
|
|
4966
|
+
override: base.override,
|
|
4967
|
+
effective: base.effective,
|
|
4968
|
+
latestTelemetry: base.latestTelemetry
|
|
4969
|
+
});
|
|
4970
|
+
identity.readRevision = this.revision(plan, identity);
|
|
4971
|
+
}
|
|
4972
|
+
return { objects, links: [], endpoints: [] };
|
|
4973
|
+
}
|
|
4974
|
+
async linkPage(plan, candidate, selected) {
|
|
4975
|
+
const links = [];
|
|
4976
|
+
const endpoints = new Map;
|
|
4977
|
+
for (const identity of selected) {
|
|
4978
|
+
const ref = identity.entity.ref;
|
|
4979
|
+
const key = projectionEntityKey2(identity.entity);
|
|
4980
|
+
const base = await this.reader.linkState(plan.projectId, ref);
|
|
4981
|
+
links.push({
|
|
4982
|
+
ref: base.ref,
|
|
4983
|
+
candidateSource: plan.owned.has(key) ? storedSourceLink(plan.sourceId, plan.materializationId, candidate.rowsByEntity.get(key)) : base.source,
|
|
4984
|
+
override: base.override,
|
|
4985
|
+
slotOverride: base.slotOverride,
|
|
4986
|
+
effective: base.effective,
|
|
4987
|
+
diffRequired: identity.diffRequired
|
|
4988
|
+
});
|
|
4989
|
+
for (const endpoint of [ref.source, ref.target]) {
|
|
4990
|
+
endpoints.set(objectRefKey2(endpoint), {
|
|
4991
|
+
ref: structuredClone(endpoint),
|
|
4992
|
+
exists: this.endpointExists(plan, endpoint)
|
|
4993
|
+
});
|
|
4994
|
+
}
|
|
4995
|
+
identity.readRevision = this.revision(plan, identity);
|
|
4996
|
+
}
|
|
4997
|
+
return { objects: [], links, endpoints: [...endpoints.values()] };
|
|
4998
|
+
}
|
|
4999
|
+
endpointExists(plan, ref) {
|
|
5000
|
+
const planned = plan.identities.get(projectionEntityKey2({ kind: "object", ref }));
|
|
5001
|
+
const existence = planned?.records.find((record) => record.kind === "object-existence");
|
|
5002
|
+
if (existence?.kind === "object-existence")
|
|
5003
|
+
return existence.exists;
|
|
5004
|
+
return getInMemoryObjectMaterializerAdapter(this.objects).getExactObjectRow(plan.projectId, ref.objectTypeId, ref.primaryId) !== null;
|
|
5005
|
+
}
|
|
5006
|
+
revision(plan, identity) {
|
|
5007
|
+
if (identity.entity.kind === "object") {
|
|
5008
|
+
return stableJsonStringify2(this.objectRevision(plan.projectId, identity.entity.ref));
|
|
5009
|
+
}
|
|
5010
|
+
const ref = identity.entity.ref;
|
|
5011
|
+
const projectId = plan.projectId;
|
|
5012
|
+
const row = getInMemoryObjectMaterializerAdapter(this.objects).getExactLinkRow(projectId, {
|
|
5013
|
+
sourceTypeId: ref.source.objectTypeId,
|
|
5014
|
+
sourceId: ref.source.primaryId,
|
|
5015
|
+
linkId: ref.linkId,
|
|
5016
|
+
targetTypeId: ref.target.objectTypeId,
|
|
5017
|
+
targetId: ref.target.primaryId
|
|
5018
|
+
});
|
|
5019
|
+
const live = this.reader.findActiveLinkSource(projectId, ref);
|
|
5020
|
+
return stableJsonStringify2([
|
|
5021
|
+
row?.lastCommitId ?? null,
|
|
5022
|
+
this.state.linkOverrides.get(projectEntityKey(projectId, linkRefKey2(ref)))?.lastCommitId ?? null,
|
|
5023
|
+
this.state.linkSlotOverrides.get(projectEntityKey(projectId, linkScopeKey(ref.source, ref.linkId)))?.lastCommitId ?? null,
|
|
5024
|
+
live ? [live.source.projectionId, live.materializationId, live.stagingOrdinal] : null,
|
|
5025
|
+
this.endpointRevision(plan, ref.source),
|
|
5026
|
+
this.endpointRevision(plan, ref.target)
|
|
5027
|
+
]);
|
|
5028
|
+
}
|
|
5029
|
+
endpointRevision(plan, ref) {
|
|
5030
|
+
if (plan.identities.has(projectionEntityKey2({ kind: "object", ref }))) {
|
|
5031
|
+
return this.objectRevision(plan.projectId, ref);
|
|
5032
|
+
}
|
|
5033
|
+
return getInMemoryObjectMaterializerAdapter(this.objects).getExactObjectRow(plan.projectId, ref.objectTypeId, ref.primaryId) !== null;
|
|
5034
|
+
}
|
|
5035
|
+
objectRevision(projectId, ref) {
|
|
5036
|
+
const row = getInMemoryObjectMaterializerAdapter(this.objects).getExactObjectRow(projectId, ref.objectTypeId, ref.primaryId);
|
|
5037
|
+
return [
|
|
5038
|
+
row ? [row.version, row.lastCommitId] : null,
|
|
5039
|
+
this.state.objectOverrides.get(projectEntityKey(projectId, objectRefKey2(ref)))?.lastCommitId ?? null,
|
|
5040
|
+
this.reader.latestTelemetry(projectId, ref).map((point) => [point.series.propertyId, point.at, point.lastCommitId])
|
|
5041
|
+
];
|
|
5042
|
+
}
|
|
5043
|
+
expandLinks(plan) {
|
|
5044
|
+
const projectId = plan.projectId;
|
|
5045
|
+
const incident = new Set;
|
|
5046
|
+
for (const identity of plan.identities.values()) {
|
|
5047
|
+
if (identity.entity.kind !== "object" || identity.expanded)
|
|
5048
|
+
continue;
|
|
5049
|
+
if (identity.plannedRevision === null)
|
|
5050
|
+
continue;
|
|
5051
|
+
identity.expanded = true;
|
|
5052
|
+
for (const record of identity.records) {
|
|
5053
|
+
if (record.kind === "incident-object")
|
|
5054
|
+
incident.add(objectRefKey2(record.ref));
|
|
5055
|
+
}
|
|
5056
|
+
}
|
|
5057
|
+
let added = 0;
|
|
5058
|
+
const consider = (ref, diffRequired) => {
|
|
5059
|
+
if (addIdentity(plan, { kind: "link", ref }, diffRequired))
|
|
5060
|
+
added += 1;
|
|
5061
|
+
};
|
|
5062
|
+
if (incident.size > 0) {
|
|
5063
|
+
const index = this.reader.incidentLinkIndex(projectId);
|
|
5064
|
+
for (const key of incident) {
|
|
5065
|
+
for (const ref of index.get(key) ?? [])
|
|
5066
|
+
consider(ref, true);
|
|
5067
|
+
}
|
|
5068
|
+
}
|
|
5069
|
+
const adapter = getInMemoryObjectMaterializerAdapter(this.objects);
|
|
5070
|
+
const scopes = new Map;
|
|
5071
|
+
for (const identity of plan.identities.values()) {
|
|
5072
|
+
if (identity.entity.kind !== "link" || !identity.diffRequired || identity.expanded)
|
|
5073
|
+
continue;
|
|
5074
|
+
identity.expanded = true;
|
|
5075
|
+
const ref = identity.entity.ref;
|
|
5076
|
+
scopes.set(linkScopeSortKey2(ref.source, ref.linkId), ref);
|
|
5077
|
+
}
|
|
5078
|
+
for (const scope of scopes.values()) {
|
|
5079
|
+
adapter.visitExactScopeLinks(projectId, scope.source.objectTypeId, scope.source.primaryId, scope.linkId, (row) => consider(linkRef(row), false));
|
|
5080
|
+
const override = this.state.linkSlotOverrides.get(projectEntityKey(projectId, linkScopeKey(scope.source, scope.linkId)));
|
|
5081
|
+
if (override)
|
|
5082
|
+
consider({ ...scope, target: override.value.target }, false);
|
|
5083
|
+
}
|
|
5084
|
+
return added;
|
|
5085
|
+
}
|
|
5086
|
+
expandTouched(plan, touched) {
|
|
5087
|
+
const projectId = plan.projectId;
|
|
5088
|
+
const incident = new Set;
|
|
5089
|
+
const scopes = new Set;
|
|
5090
|
+
for (const identity of plan.identities.values()) {
|
|
5091
|
+
for (const record of identity.records) {
|
|
5092
|
+
if (record.kind === "incident-object")
|
|
5093
|
+
incident.add(objectRefKey2(record.ref));
|
|
5094
|
+
}
|
|
5095
|
+
if (identity.entity.kind === "link" && identity.diffRequired) {
|
|
5096
|
+
scopes.add(linkScopeKey(identity.entity.ref.source, identity.entity.ref.linkId));
|
|
5097
|
+
}
|
|
5098
|
+
}
|
|
5099
|
+
let added = 0;
|
|
5100
|
+
const consider = (ref, member) => {
|
|
5101
|
+
if (incident.has(objectRefKey2(ref.source)) || incident.has(objectRefKey2(ref.target))) {
|
|
5102
|
+
if (addIdentity(plan, { kind: "link", ref }, true))
|
|
5103
|
+
added += 1;
|
|
5104
|
+
} else if (member && scopes.has(linkScopeKey(ref.source, ref.linkId))) {
|
|
5105
|
+
if (addIdentity(plan, { kind: "link", ref }, false))
|
|
5106
|
+
added += 1;
|
|
5107
|
+
}
|
|
5108
|
+
};
|
|
5109
|
+
const adapter = getInMemoryObjectMaterializerAdapter(this.objects);
|
|
5110
|
+
for (const key of touched.links) {
|
|
5111
|
+
const ref = parseLinkKey(key);
|
|
5112
|
+
const effective = adapter.getExactLinkRow(projectId, {
|
|
5113
|
+
sourceTypeId: ref.source.objectTypeId,
|
|
5114
|
+
sourceId: ref.source.primaryId,
|
|
5115
|
+
linkId: ref.linkId,
|
|
5116
|
+
targetTypeId: ref.target.objectTypeId,
|
|
5117
|
+
targetId: ref.target.primaryId
|
|
5118
|
+
}) !== null;
|
|
5119
|
+
if (effective || this.state.linkOverrides.has(projectEntityKey(projectId, key)) || this.state.activeSourceRows.has(projectEntityKey(projectId, projectionEntityKey2({ kind: "link", ref })))) {
|
|
5120
|
+
consider(ref, effective);
|
|
5121
|
+
}
|
|
5122
|
+
}
|
|
5123
|
+
for (const key of touched.scopes) {
|
|
5124
|
+
const override = this.state.linkSlotOverrides.get(projectEntityKey(projectId, key));
|
|
5125
|
+
if (override)
|
|
5126
|
+
consider({ ...override.ref, target: override.value.target }, true);
|
|
5127
|
+
}
|
|
5128
|
+
return added;
|
|
5129
|
+
}
|
|
5130
|
+
async requireCandidate(input) {
|
|
5131
|
+
const candidate = this.state.sourceMaterializations.get(replacementPlanKey(input));
|
|
5132
|
+
if (!candidate || candidate.status !== "ready" || candidate.projectionRunId !== input.execution.projectionRunId || candidate.executionToken !== input.execution.executionToken) {
|
|
5133
|
+
throw new MaterializationConflictError2("source-materialization", `Candidate source materialization '${input.materializationId}' is missing, not ready, or owned by another execution.`);
|
|
5134
|
+
}
|
|
5135
|
+
await this.assertExecution({
|
|
5136
|
+
projectId: input.projectId,
|
|
5137
|
+
source: input.source,
|
|
5138
|
+
execution: input.execution
|
|
5139
|
+
});
|
|
5140
|
+
return candidate;
|
|
5141
|
+
}
|
|
5142
|
+
async requirePlan(input) {
|
|
5143
|
+
const candidate = await this.requireCandidate(input);
|
|
5144
|
+
const plan = this.state.replacementPlans.get(replacementPlanKey(input));
|
|
5145
|
+
if (!plan) {
|
|
5146
|
+
throw new MaterializationConflictError2("source-materialization", `Candidate source materialization '${input.materializationId}' has no open plan.`);
|
|
5147
|
+
}
|
|
5148
|
+
return { plan, candidate };
|
|
5149
|
+
}
|
|
5150
|
+
}
|
|
5151
|
+
function addIdentity(plan, entity, diffRequired) {
|
|
5152
|
+
const key = projectionEntityKey2(entity);
|
|
5153
|
+
const existing = plan.identities.get(key);
|
|
5154
|
+
if (existing) {
|
|
5155
|
+
if (!diffRequired || existing.diffRequired)
|
|
5156
|
+
return false;
|
|
5157
|
+
existing.diffRequired = true;
|
|
5158
|
+
unplan(plan, existing);
|
|
5159
|
+
return true;
|
|
5160
|
+
}
|
|
5161
|
+
plan.identities.set(key, {
|
|
5162
|
+
entity: structuredClone({ kind: entity.kind, ref: entity.ref }),
|
|
5163
|
+
sortKey: entity.kind === "object" ? objectRefSortKey2(entity.ref) : linkRefSortKey2(entity.ref),
|
|
5164
|
+
diffRequired,
|
|
5165
|
+
expanded: false,
|
|
5166
|
+
readRevision: null,
|
|
5167
|
+
plannedRevision: null,
|
|
5168
|
+
records: []
|
|
5169
|
+
});
|
|
5170
|
+
return true;
|
|
5171
|
+
}
|
|
5172
|
+
function unplan(plan, identity) {
|
|
5173
|
+
for (const record of identity.records) {
|
|
5174
|
+
for (const key of workKeys(record))
|
|
5175
|
+
plan.workKeys.delete(key);
|
|
5176
|
+
}
|
|
5177
|
+
identity.readRevision = null;
|
|
5178
|
+
identity.plannedRevision = null;
|
|
5179
|
+
identity.expanded = false;
|
|
5180
|
+
identity.records = [];
|
|
5181
|
+
}
|
|
5182
|
+
function touchesIdentity(touched, entity) {
|
|
5183
|
+
if (entity.kind === "object")
|
|
5184
|
+
return touched.objects.has(objectRefKey2(entity.ref));
|
|
5185
|
+
const { ref } = entity;
|
|
5186
|
+
return touched.links.has(linkRefKey2(ref)) || touched.scopes.has(linkScopeKey(ref.source, ref.linkId)) || touched.objects.has(objectRefKey2(ref.source)) || touched.objects.has(objectRefKey2(ref.target));
|
|
5187
|
+
}
|
|
5188
|
+
function parseLinkKey(key) {
|
|
5189
|
+
const [sourceTypeId, sourceId, linkId, targetTypeId, targetId] = JSON.parse(key);
|
|
5190
|
+
return {
|
|
5191
|
+
source: { objectTypeId: sourceTypeId, primaryId: sourceId },
|
|
5192
|
+
linkId,
|
|
5193
|
+
target: { objectTypeId: targetTypeId, primaryId: targetId }
|
|
5194
|
+
};
|
|
5195
|
+
}
|
|
5196
|
+
function workKeys(record) {
|
|
5197
|
+
return [`record:${record.recordKey}`, `unique:${workUniquenessKey2(record)}`];
|
|
5198
|
+
}
|
|
5199
|
+
function unplanned(plan, kind) {
|
|
5200
|
+
return [...plan.identities.values()].filter((identity) => identity.entity.kind === kind && identity.plannedRevision === null).sort((left, right) => left.sortKey.localeCompare(right.sortKey));
|
|
5201
|
+
}
|
|
5202
|
+
|
|
5203
|
+
// src/storage/ontology/in-memory/vectors.ts
|
|
5204
|
+
function vectorObjectKey(projectId, ref) {
|
|
5205
|
+
return JSON.stringify([projectId, ref.objectTypeId, ref.primaryId]);
|
|
5206
|
+
}
|
|
5207
|
+
|
|
5208
|
+
class InMemoryOntologyVectorStorage {
|
|
5209
|
+
state;
|
|
5210
|
+
assertSession;
|
|
5211
|
+
runRootOperation;
|
|
5212
|
+
constructor(state, assertSession, runRootOperation) {
|
|
5213
|
+
this.state = state;
|
|
5214
|
+
this.assertSession = assertSession;
|
|
5215
|
+
this.runRootOperation = runRootOperation;
|
|
5216
|
+
}
|
|
5217
|
+
async list(input) {
|
|
5218
|
+
return this.listBatch({ projectId: input.projectId, refs: [input.ref] });
|
|
5219
|
+
}
|
|
5220
|
+
async listBatch(input) {
|
|
5221
|
+
return this.runRootOperation(() => [...new Set(input.refs.map((ref) => vectorObjectKey(input.projectId, ref)))].flatMap((key) => [...this.state.get(key)?.values() ?? []].map(({ values: _values, ...metadata }) => structuredClone(metadata))));
|
|
5222
|
+
}
|
|
5223
|
+
async removeBatch(input) {
|
|
5224
|
+
this.assertSession(input.session, input.projectId);
|
|
5225
|
+
for (const entry of input.entries) {
|
|
5226
|
+
await this.remove({ session: input.session, projectId: input.projectId, ...entry });
|
|
5227
|
+
}
|
|
5228
|
+
}
|
|
5229
|
+
async write(input) {
|
|
5230
|
+
this.assertSession(input.session, input.projectId, input.value.lastCommitId);
|
|
5231
|
+
const key = vectorObjectKey(input.projectId, input.value.ref);
|
|
5232
|
+
const profiles = this.state.get(key) ?? new Map;
|
|
5233
|
+
this.assertRevision(profiles.get(input.value.profile), input.expectedCommitId);
|
|
5234
|
+
profiles.set(input.value.profile, structuredClone(input.value));
|
|
5235
|
+
this.state.set(key, profiles);
|
|
5236
|
+
}
|
|
5237
|
+
async writeBatch(input) {
|
|
5238
|
+
for (const entry of input.entries) {
|
|
5239
|
+
await this.write({ session: input.session, projectId: input.projectId, ...entry });
|
|
5240
|
+
}
|
|
5241
|
+
}
|
|
5242
|
+
async remove(input) {
|
|
5243
|
+
this.assertSession(input.session, input.projectId);
|
|
5244
|
+
const key = vectorObjectKey(input.projectId, input.ref);
|
|
5245
|
+
const profiles = this.state.get(key);
|
|
5246
|
+
this.assertRevision(profiles?.get(input.profile), input.expectedCommitId);
|
|
5247
|
+
profiles?.delete(input.profile);
|
|
5248
|
+
if (profiles?.size === 0)
|
|
5249
|
+
this.state.delete(key);
|
|
5250
|
+
}
|
|
5251
|
+
assertRevision(current, expected) {
|
|
5252
|
+
if ((current?.lastCommitId ?? null) !== expected) {
|
|
5253
|
+
throw new MaterializationConflictError2("effective-state", "Vector changed since it was prepared.");
|
|
5254
|
+
}
|
|
5255
|
+
}
|
|
5256
|
+
}
|
|
5257
|
+
|
|
5258
|
+
// src/storage/ontology/in-memory/materializations.ts
|
|
5259
|
+
class InMemoryOntologyMaterializationStorage {
|
|
5260
|
+
state;
|
|
5261
|
+
objects;
|
|
5262
|
+
timeseries;
|
|
5263
|
+
reader;
|
|
5264
|
+
getTransactionToken;
|
|
5265
|
+
getMaterializationLifecycle;
|
|
5266
|
+
readExecution;
|
|
5267
|
+
hooks;
|
|
5268
|
+
sessions = new WeakMap;
|
|
5269
|
+
liveSessions = new Set;
|
|
5270
|
+
constructor(state, objects, timeseries, reader, getTransactionToken, getMaterializationLifecycle, readExecution, hooks = {}) {
|
|
5271
|
+
this.state = state;
|
|
5272
|
+
this.objects = objects;
|
|
5273
|
+
this.timeseries = timeseries;
|
|
5274
|
+
this.reader = reader;
|
|
5275
|
+
this.getTransactionToken = getTransactionToken;
|
|
5276
|
+
this.getMaterializationLifecycle = getMaterializationLifecycle;
|
|
5277
|
+
this.readExecution = readExecution;
|
|
5278
|
+
this.hooks = hooks;
|
|
5279
|
+
}
|
|
5280
|
+
async begin(input) {
|
|
5281
|
+
const transactionToken = this.getTransactionToken();
|
|
5282
|
+
const lifecycle = this.getMaterializationLifecycle();
|
|
5283
|
+
if (!transactionToken || !lifecycle) {
|
|
5284
|
+
throw new MaterializationValidationError2("Materialization sessions require an active storage transaction.");
|
|
5285
|
+
}
|
|
5286
|
+
assertMaterializationHeader2(input);
|
|
5287
|
+
if (!await this.readExecution(input.commit.projectId, input.commit.executionId)) {
|
|
5288
|
+
throw new MaterializationValidationError2(`Ontology commit execution '${input.commit.executionId}' does not exist in project '${input.commit.projectId}'.`);
|
|
5289
|
+
}
|
|
5290
|
+
this.assertCommitAbsent(input);
|
|
5291
|
+
for (const expected of input.expected.sources)
|
|
5292
|
+
this.assertSource(expected, input.commit.projectId);
|
|
5293
|
+
for (const expected of input.expected.objects)
|
|
5294
|
+
await this.assertObject(expected, input.commit.projectId);
|
|
5295
|
+
for (const expected of input.expected.links)
|
|
5296
|
+
await this.assertLink(expected, input.commit.projectId);
|
|
5297
|
+
const expectedScopeRevisions = new Map;
|
|
5298
|
+
for (const expected of input.expected.linkScopes) {
|
|
5299
|
+
const key = linkScopeSortKey2(expected.source, expected.linkId);
|
|
5300
|
+
const current = expectedScopeRevisions.get(key) ?? this.reader.effectiveLinkScope(input.commit.projectId, expected.source, expected.linkId);
|
|
5301
|
+
expectedScopeRevisions.set(key, current);
|
|
5302
|
+
assertExpectedLinkScopeRevision2(current.fingerprint, expected);
|
|
5303
|
+
}
|
|
5304
|
+
for (const expected of input.expected.points)
|
|
5305
|
+
this.assertPoint(expected, input.commit.projectId);
|
|
5306
|
+
const plan = input.plan ? this.requirePlan(input) : null;
|
|
5307
|
+
const providerToken = {};
|
|
5308
|
+
const session = {
|
|
5309
|
+
providerToken,
|
|
5310
|
+
header: structuredClone(input),
|
|
5311
|
+
transactionToken,
|
|
5312
|
+
lifecycle,
|
|
5313
|
+
active: true,
|
|
5314
|
+
writeOrdinal: 0,
|
|
5315
|
+
work: new Map,
|
|
5316
|
+
workUniqueKeys: new Set,
|
|
5317
|
+
applyWork: [],
|
|
5318
|
+
cardinalityWork: [],
|
|
5319
|
+
eventWork: [],
|
|
5320
|
+
outboxWrites: new Map,
|
|
5321
|
+
workSealed: false,
|
|
5322
|
+
vectorChangesStreamed: false,
|
|
5323
|
+
applied: false,
|
|
5324
|
+
appliedEventCount: 0,
|
|
5325
|
+
incidentLinksByObject: null,
|
|
5326
|
+
linkSlotStates: new Map,
|
|
5327
|
+
plan
|
|
5328
|
+
};
|
|
5329
|
+
if (plan) {
|
|
5330
|
+
for (const identity of plan.identities.values()) {
|
|
5331
|
+
for (const record of structuredClone(identity.records))
|
|
5332
|
+
this.addWork(session, record);
|
|
5333
|
+
}
|
|
5334
|
+
}
|
|
5335
|
+
this.sessions.set(providerToken, session);
|
|
5336
|
+
this.liveSessions.add(session);
|
|
5337
|
+
lifecycle.register(providerToken);
|
|
5338
|
+
return { providerToken };
|
|
5339
|
+
}
|
|
5340
|
+
deactivateTransaction(transactionToken) {
|
|
5341
|
+
for (const session of this.liveSessions) {
|
|
5342
|
+
if (session.transactionToken !== transactionToken)
|
|
5343
|
+
continue;
|
|
5344
|
+
this.releaseSession(session);
|
|
5345
|
+
}
|
|
5346
|
+
}
|
|
5347
|
+
releaseSession(session) {
|
|
5348
|
+
session.active = false;
|
|
5349
|
+
session.work.clear();
|
|
5350
|
+
session.workUniqueKeys.clear();
|
|
5351
|
+
session.applyWork.length = 0;
|
|
5352
|
+
session.cardinalityWork.length = 0;
|
|
5353
|
+
session.eventWork.length = 0;
|
|
5354
|
+
session.outboxWrites.clear();
|
|
5355
|
+
session.incidentLinksByObject = null;
|
|
5356
|
+
session.linkSlotStates = null;
|
|
5357
|
+
this.liveSessions.delete(session);
|
|
5358
|
+
session.lifecycle.complete(session.providerToken);
|
|
5359
|
+
}
|
|
5360
|
+
async* streamState(input) {
|
|
5023
5361
|
const session = this.requireSession(input.session);
|
|
5024
5362
|
assertPageRows2(input.pageRows);
|
|
5025
|
-
const
|
|
5026
|
-
if (stream.started) {
|
|
5027
|
-
throw new MaterializationConflictError2("effective-state", `Materialization ${input.order} work may only be streamed once per session.`);
|
|
5028
|
-
}
|
|
5029
|
-
stream.started = true;
|
|
5030
|
-
if (!session.workSealed) {
|
|
5031
|
-
session.applyWork.sort(comparePlanWork2);
|
|
5032
|
-
session.cardinalityWork.sort(compareCardinalityWork2);
|
|
5033
|
-
session.eventWork.sort(compareEventWork2);
|
|
5034
|
-
session.workSealed = true;
|
|
5035
|
-
}
|
|
5036
|
-
const records = input.order === "apply" ? session.applyWork : input.order === "cardinality" ? session.cardinalityWork : session.eventWork;
|
|
5037
|
-
for (let offset = 0;offset < records.length; offset += input.pageRows) {
|
|
5363
|
+
for await (const request of input.requests) {
|
|
5038
5364
|
this.requireSession(input.session);
|
|
5039
|
-
|
|
5040
|
-
|
|
5041
|
-
|
|
5042
|
-
|
|
5365
|
+
this.hooks.beforeRead?.("state.read");
|
|
5366
|
+
const objectRefs = uniqueSorted2(request.objects, objectRefKey2, objectRefSortKey2);
|
|
5367
|
+
for (let offset = 0;offset < objectRefs.length; offset += input.pageRows) {
|
|
5368
|
+
this.requireSession(input.session);
|
|
5369
|
+
const objects = [];
|
|
5370
|
+
for (const ref of objectRefs.slice(offset, offset + input.pageRows)) {
|
|
5371
|
+
objects.push(await this.reader.objectState(session.header.commit.projectId, ref));
|
|
5372
|
+
}
|
|
5373
|
+
this.requireSession(input.session);
|
|
5374
|
+
this.hooks.observeBuffer?.("state.object.page", objects.length);
|
|
5375
|
+
yield { objects, links: [], linkScopes: [], points: [] };
|
|
5376
|
+
}
|
|
5377
|
+
const linkRefs = uniqueSorted2(request.links, linkRefKey2, linkRefSortKey2);
|
|
5378
|
+
for (let offset = 0;offset < linkRefs.length; offset += input.pageRows) {
|
|
5379
|
+
this.requireSession(input.session);
|
|
5380
|
+
const links = [];
|
|
5381
|
+
for (const ref of linkRefs.slice(offset, offset + input.pageRows)) {
|
|
5382
|
+
links.push(await this.reader.linkState(session.header.commit.projectId, ref));
|
|
5383
|
+
}
|
|
5384
|
+
this.requireSession(input.session);
|
|
5385
|
+
this.hooks.observeBuffer?.("state.link.page", links.length);
|
|
5386
|
+
yield { objects: [], links, linkScopes: [], points: [] };
|
|
5387
|
+
}
|
|
5388
|
+
const incidentRefs = this.incidentLinkRefs(session, request.incidentObjects);
|
|
5389
|
+
for (let offset = 0;offset < incidentRefs.length; offset += input.pageRows) {
|
|
5390
|
+
this.requireSession(input.session);
|
|
5391
|
+
const refs = incidentRefs.slice(offset, offset + input.pageRows);
|
|
5392
|
+
const links = [];
|
|
5393
|
+
for (const ref of refs)
|
|
5394
|
+
links.push(await this.reader.linkState(session.header.commit.projectId, ref));
|
|
5395
|
+
this.requireSession(input.session);
|
|
5396
|
+
this.hooks.observeBuffer?.("state.incident-link.page", links.length);
|
|
5397
|
+
yield { objects: [], links, linkScopes: [], points: [] };
|
|
5398
|
+
}
|
|
5399
|
+
for (const scope of uniqueBy(request.linkScopes, (value) => linkScopeSortKey2(value.source, value.linkId))) {
|
|
5400
|
+
this.requireSession(input.session);
|
|
5401
|
+
const value = this.linkSlotState(session, scope.source, scope.linkId);
|
|
5402
|
+
yield { objects: [], links: [], linkScopes: [value], points: [] };
|
|
5403
|
+
}
|
|
5404
|
+
const requestedPoints = uniqueSorted2(request.points, (point) => telemetryPointKey2(point.series, point.at), (point) => telemetryPointSortKey2(point.series, point.at));
|
|
5405
|
+
for (let offset = 0;offset < requestedPoints.length; offset += input.pageRows) {
|
|
5406
|
+
this.requireSession(input.session);
|
|
5407
|
+
const points = [];
|
|
5408
|
+
for (const point of requestedPoints.slice(offset, offset + input.pageRows)) {
|
|
5409
|
+
const stored = getInMemoryTimeseriesMaterializerAdapter(this.timeseries).getExactPoint(session.header.commit.projectId, point.series, point.at);
|
|
5410
|
+
if (stored)
|
|
5411
|
+
points.push(storedPoint(stored));
|
|
5412
|
+
}
|
|
5413
|
+
this.requireSession(input.session);
|
|
5414
|
+
this.hooks.observeBuffer?.("state.point.page", points.length);
|
|
5415
|
+
if (points.length > 0)
|
|
5416
|
+
yield { objects: [], links: [], linkScopes: [], points };
|
|
5417
|
+
}
|
|
5043
5418
|
}
|
|
5044
|
-
this.requireSession(input.session);
|
|
5045
|
-
stream.completed = true;
|
|
5046
5419
|
}
|
|
5047
|
-
async
|
|
5420
|
+
async stageWork(input) {
|
|
5048
5421
|
const session = this.requireSession(input.session);
|
|
5049
|
-
const
|
|
5050
|
-
|
|
5051
|
-
|
|
5052
|
-
if (record) {
|
|
5053
|
-
result.push({ ref: structuredClone(record.ref), exists: record.exists });
|
|
5422
|
+
for (const { record, uniqueKey } of prepareMaterializationWork2(session, input)) {
|
|
5423
|
+
if (session.work.has(record.recordKey) || session.workUniqueKeys.has(uniqueKey)) {
|
|
5424
|
+
throw duplicateMaterializationWork2(record.recordKey);
|
|
5054
5425
|
}
|
|
5055
5426
|
}
|
|
5056
|
-
|
|
5427
|
+
const cloned = input.records.map((record) => structuredClone(record));
|
|
5428
|
+
this.hooks.observeWork?.(cloned);
|
|
5429
|
+
for (const record of cloned)
|
|
5430
|
+
this.addWork(session, record);
|
|
5431
|
+
this.hooks.observeBuffer?.("work.stage", cloned.length);
|
|
5057
5432
|
}
|
|
5058
|
-
|
|
5433
|
+
addWork(session, record) {
|
|
5434
|
+
session.work.set(record.recordKey, record);
|
|
5435
|
+
session.workUniqueKeys.add(workUniquenessKey2(record));
|
|
5436
|
+
if (record.kind === "plan")
|
|
5437
|
+
session.applyWork.push(record);
|
|
5438
|
+
if (record.kind === "cardinality")
|
|
5439
|
+
session.cardinalityWork.push(record);
|
|
5440
|
+
if (record.kind === "event")
|
|
5441
|
+
session.eventWork.push(record);
|
|
5442
|
+
}
|
|
5443
|
+
async* streamVectorChanges(input) {
|
|
5059
5444
|
const session = this.requireSession(input.session);
|
|
5445
|
+
assertPageRows2(input.pageRows);
|
|
5446
|
+
this.sealWork(session, beginMaterializationVectorChanges2);
|
|
5060
5447
|
const projectId = session.header.commit.projectId;
|
|
5061
|
-
|
|
5062
|
-
|
|
5063
|
-
|
|
5448
|
+
const profiled = new Set(input.objectTypeIds);
|
|
5449
|
+
const changes = session.applyWork.flatMap((record) => {
|
|
5450
|
+
const item = record.item;
|
|
5451
|
+
if (item.kind !== "object-upsert" && item.kind !== "object-delete")
|
|
5452
|
+
return [];
|
|
5453
|
+
const ref = item.kind === "object-upsert" ? item.value.row.ref : item.value.ref;
|
|
5454
|
+
return profiled.has(ref.objectTypeId) || (this.state.vectors.get(vectorObjectKey(projectId, ref))?.size ?? 0) > 0 ? [item] : [];
|
|
5455
|
+
});
|
|
5456
|
+
for (let offset = 0;offset < changes.length; offset += input.pageRows) {
|
|
5457
|
+
this.requireSession(input.session);
|
|
5458
|
+
yield { items: structuredClone(changes.slice(offset, offset + input.pageRows)) };
|
|
5459
|
+
}
|
|
5460
|
+
this.requireSession(input.session);
|
|
5461
|
+
}
|
|
5462
|
+
async apply(input) {
|
|
5463
|
+
const session = this.requireSession(input.session);
|
|
5464
|
+
this.sealWork(session, beginMaterializationApply2);
|
|
5465
|
+
const cardinality = createCardinalityValidator2();
|
|
5466
|
+
for (const record of session.cardinalityWork)
|
|
5467
|
+
cardinality.accept(record);
|
|
5468
|
+
for (let start = 0;start < session.applyWork.length; ) {
|
|
5469
|
+
const phase = session.applyWork[start].applyPhase;
|
|
5470
|
+
let end = start;
|
|
5471
|
+
while (session.applyWork[end]?.applyPhase === phase)
|
|
5472
|
+
end += 1;
|
|
5473
|
+
const items = session.applyWork.slice(start, end).map((record) => record.item);
|
|
5474
|
+
this.writeChunk(session, materializationPlanChunk2(items));
|
|
5475
|
+
start = end;
|
|
5476
|
+
}
|
|
5477
|
+
const outbox = session.eventWork.map((record, ordinal) => materializationOutboxWrite2(session.header.commit, record.draft, ordinal));
|
|
5478
|
+
this.writeChunk(session, materializationPlanChunk2([], outbox));
|
|
5479
|
+
session.appliedEventCount = outbox.length;
|
|
5480
|
+
return { eventCount: outbox.length };
|
|
5481
|
+
}
|
|
5482
|
+
writeChunk(session, chunk) {
|
|
5483
|
+
const projectId = session.header.commit.projectId;
|
|
5484
|
+
this.hooks.observeBuffer?.("apply.chunk", materializationChunkRows2(chunk));
|
|
5064
5485
|
const write = (boundary, apply) => {
|
|
5065
5486
|
this.hooks.beforeWrite?.(boundary, session.writeOrdinal++);
|
|
5066
5487
|
apply();
|
|
5067
5488
|
};
|
|
5068
|
-
for (const item of
|
|
5489
|
+
for (const item of chunk.overrides.objects.upserts)
|
|
5069
5490
|
write("override.object.upsert", () => {
|
|
5070
5491
|
const key = projectEntityKey(projectId, objectRefKey2(item.ref));
|
|
5071
5492
|
assertLastCommit(this.state.objectOverrides.get(key), item.expectedLastCommitId, "object override");
|
|
@@ -5078,13 +5499,13 @@ class InMemoryOntologyMaterializationStorage {
|
|
|
5078
5499
|
updatedAt: item.updatedAt
|
|
5079
5500
|
}));
|
|
5080
5501
|
});
|
|
5081
|
-
for (const item of
|
|
5502
|
+
for (const item of chunk.overrides.objects.deletes)
|
|
5082
5503
|
write("override.object.delete", () => {
|
|
5083
5504
|
const key = projectEntityKey(projectId, objectRefKey2(item.ref));
|
|
5084
5505
|
assertLastCommit(this.state.objectOverrides.get(key), item.expectedLastCommitId, "object override");
|
|
5085
5506
|
this.state.objectOverrides.delete(key);
|
|
5086
5507
|
});
|
|
5087
|
-
for (const item of
|
|
5508
|
+
for (const item of chunk.overrides.links.edges.upserts)
|
|
5088
5509
|
write("override.link.upsert", () => {
|
|
5089
5510
|
const key = projectEntityKey(projectId, linkRefKey2(item.ref));
|
|
5090
5511
|
assertLastCommit(this.state.linkOverrides.get(key), item.expectedLastCommitId, "link edge override");
|
|
@@ -5096,13 +5517,13 @@ class InMemoryOntologyMaterializationStorage {
|
|
|
5096
5517
|
updatedAt: item.updatedAt
|
|
5097
5518
|
}));
|
|
5098
5519
|
});
|
|
5099
|
-
for (const item of
|
|
5520
|
+
for (const item of chunk.overrides.links.edges.deletes)
|
|
5100
5521
|
write("override.link.delete", () => {
|
|
5101
5522
|
const key = projectEntityKey(projectId, linkRefKey2(item.ref));
|
|
5102
5523
|
assertLastCommit(this.state.linkOverrides.get(key), item.expectedLastCommitId, "link edge override");
|
|
5103
5524
|
this.state.linkOverrides.delete(key);
|
|
5104
5525
|
});
|
|
5105
|
-
for (const item of
|
|
5526
|
+
for (const item of chunk.overrides.links.slots.upserts)
|
|
5106
5527
|
write("override.link-slot.upsert", () => {
|
|
5107
5528
|
const key = projectEntityKey(projectId, linkScopeKey(item.ref.source, item.ref.linkId));
|
|
5108
5529
|
assertLastCommit(this.state.linkSlotOverrides.get(key), item.expectedLastCommitId, "link slot override");
|
|
@@ -5114,13 +5535,13 @@ class InMemoryOntologyMaterializationStorage {
|
|
|
5114
5535
|
updatedAt: item.updatedAt
|
|
5115
5536
|
}));
|
|
5116
5537
|
});
|
|
5117
|
-
for (const item of
|
|
5538
|
+
for (const item of chunk.overrides.links.slots.deletes)
|
|
5118
5539
|
write("override.link-slot.delete", () => {
|
|
5119
5540
|
const key = projectEntityKey(projectId, linkScopeKey(item.ref.source, item.ref.linkId));
|
|
5120
5541
|
assertLastCommit(this.state.linkSlotOverrides.get(key), item.expectedLastCommitId, "link slot override");
|
|
5121
5542
|
this.state.linkSlotOverrides.delete(key);
|
|
5122
5543
|
});
|
|
5123
|
-
for (const item of
|
|
5544
|
+
for (const item of chunk.effective.linkDeletes)
|
|
5124
5545
|
write("effective.link.delete", () => {
|
|
5125
5546
|
this.assertLinkSync(item.expected, projectId);
|
|
5126
5547
|
getInMemoryObjectMaterializerAdapter(this.objects).deleteExactLink({
|
|
@@ -5132,44 +5553,42 @@ class InMemoryOntologyMaterializationStorage {
|
|
|
5132
5553
|
targetId: item.ref.target.primaryId
|
|
5133
5554
|
});
|
|
5134
5555
|
});
|
|
5135
|
-
for (const item of
|
|
5556
|
+
for (const item of chunk.effective.objectDeletes)
|
|
5136
5557
|
write("effective.object.delete", () => {
|
|
5137
5558
|
this.assertObjectSync(item.expected, projectId);
|
|
5138
5559
|
getInMemoryObjectMaterializerAdapter(this.objects).deleteExactObject(projectId, item.ref.objectTypeId, item.ref.primaryId);
|
|
5139
5560
|
});
|
|
5140
|
-
for (const item of
|
|
5561
|
+
for (const item of chunk.effective.objectUpserts)
|
|
5141
5562
|
write("effective.object.upsert", () => {
|
|
5142
5563
|
this.assertObjectSync(item.expected, projectId);
|
|
5143
5564
|
getInMemoryObjectMaterializerAdapter(this.objects).applyExactObject(item.row, projectId);
|
|
5144
5565
|
});
|
|
5145
|
-
for (const item of
|
|
5566
|
+
for (const item of chunk.effective.linkUpserts)
|
|
5146
5567
|
write("effective.link.upsert", () => {
|
|
5147
5568
|
this.assertLinkSync(item.expected, projectId);
|
|
5148
5569
|
getInMemoryObjectMaterializerAdapter(this.objects).applyExactLink(item.row, projectId);
|
|
5149
5570
|
});
|
|
5150
|
-
for (const item of
|
|
5571
|
+
for (const item of chunk.timeseries.pointUpserts)
|
|
5151
5572
|
write("timeseries.point.upsert", () => {
|
|
5152
5573
|
this.assertPoint(item.expected, projectId);
|
|
5153
5574
|
getInMemoryTimeseriesMaterializerAdapter(this.timeseries).applyExactPoint(projectId, item.point);
|
|
5154
5575
|
});
|
|
5155
|
-
for (const item of
|
|
5576
|
+
for (const item of chunk.outbox)
|
|
5156
5577
|
write("outbox.insert", () => {
|
|
5157
|
-
const envelope = item.envelope;
|
|
5158
|
-
if (envelope.projectId !== projectId || envelope.commitId !== session.header.commit.id) {
|
|
5159
|
-
throw new MaterializationValidationError2("Outbox event does not correlate with its materialization commit.");
|
|
5160
|
-
}
|
|
5161
|
-
assertTimestamp(item.availableAt, "Outbox availableAt");
|
|
5162
5578
|
assertTimestamp(item.createdAt, "Outbox createdAt");
|
|
5163
|
-
|
|
5164
|
-
const key = outboxKey(projectId, envelope.id);
|
|
5579
|
+
const key = outboxKey(projectId, item.id);
|
|
5165
5580
|
if (this.state.outbox.has(key)) {
|
|
5166
|
-
throw new MaterializationConflictError2("effective-state", `Duplicate outbox event '${
|
|
5581
|
+
throw new MaterializationConflictError2("effective-state", `Duplicate outbox event '${item.id}'.`);
|
|
5167
5582
|
}
|
|
5168
|
-
if (session.
|
|
5583
|
+
if (session.outboxWrites.has(item.commitOrdinal))
|
|
5169
5584
|
throw new MaterializationConflictError2("effective-state", "Duplicate outbox commit ordinal.");
|
|
5170
5585
|
this.state.outbox.set(key, {
|
|
5171
|
-
|
|
5172
|
-
|
|
5586
|
+
projectId,
|
|
5587
|
+
id: item.id,
|
|
5588
|
+
commitId: session.header.commit.id,
|
|
5589
|
+
commitOrdinal: item.commitOrdinal,
|
|
5590
|
+
event: structuredClone(item.event),
|
|
5591
|
+
availableAt: item.createdAt,
|
|
5173
5592
|
attempts: 0,
|
|
5174
5593
|
leaseId: null,
|
|
5175
5594
|
leaseExpiresAt: null,
|
|
@@ -5177,11 +5596,8 @@ class InMemoryOntologyMaterializationStorage {
|
|
|
5177
5596
|
lastFailure: null,
|
|
5178
5597
|
createdAt: item.createdAt
|
|
5179
5598
|
});
|
|
5180
|
-
session.
|
|
5599
|
+
session.outboxWrites.set(item.commitOrdinal, structuredClone(item));
|
|
5181
5600
|
});
|
|
5182
|
-
for (const item of materializationPlanItems2(input.chunk)) {
|
|
5183
|
-
session.appliedPlanItems.push(stableJsonStringify2(item));
|
|
5184
|
-
}
|
|
5185
5601
|
}
|
|
5186
5602
|
async finalize(input) {
|
|
5187
5603
|
const session = this.requireSession(input.session);
|
|
@@ -5189,6 +5605,9 @@ class InMemoryOntologyMaterializationStorage {
|
|
|
5189
5605
|
this.assertCommitAbsent(session.header);
|
|
5190
5606
|
assertFinalizationCorrelations(session, input.finalization, this.state, this.objects);
|
|
5191
5607
|
this.hooks.beforeWrite?.("finalize", session.writeOrdinal++);
|
|
5608
|
+
const touches = emptyCommitTouches(commit.projectId);
|
|
5609
|
+
for (const record of session.applyWork)
|
|
5610
|
+
touchPlanItem(touches, record.item);
|
|
5192
5611
|
for (const activation of input.finalization.sourceActivations) {
|
|
5193
5612
|
this.hooks.beforeWrite?.("source.activate", session.writeOrdinal++);
|
|
5194
5613
|
assertTimestamp(activation.datasetVersion.createdAt, "Source dataset version createdAt");
|
|
@@ -5208,7 +5627,7 @@ class InMemoryOntologyMaterializationStorage {
|
|
|
5208
5627
|
updatedAt: activation.updatedAt
|
|
5209
5628
|
});
|
|
5210
5629
|
}
|
|
5211
|
-
activateSourceRoots(this.state, candidate, activation);
|
|
5630
|
+
activateSourceRoots(this.state, candidate, activation, touches);
|
|
5212
5631
|
this.state.sourceMaterializations.set(candidateKey, {
|
|
5213
5632
|
...candidate,
|
|
5214
5633
|
status: "active",
|
|
@@ -5218,11 +5637,19 @@ class InMemoryOntologyMaterializationStorage {
|
|
|
5218
5637
|
updatedAt: activation.updatedAt
|
|
5219
5638
|
});
|
|
5220
5639
|
}
|
|
5640
|
+
if (session.plan) {
|
|
5641
|
+
this.state.replacementPlans.delete(replacementPlanKey({
|
|
5642
|
+
projectId: commit.projectId,
|
|
5643
|
+
source: { projectionId: session.plan.sourceId },
|
|
5644
|
+
materializationId: session.plan.materializationId
|
|
5645
|
+
}));
|
|
5646
|
+
}
|
|
5221
5647
|
const record = {
|
|
5222
5648
|
...structuredClone(commit),
|
|
5223
5649
|
result: structuredClone(input.finalization.result)
|
|
5224
5650
|
};
|
|
5225
5651
|
this.state.commitsById.set(commitKey(commit.projectId, commit.id), record);
|
|
5652
|
+
this.state.commitTouches.set(this.state.commitsById.size, touches);
|
|
5226
5653
|
this.state.commitIdByIdempotency.set(idempotencyKey(commit.projectId, commit.idempotencyKey), commit.id);
|
|
5227
5654
|
const origin = ontologyCommitOriginSelector(commit.origin);
|
|
5228
5655
|
if (origin) {
|
|
@@ -5237,6 +5664,29 @@ class InMemoryOntologyMaterializationStorage {
|
|
|
5237
5664
|
throw new MaterializationValidationError2("Vector mutation does not belong to this materialization session.");
|
|
5238
5665
|
}
|
|
5239
5666
|
}
|
|
5667
|
+
sealWork(session, begin) {
|
|
5668
|
+
const sealed = session.workSealed;
|
|
5669
|
+
begin(session);
|
|
5670
|
+
if (sealed)
|
|
5671
|
+
return;
|
|
5672
|
+
session.applyWork.sort(comparePlanWork2);
|
|
5673
|
+
session.cardinalityWork.sort(compareCardinalityWork2);
|
|
5674
|
+
session.eventWork.sort(compareEventWork2);
|
|
5675
|
+
}
|
|
5676
|
+
requirePlan(header) {
|
|
5677
|
+
const { commit, plan: ref } = header;
|
|
5678
|
+
const plan = ref ? this.state.replacementPlans.get(replacementPlanKey({ projectId: commit.projectId, ...ref })) : undefined;
|
|
5679
|
+
if (!plan || commit.intent.kind !== "projection") {
|
|
5680
|
+
throw new MaterializationConflictError2("source-materialization", "A plan-bound session needs the open plan of a projection candidate.");
|
|
5681
|
+
}
|
|
5682
|
+
if (plan.commitId !== commit.id || plan.committedAt !== commit.committedAt) {
|
|
5683
|
+
invalidCorrelation2("A plan-bound session must begin with the commit its plan carries.");
|
|
5684
|
+
}
|
|
5685
|
+
if (plan.watermark !== this.state.commitsById.size || [...plan.identities.values()].some((identity) => identity.plannedRevision === null)) {
|
|
5686
|
+
invalidCorrelation2("A replacement plan applies only fully planned and just refreshed.");
|
|
5687
|
+
}
|
|
5688
|
+
return plan;
|
|
5689
|
+
}
|
|
5240
5690
|
requireSession(session) {
|
|
5241
5691
|
const value = this.sessions.get(session.providerToken);
|
|
5242
5692
|
if (!value || !value.active || !this.getTransactionToken() || this.getTransactionToken() !== value.transactionToken) {
|
|
@@ -5244,115 +5694,6 @@ class InMemoryOntologyMaterializationStorage {
|
|
|
5244
5694
|
}
|
|
5245
5695
|
return value;
|
|
5246
5696
|
}
|
|
5247
|
-
requireReplacement(session, input) {
|
|
5248
|
-
if (session.replacement) {
|
|
5249
|
-
if (session.replacement.sourceId !== input.source.projectionId || session.replacement.candidateMaterializationId !== input.candidateMaterializationId) {
|
|
5250
|
-
throw new MaterializationConflictError2("source-materialization", "Materialization session already owns another replacement union.");
|
|
5251
|
-
}
|
|
5252
|
-
return session.replacement;
|
|
5253
|
-
}
|
|
5254
|
-
const projectId = session.header.commit.projectId;
|
|
5255
|
-
const sourceId = input.source.projectionId;
|
|
5256
|
-
const candidate = this.state.sourceMaterializations.get(sourceMaterializationKey(projectId, sourceId, input.candidateMaterializationId));
|
|
5257
|
-
if (!candidate || candidate.status !== "ready") {
|
|
5258
|
-
throw new MaterializationConflictError2("source-materialization", `Candidate source materialization '${input.candidateMaterializationId}' is missing or is not ready.`);
|
|
5259
|
-
}
|
|
5260
|
-
const previous = findActiveSourceMaterialization(this.state, projectId, sourceId);
|
|
5261
|
-
if (candidate.protocol !== "replacement" || previous && (previous.protocol !== candidate.protocol || previous.projectionKind !== candidate.projectionKind)) {
|
|
5262
|
-
throw new MaterializationConflictError2("source-materialization", "Source replacement kind or protocol does not match its active materialization.");
|
|
5263
|
-
}
|
|
5264
|
-
const replacement = {
|
|
5265
|
-
sourceId,
|
|
5266
|
-
candidateMaterializationId: input.candidateMaterializationId,
|
|
5267
|
-
owned: new Set,
|
|
5268
|
-
candidate,
|
|
5269
|
-
objects: new Map,
|
|
5270
|
-
links: new Map,
|
|
5271
|
-
orderedObjects: [],
|
|
5272
|
-
orderedLinks: null,
|
|
5273
|
-
affectedScopes: new Set,
|
|
5274
|
-
incidentObjects: new Map,
|
|
5275
|
-
objectStreamStarted: false,
|
|
5276
|
-
objectStreamCompleted: false,
|
|
5277
|
-
linkStreamStarted: false,
|
|
5278
|
-
linkStreamCompleted: false,
|
|
5279
|
-
linksExpanded: false
|
|
5280
|
-
};
|
|
5281
|
-
for (const rows of [
|
|
5282
|
-
previousSourceRows(this.state, candidate),
|
|
5283
|
-
candidate.rowsByEntity.values()
|
|
5284
|
-
]) {
|
|
5285
|
-
for (const row of rows) {
|
|
5286
|
-
replacement.owned.add(projectionEntityKey2(row.assertion));
|
|
5287
|
-
if (row.assertion.kind === "object") {
|
|
5288
|
-
const ref = row.assertion.ref;
|
|
5289
|
-
replacement.objects.set(objectRefKey2(ref), { ref, sortKey: objectRefSortKey2(ref) });
|
|
5290
|
-
} else {
|
|
5291
|
-
addReplacementLink(replacement, row.assertion.ref, true);
|
|
5292
|
-
}
|
|
5293
|
-
}
|
|
5294
|
-
}
|
|
5295
|
-
replacement.orderedObjects = [...replacement.objects.values()].sort((left, right) => left.sortKey.localeCompare(right.sortKey));
|
|
5296
|
-
session.replacement = replacement;
|
|
5297
|
-
return replacement;
|
|
5298
|
-
}
|
|
5299
|
-
expandReplacementLinks(session, replacement) {
|
|
5300
|
-
if (replacement.linksExpanded)
|
|
5301
|
-
return;
|
|
5302
|
-
const projectId = session.header.commit.projectId;
|
|
5303
|
-
const incident = replacement.incidentObjects;
|
|
5304
|
-
const touchesIncident = (ref) => incident.has(objectRefKey2(ref.source)) || incident.has(objectRefKey2(ref.target));
|
|
5305
|
-
const adapter = getInMemoryObjectMaterializerAdapter(this.objects);
|
|
5306
|
-
if (incident.size > 0) {
|
|
5307
|
-
adapter.visitExactLinks(projectId, (row) => {
|
|
5308
|
-
const ref = linkRef(row);
|
|
5309
|
-
if (touchesIncident(ref))
|
|
5310
|
-
addReplacementLink(replacement, ref, true);
|
|
5311
|
-
});
|
|
5312
|
-
for (const override of this.state.linkOverrides.values()) {
|
|
5313
|
-
if (override.projectId !== projectId)
|
|
5314
|
-
continue;
|
|
5315
|
-
if (touchesIncident(override.ref))
|
|
5316
|
-
addReplacementLink(replacement, override.ref, true);
|
|
5317
|
-
}
|
|
5318
|
-
for (const override of this.state.linkSlotOverrides.values()) {
|
|
5319
|
-
if (override.projectId !== projectId)
|
|
5320
|
-
continue;
|
|
5321
|
-
const ref = {
|
|
5322
|
-
source: override.ref.source,
|
|
5323
|
-
linkId: override.ref.linkId,
|
|
5324
|
-
target: override.value.target
|
|
5325
|
-
};
|
|
5326
|
-
if (touchesIncident(ref))
|
|
5327
|
-
addReplacementLink(replacement, ref, true);
|
|
5328
|
-
}
|
|
5329
|
-
for (const [scopeKey, rows] of this.state.activeSourceLinkScopes) {
|
|
5330
|
-
if (JSON.parse(scopeKey)[0] !== projectId)
|
|
5331
|
-
continue;
|
|
5332
|
-
for (const row of rows.values()) {
|
|
5333
|
-
if (row.assertion.kind === "link" && touchesIncident(row.assertion.ref)) {
|
|
5334
|
-
addReplacementLink(replacement, row.assertion.ref, true);
|
|
5335
|
-
}
|
|
5336
|
-
}
|
|
5337
|
-
}
|
|
5338
|
-
}
|
|
5339
|
-
const scopes = new Map;
|
|
5340
|
-
for (const { ref } of replacement.links.values()) {
|
|
5341
|
-
const key = linkScopeSortKey2(ref.source, ref.linkId);
|
|
5342
|
-
if (replacement.affectedScopes.has(key))
|
|
5343
|
-
scopes.set(key, ref);
|
|
5344
|
-
}
|
|
5345
|
-
for (const scope of scopes.values()) {
|
|
5346
|
-
adapter.visitExactScopeLinks(projectId, scope.source.objectTypeId, scope.source.primaryId, scope.linkId, (row) => {
|
|
5347
|
-
addReplacementLink(replacement, linkRef(row), false);
|
|
5348
|
-
});
|
|
5349
|
-
const override = this.state.linkSlotOverrides.get(projectEntityKey(projectId, linkScopeKey(scope.source, scope.linkId)));
|
|
5350
|
-
if (override)
|
|
5351
|
-
addReplacementLink(replacement, { ...scope, target: override.value.target }, false);
|
|
5352
|
-
}
|
|
5353
|
-
replacement.linksExpanded = true;
|
|
5354
|
-
replacement.orderedLinks = null;
|
|
5355
|
-
}
|
|
5356
5697
|
assertCommitAbsent(header) {
|
|
5357
5698
|
if (this.state.commitsById.has(commitKey(header.commit.projectId, header.commit.id))) {
|
|
5358
5699
|
throw new MaterializationConflictError2("idempotency", `Ontology commit '${header.commit.id}' already exists.`);
|
|
@@ -5397,98 +5738,20 @@ class InMemoryOntologyMaterializationStorage {
|
|
|
5397
5738
|
throw new MaterializationConflictError2("timeseries-point", `Telemetry point ${telemetryPointKey2(expected.series, expected.at)} changed.`);
|
|
5398
5739
|
}
|
|
5399
5740
|
}
|
|
5400
|
-
async objectState(session, ref) {
|
|
5401
|
-
const projectId = session.header.commit.projectId;
|
|
5402
|
-
const row = await this.objects.getByPrimaryId({
|
|
5403
|
-
projectId,
|
|
5404
|
-
objectTypeId: ref.objectTypeId,
|
|
5405
|
-
primaryId: ref.primaryId
|
|
5406
|
-
});
|
|
5407
|
-
return {
|
|
5408
|
-
ref: structuredClone(ref),
|
|
5409
|
-
source: this.findActiveObjectSource(projectId, ref),
|
|
5410
|
-
override: structuredClone(publicObjectOverride(this.state.objectOverrides.get(projectEntityKey(projectId, objectRefKey2(ref))))),
|
|
5411
|
-
effective: row ? objectSnapshot(row) : null,
|
|
5412
|
-
latestTelemetry: getInMemoryTimeseriesMaterializerAdapter(this.timeseries).listLatestForObject(projectId, ref.objectTypeId, ref.primaryId).map(storedPoint)
|
|
5413
|
-
};
|
|
5414
|
-
}
|
|
5415
|
-
async linkState(session, ref) {
|
|
5416
|
-
const projectId = session.header.commit.projectId;
|
|
5417
|
-
const row = getInMemoryObjectMaterializerAdapter(this.objects).getExactLinkRow(projectId, {
|
|
5418
|
-
sourceTypeId: ref.source.objectTypeId,
|
|
5419
|
-
sourceId: ref.source.primaryId,
|
|
5420
|
-
linkId: ref.linkId,
|
|
5421
|
-
targetTypeId: ref.target.objectTypeId,
|
|
5422
|
-
targetId: ref.target.primaryId
|
|
5423
|
-
});
|
|
5424
|
-
return {
|
|
5425
|
-
ref: structuredClone(ref),
|
|
5426
|
-
source: this.findActiveLinkSource(projectId, ref),
|
|
5427
|
-
override: structuredClone(publicLinkOverride(this.state.linkOverrides.get(projectEntityKey(projectId, linkRefKey2(ref))))),
|
|
5428
|
-
slotOverride: structuredClone(publicLinkSlotOverride(this.state.linkSlotOverrides.get(projectEntityKey(projectId, linkScopeKey(ref.source, ref.linkId))))),
|
|
5429
|
-
effective: row ? linkSnapshot(row) : null
|
|
5430
|
-
};
|
|
5431
|
-
}
|
|
5432
5741
|
linkSlotState(session, source, linkId) {
|
|
5433
5742
|
session.linkSlotStates ??= new Map;
|
|
5434
5743
|
const key = linkScopeSortKey2(source, linkId);
|
|
5435
5744
|
const existing = session.linkSlotStates.get(key);
|
|
5436
5745
|
if (existing)
|
|
5437
5746
|
return structuredClone(existing);
|
|
5438
|
-
const computed = this.
|
|
5439
|
-
session.linkSlotStates.set(key, computed);
|
|
5440
|
-
return structuredClone(computed);
|
|
5441
|
-
}
|
|
5442
|
-
computeLinkSlotState(projectId, source, linkId) {
|
|
5443
|
-
const value = this.computeEffectiveLinkScope(projectId, source, linkId);
|
|
5444
|
-
return {
|
|
5445
|
-
...value,
|
|
5446
|
-
sourceAssertion: this.findActiveLinkScopeSource(projectId, source, linkId),
|
|
5447
|
-
override: structuredClone(publicLinkSlotOverride(this.state.linkSlotOverrides.get(projectEntityKey(projectId, linkScopeKey(source, linkId)))))
|
|
5448
|
-
};
|
|
5449
|
-
}
|
|
5450
|
-
computeEffectiveLinkScope(projectId, source, linkId) {
|
|
5451
|
-
const rows = [];
|
|
5452
|
-
getInMemoryObjectMaterializerAdapter(this.objects).visitExactScopeLinks(projectId, source.objectTypeId, source.primaryId, linkId, (row) => rows.push(row));
|
|
5453
|
-
rows.sort((left, right) => linkRefSortKey2(linkRef(left)).localeCompare(linkRefSortKey2(linkRef(right))));
|
|
5454
|
-
const accumulator = startScopeAccumulator2(source, linkId);
|
|
5455
|
-
for (let offset = 0;offset < rows.length; offset += 1000) {
|
|
5456
|
-
const page = rows.slice(offset, offset + 1000);
|
|
5457
|
-
this.hooks.observeBuffer?.("state.link-scope.page", page.length);
|
|
5458
|
-
for (const row of page) {
|
|
5459
|
-
appendScopeSnapshot2(accumulator, linkSnapshot(row));
|
|
5460
|
-
}
|
|
5461
|
-
}
|
|
5462
|
-
const effective = rows.length === 1 ? linkSnapshot(rows[0]) : null;
|
|
5463
|
-
return {
|
|
5464
|
-
...finishScopeAccumulator2(accumulator),
|
|
5465
|
-
effective
|
|
5466
|
-
};
|
|
5467
|
-
}
|
|
5468
|
-
findActiveLinkScopeSource(projectId, source, linkId) {
|
|
5469
|
-
const rows = this.state.activeSourceLinkScopes.get(projectEntityKey(projectId, linkScopeSortKey2(source, linkId)));
|
|
5470
|
-
if (rows && rows.size > 1)
|
|
5471
|
-
throw new MaterializationConflictError2("source-materialization", `Multiple active source links assert cardinality-one scope '${source.objectTypeId}.${linkId}'.`);
|
|
5472
|
-
return structuredClone(rows?.values().next().value ?? null);
|
|
5473
|
-
}
|
|
5474
|
-
findActiveObjectSource(projectId, ref) {
|
|
5475
|
-
const found = this.findActiveSource(projectId, projectionEntityKey2({ kind: "object", ref }));
|
|
5476
|
-
return found?.assertion.kind === "object" ? found : null;
|
|
5477
|
-
}
|
|
5478
|
-
findActiveLinkSource(projectId, ref) {
|
|
5479
|
-
const found = this.findActiveSource(projectId, projectionEntityKey2({ kind: "link", ref }));
|
|
5480
|
-
return found?.assertion.kind === "link" ? found : null;
|
|
5481
|
-
}
|
|
5482
|
-
findActiveSource(projectId, entityKey) {
|
|
5483
|
-
const rows = this.state.activeSourceRows.get(projectEntityKey(projectId, entityKey));
|
|
5484
|
-
if (rows && rows.size > 1)
|
|
5485
|
-
throw new MaterializationConflictError2("source-materialization", `Multiple active sources assert ${entityKey}.`);
|
|
5486
|
-
return structuredClone(rows?.values().next().value ?? null);
|
|
5747
|
+
const computed = this.reader.linkSlotState(session.header.commit.projectId, source, linkId);
|
|
5748
|
+
session.linkSlotStates.set(key, computed);
|
|
5749
|
+
return structuredClone(computed);
|
|
5487
5750
|
}
|
|
5488
5751
|
incidentLinkRefs(session, objects) {
|
|
5489
5752
|
if (objects.length === 0)
|
|
5490
5753
|
return [];
|
|
5491
|
-
session.incidentLinksByObject ??= this.
|
|
5754
|
+
session.incidentLinksByObject ??= this.reader.incidentLinkIndex(session.header.commit.projectId);
|
|
5492
5755
|
const selected = new Map;
|
|
5493
5756
|
for (const object of objects) {
|
|
5494
5757
|
for (const ref of session.incidentLinksByObject.get(objectRefKey2(object)) ?? []) {
|
|
@@ -5497,59 +5760,22 @@ class InMemoryOntologyMaterializationStorage {
|
|
|
5497
5760
|
}
|
|
5498
5761
|
return [...selected.entries()].sort(([left], [right]) => left.localeCompare(right)).map(([, ref]) => ref);
|
|
5499
5762
|
}
|
|
5500
|
-
buildIncidentLinkIndex(projectId) {
|
|
5501
|
-
const mutable = new Map;
|
|
5502
|
-
const consider = (ref) => {
|
|
5503
|
-
const sortKey = linkRefSortKey2(ref);
|
|
5504
|
-
for (const endpoint of [ref.source, ref.target]) {
|
|
5505
|
-
const key = objectRefKey2(endpoint);
|
|
5506
|
-
const links = mutable.get(key) ?? new Map;
|
|
5507
|
-
links.set(sortKey, structuredClone(ref));
|
|
5508
|
-
mutable.set(key, links);
|
|
5509
|
-
}
|
|
5510
|
-
};
|
|
5511
|
-
getInMemoryObjectMaterializerAdapter(this.objects).visitExactLinks(projectId, (row) => consider(linkRef(row)));
|
|
5512
|
-
for (const override of this.state.linkOverrides.values()) {
|
|
5513
|
-
if (override.projectId === projectId)
|
|
5514
|
-
consider(override.ref);
|
|
5515
|
-
}
|
|
5516
|
-
for (const override of this.state.linkSlotOverrides.values()) {
|
|
5517
|
-
if (override.projectId !== projectId)
|
|
5518
|
-
continue;
|
|
5519
|
-
consider({
|
|
5520
|
-
source: override.ref.source,
|
|
5521
|
-
linkId: override.ref.linkId,
|
|
5522
|
-
target: override.value.target
|
|
5523
|
-
});
|
|
5524
|
-
}
|
|
5525
|
-
for (const [scopeKey, rows] of this.state.activeSourceLinkScopes) {
|
|
5526
|
-
if (JSON.parse(scopeKey)[0] !== projectId)
|
|
5527
|
-
continue;
|
|
5528
|
-
for (const row of rows.values()) {
|
|
5529
|
-
if (row.assertion.kind === "link")
|
|
5530
|
-
consider(row.assertion.ref);
|
|
5531
|
-
}
|
|
5532
|
-
}
|
|
5533
|
-
const index = new Map;
|
|
5534
|
-
for (const [objectKey, refs] of mutable) {
|
|
5535
|
-
index.set(objectKey, [...refs.entries()].sort(([left], [right]) => left.localeCompare(right)).map(([, ref]) => ref));
|
|
5536
|
-
}
|
|
5537
|
-
return index;
|
|
5538
|
-
}
|
|
5539
5763
|
}
|
|
5540
5764
|
|
|
5541
5765
|
// src/storage/ontology/in-memory/outbox.ts
|
|
5542
5766
|
class InMemoryOntologyOutboxStorage {
|
|
5543
5767
|
state;
|
|
5544
5768
|
runRootOperation;
|
|
5545
|
-
|
|
5769
|
+
readExecution;
|
|
5770
|
+
constructor(state, runRootOperation, readExecution) {
|
|
5546
5771
|
this.state = state;
|
|
5547
5772
|
this.runRootOperation = runRootOperation;
|
|
5773
|
+
this.readExecution = readExecution;
|
|
5548
5774
|
}
|
|
5549
5775
|
async claim(input) {
|
|
5550
5776
|
return this.runRootOperation(() => this.claimUnlocked(input));
|
|
5551
5777
|
}
|
|
5552
|
-
claimUnlocked(input) {
|
|
5778
|
+
async claimUnlocked(input) {
|
|
5553
5779
|
assertNonblank(input.projectId, "Ontology outbox project id");
|
|
5554
5780
|
assertPositiveLimit(input.limit);
|
|
5555
5781
|
const now = assertTimestamp(input.now, "Ontology outbox claim time");
|
|
@@ -5560,7 +5786,7 @@ class InMemoryOntologyOutboxStorage {
|
|
|
5560
5786
|
}
|
|
5561
5787
|
const rows = [];
|
|
5562
5788
|
for (const row of this.state.outbox.values()) {
|
|
5563
|
-
if (row.
|
|
5789
|
+
if (row.projectId !== input.projectId)
|
|
5564
5790
|
continue;
|
|
5565
5791
|
assertPairedLease(row);
|
|
5566
5792
|
if (row.publishedAt !== null || Date.parse(row.availableAt) > now)
|
|
@@ -5569,16 +5795,23 @@ class InMemoryOntologyOutboxStorage {
|
|
|
5569
5795
|
continue;
|
|
5570
5796
|
insertBounded(rows, row, input.limit, compareClaimRows);
|
|
5571
5797
|
}
|
|
5572
|
-
|
|
5573
|
-
|
|
5574
|
-
|
|
5575
|
-
|
|
5576
|
-
|
|
5577
|
-
|
|
5578
|
-
|
|
5579
|
-
|
|
5580
|
-
|
|
5581
|
-
|
|
5798
|
+
const claimed = rows.map((row) => ({
|
|
5799
|
+
...row,
|
|
5800
|
+
attempts: row.attempts + 1,
|
|
5801
|
+
leaseId: input.leaseId,
|
|
5802
|
+
leaseExpiresAt: input.leaseExpiresAt
|
|
5803
|
+
}));
|
|
5804
|
+
const contexts = new Map;
|
|
5805
|
+
for (const commitId of new Set(claimed.map((row) => row.commitId))) {
|
|
5806
|
+
const commit = this.state.commitsById.get(commitKey(input.projectId, commitId));
|
|
5807
|
+
const execution = commit && await this.readExecution(input.projectId, commit.executionId);
|
|
5808
|
+
if (commit && execution)
|
|
5809
|
+
contexts.set(commitId, { commit, execution });
|
|
5810
|
+
}
|
|
5811
|
+
const records = claimedOutboxRows2(structuredClone(claimed), (commitId) => contexts.get(commitId));
|
|
5812
|
+
for (const row of claimed)
|
|
5813
|
+
this.state.outbox.set(outboxKey(input.projectId, row.id), row);
|
|
5814
|
+
return records;
|
|
5582
5815
|
}
|
|
5583
5816
|
async markPublished(input) {
|
|
5584
5817
|
await this.runRootOperation(() => this.markPublishedUnlocked(input));
|
|
@@ -5626,7 +5859,7 @@ class InMemoryOntologyOutboxStorage {
|
|
|
5626
5859
|
let retryingCount = 0;
|
|
5627
5860
|
let maxAttempts = 0;
|
|
5628
5861
|
for (const row of this.state.outbox.values()) {
|
|
5629
|
-
if (row.
|
|
5862
|
+
if (row.projectId !== input.projectId || row.publishedAt !== null)
|
|
5630
5863
|
continue;
|
|
5631
5864
|
pendingCount += 1;
|
|
5632
5865
|
if (row.attempts > 0)
|
|
@@ -5646,7 +5879,7 @@ class InMemoryOntologyOutboxStorage {
|
|
|
5646
5879
|
const rows = [];
|
|
5647
5880
|
for (const entry of this.state.outbox.entries()) {
|
|
5648
5881
|
const [, row] = entry;
|
|
5649
|
-
if (row.
|
|
5882
|
+
if (row.projectId !== input.projectId || row.publishedAt === null || Date.parse(row.publishedAt) >= cutoff) {
|
|
5650
5883
|
continue;
|
|
5651
5884
|
}
|
|
5652
5885
|
insertBounded(rows, entry, input.limit, ([, left], [, right]) => comparePublishedRows(left, right));
|
|
@@ -5676,10 +5909,10 @@ class InMemoryOntologyOutboxStorage {
|
|
|
5676
5909
|
}
|
|
5677
5910
|
}
|
|
5678
5911
|
function compareClaimRows(left, right) {
|
|
5679
|
-
return left.createdAt.localeCompare(right.createdAt) || left.
|
|
5912
|
+
return left.createdAt.localeCompare(right.createdAt) || left.commitId.localeCompare(right.commitId) || left.commitOrdinal - right.commitOrdinal;
|
|
5680
5913
|
}
|
|
5681
5914
|
function comparePublishedRows(left, right) {
|
|
5682
|
-
return (left.publishedAt ?? "").localeCompare(right.publishedAt ?? "") || left.
|
|
5915
|
+
return (left.publishedAt ?? "").localeCompare(right.publishedAt ?? "") || left.id.localeCompare(right.id);
|
|
5683
5916
|
}
|
|
5684
5917
|
function assertPositiveLimit(limit) {
|
|
5685
5918
|
if (!Number.isSafeInteger(limit) || limit <= 0) {
|
|
@@ -5900,23 +6133,6 @@ class InMemoryOntologySourceStorage {
|
|
|
5900
6133
|
}
|
|
5901
6134
|
return { rowsDeleted, materializationsDeleted };
|
|
5902
6135
|
}
|
|
5903
|
-
async summarizeTerminal(input) {
|
|
5904
|
-
return this.runRootOperation(() => {
|
|
5905
|
-
assertNonblank(input.projectId, "Terminal source summary project id");
|
|
5906
|
-
let count = 0;
|
|
5907
|
-
let oldestTerminalAt = null;
|
|
5908
|
-
for (const materialization of this.state.sourceMaterializations.values()) {
|
|
5909
|
-
if (materialization.projectId !== input.projectId || materialization.status !== "superseded" && materialization.status !== "abandoned" || materialization.terminalAt === null) {
|
|
5910
|
-
continue;
|
|
5911
|
-
}
|
|
5912
|
-
count += 1;
|
|
5913
|
-
if (oldestTerminalAt === null || materialization.terminalAt < oldestTerminalAt) {
|
|
5914
|
-
oldestTerminalAt = materialization.terminalAt;
|
|
5915
|
-
}
|
|
5916
|
-
}
|
|
5917
|
-
return { count, oldestTerminalAt };
|
|
5918
|
-
});
|
|
5919
|
-
}
|
|
5920
6136
|
async assertCurrentExecution(input) {
|
|
5921
6137
|
await this.assertExecution({
|
|
5922
6138
|
projectId: input.projectId,
|
|
@@ -5967,7 +6183,9 @@ class InMemoryOntologySourceStorage {
|
|
|
5967
6183
|
terminalAt: abandonedAt,
|
|
5968
6184
|
updatedAt: abandonedAt
|
|
5969
6185
|
};
|
|
5970
|
-
|
|
6186
|
+
const key = sourceMaterializationKey(materialization.projectId, materialization.source.projectionId, materialization.materializationId);
|
|
6187
|
+
this.state.sourceMaterializations.set(key, abandoned);
|
|
6188
|
+
this.state.replacementPlans.delete(key);
|
|
5971
6189
|
return sourceMaterializationRecord(abandoned);
|
|
5972
6190
|
}
|
|
5973
6191
|
findRunCandidates(projectId, sourceId, projectionRunId) {
|
|
@@ -6114,6 +6332,138 @@ function compareTerminalMaterializations([, left], [, right]) {
|
|
|
6114
6332
|
return (left.terminalAt ?? "").localeCompare(right.terminalAt ?? "") || left.source.projectionId.localeCompare(right.source.projectionId) || left.materializationId.localeCompare(right.materializationId);
|
|
6115
6333
|
}
|
|
6116
6334
|
|
|
6335
|
+
// src/storage/ontology/in-memory/state-reader.ts
|
|
6336
|
+
class InMemoryMaterializationStateReader {
|
|
6337
|
+
state;
|
|
6338
|
+
objects;
|
|
6339
|
+
timeseries;
|
|
6340
|
+
hooks;
|
|
6341
|
+
constructor(state, objects, timeseries, hooks = {}) {
|
|
6342
|
+
this.state = state;
|
|
6343
|
+
this.objects = objects;
|
|
6344
|
+
this.timeseries = timeseries;
|
|
6345
|
+
this.hooks = hooks;
|
|
6346
|
+
}
|
|
6347
|
+
async objectState(projectId, ref) {
|
|
6348
|
+
const row = await this.objects.getByPrimaryId({
|
|
6349
|
+
projectId,
|
|
6350
|
+
objectTypeId: ref.objectTypeId,
|
|
6351
|
+
primaryId: ref.primaryId
|
|
6352
|
+
});
|
|
6353
|
+
return {
|
|
6354
|
+
ref: structuredClone(ref),
|
|
6355
|
+
source: this.findActiveObjectSource(projectId, ref),
|
|
6356
|
+
override: structuredClone(publicObjectOverride(this.state.objectOverrides.get(projectEntityKey(projectId, objectRefKey2(ref))))),
|
|
6357
|
+
effective: row ? objectSnapshot(row) : null,
|
|
6358
|
+
latestTelemetry: getInMemoryTimeseriesMaterializerAdapter(this.timeseries).listLatestForObject(projectId, ref.objectTypeId, ref.primaryId).map(storedPoint)
|
|
6359
|
+
};
|
|
6360
|
+
}
|
|
6361
|
+
latestTelemetry(projectId, ref) {
|
|
6362
|
+
return getInMemoryTimeseriesMaterializerAdapter(this.timeseries).listLatestForObject(projectId, ref.objectTypeId, ref.primaryId).map(storedPoint);
|
|
6363
|
+
}
|
|
6364
|
+
async linkState(projectId, ref) {
|
|
6365
|
+
const row = getInMemoryObjectMaterializerAdapter(this.objects).getExactLinkRow(projectId, {
|
|
6366
|
+
sourceTypeId: ref.source.objectTypeId,
|
|
6367
|
+
sourceId: ref.source.primaryId,
|
|
6368
|
+
linkId: ref.linkId,
|
|
6369
|
+
targetTypeId: ref.target.objectTypeId,
|
|
6370
|
+
targetId: ref.target.primaryId
|
|
6371
|
+
});
|
|
6372
|
+
return {
|
|
6373
|
+
ref: structuredClone(ref),
|
|
6374
|
+
source: this.findActiveLinkSource(projectId, ref),
|
|
6375
|
+
override: structuredClone(publicLinkOverride(this.state.linkOverrides.get(projectEntityKey(projectId, linkRefKey2(ref))))),
|
|
6376
|
+
slotOverride: structuredClone(publicLinkSlotOverride(this.state.linkSlotOverrides.get(projectEntityKey(projectId, linkScopeKey(ref.source, ref.linkId))))),
|
|
6377
|
+
effective: row ? linkSnapshot(row) : null
|
|
6378
|
+
};
|
|
6379
|
+
}
|
|
6380
|
+
linkSlotState(projectId, source, linkId) {
|
|
6381
|
+
const value = this.effectiveLinkScope(projectId, source, linkId);
|
|
6382
|
+
return {
|
|
6383
|
+
...value,
|
|
6384
|
+
sourceAssertion: this.findActiveLinkScopeSource(projectId, source, linkId),
|
|
6385
|
+
override: structuredClone(publicLinkSlotOverride(this.state.linkSlotOverrides.get(projectEntityKey(projectId, linkScopeKey(source, linkId)))))
|
|
6386
|
+
};
|
|
6387
|
+
}
|
|
6388
|
+
effectiveLinkScope(projectId, source, linkId) {
|
|
6389
|
+
const rows = [];
|
|
6390
|
+
getInMemoryObjectMaterializerAdapter(this.objects).visitExactScopeLinks(projectId, source.objectTypeId, source.primaryId, linkId, (row) => rows.push(row));
|
|
6391
|
+
rows.sort((left, right) => linkRefSortKey2(linkRef(left)).localeCompare(linkRefSortKey2(linkRef(right))));
|
|
6392
|
+
const accumulator = startScopeAccumulator2(source, linkId);
|
|
6393
|
+
for (let offset = 0;offset < rows.length; offset += 1000) {
|
|
6394
|
+
const page = rows.slice(offset, offset + 1000);
|
|
6395
|
+
this.hooks.observeBuffer?.("state.link-scope.page", page.length);
|
|
6396
|
+
for (const row of page) {
|
|
6397
|
+
appendScopeSnapshot2(accumulator, linkSnapshot(row));
|
|
6398
|
+
}
|
|
6399
|
+
}
|
|
6400
|
+
const effective = rows.length === 1 ? linkSnapshot(rows[0]) : null;
|
|
6401
|
+
return {
|
|
6402
|
+
...finishScopeAccumulator2(accumulator),
|
|
6403
|
+
effective
|
|
6404
|
+
};
|
|
6405
|
+
}
|
|
6406
|
+
findActiveLinkScopeSource(projectId, source, linkId) {
|
|
6407
|
+
const rows = this.state.activeSourceLinkScopes.get(projectEntityKey(projectId, linkScopeSortKey2(source, linkId)));
|
|
6408
|
+
if (rows && rows.size > 1)
|
|
6409
|
+
throw new MaterializationConflictError2("source-materialization", `Multiple active source links assert cardinality-one scope '${source.objectTypeId}.${linkId}'.`);
|
|
6410
|
+
return structuredClone(rows?.values().next().value ?? null);
|
|
6411
|
+
}
|
|
6412
|
+
findActiveObjectSource(projectId, ref) {
|
|
6413
|
+
const found = this.findActiveSource(projectId, projectionEntityKey2({ kind: "object", ref }));
|
|
6414
|
+
return found?.assertion.kind === "object" ? found : null;
|
|
6415
|
+
}
|
|
6416
|
+
findActiveLinkSource(projectId, ref) {
|
|
6417
|
+
const found = this.findActiveSource(projectId, projectionEntityKey2({ kind: "link", ref }));
|
|
6418
|
+
return found?.assertion.kind === "link" ? found : null;
|
|
6419
|
+
}
|
|
6420
|
+
findActiveSource(projectId, entityKey) {
|
|
6421
|
+
const rows = this.state.activeSourceRows.get(projectEntityKey(projectId, entityKey));
|
|
6422
|
+
if (rows && rows.size > 1)
|
|
6423
|
+
throw new MaterializationConflictError2("source-materialization", `Multiple active sources assert ${entityKey}.`);
|
|
6424
|
+
return structuredClone(rows?.values().next().value ?? null);
|
|
6425
|
+
}
|
|
6426
|
+
incidentLinkIndex(projectId) {
|
|
6427
|
+
const mutable = new Map;
|
|
6428
|
+
const consider = (ref) => {
|
|
6429
|
+
const sortKey = linkRefSortKey2(ref);
|
|
6430
|
+
for (const endpoint of [ref.source, ref.target]) {
|
|
6431
|
+
const key = objectRefKey2(endpoint);
|
|
6432
|
+
const links = mutable.get(key) ?? new Map;
|
|
6433
|
+
links.set(sortKey, structuredClone(ref));
|
|
6434
|
+
mutable.set(key, links);
|
|
6435
|
+
}
|
|
6436
|
+
};
|
|
6437
|
+
getInMemoryObjectMaterializerAdapter(this.objects).visitExactLinks(projectId, (row) => consider(linkRef(row)));
|
|
6438
|
+
for (const override of this.state.linkOverrides.values()) {
|
|
6439
|
+
if (override.projectId === projectId)
|
|
6440
|
+
consider(override.ref);
|
|
6441
|
+
}
|
|
6442
|
+
for (const override of this.state.linkSlotOverrides.values()) {
|
|
6443
|
+
if (override.projectId !== projectId)
|
|
6444
|
+
continue;
|
|
6445
|
+
consider({
|
|
6446
|
+
source: override.ref.source,
|
|
6447
|
+
linkId: override.ref.linkId,
|
|
6448
|
+
target: override.value.target
|
|
6449
|
+
});
|
|
6450
|
+
}
|
|
6451
|
+
for (const [scopeKey, rows] of this.state.activeSourceLinkScopes) {
|
|
6452
|
+
if (JSON.parse(scopeKey)[0] !== projectId)
|
|
6453
|
+
continue;
|
|
6454
|
+
for (const row of rows.values()) {
|
|
6455
|
+
if (row.assertion.kind === "link")
|
|
6456
|
+
consider(row.assertion.ref);
|
|
6457
|
+
}
|
|
6458
|
+
}
|
|
6459
|
+
const index = new Map;
|
|
6460
|
+
for (const [objectKey, refs] of mutable) {
|
|
6461
|
+
index.set(objectKey, [...refs.entries()].sort(([left], [right]) => left.localeCompare(right)).map(([, ref]) => ref));
|
|
6462
|
+
}
|
|
6463
|
+
return index;
|
|
6464
|
+
}
|
|
6465
|
+
}
|
|
6466
|
+
|
|
6117
6467
|
// src/storage/ontology/in-memory/testing.ts
|
|
6118
6468
|
var testingAdapters = new WeakMap;
|
|
6119
6469
|
function registerInMemoryOntologyStorageTestingAdapter(storage, adapter) {
|
|
@@ -6242,61 +6592,6 @@ class InMemoryVectorIndexingStorage {
|
|
|
6242
6592
|
}
|
|
6243
6593
|
}
|
|
6244
6594
|
|
|
6245
|
-
// src/storage/ontology/in-memory/vectors.ts
|
|
6246
|
-
function vectorObjectKey(projectId, ref) {
|
|
6247
|
-
return JSON.stringify([projectId, ref.objectTypeId, ref.primaryId]);
|
|
6248
|
-
}
|
|
6249
|
-
|
|
6250
|
-
class InMemoryOntologyVectorStorage {
|
|
6251
|
-
state;
|
|
6252
|
-
assertSession;
|
|
6253
|
-
runRootOperation;
|
|
6254
|
-
constructor(state, assertSession, runRootOperation) {
|
|
6255
|
-
this.state = state;
|
|
6256
|
-
this.assertSession = assertSession;
|
|
6257
|
-
this.runRootOperation = runRootOperation;
|
|
6258
|
-
}
|
|
6259
|
-
async list(input) {
|
|
6260
|
-
return this.listBatch({ projectId: input.projectId, refs: [input.ref] });
|
|
6261
|
-
}
|
|
6262
|
-
async listBatch(input) {
|
|
6263
|
-
return this.runRootOperation(() => [...new Set(input.refs.map((ref) => vectorObjectKey(input.projectId, ref)))].flatMap((key) => [...this.state.get(key)?.values() ?? []].map(({ values: _values, ...metadata }) => structuredClone(metadata))));
|
|
6264
|
-
}
|
|
6265
|
-
async removeBatch(input) {
|
|
6266
|
-
this.assertSession(input.session, input.projectId);
|
|
6267
|
-
for (const entry of input.entries) {
|
|
6268
|
-
await this.remove({ session: input.session, projectId: input.projectId, ...entry });
|
|
6269
|
-
}
|
|
6270
|
-
}
|
|
6271
|
-
async write(input) {
|
|
6272
|
-
this.assertSession(input.session, input.projectId, input.value.lastCommitId);
|
|
6273
|
-
const key = vectorObjectKey(input.projectId, input.value.ref);
|
|
6274
|
-
const profiles = this.state.get(key) ?? new Map;
|
|
6275
|
-
this.assertRevision(profiles.get(input.value.profile), input.expectedCommitId);
|
|
6276
|
-
profiles.set(input.value.profile, structuredClone(input.value));
|
|
6277
|
-
this.state.set(key, profiles);
|
|
6278
|
-
}
|
|
6279
|
-
async writeBatch(input) {
|
|
6280
|
-
for (const entry of input.entries) {
|
|
6281
|
-
await this.write({ session: input.session, projectId: input.projectId, ...entry });
|
|
6282
|
-
}
|
|
6283
|
-
}
|
|
6284
|
-
async remove(input) {
|
|
6285
|
-
this.assertSession(input.session, input.projectId);
|
|
6286
|
-
const key = vectorObjectKey(input.projectId, input.ref);
|
|
6287
|
-
const profiles = this.state.get(key);
|
|
6288
|
-
this.assertRevision(profiles?.get(input.profile), input.expectedCommitId);
|
|
6289
|
-
profiles?.delete(input.profile);
|
|
6290
|
-
if (profiles?.size === 0)
|
|
6291
|
-
this.state.delete(key);
|
|
6292
|
-
}
|
|
6293
|
-
assertRevision(current, expected) {
|
|
6294
|
-
if ((current?.lastCommitId ?? null) !== expected) {
|
|
6295
|
-
throw new MaterializationConflictError2("effective-state", "Vector changed since it was prepared.");
|
|
6296
|
-
}
|
|
6297
|
-
}
|
|
6298
|
-
}
|
|
6299
|
-
|
|
6300
6595
|
// src/storage/ontology/in-memory/index.ts
|
|
6301
6596
|
class InMemoryOntologyStorage {
|
|
6302
6597
|
state = createInMemoryOntologyState();
|
|
@@ -6305,6 +6600,7 @@ class InMemoryOntologyStorage {
|
|
|
6305
6600
|
commits;
|
|
6306
6601
|
sources;
|
|
6307
6602
|
materializations;
|
|
6603
|
+
replacementPlans;
|
|
6308
6604
|
outbox;
|
|
6309
6605
|
testHooks = {};
|
|
6310
6606
|
testingAdapter = {
|
|
@@ -6317,13 +6613,16 @@ class InMemoryOntologyStorage {
|
|
|
6317
6613
|
getInMemoryObjectMaterializerAdapter(objects).setVectorReader((projectId, ref, profile) => this.state.vectors.get(vectorObjectKey(projectId, ref))?.get(profile));
|
|
6318
6614
|
this.commits = new InMemoryOntologyCommitStorage(this.state, options.runRootOperation);
|
|
6319
6615
|
this.sources = new InMemoryOntologySourceStorage(this.state, options.runRootOperation, options.assertSourceMaterializationExecution);
|
|
6320
|
-
this.outbox = new InMemoryOntologyOutboxStorage(this.state, options.runRootOperation);
|
|
6321
|
-
|
|
6616
|
+
this.outbox = new InMemoryOntologyOutboxStorage(this.state, options.runRootOperation, options.readExecution);
|
|
6617
|
+
const hooks = {
|
|
6322
6618
|
beforeRead: (boundary) => this.testHooks.beforeRead?.(boundary),
|
|
6323
6619
|
beforeWrite: (boundary, ordinal) => this.testHooks.beforeWrite?.(boundary, ordinal),
|
|
6324
6620
|
observeBuffer: (boundary, rows) => this.testHooks.observeBuffer?.(boundary, rows),
|
|
6325
6621
|
observeWork: (records) => this.testHooks.observeWork?.(records)
|
|
6326
|
-
}
|
|
6622
|
+
};
|
|
6623
|
+
const reader = new InMemoryMaterializationStateReader(this.state, objects, timeseries, hooks);
|
|
6624
|
+
this.materializations = new InMemoryOntologyMaterializationStorage(this.state, objects, timeseries, reader, options.getTransactionToken, options.getMaterializationLifecycle, options.readExecution, hooks);
|
|
6625
|
+
this.replacementPlans = new InMemoryOntologyReplacementPlanStorage(this.state, objects, reader, options.runRootOperation, options.assertSourceMaterializationExecution, hooks);
|
|
6327
6626
|
registerInMemoryOntologyStorageTestingAdapter(this, this.testingAdapter);
|
|
6328
6627
|
}
|
|
6329
6628
|
setTestHooks(hooks) {
|
|
@@ -6840,14 +7139,16 @@ class InMemoryProjectionRunStorage2 {
|
|
|
6840
7139
|
assertProjectionRunNonEmpty2(input.projectId, "projectId");
|
|
6841
7140
|
assertProjectionRunListWindow2(input.limit, "limit");
|
|
6842
7141
|
assertProjectionRunListWindow2(input.offset, "offset");
|
|
6843
|
-
if (input.statuses?.length === 0)
|
|
7142
|
+
if (input.statuses?.length === 0 || input.errorCodes?.length === 0) {
|
|
6844
7143
|
return { runs: [], hasMore: false, total: 0 };
|
|
7144
|
+
}
|
|
6845
7145
|
const order = input.order ?? "desc";
|
|
6846
7146
|
const offset = input.offset ?? 0;
|
|
6847
7147
|
const limit = input.limit ?? this.rows.size;
|
|
6848
7148
|
const statuses = input.statuses ? new Set(input.statuses) : null;
|
|
6849
7149
|
const objectTypeIds = input.objectTypeIds ? new Set(input.objectTypeIds) : null;
|
|
6850
|
-
const
|
|
7150
|
+
const errorCodes = input.errorCodes ? new Set(input.errorCodes) : null;
|
|
7151
|
+
const filtered = [...this.rows.values()].filter((record) => record.projectId === input.projectId).filter((record) => input.projectionId ? record.identity.projectionId === input.projectionId : true).filter((record) => input.projectionKind ? record.identity.projectionKind === input.projectionKind : true).filter((record) => input.datasetId ? record.identity.datasetVersion.datasetId === input.datasetId : true).filter((record) => input.datasetVersionId ? record.identity.datasetVersion.versionId === input.datasetVersionId : true).filter((record) => objectTypeIds ? projectionRunObjectTypesVisible2(record, (id) => objectTypeIds.has(id)) : true).filter((record) => statuses ? statuses.has(record.status) : true).filter((record) => errorCodes ? record.error !== undefined && errorCodes.has(record.error.code) : true).filter((record) => matchesRunListDateFilters(record, {
|
|
6851
7152
|
statuses,
|
|
6852
7153
|
startedAfter: input.startedAfter,
|
|
6853
7154
|
startedBefore: input.startedBefore
|
|
@@ -7031,7 +7332,7 @@ class InMemoryShareGrantStorage2 {
|
|
|
7031
7332
|
rows = new Map;
|
|
7032
7333
|
async create(input) {
|
|
7033
7334
|
const record = normalizeShareGrantCreate2(input);
|
|
7034
|
-
const key =
|
|
7335
|
+
const key = rowKey2(record.projectId, record.id);
|
|
7035
7336
|
const duplicateTokenHash = [...this.rows.values()].some((current) => current.projectId === record.projectId && current.tokenHash === record.tokenHash);
|
|
7036
7337
|
if (this.rows.has(key) || duplicateTokenHash) {
|
|
7037
7338
|
throw new ShareGrantStorageError2("duplicate", `[Sixb] Share grant '${record.id}' conflicts with an existing record.`);
|
|
@@ -7041,7 +7342,7 @@ class InMemoryShareGrantStorage2 {
|
|
|
7041
7342
|
}
|
|
7042
7343
|
async getById(input) {
|
|
7043
7344
|
const normalized = normalizeGetShareGrantByIdInput2(input);
|
|
7044
|
-
const record = this.rows.get(
|
|
7345
|
+
const record = this.rows.get(rowKey2(normalized.projectId, normalized.id));
|
|
7045
7346
|
return record ? cloneShareGrantRecord2(record) : null;
|
|
7046
7347
|
}
|
|
7047
7348
|
async list(input) {
|
|
@@ -7057,7 +7358,7 @@ class InMemoryShareGrantStorage2 {
|
|
|
7057
7358
|
}
|
|
7058
7359
|
async revoke(input) {
|
|
7059
7360
|
const normalized = normalizeRevokeShareGrantInput2(input);
|
|
7060
|
-
const key =
|
|
7361
|
+
const key = rowKey2(normalized.projectId, normalized.id);
|
|
7061
7362
|
const current = this.rows.get(key);
|
|
7062
7363
|
if (!current)
|
|
7063
7364
|
return null;
|
|
@@ -7085,7 +7386,7 @@ function compareShareGrants(left, right) {
|
|
|
7085
7386
|
return created;
|
|
7086
7387
|
return left.id === right.id ? 0 : left.id < right.id ? 1 : -1;
|
|
7087
7388
|
}
|
|
7088
|
-
function
|
|
7389
|
+
function rowKey2(projectId, id) {
|
|
7089
7390
|
return `${projectId}\x00${id}`;
|
|
7090
7391
|
}
|
|
7091
7392
|
// src/storage/share-sessions/in-memory.ts
|
|
@@ -7101,7 +7402,7 @@ class InMemoryShareSessionStorage2 {
|
|
|
7101
7402
|
if (!grant) {
|
|
7102
7403
|
throw new ShareSessionStorageError2("invalid_input", `[Sixb] Share grant '${record.grantId}' does not exist in project '${record.projectId}'.`);
|
|
7103
7404
|
}
|
|
7104
|
-
const key =
|
|
7405
|
+
const key = rowKey3(record.projectId, record.id);
|
|
7105
7406
|
const duplicateTokenHash = [...this.rows.values()].some((current) => current.projectId === record.projectId && current.tokenHash === record.tokenHash);
|
|
7106
7407
|
if (this.rows.has(key) || duplicateTokenHash) {
|
|
7107
7408
|
throw new ShareSessionStorageError2("duplicate", `[Sixb] Share session '${record.id}' conflicts with an existing record.`);
|
|
@@ -7111,12 +7412,12 @@ class InMemoryShareSessionStorage2 {
|
|
|
7111
7412
|
}
|
|
7112
7413
|
async getById(input) {
|
|
7113
7414
|
const normalized = normalizeGetShareSessionByIdInput2(input);
|
|
7114
|
-
const record = this.rows.get(
|
|
7415
|
+
const record = this.rows.get(rowKey3(normalized.projectId, normalized.id));
|
|
7115
7416
|
return record ? cloneShareSessionRecord2(record) : null;
|
|
7116
7417
|
}
|
|
7117
7418
|
async renewIfValid(input) {
|
|
7118
7419
|
const normalized = normalizeRenewShareSessionIfValidInput2(input);
|
|
7119
|
-
const key =
|
|
7420
|
+
const key = rowKey3(normalized.projectId, normalized.id);
|
|
7120
7421
|
const current = this.rows.get(key);
|
|
7121
7422
|
if (!current || current.grantId !== normalized.grantId || current.tokenHash !== normalized.tokenHash || current.revokedAt !== undefined || current.createdAt.getTime() > normalized.now.getTime() || current.expiresAt.getTime() <= normalized.now.getTime() || current.absoluteExpiresAt.getTime() <= normalized.now.getTime()) {
|
|
7122
7423
|
return null;
|
|
@@ -7128,7 +7429,7 @@ class InMemoryShareSessionStorage2 {
|
|
|
7128
7429
|
}
|
|
7129
7430
|
async revoke(input) {
|
|
7130
7431
|
const normalized = normalizeRevokeShareSessionInput2(input);
|
|
7131
|
-
const key =
|
|
7432
|
+
const key = rowKey3(normalized.projectId, normalized.id);
|
|
7132
7433
|
const current = this.rows.get(key);
|
|
7133
7434
|
if (!current)
|
|
7134
7435
|
return null;
|
|
@@ -7146,7 +7447,7 @@ class InMemoryShareSessionStorage2 {
|
|
|
7146
7447
|
this.rows = new Map([...snapshot].map(([key, record]) => [key, parseShareSessionRecord2(record)]));
|
|
7147
7448
|
}
|
|
7148
7449
|
}
|
|
7149
|
-
function
|
|
7450
|
+
function rowKey3(projectId, id) {
|
|
7150
7451
|
return `${projectId}\x00${id}`;
|
|
7151
7452
|
}
|
|
7152
7453
|
// src/storage/sync-runs/types.ts
|
|
@@ -8173,6 +8474,7 @@ class InMemoryStorage2 {
|
|
|
8173
8474
|
webhookRunStorage = new InMemoryWebhookRunStorage2(this.executionStorage);
|
|
8174
8475
|
rulesStorage = new InMemoryRulesStorage2;
|
|
8175
8476
|
fileUploadSessionStorage = new InMemoryFileUploadSessions2;
|
|
8477
|
+
fileDownloadGrantStorage = new InMemoryFileDownloadGrantStorage;
|
|
8176
8478
|
connectorConnectionStorage;
|
|
8177
8479
|
auth;
|
|
8178
8480
|
executions;
|
|
@@ -8191,6 +8493,7 @@ class InMemoryStorage2 {
|
|
|
8191
8493
|
shareGrants;
|
|
8192
8494
|
shareSessions;
|
|
8193
8495
|
fileUploadSessions;
|
|
8496
|
+
fileDownloadGrants;
|
|
8194
8497
|
connectorConnections;
|
|
8195
8498
|
constructor(options = {}) {
|
|
8196
8499
|
this.connectorConnectionStorage = new InMemoryConnectorConnectionStorage2(options.connectorConnections);
|
|
@@ -8214,13 +8517,14 @@ class InMemoryStorage2 {
|
|
|
8214
8517
|
this.shareGrants = createOperationScopedFacade2(this.shareGrantStorage, scope);
|
|
8215
8518
|
this.shareSessions = createOperationScopedFacade2(this.shareSessionStorage, scope);
|
|
8216
8519
|
this.fileUploadSessions = createOperationScopedFacade2(this.fileUploadSessionStorage, scope);
|
|
8520
|
+
this.fileDownloadGrants = createOperationScopedFacade2(this.fileDownloadGrantStorage, scope);
|
|
8217
8521
|
this.connectorConnections = createOperationScopedFacade2(this.connectorConnectionStorage, scope);
|
|
8218
8522
|
this.ontologyStorage = new InMemoryOntologyStorage(this.objectStorage, this.timeseriesStorage, {
|
|
8219
8523
|
runRootOperation: async (run) => run(),
|
|
8220
8524
|
getTransactionToken: () => this.getActiveTransactionToken(),
|
|
8221
8525
|
getMaterializationLifecycle: () => this.getActiveMaterializationLifecycle(),
|
|
8222
8526
|
assertSourceMaterializationExecution: (input) => this.projectionRunStorage.assertSourceMaterializationExecutionUnlocked(input),
|
|
8223
|
-
|
|
8527
|
+
readExecution: (projectId, executionId) => this.executionStorage.getById({ projectId, id: executionId })
|
|
8224
8528
|
});
|
|
8225
8529
|
this.ontology = createOntologyOperationScope2(this.ontologyStorage, scope);
|
|
8226
8530
|
this.ontologyStorage.registerTestingAlias(this.ontology);
|
|
@@ -8374,6 +8678,7 @@ class InMemoryStorage2 {
|
|
|
8374
8678
|
shareGrants: this.shareGrantStorage,
|
|
8375
8679
|
shareSessions: this.shareSessionStorage,
|
|
8376
8680
|
fileUploadSessions: this.fileUploadSessionStorage,
|
|
8681
|
+
fileDownloadGrants: this.fileDownloadGrantStorage,
|
|
8377
8682
|
connectorConnections: this.connectorConnectionStorage,
|
|
8378
8683
|
ping: async () => {
|
|
8379
8684
|
return;
|
|
@@ -8405,6 +8710,7 @@ class InMemoryStorage2 {
|
|
|
8405
8710
|
shareGrants: this.shareGrantStorage.snapshot(),
|
|
8406
8711
|
shareSessions: this.shareSessionStorage.snapshot(),
|
|
8407
8712
|
fileUploadSessions: this.fileUploadSessionStorage.snapshot(),
|
|
8713
|
+
fileDownloadGrants: this.fileDownloadGrantStorage.snapshot(),
|
|
8408
8714
|
connectorConnections: this.connectorConnectionStorage.snapshot()
|
|
8409
8715
|
};
|
|
8410
8716
|
}
|
|
@@ -8429,25 +8735,65 @@ class InMemoryStorage2 {
|
|
|
8429
8735
|
this.shareGrantStorage.restore(snapshot.shareGrants);
|
|
8430
8736
|
this.shareSessionStorage.restore(snapshot.shareSessions);
|
|
8431
8737
|
this.fileUploadSessionStorage.restore(snapshot.fileUploadSessions);
|
|
8738
|
+
this.fileDownloadGrantStorage.restore(snapshot.fileDownloadGrants);
|
|
8432
8739
|
this.connectorConnectionStorage.restore(snapshot.connectorConnections);
|
|
8433
8740
|
}
|
|
8434
8741
|
}
|
|
8742
|
+
// src/storage/objects/query-preparation.ts
|
|
8743
|
+
function isQueryPreparationCapableStorage(storage) {
|
|
8744
|
+
return "prepareObjectQueries" in storage && typeof storage.prepareObjectQueries === "function";
|
|
8745
|
+
}
|
|
8746
|
+
async function prepareObjectQueries2(input) {
|
|
8747
|
+
if (!isQueryPreparationCapableStorage(input.storage)) {
|
|
8748
|
+
throw new Error("[Sixb] This storage provider does not support object query preparation");
|
|
8749
|
+
}
|
|
8750
|
+
const values = input.ontology.getValueTypesById();
|
|
8751
|
+
const objectTypes = input.ontology.listObjectTypes().map((type) => ({
|
|
8752
|
+
objectTypeId: type.id,
|
|
8753
|
+
properties: type.properties.filter((property) => property.mode !== "telemetry" && !property.primary).map((property) => {
|
|
8754
|
+
const capabilities = resolvePropertyQueryCapabilities2(property, values);
|
|
8755
|
+
const schema = resolveQuerySchema(property.schema, values);
|
|
8756
|
+
return {
|
|
8757
|
+
propertyId: property.id,
|
|
8758
|
+
scalarKind: schema ? queryScalarKindForSchema(schema) : undefined,
|
|
8759
|
+
filterable: capabilities.operators.includes("eq"),
|
|
8760
|
+
sortable: capabilities.sortable,
|
|
8761
|
+
text: capabilities.text
|
|
8762
|
+
};
|
|
8763
|
+
}).filter((property) => property.filterable || property.sortable || property.text),
|
|
8764
|
+
indexes: type.query?.indexes ?? []
|
|
8765
|
+
}));
|
|
8766
|
+
return input.storage.prepareObjectQueries({ projectId: input.projectId, objectTypes });
|
|
8767
|
+
}
|
|
8768
|
+
|
|
8435
8769
|
// src/storage/migrations/migrate-storage.ts
|
|
8436
8770
|
function isMigrationCapableStorage2(storage) {
|
|
8437
8771
|
return Array.isArray(storage.migrators);
|
|
8438
8772
|
}
|
|
8439
|
-
async function migrateStorage2(storage) {
|
|
8440
|
-
if (!isMigrationCapableStorage2(storage) || storage.migrators.length === 0) {
|
|
8441
|
-
return { status: "skipped", reports: [] };
|
|
8442
|
-
}
|
|
8773
|
+
async function migrateStorage2(storage, options) {
|
|
8443
8774
|
const reports = [];
|
|
8444
|
-
|
|
8445
|
-
|
|
8775
|
+
if (isMigrationCapableStorage2(storage)) {
|
|
8776
|
+
for (const migrator of storage.migrators) {
|
|
8777
|
+
reports.push(await migrator.migrate());
|
|
8778
|
+
}
|
|
8446
8779
|
}
|
|
8447
|
-
|
|
8448
|
-
|
|
8449
|
-
|
|
8450
|
-
|
|
8780
|
+
let queries;
|
|
8781
|
+
if (options && isQueryPreparationCapableStorage(storage)) {
|
|
8782
|
+
queries = await prepareObjectQueries2({ ...options, storage });
|
|
8783
|
+
for (const warning of queries.warnings) {
|
|
8784
|
+
console.warn(`[Sixb] ${warning}`);
|
|
8785
|
+
}
|
|
8786
|
+
}
|
|
8787
|
+
let status = "skipped";
|
|
8788
|
+
if (reports.length > 0 || queries) {
|
|
8789
|
+
status = "current";
|
|
8790
|
+
}
|
|
8791
|
+
if (reports.some((report) => report.status === "migrated") || queries?.status === "prepared") {
|
|
8792
|
+
status = "migrated";
|
|
8793
|
+
}
|
|
8794
|
+
if (queries)
|
|
8795
|
+
return { status, reports, queries };
|
|
8796
|
+
return { status, reports };
|
|
8451
8797
|
}
|
|
8452
8798
|
|
|
8453
8799
|
// src/storage/migrations/check-schema.ts
|
|
@@ -8648,6 +8994,6 @@ var VECTOR_INDEXING_FAILURE_CODES2 = [
|
|
|
8648
8994
|
"vector.outcome_unknown",
|
|
8649
8995
|
"internal.unexpected"
|
|
8650
8996
|
];
|
|
8651
|
-
export { InMemoryActionRunStorage2, AGENT_MESSAGE_CONTENT_VERSION2, InMemoryAgentStorage2, AiCostStorageError2, InMemoryAiCostStorage2, InMemoryAiLimitStorage2, InMemoryConnectorConnectionStorage2, InMemoryFileUploadSessions2, hasVectorProfile2, isVectorProfileQuery2, objectBatchKey2, linkBatchKey2, objectLinkCursor2, compareQueryScalarValues, queryScalarValuesEqual, MAX_VECTOR_K, vectorConfiguration, vectorSources, normalizeVector2, vectorSearchCandidateLimit2, PIPELINE_RUN_FAILURE_CODES2, InMemoryPipelineRunStorage2, InMemoryProjectionRunStorage2, InMemoryRulesStorage2, InMemoryShareGrantStorage2, InMemoryShareSessionStorage2, SYNC_RUN_FAILURE_CODES2, InMemorySyncRunStorage2, WEBHOOK_RUN_FAILURE_CODES2, canRetryWebhookRun2, InMemoryWebhookRunStorage2, WorkflowInterventionError2, InMemoryWorkflowInterventionStorage2, WORKFLOW_RUN_FAILURE_CODES2, InMemoryWorkflowRunStorage2, InMemoryWorkflowNodeRunStorage2, InMemoryWorkflowAgentNodeRunStorage2, InMemoryStorage2, isMigrationCapableStorage2, migrateStorage2, checkStorageSchema2, step2, defineMigrations2, runMigrationSet2, describeMigrationHistory2, VECTOR_INDEXING_FAILURE_CODES2 };
|
|
8997
|
+
export { InMemoryActionRunStorage2, AGENT_MESSAGE_CONTENT_VERSION2, InMemoryAgentStorage2, AiCostStorageError2, InMemoryAiCostStorage2, InMemoryAiLimitStorage2, InMemoryConnectorConnectionStorage2, InMemoryFileUploadSessions2, hasVectorProfile2, isVectorProfileQuery2, objectBatchKey2, linkBatchKey2, objectLinkCursor2, compareQueryScalarValues, queryScalarValuesEqual, MAX_VECTOR_K, vectorConfiguration, vectorSources, normalizeVector2, vectorSearchCandidateLimit2, PIPELINE_RUN_FAILURE_CODES2, InMemoryPipelineRunStorage2, InMemoryProjectionRunStorage2, InMemoryRulesStorage2, InMemoryShareGrantStorage2, InMemoryShareSessionStorage2, SYNC_RUN_FAILURE_CODES2, InMemorySyncRunStorage2, WEBHOOK_RUN_FAILURE_CODES2, canRetryWebhookRun2, InMemoryWebhookRunStorage2, WorkflowInterventionError2, InMemoryWorkflowInterventionStorage2, WORKFLOW_RUN_FAILURE_CODES2, InMemoryWorkflowRunStorage2, InMemoryWorkflowNodeRunStorage2, InMemoryWorkflowAgentNodeRunStorage2, InMemoryStorage2, prepareObjectQueries2, isMigrationCapableStorage2, migrateStorage2, checkStorageSchema2, step2, defineMigrations2, runMigrationSet2, describeMigrationHistory2, VECTOR_INDEXING_FAILURE_CODES2 };
|
|
8652
8998
|
|
|
8653
|
-
//# debugId=
|
|
8999
|
+
//# debugId=06195CF0CDEA109D64756E2164756E21
|