@draht/chord 2026.10.20 → 2026.10.23

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.
Files changed (220) hide show
  1. package/dist/cell.d.ts +122 -0
  2. package/dist/cell.d.ts.map +1 -0
  3. package/dist/cell.js +356 -0
  4. package/dist/cell.js.map +1 -0
  5. package/dist/cluster.d.ts +27 -0
  6. package/dist/cluster.d.ts.map +1 -0
  7. package/dist/cluster.js +230 -0
  8. package/dist/cluster.js.map +1 -0
  9. package/dist/connection.d.ts +270 -0
  10. package/dist/connection.d.ts.map +1 -0
  11. package/dist/connection.js +1216 -0
  12. package/dist/connection.js.map +1 -0
  13. package/dist/context/index.d.ts +20 -1
  14. package/dist/context/index.d.ts.map +1 -1
  15. package/dist/context/index.js +15 -0
  16. package/dist/context/index.js.map +1 -1
  17. package/dist/contract.d.ts +208 -0
  18. package/dist/contract.d.ts.map +1 -0
  19. package/dist/contract.js +246 -0
  20. package/dist/contract.js.map +1 -0
  21. package/dist/declare.d.ts +33 -0
  22. package/dist/declare.d.ts.map +1 -0
  23. package/dist/declare.js +2 -0
  24. package/dist/declare.js.map +1 -0
  25. package/dist/delta/apply-immutable-trusted.js.map +1 -1
  26. package/dist/delta/diff.d.ts +1 -1
  27. package/dist/delta/diff.d.ts.map +1 -1
  28. package/dist/delta/diff.js.map +1 -1
  29. package/dist/delta/index.d.ts +4 -3
  30. package/dist/delta/index.d.ts.map +1 -1
  31. package/dist/delta/index.js +45 -0
  32. package/dist/delta/index.js.map +1 -1
  33. package/dist/delta/revision-validator.d.ts +1 -1
  34. package/dist/delta/revision-validator.d.ts.map +1 -1
  35. package/dist/delta/revision-validator.js.map +1 -1
  36. package/dist/delta/tracker.d.ts +1 -1
  37. package/dist/delta/tracker.d.ts.map +1 -1
  38. package/dist/delta/tracker.js +40 -4
  39. package/dist/delta/tracker.js.map +1 -1
  40. package/dist/errors.d.ts +28 -0
  41. package/dist/errors.d.ts.map +1 -0
  42. package/dist/errors.js +59 -0
  43. package/dist/errors.js.map +1 -0
  44. package/dist/host.d.ts +348 -0
  45. package/dist/host.d.ts.map +1 -0
  46. package/dist/host.js +1000 -0
  47. package/dist/host.js.map +1 -0
  48. package/dist/index.d.ts +17 -10
  49. package/dist/index.d.ts.map +1 -1
  50. package/dist/index.js +8 -8
  51. package/dist/index.js.map +1 -1
  52. package/dist/json.d.ts +9 -1
  53. package/dist/json.d.ts.map +1 -1
  54. package/dist/json.js.map +1 -1
  55. package/dist/link.d.ts +109 -0
  56. package/dist/link.d.ts.map +1 -0
  57. package/dist/link.js +375 -0
  58. package/dist/link.js.map +1 -0
  59. package/dist/loader.d.ts +4 -0
  60. package/dist/loader.d.ts.map +1 -0
  61. package/dist/loader.js +73 -0
  62. package/dist/loader.js.map +1 -0
  63. package/dist/manager.d.ts +115 -0
  64. package/dist/manager.d.ts.map +1 -0
  65. package/dist/manager.js +345 -0
  66. package/dist/manager.js.map +1 -0
  67. package/dist/node.d.ts +3 -4
  68. package/dist/node.d.ts.map +1 -1
  69. package/dist/node.js +3 -2
  70. package/dist/node.js.map +1 -1
  71. package/dist/object.d.ts +438 -0
  72. package/dist/object.d.ts.map +1 -0
  73. package/dist/object.js +1571 -0
  74. package/dist/object.js.map +1 -0
  75. package/dist/output.d.ts +91 -0
  76. package/dist/output.d.ts.map +1 -0
  77. package/dist/output.js +360 -0
  78. package/dist/output.js.map +1 -0
  79. package/dist/publish.d.ts +5 -0
  80. package/dist/publish.d.ts.map +1 -0
  81. package/dist/publish.js +40 -0
  82. package/dist/publish.js.map +1 -0
  83. package/dist/registry.d.ts +25 -0
  84. package/dist/registry.d.ts.map +1 -0
  85. package/dist/registry.js +6 -0
  86. package/dist/registry.js.map +1 -0
  87. package/dist/reload.d.ts +126 -0
  88. package/dist/reload.d.ts.map +1 -0
  89. package/dist/reload.js +653 -0
  90. package/dist/reload.js.map +1 -0
  91. package/dist/remote.d.ts +165 -0
  92. package/dist/remote.d.ts.map +1 -0
  93. package/dist/remote.js +612 -0
  94. package/dist/remote.js.map +1 -0
  95. package/dist/schema.d.ts +21 -0
  96. package/dist/schema.d.ts.map +1 -0
  97. package/dist/schema.js +228 -0
  98. package/dist/schema.js.map +1 -0
  99. package/dist/sqlite/cloudflare.d.ts +52 -0
  100. package/dist/sqlite/cloudflare.d.ts.map +1 -0
  101. package/dist/sqlite/cloudflare.js +134 -0
  102. package/dist/sqlite/cloudflare.js.map +1 -0
  103. package/dist/sqlite/database.d.ts +37 -0
  104. package/dist/sqlite/database.d.ts.map +1 -0
  105. package/dist/sqlite/database.js +2 -0
  106. package/dist/sqlite/database.js.map +1 -0
  107. package/dist/sqlite/index.d.ts +4 -0
  108. package/dist/sqlite/index.d.ts.map +1 -0
  109. package/dist/sqlite/index.js +3 -0
  110. package/dist/sqlite/index.js.map +1 -0
  111. package/dist/sqlite/migrations.d.ts +10 -0
  112. package/dist/sqlite/migrations.d.ts.map +1 -0
  113. package/dist/sqlite/migrations.js +33 -0
  114. package/dist/sqlite/migrations.js.map +1 -0
  115. package/dist/sqlite/node.d.ts +38 -0
  116. package/dist/sqlite/node.d.ts.map +1 -0
  117. package/dist/sqlite/node.js +174 -0
  118. package/dist/sqlite/node.js.map +1 -0
  119. package/dist/sqlite/schema.d.ts +3 -0
  120. package/dist/sqlite/schema.d.ts.map +1 -0
  121. package/dist/sqlite/schema.js +10 -0
  122. package/dist/sqlite/schema.js.map +1 -0
  123. package/dist/state.d.ts +92 -0
  124. package/dist/state.d.ts.map +1 -0
  125. package/dist/{services/state.js → state.js} +28 -138
  126. package/dist/state.js.map +1 -0
  127. package/dist/telemetry-sqlite/index.d.ts +24 -0
  128. package/dist/telemetry-sqlite/index.d.ts.map +1 -0
  129. package/dist/telemetry-sqlite/index.js +273 -0
  130. package/dist/telemetry-sqlite/index.js.map +1 -0
  131. package/dist/telemetry-sqlite/store.d.ts +9 -0
  132. package/dist/telemetry-sqlite/store.d.ts.map +1 -0
  133. package/dist/telemetry-sqlite/store.js +110 -0
  134. package/dist/telemetry-sqlite/store.js.map +1 -0
  135. package/dist/types.d.ts +69 -254
  136. package/dist/types.d.ts.map +1 -1
  137. package/dist/types.js.map +1 -1
  138. package/dist/websocket.d.ts +15 -0
  139. package/dist/websocket.d.ts.map +1 -0
  140. package/dist/websocket.js +16 -0
  141. package/dist/websocket.js.map +1 -0
  142. package/dist/wire.d.ts +216 -0
  143. package/dist/wire.d.ts.map +1 -0
  144. package/dist/wire.js +165 -0
  145. package/dist/wire.js.map +1 -0
  146. package/docs/guide.md +814 -0
  147. package/docs/spec.md +288 -0
  148. package/docs/tutorial.md +931 -0
  149. package/package.json +36 -12
  150. package/dist/api.d.ts +0 -20
  151. package/dist/api.d.ts.map +0 -1
  152. package/dist/api.js +0 -77
  153. package/dist/api.js.map +0 -1
  154. package/dist/bundler.d.ts +0 -6
  155. package/dist/bundler.d.ts.map +0 -1
  156. package/dist/bundler.js +0 -3
  157. package/dist/bundler.js.map +0 -1
  158. package/dist/facets/host.d.ts +0 -12
  159. package/dist/facets/host.d.ts.map +0 -1
  160. package/dist/facets/host.js +0 -763
  161. package/dist/facets/host.js.map +0 -1
  162. package/dist/facets/loader.d.ts +0 -3
  163. package/dist/facets/loader.d.ts.map +0 -1
  164. package/dist/facets/loader.js +0 -5
  165. package/dist/facets/loader.js.map +0 -1
  166. package/dist/node/bundle-loader.d.ts +0 -30
  167. package/dist/node/bundle-loader.d.ts.map +0 -1
  168. package/dist/node/bundle-loader.js +0 -377
  169. package/dist/node/bundle-loader.js.map +0 -1
  170. package/dist/node/bundle.d.ts +0 -26
  171. package/dist/node/bundle.d.ts.map +0 -1
  172. package/dist/node/bundle.js +0 -183
  173. package/dist/node/bundle.js.map +0 -1
  174. package/dist/node/manifest.d.ts +0 -36
  175. package/dist/node/manifest.d.ts.map +0 -1
  176. package/dist/node/manifest.js +0 -6
  177. package/dist/node/manifest.js.map +0 -1
  178. package/dist/node/package.d.ts +0 -15
  179. package/dist/node/package.d.ts.map +0 -1
  180. package/dist/node/package.js +0 -199
  181. package/dist/node/package.js.map +0 -1
  182. package/dist/services/consumer.d.ts +0 -11
  183. package/dist/services/consumer.d.ts.map +0 -1
  184. package/dist/services/consumer.js +0 -585
  185. package/dist/services/consumer.js.map +0 -1
  186. package/dist/services/errors.d.ts +0 -8
  187. package/dist/services/errors.d.ts.map +0 -1
  188. package/dist/services/errors.js +0 -22
  189. package/dist/services/errors.js.map +0 -1
  190. package/dist/services/handle.d.ts +0 -15
  191. package/dist/services/handle.d.ts.map +0 -1
  192. package/dist/services/handle.js +0 -101
  193. package/dist/services/handle.js.map +0 -1
  194. package/dist/services/instances.d.ts +0 -26
  195. package/dist/services/instances.d.ts.map +0 -1
  196. package/dist/services/instances.js +0 -140
  197. package/dist/services/instances.js.map +0 -1
  198. package/dist/services/loopback.d.ts +0 -5
  199. package/dist/services/loopback.d.ts.map +0 -1
  200. package/dist/services/loopback.js +0 -15
  201. package/dist/services/loopback.js.map +0 -1
  202. package/dist/services/provider.d.ts +0 -37
  203. package/dist/services/provider.d.ts.map +0 -1
  204. package/dist/services/provider.js +0 -521
  205. package/dist/services/provider.js.map +0 -1
  206. package/dist/services/state-codec.d.ts +0 -15
  207. package/dist/services/state-codec.d.ts.map +0 -1
  208. package/dist/services/state-codec.js +0 -133
  209. package/dist/services/state-codec.js.map +0 -1
  210. package/dist/services/state-internals.d.ts +0 -13
  211. package/dist/services/state-internals.d.ts.map +0 -1
  212. package/dist/services/state-internals.js +0 -10
  213. package/dist/services/state-internals.js.map +0 -1
  214. package/dist/services/state.d.ts +0 -28
  215. package/dist/services/state.d.ts.map +0 -1
  216. package/dist/services/state.js.map +0 -1
  217. package/dist/services/wire.d.ts +0 -63
  218. package/dist/services/wire.d.ts.map +0 -1
  219. package/dist/services/wire.js +0 -186
  220. package/dist/services/wire.js.map +0 -1
@@ -0,0 +1,37 @@
1
+ /** Values supported by the portable SQLite drivers. */
2
+ export type SqliteValue = null | number | bigint | string | Uint8Array;
3
+ /**
4
+ * Asynchronous SQL operations shared by a database and its transaction handles.
5
+ *
6
+ * `exec` runs SQL text without bindings and may contain several statements. `run`, `get`, and `all`
7
+ * execute one statement with positional bindings. Adapters may cache prepared statements by SQL text,
8
+ * so callers pass values as bindings instead of interpolating them.
9
+ */
10
+ export interface SqliteExecutor {
11
+ exec(sql: string): Promise<void>;
12
+ run(sql: string, ...params: SqliteValue[]): Promise<void>;
13
+ get<T extends object>(sql: string, ...params: SqliteValue[]): Promise<T | undefined>;
14
+ all<T extends object>(sql: string, ...params: SqliteValue[]): Promise<T[]>;
15
+ }
16
+ /**
17
+ * Minimal portable SQLite database facade.
18
+ *
19
+ * All operations are asynchronous so adapters may execute outside the caller's runtime.
20
+ *
21
+ * `transaction` passes the callback a transaction handle. All work in the transaction
22
+ * must use that handle; the handle is invalid after the callback settles. Adapters must
23
+ * queue unrelated operations and other transactions until the transaction finishes. The
24
+ * returned promise settles after commit or rollback. Calling the database itself (including
25
+ * `transaction` or `close`) from inside a callback therefore waits for that transaction and
26
+ * never settles.
27
+ *
28
+ * When the callback rejects, the adapter must roll the transaction back before rejecting
29
+ * with that same error. If rollback fails, it must reject with a different error (for
30
+ * example an `AggregateError`) so callers cannot mistake the callback error for a
31
+ * guaranteed rollback.
32
+ */
33
+ export interface SqliteDatabase extends SqliteExecutor {
34
+ transaction<T>(callback: (transaction: SqliteExecutor) => Promise<T>): Promise<T>;
35
+ close(): Promise<void>;
36
+ }
37
+ //# sourceMappingURL=database.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"database.d.ts","sourceRoot":"","sources":["../../src/sqlite/database.ts"],"names":[],"mappings":"AAAA,uDAAuD;AACvD,MAAM,MAAM,WAAW,GAAG,IAAI,GAAG,MAAM,GAAG,MAAM,GAAG,MAAM,GAAG,UAAU,CAAC;AAEvE;;;;;;GAMG;AACH,MAAM,WAAW,cAAc;IAC9B,IAAI,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACjC,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,MAAM,EAAE,WAAW,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAC1D,GAAG,CAAC,CAAC,SAAS,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,MAAM,EAAE,WAAW,EAAE,GAAG,OAAO,CAAC,CAAC,GAAG,SAAS,CAAC,CAAC;IACrF,GAAG,CAAC,CAAC,SAAS,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,MAAM,EAAE,WAAW,EAAE,GAAG,OAAO,CAAC,CAAC,EAAE,CAAC,CAAC;CAC3E;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,WAAW,cAAe,SAAQ,cAAc;IACrD,WAAW,CAAC,CAAC,EAAE,QAAQ,EAAE,CAAC,WAAW,EAAE,cAAc,KAAK,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;IAClF,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CACvB"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=database.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"database.js","sourceRoot":"","sources":["../../src/sqlite/database.ts"],"names":[],"mappings":"","sourcesContent":["/** Values supported by the portable SQLite drivers. */\nexport type SqliteValue = null | number | bigint | string | Uint8Array;\n\n/**\n * Asynchronous SQL operations shared by a database and its transaction handles.\n *\n * `exec` runs SQL text without bindings and may contain several statements. `run`, `get`, and `all`\n * execute one statement with positional bindings. Adapters may cache prepared statements by SQL text,\n * so callers pass values as bindings instead of interpolating them.\n */\nexport interface SqliteExecutor {\n\texec(sql: string): Promise<void>;\n\trun(sql: string, ...params: SqliteValue[]): Promise<void>;\n\tget<T extends object>(sql: string, ...params: SqliteValue[]): Promise<T | undefined>;\n\tall<T extends object>(sql: string, ...params: SqliteValue[]): Promise<T[]>;\n}\n\n/**\n * Minimal portable SQLite database facade.\n *\n * All operations are asynchronous so adapters may execute outside the caller's runtime.\n *\n * `transaction` passes the callback a transaction handle. All work in the transaction\n * must use that handle; the handle is invalid after the callback settles. Adapters must\n * queue unrelated operations and other transactions until the transaction finishes. The\n * returned promise settles after commit or rollback. Calling the database itself (including\n * `transaction` or `close`) from inside a callback therefore waits for that transaction and\n * never settles.\n *\n * When the callback rejects, the adapter must roll the transaction back before rejecting\n * with that same error. If rollback fails, it must reject with a different error (for\n * example an `AggregateError`) so callers cannot mistake the callback error for a\n * guaranteed rollback.\n */\nexport interface SqliteDatabase extends SqliteExecutor {\n\ttransaction<T>(callback: (transaction: SqliteExecutor) => Promise<T>): Promise<T>;\n\tclose(): Promise<void>;\n}\n"]}
@@ -0,0 +1,4 @@
1
+ export type { SqliteDatabase, SqliteExecutor, SqliteValue } from "./database.ts";
2
+ export { applySqliteMigrations, type SqliteMigration } from "./migrations.ts";
3
+ export { validateSqliteSchemaPrefix } from "./schema.ts";
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/sqlite/index.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,cAAc,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AACjF,OAAO,EAAE,qBAAqB,EAAE,KAAK,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAC9E,OAAO,EAAE,0BAA0B,EAAE,MAAM,aAAa,CAAC"}
@@ -0,0 +1,3 @@
1
+ export { applySqliteMigrations } from "./migrations.js";
2
+ export { validateSqliteSchemaPrefix } from "./schema.js";
3
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/sqlite/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,qBAAqB,EAAwB,MAAM,iBAAiB,CAAC;AAC9E,OAAO,EAAE,0BAA0B,EAAE,MAAM,aAAa,CAAC","sourcesContent":["export type { SqliteDatabase, SqliteExecutor, SqliteValue } from \"./database.ts\";\nexport { applySqliteMigrations, type SqliteMigration } from \"./migrations.ts\";\nexport { validateSqliteSchemaPrefix } from \"./schema.ts\";\n"]}
@@ -0,0 +1,10 @@
1
+ import type { SqliteDatabase } from "./database.ts";
2
+ export type SqliteMigration = {
3
+ readonly version: number;
4
+ readonly statements: readonly string[];
5
+ };
6
+ /** Apply all pending migrations atomically, tracking their version in the named metadata table. */
7
+ export declare function applySqliteMigrations(database: SqliteDatabase, migrations: readonly SqliteMigration[], options: {
8
+ readonly table: string;
9
+ }): Promise<void>;
10
+ //# sourceMappingURL=migrations.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"migrations.d.ts","sourceRoot":"","sources":["../../src/sqlite/migrations.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAGpD,MAAM,MAAM,eAAe,GAAG;IAC7B,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,UAAU,EAAE,SAAS,MAAM,EAAE,CAAC;CACvC,CAAC;AAIF,mGAAmG;AACnG,wBAAsB,qBAAqB,CAC1C,QAAQ,EAAE,cAAc,EACxB,UAAU,EAAE,SAAS,eAAe,EAAE,EACtC,OAAO,EAAE;IAAE,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAA;CAAE,GACjC,OAAO,CAAC,IAAI,CAAC,CA2Bf"}
@@ -0,0 +1,33 @@
1
+ import { validateSqliteSchemaPrefix } from "./schema.js";
2
+ /** Apply all pending migrations atomically, tracking their version in the named metadata table. */
3
+ export async function applySqliteMigrations(database, migrations, options) {
4
+ const { table } = options;
5
+ validateSqliteSchemaPrefix(table);
6
+ for (let index = 0; index < migrations.length; index++) {
7
+ if (migrations[index]?.version !== index + 1) {
8
+ throw new Error("SQLite migrations must have contiguous versions starting at 1");
9
+ }
10
+ }
11
+ await database.transaction(async (transaction) => {
12
+ await transaction.exec(`CREATE TABLE IF NOT EXISTS ${table} (
13
+ singleton INTEGER PRIMARY KEY CHECK (singleton = 1),
14
+ version INTEGER NOT NULL CHECK (version >= 0)
15
+ ) STRICT`);
16
+ await transaction.run(`INSERT OR IGNORE INTO ${table} (singleton, version) VALUES (1, 0)`);
17
+ const row = await transaction.get(`SELECT version FROM ${table} WHERE singleton = 1`);
18
+ if (row === undefined)
19
+ throw new Error("SQLite schema metadata is missing");
20
+ const currentVersion = migrations.at(-1)?.version ?? 0;
21
+ if (row.version > currentVersion) {
22
+ throw new Error(`SQLite schema version ${row.version} is newer than supported version ${currentVersion}`);
23
+ }
24
+ for (const migration of migrations) {
25
+ if (migration.version <= row.version)
26
+ continue;
27
+ for (const statement of migration.statements)
28
+ await transaction.exec(statement);
29
+ await transaction.run(`UPDATE ${table} SET version = ? WHERE singleton = 1`, migration.version);
30
+ }
31
+ });
32
+ }
33
+ //# sourceMappingURL=migrations.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"migrations.js","sourceRoot":"","sources":["../../src/sqlite/migrations.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,0BAA0B,EAAE,MAAM,aAAa,CAAC;AASzD,mGAAmG;AACnG,MAAM,CAAC,KAAK,UAAU,qBAAqB,CAC1C,QAAwB,EACxB,UAAsC,EACtC,OAAmC;IAEnC,MAAM,EAAE,KAAK,EAAE,GAAG,OAAO,CAAC;IAC1B,0BAA0B,CAAC,KAAK,CAAC,CAAC;IAClC,KAAK,IAAI,KAAK,GAAG,CAAC,EAAE,KAAK,GAAG,UAAU,CAAC,MAAM,EAAE,KAAK,EAAE,EAAE,CAAC;QACxD,IAAI,UAAU,CAAC,KAAK,CAAC,EAAE,OAAO,KAAK,KAAK,GAAG,CAAC,EAAE,CAAC;YAC9C,MAAM,IAAI,KAAK,CAAC,+DAA+D,CAAC,CAAC;QAClF,CAAC;IACF,CAAC;IAED,MAAM,QAAQ,CAAC,WAAW,CAAC,KAAK,EAAE,WAAW,EAAE,EAAE;QAChD,MAAM,WAAW,CAAC,IAAI,CAAC,8BAA8B,KAAK;;;WAGjD,CAAC,CAAC;QACX,MAAM,WAAW,CAAC,GAAG,CAAC,yBAAyB,KAAK,qCAAqC,CAAC,CAAC;QAC3F,MAAM,GAAG,GAAG,MAAM,WAAW,CAAC,GAAG,CAAY,uBAAuB,KAAK,sBAAsB,CAAC,CAAC;QACjG,IAAI,GAAG,KAAK,SAAS;YAAE,MAAM,IAAI,KAAK,CAAC,mCAAmC,CAAC,CAAC;QAC5E,MAAM,cAAc,GAAG,UAAU,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE,OAAO,IAAI,CAAC,CAAC;QACvD,IAAI,GAAG,CAAC,OAAO,GAAG,cAAc,EAAE,CAAC;YAClC,MAAM,IAAI,KAAK,CAAC,yBAAyB,GAAG,CAAC,OAAO,oCAAoC,cAAc,EAAE,CAAC,CAAC;QAC3G,CAAC;QACD,KAAK,MAAM,SAAS,IAAI,UAAU,EAAE,CAAC;YACpC,IAAI,SAAS,CAAC,OAAO,IAAI,GAAG,CAAC,OAAO;gBAAE,SAAS;YAC/C,KAAK,MAAM,SAAS,IAAI,SAAS,CAAC,UAAU;gBAAE,MAAM,WAAW,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;YAChF,MAAM,WAAW,CAAC,GAAG,CAAC,UAAU,KAAK,sCAAsC,EAAE,SAAS,CAAC,OAAO,CAAC,CAAC;QACjG,CAAC;IACF,CAAC,CAAC,CAAC;AACJ,CAAC","sourcesContent":["import type { SqliteDatabase } from \"./database.ts\";\nimport { validateSqliteSchemaPrefix } from \"./schema.ts\";\n\nexport type SqliteMigration = {\n\treadonly version: number;\n\treadonly statements: readonly string[];\n};\n\ntype SchemaRow = { readonly version: number };\n\n/** Apply all pending migrations atomically, tracking their version in the named metadata table. */\nexport async function applySqliteMigrations(\n\tdatabase: SqliteDatabase,\n\tmigrations: readonly SqliteMigration[],\n\toptions: { readonly table: string },\n): Promise<void> {\n\tconst { table } = options;\n\tvalidateSqliteSchemaPrefix(table);\n\tfor (let index = 0; index < migrations.length; index++) {\n\t\tif (migrations[index]?.version !== index + 1) {\n\t\t\tthrow new Error(\"SQLite migrations must have contiguous versions starting at 1\");\n\t\t}\n\t}\n\n\tawait database.transaction(async (transaction) => {\n\t\tawait transaction.exec(`CREATE TABLE IF NOT EXISTS ${table} (\n\t\t\tsingleton INTEGER PRIMARY KEY CHECK (singleton = 1),\n\t\t\tversion INTEGER NOT NULL CHECK (version >= 0)\n\t\t) STRICT`);\n\t\tawait transaction.run(`INSERT OR IGNORE INTO ${table} (singleton, version) VALUES (1, 0)`);\n\t\tconst row = await transaction.get<SchemaRow>(`SELECT version FROM ${table} WHERE singleton = 1`);\n\t\tif (row === undefined) throw new Error(\"SQLite schema metadata is missing\");\n\t\tconst currentVersion = migrations.at(-1)?.version ?? 0;\n\t\tif (row.version > currentVersion) {\n\t\t\tthrow new Error(`SQLite schema version ${row.version} is newer than supported version ${currentVersion}`);\n\t\t}\n\t\tfor (const migration of migrations) {\n\t\t\tif (migration.version <= row.version) continue;\n\t\t\tfor (const statement of migration.statements) await transaction.exec(statement);\n\t\t\tawait transaction.run(`UPDATE ${table} SET version = ? WHERE singleton = 1`, migration.version);\n\t\t}\n\t});\n}\n"]}
@@ -0,0 +1,38 @@
1
+ import type { StatementSync } from "node:sqlite";
2
+ import { DatabaseSync } from "node:sqlite";
3
+ import type { SqliteDatabase, SqliteExecutor, SqliteValue } from "./database.ts";
4
+ /** Node SQLite connection settings for a database file. */
5
+ export type NodeSqliteDatabaseOptions = {
6
+ /** SQLite WAL auto-checkpoint threshold. SQLite and this adapter default to 1,000 pages; 0 disables it. */
7
+ readonly walAutoCheckpointPages?: number;
8
+ /** Time SQLite waits for a competing file lock. SQLite defaults to 0; this adapter defaults to 5,000 ms. */
9
+ readonly busyTimeoutMs?: number;
10
+ };
11
+ /**
12
+ * Executes SQL on one connection. Prepared statements are cached per connection by SQL text, so the
13
+ * database and its transaction handles share them across transactions.
14
+ */
15
+ declare abstract class NodeSqliteExecutor implements SqliteExecutor {
16
+ protected readonly database: DatabaseSync;
17
+ protected readonly statements: Map<string, StatementSync>;
18
+ constructor(database: DatabaseSync, statements: Map<string, StatementSync>);
19
+ exec(sql: string): Promise<void>;
20
+ run(sql: string, ...params: SqliteValue[]): Promise<void>;
21
+ get<T extends object>(sql: string, ...params: SqliteValue[]): Promise<T | undefined>;
22
+ all<T extends object>(sql: string, ...params: SqliteValue[]): Promise<T[]>;
23
+ protected abstract runOperation<T>(operation: () => T): Promise<T>;
24
+ private statement;
25
+ }
26
+ /** `SqliteDatabase` adapter backed by Node's built-in `node:sqlite`. */
27
+ export declare class NodeSqliteDatabase extends NodeSqliteExecutor implements SqliteDatabase {
28
+ private readonly access;
29
+ private closed;
30
+ constructor(database: DatabaseSync);
31
+ transaction<T>(callback: (transaction: SqliteExecutor) => Promise<T>): Promise<T>;
32
+ close(): Promise<void>;
33
+ protected runOperation<T>(operation: () => T): Promise<T>;
34
+ }
35
+ /** Open and configure a Node-backed SQLite database facade. */
36
+ export declare function openNodeSqliteDatabase(path: string, options?: NodeSqliteDatabaseOptions): Promise<NodeSqliteDatabase>;
37
+ export {};
38
+ //# sourceMappingURL=node.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"node.d.ts","sourceRoot":"","sources":["../../src/sqlite/node.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AACjD,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC3C,OAAO,KAAK,EAAE,cAAc,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAEjF,2DAA2D;AAC3D,MAAM,MAAM,yBAAyB,GAAG;IACvC,2GAA2G;IAC3G,QAAQ,CAAC,sBAAsB,CAAC,EAAE,MAAM,CAAC;IACzC,4GAA4G;IAC5G,QAAQ,CAAC,aAAa,CAAC,EAAE,MAAM,CAAC;CAChC,CAAC;AA0DF;;;GAGG;AACH,uBAAe,kBAAmB,YAAW,c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YAAY,CAAC,CAAC,EAAE,SAAS,EAAE,MAAM,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAExD;CACD;AAED,+DAA+D;AAC/D,wBAAsB,sBAAsB,CAC3C,IAAI,EAAE,MAAM,EACZ,OAAO,GAAE,yBAA8B,GACrC,OAAO,CAAC,kBAAkB,CAAC,CAmB7B"}
@@ -0,0 +1,174 @@
1
+ import { mkdir } from "node:fs/promises";
2
+ import { dirname } from "node:path";
3
+ import { DatabaseSync } from "node:sqlite";
4
+ const DEFAULT_WAL_AUTO_CHECKPOINT_PAGES = 1_000;
5
+ const DEFAULT_BUSY_TIMEOUT_MS = 5_000;
6
+ const ignore = () => { };
7
+ /**
8
+ * Runs operations in call order. An operation starts immediately when nothing is running or waiting;
9
+ * otherwise it waits for everything before it. An asynchronous operation holds the queue until it settles.
10
+ */
11
+ class SerialOperationQueue {
12
+ tail = Promise.resolve();
13
+ pending = 0;
14
+ run(operation) {
15
+ if (this.pending > 0)
16
+ return this.enqueue(operation);
17
+ try {
18
+ return Promise.resolve(operation());
19
+ }
20
+ catch (error) {
21
+ return Promise.reject(error);
22
+ }
23
+ }
24
+ runAsync(operation) {
25
+ if (this.pending > 0)
26
+ return this.enqueue(operation);
27
+ this.pending++;
28
+ // Publish the barrier before the operation starts, so calls it makes synchronously wait behind it.
29
+ const { promise: barrier, resolve: releaseBarrier } = Promise.withResolvers();
30
+ this.tail = barrier;
31
+ let started;
32
+ try {
33
+ started = operation();
34
+ }
35
+ catch (error) {
36
+ started = Promise.reject(error);
37
+ }
38
+ return started.finally(() => {
39
+ this.pending--;
40
+ releaseBarrier();
41
+ });
42
+ }
43
+ enqueue(operation) {
44
+ this.pending++;
45
+ return this.release(this.tail.then(operation));
46
+ }
47
+ release(operation) {
48
+ const settled = operation.finally(() => {
49
+ this.pending--;
50
+ });
51
+ this.tail = settled.then(ignore, ignore);
52
+ return settled;
53
+ }
54
+ }
55
+ /**
56
+ * Executes SQL on one connection. Prepared statements are cached per connection by SQL text, so the
57
+ * database and its transaction handles share them across transactions.
58
+ */
59
+ class NodeSqliteExecutor {
60
+ database;
61
+ statements;
62
+ constructor(database, statements) {
63
+ this.database = database;
64
+ this.statements = statements;
65
+ }
66
+ exec(sql) {
67
+ return this.runOperation(() => {
68
+ this.database.exec(sql);
69
+ });
70
+ }
71
+ run(sql, ...params) {
72
+ return this.runOperation(() => {
73
+ this.statement(sql).run(...params);
74
+ });
75
+ }
76
+ get(sql, ...params) {
77
+ return this.runOperation(() => this.statement(sql).get(...params));
78
+ }
79
+ all(sql, ...params) {
80
+ return this.runOperation(() => this.statement(sql).all(...params));
81
+ }
82
+ statement(sql) {
83
+ let statement = this.statements.get(sql);
84
+ if (statement === undefined) {
85
+ statement = this.database.prepare(sql);
86
+ this.statements.set(sql, statement);
87
+ }
88
+ return statement;
89
+ }
90
+ }
91
+ class NodeSqliteTransaction extends NodeSqliteExecutor {
92
+ scope;
93
+ constructor(database, statements, scope) {
94
+ super(database, statements);
95
+ this.scope = scope;
96
+ }
97
+ async runOperation(operation) {
98
+ if (!this.scope.active)
99
+ throw new Error("SQLite transaction handle is no longer active");
100
+ return operation();
101
+ }
102
+ }
103
+ /** `SqliteDatabase` adapter backed by Node's built-in `node:sqlite`. */
104
+ export class NodeSqliteDatabase extends NodeSqliteExecutor {
105
+ access = new SerialOperationQueue();
106
+ closed = false;
107
+ constructor(database) {
108
+ super(database, new Map());
109
+ }
110
+ transaction(callback) {
111
+ return this.access.runAsync(async () => {
112
+ this.database.exec("BEGIN IMMEDIATE");
113
+ const scope = { active: true };
114
+ try {
115
+ const result = await callback(new NodeSqliteTransaction(this.database, this.statements, scope));
116
+ scope.active = false;
117
+ this.database.exec("COMMIT");
118
+ return result;
119
+ }
120
+ catch (error) {
121
+ scope.active = false;
122
+ try {
123
+ this.database.exec("ROLLBACK");
124
+ }
125
+ catch (rollbackError) {
126
+ throw new AggregateError([error, rollbackError], "SQLite transaction failed and rollback failed");
127
+ }
128
+ throw error;
129
+ }
130
+ });
131
+ }
132
+ close() {
133
+ return this.access.run(() => {
134
+ if (this.closed)
135
+ return;
136
+ this.closed = true;
137
+ this.statements.clear();
138
+ try {
139
+ this.database.exec("PRAGMA wal_checkpoint(TRUNCATE)");
140
+ }
141
+ finally {
142
+ this.database.close();
143
+ }
144
+ });
145
+ }
146
+ runOperation(operation) {
147
+ return this.access.run(operation);
148
+ }
149
+ }
150
+ /** Open and configure a Node-backed SQLite database facade. */
151
+ export async function openNodeSqliteDatabase(path, options = {}) {
152
+ const checkpointPages = options.walAutoCheckpointPages ?? DEFAULT_WAL_AUTO_CHECKPOINT_PAGES;
153
+ const timeout = options.busyTimeoutMs ?? DEFAULT_BUSY_TIMEOUT_MS;
154
+ if (path !== ":memory:")
155
+ await mkdir(dirname(path), { recursive: true });
156
+ const database = new DatabaseSync(path, { timeout });
157
+ const adapter = new NodeSqliteDatabase(database);
158
+ try {
159
+ await adapter.exec("PRAGMA journal_mode = WAL");
160
+ await adapter.exec("PRAGMA synchronous = NORMAL");
161
+ await adapter.exec(`PRAGMA wal_autocheckpoint = ${checkpointPages}`);
162
+ return adapter;
163
+ }
164
+ catch (error) {
165
+ try {
166
+ await adapter.close();
167
+ }
168
+ catch {
169
+ // Preserve the configuration failure.
170
+ }
171
+ throw error;
172
+ }
173
+ }
174
+ //# sourceMappingURL=node.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"node.js","sourceRoot":"","sources":["../../src/sqlite/node.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AACzC,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAEpC,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAW3C,MAAM,iCAAiC,GAAG,KAAK,CAAC;AAChD,MAAM,uBAAuB,GAAG,KAAK,CAAC;AAItC,MAAM,MAAM,GAAG,GAAS,EAAE,GAAE,CAAC,CAAC;AAE9B;;;GAGG;AACH,MAAM,oBAAoB;IACj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MAAM,eAAe,GAAG,OAAO,CAAC,sBAAsB,IAAI,iCAAiC,CAAC;IAC5F,MAAM,OAAO,GAAG,OAAO,CAAC,aAAa,IAAI,uBAAuB,CAAC;IACjE,IAAI,IAAI,KAAK,UAAU;QAAE,MAAM,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;IACzE,MAAM,QAAQ,GAAG,IAAI,YAAY,CAAC,IAAI,EAAE,EAAE,OAAO,EAAE,CAAC,CAAC;IACrD,MAAM,OAAO,GAAG,IAAI,kBAAkB,CAAC,QAAQ,CAAC,CAAC;IACjD,IAAI,CAAC;QACJ,MAAM,OAAO,CAAC,IAAI,CAAC,2BAA2B,CAAC,CAAC;QAChD,MAAM,OAAO,CAAC,IAAI,CAAC,6BAA6B,CAAC,CAAC;QAClD,MAAM,OAAO,CAAC,IAAI,CAAC,+BAA+B,eAAe,EAAE,CAAC,CAAC;QACrE,OAAO,OAAO,CAAC;IAChB,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QAChB,IAAI,CAAC;YACJ,MAAM,OAAO,CAAC,KAAK,EAAE,CAAC;QACvB,CAAC;QAAC,MAAM,CAAC;YACR,sCAAsC;QACvC,CAAC;QACD,MAAM,KAAK,CAAC;IACb,CAAC;AACF,CAAC","sourcesContent":["import { mkdir } from \"node:fs/promises\";\nimport { dirname } from \"node:path\";\nimport type { StatementSync } from \"node:sqlite\";\nimport { DatabaseSync } from \"node:sqlite\";\nimport type { SqliteDatabase, SqliteExecutor, SqliteValue } from \"./database.ts\";\n\n/** Node SQLite connection settings for a database file. */\nexport type NodeSqliteDatabaseOptions = {\n\t/** SQLite WAL auto-checkpoint threshold. SQLite and this adapter default to 1,000 pages; 0 disables it. */\n\treadonly walAutoCheckpointPages?: number;\n\t/** Time SQLite waits for a competing file lock. SQLite defaults to 0; this adapter defaults to 5,000 ms. */\n\treadonly busyTimeoutMs?: number;\n};\n\nconst DEFAULT_WAL_AUTO_CHECKPOINT_PAGES = 1_000;\nconst DEFAULT_BUSY_TIMEOUT_MS = 5_000;\n\ntype TransactionScope = { active: boolean };\n\nconst ignore = (): void => {};\n\n/**\n * Runs operations in call order. An operation starts immediately when nothing is running or waiting;\n * otherwise it waits for everything before it. An asynchronous operation holds the queue until it settles.\n */\nclass SerialOperationQueue {\n\tprivate tail: Promise<void> = Promise.resolve();\n\tprivate pending = 0;\n\n\trun<T>(operation: () => T): Promise<T> {\n\t\tif (this.pending > 0) return this.enqueue(operation);\n\t\ttry {\n\t\t\treturn Promise.resolve(operation());\n\t\t} catch (error) {\n\t\t\treturn Promise.reject(error);\n\t\t}\n\t}\n\n\trunAsync<T>(operation: () => Promise<T>): Promise<T> {\n\t\tif (this.pending > 0) return this.enqueue(operation);\n\t\tthis.pending++;\n\t\t// Publish the barrier before the operation starts, so calls it makes synchronously wait behind it.\n\t\tconst { promise: barrier, resolve: releaseBarrier } = Promise.withResolvers<void>();\n\t\tthis.tail = barrier;\n\t\tlet started: Promise<T>;\n\t\ttry {\n\t\t\tstarted = operation();\n\t\t} catch (error) {\n\t\t\tstarted = Promise.reject(error);\n\t\t}\n\t\treturn started.finally(() => {\n\t\t\tthis.pending--;\n\t\t\treleaseBarrier();\n\t\t});\n\t}\n\n\tprivate enqueue<T>(operation: () => T | Promise<T>): Promise<T> {\n\t\tthis.pending++;\n\t\treturn this.release(this.tail.then(operation));\n\t}\n\n\tprivate release<T>(operation: Promise<T>): Promise<T> {\n\t\tconst settled = operation.finally(() => {\n\t\t\tthis.pending--;\n\t\t});\n\t\tthis.tail = settled.then(ignore, ignore);\n\t\treturn settled;\n\t}\n}\n\n/**\n * Executes SQL on one connection. Prepared statements are cached per connection by SQL text, so the\n * database and its transaction handles share them across transactions.\n */\nabstract class NodeSqliteExecutor implements SqliteExecutor {\n\tprotected readonly database: DatabaseSync;\n\tprotected readonly statements: Map<string, StatementSync>;\n\n\tconstructor(database: DatabaseSync, statements: Map<string, StatementSync>) {\n\t\tthis.database = database;\n\t\tthis.statements = statements;\n\t}\n\n\texec(sql: string): Promise<void> {\n\t\treturn this.runOperation(() => {\n\t\t\tthis.database.exec(sql);\n\t\t});\n\t}\n\n\trun(sql: string, ...params: SqliteValue[]): Promise<void> {\n\t\treturn this.runOperation(() => {\n\t\t\tthis.statement(sql).run(...params);\n\t\t});\n\t}\n\n\tget<T extends object>(sql: string, ...params: SqliteValue[]): Promise<T | undefined> {\n\t\treturn this.runOperation(() => this.statement(sql).get(...params) as T | undefined);\n\t}\n\n\tall<T extends object>(sql: string, ...params: SqliteValue[]): Promise<T[]> {\n\t\treturn this.runOperation(() => this.statement(sql).all(...params) as T[]);\n\t}\n\n\tprotected abstract runOperation<T>(operation: () => T): Promise<T>;\n\n\tprivate statement(sql: string): StatementSync {\n\t\tlet statement = this.statements.get(sql);\n\t\tif (statement === undefined) {\n\t\t\tstatement = this.database.prepare(sql);\n\t\t\tthis.statements.set(sql, statement);\n\t\t}\n\t\treturn statement;\n\t}\n}\n\nclass NodeSqliteTransaction extends NodeSqliteExecutor {\n\tprivate readonly scope: TransactionScope;\n\n\tconstructor(database: DatabaseSync, statements: Map<string, StatementSync>, scope: TransactionScope) {\n\t\tsuper(database, statements);\n\t\tthis.scope = scope;\n\t}\n\n\tprotected async runOperation<T>(operation: () => T): Promise<T> {\n\t\tif (!this.scope.active) throw new Error(\"SQLite transaction handle is no longer active\");\n\t\treturn operation();\n\t}\n}\n\n/** `SqliteDatabase` adapter backed by Node's built-in `node:sqlite`. */\nexport class NodeSqliteDatabase extends NodeSqliteExecutor implements SqliteDatabase {\n\tprivate readonly access = new SerialOperationQueue();\n\tprivate closed = false;\n\n\tconstructor(database: DatabaseSync) {\n\t\tsuper(database, new Map());\n\t}\n\n\ttransaction<T>(callback: (transaction: SqliteExecutor) => Promise<T>): Promise<T> {\n\t\treturn this.access.runAsync(async () => {\n\t\t\tthis.database.exec(\"BEGIN IMMEDIATE\");\n\t\t\tconst scope = { active: true };\n\t\t\ttry {\n\t\t\t\tconst result = await callback(new NodeSqliteTransaction(this.database, this.statements, scope));\n\t\t\t\tscope.active = false;\n\t\t\t\tthis.database.exec(\"COMMIT\");\n\t\t\t\treturn result;\n\t\t\t} catch (error) {\n\t\t\t\tscope.active = false;\n\t\t\t\ttry {\n\t\t\t\t\tthis.database.exec(\"ROLLBACK\");\n\t\t\t\t} catch (rollbackError) {\n\t\t\t\t\tthrow new AggregateError([error, rollbackError], \"SQLite transaction failed and rollback failed\");\n\t\t\t\t}\n\t\t\t\tthrow error;\n\t\t\t}\n\t\t});\n\t}\n\n\tclose(): Promise<void> {\n\t\treturn this.access.run(() => {\n\t\t\tif (this.closed) return;\n\t\t\tthis.closed = true;\n\t\t\tthis.statements.clear();\n\t\t\ttry {\n\t\t\t\tthis.database.exec(\"PRAGMA wal_checkpoint(TRUNCATE)\");\n\t\t\t} finally {\n\t\t\t\tthis.database.close();\n\t\t\t}\n\t\t});\n\t}\n\n\tprotected runOperation<T>(operation: () => T): Promise<T> {\n\t\treturn this.access.run(operation);\n\t}\n}\n\n/** Open and configure a Node-backed SQLite database facade. */\nexport async function openNodeSqliteDatabase(\n\tpath: string,\n\toptions: NodeSqliteDatabaseOptions = {},\n): Promise<NodeSqliteDatabase> {\n\tconst checkpointPages = options.walAutoCheckpointPages ?? DEFAULT_WAL_AUTO_CHECKPOINT_PAGES;\n\tconst timeout = options.busyTimeoutMs ?? DEFAULT_BUSY_TIMEOUT_MS;\n\tif (path !== \":memory:\") await mkdir(dirname(path), { recursive: true });\n\tconst database = new DatabaseSync(path, { timeout });\n\tconst adapter = new NodeSqliteDatabase(database);\n\ttry {\n\t\tawait adapter.exec(\"PRAGMA journal_mode = WAL\");\n\t\tawait adapter.exec(\"PRAGMA synchronous = NORMAL\");\n\t\tawait adapter.exec(`PRAGMA wal_autocheckpoint = ${checkpointPages}`);\n\t\treturn adapter;\n\t} catch (error) {\n\t\ttry {\n\t\t\tawait adapter.close();\n\t\t} catch {\n\t\t\t// Preserve the configuration failure.\n\t\t}\n\t\tthrow error;\n\t}\n}\n"]}
@@ -0,0 +1,3 @@
1
+ /** Validate a prefix before using it as part of a SQLite identifier. */
2
+ export declare function validateSqliteSchemaPrefix(prefix: string): void;
3
+ //# sourceMappingURL=schema.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../../src/sqlite/schema.ts"],"names":[],"mappings":"AAAA,wEAAwE;AACxE,wBAAgB,0BAA0B,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAO/D"}
@@ -0,0 +1,10 @@
1
+ /** Validate a prefix before using it as part of a SQLite identifier. */
2
+ export function validateSqliteSchemaPrefix(prefix) {
3
+ if (!/^[A-Za-z_][A-Za-z0-9_]*$/.test(prefix)) {
4
+ throw new Error(`Invalid SQLite schema prefix ${JSON.stringify(prefix)}`);
5
+ }
6
+ if (prefix.toLowerCase().startsWith("sqlite_")) {
7
+ throw new Error(`SQLite schema prefix ${JSON.stringify(prefix)} is reserved`);
8
+ }
9
+ }
10
+ //# sourceMappingURL=schema.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"schema.js","sourceRoot":"","sources":["../../src/sqlite/schema.ts"],"names":[],"mappings":"AAAA,wEAAwE;AACxE,MAAM,UAAU,0BAA0B,CAAC,MAAc;IACxD,IAAI,CAAC,0BAA0B,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC;QAC9C,MAAM,IAAI,KAAK,CAAC,gCAAgC,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;IAC3E,CAAC;IACD,IAAI,MAAM,CAAC,WAAW,EAAE,CAAC,UAAU,CAAC,SAAS,CAAC,EAAE,CAAC;QAChD,MAAM,IAAI,KAAK,CAAC,wBAAwB,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,cAAc,CAAC,CAAC;IAC/E,CAAC;AACF,CAAC","sourcesContent":["/** Validate a prefix before using it as part of a SQLite identifier. */\nexport function validateSqliteSchemaPrefix(prefix: string): void {\n\tif (!/^[A-Za-z_][A-Za-z0-9_]*$/.test(prefix)) {\n\t\tthrow new Error(`Invalid SQLite schema prefix ${JSON.stringify(prefix)}`);\n\t}\n\tif (prefix.toLowerCase().startsWith(\"sqlite_\")) {\n\t\tthrow new Error(`SQLite schema prefix ${JSON.stringify(prefix)} is reserved`);\n\t}\n}\n"]}
@@ -0,0 +1,92 @@
1
+ /**
2
+ * Replicated state: an immutable JSON value with ordered, serialized change notifications. Either authoritative and
3
+ * mutable (`replicatedState(initial)`) or a publication-only view of an external revision source
4
+ * (`replicatedState(source)`).
5
+ */
6
+ import { type Context } from "./context/index.ts";
7
+ import { type Draft, type Op } from "./delta/index.ts";
8
+ export interface ReplicatedStateDelivery {
9
+ readonly kind: "hydrate" | "update";
10
+ readonly sequence: number;
11
+ }
12
+ export interface ReplicatedState<T> {
13
+ /**
14
+ * Contract-immutable value, or undefined until hydration. It is not frozen and may share containers with an
15
+ * in-process provider; consumers must not mutate it. Later updates do not mutate previously returned values.
16
+ */
17
+ readonly value: T | undefined;
18
+ /**
19
+ * Each subscription serializes callbacks, awaiting hydration before updates. Values are immutable and may
20
+ * share unchanged revision data. At most 100 deliveries wait behind the running callback; overflow keeps
21
+ * only the newest pending value/context/delivery, so update sequences may skip. Failures are reported in
22
+ * isolation and delivery continues. Unsubscribe discards pending work without aborting or joining a callback.
23
+ */
24
+ subscribe(listener: (value: T, context: Context, delivery: ReplicatedStateDelivery) => Promise<void>): () => void;
25
+ subscribe(listener: (value: T, context: Context, delivery: ReplicatedStateDelivery) => void): () => void;
26
+ }
27
+ export interface MutableReplicatedState<T extends object> extends ReplicatedState<T> {
28
+ readonly value: T;
29
+ /**
30
+ * Atomically publish one synchronous overlay mutation. Draft handles are unusable after the callback returns.
31
+ * Values placed through the draft are cloned by value; assigning `undefined` to an object property deletes it.
32
+ */
33
+ change(context: Context, mutate: (draft: Draft<T>) => void): void;
34
+ /**
35
+ * Atomically take immutable ownership of an alias-free strict-JSON replacement.
36
+ * The caller must not mutate the transferred root after this call.
37
+ */
38
+ replace(context: Context, value: T): void;
39
+ }
40
+ /** One immutable authoritative revision committed after an attachment snapshot. */
41
+ export interface ReplicatedStateSourceFrame<T> {
42
+ /** Monotonic source cursor. The first frame after a snapshot must be `snapshot.cursor + 1`. */
43
+ readonly cursor: number;
44
+ /** The exact immutable value produced by this commit. */
45
+ readonly value: T;
46
+ /** The exact immutable operation batch that produced `value` from the preceding source revision. */
47
+ readonly ops: readonly Op[];
48
+ readonly context: Context;
49
+ }
50
+ export interface ReplicatedStateSourceAttachment<T> {
51
+ /** Fixed immutable snapshot captured at the atomic attachment boundary. */
52
+ readonly snapshot: {
53
+ readonly value: T;
54
+ readonly cursor: number;
55
+ };
56
+ /**
57
+ * Install the sole listener and synchronously drain every buffered frame in source commit order.
58
+ * This method is single-use. After it begins, every new committed frame must also be delivered in order
59
+ * until disposal, including commits made reentrantly while a prior frame is being delivered.
60
+ */
61
+ activate(listener: (frame: ReplicatedStateSourceFrame<T>) => void): void;
62
+ /** Stop delivery and release source resources. Disposal must be idempotent. */
63
+ dispose(): void;
64
+ }
65
+ /**
66
+ * An authoritative immutable revision source.
67
+ *
68
+ * `attach()` must synchronously and atomically capture one snapshot and register the returned attachment to buffer
69
+ * every later committed frame. The snapshot must include every commit before that boundary; buffered frames must
70
+ * include every commit after it, with no overlap or gap. Snapshot values, frame values, and operation batches are
71
+ * immutable and remain valid after delivery. Chord only publishes these references; it never applies or re-diffs them.
72
+ */
73
+ export interface ReplicatedStateSource<T> {
74
+ attach(): ReplicatedStateSourceAttachment<T>;
75
+ }
76
+ export interface ReplicatedStateSourceOptions {
77
+ /** Receives source-contract and publication-listener failures without throwing them into the source. */
78
+ readonly onError?: (error: Error) => void;
79
+ }
80
+ /** A synchronously hydrated publication-only state backed by one source attachment. */
81
+ export interface AttachedReplicatedState<T> extends ReplicatedState<T> {
82
+ readonly value: T;
83
+ /** Idempotently release the source attachment. The last published value remains readable. */
84
+ dispose(): void;
85
+ }
86
+ export declare function replicatedState<T>(source: ReplicatedStateSource<T>, options?: ReplicatedStateSourceOptions): AttachedReplicatedState<T>;
87
+ /**
88
+ * Create authoritative state by taking immutable ownership of an alias-free strict-JSON root.
89
+ * The caller must not mutate `initial` after this call.
90
+ */
91
+ export declare function replicatedState<T extends object>(initial: T): MutableReplicatedState<T>;
92
+ //# sourceMappingURL=state.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"state.d.ts","sourceRoot":"","sources":["../src/state.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EAAsB,KAAK,OAAO,EAAE,MAAM,oBAAoB,CAAC;AACtE,OAAO,EAAE,KAAK,KAAK,EAAE,KAAK,EAAE,EAAsC,MAAM,kBAAkB,CAAC;AAE3F,MAAM,WAAW,uBAAuB;IACvC,QAAQ,CAAC,IAAI,EAAE,SAAS,GAAG,QAAQ,CAAC;IACpC,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;CAC1B;AAED,MAAM,WAAW,eAAe,CAAC,CAAC;IACjC;;;OAGG;IACH,QAAQ,CAAC,KAAK,EAAE,CAAC,GAAG,SAAS,CAAC;IAC9B;;;;;OAKG;IACH,SAAS,CAAC,QAAQ,EAAE,CAAC,KAAK,EAAE,CAAC,EAAE,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,uBAAuB,KAAK,OAAO,CAAC,IAAI,CAAC,GAAG,MAAM,IAAI,CAAC;IAClH,SAAS,CAAC,QAAQ,EAAE,CAAC,KAAK,EAAE,CAAC,EAAE,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,uBAAuB,KAAK,IAAI,GAAG,MAAM,IAAI,CAAC;CACzG;AAED,MAAM,WAAW,sBAAsB,CAAC,CAAC,SAAS,MAAM,CAAE,SAAQ,eAAe,CAAC,CAAC,CAAC;IACnF,QAAQ,CAAC,KAAK,EAAE,CAAC,CAAC;IAClB;;;OAGG;IACH,MAAM,CAAC,OAAO,EAAE,OAAO,EAAE,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