@framers/sql-storage-adapter 0.7.1 → 0.7.3

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 (192) hide show
  1. package/README.md +43 -0
  2. package/dist/adapters/electron/preload.cjs +289 -0
  3. package/dist/adapters/electron/renderer.d.ts +9 -0
  4. package/dist/adapters/electron/renderer.d.ts.map +1 -0
  5. package/dist/adapters/electron/renderer.js +8 -0
  6. package/dist/adapters/electron/renderer.js.map +1 -0
  7. package/dist/cjs/adapters/__tests__/indexedDbAdapter.spec.d.ts +2 -0
  8. package/dist/cjs/adapters/__tests__/indexedDbAdapter.spec.js +133 -0
  9. package/dist/cjs/adapters/baseStorageAdapter.d.ts +368 -0
  10. package/dist/cjs/adapters/baseStorageAdapter.js +744 -0
  11. package/dist/cjs/adapters/betterSqliteAdapter.d.ts +124 -0
  12. package/dist/cjs/adapters/betterSqliteAdapter.js +334 -0
  13. package/dist/cjs/adapters/capacitorSqliteAdapter.d.ts +83 -0
  14. package/dist/cjs/adapters/capacitorSqliteAdapter.js +250 -0
  15. package/dist/cjs/adapters/electron/electronMainAdapter.d.ts +251 -0
  16. package/dist/cjs/adapters/electron/electronMainAdapter.js +392 -0
  17. package/dist/cjs/adapters/electron/electronRendererAdapter.d.ts +177 -0
  18. package/dist/cjs/adapters/electron/electronRendererAdapter.js +283 -0
  19. package/dist/cjs/adapters/electron/index.d.ts +74 -0
  20. package/dist/cjs/adapters/electron/index.js +86 -0
  21. package/dist/cjs/adapters/electron/ipc/channels.d.ts +196 -0
  22. package/dist/cjs/adapters/electron/ipc/channels.js +127 -0
  23. package/dist/cjs/adapters/electron/ipc/index.d.ts +11 -0
  24. package/dist/cjs/adapters/electron/ipc/index.js +38 -0
  25. package/dist/cjs/adapters/electron/ipc/protocol.d.ts +78 -0
  26. package/dist/cjs/adapters/electron/ipc/protocol.js +341 -0
  27. package/dist/cjs/adapters/electron/ipc/types.d.ts +248 -0
  28. package/dist/cjs/adapters/electron/ipc/types.js +15 -0
  29. package/dist/cjs/adapters/electron/migration/autoMigrator.d.ts +184 -0
  30. package/dist/cjs/adapters/electron/migration/autoMigrator.js +441 -0
  31. package/dist/cjs/adapters/electron/migration/index.d.ts +9 -0
  32. package/dist/cjs/adapters/electron/migration/index.js +29 -0
  33. package/dist/cjs/adapters/electron/preload.d.ts +126 -0
  34. package/dist/cjs/adapters/electron/preload.js +233 -0
  35. package/dist/cjs/adapters/electron/recovery/corruptionDetector.d.ts +214 -0
  36. package/dist/cjs/adapters/electron/recovery/corruptionDetector.js +359 -0
  37. package/dist/cjs/adapters/electron/recovery/index.d.ts +11 -0
  38. package/dist/cjs/adapters/electron/recovery/index.js +34 -0
  39. package/dist/cjs/adapters/electron/recovery/walCheckpoint.d.ts +186 -0
  40. package/dist/cjs/adapters/electron/recovery/walCheckpoint.js +263 -0
  41. package/dist/cjs/adapters/electron/renderer.d.ts +9 -0
  42. package/dist/cjs/adapters/electron/renderer.js +33 -0
  43. package/dist/cjs/adapters/electron/window/index.d.ts +9 -0
  44. package/dist/cjs/adapters/electron/window/index.js +29 -0
  45. package/dist/cjs/adapters/electron/window/windowManager.d.ts +190 -0
  46. package/dist/cjs/adapters/electron/window/windowManager.js +321 -0
  47. package/dist/cjs/adapters/indexedDbAdapter.d.ts +490 -0
  48. package/dist/cjs/adapters/indexedDbAdapter.js +993 -0
  49. package/dist/cjs/adapters/postgresAdapter.d.ts +424 -0
  50. package/dist/cjs/adapters/postgresAdapter.js +889 -0
  51. package/dist/cjs/adapters/sqlJsAdapter.d.ts +64 -0
  52. package/dist/cjs/adapters/sqlJsAdapter.js +268 -0
  53. package/dist/cjs/adapters/supabase.d.ts +58 -0
  54. package/dist/cjs/adapters/supabase.js +401 -0
  55. package/dist/cjs/codecs/BrowserBlobCodec.d.ts +14 -0
  56. package/dist/cjs/codecs/BrowserBlobCodec.js +57 -0
  57. package/dist/cjs/codecs/NodeBlobCodec.d.ts +14 -0
  58. package/dist/cjs/codecs/NodeBlobCodec.js +59 -0
  59. package/dist/cjs/core/contracts/blobCodec.d.ts +15 -0
  60. package/dist/cjs/core/contracts/blobCodec.js +15 -0
  61. package/dist/cjs/core/contracts/context.d.ts +221 -0
  62. package/dist/cjs/core/contracts/context.js +15 -0
  63. package/dist/cjs/core/contracts/dialect.d.ts +154 -0
  64. package/dist/cjs/core/contracts/dialect.js +15 -0
  65. package/dist/cjs/core/contracts/events.d.ts +225 -0
  66. package/dist/cjs/core/contracts/events.js +15 -0
  67. package/dist/cjs/core/contracts/exporter.d.ts +13 -0
  68. package/dist/cjs/core/contracts/exporter.js +15 -0
  69. package/dist/cjs/core/contracts/extensions.d.ts +73 -0
  70. package/dist/cjs/core/contracts/extensions.js +15 -0
  71. package/dist/cjs/core/contracts/features.d.ts +25 -0
  72. package/dist/cjs/core/contracts/features.js +61 -0
  73. package/dist/cjs/core/contracts/fts.d.ts +66 -0
  74. package/dist/cjs/core/contracts/fts.js +15 -0
  75. package/dist/cjs/core/contracts/hooks.d.ts +481 -0
  76. package/dist/cjs/core/contracts/hooks.js +140 -0
  77. package/dist/cjs/core/contracts/index.d.ts +260 -0
  78. package/dist/cjs/core/contracts/index.js +41 -0
  79. package/dist/cjs/core/contracts/limitations.d.ts +46 -0
  80. package/dist/cjs/core/contracts/limitations.js +218 -0
  81. package/dist/cjs/core/contracts/performance.d.ts +308 -0
  82. package/dist/cjs/core/contracts/performance.js +144 -0
  83. package/dist/cjs/core/database.d.ts +220 -0
  84. package/dist/cjs/core/database.js +136 -0
  85. package/dist/cjs/core/portable.d.ts +23 -0
  86. package/dist/cjs/core/portable.js +66 -0
  87. package/dist/cjs/core/resolver.d.ts +77 -0
  88. package/dist/cjs/core/resolver.js +235 -0
  89. package/dist/cjs/dialects/PostgresDialect.d.ts +35 -0
  90. package/dist/cjs/dialects/PostgresDialect.js +143 -0
  91. package/dist/cjs/dialects/SqliteDialect.d.ts +35 -0
  92. package/dist/cjs/dialects/SqliteDialect.js +142 -0
  93. package/dist/cjs/dialects/shared.d.ts +17 -0
  94. package/dist/cjs/dialects/shared.js +90 -0
  95. package/dist/cjs/exporters/PostgresExporter.d.ts +14 -0
  96. package/dist/cjs/exporters/PostgresExporter.js +61 -0
  97. package/dist/cjs/exporters/SqliteFileExporter.d.ts +16 -0
  98. package/dist/cjs/exporters/SqliteFileExporter.js +43 -0
  99. package/dist/cjs/features/backup/cloudBackup.d.ts +219 -0
  100. package/dist/cjs/features/backup/cloudBackup.js +209 -0
  101. package/dist/cjs/features/kv/idb.d.ts +79 -0
  102. package/dist/cjs/features/kv/idb.js +32 -0
  103. package/dist/cjs/features/kv/index.d.ts +14 -0
  104. package/dist/cjs/features/kv/index.js +40 -0
  105. package/dist/cjs/features/kv/indexedDbKeyValueStore.d.ts +77 -0
  106. package/dist/cjs/features/kv/indexedDbKeyValueStore.js +116 -0
  107. package/dist/cjs/features/kv/keyValueStore.d.ts +48 -0
  108. package/dist/cjs/features/kv/keyValueStore.js +67 -0
  109. package/dist/cjs/features/kv/sqlKeyValueStore.d.ts +34 -0
  110. package/dist/cjs/features/kv/sqlKeyValueStore.js +81 -0
  111. package/dist/cjs/features/kv/valueCodec.d.ts +35 -0
  112. package/dist/cjs/features/kv/valueCodec.js +426 -0
  113. package/dist/cjs/features/migrations/dataExport.d.ts +77 -0
  114. package/dist/cjs/features/migrations/dataExport.js +194 -0
  115. package/dist/cjs/features/migrations/dataImport.d.ts +54 -0
  116. package/dist/cjs/features/migrations/dataImport.js +300 -0
  117. package/dist/cjs/features/migrations/migration.d.ts +89 -0
  118. package/dist/cjs/features/migrations/migration.js +187 -0
  119. package/dist/cjs/features/migrations/schemaMigrations.d.ts +93 -0
  120. package/dist/cjs/features/migrations/schemaMigrations.js +220 -0
  121. package/dist/cjs/features/sync/conflicts/conflictResolver.d.ts +222 -0
  122. package/dist/cjs/features/sync/conflicts/conflictResolver.js +366 -0
  123. package/dist/cjs/features/sync/conflicts/index.d.ts +9 -0
  124. package/dist/cjs/features/sync/conflicts/index.js +21 -0
  125. package/dist/cjs/features/sync/crossPlatformSync.d.ts +281 -0
  126. package/dist/cjs/features/sync/crossPlatformSync.js +551 -0
  127. package/dist/cjs/features/sync/devices/deviceManager.d.ts +243 -0
  128. package/dist/cjs/features/sync/devices/deviceManager.js +450 -0
  129. package/dist/cjs/features/sync/devices/index.d.ts +10 -0
  130. package/dist/cjs/features/sync/devices/index.js +21 -0
  131. package/dist/cjs/features/sync/index.d.ts +37 -0
  132. package/dist/cjs/features/sync/index.js +111 -0
  133. package/dist/cjs/features/sync/protocol/index.d.ts +11 -0
  134. package/dist/cjs/features/sync/protocol/index.js +23 -0
  135. package/dist/cjs/features/sync/protocol/messages.d.ts +348 -0
  136. package/dist/cjs/features/sync/protocol/messages.js +215 -0
  137. package/dist/cjs/features/sync/protocol/vectorClock.d.ts +164 -0
  138. package/dist/cjs/features/sync/protocol/vectorClock.js +256 -0
  139. package/dist/cjs/features/sync/syncManager.d.ts +348 -0
  140. package/dist/cjs/features/sync/syncManager.js +455 -0
  141. package/dist/cjs/features/sync/tables/index.d.ts +10 -0
  142. package/dist/cjs/features/sync/tables/index.js +21 -0
  143. package/dist/cjs/features/sync/tables/syncLogManager.d.ts +216 -0
  144. package/dist/cjs/features/sync/tables/syncLogManager.js +423 -0
  145. package/dist/cjs/features/sync/transport/httpTransport.d.ts +123 -0
  146. package/dist/cjs/features/sync/transport/httpTransport.js +346 -0
  147. package/dist/cjs/features/sync/transport/index.d.ts +12 -0
  148. package/dist/cjs/features/sync/transport/index.js +25 -0
  149. package/dist/cjs/features/sync/transport/transport.d.ts +259 -0
  150. package/dist/cjs/features/sync/transport/transport.js +163 -0
  151. package/dist/cjs/features/sync/transport/websocketTransport.d.ts +126 -0
  152. package/dist/cjs/features/sync/transport/websocketTransport.js +342 -0
  153. package/dist/cjs/fts/PostgresFts.d.ts +29 -0
  154. package/dist/cjs/fts/PostgresFts.js +77 -0
  155. package/dist/cjs/fts/SqliteFts5.d.ts +22 -0
  156. package/dist/cjs/fts/SqliteFts5.js +58 -0
  157. package/dist/cjs/index.d.ts +30 -0
  158. package/dist/cjs/index.js +101 -0
  159. package/dist/cjs/package.json +3 -0
  160. package/dist/cjs/shared/connectionGate.d.ts +94 -0
  161. package/dist/cjs/shared/connectionGate.js +77 -0
  162. package/dist/cjs/shared/errors.d.ts +23 -0
  163. package/dist/cjs/shared/errors.js +45 -0
  164. package/dist/cjs/shared/logger.d.ts +26 -0
  165. package/dist/cjs/shared/logger.js +40 -0
  166. package/dist/cjs/shared/parameterUtils.d.ts +16 -0
  167. package/dist/cjs/shared/parameterUtils.js +59 -0
  168. package/dist/cjs/shared/postgresTarget.d.ts +11 -0
  169. package/dist/cjs/shared/postgresTarget.js +30 -0
  170. package/dist/cjs/shared/segment.d.ts +43 -0
  171. package/dist/cjs/shared/segment.js +63 -0
  172. package/dist/cjs/shared/serializedTransaction.d.ts +14 -0
  173. package/dist/cjs/shared/serializedTransaction.js +74 -0
  174. package/dist/cjs/shared/splitSqlStatements.d.ts +27 -0
  175. package/dist/cjs/shared/splitSqlStatements.js +163 -0
  176. package/dist/cjs/shared/sqlPlaceholders.d.ts +48 -0
  177. package/dist/cjs/shared/sqlPlaceholders.js +263 -0
  178. package/dist/cjs/types/index.d.ts +29 -0
  179. package/dist/cjs/types/index.js +33 -0
  180. package/dist/core/portable.d.ts +23 -0
  181. package/dist/core/portable.d.ts.map +1 -0
  182. package/dist/core/portable.js +23 -0
  183. package/dist/core/portable.js.map +1 -0
  184. package/dist/features/migrations/schemaMigrations.d.ts +93 -0
  185. package/dist/features/migrations/schemaMigrations.d.ts.map +1 -0
  186. package/dist/features/migrations/schemaMigrations.js +216 -0
  187. package/dist/features/migrations/schemaMigrations.js.map +1 -0
  188. package/dist/index.d.ts +1 -0
  189. package/dist/index.d.ts.map +1 -1
  190. package/dist/index.js +1 -0
  191. package/dist/index.js.map +1 -1
  192. package/package.json +139 -24
@@ -0,0 +1,59 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+ var parameterUtils_exports = {};
19
+ __export(parameterUtils_exports, {
20
+ expandNamedParameters: () => expandNamedParameters,
21
+ normaliseParameters: () => normaliseParameters
22
+ });
23
+ module.exports = __toCommonJS(parameterUtils_exports);
24
+ const normaliseParameters = (parameters) => {
25
+ if (parameters == null) {
26
+ return {};
27
+ }
28
+ if (Array.isArray(parameters)) {
29
+ return { positional: parameters };
30
+ }
31
+ if (typeof parameters === "object") {
32
+ return { named: parameters };
33
+ }
34
+ return { positional: [parameters] };
35
+ };
36
+ const expandNamedParameters = (named) => {
37
+ const expanded = { ...named };
38
+ for (const [rawKey, value] of Object.entries(named)) {
39
+ if (!rawKey)
40
+ continue;
41
+ const key = rawKey.replace(/^[:@$]/, "");
42
+ if (!key)
43
+ continue;
44
+ if (!(key in expanded))
45
+ expanded[key] = value;
46
+ if (!(`:${key}` in expanded))
47
+ expanded[`:${key}`] = value;
48
+ if (!(`@${key}` in expanded))
49
+ expanded[`@${key}`] = value;
50
+ if (!(`$${key}` in expanded))
51
+ expanded[`$${key}`] = value;
52
+ }
53
+ return expanded;
54
+ };
55
+ // Annotate the CommonJS export names for ESM import in node:
56
+ 0 && (module.exports = {
57
+ expandNamedParameters,
58
+ normaliseParameters
59
+ });
@@ -0,0 +1,11 @@
1
+ import type { PostgresAdapterOptions } from '../adapters/postgresAdapter.js';
2
+ /** A string with something in it. */
3
+ export declare const isNonEmpty: (value: unknown) => value is string;
4
+ /**
5
+ * Whether Postgres options name a server: a pool of the caller's, a
6
+ * connection string, or a host, database or user.
7
+ * `{ connectionString: process.env.DATABASE_URL }` with DATABASE_URL unset
8
+ * names none.
9
+ */
10
+ export declare const namesPostgresServer: (options: PostgresAdapterOptions | undefined) => boolean;
11
+ //# sourceMappingURL=postgresTarget.d.ts.map
@@ -0,0 +1,30 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+ var postgresTarget_exports = {};
19
+ __export(postgresTarget_exports, {
20
+ isNonEmpty: () => isNonEmpty,
21
+ namesPostgresServer: () => namesPostgresServer
22
+ });
23
+ module.exports = __toCommonJS(postgresTarget_exports);
24
+ const isNonEmpty = (value) => typeof value === "string" && value.length > 0;
25
+ const namesPostgresServer = (options) => Boolean(options && (Boolean(options.pool) || isNonEmpty(options.connectionString) || isNonEmpty(options.host) || isNonEmpty(options.database) || isNonEmpty(options.user)));
26
+ // Annotate the CommonJS export names for ESM import in node:
27
+ 0 && (module.exports = {
28
+ isNonEmpty,
29
+ namesPostgresServer
30
+ });
@@ -0,0 +1,43 @@
1
+ /**
2
+ * Segments keep one user's tables apart from another's in a database they
3
+ * share. On PostgreSQL a segment is a schema of its own; on the SQLite family a
4
+ * database file of its own; on IndexedDB and Capacitor a database name of its
5
+ * own. A segment name is the same on every backend, so one name gives a host
6
+ * the same separation on the server, the desktop, the phone and the browser.
7
+ *
8
+ * This module imports nothing, so browser bundles can include it.
9
+ */
10
+ /**
11
+ * Checks a segment name and returns it.
12
+ *
13
+ * A segment name is lower-case letters, digits and underscores, starts with a
14
+ * letter or an underscore, and has at most 63 characters: an unquoted
15
+ * PostgreSQL identifier, and a safe file, IndexedDB and Capacitor database
16
+ * name. It is not `public`, `information_schema` or a name beginning with
17
+ * `pg_`, which PostgreSQL keeps for its own schemas.
18
+ *
19
+ * @throws {Error} When the name is not one a segment can take.
20
+ */
21
+ export declare const validateSegment: (segment: string) => string;
22
+ /**
23
+ * The name of a segment's database: `name` followed by `-` and the segment,
24
+ * or `name` itself when there is no segment. For IndexedDB and Capacitor
25
+ * database names: `app-db` and segment `agentos` give `app-db-agentos`.
26
+ *
27
+ * @throws {Error} When the segment is not one a segment name can take.
28
+ */
29
+ export declare const segmentName: (name: string, segment: string | undefined) => string;
30
+ /**
31
+ * The file of a segment's database: the segment goes between the file's name
32
+ * and its extension (`/data/app.sqlite3` and segment `agentos` give
33
+ * `/data/app-agentos.sqlite3`), or after a name with no extension. A `file:`
34
+ * URI keeps its query, and SQLite's in-memory names (`:memory:`,
35
+ * `file::memory:`) stay as they are, since each in-memory connection is a
36
+ * database of its own. Without a segment the path is returned as it is.
37
+ *
38
+ * @throws {Error} When the segment is not one a segment name can take.
39
+ */
40
+ export declare const segmentFilePath: (filePath: string, segment: string | undefined) => string;
41
+ /** Whether a path names an in-memory SQLite database, which no file holds. */
42
+ export declare const namesInMemoryDatabase: (filePath: string) => boolean;
43
+ //# sourceMappingURL=segment.d.ts.map
@@ -0,0 +1,63 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+ var segment_exports = {};
19
+ __export(segment_exports, {
20
+ namesInMemoryDatabase: () => namesInMemoryDatabase,
21
+ segmentFilePath: () => segmentFilePath,
22
+ segmentName: () => segmentName,
23
+ validateSegment: () => validateSegment
24
+ });
25
+ module.exports = __toCommonJS(segment_exports);
26
+ const MAX_SEGMENT_LENGTH = 63;
27
+ const SEGMENT_PATTERN = /^[a-z_][a-z0-9_]*$/;
28
+ const RESERVED_SEGMENTS = /* @__PURE__ */ new Set(["public", "information_schema"]);
29
+ const validateSegment = (segment) => {
30
+ if (typeof segment !== "string" || !SEGMENT_PATTERN.test(segment) || segment.length > MAX_SEGMENT_LENGTH) {
31
+ throw new Error(`Invalid segment ${JSON.stringify(segment)}: a segment name is lower-case letters, digits and underscores, starts with a letter or an underscore, and has at most ${MAX_SEGMENT_LENGTH} characters.`);
32
+ }
33
+ if (RESERVED_SEGMENTS.has(segment) || segment.startsWith("pg_")) {
34
+ throw new Error(`Invalid segment "${segment}": PostgreSQL keeps public, information_schema and the names beginning with pg_ for its own schemas.`);
35
+ }
36
+ return segment;
37
+ };
38
+ const segmentName = (name, segment) => segment === void 0 ? name : `${name}-${validateSegment(segment)}`;
39
+ const isInMemoryPath = (filePath) => filePath === "" || filePath === ":memory:" || filePath.startsWith("file::memory:");
40
+ const segmentFilePath = (filePath, segment) => {
41
+ if (segment === void 0)
42
+ return filePath;
43
+ validateSegment(segment);
44
+ if (isInMemoryPath(filePath))
45
+ return filePath;
46
+ const queryAt = filePath.startsWith("file:") ? filePath.search(/[?#]/) : -1;
47
+ const pathPart = queryAt === -1 ? filePath : filePath.slice(0, queryAt);
48
+ const rest = queryAt === -1 ? "" : filePath.slice(queryAt);
49
+ const nameAt = Math.max(pathPart.lastIndexOf("/"), pathPart.lastIndexOf("\\"), pathPart.startsWith("file:") ? 4 : -1) + 1;
50
+ const directory = pathPart.slice(0, nameAt);
51
+ const name = pathPart.slice(nameAt);
52
+ const extensionAt = name.lastIndexOf(".");
53
+ const segmented = extensionAt > 0 ? `${name.slice(0, extensionAt)}-${segment}${name.slice(extensionAt)}` : `${name}-${segment}`;
54
+ return `${directory}${segmented}${rest}`;
55
+ };
56
+ const namesInMemoryDatabase = isInMemoryPath;
57
+ // Annotate the CommonJS export names for ESM import in node:
58
+ 0 && (module.exports = {
59
+ namesInMemoryDatabase,
60
+ segmentFilePath,
61
+ segmentName,
62
+ validateSegment
63
+ });
@@ -0,0 +1,14 @@
1
+ import type { StorageAdapter } from '../core/contracts/index.js';
2
+ /** Function that runs one asynchronous operation after earlier operations finish. */
3
+ export type SerializedTransactionRunner = <T>(operation: () => Promise<T>) => Promise<T>;
4
+ /**
5
+ * Create a FIFO runner for adapters whose transactions share one connection.
6
+ *
7
+ * The queue tail always resolves, even when an operation rejects, so a failed
8
+ * transaction cannot poison later work. Each caller installs its own release
9
+ * promise before yielding, which preserves invocation order.
10
+ */
11
+ export declare const createSerializedTransactionRunner: () => SerializedTransactionRunner;
12
+ /** Create a callback-scoped adapter view for an already-open transaction. */
13
+ export declare const createSharedConnectionTransactionAdapter: (owner: StorageAdapter) => StorageAdapter;
14
+ //# sourceMappingURL=serializedTransaction.d.ts.map
@@ -0,0 +1,74 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+ var serializedTransaction_exports = {};
19
+ __export(serializedTransaction_exports, {
20
+ createSerializedTransactionRunner: () => createSerializedTransactionRunner,
21
+ createSharedConnectionTransactionAdapter: () => createSharedConnectionTransactionAdapter
22
+ });
23
+ module.exports = __toCommonJS(serializedTransaction_exports);
24
+ const createSerializedTransactionRunner = () => {
25
+ let tail = Promise.resolve();
26
+ return async (operation) => {
27
+ const previous = tail;
28
+ let release;
29
+ tail = new Promise((resolve) => {
30
+ release = resolve;
31
+ });
32
+ await previous;
33
+ try {
34
+ return await operation();
35
+ } finally {
36
+ release();
37
+ }
38
+ };
39
+ };
40
+ class SharedConnectionTransactionAdapter {
41
+ constructor(owner) {
42
+ this.owner = owner;
43
+ this.kind = owner.kind;
44
+ this.capabilities = owner.capabilities;
45
+ if (owner.batch) {
46
+ this.batch = (operations) => owner.batch(operations);
47
+ }
48
+ }
49
+ async open(_options) {
50
+ }
51
+ async run(statement, parameters) {
52
+ return this.owner.run(statement, parameters);
53
+ }
54
+ async get(statement, parameters) {
55
+ return this.owner.get(statement, parameters);
56
+ }
57
+ async all(statement, parameters) {
58
+ return this.owner.all(statement, parameters);
59
+ }
60
+ async exec(script) {
61
+ await this.owner.exec(script);
62
+ }
63
+ async transaction(fn) {
64
+ return fn(this);
65
+ }
66
+ async close() {
67
+ }
68
+ }
69
+ const createSharedConnectionTransactionAdapter = (owner) => new SharedConnectionTransactionAdapter(owner);
70
+ // Annotate the CommonJS export names for ESM import in node:
71
+ 0 && (module.exports = {
72
+ createSerializedTransactionRunner,
73
+ createSharedConnectionTransactionAdapter
74
+ });
@@ -0,0 +1,27 @@
1
+ /**
2
+ * Splits a multi-statement SQL script into individual statements without
3
+ * cutting inside the SQL surface forms a naive `.split(';')` mishandles.
4
+ *
5
+ * Recognised constructs that suppress top-level `;` splitting:
6
+ * - `--` line comments (terminate at the next newline or EOF)
7
+ * - `/* ... *\/` block comments, with Postgres-style nesting
8
+ * - `'...'` single-quoted strings, including the `''` escape for an apostrophe
9
+ * - `"..."` double-quoted identifiers, including the `""` escape
10
+ * - `$$...$$` and `$tag$...$tag$` dollar-quoted strings
11
+ *
12
+ * A bare `$` not followed by a valid tag character or another `$` is treated
13
+ * as a literal `$` so positional parameters (`$1`, `$2`, ...) round-trip.
14
+ *
15
+ * The function returns trimmed, non-empty statements. It does not parse SQL
16
+ * beyond what's needed to find top-level statement separators, and it does
17
+ * not validate or modify statement contents.
18
+ *
19
+ * Postgres E-string escape syntax (`E'...\n...'`) is parsed conservatively:
20
+ * the `E` prefix is ignored and standard `''` escape rules apply. Migrations
21
+ * in this codebase do not rely on backslash escapes, so this is sufficient.
22
+ *
23
+ * @param script - Multi-statement SQL script (may include comments and strings).
24
+ * @returns Array of trimmed individual statements, in input order.
25
+ */
26
+ export declare const splitSqlStatements: (script: string) => string[];
27
+ //# sourceMappingURL=splitSqlStatements.d.ts.map
@@ -0,0 +1,163 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+ var splitSqlStatements_exports = {};
19
+ __export(splitSqlStatements_exports, {
20
+ splitSqlStatements: () => splitSqlStatements
21
+ });
22
+ module.exports = __toCommonJS(splitSqlStatements_exports);
23
+ const splitSqlStatements = (script) => {
24
+ const length = script.length;
25
+ const statements = [];
26
+ let buffer = "";
27
+ let i = 0;
28
+ const pushBuffer = () => {
29
+ const trimmed = buffer.trim();
30
+ if (trimmed.length > 0) {
31
+ statements.push(trimmed);
32
+ }
33
+ buffer = "";
34
+ };
35
+ const isIdentStart = (ch) => ch >= "A" && ch <= "Z" || ch >= "a" && ch <= "z" || ch === "_";
36
+ const isIdentCont = (ch) => isIdentStart(ch) || ch >= "0" && ch <= "9";
37
+ const readDollarTag = (start) => {
38
+ if (script[start] !== "$")
39
+ return null;
40
+ if (start + 1 >= length)
41
+ return null;
42
+ if (script[start + 1] === "$") {
43
+ return "$$";
44
+ }
45
+ if (!isIdentStart(script[start + 1]))
46
+ return null;
47
+ let j = start + 2;
48
+ while (j < length && isIdentCont(script[j])) {
49
+ j += 1;
50
+ }
51
+ if (j >= length || script[j] !== "$")
52
+ return null;
53
+ return script.slice(start, j + 1);
54
+ };
55
+ while (i < length) {
56
+ const ch = script[i];
57
+ const next = i + 1 < length ? script[i + 1] : "";
58
+ if (ch === "-" && next === "-") {
59
+ buffer += ch + next;
60
+ i += 2;
61
+ while (i < length && script[i] !== "\n") {
62
+ buffer += script[i];
63
+ i += 1;
64
+ }
65
+ continue;
66
+ }
67
+ if (ch === "/" && next === "*") {
68
+ buffer += ch + next;
69
+ i += 2;
70
+ let depth = 1;
71
+ while (i < length && depth > 0) {
72
+ const c = script[i];
73
+ const n = i + 1 < length ? script[i + 1] : "";
74
+ if (c === "/" && n === "*") {
75
+ buffer += c + n;
76
+ i += 2;
77
+ depth += 1;
78
+ } else if (c === "*" && n === "/") {
79
+ buffer += c + n;
80
+ i += 2;
81
+ depth -= 1;
82
+ } else {
83
+ buffer += c;
84
+ i += 1;
85
+ }
86
+ }
87
+ continue;
88
+ }
89
+ if (ch === "'") {
90
+ buffer += ch;
91
+ i += 1;
92
+ while (i < length) {
93
+ const c = script[i];
94
+ if (c === "'") {
95
+ if (i + 1 < length && script[i + 1] === "'") {
96
+ buffer += "''";
97
+ i += 2;
98
+ continue;
99
+ }
100
+ buffer += c;
101
+ i += 1;
102
+ break;
103
+ }
104
+ buffer += c;
105
+ i += 1;
106
+ }
107
+ continue;
108
+ }
109
+ if (ch === '"') {
110
+ buffer += ch;
111
+ i += 1;
112
+ while (i < length) {
113
+ const c = script[i];
114
+ if (c === '"') {
115
+ if (i + 1 < length && script[i + 1] === '"') {
116
+ buffer += '""';
117
+ i += 2;
118
+ continue;
119
+ }
120
+ buffer += c;
121
+ i += 1;
122
+ break;
123
+ }
124
+ buffer += c;
125
+ i += 1;
126
+ }
127
+ continue;
128
+ }
129
+ if (ch === "$") {
130
+ const tag = readDollarTag(i);
131
+ if (tag !== null) {
132
+ buffer += tag;
133
+ i += tag.length;
134
+ while (i < length) {
135
+ if (script[i] === "$") {
136
+ const close = readDollarTag(i);
137
+ if (close === tag) {
138
+ buffer += close;
139
+ i += close.length;
140
+ break;
141
+ }
142
+ }
143
+ buffer += script[i];
144
+ i += 1;
145
+ }
146
+ continue;
147
+ }
148
+ }
149
+ if (ch === ";") {
150
+ pushBuffer();
151
+ i += 1;
152
+ continue;
153
+ }
154
+ buffer += ch;
155
+ i += 1;
156
+ }
157
+ pushBuffer();
158
+ return statements;
159
+ };
160
+ // Annotate the CommonJS export names for ESM import in node:
161
+ 0 && (module.exports = {
162
+ splitSqlStatements
163
+ });
@@ -0,0 +1,48 @@
1
+ import type { StorageParameters } from '../core/contracts/index.js';
2
+ /** A statement and its values, ready for node-postgres. */
3
+ export interface PostgresStatement {
4
+ text: string;
5
+ values: unknown[];
6
+ }
7
+ /**
8
+ * Rewrites a statement's placeholders for node-postgres, which takes only
9
+ * `$1`, `$2`, ... Outside literals, quoted identifiers, dollar-quoted strings
10
+ * and comments:
11
+ *
12
+ * - Named parameters: each `@name` becomes the next `$n`, bound to that name's value.
13
+ * - A statement that already uses `$n` placeholders is sent as written, its
14
+ * `?` operators included.
15
+ * - Otherwise `??` becomes `?` (the jsonb key-exists operator), `?|` and `?&`
16
+ * stay operators (`?||` and `?&&` are a placeholder followed by `||` or
17
+ * `&&`), and each other `?` becomes the next `$n`. A statement run without
18
+ * parameters keeps its `?`, so the jsonb `?` operator works in it as written.
19
+ */
20
+ export declare const toPostgresStatement: (statement: string, parameters?: StorageParameters) => PostgresStatement;
21
+ /** A statement and its parameters, ready for a SQLite engine. */
22
+ export interface SqliteStatement {
23
+ statement: string;
24
+ parameters?: StorageParameters;
25
+ }
26
+ /**
27
+ * A value as the SQLite adapters bind it. better-sqlite3 refuses booleans,
28
+ * Dates and objects, and sql.js refuses Dates and binds an array as a blob,
29
+ * so: a boolean binds as 1 or 0, a Date as its ISO 8601 text (an Invalid Date
30
+ * is refused), an array or a plain object as JSON text, and undefined as
31
+ * NULL. Strings, numbers, bigints, null and bytes bind as they are.
32
+ */
33
+ export declare const toSqliteValue: (value: unknown) => unknown;
34
+ /**
35
+ * The statement and values a SQLite adapter binds: `$n` placeholders become
36
+ * `?` (see rewriteDollarPlaceholders above) and each value is converted with
37
+ * toSqliteValue, positional and named alike.
38
+ */
39
+ export declare const toSqliteStatement: (statement: string, parameters?: StorageParameters) => SqliteStatement;
40
+ /**
41
+ * better-sqlite3 binds every JavaScript number as a REAL (sqlite3_bind_double),
42
+ * so 7 reaches SQL as 7.0: `CAST(? AS TEXT)` gives '7.0', a TEXT column
43
+ * stores '7.0', and a comparison with a JSON element misses. It binds a
44
+ * BigInt as an INTEGER, so this hands it each safe integer as one. sql.js
45
+ * binds integers in the 32-bit range as INTEGER already.
46
+ */
47
+ export declare const integersAsBigInt: (parameters?: StorageParameters) => StorageParameters;
48
+ //# sourceMappingURL=sqlPlaceholders.d.ts.map