@diffra-ai/durable 0.0.0-stage → 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/CHANGELOG.md +440 -0
- package/README.md +1153 -2
- package/dist/codemode/codemode.d.ts +174 -0
- package/dist/codemode/codemode.d.ts.map +1 -0
- package/dist/codemode/codemode.js +884 -0
- package/dist/codemode/codemode.js.map +1 -0
- package/dist/codemode/describe.d.ts +38 -0
- package/dist/codemode/describe.d.ts.map +1 -0
- package/dist/codemode/describe.js +127 -0
- package/dist/codemode/describe.js.map +1 -0
- package/dist/codemode/index.d.ts +3 -0
- package/dist/codemode/index.d.ts.map +1 -0
- package/dist/codemode/index.js +3 -0
- package/dist/codemode/index.js.map +1 -0
- package/dist/codemode/models.d.ts +29 -0
- package/dist/codemode/models.d.ts.map +1 -0
- package/dist/codemode/models.js +242 -0
- package/dist/codemode/models.js.map +1 -0
- package/dist/codemode/output.d.ts +43 -0
- package/dist/codemode/output.d.ts.map +1 -0
- package/dist/codemode/output.js +168 -0
- package/dist/codemode/output.js.map +1 -0
- package/dist/documents.d.ts +66 -0
- package/dist/documents.d.ts.map +1 -0
- package/dist/documents.js +98 -0
- package/dist/documents.js.map +1 -0
- package/dist/entries.d.ts +31 -0
- package/dist/entries.d.ts.map +1 -0
- package/dist/entries.js +31 -0
- package/dist/entries.js.map +1 -0
- package/dist/env/decode.d.ts +16 -0
- package/dist/env/decode.d.ts.map +1 -0
- package/dist/env/decode.js +28 -0
- package/dist/env/decode.js.map +1 -0
- package/dist/env/index.d.ts +308 -0
- package/dist/env/index.d.ts.map +1 -0
- package/dist/env/index.js +49 -0
- package/dist/env/index.js.map +1 -0
- package/dist/env/line-scan.d.ts +13 -0
- package/dist/env/line-scan.d.ts.map +1 -0
- package/dist/env/line-scan.js +147 -0
- package/dist/env/line-scan.js.map +1 -0
- package/dist/env/node-watch.d.ts +29 -0
- package/dist/env/node-watch.d.ts.map +1 -0
- package/dist/env/node-watch.js +487 -0
- package/dist/env/node-watch.js.map +1 -0
- package/dist/env/node.d.ts +56 -0
- package/dist/env/node.d.ts.map +1 -0
- package/dist/env/node.js +1185 -0
- package/dist/env/node.js.map +1 -0
- package/dist/errors.d.ts +48 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +76 -0
- package/dist/errors.js.map +1 -0
- package/dist/harness/agent.d.ts +46 -0
- package/dist/harness/agent.d.ts.map +1 -0
- package/dist/harness/agent.js +334 -0
- package/dist/harness/agent.js.map +1 -0
- package/dist/harness/compaction.d.ts +68 -0
- package/dist/harness/compaction.d.ts.map +1 -0
- package/dist/harness/compaction.js +431 -0
- package/dist/harness/compaction.js.map +1 -0
- package/dist/harness/context.d.ts +84 -0
- package/dist/harness/context.d.ts.map +1 -0
- package/dist/harness/context.js +301 -0
- package/dist/harness/context.js.map +1 -0
- package/dist/harness/define.d.ts +25 -0
- package/dist/harness/define.d.ts.map +1 -0
- package/dist/harness/define.js +32 -0
- package/dist/harness/define.js.map +1 -0
- package/dist/harness/generation.d.ts +117 -0
- package/dist/harness/generation.d.ts.map +1 -0
- package/dist/harness/generation.js +1098 -0
- package/dist/harness/generation.js.map +1 -0
- package/dist/harness/harness.d.ts +22 -0
- package/dist/harness/harness.d.ts.map +1 -0
- package/dist/harness/harness.js +438 -0
- package/dist/harness/harness.js.map +1 -0
- package/dist/harness/inbox.d.ts +84 -0
- package/dist/harness/inbox.d.ts.map +1 -0
- package/dist/harness/inbox.js +135 -0
- package/dist/harness/inbox.js.map +1 -0
- package/dist/harness/json.d.ts +26 -0
- package/dist/harness/json.d.ts.map +1 -0
- package/dist/harness/json.js +51 -0
- package/dist/harness/json.js.map +1 -0
- package/dist/harness/live.d.ts +285 -0
- package/dist/harness/live.d.ts.map +1 -0
- package/dist/harness/live.js +257 -0
- package/dist/harness/live.js.map +1 -0
- package/dist/harness/parks.d.ts +23 -0
- package/dist/harness/parks.d.ts.map +1 -0
- package/dist/harness/parks.js +52 -0
- package/dist/harness/parks.js.map +1 -0
- package/dist/harness/partial-changes.d.ts +54 -0
- package/dist/harness/partial-changes.d.ts.map +1 -0
- package/dist/harness/partial-changes.js +163 -0
- package/dist/harness/partial-changes.js.map +1 -0
- package/dist/harness/prompt.d.ts +27 -0
- package/dist/harness/prompt.d.ts.map +1 -0
- package/dist/harness/prompt.js +131 -0
- package/dist/harness/prompt.js.map +1 -0
- package/dist/harness/provider.d.ts +16 -0
- package/dist/harness/provider.d.ts.map +1 -0
- package/dist/harness/provider.js +33 -0
- package/dist/harness/provider.js.map +1 -0
- package/dist/harness/registry-reader.d.ts +11 -0
- package/dist/harness/registry-reader.d.ts.map +1 -0
- package/dist/harness/registry-reader.js +25 -0
- package/dist/harness/registry-reader.js.map +1 -0
- package/dist/harness/registry.d.ts +6 -0
- package/dist/harness/registry.d.ts.map +1 -0
- package/dist/harness/registry.js +101 -0
- package/dist/harness/registry.js.map +1 -0
- package/dist/harness/scheduler.d.ts +195 -0
- package/dist/harness/scheduler.d.ts.map +1 -0
- package/dist/harness/scheduler.js +3073 -0
- package/dist/harness/scheduler.js.map +1 -0
- package/dist/harness/submissions.d.ts +44 -0
- package/dist/harness/submissions.d.ts.map +1 -0
- package/dist/harness/submissions.js +265 -0
- package/dist/harness/submissions.js.map +1 -0
- package/dist/harness/task-graph.d.ts +75 -0
- package/dist/harness/task-graph.d.ts.map +1 -0
- package/dist/harness/task-graph.js +224 -0
- package/dist/harness/task-graph.js.map +1 -0
- package/dist/harness/telemetry.d.ts +307 -0
- package/dist/harness/telemetry.d.ts.map +1 -0
- package/dist/harness/telemetry.js +140 -0
- package/dist/harness/telemetry.js.map +1 -0
- package/dist/harness/tool.d.ts +106 -0
- package/dist/harness/tool.d.ts.map +1 -0
- package/dist/harness/tool.js +1182 -0
- package/dist/harness/tool.js.map +1 -0
- package/dist/harness/transcript.d.ts +72 -0
- package/dist/harness/transcript.d.ts.map +1 -0
- package/dist/harness/transcript.js +264 -0
- package/dist/harness/transcript.js.map +1 -0
- package/dist/harness/types.d.ts +1146 -0
- package/dist/harness/types.d.ts.map +1 -0
- package/dist/harness/types.js +2 -0
- package/dist/harness/types.js.map +1 -0
- package/dist/harness/usage.d.ts +19 -0
- package/dist/harness/usage.d.ts.map +1 -0
- package/dist/harness/usage.js +57 -0
- package/dist/harness/usage.js.map +1 -0
- package/dist/harness/util.d.ts +25 -0
- package/dist/harness/util.d.ts.map +1 -0
- package/dist/harness/util.js +76 -0
- package/dist/harness/util.js.map +1 -0
- package/dist/harness/view.d.ts +69 -0
- package/dist/harness/view.d.ts.map +1 -0
- package/dist/harness/view.js +265 -0
- package/dist/harness/view.js.map +1 -0
- package/dist/ids.d.ts +6 -0
- package/dist/ids.d.ts.map +1 -0
- package/dist/ids.js +9 -0
- package/dist/ids.js.map +1 -0
- package/dist/images/cloudflare.d.ts +4 -0
- package/dist/images/cloudflare.d.ts.map +1 -0
- package/dist/images/cloudflare.js +9 -0
- package/dist/images/cloudflare.js.map +1 -0
- package/dist/images/exif.d.ts +3 -0
- package/dist/images/exif.d.ts.map +1 -0
- package/dist/images/exif.js +71 -0
- package/dist/images/exif.js.map +1 -0
- package/dist/images/fit.d.ts +41 -0
- package/dist/images/fit.d.ts.map +1 -0
- package/dist/images/fit.js +108 -0
- package/dist/images/fit.js.map +1 -0
- package/dist/images/index.d.ts +18 -0
- package/dist/images/index.d.ts.map +1 -0
- package/dist/images/index.js +125 -0
- package/dist/images/index.js.map +1 -0
- package/dist/images/node-worker.d.ts +19 -0
- package/dist/images/node-worker.d.ts.map +1 -0
- package/dist/images/node-worker.js +17 -0
- package/dist/images/node-worker.js.map +1 -0
- package/dist/images/node.d.ts +21 -0
- package/dist/images/node.d.ts.map +1 -0
- package/dist/images/node.js +121 -0
- package/dist/images/node.js.map +1 -0
- package/dist/index.d.ts +29 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +23 -0
- package/dist/index.js.map +1 -0
- package/dist/search.d.ts +29 -0
- package/dist/search.d.ts.map +1 -0
- package/dist/search.js +148 -0
- package/dist/search.js.map +1 -0
- package/dist/session/cached-storage.d.ts +72 -0
- package/dist/session/cached-storage.d.ts.map +1 -0
- package/dist/session/cached-storage.js +269 -0
- package/dist/session/cached-storage.js.map +1 -0
- package/dist/session/conversation-tails.d.ts +33 -0
- package/dist/session/conversation-tails.d.ts.map +1 -0
- package/dist/session/conversation-tails.js +101 -0
- package/dist/session/conversation-tails.js.map +1 -0
- package/dist/session/forks.d.ts +10 -0
- package/dist/session/forks.d.ts.map +1 -0
- package/dist/session/forks.js +42 -0
- package/dist/session/forks.js.map +1 -0
- package/dist/session/keys.d.ts +69 -0
- package/dist/session/keys.d.ts.map +1 -0
- package/dist/session/keys.js +161 -0
- package/dist/session/keys.js.map +1 -0
- package/dist/session/session.d.ts +287 -0
- package/dist/session/session.d.ts.map +1 -0
- package/dist/session/session.js +1701 -0
- package/dist/session/session.js.map +1 -0
- package/dist/session/transaction.d.ts +205 -0
- package/dist/session/transaction.d.ts.map +1 -0
- package/dist/session/transaction.js +1059 -0
- package/dist/session/transaction.js.map +1 -0
- package/dist/session/writer.d.ts +74 -0
- package/dist/session/writer.d.ts.map +1 -0
- package/dist/session/writer.js +294 -0
- package/dist/session/writer.js.map +1 -0
- package/dist/signals.d.ts +180 -0
- package/dist/signals.d.ts.map +1 -0
- package/dist/signals.js +236 -0
- package/dist/signals.js.map +1 -0
- package/dist/storage/indexeddb.d.ts +69 -0
- package/dist/storage/indexeddb.d.ts.map +1 -0
- package/dist/storage/indexeddb.js +883 -0
- package/dist/storage/indexeddb.js.map +1 -0
- package/dist/storage/jsonl/index.d.ts +2 -0
- package/dist/storage/jsonl/index.d.ts.map +1 -0
- package/dist/storage/jsonl/index.js +2 -0
- package/dist/storage/jsonl/index.js.map +1 -0
- package/dist/storage/jsonl/node.d.ts +6 -0
- package/dist/storage/jsonl/node.d.ts.map +1 -0
- package/dist/storage/jsonl/node.js +8 -0
- package/dist/storage/jsonl/node.js.map +1 -0
- package/dist/storage/jsonl/storage.d.ts +206 -0
- package/dist/storage/jsonl/storage.d.ts.map +1 -0
- package/dist/storage/jsonl/storage.js +799 -0
- package/dist/storage/jsonl/storage.js.map +1 -0
- package/dist/storage/memory.d.ts +68 -0
- package/dist/storage/memory.d.ts.map +1 -0
- package/dist/storage/memory.js +761 -0
- package/dist/storage/memory.js.map +1 -0
- package/dist/storage/scan.d.ts +18 -0
- package/dist/storage/scan.d.ts.map +1 -0
- package/dist/storage/scan.js +29 -0
- package/dist/storage/scan.js.map +1 -0
- package/dist/storage/sqlite/cloudflare.d.ts +9 -0
- package/dist/storage/sqlite/cloudflare.d.ts.map +1 -0
- package/dist/storage/sqlite/cloudflare.js +11 -0
- package/dist/storage/sqlite/cloudflare.js.map +1 -0
- package/dist/storage/sqlite/commit.d.ts +52 -0
- package/dist/storage/sqlite/commit.d.ts.map +1 -0
- package/dist/storage/sqlite/commit.js +371 -0
- package/dist/storage/sqlite/commit.js.map +1 -0
- package/dist/storage/sqlite/database.d.ts +2 -0
- package/dist/storage/sqlite/database.d.ts.map +1 -0
- package/dist/storage/sqlite/database.js +2 -0
- package/dist/storage/sqlite/database.js.map +1 -0
- package/dist/storage/sqlite/index.d.ts +4 -0
- package/dist/storage/sqlite/index.d.ts.map +1 -0
- package/dist/storage/sqlite/index.js +3 -0
- package/dist/storage/sqlite/index.js.map +1 -0
- package/dist/storage/sqlite/migrations.d.ts +12 -0
- package/dist/storage/sqlite/migrations.d.ts.map +1 -0
- package/dist/storage/sqlite/migrations.js +121 -0
- package/dist/storage/sqlite/migrations.js.map +1 -0
- package/dist/storage/sqlite/node.d.ts +8 -0
- package/dist/storage/sqlite/node.d.ts.map +1 -0
- package/dist/storage/sqlite/node.js +12 -0
- package/dist/storage/sqlite/node.js.map +1 -0
- package/dist/storage/sqlite/rows.d.ts +33 -0
- package/dist/storage/sqlite/rows.d.ts.map +1 -0
- package/dist/storage/sqlite/rows.js +53 -0
- package/dist/storage/sqlite/rows.js.map +1 -0
- package/dist/storage/sqlite/schema.d.ts +45 -0
- package/dist/storage/sqlite/schema.d.ts.map +1 -0
- package/dist/storage/sqlite/schema.js +50 -0
- package/dist/storage/sqlite/schema.js.map +1 -0
- package/dist/storage/sqlite/statements.d.ts +13 -0
- package/dist/storage/sqlite/statements.d.ts.map +1 -0
- package/dist/storage/sqlite/statements.js +88 -0
- package/dist/storage/sqlite/statements.js.map +1 -0
- package/dist/storage/sqlite/storage.d.ts +86 -0
- package/dist/storage/sqlite/storage.d.ts.map +1 -0
- package/dist/storage/sqlite/storage.js +534 -0
- package/dist/storage/sqlite/storage.js.map +1 -0
- package/dist/storage/store/commit.d.ts +33 -0
- package/dist/storage/store/commit.d.ts.map +1 -0
- package/dist/storage/store/commit.js +286 -0
- package/dist/storage/store/commit.js.map +1 -0
- package/dist/storage/store/documents.d.ts +43 -0
- package/dist/storage/store/documents.d.ts.map +1 -0
- package/dist/storage/store/documents.js +102 -0
- package/dist/storage/store/documents.js.map +1 -0
- package/dist/storage/store/index.d.ts +2 -0
- package/dist/storage/store/index.d.ts.map +1 -0
- package/dist/storage/store/index.js +2 -0
- package/dist/storage/store/index.js.map +1 -0
- package/dist/storage/store/queries.d.ts +49 -0
- package/dist/storage/store/queries.d.ts.map +1 -0
- package/dist/storage/store/queries.js +93 -0
- package/dist/storage/store/queries.js.map +1 -0
- package/dist/storage/store/storage.d.ts +60 -0
- package/dist/storage/store/storage.d.ts.map +1 -0
- package/dist/storage/store/storage.js +438 -0
- package/dist/storage/store/storage.js.map +1 -0
- package/dist/storage/store/tables.d.ts +54 -0
- package/dist/storage/store/tables.d.ts.map +1 -0
- package/dist/storage/store/tables.js +108 -0
- package/dist/storage/store/tables.js.map +1 -0
- package/dist/tasks.d.ts +6 -0
- package/dist/tasks.d.ts.map +1 -0
- package/dist/tasks.js +5 -0
- package/dist/tasks.js.map +1 -0
- package/dist/testing/assertions.d.ts +5 -0
- package/dist/testing/assertions.d.ts.map +1 -0
- package/dist/testing/assertions.js +25 -0
- package/dist/testing/assertions.js.map +1 -0
- package/dist/testing/commit-writes.d.ts +5 -0
- package/dist/testing/commit-writes.d.ts.map +1 -0
- package/dist/testing/commit-writes.js +12 -0
- package/dist/testing/commit-writes.js.map +1 -0
- package/dist/testing/env-conformance.d.ts +7 -0
- package/dist/testing/env-conformance.d.ts.map +1 -0
- package/dist/testing/env-conformance.js +531 -0
- package/dist/testing/env-conformance.js.map +1 -0
- package/dist/testing/index.d.ts +8 -0
- package/dist/testing/index.d.ts.map +1 -0
- package/dist/testing/index.js +7 -0
- package/dist/testing/index.js.map +1 -0
- package/dist/testing/runner.d.ts +12 -0
- package/dist/testing/runner.d.ts.map +1 -0
- package/dist/testing/runner.js +23 -0
- package/dist/testing/runner.js.map +1 -0
- package/dist/testing/storage-benchmark.d.ts +41 -0
- package/dist/testing/storage-benchmark.d.ts.map +1 -0
- package/dist/testing/storage-benchmark.js +351 -0
- package/dist/testing/storage-benchmark.js.map +1 -0
- package/dist/testing/storage-conformance.d.ts +4 -0
- package/dist/testing/storage-conformance.d.ts.map +1 -0
- package/dist/testing/storage-conformance.js +1554 -0
- package/dist/testing/storage-conformance.js.map +1 -0
- package/dist/testing/types.d.ts +39 -0
- package/dist/testing/types.d.ts.map +1 -0
- package/dist/testing/types.js +2 -0
- package/dist/testing/types.js.map +1 -0
- package/dist/timers.d.ts +21 -0
- package/dist/timers.d.ts.map +1 -0
- package/dist/timers.js +72 -0
- package/dist/timers.js.map +1 -0
- package/dist/tool-search/index.d.ts +2 -0
- package/dist/tool-search/index.d.ts.map +1 -0
- package/dist/tool-search/index.js +2 -0
- package/dist/tool-search/index.js.map +1 -0
- package/dist/tool-search/tool-search.d.ts +17 -0
- package/dist/tool-search/tool-search.d.ts.map +1 -0
- package/dist/tool-search/tool-search.js +96 -0
- package/dist/tool-search/tool-search.js.map +1 -0
- package/dist/tools/bash.d.ts +55 -0
- package/dist/tools/bash.d.ts.map +1 -0
- package/dist/tools/bash.js +139 -0
- package/dist/tools/bash.js.map +1 -0
- package/dist/tools/edit-diff.d.ts +89 -0
- package/dist/tools/edit-diff.d.ts.map +1 -0
- package/dist/tools/edit-diff.js +386 -0
- package/dist/tools/edit-diff.js.map +1 -0
- package/dist/tools/edit.d.ts +18 -0
- package/dist/tools/edit.d.ts.map +1 -0
- package/dist/tools/edit.js +117 -0
- package/dist/tools/edit.js.map +1 -0
- package/dist/tools/env.d.ts +5 -0
- package/dist/tools/env.d.ts.map +1 -0
- package/dist/tools/env.js +7 -0
- package/dist/tools/env.js.map +1 -0
- package/dist/tools/file-mutation-queue.d.ts +9 -0
- package/dist/tools/file-mutation-queue.d.ts.map +1 -0
- package/dist/tools/file-mutation-queue.js +52 -0
- package/dist/tools/file-mutation-queue.js.map +1 -0
- package/dist/tools/image-processor.d.ts +57 -0
- package/dist/tools/image-processor.d.ts.map +1 -0
- package/dist/tools/image-processor.js +49 -0
- package/dist/tools/image-processor.js.map +1 -0
- package/dist/tools/image.d.ts +20 -0
- package/dist/tools/image.d.ts.map +1 -0
- package/dist/tools/image.js +178 -0
- package/dist/tools/image.js.map +1 -0
- package/dist/tools/index.d.ts +46 -0
- package/dist/tools/index.d.ts.map +1 -0
- package/dist/tools/index.js +23 -0
- package/dist/tools/index.js.map +1 -0
- package/dist/tools/path-utils.d.ts +5 -0
- package/dist/tools/path-utils.d.ts.map +1 -0
- package/dist/tools/path-utils.js +26 -0
- package/dist/tools/path-utils.js.map +1 -0
- package/dist/tools/read.d.ts +30 -0
- package/dist/tools/read.d.ts.map +1 -0
- package/dist/tools/read.js +239 -0
- package/dist/tools/read.js.map +1 -0
- package/dist/tools/write.d.ts +10 -0
- package/dist/tools/write.d.ts.map +1 -0
- package/dist/tools/write.js +31 -0
- package/dist/tools/write.js.map +1 -0
- package/dist/truncate.d.ts +65 -0
- package/dist/truncate.d.ts.map +1 -0
- package/dist/truncate.js +124 -0
- package/dist/truncate.js.map +1 -0
- package/dist/types.d.ts +1244 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +3 -0
- package/dist/types.js.map +1 -0
- package/package.json +179 -5
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"migrations.js","sourceRoot":"","sources":["../../../src/storage/sqlite/migrations.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,qBAAqB,IAAI,eAAe,GAGxC,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAAE,qBAAqB,EAAqB,MAAM,aAAa,CAAC;AAIvE,+EAA+E;AAC/E,MAAM,UAAU,sBAAsB,CAAC,MAAoB;IAC1D,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,GAAG,MAAM,CAAC;IACnC,uGAAuG;IACvG,MAAM,aAAa,GAAsB;QACxC,gBAAgB,MAAM,CAAC,eAAe;;;;WAI7B;QACT,eAAe,MAAM,CAAC,eAAe,oDAAoD;QACzF,gBAAgB,MAAM,CAAC,SAAS;;;WAGvB;QACT,gBAAgB,MAAM,CAAC,aAAa;;;;;WAK3B;QACT,gBAAgB,OAAO,CAAC,gCAAgC,OAAO,MAAM,CAAC,aAAa,8BAA8B;QACjH,gBAAgB,OAAO,CAAC,wBAAwB,OAAO,MAAM,CAAC,aAAa,sBAAsB;QACjG,gBAAgB,MAAM,CAAC,OAAO;;;;;;WAMrB;QACT,gBAAgB,OAAO,CAAC,qBAAqB,OAAO,MAAM,CAAC,OAAO,6BAA6B;QAC/F,gBAAgB,OAAO,CAAC,wBAAwB,OAAO,MAAM,CAAC,OAAO,oDAAoD;QACzH,gBAAgB,MAAM,CAAC,KAAK;;;;;;;;WAQnB;QACT,gBAAgB,OAAO,CAAC,aAAa,OAAO,MAAM,CAAC,KAAK,eAAe;QACvE,gBAAgB,OAAO,CAAC,mBAAmB,OAAO,MAAM,CAAC,KAAK,wBAAwB;QACtF,gBAAgB,OAAO,CAAC,WAAW,OAAO,MAAM,CAAC,KAAK,aAAa;QACnE,gBAAgB,OAAO,CAAC,qBAAqB,OAAO,MAAM,CAAC,KAAK,wBAAwB;QACxF,gBAAgB,OAAO,CAAC,iBAAiB,OAAO,MAA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AC,KAAK,mBAAmB;KAC/E,CAAC;IACF,OAAO;QACN,EAAE,OAAO,EAAE,CAAC,EAAE,UAAU,EAAE,aAAa,EAAE;QACzC,EAAE,OAAO,EAAE,CAAC,EAAE,UAAU,EAAE,cAAc,EAAE;KAC1C,CAAC;AACH,CAAC;AAED,MAAM,CAAC,MAAM,iBAAiB,GAA+B,sBAAsB,CAAC,qBAAqB,CAAC,CAAC;AAE3G,MAAM,CAAC,MAAM,6BAA6B,GAAG,iBAAiB,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE,OAAO,IAAI,CAAC,CAAC;AAEpF,sDAAsD;AACtD,MAAM,CAAC,KAAK,UAAU,qBAAqB,CAC1C,QAAwB,EACxB,UAAU,GAA+B,iBAAiB;IAE1D,MAAM,8BAA8B,CAAC,QAAQ,EAAE,qBAAqB,EAAE,UAAU,CAAC,CAAC;AACnF,CAAC;AAED,yDAAyD;AACzD,MAAM,CAAC,KAAK,UAAU,8BAA8B,CACnD,QAAwB,EACxB,MAAoB,EACpB,UAAU,GAA+B,sBAAsB,CAAC,MAAM,CAAC;IAEvE,MAAM,eAAe,CAAC,QAAQ,EAAE,UAAU,EAAE,EAAE,KAAK,EAAE,MAAM,CAAC,MAAM,CAAC,aAAa,EAAE,CAAC,CAAC;AACrF,CAAC","sourcesContent":["import {\n\tapplySqliteMigrations as applyMigrations,\n\ttype SqliteDatabase,\n\ttype SqliteMigration,\n} from \"@diffra-ai/chord/sqlite\";\nimport { DEFAULT_SQLITE_SCHEMA, type SqliteSchema } from \"./schema.ts\";\n\nexport type { SqliteMigration } from \"@diffra-ai/chord/sqlite\";\n\n/** Build immutable, ordered schema history for a set of SQLite identifiers. */\nexport function createSqliteMigrations(schema: SqliteSchema): readonly SqliteMigration[] {\n\tconst { tables, indexes } = schema;\n\t// next_id is TEXT because node:sqlite rejects INTEGER results outside JavaScript's safe integer range.\n\tconst initialSchema: readonly string[] = [\n\t\t`CREATE TABLE ${tables.durableMetadata} (\n\t\t\tsingleton INTEGER PRIMARY KEY CHECK (singleton = 1),\n\t\t\tnext_id TEXT NOT NULL,\n\t\t\tnext_seq INTEGER NOT NULL\n\t\t) STRICT`,\n\t\t`INSERT INTO ${tables.durableMetadata} (singleton, next_id, next_seq) VALUES (1, '2', 1)`,\n\t\t`CREATE TABLE ${tables.recordIds} (\n\t\t\tid INTEGER PRIMARY KEY,\n\t\t\trecord_type TEXT NOT NULL CHECK (record_type IN ('conversation', 'entry', 'task', 'submission', 'document'))\n\t\t) STRICT`,\n\t\t`CREATE TABLE ${tables.conversations} (\n\t\t\tid INTEGER PRIMARY KEY,\n\t\t\towner_conversation_id INTEGER,\n\t\t\towner_task_id INTEGER,\n\t\t\trecord TEXT NOT NULL CHECK (json_valid(record))\n\t\t) STRICT`,\n\t\t`CREATE INDEX ${indexes.conversationsByOwnerConversation} ON ${tables.conversations} (owner_conversation_id, id)`,\n\t\t`CREATE INDEX ${indexes.conversationsByOwnerTask} ON ${tables.conversations} (owner_task_id, id)`,\n\t\t`CREATE TABLE ${tables.entries} (\n\t\t\tid INTEGER PRIMARY KEY,\n\t\t\tconversation_id INTEGER NOT NULL,\n\t\t\thead INTEGER,\n\t\t\tcommit_seq INTEGER NOT NULL,\n\t\t\trecord TEXT NOT NULL CHECK (json_valid(record))\n\t\t) STRICT`,\n\t\t`CREATE INDEX ${indexes.entriesByConversation} ON ${tables.entries} (conversation_id, id DESC)`,\n\t\t`CREATE INDEX ${indexes.entryHeadsByConversation} ON ${tables.entries} (conversation_id, id DESC) WHERE head IS NOT NULL`,\n\t\t`CREATE TABLE ${tables.tasks} (\n\t\t\tid INTEGER PRIMARY KEY,\n\t\t\tconversation_id INTEGER NOT NULL,\n\t\t\tkind TEXT NOT NULL,\n\t\t\tstatus TEXT NOT NULL CHECK (status IN ('pending', 'running', 'waiting', 'completing', 'terminal')),\n\t\t\tabort_requested INTEGER NOT NULL CHECK (abort_requested IN (0, 1)),\n\t\t\tbackground INTEGER NOT NULL CHECK (background IN (0, 1)),\n\t\t\trecord TEXT NOT NULL CHECK (json_valid(record))\n\t\t) STRICT`,\n\t\t`CREATE INDEX ${indexes.tasksByStatus} ON ${tables.tasks} (status, id)`,\n\t\t`CREATE INDEX ${indexes.tasksByConversation} ON ${tables.tasks} (conversation_id, id)`,\n\t\t`CREATE INDEX ${indexes.tasksByKind} ON ${tables.tasks} (kind, id)`,\n\t\t`CREATE INDEX ${indexes.tasksByAbortRequested} ON ${tables.tasks} (abort_requested, id)`,\n\t\t`CREATE INDEX ${indexes.tasksByBackground} ON ${tables.tasks} (background, id)`,\n\t\t`CREATE TABLE ${tables.submissions} (\n\t\t\tid INTEGER PRIMARY KEY,\n\t\t\tconversation_id INTEGER NOT NULL,\n\t\t\trequest_id TEXT,\n\t\t\tstatus TEXT NOT NULL CHECK (status IN ('queued', 'placed', 'done', 'unanswered')),\n\t\t\trecord TEXT NOT NULL CHECK (json_valid(record))\n\t\t) STRICT`,\n\t\t`CREATE INDEX ${indexes.submissionsByRequest} ON ${tables.submissions} (conversation_id, request_id)`,\n\t\t`CREATE INDEX ${indexes.submissionsByConversation} ON ${tables.submissions} (conversation_id, id)`,\n\t\t`CREATE INDEX ${indexes.submissionsByStatus} ON ${tables.submissions} (status, id)`,\n\t\t`CREATE TABLE ${tables.documents} (\n\t\t\tid INTEGER PRIMARY KEY,\n\t\t\tkind TEXT NOT NULL,\n\t\t\tfamily INTEGER NOT NULL CHECK (family IN (0, 1)),\n\t\t\tkey_value TEXT NOT NULL,\n\t\t\tscope_kind TEXT NOT NULL CHECK (scope_kind IN ('session', 'conversation', 'task')),\n\t\t\towner_id INTEGER NOT NULL,\n\t\t\tcreated_at INTEGER NOT NULL,\n\t\t\tretired_at INTEGER,\n\t\t\trecord TEXT NOT NULL CHECK (json_valid(record))\n\t\t) STRICT`,\n\t\t`CREATE INDEX ${indexes.documentsByAddress}\n\t\t\tON ${tables.documents} (kind, scope_kind, owner_id, family, key_value, created_at DESC, retired_at)`,\n\t\t`CREATE INDEX ${indexes.documentsByScope} ON ${tables.documents} (scope_kind, owner_id, id)`,\n\t\t`CREATE INDEX ${indexes.documentsByScopeKind} ON ${tables.documents} (scope_kind, owner_id, kind, id)`,\n\t\t`CREATE TABLE ${tables.documentRevisions} (\n\t\t\tdocument_id INTEGER NOT NULL,\n\t\t\tseq INTEGER NOT NULL,\n\t\t\tkind TEXT NOT NULL CHECK (kind IN ('base', 'delta')),\n\t\t\tversion INTEGER NOT NULL,\n\t\t\tcontent TEXT NOT NULL CHECK (json_valid(content)),\n\t\t\tPRIMARY KEY (document_id, seq)\n\t\t) STRICT`,\n\t\t`CREATE INDEX ${indexes.documentRevisionsByKind} ON ${tables.documentRevisions} (document_id, kind, seq DESC)`,\n\t];\n\t// Version 2 adds the `sleeping` task status. SQLite cannot change a CHECK constraint in place, so the table is rebuilt.\n\tconst rebuiltTasks = `${tables.tasks}_v2`;\n\tconst sleepingStatus: readonly string[] = [\n\t\t`CREATE TABLE ${rebuiltTasks} (\n\t\t\tid INTEGER PRIMARY KEY,\n\t\t\tconversation_id INTEGER NOT NULL,\n\t\t\tkind TEXT NOT NULL,\n\t\t\tstatus TEXT NOT NULL CHECK (status IN ('pending', 'running', 'waiting', 'sleeping', 'completing', 'terminal')),\n\t\t\tabort_requested INTEGER NOT NULL CHECK (abort_requested IN (0, 1)),\n\t\t\tbackground INTEGER NOT NULL CHECK (background IN (0, 1)),\n\t\t\trecord TEXT NOT NULL CHECK (json_valid(record))\n\t\t) STRICT`,\n\t\t`INSERT INTO ${rebuiltTasks} (id, conversation_id, kind, status, abort_requested, background, record)\n\t\t\tSELECT id, conversation_id, kind, status, abort_requested, background, record FROM ${tables.tasks}`,\n\t\t`DROP TABLE ${tables.tasks}`,\n\t\t`ALTER TABLE ${rebuiltTasks} RENAME TO ${tables.tasks}`,\n\t\t`CREATE INDEX ${indexes.tasksByStatus} ON ${tables.tasks} (status, id)`,\n\t\t`CREATE INDEX ${indexes.tasksByConversation} ON ${tables.tasks} (conversation_id, id)`,\n\t\t`CREATE INDEX ${indexes.tasksByKind} ON ${tables.tasks} (kind, id)`,\n\t\t`CREATE INDEX ${indexes.tasksByAbortRequested} ON ${tables.tasks} (abort_requested, id)`,\n\t\t`CREATE INDEX ${indexes.tasksByBackground} ON ${tables.tasks} (background, id)`,\n\t];\n\treturn [\n\t\t{ version: 1, statements: initialSchema },\n\t\t{ version: 2, statements: sleepingStatus },\n\t];\n}\n\nexport const SQLITE_MIGRATIONS: readonly SqliteMigration[] = createSqliteMigrations(DEFAULT_SQLITE_SCHEMA);\n\nexport const CURRENT_SQLITE_SCHEMA_VERSION = SQLITE_MIGRATIONS.at(-1)?.version ?? 0;\n\n/** Apply all pending schema migrations atomically. */\nexport async function applySqliteMigrations(\n\tdatabase: SqliteDatabase,\n\tmigrations: readonly SqliteMigration[] = SQLITE_MIGRATIONS,\n): Promise<void> {\n\tawait applySqliteMigrationsForSchema(database, DEFAULT_SQLITE_SCHEMA, migrations);\n}\n\n/** Apply migrations rendered for a particular schema. */\nexport async function applySqliteMigrationsForSchema(\n\tdatabase: SqliteDatabase,\n\tschema: SqliteSchema,\n\tmigrations: readonly SqliteMigration[] = createSqliteMigrations(schema),\n): Promise<void> {\n\tawait applyMigrations(database, migrations, { table: schema.tables.durableSchema });\n}\n"]}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { type NodeSqliteDatabaseOptions } from "@diffra-ai/chord/sqlite/node";
|
|
2
|
+
import { SqliteStorage, type SqliteStorageOptions } from "./storage.ts";
|
|
3
|
+
export { NodeSqliteDatabase, type NodeSqliteDatabaseOptions, openNodeSqliteDatabase, } from "@diffra-ai/chord/sqlite/node";
|
|
4
|
+
/** Node SQLite connection settings plus durable storage options. */
|
|
5
|
+
export type NodeSqliteStorageOptions = NodeSqliteDatabaseOptions & SqliteStorageOptions;
|
|
6
|
+
/** Open or create file-backed durable storage using Node's built-in SQLite, optionally under a table prefix. */
|
|
7
|
+
export declare function openNodeSqliteStorage(path: string, options?: NodeSqliteStorageOptions): Promise<SqliteStorage>;
|
|
8
|
+
//# sourceMappingURL=node.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"node.d.ts","sourceRoot":"","sources":["../../../src/storage/sqlite/node.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,yBAAyB,EAA0B,MAAM,8BAA8B,CAAC;AACtG,OAAO,EAAE,aAAa,EAAE,KAAK,oBAAoB,EAAE,MAAM,cAAc,CAAC;AAExE,OAAO,EACN,kBAAkB,EAClB,KAAK,yBAAyB,EAC9B,sBAAsB,GACtB,MAAM,8BAA8B,CAAC;AAEtC,oEAAoE;AACpE,MAAM,MAAM,wBAAwB,GAAG,yBAAyB,GAAG,oBAAoB,CAAC;AAExF,gHAAgH;AAChH,wBAAsB,qBAAqB,CAC1C,IAAI,EAAE,MAAM,EACZ,OAAO,GAAE,wBAA6B,GACpC,OAAO,CAAC,aAAa,CAAC,CAIxB"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { validateSqliteSchemaPrefix } from "@diffra-ai/chord/sqlite";
|
|
2
|
+
import { openNodeSqliteDatabase } from "@diffra-ai/chord/sqlite/node";
|
|
3
|
+
import { SqliteStorage } from "./storage.js";
|
|
4
|
+
export { NodeSqliteDatabase, openNodeSqliteDatabase, } from "@diffra-ai/chord/sqlite/node";
|
|
5
|
+
/** Open or create file-backed durable storage using Node's built-in SQLite, optionally under a table prefix. */
|
|
6
|
+
export async function openNodeSqliteStorage(path, options = {}) {
|
|
7
|
+
const { prefix, ...databaseOptions } = options;
|
|
8
|
+
if (prefix !== undefined)
|
|
9
|
+
validateSqliteSchemaPrefix(prefix);
|
|
10
|
+
return SqliteStorage.open(await openNodeSqliteDatabase(path, databaseOptions), { prefix });
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=node.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"node.js","sourceRoot":"","sources":["../../../src/storage/sqlite/node.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,0BAA0B,EAAE,MAAM,yBAAyB,CAAC;AACrE,OAAO,EAAkC,sBAAsB,EAAE,MAAM,8BAA8B,CAAC;AACtG,OAAO,EAAE,aAAa,EAA6B,MAAM,cAAc,CAAC;AAExE,OAAO,EACN,kBAAkB,EAElB,sBAAsB,GACtB,MAAM,8BAA8B,CAAC;AAKtC,gHAAgH;AAChH,MAAM,CAAC,KAAK,UAAU,qBAAqB,CAC1C,IAAY,EACZ,OAAO,GAA6B,EAAE;IAEtC,MAAM,EAAE,MAAM,EAAE,GAAG,eAAe,EAAE,GAAG,OAAO,CAAC;IAC/C,IAAI,MAAM,KAAK,SAAS;QAAE,0BAA0B,CAAC,MAAM,CAAC,CAAC;IAC7D,OAAO,aAAa,CAAC,IAAI,CAAC,MAAM,sBAAsB,CAAC,IAAI,EAAE,eAAe,CAAC,EAAE,EAAE,MAAM,EAAE,CAAC,CAAC;AAC5F,CAAC","sourcesContent":["import { validateSqliteSchemaPrefix } from \"@diffra-ai/chord/sqlite\";\nimport { type NodeSqliteDatabaseOptions, openNodeSqliteDatabase } from \"@diffra-ai/chord/sqlite/node\";\nimport { SqliteStorage, type SqliteStorageOptions } from \"./storage.ts\";\n\nexport {\n\tNodeSqliteDatabase,\n\ttype NodeSqliteDatabaseOptions,\n\topenNodeSqliteDatabase,\n} from \"@diffra-ai/chord/sqlite/node\";\n\n/** Node SQLite connection settings plus durable storage options. */\nexport type NodeSqliteStorageOptions = NodeSqliteDatabaseOptions & SqliteStorageOptions;\n\n/** Open or create file-backed durable storage using Node's built-in SQLite, optionally under a table prefix. */\nexport async function openNodeSqliteStorage(\n\tpath: string,\n\toptions: NodeSqliteStorageOptions = {},\n): Promise<SqliteStorage> {\n\tconst { prefix, ...databaseOptions } = options;\n\tif (prefix !== undefined) validateSqliteSchemaPrefix(prefix);\n\treturn SqliteStorage.open(await openNodeSqliteDatabase(path, databaseOptions), { prefix });\n}\n"]}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { DocumentAddress, DocumentCreate, DocumentRecord } from "../../types.ts";
|
|
2
|
+
/** A value of a stored cell, as Durable's rows hold them. */
|
|
3
|
+
export type Cell = string | number | null;
|
|
4
|
+
/** A document's scope as its `scope_kind` and `owner_id` columns. */
|
|
5
|
+
export type ScopeColumns = {
|
|
6
|
+
readonly scopeKind: DocumentRecord["scope"]["kind"];
|
|
7
|
+
readonly ownerId: number;
|
|
8
|
+
};
|
|
9
|
+
/** Parses a stored JSON column. */
|
|
10
|
+
export declare const parseJson: <T>(value: string) => T;
|
|
11
|
+
/** Encodes a value as a stored JSON column. */
|
|
12
|
+
export declare const encodeJson: (value: unknown) => string;
|
|
13
|
+
/** Encodes an indexed string column. Some SQLite bindings replace lone UTF-16 surrogates; JSON keeps it lossless. */
|
|
14
|
+
export declare const encodeIndexedString: (value: string) => string;
|
|
15
|
+
/** A document scope's columns. */
|
|
16
|
+
export declare const scopeColumns: (scope: DocumentRecord["scope"]) => ScopeColumns;
|
|
17
|
+
/** A document address's columns, as `documents` stores and indexes them. */
|
|
18
|
+
export declare const addressParts: (address: DocumentAddress | DocumentCreate | DocumentRecord) => {
|
|
19
|
+
scopeKind: DocumentRecord["scope"]["kind"];
|
|
20
|
+
ownerId: number;
|
|
21
|
+
kind: string;
|
|
22
|
+
family: number;
|
|
23
|
+
keyValue: string;
|
|
24
|
+
};
|
|
25
|
+
/** One string per document address, from its stored columns. */
|
|
26
|
+
export declare const addressColumnsKey: (kind: string, scopeKind: string, ownerId: number, family: number, keyValue: string) => string;
|
|
27
|
+
/** One string per document address. */
|
|
28
|
+
export declare const addressKey: (address: DocumentAddress | DocumentCreate | DocumentRecord) => string;
|
|
29
|
+
/** Whether a document keeps only its current state: its revisions go at each new base and at retirement. */
|
|
30
|
+
export declare const isCurrentOnly: (record: DocumentRecord) => boolean;
|
|
31
|
+
/** A document record's `documents` row: id, kind, family, key, scope, owner, created and retired seqs, record. */
|
|
32
|
+
export declare function documentRow(record: DocumentRecord): Cell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KAAG,OACa,CAAC;AAErE,kHAAkH;AAClH,wBAAgB,WAAW,CAAC,MAAM,EAAE,cAAc,GAAG,IAAI,EAAE,CAa1D"}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
// How Durable's records map to SQLite: JSON text, indexed strings, and a document's scope and address columns.
|
|
2
|
+
/** Parses a stored JSON column. */
|
|
3
|
+
export const parseJson = (value) => JSON.parse(value);
|
|
4
|
+
/** Encodes a value as a stored JSON column. */
|
|
5
|
+
export const encodeJson = (value) => JSON.stringify(value);
|
|
6
|
+
/** Encodes an indexed string column. Some SQLite bindings replace lone UTF-16 surrogates; JSON keeps it lossless. */
|
|
7
|
+
export const encodeIndexedString = (value) => JSON.stringify(value);
|
|
8
|
+
/** A document scope's columns. */
|
|
9
|
+
export const scopeColumns = (scope) => {
|
|
10
|
+
switch (scope.kind) {
|
|
11
|
+
case "session":
|
|
12
|
+
return { scopeKind: "session", ownerId: 0 };
|
|
13
|
+
case "conversation":
|
|
14
|
+
return { scopeKind: "conversation", ownerId: scope.conversationId };
|
|
15
|
+
case "task":
|
|
16
|
+
return { scopeKind: "task", ownerId: scope.taskId };
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
/** A document address's columns, as `documents` stores and indexes them. */
|
|
20
|
+
export const addressParts = (address) => {
|
|
21
|
+
const scope = scopeColumns(address.scope);
|
|
22
|
+
return {
|
|
23
|
+
kind: encodeIndexedString(address.kind),
|
|
24
|
+
...scope,
|
|
25
|
+
family: address.key === undefined ? 0 : 1,
|
|
26
|
+
keyValue: encodeIndexedString(address.key ?? ""),
|
|
27
|
+
};
|
|
28
|
+
};
|
|
29
|
+
/** One string per document address, from its stored columns. */
|
|
30
|
+
export const addressColumnsKey = (kind, scopeKind, ownerId, family, keyValue) => JSON.stringify([kind, scopeKind, ownerId, family, keyValue]);
|
|
31
|
+
/** One string per document address. */
|
|
32
|
+
export const addressKey = (address) => {
|
|
33
|
+
const parts = addressParts(address);
|
|
34
|
+
return addressColumnsKey(parts.kind, parts.scopeKind, parts.ownerId, parts.family, parts.keyValue);
|
|
35
|
+
};
|
|
36
|
+
/** Whether a document keeps only its current state: its revisions go at each new base and at retirement. */
|
|
37
|
+
export const isCurrentOnly = (record) => record.scope.kind !== "conversation" || record.history === "latest";
|
|
38
|
+
/** A document record's `documents` row: id, kind, family, key, scope, owner, created and retired seqs, record. */
|
|
39
|
+
export function documentRow(record) {
|
|
40
|
+
const parts = addressParts(record);
|
|
41
|
+
return [
|
|
42
|
+
record.id,
|
|
43
|
+
parts.kind,
|
|
44
|
+
parts.family,
|
|
45
|
+
parts.keyValue,
|
|
46
|
+
parts.scopeKind,
|
|
47
|
+
parts.ownerId,
|
|
48
|
+
record.createdAt,
|
|
49
|
+
record.retiredAt ?? null,
|
|
50
|
+
encodeJson(record),
|
|
51
|
+
];
|
|
52
|
+
}
|
|
53
|
+
//# sourceMappingURL=rows.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rows.js","sourceRoot":"","sources":["../../../src/storage/sqlite/rows.ts"],"names":[],"mappings":"AAAA,+GAA+G;AAa/G,mCAAmC;AACnC,MAAM,CAAC,MAAM,SAAS,GAAG,CAAI,KAAa,EAAK,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,CAAM,CAAC;AAEzE,+CAA+C;AAC/C,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,KAAc,EAAU,EAAE,CAAC,IAAI,CAAC,SAAS,CAAC,KAAK,CAAW,CAAC;AAEtF,qHAAqH;AACrH,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAAC,KAAa,EAAU,EAAE,CAAC,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;AAEpF,kCAAkC;AAClC,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,KAA8B,EAAgB,EAAE;IAC5E,QAAQ,KAAK,CAAC,IAAI,EAAE,CAAC;QACpB,KAAK,SAAS;YACb,OAAO,EAAE,SAAS,EAAE,SAAS,E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EF,4GAA4G;AAC5G,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,MAAsB,EAAW,EAAE,CAChE,MAAM,CAAC,KAAK,CAAC,IAAI,KAAK,cAAc,IAAI,MAAM,CAAC,OAAO,KAAK,QAAQ,CAAC;AAErE,kHAAkH;AAClH,MAAM,UAAU,WAAW,CAAC,MAAsB;IACjD,MAAM,KAAK,GAAG,YAAY,CAAC,MAAM,CAAC,CAAC;IACnC,OAAO;QACN,MAAM,CAAC,EAAE;QACT,KAAK,CAAC,IAAI;QACV,KAAK,CAAC,MAAM;QACZ,KAAK,CAAC,QAAQ;QACd,KAAK,CAAC,SAAS;QACf,KAAK,CAAC,OAAO;QACb,MAAM,CAAC,SAAS;QAChB,MAAM,CAAC,SAAS,IAAI,IAAI;QACxB,UAAU,CAAC,MAAM,CAAC;KAClB,CAAC;AACH,CAAC","sourcesContent":["// How Durable's records map to SQLite: JSON text, indexed strings, and a document's scope and address columns.\n\nimport type { DocumentAddress, DocumentCreate, DocumentRecord } from \"../../types.ts\";\n\n/** A value of a stored cell, as Durable's rows hold them. */\nexport type Cell = string | number | null;\n\n/** A document's scope as its `scope_kind` and `owner_id` columns. */\nexport type ScopeColumns = {\n\treadonly scopeKind: DocumentRecord[\"scope\"][\"kind\"];\n\treadonly ownerId: number;\n};\n\n/** Parses a stored JSON column. */\nexport const parseJson = <T>(value: string): T => JSON.parse(value) as T;\n\n/** Encodes a value as a stored JSON column. */\nexport const encodeJson = (value: unknown): string => JSON.stringify(value) as string;\n\n/** Encodes an indexed string column. Some SQLite bindings replace lone UTF-16 surrogates; JSON keeps it lossless. */\nexport const encodeIndexedString = (value: string): string => JSON.stringify(value);\n\n/** A document scope's columns. */\nexport const scopeColumns = (scope: DocumentRecord[\"scope\"]): ScopeColumns => {\n\tswitch (scope.kind) {\n\t\tcase \"session\":\n\t\t\treturn { scopeKind: \"session\", ownerId: 0 };\n\t\tcase \"conversation\":\n\t\t\treturn { scopeKind: \"conversation\", ownerId: scope.conversationId };\n\t\tcase \"task\":\n\t\t\treturn { scopeKind: \"task\", ownerId: scope.taskId };\n\t}\n};\n\n/** A document address's columns, as `documents` stores and indexes them. */\nexport const addressParts = (address: DocumentAddress | DocumentCreate | DocumentRecord) => {\n\tconst scope = scopeColumns(address.scope);\n\treturn {\n\t\tkind: encodeIndexedString(address.kind),\n\t\t...scope,\n\t\tfamily: address.key === undefined ? 0 : 1,\n\t\tkeyValue: encodeIndexedString(address.key ?? \"\"),\n\t};\n};\n\n/** One string per document address, from its stored columns. */\nexport const addressColumnsKey = (\n\tkind: string,\n\tscopeKind: string,\n\townerId: number,\n\tfamily: number,\n\tkeyValue: string,\n): string => JSON.stringify([kind, scopeKind, ownerId, family, keyValue]);\n\n/** One string per document address. */\nexport const addressKey = (address: DocumentAddress | DocumentCreate | DocumentRecord): string => {\n\tconst parts = addressParts(address);\n\treturn addressColumnsKey(parts.kind, parts.scopeKind, parts.ownerId, parts.family, parts.keyValue);\n};\n\n/** Whether a document keeps only its current state: its revisions go at each new base and at retirement. */\nexport const isCurrentOnly = (record: DocumentRecord): boolean =>\n\trecord.scope.kind !== \"conversation\" || record.history === \"latest\";\n\n/** A document record's `documents` row: id, kind, family, key, scope, owner, created and retired seqs, record. */\nexport function documentRow(record: DocumentRecord): Cell[] {\n\tconst parts = addressParts(record);\n\treturn [\n\t\trecord.id,\n\t\tparts.kind,\n\t\tparts.family,\n\t\tparts.keyValue,\n\t\tparts.scopeKind,\n\t\tparts.ownerId,\n\t\trecord.createdAt,\n\t\trecord.retiredAt ?? null,\n\t\tencodeJson(record),\n\t];\n}\n"]}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
export { validateSqliteSchemaPrefix } from "@diffra-ai/chord/sqlite";
|
|
2
|
+
/**
|
|
3
|
+
* Immutable identifier history for migrations and runtime queries. Never change or remove an existing value; a
|
|
4
|
+
* rename adds a new entry so historical migrations keep rendering their original object names.
|
|
5
|
+
*/
|
|
6
|
+
declare const TABLE_NAMES: {
|
|
7
|
+
readonly durableSchema: "durable_schema";
|
|
8
|
+
readonly durableMetadata: "durable_metadata";
|
|
9
|
+
readonly recordIds: "record_ids";
|
|
10
|
+
readonly conversations: "conversations";
|
|
11
|
+
readonly entries: "entries";
|
|
12
|
+
readonly tasks: "tasks";
|
|
13
|
+
readonly submissions: "submissions";
|
|
14
|
+
readonly documents: "documents";
|
|
15
|
+
readonly documentRevisions: "document_revisions";
|
|
16
|
+
};
|
|
17
|
+
declare const INDEX_NAMES: {
|
|
18
|
+
readonly conversationsByOwnerConversation: "conversations_by_owner_conversation";
|
|
19
|
+
readonly conversationsByOwnerTask: "conversations_by_owner_task";
|
|
20
|
+
readonly entriesByConversation: "entries_by_conversation";
|
|
21
|
+
readonly entryHeadsByConversation: "entry_heads_by_conversation";
|
|
22
|
+
readonly tasksByStatus: "tasks_by_status";
|
|
23
|
+
readonly tasksByConversation: "tasks_by_conversation";
|
|
24
|
+
readonly tasksByKind: "tasks_by_kind";
|
|
25
|
+
readonly tasksByAbortRequested: "tasks_by_abort_requested";
|
|
26
|
+
readonly tasksByBackground: "tasks_by_background";
|
|
27
|
+
readonly submissionsByRequest: "submissions_by_request";
|
|
28
|
+
readonly submissionsByConversation: "submissions_by_conversation";
|
|
29
|
+
readonly submissionsByStatus: "submissions_by_status";
|
|
30
|
+
readonly documentsByAddress: "documents_by_address";
|
|
31
|
+
readonly documentsByScope: "documents_by_scope";
|
|
32
|
+
readonly documentsByScopeKind: "documents_by_scope_kind";
|
|
33
|
+
readonly documentRevisionsByKind: "document_revisions_by_kind";
|
|
34
|
+
};
|
|
35
|
+
type SqliteIdentifiers<T extends Record<string, string>> = {
|
|
36
|
+
readonly [K in keyof T]: string;
|
|
37
|
+
};
|
|
38
|
+
export type SqliteSchema = {
|
|
39
|
+
readonly tables: SqliteIdentifiers<typeof TABLE_NAMES>;
|
|
40
|
+
readonly indexes: SqliteIdentifiers<typeof INDEX_NAMES>;
|
|
41
|
+
};
|
|
42
|
+
/** Build the identifiers used by every migration and storage query. */
|
|
43
|
+
export declare function createSqliteSchema(prefix?: string): SqliteSchema;
|
|
44
|
+
export declare const DEFAULT_SQLITE_SCHEMA: SqliteSchema;
|
|
45
|
+
//# sourceMappingURL=schema.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../../../src/storage/sqlite/schema.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,0BAA0B,EAAE,MAAM,yBAAyB,CAAC;AAErE;;;GAGG;AACH,QAAA,MAAM,WAAW;aAChB,aAAa,EAAE,gBAAgB;aAC/B,eAAe,EAAE,kBAAkB;aACnC,SAAS,EAAE,YAAY;aACvB,aAAa,EAAE,eAAe;aAC9B,OAAO,EAAE,SAAS;aAClB,KAAK,EAAE,OAAO;aACd,WAAW,EAAE,aAAa;aAC1B,SAAS,EAAE,WAAW;aACtB,iBAAiB,EAAE,oBAAoB;CAC9B,CAAC;AAEX,QAAA,MAAM,WAAW;aAChB,gCAAgC,EAAE,qCAAqC;aACvE,wBAAwB,EAAE,6BAA6B;aACvD,qBAAqB,EAAE,yBAAyB;aAChD,wBAAwB,EAAE,6BAA6B;aACvD,aAAa,EAAE,iBAAiB;aAChC,mBAAmB,EAAE,uBAAuB;aAC5C,WAAW,EAAE,eAAe;aAC5B,qBAAqB,EAAE,0BAA0B;aACjD,iBAAiB,EAAE,qBAAqB;aACxC,oBAAoB,EAAE,wBAAwB;aAC9C,yBAAyB,EAAE,6BAA6B;aACxD,mBAAmB,EAAE,uBAAuB;aAC5C,kBAAkB,EAAE,sBAAsB;aAC1C,gBAAgB,EAAE,oBAAoB;aACtC,oBAAoB,EAAE,yBAAyB;aAC/C,uBAAuB,EAAE,4BAA4B;CAC5C,CAAC;AAEX,KAAK,iBAAiB,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,IAAI;IAAE,QAAQ,EAAE,CAAC,IAAI,MAAM,CAAC,GAAG,MAAM;CAAE,CAAC;AAE/F,MAAM,MAAM,YAAY,GAAG;IAC1B,QAAQ,CAAC,MAAM,EAAE,iBAAiB,CAAC,OAAO,WAAW,CAAC,CAAC;IACvD,QAAQ,CAAC,OAAO,EAAE,iBAAiB,CAAC,OAAO,WAAW,CAAC,CAAC;CACxD,CAAC;AAQF,uEAAuE;AACvE,wBAAgB,kBAAkB,CAAC,MAAM,CAAC,EAAE,MAAM,GAAG,YAAY,CAOhE;AAED,eAAO,MAAM,qBAAqB,cAAuB,CAAC"}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { validateSqliteSchemaPrefix } from "@diffra-ai/chord/sqlite";
|
|
2
|
+
export { validateSqliteSchemaPrefix } from "@diffra-ai/chord/sqlite";
|
|
3
|
+
/**
|
|
4
|
+
* Immutable identifier history for migrations and runtime queries. Never change or remove an existing value; a
|
|
5
|
+
* rename adds a new entry so historical migrations keep rendering their original object names.
|
|
6
|
+
*/
|
|
7
|
+
const TABLE_NAMES = {
|
|
8
|
+
durableSchema: "durable_schema",
|
|
9
|
+
durableMetadata: "durable_metadata",
|
|
10
|
+
recordIds: "record_ids",
|
|
11
|
+
conversations: "conversations",
|
|
12
|
+
entries: "entries",
|
|
13
|
+
tasks: "tasks",
|
|
14
|
+
submissions: "submissions",
|
|
15
|
+
documents: "documents",
|
|
16
|
+
documentRevisions: "document_revisions",
|
|
17
|
+
};
|
|
18
|
+
const INDEX_NAMES = {
|
|
19
|
+
conversationsByOwnerConversation: "conversations_by_owner_conversation",
|
|
20
|
+
conversationsByOwnerTask: "conversations_by_owner_task",
|
|
21
|
+
entriesByConversation: "entries_by_conversation",
|
|
22
|
+
entryHeadsByConversation: "entry_heads_by_conversation",
|
|
23
|
+
tasksByStatus: "tasks_by_status",
|
|
24
|
+
tasksByConversation: "tasks_by_conversation",
|
|
25
|
+
tasksByKind: "tasks_by_kind",
|
|
26
|
+
tasksByAbortRequested: "tasks_by_abort_requested",
|
|
27
|
+
tasksByBackground: "tasks_by_background",
|
|
28
|
+
submissionsByRequest: "submissions_by_request",
|
|
29
|
+
submissionsByConversation: "submissions_by_conversation",
|
|
30
|
+
submissionsByStatus: "submissions_by_status",
|
|
31
|
+
documentsByAddress: "documents_by_address",
|
|
32
|
+
documentsByScope: "documents_by_scope",
|
|
33
|
+
documentsByScopeKind: "documents_by_scope_kind",
|
|
34
|
+
documentRevisionsByKind: "document_revisions_by_kind",
|
|
35
|
+
};
|
|
36
|
+
function prefixIdentifiers(names, prefix) {
|
|
37
|
+
return Object.fromEntries(Object.entries(names).map(([key, name]) => [key, `${prefix}${name}`]));
|
|
38
|
+
}
|
|
39
|
+
/** Build the identifiers used by every migration and storage query. */
|
|
40
|
+
export function createSqliteSchema(prefix) {
|
|
41
|
+
if (prefix !== undefined)
|
|
42
|
+
validateSqliteSchemaPrefix(prefix);
|
|
43
|
+
const actualPrefix = prefix ?? "";
|
|
44
|
+
return {
|
|
45
|
+
tables: prefixIdentifiers(TABLE_NAMES, actualPrefix),
|
|
46
|
+
indexes: prefixIdentifiers(INDEX_NAMES, actualPrefix),
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
export const DEFAULT_SQLITE_SCHEMA = createSqliteSchema();
|
|
50
|
+
//# sourceMappingURL=schema.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schema.js","sourceRoot":"","sources":["../../../src/storage/sqlite/schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,0BAA0B,EAAE,MAAM,yBAAyB,CAAC;AAErE,OAAO,EAAE,0BAA0B,EAAE,MAAM,yBAAyB,CAAC;AAErE;;;GAGG;AACH,MAAM,WAAW,GAAG;IACnB,aAAa,EAAE,gBAAgB;IAC/B,eAAe,EAAE,kBAAkB;IACnC,SAAS,EAAE,YAAY;IACvB,aAAa,EAAE,eAAe;IAC9B,OAAO,EAAE,SAAS;IAClB,KAAK,EAAE,OAAO;IACd,WAAW,EAAE,aAAa;IAC1B,SAAS,EAAE,WAAW;IACtB,iBAAiB,E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n\nexport { validateSqliteSchemaPrefix } from \"@diffra-ai/chord/sqlite\";\n\n/**\n * Immutable identifier history for migrations and runtime queries. Never change or remove an existing value; a\n * rename adds a new entry so historical migrations keep rendering their original object names.\n */\nconst TABLE_NAMES = {\n\tdurableSchema: \"durable_schema\",\n\tdurableMetadata: \"durable_metadata\",\n\trecordIds: \"record_ids\",\n\tconversations: \"conversations\",\n\tentries: \"entries\",\n\ttasks: \"tasks\",\n\tsubmissions: \"submissions\",\n\tdocuments: \"documents\",\n\tdocumentRevisions: \"document_revisions\",\n} as const;\n\nconst INDEX_NAMES = {\n\tconversationsByOwnerConversation: \"conversations_by_owner_conversation\",\n\tconversationsByOwnerTask: \"conversations_by_owner_task\",\n\tentriesByConversation: \"entries_by_conversation\",\n\tentryHeadsByConversation: \"entry_heads_by_conversation\",\n\ttasksByStatus: \"tasks_by_status\",\n\ttasksByConversation: \"tasks_by_conversation\",\n\ttasksByKind: \"tasks_by_kind\",\n\ttasksByAbortRequested: \"tasks_by_abort_requested\",\n\ttasksByBackground: \"tasks_by_background\",\n\tsubmissionsByRequest: \"submissions_by_request\",\n\tsubmissionsByConversation: \"submissions_by_conversation\",\n\tsubmissionsByStatus: \"submissions_by_status\",\n\tdocumentsByAddress: \"documents_by_address\",\n\tdocumentsByScope: \"documents_by_scope\",\n\tdocumentsByScopeKind: \"documents_by_scope_kind\",\n\tdocumentRevisionsByKind: \"document_revisions_by_kind\",\n} as const;\n\ntype SqliteIdentifiers<T extends Record<string, string>> = { readonly [K in keyof T]: string };\n\nexport type SqliteSchema = {\n\treadonly tables: SqliteIdentifiers<typeof TABLE_NAMES>;\n\treadonly indexes: SqliteIdentifiers<typeof INDEX_NAMES>;\n};\n\nfunction prefixIdentifiers<T extends Record<string, string>>(names: T, prefix: string): SqliteIdentifiers<T> {\n\treturn Object.fromEntries(\n\t\tObject.entries(names).map(([key, name]) => [key, `${prefix}${name}`]),\n\t) as SqliteIdentifiers<T>;\n}\n\n/** Build the identifiers used by every migration and storage query. */\nexport function createSqliteSchema(prefix?: string): SqliteSchema {\n\tif (prefix !== undefined) validateSqliteSchemaPrefix(prefix);\n\tconst actualPrefix = prefix ?? \"\";\n\treturn {\n\t\ttables: prefixIdentifiers(TABLE_NAMES, actualPrefix),\n\t\tindexes: prefixIdentifiers(INDEX_NAMES, actualPrefix),\n\t};\n}\n\nexport const DEFAULT_SQLITE_SCHEMA = createSqliteSchema();\n"]}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { SqliteExecutor } from "@diffra-ai/chord/sqlite";
|
|
2
|
+
import type { Cell } from "./rows.ts";
|
|
3
|
+
/** The rows `sql` reads for `values`, given as its one JSON array parameter (`json_each(?)`): one statement per chunk. */
|
|
4
|
+
export declare function readRows<T extends object>(executor: SqliteExecutor, sql: string, values: readonly (Cell | readonly Cell[])[]): Promise<T[]>;
|
|
5
|
+
/** Runs `sql` (a deletion) for `values`, given as its one JSON array parameter: one statement per chunk. */
|
|
6
|
+
export declare function runForEach(executor: SqliteExecutor, sql: string, values: readonly Cell[]): Promise<void>;
|
|
7
|
+
/**
|
|
8
|
+
* Inserts `rows` (one cell per column, in order) into `table`, then `conflict` (an upsert's clause): the rows of little
|
|
9
|
+
* text from one JSON array parameter per chunk, the same SQL text whatever their number; the large ones bound column by
|
|
10
|
+
* column.
|
|
11
|
+
*/
|
|
12
|
+
export declare function insertRows(executor: SqliteExecutor, table: string, columns: readonly string[], rows: readonly (readonly Cell[])[], conflict?: string): Promise<void>;
|
|
13
|
+
//# sourceMappingURL=statements.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"statements.d.ts","sourceRoot":"","sources":["../../../src/storage/sqlite/statements.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAC;AAC9D,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAEtC,0HAA0H;AAC1H,wBAAsB,QAAQ,CAAC,CAAC,SAAS,MAAM,EAC9C,QAAQ,EAAE,cAAc,EACxB,GAAG,EAAE,MAAM,EACX,MAAM,EAAE,SAAS,CAAC,IAAI,GAAG,SAAS,IAAI,EAAE,CAAC,EAAE,GACzC,OAAO,CAAC,CAAC,EAAE,CAAC,CAMd;AAED,4GAA4G;AAC5G,wBAAsB,UAAU,CAAC,QAAQ,EAAE,cAAc,EAAE,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,SAAS,IAAI,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAE9G;AAMD;;;;GAIG;AACH,wBAAsB,UAAU,CAC/B,QAAQ,EAAE,cAAc,EACxB,KAAK,EAAE,MAAM,EACb,OAAO,EAAE,SAAS,MAAM,EAAE,EAC1B,IAAI,EAAE,SAAS,CAAC,SAAS,IAAI,EAAE,CAAC,EAAE,EAClC,QAAQ,SAAK,GACX,OAAO,CAAC,IAAI,CAAC,CAiBf"}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
// The multi-row statements of a commit call, few whatever the number of rows: rows as one JSON array parameter read
|
|
2
|
+
// through `json_each(?)` (one SQL text per table, no bound-parameter limit), and large rows bound column by column in
|
|
3
|
+
// multi-row `VALUES` of a few fixed sizes, so their already JSON-encoded records are not escaped a second time.
|
|
4
|
+
/** The rows `sql` reads for `values`, given as its one JSON array parameter (`json_each(?)`): one statement per chunk. */
|
|
5
|
+
export async function readRows(executor, sql, values) {
|
|
6
|
+
const rows = [];
|
|
7
|
+
for (const array of jsonArrays(values.map((value) => JSON.stringify(value)))) {
|
|
8
|
+
rows.push(...(await executor.all(sql, array)));
|
|
9
|
+
}
|
|
10
|
+
return rows;
|
|
11
|
+
}
|
|
12
|
+
/** Runs `sql` (a deletion) for `values`, given as its one JSON array parameter: one statement per chunk. */
|
|
13
|
+
export async function runForEach(executor, sql, values) {
|
|
14
|
+
for (const array of jsonArrays(values.map((value) => JSON.stringify(value))))
|
|
15
|
+
await executor.run(sql, array);
|
|
16
|
+
}
|
|
17
|
+
// Rows whose string cells hold more characters than this (before escaping) go bound: a second JSON escaping of their
|
|
18
|
+
// records costs more than the statements they need.
|
|
19
|
+
const LARGE_ROW_CHARACTERS = 8 * 1024;
|
|
20
|
+
/**
|
|
21
|
+
* Inserts `rows` (one cell per column, in order) into `table`, then `conflict` (an upsert's clause): the rows of little
|
|
22
|
+
* text from one JSON array parameter per chunk, the same SQL text whatever their number; the large ones bound column by
|
|
23
|
+
* column.
|
|
24
|
+
*/
|
|
25
|
+
export async function insertRows(executor, table, columns, rows, conflict = "") {
|
|
26
|
+
const small = [];
|
|
27
|
+
const large = [];
|
|
28
|
+
for (const row of rows) {
|
|
29
|
+
let text = 0;
|
|
30
|
+
for (const cell of row)
|
|
31
|
+
if (typeof cell === "string")
|
|
32
|
+
text += cell.length;
|
|
33
|
+
if (text > LARGE_ROW_CHARACTERS)
|
|
34
|
+
large.push(row);
|
|
35
|
+
else
|
|
36
|
+
small.push(JSON.stringify(row));
|
|
37
|
+
}
|
|
38
|
+
const names = columns.join(", ");
|
|
39
|
+
if (small.length > 0) {
|
|
40
|
+
const cells = columns.map((_, index) => `json_extract(item.value, '$[${index}]')`).join(", ");
|
|
41
|
+
// `WHERE true` keeps SQLite from reading an upsert's `ON` as a join constraint of the `SELECT`.
|
|
42
|
+
const sql = `INSERT INTO ${table} (${names}) SELECT ${cells} FROM json_each(?) AS item WHERE true ${conflict}`;
|
|
43
|
+
for (const array of jsonArrays(small))
|
|
44
|
+
await executor.run(sql, array);
|
|
45
|
+
}
|
|
46
|
+
await insertBound(executor, `INSERT INTO ${table} (${names}) VALUES`, columns.length, large, conflict);
|
|
47
|
+
}
|
|
48
|
+
// Durable Objects bind at most 100 parameters per statement.
|
|
49
|
+
const MAX_PARAMETERS = 100;
|
|
50
|
+
/**
|
|
51
|
+
* Inserts `rows` with `head` (`INSERT INTO t (columns) VALUES`), `width` cells each, in statements of 1, 2, 4, ... rows
|
|
52
|
+
* up to `MAX_PARAMETERS` cells: few statements, and at most a handful of SQL texts per table for prepared statements.
|
|
53
|
+
*/
|
|
54
|
+
async function insertBound(executor, head, width, rows, conflict) {
|
|
55
|
+
const row = `(${new Array(width).fill("?").join(", ")})`;
|
|
56
|
+
let size = 1;
|
|
57
|
+
while (size * 2 * width <= MAX_PARAMETERS)
|
|
58
|
+
size *= 2;
|
|
59
|
+
// `size` only shrinks: halved before a chunk to fit the rows left, it is also what the loop then steps over.
|
|
60
|
+
for (let start = 0; start < rows.length; start += size) {
|
|
61
|
+
while (size > rows.length - start)
|
|
62
|
+
size /= 2;
|
|
63
|
+
const chunk = rows.slice(start, start + size);
|
|
64
|
+
await executor.run(`${head} ${new Array(size).fill(row).join(", ")} ${conflict}`, ...chunk.flat());
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
// Durable Objects refuse a string over 2 MB, a bound parameter too; 512 Ki characters are at most 1.5 MB of UTF-8.
|
|
68
|
+
const MAX_ARRAY_CHARACTERS = 512 * 1024;
|
|
69
|
+
/** JSON values `parts`, in order, as JSON arrays of at most `MAX_ARRAY_CHARACTERS` each (a longer value alone). */
|
|
70
|
+
function jsonArrays(parts) {
|
|
71
|
+
const arrays = [];
|
|
72
|
+
let chunk = [];
|
|
73
|
+
// The array's text: its brackets, its parts and the commas between them.
|
|
74
|
+
let length = 2;
|
|
75
|
+
for (const part of parts) {
|
|
76
|
+
if (chunk.length > 0 && length + 1 + part.length > MAX_ARRAY_CHARACTERS) {
|
|
77
|
+
arrays.push(`[${chunk.join(",")}]`);
|
|
78
|
+
chunk = [];
|
|
79
|
+
length = 2;
|
|
80
|
+
}
|
|
81
|
+
length += (chunk.length > 0 ? 1 : 0) + part.length;
|
|
82
|
+
chunk.push(part);
|
|
83
|
+
}
|
|
84
|
+
if (chunk.length > 0)
|
|
85
|
+
arrays.push(`[${chunk.join(",")}]`);
|
|
86
|
+
return arrays;
|
|
87
|
+
}
|
|
88
|
+
//# sourceMappingURL=statements.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file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AAC,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,MAAM,CAAC;QACnD,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAClB,CAAC;IACD,IAAI,KAAK,CAAC,MAAM,GAAG,CAAC;QAAE,MAAM,CAAC,IAAI,CAAC,IAAI,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;IAC1D,OAAO,MAAM,CAAC;AACf,CAAC","sourcesContent":["// The multi-row statements of a commit call, few whatever the number of rows: rows as one JSON array parameter read\n// through `json_each(?)` (one SQL text per table, no bound-parameter limit), and large rows bound column by column in\n// multi-row `VALUES` of a few fixed sizes, so their already JSON-encoded records are not escaped a second time.\n\nimport type { SqliteExecutor } from \"@diffra-ai/chord/sqlite\";\nimport type { Cell } from \"./rows.ts\";\n\n/** The rows `sql` reads for `values`, given as its one JSON array parameter (`json_each(?)`): one statement per chunk. */\nexport async function readRows<T extends object>(\n\texecutor: SqliteExecutor,\n\tsql: string,\n\tvalues: readonly (Cell | readonly Cell[])[],\n): Promise<T[]> {\n\tconst rows: T[] = [];\n\tfor (const array of jsonArrays(values.map((value) => JSON.stringify(value)))) {\n\t\trows.push(...(await executor.all<T>(sql, array)));\n\t}\n\treturn rows;\n}\n\n/** Runs `sql` (a deletion) for `values`, given as its one JSON array parameter: one statement per chunk. */\nexport async function runForEach(executor: SqliteExecutor, sql: string, values: readonly Cell[]): Promise<void> {\n\tfor (const array of jsonArrays(values.map((value) => JSON.stringify(value)))) await executor.run(sql, array);\n}\n\n// Rows whose string cells hold more characters than this (before escaping) go bound: a second JSON escaping of their\n// records costs more than the statements they need.\nconst LARGE_ROW_CHARACTERS = 8 * 1024;\n\n/**\n * Inserts `rows` (one cell per column, in order) into `table`, then `conflict` (an upsert's clause): the rows of little\n * text from one JSON array parameter per chunk, the same SQL text whatever their number; the large ones bound column by\n * column.\n */\nexport async function insertRows(\n\texecutor: SqliteExecutor,\n\ttable: string,\n\tcolumns: readonly string[],\n\trows: readonly (readonly Cell[])[],\n\tconflict = \"\",\n): Promise<void> {\n\tconst small: string[] = [];\n\tconst large: (readonly Cell[])[] = [];\n\tfor (const row of rows) {\n\t\tlet text = 0;\n\t\tfor (const cell of row) if (typeof cell === \"string\") text += cell.length;\n\t\tif (text > LARGE_ROW_CHARACTERS) large.push(row);\n\t\telse small.push(JSON.stringify(row));\n\t}\n\tconst names = columns.join(\", \");\n\tif (small.length > 0) {\n\t\tconst cells = columns.map((_, index) => `json_extract(item.value, '$[${index}]')`).join(\", \");\n\t\t// `WHERE true` keeps SQLite from reading an upsert's `ON` as a join constraint of the `SELECT`.\n\t\tconst sql = `INSERT INTO ${table} (${names}) SELECT ${cells} FROM json_each(?) AS item WHERE true ${conflict}`;\n\t\tfor (const array of jsonArrays(small)) await executor.run(sql, array);\n\t}\n\tawait insertBound(executor, `INSERT INTO ${table} (${names}) VALUES`, columns.length, large, conflict);\n}\n\n// Durable Objects bind at most 100 parameters per statement.\nconst MAX_PARAMETERS = 100;\n\n/**\n * Inserts `rows` with `head` (`INSERT INTO t (columns) VALUES`), `width` cells each, in statements of 1, 2, 4, ... rows\n * up to `MAX_PARAMETERS` cells: few statements, and at most a handful of SQL texts per table for prepared statements.\n */\nasync function insertBound(\n\texecutor: SqliteExecutor,\n\thead: string,\n\twidth: number,\n\trows: readonly (readonly Cell[])[],\n\tconflict: string,\n): Promise<void> {\n\tconst row = `(${new Array(width).fill(\"?\").join(\", \")})`;\n\tlet size = 1;\n\twhile (size * 2 * width <= MAX_PARAMETERS) size *= 2;\n\t// `size` only shrinks: halved before a chunk to fit the rows left, it is also what the loop then steps over.\n\tfor (let start = 0; start < rows.length; start += size) {\n\t\twhile (size > rows.length - start) size /= 2;\n\t\tconst chunk = rows.slice(start, start + size);\n\t\tawait executor.run(`${head} ${new Array(size).fill(row).join(\", \")} ${conflict}`, ...chunk.flat());\n\t}\n}\n\n// Durable Objects refuse a string over 2 MB, a bound parameter too; 512 Ki characters are at most 1.5 MB of UTF-8.\nconst MAX_ARRAY_CHARACTERS = 512 * 1024;\n\n/** JSON values `parts`, in order, as JSON arrays of at most `MAX_ARRAY_CHARACTERS` each (a longer value alone). */\nfunction jsonArrays(parts: readonly string[]): string[] {\n\tconst arrays: string[] = [];\n\tlet chunk: string[] = [];\n\t// The array's text: its brackets, its parts and the commas between them.\n\tlet length = 2;\n\tfor (const part of parts) {\n\t\tif (chunk.length > 0 && length + 1 + part.length > MAX_ARRAY_CHARACTERS) {\n\t\t\tarrays.push(`[${chunk.join(\",\")}]`);\n\t\t\tchunk = [];\n\t\t\tlength = 2;\n\t\t}\n\t\tlength += (chunk.length > 0 ? 1 : 0) + part.length;\n\t\tchunk.push(part);\n\t}\n\tif (chunk.length > 0) arrays.push(`[${chunk.join(\",\")}]`);\n\treturn arrays;\n}\n"]}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import type { Context } from "@diffra-ai/chord/context";
|
|
2
|
+
import type { JsonValue } from "@diffra-ai/chord/json";
|
|
3
|
+
import type { SqliteDatabase } from "@diffra-ai/chord/sqlite";
|
|
4
|
+
import type { CommitResult, ConversationId, ConversationQuery, ConversationRecord, Cursor, DocumentAddress, DocumentId, DocumentPoint, DocumentQuery, DocumentRecord, EntryId, EntryQuery, EntryRecord, Id, Page, Seq, Storage, StorageWrite, StoredDocument, SubmissionId, SubmissionQuery, SubmissionRecord, TaskId, TaskQuery, TaskRecord } from "../../types.ts";
|
|
5
|
+
type StoredTask = TaskRecord<JsonValue, JsonValue, JsonValue>;
|
|
6
|
+
export type SqliteStorageOptions = {
|
|
7
|
+
/**
|
|
8
|
+
* Prefix for every table and index in the durable schema. It must be a SQLite identifier and must not use
|
|
9
|
+
* SQLite's reserved `sqlite_` prefix. Existing data is not migrated when this changes.
|
|
10
|
+
*/
|
|
11
|
+
readonly prefix?: string;
|
|
12
|
+
};
|
|
13
|
+
/** Portable SQLite implementation of the Pico storage contract. */
|
|
14
|
+
export declare class SqliteStorage implements Storage {
|
|
15
|
+
private readonly db;
|
|
16
|
+
private readonly schema;
|
|
17
|
+
private nextId;
|
|
18
|
+
private closed;
|
|
19
|
+
private closing;
|
|
20
|
+
private admittedReads;
|
|
21
|
+
private readsDrained;
|
|
22
|
+
private constructor();
|
|
23
|
+
/** Initialize storage over an owned SQLite database facade. */
|
|
24
|
+
static open(db: SqliteDatabase, options?: SqliteStorageOptions): Promise<SqliteStorage>;
|
|
25
|
+
/**
|
|
26
|
+
* Commit `batches` in one SQL transaction, each with its own seq. Each batch is checked before it writes anything,
|
|
27
|
+
* against the state the earlier ones left, and the first one refused ends the batch: the transaction commits the ones
|
|
28
|
+
* before it. No savepoints, which Durable Objects do not allow: the checks run before the writes instead. The checks
|
|
29
|
+
* read the stored state of all batches up front and run in memory, and the accepted batches are written per table in
|
|
30
|
+
* multi-row statements (`commit.ts`), so a call costs a few statements whatever its number of batches. A batch with a
|
|
31
|
+
* copy reads the copy's source from the database: the batches before it are written first, so a call of many fork
|
|
32
|
+
* batches costs a few statements per fork.
|
|
33
|
+
*/
|
|
34
|
+
commit(batches: readonly (readonly StorageWrite[])[], receive: (index: number, seq: Seq) => void, _context: Context): Promise<CommitResult>;
|
|
35
|
+
private readMetadata;
|
|
36
|
+
private writeMetadata;
|
|
37
|
+
/**
|
|
38
|
+
* Durable's own checks of one batch, against what the batches before it left: its document actions, or its refusal.
|
|
39
|
+
* Only these checks refuse; a failure of a database call rejects. A copy reads its source from the database, so the
|
|
40
|
+
* batches before it are written first.
|
|
41
|
+
*/
|
|
42
|
+
private checkBatch;
|
|
43
|
+
mintId<I extends Id<string>>(): Promise<I>;
|
|
44
|
+
conversation(id: ConversationId, _context: Context): Promise<ConversationRecord | undefined>;
|
|
45
|
+
scanConversations(query: ConversationQuery, limit: number, cursor: Cursor | undefined, _context: Context): Promise<Page<ConversationRecord, Cursor>>;
|
|
46
|
+
entry(id: EntryId, context: Context): Promise<{
|
|
47
|
+
readonly entry: EntryRecord;
|
|
48
|
+
readonly commitSeq: Seq;
|
|
49
|
+
} | undefined>;
|
|
50
|
+
entry(conversationId: ConversationId, id: EntryId, context: Context): Promise<{
|
|
51
|
+
readonly entry: EntryRecord;
|
|
52
|
+
readonly commitSeq: Seq;
|
|
53
|
+
} | undefined>;
|
|
54
|
+
findLatestHeadMarker(conversationId: ConversationId, atOrBeforeEntryId: EntryId | undefined, _context: Context): Promise<(EntryRecord & {
|
|
55
|
+
readonly head: EntryId;
|
|
56
|
+
}) | undefined>;
|
|
57
|
+
scanEntries(query: EntryQuery, limit: number, cursor: Cursor | undefined, _context: Context): Promise<Page<EntryRecord, Cursor>>;
|
|
58
|
+
private readEntry;
|
|
59
|
+
private readLatestHeadMarker;
|
|
60
|
+
private readEntries;
|
|
61
|
+
/** Oldest first: the fork chain's segments from the root conversation forward, each up to its fork point. */
|
|
62
|
+
private readEntriesAscending;
|
|
63
|
+
task(id: TaskId, _context: Context): Promise<StoredTask | undefined>;
|
|
64
|
+
scanTasks(query: TaskQuery, limit: number, cursor: Cursor | undefined, _context: Context): Promise<Page<StoredTask, Cursor>>;
|
|
65
|
+
submission(id: SubmissionId, _context: Context): Promise<SubmissionRecord | undefined>;
|
|
66
|
+
scanSubmissions(query: SubmissionQuery, limit: number, cursor: Cursor | undefined, _context: Context): Promise<Page<SubmissionRecord, Cursor>>;
|
|
67
|
+
submissionByRequest(conversationId: ConversationId, requestId: string, _context: Context): Promise<SubmissionRecord | undefined>;
|
|
68
|
+
findDocument(address: DocumentAddress, at: DocumentPoint, _context: Context): Promise<DocumentRecord | undefined>;
|
|
69
|
+
document(id: DocumentId, at: DocumentPoint, _context: Context): Promise<StoredDocument | undefined>;
|
|
70
|
+
scanDocuments(query: DocumentQuery, limit: number, cursor: Cursor | undefined, _context: Context): Promise<Page<DocumentRecord, Cursor>>;
|
|
71
|
+
close(_context: Context): Promise<void>;
|
|
72
|
+
private closeDatabase;
|
|
73
|
+
/**
|
|
74
|
+
* Run a read that issues several queries. Close waits for admitted reads, so their later queries never reach a
|
|
75
|
+
* closed database. Single-query reads and transactions are already ordered before close by the database.
|
|
76
|
+
*/
|
|
77
|
+
private admitRead;
|
|
78
|
+
private readConversation;
|
|
79
|
+
private materializeDocument;
|
|
80
|
+
private candidateNextId;
|
|
81
|
+
/** Resolve each copy to a base of its source's state before this batch, which may not change the source. */
|
|
82
|
+
private resolveCopies;
|
|
83
|
+
private assertOpen;
|
|
84
|
+
}
|
|
85
|
+
export {};
|
|
86
|
+
//# sourceMappingURL=storage.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"storage.d.ts","sourceRoot":"","sources":["../../../src/storage/sqlite/storage.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,0BAA0B,CAAC;AAExD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AACvD,OAAO,KAAK,EAAE,cAAc,EAA+B,MAAM,yBAAyB,CAAC;AAG3F,OAAO,KAAK,EACX,YAAY,EACZ,cAAc,EACd,iBAAiB,EACjB,kBAAkB,EAClB,MAAM,EACN,eAAe,EAEf,UAAU,EACV,aAAa,EACb,aAAa,EACb,cAAc,EACd,OAAO,EACP,UAAU,EACV,WAAW,EACX,EAAE,EAEF,IAAI,EAEJ,GAAG,EACH,OAAO,EACP,YAAY,EACZ,cAAc,EACd,YAAY,EACZ,eAAe,EACf,gBAAgB,EAChB,MAAM,EACN,SAAS,EACT,UAAU,EACV,MAAM,gBAAgB,CAAC;AAOxB,KAAK,UAAU,GAAG,UAAU,CAAC,SAAS,EAAE,SAAS,EAAE,SAAS,CAAC,CAAC;AAW9D,MAAM,MAAM,oBAAoB,GAAG;IAClC;;;OAGG;IACH,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;CACzB,CAAC;AAwDF,mEAAmE;AACnE,qBAAa,aAAc,YAAW,OAAO;IAC5C,OAAO,CAAC,QAAQ,C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