@sixb/core 0.2.0 → 0.2.2
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 -30
- package/dist/agents/cancel.d.ts.map +1 -1
- package/dist/agents/index.d.ts +5 -3
- package/dist/agents/index.d.ts.map +1 -1
- package/dist/agents/index.js +39 -33
- package/dist/agents/index.js.map +1 -1
- package/dist/agents/run-plan.d.ts +15 -1
- package/dist/agents/run-plan.d.ts.map +1 -1
- package/dist/agents/run-session-http.d.ts.map +1 -1
- package/dist/agents/run-session-serve.d.ts.map +1 -1
- package/dist/agents/run-session.d.ts +14 -2
- package/dist/agents/run-session.d.ts.map +1 -1
- package/dist/agents/skills.d.ts +3 -0
- package/dist/agents/skills.d.ts.map +1 -1
- package/dist/agents/step-limits.d.ts +6 -0
- package/dist/agents/step-limits.d.ts.map +1 -1
- package/dist/agents/streams/index.js +1 -1
- package/dist/agents/streams/internal.js +1 -1
- package/dist/agents/streams/protocol.d.ts +8 -2
- package/dist/agents/streams/protocol.d.ts.map +1 -1
- package/dist/agents/tool-files.d.ts +3 -1
- package/dist/agents/tool-files.d.ts.map +1 -1
- package/dist/agents/validation.d.ts +1 -1
- package/dist/agents/validation.d.ts.map +1 -1
- package/dist/agents/web.d.ts +47 -0
- package/dist/agents/web.d.ts.map +1 -0
- package/dist/artifacts/publish/index.js +17 -17
- package/dist/auth/index.js +3 -3
- package/dist/authorization/index.js +2 -2
- package/dist/authorization/resolve.d.ts +4 -3
- package/dist/authorization/resolve.d.ts.map +1 -1
- package/dist/authorization/types.d.ts +5 -5
- package/dist/authorization/types.d.ts.map +1 -1
- package/dist/bootstrap/index.js +38 -38
- package/dist/{chunk-neftrg0n.js → chunk-0j3crh1w.js} +2 -2
- package/dist/{chunk-8dcfj58k.js → chunk-2ajw5rz0.js} +14 -10
- package/dist/chunk-2ajw5rz0.js.map +18 -0
- package/dist/{chunk-23s66j86.js → chunk-31kcqmhf.js} +1 -1
- package/dist/{chunk-nghc7eq0.js → chunk-3723kgba.js} +1 -1
- package/dist/{chunk-fdkpkkpw.js → chunk-3sqqhpr7.js} +5 -5
- package/dist/{chunk-m3qe54bb.js → chunk-4bm0caep.js} +1 -1
- package/dist/{chunk-ztf5vtmp.js → chunk-4s753g3k.js} +41 -10
- package/dist/chunk-4s753g3k.js.map +12 -0
- package/dist/{chunk-fntqb7qy.js → chunk-57g0215c.js} +1 -1
- package/dist/{chunk-8wsjr52f.js → chunk-5wtnmpze.js} +1 -1
- package/dist/{chunk-edx8xcsm.js → chunk-7z5rkf0m.js} +29 -6
- package/dist/chunk-7z5rkf0m.js.map +13 -0
- package/dist/{chunk-2pk5hjj9.js → chunk-80gym75n.js} +1 -1
- package/dist/{chunk-qbrmpgvv.js → chunk-9whfmsfk.js} +1 -1
- package/dist/{chunk-qya541bk.js → chunk-a5v4gjdx.js} +31 -28
- package/dist/{chunk-qya541bk.js.map → chunk-a5v4gjdx.js.map} +4 -4
- package/dist/{chunk-he7g39e5.js → chunk-a7aa0nzj.js} +7 -7
- package/dist/{chunk-tvefbgvw.js → chunk-az95tsh3.js} +4 -2
- package/dist/chunk-az95tsh3.js.map +11 -0
- package/dist/{chunk-7hd2ez3q.js → chunk-c4nrycdy.js} +1 -1
- package/dist/{chunk-ekkpzcka.js → chunk-c706qvyc.js} +36 -9
- package/dist/chunk-c706qvyc.js.map +11 -0
- package/dist/{chunk-n54k068r.js → chunk-c7cfe31p.js} +7 -7
- package/dist/{chunk-qsg8rw04.js → chunk-d04g36fw.js} +1 -1
- package/dist/{chunk-hjy3dsws.js → chunk-dsv783c3.js} +305 -32
- package/dist/{chunk-hjy3dsws.js.map → chunk-dsv783c3.js.map} +12 -10
- package/dist/{chunk-peggaard.js → chunk-e6xgz4h4.js} +20 -2
- package/dist/{chunk-peggaard.js.map → chunk-e6xgz4h4.js.map} +5 -3
- package/dist/{chunk-e99kp9jh.js → chunk-eqgr6nsa.js} +86 -30
- package/dist/{chunk-e99kp9jh.js.map → chunk-eqgr6nsa.js.map} +10 -9
- package/dist/{chunk-f2w6328x.js → chunk-f1h34y3r.js} +6 -6
- package/dist/{chunk-9rh8ncs5.js → chunk-fwsvshr5.js} +1 -1
- package/dist/{chunk-c78jjzhy.js → chunk-ga63a3dz.js} +6 -6
- package/dist/{chunk-c78jjzhy.js.map → chunk-ga63a3dz.js.map} +2 -2
- package/dist/{chunk-cgznz22f.js → chunk-gkv8r794.js} +2 -2
- package/dist/{chunk-d3t26vah.js → chunk-j1ny5fwh.js} +35 -11
- package/dist/chunk-j1ny5fwh.js.map +15 -0
- package/dist/{chunk-8hvfs0fr.js → chunk-j8thxj7w.js} +4 -4
- package/dist/{chunk-855n80en.js → chunk-jjmggm9a.js} +1 -1
- package/dist/{chunk-31khg3g0.js → chunk-kkjfve0t.js} +73 -2
- package/dist/{chunk-31khg3g0.js.map → chunk-kkjfve0t.js.map} +3 -3
- package/dist/{chunk-fb3m4sa1.js → chunk-m2vh8gh0.js} +8 -14
- package/dist/{chunk-fb3m4sa1.js.map → chunk-m2vh8gh0.js.map} +3 -3
- package/dist/{chunk-vkweppkw.js → chunk-mbc5hvnj.js} +3 -3
- package/dist/{chunk-jk97v21j.js → chunk-n4zzaf6q.js} +3 -2
- package/dist/chunk-n4zzaf6q.js.map +10 -0
- package/dist/{chunk-y2x2935j.js → chunk-nh26e7c5.js} +2 -2
- package/dist/{chunk-jhbk10wf.js → chunk-q9nkpr8k.js} +1 -1
- package/dist/{chunk-47e09r7z.js → chunk-qttqe1ah.js} +86 -6
- package/dist/{chunk-47e09r7z.js.map → chunk-qttqe1ah.js.map} +5 -4
- package/dist/{chunk-9mab3dvg.js → chunk-s038wa5v.js} +9 -1
- package/dist/{chunk-9mab3dvg.js.map → chunk-s038wa5v.js.map} +3 -3
- package/dist/{chunk-3x3bebz7.js → chunk-s7j8ewqv.js} +161 -62
- package/dist/{chunk-3x3bebz7.js.map → chunk-s7j8ewqv.js.map} +7 -6
- package/dist/{chunk-dz7a4t3a.js → chunk-twfreyxr.js} +5 -10
- package/dist/{chunk-dz7a4t3a.js.map → chunk-twfreyxr.js.map} +4 -4
- package/dist/{chunk-semf1yqn.js → chunk-w1btn96n.js} +51 -26
- package/dist/{chunk-semf1yqn.js.map → chunk-w1btn96n.js.map} +6 -6
- package/dist/{chunk-fg1db9xx.js → chunk-wkq3kvzd.js} +5 -5
- package/dist/chunk-wkq3kvzd.js.map +10 -0
- package/dist/{chunk-xj97s5js.js → chunk-wrjx1fqz.js} +6 -6
- package/dist/{chunk-agn8d8ys.js → chunk-xtztwpkh.js} +1 -1
- package/dist/{chunk-0g5nyx0k.js → chunk-zeykm8my.js} +2 -2
- package/dist/connectors/connections/runs.d.ts +7 -0
- package/dist/connectors/connections/runs.d.ts.map +1 -1
- package/dist/datasets/execution.d.ts.map +1 -1
- package/dist/events/index.js +1 -1
- package/dist/events/selectors/index.js +1 -1
- package/dist/events/selectors/predicate.d.ts.map +1 -1
- package/dist/events/types/datasets.d.ts +6 -0
- package/dist/events/types/datasets.d.ts.map +1 -1
- package/dist/execution/agent.js +30 -30
- package/dist/execution/object-reader-security.d.ts.map +1 -1
- package/dist/execution/primitive.js +30 -30
- package/dist/execution/request.js +31 -31
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +42 -42
- package/dist/lake-storage/in-memory.d.ts.map +1 -1
- package/dist/lake-storage/index.d.ts +2 -2
- package/dist/lake-storage/index.d.ts.map +1 -1
- package/dist/lake-storage/index.js +6 -2
- package/dist/lake-storage/index.js.map +1 -1
- package/dist/lake-storage/source-ordering.d.ts +7 -0
- package/dist/lake-storage/source-ordering.d.ts.map +1 -1
- package/dist/lake-storage/types.d.ts +18 -0
- package/dist/lake-storage/types.d.ts.map +1 -1
- package/dist/lake-storage/version-inputs.d.ts +11 -3
- package/dist/lake-storage/version-inputs.d.ts.map +1 -1
- package/dist/materializer/index.js +16 -16
- package/dist/models/catalog.d.ts +16 -0
- 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/execution/index.js +18 -18
- package/dist/models/execution/model-call-recorder.d.ts +1 -1
- package/dist/models/execution/model-call-recorder.d.ts.map +1 -1
- package/dist/models/execution/web-search.d.ts +7 -0
- package/dist/models/execution/web-search.d.ts.map +1 -0
- package/dist/models/index.d.ts +3 -1
- package/dist/models/index.d.ts.map +1 -1
- package/dist/models/index.js +5 -3
- package/dist/models/index.js.map +1 -1
- package/dist/models/language-model.d.ts +12 -0
- package/dist/models/language-model.d.ts.map +1 -1
- package/dist/models/web-search-model.d.ts +66 -0
- package/dist/models/web-search-model.d.ts.map +1 -0
- package/dist/objects/index.js +30 -30
- package/dist/objects/query/executor.d.ts.map +1 -1
- package/dist/objects/query/index.d.ts +1 -0
- package/dist/objects/query/index.d.ts.map +1 -1
- package/dist/objects/query/index.js +19 -16
- package/dist/objects/query/index.js.map +1 -1
- package/dist/objects/query/sort-ties.d.ts +11 -0
- package/dist/objects/query/sort-ties.d.ts.map +1 -0
- package/dist/pipelines/index.js +19 -19
- package/dist/pipelines/run-dispatch.d.ts +2 -0
- package/dist/pipelines/run-dispatch.d.ts.map +1 -1
- package/dist/projections/internal.js +16 -16
- package/dist/runtime/create.d.ts +1 -1
- package/dist/runtime/create.d.ts.map +1 -1
- package/dist/runtime/internal.js +22 -22
- package/dist/runtime/resolve-definitions.d.ts.map +1 -1
- package/dist/schedules/index.js +2 -2
- package/dist/security/index.d.ts +1 -0
- package/dist/security/index.d.ts.map +1 -1
- package/dist/security/registry.d.ts +2 -0
- package/dist/security/registry.d.ts.map +1 -1
- package/dist/security/view-conditions.d.ts.map +1 -1
- package/dist/security/visibility-keys.d.ts +19 -0
- package/dist/security/visibility-keys.d.ts.map +1 -0
- package/dist/shares/internal.js +16 -16
- package/dist/storage/agents/in-memory.d.ts +8 -2
- package/dist/storage/agents/in-memory.d.ts.map +1 -1
- package/dist/storage/agents/index.d.ts +1 -1
- package/dist/storage/agents/index.d.ts.map +1 -1
- package/dist/storage/agents/provider.d.ts +8 -2
- package/dist/storage/agents/provider.d.ts.map +1 -1
- package/dist/storage/agents/provider.js +12 -6
- package/dist/storage/agents/provider.js.map +1 -1
- package/dist/storage/agents/types.d.ts +42 -2
- package/dist/storage/agents/types.d.ts.map +1 -1
- package/dist/storage/ai-cost/provider.js +4 -4
- package/dist/storage/ai-limits/enforcement.js +3 -3
- package/dist/storage/ai-limits/provider.js +2 -2
- package/dist/storage/connector-connections/provider.js +3 -3
- package/dist/storage/connector-connections/provider.js.map +3 -3
- package/dist/storage/file-upload-sessions/provider.js +4 -4
- package/dist/storage/index.d.ts +2 -2
- package/dist/storage/index.d.ts.map +1 -1
- package/dist/storage/index.js +15 -15
- package/dist/storage/internal.d.ts +2 -0
- package/dist/storage/internal.d.ts.map +1 -1
- package/dist/storage/internal.js +8 -4
- package/dist/storage/internal.js.map +1 -1
- package/dist/storage/migrations/types.d.ts +6 -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/index.d.ts +1 -1
- package/dist/storage/objects/index.d.ts.map +1 -1
- package/dist/storage/objects/query-preparation.d.ts +13 -0
- package/dist/storage/objects/query-preparation.d.ts.map +1 -1
- package/dist/storage/objects/read-scope.d.ts.map +1 -1
- package/dist/storage/objects/types.d.ts +52 -0
- package/dist/storage/objects/types.d.ts.map +1 -1
- package/dist/storage/pipeline-runs/in-memory.d.ts.map +1 -1
- package/dist/storage/pipeline-runs/transitions.d.ts +7 -0
- package/dist/storage/pipeline-runs/transitions.d.ts.map +1 -0
- package/dist/storage/share-grants/provider.js +2 -2
- package/dist/storage/sync-runs/in-memory.d.ts.map +1 -1
- package/dist/storage/sync-runs/transitions.d.ts +7 -0
- package/dist/storage/sync-runs/transitions.d.ts.map +1 -0
- package/dist/storage/workflow-runs/provider.js +4 -4
- package/dist/syncs/index.js +20 -20
- package/dist/syncs/run-dispatch.d.ts +2 -0
- package/dist/syncs/run-dispatch.d.ts.map +1 -1
- package/dist/testing/agent-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/connector-connection-storage-contract.d.ts.map +1 -1
- package/dist/testing/dataset-sequence-contract.d.ts.map +1 -1
- package/dist/testing/index.js +552 -61
- package/dist/testing/index.js.map +11 -11
- package/dist/testing/lake-changes-contract.d.ts.map +1 -1
- package/dist/testing/lake-storage-contract.d.ts.map +1 -1
- package/dist/testing/object-conditional-read-scope-contract.d.ts.map +1 -1
- package/dist/testing/object-query-contract.d.ts.map +1 -1
- package/dist/webhooks/internal.js +16 -16
- package/dist/workers/index.d.ts +1 -0
- package/dist/workers/index.d.ts.map +1 -1
- package/dist/workers/index.js +12 -2
- package/dist/workers/index.js.map +5 -4
- package/dist/workers/unstarted-run.d.ts +10 -0
- package/dist/workers/unstarted-run.d.ts.map +1 -0
- package/dist/workflows/index.js +34 -34
- package/package.json +1 -1
- package/src/agents/README.md +2 -1
- package/src/agents/cancel.ts +7 -1
- package/src/agents/index.ts +9 -1
- package/src/agents/run-plan.ts +31 -0
- package/src/agents/run-session-http.ts +15 -12
- package/src/agents/run-session-serve.ts +8 -2
- package/src/agents/run-session.ts +31 -11
- package/src/agents/skills.ts +3 -0
- package/src/agents/step-limits.ts +6 -0
- package/src/agents/streams/protocol.ts +9 -4
- package/src/agents/tool-files.ts +11 -3
- package/src/agents/validation.ts +9 -0
- package/src/agents/web.ts +218 -0
- package/src/authorization/resolve.ts +9 -11
- package/src/authorization/types.ts +5 -5
- package/src/connectors/connections/runs.ts +42 -5
- package/src/datasets/execution.ts +2 -0
- package/src/events/selectors/predicate.ts +15 -0
- package/src/events/types/datasets.ts +6 -0
- package/src/execution/object-reader-security.ts +4 -9
- package/src/index.ts +2 -0
- package/src/lake-storage/in-memory.ts +30 -20
- package/src/lake-storage/index.ts +2 -1
- package/src/lake-storage/source-ordering.ts +31 -4
- package/src/lake-storage/types.ts +18 -0
- package/src/lake-storage/version-inputs.ts +21 -5
- package/src/models/catalog.ts +52 -3
- package/src/models/definitions.ts +2 -0
- package/src/models/execution/README.md +22 -2
- package/src/models/execution/model-call-recorder.ts +1 -1
- package/src/models/execution/web-search.ts +186 -0
- package/src/models/index.ts +12 -0
- package/src/models/language-model.ts +12 -0
- package/src/models/web-search-model.ts +152 -0
- package/src/objects/query/executor.ts +7 -3
- package/src/objects/query/index.ts +1 -0
- package/src/objects/query/sort-ties.ts +16 -0
- package/src/pipelines/run-dispatch.ts +53 -6
- package/src/runtime/create.ts +3 -2
- package/src/runtime/resolve-definitions.ts +4 -0
- package/src/security/index.ts +1 -0
- package/src/security/registry.ts +2 -0
- package/src/security/view-conditions.ts +4 -3
- package/src/security/visibility-keys.ts +144 -0
- package/src/storage/agents/in-memory.ts +29 -2
- package/src/storage/agents/index.ts +2 -0
- package/src/storage/agents/provider.ts +57 -1
- package/src/storage/agents/types.ts +45 -2
- package/src/storage/connector-connections/in-memory.ts +2 -2
- package/src/storage/connector-connections/provider/connections.ts +2 -2
- package/src/storage/index.ts +4 -0
- package/src/storage/internal.ts +2 -0
- package/src/storage/migrations/types.ts +6 -0
- package/src/storage/objects/in-memory/query.ts +5 -2
- package/src/storage/objects/index.ts +2 -0
- package/src/storage/objects/query-preparation.ts +59 -1
- package/src/storage/objects/read-scope.ts +108 -2
- package/src/storage/objects/types.ts +43 -0
- package/src/storage/pipeline-runs/in-memory.ts +2 -5
- package/src/storage/pipeline-runs/transitions.ts +14 -0
- package/src/storage/sync-runs/in-memory.ts +2 -5
- package/src/storage/sync-runs/transitions.ts +11 -0
- package/src/syncs/run-dispatch.ts +68 -13
- package/src/testing/agent-storage-contract.ts +70 -0
- package/src/testing/ai-limit-storage-contract.ts +11 -1
- package/src/testing/ai-usage-storage-contract.ts +15 -2
- package/src/testing/connector-connection-storage-contract.ts +23 -0
- package/src/testing/dataset-sequence-contract.ts +81 -0
- package/src/testing/lake-changes-contract.ts +2 -1
- package/src/testing/lake-storage-contract.ts +112 -0
- package/src/testing/object-conditional-read-scope-contract.ts +267 -5
- package/src/testing/object-query-contract.ts +75 -0
- package/src/workers/index.ts +1 -0
- package/src/workers/unstarted-run.ts +18 -0
- package/dist/chunk-8dcfj58k.js.map +0 -18
- package/dist/chunk-d3t26vah.js.map +0 -15
- package/dist/chunk-edx8xcsm.js.map +0 -13
- package/dist/chunk-ekkpzcka.js.map +0 -11
- package/dist/chunk-fg1db9xx.js.map +0 -10
- package/dist/chunk-jk97v21j.js.map +0 -10
- package/dist/chunk-tvefbgvw.js.map +0 -11
- package/dist/chunk-ztf5vtmp.js.map +0 -12
- /package/dist/{chunk-neftrg0n.js.map → chunk-0j3crh1w.js.map} +0 -0
- /package/dist/{chunk-23s66j86.js.map → chunk-31kcqmhf.js.map} +0 -0
- /package/dist/{chunk-nghc7eq0.js.map → chunk-3723kgba.js.map} +0 -0
- /package/dist/{chunk-fdkpkkpw.js.map → chunk-3sqqhpr7.js.map} +0 -0
- /package/dist/{chunk-m3qe54bb.js.map → chunk-4bm0caep.js.map} +0 -0
- /package/dist/{chunk-fntqb7qy.js.map → chunk-57g0215c.js.map} +0 -0
- /package/dist/{chunk-8wsjr52f.js.map → chunk-5wtnmpze.js.map} +0 -0
- /package/dist/{chunk-2pk5hjj9.js.map → chunk-80gym75n.js.map} +0 -0
- /package/dist/{chunk-qbrmpgvv.js.map → chunk-9whfmsfk.js.map} +0 -0
- /package/dist/{chunk-he7g39e5.js.map → chunk-a7aa0nzj.js.map} +0 -0
- /package/dist/{chunk-7hd2ez3q.js.map → chunk-c4nrycdy.js.map} +0 -0
- /package/dist/{chunk-n54k068r.js.map → chunk-c7cfe31p.js.map} +0 -0
- /package/dist/{chunk-qsg8rw04.js.map → chunk-d04g36fw.js.map} +0 -0
- /package/dist/{chunk-f2w6328x.js.map → chunk-f1h34y3r.js.map} +0 -0
- /package/dist/{chunk-9rh8ncs5.js.map → chunk-fwsvshr5.js.map} +0 -0
- /package/dist/{chunk-cgznz22f.js.map → chunk-gkv8r794.js.map} +0 -0
- /package/dist/{chunk-8hvfs0fr.js.map → chunk-j8thxj7w.js.map} +0 -0
- /package/dist/{chunk-855n80en.js.map → chunk-jjmggm9a.js.map} +0 -0
- /package/dist/{chunk-vkweppkw.js.map → chunk-mbc5hvnj.js.map} +0 -0
- /package/dist/{chunk-y2x2935j.js.map → chunk-nh26e7c5.js.map} +0 -0
- /package/dist/{chunk-jhbk10wf.js.map → chunk-q9nkpr8k.js.map} +0 -0
- /package/dist/{chunk-xj97s5js.js.map → chunk-wrjx1fqz.js.map} +0 -0
- /package/dist/{chunk-agn8d8ys.js.map → chunk-xtztwpkh.js.map} +0 -0
- /package/dist/{chunk-0g5nyx0k.js.map → chunk-zeykm8my.js.map} +0 -0
|
@@ -250,6 +250,87 @@ export function runDatasetSequenceContract<TStorage extends LakeStorage>(
|
|
|
250
250
|
expect(await rows(storage)).toEqual([])
|
|
251
251
|
}))
|
|
252
252
|
|
|
253
|
+
test("records a merge that only advances source ordering as changing no rows", () =>
|
|
254
|
+
withStorage(async (storage) => {
|
|
255
|
+
// Red check: record `rowsChanged: true` on every merge version the provider creates.
|
|
256
|
+
const changed = (result: DatasetMergeCommitResult) => ({
|
|
257
|
+
outcome: result.outcome,
|
|
258
|
+
rowsChanged: result.version?.rowsChanged,
|
|
259
|
+
lineageChanged: result.version?.lineageChanged,
|
|
260
|
+
})
|
|
261
|
+
|
|
262
|
+
expect(changed(await merge(storage, [upsert(1)]))).toEqual({
|
|
263
|
+
outcome: "created",
|
|
264
|
+
rowsChanged: true,
|
|
265
|
+
lineageChanged: true,
|
|
266
|
+
})
|
|
267
|
+
|
|
268
|
+
// The delete of a key the dataset does not hold only records its sequence.
|
|
269
|
+
const orderingOnly = await merge(storage, [change.delete({ id: "7" }, { sequence: 3 })])
|
|
270
|
+
expect(changed(orderingOnly)).toEqual({
|
|
271
|
+
outcome: "created",
|
|
272
|
+
rowsChanged: false,
|
|
273
|
+
lineageChanged: false,
|
|
274
|
+
})
|
|
275
|
+
expect(
|
|
276
|
+
(await storage.getVersion(dataset.id, orderingOnly.version!.versionId))?.rowsChanged
|
|
277
|
+
).toBe(false)
|
|
278
|
+
|
|
279
|
+
expect(changed(await merge(storage, [upsert(2, "Ada")]))).toEqual({
|
|
280
|
+
outcome: "created",
|
|
281
|
+
rowsChanged: true,
|
|
282
|
+
lineageChanged: false,
|
|
283
|
+
})
|
|
284
|
+
}))
|
|
285
|
+
|
|
286
|
+
test("keeps a stored row that a newer delivery repeats with only its sequence changed", () =>
|
|
287
|
+
withStorage(async (storage) => {
|
|
288
|
+
// Red check: write every accepted upsert's row (drop `isSequenceOnlyChange` from the
|
|
289
|
+
// provider's merge, or the `sequenceBy` filter from DuckLake's row difference).
|
|
290
|
+
const stored = async () =>
|
|
291
|
+
(await rows(storage))
|
|
292
|
+
.map((row) => ({ id: row.id, revision: String(row.revision), name: row.name }))
|
|
293
|
+
.sort((left, right) => String(left.id).localeCompare(String(right.id)))
|
|
294
|
+
const changed = (result: DatasetMergeCommitResult) => ({
|
|
295
|
+
outcome: result.outcome,
|
|
296
|
+
rowsChanged: result.version?.rowsChanged,
|
|
297
|
+
})
|
|
298
|
+
|
|
299
|
+
await merge(storage, [upsert(10), upsert(1, "Lin", "7")])
|
|
300
|
+
|
|
301
|
+
// A re-read at 12 returns the same content: the row keeps 10, the ordering moves to 12.
|
|
302
|
+
expect(changed(await merge(storage, [upsert(12)]))).toEqual({
|
|
303
|
+
outcome: "created",
|
|
304
|
+
rowsChanged: false,
|
|
305
|
+
})
|
|
306
|
+
expect(await stored()).toEqual([
|
|
307
|
+
{ id: "42", revision: "10", name: "Sam" },
|
|
308
|
+
{ id: "7", revision: "1", name: "Lin" },
|
|
309
|
+
])
|
|
310
|
+
|
|
311
|
+
// A late delivery read at 11 stays ignored, and 12 compares with what was delivered at 12.
|
|
312
|
+
expect((await merge(storage, [upsert(11, "Late")])).outcome).toBe("unchanged")
|
|
313
|
+
expect((await merge(storage, [upsert(12)])).outcome).toBe("unchanged")
|
|
314
|
+
await expect(merge(storage, [upsert(12, "Tie")])).rejects.toThrow("conflicting content")
|
|
315
|
+
|
|
316
|
+
// In one batch, only the row whose content changed is rewritten.
|
|
317
|
+
expect(changed(await merge(storage, [upsert(13), upsert(2, "Grace", "7")]))).toEqual({
|
|
318
|
+
outcome: "created",
|
|
319
|
+
rowsChanged: true,
|
|
320
|
+
})
|
|
321
|
+
expect(await stored()).toEqual([
|
|
322
|
+
{ id: "42", revision: "10", name: "Sam" },
|
|
323
|
+
{ id: "7", revision: "2", name: "Grace" },
|
|
324
|
+
])
|
|
325
|
+
|
|
326
|
+
// Any other difference rewrites the whole row, its sequence included.
|
|
327
|
+
expect(changed(await merge(storage, [upsert(14, "Ada")]))).toEqual({
|
|
328
|
+
outcome: "created",
|
|
329
|
+
rowsChanged: true,
|
|
330
|
+
})
|
|
331
|
+
expect((await stored())[0]).toEqual({ id: "42", revision: "14", name: "Ada" })
|
|
332
|
+
}))
|
|
333
|
+
|
|
253
334
|
test("compares canonical content across JSON order and nullable representations", () =>
|
|
254
335
|
withStorage(async (storage) => {
|
|
255
336
|
await merge(storage, [
|
|
@@ -121,7 +121,8 @@ export function runLakeChangesContractSuite<T extends LakeStorage>(
|
|
|
121
121
|
})
|
|
122
122
|
test("refuses blank identities and invalid column requests", async () => {
|
|
123
123
|
const first = await write([row(" ", "one")])
|
|
124
|
-
|
|
124
|
+
const second = await write([row(" ", "two")])
|
|
125
|
+
expect(await read(first, second)).toBeNull()
|
|
125
126
|
await expect(read(first, first, [])).rejects.toThrow("distinct columns")
|
|
126
127
|
await expect(read(first, first, ["missing"])).rejects.toThrow("distinct columns")
|
|
127
128
|
})
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { describe, expect, test } from "bun:test"
|
|
2
|
+
import { randomUUID } from "node:crypto"
|
|
2
3
|
import type { FileRef } from "../blob-storage"
|
|
3
4
|
import { col, type DatasetDefinition, defineDataset } from "../datasets"
|
|
4
5
|
import { LakeStorageError } from "../lake-storage/errors"
|
|
@@ -7,6 +8,7 @@ import type {
|
|
|
7
8
|
DatasetColumnRef,
|
|
8
9
|
DatasetProducer,
|
|
9
10
|
DatasetRow,
|
|
11
|
+
DatasetVersion,
|
|
10
12
|
DatasetWriteCommitResult,
|
|
11
13
|
LakeStorage,
|
|
12
14
|
} from "../lake-storage/types"
|
|
@@ -1178,6 +1180,116 @@ export function runLakeStorageContractSuite<TStorage extends LakeStorage>(
|
|
|
1178
1180
|
})
|
|
1179
1181
|
}))
|
|
1180
1182
|
})
|
|
1183
|
+
|
|
1184
|
+
describe("what a version changed", () => {
|
|
1185
|
+
const changed = (version: DatasetVersion | null | undefined) => ({
|
|
1186
|
+
rowsChanged: version?.rowsChanged,
|
|
1187
|
+
lineageChanged: version?.lineageChanged,
|
|
1188
|
+
})
|
|
1189
|
+
|
|
1190
|
+
test("records whether a version changed rows or lineage, across reopening", async () => {
|
|
1191
|
+
// Red check: store `rowsChanged: true` on every version the provider creates.
|
|
1192
|
+
let storage = await options.createStorage()
|
|
1193
|
+
try {
|
|
1194
|
+
await storage.createDataset(writeDataset)
|
|
1195
|
+
await storage.createDataset(definitionDataset)
|
|
1196
|
+
|
|
1197
|
+
const inputVersion = async () => {
|
|
1198
|
+
const session = await storage.beginWrite({ dataset: definitionDataset })
|
|
1199
|
+
await session.writeRows([{ orderId: randomUUID(), customerName: "Input" }])
|
|
1200
|
+
const version = await session.commit()
|
|
1201
|
+
return { datasetId: definitionDataset.id, versionId: version.versionId }
|
|
1202
|
+
}
|
|
1203
|
+
|
|
1204
|
+
const rows = [{ orderId: "ord_1", customerName: "Ada" }]
|
|
1205
|
+
const commit = async (
|
|
1206
|
+
input: Pick<BeginDatasetWriteInput, "producer" | "lineage" | "mode" | "inputs">,
|
|
1207
|
+
written: readonly DatasetRow[] = rows
|
|
1208
|
+
) => {
|
|
1209
|
+
const session = await storage.beginWrite({ dataset: writeDataset, ...input })
|
|
1210
|
+
await session.writeRows(written)
|
|
1211
|
+
const version = await session.commit()
|
|
1212
|
+
expect(version.outcome).toBe("created")
|
|
1213
|
+
return version
|
|
1214
|
+
}
|
|
1215
|
+
|
|
1216
|
+
const first = await commit({ inputs: [await inputVersion()] })
|
|
1217
|
+
expect(changed(first)).toEqual({ rowsChanged: true, lineageChanged: true })
|
|
1218
|
+
|
|
1219
|
+
// Identical rows computed from a new input version.
|
|
1220
|
+
const provenanceOnly = await commit({ inputs: [await inputVersion()] })
|
|
1221
|
+
expect(changed(provenanceOnly)).toEqual({ rowsChanged: false, lineageChanged: false })
|
|
1222
|
+
|
|
1223
|
+
// Identical rows that come from other columns.
|
|
1224
|
+
const lineageOnly = await commit({ producer: pipeline, lineage: copied })
|
|
1225
|
+
expect(changed(lineageOnly)).toEqual({ rowsChanged: false, lineageChanged: true })
|
|
1226
|
+
|
|
1227
|
+
const rowsOnly = await commit({ producer: pipeline, lineage: copied }, [
|
|
1228
|
+
{ orderId: "ord_2", customerName: "Grace" },
|
|
1229
|
+
])
|
|
1230
|
+
expect(changed(rowsOnly)).toEqual({ rowsChanged: true, lineageChanged: false })
|
|
1231
|
+
|
|
1232
|
+
// An append of no rows from a new input version.
|
|
1233
|
+
const emptyAppend = await commit(
|
|
1234
|
+
{ producer: pipeline, lineage: copied, mode: "append", inputs: [await inputVersion()] },
|
|
1235
|
+
[]
|
|
1236
|
+
)
|
|
1237
|
+
expect(changed(emptyAppend)).toEqual({ rowsChanged: false, lineageChanged: false })
|
|
1238
|
+
|
|
1239
|
+
const append = await commit({ producer: pipeline, lineage: copied, mode: "append" }, [
|
|
1240
|
+
{ orderId: "ord_3", customerName: "Lin" },
|
|
1241
|
+
])
|
|
1242
|
+
expect(changed(append)).toEqual({ rowsChanged: true, lineageChanged: false })
|
|
1243
|
+
|
|
1244
|
+
if (options.reopen) storage = await options.reopen(storage)
|
|
1245
|
+
|
|
1246
|
+
const committed = [first, provenanceOnly, lineageOnly, rowsOnly, emptyAppend, append]
|
|
1247
|
+
const expected = Object.fromEntries(committed.map((v) => [v.versionId, changed(v)]))
|
|
1248
|
+
const listed = await storage.listVersions(writeDataset.id)
|
|
1249
|
+
expect(Object.fromEntries(listed.map((v) => [v.versionId, changed(v)]))).toEqual(expected)
|
|
1250
|
+
|
|
1251
|
+
for (const version of committed) {
|
|
1252
|
+
expect(changed(await storage.getVersion(writeDataset.id, version.versionId))).toEqual(
|
|
1253
|
+
changed(version)
|
|
1254
|
+
)
|
|
1255
|
+
}
|
|
1256
|
+
expect(changed(await storage.getLatestVersion(writeDataset.id))).toEqual(changed(append))
|
|
1257
|
+
} finally {
|
|
1258
|
+
await options.teardown?.(storage)
|
|
1259
|
+
}
|
|
1260
|
+
})
|
|
1261
|
+
|
|
1262
|
+
test("a dataset's first version changes rows, even empty", () =>
|
|
1263
|
+
withStorage(async (storage) => {
|
|
1264
|
+
await storage.createDataset(writeDataset)
|
|
1265
|
+
const session = await storage.beginWrite({ dataset: writeDataset })
|
|
1266
|
+
const first = await session.commit()
|
|
1267
|
+
|
|
1268
|
+
expect(changed(first)).toEqual({ rowsChanged: true, lineageChanged: true })
|
|
1269
|
+
}))
|
|
1270
|
+
|
|
1271
|
+
test("a schema change changes rows", () =>
|
|
1272
|
+
withStorage(async (storage) => {
|
|
1273
|
+
if (schemaEvolution === "strict") return
|
|
1274
|
+
|
|
1275
|
+
const initial = defineDataset("contract.changes.schema_evolution", {
|
|
1276
|
+
schema: [col("invoiceId", "string")],
|
|
1277
|
+
})
|
|
1278
|
+
const widened = defineDataset("contract.changes.schema_evolution", {
|
|
1279
|
+
schema: [col("invoiceId", "string"), col("currency", "string", { nullable: true })],
|
|
1280
|
+
})
|
|
1281
|
+
|
|
1282
|
+
await storage.createDataset(initial)
|
|
1283
|
+
const session = await storage.beginWrite({ dataset: initial })
|
|
1284
|
+
await session.writeRows([{ invoiceId: "inv_1" }])
|
|
1285
|
+
await session.commit()
|
|
1286
|
+
|
|
1287
|
+
await storage.createDataset(widened)
|
|
1288
|
+
const [schemaVersion] = await storage.listVersions(initial.id, 1)
|
|
1289
|
+
expect(schemaVersion?.mode).toBe("schema")
|
|
1290
|
+
expect(changed(schemaVersion)).toEqual({ rowsChanged: true, lineageChanged: true })
|
|
1291
|
+
}))
|
|
1292
|
+
})
|
|
1181
1293
|
})
|
|
1182
1294
|
}
|
|
1183
1295
|
|
|
@@ -6,10 +6,14 @@ import {
|
|
|
6
6
|
type ObjectQueryPredicate,
|
|
7
7
|
validateObjectQuery,
|
|
8
8
|
} from "../objects/query"
|
|
9
|
-
import {
|
|
9
|
+
import { bindCurrentUserPredicate } from "../objects/query/current-user"
|
|
10
|
+
import { defineObjectType, link, OntologyRegistry, prop, ref } from "../ontology"
|
|
11
|
+
import type { UserRef } from "../ontology/user-ref"
|
|
12
|
+
import { viewConditionReadCondition } from "../security/visibility-keys"
|
|
10
13
|
import { migrateStorage } from "../storage/migrations"
|
|
11
14
|
import {
|
|
12
15
|
compileConditionalObjectReadScope,
|
|
16
|
+
type ExpandedLinkValue,
|
|
13
17
|
linkBatchKey,
|
|
14
18
|
type ObjectReadCondition,
|
|
15
19
|
type ObjectReadScopeFactory,
|
|
@@ -57,10 +61,30 @@ const Customer = defineObjectType({
|
|
|
57
61
|
id: "ConditionCustomer",
|
|
58
62
|
name: "Condition Customer",
|
|
59
63
|
properties: [prop("id", "string", { required: true, primary: true }), prop("name", "string")],
|
|
60
|
-
links: [link("invoices", Invoice)],
|
|
64
|
+
links: [link("invoices", Invoice), link("primaryInvoice", Invoice, { cardinality: "one" })],
|
|
61
65
|
})
|
|
62
66
|
|
|
63
|
-
|
|
67
|
+
/** Who sees a ticket depends on its reader: the conditions compare `currentUser()`. */
|
|
68
|
+
const Ticket = defineObjectType({
|
|
69
|
+
id: "ConditionTicket",
|
|
70
|
+
name: "Condition Ticket",
|
|
71
|
+
properties: [
|
|
72
|
+
prop("id", "string", {
|
|
73
|
+
required: true,
|
|
74
|
+
primary: true,
|
|
75
|
+
query: { searchable: true, sortable: true },
|
|
76
|
+
}),
|
|
77
|
+
prop("status", "string", { query: { searchable: true, filterable: true } }),
|
|
78
|
+
prop("owner", ref.user(), { nullable: true, query: { searchable: true, filterable: true } }),
|
|
79
|
+
prop(
|
|
80
|
+
"watchers",
|
|
81
|
+
{ type: "array", items: ref.user() },
|
|
82
|
+
{ nullable: true, query: { searchable: true, filterable: true } }
|
|
83
|
+
),
|
|
84
|
+
],
|
|
85
|
+
})
|
|
86
|
+
|
|
87
|
+
const ontology = new OntologyRegistry({ sources: [Invoice, CreditNote, Customer, Ticket] })
|
|
64
88
|
|
|
65
89
|
/**
|
|
66
90
|
* Portable conditional-read contract shared by every storage provider.
|
|
@@ -393,6 +417,134 @@ export function runConditionalObjectReadScopeContractSuite<TStorage extends Stor
|
|
|
393
417
|
})
|
|
394
418
|
})
|
|
395
419
|
|
|
420
|
+
test("never expands through a hidden object", async () => {
|
|
421
|
+
await withHarness(async ({ harness }) => {
|
|
422
|
+
// Without conditions every edge is reached, so each expectation of the conditioned reader
|
|
423
|
+
// can only hold if the hidden draft and the links touching it stay out.
|
|
424
|
+
const unconditioned = createReader(harness.objectReadScopeFactory, [])
|
|
425
|
+
const conditioned = createReader(harness.objectReadScopeFactory, [noDrafts(Invoice.id)])
|
|
426
|
+
|
|
427
|
+
const customers = async (reader: ObjectReadStorage) => {
|
|
428
|
+
const [customer] = await queryRows(reader, {
|
|
429
|
+
kind: "expand",
|
|
430
|
+
input: {
|
|
431
|
+
kind: "limit",
|
|
432
|
+
limit: 10,
|
|
433
|
+
input: { kind: "start", objectTypeId: Customer.id },
|
|
434
|
+
},
|
|
435
|
+
expansions: [
|
|
436
|
+
{ linkId: "primaryInvoice", direction: "outgoing" },
|
|
437
|
+
{
|
|
438
|
+
linkId: "invoices",
|
|
439
|
+
direction: "outgoing",
|
|
440
|
+
expand: [{ linkId: "related", direction: "outgoing" }],
|
|
441
|
+
},
|
|
442
|
+
],
|
|
443
|
+
})
|
|
444
|
+
|
|
445
|
+
return {
|
|
446
|
+
primaryInvoice: linkedIds(customer?.links?.primaryInvoice),
|
|
447
|
+
invoices: Object.fromEntries(
|
|
448
|
+
linkedRows(customer?.links?.invoices).map((row) => [
|
|
449
|
+
row.primaryId,
|
|
450
|
+
linkedIds(row.links?.related),
|
|
451
|
+
])
|
|
452
|
+
),
|
|
453
|
+
}
|
|
454
|
+
}
|
|
455
|
+
|
|
456
|
+
expect(await customers(unconditioned)).toEqual({
|
|
457
|
+
primaryInvoice: ["inv-2"],
|
|
458
|
+
invoices: { "inv-1": ["inv-2", "inv-3"], "inv-2": ["inv-1"], "inv-3": [] },
|
|
459
|
+
})
|
|
460
|
+
// The hidden draft is neither a neighbour nor the middle of a nested expansion.
|
|
461
|
+
expect(await customers(conditioned)).toEqual({
|
|
462
|
+
primaryInvoice: [],
|
|
463
|
+
invoices: { "inv-1": ["inv-3"], "inv-3": [] },
|
|
464
|
+
})
|
|
465
|
+
|
|
466
|
+
const relatedFrom = async (reader: ObjectReadStorage) => {
|
|
467
|
+
const invoices = await queryRows(reader, {
|
|
468
|
+
kind: "expand",
|
|
469
|
+
input: {
|
|
470
|
+
kind: "limit",
|
|
471
|
+
limit: 10,
|
|
472
|
+
input: sorted({ kind: "start", objectTypeId: Invoice.id }, "amount"),
|
|
473
|
+
},
|
|
474
|
+
expansions: [
|
|
475
|
+
{ linkId: "related", direction: "incoming", sourceObjectTypeId: Invoice.id },
|
|
476
|
+
],
|
|
477
|
+
})
|
|
478
|
+
|
|
479
|
+
return invoices.map((row) => linkedIds(row.links?.related))
|
|
480
|
+
}
|
|
481
|
+
|
|
482
|
+
expect(await relatedFrom(unconditioned)).toEqual([["inv-2"], ["inv-1"], ["inv-1"]])
|
|
483
|
+
expect(await relatedFrom(conditioned)).toEqual([[], ["inv-1"]])
|
|
484
|
+
})
|
|
485
|
+
})
|
|
486
|
+
|
|
487
|
+
test("never traverses through a hidden object", async () => {
|
|
488
|
+
await withHarness(async ({ harness }) => {
|
|
489
|
+
// As above, the unconditioned reader shows what each traversal reaches through the draft.
|
|
490
|
+
const unconditioned = createReader(harness.objectReadScopeFactory, [])
|
|
491
|
+
const conditioned = createReader(harness.objectReadScopeFactory, [noDrafts(Invoice.id)])
|
|
492
|
+
|
|
493
|
+
const reached = async (reader: ObjectReadStorage, query: ObjectQuery) => {
|
|
494
|
+
const rows = await queryRows(reader, query)
|
|
495
|
+
return rows.map((row) => row.primaryId).sort()
|
|
496
|
+
}
|
|
497
|
+
const relatedOf = (input: ObjectQuery): ObjectQuery => ({
|
|
498
|
+
kind: "traverse",
|
|
499
|
+
direction: "outgoing",
|
|
500
|
+
linkId: "related",
|
|
501
|
+
input,
|
|
502
|
+
})
|
|
503
|
+
const refs = (...primaryIds: string[]): ObjectQuery => ({
|
|
504
|
+
kind: "refs",
|
|
505
|
+
refs: primaryIds.map((primaryId) => ({ objectTypeId: Invoice.id, primaryId })),
|
|
506
|
+
})
|
|
507
|
+
|
|
508
|
+
const twoHops = relatedOf({
|
|
509
|
+
kind: "traverse",
|
|
510
|
+
direction: "outgoing",
|
|
511
|
+
linkId: "invoices",
|
|
512
|
+
input: { kind: "start", objectTypeId: Customer.id },
|
|
513
|
+
})
|
|
514
|
+
expect(await reached(unconditioned, twoHops)).toEqual(["inv-1", "inv-2", "inv-3"])
|
|
515
|
+
expect(await reached(conditioned, twoHops)).toEqual(["inv-3"])
|
|
516
|
+
|
|
517
|
+
const fromRefs = relatedOf(refs("inv-1", "inv-2"))
|
|
518
|
+
expect(await reached(unconditioned, fromRefs)).toEqual(["inv-1", "inv-2", "inv-3"])
|
|
519
|
+
expect(await reached(conditioned, fromRefs)).toEqual(["inv-3"])
|
|
520
|
+
|
|
521
|
+
const fromSet = relatedOf({
|
|
522
|
+
kind: "set",
|
|
523
|
+
op: "union",
|
|
524
|
+
inputs: [refs("inv-2"), refs("inv-3")],
|
|
525
|
+
})
|
|
526
|
+
expect(await reached(unconditioned, fromSet)).toEqual(["inv-1"])
|
|
527
|
+
expect(await reached(conditioned, fromSet)).toEqual([])
|
|
528
|
+
|
|
529
|
+
// From the target side, the hidden draft is the source of a link to a visible invoice.
|
|
530
|
+
const sourcesOf: ObjectQuery = {
|
|
531
|
+
kind: "traverse",
|
|
532
|
+
direction: "incoming",
|
|
533
|
+
linkId: "related",
|
|
534
|
+
sourceObjectTypeId: Invoice.id,
|
|
535
|
+
input: refs("inv-1", "inv-3"),
|
|
536
|
+
}
|
|
537
|
+
expect(await reached(unconditioned, sourcesOf)).toEqual(["inv-1", "inv-2"])
|
|
538
|
+
expect(await reached(conditioned, sourcesOf)).toEqual(["inv-1"])
|
|
539
|
+
expect(await unconditioned.countObjects?.({ projectId, query: sourcesOf })).toEqual({
|
|
540
|
+
count: 2,
|
|
541
|
+
})
|
|
542
|
+
expect(await conditioned.countObjects?.({ projectId, query: sourcesOf })).toEqual({
|
|
543
|
+
count: 1,
|
|
544
|
+
})
|
|
545
|
+
})
|
|
546
|
+
})
|
|
547
|
+
|
|
396
548
|
test("applies a condition to its concrete type only", async () => {
|
|
397
549
|
await withHarness(async ({ harness }) => {
|
|
398
550
|
const invoicesOnly = createReader(harness.objectReadScopeFactory, [noDrafts(Invoice.id)])
|
|
@@ -445,6 +597,84 @@ export function runConditionalObjectReadScopeContractSuite<TStorage extends Stor
|
|
|
445
597
|
})
|
|
446
598
|
})
|
|
447
599
|
|
|
600
|
+
// A provider may filter a member's reads on the keys of its conditions instead of their
|
|
601
|
+
// predicate. Both must show each reader the same objects, whatever its user's id.
|
|
602
|
+
test("shows a reader through its conditions' keys exactly what their predicate shows", async () => {
|
|
603
|
+
await withHarness(async ({ harness, fixture }) => {
|
|
604
|
+
const ids = ["usr_1", 'a"b', "a\\b", 'a", "b', "*", "u:usr_1"]
|
|
605
|
+
const users = ids.map((id): UserRef => ({ type: "user", id }))
|
|
606
|
+
|
|
607
|
+
const auth = harness.storage.auth
|
|
608
|
+
if (!auth) throw new Error("The conditional read contract requires auth storage.")
|
|
609
|
+
for (const [index, id] of ids.entries()) {
|
|
610
|
+
await auth.users.create({ projectId, id, email: `reader-${index}@example.com` })
|
|
611
|
+
}
|
|
612
|
+
|
|
613
|
+
await fixture.seed({
|
|
614
|
+
objects: users.flatMap((user, index) => [
|
|
615
|
+
object(Ticket.id, `t-${index}-owned`, {
|
|
616
|
+
id: `t-${index}-owned`,
|
|
617
|
+
status: "open",
|
|
618
|
+
owner: user,
|
|
619
|
+
}),
|
|
620
|
+
object(Ticket.id, `t-${index}-watched`, {
|
|
621
|
+
id: `t-${index}-watched`,
|
|
622
|
+
status: index % 2 === 0 ? "open" : "closed",
|
|
623
|
+
owner: users[(index + 1) % users.length]!,
|
|
624
|
+
watchers: [user, users[(index + 2) % users.length]!],
|
|
625
|
+
}),
|
|
626
|
+
]),
|
|
627
|
+
links: [],
|
|
628
|
+
})
|
|
629
|
+
|
|
630
|
+
const me = { type: "currentUser" }
|
|
631
|
+
const conditions: ObjectQueryPredicate[] = [
|
|
632
|
+
{ op: "eq", propertyId: "owner", value: me },
|
|
633
|
+
{ op: "contains", propertyId: "watchers", value: me },
|
|
634
|
+
{
|
|
635
|
+
op: "or",
|
|
636
|
+
items: [
|
|
637
|
+
{ op: "eq", propertyId: "status", value: "closed" },
|
|
638
|
+
{ op: "in", propertyId: "owner", values: [me, users[0]!] },
|
|
639
|
+
],
|
|
640
|
+
},
|
|
641
|
+
{
|
|
642
|
+
op: "and",
|
|
643
|
+
items: [
|
|
644
|
+
{ op: "eq", propertyId: "status", value: "open" },
|
|
645
|
+
{ op: "contains", propertyId: "watchers", value: me },
|
|
646
|
+
],
|
|
647
|
+
},
|
|
648
|
+
// No keys: read through its predicate beside the keys of the others.
|
|
649
|
+
{ op: "neq", propertyId: "owner", value: me },
|
|
650
|
+
]
|
|
651
|
+
|
|
652
|
+
const visible = async (condition: ObjectReadCondition) => {
|
|
653
|
+
const reader = createReader(harness.objectReadScopeFactory, [condition])
|
|
654
|
+
const rows = await queryRows(reader, {
|
|
655
|
+
kind: "limit",
|
|
656
|
+
limit: 100,
|
|
657
|
+
input: sorted({ kind: "start", objectTypeId: Ticket.id }, "id"),
|
|
658
|
+
})
|
|
659
|
+
return rows.map((row) => row.primaryId)
|
|
660
|
+
}
|
|
661
|
+
|
|
662
|
+
for (const [index, condition] of conditions.entries()) {
|
|
663
|
+
const predicates = [ticketCondition(condition), ticketCondition(conditions[0]!)]
|
|
664
|
+
for (const user of [undefined, ...users]) {
|
|
665
|
+
const keyed = viewConditionReadCondition(Ticket.id, predicates, user)
|
|
666
|
+
const bound = bindCurrentUserPredicate({ op: "or", items: predicates }, user)
|
|
667
|
+
|
|
668
|
+
expect({ index, user, ids: await visible(keyed) }).toEqual({
|
|
669
|
+
index,
|
|
670
|
+
user,
|
|
671
|
+
ids: await visible({ objectTypeId: Ticket.id, predicate: bound }),
|
|
672
|
+
})
|
|
673
|
+
}
|
|
674
|
+
}
|
|
675
|
+
})
|
|
676
|
+
})
|
|
677
|
+
|
|
448
678
|
test("never reads another project's objects or links", async () => {
|
|
449
679
|
await withHarness(async ({ harness }) => {
|
|
450
680
|
await migrateStorage(harness.storage, { projectId: otherProjectId, ontology })
|
|
@@ -555,7 +785,10 @@ function createReader(
|
|
|
555
785
|
})
|
|
556
786
|
}
|
|
557
787
|
|
|
558
|
-
/**
|
|
788
|
+
/**
|
|
789
|
+
* `status neq "draft"`, validated like a grant's condition so `scalarKind` is resolved, and read the
|
|
790
|
+
* way a member reads it: with its keys, which a provider may filter on instead of the predicate.
|
|
791
|
+
*/
|
|
559
792
|
function noDrafts(objectTypeId: string): ObjectReadCondition {
|
|
560
793
|
const predicate: ObjectQueryPredicate = { op: "neq", propertyId: "status", value: "draft" }
|
|
561
794
|
const { query } = validateObjectQuery(
|
|
@@ -564,7 +797,35 @@ function noDrafts(objectTypeId: string): ObjectReadCondition {
|
|
|
564
797
|
)
|
|
565
798
|
if (query.kind !== "filter") throw new Error("expected a validated filter")
|
|
566
799
|
|
|
567
|
-
return
|
|
800
|
+
return viewConditionReadCondition(objectTypeId, [query.predicate], undefined)
|
|
801
|
+
}
|
|
802
|
+
|
|
803
|
+
/** A ticket condition as a grant's validation returns it, `currentUser()` left unbound. */
|
|
804
|
+
function ticketCondition(predicate: ObjectQueryPredicate): ObjectQueryPredicate {
|
|
805
|
+
const { query } = validateObjectQuery(
|
|
806
|
+
{ kind: "filter", input: { kind: "start", objectTypeId: Ticket.id }, predicate },
|
|
807
|
+
{ ontology }
|
|
808
|
+
)
|
|
809
|
+
if (query.kind !== "filter") throw new Error("expected a validated filter")
|
|
810
|
+
return query.predicate
|
|
811
|
+
}
|
|
812
|
+
|
|
813
|
+
/** Run a query as the executor does, so a provider pushes down what it can. */
|
|
814
|
+
async function queryRows(reader: ObjectReadStorage, query: ObjectQuery) {
|
|
815
|
+
const result = await executeObjectQuery({ projectId, query }, { ontology, storage: reader })
|
|
816
|
+
return result.objects
|
|
817
|
+
}
|
|
818
|
+
|
|
819
|
+
/** An expanded link's neighbours, whatever its cardinality. */
|
|
820
|
+
function linkedRows(value: ExpandedLinkValue | undefined) {
|
|
821
|
+
if (Array.isArray(value)) return value
|
|
822
|
+
return value ? [value] : []
|
|
823
|
+
}
|
|
824
|
+
|
|
825
|
+
function linkedIds(value: ExpandedLinkValue | undefined): string[] {
|
|
826
|
+
return linkedRows(value)
|
|
827
|
+
.map((row) => row.primaryId)
|
|
828
|
+
.sort()
|
|
568
829
|
}
|
|
569
830
|
|
|
570
831
|
function sorted(
|
|
@@ -595,6 +856,7 @@ async function seed(fixture: MaterializerTestFixture): Promise<void> {
|
|
|
595
856
|
linkRow(Customer.id, "cust-1", "invoices", Invoice.id, "inv-1"),
|
|
596
857
|
linkRow(Customer.id, "cust-1", "invoices", Invoice.id, "inv-2"),
|
|
597
858
|
linkRow(Customer.id, "cust-1", "invoices", Invoice.id, "inv-3"),
|
|
859
|
+
linkRow(Customer.id, "cust-1", "primaryInvoice", Invoice.id, "inv-2"),
|
|
598
860
|
linkRow(Invoice.id, "inv-1", "related", Invoice.id, "inv-2"),
|
|
599
861
|
linkRow(Invoice.id, "inv-2", "related", Invoice.id, "inv-1"),
|
|
600
862
|
linkRow(Invoice.id, "inv-1", "related", Invoice.id, "inv-3"),
|
|
@@ -689,6 +689,81 @@ export function runObjectQueryProviderContractSuite<TStorage extends Storage>(
|
|
|
689
689
|
})
|
|
690
690
|
})
|
|
691
691
|
|
|
692
|
+
// A guard on the tie order: break ties in identity order whatever the direction, and each
|
|
693
|
+
// descending list below stops being the ascending one backwards.
|
|
694
|
+
test("lists a descending sort as the ascending one backwards, ties included", async () => {
|
|
695
|
+
await withStorage(async ({ objects: storage, fixture }) => {
|
|
696
|
+
const labelCodes = ["b", null, "a", "b", "a", null, "b"]
|
|
697
|
+
const deviceNames = ["dimmer", "sensor", "dimmer", "sensor"]
|
|
698
|
+
await fixture.seed({
|
|
699
|
+
objects: [
|
|
700
|
+
...labelCodes.map((code, index) =>
|
|
701
|
+
objectSeed(Label.id, `tie-${index}`, { id: `tie-${index}`, code })
|
|
702
|
+
),
|
|
703
|
+
objectSeed(Room.id, "room-ties", { id: "room-ties" }),
|
|
704
|
+
...deviceNames.map((name, index) =>
|
|
705
|
+
objectSeed(Device.id, `device-tie-${index}`, { id: `device-tie-${index}`, name })
|
|
706
|
+
),
|
|
707
|
+
],
|
|
708
|
+
links: deviceNames.map((_, index) =>
|
|
709
|
+
linkSeed(Room.id, "room-ties", "hasDevice", Device.id, `device-tie-${index}`)
|
|
710
|
+
),
|
|
711
|
+
})
|
|
712
|
+
|
|
713
|
+
const run = (query: ObjectQuery) =>
|
|
714
|
+
executeObjectQuery(
|
|
715
|
+
{ projectId, query },
|
|
716
|
+
{ ontology: objectQueryContractOntology, storage }
|
|
717
|
+
)
|
|
718
|
+
const byCode = (direction: "asc" | "desc"): ObjectQuery => ({
|
|
719
|
+
kind: "sort",
|
|
720
|
+
fields: [{ kind: "property", propertyId: "code", direction }],
|
|
721
|
+
input: { kind: "start", objectTypeId: Label.id },
|
|
722
|
+
})
|
|
723
|
+
|
|
724
|
+
const ascending = ids(await run(byCode("asc")))
|
|
725
|
+
const descending = ids(await run(byCode("desc")))
|
|
726
|
+
|
|
727
|
+
// Null values sort last in both directions, so each part is reversed on its own.
|
|
728
|
+
const valued = ascending.slice(0, 5)
|
|
729
|
+
const nulls = ascending.slice(5)
|
|
730
|
+
expect(descending).toEqual([...valued.reverse(), ...nulls.reverse()])
|
|
731
|
+
|
|
732
|
+
const paged: string[] = []
|
|
733
|
+
let pageToken: string | undefined
|
|
734
|
+
do {
|
|
735
|
+
const page = await run({ kind: "page", pageSize: 2, pageToken, input: byCode("desc") })
|
|
736
|
+
paged.push(...ids(page))
|
|
737
|
+
pageToken = page.nextPageToken
|
|
738
|
+
} while (pageToken)
|
|
739
|
+
|
|
740
|
+
expect(paged).toEqual(descending)
|
|
741
|
+
|
|
742
|
+
// A parent's linked objects tie the same way.
|
|
743
|
+
const devices = async (direction: "asc" | "desc") => {
|
|
744
|
+
const result = await run({
|
|
745
|
+
kind: "expand",
|
|
746
|
+
expansions: [
|
|
747
|
+
{
|
|
748
|
+
linkId: "hasDevice",
|
|
749
|
+
direction: "outgoing",
|
|
750
|
+
limit: deviceNames.length,
|
|
751
|
+
orderBy: [{ kind: "property", propertyId: "name", direction }],
|
|
752
|
+
},
|
|
753
|
+
],
|
|
754
|
+
input: { kind: "limit", limit: 10, input: { kind: "start", objectTypeId: Room.id } },
|
|
755
|
+
})
|
|
756
|
+
const room = result.objects.find((row) => row.primaryId === "room-ties")
|
|
757
|
+
const linked = room?.links?.hasDevice
|
|
758
|
+
return Array.isArray(linked) ? linked.map((row) => row.primaryId) : []
|
|
759
|
+
}
|
|
760
|
+
|
|
761
|
+
const ascendingDevices = await devices("asc")
|
|
762
|
+
expect(ascendingDevices).toHaveLength(deviceNames.length)
|
|
763
|
+
expect(await devices("desc")).toEqual([...ascendingDevices].reverse())
|
|
764
|
+
})
|
|
765
|
+
})
|
|
766
|
+
|
|
692
767
|
test("keeps page tokens stable when projection hides sorted cursor fields", async () => {
|
|
693
768
|
await withStorage(async ({ objects: storage, fixture }) => {
|
|
694
769
|
await seedObjectQueryContractData(fixture)
|
package/src/workers/index.ts
CHANGED
|
@@ -3,4 +3,5 @@ export type { QueueDelivery, QueueDeliveryState, QueueSettlementResult } from ".
|
|
|
3
3
|
export { QueueDeliveryLeaseLostError } from "./queue-delivery"
|
|
4
4
|
export type { QueueWorkerConfig, QueueWorkerFailureDecision } from "./queue-worker"
|
|
5
5
|
export { isAbortError, QueueWorker } from "./queue-worker"
|
|
6
|
+
export { retryUnstartedRun } from "./unstarted-run"
|
|
6
7
|
export { Worker } from "./worker"
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { QueueWorkerFailureDecision } from "./queue-worker"
|
|
2
|
+
|
|
3
|
+
const UNSTARTED_RUN_ATTEMPTS = 3
|
|
4
|
+
const UNSTARTED_RUN_RETRY_INITIAL_DELAY_MS = 250
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* A run that has not started has committed nothing, so a job that fails before starting it is
|
|
8
|
+
* retried with a short doubling backoff. Returns `undefined` once its attempts are spent: the
|
|
9
|
+
* worker then fails the run, so that later triggers stop joining it.
|
|
10
|
+
*/
|
|
11
|
+
export function retryUnstartedRun(
|
|
12
|
+
attempt: number
|
|
13
|
+
): Extract<QueueWorkerFailureDecision, { readonly kind: "retry" }> | undefined {
|
|
14
|
+
if (attempt >= UNSTARTED_RUN_ATTEMPTS) return undefined
|
|
15
|
+
|
|
16
|
+
const delayMs = UNSTARTED_RUN_RETRY_INITIAL_DELAY_MS * 2 ** (Math.max(attempt, 1) - 1)
|
|
17
|
+
return { kind: "retry", availableAt: new Date(Date.now() + delayMs).toISOString() }
|
|
18
|
+
}
|