@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,263 @@
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 sqlPlaceholders_exports = {};
19
+ __export(sqlPlaceholders_exports, {
20
+ integersAsBigInt: () => integersAsBigInt,
21
+ toPostgresStatement: () => toPostgresStatement,
22
+ toSqliteStatement: () => toSqliteStatement,
23
+ toSqliteValue: () => toSqliteValue
24
+ });
25
+ module.exports = __toCommonJS(sqlPlaceholders_exports);
26
+ var import_parameterUtils = require("./parameterUtils.js");
27
+ const POSTGRES_RULES = { nestedComments: true, dollarQuotes: true, escapeStrings: true, backticks: false };
28
+ const SQLITE_RULES = { nestedComments: false, dollarQuotes: false, escapeStrings: false, backticks: true };
29
+ const isIdentStart = (ch) => ch !== void 0 && (ch >= "A" && ch <= "Z" || ch >= "a" && ch <= "z" || ch === "_");
30
+ const isIdentPart = (ch) => ch !== void 0 && (isIdentStart(ch) || ch >= "0" && ch <= "9" || ch === "$");
31
+ const readDollarTag = (sql, start) => {
32
+ if (sql[start + 1] === "$")
33
+ return "$$";
34
+ if (!isIdentStart(sql[start + 1]))
35
+ return null;
36
+ let end = start + 2;
37
+ while (end < sql.length && (isIdentStart(sql[end]) || sql[end] >= "0" && sql[end] <= "9"))
38
+ end += 1;
39
+ return sql[end] === "$" ? sql.slice(start, end + 1) : null;
40
+ };
41
+ const scanSql = (sql, rules) => {
42
+ const segments = [];
43
+ const length = sql.length;
44
+ let codeStart = 0;
45
+ let i = 0;
46
+ const keep = (start, end) => {
47
+ if (start > codeStart)
48
+ segments.push({ code: true, text: sql.slice(codeStart, start) });
49
+ segments.push({ code: false, text: sql.slice(start, end) });
50
+ codeStart = end;
51
+ };
52
+ while (i < length) {
53
+ const ch = sql[i];
54
+ const next = sql[i + 1];
55
+ if (ch === "-" && next === "-") {
56
+ const newline = sql.indexOf("\n", i + 2);
57
+ const end = newline === -1 ? length : newline;
58
+ keep(i, end);
59
+ i = end;
60
+ continue;
61
+ }
62
+ if (ch === "/" && next === "*") {
63
+ let end = i + 2;
64
+ let depth = 1;
65
+ while (end < length && depth > 0) {
66
+ if (rules.nestedComments && sql[end] === "/" && sql[end + 1] === "*") {
67
+ depth += 1;
68
+ end += 2;
69
+ } else if (sql[end] === "*" && sql[end + 1] === "/") {
70
+ depth -= 1;
71
+ end += 2;
72
+ } else {
73
+ end += 1;
74
+ }
75
+ }
76
+ keep(i, Math.min(end, length));
77
+ i = Math.min(end, length);
78
+ continue;
79
+ }
80
+ if (ch === "'") {
81
+ const escapes = rules.escapeStrings && (sql[i - 1] === "E" || sql[i - 1] === "e") && !isIdentPart(sql[i - 2]);
82
+ let end = i + 1;
83
+ while (end < length) {
84
+ if (escapes && sql[end] === "\\") {
85
+ end += 2;
86
+ continue;
87
+ }
88
+ if (sql[end] === "'") {
89
+ if (sql[end + 1] === "'") {
90
+ end += 2;
91
+ continue;
92
+ }
93
+ end += 1;
94
+ break;
95
+ }
96
+ end += 1;
97
+ }
98
+ keep(i, Math.min(end, length));
99
+ i = Math.min(end, length);
100
+ continue;
101
+ }
102
+ if (ch === '"' || rules.backticks && ch === "`") {
103
+ let end = i + 1;
104
+ while (end < length) {
105
+ if (sql[end] === ch) {
106
+ if (sql[end + 1] === ch) {
107
+ end += 2;
108
+ continue;
109
+ }
110
+ end += 1;
111
+ break;
112
+ }
113
+ end += 1;
114
+ }
115
+ keep(i, Math.min(end, length));
116
+ i = Math.min(end, length);
117
+ continue;
118
+ }
119
+ if (rules.dollarQuotes && ch === "$" && !isIdentPart(sql[i - 1])) {
120
+ const tag = readDollarTag(sql, i);
121
+ if (tag) {
122
+ const close = sql.indexOf(tag, i + tag.length);
123
+ const end = close === -1 ? length : close + tag.length;
124
+ keep(i, end);
125
+ i = end;
126
+ continue;
127
+ }
128
+ }
129
+ i += 1;
130
+ }
131
+ if (codeStart < length)
132
+ segments.push({ code: true, text: sql.slice(codeStart) });
133
+ return segments;
134
+ };
135
+ const DOLLAR_PLACEHOLDER = /(^|[^A-Za-z0-9_$])\$(\d+)/g;
136
+ const hasDollarPlaceholder = (code) => new RegExp(DOLLAR_PLACEHOLDER.source).test(code);
137
+ const toPostgresStatement = (statement, parameters) => {
138
+ const { named, positional } = (0, import_parameterUtils.normaliseParameters)(parameters);
139
+ if (!named && !statement.includes("?")) {
140
+ return { text: statement, values: positional ?? [] };
141
+ }
142
+ if (named && !statement.includes("@")) {
143
+ return { text: statement, values: [] };
144
+ }
145
+ const segments = scanSql(statement, POSTGRES_RULES);
146
+ if (named) {
147
+ const order = [];
148
+ const text2 = segments.map((segment) => segment.code ? segment.text.replace(/@([A-Za-z0-9_]+)/g, (_match, name) => {
149
+ order.push(name);
150
+ return `$${order.length}`;
151
+ }) : segment.text).join("");
152
+ return { text: text2, values: order.map((name) => named[name]) };
153
+ }
154
+ if (segments.some((segment) => segment.code && hasDollarPlaceholder(segment.text))) {
155
+ return { text: statement, values: positional ?? [] };
156
+ }
157
+ let index = 0;
158
+ const text = segments.map((segment) => {
159
+ if (!segment.code)
160
+ return segment.text;
161
+ const code = segment.text;
162
+ let out = "";
163
+ for (let i = 0; i < code.length; i += 1) {
164
+ const ch = code[i];
165
+ if (ch !== "?") {
166
+ out += ch;
167
+ continue;
168
+ }
169
+ const after = code[i + 1];
170
+ if (after === "?") {
171
+ out += "?";
172
+ i += 1;
173
+ } else if (after === "|" && code[i + 2] !== "|" || after === "&" && code[i + 2] !== "&") {
174
+ out += `?${after}`;
175
+ i += 1;
176
+ } else if (positional) {
177
+ index += 1;
178
+ out += `$${index}`;
179
+ } else {
180
+ out += "?";
181
+ }
182
+ }
183
+ return out;
184
+ }).join("");
185
+ return { text, values: positional ?? [] };
186
+ };
187
+ const rewriteDollarPlaceholders = (statement, parameters) => {
188
+ if (!statement.includes("$"))
189
+ return { statement, parameters };
190
+ const { named, positional } = (0, import_parameterUtils.normaliseParameters)(parameters);
191
+ if (named)
192
+ return { statement, parameters };
193
+ const segments = scanSql(statement, SQLITE_RULES);
194
+ if (!segments.some((segment) => segment.code && hasDollarPlaceholder(segment.text))) {
195
+ return { statement, parameters };
196
+ }
197
+ if (segments.some((segment) => segment.code && segment.text.includes("?"))) {
198
+ throw new Error("This statement mixes ? and $n placeholders. Write it with one kind: ?, or $1, $2, ... bound from the same array.");
199
+ }
200
+ const order = [];
201
+ const text = segments.map((segment) => segment.code ? segment.text.replace(DOLLAR_PLACEHOLDER, (_match, before, digits) => {
202
+ order.push(Number(digits));
203
+ return `${before}?`;
204
+ }) : segment.text).join("");
205
+ const values = positional ?? [];
206
+ return { statement: text, parameters: order.map((n) => values[n - 1]) };
207
+ };
208
+ const needsSqliteConversion = (value) => value === void 0 || typeof value === "boolean" || value !== null && typeof value === "object" && !ArrayBuffer.isView(value) && !(value instanceof ArrayBuffer);
209
+ const toSqliteValue = (value) => {
210
+ if (value === void 0)
211
+ return null;
212
+ if (typeof value === "boolean")
213
+ return value ? 1 : 0;
214
+ if (value instanceof Date) {
215
+ if (Number.isNaN(value.getTime())) {
216
+ throw new RangeError("Cannot bind an Invalid Date.");
217
+ }
218
+ return value.toISOString();
219
+ }
220
+ if (needsSqliteConversion(value))
221
+ return JSON.stringify(value);
222
+ return value;
223
+ };
224
+ const toSqliteParameters = (parameters) => {
225
+ if (parameters == null)
226
+ return parameters;
227
+ if (Array.isArray(parameters)) {
228
+ return parameters.some(needsSqliteConversion) ? parameters.map(toSqliteValue) : parameters;
229
+ }
230
+ if (typeof parameters === "object") {
231
+ const values = Object.values(parameters);
232
+ if (!values.some(needsSqliteConversion))
233
+ return parameters;
234
+ return Object.fromEntries(Object.entries(parameters).map(([name, value]) => [name, toSqliteValue(value)]));
235
+ }
236
+ return [toSqliteValue(parameters)];
237
+ };
238
+ const toSqliteStatement = (statement, parameters) => {
239
+ const rewritten = rewriteDollarPlaceholders(statement, parameters);
240
+ return { statement: rewritten.statement, parameters: toSqliteParameters(rewritten.parameters) };
241
+ };
242
+ const isSafeInteger = (value) => typeof value === "number" && Number.isSafeInteger(value);
243
+ const toBigIntIfInteger = (value) => isSafeInteger(value) ? BigInt(value) : value;
244
+ const integersAsBigInt = (parameters) => {
245
+ if (parameters == null)
246
+ return parameters;
247
+ if (Array.isArray(parameters)) {
248
+ return parameters.some(isSafeInteger) ? parameters.map(toBigIntIfInteger) : parameters;
249
+ }
250
+ if (typeof parameters === "object") {
251
+ if (!Object.values(parameters).some(isSafeInteger))
252
+ return parameters;
253
+ return Object.fromEntries(Object.entries(parameters).map(([name, value]) => [name, toBigIntIfInteger(value)]));
254
+ }
255
+ return parameters;
256
+ };
257
+ // Annotate the CommonJS export names for ESM import in node:
258
+ 0 && (module.exports = {
259
+ integersAsBigInt,
260
+ toPostgresStatement,
261
+ toSqliteStatement,
262
+ toSqliteValue
263
+ });
@@ -0,0 +1,29 @@
1
+ /**
2
+ * Aggregated type exports for scenarios where consumers import from
3
+ * "@framers/sql-storage-adapter/types". Ensures Node's specifier
4
+ * resolution finds an index module alongside the compiled artifacts.
5
+ *
6
+ * @packageDocumentation
7
+ * @module @framers/sql-storage-adapter/types
8
+ *
9
+ * @remarks
10
+ * This module re-exports all public types from the sql-storage-adapter package.
11
+ * Import from here when you only need types without runtime code.
12
+ *
13
+ * @example
14
+ * ```typescript
15
+ * import type {
16
+ * StorageAdapter,
17
+ * PerformanceConfig,
18
+ * StorageHooks
19
+ * } from '@framers/sql-storage-adapter/types';
20
+ * ```
21
+ */
22
+ export * from '../core/contracts/index.js';
23
+ export * from '../core/contracts/context.js';
24
+ export * from '../core/contracts/events.js';
25
+ export * from '../core/contracts/extensions.js';
26
+ export * from '../core/contracts/limitations.js';
27
+ export * from '../core/contracts/performance.js';
28
+ export * from '../core/contracts/hooks.js';
29
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,33 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __copyProps = (to, from, except, desc) => {
6
+ if (from && typeof from === "object" || typeof from === "function") {
7
+ for (let key of __getOwnPropNames(from))
8
+ if (!__hasOwnProp.call(to, key) && key !== except)
9
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
10
+ }
11
+ return to;
12
+ };
13
+ var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
14
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
15
+ var types_exports = {};
16
+ module.exports = __toCommonJS(types_exports);
17
+ __reExport(types_exports, require("../core/contracts/index.js"), module.exports);
18
+ __reExport(types_exports, require("../core/contracts/context.js"), module.exports);
19
+ __reExport(types_exports, require("../core/contracts/events.js"), module.exports);
20
+ __reExport(types_exports, require("../core/contracts/extensions.js"), module.exports);
21
+ __reExport(types_exports, require("../core/contracts/limitations.js"), module.exports);
22
+ __reExport(types_exports, require("../core/contracts/performance.js"), module.exports);
23
+ __reExport(types_exports, require("../core/contracts/hooks.js"), module.exports);
24
+ // Annotate the CommonJS export names for ESM import in node:
25
+ 0 && (module.exports = {
26
+ ...require("../core/contracts/index.js"),
27
+ ...require("../core/contracts/context.js"),
28
+ ...require("../core/contracts/events.js"),
29
+ ...require("../core/contracts/extensions.js"),
30
+ ...require("../core/contracts/limitations.js"),
31
+ ...require("../core/contracts/performance.js"),
32
+ ...require("../core/contracts/hooks.js")
33
+ });
@@ -0,0 +1,23 @@
1
+ /**
2
+ * The adapter-free entry, `@framers/sql-storage-adapter/core`: the contracts and errors, the SQL dialects, full-text
3
+ * search, codecs and exporters, `createStorageFeatures`, the schema-migration runner, `isUniqueViolation` and the
4
+ * logger. It imports no adapter, so a server that takes its adapter from a per-adapter entry
5
+ * (`@framers/sql-storage-adapter/postgres`) bundles neither sql.js nor the S3 client.
6
+ *
7
+ * @module
8
+ */
9
+ export * from '../types/index.js';
10
+ export { SqliteDialect } from '../dialects/SqliteDialect.js';
11
+ export { PostgresDialect } from '../dialects/PostgresDialect.js';
12
+ export { SqliteFts5 } from '../fts/SqliteFts5.js';
13
+ export { PostgresFts } from '../fts/PostgresFts.js';
14
+ export { NodeBlobCodec } from '../codecs/NodeBlobCodec.js';
15
+ export { BrowserBlobCodec } from '../codecs/BrowserBlobCodec.js';
16
+ export { SqliteFileExporter } from '../exporters/SqliteFileExporter.js';
17
+ export { PostgresExporter } from '../exporters/PostgresExporter.js';
18
+ export { createStorageFeatures } from './contracts/features.js';
19
+ export { isUniqueViolation } from '../shared/errors.js';
20
+ export { setStorageLogger, getStorageLogger, type StorageLogger } from '../shared/logger.js';
21
+ export * from '../features/migrations/schemaMigrations.js';
22
+ export * from '../shared/parameterUtils.js';
23
+ //# sourceMappingURL=portable.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"portable.d.ts","sourceRoot":"","sources":["../../src/core/portable.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,cAAc,UAAU,CAAC;AACzB,OAAO,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAC1D,OAAO,EAAE,eAAe,EAAE,MAAM,6BAA6B,CAAC;AAC9D,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAC/C,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACjD,OAAO,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AACxD,OAAO,EAAE,gBAAgB,EAAE,MAAM,4BAA4B,CAAC;AAC9D,OAAO,EAAE,kBAAkB,EAAE,MAAM,iCAAiC,CAAC;AACrE,OAAO,EAAE,gBAAgB,EAAE,MAAM,+BAA+B,CAAC;AACjE,OAAO,EAAE,qBAAqB,EAAE,MAAM,sBAAsB,CAAC;AAC7D,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AACrD,OAAO,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,KAAK,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAC1F,cAAc,yCAAyC,CAAC;AACxD,cAAc,0BAA0B,CAAC"}
@@ -0,0 +1,23 @@
1
+ /**
2
+ * The adapter-free entry, `@framers/sql-storage-adapter/core`: the contracts and errors, the SQL dialects, full-text
3
+ * search, codecs and exporters, `createStorageFeatures`, the schema-migration runner, `isUniqueViolation` and the
4
+ * logger. It imports no adapter, so a server that takes its adapter from a per-adapter entry
5
+ * (`@framers/sql-storage-adapter/postgres`) bundles neither sql.js nor the S3 client.
6
+ *
7
+ * @module
8
+ */
9
+ export * from '../types/index.js';
10
+ export { SqliteDialect } from '../dialects/SqliteDialect.js';
11
+ export { PostgresDialect } from '../dialects/PostgresDialect.js';
12
+ export { SqliteFts5 } from '../fts/SqliteFts5.js';
13
+ export { PostgresFts } from '../fts/PostgresFts.js';
14
+ export { NodeBlobCodec } from '../codecs/NodeBlobCodec.js';
15
+ export { BrowserBlobCodec } from '../codecs/BrowserBlobCodec.js';
16
+ export { SqliteFileExporter } from '../exporters/SqliteFileExporter.js';
17
+ export { PostgresExporter } from '../exporters/PostgresExporter.js';
18
+ export { createStorageFeatures } from './contracts/features.js';
19
+ export { isUniqueViolation } from '../shared/errors.js';
20
+ export { setStorageLogger, getStorageLogger } from '../shared/logger.js';
21
+ export * from '../features/migrations/schemaMigrations.js';
22
+ export * from '../shared/parameterUtils.js';
23
+ //# sourceMappingURL=portable.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"portable.js","sourceRoot":"","sources":["../../src/core/portable.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,cAAc,UAAU,CAAC;AACzB,OAAO,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAC1D,OAAO,EAAE,eAAe,EAAE,MAAM,6BAA6B,CAAC;AAC9D,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAC/C,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACjD,OAAO,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AACxD,OAAO,EAAE,gBAAgB,EAAE,MAAM,4BAA4B,CAAC;AAC9D,OAAO,EAAE,kBAAkB,EAAE,MAAM,iCAAiC,CAAC;AACrE,OAAO,EAAE,gBAAgB,EAAE,MAAM,+BAA+B,CAAC;AACjE,OAAO,EAAE,qBAAqB,EAAE,MAAM,sBAAsB,CAAC;AAC7D,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AACrD,OAAO,EAAE,gBAAgB,EAAE,gBAAgB,EAAsB,MAAM,kBAAkB,CAAC;AAC1F,cAAc,yCAAyC,CAAC;AACxD,cAAc,0BAA0B,CAAC"}
@@ -0,0 +1,93 @@
1
+ /**
2
+ * A versioned schema-migration runner over StorageAdapter, for PostgreSQL and
3
+ * SQLite alike. It applies hand-written SQL files in number order, each in its
4
+ * own transaction, records each in a ledger table with the SHA-256 of its text,
5
+ * refuses an applied file whose text changed, and stops at the first error.
6
+ *
7
+ * Locking: on PostgreSQL each file's transaction first takes a
8
+ * transaction-scoped advisory lock, and checks the ledger again under it, so
9
+ * two runners at once apply each file once. A file marked to run outside a
10
+ * transaction (CREATE INDEX CONCURRENTLY) runs under the session-level lock on
11
+ * one held connection. On SQLite the file's write transaction is the lock.
12
+ *
13
+ * @module
14
+ */
15
+ import type { StorageAdapter } from '../../core/contracts/index.js';
16
+ /** One migration: its file name, which orders it, and its SQL. */
17
+ export interface SchemaMigration {
18
+ name: string;
19
+ sql: string;
20
+ }
21
+ /** How the runner names its ledger and lock, and what it does with surprises. */
22
+ export interface SchemaMigrationOptions {
23
+ /** The ledger table, schema-qualified if need be. Default: `schema_migrations`. */
24
+ table?: string;
25
+ /** The ledger column that holds each file's SHA-256 in hex. Default: `checksum`. */
26
+ checksumColumn?: string;
27
+ /**
28
+ * The PostgreSQL advisory lock key: an integer, or text hashed with
29
+ * `hashtext()`. Default: 724313571. Runners that share a database share a key.
30
+ */
31
+ lockKey?: number | string;
32
+ /**
33
+ * A ledger row whose file the list lacks (the database is ahead of the
34
+ * code): `'refuse'` (the default) stops before applying anything; `'ignore'`
35
+ * goes on.
36
+ */
37
+ unknown?: 'refuse' | 'ignore';
38
+ /**
39
+ * A file whose first line, trimmed, is this runs outside a transaction.
40
+ * Default: `-- outside transaction`.
41
+ */
42
+ outsideTransactionMarker?: string;
43
+ }
44
+ /** What a run or a status check found. */
45
+ export interface SchemaMigrationReport {
46
+ /** Applied by this run, in order (a status check applies none, and lists the files the ledger holds unchanged). */
47
+ applied: string[];
48
+ /** Already in the ledger with the same checksum: a run skipped them. */
49
+ skipped: string[];
50
+ /** In the list and not in the ledger: a status check's pending files. */
51
+ pending: string[];
52
+ /** In the ledger with a different checksum. */
53
+ changed: string[];
54
+ /** In the ledger and not in the list. */
55
+ unknown: string[];
56
+ }
57
+ /** Options for reading a migrations folder. */
58
+ export interface ReadSchemaMigrationsOptions {
59
+ /** Reads `<dir>/<dialect>` when that folder exists, else `<dir>`. */
60
+ dialect?: 'postgres' | 'sqlite';
61
+ /**
62
+ * The file-name form, whose first capture group is the number that orders
63
+ * the file. Default: digits, an underscore, then lower-case letters, digits
64
+ * and underscores, `.sql` (`001_init.sql`, `0001_accounts.sql`).
65
+ */
66
+ namePattern?: RegExp;
67
+ }
68
+ /**
69
+ * Reads the migrations of a folder in number order: `<dir>/<dialect>` when
70
+ * that folder exists, else `<dir>`. Files not ending in `.sql` are left out; a
71
+ * `.sql` name out of form, or a number used twice, is refused. Node only.
72
+ */
73
+ export declare function readSchemaMigrations(dir: string, options?: ReadSchemaMigrationsOptions): Promise<SchemaMigration[]>;
74
+ /**
75
+ * Compares the list with the ledger and applies nothing: `applied` lists the
76
+ * files the ledger holds unchanged, `pending` the files it lacks, `changed`
77
+ * the files whose text differs from what was applied, `unknown` the ledger
78
+ * rows the list lacks. Creates the ledger when it is missing.
79
+ */
80
+ export declare function schemaMigrationStatus(adapter: StorageAdapter, migrations: SchemaMigration[], options?: SchemaMigrationOptions): Promise<SchemaMigrationReport>;
81
+ /**
82
+ * Applies every migration the ledger lacks, in list order, and reports what
83
+ * it did: `applied` (this run) and `skipped` (already applied). Refuses to
84
+ * start when an applied file's text changed, or (unless `unknown: 'ignore'`)
85
+ * when the ledger holds a file the list lacks. A file runs in its own
86
+ * transaction and holds no BEGIN or COMMIT; a file whose first line is the
87
+ * outside-transaction marker runs outside one (on PostgreSQL that needs
88
+ * `withConnection`, which PostgresAdapter has). Stops at the first error,
89
+ * after rolling that file back, with an error that names it and carries the
90
+ * database's error as `cause`.
91
+ */
92
+ export declare function runSchemaMigrations(adapter: StorageAdapter, migrations: SchemaMigration[], options?: SchemaMigrationOptions): Promise<SchemaMigrationReport>;
93
+ //# sourceMappingURL=schemaMigrations.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"schemaMigrations.d.ts","sourceRoot":"","sources":["../../../src/features/migrations/schemaMigrations.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AACH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAI3D,kEAAkE;AAClE,MAAM,WAAW,eAAe;IAC9B,IAAI,EAAE,MAAM,CAAC;IACb,GAAG,EAAE,MAAM,CAAC;CACb;AAED,iFAAiF;AACjF,MAAM,WAAW,sBAAsB;IACrC,mFAAmF;IACnF,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,oFAAoF;IACpF,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB;;;OAGG;IACH,OAAO,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IAC1B;;;;OAIG;IACH,OAAO,CAAC,EAAE,QAAQ,GAAG,QAAQ,CAAC;IAC9B;;;OAGG;IACH,wBAAwB,CAAC,EAAE,MAAM,CAAC;CACnC;AAED,0CAA0C;AAC1C,MAAM,WAAW,qBAAqB;IACpC,mHAAmH;IACnH,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,wEAAwE;IACxE,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,yEAAyE;IACzE,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,+CAA+C;IAC/C,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,yCAAyC;IACzC,OAAO,EAAE,MAAM,EAAE,CAAC;CACnB;AAED,+CAA+C;AAC/C,MAAM,WAAW,2BAA2B;IAC1C,qEAAqE;IACrE,OAAO,CAAC,EAAE,UAAU,GAAG,QAAQ,CAAC;IAChC;;;;OAIG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AA2BD;;;;GAIG;AACH,wBAAsB,oBAAoB,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,GAAE,2BAAgC,GAAG,OAAO,CAAC,eAAe,EAAE,CAAC,CA4B7H;AA8ED;;;;;GAKG;AACH,wBAAsB,qBAAqB,CACzC,OAAO,EAAE,cAAc,EACvB,UAAU,EAAE,eAAe,EAAE,EAC7B,OAAO,GAAE,sBAA2B,GACnC,OAAO,CAAC,qBAAqB,CAAC,CAIhC;AAED;;;;;;;;;;GAUG;AACH,wBAAsB,mBAAmB,CACvC,OAAO,EAAE,cAAc,EACvB,UAAU,EAAE,eAAe,EAAE,EAC7B,OAAO,GAAE,sBAA2B,GACnC,OAAO,CAAC,qBAAqB,CAAC,CA6BhC"}