@earendil-works/pi-durable 1.5.0 → 1.5.1
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 +18 -0
- package/README.md +17 -4
- package/dist/codemode/codemode.d.ts +2 -1
- package/dist/codemode/codemode.d.ts.map +1 -1
- package/dist/codemode/codemode.js +1 -37
- package/dist/codemode/codemode.js.map +1 -1
- package/dist/codemode/models.d.ts +2 -1
- package/dist/codemode/models.d.ts.map +1 -1
- package/dist/codemode/models.js.map +1 -1
- package/dist/documents.d.ts +1 -1
- package/dist/documents.d.ts.map +1 -1
- package/dist/documents.js +1 -1
- package/dist/documents.js.map +1 -1
- package/dist/entries.d.ts +1 -1
- package/dist/entries.d.ts.map +1 -1
- package/dist/entries.js.map +1 -1
- package/dist/env/index.d.ts +1 -1
- package/dist/env/index.d.ts.map +1 -1
- package/dist/env/index.js.map +1 -1
- package/dist/env/node-watch.d.ts +1 -1
- package/dist/env/node-watch.d.ts.map +1 -1
- package/dist/env/node-watch.js.map +1 -1
- package/dist/env/node.d.ts +1 -1
- package/dist/env/node.d.ts.map +1 -1
- package/dist/env/node.js.map +1 -1
- package/dist/harness/agent.d.ts.map +1 -1
- package/dist/harness/agent.js +27 -1
- package/dist/harness/agent.js.map +1 -1
- package/dist/harness/compaction.d.ts +8 -3
- package/dist/harness/compaction.d.ts.map +1 -1
- package/dist/harness/compaction.js +21 -9
- package/dist/harness/compaction.js.map +1 -1
- package/dist/harness/context.d.ts +1 -1
- package/dist/harness/context.d.ts.map +1 -1
- package/dist/harness/context.js.map +1 -1
- package/dist/harness/define.d.ts +1 -1
- package/dist/harness/define.d.ts.map +1 -1
- package/dist/harness/define.js.map +1 -1
- package/dist/harness/generation.d.ts +1 -1
- package/dist/harness/generation.d.ts.map +1 -1
- package/dist/harness/generation.js +6 -4
- package/dist/harness/generation.js.map +1 -1
- package/dist/harness/harness.d.ts +1 -1
- package/dist/harness/harness.d.ts.map +1 -1
- package/dist/harness/harness.js.map +1 -1
- package/dist/harness/inbox.d.ts +2 -1
- package/dist/harness/inbox.d.ts.map +1 -1
- package/dist/harness/inbox.js +1 -1
- package/dist/harness/inbox.js.map +1 -1
- package/dist/harness/json.d.ts +1 -1
- package/dist/harness/json.d.ts.map +1 -1
- package/dist/harness/json.js.map +1 -1
- package/dist/harness/live.d.ts +2 -1
- package/dist/harness/live.d.ts.map +1 -1
- package/dist/harness/live.js.map +1 -1
- package/dist/harness/partial-changes.d.ts +1 -1
- package/dist/harness/partial-changes.d.ts.map +1 -1
- package/dist/harness/partial-changes.js +1 -0
- package/dist/harness/partial-changes.js.map +1 -1
- package/dist/harness/prompt.d.ts +1 -1
- package/dist/harness/prompt.d.ts.map +1 -1
- package/dist/harness/prompt.js.map +1 -1
- package/dist/harness/provider.d.ts +1 -1
- package/dist/harness/provider.d.ts.map +1 -1
- package/dist/harness/provider.js.map +1 -1
- package/dist/harness/registry-reader.d.ts +1 -1
- package/dist/harness/registry-reader.d.ts.map +1 -1
- package/dist/harness/registry-reader.js.map +1 -1
- package/dist/harness/scheduler.d.ts +2 -1
- package/dist/harness/scheduler.d.ts.map +1 -1
- package/dist/harness/scheduler.js +42 -13
- package/dist/harness/scheduler.js.map +1 -1
- package/dist/harness/submissions.d.ts +1 -1
- package/dist/harness/submissions.d.ts.map +1 -1
- package/dist/harness/submissions.js +1 -1
- package/dist/harness/submissions.js.map +1 -1
- package/dist/harness/task-graph.d.ts +3 -1
- package/dist/harness/task-graph.d.ts.map +1 -1
- package/dist/harness/task-graph.js +1 -1
- package/dist/harness/task-graph.js.map +1 -1
- package/dist/harness/tool.d.ts +1 -1
- package/dist/harness/tool.d.ts.map +1 -1
- package/dist/harness/tool.js +1 -1
- package/dist/harness/tool.js.map +1 -1
- package/dist/harness/transcript.d.ts +1 -1
- package/dist/harness/transcript.d.ts.map +1 -1
- package/dist/harness/transcript.js.map +1 -1
- package/dist/harness/types.d.ts +21 -4
- package/dist/harness/types.d.ts.map +1 -1
- package/dist/harness/types.js.map +1 -1
- package/dist/harness/usage.d.ts +2 -1
- package/dist/harness/usage.d.ts.map +1 -1
- package/dist/harness/usage.js +1 -1
- package/dist/harness/usage.js.map +1 -1
- package/dist/harness/util.d.ts +1 -1
- package/dist/harness/util.d.ts.map +1 -1
- package/dist/harness/util.js.map +1 -1
- package/dist/harness/view.d.ts +2 -1
- package/dist/harness/view.d.ts.map +1 -1
- package/dist/harness/view.js +1 -1
- package/dist/harness/view.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/session/cached-storage.d.ts +2 -1
- package/dist/session/cached-storage.d.ts.map +1 -1
- package/dist/session/cached-storage.js.map +1 -1
- package/dist/session/forks.d.ts +1 -1
- package/dist/session/forks.d.ts.map +1 -1
- package/dist/session/forks.js.map +1 -1
- package/dist/session/keys.d.ts +2 -1
- package/dist/session/keys.d.ts.map +1 -1
- package/dist/session/keys.js.map +1 -1
- package/dist/session/session.d.ts +3 -1
- package/dist/session/session.d.ts.map +1 -1
- package/dist/session/session.js +1 -1
- package/dist/session/session.js.map +1 -1
- package/dist/session/transaction.d.ts +4 -3
- package/dist/session/transaction.d.ts.map +1 -1
- package/dist/session/transaction.js +3 -3
- package/dist/session/transaction.js.map +1 -1
- package/dist/session/writer.d.ts +1 -1
- package/dist/session/writer.d.ts.map +1 -1
- package/dist/session/writer.js.map +1 -1
- package/dist/storage/indexeddb.d.ts +2 -1
- package/dist/storage/indexeddb.d.ts.map +1 -1
- package/dist/storage/indexeddb.js.map +1 -1
- package/dist/storage/jsonl/index.d.ts +1 -1
- package/dist/storage/jsonl/index.d.ts.map +1 -1
- package/dist/storage/jsonl/index.js +1 -1
- package/dist/storage/jsonl/index.js.map +1 -1
- package/dist/storage/jsonl/node.d.ts +3 -3
- package/dist/storage/jsonl/node.d.ts.map +1 -1
- package/dist/storage/jsonl/node.js +2 -2
- package/dist/storage/jsonl/node.js.map +1 -1
- package/dist/storage/jsonl/storage.d.ts +32 -3
- package/dist/storage/jsonl/storage.d.ts.map +1 -1
- package/dist/storage/jsonl/storage.js +70 -19
- package/dist/storage/jsonl/storage.js.map +1 -1
- package/dist/storage/memory.d.ts +2 -1
- package/dist/storage/memory.d.ts.map +1 -1
- package/dist/storage/memory.js.map +1 -1
- 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/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/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 +12 -11
- package/dist/storage/sqlite/storage.d.ts.map +1 -1
- package/dist/storage/sqlite/storage.js +44 -259
- package/dist/storage/sqlite/storage.js.map +1 -1
- package/dist/storage/store/commit.d.ts +2 -2
- package/dist/storage/store/commit.d.ts.map +1 -1
- package/dist/storage/store/commit.js +1 -1
- package/dist/storage/store/commit.js.map +1 -1
- package/dist/storage/store/documents.d.ts +1 -1
- package/dist/storage/store/documents.d.ts.map +1 -1
- package/dist/storage/store/documents.js +1 -1
- package/dist/storage/store/documents.js.map +1 -1
- package/dist/storage/store/queries.d.ts +2 -2
- package/dist/storage/store/queries.d.ts.map +1 -1
- package/dist/storage/store/queries.js.map +1 -1
- package/dist/storage/store/storage.d.ts +3 -2
- package/dist/storage/store/storage.d.ts.map +1 -1
- package/dist/storage/store/storage.js +1 -1
- package/dist/storage/store/storage.js.map +1 -1
- package/dist/storage/store/tables.d.ts +31 -31
- package/dist/storage/store/tables.d.ts.map +1 -1
- package/dist/storage/store/tables.js +1 -1
- package/dist/storage/store/tables.js.map +1 -1
- package/dist/testing/commit-writes.d.ts +1 -1
- package/dist/testing/commit-writes.d.ts.map +1 -1
- package/dist/testing/commit-writes.js.map +1 -1
- package/dist/testing/env-conformance.js.map +1 -1
- package/dist/testing/storage-benchmark.js.map +1 -1
- package/dist/testing/storage-conformance.js.map +1 -1
- package/dist/tool-search/tool-search.d.ts +2 -2
- package/dist/tool-search/tool-search.d.ts.map +1 -1
- package/dist/tool-search/tool-search.js +18 -6
- package/dist/tool-search/tool-search.js.map +1 -1
- package/dist/tools/bash.d.ts +1 -1
- package/dist/tools/bash.d.ts.map +1 -1
- package/dist/tools/bash.js.map +1 -1
- package/dist/tools/file-mutation-queue.d.ts +1 -1
- package/dist/tools/file-mutation-queue.d.ts.map +1 -1
- package/dist/tools/file-mutation-queue.js.map +1 -1
- package/dist/tools/path-utils.d.ts +1 -1
- package/dist/tools/path-utils.d.ts.map +1 -1
- package/dist/tools/path-utils.js.map +1 -1
- package/dist/tools/read.js.map +1 -1
- package/dist/types.d.ts +6 -2
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/package.json +6 -6
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"queries.js","sourceRoot":"","sources":["../../../src/storage/store/queries.ts"],"names":[],"mappings":"AAAA,mHAAmH;AACnH,qHAAqH;AACrH,oHAAoH;AAgBpH,MAAM,SAAS,GAAU,EAAE,OAAO,EAAE,CAAC,IAAI,CAAC,EAAE,SAAS,EAAE,KAAK,EAAE,CAAC;AAC/D,MAAM,UAAU,GAAU,EAAE,OAAO,EAAE,CAAC,IAAI,CAAC,EAAE,SAAS,EAAE,MAAM,EAAE,CAAC;AAEjE,yCAAyC;AACzC,MAAM,EAAE,GAAG,CAAC,IAAI,CAAC,CAAC;AAElB,0EAA0E;AAC1E,MAAM,GAAG,GAAG,CAAC,CAAC;AAEd;;;GAGG;AACH,MAAM,OAAO,YAAY;IACf,MAAM,CAAa;IAC5B,4GAA4G;IACnG,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AAC,CAAC;QACzD,UAAU,EAAE;YACX,GAAG,EAAE,KAAK,CAAC,YAAY,CAAC,EAAE,EAAE,EAAE,EAAE,EAAE,CAAC,iBAAiB,EAAE,GAAG,CAAC,EAAE,EAAE,UAAU,CAAC;YACzE,UAAU,EAAE,KAAK,CAAC,YAAY,CAC7B,EAAE,EACF,EAAE,GAAG,EAAE,CAAC,EAAE,EAAE,EAAE,CAAC,iBAAiB,EAAE,GAAG,CAAC,EAAE,EAAE,EAAE,GAAG,EAAE,CAAC,IAAI,EAAE,GAAG,CAAC,EAAE,CAAC,EAAE,EACjE,UAAU,CACV;SACD;QACD,KAAK,EAAE,IAAI,YAAY,CAAC,MAAM,CAAC,KAAK,CAAC;QACrC,WAAW,EAAE,IAAI,YAAY,CAAC,MAAM,CAAC,WAAW,CAAC;KACjD,CAAC;AACH,CAAC","sourcesContent":["// StoreStorage's reads as the store's queries (slice 6b D2, §2.4), compiled once from the store's query vocabulary\n// into SQL over the declared tables: no SQL is rendered per call, and a read selects only the record cell (by id, an\n// entry's commit seq too; each column returned costs) and parses one JSON text per record, as `SqliteStorage`'s do.\n\nimport type { Context } from \"@earendil-works/chord\";\nimport type { Order, OwnerTable, WhereNode } from \"@earendil-works/chord/next\";\nimport type { SqliteExecutor, SqliteValue } from \"@earendil-works/chord/sqlite\";\nimport type { CommitTables } from \"./commit.ts\";\n\n/**\n * A stored row as a query selects it: the record cell, its version (selected only once the column has versions past\n * 1), and an entry's commit seq.\n */\ntype RecordRow = { readonly record: string; readonly record$v?: number; readonly commit_seq?: number };\n\n/** One condition of a read: a column, how it compares, its value; a call site keeps one order of them. */\nexport type Condition = readonly [string, \"eq\" | \"gt\" | \"lt\" | \"gte\" | \"lte\", SqliteValue];\n\nconst ASCENDING: Order = { columns: [\"id\"], direction: \"asc\" };\nconst DESCENDING: Order = { columns: [\"id\"], direction: \"desc\" };\n\n/** The columns of a read of ids only. */\nconst ID = [\"id\"];\n\n/** A placeholder value: a query's shape binds its values at each call. */\nconst ANY = 0;\n\n/**\n * One table's compiled reads: by id (with the `byIdExtra` columns), and by shape (conditions in binding order, an\n * order; the record only), each shape compiled at its first use.\n */\nexport class TableQueries {\n\treadonly #table: OwnerTable;\n\t/** The record column's read of a cell at a version past 1; `undefined` while the column is at version 1. */\n\treadonly #versioned: ((text: string, version: number, context: Context) => unknown) | undefined;\n\treadonly #byId: string;\n\treadonly #shapes = new Map<string, string>();\n\treadonly #columns: readonly string[];\n\n\tconstructor(table: OwnerTable, byIdExtra: readonly string[] = []) {\n\t\tthis.#table = table;\n\t\tconst versioned = table.jsonVersion(\"record\") > 1;\n\t\tthis.#versioned = versioned ? table.reader(\"record\") : undefined;\n\t\tthis.#columns = versioned ? [\"record\", \"record$v\"] : [\"record\"];\n\t\tthis.#byId = table.prepareGet([...this.#columns, ...byIdExtra]);\n\t}\n\n\t/** The row with `id`, `undefined` when absent. */\n\tbyId(executor: Pick<SqliteExecutor, \"get\">, id: number): Promise<RecordRow | undefined> {\n\t\treturn executor.get<RecordRow>(this.#byId, id);\n\t}\n\n\t/** Up to `limit` rows whose `conditions` hold, by id in `direction`. */\n\tselect(\n\t\texecutor: Pick<SqliteExecutor, \"all\">,\n\t\tconditions: readonly Condition[],\n\t\tdirection: \"ascending\" | \"descending\",\n\t\tlimit: number,\n\t): Promise<RecordRow[]> {\n\t\tconst sql = this.#shape(conditions, direction, \"many\");\n\t\treturn executor.all<RecordRow>(sql, ...conditions.map(([, , value]) => value), limit);\n\t}\n\n\t/** The first row whose `conditions` hold, by id in `direction`; `undefined` when none does. */\n\tfirst(\n\t\texecutor: Pick<SqliteExecutor, \"get\">,\n\t\tconditions: readonly Condition[],\n\t\tdirection: \"ascending\" | \"descending\",\n\t): Promise<RecordRow | undefined> {\n\t\tconst sql = this.#shape(conditions, direction, \"first\");\n\t\treturn executor.get<RecordRow>(sql, ...conditions.map(([, , value]) => value));\n\t}\n\n\t/** A row's record, read as its column's (version checked, migrated on access). */\n\trecord<T>(row: RecordRow, context: Context): T {\n\t\tconst versioned = this.#versioned;\n\t\t// The cell holds a record of this table the storage wrote; at version 1 it is that JSON (`OwnerTable.reader`).\n\t\treturn (versioned === undefined ? JSON.parse(row.record) : versioned(row.record, row.record$v!, context)) as T;\n\t}\n\n\t/** Appends the records of `rows` to `into`, in order, each read as `record` reads it (one check per call). */\n\trecords<T>(rows: readonly RecordRow[], into: T[], context: Context): void {\n\t\tconst versioned = this.#versioned;\n\t\tif (versioned === undefined) {\n\t\t\tfor (const row of rows) into.push(JSON.parse(row.record) as T);\n\t\t\treturn;\n\t\t}\n\t\tfor (const row of rows) into.push(versioned(row.record, row.record$v!, context) as T);\n\t}\n\n\t/** The compiled read of a shape: its conditions' columns and comparisons, the direction, one row or many. */\n\t#shape(conditions: readonly Condition[], direction: \"ascending\" | \"descending\", rows: \"first\" | \"many\"): string {\n\t\tlet key = `${rows} ${direction}`;\n\t\tfor (const [column, condition] of conditions) key += ` ${column} ${condition}`;\n\t\tlet sql = this.#shapes.get(key);\n\t\tif (sql !== undefined) return sql;\n\t\t// One comparison per condition: the vocabulary's node of that name, its value a placeholder.\n\t\tconst nodes = conditions.map(([column, condition]) => ({ [condition]: [column, ANY] }) as unknown as WhereNode);\n\t\tconst where: WhereNode | undefined = nodes.length === 0 ? undefined : { and: nodes };\n\t\tconst order = direction === \"ascending\" ? ASCENDING : DESCENDING;\n\t\tsql =\n\t\t\trows === \"first\"\n\t\t\t\t? this.#table.prepareFirst(this.#columns, where, order)\n\t\t\t\t: this.#table.prepare(this.#columns, where, order);\n\t\tthis.#shapes.set(key, sql);\n\t\treturn sql;\n\t}\n}\n\n/** The compiled reads of the storage's tables. */\nexport type StorageQueries = {\n\treadonly conversations: TableQueries;\n\treadonly entries: TableQueries;\n\t/** The id of a conversation's newest entry with a head marker: any, or at or before an id (bound second). */\n\treadonly latestHead: { readonly any: string; readonly atOrBefore: string };\n\treadonly tasks: TableQueries;\n\treadonly submissions: TableQueries;\n};\n\n/** The reads of `tables`. */\nexport function storageQueries(tables: CommitTables): StorageQueries {\n\tconst heads = tables.entryHeads;\n\treturn {\n\t\tconversations: new TableQueries(tables.conversations),\n\t\tentries: new TableQueries(tables.entries, [\"commit_seq\"]),\n\t\tlatestHead: {\n\t\t\tany: heads.prepareFirst(ID, { eq: [\"conversation_id\", ANY] }, DESCENDING),\n\t\t\tatOrBefore: heads.prepareFirst(\n\t\t\t\tID,\n\t\t\t\t{ and: [{ eq: [\"conversation_id\", ANY] }, { lte: [\"id\", ANY] }] },\n\t\t\t\tDESCENDING,\n\t\t\t),\n\t\t},\n\t\ttasks: new TableQueries(tables.tasks),\n\t\tsubmissions: new TableQueries(tables.submissions),\n\t};\n}\n"]}
|
|
1
|
+
{"version":3,"file":"queries.js","sourceRoot":"","sources":["../../../src/storage/store/queries.ts"],"names":[],"mappings":"AAAA,mHAAmH;AACnH,qHAAqH;AACrH,oHAAoH;AAgBpH,MAAM,SAAS,GAAU,EAAE,OAAO,EAAE,CAAC,IAAI,CAAC,EAAE,SAAS,EAAE,KAAK,EAAE,CAAC;AAC/D,MAAM,UAAU,GAAU,EAAE,OAAO,EAAE,CAAC,IAAI,CAAC,EAAE,SAAS,EAAE,MAAM,EAAE,CAAC;AAEjE,yCAAyC;AACzC,MAAM,EAAE,GAAG,CAAC,IAAI,CAAC,CAAC;AAElB,0EAA0E;AAC1E,MAAM,GAAG,GAAG,CAAC,CAAC;AAEd;;;GAGG;AACH,MAAM,OAAO,YAAY;IACf,MAAM,CAAa;IAC5B,4GAA4G;IACnG,UAAU,CAA6E;IACvF,KAAK,CAAS;IACd,OAAO,GAAG,IAAI,GAAG,EAAkB,CAAC;IACpC,QAAQ,CAAoB;IAErC,YAAY,KAAiB,EAAE,SAAS,GAAsB,EAAE;QAC/D,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC;QACpB,MAAM,SAAS,GAAG,KAAK,CAAC,WAAW,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC;QAClD,IAAI,CAAC,UAAU,GAAG,SAAS,CAAC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,GAAG,EAAE,CAAC,IAAI,EAAE,GAAG,CAAC,EAAE,CAAC,EAAE,EACjE,UAAU,CACV;SACD;QACD,KAAK,EAAE,IAAI,YAAY,CAAC,MAAM,CAAC,KAAK,CAAC;QACrC,WAAW,EAAE,IAAI,YAAY,CAAC,MAAM,CAAC,WAAW,CAAC;KACjD,CAAC;AACH,CAAC","sourcesContent":["// StoreStorage's reads as the store's queries (slice 6b D2, §2.4), compiled once from the store's query vocabulary\n// into SQL over the declared tables: no SQL is rendered per call, and a read selects only the record cell (by id, an\n// entry's commit seq too; each column returned costs) and parses one JSON text per record, as `SqliteStorage`'s do.\n\nimport type { Order, OwnerTable, WhereNode } from \"@earendil-works/chord\";\nimport type { Context } from \"@earendil-works/chord/context\";\nimport type { SqliteExecutor, SqliteValue } from \"@earendil-works/chord/sqlite\";\nimport type { CommitTables } from \"./commit.ts\";\n\n/**\n * A stored row as a query selects it: the record cell, its version (selected only once the column has versions past\n * 1), and an entry's commit seq.\n */\ntype RecordRow = { readonly record: string; readonly record$v?: number; readonly commit_seq?: number };\n\n/** One condition of a read: a column, how it compares, its value; a call site keeps one order of them. */\nexport type Condition = readonly [string, \"eq\" | \"gt\" | \"lt\" | \"gte\" | \"lte\", SqliteValue];\n\nconst ASCENDING: Order = { columns: [\"id\"], direction: \"asc\" };\nconst DESCENDING: Order = { columns: [\"id\"], direction: \"desc\" };\n\n/** The columns of a read of ids only. */\nconst ID = [\"id\"];\n\n/** A placeholder value: a query's shape binds its values at each call. */\nconst ANY = 0;\n\n/**\n * One table's compiled reads: by id (with the `byIdExtra` columns), and by shape (conditions in binding order, an\n * order; the record only), each shape compiled at its first use.\n */\nexport class TableQueries {\n\treadonly #table: OwnerTable;\n\t/** The record column's read of a cell at a version past 1; `undefined` while the column is at version 1. */\n\treadonly #versioned: ((text: string, version: number, context: Context) => unknown) | undefined;\n\treadonly #byId: string;\n\treadonly #shapes = new Map<string, string>();\n\treadonly #columns: readonly string[];\n\n\tconstructor(table: OwnerTable, byIdExtra: readonly string[] = []) {\n\t\tthis.#table = table;\n\t\tconst versioned = table.jsonVersion(\"record\") > 1;\n\t\tthis.#versioned = versioned ? table.reader(\"record\") : undefined;\n\t\tthis.#columns = versioned ? [\"record\", \"record$v\"] : [\"record\"];\n\t\tthis.#byId = table.prepareGet([...this.#columns, ...byIdExtra]);\n\t}\n\n\t/** The row with `id`, `undefined` when absent. */\n\tbyId(executor: Pick<SqliteExecutor, \"get\">, id: number): Promise<RecordRow | undefined> {\n\t\treturn executor.get<RecordRow>(this.#byId, id);\n\t}\n\n\t/** Up to `limit` rows whose `conditions` hold, by id in `direction`. */\n\tselect(\n\t\texecutor: Pick<SqliteExecutor, \"all\">,\n\t\tconditions: readonly Condition[],\n\t\tdirection: \"ascending\" | \"descending\",\n\t\tlimit: number,\n\t): Promise<RecordRow[]> {\n\t\tconst sql = this.#shape(conditions, direction, \"many\");\n\t\treturn executor.all<RecordRow>(sql, ...conditions.map(([, , value]) => value), limit);\n\t}\n\n\t/** The first row whose `conditions` hold, by id in `direction`; `undefined` when none does. */\n\tfirst(\n\t\texecutor: Pick<SqliteExecutor, \"get\">,\n\t\tconditions: readonly Condition[],\n\t\tdirection: \"ascending\" | \"descending\",\n\t): Promise<RecordRow | undefined> {\n\t\tconst sql = this.#shape(conditions, direction, \"first\");\n\t\treturn executor.get<RecordRow>(sql, ...conditions.map(([, , value]) => value));\n\t}\n\n\t/** A row's record, read as its column's (version checked, migrated on access). */\n\trecord<T>(row: RecordRow, context: Context): T {\n\t\tconst versioned = this.#versioned;\n\t\t// The cell holds a record of this table the storage wrote; at version 1 it is that JSON (`OwnerTable.reader`).\n\t\treturn (versioned === undefined ? JSON.parse(row.record) : versioned(row.record, row.record$v!, context)) as T;\n\t}\n\n\t/** Appends the records of `rows` to `into`, in order, each read as `record` reads it (one check per call). */\n\trecords<T>(rows: readonly RecordRow[], into: T[], context: Context): void {\n\t\tconst versioned = this.#versioned;\n\t\tif (versioned === undefined) {\n\t\t\tfor (const row of rows) into.push(JSON.parse(row.record) as T);\n\t\t\treturn;\n\t\t}\n\t\tfor (const row of rows) into.push(versioned(row.record, row.record$v!, context) as T);\n\t}\n\n\t/** The compiled read of a shape: its conditions' columns and comparisons, the direction, one row or many. */\n\t#shape(conditions: readonly Condition[], direction: \"ascending\" | \"descending\", rows: \"first\" | \"many\"): string {\n\t\tlet key = `${rows} ${direction}`;\n\t\tfor (const [column, condition] of conditions) key += ` ${column} ${condition}`;\n\t\tlet sql = this.#shapes.get(key);\n\t\tif (sql !== undefined) return sql;\n\t\t// One comparison per condition: the vocabulary's node of that name, its value a placeholder.\n\t\tconst nodes = conditions.map(([column, condition]) => ({ [condition]: [column, ANY] }) as unknown as WhereNode);\n\t\tconst where: WhereNode | undefined = nodes.length === 0 ? undefined : { and: nodes };\n\t\tconst order = direction === \"ascending\" ? ASCENDING : DESCENDING;\n\t\tsql =\n\t\t\trows === \"first\"\n\t\t\t\t? this.#table.prepareFirst(this.#columns, where, order)\n\t\t\t\t: this.#table.prepare(this.#columns, where, order);\n\t\tthis.#shapes.set(key, sql);\n\t\treturn sql;\n\t}\n}\n\n/** The compiled reads of the storage's tables. */\nexport type StorageQueries = {\n\treadonly conversations: TableQueries;\n\treadonly entries: TableQueries;\n\t/** The id of a conversation's newest entry with a head marker: any, or at or before an id (bound second). */\n\treadonly latestHead: { readonly any: string; readonly atOrBefore: string };\n\treadonly tasks: TableQueries;\n\treadonly submissions: TableQueries;\n};\n\n/** The reads of `tables`. */\nexport function storageQueries(tables: CommitTables): StorageQueries {\n\tconst heads = tables.entryHeads;\n\treturn {\n\t\tconversations: new TableQueries(tables.conversations),\n\t\tentries: new TableQueries(tables.entries, [\"commit_seq\"]),\n\t\tlatestHead: {\n\t\t\tany: heads.prepareFirst(ID, { eq: [\"conversation_id\", ANY] }, DESCENDING),\n\t\t\tatOrBefore: heads.prepareFirst(\n\t\t\t\tID,\n\t\t\t\t{ and: [{ eq: [\"conversation_id\", ANY] }, { lte: [\"id\", ANY] }] },\n\t\t\t\tDESCENDING,\n\t\t\t),\n\t\t},\n\t\ttasks: new TableQueries(tables.tasks),\n\t\tsubmissions: new TableQueries(tables.submissions),\n\t};\n}\n"]}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
1
|
+
import { type Store } from "@earendil-works/chord";
|
|
2
|
+
import type { Context } from "@earendil-works/chord/context";
|
|
3
|
+
import type { JsonValue } from "@earendil-works/chord/json";
|
|
3
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";
|
|
4
5
|
type StoredTask = TaskRecord<JsonValue, JsonValue, JsonValue>;
|
|
5
6
|
type StoredEntry = {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"storage.d.ts","sourceRoot":"","sources":["../../../src/storage/store/storage.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"storage.d.ts","sourceRoot":"","sources":["../../../src/storage/store/storage.ts"],"names":[],"mappings":"AAIA,OAAO,EAMN,KAAK,KAAK,EAEV,MAAM,uBAAuB,CAAC;AAC/B,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,+BAA+B,CAAC;AAC7D,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,4BAA4B,CAAC;AAI5D,OAAO,KAAK,EACX,YAAY,EACZ,cAAc,EACd,iBAAiB,EACjB,kBAAkB,EAClB,MAAM,EACN,eAAe,EACf,UAAU,EACV,aAAa,EACb,aAAa,EACb,cAAc,EACd,OAAO,EACP,UAAU,EACV,WAAW,EACX,EAAE,EACF,IAAI,EAEJ,GAAG,EACH,OAAO,EACP,YAAY,EACZ,cAAc,EACd,YAAY,EACZ,eAAe,EACf,g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c,EAC9B,SAAS,EAAE,MAAM,EACjB,OAAO,EAAE,OAAO,GACd,OAAO,CAAC,gBAAgB,GAAG,SAAS,CAAC,CAUvC;IAED,YAAY,CAAC,OAAO,EAAE,eAAe,EAAE,EAAE,EAAE,aAAa,EAAE,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,cAAc,GAAG,SAAS,CAAC,CAK/G;IAED,QAAQ,CAAC,EAAE,EAAE,UAAU,EAAE,EAAE,EAAE,aAAa,EAAE,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,cAAc,GAAG,SAAS,CAAC,CAKjG;IAED,aAAa,CACZ,KAAK,EAAE,aAAa,EACpB,KAAK,EAAE,MAAM,EACb,MAAM,EAAE,MAAM,GAAG,SAAS,EAC1B,OAAO,EAAE,OAAO,GACd,OAAO,CAAC,IAAI,CAAC,cAAc,EAAE,MAAM,CAAC,CAAC,CAYvC;IAED;;;OAGG;IACH,KAAK,CAAC,QAAQ,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC,CAatC;CAmLD"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// Durable's `Storage` on Chord's store (slice 6b D1, D2, §2): opening under an owner name (claims, tables, the
|
|
2
2
|
// allocator), commits as one composite write of the store's commit step, and the reads, each one guarded read of the
|
|
3
3
|
// store (several queries at one state in a read transaction), its request errors in a tagged result told after it.
|
|
4
|
-
import { findDocumentEntry, listDocumentEntries, StoreOwnerTables, } from "@earendil-works/chord
|
|
4
|
+
import { findDocumentEntry, listDocumentEntries, StoreOwnerTables, } from "@earendil-works/chord";
|
|
5
5
|
import { StorageRequestError } from "../../errors.js";
|
|
6
6
|
import { idFromNumber, seqFromNumber } from "../../ids.js";
|
|
7
7
|
import { nextCursor, scanStart } from "../scan.js";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"storage.js","sourceRoot":"","sources":["../../../src/storage/store/storage.ts"],"names":[],"mappings":"AAAA,+GAA+G;AAC/G,qHAAqH;AACrH,m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AAmB,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IACzE,OAAO,IAAI,CAAC,KAAK,CAAC;AACnB,CAAC;AAED,+GAA+G;AAC/G,SAAS,UAAU,CAAC,IAAkB;IACrC,IAAI,IAAI,CAAC,IAAI,KAAK,cAAc;QAC/B,MAAM,IAAI,mBAAmB,CAAC,YAAY,IAAI,CAAC,EAAE,qCAAqC,CAAC,CAAC;IACzF,OAAO,IAAI,CAAC,QAAQ,CAAC;AACtB,CAAC","sourcesContent":["// Durable's `Storage` on Chord's store (slice 6b D1, D2, §2): opening under an owner name (claims, tables, the\n// allocator), commits as one composite write of the store's commit step, and the reads, each one guarded read of the\n// store (several queries at one state in a read transaction), its request errors in a tagged result told after it.\n\nimport type { Context, JsonValue } from \"@earendil-works/chord\";\nimport {\n\ttype ChordStore,\n\ttype Claimant,\n\tfindDocumentEntry,\n\tlistDocumentEntries,\n\ttype SeriesCommit,\n\ttype Store,\n\tStoreOwnerTables,\n} from \"@earendil-works/chord/next\";\nimport type { SqliteExecutor } from \"@earendil-works/chord/sqlite\";\nimport { StorageRequestError } from \"../../errors.ts\";\nimport { idFromNumber, seqFromNumber } from \"../../ids.ts\";\nimport type {\n\tCommitResult,\n\tConversationId,\n\tConversationQuery,\n\tConversationRecord,\n\tCursor,\n\tDocumentAddress,\n\tDocumentId,\n\tDocumentPoint,\n\tDocumentQuery,\n\tDocumentRecord,\n\tEntryId,\n\tEntryQuery,\n\tEntryRecord,\n\tId,\n\tPage,\n\tScanOrder,\n\tSeq,\n\tStorage,\n\tStorageWrite,\n\tStoredDocument,\n\tSubmissionId,\n\tSubmissionQuery,\n\tSubmissionRecord,\n\tTaskId,\n\tTaskQuery,\n\tTaskRecord,\n} from \"../../types.ts\";\nimport { nextCursor, type ScanStart, scanStart } from \"../scan.ts\";\nimport { type CommitTables, DurableCommit } from \"./commit.ts\";\nimport { addressOf, type DocumentRead, namespaceOf, readAt, recordOfEntry, SCOPE_NAMESPACES } from \"./documents.ts\";\nimport { type Condition, type StorageQueries, storageQueries, type TableQueries } from \"./queries.ts\";\nimport { Conversations, Entries, EntryHeads, encodeIndexed, RecordIds, Submissions, Tasks } from \"./tables.ts\";\n\ntype StoredTask = TaskRecord<JsonValue, JsonValue, JsonValue>;\ntype StoredEntry = { readonly entry: EntryRecord; readonly commitSeq: Seq };\n\n/**\n * A guarded read's result: its data, or its request error, which is thrown after the guarded read (slice 6b §1.4),\n * never inside it.\n */\ntype Read<T> = { readonly kind: \"found\"; readonly value: T } | { readonly kind: \"refused\"; readonly message: string };\n\n/** The id condition of a table scan from `start`. */\nfunction scanFrom(start: ScanStart): Condition {\n\treturn start.order === \"ascending\"\n\t\t? [\"id\", \"gt\", start.after ?? -1]\n\t\t: [\"id\", \"lt\", start.after ?? Number.MAX_SAFE_INTEGER];\n}\n\nfunction page<T extends { readonly id: Id<string> }>(\n\tvalues: readonly T[],\n\tlimit: number,\n\torder: ScanOrder,\n): Page<T, Cursor> {\n\tconst items = values.slice(0, limit);\n\tif (values.length <= limit) return { items };\n\treturn { items, next: nextCursor(items.at(-1)!.id, order) };\n}\n\nfunction cursorId(cursor: Cursor | undefined): number | undefined {\n\tconst after = cursor?.after;\n\tif (after === undefined) return undefined;\n\tif (typeof after !== \"number\" || !Number.isSafeInteger(after))\n\t\tthrow new StorageRequestError(\"Invalid storage cursor\");\n\treturn after;\n}\n\n/**\n * Durable's `Storage` on Chord's store (slice 6b D1, D2, §2): its records as declared tables under an owner name, its\n * documents in the store's documents engine, its ids from the store's one allocator, each commit call as one series\n * of the store's commit queue (one backend transaction, one seq per batch), published in the host's batch. Several may share a store under distinct owner names\n * (claims); the app owns the store, and `close` leaves it open.\n */\nexport class StoreStorage implements Storage {\n\treadonly #store: ChordStore;\n\treadonly #owner: string;\n\treadonly #claimant: Claimant;\n\treadonly #tables: CommitTables;\n\treadonly #queries: StorageQueries;\n\t#closed = false;\n\t#closing: Promise<void> | undefined;\n\t/** Calls underway, which `close` waits for before it releases the claims (`#drained` once they reach 0). */\n\t#underway = 0;\n\t#drained: (() => void) | undefined;\n\n\tprivate constructor(store: ChordStore, owner: string, claimant: Claimant, tables: CommitTables) {\n\t\tthis.#store = store;\n\t\tthis.#owner = owner;\n\t\tthis.#claimant = claimant;\n\t\tthis.#tables = tables;\n\t\tthis.#queries = storageQueries(tables);\n\t}\n\n\t/**\n\t * Opens Durable's storage in `store` under `owner` (a lowercase `[a-z0-9@/._~-]` name): claims its tables and its\n\t * document namespaces (a second claim is refused `invalid/args`), creates or migrates its tables, and raises the\n\t * store's allocator above every id it holds (one index read). A failure releases what it claimed.\n\t */\n\tstatic async open(store: Store, owner: string, context: Context): Promise<StoreStorage> {\n\t\t// Chord's own: `openStore` or `importStore` made it.\n\t\tconst chord = store as ChordStore;\n\t\tconst claimant: Claimant = { label: `StoreStorage(${owner})` };\n\t\ttry {\n\t\t\tconst declared = new StoreOwnerTables(chord, owner, claimant);\n\t\t\tconst tables: CommitTables = {\n\t\t\t\trecordIds: declared.declare(RecordIds),\n\t\t\t\tconversations: declared.declare(Conversations),\n\t\t\t\tentries: declared.declare(Entries),\n\t\t\t\tentryHeads: declared.declare(EntryHeads),\n\t\t\t\ttasks: declared.declare(Tasks),\n\t\t\t\tsubmissions: declared.declare(Submissions),\n\t\t\t};\n\t\t\tfor (const namespace of SCOPE_NAMESPACES) chord.claims.documents(owner, namespace, claimant);\n\t\t\tawait declared.prepare(context);\n\t\t\tconst highest = await chord.read(\n\t\t\t\t(executor) =>\n\t\t\t\t\texecutor.get<{ readonly id: number | null }>(\n\t\t\t\t\t\t`SELECT max(\"id\") AS id FROM \"${tables.recordIds.sql.table}\"`,\n\t\t\t\t\t),\n\t\t\t\tcontext,\n\t\t\t);\n\t\t\tif (highest?.id != null) chord.ids.raise(highest.id);\n\t\t\treturn new StoreStorage(chord, owner, claimant, tables);\n\t\t} catch (error) {\n\t\t\tchord.claims.release(claimant);\n\t\t\tthrow error;\n\t\t}\n\t}\n\n\t/**\n\t * Commit `batches` as one series of the store (`ChordStore.commitSeries`): one backend transaction, one seq per\n\t * batch, each batch's checks (at staging, then against the state the earlier ones left) before its writes.\n\t */\n\tcommit(\n\t\tbatches: readonly (readonly StorageWrite[])[],\n\t\treceive: (index: number, seq: Seq) => void,\n\t\tcontext: Context,\n\t): Promise<CommitResult> {\n\t\treturn this.#call(() => {\n\t\t\tconst store = this.#store;\n\t\t\tconst raise = (id: number): void => store.ids.raise(id);\n\t\t\tconst commits: SeriesCommit[] = [];\n\t\t\tfor (const writes of batches) {\n\t\t\t\ttry {\n\t\t\t\t\tcommits.push(new DurableCommit(writes, this.#owner, this.#tables, raise, context));\n\t\t\t\t} catch (error) {\n\t\t\t\t\t// Staging runs Durable's checks of the batch itself: a refusal in its turn, the batches before it stored.\n\t\t\t\t\tcommits.push({ check: () => Promise.reject(error), writes: [] });\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn store.commitSeries(commits, (index, seq) => receive(index, seqFromNumber(seq)), context);\n\t\t});\n\t}\n\n\t/**\n\t * Run a commit's publication in the attached host's batch (`batch.within`: it joins a running batch, opens one, or\n\t * runs next while one sends): Chord sources over Durable's views are marked in one batch per commit. Plainly without\n\t * a host.\n\t */\n\tpublishing(publish: () => void, context: Context): void {\n\t\tconst batch = this.#store.batch;\n\t\tif (batch === undefined) publish();\n\t\telse batch.within(publish, context);\n\t}\n\n\tmintId<I extends Id<string>>(): Promise<I> {\n\t\treturn this.#call(async () => idFromNumber<I>(this.#store.mintId()));\n\t}\n\n\tconversation(id: ConversationId, context: Context): Promise<ConversationRecord | undefined> {\n\t\treturn this.#read((executor) => this.#conversation(executor, id, context), context);\n\t}\n\n\tscanConversations(\n\t\tquery: ConversationQuery,\n\t\tlimit: number,\n\t\tcursor: Cursor | undefined,\n\t\tcontext: Context,\n\t): Promise<Page<ConversationRecord, Cursor>> {\n\t\treturn this.#reading(() => {\n\t\t\tconst start = scanStart(query.order, cursor, \"ascending\");\n\t\t\tconst conditions: Condition[] = [scanFrom(start)];\n\t\t\tif (query.ownerConversationId !== undefined) {\n\t\t\t\tconditions.push([\"owner_conversation_id\", \"eq\", query.ownerConversationId]);\n\t\t\t}\n\t\t\tif (query.ownerTaskId !== undefined) conditions.push([\"owner_task_id\", \"eq\", query.ownerTaskId]);\n\t\t\treturn this.#scan<ConversationRecord>(this.#queries.conversations, conditions, start, limit, context);\n\t\t});\n\t}\n\n\tentry(id: EntryId, context: Context): Promise<StoredEntry | undefined>;\n\tentry(conversationId: ConversationId, id: EntryId, context: Context): Promise<StoredEntry | undefined>;\n\tentry(\n\t\tidOrConversationId: EntryId | ConversationId,\n\t\tidOrContext: EntryId | Context,\n\t\tmaybeContext?: Context,\n\t): Promise<StoredEntry | undefined> {\n\t\tif (maybeContext === undefined) {\n\t\t\tconst context = idOrContext as Context;\n\t\t\treturn this.#read((executor) => this.#entry(executor, idOrConversationId as EntryId, context), context);\n\t\t}\n\t\tconst context = maybeContext;\n\t\tconst id = typeof idOrContext === \"number\" ? idFromNumber<EntryId>(idOrContext) : undefined;\n\t\treturn this.#reading(() => {\n\t\t\tif (id === undefined) throw new StorageRequestError(\"Storage.entry() requires an entry ID\");\n\t\t\tconst conversationId = idOrConversationId as ConversationId;\n\t\t\treturn this.#store\n\t\t\t\t.read((executor) => this.#visibleEntry(executor, conversationId, id, context), context)\n\t\t\t\t.then(told);\n\t\t});\n\t}\n\n\tfindLatestHeadMarker(\n\t\tconversationId: ConversationId,\n\t\tatOrBeforeEntryId: EntryId | undefined,\n\t\tcontext: Context,\n\t): Promise<(EntryRecord & { readonly head: EntryId }) | undefined> {\n\t\treturn this.#reading(() =>\n\t\t\tthis.#store\n\t\t\t\t.read((executor) => this.#latestHeadMarker(executor, conversationId, atOrBeforeEntryId, context), context)\n\t\t\t\t.then(told),\n\t\t);\n\t}\n\n\tscanEntries(\n\t\tquery: EntryQuery,\n\t\tlimit: number,\n\t\tcursor: Cursor | undefined,\n\t\tcontext: Context,\n\t): Promise<Page<EntryRecord, Cursor>> {\n\t\treturn this.#reading(() => {\n\t\t\tconst { order, after } = scanStart(query.order, cursor, \"descending\");\n\t\t\tconst read =\n\t\t\t\torder === \"ascending\"\n\t\t\t\t\t? (executor: SqliteExecutor) => this.#entriesAscending(executor, query, limit, after, context)\n\t\t\t\t\t: (executor: SqliteExecutor) => this.#entriesDescending(executor, query, limit, after, context);\n\t\t\treturn this.#store.read(read, context).then(told);\n\t\t});\n\t}\n\n\ttask(id: TaskId, context: Context): Promise<StoredTask | undefined> {\n\t\tconst tasks = this.#queries.tasks;\n\t\treturn this.#read(async (executor) => {\n\t\t\tconst row = await tasks.byId(executor, id);\n\t\t\treturn row === undefined ? undefined : tasks.record<StoredTask>(row, context);\n\t\t}, context);\n\t}\n\n\tscanTasks(\n\t\tquery: TaskQuery,\n\t\tlimit: number,\n\t\tcursor: Cursor | undefined,\n\t\tcontext: Context,\n\t): Promise<Page<StoredTask, Cursor>> {\n\t\treturn this.#reading(() => {\n\t\t\tconst start = scanStart(query.order, cursor, \"ascending\");\n\t\t\tconst conditions: Condition[] = [scanFrom(start)];\n\t\t\tif (query.conversationId !== undefined) conditions.push([\"conversation_id\", \"eq\", query.conversationId]);\n\t\t\tif (query.kind !== undefined) conditions.push([\"kind\", \"eq\", encodeIndexed(query.kind)]);\n\t\t\tif (query.status !== undefined) conditions.push([\"status\", \"eq\", query.status]);\n\t\t\tif (query.abortRequested !== undefined)\n\t\t\t\tconditions.push([\"abort_requested\", \"eq\", query.abortRequested ? 1 : 0]);\n\t\t\tif (query.background !== undefined) conditions.push([\"background\", \"eq\", query.background ? 1 : 0]);\n\t\t\treturn this.#scan<StoredTask>(this.#queries.tasks, conditions, start, limit, context);\n\t\t});\n\t}\n\n\tsubmission(id: SubmissionId, context: Context): Promise<SubmissionRecord | undefined> {\n\t\tconst submissions = this.#queries.submissions;\n\t\treturn this.#read(async (executor) => {\n\t\t\tconst row = await submissions.byId(executor, id);\n\t\t\treturn row === undefined ? undefined : submissions.record<SubmissionRecord>(row, context);\n\t\t}, context);\n\t}\n\n\tscanSubmissions(\n\t\tquery: SubmissionQuery,\n\t\tlimit: number,\n\t\tcursor: Cursor | undefined,\n\t\tcontext: Context,\n\t): Promise<Page<SubmissionRecord, Cursor>> {\n\t\treturn this.#reading(() => {\n\t\t\tconst start = scanStart(query.order, cursor, \"ascending\");\n\t\t\tconst conditions: Condition[] = [scanFrom(start)];\n\t\t\tif (query.conversationId !== undefined) conditions.push([\"conversation_id\", \"eq\", query.conversationId]);\n\t\t\tif (query.status !== undefined) conditions.push([\"status\", \"eq\", query.status]);\n\t\t\treturn this.#scan<SubmissionRecord>(this.#queries.submissions, conditions, start, limit, context);\n\t\t});\n\t}\n\n\tsubmissionByRequest(\n\t\tconversationId: ConversationId,\n\t\trequestId: string,\n\t\tcontext: Context,\n\t): Promise<SubmissionRecord | undefined> {\n\t\tconst submissions = this.#queries.submissions;\n\t\tconst conditions: Condition[] = [\n\t\t\t[\"conversation_id\", \"eq\", conversationId],\n\t\t\t[\"request_id\", \"eq\", encodeIndexed(requestId)],\n\t\t];\n\t\treturn this.#read(async (executor) => {\n\t\t\tconst row = await submissions.first(executor, conditions, \"ascending\");\n\t\t\treturn row === undefined ? undefined : submissions.record<SubmissionRecord>(row, context);\n\t\t}, context);\n\t}\n\n\tfindDocument(address: DocumentAddress, at: DocumentPoint, context: Context): Promise<DocumentRecord | undefined> {\n\t\treturn this.#read(async (executor) => {\n\t\t\tconst entry = await findDocumentEntry(executor, addressOf(address, this.#owner), at);\n\t\t\treturn entry === undefined ? undefined : recordOfEntry(entry);\n\t\t}, context);\n\t}\n\n\tdocument(id: DocumentId, at: DocumentPoint, context: Context): Promise<StoredDocument | undefined> {\n\t\t// The record and its revisions must come from one committed state (S4).\n\t\treturn this.#reading(() =>\n\t\t\tthis.#store.readTransaction((executor) => readAt(executor, id, at, this.#owner), context).then(documentOf),\n\t\t);\n\t}\n\n\tscanDocuments(\n\t\tquery: DocumentQuery,\n\t\tlimit: number,\n\t\tcursor: Cursor | undefined,\n\t\tcontext: Context,\n\t): Promise<Page<DocumentRecord, Cursor>> {\n\t\treturn this.#reading(() => {\n\t\t\tconst after = cursorId(cursor) ?? -1;\n\t\t\tconst scope = {\n\t\t\t\towner: this.#owner,\n\t\t\t\tnamespace: namespaceOf(query.scope),\n\t\t\t\t...(query.kind === undefined ? {} : { kind: encodeIndexed(query.kind) }),\n\t\t\t};\n\t\t\treturn this.#store\n\t\t\t\t.read((executor) => listDocumentEntries(executor, scope, query.at, after, limit + 1), context)\n\t\t\t\t.then((found) => page(found.map(recordOfEntry), limit, \"ascending\"));\n\t\t});\n\t}\n\n\t/**\n\t * Refuses new calls, waits for its commits underway, then releases its claims; the store stays open (the app's),\n\t * and finishes the reads underway, which change nothing.\n\t */\n\tclose(_context: Context): Promise<void> {\n\t\tif (this.#closing === undefined) {\n\t\t\tthis.#closed = true;\n\t\t\tthis.#closing = (async () => {\n\t\t\t\tif (this.#underway > 0) {\n\t\t\t\t\tawait new Promise<void>((resolve) => {\n\t\t\t\t\t\tthis.#drained = resolve;\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t\tthis.#store.claims.release(this.#claimant);\n\t\t\t})();\n\t\t}\n\t\treturn this.#closing;\n\t}\n\n\t/** Runs one commit or mint of this storage: refused once it closed, counted until it settles (`close` waits). */\n\tasync #call<T>(run: () => Promise<T>): Promise<T> {\n\t\tif (this.#closed) throw new Error(\"StoreStorage is closed\");\n\t\tthis.#underway++;\n\t\ttry {\n\t\t\treturn await run();\n\t\t} finally {\n\t\t\tif (--this.#underway === 0) this.#drained?.();\n\t\t}\n\t}\n\n\t/**\n\t * A call that is one guarded read of the store: refused once closed; not waited for by `close` (a read changes\n\t * nothing, and the store, which stays open, finishes it).\n\t */\n\t#read<T>(read: (executor: SqliteExecutor) => Promise<T>, context: Context): Promise<T> {\n\t\treturn this.#reading(() => this.#store.read(read, context));\n\t}\n\n\t/**\n\t * A read call: `read` prepares its guarded read (a request error thrown then, before it) and returns it. Refused\n\t * once closed; one promise per call besides the guard's (no async wrapper).\n\t */\n\t#reading<T>(read: () => Promise<T>): Promise<T> {\n\t\ttry {\n\t\t\tif (this.#closed) throw new Error(\"StoreStorage is closed\");\n\t\t\treturn read();\n\t\t} catch (error) {\n\t\t\treturn Promise.reject(error);\n\t\t}\n\t}\n\n\tasync #conversation(\n\t\texecutor: SqliteExecutor,\n\t\tid: ConversationId,\n\t\tcontext: Context,\n\t): Promise<ConversationRecord | undefined> {\n\t\tconst conversations = this.#queries.conversations;\n\t\tconst row = await conversations.byId(executor, id);\n\t\treturn row === undefined ? undefined : conversations.record<ConversationRecord>(row, context);\n\t}\n\n\t#entry(executor: SqliteExecutor, id: EntryId, context: Context): Promise<StoredEntry | undefined> {\n\t\tconst entries = this.#queries.entries;\n\t\treturn entries.byId(executor, id).then((row) => {\n\t\t\tif (row === undefined) return undefined;\n\t\t\treturn { entry: entries.record<EntryRecord>(row, context), commitSeq: seqFromNumber(row.commit_seq!) };\n\t\t});\n\t}\n\n\t/** Entry `id` when visible through `conversationId`'s fork chain (`SqliteStorage.readEntry`). */\n\tasync #visibleEntry(\n\t\texecutor: SqliteExecutor,\n\t\tconversationId: ConversationId,\n\t\tid: EntryId,\n\t\tcontext: Context,\n\t): Promise<Read<StoredEntry | undefined>> {\n\t\tlet conversation = await this.#conversation(executor, conversationId, context);\n\t\tif (conversation === undefined) return unknownConversation(conversationId);\n\t\tconst stored = await this.#entry(executor, id, context);\n\t\tif (stored === undefined) return NOTHING_FOUND;\n\t\tlet upper = Number.POSITIVE_INFINITY;\n\t\twhile (conversation.id !== stored.entry.conversationId) {\n\t\t\tif (conversation.parent === undefined) return NOTHING_FOUND;\n\t\t\tupper = Math.min(upper, conversation.parent.at);\n\t\t\tconversation = (await this.#conversation(executor, conversation.parent.conversationId, context))!;\n\t\t}\n\t\treturn stored.entry.id > upper ? NOTHING_FOUND : { kind: \"found\", value: stored };\n\t}\n\n\tasync #latestHeadMarker(\n\t\texecutor: SqliteExecutor,\n\t\tconversationId: ConversationId,\n\t\tatOrBeforeEntryId: EntryId | undefined,\n\t\tcontext: Context,\n\t): Promise<Read<(EntryRecord & { readonly head: EntryId }) | undefined>> {\n\t\tlet conversation = await this.#conversation(executor, conversationId, context);\n\t\tif (conversation === undefined) return unknownConversation(conversationId);\n\t\tlet upper: number | undefined = atOrBeforeEntryId;\n\t\twhile (true) {\n\t\t\tconst { latestHead } = this.#queries;\n\t\t\tconst head =\n\t\t\t\tupper === undefined\n\t\t\t\t\t? await executor.get<{ readonly id: number }>(latestHead.any, conversation.id)\n\t\t\t\t\t: await executor.get<{ readonly id: number }>(latestHead.atOrBefore, conversation.id, upper);\n\t\t\tif (head !== undefined) {\n\t\t\t\t// Written with its entry, in the same commit.\n\t\t\t\tconst row = (await this.#queries.entries.byId(executor, head.id))!;\n\t\t\t\tconst value = this.#queries.entries.record<EntryRecord & { readonly head: EntryId }>(row, context);\n\t\t\t\treturn { kind: \"found\", value };\n\t\t\t}\n\t\t\tif (conversation.parent === undefined) return NOTHING_FOUND;\n\t\t\tupper = upper === undefined ? conversation.parent.at : Math.min(upper, conversation.parent.at);\n\t\t\tconversation = (await this.#conversation(executor, conversation.parent.conversationId, context))!;\n\t\t}\n\t}\n\n\t/** Newest first: each conversation of the fork chain up to its fork point (`SqliteStorage.readEntries`). */\n\tasync #entriesDescending(\n\t\texecutor: SqliteExecutor,\n\t\tquery: EntryQuery,\n\t\tlimit: number,\n\t\tafter: number | undefined,\n\t\tcontext: Context,\n\t): Promise<Read<Page<EntryRecord, Cursor>>> {\n\t\tlet conversation = await this.#conversation(executor, query.conversationId, context);\n\t\tif (conversation === undefined) return unknownConversation(query.conversationId);\n\t\tlet upper: number | undefined = query.maxEntryId;\n\t\tif (after !== undefined) upper = Math.min(upper ?? Number.MAX_SAFE_INTEGER, after - 1);\n\t\tconst values: EntryRecord[] = [];\n\t\twhile (true) {\n\t\t\tconst range = this.#range(conversation.id, query.minEntryId, upper);\n\t\t\tconst rows = await this.#queries.entries.select(executor, range, \"descending\", limit + 1 - values.length);\n\t\t\tthis.#queries.entries.records(rows, values, context);\n\t\t\tif (values.length > limit || conversation.parent === undefined) break;\n\t\t\tupper = upper === undefined ? conversation.parent.at : Math.min(upper, conversation.parent.at);\n\t\t\tif (query.minEntryId !== undefined && upper < query.minEntryId) break;\n\t\t\tconversation = (await this.#conversation(executor, conversation.parent.conversationId, context))!;\n\t\t}\n\t\treturn { kind: \"found\", value: page(values, limit, \"descending\") };\n\t}\n\n\t/** Oldest first: the fork chain's segments from the root forward, each up to its fork point. */\n\tasync #entriesAscending(\n\t\texecutor: SqliteExecutor,\n\t\tquery: EntryQuery,\n\t\tlimit: number,\n\t\tafter: number | undefined,\n\t\tcontext: Context,\n\t): Promise<Read<Page<EntryRecord, Cursor>>> {\n\t\tconst segments: { readonly conversationId: ConversationId; readonly upper: number | undefined }[] = [];\n\t\tlet conversation = await this.#conversation(executor, query.conversationId, context);\n\t\tif (conversation === undefined) return unknownConversation(query.conversationId);\n\t\tlet upper: number | undefined = query.maxEntryId;\n\t\twhile (true) {\n\t\t\tsegments.push({ conversationId: conversation.id, upper });\n\t\t\tif (conversation.parent === undefined) break;\n\t\t\tupper = upper === undefined ? conversation.parent.at : Math.min(upper, conversation.parent.at);\n\t\t\tif (query.minEntryId !== undefined && upper < query.minEntryId) break;\n\t\t\tconversation = (await this.#conversation(executor, conversation.parent.conversationId, context))!;\n\t\t}\n\t\tlet lower: number | undefined = query.minEntryId;\n\t\tif (after !== undefined) lower = Math.max(lower ?? after + 1, after + 1);\n\t\tconst values: EntryRecord[] = [];\n\t\tfor (const segment of segments.reverse()) {\n\t\t\tconst range = this.#range(segment.conversationId, lower, segment.upper);\n\t\t\tconst rows = await this.#queries.entries.select(executor, range, \"ascending\", limit + 1 - values.length);\n\t\t\tthis.#queries.entries.records(rows, values, context);\n\t\t\tif (values.length > limit) break;\n\t\t}\n\t\treturn { kind: \"found\", value: page(values, limit, \"ascending\") };\n\t}\n\n\t/** One conversation's entries with ids from `lower` to `upper` (inclusive, each optional). */\n\t#range(conversationId: ConversationId, lower: number | undefined, upper: number | undefined): Condition[] {\n\t\tconst conditions: Condition[] = [[\"conversation_id\", \"eq\", conversationId]];\n\t\tif (lower !== undefined) conditions.push([\"id\", \"gte\", lower]);\n\t\tif (upper !== undefined) conditions.push([\"id\", \"lte\", upper]);\n\t\treturn conditions;\n\t}\n\n\t/** A page of a table scan: up to `limit` records of `queries`' table whose `conditions` hold, from `start`. */\n\t#scan<T extends { readonly id: Id<string> }>(\n\t\tqueries: TableQueries,\n\t\tconditions: readonly Condition[],\n\t\tstart: ScanStart,\n\t\tlimit: number,\n\t\tcontext: Context,\n\t): Promise<Page<T, Cursor>> {\n\t\treturn this.#store\n\t\t\t.read((executor) => queries.select(executor, conditions, start.order, limit + 1), context)\n\t\t\t.then((rows) => {\n\t\t\t\tconst values: T[] = [];\n\t\t\t\tqueries.records(rows, values, context);\n\t\t\t\treturn page(values, limit, start.order);\n\t\t\t});\n\t}\n}\n\n/** A read that found nothing. */\nconst NOTHING_FOUND: Read<undefined> = { kind: \"found\", value: undefined };\n\nfunction unknownConversation(id: ConversationId): Read<never> {\n\treturn { kind: \"refused\", message: `Unknown conversation: ${id}` };\n}\n\n/** A read's data, its request error thrown now that the guarded read returned (slice 6b §1.4). */\nfunction told<T>(read: Read<T>): T {\n\tif (read.kind === \"refused\") throw new StorageRequestError(read.message);\n\treturn read.value;\n}\n\n/** A document read's result, a record that keeps no history at the point thrown as Durable's request error. */\nfunction documentOf(read: DocumentRead): StoredDocument | undefined {\n\tif (read.kind === \"current_only\")\n\t\tthrow new StorageRequestError(`Document ${read.id} does not retain historical content`);\n\treturn read.document;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"storage.js","sourceRoot":"","sources":["../../../src/storage/store/storage.ts"],"names":[],"mappings":"AAAA,+GAA+G;AAC/G,qHAAqH;AACrH,mHAAmH;AAEnH,OAAO,EAGN,iBAAiB,EACjB,mBAAmB,EAGnB,gBAAgB,GAChB,MAAM,uBAAu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,CAAC;AAED,+GAA+G;AAC/G,SAAS,UAAU,CAAC,IAAkB;IACrC,IAAI,IAAI,CAAC,IAAI,KAAK,cAAc;QAC/B,MAAM,IAAI,mBAAmB,CAAC,YAAY,IAAI,CAAC,EAAE,qCAAqC,CAAC,CAAC;IACzF,OAAO,IAAI,CAAC,QAAQ,CAAC;AACtB,CAAC","sourcesContent":["// Durable's `Storage` on Chord's store (slice 6b D1, D2, §2): opening under an owner name (claims, tables, the\n// allocator), commits as one composite write of the store's commit step, and the reads, each one guarded read of the\n// store (several queries at one state in a read transaction), its request errors in a tagged result told after it.\n\nimport {\n\ttype ChordStore,\n\ttype Claimant,\n\tfindDocumentEntry,\n\tlistDocumentEntries,\n\ttype SeriesCommit,\n\ttype Store,\n\tStoreOwnerTables,\n} from \"@earendil-works/chord\";\nimport type { Context } from \"@earendil-works/chord/context\";\nimport type { JsonValue } from \"@earendil-works/chord/json\";\nimport type { SqliteExecutor } from \"@earendil-works/chord/sqlite\";\nimport { StorageRequestError } from \"../../errors.ts\";\nimport { idFromNumber, seqFromNumber } from \"../../ids.ts\";\nimport type {\n\tCommitResult,\n\tConversationId,\n\tConversationQuery,\n\tConversationRecord,\n\tCursor,\n\tDocumentAddress,\n\tDocumentId,\n\tDocumentPoint,\n\tDocumentQuery,\n\tDocumentRecord,\n\tEntryId,\n\tEntryQuery,\n\tEntryRecord,\n\tId,\n\tPage,\n\tScanOrder,\n\tSeq,\n\tStorage,\n\tStorageWrite,\n\tStoredDocument,\n\tSubmissionId,\n\tSubmissionQuery,\n\tSubmissionRecord,\n\tTaskId,\n\tTaskQuery,\n\tTaskRecord,\n} from \"../../types.ts\";\nimport { nextCursor, type ScanStart, scanStart } from \"../scan.ts\";\nimport { type CommitTables, DurableCommit } from \"./commit.ts\";\nimport { addressOf, type DocumentRead, namespaceOf, readAt, recordOfEntry, SCOPE_NAMESPACES } from \"./documents.ts\";\nimport { type Condition, type StorageQueries, storageQueries, type TableQueries } from \"./queries.ts\";\nimport { Conversations, Entries, EntryHeads, encodeIndexed, RecordIds, Submissions, Tasks } from \"./tables.ts\";\n\ntype StoredTask = TaskRecord<JsonValue, JsonValue, JsonValue>;\ntype StoredEntry = { readonly entry: EntryRecord; readonly commitSeq: Seq };\n\n/**\n * A guarded read's result: its data, or its request error, which is thrown after the guarded read (slice 6b §1.4),\n * never inside it.\n */\ntype Read<T> = { readonly kind: \"found\"; readonly value: T } | { readonly kind: \"refused\"; readonly message: string };\n\n/** The id condition of a table scan from `start`. */\nfunction scanFrom(start: ScanStart): Condition {\n\treturn start.order === \"ascending\"\n\t\t? [\"id\", \"gt\", start.after ?? -1]\n\t\t: [\"id\", \"lt\", start.after ?? Number.MAX_SAFE_INTEGER];\n}\n\nfunction page<T extends { readonly id: Id<string> }>(\n\tvalues: readonly T[],\n\tlimit: number,\n\torder: ScanOrder,\n): Page<T, Cursor> {\n\tconst items = values.slice(0, limit);\n\tif (values.length <= limit) return { items };\n\treturn { items, next: nextCursor(items.at(-1)!.id, order) };\n}\n\nfunction cursorId(cursor: Cursor | undefined): number | undefined {\n\tconst after = cursor?.after;\n\tif (after === undefined) return undefined;\n\tif (typeof after !== \"number\" || !Number.isSafeInteger(after))\n\t\tthrow new StorageRequestError(\"Invalid storage cursor\");\n\treturn after;\n}\n\n/**\n * Durable's `Storage` on Chord's store (slice 6b D1, D2, §2): its records as declared tables under an owner name, its\n * documents in the store's documents engine, its ids from the store's one allocator, each commit call as one series\n * of the store's commit queue (one backend transaction, one seq per batch), published in the host's batch. Several may share a store under distinct owner names\n * (claims); the app owns the store, and `close` leaves it open.\n */\nexport class StoreStorage implements Storage {\n\treadonly #store: ChordStore;\n\treadonly #owner: string;\n\treadonly #claimant: Claimant;\n\treadonly #tables: CommitTables;\n\treadonly #queries: StorageQueries;\n\t#closed = false;\n\t#closing: Promise<void> | undefined;\n\t/** Calls underway, which `close` waits for before it releases the claims (`#drained` once they reach 0). */\n\t#underway = 0;\n\t#drained: (() => void) | undefined;\n\n\tprivate constructor(store: ChordStore, owner: string, claimant: Claimant, tables: CommitTables) {\n\t\tthis.#store = store;\n\t\tthis.#owner = owner;\n\t\tthis.#claimant = claimant;\n\t\tthis.#tables = tables;\n\t\tthis.#queries = storageQueries(tables);\n\t}\n\n\t/**\n\t * Opens Durable's storage in `store` under `owner` (a lowercase `[a-z0-9@/._~-]` name): claims its tables and its\n\t * document namespaces (a second claim is refused `invalid/args`), creates or migrates its tables, and raises the\n\t * store's allocator above every id it holds (one index read). A failure releases what it claimed.\n\t */\n\tstatic async open(store: Store, owner: string, context: Context): Promise<StoreStorage> {\n\t\t// Chord's own: `openStore` or `importStore` made it.\n\t\tconst chord = store as ChordStore;\n\t\tconst claimant: Claimant = { label: `StoreStorage(${owner})` };\n\t\ttry {\n\t\t\tconst declared = new StoreOwnerTables(chord, owner, claimant);\n\t\t\tconst tables: CommitTables = {\n\t\t\t\trecordIds: declared.declare(RecordIds),\n\t\t\t\tconversations: declared.declare(Conversations),\n\t\t\t\tentries: declared.declare(Entries),\n\t\t\t\tentryHeads: declared.declare(EntryHeads),\n\t\t\t\ttasks: declared.declare(Tasks),\n\t\t\t\tsubmissions: declared.declare(Submissions),\n\t\t\t};\n\t\t\tfor (const namespace of SCOPE_NAMESPACES) chord.claims.documents(owner, namespace, claimant);\n\t\t\tawait declared.prepare(context);\n\t\t\tconst highest = await chord.read(\n\t\t\t\t(executor) =>\n\t\t\t\t\texecutor.get<{ readonly id: number | null }>(\n\t\t\t\t\t\t`SELECT max(\"id\") AS id FROM \"${tables.recordIds.sql.table}\"`,\n\t\t\t\t\t),\n\t\t\t\tcontext,\n\t\t\t);\n\t\t\tif (highest?.id != null) chord.ids.raise(highest.id);\n\t\t\treturn new StoreStorage(chord, owner, claimant, tables);\n\t\t} catch (error) {\n\t\t\tchord.claims.release(claimant);\n\t\t\tthrow error;\n\t\t}\n\t}\n\n\t/**\n\t * Commit `batches` as one series of the store (`ChordStore.commitSeries`): one backend transaction, one seq per\n\t * batch, each batch's checks (at staging, then against the state the earlier ones left) before its writes.\n\t */\n\tcommit(\n\t\tbatches: readonly (readonly StorageWrite[])[],\n\t\treceive: (index: number, seq: Seq) => void,\n\t\tcontext: Context,\n\t): Promise<CommitResult> {\n\t\treturn this.#call(() => {\n\t\t\tconst store = this.#store;\n\t\t\tconst raise = (id: number): void => store.ids.raise(id);\n\t\t\tconst commits: SeriesCommit[] = [];\n\t\t\tfor (const writes of batches) {\n\t\t\t\ttry {\n\t\t\t\t\tcommits.push(new DurableCommit(writes, this.#owner, this.#tables, raise, context));\n\t\t\t\t} catch (error) {\n\t\t\t\t\t// Staging runs Durable's checks of the batch itself: a refusal in its turn, the batches before it stored.\n\t\t\t\t\tcommits.push({ check: () => Promise.reject(error), writes: [] });\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn store.commitSeries(commits, (index, seq) => receive(index, seqFromNumber(seq)), context);\n\t\t});\n\t}\n\n\t/**\n\t * Run a commit's publication in the attached host's batch (`batch.within`: it joins a running batch, opens one, or\n\t * runs next while one sends): Chord sources over Durable's views are marked in one batch per commit. Plainly without\n\t * a host.\n\t */\n\tpublishing(publish: () => void, context: Context): void {\n\t\tconst batch = this.#store.batch;\n\t\tif (batch === undefined) publish();\n\t\telse batch.within(publish, context);\n\t}\n\n\tmintId<I extends Id<string>>(): Promise<I> {\n\t\treturn this.#call(async () => idFromNumber<I>(this.#store.mintId()));\n\t}\n\n\tconversation(id: ConversationId, context: Context): Promise<ConversationRecord | undefined> {\n\t\treturn this.#read((executor) => this.#conversation(executor, id, context), context);\n\t}\n\n\tscanConversations(\n\t\tquery: ConversationQuery,\n\t\tlimit: number,\n\t\tcursor: Cursor | undefined,\n\t\tcontext: Context,\n\t): Promise<Page<ConversationRecord, Cursor>> {\n\t\treturn this.#reading(() => {\n\t\t\tconst start = scanStart(query.order, cursor, \"ascending\");\n\t\t\tconst conditions: Condition[] = [scanFrom(start)];\n\t\t\tif (query.ownerConversationId !== undefined) {\n\t\t\t\tconditions.push([\"owner_conversation_id\", \"eq\", query.ownerConversationId]);\n\t\t\t}\n\t\t\tif (query.ownerTaskId !== undefined) conditions.push([\"owner_task_id\", \"eq\", query.ownerTaskId]);\n\t\t\treturn this.#scan<ConversationRecord>(this.#queries.conversations, conditions, start, limit, context);\n\t\t});\n\t}\n\n\tentry(id: EntryId, context: Context): Promise<StoredEntry | undefined>;\n\tentry(conversationId: ConversationId, id: EntryId, context: Context): Promise<StoredEntry | undefined>;\n\tentry(\n\t\tidOrConversationId: EntryId | ConversationId,\n\t\tidOrContext: EntryId | Context,\n\t\tmaybeContext?: Context,\n\t): Promise<StoredEntry | undefined> {\n\t\tif (maybeContext === undefined) {\n\t\t\tconst context = idOrContext as Context;\n\t\t\treturn this.#read((executor) => this.#entry(executor, idOrConversationId as EntryId, context), context);\n\t\t}\n\t\tconst context = maybeContext;\n\t\tconst id = typeof idOrContext === \"number\" ? idFromNumber<EntryId>(idOrContext) : undefined;\n\t\treturn this.#reading(() => {\n\t\t\tif (id === undefined) throw new StorageRequestError(\"Storage.entry() requires an entry ID\");\n\t\t\tconst conversationId = idOrConversationId as ConversationId;\n\t\t\treturn this.#store\n\t\t\t\t.read((executor) => this.#visibleEntry(executor, conversationId, id, context), context)\n\t\t\t\t.then(told);\n\t\t});\n\t}\n\n\tfindLatestHeadMarker(\n\t\tconversationId: ConversationId,\n\t\tatOrBeforeEntryId: EntryId | undefined,\n\t\tcontext: Context,\n\t): Promise<(EntryRecord & { readonly head: EntryId }) | undefined> {\n\t\treturn this.#reading(() =>\n\t\t\tthis.#store\n\t\t\t\t.read((executor) => this.#latestHeadMarker(executor, conversationId, atOrBeforeEntryId, context), context)\n\t\t\t\t.then(told),\n\t\t);\n\t}\n\n\tscanEntries(\n\t\tquery: EntryQuery,\n\t\tlimit: number,\n\t\tcursor: Cursor | undefined,\n\t\tcontext: Context,\n\t): Promise<Page<EntryRecord, Cursor>> {\n\t\treturn this.#reading(() => {\n\t\t\tconst { order, after } = scanStart(query.order, cursor, \"descending\");\n\t\t\tconst read =\n\t\t\t\torder === \"ascending\"\n\t\t\t\t\t? (executor: SqliteExecutor) => this.#entriesAscending(executor, query, limit, after, context)\n\t\t\t\t\t: (executor: SqliteExecutor) => this.#entriesDescending(executor, query, limit, after, context);\n\t\t\treturn this.#store.read(read, context).then(told);\n\t\t});\n\t}\n\n\ttask(id: TaskId, context: Context): Promise<StoredTask | undefined> {\n\t\tconst tasks = this.#queries.tasks;\n\t\treturn this.#read(async (executor) => {\n\t\t\tconst row = await tasks.byId(executor, id);\n\t\t\treturn row === undefined ? undefined : tasks.record<StoredTask>(row, context);\n\t\t}, context);\n\t}\n\n\tscanTasks(\n\t\tquery: TaskQuery,\n\t\tlimit: number,\n\t\tcursor: Cursor | undefined,\n\t\tcontext: Context,\n\t): Promise<Page<StoredTask, Cursor>> {\n\t\treturn this.#reading(() => {\n\t\t\tconst start = scanStart(query.order, cursor, \"ascending\");\n\t\t\tconst conditions: Condition[] = [scanFrom(start)];\n\t\t\tif (query.conversationId !== undefined) conditions.push([\"conversation_id\", \"eq\", query.conversationId]);\n\t\t\tif (query.kind !== undefined) conditions.push([\"kind\", \"eq\", encodeIndexed(query.kind)]);\n\t\t\tif (query.status !== undefined) conditions.push([\"status\", \"eq\", query.status]);\n\t\t\tif (query.abortRequested !== undefined)\n\t\t\t\tconditions.push([\"abort_requested\", \"eq\", query.abortRequested ? 1 : 0]);\n\t\t\tif (query.background !== undefined) conditions.push([\"background\", \"eq\", query.background ? 1 : 0]);\n\t\t\treturn this.#scan<StoredTask>(this.#queries.tasks, conditions, start, limit, context);\n\t\t});\n\t}\n\n\tsubmission(id: SubmissionId, context: Context): Promise<SubmissionRecord | undefined> {\n\t\tconst submissions = this.#queries.submissions;\n\t\treturn this.#read(async (executor) => {\n\t\t\tconst row = await submissions.byId(executor, id);\n\t\t\treturn row === undefined ? undefined : submissions.record<SubmissionRecord>(row, context);\n\t\t}, context);\n\t}\n\n\tscanSubmissions(\n\t\tquery: SubmissionQuery,\n\t\tlimit: number,\n\t\tcursor: Cursor | undefined,\n\t\tcontext: Context,\n\t): Promise<Page<SubmissionRecord, Cursor>> {\n\t\treturn this.#reading(() => {\n\t\t\tconst start = scanStart(query.order, cursor, \"ascending\");\n\t\t\tconst conditions: Condition[] = [scanFrom(start)];\n\t\t\tif (query.conversationId !== undefined) conditions.push([\"conversation_id\", \"eq\", query.conversationId]);\n\t\t\tif (query.status !== undefined) conditions.push([\"status\", \"eq\", query.status]);\n\t\t\treturn this.#scan<SubmissionRecord>(this.#queries.submissions, conditions, start, limit, context);\n\t\t});\n\t}\n\n\tsubmissionByRequest(\n\t\tconversationId: ConversationId,\n\t\trequestId: string,\n\t\tcontext: Context,\n\t): Promise<SubmissionRecord | undefined> {\n\t\tconst submissions = this.#queries.submissions;\n\t\tconst conditions: Condition[] = [\n\t\t\t[\"conversation_id\", \"eq\", conversationId],\n\t\t\t[\"request_id\", \"eq\", encodeIndexed(requestId)],\n\t\t];\n\t\treturn this.#read(async (executor) => {\n\t\t\tconst row = await submissions.first(executor, conditions, \"ascending\");\n\t\t\treturn row === undefined ? undefined : submissions.record<SubmissionRecord>(row, context);\n\t\t}, context);\n\t}\n\n\tfindDocument(address: DocumentAddress, at: DocumentPoint, context: Context): Promise<DocumentRecord | undefined> {\n\t\treturn this.#read(async (executor) => {\n\t\t\tconst entry = await findDocumentEntry(executor, addressOf(address, this.#owner), at);\n\t\t\treturn entry === undefined ? undefined : recordOfEntry(entry);\n\t\t}, context);\n\t}\n\n\tdocument(id: DocumentId, at: DocumentPoint, context: Context): Promise<StoredDocument | undefined> {\n\t\t// The record and its revisions must come from one committed state (S4).\n\t\treturn this.#reading(() =>\n\t\t\tthis.#store.readTransaction((executor) => readAt(executor, id, at, this.#owner), context).then(documentOf),\n\t\t);\n\t}\n\n\tscanDocuments(\n\t\tquery: DocumentQuery,\n\t\tlimit: number,\n\t\tcursor: Cursor | undefined,\n\t\tcontext: Context,\n\t): Promise<Page<DocumentRecord, Cursor>> {\n\t\treturn this.#reading(() => {\n\t\t\tconst after = cursorId(cursor) ?? -1;\n\t\t\tconst scope = {\n\t\t\t\towner: this.#owner,\n\t\t\t\tnamespace: namespaceOf(query.scope),\n\t\t\t\t...(query.kind === undefined ? {} : { kind: encodeIndexed(query.kind) }),\n\t\t\t};\n\t\t\treturn this.#store\n\t\t\t\t.read((executor) => listDocumentEntries(executor, scope, query.at, after, limit + 1), context)\n\t\t\t\t.then((found) => page(found.map(recordOfEntry), limit, \"ascending\"));\n\t\t});\n\t}\n\n\t/**\n\t * Refuses new calls, waits for its commits underway, then releases its claims; the store stays open (the app's),\n\t * and finishes the reads underway, which change nothing.\n\t */\n\tclose(_context: Context): Promise<void> {\n\t\tif (this.#closing === undefined) {\n\t\t\tthis.#closed = true;\n\t\t\tthis.#closing = (async () => {\n\t\t\t\tif (this.#underway > 0) {\n\t\t\t\t\tawait new Promise<void>((resolve) => {\n\t\t\t\t\t\tthis.#drained = resolve;\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t\tthis.#store.claims.release(this.#claimant);\n\t\t\t})();\n\t\t}\n\t\treturn this.#closing;\n\t}\n\n\t/** Runs one commit or mint of this storage: refused once it closed, counted until it settles (`close` waits). */\n\tasync #call<T>(run: () => Promise<T>): Promise<T> {\n\t\tif (this.#closed) throw new Error(\"StoreStorage is closed\");\n\t\tthis.#underway++;\n\t\ttry {\n\t\t\treturn await run();\n\t\t} finally {\n\t\t\tif (--this.#underway === 0) this.#drained?.();\n\t\t}\n\t}\n\n\t/**\n\t * A call that is one guarded read of the store: refused once closed; not waited for by `close` (a read changes\n\t * nothing, and the store, which stays open, finishes it).\n\t */\n\t#read<T>(read: (executor: SqliteExecutor) => Promise<T>, context: Context): Promise<T> {\n\t\treturn this.#reading(() => this.#store.read(read, context));\n\t}\n\n\t/**\n\t * A read call: `read` prepares its guarded read (a request error thrown then, before it) and returns it. Refused\n\t * once closed; one promise per call besides the guard's (no async wrapper).\n\t */\n\t#reading<T>(read: () => Promise<T>): Promise<T> {\n\t\ttry {\n\t\t\tif (this.#closed) throw new Error(\"StoreStorage is closed\");\n\t\t\treturn read();\n\t\t} catch (error) {\n\t\t\treturn Promise.reject(error);\n\t\t}\n\t}\n\n\tasync #conversation(\n\t\texecutor: SqliteExecutor,\n\t\tid: ConversationId,\n\t\tcontext: Context,\n\t): Promise<ConversationRecord | undefined> {\n\t\tconst conversations = this.#queries.conversations;\n\t\tconst row = await conversations.byId(executor, id);\n\t\treturn row === undefined ? undefined : conversations.record<ConversationRecord>(row, context);\n\t}\n\n\t#entry(executor: SqliteExecutor, id: EntryId, context: Context): Promise<StoredEntry | undefined> {\n\t\tconst entries = this.#queries.entries;\n\t\treturn entries.byId(executor, id).then((row) => {\n\t\t\tif (row === undefined) return undefined;\n\t\t\treturn { entry: entries.record<EntryRecord>(row, context), commitSeq: seqFromNumber(row.commit_seq!) };\n\t\t});\n\t}\n\n\t/** Entry `id` when visible through `conversationId`'s fork chain (`SqliteStorage.readEntry`). */\n\tasync #visibleEntry(\n\t\texecutor: SqliteExecutor,\n\t\tconversationId: ConversationId,\n\t\tid: EntryId,\n\t\tcontext: Context,\n\t): Promise<Read<StoredEntry | undefined>> {\n\t\tlet conversation = await this.#conversation(executor, conversationId, context);\n\t\tif (conversation === undefined) return unknownConversation(conversationId);\n\t\tconst stored = await this.#entry(executor, id, context);\n\t\tif (stored === undefined) return NOTHING_FOUND;\n\t\tlet upper = Number.POSITIVE_INFINITY;\n\t\twhile (conversation.id !== stored.entry.conversationId) {\n\t\t\tif (conversation.parent === undefined) return NOTHING_FOUND;\n\t\t\tupper = Math.min(upper, conversation.parent.at);\n\t\t\tconversation = (await this.#conversation(executor, conversation.parent.conversationId, context))!;\n\t\t}\n\t\treturn stored.entry.id > upper ? NOTHING_FOUND : { kind: \"found\", value: stored };\n\t}\n\n\tasync #latestHeadMarker(\n\t\texecutor: SqliteExecutor,\n\t\tconversationId: ConversationId,\n\t\tatOrBeforeEntryId: EntryId | undefined,\n\t\tcontext: Context,\n\t): Promise<Read<(EntryRecord & { readonly head: EntryId }) | undefined>> {\n\t\tlet conversation = await this.#conversation(executor, conversationId, context);\n\t\tif (conversation === undefined) return unknownConversation(conversationId);\n\t\tlet upper: number | undefined = atOrBeforeEntryId;\n\t\twhile (true) {\n\t\t\tconst { latestHead } = this.#queries;\n\t\t\tconst head =\n\t\t\t\tupper === undefined\n\t\t\t\t\t? await executor.get<{ readonly id: number }>(latestHead.any, conversation.id)\n\t\t\t\t\t: await executor.get<{ readonly id: number }>(latestHead.atOrBefore, conversation.id, upper);\n\t\t\tif (head !== undefined) {\n\t\t\t\t// Written with its entry, in the same commit.\n\t\t\t\tconst row = (await this.#queries.entries.byId(executor, head.id))!;\n\t\t\t\tconst value = this.#queries.entries.record<EntryRecord & { readonly head: EntryId }>(row, context);\n\t\t\t\treturn { kind: \"found\", value };\n\t\t\t}\n\t\t\tif (conversation.parent === undefined) return NOTHING_FOUND;\n\t\t\tupper = upper === undefined ? conversation.parent.at : Math.min(upper, conversation.parent.at);\n\t\t\tconversation = (await this.#conversation(executor, conversation.parent.conversationId, context))!;\n\t\t}\n\t}\n\n\t/** Newest first: each conversation of the fork chain up to its fork point (`SqliteStorage.readEntries`). */\n\tasync #entriesDescending(\n\t\texecutor: SqliteExecutor,\n\t\tquery: EntryQuery,\n\t\tlimit: number,\n\t\tafter: number | undefined,\n\t\tcontext: Context,\n\t): Promise<Read<Page<EntryRecord, Cursor>>> {\n\t\tlet conversation = await this.#conversation(executor, query.conversationId, context);\n\t\tif (conversation === undefined) return unknownConversation(query.conversationId);\n\t\tlet upper: number | undefined = query.maxEntryId;\n\t\tif (after !== undefined) upper = Math.min(upper ?? Number.MAX_SAFE_INTEGER, after - 1);\n\t\tconst values: EntryRecord[] = [];\n\t\twhile (true) {\n\t\t\tconst range = this.#range(conversation.id, query.minEntryId, upper);\n\t\t\tconst rows = await this.#queries.entries.select(executor, range, \"descending\", limit + 1 - values.length);\n\t\t\tthis.#queries.entries.records(rows, values, context);\n\t\t\tif (values.length > limit || conversation.parent === undefined) break;\n\t\t\tupper = upper === undefined ? conversation.parent.at : Math.min(upper, conversation.parent.at);\n\t\t\tif (query.minEntryId !== undefined && upper < query.minEntryId) break;\n\t\t\tconversation = (await this.#conversation(executor, conversation.parent.conversationId, context))!;\n\t\t}\n\t\treturn { kind: \"found\", value: page(values, limit, \"descending\") };\n\t}\n\n\t/** Oldest first: the fork chain's segments from the root forward, each up to its fork point. */\n\tasync #entriesAscending(\n\t\texecutor: SqliteExecutor,\n\t\tquery: EntryQuery,\n\t\tlimit: number,\n\t\tafter: number | undefined,\n\t\tcontext: Context,\n\t): Promise<Read<Page<EntryRecord, Cursor>>> {\n\t\tconst segments: { readonly conversationId: ConversationId; readonly upper: number | undefined }[] = [];\n\t\tlet conversation = await this.#conversation(executor, query.conversationId, context);\n\t\tif (conversation === undefined) return unknownConversation(query.conversationId);\n\t\tlet upper: number | undefined = query.maxEntryId;\n\t\twhile (true) {\n\t\t\tsegments.push({ conversationId: conversation.id, upper });\n\t\t\tif (conversation.parent === undefined) break;\n\t\t\tupper = upper === undefined ? conversation.parent.at : Math.min(upper, conversation.parent.at);\n\t\t\tif (query.minEntryId !== undefined && upper < query.minEntryId) break;\n\t\t\tconversation = (await this.#conversation(executor, conversation.parent.conversationId, context))!;\n\t\t}\n\t\tlet lower: number | undefined = query.minEntryId;\n\t\tif (after !== undefined) lower = Math.max(lower ?? after + 1, after + 1);\n\t\tconst values: EntryRecord[] = [];\n\t\tfor (const segment of segments.reverse()) {\n\t\t\tconst range = this.#range(segment.conversationId, lower, segment.upper);\n\t\t\tconst rows = await this.#queries.entries.select(executor, range, \"ascending\", limit + 1 - values.length);\n\t\t\tthis.#queries.entries.records(rows, values, context);\n\t\t\tif (values.length > limit) break;\n\t\t}\n\t\treturn { kind: \"found\", value: page(values, limit, \"ascending\") };\n\t}\n\n\t/** One conversation's entries with ids from `lower` to `upper` (inclusive, each optional). */\n\t#range(conversationId: ConversationId, lower: number | undefined, upper: number | undefined): Condition[] {\n\t\tconst conditions: Condition[] = [[\"conversation_id\", \"eq\", conversationId]];\n\t\tif (lower !== undefined) conditions.push([\"id\", \"gte\", lower]);\n\t\tif (upper !== undefined) conditions.push([\"id\", \"lte\", upper]);\n\t\treturn conditions;\n\t}\n\n\t/** A page of a table scan: up to `limit` records of `queries`' table whose `conditions` hold, from `start`. */\n\t#scan<T extends { readonly id: Id<string> }>(\n\t\tqueries: TableQueries,\n\t\tconditions: readonly Condition[],\n\t\tstart: ScanStart,\n\t\tlimit: number,\n\t\tcontext: Context,\n\t): Promise<Page<T, Cursor>> {\n\t\treturn this.#store\n\t\t\t.read((executor) => queries.select(executor, conditions, start.order, limit + 1), context)\n\t\t\t.then((rows) => {\n\t\t\t\tconst values: T[] = [];\n\t\t\t\tqueries.records(rows, values, context);\n\t\t\t\treturn page(values, limit, start.order);\n\t\t\t});\n\t}\n}\n\n/** A read that found nothing. */\nconst NOTHING_FOUND: Read<undefined> = { kind: \"found\", value: undefined };\n\nfunction unknownConversation(id: ConversationId): Read<never> {\n\treturn { kind: \"refused\", message: `Unknown conversation: ${id}` };\n}\n\n/** A read's data, its request error thrown now that the guarded read returned (slice 6b §1.4). */\nfunction told<T>(read: Read<T>): T {\n\tif (read.kind === \"refused\") throw new StorageRequestError(read.message);\n\treturn read.value;\n}\n\n/** A document read's result, a record that keeps no history at the point thrown as Durable's request error. */\nfunction documentOf(read: DocumentRead): StoredDocument | undefined {\n\tif (read.kind === \"current_only\")\n\t\tthrow new StorageRequestError(`Document ${read.id} does not retain historical content`);\n\treturn read.document;\n}\n"]}
|
|
@@ -1,45 +1,45 @@
|
|
|
1
|
-
import type { JsonValue } from "@earendil-works/chord";
|
|
1
|
+
import type { JsonValue } from "@earendil-works/chord/json";
|
|
2
2
|
import type { ConversationRecord, EntryRecord, SubmissionRecord, TaskRecord } from "../../types.ts";
|
|
3
3
|
/** Which record type owns an id: Durable's one namespace across its five record types. */
|
|
4
|
-
export declare const RecordIds: import("@earendil-works/chord
|
|
5
|
-
id: import("@earendil-works/chord
|
|
6
|
-
record_type: import("@earendil-works/chord
|
|
4
|
+
export declare const RecordIds: import("@earendil-works/chord").TableDefinition<{
|
|
5
|
+
id: import("@earendil-works/chord").IntegerSchema;
|
|
6
|
+
record_type: import("@earendil-works/chord").StringSchema;
|
|
7
7
|
}, readonly ["id"], 1>;
|
|
8
|
-
export declare const Conversations: import("@earendil-works/chord
|
|
9
|
-
id: import("@earendil-works/chord
|
|
10
|
-
owner_conversation_id: import("@earendil-works/chord
|
|
11
|
-
owner_task_id: import("@earendil-works/chord
|
|
12
|
-
record: import("@earendil-works/chord
|
|
8
|
+
export declare const Conversations: import("@earendil-works/chord").TableDefinition<{
|
|
9
|
+
id: import("@earendil-works/chord").IntegerSchema;
|
|
10
|
+
owner_conversation_id: import("@earendil-works/chord").IntegerSchema;
|
|
11
|
+
owner_task_id: import("@earendil-works/chord").IntegerSchema;
|
|
12
|
+
record: import("@earendil-works/chord").JsonColumnSchema<unknown>;
|
|
13
13
|
}, readonly ["id"], 1>;
|
|
14
|
-
export declare const Entries: import("@earendil-works/chord
|
|
15
|
-
id: import("@earendil-works/chord
|
|
16
|
-
conversation_id: import("@earendil-works/chord
|
|
17
|
-
commit_seq: import("@earendil-works/chord
|
|
18
|
-
record: import("@earendil-works/chord
|
|
14
|
+
export declare const Entries: import("@earendil-works/chord").TableDefinition<{
|
|
15
|
+
id: import("@earendil-works/chord").IntegerSchema;
|
|
16
|
+
conversation_id: import("@earendil-works/chord").IntegerSchema;
|
|
17
|
+
commit_seq: import("@earendil-works/chord").IntegerSchema;
|
|
18
|
+
record: import("@earendil-works/chord").JsonColumnSchema<unknown>;
|
|
19
19
|
}, readonly ["id"], 1>;
|
|
20
20
|
/**
|
|
21
21
|
* The entries with a head marker, by conversation: what `SqliteStorage`'s partial index on `head IS NOT NULL` is,
|
|
22
22
|
* as rows written only with such an entry, so a commit of an entry without one updates no second index.
|
|
23
23
|
*/
|
|
24
|
-
export declare const EntryHeads: import("@earendil-works/chord
|
|
25
|
-
id: import("@earendil-works/chord
|
|
26
|
-
conversation_id: import("@earendil-works/chord
|
|
24
|
+
export declare const EntryHeads: import("@earendil-works/chord").TableDefinition<{
|
|
25
|
+
id: import("@earendil-works/chord").IntegerSchema;
|
|
26
|
+
conversation_id: import("@earendil-works/chord").IntegerSchema;
|
|
27
27
|
}, readonly ["id"], 1>;
|
|
28
|
-
export declare const Tasks: import("@earendil-works/chord
|
|
29
|
-
id: import("@earendil-works/chord
|
|
30
|
-
conversation_id: import("@earendil-works/chord
|
|
31
|
-
kind: import("@earendil-works/chord
|
|
32
|
-
status: import("@earendil-works/chord
|
|
33
|
-
abort_requested: import("@earendil-works/chord
|
|
34
|
-
background: import("@earendil-works/chord
|
|
35
|
-
record: import("@earendil-works/chord
|
|
28
|
+
export declare const Tasks: import("@earendil-works/chord").TableDefinition<{
|
|
29
|
+
id: import("@earendil-works/chord").IntegerSchema;
|
|
30
|
+
conversation_id: import("@earendil-works/chord").IntegerSchema;
|
|
31
|
+
kind: import("@earendil-works/chord").StringSchema;
|
|
32
|
+
status: import("@earendil-works/chord").StringSchema;
|
|
33
|
+
abort_requested: import("@earendil-works/chord").IntegerSchema;
|
|
34
|
+
background: import("@earendil-works/chord").IntegerSchema;
|
|
35
|
+
record: import("@earendil-works/chord").JsonColumnSchema<unknown>;
|
|
36
36
|
}, readonly ["id"], 1>;
|
|
37
|
-
export declare const Submissions: import("@earendil-works/chord
|
|
38
|
-
id: import("@earendil-works/chord
|
|
39
|
-
conversation_id: import("@earendil-works/chord
|
|
40
|
-
request_id: import("@earendil-works/chord
|
|
41
|
-
status: import("@earendil-works/chord
|
|
42
|
-
record: import("@earendil-works/chord
|
|
37
|
+
export declare const Submissions: import("@earendil-works/chord").TableDefinition<{
|
|
38
|
+
id: import("@earendil-works/chord").IntegerSchema;
|
|
39
|
+
conversation_id: import("@earendil-works/chord").IntegerSchema;
|
|
40
|
+
request_id: import("@earendil-works/chord").StringSchema;
|
|
41
|
+
status: import("@earendil-works/chord").StringSchema;
|
|
42
|
+
record: import("@earendil-works/chord").JsonColumnSchema<unknown>;
|
|
43
43
|
}, readonly ["id"], 1>;
|
|
44
44
|
/** Durable's JSON encoding of an indexed string: lossless whatever the string (lone surrogates, NUL). */
|
|
45
45
|
export declare const encodeIndexed: (value: string) => string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tables.d.ts","sourceRoot":"","sources":["../../../src/storage/store/tables.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"tables.d.ts","sourceRoot":"","sources":["../../../src/storage/store/tables.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,4BAA4B,CAAC;AAC5D,OAAO,KAAK,EAAE,kBAAkB,EAAE,WAAW,EAAE,gBAAgB,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAKpG,0FAA0F;AAC1F,eAAO,MAAM,SAAS;;;sBAIpB,CAAC;AAEH,eAAO,MAAM,aAAa;;;;;sBAKxB,CAAC;AAEH,eAAO,MAAM,OAAO;;;;;sBAKlB,CAAC;AAEH;;;GAGG;AACH,eAAO,MAAM,UAAU;;;sBAKrB,CAAC;AAEH,eAAO,MAAM,KAAK;;;;;;;;sBAmBhB,CAAC;AAEH,eAAO,MAAM,WAAW;;;;;;sBAStB,CAAC;AAEH,yGAAyG;AACzG,eAAO,MAAM,aAAa,UAAW,MAAM,KAAG,MAA+B,CAAC;AAE9E,wCAAwC;AACxC,wBAAgB,eAAe,CAAC,KAAK,EAAE,kBAAkB,GAAG,MAAM,CAOjE;AAED,uEAAuE;AACvE,wBAAgB,QAAQ,CAAC,KAAK,EAAE,WAAW,GAAG,MAAM,CAOnD;AAED,gCAAgC;AAChC,wBAAgB,OAAO,CAAC,KAAK,EAAE,UAAU,CAAC,SAAS,EAAE,SAAS,EAAE,SAAS,CAAC,GAAG,MAAM,CAUlF;AAED,sCAAsC;AACtC,wBAAgB,aAAa,CAAC,KAAK,EAAE,gBAAgB,GAAG,MAAM,CAQ7D"}
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// and the whole record as one `json(...)` cell. Indexed strings that must stay lossless (`kind`, `request_id`) hold
|
|
3
3
|
// Durable's JSON encoding; index columns are never `opt`, so absent values take sentinels no encoded value can be
|
|
4
4
|
// (`0` for an absent owner, which is never an id; `""` for an absent request id: an encoded string starts with `"`).
|
|
5
|
-
import { defineTable, int, json, str, unknown } from "@earendil-works/chord
|
|
5
|
+
import { defineTable, int, json, str, unknown } from "@earendil-works/chord";
|
|
6
6
|
/** A record as one `json(...)` cell. */
|
|
7
7
|
const record = () => json(unknown(), { version: 1 });
|
|
8
8
|
/** Which record type owns an id: Durable's one namespace across its five record types. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tables.js","sourceRoot":"","sources":["../../../src/storage/store/tables.ts"],"names":[],"mappings":"AAAA,wHAAwH;AACxH,oHAAoH;AACpH,kHAAkH;AAClH,qHAAqH;
|
|
1
|
+
{"version":3,"file":"tables.js","sourceRoot":"","sources":["../../../src/storage/store/tables.ts"],"names":[],"mappings":"AAAA,wHAAwH;AACxH,oHAAoH;AACpH,kHAAkH;AAClH,qHAAqH;AAErH,OAAO,EAAE,WAAW,EAAE,GAAG,EAAE,IAAI,EAAE,GAAG,EAAE,OAAO,EAAE,MAAM,uBAAuB,CAAC;AAI7E,wCAAwC;AACxC,MAAM,MAAM,GAAG,GAAG,EAAE,CAAC,IAAI,CAAC,OAAO,EAAE,EAAE,EAAE,OAAO,EAAE,CAAC,EAAE,CAAC,CAAC;AAErD,0FAA0F;AAC1F,MAAM,CAAC,MAAM,SAAS,GAAG,WAAW,CAAC,YAAY,EAAE;IAClD,OAAO,EAAE,CAAC;IACV,OAAO,EAAE,EAAE,EAAE,EAAE,GAAG,EAAE,EAAE,WAAW,EAAE,GAAG,EAAE,EAAE;IAC1C,GAAG,EAAE,CAAC,IAAI,CAAC;CACX,CAAC,CAAC;AAEH,MAAM,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AM,UAAU,QAAQ,CAAC,KAAkB;IAC1C,OAAO;QACN,EAAE,EAAE,KAAK,CAAC,EAAE;QACZ,eAAe,EAAE,KAAK,CAAC,cAAc;QACrC,UAAU,EAAE,CAAC;QACb,MAAM,EAAE,KAAK;KACb,CAAC;AACH,CAAC;AAED,gCAAgC;AAChC,MAAM,UAAU,OAAO,CAAC,KAAkD;IACzE,OAAO;QACN,EAAE,EAAE,KAAK,CAAC,EAAE;QACZ,eAAe,EAAE,KAAK,CAAC,cAAc;QACrC,IAAI,EAAE,aAAa,CAAC,KAAK,CAAC,IAAI,CAAC;QAC/B,MAAM,EAAE,KAAK,CAAC,KAAK,CAAC,MAAM;QAC1B,eAAe,EAAE,KAAK,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;QAC7C,UAAU,EAAE,KAAK,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;QACpC,MAAM,EAAE,KAAK;KACb,CAAC;AACH,CAAC;AAED,sCAAsC;AACtC,MAAM,UAAU,aAAa,CAAC,KAAuB;IACpD,OAAO;QACN,EAAE,EAAE,KAAK,CAAC,EAAE;QACZ,eAAe,EAAE,KAAK,CAAC,cAAc;QACrC,UAAU,EAAE,KAAK,CAAC,SAAS,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,aAAa,CAAC,KAAK,CAAC,SAAS,CAAC;QAC/E,MAAM,EAAE,KAAK,CAAC,MAAM;QACpB,MAAM,EAAE,KAAK;KACb,CAAC;AACH,CAAC","sourcesContent":["// Durable's records as declared tables of the store (slice 6b D2, §2.2): every row carries its record's indexed columns\n// and the whole record as one `json(...)` cell. Indexed strings that must stay lossless (`kind`, `request_id`) hold\n// Durable's JSON encoding; index columns are never `opt`, so absent values take sentinels no encoded value can be\n// (`0` for an absent owner, which is never an id; `\"\"` for an absent request id: an encoded string starts with `\"`).\n\nimport { defineTable, int, json, str, unknown } from \"@earendil-works/chord\";\nimport type { JsonValue } from \"@earendil-works/chord/json\";\nimport type { ConversationRecord, EntryRecord, SubmissionRecord, TaskRecord } from \"../../types.ts\";\n\n/** A record as one `json(...)` cell. */\nconst record = () => json(unknown(), { version: 1 });\n\n/** Which record type owns an id: Durable's one namespace across its five record types. */\nexport const RecordIds = defineTable(\"record_ids\", {\n\tversion: 1,\n\tcolumns: { id: int(), record_type: str() },\n\tkey: [\"id\"],\n});\n\nexport const Conversations = defineTable(\"conversations\", {\n\tversion: 1,\n\tcolumns: { id: int(), owner_conversation_id: int(), owner_task_id: int(), record: record() },\n\tkey: [\"id\"],\n\tindexes: { by_owner_conversation: [\"owner_conversation_id\"], by_owner_task: [\"owner_task_id\"] },\n});\n\nexport const Entries = defineTable(\"entries\", {\n\tversion: 1,\n\tcolumns: { id: int(), conversation_id: int(), commit_seq: int(), record: record() },\n\tkey: [\"id\"],\n\tindexes: { by_conversation: [\"conversation_id\"] },\n});\n\n/**\n * The entries with a head marker, by conversation: what `SqliteStorage`'s partial index on `head IS NOT NULL` is,\n * as rows written only with such an entry, so a commit of an entry without one updates no second index.\n */\nexport const EntryHeads = defineTable(\"entry_heads\", {\n\tversion: 1,\n\tcolumns: { id: int(), conversation_id: int() },\n\tkey: [\"id\"],\n\tindexes: { by_conversation: [\"conversation_id\"] },\n});\n\nexport const Tasks = defineTable(\"tasks\", {\n\tversion: 1,\n\tcolumns: {\n\t\tid: int(),\n\t\tconversation_id: int(),\n\t\tkind: str(),\n\t\tstatus: str(),\n\t\tabort_requested: int(),\n\t\tbackground: int(),\n\t\trecord: record(),\n\t},\n\tkey: [\"id\"],\n\tindexes: {\n\t\tby_status: [\"status\"],\n\t\tby_conversation: [\"conversation_id\"],\n\t\tby_kind: [\"kind\"],\n\t\tby_abort_requested: [\"abort_requested\"],\n\t\tby_background: [\"background\"],\n\t},\n});\n\nexport const Submissions = defineTable(\"submissions\", {\n\tversion: 1,\n\tcolumns: { id: int(), conversation_id: int(), request_id: str(), status: str(), record: record() },\n\tkey: [\"id\"],\n\tindexes: {\n\t\tby_request: [\"conversation_id\", \"request_id\"],\n\t\tby_conversation: [\"conversation_id\"],\n\t\tby_status: [\"status\"],\n\t},\n});\n\n/** Durable's JSON encoding of an indexed string: lossless whatever the string (lone surrogates, NUL). */\nexport const encodeIndexed = (value: string): string => JSON.stringify(value);\n\n/** The row of a conversation record. */\nexport function conversationRow(value: ConversationRecord): object {\n\treturn {\n\t\tid: value.id,\n\t\towner_conversation_id: value.owner?.conversationId ?? 0,\n\t\towner_task_id: value.owner?.taskId ?? 0,\n\t\trecord: value,\n\t};\n}\n\n/** The row of an entry record; `commit_seq` is stamped by the step. */\nexport function entryRow(value: EntryRecord): object {\n\treturn {\n\t\tid: value.id,\n\t\tconversation_id: value.conversationId,\n\t\tcommit_seq: 0,\n\t\trecord: value,\n\t};\n}\n\n/** The row of a task record. */\nexport function taskRow(value: TaskRecord<JsonValue, JsonValue, JsonValue>): object {\n\treturn {\n\t\tid: value.id,\n\t\tconversation_id: value.conversationId,\n\t\tkind: encodeIndexed(value.kind),\n\t\tstatus: value.state.status,\n\t\tabort_requested: value.abortRequested ? 1 : 0,\n\t\tbackground: value.background ? 1 : 0,\n\t\trecord: value,\n\t};\n}\n\n/** The row of a submission record. */\nexport function submissionRow(value: SubmissionRecord): object {\n\treturn {\n\t\tid: value.id,\n\t\tconversation_id: value.conversationId,\n\t\trequest_id: value.requestId === undefined ? \"\" : encodeIndexed(value.requestId),\n\t\tstatus: value.status,\n\t\trecord: value,\n\t};\n}\n"]}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Context } from "@earendil-works/chord";
|
|
1
|
+
import type { Context } from "@earendil-works/chord/context";
|
|
2
2
|
import type { Seq, Storage, StorageWrite } from "../types.ts";
|
|
3
3
|
/** Commits `writes` as one batch and resolves with its seq; rejects with the refusal if the storage refused it. */
|
|
4
4
|
export declare function commitWrites(storage: Storage, writes: readonly StorageWrite[], context: Context): Promise<Seq>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"commit-writes.d.ts","sourceRoot":"","sources":["../../src/testing/commit-writes.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"commit-writes.d.ts","sourceRoot":"","sources":["../../src/testing/commit-writes.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,+BAA+B,CAAC;AAC7D,OAAO,KAAK,EAAE,GAAG,EAAE,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAE9D,mHAAmH;AACnH,wBAAsB,YAAY,CAAC,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,SAAS,YAAY,EAAE,EAAE,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,GAAG,CAAC,CAWpH"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"commit-writes.js","sourceRoot":"","sources":["../../src/testing/commit-writes.ts"],"names":[],"mappings":"AAAA,oGAAoG;AAKpG,mHAAmH;AACnH,MAAM,CAAC,KAAK,UAAU,YAAY,CAAC,OAAgB,EAAE,MAA+B,EAAE,OAAgB;IACrG,IAAI,MAAuB,CAAC;IAC5B,MAAM,MAAM,GAAG,MAAM,OAAO,CAAC,MAAM,CAClC,CAAC,MAAM,CAAC,EACR,CAAC,MAAM,EAAE,GAAG,EAAE,EAAE;QACf,MAAM,GAAG,GAAG,CAAC;IACd,CAAC,EACD,OAAO,CACP,CAAC;IACF,IAAI,MAAM,CAAC,MAAM,KAAK,CAAC;QAAE,MAAM,MAAM,CAAC,OAAO,CAAC;IAC9C,OAAO,MAAO,CAAC;AAChB,CAAC","sourcesContent":["// One batch through `Storage.commit()`, for tests and suites that seed or write a storage directly.\n\nimport type { Context } from \"@earendil-works/chord\";\nimport type { Seq, Storage, StorageWrite } from \"../types.ts\";\n\n/** Commits `writes` as one batch and resolves with its seq; rejects with the refusal if the storage refused it. */\nexport async function commitWrites(storage: Storage, writes: readonly StorageWrite[], context: Context): Promise<Seq> {\n\tlet stored: Seq | undefined;\n\tconst result = await storage.commit(\n\t\t[writes],\n\t\t(_index, seq) => {\n\t\t\tstored = seq;\n\t\t},\n\t\tcontext,\n\t);\n\tif (result.stored === 0) throw result.refused;\n\treturn stored!;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"commit-writes.js","sourceRoot":"","sources":["../../src/testing/commit-writes.ts"],"names":[],"mappings":"AAAA,oGAAoG;AAKpG,mHAAmH;AACnH,MAAM,CAAC,KAAK,UAAU,YAAY,CAAC,OAAgB,EAAE,MAA+B,EAAE,OAAgB;IACrG,IAAI,MAAuB,CAAC;IAC5B,MAAM,MAAM,GAAG,MAAM,OAAO,CAAC,MAAM,CAClC,CAAC,MAAM,CAAC,EACR,CAAC,MAAM,EAAE,GAAG,EAAE,EAAE;QACf,MAAM,GAAG,GAAG,CAAC;IACd,CAAC,EACD,OAAO,CACP,CAAC;IACF,IAAI,MAAM,CAAC,MAAM,KAAK,CAAC;QAAE,MAAM,MAAM,CAAC,OAAO,CAAC;IAC9C,OAAO,MAAO,CAAC;AAChB,CAAC","sourcesContent":["// One batch through `Storage.commit()`, for tests and suites that seed or write a storage directly.\n\nimport type { Context } from \"@earendil-works/chord/context\";\nimport type { Seq, Storage, StorageWrite } from \"../types.ts\";\n\n/** Commits `writes` as one batch and resolves with its seq; rejects with the refusal if the storage refused it. */\nexport async function commitWrites(storage: Storage, writes: readonly StorageWrite[], context: Context): Promise<Seq> {\n\tlet stored: Seq | undefined;\n\tconst result = await storage.commit(\n\t\t[writes],\n\t\t(_index, seq) => {\n\t\t\tstored = seq;\n\t\t},\n\t\tcontext,\n\t);\n\tif (result.stored === 0) throw result.refused;\n\treturn stored!;\n}\n"]}
|