@genesislcap/foundation-comms 15.79.2-alpha-e9d30db797.0 → 15.80.0
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.
- package/asconfig.json +15 -0
- package/assembly/scdb/README.md +74 -0
- package/assembly/scdb/bench.mjs +32 -0
- package/assembly/scdb/decoder.ts +217 -0
- package/assembly/scdb/decoder.wasm +0 -0
- package/assembly/scdb/inline-wasm-base64.mjs +24 -0
- package/dist/dts/connect/connect.d.ts +2 -0
- package/dist/dts/connect/connect.d.ts.map +1 -1
- package/dist/dts/connect/http.connect.d.ts +10 -0
- package/dist/dts/connect/http.connect.d.ts.map +1 -1
- package/dist/dts/connect/message.d.ts +18 -0
- package/dist/dts/connect/message.d.ts.map +1 -1
- package/dist/dts/connect/scdbStreamDecoder.d.ts +66 -0
- package/dist/dts/connect/scdbStreamDecoder.d.ts.map +1 -0
- package/dist/dts/connect/socket.d.ts +23 -0
- package/dist/dts/connect/socket.d.ts.map +1 -1
- package/dist/dts/connect/socket.types.d.ts +14 -0
- package/dist/dts/connect/socket.types.d.ts.map +1 -1
- package/dist/dts/datasource/datasource.d.ts.map +1 -1
- package/dist/dts/datasource/datasource.types.d.ts +8 -0
- package/dist/dts/datasource/datasource.types.d.ts.map +1 -1
- package/dist/dts/datasource/index.d.ts +1 -0
- package/dist/dts/datasource/index.d.ts.map +1 -1
- package/dist/dts/datasource/scdb/base64.d.ts +6 -0
- package/dist/dts/datasource/scdb/base64.d.ts.map +1 -0
- package/dist/dts/datasource/scdb/dictionaryHash.d.ts +40 -0
- package/dist/dts/datasource/scdb/dictionaryHash.d.ts.map +1 -0
- package/dist/dts/datasource/scdb/index.d.ts +6 -0
- package/dist/dts/datasource/scdb/index.d.ts.map +1 -0
- package/dist/dts/datasource/scdb/scdb-js-bench.d.mts +2 -0
- package/dist/dts/datasource/scdb/scdb-js-bench.d.mts.map +1 -0
- package/dist/dts/datasource/scdb/scdbDecode.d.ts +24 -0
- package/dist/dts/datasource/scdb/scdbDecode.d.ts.map +1 -0
- package/dist/dts/datasource/scdb/scdbDecoder.d.ts +42 -0
- package/dist/dts/datasource/scdb/scdbDecoder.d.ts.map +1 -0
- package/dist/dts/datasource/scdb/scdbWasmDecoder.d.ts +27 -0
- package/dist/dts/datasource/scdb/scdbWasmDecoder.d.ts.map +1 -0
- package/dist/dts/datasource/scdb/scdbjDecoder.d.ts +35 -0
- package/dist/dts/datasource/scdb/scdbjDecoder.d.ts.map +1 -0
- package/dist/dts/datasource/scdb/wasm/decoder.wasm.base64.d.ts +7 -0
- package/dist/dts/datasource/scdb/wasm/decoder.wasm.base64.d.ts.map +1 -0
- package/dist/dts/testing/mocks/connect/socket.d.ts +1 -0
- package/dist/dts/testing/mocks/connect/socket.d.ts.map +1 -1
- package/dist/esm/connect/connect.js +22 -3
- package/dist/esm/connect/http.connect.js +33 -1
- package/dist/esm/connect/message.js +3 -1
- package/dist/esm/connect/scdbStreamDecoder.js +160 -0
- package/dist/esm/connect/socket.js +72 -2
- package/dist/esm/datasource/datasource.js +3 -0
- package/dist/esm/datasource/index.js +1 -0
- package/dist/esm/datasource/scdb/base64.js +17 -0
- package/dist/esm/datasource/scdb/dictionaryHash.js +45 -0
- package/dist/esm/datasource/scdb/index.js +5 -0
- package/dist/esm/datasource/scdb/scdb-golden-v1.json +15 -0
- package/dist/esm/datasource/scdb/scdb-js-bench.mjs +461 -0
- package/dist/esm/datasource/scdb/scdbDecode.js +67 -0
- package/dist/esm/datasource/scdb/scdbDecoder.js +279 -0
- package/dist/esm/datasource/scdb/scdbWasmDecoder.js +213 -0
- package/dist/esm/datasource/scdb/scdbjDecoder.js +60 -0
- package/dist/esm/datasource/scdb/wasm/decoder.wasm.base64.js +6 -0
- package/dist/esm/testing/mocks/connect/socket.js +3 -0
- package/dist/foundation-comms.api.json +1453 -8
- package/dist/foundation-comms.d.ts +251 -0
- package/package.json +14 -12
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
import { decodeColumnarQueryUpdate, decodeColumnarReply, dictionaryFromMetadata, dictionaryHash, } from '../datasource/scdb';
|
|
2
|
+
import { logger } from '../utils';
|
|
3
|
+
/** Req/rep requests carry the resource name in their `REQ_`-prefixed `MESSAGE_TYPE`. */
|
|
4
|
+
export function resourceNameOf(sent) {
|
|
5
|
+
var _a;
|
|
6
|
+
const datasourceName = (_a = sent === null || sent === void 0 ? void 0 : sent.DETAILS) === null || _a === void 0 ? void 0 : _a.DATASOURCE_NAME;
|
|
7
|
+
if (datasourceName)
|
|
8
|
+
return datasourceName;
|
|
9
|
+
const messageType = sent === null || sent === void 0 ? void 0 : sent.MESSAGE_TYPE;
|
|
10
|
+
if (typeof messageType === 'string' && messageType.startsWith('REQ_')) {
|
|
11
|
+
return messageType.slice('REQ_'.length);
|
|
12
|
+
}
|
|
13
|
+
return undefined;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Socket-side adapter that makes the SCDB columnar encodings transparent to all stream consumers.
|
|
17
|
+
*
|
|
18
|
+
* The column dictionary is **derived from resource metadata** (the same metadata the client already
|
|
19
|
+
* holds in `MetaCache`), NOT sent on the wire — for BOTH dataserver and req/rep. The server only
|
|
20
|
+
* stamps the payload with a small `DICT_HASH`; this adapter derives the dictionary from metadata,
|
|
21
|
+
* validates it against that hash, and decodes. The dictionary is resolved **per message from
|
|
22
|
+
* metadata** (not bound to the `LOGON_ACK`/`SOURCE_REF`).
|
|
23
|
+
*
|
|
24
|
+
* - Dataserver: `QUERY_UPDATE` carries no hash, so the expected hash is captured once from
|
|
25
|
+
* `LOGON_ACK` (which the socket consumes and does NOT forward), keyed by resource; the dictionary
|
|
26
|
+
* itself is still derived from metadata per update and decoded in place into `ROW`.
|
|
27
|
+
* - Req/rep: each reply carries its own `DICT_HASH`; dictionary derived from metadata and decoded
|
|
28
|
+
* into `REPLY`.
|
|
29
|
+
*
|
|
30
|
+
* The server sends a negotiated batch only in columnar form, so a message that cannot be decoded is
|
|
31
|
+
* lost.
|
|
32
|
+
*
|
|
33
|
+
* Memory: validated dictionaries are cached by their content hash, so all subscriptions/resources
|
|
34
|
+
* sharing a schema share one `string[]`, and a schema change (new hash) naturally re-derives.
|
|
35
|
+
*/
|
|
36
|
+
export class ScdbStreamDecoder {
|
|
37
|
+
constructor(metaCache) {
|
|
38
|
+
this.metaCache = metaCache;
|
|
39
|
+
/** Content hash -> validated dictionary. Shared across every resource/subscription with that schema. */
|
|
40
|
+
this.byHash = new Map();
|
|
41
|
+
/** Dataserver resource -> expected DICT_HASH captured from its LOGON_ACK (QUERY_UPDATE has none). */
|
|
42
|
+
this.expectedHashByResource = new Map();
|
|
43
|
+
/** Resources with an in-flight metadata refresh, to avoid issuing duplicate META_REQUESTs. */
|
|
44
|
+
this.refreshing = new Set();
|
|
45
|
+
}
|
|
46
|
+
/** Optionally supply the WASM decoder for the binary `SCDB_V1` fast-path (else pure-JS is used). */
|
|
47
|
+
setWasm(wasm) {
|
|
48
|
+
this.wasm = wasm;
|
|
49
|
+
}
|
|
50
|
+
/** Wire the metadata-refresh hook (host supplies a force-refresh, e.g. `getMetadata(r, false)`). */
|
|
51
|
+
setMetadataRefresher(refresher) {
|
|
52
|
+
this.metadataRefresher = refresher;
|
|
53
|
+
}
|
|
54
|
+
/** Without cached metadata the columnar answer could not be decoded, so row mode is requested. */
|
|
55
|
+
prepareRequest(message) {
|
|
56
|
+
const details = message.DETAILS;
|
|
57
|
+
if (!(details === null || details === void 0 ? void 0 : details.ENCODING))
|
|
58
|
+
return;
|
|
59
|
+
const resourceName = resourceNameOf(message);
|
|
60
|
+
if (resourceName && this.metaCache.hasMetadataFor(resourceName))
|
|
61
|
+
return;
|
|
62
|
+
const withoutEncoding = Object.assign({}, details);
|
|
63
|
+
delete withoutEncoding.ENCODING;
|
|
64
|
+
message.DETAILS = withoutEncoding;
|
|
65
|
+
if (resourceName)
|
|
66
|
+
this.requestRefresh(resourceName);
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Capture the dataserver resource's expected `DICT_HASH` from a `LOGON_ACK` (call before it is
|
|
70
|
+
* dropped) and pre-warm the dictionary from metadata. No-op for row-mode logons.
|
|
71
|
+
*/
|
|
72
|
+
onLogonAck(msg, resourceName) {
|
|
73
|
+
if (!(msg === null || msg === void 0 ? void 0 : msg.ENCODING) || !resourceName || msg.DICT_HASH == null)
|
|
74
|
+
return;
|
|
75
|
+
this.expectedHashByResource.set(resourceName, msg.DICT_HASH);
|
|
76
|
+
// Pre-warm (and kick off a refresh now if the cached metadata is stale).
|
|
77
|
+
this.dictionaryFor(resourceName, msg.DICT_HASH);
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Decodes a columnar message in place: dataserver `QUERY_UPDATE` into `msg.ROW` (expected hash from
|
|
81
|
+
* the resource's LOGON_ACK), req/rep reply into `msg.REPLY` (hash on the reply). No-op for row-mode
|
|
82
|
+
* or already decoded messages. Throws when the message cannot be decoded.
|
|
83
|
+
*/
|
|
84
|
+
onMessage(msg, resourceName) {
|
|
85
|
+
if (!msg || !msg.ENCODING || msg.ROW || msg.REPLY)
|
|
86
|
+
return;
|
|
87
|
+
const isQueryUpdate = msg.MESSAGE_TYPE === 'QUERY_UPDATE';
|
|
88
|
+
const expectedHash = isQueryUpdate
|
|
89
|
+
? resourceName && this.expectedHashByResource.get(resourceName)
|
|
90
|
+
: msg.DICT_HASH;
|
|
91
|
+
const dictionary = this.dictionaryFor(resourceName, expectedHash);
|
|
92
|
+
if (!dictionary) {
|
|
93
|
+
throw new Error(`Cannot decode ${msg.ENCODING} ${msg.MESSAGE_TYPE} for '${resourceName}': ` +
|
|
94
|
+
`no column dictionary matching DICT_HASH ${expectedHash}`);
|
|
95
|
+
}
|
|
96
|
+
if (isQueryUpdate)
|
|
97
|
+
msg.ROW = this.decodeQueryUpdate(msg, dictionary);
|
|
98
|
+
else
|
|
99
|
+
msg.REPLY = decodeColumnarReply(msg, dictionary);
|
|
100
|
+
}
|
|
101
|
+
decodeQueryUpdate(msg, dictionary) {
|
|
102
|
+
if (this.wasm) {
|
|
103
|
+
try {
|
|
104
|
+
return decodeColumnarQueryUpdate(msg, dictionary, this.wasm);
|
|
105
|
+
}
|
|
106
|
+
catch (e) {
|
|
107
|
+
// Throws again when the payload itself is bad, which is not a reason to drop the WASM decoder.
|
|
108
|
+
const rows = decodeColumnarQueryUpdate(msg, dictionary);
|
|
109
|
+
logger.warn('SCDB WASM decode failed, using the pure-JS decoder from now on', e);
|
|
110
|
+
this.wasm = undefined;
|
|
111
|
+
return rows;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
return decodeColumnarQueryUpdate(msg, dictionary);
|
|
115
|
+
}
|
|
116
|
+
clear() {
|
|
117
|
+
this.byHash.clear();
|
|
118
|
+
this.expectedHashByResource.clear();
|
|
119
|
+
this.refreshing.clear();
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Ordered dictionary for a resource, derived from cached metadata and validated against the
|
|
123
|
+
* server's `DICT_HASH`. Missing or mismatching metadata is refreshed for later requests.
|
|
124
|
+
* Validated results are cached by content hash (never negatives).
|
|
125
|
+
*/
|
|
126
|
+
dictionaryFor(resourceName, expectedHash) {
|
|
127
|
+
if (!resourceName)
|
|
128
|
+
return undefined;
|
|
129
|
+
if (expectedHash == null)
|
|
130
|
+
return undefined;
|
|
131
|
+
const cached = this.byHash.get(expectedHash);
|
|
132
|
+
if (cached)
|
|
133
|
+
return cached;
|
|
134
|
+
if (!this.metaCache.hasMetadataFor(resourceName)) {
|
|
135
|
+
this.requestRefresh(resourceName);
|
|
136
|
+
return undefined;
|
|
137
|
+
}
|
|
138
|
+
const names = dictionaryFromMetadata(this.metaCache.getMetadataFor(resourceName));
|
|
139
|
+
if (!names.length)
|
|
140
|
+
return undefined;
|
|
141
|
+
const clientHash = dictionaryHash(names);
|
|
142
|
+
if (clientHash !== expectedHash) {
|
|
143
|
+
logger.warn(`SCDB dictionary hash mismatch for '${resourceName}' (server=${expectedHash} ` +
|
|
144
|
+
`client=${clientHash}); refreshing metadata`);
|
|
145
|
+
this.requestRefresh(resourceName);
|
|
146
|
+
return undefined;
|
|
147
|
+
}
|
|
148
|
+
this.byHash.set(expectedHash, names);
|
|
149
|
+
return names;
|
|
150
|
+
}
|
|
151
|
+
/** Fire-and-forget metadata refresh, deduped per resource while one is in flight. */
|
|
152
|
+
requestRefresh(resourceName) {
|
|
153
|
+
if (!this.metadataRefresher || this.refreshing.has(resourceName))
|
|
154
|
+
return;
|
|
155
|
+
this.refreshing.add(resourceName);
|
|
156
|
+
Promise.resolve(this.metadataRefresher(resourceName))
|
|
157
|
+
.catch(() => undefined)
|
|
158
|
+
.finally(() => this.refreshing.delete(resourceName));
|
|
159
|
+
}
|
|
160
|
+
}
|
|
@@ -6,6 +6,8 @@ import { DI } from '@microsoft/fast-foundation';
|
|
|
6
6
|
import { from, Observable, of, Subject, Subscription, throwError } from 'rxjs';
|
|
7
7
|
import { exhaustMap, filter, map, switchMap, takeWhile } from 'rxjs/operators';
|
|
8
8
|
import { WebSocketSubject } from 'rxjs/webSocket';
|
|
9
|
+
import { getDefaultScdbWasm } from '../datasource/scdb';
|
|
10
|
+
import { MetaCache } from '../metadata';
|
|
9
11
|
import { Session } from '../session';
|
|
10
12
|
import { logger } from '../utils';
|
|
11
13
|
import { withErrorCode } from '../utils/error-code';
|
|
@@ -13,6 +15,7 @@ import { ConnectConfig } from './connect.types';
|
|
|
13
15
|
import { Http } from './http';
|
|
14
16
|
import { EventMessageType, MessageBuilder, MessageType, } from './message';
|
|
15
17
|
import { exponentialScheduler, linearScheduler, MAX_RECONNECT_ATTEMPTS, retryInterval, SocketReconnectStrategy, } from './reconnectStrategy';
|
|
18
|
+
import { resourceNameOf, ScdbStreamDecoder } from './scdbStreamDecoder';
|
|
16
19
|
import { onOtherTabReauthComplete, SessionRefreshResult, tryRefreshSession, waitForOtherTabReauth, } from './sessionRefresh';
|
|
17
20
|
import { SocketStatus } from './socket.status';
|
|
18
21
|
import { Ticker } from './ticker';
|
|
@@ -135,10 +138,17 @@ let DefaultSocket = class DefaultSocket {
|
|
|
135
138
|
this.defaultInterval = 10000;
|
|
136
139
|
this.secondsMultiplier = 1000;
|
|
137
140
|
this.sessionCheckTimeout = 10000;
|
|
141
|
+
this.scdbWasmRequested = false;
|
|
138
142
|
this.heartbeatIsEnabled = true;
|
|
139
143
|
this.heartbeatInterval = this.defaultInterval;
|
|
140
144
|
this.socketMessages = () => this.wsMessages;
|
|
141
145
|
}
|
|
146
|
+
/** Makes SCDB columnar payloads transparent (no-op unless an encoding was negotiated). */
|
|
147
|
+
get scdbDecoder() {
|
|
148
|
+
var _a;
|
|
149
|
+
(_a = this._scdbDecoder) !== null && _a !== void 0 ? _a : (this._scdbDecoder = new ScdbStreamDecoder(this.metaCache));
|
|
150
|
+
return this._scdbDecoder;
|
|
151
|
+
}
|
|
142
152
|
get heartbeatLoggingIsEnabled() {
|
|
143
153
|
var _a, _b;
|
|
144
154
|
return (_b = (_a = this.connectOptions) === null || _a === void 0 ? void 0 : _a.enableHeartbeatLogging) !== null && _b !== void 0 ? _b : false;
|
|
@@ -148,11 +158,15 @@ let DefaultSocket = class DefaultSocket {
|
|
|
148
158
|
return (_b = (_a = this.connectOptions) === null || _a === void 0 ? void 0 : _a.enableMessageLogging) !== null && _b !== void 0 ? _b : false;
|
|
149
159
|
}
|
|
150
160
|
connect(host = GENESIS_SOCKET_URL, connectOptions, reconnectOptions) {
|
|
151
|
-
var _a;
|
|
161
|
+
var _a, _b;
|
|
152
162
|
this.url = host;
|
|
153
163
|
this.connectOptions = connectOptions !== null && connectOptions !== void 0 ? connectOptions : this.config.connect;
|
|
154
164
|
this.reconnectOptions = reconnectOptions !== null && reconnectOptions !== void 0 ? reconnectOptions : this.config.reconnect;
|
|
155
|
-
|
|
165
|
+
// Pre-warm the WASM fast-path when binary is the app-wide default; per-datasource opt-ins warm it
|
|
166
|
+
// lazily on the first SCDB_V1 payload (see the receive path).
|
|
167
|
+
if (((_a = this.connectOptions) === null || _a === void 0 ? void 0 : _a.dataserverEncoding) === 'SCDB_V1')
|
|
168
|
+
this.ensureScdbWasm();
|
|
169
|
+
if (!((_b = this.config.isWebSocketExpression) === null || _b === void 0 ? void 0 : _b.test(this.host))) {
|
|
156
170
|
logger.error(`Specified host (${this.host}) is not valid WebSocket url. Connection will not proceed.`);
|
|
157
171
|
logger.warn(`Make sure the host url starts with wss:// or ws://`);
|
|
158
172
|
return;
|
|
@@ -190,6 +204,7 @@ let DefaultSocket = class DefaultSocket {
|
|
|
190
204
|
deserializer: (event) => this.serializer.deserialize(event),
|
|
191
205
|
});
|
|
192
206
|
const onNextMessage = (receivedMessage) => __awaiter(this, void 0, void 0, function* () {
|
|
207
|
+
var _a;
|
|
193
208
|
const responseMessageReceivedLog = `Response Message received for SourceRef: ${receivedMessage.SOURCE_REF} | MessageType: ${receivedMessage.MESSAGE_TYPE}`;
|
|
194
209
|
this.logMessageTypeFlow(receivedMessage.MESSAGE_TYPE, logger.info, responseMessageReceivedLog);
|
|
195
210
|
const { SOURCE_REF, MESSAGE_TYPE } = receivedMessage;
|
|
@@ -214,6 +229,8 @@ let DefaultSocket = class DefaultSocket {
|
|
|
214
229
|
return;
|
|
215
230
|
}
|
|
216
231
|
case MessageType.LOGON_ACK:
|
|
232
|
+
// Resolve the SCDB column dictionary (from metadata) before LOGON_ACK is dropped.
|
|
233
|
+
this.scdbDecoder.onLogonAck(receivedMessage, resourceNameOf(messageHandler.sentMessage));
|
|
217
234
|
return;
|
|
218
235
|
case MessageType.LOGOFF_ACK: {
|
|
219
236
|
break;
|
|
@@ -230,6 +247,30 @@ let DefaultSocket = class DefaultSocket {
|
|
|
230
247
|
break;
|
|
231
248
|
}
|
|
232
249
|
}
|
|
250
|
+
// A binary payload lazily warms the WASM fast-path (covers per-datasource opt-ins too).
|
|
251
|
+
if ((receivedMessage === null || receivedMessage === void 0 ? void 0 : receivedMessage.ENCODING) === 'SCDB_V1')
|
|
252
|
+
this.ensureScdbWasm();
|
|
253
|
+
try {
|
|
254
|
+
this.scdbDecoder.onMessage(receivedMessage, resourceNameOf(messageHandler.sentMessage));
|
|
255
|
+
}
|
|
256
|
+
catch (error) {
|
|
257
|
+
logger.error(`Failed to decode ${MESSAGE_TYPE} for SourceRef: ${SOURCE_REF}`, error);
|
|
258
|
+
// The server will not resend this batch, so the stream stops being handled.
|
|
259
|
+
const nack = {
|
|
260
|
+
SOURCE_REF,
|
|
261
|
+
MESSAGE_TYPE: MessageType.MSG_NACK,
|
|
262
|
+
ERROR: [
|
|
263
|
+
{ CODE: 'SCDB_DECODE_FAILED', TEXT: String((_a = error === null || error === void 0 ? void 0 : error.message) !== null && _a !== void 0 ? _a : error) },
|
|
264
|
+
],
|
|
265
|
+
};
|
|
266
|
+
messageHandler.onReceivedError.call(this, {
|
|
267
|
+
receivedMessage: nack,
|
|
268
|
+
sentMessage: messageHandler.sentMessage,
|
|
269
|
+
});
|
|
270
|
+
this.removeMessageHandler(SOURCE_REF);
|
|
271
|
+
this.wsMessages.next(nack);
|
|
272
|
+
return;
|
|
273
|
+
}
|
|
233
274
|
if (nacked) {
|
|
234
275
|
messageHandler.onReceivedError.call(this, {
|
|
235
276
|
receivedMessage,
|
|
@@ -448,6 +489,7 @@ let DefaultSocket = class DefaultSocket {
|
|
|
448
489
|
this.wsMessages && this.wsMessages.complete();
|
|
449
490
|
this.wsMessages = new SocketSubject();
|
|
450
491
|
this.wsMessageHandlers = new Map();
|
|
492
|
+
this.scdbDecoder.clear();
|
|
451
493
|
}
|
|
452
494
|
send(message, needsHandling = true) {
|
|
453
495
|
if (!this.isConnected) {
|
|
@@ -455,6 +497,7 @@ let DefaultSocket = class DefaultSocket {
|
|
|
455
497
|
}
|
|
456
498
|
const sendingMessasgeLog = `Sending Message for SourceRef: ${message.SOURCE_REF} | MessageType: ${message.MESSAGE_TYPE}`;
|
|
457
499
|
this.logMessageTypeFlow(message.MESSAGE_TYPE, logger.info, sendingMessasgeLog);
|
|
500
|
+
this.scdbDecoder.prepareRequest(message);
|
|
458
501
|
return new Promise((resolve, reject) => {
|
|
459
502
|
const onMessage = (msg) => {
|
|
460
503
|
resolve(msg);
|
|
@@ -474,6 +517,7 @@ let DefaultSocket = class DefaultSocket {
|
|
|
474
517
|
}
|
|
475
518
|
const sendingMessageLog = `Sending Message (stream) for SourceRef: ${message.SOURCE_REF} | MessageType: ${message.MESSAGE_TYPE}`;
|
|
476
519
|
this.logMessageTypeFlow(message.MESSAGE_TYPE, logger.info, sendingMessageLog);
|
|
520
|
+
this.scdbDecoder.prepareRequest(message);
|
|
477
521
|
this.setMessageHandler(message, onMessage, onError, true);
|
|
478
522
|
/**
|
|
479
523
|
* We need to queue these outgoing messages to allow the consumers to subscribe in time. We should review the entire
|
|
@@ -513,6 +557,7 @@ let DefaultSocket = class DefaultSocket {
|
|
|
513
557
|
}
|
|
514
558
|
const sendingMessageLog = `Sending Message (stream) for SourceRef: ${message.SOURCE_REF} | MessageType: ${message.MESSAGE_TYPE}`;
|
|
515
559
|
this.logMessageTypeFlow(message.MESSAGE_TYPE, logger.info, sendingMessageLog);
|
|
560
|
+
this.scdbDecoder.prepareRequest(message);
|
|
516
561
|
this.setMessageHandler(message, onMessage, onError, true);
|
|
517
562
|
this.websocket.next(message);
|
|
518
563
|
return this.wsMessages.pipe(filter((msg) => msg.SOURCE_REF === message.SOURCE_REF));
|
|
@@ -528,6 +573,28 @@ let DefaultSocket = class DefaultSocket {
|
|
|
528
573
|
removeMessageHandler(sourceRef) {
|
|
529
574
|
this.wsMessageHandlers.delete(sourceRef);
|
|
530
575
|
}
|
|
576
|
+
/**
|
|
577
|
+
* Wires the SCDB decoder's metadata-refresh hook, used to fetch a resource's missing or stale
|
|
578
|
+
* metadata. The host passes a force-refresh, e.g. `Connect.getMetadata(resource, false)`.
|
|
579
|
+
*/
|
|
580
|
+
setScdbMetadataRefresher(refresher) {
|
|
581
|
+
this.scdbDecoder.setMetadataRefresher(refresher);
|
|
582
|
+
}
|
|
583
|
+
/**
|
|
584
|
+
* Loads the bundled WASM decoder for the `SCDB_V1` binary encoding once (lazy, idempotent). Called
|
|
585
|
+
* eagerly when the app-wide `dataserverEncoding` is binary, and on demand the first time a binary
|
|
586
|
+
* payload is seen (so a per-datasource/grid `encoding: 'SCDB_V1'` also gets the fast-path, not just
|
|
587
|
+
* the app-wide opt-in). On any failure (no WebAssembly, CSP, SSR) we silently keep the pure-JS
|
|
588
|
+
* decoder — output is identical.
|
|
589
|
+
*/
|
|
590
|
+
ensureScdbWasm() {
|
|
591
|
+
if (this.scdbWasmRequested)
|
|
592
|
+
return;
|
|
593
|
+
this.scdbWasmRequested = true;
|
|
594
|
+
getDefaultScdbWasm()
|
|
595
|
+
.then((wasm) => this.scdbDecoder.setWasm(wasm))
|
|
596
|
+
.catch((err) => logger.warn('SCDB WASM decoder unavailable, using pure-JS decoder', err));
|
|
597
|
+
}
|
|
531
598
|
getMessageHandler(sourceRef, messageType) {
|
|
532
599
|
const gettingMessageHandlerLog = `Getting Message Handler for SourceRef: ${sourceRef} | MessageType: ${messageType}`;
|
|
533
600
|
this.logMessageTypeFlow(messageType, logger.debug, gettingMessageHandlerLog);
|
|
@@ -564,6 +631,9 @@ __decorate([
|
|
|
564
631
|
__decorate([
|
|
565
632
|
Http
|
|
566
633
|
], DefaultSocket.prototype, "http", void 0);
|
|
634
|
+
__decorate([
|
|
635
|
+
MetaCache
|
|
636
|
+
], DefaultSocket.prototype, "metaCache", void 0);
|
|
567
637
|
__decorate([
|
|
568
638
|
observable
|
|
569
639
|
], DefaultSocket.prototype, "heartbeatIsEnabled", void 0);
|
|
@@ -170,6 +170,7 @@ let DefaultDatasource = class DefaultDatasource {
|
|
|
170
170
|
MAX_VIEW: this.options.maxView,
|
|
171
171
|
MOVING_VIEW: this.options.movingView,
|
|
172
172
|
REVERSE: this.options.reverse,
|
|
173
|
+
ENCODING: this.options.encoding,
|
|
173
174
|
// REQUEST_SERVER only
|
|
174
175
|
DISABLE_POLLING: this.options.disablePolling, // component-level only
|
|
175
176
|
OFFSET: this.options.offset,
|
|
@@ -192,6 +193,7 @@ let DefaultDatasource = class DefaultDatasource {
|
|
|
192
193
|
MOVING_VIEW: this.allResourceParams.MOVING_VIEW,
|
|
193
194
|
ORDER_BY: this.allResourceParams.ORDER_BY,
|
|
194
195
|
REVERSE: this.allResourceParams.REVERSE,
|
|
196
|
+
ENCODING: this.allResourceParams.ENCODING,
|
|
195
197
|
};
|
|
196
198
|
}
|
|
197
199
|
/**
|
|
@@ -206,6 +208,7 @@ let DefaultDatasource = class DefaultDatasource {
|
|
|
206
208
|
OFFSET: DETAILS.OFFSET,
|
|
207
209
|
ORDER_BY: DETAILS.ORDER_BY,
|
|
208
210
|
VIEW_NUMBER: DETAILS.VIEW_NUMBER,
|
|
211
|
+
ENCODING: DETAILS.ENCODING,
|
|
209
212
|
},
|
|
210
213
|
REQUEST: this.criteriaOnlyRequest ? {} : (REQUEST !== null && REQUEST !== void 0 ? REQUEST : this.buildRequestFields()),
|
|
211
214
|
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Decodes a base64 string to bytes in both browser (`atob`) and Node/SSR (`Buffer`) runtimes.
|
|
3
|
+
* The SCDB `RBUF` payload (over JSON transports) and the inlined wasm module both arrive as base64.
|
|
4
|
+
*/
|
|
5
|
+
export function base64ToBytes(b64) {
|
|
6
|
+
var _a;
|
|
7
|
+
if (typeof atob === 'function') {
|
|
8
|
+
const bin = atob(b64);
|
|
9
|
+
const out = new Uint8Array(bin.length);
|
|
10
|
+
for (let i = 0; i < bin.length; i += 1)
|
|
11
|
+
out[i] = bin.charCodeAt(i);
|
|
12
|
+
return out;
|
|
13
|
+
}
|
|
14
|
+
// Node / SSR (avoids a hard @types/node dependency)
|
|
15
|
+
const buf = (_a = globalThis.Buffer) === null || _a === void 0 ? void 0 : _a.from(b64, 'base64');
|
|
16
|
+
return buf ? Uint8Array.from(buf) : new Uint8Array(0);
|
|
17
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/* oxlint-disable no-magic-numbers, no-plusplus -- FNV-1a hashing uses fixed prime/offset constants and byte loops */
|
|
2
|
+
/**
|
|
3
|
+
* Dictionary derivation + fingerprinting for the metadata-driven dictionary mechanism.
|
|
4
|
+
*
|
|
5
|
+
* The server no longer ships the column dictionary; instead the client derives it from the resource
|
|
6
|
+
* metadata it already holds (`id = index` into the ordered field list) and validates it against a
|
|
7
|
+
* small hash the server sends with the columnar payload. A columnar message that fails validation
|
|
8
|
+
* is not decoded.
|
|
9
|
+
*/
|
|
10
|
+
/**
|
|
11
|
+
* FNV-1a 32-bit hash of the field names joined by '\n', as lowercase 8-char hex. MUST match the
|
|
12
|
+
* Kotlin `ColumnDictionary.contentHash` in genesis-columnar (cross-language vector:
|
|
13
|
+
* ['QUANTITY','PRICE','SYMBOL'] -> '40e6db4f').
|
|
14
|
+
*
|
|
15
|
+
* Hashes UTF-16 code units (`charCodeAt`), matching Kotlin's `Char.code` — NOT the UTF-8 bytes used for
|
|
16
|
+
* on-wire strings. Field names are ASCII in practice so the two coincide; keep both ends on UTF-16 units
|
|
17
|
+
* (do not switch to UTF-8 bytes) or a non-ASCII field name would hash differently across languages.
|
|
18
|
+
*/
|
|
19
|
+
export function dictionaryHash(fieldNames) {
|
|
20
|
+
let h = 0x811c9dc5;
|
|
21
|
+
const joined = fieldNames.join('\n');
|
|
22
|
+
for (let i = 0; i < joined.length; i++) {
|
|
23
|
+
h ^= joined.charCodeAt(i);
|
|
24
|
+
h = Math.imul(h, 0x01000193); // 32-bit FNV prime multiply
|
|
25
|
+
}
|
|
26
|
+
return (h >>> 0).toString(16).padStart(8, '0');
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Ordered field-name list (the SCDB dictionary) for a resource, from its metadata. The order MUST
|
|
30
|
+
* match the server's, which derives the dictionary per resource type: a DATASERVER hashes its `FIELD`
|
|
31
|
+
* list, a REQUEST_SERVER its `REPLY_FIELD` (⇒ `REPLY.FIELD`) list. Selecting by `TYPE` — rather than
|
|
32
|
+
* "first non-null" — matters because a metadata object can legitimately carry BOTH `FIELD` and
|
|
33
|
+
* `REPLY_FIELD`; picking the wrong one yields a hash that never matches the server's `DICT_HASH`, so
|
|
34
|
+
* no columnar message for that resource can be decoded. Falls back to a lenient scan for unknown types.
|
|
35
|
+
*/
|
|
36
|
+
export function dictionaryFromMetadata(metadata) {
|
|
37
|
+
var _a, _b, _c, _d, _e;
|
|
38
|
+
const replyFields = (_a = metadata.REPLY_FIELD) !== null && _a !== void 0 ? _a : (_b = metadata.REPLY) === null || _b === void 0 ? void 0 : _b.FIELD;
|
|
39
|
+
const fields = metadata.TYPE === 'REQUEST_SERVER'
|
|
40
|
+
? (replyFields !== null && replyFields !== void 0 ? replyFields : [])
|
|
41
|
+
: metadata.TYPE === 'DATASERVER'
|
|
42
|
+
? ((_c = metadata.FIELD) !== null && _c !== void 0 ? _c : [])
|
|
43
|
+
: ((_e = (_d = metadata.FIELD) !== null && _d !== void 0 ? _d : replyFields) !== null && _e !== void 0 ? _e : []);
|
|
44
|
+
return fields.map((f) => f.NAME);
|
|
45
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
{
|
|
2
|
+
"format": "scdb-v1",
|
|
3
|
+
"comment": "Shared cross-language conformance fixture for the SCDB v1 wire format. The canonical input batches are defined in prose in docs/scdb-v1.md and constructed identically in the Kotlin (ScdbConformanceTest) and JavaScript (foundation-ui) test suites. Each entry pins the exact encoded bytes (lowercase hex). Both ends assert encode(case)==hex and decode(hex)==case. Do not edit by hand; regenerate if the format changes and update both decoders.",
|
|
4
|
+
"vectors": {
|
|
5
|
+
"mixed-tristate": "53434431020301310132103930303731393932353437343039393301030000000101c8010100000303402400000000000009020000040005564f442e4c",
|
|
6
|
+
"string-dict": "5343443102030131013201330101030101020641435449564506434c4f534544010102",
|
|
7
|
+
"deletes-only": "534344310202013501360200",
|
|
8
|
+
"empty": "53434431000000",
|
|
9
|
+
"delta-longs": "53434431020301310132013300010002010280c0a8ca9a3a0a0c",
|
|
10
|
+
"delta-longs-highbit": "534344310203013101320133000100020102faffffffffffffffff010202",
|
|
11
|
+
"delta-longs-straddle-2p53": "534344310203013101320133000100020102feffffffffffff1f0404",
|
|
12
|
+
"delta-datetimes": "53434431020301310132013300010002010880a0abfef962d00fb817",
|
|
13
|
+
"delta-longs-negative": "53434431020301310132013300010002010280a8d6b90763ac02"
|
|
14
|
+
}
|
|
15
|
+
}
|