@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,286 @@
1
+ // Twin of G9SyncData.Client.SignalR/G9CSignalRSyncTransport.cs: the sync transport over the G9SignalRSuperNetCore client
2
+ // (its jittered reconnect policy and connection states), every failure surfacing as a G9SyncException with the server's
3
+ // stable code. Lynx hosts build the client with the native WebSocket of @g9tm/signalr-supernetcore-lynx
4
+ // (`createLynxSyncTransport` in @g9tm/syncdata-lynx does).
5
+ import { G9Client } from '@g9tm/signalr-supernetcore-client';
6
+ import { HubConnectionState, Subject } from '@microsoft/signalr';
7
+ import { G9SyncErrorCodes, G9SyncException, isSyncException } from '../abstractions/errors.js';
8
+ import { createAbortController, onAbort } from '../internal/abort.js';
9
+ import { G9SyncHubErrors, G9SyncProtocol } from '../protocol/protocol.js';
10
+ import { fromMessagePackNames, readChangesAvailable, readHelloResult, readPullPlan, readPushResult, readSyncChunk, toMessagePackNames, } from '../protocol/wire.js';
11
+ import { createSyncMessagePackProtocol, G9SyncJsonHubProtocol } from './protocols.js';
12
+ /** The SignalR hub protocol a client speaks (`G9ESyncHubProtocol`). The server accepts both. */
13
+ export const G9ESyncHubProtocol = {
14
+ /** Text frames; payloads base64-encoded (+33%). Readable in traces. */
15
+ Json: 0,
16
+ /** Binary frames: payloads as raw bytes. The default. */
17
+ MessagePack: 1,
18
+ };
19
+ /** The SignalR implementation of {@link G9SyncTransport}. */
20
+ export class G9SignalRSyncTransport {
21
+ constructor(options) {
22
+ var _a, _b, _c, _d;
23
+ this._handlers = [];
24
+ this._connecting = null;
25
+ if (!options || typeof options.url !== 'string' || options.url.trim() === '')
26
+ throw new TypeError('A hub URL is required.');
27
+ this._options = options;
28
+ const json = options.protocol === G9ESyncHubProtocol.Json;
29
+ this.format = json ? 'json' : 'messagepack';
30
+ const protocol = json ? new G9SyncJsonHubProtocol() : createSyncMessagePackProtocol();
31
+ const clientOptions = {
32
+ ...((_a = options.client) !== null && _a !== void 0 ? _a : {}),
33
+ url: options.url,
34
+ protocol,
35
+ statefulReconnect: (_b = options.statefulReconnect) !== null && _b !== void 0 ? _b : false,
36
+ serverTimeoutMs: (_c = options.serverTimeoutMs) !== null && _c !== void 0 ? _c : 30000,
37
+ keepAliveIntervalMs: (_d = options.keepAliveIntervalMs) !== null && _d !== void 0 ? _d : 10000,
38
+ };
39
+ if (options.accessTokenFactory)
40
+ clientOptions.accessTokenFactory = options.accessTokenFactory;
41
+ this.client = options.createClient ? options.createClient(clientOptions) : new G9Client(clientOptions);
42
+ this.client.on(G9SyncProtocol.Listeners.OnChangesAvailable, (payload) => this._onChanges(payload));
43
+ }
44
+ get isConnected() {
45
+ return this.client.connection.state === HubConnectionState.Connected;
46
+ }
47
+ onChangesAvailable(handler) {
48
+ this._handlers.push(handler);
49
+ return () => {
50
+ const index = this._handlers.indexOf(handler);
51
+ if (index >= 0)
52
+ this._handlers.splice(index, 1);
53
+ };
54
+ }
55
+ /** Connects (joins a connect in progress); a connect that takes longer than connectTimeoutMs is a network failure. */
56
+ connect(signal) {
57
+ if (this.isConnected)
58
+ return Promise.resolve();
59
+ if (!this._connecting) {
60
+ const connecting = this._connectCore().finally(() => {
61
+ if (this._connecting === connecting)
62
+ this._connecting = null;
63
+ });
64
+ this._connecting = connecting;
65
+ }
66
+ const connecting = this._connecting;
67
+ if (!signal)
68
+ return connecting;
69
+ return new Promise((resolve, reject) => {
70
+ const unsubscribe = onAbort(signal, () => reject(new G9SyncException(G9SyncErrorCodes.Canceled, 'The connect was canceled.')));
71
+ connecting.then(() => {
72
+ unsubscribe();
73
+ resolve();
74
+ }, (error) => {
75
+ unsubscribe();
76
+ reject(error);
77
+ });
78
+ });
79
+ }
80
+ async _connectCore() {
81
+ var _a, _b;
82
+ const timeout = createAbortController();
83
+ const timer = setTimeout(() => timeout.abort(), (_a = this._options.connectTimeoutMs) !== null && _a !== void 0 ? _a : 20000);
84
+ try {
85
+ await this.client.start(timeout.signal);
86
+ }
87
+ catch (error) {
88
+ const mapped = (_b = mapError(error, false)) !== null && _b !== void 0 ? _b : new G9SyncException(G9SyncErrorCodes.NetworkFailure, messageOf(error), { retryable: true, cause: error });
89
+ throw mapped.code === G9SyncErrorCodes.Canceled
90
+ ? new G9SyncException(G9SyncErrorCodes.NetworkFailure, `The sync connection to ${this._options.url} did not open in time.`, { retryable: true, cause: error })
91
+ : mapped;
92
+ }
93
+ finally {
94
+ clearTimeout(timer);
95
+ }
96
+ if (!this.isConnected) {
97
+ throw new G9SyncException(G9SyncErrorCodes.NetworkFailure, `The sync connection is ${String(this.client.connection.state)}.`, { retryable: true });
98
+ }
99
+ }
100
+ hello(request, signal) {
101
+ return this._invoke(G9SyncProtocol.Methods.Hello, [this._wire(request)], readHelloResult, signal);
102
+ }
103
+ push(request, chunks, signal) {
104
+ const subject = new Subject();
105
+ const result = this._invoke(G9SyncProtocol.Methods.Push, [this._wire(request), subject], readPushResult, signal);
106
+ void (async () => {
107
+ try {
108
+ for await (const chunk of chunks)
109
+ subject.next(this._wire(chunk));
110
+ subject.complete();
111
+ }
112
+ catch (error) {
113
+ subject.error(error);
114
+ }
115
+ })();
116
+ return result;
117
+ }
118
+ planPull(request, signal) {
119
+ return this._invoke(G9SyncProtocol.Methods.PlanPull, [this._wire(request)], readPullPlan, signal);
120
+ }
121
+ pull(token, continuation, signal) {
122
+ return this._stream(G9SyncProtocol.Methods.Pull, [token, continuation === null ? null : this._wire(continuation)], signal);
123
+ }
124
+ reconcile(request, signal) {
125
+ return this._stream(G9SyncProtocol.Methods.Reconcile, [this._wire(request)], signal);
126
+ }
127
+ fetchRows(request, signal) {
128
+ return this._stream(G9SyncProtocol.Methods.FetchRows, [this._wire(request)], signal);
129
+ }
130
+ async dispose() {
131
+ this._handlers.length = 0;
132
+ await this.client.stop();
133
+ }
134
+ // ================================================================ plumbing
135
+ _wire(value) {
136
+ return this.format === 'messagepack' ? toMessagePackNames(value) : value;
137
+ }
138
+ _read(value) {
139
+ return this.format === 'messagepack' ? fromMessagePackNames(value) : value;
140
+ }
141
+ async _invoke(method, args, read, signal) {
142
+ var _a;
143
+ if (signal && signal.aborted)
144
+ throw new G9SyncException(G9SyncErrorCodes.Canceled, 'The call was canceled.');
145
+ let unsubscribe = () => undefined;
146
+ try {
147
+ const call = this.client.connection.invoke(method, ...args);
148
+ const raw = signal
149
+ ? await new Promise((resolve, reject) => {
150
+ unsubscribe = onAbort(signal, () => reject(new G9SyncException(G9SyncErrorCodes.Canceled, 'The call was canceled.')));
151
+ call.then(resolve, reject);
152
+ })
153
+ : await call;
154
+ return read(this._read(raw));
155
+ }
156
+ catch (error) {
157
+ throw (_a = mapError(error, signal ? signal.aborted : false)) !== null && _a !== void 0 ? _a : error;
158
+ }
159
+ finally {
160
+ unsubscribe();
161
+ }
162
+ }
163
+ _stream(method, args, signal) {
164
+ // eslint-disable-next-line @typescript-eslint/no-this-alias
165
+ const self = this;
166
+ return {
167
+ [Symbol.asyncIterator]() {
168
+ const queue = [];
169
+ let done = false;
170
+ let failure = null;
171
+ let wake = null;
172
+ let subscription = null;
173
+ const notify = () => {
174
+ const w = wake;
175
+ wake = null;
176
+ if (w)
177
+ w();
178
+ };
179
+ let unsubscribeAbort = () => undefined;
180
+ const start = () => {
181
+ if (subscription || done)
182
+ return;
183
+ let stream;
184
+ try {
185
+ stream = self.client.connection.stream(method, ...args);
186
+ }
187
+ catch (error) {
188
+ failure = error;
189
+ done = true;
190
+ return;
191
+ }
192
+ subscription = stream.subscribe({
193
+ next: (item) => {
194
+ queue.push(readSyncChunk(self._read(item)));
195
+ notify();
196
+ },
197
+ error: (error) => {
198
+ failure = error;
199
+ done = true;
200
+ notify();
201
+ },
202
+ complete: () => {
203
+ done = true;
204
+ notify();
205
+ },
206
+ });
207
+ unsubscribeAbort = onAbort(signal, () => {
208
+ failure = new G9SyncException(G9SyncErrorCodes.Canceled, 'The stream was canceled.');
209
+ done = true;
210
+ subscription === null || subscription === void 0 ? void 0 : subscription.dispose();
211
+ notify();
212
+ });
213
+ };
214
+ const finish = () => {
215
+ unsubscribeAbort();
216
+ if (subscription && !done)
217
+ subscription.dispose();
218
+ done = true;
219
+ };
220
+ return {
221
+ async next() {
222
+ var _a;
223
+ start();
224
+ for (;;) {
225
+ const item = queue.shift();
226
+ if (item)
227
+ return { value: item, done: false };
228
+ if (done) {
229
+ unsubscribeAbort();
230
+ if (failure !== null)
231
+ throw (_a = mapError(failure, signal ? signal.aborted : false)) !== null && _a !== void 0 ? _a : failure;
232
+ return { value: undefined, done: true };
233
+ }
234
+ await new Promise((resolve) => {
235
+ wake = resolve;
236
+ });
237
+ }
238
+ },
239
+ async return() {
240
+ finish();
241
+ return { value: undefined, done: true };
242
+ },
243
+ };
244
+ },
245
+ };
246
+ }
247
+ _onChanges(payload) {
248
+ const changes = readChangesAvailable(this._read(payload));
249
+ for (const handler of this._handlers.slice()) {
250
+ try {
251
+ handler(changes);
252
+ }
253
+ catch {
254
+ // A ChangesAvailable handler threw (logged by the .NET transport); it must not break the connection.
255
+ }
256
+ }
257
+ }
258
+ }
259
+ function messageOf(error) {
260
+ return error instanceof Error ? error.message : String(error);
261
+ }
262
+ /**
263
+ * The sync exception for a transport failure (`Map`): the server's `[G9S|code|retryable]` marker wins; any other hub
264
+ * error is a retryable server error; 401/403 is Unauthorized; the rest is a retryable network failure. Null leaves the
265
+ * error as it is (an already mapped one).
266
+ */
267
+ export function mapError(error, canceled) {
268
+ if (isSyncException(error))
269
+ return null;
270
+ if (canceled)
271
+ return new G9SyncException(G9SyncErrorCodes.Canceled, 'The call was canceled.', { cause: error });
272
+ const message = messageOf(error);
273
+ const marked = G9SyncHubErrors.tryParse(message);
274
+ if (marked)
275
+ return marked;
276
+ const status = error.statusCode;
277
+ if (status === 401 || status === 403)
278
+ return new G9SyncException(G9SyncErrorCodes.Unauthorized, 'The sync server refused the credentials.', { cause: error });
279
+ if (error instanceof Error && error.name === 'AbortError')
280
+ return new G9SyncException(G9SyncErrorCodes.Canceled, message, { cause: error });
281
+ // A completion error from the hub: SignalR words it "An unexpected error occurred invoking '…' on the server."
282
+ if (/on the server|HubException/i.test(message))
283
+ return new G9SyncException(G9SyncErrorCodes.ServerError, message, { retryable: true, cause: error });
284
+ return new G9SyncException(G9SyncErrorCodes.NetworkFailure, message, { retryable: true, cause: error });
285
+ }
286
+ //# sourceMappingURL=transport.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"transport.js","sourceRoot":"","sources":["../../src/signalr/transport.ts"],"names":[],"mappings":"AAAA,yHAAyH;AACzH,wHAAwH;AACxH,wGAAwG;AACxG,2DAA2D;AAC3D,OAAO,EAAE,QAAQ,EAAwB,MAAM,mCAAmC,CAAC;AACnF,OAAO,EAAE,kBAAkB,EAAE,OAAO,EAA6D,MAAM,oBAAoB,CAAC;AAC5H,OAAO,EAAE,gBAAgB,EAAE,eAAe,EAAE,eAAe,EAAE,MAAM,2BAA2B,CAAC;AAC/F,OA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,OAAO,IAAI,eAAe,CAAC,gBAAgB,CAAC,QAAQ,EAAE,wBAAwB,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC,CAAC;IAChH,MAAM,OAAO,GAAG,SAAS,CAAC,KAAK,CAAC,CAAC;IACjC,MAAM,MAAM,GAAG,eAAe,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;IACjD,IAAI,MAAM;QAAE,OAAO,MAAM,CAAC;IAC1B,MAAM,MAAM,GAAI,KAAkC,CAAC,UAAU,CAAC;IAC9D,IAAI,MAAM,KAAK,GAAG,IAAI,MAAM,KAAK,GAAG;QAAE,OAAO,IAAI,eAAe,CAAC,gBAAgB,CAAC,YAAY,EAAE,0CAA0C,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC,CAAC;IAC9J,IAAI,KAAK,YAAY,KAAK,IAAI,KAAK,CAAC,IAAI,KAAK,YAAY;QAAE,OAAO,IAAI,eAAe,CAAC,gBAAgB,CAAC,QAAQ,EAAE,OAAO,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC,CAAC;IAC5I,+GAA+G;IAC/G,IAAI,6BAA6B,CAAC,IAAI,CAAC,OAAO,CAAC;QAAE,OAAO,IAAI,eAAe,CAAC,gBAAgB,CAAC,WAAW,EAAE,OAAO,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC,CAAC;IACtJ,OAAO,IAAI,eAAe,CAAC,gBAAgB,CAAC,cAAc,EAAE,OAAO,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC,CAAC;AAC1G,CAAC","sourcesContent":["// Twin of G9SyncData.Client.SignalR/G9CSignalRSyncTransport.cs: the sync transport over the G9SignalRSuperNetCore client\n// (its jittered reconnect policy and connection states), every failure surfacing as a G9SyncException with the server's\n// stable code. Lynx hosts build the client with the native WebSocket of @g9tm/signalr-supernetcore-lynx\n// (`createLynxSyncTransport` in @g9tm/syncdata-lynx does).\nimport { G9Client, type G9ClientOptions } from '@g9tm/signalr-supernetcore-client';\nimport { HubConnectionState, Subject, type IHubProtocol, type IStreamResult, type ISubscription } from '@microsoft/signalr';\nimport { G9SyncErrorCodes, G9SyncException, isSyncException } from '../abstractions/errors.js';\nimport { createAbortController, onAbort } from '../internal/abort.js';\nimport type { G9SyncTransport } from '../client/transport.js';\nimport type {\n G9DtChangesAvailable,\n G9DtFetchRowsRequest,\n G9DtHelloRequest,\n G9DtHelloResult,\n G9DtPullContinuation,\n G9DtPullPlan,\n G9DtPullRequest,\n G9DtPushRequest,\n G9DtPushResult,\n G9DtReconcileRequest,\n G9DtSyncChunk,\n} from '../protocol/dtos.js';\nimport { G9SyncHubErrors, G9SyncProtocol } from '../protocol/protocol.js';\nimport {\n fromMessagePackNames,\n readChangesAvailable,\n readHelloResult,\n readPullPlan,\n readPushResult,\n readSyncChunk,\n toMessagePackNames,\n type G9WireFormat,\n} from '../protocol/wire.js';\nimport { createSyncMessagePackProtocol, G9SyncJsonHubProtocol } from './protocols.js';\n\n/** The SignalR hub protocol a client speaks (`G9ESyncHubProtocol`). The server accepts both. */\nexport const G9ESyncHubProtocol = {\n /** Text frames; payloads base64-encoded (+33%). Readable in traces. */\n Json: 0,\n /** Binary frames: payloads as raw bytes. The default. */\n MessagePack: 1,\n} as const;\nexport type G9ESyncHubProtocol = (typeof G9ESyncHubProtocol)[keyof typeof G9ESyncHubProtocol];\n\n/** Options of {@link G9SignalRSyncTransport} (`G9CSignalRSyncTransportOptions`). Durations are milliseconds. */\nexport interface G9SignalRSyncTransportOptions {\n /** Absolute hub URL, e.g. `https://sync.example.com/g9sync`. */\n url: string;\n /** Hub protocol; MessagePack by default. */\n protocol?: G9ESyncHubProtocol;\n /** Supplies the bearer token for every (re)connect. */\n accessTokenFactory?: () => string | Promise<string>;\n /** SignalR stateful reconnect (ADR-0069); off by default, the server must allow it too. */\n statefulReconnect?: boolean;\n /** How long one connect may take before it counts as a network failure. */\n connectTimeoutMs?: number;\n serverTimeoutMs?: number;\n keepAliveIntervalMs?: number;\n /**\n * Everything else the G9 client takes (transport, headers, WebSocket constructor, skipNegotiation, reconnect policy, log\n * level…) — the twin of ConfigureHttpConnection/ConfigureBuilder. `url`, `protocol` and the timeouts above win.\n */\n client?: Partial<G9ClientOptions>;\n /** Builds the client (tests, hosts with their own wiring); `new G9Client(options)` by default. */\n createClient?: (options: G9ClientOptions) => G9Client;\n}\n\n/** The SignalR implementation of {@link G9SyncTransport}. */\nexport class G9SignalRSyncTransport implements G9SyncTransport {\n readonly client: G9Client;\n readonly format: G9WireFormat;\n private readonly _options: G9SignalRSyncTransportOptions;\n private readonly _handlers: ((changes: G9DtChangesAvailable) => void)[] = [];\n private _connecting: Promise<void> | null = null;\n\n constructor(options: G9SignalRSyncTransportOptions) {\n if (!options || typeof options.url !== 'string' || options.url.trim() === '') throw new TypeError('A hub URL is required.');\n this._options = options;\n const json = options.protocol === G9ESyncHubProtocol.Json;\n this.format = json ? 'json' : 'messagepack';\n const protocol: IHubProtocol = json ? new G9SyncJsonHubProtocol() : createSyncMessagePackProtocol();\n const clientOptions: G9ClientOptions = {\n ...(options.client ?? {}),\n url: options.url,\n protocol,\n statefulReconnect: options.statefulReconnect ?? false,\n serverTimeoutMs: options.serverTimeoutMs ?? 30000,\n keepAliveIntervalMs: options.keepAliveIntervalMs ?? 10000,\n };\n if (options.accessTokenFactory) clientOptions.accessTokenFactory = options.accessTokenFactory;\n this.client = options.createClient ? options.createClient(clientOptions) : new G9Client(clientOptions);\n this.client.on(G9SyncProtocol.Listeners.OnChangesAvailable, (payload: unknown) => this._onChanges(payload));\n }\n\n get isConnected(): boolean {\n return this.client.connection.state === HubConnectionState.Connected;\n }\n\n onChangesAvailable(handler: (changes: G9DtChangesAvailable) => void): () => void {\n this._handlers.push(handler);\n return () => {\n const index = this._handlers.indexOf(handler);\n if (index >= 0) this._handlers.splice(index, 1);\n };\n }\n\n /** Connects (joins a connect in progress); a connect that takes longer than connectTimeoutMs is a network failure. */\n connect(signal?: AbortSignal): Promise<void> {\n if (this.isConnected) return Promise.resolve();\n if (!this._connecting) {\n const connecting = this._connectCore().finally(() => {\n if (this._connecting === connecting) this._connecting = null;\n });\n this._connecting = connecting;\n }\n const connecting = this._connecting;\n if (!signal) return connecting;\n return new Promise<void>((resolve, reject) => {\n const unsubscribe = onAbort(signal, () => reject(new G9SyncException(G9SyncErrorCodes.Canceled, 'The connect was canceled.')));\n connecting.then(\n () => {\n unsubscribe();\n resolve();\n },\n (error) => {\n unsubscribe();\n reject(error);\n },\n );\n });\n }\n\n private async _connectCore(): Promise<void> {\n const timeout = createAbortController();\n const timer = setTimeout(() => timeout.abort(), this._options.connectTimeoutMs ?? 20000);\n try {\n await this.client.start(timeout.signal);\n } catch (error) {\n const mapped = mapError(error, false) ?? new G9SyncException(G9SyncErrorCodes.NetworkFailure, messageOf(error), { retryable: true, cause: error });\n throw mapped.code === G9SyncErrorCodes.Canceled\n ? new G9SyncException(G9SyncErrorCodes.NetworkFailure, `The sync connection to ${this._options.url} did not open in time.`, { retryable: true, cause: error })\n : mapped;\n } finally {\n clearTimeout(timer);\n }\n if (!this.isConnected) {\n throw new G9SyncException(G9SyncErrorCodes.NetworkFailure, `The sync connection is ${String(this.client.connection.state)}.`, { retryable: true });\n }\n }\n\n hello(request: G9DtHelloRequest, signal?: AbortSignal): Promise<G9DtHelloResult> {\n return this._invoke(G9SyncProtocol.Methods.Hello, [this._wire(request)], readHelloResult, signal);\n }\n\n push(request: G9DtPushRequest, chunks: AsyncIterable<G9DtSyncChunk>, signal?: AbortSignal): Promise<G9DtPushResult> {\n const subject = new Subject<unknown>();\n const result = this._invoke(G9SyncProtocol.Methods.Push, [this._wire(request), subject], readPushResult, signal);\n void (async () => {\n try {\n for await (const chunk of chunks) subject.next(this._wire(chunk));\n subject.complete();\n } catch (error) {\n subject.error(error);\n }\n })();\n return result;\n }\n\n planPull(request: G9DtPullRequest, signal?: AbortSignal): Promise<G9DtPullPlan> {\n return this._invoke(G9SyncProtocol.Methods.PlanPull, [this._wire(request)], readPullPlan, signal);\n }\n\n pull(token: string, continuation: G9DtPullContinuation | null, signal?: AbortSignal): AsyncIterable<G9DtSyncChunk> {\n return this._stream(G9SyncProtocol.Methods.Pull, [token, continuation === null ? null : this._wire(continuation)], signal);\n }\n\n reconcile(request: G9DtReconcileRequest, signal?: AbortSignal): AsyncIterable<G9DtSyncChunk> {\n return this._stream(G9SyncProtocol.Methods.Reconcile, [this._wire(request)], signal);\n }\n\n fetchRows(request: G9DtFetchRowsRequest, signal?: AbortSignal): AsyncIterable<G9DtSyncChunk> {\n return this._stream(G9SyncProtocol.Methods.FetchRows, [this._wire(request)], signal);\n }\n\n async dispose(): Promise<void> {\n this._handlers.length = 0;\n await this.client.stop();\n }\n\n // ================================================================ plumbing\n\n private _wire(value: unknown): unknown {\n return this.format === 'messagepack' ? toMessagePackNames(value) : value;\n }\n\n private _read(value: unknown): unknown {\n return this.format === 'messagepack' ? fromMessagePackNames(value) : value;\n }\n\n private async _invoke<T>(method: string, args: unknown[], read: (value: unknown) => T, signal?: AbortSignal): Promise<T> {\n if (signal && signal.aborted) throw new G9SyncException(G9SyncErrorCodes.Canceled, 'The call was canceled.');\n let unsubscribe: () => void = () => undefined;\n try {\n const call = this.client.connection.invoke(method, ...args);\n const raw = signal\n ? await new Promise<unknown>((resolve, reject) => {\n unsubscribe = onAbort(signal, () => reject(new G9SyncException(G9SyncErrorCodes.Canceled, 'The call was canceled.')));\n call.then(resolve, reject);\n })\n : await call;\n return read(this._read(raw));\n } catch (error) {\n throw mapError(error, signal ? signal.aborted : false) ?? error;\n } finally {\n unsubscribe();\n }\n }\n\n private _stream(method: string, args: unknown[], signal?: AbortSignal): AsyncIterable<G9DtSyncChunk> {\n // eslint-disable-next-line @typescript-eslint/no-this-alias\n const self = this;\n return {\n [Symbol.asyncIterator](): AsyncIterator<G9DtSyncChunk> {\n const queue: G9DtSyncChunk[] = [];\n let done = false;\n let failure: unknown = null;\n let wake: (() => void) | null = null;\n let subscription: ISubscription<unknown> | null = null;\n const notify = (): void => {\n const w = wake;\n wake = null;\n if (w) w();\n };\n let unsubscribeAbort: () => void = () => undefined;\n const start = (): void => {\n if (subscription || done) return;\n let stream: IStreamResult<unknown>;\n try {\n stream = self.client.connection.stream(method, ...args);\n } catch (error) {\n failure = error;\n done = true;\n return;\n }\n subscription = stream.subscribe({\n next: (item) => {\n queue.push(readSyncChunk(self._read(item)));\n notify();\n },\n error: (error) => {\n failure = error;\n done = true;\n notify();\n },\n complete: () => {\n done = true;\n notify();\n },\n });\n unsubscribeAbort = onAbort(signal, () => {\n failure = new G9SyncException(G9SyncErrorCodes.Canceled, 'The stream was canceled.');\n done = true;\n subscription?.dispose();\n notify();\n });\n };\n const finish = (): void => {\n unsubscribeAbort();\n if (subscription && !done) subscription.dispose();\n done = true;\n };\n return {\n async next(): Promise<IteratorResult<G9DtSyncChunk>> {\n start();\n for (;;) {\n const item = queue.shift();\n if (item) return { value: item, done: false };\n if (done) {\n unsubscribeAbort();\n if (failure !== null) throw mapError(failure, signal ? signal.aborted : false) ?? failure;\n return { value: undefined as unknown as G9DtSyncChunk, done: true };\n }\n await new Promise<void>((resolve) => {\n wake = resolve;\n });\n }\n },\n async return(): Promise<IteratorResult<G9DtSyncChunk>> {\n finish();\n return { value: undefined as unknown as G9DtSyncChunk, done: true };\n },\n };\n },\n };\n }\n\n private _onChanges(payload: unknown): void {\n const changes = readChangesAvailable(this._read(payload));\n for (const handler of this._handlers.slice()) {\n try {\n handler(changes);\n } catch {\n // A ChangesAvailable handler threw (logged by the .NET transport); it must not break the connection.\n }\n }\n }\n}\n\nfunction messageOf(error: unknown): string {\n return error instanceof Error ? error.message : String(error);\n}\n\n/**\n * The sync exception for a transport failure (`Map`): the server's `[G9S|code|retryable]` marker wins; any other hub\n * error is a retryable server error; 401/403 is Unauthorized; the rest is a retryable network failure. Null leaves the\n * error as it is (an already mapped one).\n */\nexport function mapError(error: unknown, canceled: boolean): G9SyncException | null {\n if (isSyncException(error)) return null;\n if (canceled) return new G9SyncException(G9SyncErrorCodes.Canceled, 'The call was canceled.', { cause: error });\n const message = messageOf(error);\n const marked = G9SyncHubErrors.tryParse(message);\n if (marked) return marked;\n const status = (error as { statusCode?: unknown }).statusCode;\n if (status === 401 || status === 403) return new G9SyncException(G9SyncErrorCodes.Unauthorized, 'The sync server refused the credentials.', { cause: error });\n if (error instanceof Error && error.name === 'AbortError') return new G9SyncException(G9SyncErrorCodes.Canceled, message, { cause: error });\n // A completion error from the hub: SignalR words it \"An unexpected error occurred invoking '…' on the server.\"\n if (/on the server|HubException/i.test(message)) return new G9SyncException(G9SyncErrorCodes.ServerError, message, { retryable: true, cause: error });\n return new G9SyncException(G9SyncErrorCodes.NetworkFailure, message, { retryable: true, cause: error });\n}\n"]}
@@ -0,0 +1,91 @@
1
+ import { G9EMoveOutPolicy } from '../abstractions/enums.js';
2
+ import { G9Long } from '../abstractions/long.js';
3
+ import { G9ApplyReport, type G9ApplySlice } from '../client/storeTypes.js';
4
+ import { type G9DtBackfillRequest, type G9DtNegotiatedTable, type G9DtPullPlan } from '../protocol/dtos.js';
5
+ import { G9StatementBatch, type G9SqliteConnection } from './connection.js';
6
+ import type { G9SqlResult } from './driver.js';
7
+ import { type LocalTable, type StoreInternals } from './internals.js';
8
+ /** The state of one apply transaction (`ApplyContext`). */
9
+ export declare class ApplyContext {
10
+ readonly connection: G9SqliteConnection;
11
+ readonly batch: G9StatementBatch;
12
+ readonly report: G9ApplyReport;
13
+ readonly dirty: Set<string>;
14
+ readonly subscriptions: Map<string, {
15
+ slot: number;
16
+ ephemeral: boolean;
17
+ }>;
18
+ readonly policies: Map<string, G9EMoveOutPolicy>;
19
+ readonly backfillColumns: Map<number, readonly string[]>;
20
+ readonly deferredIndexes: {
21
+ name: string;
22
+ sql: string;
23
+ }[];
24
+ /** Library triggers dropped for the apply, re-created from this SQL before commit. */
25
+ readonly droppedTriggers: {
26
+ name: string;
27
+ sql: string;
28
+ }[];
29
+ rows: number;
30
+ hasRevoked: boolean;
31
+ private readonly _dirtyTables;
32
+ private readonly _tableTime;
33
+ private readonly _progress;
34
+ private readonly _maxChangedKeys;
35
+ private readonly _signal;
36
+ constructor(connection: G9SqliteConnection, progress: ((rows: number) => void) | null, maxChangedKeys: number, statementsPerBatch: number, signal?: AbortSignal);
37
+ addDirty(tid: number, key: string): void;
38
+ isDirty(tid: number, key: string): boolean;
39
+ hasDirty(tid: number): boolean;
40
+ wantsChangedKey(table: string): boolean;
41
+ addChanged(table: string, key: string): void;
42
+ tick(): void;
43
+ /** Queues a script; flushes when the batch is full. */
44
+ queue(script: string, params?: Parameters<G9StatementBatch['add']>[1], callback?: (results: G9SqlResult[]) => void): Promise<void>;
45
+ /** Runs what is queued (before anything that reads, and at the end). Yields to the event loop between batches. */
46
+ flush(): Promise<void>;
47
+ addTableTime(table: string, rows: number, elapsedMs: number): void;
48
+ private readonly _tableNames;
49
+ publishTableTimes(): void;
50
+ }
51
+ /**
52
+ * Opens an apply and decides which rows it may not touch (`BeginApply`). `dirtyAfterSequence` narrows the protected set to
53
+ * pending changes after it; `changedAfterSequence` widens it with every row changed after it (ADR-0046).
54
+ */
55
+ export declare function beginApply(store: StoreInternals, connection: G9SqliteConnection, options: {
56
+ dirtyAfterSequence?: number | null;
57
+ progress?: ((rows: number) => void) | null;
58
+ backfills?: readonly G9DtBackfillRequest[];
59
+ snapshotRows?: Map<number, number> | null;
60
+ changedAfterSequence?: number | null;
61
+ protectedRows?: {
62
+ tid: number;
63
+ key: string;
64
+ }[] | null;
65
+ skipTriggers?: boolean;
66
+ signal?: AbortSignal;
67
+ }): Promise<ApplyContext>;
68
+ /** `EndApply`: rebuilds deferred indexes, re-creates dropped triggers, clears the applying flag. */
69
+ export declare function endApply(context: ApplyContext): Promise<void>;
70
+ /** `g9_{table}_{ai|au|ad|ci|cu|cd}` for a table of the model. */
71
+ export declare function isLibraryTrigger(store: StoreInternals, name: string): boolean;
72
+ /** The triggers the library did not create. */
73
+ export declare function foreignTriggerNames(store: StoreInternals, connection: G9SqliteConnection): Promise<string[]>;
74
+ /** Rows changed after a sequence, table by table (`g9_rows_feed (tid, local_seq)` serves each read). */
75
+ export declare function readRowsChangedAfter(store: StoreInternals, connection: G9SqliteConnection, sequence: number, add: (tid: number, key: string) => void): Promise<void>;
76
+ /** Rows each table receives from snapshot parts of a plan, by server table id. */
77
+ export declare function snapshotRowsByTable(plan: G9DtPullPlan): Map<number, number>;
78
+ /** `synchronous=NORMAL` while a transaction writes only server-derived data (WAL only); returns the restore action. */
79
+ export declare function downloadDurability(store: StoreInternals, connection: G9SqliteConnection): Promise<(() => Promise<void>) | null>;
80
+ /** Applies one frame (`ApplyFrame`). */
81
+ export declare function applyFrame(store: StoreInternals, context: ApplyContext, frame: Uint8Array, subscriptionKey: string | null): Promise<void>;
82
+ /** `MoveOut`: drops the membership; with a Delete policy a row nobody holds goes through the revocation policy. */
83
+ export declare function moveOut(store: StoreInternals, context: ApplyContext, table: LocalTable, key: string, subscriptionKey: string, slot: number, ephemeral: boolean, policy: G9EMoveOutPolicy): Promise<void>;
84
+ /** `AddMembership`. */
85
+ export declare function addMembership(context: ApplyContext, table: LocalTable, key: string, slot: number, ephemeralKey: string | null): Promise<void>;
86
+ /** `ApplyStagedPullAsync`: atomic, or in committed slices (ADR-0053); cursors move only with the last slice. */
87
+ export declare function applyStagedPull(store: StoreInternals, runId: string, rowsApplied: ((rows: number) => void) | null, slices: ((slice: G9ApplySlice) => void) | null, readStagedRun: (connection: G9SqliteConnection, runId: string) => Promise<import('../client/storeTypes.js').G9StagedPull | null>, signal?: AbortSignal): Promise<G9ApplyReport>;
88
+ /** `ApplyReconcileAsync`. */
89
+ export declare function applyReconcile(store: StoreInternals, subscriptionKey: string, table: G9DtNegotiatedTable, fetchedFrames: readonly Uint8Array[], addMembershipKeys: readonly string[], moveOutKeys: readonly string[], policy: G9EMoveOutPolicy, signal?: AbortSignal): Promise<G9ApplyReport>;
90
+ /** For callers that need a G9Long bit as a bind value. */
91
+ export declare function bitValue(slot: number): G9Long;