@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,77 @@
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 PostgresFts_exports = {};
19
+ __export(PostgresFts_exports, {
20
+ PostgresFts: () => PostgresFts
21
+ });
22
+ module.exports = __toCommonJS(PostgresFts_exports);
23
+ class PostgresFts {
24
+ constructor() {
25
+ this._contentTable = "";
26
+ this._columns = [];
27
+ this._lang = "english";
28
+ }
29
+ createIndex(config) {
30
+ const ct = config.contentTable ?? config.table;
31
+ this._contentTable = ct;
32
+ this._columns = config.columns;
33
+ const colConcat = config.columns.map((c) => `COALESCE(${c}, '')`).join(" || ' ' || ");
34
+ const lang = this._tokenizerToLang(config.tokenizer);
35
+ this._lang = lang;
36
+ return [
37
+ `ALTER TABLE ${ct} ADD COLUMN IF NOT EXISTS _tsv tsvector`,
38
+ `CREATE INDEX IF NOT EXISTS idx_${config.table}_tsv ON ${ct} USING GIN(_tsv)`,
39
+ `UPDATE ${ct} SET _tsv = to_tsvector('${lang}', ${colConcat}) WHERE _tsv IS NULL`
40
+ ].join(";\n");
41
+ }
42
+ matchClause(_indexName, queryPlaceholder) {
43
+ return `_tsv @@ plainto_tsquery('${this._lang}', ${queryPlaceholder})`;
44
+ }
45
+ rankExpression(_indexName, queryPlaceholder) {
46
+ const qp = queryPlaceholder ?? "$1";
47
+ return `ts_rank(_tsv, plainto_tsquery('${this._lang}', ${qp}))`;
48
+ }
49
+ rebuildCommand(_indexName) {
50
+ const ct = this._contentTable;
51
+ const colConcat = this._columns.map((c) => `COALESCE(${c}, '')`).join(" || ' ' || ");
52
+ return `UPDATE ${ct} SET _tsv = to_tsvector('${this._lang}', ${colConcat})`;
53
+ }
54
+ syncInsert(_indexName, _rowIdExpr, columns) {
55
+ const ct = this._contentTable;
56
+ const colConcat = columns.map((_, index) => `COALESCE($${index + 2}, '')`).join(" || ' ' || ");
57
+ return `UPDATE ${ct} SET _tsv = to_tsvector('${this._lang}', ${colConcat}) WHERE id = $1`;
58
+ }
59
+ sanitizeQuery(input) {
60
+ return input;
61
+ }
62
+ joinClause(contentTable, contentAlias, _ftsAlias, _indexName) {
63
+ return `${contentTable} ${contentAlias}`;
64
+ }
65
+ /** Map FTS5-style tokenizer strings to Postgres text search configurations. */
66
+ _tokenizerToLang(tokenizer) {
67
+ if (!tokenizer)
68
+ return "english";
69
+ if (tokenizer.includes("porter"))
70
+ return "english";
71
+ return "simple";
72
+ }
73
+ }
74
+ // Annotate the CommonJS export names for ESM import in node:
75
+ 0 && (module.exports = {
76
+ PostgresFts
77
+ });
@@ -0,0 +1,22 @@
1
+ import type { IFullTextSearch } from '../core/contracts/fts.js';
2
+ /**
3
+ * SQLite FTS5 full-text search implementation.
4
+ *
5
+ * Uses FTS5 virtual tables with external-content support, porter/ascii
6
+ * tokenizers, and rowid-based joins to the content table.
7
+ */
8
+ export declare class SqliteFts5 implements IFullTextSearch {
9
+ createIndex(config: {
10
+ table: string;
11
+ columns: string[];
12
+ contentTable?: string;
13
+ tokenizer?: string;
14
+ }): string;
15
+ matchClause(indexName: string, queryPlaceholder: string): string;
16
+ rankExpression(indexName: string, _queryPlaceholder?: string): string;
17
+ rebuildCommand(indexName: string): string;
18
+ syncInsert(indexName: string, rowIdExpr: string, columns: string[]): string;
19
+ sanitizeQuery(input: string): string;
20
+ joinClause(contentTable: string, contentAlias: string, ftsAlias: string, indexName: string): string;
21
+ }
22
+ //# sourceMappingURL=SqliteFts5.d.ts.map
@@ -0,0 +1,58 @@
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 SqliteFts5_exports = {};
19
+ __export(SqliteFts5_exports, {
20
+ SqliteFts5: () => SqliteFts5
21
+ });
22
+ module.exports = __toCommonJS(SqliteFts5_exports);
23
+ class SqliteFts5 {
24
+ createIndex(config) {
25
+ const parts = [...config.columns];
26
+ if (config.contentTable) {
27
+ parts.push(`content='${config.contentTable}'`);
28
+ parts.push(`content_rowid='rowid'`);
29
+ }
30
+ if (config.tokenizer) {
31
+ parts.push(`tokenize='${config.tokenizer}'`);
32
+ }
33
+ return `CREATE VIRTUAL TABLE IF NOT EXISTS ${config.table} USING fts5(${parts.join(", ")})`;
34
+ }
35
+ matchClause(indexName, queryPlaceholder) {
36
+ return `${indexName} MATCH ${queryPlaceholder}`;
37
+ }
38
+ rankExpression(indexName, _queryPlaceholder) {
39
+ return `${indexName}.rank`;
40
+ }
41
+ rebuildCommand(indexName) {
42
+ return `INSERT INTO ${indexName}(${indexName}) VALUES('rebuild')`;
43
+ }
44
+ syncInsert(indexName, rowIdExpr, columns) {
45
+ const placeholders = columns.map(() => "?").join(", ");
46
+ return `INSERT INTO ${indexName} (rowid, ${columns.join(", ")}) VALUES (${rowIdExpr}, ${placeholders})`;
47
+ }
48
+ sanitizeQuery(input) {
49
+ return input.replace(/[*()":^~{}[\]\\]/g, "").split(/\s+/).filter((w) => w.length > 0).map((w) => `"${w}"`).join(" OR ");
50
+ }
51
+ joinClause(contentTable, contentAlias, ftsAlias, indexName) {
52
+ return `${indexName} ${ftsAlias} JOIN ${contentTable} ${contentAlias} ON ${contentAlias}.rowid = ${ftsAlias}.rowid`;
53
+ }
54
+ }
55
+ // Annotate the CommonJS export names for ESM import in node:
56
+ 0 && (module.exports = {
57
+ SqliteFts5
58
+ });
@@ -0,0 +1,30 @@
1
+ export * from './types/index.js';
2
+ export * from './core/database.js';
3
+ export * from './core/resolver.js';
4
+ export * from './adapters/betterSqliteAdapter.js';
5
+ export * from './adapters/sqlJsAdapter.js';
6
+ export * from './adapters/indexedDbAdapter.js';
7
+ export * from './adapters/capacitorSqliteAdapter.js';
8
+ export * from './adapters/postgresAdapter.js';
9
+ export * from './adapters/supabase.js';
10
+ export * from './adapters/baseStorageAdapter.js';
11
+ export * from './features/backup/cloudBackup.js';
12
+ export * from './features/migrations/dataExport.js';
13
+ export * from './features/migrations/dataImport.js';
14
+ export * from './features/migrations/migration.js';
15
+ export * from './features/migrations/schemaMigrations.js';
16
+ export * from './features/sync/syncManager.js';
17
+ export * from './shared/parameterUtils.js';
18
+ export { segmentFilePath, segmentName, validateSegment } from './shared/segment.js';
19
+ export { SqliteDialect } from './dialects/SqliteDialect.js';
20
+ export { PostgresDialect } from './dialects/PostgresDialect.js';
21
+ export { SqliteFts5 } from './fts/SqliteFts5.js';
22
+ export { PostgresFts } from './fts/PostgresFts.js';
23
+ export { NodeBlobCodec } from './codecs/NodeBlobCodec.js';
24
+ export { BrowserBlobCodec } from './codecs/BrowserBlobCodec.js';
25
+ export { SqliteFileExporter } from './exporters/SqliteFileExporter.js';
26
+ export { PostgresExporter } from './exporters/PostgresExporter.js';
27
+ export { createStorageFeatures } from './core/contracts/features.js';
28
+ export { isUniqueViolation } from './shared/errors.js';
29
+ export { setStorageLogger, getStorageLogger, type StorageLogger } from './shared/logger.js';
30
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,101 @@
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 __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var dist_exports = {};
20
+ __export(dist_exports, {
21
+ BrowserBlobCodec: () => import_BrowserBlobCodec.BrowserBlobCodec,
22
+ NodeBlobCodec: () => import_NodeBlobCodec.NodeBlobCodec,
23
+ PostgresDialect: () => import_PostgresDialect.PostgresDialect,
24
+ PostgresExporter: () => import_PostgresExporter.PostgresExporter,
25
+ PostgresFts: () => import_PostgresFts.PostgresFts,
26
+ SqliteDialect: () => import_SqliteDialect.SqliteDialect,
27
+ SqliteFileExporter: () => import_SqliteFileExporter.SqliteFileExporter,
28
+ SqliteFts5: () => import_SqliteFts5.SqliteFts5,
29
+ createStorageFeatures: () => import_features.createStorageFeatures,
30
+ getStorageLogger: () => import_logger.getStorageLogger,
31
+ isUniqueViolation: () => import_errors.isUniqueViolation,
32
+ segmentFilePath: () => import_segment.segmentFilePath,
33
+ segmentName: () => import_segment.segmentName,
34
+ setStorageLogger: () => import_logger.setStorageLogger,
35
+ validateSegment: () => import_segment.validateSegment
36
+ });
37
+ module.exports = __toCommonJS(dist_exports);
38
+ __reExport(dist_exports, require("./types/index.js"), module.exports);
39
+ __reExport(dist_exports, require("./core/database.js"), module.exports);
40
+ __reExport(dist_exports, require("./core/resolver.js"), module.exports);
41
+ __reExport(dist_exports, require("./adapters/betterSqliteAdapter.js"), module.exports);
42
+ __reExport(dist_exports, require("./adapters/sqlJsAdapter.js"), module.exports);
43
+ __reExport(dist_exports, require("./adapters/indexedDbAdapter.js"), module.exports);
44
+ __reExport(dist_exports, require("./adapters/capacitorSqliteAdapter.js"), module.exports);
45
+ __reExport(dist_exports, require("./adapters/postgresAdapter.js"), module.exports);
46
+ __reExport(dist_exports, require("./adapters/supabase.js"), module.exports);
47
+ __reExport(dist_exports, require("./adapters/baseStorageAdapter.js"), module.exports);
48
+ __reExport(dist_exports, require("./features/backup/cloudBackup.js"), module.exports);
49
+ __reExport(dist_exports, require("./features/migrations/dataExport.js"), module.exports);
50
+ __reExport(dist_exports, require("./features/migrations/dataImport.js"), module.exports);
51
+ __reExport(dist_exports, require("./features/migrations/migration.js"), module.exports);
52
+ __reExport(dist_exports, require("./features/migrations/schemaMigrations.js"), module.exports);
53
+ __reExport(dist_exports, require("./features/sync/syncManager.js"), module.exports);
54
+ __reExport(dist_exports, require("./shared/parameterUtils.js"), module.exports);
55
+ var import_segment = require("./shared/segment.js");
56
+ var import_SqliteDialect = require("./dialects/SqliteDialect.js");
57
+ var import_PostgresDialect = require("./dialects/PostgresDialect.js");
58
+ var import_SqliteFts5 = require("./fts/SqliteFts5.js");
59
+ var import_PostgresFts = require("./fts/PostgresFts.js");
60
+ var import_NodeBlobCodec = require("./codecs/NodeBlobCodec.js");
61
+ var import_BrowserBlobCodec = require("./codecs/BrowserBlobCodec.js");
62
+ var import_SqliteFileExporter = require("./exporters/SqliteFileExporter.js");
63
+ var import_PostgresExporter = require("./exporters/PostgresExporter.js");
64
+ var import_features = require("./core/contracts/features.js");
65
+ var import_errors = require("./shared/errors.js");
66
+ var import_logger = require("./shared/logger.js");
67
+ // Annotate the CommonJS export names for ESM import in node:
68
+ 0 && (module.exports = {
69
+ BrowserBlobCodec,
70
+ NodeBlobCodec,
71
+ PostgresDialect,
72
+ PostgresExporter,
73
+ PostgresFts,
74
+ SqliteDialect,
75
+ SqliteFileExporter,
76
+ SqliteFts5,
77
+ createStorageFeatures,
78
+ getStorageLogger,
79
+ isUniqueViolation,
80
+ segmentFilePath,
81
+ segmentName,
82
+ setStorageLogger,
83
+ validateSegment,
84
+ ...require("./types/index.js"),
85
+ ...require("./core/database.js"),
86
+ ...require("./core/resolver.js"),
87
+ ...require("./adapters/betterSqliteAdapter.js"),
88
+ ...require("./adapters/sqlJsAdapter.js"),
89
+ ...require("./adapters/indexedDbAdapter.js"),
90
+ ...require("./adapters/capacitorSqliteAdapter.js"),
91
+ ...require("./adapters/postgresAdapter.js"),
92
+ ...require("./adapters/supabase.js"),
93
+ ...require("./adapters/baseStorageAdapter.js"),
94
+ ...require("./features/backup/cloudBackup.js"),
95
+ ...require("./features/migrations/dataExport.js"),
96
+ ...require("./features/migrations/dataImport.js"),
97
+ ...require("./features/migrations/migration.js"),
98
+ ...require("./features/migrations/schemaMigrations.js"),
99
+ ...require("./features/sync/syncManager.js"),
100
+ ...require("./shared/parameterUtils.js")
101
+ });
@@ -0,0 +1,3 @@
1
+ {
2
+ "type": "commonjs"
3
+ }
@@ -0,0 +1,94 @@
1
+ /**
2
+ * Keeps statements from outside an open transaction out of it.
3
+ *
4
+ * An adapter whose transactions share one connection runs BEGIN, the
5
+ * callback's statements and COMMIT on that connection. While the callback
6
+ * awaits, a statement another caller issues would otherwise run on the same
7
+ * connection inside the open transaction: a write would be undone if the
8
+ * transaction rolled back, and a read would see rows the transaction has not
9
+ * committed. The gate makes such a statement wait until the transaction ends.
10
+ *
11
+ * A statement issued from inside the transaction runs in it. Through the
12
+ * callback's handle it carries the transaction's token, so it is admitted
13
+ * whatever async context runs it. Through the adapter itself, from code the
14
+ * callback runs, the callback's async context tells it apart, so the gate needs
15
+ * a context store (Node's AsyncLocalStorage). Without one, the gate either
16
+ * admits every statement that carries no token at once, which is how the
17
+ * adapters behaved before the gate, or makes it wait like any outside caller,
18
+ * so that the handle is the only way into an open transaction: the adapters
19
+ * that run in a browser or a WebView, where there is no context store, wait.
20
+ *
21
+ * This module imports nothing from Node, so browser bundles can include it;
22
+ * the adapter that runs on Node passes the store in.
23
+ */
24
+ /** The part of Node's `AsyncLocalStorage` the gate uses. */
25
+ export interface TransactionContextStore {
26
+ run<R>(store: symbol, callback: () => R): R;
27
+ getStore(): symbol | undefined;
28
+ /** Releases the store; Node collects an enabled store only after this. */
29
+ disable(): void;
30
+ }
31
+ /** The gate of one shared connection. */
32
+ export interface ConnectionGate {
33
+ /**
34
+ * True when a statement must wait: a transaction is open and the statement
35
+ * is not its own. A transaction handle passes its token; any other caller is
36
+ * judged by its async context.
37
+ */
38
+ blocks(token?: symbol): boolean;
39
+ /** True when a transaction is open and the caller runs inside it. */
40
+ inside(): boolean;
41
+ /** The open transaction's token, for a handle made inside it; null when none is open. */
42
+ openToken(): symbol | null;
43
+ /** Settles when the open transaction ends; at once when none is open. */
44
+ ended(): Promise<void>;
45
+ /**
46
+ * Runs one transaction's body with the gate closed to callers outside it.
47
+ * The body receives the transaction's token for its handle, and runs in its
48
+ * own async context, so code it runs is admitted too. The caller runs one
49
+ * body at a time (the adapter's transaction queue).
50
+ */
51
+ hold<T>(body: (token: symbol) => Promise<T>): Promise<T>;
52
+ /** Releases the context store when the connection closes. */
53
+ dispose(): void;
54
+ }
55
+ /** How a gate treats a statement that carries no token. */
56
+ export interface ConnectionGateOptions {
57
+ /**
58
+ * When there is no context store: 'admit' runs such a statement at once (the
59
+ * default, how the adapters behaved before the gate); 'wait' holds it until
60
+ * the open transaction ends, so only the transaction's handle reaches it.
61
+ */
62
+ withoutContext?: 'admit' | 'wait';
63
+ }
64
+ /**
65
+ * Creates the gate of one shared connection.
66
+ *
67
+ * @param context - Node's AsyncLocalStorage, or null where there is none.
68
+ * @param options - What the gate does with a token-less statement when there
69
+ * is no context store.
70
+ */
71
+ export declare const createConnectionGate: (context: TransactionContextStore | null, options?: ConnectionGateOptions) => ConnectionGate;
72
+ /** Reports a statement that is still waiting for an open transaction after a while. */
73
+ export interface LongWaitWatch {
74
+ /** How long a statement may wait before `onLongWait` is called. */
75
+ afterMs: number;
76
+ /** Called once per waiting statement that passes `afterMs`. */
77
+ onLongWait: () => void;
78
+ }
79
+ /**
80
+ * Runs `work` once the gate admits it. `work` starts the statement: it runs it
81
+ * (a synchronous adapter) or sends it (an asynchronous one), and the last check
82
+ * and that start happen in the same turn, so no transaction can open between
83
+ * them; a caller woken when a transaction ends checks again, since the next
84
+ * transaction may already be open.
85
+ *
86
+ * @param token - The transaction's token when the statement comes through a
87
+ * transaction handle; a handle whose transaction has ended waits like any
88
+ * outside caller.
89
+ * @param watch - Reports a statement that waits long, which is how a callback
90
+ * that issues a statement through the adapter instead of its handle shows
91
+ * on an adapter whose gate makes such statements wait.
92
+ */
93
+ export declare const whenAdmitted: <T>(gate: ConnectionGate, work: () => T | PromiseLike<T>, token?: symbol, watch?: LongWaitWatch) => Promise<T>;
94
+ //# sourceMappingURL=connectionGate.d.ts.map
@@ -0,0 +1,77 @@
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 connectionGate_exports = {};
19
+ __export(connectionGate_exports, {
20
+ createConnectionGate: () => createConnectionGate,
21
+ whenAdmitted: () => whenAdmitted
22
+ });
23
+ module.exports = __toCommonJS(connectionGate_exports);
24
+ const createConnectionGate = (context, options = {}) => {
25
+ let open = null;
26
+ const waitWithoutContext = options.withoutContext === "wait";
27
+ return {
28
+ blocks: (token) => {
29
+ if (open === null)
30
+ return false;
31
+ if (token !== void 0)
32
+ return token !== open.id;
33
+ if (context === null)
34
+ return waitWithoutContext;
35
+ return context.getStore() !== open.id;
36
+ },
37
+ inside: () => open !== null && context !== null && context.getStore() === open.id,
38
+ openToken: () => open?.id ?? null,
39
+ ended: () => open?.done ?? Promise.resolve(),
40
+ async hold(body) {
41
+ const id = /* @__PURE__ */ Symbol("transaction");
42
+ let release;
43
+ const done = new Promise((resolve) => {
44
+ release = resolve;
45
+ });
46
+ open = { id, done };
47
+ try {
48
+ return await (context ? context.run(id, () => body(id)) : body(id));
49
+ } finally {
50
+ open = null;
51
+ release();
52
+ }
53
+ },
54
+ dispose: () => {
55
+ context?.disable();
56
+ }
57
+ };
58
+ };
59
+ const whenAdmitted = async (gate, work, token, watch) => {
60
+ if (gate.blocks(token)) {
61
+ const timer = watch ? setTimeout(watch.onLongWait, watch.afterMs) : void 0;
62
+ try {
63
+ while (gate.blocks(token)) {
64
+ await gate.ended();
65
+ }
66
+ } finally {
67
+ if (timer !== void 0)
68
+ clearTimeout(timer);
69
+ }
70
+ }
71
+ return work();
72
+ };
73
+ // Annotate the CommonJS export names for ESM import in node:
74
+ 0 && (module.exports = {
75
+ createConnectionGate,
76
+ whenAdmitted
77
+ });
@@ -0,0 +1,23 @@
1
+ /**
2
+ * Error checks that read the same failure from every adapter.
3
+ */
4
+ /**
5
+ * Whether `error` is a unique or primary-key violation, from any adapter:
6
+ * PostgreSQL's SQLSTATE `23505` (`unique_violation`, pg's `code`),
7
+ * better-sqlite3's `SQLITE_CONSTRAINT_UNIQUE` and
8
+ * `SQLITE_CONSTRAINT_PRIMARYKEY`, and the "UNIQUE constraint failed" message
9
+ * that sql.js, the IndexedDB adapter and the Capacitor plugin give. An error
10
+ * that wraps one as its `cause`, to any depth up to ten, counts too.
11
+ *
12
+ * @example
13
+ * ```typescript
14
+ * try {
15
+ * await db.run('INSERT INTO users (email) VALUES (?)', [email]);
16
+ * } catch (error) {
17
+ * if (isUniqueViolation(error)) return { taken: true };
18
+ * throw error;
19
+ * }
20
+ * ```
21
+ */
22
+ export declare const isUniqueViolation: (error: unknown) => boolean;
23
+ //# sourceMappingURL=errors.d.ts.map
@@ -0,0 +1,45 @@
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 errors_exports = {};
19
+ __export(errors_exports, {
20
+ isUniqueViolation: () => isUniqueViolation
21
+ });
22
+ module.exports = __toCommonJS(errors_exports);
23
+ const SQLITE_UNIQUE_CODES = /* @__PURE__ */ new Set(["SQLITE_CONSTRAINT_UNIQUE", "SQLITE_CONSTRAINT_PRIMARYKEY"]);
24
+ const SQLITE_UNIQUE_MESSAGE = /\bUNIQUE constraint failed\b/;
25
+ const MAX_CAUSE_DEPTH = 10;
26
+ const isUniqueViolation = (error) => {
27
+ const seen = /* @__PURE__ */ new Set();
28
+ let current = error;
29
+ while (current !== null && typeof current === "object" && !seen.has(current) && seen.size < MAX_CAUSE_DEPTH) {
30
+ seen.add(current);
31
+ const { code, message } = current;
32
+ if (code === "23505")
33
+ return true;
34
+ if (typeof code === "string" && SQLITE_UNIQUE_CODES.has(code))
35
+ return true;
36
+ if (typeof message === "string" && SQLITE_UNIQUE_MESSAGE.test(message))
37
+ return true;
38
+ current = current.cause;
39
+ }
40
+ return false;
41
+ };
42
+ // Annotate the CommonJS export names for ESM import in node:
43
+ 0 && (module.exports = {
44
+ isUniqueViolation
45
+ });
@@ -0,0 +1,26 @@
1
+ /**
2
+ * Where the library's log lines go. A host hands its own logger in, and
3
+ * pino's logger fits as it is: each call passes the line's fields first and
4
+ * its message second, as pino takes them. Without one, lines go to the
5
+ * console, as the library has always written them.
6
+ */
7
+ export interface StorageLogger {
8
+ debug?(fields: Record<string, unknown>, message: string): void;
9
+ info(fields: Record<string, unknown>, message: string): void;
10
+ warn(fields: Record<string, unknown>, message: string): void;
11
+ error(fields: Record<string, unknown>, message: string): void;
12
+ }
13
+ /**
14
+ * Routes every line the library writes to `logger`, from then on and in every
15
+ * adapter. `null` routes them back to the console.
16
+ *
17
+ * @example
18
+ * ```typescript
19
+ * import pino from 'pino';
20
+ * setStorageLogger(pino({ name: 'storage' }));
21
+ * ```
22
+ */
23
+ export declare const setStorageLogger: (logger: StorageLogger | null) => void;
24
+ /** The logger the library writes to now. */
25
+ export declare const getStorageLogger: () => StorageLogger;
26
+ //# sourceMappingURL=logger.d.ts.map
@@ -0,0 +1,40 @@
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 logger_exports = {};
19
+ __export(logger_exports, {
20
+ getStorageLogger: () => getStorageLogger,
21
+ setStorageLogger: () => setStorageLogger
22
+ });
23
+ module.exports = __toCommonJS(logger_exports);
24
+ const prefix = (fields) => `[${typeof fields.scope === "string" ? fields.scope : "StorageAdapter"}]`;
25
+ const consoleLogger = {
26
+ debug: (fields, message) => console.log(`${prefix(fields)} ${message}`),
27
+ info: (fields, message) => console.info(`${prefix(fields)} ${message}`),
28
+ warn: (fields, message) => console.warn(`${prefix(fields)} ${message}`),
29
+ error: (fields, message) => console.error(`${prefix(fields)} ${message}`)
30
+ };
31
+ let current = consoleLogger;
32
+ const setStorageLogger = (logger) => {
33
+ current = logger ?? consoleLogger;
34
+ };
35
+ const getStorageLogger = () => current;
36
+ // Annotate the CommonJS export names for ESM import in node:
37
+ 0 && (module.exports = {
38
+ getStorageLogger,
39
+ setStorageLogger
40
+ });
@@ -0,0 +1,16 @@
1
+ import type { StorageParameters } from '../core/contracts/index.js';
2
+ /**
3
+ * Normalises parameter payloads into a tuple of named/object parameters and positional arrays.
4
+ */
5
+ export declare const normaliseParameters: (parameters?: StorageParameters) => {
6
+ named?: Record<string, unknown>;
7
+ positional?: Array<unknown>;
8
+ };
9
+ /**
10
+ * Named parameters under every key sql.js may look them up by. sql.js binds a
11
+ * named value only under the key that matches the placeholder as written
12
+ * (":id", "@id", "$id"); better-sqlite3 takes the bare key ("id"). Expanding
13
+ * every variant lets one payload work on both.
14
+ */
15
+ export declare const expandNamedParameters: (named: Record<string, unknown>) => Record<string, unknown>;
16
+ //# sourceMappingURL=parameterUtils.d.ts.map