@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,143 @@
1
+ // UTF-8 without TextEncoder/TextDecoder: Lynx's background thread (PrimJS) has neither. The native codecs are used
2
+ // where they exist; the fallbacks follow the WHATWG encoder/decoder (lone surrogates become U+FFFD, invalid bytes
3
+ // decode to U+FFFD), so both paths produce the same bytes and text.
4
+ function nativeEncoder() {
5
+ try {
6
+ const ctor = globalThis.TextEncoder;
7
+ return typeof ctor === 'function' ? new ctor() : null;
8
+ }
9
+ catch {
10
+ return null;
11
+ }
12
+ }
13
+ function nativeDecoder() {
14
+ try {
15
+ const ctor = globalThis.TextDecoder;
16
+ return typeof ctor === 'function' ? new ctor('utf-8') : null;
17
+ }
18
+ catch {
19
+ return null;
20
+ }
21
+ }
22
+ const encoder = nativeEncoder();
23
+ const decoder = nativeDecoder();
24
+ /** UTF-8 bytes of `text`. */
25
+ export function utf8Encode(text) {
26
+ if (encoder)
27
+ return encoder.encode(text);
28
+ return utf8EncodeJs(text);
29
+ }
30
+ /** Text of UTF-8 `bytes`. */
31
+ export function utf8Decode(bytes) {
32
+ if (decoder)
33
+ return decoder.decode(bytes);
34
+ return utf8DecodeJs(bytes);
35
+ }
36
+ /** The pure-JS encoder (exported for tests; use {@link utf8Encode}). */
37
+ export function utf8EncodeJs(text) {
38
+ const out = new Uint8Array(text.length * 3);
39
+ let p = 0;
40
+ for (let i = 0; i < text.length; i++) {
41
+ let c = text.charCodeAt(i);
42
+ if (c < 0x80) {
43
+ out[p++] = c;
44
+ continue;
45
+ }
46
+ if (c < 0x800) {
47
+ out[p++] = 0xc0 | (c >> 6);
48
+ out[p++] = 0x80 | (c & 63);
49
+ continue;
50
+ }
51
+ if (c >= 0xd800 && c <= 0xdfff) {
52
+ const next = i + 1 < text.length ? text.charCodeAt(i + 1) : 0;
53
+ if (c <= 0xdbff && next >= 0xdc00 && next <= 0xdfff) {
54
+ c = 0x10000 + ((c - 0xd800) << 10) + (next - 0xdc00);
55
+ i++;
56
+ out[p++] = 0xf0 | (c >> 18);
57
+ out[p++] = 0x80 | ((c >> 12) & 63);
58
+ out[p++] = 0x80 | ((c >> 6) & 63);
59
+ out[p++] = 0x80 | (c & 63);
60
+ continue;
61
+ }
62
+ c = 0xfffd; // lone surrogate
63
+ }
64
+ out[p++] = 0xe0 | (c >> 12);
65
+ out[p++] = 0x80 | ((c >> 6) & 63);
66
+ out[p++] = 0x80 | (c & 63);
67
+ }
68
+ return out.slice(0, p);
69
+ }
70
+ /** The pure-JS decoder, the WHATWG UTF-8 decode algorithm (exported for tests; use {@link utf8Decode}). */
71
+ export function utf8DecodeJs(bytes) {
72
+ const parts = [];
73
+ let units = [];
74
+ const emit = (cp) => {
75
+ if (cp >= 0x10000) {
76
+ cp -= 0x10000;
77
+ units.push(0xd800 + (cp >> 10), 0xdc00 + (cp & 0x3ff));
78
+ }
79
+ else {
80
+ units.push(cp);
81
+ }
82
+ if (units.length >= 8192) {
83
+ parts.push(String.fromCharCode.apply(null, units));
84
+ units = [];
85
+ }
86
+ };
87
+ let codePoint = 0;
88
+ let needed = 0;
89
+ let seen = 0;
90
+ let lower = 0x80;
91
+ let upper = 0xbf;
92
+ for (let i = 0; i < bytes.length; i++) {
93
+ const b = bytes[i];
94
+ if (needed === 0) {
95
+ if (b <= 0x7f)
96
+ emit(b);
97
+ else if (b >= 0xc2 && b <= 0xdf) {
98
+ needed = 1;
99
+ codePoint = b & 0x1f;
100
+ }
101
+ else if (b >= 0xe0 && b <= 0xef) {
102
+ if (b === 0xe0)
103
+ lower = 0xa0;
104
+ if (b === 0xed)
105
+ upper = 0x9f;
106
+ needed = 2;
107
+ codePoint = b & 0x0f;
108
+ }
109
+ else if (b >= 0xf0 && b <= 0xf4) {
110
+ if (b === 0xf0)
111
+ lower = 0x90;
112
+ if (b === 0xf4)
113
+ upper = 0x8f;
114
+ needed = 3;
115
+ codePoint = b & 0x07;
116
+ }
117
+ else
118
+ emit(0xfffd);
119
+ continue;
120
+ }
121
+ if (b < lower || b > upper) {
122
+ // Not a valid continuation: the sequence so far is one error, and this byte is processed again on its own.
123
+ codePoint = needed = seen = 0;
124
+ lower = 0x80;
125
+ upper = 0xbf;
126
+ emit(0xfffd);
127
+ i--;
128
+ continue;
129
+ }
130
+ lower = 0x80;
131
+ upper = 0xbf;
132
+ codePoint = (codePoint << 6) | (b & 0x3f);
133
+ if (++seen === needed) {
134
+ emit(codePoint);
135
+ codePoint = needed = seen = 0;
136
+ }
137
+ }
138
+ if (needed !== 0)
139
+ emit(0xfffd);
140
+ parts.push(String.fromCharCode.apply(null, units));
141
+ return parts.join('');
142
+ }
143
+ //# sourceMappingURL=utf8.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utf8.js","sourceRoot":"","sources":["../../src/internal/utf8.ts"],"names":[],"mappings":"AAAA,mHAAmH;AACnH,kHAAkH;AAClH,oEAAo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CAAC;QACD,IAAI,CAAC,GAAG,KAAK,IAAI,CAAC,GAAG,KAAK,EAAE,CAAC;YAC3B,2GAA2G;YAC3G,SAAS,GAAG,MAAM,GAAG,IAAI,GAAG,CAAC,CAAC;YAC9B,KAAK,GAAG,IAAI,CAAC;YACb,KAAK,GAAG,IAAI,CAAC;YACb,IAAI,CAAC,MAAM,CAAC,CAAC;YACb,CAAC,EAAE,CAAC;YACJ,SAAS;QACX,CAAC;QACD,KAAK,GAAG,IAAI,CAAC;QACb,KAAK,GAAG,IAAI,CAAC;QACb,SAAS,GAAG,CAAC,SAAS,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC;QAC1C,IAAI,EAAE,IAAI,KAAK,MAAM,EAAE,CAAC;YACtB,IAAI,CAAC,SAAS,CAAC,CAAC;YAChB,SAAS,GAAG,MAAM,GAAG,IAAI,GAAG,CAAC,CAAC;QAChC,CAAC;IACH,CAAC;IACD,IAAI,MAAM,KAAK,CAAC;QAAE,IAAI,CAAC,MAAM,CAAC,CAAC;IAC/B,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,YAAY,CAAC,KAAK,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC,CAAC;IACnD,OAAO,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;AACxB,CAAC","sourcesContent":["// UTF-8 without TextEncoder/TextDecoder: Lynx's background thread (PrimJS) has neither. The native codecs are used\n// where they exist; the fallbacks follow the WHATWG encoder/decoder (lone surrogates become U+FFFD, invalid bytes\n// decode to U+FFFD), so both paths produce the same bytes and text.\n\ninterface Encoder {\n encode(text: string): Uint8Array;\n}\ninterface Decoder {\n decode(bytes: Uint8Array): string;\n}\n\nfunction nativeEncoder(): Encoder | null {\n try {\n const ctor = (globalThis as { TextEncoder?: new () => Encoder }).TextEncoder;\n return typeof ctor === 'function' ? new ctor() : null;\n } catch {\n return null;\n }\n}\n\nfunction nativeDecoder(): Decoder | null {\n try {\n const ctor = (globalThis as { TextDecoder?: new (label?: string) => Decoder }).TextDecoder;\n return typeof ctor === 'function' ? new ctor('utf-8') : null;\n } catch {\n return null;\n }\n}\n\nconst encoder = nativeEncoder();\nconst decoder = nativeDecoder();\n\n/** UTF-8 bytes of `text`. */\nexport function utf8Encode(text: string): Uint8Array {\n if (encoder) return encoder.encode(text);\n return utf8EncodeJs(text);\n}\n\n/** Text of UTF-8 `bytes`. */\nexport function utf8Decode(bytes: Uint8Array): string {\n if (decoder) return decoder.decode(bytes);\n return utf8DecodeJs(bytes);\n}\n\n/** The pure-JS encoder (exported for tests; use {@link utf8Encode}). */\nexport function utf8EncodeJs(text: string): Uint8Array {\n const out = new Uint8Array(text.length * 3);\n let p = 0;\n for (let i = 0; i < text.length; i++) {\n let c = text.charCodeAt(i);\n if (c < 0x80) {\n out[p++] = c;\n continue;\n }\n if (c < 0x800) {\n out[p++] = 0xc0 | (c >> 6);\n out[p++] = 0x80 | (c & 63);\n continue;\n }\n if (c >= 0xd800 && c <= 0xdfff) {\n const next = i + 1 < text.length ? text.charCodeAt(i + 1) : 0;\n if (c <= 0xdbff && next >= 0xdc00 && next <= 0xdfff) {\n c = 0x10000 + ((c - 0xd800) << 10) + (next - 0xdc00);\n i++;\n out[p++] = 0xf0 | (c >> 18);\n out[p++] = 0x80 | ((c >> 12) & 63);\n out[p++] = 0x80 | ((c >> 6) & 63);\n out[p++] = 0x80 | (c & 63);\n continue;\n }\n c = 0xfffd; // lone surrogate\n }\n out[p++] = 0xe0 | (c >> 12);\n out[p++] = 0x80 | ((c >> 6) & 63);\n out[p++] = 0x80 | (c & 63);\n }\n return out.slice(0, p);\n}\n\n/** The pure-JS decoder, the WHATWG UTF-8 decode algorithm (exported for tests; use {@link utf8Decode}). */\nexport function utf8DecodeJs(bytes: Uint8Array): string {\n const parts: string[] = [];\n let units: number[] = [];\n const emit = (cp: number): void => {\n if (cp >= 0x10000) {\n cp -= 0x10000;\n units.push(0xd800 + (cp >> 10), 0xdc00 + (cp & 0x3ff));\n } else {\n units.push(cp);\n }\n if (units.length >= 8192) {\n parts.push(String.fromCharCode.apply(null, units));\n units = [];\n }\n };\n\n let codePoint = 0;\n let needed = 0;\n let seen = 0;\n let lower = 0x80;\n let upper = 0xbf;\n for (let i = 0; i < bytes.length; i++) {\n const b = bytes[i]!;\n if (needed === 0) {\n if (b <= 0x7f) emit(b);\n else if (b >= 0xc2 && b <= 0xdf) {\n needed = 1;\n codePoint = b & 0x1f;\n } else if (b >= 0xe0 && b <= 0xef) {\n if (b === 0xe0) lower = 0xa0;\n if (b === 0xed) upper = 0x9f;\n needed = 2;\n codePoint = b & 0x0f;\n } else if (b >= 0xf0 && b <= 0xf4) {\n if (b === 0xf0) lower = 0x90;\n if (b === 0xf4) upper = 0x8f;\n needed = 3;\n codePoint = b & 0x07;\n } else emit(0xfffd);\n continue;\n }\n if (b < lower || b > upper) {\n // Not a valid continuation: the sequence so far is one error, and this byte is processed again on its own.\n codePoint = needed = seen = 0;\n lower = 0x80;\n upper = 0xbf;\n emit(0xfffd);\n i--;\n continue;\n }\n lower = 0x80;\n upper = 0xbf;\n codePoint = (codePoint << 6) | (b & 0x3f);\n if (++seen === needed) {\n emit(codePoint);\n codePoint = needed = seen = 0;\n }\n }\n if (needed !== 0) emit(0xfffd);\n parts.push(String.fromCharCode.apply(null, units));\n return parts.join('');\n}\n"]}
@@ -0,0 +1,9 @@
1
+ import { type G9FrameDecompressor } from '../protocol/rowBatch/reader.js';
2
+ import type { G9FrameCompressor } from '../protocol/rowBatch/writer.js';
3
+ export { nodeSqliteDriver, G9NodeSqliteError } from './sqliteDriver.js';
4
+ /** A frame decompressor over node:zlib. */
5
+ export declare function nodeBrotliDecompressor(): G9FrameDecompressor;
6
+ /** A push-frame compressor over node:zlib. */
7
+ export declare function nodeBrotliCompressor(): G9FrameCompressor;
8
+ /** Makes node:zlib the process-wide frame decompressor (setDefaultFrameDecompressor). */
9
+ export declare function useNodeBrotli(): G9FrameDecompressor;
@@ -0,0 +1,35 @@
1
+ /// <reference types="node" />
2
+ // @g9tm/syncdata/node — Node helpers: the node:sqlite reference driver and Brotli through node:zlib (the same
3
+ // quality 4 / window 22 the .NET writer uses).
4
+ import { brotliCompressSync, brotliDecompressSync, constants } from 'node:zlib';
5
+ import { setDefaultFrameDecompressor } from '../protocol/rowBatch/reader.js';
6
+ export { nodeSqliteDriver, G9NodeSqliteError } from './sqliteDriver.js';
7
+ /** A frame decompressor over node:zlib. */
8
+ export function nodeBrotliDecompressor() {
9
+ return {
10
+ decompress(compressed, expectedLength) {
11
+ const out = brotliDecompressSync(compressed, { maxOutputLength: Math.max(1, expectedLength + 1) });
12
+ if (out.length !== expectedLength)
13
+ throw new Error(`Brotli body decoded to ${out.length} bytes, ${expectedLength} expected.`);
14
+ return new Uint8Array(out.buffer, out.byteOffset, out.length);
15
+ },
16
+ };
17
+ }
18
+ /** A push-frame compressor over node:zlib. */
19
+ export function nodeBrotliCompressor() {
20
+ return {
21
+ compress(body, quality, window) {
22
+ const out = brotliCompressSync(body, {
23
+ params: { [constants.BROTLI_PARAM_QUALITY]: quality, [constants.BROTLI_PARAM_LGWIN]: window, [constants.BROTLI_PARAM_SIZE_HINT]: body.length },
24
+ });
25
+ return new Uint8Array(out.buffer, out.byteOffset, out.length);
26
+ },
27
+ };
28
+ }
29
+ /** Makes node:zlib the process-wide frame decompressor (setDefaultFrameDecompressor). */
30
+ export function useNodeBrotli() {
31
+ const decompressor = nodeBrotliDecompressor();
32
+ setDefaultFrameDecompressor(decompressor);
33
+ return decompressor;
34
+ }
35
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/node/index.ts"],"names":[],"mappings":"AAAA,8BAA8B;AAC9B,8GAA8G;AAC9G,+CAA+C;AAC/C,OAAO,EAAE,kBAAkB,EAAE,oBAAoB,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAChF,OAAO,EAAE,2BAA2B,EAA4B,MAAM,gCAAgC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,CAAC;AACtB,CAAC","sourcesContent":["/// <reference types=\"node\" />\n// @g9tm/syncdata/node — Node helpers: the node:sqlite reference driver and Brotli through node:zlib (the same\n// quality 4 / window 22 the .NET writer uses).\nimport { brotliCompressSync, brotliDecompressSync, constants } from 'node:zlib';\nimport { setDefaultFrameDecompressor, type G9FrameDecompressor } from '../protocol/rowBatch/reader.js';\nimport type { G9FrameCompressor } from '../protocol/rowBatch/writer.js';\n\nexport { nodeSqliteDriver, G9NodeSqliteError } from './sqliteDriver.js';\n\n/** A frame decompressor over node:zlib. */\nexport function nodeBrotliDecompressor(): G9FrameDecompressor {\n return {\n decompress(compressed: Uint8Array, expectedLength: number): Uint8Array {\n const out = brotliDecompressSync(compressed, { maxOutputLength: Math.max(1, expectedLength + 1) });\n if (out.length !== expectedLength) throw new Error(`Brotli body decoded to ${out.length} bytes, ${expectedLength} expected.`);\n return new Uint8Array(out.buffer, out.byteOffset, out.length);\n },\n };\n}\n\n/** A push-frame compressor over node:zlib. */\nexport function nodeBrotliCompressor(): G9FrameCompressor {\n return {\n compress(body: Uint8Array, quality: number, window: number): Uint8Array {\n const out = brotliCompressSync(body, {\n params: { [constants.BROTLI_PARAM_QUALITY]: quality, [constants.BROTLI_PARAM_LGWIN]: window, [constants.BROTLI_PARAM_SIZE_HINT]: body.length },\n });\n return new Uint8Array(out.buffer, out.byteOffset, out.length);\n },\n };\n}\n\n/** Makes node:zlib the process-wide frame decompressor (setDefaultFrameDecompressor). */\nexport function useNodeBrotli(): G9FrameDecompressor {\n const decompressor = nodeBrotliDecompressor();\n setDefaultFrameDecompressor(decompressor);\n return decompressor;\n}\n"]}
@@ -0,0 +1,11 @@
1
+ import type { G9SqliteDriver } from '../sqlite/driver.js';
2
+ /** A driver error with the shape the store classifies (`code` + SQLite's `sqliteCode`). */
3
+ export declare class G9NodeSqliteError extends Error {
4
+ readonly code: string;
5
+ readonly sqliteCode: number | undefined;
6
+ constructor(code: string, message: string, sqliteCode?: number, cause?: unknown);
7
+ }
8
+ /** The node:sqlite G9SqliteDriver (tests, tools, Node hosts). */
9
+ export declare function nodeSqliteDriver(options?: {
10
+ name?: string;
11
+ }): G9SqliteDriver;
@@ -0,0 +1,252 @@
1
+ /// <reference types="node" />
2
+ // The Node reference G9SqliteDriver over node:sqlite (Node ≥ 22.13), structurally the driver G9LynxControls tests its
3
+ // SQL against (@g9lynx/testing createNodeTestDriver). Safe integers bind as INTEGER (node binds a plain number as REAL),
4
+ // int64 beyond 2^53 travels as `{ int64 }` tags, BLOBs as ArrayBuffers. Node only.
5
+ import { existsSync, mkdirSync } from 'node:fs';
6
+ import { dirname } from 'node:path';
7
+ import { DatabaseSync } from 'node:sqlite';
8
+ /** A driver error with the shape the store classifies (`code` + SQLite's `sqliteCode`). */
9
+ export class G9NodeSqliteError extends Error {
10
+ constructor(code, message, sqliteCode, cause) {
11
+ super(message);
12
+ this.name = 'G9SqliteError';
13
+ this.code = code;
14
+ this.sqliteCode = sqliteCode;
15
+ if (cause !== undefined)
16
+ Object.defineProperty(this, 'cause', { value: cause, enumerable: false, writable: true, configurable: true });
17
+ }
18
+ }
19
+ function codeFor(resultCode) {
20
+ switch (resultCode & 0xff) {
21
+ case 5:
22
+ return 'busy';
23
+ case 6:
24
+ return 'locked';
25
+ case 19:
26
+ return 'constraint';
27
+ case 11:
28
+ case 26:
29
+ return 'corrupt';
30
+ case 8:
31
+ return 'readonly';
32
+ case 13:
33
+ return 'full';
34
+ case 9:
35
+ return 'interrupted';
36
+ case 21:
37
+ return 'misuse';
38
+ case 14:
39
+ return 'not-found';
40
+ default:
41
+ return 'other';
42
+ }
43
+ }
44
+ function toError(error, sql) {
45
+ var _a;
46
+ if (error instanceof G9NodeSqliteError)
47
+ return error;
48
+ const e = error;
49
+ const sqliteCode = typeof (e === null || e === void 0 ? void 0 : e.errcode) === 'number' ? e.errcode : undefined;
50
+ return new G9NodeSqliteError(sqliteCode !== undefined ? codeFor(sqliteCode) : 'misuse', ((_a = e === null || e === void 0 ? void 0 : e.message) !== null && _a !== void 0 ? _a : String(error)) + (sql ? ` [${sql}]` : ''), sqliteCode, error);
51
+ }
52
+ function bind(value) {
53
+ if (value === null || typeof value === 'string')
54
+ return value;
55
+ if (typeof value === 'number') {
56
+ if (Number.isNaN(value))
57
+ throw new G9NodeSqliteError('misuse', 'NaN is not a SQL value.');
58
+ return Number.isSafeInteger(value) ? BigInt(value) : value;
59
+ }
60
+ if (value instanceof ArrayBuffer)
61
+ return value.byteLength === 0 ? new Uint8Array(0) : new Uint8Array(value);
62
+ if (typeof value === 'object' && typeof value.int64 === 'string')
63
+ return BigInt(value.int64);
64
+ throw new G9NodeSqliteError('misuse', `Not a G9SqlValue (${typeof value}).`);
65
+ }
66
+ function read(value) {
67
+ if (typeof value === 'bigint') {
68
+ const n = Number(value);
69
+ return Number.isSafeInteger(n) ? n : { int64: value.toString() };
70
+ }
71
+ if (ArrayBuffer.isView(value)) {
72
+ const copy = new Uint8Array(value.byteLength);
73
+ copy.set(new Uint8Array(value.buffer, value.byteOffset, value.byteLength));
74
+ return copy.buffer;
75
+ }
76
+ return value;
77
+ }
78
+ let seed = 0;
79
+ /** The node:sqlite G9SqliteDriver (tests, tools, Node hosts). */
80
+ export function nodeSqliteDriver(options = {}) {
81
+ var _a;
82
+ const sessions = new Map();
83
+ const owners = new Map();
84
+ const session = (token) => {
85
+ const s = sessions.get(token);
86
+ if (!s)
87
+ throw new G9NodeSqliteError('misuse', 'The database session is closed or unknown.');
88
+ return s;
89
+ };
90
+ const prepare = (s, sql) => {
91
+ let statement = s.statements.get(sql);
92
+ if (!statement) {
93
+ statement = s.db.prepare(sql);
94
+ statement.setReadBigInts(true);
95
+ statement.setReturnArrays(true);
96
+ if (s.statements.size > 500)
97
+ s.statements.clear();
98
+ s.statements.set(sql, statement);
99
+ }
100
+ return statement;
101
+ };
102
+ const execute = (s, statement, maxRows) => {
103
+ const prepared = prepare(s, statement.sql);
104
+ const args = statement.params.map(bind);
105
+ const columns = prepared.columns().map((c) => c.name);
106
+ if (columns.length > 0) {
107
+ const rows = [];
108
+ for (const row of prepared.iterate(...args)) {
109
+ if (maxRows !== undefined && rows.length >= maxRows)
110
+ throw new G9NodeSqliteError('too-many-rows', `More than ${maxRows} rows.`);
111
+ rows.push(row.map(read));
112
+ }
113
+ return { columns, rows, changes: 0, lastInsertRowId: s.lastInsertRowId };
114
+ }
115
+ const result = prepared.run(...args);
116
+ s.lastInsertRowId = read(result.lastInsertRowid);
117
+ return { columns: [], rows: [], changes: Number(result.changes), lastInsertRowId: s.lastInsertRowId };
118
+ };
119
+ return {
120
+ name: (_a = options.name) !== null && _a !== void 0 ? _a : 'node-sqlite',
121
+ async capabilities() {
122
+ const db = new DatabaseSync(':memory:');
123
+ try {
124
+ const row = db.prepare('SELECT sqlite_version() AS v').get();
125
+ return { sqliteVersion: row.v, maxVariables: 32766, json1: true, returning: true, upsert: true, interrupt: false };
126
+ }
127
+ finally {
128
+ db.close();
129
+ }
130
+ },
131
+ async open(open) {
132
+ var _a;
133
+ const memory = open.path === ':memory:' || open.path === '';
134
+ if (!memory && !open.create && !existsSync(open.path))
135
+ throw new G9NodeSqliteError('not-found', `Database file does not exist: ${open.path}`);
136
+ if (!memory && open.create)
137
+ mkdirSync(dirname(open.path), { recursive: true });
138
+ let db;
139
+ try {
140
+ db = new DatabaseSync(open.path || ':memory:', { readOnly: open.readOnly === true });
141
+ }
142
+ catch (error) {
143
+ throw toError(error);
144
+ }
145
+ const pragmas = (_a = open.pragmas) !== null && _a !== void 0 ? _a : {};
146
+ try {
147
+ if (pragmas.journalMode)
148
+ db.exec(`PRAGMA journal_mode=${pragmas.journalMode.toUpperCase()}`);
149
+ db.exec(`PRAGMA synchronous=${open.durability === 'normal' ? 'NORMAL' : 'FULL'}`);
150
+ if (pragmas.busyTimeoutMs !== undefined)
151
+ db.exec(`PRAGMA busy_timeout=${Math.max(0, Math.floor(pragmas.busyTimeoutMs))}`);
152
+ if (pragmas.foreignKeys !== undefined)
153
+ db.exec(`PRAGMA foreign_keys=${pragmas.foreignKeys ? 'ON' : 'OFF'}`);
154
+ }
155
+ catch (error) {
156
+ db.close();
157
+ throw toError(error);
158
+ }
159
+ const token = `node-session-${++seed}`;
160
+ sessions.set(token, { token, db, statements: new Map(), tx: null, lastInsertRowId: 0 });
161
+ return token;
162
+ },
163
+ async run(token, statements, run = {}) {
164
+ var _a;
165
+ const s = session(token);
166
+ if (run.tx !== undefined && s.tx !== run.tx)
167
+ throw new G9NodeSqliteError('misuse', 'The transaction is finished or belongs to another session.');
168
+ if (run.tx === undefined && s.tx !== null)
169
+ throw new G9NodeSqliteError('misuse', 'A transaction is open on this session; pass its token (tx).');
170
+ if ((_a = run.signal) === null || _a === void 0 ? void 0 : _a.aborted)
171
+ throw new G9NodeSqliteError('cancelled', 'Cancelled before the batch started.');
172
+ const atomic = run.atomic === true && run.tx === undefined && statements.length > 0;
173
+ if (atomic)
174
+ s.db.exec('BEGIN');
175
+ const results = [];
176
+ try {
177
+ for (const statement of statements) {
178
+ try {
179
+ results.push(execute(s, statement, run.maxRows));
180
+ }
181
+ catch (error) {
182
+ throw toError(error, statement.sql);
183
+ }
184
+ }
185
+ if (atomic)
186
+ s.db.exec('COMMIT');
187
+ }
188
+ catch (error) {
189
+ if (atomic) {
190
+ try {
191
+ s.db.exec('ROLLBACK');
192
+ }
193
+ catch {
194
+ // already rolled back
195
+ }
196
+ }
197
+ throw toError(error);
198
+ }
199
+ return results;
200
+ },
201
+ async begin(token, mode) {
202
+ const s = session(token);
203
+ if (s.tx !== null)
204
+ throw new G9NodeSqliteError('misuse', 'A transaction is already open on this session.');
205
+ try {
206
+ s.db.exec(mode === 'immediate' ? 'BEGIN IMMEDIATE' : 'BEGIN DEFERRED');
207
+ }
208
+ catch (error) {
209
+ throw toError(error);
210
+ }
211
+ const tx = `node-tx-${++seed}`;
212
+ s.tx = tx;
213
+ owners.set(tx, s);
214
+ return tx;
215
+ },
216
+ async commit(tx) {
217
+ const s = owners.get(tx);
218
+ if (!s || s.tx !== tx)
219
+ throw new G9NodeSqliteError('misuse', 'The transaction is finished or unknown.');
220
+ try {
221
+ s.db.exec('COMMIT');
222
+ }
223
+ catch (error) {
224
+ throw toError(error);
225
+ }
226
+ s.tx = null;
227
+ owners.delete(tx);
228
+ },
229
+ async rollback(tx) {
230
+ const s = owners.get(tx);
231
+ if (!s || s.tx !== tx)
232
+ throw new G9NodeSqliteError('misuse', 'The transaction is finished or unknown.');
233
+ s.tx = null;
234
+ owners.delete(tx);
235
+ try {
236
+ s.db.exec('ROLLBACK');
237
+ }
238
+ catch {
239
+ // SQLite may already have rolled back
240
+ }
241
+ },
242
+ async close(token) {
243
+ const s = session(token);
244
+ sessions.delete(token);
245
+ if (s.tx)
246
+ owners.delete(s.tx);
247
+ s.statements.clear();
248
+ s.db.close();
249
+ },
250
+ };
251
+ }
252
+ //# sourceMappingURL=sqliteDriver.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sqliteDriver.js","sourceRoot":"","sources":["../../src/node/sqliteDriver.ts"],"names":[],"mappings":"AAAA,8BAA8B;AAC9B,sHAAsH;AACtH,yHAAyH;AACzH,mFAAmF;AACnF,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAChD,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,YAAY,EAAsB,MAAM,aAAa,CAAC;AAqB/D,2FAA2F;AAC3F,MAAM,OAAO,iBAAkB,SAAQ,KAAK;IAI1C,YAAY,IAAY,EAAE,OAAe,EAAE,UAAmB,EAAE,KAAe;QAC7E,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,eAAe,CAAC;QAC5B,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;QAC7B,IAAI,KAAK,KAAK,SAAS;YAAE,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,OAAO,EAAE,EAAE,KAAK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AQ,CAAC,CAAC;YACtB,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBACf,MAAM,OAAO,CAAC,KAAK,CAAC,CAAC;YACvB,CAAC;YACD,CAAC,CAAC,EAAE,GAAG,IAAI,CAAC;YACZ,MAAM,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;QACpB,CAAC;QAED,KAAK,CAAC,QAAQ,CAAC,EAAa;YAC1B,MAAM,CAAC,GAAG,MAAM,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;YACzB,IAAI,CAAC,CAAC,IAAI,CAAC,CAAC,EAAE,KAAK,EAAE;gBAAE,MAAM,IAAI,iBAAiB,CAAC,QAAQ,EAAE,yCAAyC,CAAC,CAAC;YACxG,CAAC,CAAC,EAAE,GAAG,IAAI,CAAC;YACZ,MAAM,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;YAClB,IAAI,CAAC;gBACH,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;YACxB,CAAC;YAAC,MAAM,CAAC;gBACP,sCAAsC;YACxC,CAAC;QACH,CAAC;QAED,KAAK,CAAC,KAAK,CAAC,KAAqB;YAC/B,MAAM,CAAC,GAAG,OAAO,CAAC,KAAK,CAAC,CAAC;YACzB,QAAQ,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;YACvB,IAAI,CAAC,CAAC,EAAE;gBAAE,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;YAC9B,CAAC,CAAC,UAAU,CAAC,KAAK,EAAE,CAAC;YACrB,CAAC,CAAC,EAAE,CAAC,KAAK,EAAE,CAAC;QACf,CAAC;KACF,CAAC;AACJ,CAAC","sourcesContent":["/// <reference types=\"node\" />\n// The Node reference G9SqliteDriver over node:sqlite (Node ≥ 22.13), structurally the driver G9LynxControls tests its\n// SQL against (@g9lynx/testing createNodeTestDriver). Safe integers bind as INTEGER (node binds a plain number as REAL),\n// int64 beyond 2^53 travels as `{ int64 }` tags, BLOBs as ArrayBuffers. Node only.\nimport { existsSync, mkdirSync } from 'node:fs';\nimport { dirname } from 'node:path';\nimport { DatabaseSync, type StatementSync } from 'node:sqlite';\nimport type {\n G9DriverCapabilities,\n G9DriverStatement,\n G9OpenOptions,\n G9RunOptions,\n G9SessionToken,\n G9SqlResult,\n G9SqlValue,\n G9SqliteDriver,\n G9TxToken,\n} from '../sqlite/driver.js';\n\ninterface Session {\n readonly token: G9SessionToken;\n readonly db: DatabaseSync;\n readonly statements: Map<string, StatementSync>;\n tx: G9TxToken | null;\n lastInsertRowId: G9SqlValue;\n}\n\n/** A driver error with the shape the store classifies (`code` + SQLite's `sqliteCode`). */\nexport class G9NodeSqliteError extends Error {\n readonly code: string;\n readonly sqliteCode: number | undefined;\n\n constructor(code: string, message: string, sqliteCode?: number, cause?: unknown) {\n super(message);\n this.name = 'G9SqliteError';\n this.code = code;\n this.sqliteCode = sqliteCode;\n if (cause !== undefined) Object.defineProperty(this, 'cause', { value: cause, enumerable: false, writable: true, configurable: true });\n }\n}\n\nfunction codeFor(resultCode: number): string {\n switch (resultCode & 0xff) {\n case 5:\n return 'busy';\n case 6:\n return 'locked';\n case 19:\n return 'constraint';\n case 11:\n case 26:\n return 'corrupt';\n case 8:\n return 'readonly';\n case 13:\n return 'full';\n case 9:\n return 'interrupted';\n case 21:\n return 'misuse';\n case 14:\n return 'not-found';\n default:\n return 'other';\n }\n}\n\nfunction toError(error: unknown, sql?: string): G9NodeSqliteError {\n if (error instanceof G9NodeSqliteError) return error;\n const e = error as { errcode?: number; message?: string };\n const sqliteCode = typeof e?.errcode === 'number' ? e.errcode : undefined;\n return new G9NodeSqliteError(sqliteCode !== undefined ? codeFor(sqliteCode) : 'misuse', (e?.message ?? String(error)) + (sql ? ` [${sql}]` : ''), sqliteCode, error);\n}\n\nfunction bind(value: G9SqlValue): null | number | bigint | string | Uint8Array {\n if (value === null || typeof value === 'string') return value;\n if (typeof value === 'number') {\n if (Number.isNaN(value)) throw new G9NodeSqliteError('misuse', 'NaN is not a SQL value.');\n return Number.isSafeInteger(value) ? BigInt(value) : value;\n }\n if (value instanceof ArrayBuffer) return value.byteLength === 0 ? new Uint8Array(0) : new Uint8Array(value);\n if (typeof value === 'object' && typeof (value as { int64?: unknown }).int64 === 'string') return BigInt((value as { int64: string }).int64);\n throw new G9NodeSqliteError('misuse', `Not a G9SqlValue (${typeof value}).`);\n}\n\nfunction read(value: unknown): G9SqlValue {\n if (typeof value === 'bigint') {\n const n = Number(value);\n return Number.isSafeInteger(n) ? n : { int64: value.toString() };\n }\n if (ArrayBuffer.isView(value)) {\n const copy = new Uint8Array(value.byteLength);\n copy.set(new Uint8Array(value.buffer, value.byteOffset, value.byteLength));\n return copy.buffer;\n }\n return value as G9SqlValue;\n}\n\nlet seed = 0;\n\n/** The node:sqlite G9SqliteDriver (tests, tools, Node hosts). */\nexport function nodeSqliteDriver(options: { name?: string } = {}): G9SqliteDriver {\n const sessions = new Map<string, Session>();\n const owners = new Map<string, Session>();\n\n const session = (token: G9SessionToken): Session => {\n const s = sessions.get(token);\n if (!s) throw new G9NodeSqliteError('misuse', 'The database session is closed or unknown.');\n return s;\n };\n\n const prepare = (s: Session, sql: string): StatementSync => {\n let statement = s.statements.get(sql);\n if (!statement) {\n statement = s.db.prepare(sql);\n statement.setReadBigInts(true);\n statement.setReturnArrays(true);\n if (s.statements.size > 500) s.statements.clear();\n s.statements.set(sql, statement);\n }\n return statement;\n };\n\n const execute = (s: Session, statement: G9DriverStatement, maxRows: number | undefined): G9SqlResult => {\n const prepared = prepare(s, statement.sql);\n const args = statement.params.map(bind);\n const columns = prepared.columns().map((c) => c.name);\n if (columns.length > 0) {\n const rows: G9SqlValue[][] = [];\n for (const row of prepared.iterate(...args) as Iterable<unknown[]>) {\n if (maxRows !== undefined && rows.length >= maxRows) throw new G9NodeSqliteError('too-many-rows', `More than ${maxRows} rows.`);\n rows.push(row.map(read));\n }\n return { columns, rows, changes: 0, lastInsertRowId: s.lastInsertRowId };\n }\n const result = prepared.run(...args);\n s.lastInsertRowId = read(result.lastInsertRowid);\n return { columns: [], rows: [], changes: Number(result.changes), lastInsertRowId: s.lastInsertRowId };\n };\n\n return {\n name: options.name ?? 'node-sqlite',\n\n async capabilities(): Promise<G9DriverCapabilities> {\n const db = new DatabaseSync(':memory:');\n try {\n const row = db.prepare('SELECT sqlite_version() AS v').get() as { v: string };\n return { sqliteVersion: row.v, maxVariables: 32766, json1: true, returning: true, upsert: true, interrupt: false };\n } finally {\n db.close();\n }\n },\n\n async open(open: G9OpenOptions): Promise<G9SessionToken> {\n const memory = open.path === ':memory:' || open.path === '';\n if (!memory && !open.create && !existsSync(open.path)) throw new G9NodeSqliteError('not-found', `Database file does not exist: ${open.path}`);\n if (!memory && open.create) mkdirSync(dirname(open.path), { recursive: true });\n let db: DatabaseSync;\n try {\n db = new DatabaseSync(open.path || ':memory:', { readOnly: open.readOnly === true });\n } catch (error) {\n throw toError(error);\n }\n const pragmas = open.pragmas ?? {};\n try {\n if (pragmas.journalMode) db.exec(`PRAGMA journal_mode=${pragmas.journalMode.toUpperCase()}`);\n db.exec(`PRAGMA synchronous=${open.durability === 'normal' ? 'NORMAL' : 'FULL'}`);\n if (pragmas.busyTimeoutMs !== undefined) db.exec(`PRAGMA busy_timeout=${Math.max(0, Math.floor(pragmas.busyTimeoutMs))}`);\n if (pragmas.foreignKeys !== undefined) db.exec(`PRAGMA foreign_keys=${pragmas.foreignKeys ? 'ON' : 'OFF'}`);\n } catch (error) {\n db.close();\n throw toError(error);\n }\n const token = `node-session-${++seed}` as G9SessionToken;\n sessions.set(token, { token, db, statements: new Map(), tx: null, lastInsertRowId: 0 });\n return token;\n },\n\n async run(token: G9SessionToken, statements: readonly G9DriverStatement[], run: G9RunOptions = {}): Promise<G9SqlResult[]> {\n const s = session(token);\n if (run.tx !== undefined && s.tx !== run.tx) throw new G9NodeSqliteError('misuse', 'The transaction is finished or belongs to another session.');\n if (run.tx === undefined && s.tx !== null) throw new G9NodeSqliteError('misuse', 'A transaction is open on this session; pass its token (tx).');\n if (run.signal?.aborted) throw new G9NodeSqliteError('cancelled', 'Cancelled before the batch started.');\n const atomic = run.atomic === true && run.tx === undefined && statements.length > 0;\n if (atomic) s.db.exec('BEGIN');\n const results: G9SqlResult[] = [];\n try {\n for (const statement of statements) {\n try {\n results.push(execute(s, statement, run.maxRows));\n } catch (error) {\n throw toError(error, statement.sql);\n }\n }\n if (atomic) s.db.exec('COMMIT');\n } catch (error) {\n if (atomic) {\n try {\n s.db.exec('ROLLBACK');\n } catch {\n // already rolled back\n }\n }\n throw toError(error);\n }\n return results;\n },\n\n async begin(token: G9SessionToken, mode: 'deferred' | 'immediate'): Promise<G9TxToken> {\n const s = session(token);\n if (s.tx !== null) throw new G9NodeSqliteError('misuse', 'A transaction is already open on this session.');\n try {\n s.db.exec(mode === 'immediate' ? 'BEGIN IMMEDIATE' : 'BEGIN DEFERRED');\n } catch (error) {\n throw toError(error);\n }\n const tx = `node-tx-${++seed}` as G9TxToken;\n s.tx = tx;\n owners.set(tx, s);\n return tx;\n },\n\n async commit(tx: G9TxToken): Promise<void> {\n const s = owners.get(tx);\n if (!s || s.tx !== tx) throw new G9NodeSqliteError('misuse', 'The transaction is finished or unknown.');\n try {\n s.db.exec('COMMIT');\n } catch (error) {\n throw toError(error);\n }\n s.tx = null;\n owners.delete(tx);\n },\n\n async rollback(tx: G9TxToken): Promise<void> {\n const s = owners.get(tx);\n if (!s || s.tx !== tx) throw new G9NodeSqliteError('misuse', 'The transaction is finished or unknown.');\n s.tx = null;\n owners.delete(tx);\n try {\n s.db.exec('ROLLBACK');\n } catch {\n // SQLite may already have rolled back\n }\n },\n\n async close(token: G9SessionToken): Promise<void> {\n const s = session(token);\n sessions.delete(token);\n if (s.tx) owners.delete(s.tx);\n s.statements.clear();\n s.db.close();\n },\n };\n}\n"]}