@g9tm/syncdata 1.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (149) hide show
  1. package/LICENSE.md +21 -0
  2. package/PARITY.md +71 -0
  3. package/README.md +71 -0
  4. package/THIRD-PARTY-NOTICES.md +31 -0
  5. package/dist/abstractions/digest.d.ts +27 -0
  6. package/dist/abstractions/digest.js +78 -0
  7. package/dist/abstractions/digest.js.map +1 -0
  8. package/dist/abstractions/enums.d.ts +42 -0
  9. package/dist/abstractions/enums.js +60 -0
  10. package/dist/abstractions/enums.js.map +1 -0
  11. package/dist/abstractions/errors.d.ts +72 -0
  12. package/dist/abstractions/errors.js +90 -0
  13. package/dist/abstractions/errors.js.map +1 -0
  14. package/dist/abstractions/guid.d.ts +24 -0
  15. package/dist/abstractions/guid.js +93 -0
  16. package/dist/abstractions/guid.js.map +1 -0
  17. package/dist/abstractions/key.d.ts +16 -0
  18. package/dist/abstractions/key.js +47 -0
  19. package/dist/abstractions/key.js.map +1 -0
  20. package/dist/abstractions/long.d.ts +103 -0
  21. package/dist/abstractions/long.js +351 -0
  22. package/dist/abstractions/long.js.map +1 -0
  23. package/dist/abstractions/parameters.d.ts +49 -0
  24. package/dist/abstractions/parameters.js +153 -0
  25. package/dist/abstractions/parameters.js.map +1 -0
  26. package/dist/brotli-js/decode.d.ts +8 -0
  27. package/dist/brotli-js/decode.js +2004 -0
  28. package/dist/brotli-js/decode.js.map +1 -0
  29. package/dist/brotli-js/index.d.ts +5 -0
  30. package/dist/brotli-js/index.js +19 -0
  31. package/dist/brotli-js/index.js.map +1 -0
  32. package/dist/client/engine.d.ts +110 -0
  33. package/dist/client/engine.js +1158 -0
  34. package/dist/client/engine.js.map +1 -0
  35. package/dist/client/model.d.ts +61 -0
  36. package/dist/client/model.js +154 -0
  37. package/dist/client/model.js.map +1 -0
  38. package/dist/client/progress.d.ts +101 -0
  39. package/dist/client/progress.js +251 -0
  40. package/dist/client/progress.js.map +1 -0
  41. package/dist/client/runs.d.ts +219 -0
  42. package/dist/client/runs.js +239 -0
  43. package/dist/client/runs.js.map +1 -0
  44. package/dist/client/storeTypes.d.ts +428 -0
  45. package/dist/client/storeTypes.js +256 -0
  46. package/dist/client/storeTypes.js.map +1 -0
  47. package/dist/client/transport.d.ts +19 -0
  48. package/dist/client/transport.js +2 -0
  49. package/dist/client/transport.js.map +1 -0
  50. package/dist/index.d.ts +27 -0
  51. package/dist/index.js +35 -0
  52. package/dist/index.js.map +1 -0
  53. package/dist/internal/abort.d.ts +21 -0
  54. package/dist/internal/abort.js +125 -0
  55. package/dist/internal/abort.js.map +1 -0
  56. package/dist/internal/base64.d.ts +8 -0
  57. package/dist/internal/base64.js +85 -0
  58. package/dist/internal/base64.js.map +1 -0
  59. package/dist/internal/dotnetFormat.d.ts +32 -0
  60. package/dist/internal/dotnetFormat.js +207 -0
  61. package/dist/internal/dotnetFormat.js.map +1 -0
  62. package/dist/internal/md5.d.ts +2 -0
  63. package/dist/internal/md5.js +97 -0
  64. package/dist/internal/md5.js.map +1 -0
  65. package/dist/internal/sha256.d.ts +20 -0
  66. package/dist/internal/sha256.js +153 -0
  67. package/dist/internal/sha256.js.map +1 -0
  68. package/dist/internal/utf8.d.ts +8 -0
  69. package/dist/internal/utf8.js +143 -0
  70. package/dist/internal/utf8.js.map +1 -0
  71. package/dist/node/index.d.ts +9 -0
  72. package/dist/node/index.js +35 -0
  73. package/dist/node/index.js.map +1 -0
  74. package/dist/node/sqliteDriver.d.ts +11 -0
  75. package/dist/node/sqliteDriver.js +252 -0
  76. package/dist/node/sqliteDriver.js.map +1 -0
  77. package/dist/protocol/dtos.d.ts +280 -0
  78. package/dist/protocol/dtos.js +33 -0
  79. package/dist/protocol/dtos.js.map +1 -0
  80. package/dist/protocol/protocol.d.ts +36 -0
  81. package/dist/protocol/protocol.js +63 -0
  82. package/dist/protocol/protocol.js.map +1 -0
  83. package/dist/protocol/rowBatch/columnLayout.d.ts +4 -0
  84. package/dist/protocol/rowBatch/columnLayout.js +309 -0
  85. package/dist/protocol/rowBatch/columnLayout.js.map +1 -0
  86. package/dist/protocol/rowBatch/format.d.ts +74 -0
  87. package/dist/protocol/rowBatch/format.js +163 -0
  88. package/dist/protocol/rowBatch/format.js.map +1 -0
  89. package/dist/protocol/rowBatch/reader.d.ts +119 -0
  90. package/dist/protocol/rowBatch/reader.js +459 -0
  91. package/dist/protocol/rowBatch/reader.js.map +1 -0
  92. package/dist/protocol/rowBatch/writer.d.ts +101 -0
  93. package/dist/protocol/rowBatch/writer.js +412 -0
  94. package/dist/protocol/rowBatch/writer.js.map +1 -0
  95. package/dist/protocol/wire.d.ts +32 -0
  96. package/dist/protocol/wire.js +329 -0
  97. package/dist/protocol/wire.js.map +1 -0
  98. package/dist/signalr/index.d.ts +2 -0
  99. package/dist/signalr/index.js +5 -0
  100. package/dist/signalr/index.js.map +1 -0
  101. package/dist/signalr/protocols.d.ts +17 -0
  102. package/dist/signalr/protocols.js +109 -0
  103. package/dist/signalr/protocols.js.map +1 -0
  104. package/dist/signalr/transport.d.ts +67 -0
  105. package/dist/signalr/transport.js +286 -0
  106. package/dist/signalr/transport.js.map +1 -0
  107. package/dist/sqlite/apply.d.ts +91 -0
  108. package/dist/sqlite/apply.js +657 -0
  109. package/dist/sqlite/apply.js.map +1 -0
  110. package/dist/sqlite/commands.d.ts +24 -0
  111. package/dist/sqlite/commands.js +167 -0
  112. package/dist/sqlite/commands.js.map +1 -0
  113. package/dist/sqlite/connection.d.ts +81 -0
  114. package/dist/sqlite/connection.js +322 -0
  115. package/dist/sqlite/connection.js.map +1 -0
  116. package/dist/sqlite/driver.d.ts +63 -0
  117. package/dist/sqlite/driver.js +9 -0
  118. package/dist/sqlite/driver.js.map +1 -0
  119. package/dist/sqlite/index.d.ts +6 -0
  120. package/dist/sqlite/index.js +7 -0
  121. package/dist/sqlite/index.js.map +1 -0
  122. package/dist/sqlite/internals.d.ts +63 -0
  123. package/dist/sqlite/internals.js +194 -0
  124. package/dist/sqlite/internals.js.map +1 -0
  125. package/dist/sqlite/options.d.ts +78 -0
  126. package/dist/sqlite/options.js +78 -0
  127. package/dist/sqlite/options.js.map +1 -0
  128. package/dist/sqlite/push.d.ts +9 -0
  129. package/dist/sqlite/push.js +272 -0
  130. package/dist/sqlite/push.js.map +1 -0
  131. package/dist/sqlite/query.d.ts +38 -0
  132. package/dist/sqlite/query.js +476 -0
  133. package/dist/sqlite/query.js.map +1 -0
  134. package/dist/sqlite/revocation.d.ts +28 -0
  135. package/dist/sqlite/revocation.js +337 -0
  136. package/dist/sqlite/revocation.js.map +1 -0
  137. package/dist/sqlite/sql.d.ts +60 -0
  138. package/dist/sqlite/sql.js +324 -0
  139. package/dist/sqlite/sql.js.map +1 -0
  140. package/dist/sqlite/store.d.ts +116 -0
  141. package/dist/sqlite/store.js +664 -0
  142. package/dist/sqlite/store.js.map +1 -0
  143. package/dist/sqlite/values.d.ts +29 -0
  144. package/dist/sqlite/values.js +288 -0
  145. package/dist/sqlite/values.js.map +1 -0
  146. package/dist/testing/index.d.ts +61 -0
  147. package/dist/testing/index.js +175 -0
  148. package/dist/testing/index.js.map +1 -0
  149. package/package.json +104 -0
@@ -0,0 +1,322 @@
1
+ // The store's data access over a G9SqliteDriver: the TypeScript twin of the C# helpers Exec / Scalar / Command and the
2
+ // native layer's multi-statement commands. SQL keeps the .NET store's `$name` parameters; they are rewritten to numbered
3
+ // `?N` placeholders (one number per name, so a name used twice binds once), and scripts are split into statements.
4
+ import { G9Long } from '../abstractions/long.js';
5
+ import { G9ELocalStoreFailure } from '../client/storeTypes.js';
6
+ import { splitSql } from './sql.js';
7
+ /** A SQLite failure raised by the store, classified for the engine (twin of `G9CSqliteException`). */
8
+ export class G9SqliteStoreError extends Error {
9
+ constructor(message, driverCode, sqliteCode, cause) {
10
+ super(message);
11
+ this.name = 'G9SqliteStoreError';
12
+ this.driverCode = driverCode;
13
+ this.sqliteCode = sqliteCode;
14
+ if (cause !== undefined)
15
+ Object.defineProperty(this, 'cause', { value: cause, enumerable: false, writable: true, configurable: true });
16
+ Object.setPrototypeOf(this, new.target.prototype);
17
+ }
18
+ /** ADR-0068: corrupt (11/26), full (13), busy/locked (5/6). */
19
+ get localStoreFailure() {
20
+ const code = this.sqliteCode !== null ? this.sqliteCode & 0xff : -1;
21
+ if (code === 11 || code === 26 || this.driverCode === 'corrupt')
22
+ return G9ELocalStoreFailure.Corrupt;
23
+ if (code === 13 || this.driverCode === 'full')
24
+ return G9ELocalStoreFailure.DiskFull;
25
+ if (code === 5 || code === 6 || this.driverCode === 'busy' || this.driverCode === 'locked')
26
+ return G9ELocalStoreFailure.Busy;
27
+ return G9ELocalStoreFailure.Other;
28
+ }
29
+ }
30
+ function wrap(error, sql) {
31
+ if (error instanceof G9SqliteStoreError)
32
+ return error;
33
+ const e = error;
34
+ if (e && typeof e === 'object' && (typeof e.code === 'string' || typeof e.sqliteCode === 'number')) {
35
+ const message = (typeof e.message === 'string' ? e.message : String(error)) + (sql ? ` [${sql.length > 160 ? sql.slice(0, 160) + '…' : sql}]` : '');
36
+ return new G9SqliteStoreError(message, typeof e.code === 'string' ? e.code : 'other', typeof e.sqliteCode === 'number' ? e.sqliteCode : null, error);
37
+ }
38
+ return error;
39
+ }
40
+ /** Converts a bind value to the driver's form. */
41
+ export function toSqlValue(value) {
42
+ if (value === undefined || value === null)
43
+ return null;
44
+ if (typeof value === 'boolean')
45
+ return value ? 1 : 0;
46
+ if (value instanceof G9Long)
47
+ return value.toSqlValue();
48
+ if (value instanceof Uint8Array) {
49
+ const copy = new Uint8Array(value.length);
50
+ copy.set(value);
51
+ return copy.buffer;
52
+ }
53
+ return value;
54
+ }
55
+ const compiled = new Map();
56
+ /** Splits a script and rewrites `$name` parameters (outside strings, identifiers and comments) to `?N`. */
57
+ export function compile(script) {
58
+ let entry = compiled.get(script);
59
+ if (entry)
60
+ return entry;
61
+ entry = { statements: splitSql(script).map(rewriteParameters) };
62
+ if (compiled.size > 2000)
63
+ compiled.clear();
64
+ compiled.set(script, entry);
65
+ return entry;
66
+ }
67
+ function rewriteParameters(sql) {
68
+ const names = [];
69
+ let out = '';
70
+ let i = 0;
71
+ const n = sql.length;
72
+ while (i < n) {
73
+ const c = sql.charAt(i);
74
+ if (c === "'" || c === '"') {
75
+ let j = i + 1;
76
+ while (j < n) {
77
+ if (sql.charAt(j) === c) {
78
+ if (sql.charAt(j + 1) === c)
79
+ j += 2;
80
+ else
81
+ break;
82
+ }
83
+ else
84
+ j++;
85
+ }
86
+ out += sql.slice(i, j + 1);
87
+ i = j + 1;
88
+ continue;
89
+ }
90
+ if (c === '[') {
91
+ const close = sql.indexOf(']', i + 1);
92
+ const end = close < 0 ? n : close + 1;
93
+ out += sql.slice(i, end);
94
+ i = end;
95
+ continue;
96
+ }
97
+ if (c === '$' && i + 1 < n && /[A-Za-z0-9_]/.test(sql.charAt(i + 1))) {
98
+ let j = i + 1;
99
+ while (j < n && /[A-Za-z0-9_]/.test(sql.charAt(j)))
100
+ j++;
101
+ const name = sql.slice(i, j);
102
+ let index = names.indexOf(name);
103
+ if (index < 0) {
104
+ names.push(name);
105
+ index = names.length - 1;
106
+ }
107
+ out += '?' + (index + 1);
108
+ i = j;
109
+ continue;
110
+ }
111
+ out += c;
112
+ i++;
113
+ }
114
+ return { sql: out, names };
115
+ }
116
+ /** Statements of a script with their parameters bound by name. */
117
+ export function statementsOf(script, params) {
118
+ const entry = compile(script);
119
+ return entry.statements.map((s) => ({
120
+ sql: s.sql,
121
+ params: s.names.map((name) => {
122
+ if (!params || !Object.prototype.hasOwnProperty.call(params, name))
123
+ throw new Error(`Must add a value for parameter '${name}'.`);
124
+ return toSqlValue(params[name]);
125
+ }),
126
+ }));
127
+ }
128
+ /** An async mutex (the SemaphoreSlim(1, 1) twin). */
129
+ export class G9AsyncLock {
130
+ constructor() {
131
+ this._tail = Promise.resolve();
132
+ }
133
+ async run(action) {
134
+ let release;
135
+ const next = new Promise((resolve) => {
136
+ release = resolve;
137
+ });
138
+ const previous = this._tail;
139
+ this._tail = previous.then(() => next);
140
+ await previous;
141
+ try {
142
+ return await action();
143
+ }
144
+ finally {
145
+ release();
146
+ }
147
+ }
148
+ }
149
+ /** One driver session (a "connection") with the store's helpers. `tx` is the open transaction, if any. */
150
+ export class G9SqliteConnection {
151
+ constructor(driver, session) {
152
+ this.tx = null;
153
+ this.driver = driver;
154
+ this.session = session;
155
+ }
156
+ /** Runs prepared driver statements in one bridge call. */
157
+ async runStatements(statements, signal) {
158
+ var _a;
159
+ if (statements.length === 0)
160
+ return [];
161
+ try {
162
+ return await this.driver.run(this.session, statements, this.tx ? { tx: this.tx, signal } : { signal });
163
+ }
164
+ catch (error) {
165
+ throw wrap(error, statements.length === 1 ? (_a = statements[0]) === null || _a === void 0 ? void 0 : _a.sql : undefined);
166
+ }
167
+ }
168
+ /** `ExecuteNonQuery`: the summed changes of every statement. */
169
+ async exec(script, params) {
170
+ const results = await this.runStatements(statementsOf(script, params));
171
+ let changes = 0;
172
+ for (const result of results)
173
+ changes += result.columns.length > 0 ? 0 : result.changes;
174
+ return changes;
175
+ }
176
+ /** Rows of the first row-producing statement (statements before it run first, like ExecuteReader). */
177
+ async query(script, params) {
178
+ const results = await this.runStatements(statementsOf(script, params));
179
+ for (const result of results)
180
+ if (result.columns.length > 0)
181
+ return result.rows;
182
+ return [];
183
+ }
184
+ /** First column of the first row, or null. */
185
+ async scalar(script, params) {
186
+ const rows = await this.query(script, params);
187
+ const row = rows[0];
188
+ return row && row.length > 0 ? row[0] : null;
189
+ }
190
+ /** `BEGIN IMMEDIATE` (or deferred) on this session. */
191
+ async begin(mode = 'immediate') {
192
+ if (this.tx)
193
+ throw new Error('A transaction is already open on this connection.');
194
+ try {
195
+ this.tx = await this.driver.begin(this.session, mode);
196
+ }
197
+ catch (error) {
198
+ throw wrap(error);
199
+ }
200
+ }
201
+ async commit() {
202
+ const tx = this.tx;
203
+ if (!tx)
204
+ throw new Error('No transaction is open.');
205
+ try {
206
+ await this.driver.commit(tx);
207
+ this.tx = null;
208
+ }
209
+ catch (error) {
210
+ throw wrap(error);
211
+ }
212
+ }
213
+ async rollback() {
214
+ const tx = this.tx;
215
+ if (!tx)
216
+ return;
217
+ this.tx = null;
218
+ try {
219
+ await this.driver.rollback(tx);
220
+ }
221
+ catch {
222
+ // SQLite may already have rolled back; the transaction is over either way.
223
+ }
224
+ }
225
+ /** Runs `action` in a transaction: committed when it returns, rolled back when it throws (the `using var transaction` pattern). */
226
+ async transaction(mode, action) {
227
+ await this.begin(mode);
228
+ try {
229
+ const result = await action();
230
+ if (this.tx)
231
+ await this.commit();
232
+ return result;
233
+ }
234
+ catch (error) {
235
+ await this.rollback();
236
+ throw error;
237
+ }
238
+ }
239
+ }
240
+ /** Collects statements and runs them in one driver call, handing each its result (the apply's batching). */
241
+ export class G9StatementBatch {
242
+ constructor(connection, limit = 1500) {
243
+ this._statements = [];
244
+ this._callbacks = [];
245
+ this._connection = connection;
246
+ this._limit = limit;
247
+ }
248
+ get count() {
249
+ return this._statements.length;
250
+ }
251
+ /**
252
+ * Queues a script's statements; `callback` receives their results (in order) once the batch has run. Returns true when
253
+ * the batch is full and should be flushed.
254
+ */
255
+ add(script, params, callback) {
256
+ const statements = statementsOf(script, params);
257
+ const index = this._statements.length;
258
+ for (const statement of statements)
259
+ this._statements.push(statement);
260
+ this._callbacks.push(callback ? { index, callback: (all) => callback(all.slice(index, index + statements.length)) } : null);
261
+ return this._statements.length >= this._limit;
262
+ }
263
+ /** Queues prepared statements. */
264
+ addStatements(statements, callback) {
265
+ const index = this._statements.length;
266
+ for (const statement of statements)
267
+ this._statements.push(statement);
268
+ this._callbacks.push(callback ? { index, callback: (all) => callback(all.slice(index, index + statements.length)) } : null);
269
+ return this._statements.length >= this._limit;
270
+ }
271
+ async flush(signal) {
272
+ if (this._statements.length === 0)
273
+ return;
274
+ const statements = this._statements.splice(0, this._statements.length);
275
+ const callbacks = this._callbacks.splice(0, this._callbacks.length);
276
+ const results = await this._connection.runStatements(statements, signal);
277
+ for (const entry of callbacks)
278
+ if (entry)
279
+ entry.callback(results);
280
+ }
281
+ }
282
+ /** Reads an INTEGER cell as a number (an int64 tag rounds; the store's counters are far below 2^53). */
283
+ export function asNumber(value) {
284
+ if (value === null || value === undefined)
285
+ return 0;
286
+ if (typeof value === 'number')
287
+ return value;
288
+ if (typeof value === 'string')
289
+ return Number(value);
290
+ if (value instanceof ArrayBuffer)
291
+ return 0;
292
+ return Number(value.int64);
293
+ }
294
+ /** Reads an INTEGER cell exactly. */
295
+ export function asLong(value) {
296
+ var _a;
297
+ if (value === null || value === undefined)
298
+ return G9Long.ZERO;
299
+ if (typeof value === 'number')
300
+ return G9Long.fromNumber(Math.trunc(value));
301
+ if (typeof value === 'string')
302
+ return (_a = G9Long.tryParse(value)) !== null && _a !== void 0 ? _a : G9Long.ZERO;
303
+ if (value instanceof ArrayBuffer)
304
+ return G9Long.ZERO;
305
+ return G9Long.parse(value.int64);
306
+ }
307
+ /** Reads a TEXT cell (`GetString`: SQLite's text form of a number, as JavaScript prints it). */
308
+ export function asString(value) {
309
+ if (value === null || value === undefined)
310
+ return '';
311
+ if (typeof value === 'string')
312
+ return value;
313
+ if (typeof value === 'number')
314
+ return String(value);
315
+ if (value instanceof ArrayBuffer)
316
+ return '';
317
+ return value.int64;
318
+ }
319
+ export function asOptionalString(value) {
320
+ return value === null || value === undefined ? null : asString(value);
321
+ }
322
+ //# sourceMappingURL=connection.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"connection.js","sourceRoot":"","sources":["../../src/sqlite/connection.ts"],"names":[],"mappings":"AAAA,uHAAuH;AACvH,yHAAyH;AACzH,mHAAmH;AACnH,OAAO,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAC;AACjD,OAAO,EAAE,oBAAoB,EAAgC,MAAM,yBAAyB,CAAC;AAE7F,OAAO,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AAOpC,sGAAsG;AACtG,MAAM,OAAO,kBAAmB,SAAQ,KAAK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CAAC,KAA6B;;IAClD,IAAI,KAAK,KAAK,IAAI,IAAI,KAAK,KAAK,SAAS;QAAE,OAAO,MAAM,CAAC,IAAI,CAAC;IAC9D,IAAI,OAAO,KAAK,KAAK,QAAQ;QAAE,OAAO,MAAM,CAAC,UAAU,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC;IAC3E,IAAI,OAAO,KAAK,KAAK,QAAQ;QAAE,OAAO,MAAA,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,mCAAI,MAAM,CAAC,IAAI,CAAC;IAC5E,IAAI,KAAK,YAAY,WAAW;QAAE,OAAO,MAAM,CAAC,IAAI,CAAC;IACrD,OAAO,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;AACnC,CAAC;AAED,gGAAgG;AAChG,MAAM,UAAU,QAAQ,CAAC,KAA6B;IACpD,IAAI,KAAK,KAAK,IAAI,IAAI,KAAK,KAAK,SAAS;QAAE,OAAO,EAAE,CAAC;IACrD,IAAI,OAAO,KAAK,KAAK,QAAQ;QAAE,OAAO,KAAK,CAAC;IAC5C,IAAI,OAAO,KAAK,KAAK,QAAQ;QAAE,OAAO,MAAM,CAAC,KAAK,CAAC,CAAC;IACpD,IAAI,KAAK,YAAY,WAAW;QAAE,OAAO,EAAE,CAAC;IAC5C,OAAO,KAAK,CAAC,KAAK,CAAC;AACrB,CAAC;AAED,MAAM,UAAU,gBAAgB,CAAC,KAA6B;IAC5D,OAAO,KAAK,KAAK,IAAI,IAAI,KAAK,KAAK,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;AACxE,CAAC","sourcesContent":["// The store's data access over a G9SqliteDriver: the TypeScript twin of the C# helpers Exec / Scalar / Command and the\n// native layer's multi-statement commands. SQL keeps the .NET store's `$name` parameters; they are rewritten to numbered\n// `?N` placeholders (one number per name, so a name used twice binds once), and scripts are split into statements.\nimport { G9Long } from '../abstractions/long.js';\nimport { G9ELocalStoreFailure, type G9SyncLocalStoreFailure } from '../client/storeTypes.js';\nimport type { G9DriverStatement, G9SessionToken, G9SqlResult, G9SqlValue, G9SqliteDriver, G9TxToken } from './driver.js';\nimport { splitSql } from './sql.js';\n\n/** A parameter value the store binds. */\nexport type G9BindValue = G9SqlValue | boolean | G9Long | Uint8Array | undefined;\n\nexport type G9Params = { [name: string]: G9BindValue };\n\n/** A SQLite failure raised by the store, classified for the engine (twin of `G9CSqliteException`). */\nexport class G9SqliteStoreError extends Error implements G9SyncLocalStoreFailure {\n /** The driver's error code (`busy`, `corrupt`, `full`, `constraint`, …). */\n readonly driverCode: string;\n /** SQLite's primary result code when the driver reported one. */\n readonly sqliteCode: number | null;\n\n constructor(message: string, driverCode: string, sqliteCode: number | null, cause?: unknown) {\n super(message);\n this.name = 'G9SqliteStoreError';\n this.driverCode = driverCode;\n this.sqliteCode = sqliteCode;\n if (cause !== undefined) Object.defineProperty(this, 'cause', { value: cause, enumerable: false, writable: true, configurable: true });\n Object.setPrototypeOf(this, new.target.prototype);\n }\n\n /** ADR-0068: corrupt (11/26), full (13), busy/locked (5/6). */\n get localStoreFailure(): G9ELocalStoreFailure {\n const code = this.sqliteCode !== null ? this.sqliteCode & 0xff : -1;\n if (code === 11 || code === 26 || this.driverCode === 'corrupt') return G9ELocalStoreFailure.Corrupt;\n if (code === 13 || this.driverCode === 'full') return G9ELocalStoreFailure.DiskFull;\n if (code === 5 || code === 6 || this.driverCode === 'busy' || this.driverCode === 'locked') return G9ELocalStoreFailure.Busy;\n return G9ELocalStoreFailure.Other;\n }\n}\n\nfunction wrap(error: unknown, sql?: string): unknown {\n if (error instanceof G9SqliteStoreError) return error;\n const e = error as { code?: unknown; sqliteCode?: unknown; message?: unknown; name?: unknown };\n if (e && typeof e === 'object' && (typeof e.code === 'string' || typeof e.sqliteCode === 'number')) {\n const message = (typeof e.message === 'string' ? e.message : String(error)) + (sql ? ` [${sql.length > 160 ? sql.slice(0, 160) + '…' : sql}]` : '');\n return new G9SqliteStoreError(message, typeof e.code === 'string' ? e.code : 'other', typeof e.sqliteCode === 'number' ? e.sqliteCode : null, error);\n }\n return error;\n}\n\n/** Converts a bind value to the driver's form. */\nexport function toSqlValue(value: G9BindValue): G9SqlValue {\n if (value === undefined || value === null) return null;\n if (typeof value === 'boolean') return value ? 1 : 0;\n if (value instanceof G9Long) return value.toSqlValue();\n if (value instanceof Uint8Array) {\n const copy = new Uint8Array(value.length);\n copy.set(value);\n return copy.buffer;\n }\n return value;\n}\n\ninterface Compiled {\n statements: { sql: string; names: string[] }[];\n}\n\nconst compiled = new Map<string, Compiled>();\n\n/** Splits a script and rewrites `$name` parameters (outside strings, identifiers and comments) to `?N`. */\nexport function compile(script: string): Compiled {\n let entry = compiled.get(script);\n if (entry) return entry;\n entry = { statements: splitSql(script).map(rewriteParameters) };\n if (compiled.size > 2000) compiled.clear();\n compiled.set(script, entry);\n return entry;\n}\n\nfunction rewriteParameters(sql: string): { sql: string; names: string[] } {\n const names: string[] = [];\n let out = '';\n let i = 0;\n const n = sql.length;\n while (i < n) {\n const c = sql.charAt(i);\n if (c === \"'\" || c === '\"') {\n let j = i + 1;\n while (j < n) {\n if (sql.charAt(j) === c) {\n if (sql.charAt(j + 1) === c) j += 2;\n else break;\n } else j++;\n }\n out += sql.slice(i, j + 1);\n i = j + 1;\n continue;\n }\n if (c === '[') {\n const close = sql.indexOf(']', i + 1);\n const end = close < 0 ? n : close + 1;\n out += sql.slice(i, end);\n i = end;\n continue;\n }\n if (c === '$' && i + 1 < n && /[A-Za-z0-9_]/.test(sql.charAt(i + 1))) {\n let j = i + 1;\n while (j < n && /[A-Za-z0-9_]/.test(sql.charAt(j))) j++;\n const name = sql.slice(i, j);\n let index = names.indexOf(name);\n if (index < 0) {\n names.push(name);\n index = names.length - 1;\n }\n out += '?' + (index + 1);\n i = j;\n continue;\n }\n out += c;\n i++;\n }\n return { sql: out, names };\n}\n\n/** Statements of a script with their parameters bound by name. */\nexport function statementsOf(script: string, params?: G9Params): G9DriverStatement[] {\n const entry = compile(script);\n return entry.statements.map((s) => ({\n sql: s.sql,\n params: s.names.map((name) => {\n if (!params || !Object.prototype.hasOwnProperty.call(params, name)) throw new Error(`Must add a value for parameter '${name}'.`);\n return toSqlValue(params[name]);\n }),\n }));\n}\n\n/** An async mutex (the SemaphoreSlim(1, 1) twin). */\nexport class G9AsyncLock {\n private _tail: Promise<void> = Promise.resolve();\n\n async run<T>(action: () => Promise<T>): Promise<T> {\n let release!: () => void;\n const next = new Promise<void>((resolve) => {\n release = resolve;\n });\n const previous = this._tail;\n this._tail = previous.then(() => next);\n await previous;\n try {\n return await action();\n } finally {\n release();\n }\n }\n}\n\n/** One driver session (a \"connection\") with the store's helpers. `tx` is the open transaction, if any. */\nexport class G9SqliteConnection {\n readonly driver: G9SqliteDriver;\n readonly session: G9SessionToken;\n tx: G9TxToken | null = null;\n\n constructor(driver: G9SqliteDriver, session: G9SessionToken) {\n this.driver = driver;\n this.session = session;\n }\n\n /** Runs prepared driver statements in one bridge call. */\n async runStatements(statements: readonly G9DriverStatement[], signal?: AbortSignal): Promise<G9SqlResult[]> {\n if (statements.length === 0) return [];\n try {\n return await this.driver.run(this.session, statements, this.tx ? { tx: this.tx, signal } : { signal });\n } catch (error) {\n throw wrap(error, statements.length === 1 ? statements[0]?.sql : undefined);\n }\n }\n\n /** `ExecuteNonQuery`: the summed changes of every statement. */\n async exec(script: string, params?: G9Params): Promise<number> {\n const results = await this.runStatements(statementsOf(script, params));\n let changes = 0;\n for (const result of results) changes += result.columns.length > 0 ? 0 : result.changes;\n return changes;\n }\n\n /** Rows of the first row-producing statement (statements before it run first, like ExecuteReader). */\n async query(script: string, params?: G9Params): Promise<(readonly G9SqlValue[])[]> {\n const results = await this.runStatements(statementsOf(script, params));\n for (const result of results) if (result.columns.length > 0) return result.rows as (readonly G9SqlValue[])[];\n return [];\n }\n\n /** First column of the first row, or null. */\n async scalar(script: string, params?: G9Params): Promise<G9SqlValue> {\n const rows = await this.query(script, params);\n const row = rows[0];\n return row && row.length > 0 ? (row[0] as G9SqlValue) : null;\n }\n\n /** `BEGIN IMMEDIATE` (or deferred) on this session. */\n async begin(mode: 'deferred' | 'immediate' = 'immediate'): Promise<void> {\n if (this.tx) throw new Error('A transaction is already open on this connection.');\n try {\n this.tx = await this.driver.begin(this.session, mode);\n } catch (error) {\n throw wrap(error);\n }\n }\n\n async commit(): Promise<void> {\n const tx = this.tx;\n if (!tx) throw new Error('No transaction is open.');\n try {\n await this.driver.commit(tx);\n this.tx = null;\n } catch (error) {\n throw wrap(error);\n }\n }\n\n async rollback(): Promise<void> {\n const tx = this.tx;\n if (!tx) return;\n this.tx = null;\n try {\n await this.driver.rollback(tx);\n } catch {\n // SQLite may already have rolled back; the transaction is over either way.\n }\n }\n\n /** Runs `action` in a transaction: committed when it returns, rolled back when it throws (the `using var transaction` pattern). */\n async transaction<T>(mode: 'deferred' | 'immediate', action: () => Promise<T>): Promise<T> {\n await this.begin(mode);\n try {\n const result = await action();\n if (this.tx) await this.commit();\n return result;\n } catch (error) {\n await this.rollback();\n throw error;\n }\n }\n}\n\n/** Collects statements and runs them in one driver call, handing each its result (the apply's batching). */\nexport class G9StatementBatch {\n private readonly _connection: G9SqliteConnection;\n private readonly _statements: G9DriverStatement[] = [];\n private readonly _callbacks: ({ index: number; callback: (results: G9SqlResult[]) => void } | null)[] = [];\n private readonly _limit: number;\n\n constructor(connection: G9SqliteConnection, limit = 1500) {\n this._connection = connection;\n this._limit = limit;\n }\n\n get count(): number {\n return this._statements.length;\n }\n\n /**\n * Queues a script's statements; `callback` receives their results (in order) once the batch has run. Returns true when\n * the batch is full and should be flushed.\n */\n add(script: string, params?: G9Params, callback?: (results: G9SqlResult[]) => void): boolean {\n const statements = statementsOf(script, params);\n const index = this._statements.length;\n for (const statement of statements) this._statements.push(statement);\n this._callbacks.push(callback ? { index, callback: (all) => callback(all.slice(index, index + statements.length)) } : null);\n return this._statements.length >= this._limit;\n }\n\n /** Queues prepared statements. */\n addStatements(statements: readonly G9DriverStatement[], callback?: (results: G9SqlResult[]) => void): boolean {\n const index = this._statements.length;\n for (const statement of statements) this._statements.push(statement);\n this._callbacks.push(callback ? { index, callback: (all) => callback(all.slice(index, index + statements.length)) } : null);\n return this._statements.length >= this._limit;\n }\n\n async flush(signal?: AbortSignal): Promise<void> {\n if (this._statements.length === 0) return;\n const statements = this._statements.splice(0, this._statements.length);\n const callbacks = this._callbacks.splice(0, this._callbacks.length);\n const results = await this._connection.runStatements(statements, signal);\n for (const entry of callbacks) if (entry) entry.callback(results);\n }\n}\n\n/** Reads an INTEGER cell as a number (an int64 tag rounds; the store's counters are far below 2^53). */\nexport function asNumber(value: G9SqlValue | undefined): number {\n if (value === null || value === undefined) return 0;\n if (typeof value === 'number') return value;\n if (typeof value === 'string') return Number(value);\n if (value instanceof ArrayBuffer) return 0;\n return Number(value.int64);\n}\n\n/** Reads an INTEGER cell exactly. */\nexport function asLong(value: G9SqlValue | undefined): G9Long {\n if (value === null || value === undefined) return G9Long.ZERO;\n if (typeof value === 'number') return G9Long.fromNumber(Math.trunc(value));\n if (typeof value === 'string') return G9Long.tryParse(value) ?? G9Long.ZERO;\n if (value instanceof ArrayBuffer) return G9Long.ZERO;\n return G9Long.parse(value.int64);\n}\n\n/** Reads a TEXT cell (`GetString`: SQLite's text form of a number, as JavaScript prints it). */\nexport function asString(value: G9SqlValue | undefined): string {\n if (value === null || value === undefined) return '';\n if (typeof value === 'string') return value;\n if (typeof value === 'number') return String(value);\n if (value instanceof ArrayBuffer) return '';\n return value.int64;\n}\n\nexport function asOptionalString(value: G9SqlValue | undefined): string | null {\n return value === null || value === undefined ? null : asString(value);\n}\n"]}
@@ -0,0 +1,63 @@
1
+ /** An int64 outside ±(2^53 − 1), tagged so it is never mistaken for text. */
2
+ export interface G9Int64Tag {
3
+ readonly int64: string;
4
+ }
5
+ /** A value crossing the driver boundary: null, a number, text, a BLOB (ArrayBuffer) or an int64 tag. */
6
+ export type G9SqlValue = null | number | string | ArrayBuffer | G9Int64Tag;
7
+ export interface G9DriverStatement {
8
+ readonly sql: string;
9
+ readonly params: readonly G9SqlValue[];
10
+ }
11
+ export interface G9SqlResult {
12
+ readonly columns: readonly string[];
13
+ readonly rows: readonly (readonly G9SqlValue[])[];
14
+ readonly changes: number;
15
+ readonly lastInsertRowId: G9SqlValue;
16
+ }
17
+ export type G9SessionToken = string & {
18
+ readonly __g9Session: true;
19
+ };
20
+ export type G9TxToken = string & {
21
+ readonly __g9Tx: true;
22
+ };
23
+ export interface G9ConnectionPragmas {
24
+ readonly journalMode?: 'wal' | 'delete' | 'truncate' | 'memory';
25
+ readonly busyTimeoutMs?: number;
26
+ readonly foreignKeys?: boolean;
27
+ readonly tempStore?: 'memory' | 'file' | 'default';
28
+ readonly cacheSize?: number;
29
+ readonly mmapSize?: number;
30
+ }
31
+ export interface G9OpenOptions {
32
+ readonly path: string;
33
+ readonly readOnly?: boolean;
34
+ readonly create?: boolean;
35
+ readonly durability?: 'full' | 'normal';
36
+ readonly pragmas?: G9ConnectionPragmas;
37
+ }
38
+ export interface G9RunOptions {
39
+ readonly tx?: G9TxToken;
40
+ readonly signal?: AbortSignal;
41
+ readonly maxRows?: number;
42
+ readonly atomic?: boolean;
43
+ }
44
+ export interface G9DriverCapabilities {
45
+ readonly sqliteVersion: string;
46
+ readonly maxVariables: number;
47
+ readonly json1: boolean;
48
+ readonly returning: boolean;
49
+ readonly upsert: boolean;
50
+ readonly interrupt: boolean;
51
+ }
52
+ export interface G9SqliteDriver {
53
+ readonly name: string;
54
+ capabilities(): Promise<G9DriverCapabilities>;
55
+ open(options: G9OpenOptions): Promise<G9SessionToken>;
56
+ run(session: G9SessionToken, statements: readonly G9DriverStatement[], options?: G9RunOptions): Promise<G9SqlResult[]>;
57
+ begin(session: G9SessionToken, mode: 'deferred' | 'immediate'): Promise<G9TxToken>;
58
+ commit(tx: G9TxToken): Promise<void>;
59
+ rollback(tx: G9TxToken): Promise<void>;
60
+ close(session: G9SessionToken): Promise<void>;
61
+ }
62
+ /** True for an `{ int64 }` tag. */
63
+ export declare function isInt64Tag(value: unknown): value is G9Int64Tag;
@@ -0,0 +1,9 @@
1
+ // The SQLite driver boundary, structurally identical to G9LynxControls' `G9SqliteDriver` (@g9lynx/sqlite,
2
+ // driver/types.ts): the Lynx native driver (Android androidx.sqlite bundled, iOS), the Lynxtron driver and the Node
3
+ // reference driver all satisfy it, and this package depends on none of them. One `run` = one bridge round trip for N
4
+ // statements, each statement ONE SQL statement with `?` placeholders.
5
+ /** True for an `{ int64 }` tag. */
6
+ export function isInt64Tag(value) {
7
+ return typeof value === 'object' && value !== null && !(value instanceof ArrayBuffer) && typeof value.int64 === 'string';
8
+ }
9
+ //# sourceMappingURL=driver.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"driver.js","sourceRoot":"","sources":["../../src/sqlite/driver.ts"],"names":[],"mappings":"AAAA,0GAA0G;AAC1G,oHAAoH;AACpH,qHAAqH;AACrH,sEAAsE;AAqEtE,mCAAmC;AACnC,MAAM,UAAU,UAAU,CAAC,KAAc;IACvC,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,IAAI,CAAC,CAAC,KAAK,YAAY,WAAW,CAAC,IAAI,OAAQ,KAA6B,CAAC,KAAK,KAAK,QAAQ,CAAC;AACpJ,CAAC","sourcesContent":["// The SQLite driver boundary, structurally identical to G9LynxControls' `G9SqliteDriver` (@g9lynx/sqlite,\n// driver/types.ts): the Lynx native driver (Android androidx.sqlite bundled, iOS), the Lynxtron driver and the Node\n// reference driver all satisfy it, and this package depends on none of them. One `run` = one bridge round trip for N\n// statements, each statement ONE SQL statement with `?` placeholders.\n\n/** An int64 outside ±(2^53 − 1), tagged so it is never mistaken for text. */\nexport interface G9Int64Tag {\n readonly int64: string;\n}\n\n/** A value crossing the driver boundary: null, a number, text, a BLOB (ArrayBuffer) or an int64 tag. */\nexport type G9SqlValue = null | number | string | ArrayBuffer | G9Int64Tag;\n\nexport interface G9DriverStatement {\n readonly sql: string;\n readonly params: readonly G9SqlValue[];\n}\n\nexport interface G9SqlResult {\n readonly columns: readonly string[];\n readonly rows: readonly (readonly G9SqlValue[])[];\n readonly changes: number;\n readonly lastInsertRowId: G9SqlValue;\n}\n\nexport type G9SessionToken = string & { readonly __g9Session: true };\nexport type G9TxToken = string & { readonly __g9Tx: true };\n\nexport interface G9ConnectionPragmas {\n readonly journalMode?: 'wal' | 'delete' | 'truncate' | 'memory';\n readonly busyTimeoutMs?: number;\n readonly foreignKeys?: boolean;\n readonly tempStore?: 'memory' | 'file' | 'default';\n readonly cacheSize?: number;\n readonly mmapSize?: number;\n}\n\nexport interface G9OpenOptions {\n readonly path: string;\n readonly readOnly?: boolean;\n readonly create?: boolean;\n readonly durability?: 'full' | 'normal';\n readonly pragmas?: G9ConnectionPragmas;\n}\n\nexport interface G9RunOptions {\n readonly tx?: G9TxToken;\n readonly signal?: AbortSignal;\n readonly maxRows?: number;\n readonly atomic?: boolean;\n}\n\nexport interface G9DriverCapabilities {\n readonly sqliteVersion: string;\n readonly maxVariables: number;\n readonly json1: boolean;\n readonly returning: boolean;\n readonly upsert: boolean;\n readonly interrupt: boolean;\n}\n\nexport interface G9SqliteDriver {\n readonly name: string;\n capabilities(): Promise<G9DriverCapabilities>;\n open(options: G9OpenOptions): Promise<G9SessionToken>;\n run(session: G9SessionToken, statements: readonly G9DriverStatement[], options?: G9RunOptions): Promise<G9SqlResult[]>;\n begin(session: G9SessionToken, mode: 'deferred' | 'immediate'): Promise<G9TxToken>;\n commit(tx: G9TxToken): Promise<void>;\n rollback(tx: G9TxToken): Promise<void>;\n close(session: G9SessionToken): Promise<void>;\n}\n\n/** True for an `{ int64 }` tag. */\nexport function isInt64Tag(value: unknown): value is G9Int64Tag {\n return typeof value === 'object' && value !== null && !(value instanceof ArrayBuffer) && typeof (value as { int64?: unknown }).int64 === 'string';\n}\n"]}
@@ -0,0 +1,6 @@
1
+ export { G9SqliteSyncStore, type G9PendingExport } from './store.js';
2
+ export { fileIncarnationMarker, type G9IncarnationMarker, type G9MarkerFileSystem, type G9SqliteSyncStoreOptions, type G9ResolvedSqliteStoreOptions, } from './options.js';
3
+ export { G9ESqliteDateTimeStorage, G9ESqliteDecimalStorage, splitSql } from './sql.js';
4
+ export { G9SqliteStoreError } from './connection.js';
5
+ export { formatTicks, formatDateTimeOffset, parseDateTime, parseDateTimeOffset, ticksOf, ticksToUnixMs } from './values.js';
6
+ export type { G9ConnectionPragmas, G9DriverCapabilities, G9DriverStatement, G9Int64Tag, G9OpenOptions, G9RunOptions, G9SessionToken, G9SqlResult, G9SqlValue, G9SqliteDriver, G9TxToken, } from './driver.js';
@@ -0,0 +1,7 @@
1
+ // @g9tm/syncdata/sqlite — the SQLite client store (twin of G9SyncData.Client.Sqlite) over the G9SqliteDriver contract.
2
+ export { G9SqliteSyncStore } from './store.js';
3
+ export { fileIncarnationMarker, } from './options.js';
4
+ export { G9ESqliteDateTimeStorage, G9ESqliteDecimalStorage, splitSql } from './sql.js';
5
+ export { G9SqliteStoreError } from './connection.js';
6
+ export { formatTicks, formatDateTimeOffset, parseDateTime, parseDateTimeOffset, ticksOf, ticksToUnixMs } from './values.js';
7
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/sqlite/index.ts"],"names":[],"mappings":"AAAA,uHAAuH;AACvH,OAAO,EAAE,iBAAiB,EAAwB,MAAM,YAAY,CAAC;AACrE,OAAO,EACL,qBAAqB,GAKtB,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,wBAAwB,EAAE,uBAAuB,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AACvF,OAAO,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAC;AACrD,OAAO,EAAE,WAAW,EAAE,oBAAoB,EAAE,aAAa,EAAE,mBAAmB,EAAE,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC","sourcesContent":["// @g9tm/syncdata/sqlite — the SQLite client store (twin of G9SyncData.Client.Sqlite) over the G9SqliteDriver contract.\nexport { G9SqliteSyncStore, type G9PendingExport } from './store.js';\nexport {\n fileIncarnationMarker,\n type G9IncarnationMarker,\n type G9MarkerFileSystem,\n type G9SqliteSyncStoreOptions,\n type G9ResolvedSqliteStoreOptions,\n} from './options.js';\nexport { G9ESqliteDateTimeStorage, G9ESqliteDecimalStorage, splitSql } from './sql.js';\nexport { G9SqliteStoreError } from './connection.js';\nexport { formatTicks, formatDateTimeOffset, parseDateTime, parseDateTimeOffset, ticksOf, ticksToUnixMs } from './values.js';\nexport type {\n G9ConnectionPragmas,\n G9DriverCapabilities,\n G9DriverStatement,\n G9Int64Tag,\n G9OpenOptions,\n G9RunOptions,\n G9SessionToken,\n G9SqlResult,\n G9SqlValue,\n G9SqliteDriver,\n G9TxToken,\n} from './driver.js';\n"]}
@@ -0,0 +1,63 @@
1
+ import { G9SyncException } from '../abstractions/errors.js';
2
+ import type { G9SyncClientModel, G9SyncClientTable } from '../client/model.js';
3
+ import type { G9SyncLogger, G9SyncLogLevel } from '../client/runs.js';
4
+ import { type G9SyncSubscriptionRecord } from '../client/storeTypes.js';
5
+ import type { G9DtNegotiatedTable } from '../protocol/dtos.js';
6
+ import { type G9AsyncLock, type G9SqliteConnection } from './connection.js';
7
+ import { type G9SqlValue } from './driver.js';
8
+ import type { G9ResolvedSqliteStoreOptions } from './options.js';
9
+ /** A table of the model with its local metadata (`LocalTable`). */
10
+ export declare class LocalTable {
11
+ readonly model: G9SyncClientTable;
12
+ readonly tid: number;
13
+ negotiated: G9DtNegotiatedTable | null;
14
+ syncedColumns: string[];
15
+ constructor(model: G9SyncClientTable, tid: number, negotiated: G9DtNegotiatedTable | null, syncedColumns: string[]);
16
+ get quoted(): string;
17
+ get keyQuoted(): string;
18
+ }
19
+ /** What the store's parts share. */
20
+ export interface StoreInternals {
21
+ readonly options: G9ResolvedSqliteStoreOptions;
22
+ readonly writeLock: G9AsyncLock;
23
+ /** The connection library writes go through (under the write lock). */
24
+ writer(): G9SqliteConnection;
25
+ /** A connection for reads that never wait on a running write. */
26
+ reader(): G9SqliteConnection;
27
+ ensureInitialized(): G9SyncClientModel;
28
+ byLocal: Map<string, LocalTable>;
29
+ byServerId: Map<number, LocalTable>;
30
+ log(level: G9SyncLogLevel, eventId: number, message: string, error?: unknown): void;
31
+ }
32
+ export declare function logTo(logger: G9SyncLogger | null, level: G9SyncLogLevel, eventId: number, message: string, error?: unknown): void;
33
+ export declare function nowMs(): number;
34
+ export declare function meta(connection: G9SqliteConnection, key: string): Promise<string | null>;
35
+ export declare function setMeta(connection: G9SqliteConnection, key: string, value: string | null): Promise<void>;
36
+ /** `KeyValue`: the key in the table's storage form (integers for an integer key). */
37
+ export declare function keyValue(table: LocalTable, canonicalKey: string): G9SqlValue;
38
+ export declare function getLocal(store: StoreInternals, localName: string): LocalTable;
39
+ export declare function findByServerName(store: StoreInternals, serverName: string): LocalTable | null;
40
+ export declare function byTid(store: StoreInternals, tid: number): LocalTable | null;
41
+ /** Reads subscriptions, all or one key, oldest first. */
42
+ export declare function readSubscriptions(connection: G9SqliteConnection, key: string | null): Promise<G9SyncSubscriptionRecord[]>;
43
+ /**
44
+ * JSON of a persisted DTO in the form .NET's source-generated context writes (camelCase, nulls omitted), so a database
45
+ * written by either side reads on the other.
46
+ */
47
+ export declare function persistedJson(value: unknown): string;
48
+ export declare function readPersistedNegotiated(json: string | null): G9DtNegotiatedTable | null;
49
+ export declare function readPersistedDefinitions(json: string | null): import("../protocol/dtos.js").G9DtSubscriptionDefinition[];
50
+ /** SQLite values as JSON (`SerializeValues`): text as strings, numbers as numbers, blobs as `{"$b64": "…"}`. */
51
+ export declare function serializeValues(values: {
52
+ [column: string]: unknown;
53
+ }): string;
54
+ /** `DeserializeValues`: numbers as integers when they are, int64 beyond 2^53 as tags, `{"$b64"}` as BLOBs. */
55
+ export declare function deserializeValues(json: string): {
56
+ [column: string]: G9SqlValue;
57
+ };
58
+ /** Reads every column of a local row (`ReadLocalValues`): column name → stored value; empty when the row is gone. */
59
+ export declare function readLocalValues(connection: G9SqliteConnection, table: LocalTable, key: string): Promise<{
60
+ [column: string]: G9SqlValue;
61
+ }>;
62
+ /** A store error that the engine maps to G9S-LOCAL-STORE. */
63
+ export declare function storeError(message: string): G9SyncException;