@lsmsgpack/client 0.0.0-stage → 2026.10.2901
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/README.md +39 -3
- package/dist/client.d.ts +76 -0
- package/dist/client.js +150 -0
- package/dist/client.js.map +1 -0
- package/dist/decoder.d.ts +180 -0
- package/dist/decoder.js +738 -0
- package/dist/decoder.js.map +1 -0
- package/dist/errors.d.ts +18 -0
- package/dist/errors.js +28 -0
- package/dist/errors.js.map +1 -0
- package/dist/index.d.ts +19 -0
- package/dist/index.js +11 -0
- package/dist/index.js.map +1 -0
- package/dist/models.d.ts +56 -0
- package/dist/models.js +64 -0
- package/dist/models.js.map +1 -0
- package/dist/names.d.ts +9 -0
- package/dist/names.js +37 -0
- package/dist/names.js.map +1 -0
- package/dist/reader.d.ts +62 -0
- package/dist/reader.js +338 -0
- package/dist/reader.js.map +1 -0
- package/dist/schema.d.ts +76 -0
- package/dist/schema.js +107 -0
- package/dist/schema.js.map +1 -0
- package/dist/sha256.d.ts +4 -0
- package/dist/sha256.js +75 -0
- package/dist/sha256.js.map +1 -0
- package/dist/store.d.ts +49 -0
- package/dist/store.js +148 -0
- package/dist/store.js.map +1 -0
- package/dist/values.d.ts +34 -0
- package/dist/values.js +169 -0
- package/dist/values.js.map +1 -0
- package/dist/writer.d.ts +18 -0
- package/dist/writer.js +685 -0
- package/dist/writer.js.map +1 -0
- package/package.json +38 -6
package/dist/reader.js
ADDED
|
@@ -0,0 +1,338 @@
|
|
|
1
|
+
// A MsgPack reader for all formats of the specification, with LsMsgPack's extensions (timestamps -1, decimal 1, big integers -2).
|
|
2
|
+
// The schema-aware reader (decoder.ts) derives from it: array() and map() are the places it hooks into.
|
|
3
|
+
import { MsgPackError } from './errors.js';
|
|
4
|
+
import { decodeDecimal } from './values.js';
|
|
5
|
+
/** An extension type the reader does not know (as LtMsgPack's MsgPackExtension). */
|
|
6
|
+
export class MsgPackExtension {
|
|
7
|
+
constructor(type, data) {
|
|
8
|
+
this.type = type;
|
|
9
|
+
this.data = data;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
const textDecoder = new TextDecoder('utf-8', { fatal: false });
|
|
13
|
+
const twoPow32 = 4294967296;
|
|
14
|
+
export class MsgPackReader {
|
|
15
|
+
constructor(bytes, options, pos = 0) {
|
|
16
|
+
this.depth = 0;
|
|
17
|
+
this.bytes = bytes;
|
|
18
|
+
this.view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
|
|
19
|
+
this.pos = pos;
|
|
20
|
+
this.maxDepth = options?.maxDepth ?? 256;
|
|
21
|
+
this.decimal = options?.decimal ?? 'number';
|
|
22
|
+
}
|
|
23
|
+
get remaining() {
|
|
24
|
+
return this.bytes.length - this.pos;
|
|
25
|
+
}
|
|
26
|
+
/** The next byte, without reading it. */
|
|
27
|
+
peek() {
|
|
28
|
+
if (this.pos >= this.bytes.length)
|
|
29
|
+
throw this.endOfData();
|
|
30
|
+
return this.bytes[this.pos];
|
|
31
|
+
}
|
|
32
|
+
endOfData() {
|
|
33
|
+
return new MsgPackError('Unexpected end of data.', this.pos);
|
|
34
|
+
}
|
|
35
|
+
/** Throws when fewer than count bytes are left (checked before anything is allocated for a length read from the data). */
|
|
36
|
+
need(count) {
|
|
37
|
+
if (count > this.bytes.length - this.pos)
|
|
38
|
+
throw this.endOfData();
|
|
39
|
+
}
|
|
40
|
+
u8() {
|
|
41
|
+
if (this.pos >= this.bytes.length)
|
|
42
|
+
throw this.endOfData();
|
|
43
|
+
return this.bytes[this.pos++];
|
|
44
|
+
}
|
|
45
|
+
u16() {
|
|
46
|
+
this.need(2);
|
|
47
|
+
const v = this.view.getUint16(this.pos);
|
|
48
|
+
this.pos += 2;
|
|
49
|
+
return v;
|
|
50
|
+
}
|
|
51
|
+
u32() {
|
|
52
|
+
this.need(4);
|
|
53
|
+
const v = this.view.getUint32(this.pos);
|
|
54
|
+
this.pos += 4;
|
|
55
|
+
return v;
|
|
56
|
+
}
|
|
57
|
+
/** A 64 bit integer: a number when it is safe, otherwise a bigint (no precision is lost). */
|
|
58
|
+
i64(signed) {
|
|
59
|
+
this.need(8);
|
|
60
|
+
const hi = signed ? this.view.getInt32(this.pos) : this.view.getUint32(this.pos);
|
|
61
|
+
const lo = this.view.getUint32(this.pos + 4);
|
|
62
|
+
const pos = this.pos;
|
|
63
|
+
this.pos += 8;
|
|
64
|
+
const n = hi * twoPow32 + lo;
|
|
65
|
+
if (Number.isSafeInteger(n))
|
|
66
|
+
return n;
|
|
67
|
+
return signed ? this.view.getBigInt64(pos) : this.view.getBigUint64(pos);
|
|
68
|
+
}
|
|
69
|
+
/** A string of the given number of UTF-8 bytes. */
|
|
70
|
+
str(length) {
|
|
71
|
+
this.need(length);
|
|
72
|
+
const bytes = this.bytes;
|
|
73
|
+
const start = this.pos;
|
|
74
|
+
this.pos += length;
|
|
75
|
+
if (length <= 32) { // short ASCII strings (property values, keys) without the decoder call: the codes in an array, one fromCharCode (+= per character was 25% slower, TextDecoder wins beyond 32)
|
|
76
|
+
const codes = new Array(length);
|
|
77
|
+
for (let t = 0; t < length; t++) {
|
|
78
|
+
const c = bytes[start + t];
|
|
79
|
+
if (c > 127)
|
|
80
|
+
return textDecoder.decode(bytes.subarray(start, start + length));
|
|
81
|
+
codes[t] = c;
|
|
82
|
+
}
|
|
83
|
+
return String.fromCharCode.apply(null, codes);
|
|
84
|
+
}
|
|
85
|
+
return textDecoder.decode(bytes.subarray(start, start + length));
|
|
86
|
+
}
|
|
87
|
+
/** A copy, so the result does not keep the whole payload alive. */
|
|
88
|
+
bin(length) {
|
|
89
|
+
this.need(length);
|
|
90
|
+
const result = this.bytes.slice(this.pos, this.pos + length);
|
|
91
|
+
this.pos += length;
|
|
92
|
+
return result;
|
|
93
|
+
}
|
|
94
|
+
/** Any value. */
|
|
95
|
+
value() {
|
|
96
|
+
const b = this.u8();
|
|
97
|
+
if (b <= 0x7f)
|
|
98
|
+
return b;
|
|
99
|
+
if (b >= 0xe0)
|
|
100
|
+
return b - 256;
|
|
101
|
+
if (b >= 0xa0 && b <= 0xbf)
|
|
102
|
+
return this.str(b & 0x1f);
|
|
103
|
+
if (b >= 0x90 && b <= 0x9f)
|
|
104
|
+
return this.array(b & 0x0f);
|
|
105
|
+
if (b >= 0x80 && b <= 0x8f)
|
|
106
|
+
return this.map(b & 0x0f);
|
|
107
|
+
switch (b) {
|
|
108
|
+
case 0xc0: return null;
|
|
109
|
+
case 0xc2: return false;
|
|
110
|
+
case 0xc3: return true;
|
|
111
|
+
case 0xc4: return this.bin(this.u8());
|
|
112
|
+
case 0xc5: return this.bin(this.u16());
|
|
113
|
+
case 0xc6: return this.bin(this.u32());
|
|
114
|
+
case 0xc7: {
|
|
115
|
+
const n = this.u8();
|
|
116
|
+
return this.ext(this.i8(), n);
|
|
117
|
+
}
|
|
118
|
+
case 0xc8: {
|
|
119
|
+
const n = this.u16();
|
|
120
|
+
return this.ext(this.i8(), n);
|
|
121
|
+
}
|
|
122
|
+
case 0xc9: {
|
|
123
|
+
const n = this.u32();
|
|
124
|
+
return this.ext(this.i8(), n);
|
|
125
|
+
}
|
|
126
|
+
case 0xca: {
|
|
127
|
+
this.need(4);
|
|
128
|
+
const v = this.view.getFloat32(this.pos);
|
|
129
|
+
this.pos += 4;
|
|
130
|
+
return v;
|
|
131
|
+
}
|
|
132
|
+
case 0xcb: {
|
|
133
|
+
this.need(8);
|
|
134
|
+
const v = this.view.getFloat64(this.pos);
|
|
135
|
+
this.pos += 8;
|
|
136
|
+
return v;
|
|
137
|
+
}
|
|
138
|
+
case 0xcc: return this.u8();
|
|
139
|
+
case 0xcd: return this.u16();
|
|
140
|
+
case 0xce: return this.u32();
|
|
141
|
+
case 0xcf: return this.i64(false);
|
|
142
|
+
case 0xd0: return this.i8();
|
|
143
|
+
case 0xd1: {
|
|
144
|
+
this.need(2);
|
|
145
|
+
const v = this.view.getInt16(this.pos);
|
|
146
|
+
this.pos += 2;
|
|
147
|
+
return v;
|
|
148
|
+
}
|
|
149
|
+
case 0xd2: {
|
|
150
|
+
this.need(4);
|
|
151
|
+
const v = this.view.getInt32(this.pos);
|
|
152
|
+
this.pos += 4;
|
|
153
|
+
return v;
|
|
154
|
+
}
|
|
155
|
+
case 0xd3: return this.i64(true);
|
|
156
|
+
case 0xd4: return this.ext(this.i8(), 1);
|
|
157
|
+
case 0xd5: return this.ext(this.i8(), 2);
|
|
158
|
+
case 0xd6: return this.ext(this.i8(), 4);
|
|
159
|
+
case 0xd7: return this.ext(this.i8(), 8);
|
|
160
|
+
case 0xd8: return this.ext(this.i8(), 16);
|
|
161
|
+
case 0xd9: return this.str(this.u8());
|
|
162
|
+
case 0xda: return this.str(this.u16());
|
|
163
|
+
case 0xdb: return this.str(this.u32());
|
|
164
|
+
case 0xdc: return this.array(this.u16());
|
|
165
|
+
case 0xdd: return this.array(this.u32());
|
|
166
|
+
case 0xde: return this.map(this.u16());
|
|
167
|
+
case 0xdf: return this.map(this.u32());
|
|
168
|
+
}
|
|
169
|
+
throw new MsgPackError(`0x${b.toString(16)} is not a MsgPack type.`, this.pos - 1);
|
|
170
|
+
}
|
|
171
|
+
i8() {
|
|
172
|
+
const v = this.u8();
|
|
173
|
+
return v > 127 ? v - 256 : v;
|
|
174
|
+
}
|
|
175
|
+
/** The length of an array (its header is read), or -1 when the next value is not an array (nothing is read). */
|
|
176
|
+
arrayLength() {
|
|
177
|
+
const b = this.peek();
|
|
178
|
+
if (b >= 0x90 && b <= 0x9f) {
|
|
179
|
+
this.pos++;
|
|
180
|
+
return this.count(b & 0x0f);
|
|
181
|
+
}
|
|
182
|
+
if (b === 0xdc) {
|
|
183
|
+
this.pos++;
|
|
184
|
+
return this.count(this.u16());
|
|
185
|
+
}
|
|
186
|
+
if (b === 0xdd) {
|
|
187
|
+
this.pos++;
|
|
188
|
+
return this.count(this.u32());
|
|
189
|
+
}
|
|
190
|
+
return -1;
|
|
191
|
+
}
|
|
192
|
+
/** The number of entries of a map (its header is read), or -1 when the next value is not a map (nothing is read). */
|
|
193
|
+
mapLength() {
|
|
194
|
+
const b = this.peek();
|
|
195
|
+
if (b >= 0x80 && b <= 0x8f) {
|
|
196
|
+
this.pos++;
|
|
197
|
+
return this.count(b & 0x0f);
|
|
198
|
+
}
|
|
199
|
+
if (b === 0xde) {
|
|
200
|
+
this.pos++;
|
|
201
|
+
return this.count(this.u16());
|
|
202
|
+
}
|
|
203
|
+
if (b === 0xdf) {
|
|
204
|
+
this.pos++;
|
|
205
|
+
return this.count(this.u32());
|
|
206
|
+
}
|
|
207
|
+
return -1;
|
|
208
|
+
}
|
|
209
|
+
/** Every item takes at least a byte: a count beyond the rest of the data is refused before anything is allocated. */
|
|
210
|
+
count(n) {
|
|
211
|
+
if (n > this.bytes.length - this.pos)
|
|
212
|
+
throw this.endOfData();
|
|
213
|
+
return n;
|
|
214
|
+
}
|
|
215
|
+
/** The next value is a map whose first key is "" (a type id: { "": typeId, ... }). Reads nothing. */
|
|
216
|
+
startsWithTypeId() {
|
|
217
|
+
const b = this.bytes[this.pos];
|
|
218
|
+
let key;
|
|
219
|
+
if (b >= 0x81 && b <= 0x8f)
|
|
220
|
+
key = this.pos + 1;
|
|
221
|
+
else if (b === 0xde)
|
|
222
|
+
key = this.pos + 3;
|
|
223
|
+
else if (b === 0xdf)
|
|
224
|
+
key = this.pos + 5;
|
|
225
|
+
else
|
|
226
|
+
return false;
|
|
227
|
+
const k = this.bytes[key];
|
|
228
|
+
return k === 0xa0 || (k === 0xd9 && this.bytes[key + 1] === 0);
|
|
229
|
+
}
|
|
230
|
+
enter() {
|
|
231
|
+
if (++this.depth > this.maxDepth)
|
|
232
|
+
throw new MsgPackError(`The data is nested deeper than ${this.maxDepth} levels.`, this.pos);
|
|
233
|
+
}
|
|
234
|
+
array(n) {
|
|
235
|
+
this.count(n);
|
|
236
|
+
this.enter();
|
|
237
|
+
const result = new Array(n);
|
|
238
|
+
for (let t = 0; t < n; t++)
|
|
239
|
+
result[t] = this.value();
|
|
240
|
+
this.depth--;
|
|
241
|
+
return result;
|
|
242
|
+
}
|
|
243
|
+
/** A map with string keys becomes an object, other keys are converted to strings (as JSON does). */
|
|
244
|
+
map(n) {
|
|
245
|
+
this.count(n);
|
|
246
|
+
this.enter();
|
|
247
|
+
const result = {};
|
|
248
|
+
for (let t = 0; t < n; t++) {
|
|
249
|
+
const key = this.key();
|
|
250
|
+
const name = typeof key === 'string' ? key : String(key);
|
|
251
|
+
if (name === '__proto__')
|
|
252
|
+
Object.defineProperty(result, name, { value: this.value(), writable: true, enumerable: true, configurable: true }); // an own property, as JSON.parse makes it
|
|
253
|
+
else
|
|
254
|
+
result[name] = this.value();
|
|
255
|
+
}
|
|
256
|
+
this.depth--;
|
|
257
|
+
return result;
|
|
258
|
+
}
|
|
259
|
+
/** A map key: a fixstr through the key cache, anything else as a value. */
|
|
260
|
+
key() {
|
|
261
|
+
const bytes = this.bytes, p = this.pos, b = bytes[p];
|
|
262
|
+
if (b > 0xa0 && b <= 0xbf) {
|
|
263
|
+
const length = b & 0x1f;
|
|
264
|
+
if (p + 1 + length <= bytes.length) {
|
|
265
|
+
this.pos = p + 1;
|
|
266
|
+
return cachedKey(this, bytes, p + 1, length);
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
return this.value();
|
|
270
|
+
}
|
|
271
|
+
ext(type, length) {
|
|
272
|
+
this.need(length);
|
|
273
|
+
const start = this.pos;
|
|
274
|
+
if (type === -1)
|
|
275
|
+
return this.timestamp(length);
|
|
276
|
+
this.pos += length;
|
|
277
|
+
if (type === 1 && length === 16 && this.decimal !== 'raw')
|
|
278
|
+
return decodeDecimal(this.bytes, start, this.decimal);
|
|
279
|
+
if (type === -2)
|
|
280
|
+
return bigIntOf(this.bytes, start, length);
|
|
281
|
+
return new MsgPackExtension(type, this.bytes.slice(start, start + length));
|
|
282
|
+
}
|
|
283
|
+
/** The timestamp extension (type -1) as a Date (milliseconds: the nanoseconds below them are dropped). */
|
|
284
|
+
timestamp(length) {
|
|
285
|
+
const view = this.view;
|
|
286
|
+
const p = this.pos;
|
|
287
|
+
this.pos += length;
|
|
288
|
+
switch (length) {
|
|
289
|
+
case 4: return new Date(view.getUint32(p) * 1000);
|
|
290
|
+
case 8: {
|
|
291
|
+
const hi = view.getUint32(p);
|
|
292
|
+
const lo = view.getUint32(p + 4);
|
|
293
|
+
return new Date(((hi & 3) * twoPow32 + lo) * 1000 + Math.floor((hi >>> 2) / 1e6));
|
|
294
|
+
}
|
|
295
|
+
case 12: return new Date(Number(view.getBigInt64(p + 4)) * 1000 + Math.floor(view.getUint32(p) / 1e6));
|
|
296
|
+
}
|
|
297
|
+
throw new MsgPackError(`A timestamp of ${length} bytes is not valid.`, p);
|
|
298
|
+
}
|
|
299
|
+
/** Skips a value. */
|
|
300
|
+
skip() {
|
|
301
|
+
this.value();
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
// The keys of maps read by name repeat (the property names of every object): the same bytes give the same string instance, which V8 has hashed and internalized
|
|
305
|
+
// when it was first used as a property name, so setting the property does not hash new text again (decodePlain of 100 invoices with names: 3.4 -> 1.6 ms).
|
|
306
|
+
const KeySlots = 1024; // a power of two
|
|
307
|
+
const keyBytes = new Array(KeySlots);
|
|
308
|
+
const keyStrings = new Array(KeySlots);
|
|
309
|
+
function cachedKey(reader, bytes, start, length) {
|
|
310
|
+
let h = 0x811c9dc5; // FNV-1a
|
|
311
|
+
for (let t = start; t < start + length; t++)
|
|
312
|
+
h = Math.imul(h ^ bytes[t], 0x01000193);
|
|
313
|
+
const slot = (h ^ (h >>> 16)) & (KeySlots - 1);
|
|
314
|
+
const known = keyBytes[slot];
|
|
315
|
+
if (known !== undefined && known.length === length) {
|
|
316
|
+
let t = 0;
|
|
317
|
+
while (t < length && known[t] === bytes[start + t])
|
|
318
|
+
t++;
|
|
319
|
+
if (t === length) {
|
|
320
|
+
reader.pos = start + length;
|
|
321
|
+
return keyStrings[slot];
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
const key = reader.str(length);
|
|
325
|
+
keyBytes[slot] = bytes.slice(start, start + length);
|
|
326
|
+
keyStrings[slot] = key;
|
|
327
|
+
return key;
|
|
328
|
+
}
|
|
329
|
+
/** Extension type -2: a big-endian two's complement integer. */
|
|
330
|
+
export function bigIntOf(bytes, start, length) {
|
|
331
|
+
let value = 0n;
|
|
332
|
+
for (let t = start; t < start + length; t++)
|
|
333
|
+
value = (value << 8n) | BigInt(bytes[t]);
|
|
334
|
+
if (length > 0 && bytes[start] & 0x80)
|
|
335
|
+
value -= 1n << BigInt(length * 8);
|
|
336
|
+
return value;
|
|
337
|
+
}
|
|
338
|
+
//# sourceMappingURL=reader.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"reader.js","sourceRoot":"","sources":["../src/reader.ts"],"names":[],"mappings":"AAAA,kIAAkI;AAClI,wGAAwG;AAExG,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC3C,OAAO,EAAe,aAAa,EAAE,MAAM,aAAa,CAAC;AAEzD,oFAAoF;AACpF,MAAM,OAAO,gBAAgB;IAC3B,YAAqB,IAAY,EAAW,IAAgB;QAAvC,SAAI,GAAJ,IAAI,CAAQ;QAAW,SAAI,GAAJ,IAAI,CAAY;IAAG,CAAC;CACjE;AASD,MAAM,WAAW,GAAG,IAAI,WAAW,CAAC,OAAO,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC,CAAC;AAC/D,MAAM,QAAQ,GAAG,UAAU,CAAC;AAE5B,MAAM,OAAO,aAAa;IAQxB,YAAY,KAAiB,EAAE,OAAuB,EAAE,GAAG,GAAG,CAAC;QAJrD,UAAK,GAAG,CAAC,CAAC;QAKlB,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;QACnB,IAAI,CAAC,IAAI,GAAG,IAAI,QAAQ,CAAC,KAAK,CAAC,MAAM,EAAE,KAAK,CAAC,UAAU,EAAE,KAAK,CAAC,UAAU,CAAC,CAAC;QAC3E,IAAI,CAAC,GAAG,GAAG,G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C,KAAK,MAAM,EAAE,CAAC;YACjB,MAAM,CAAC,GAAG,GAAG,KAAK,GAAG,MAAM,CAAC;YAC5B,OAAO,UAAU,CAAC,IAAI,CAAC,CAAC;QAC1B,CAAC;IACH,CAAC;IACD,MAAM,GAAG,GAAG,MAAM,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;IAC/B,QAAQ,CAAC,IAAI,CAAC,GAAG,KAAK,CAAC,KAAK,CAAC,KAAK,EAAE,KAAK,GAAG,MAAM,CAAC,CAAC;IACpD,UAAU,CAAC,IAAI,CAAC,GAAG,GAAG,CAAC;IACvB,OAAO,GAAG,CAAC;AACb,CAAC;AAED,gEAAgE;AAChE,MAAM,UAAU,QAAQ,CAAC,KAAiB,EAAE,KAAa,EAAE,MAAc;IACvE,IAAI,KAAK,GAAG,EAAE,CAAC;IACf,KAAK,IAAI,CAAC,GAAG,KAAK,EAAE,CAAC,GAAG,KAAK,GAAG,MAAM,EAAE,CAAC,EAAE;QAAE,KAAK,GAAG,CAAC,KAAK,IAAI,EAAE,CAAC,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;IACtF,IAAI,MAAM,GAAG,CAAC,IAAI,KAAK,CAAC,KAAK,CAAC,GAAG,IAAI;QAAE,KAAK,IAAI,EAAE,IAAI,MAAM,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;IACzE,OAAO,KAAK,CAAC;AACf,CAAC"}
|
package/dist/schema.d.ts
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
/** The kinds of the described schema (an unknown kind is read as 'any'). */
|
|
2
|
+
export type Kind = 'string' | 'bool' | 'int' | 'long' | 'ulong' | 'float' | 'decimal' | 'char' | 'bigint' | 'guid' | 'bin' | 'uri' | 'datetime' | 'dto' | 'dto-clock' | 'timespan' | 'dateonly' | 'timeonly' | 'any';
|
|
3
|
+
/** The declared type of a property, as the described schema gives it. */
|
|
4
|
+
export type TypeExpr = {
|
|
5
|
+
k: 'kind';
|
|
6
|
+
kind: Kind;
|
|
7
|
+
}
|
|
8
|
+
/** An object of a schema entry (by index), or of a struct the schema has no entry for (only its default was written so far: its properties inline). */
|
|
9
|
+
| {
|
|
10
|
+
k: 'object';
|
|
11
|
+
entry: number | SchemaEntry;
|
|
12
|
+
struct: boolean;
|
|
13
|
+
} | {
|
|
14
|
+
k: 'nullable';
|
|
15
|
+
of: TypeExpr;
|
|
16
|
+
} | {
|
|
17
|
+
k: 'list';
|
|
18
|
+
of: TypeExpr;
|
|
19
|
+
} | {
|
|
20
|
+
k: 'dict';
|
|
21
|
+
key: TypeExpr;
|
|
22
|
+
value: TypeExpr;
|
|
23
|
+
} | {
|
|
24
|
+
k: 'pair';
|
|
25
|
+
key: TypeExpr;
|
|
26
|
+
value: TypeExpr;
|
|
27
|
+
} | {
|
|
28
|
+
k: 'tuple';
|
|
29
|
+
items: TypeExpr[];
|
|
30
|
+
}
|
|
31
|
+
/** A class of the models by its type name (generated models, see models.ts): the entry of that name in the schema of the payload. */
|
|
32
|
+
| {
|
|
33
|
+
k: 'model';
|
|
34
|
+
name: string;
|
|
35
|
+
struct: boolean;
|
|
36
|
+
};
|
|
37
|
+
export declare const AnyType: TypeExpr;
|
|
38
|
+
export interface SchemaProperty {
|
|
39
|
+
readonly name: string;
|
|
40
|
+
/** Undefined in a plain schema. */
|
|
41
|
+
readonly type?: TypeExpr;
|
|
42
|
+
/** The [DefaultValue] of the property, as read (converted when the plans are made). */
|
|
43
|
+
readonly default?: unknown;
|
|
44
|
+
readonly hasDefault: boolean;
|
|
45
|
+
}
|
|
46
|
+
export interface SchemaEntry {
|
|
47
|
+
/** The type name of the writer (short by default, may repeat: entries are found by index). */
|
|
48
|
+
readonly name: string | null;
|
|
49
|
+
/** By position: the index of a property in the data. */
|
|
50
|
+
readonly properties: readonly SchemaProperty[];
|
|
51
|
+
/** The content of a value of this type wrapped with a type id ({ "": index, "@": content }): set for collections and values that are not objects. */
|
|
52
|
+
readonly content?: TypeExpr;
|
|
53
|
+
}
|
|
54
|
+
/** The format version hashed before the bytes of a schema (SchemaId.FormatVersion) and of a described schema (SchemaId.DescribedFormatVersion). */
|
|
55
|
+
export declare const PlainVersion = 1;
|
|
56
|
+
export declare const DescribedVersion = 2;
|
|
57
|
+
export declare class Schema {
|
|
58
|
+
readonly bytes: Uint8Array;
|
|
59
|
+
private _byName?;
|
|
60
|
+
/** The index of the entry with the type name (the first one: short names may repeat), -1 when there is none. */
|
|
61
|
+
indexOf(name: string): number;
|
|
62
|
+
/** The entries the type ids of the data refer to (without the root entry of a described schema). */
|
|
63
|
+
readonly entries: readonly SchemaEntry[];
|
|
64
|
+
/** The declared type of the root (described schemas only). */
|
|
65
|
+
readonly root?: TypeExpr;
|
|
66
|
+
readonly described: boolean;
|
|
67
|
+
/** @param bytes the schema exactly as it was received (its id is computed over them) */
|
|
68
|
+
constructor(bytes: Uint8Array);
|
|
69
|
+
/** The id (32 hex digits) of these bytes as a schema of the given version: the first 16 bytes of SHA-256(version + bytes). */
|
|
70
|
+
static idOf(bytes: Uint8Array, version: number): string;
|
|
71
|
+
private _id?;
|
|
72
|
+
/** The id the server gives this schema (the version follows from the form: described or plain). */
|
|
73
|
+
get id(): string;
|
|
74
|
+
}
|
|
75
|
+
/** Parses a type expression of the described schema. Unknown kinds and forms are read as 'any' (a newer server). */
|
|
76
|
+
export declare function parseType(value: unknown): TypeExpr;
|
package/dist/schema.js
ADDED
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
// The indexed schema of application/x-lsmsgpack: { typeName: [propertyName, ...] }, or the described schema (docs/TypeScriptClient.md#the-described-schema)
|
|
2
|
+
// where each property is [name, type] or [name, type, default], a non-object entry has ["@", type] and the last entry "" describes the root.
|
|
3
|
+
import { MsgPackError } from './errors.js';
|
|
4
|
+
import { MsgPackReader } from './reader.js';
|
|
5
|
+
import { sha256, toHex } from './sha256.js';
|
|
6
|
+
const Kinds = new Set(['string', 'bool', 'int', 'long', 'ulong', 'float', 'decimal', 'char', 'bigint', 'guid', 'bin', 'uri',
|
|
7
|
+
'datetime', 'dto', 'dto-clock', 'timespan', 'dateonly', 'timeonly', 'any']);
|
|
8
|
+
export const AnyType = { k: 'kind', kind: 'any' };
|
|
9
|
+
/** The format version hashed before the bytes of a schema (SchemaId.FormatVersion) and of a described schema (SchemaId.DescribedFormatVersion). */
|
|
10
|
+
export const PlainVersion = 1;
|
|
11
|
+
export const DescribedVersion = 2;
|
|
12
|
+
export class Schema {
|
|
13
|
+
/** The index of the entry with the type name (the first one: short names may repeat), -1 when there is none. */
|
|
14
|
+
indexOf(name) {
|
|
15
|
+
if (this._byName === undefined) {
|
|
16
|
+
this._byName = new Map();
|
|
17
|
+
for (let t = this.entries.length - 1; t >= 0; t--)
|
|
18
|
+
if (this.entries[t].name !== null)
|
|
19
|
+
this._byName.set(this.entries[t].name, t);
|
|
20
|
+
}
|
|
21
|
+
return this._byName.get(name) ?? -1;
|
|
22
|
+
}
|
|
23
|
+
/** @param bytes the schema exactly as it was received (its id is computed over them) */
|
|
24
|
+
constructor(bytes) {
|
|
25
|
+
this.bytes = bytes;
|
|
26
|
+
const r = new MsgPackReader(bytes, { decimal: 'raw' }); // defaults are converted per the client's options when the plans are made
|
|
27
|
+
const count = r.mapLength();
|
|
28
|
+
if (count < 0)
|
|
29
|
+
throw new MsgPackError('The data does not start with a schema (a map).', 0);
|
|
30
|
+
const entries = [];
|
|
31
|
+
let root;
|
|
32
|
+
let described = false;
|
|
33
|
+
for (let t = 0; t < count; t++) {
|
|
34
|
+
const name = r.value();
|
|
35
|
+
if (name !== null && typeof name !== 'string')
|
|
36
|
+
throw new MsgPackError('A type name of the schema is not a string.', r.pos);
|
|
37
|
+
const items = r.value();
|
|
38
|
+
if (!Array.isArray(items))
|
|
39
|
+
throw new MsgPackError(`The schema entry ${name} is not an array.`, r.pos);
|
|
40
|
+
const entry = parseEntry(name, items);
|
|
41
|
+
if (entry.described)
|
|
42
|
+
described = true;
|
|
43
|
+
if (name === '' && t === count - 1 && entry.entry.content) // the root entry of a described schema
|
|
44
|
+
root = entry.entry.content;
|
|
45
|
+
else
|
|
46
|
+
entries.push(entry.entry);
|
|
47
|
+
}
|
|
48
|
+
if (r.pos !== bytes.length)
|
|
49
|
+
throw new MsgPackError('Data after the schema.', r.pos);
|
|
50
|
+
this.entries = entries;
|
|
51
|
+
this.root = root;
|
|
52
|
+
this.described = described || root !== undefined;
|
|
53
|
+
}
|
|
54
|
+
/** The id (32 hex digits) of these bytes as a schema of the given version: the first 16 bytes of SHA-256(version + bytes). */
|
|
55
|
+
static idOf(bytes, version) {
|
|
56
|
+
return toHex(sha256(new Uint8Array([version]), bytes), 0, 16);
|
|
57
|
+
}
|
|
58
|
+
/** The id the server gives this schema (the version follows from the form: described or plain). */
|
|
59
|
+
get id() {
|
|
60
|
+
return this._id ?? (this._id = Schema.idOf(this.bytes, this.described ? DescribedVersion : PlainVersion));
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
function parseEntry(name, items) {
|
|
64
|
+
const properties = [];
|
|
65
|
+
let content;
|
|
66
|
+
let described = false;
|
|
67
|
+
for (const item of items) {
|
|
68
|
+
if (typeof item === 'string') {
|
|
69
|
+
properties.push({ name: item, hasDefault: false });
|
|
70
|
+
continue;
|
|
71
|
+
}
|
|
72
|
+
if (!Array.isArray(item) || item.length < 2 || typeof item[0] !== 'string')
|
|
73
|
+
throw new MsgPackError(`A property of the schema entry ${name} is not a name or [name, type].`);
|
|
74
|
+
described = true;
|
|
75
|
+
const type = parseType(item[1]);
|
|
76
|
+
if (item[0] === '@') {
|
|
77
|
+
content = type;
|
|
78
|
+
continue;
|
|
79
|
+
}
|
|
80
|
+
properties.push(item.length >= 3 ? { name: item[0], type, default: item[2], hasDefault: true } : { name: item[0], type, hasDefault: false });
|
|
81
|
+
}
|
|
82
|
+
return { entry: { name, properties, content }, described };
|
|
83
|
+
}
|
|
84
|
+
/** Parses a type expression of the described schema. Unknown kinds and forms are read as 'any' (a newer server). */
|
|
85
|
+
export function parseType(value) {
|
|
86
|
+
if (typeof value === 'string')
|
|
87
|
+
return Kinds.has(value) ? { k: 'kind', kind: value } : AnyType;
|
|
88
|
+
if (typeof value === 'number')
|
|
89
|
+
return { k: 'object', entry: value, struct: false };
|
|
90
|
+
if (!Array.isArray(value) || typeof value[0] !== 'string')
|
|
91
|
+
return AnyType;
|
|
92
|
+
switch (value[0]) {
|
|
93
|
+
case '?': return { k: 'nullable', of: parseType(value[1]) };
|
|
94
|
+
case 'struct':
|
|
95
|
+
if (typeof value[1] === 'number')
|
|
96
|
+
return { k: 'object', entry: value[1], struct: true };
|
|
97
|
+
if (Array.isArray(value[1]))
|
|
98
|
+
return { k: 'object', entry: parseEntry(null, value[1]).entry, struct: true };
|
|
99
|
+
return AnyType;
|
|
100
|
+
case 'list': return { k: 'list', of: parseType(value[1]) };
|
|
101
|
+
case 'dict': return { k: 'dict', key: parseType(value[1]), value: parseType(value[2]) };
|
|
102
|
+
case 'pair': return { k: 'pair', key: parseType(value[1]), value: parseType(value[2]) };
|
|
103
|
+
case 'tuple': return { k: 'tuple', items: value.slice(1).map(parseType) };
|
|
104
|
+
}
|
|
105
|
+
return AnyType;
|
|
106
|
+
}
|
|
107
|
+
//# sourceMappingURL=schema.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schema.js","sourceRoot":"","sources":["../src/schema.ts"],"names":[],"mappings":"AAAA,4JAA4J;AAC5J,6IAA6I;AAE7I,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC3C,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AAM5C,MAAM,KAAK,GAAG,IAAI,GAAG,CAAS,CAAC,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,KAA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AE,CAAC,EAAE,QAAQ,EAAE,KAAK,EAAE,KAAK,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC;YACxF,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;gBAAE,OAAO,EAAE,CAAC,EAAE,QAAQ,EAAE,KAAK,EAAE,UAAU,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC;YAC3G,OAAO,OAAO,CAAC;QACjB,KAAK,MAAM,CAAC,CAAC,OAAO,EAAE,CAAC,EAAE,MAAM,EAAE,EAAE,EAAE,SAAS,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;QAC3D,KAAK,MAAM,CAAC,CAAC,OAAO,EAAE,CAAC,EAAE,MAAM,EAAE,GAAG,EAAE,SAAS,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,SAAS,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;QACxF,KAAK,MAAM,CAAC,CAAC,OAAO,EAAE,CAAC,EAAE,MAAM,EAAE,GAAG,EAAE,SAAS,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,SAAS,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;QACxF,KAAK,OAAO,CAAC,CAAC,OAAO,EAAE,CAAC,EAAE,OAAO,EAAE,KAAK,EAAE,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,SAAS,CAAC,EAAE,CAAC;IAC5E,CAAC;IACD,OAAO,OAAO,CAAC;AACjB,CAAC"}
|
package/dist/sha256.d.ts
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
/** The SHA-256 digest (32 bytes) of the given parts, hashed one after the other. */
|
|
2
|
+
export declare function sha256(...parts: Uint8Array[]): Uint8Array;
|
|
3
|
+
/** Lowercase hexadecimal digits, as the schema ids of the headers. */
|
|
4
|
+
export declare function toHex(bytes: Uint8Array, start?: number, end?: number): string;
|
package/dist/sha256.js
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
// SHA-256 (FIPS 180-4), synchronous: a schema is hashed once when it is learned, and crypto.subtle is asynchronous and only available in secure contexts.
|
|
2
|
+
const K = new Uint32Array([
|
|
3
|
+
0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5,
|
|
4
|
+
0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3, 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174,
|
|
5
|
+
0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc, 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da,
|
|
6
|
+
0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7, 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967,
|
|
7
|
+
0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13, 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85,
|
|
8
|
+
0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3, 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070,
|
|
9
|
+
0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5, 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3,
|
|
10
|
+
0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208, 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2,
|
|
11
|
+
]);
|
|
12
|
+
/** The SHA-256 digest (32 bytes) of the given parts, hashed one after the other. */
|
|
13
|
+
export function sha256(...parts) {
|
|
14
|
+
let length = 0;
|
|
15
|
+
for (const part of parts)
|
|
16
|
+
length += part.length;
|
|
17
|
+
const padded = new Uint8Array(((length + 9 + 63) >>> 6) << 6);
|
|
18
|
+
let offset = 0;
|
|
19
|
+
for (const part of parts) {
|
|
20
|
+
padded.set(part, offset);
|
|
21
|
+
offset += part.length;
|
|
22
|
+
}
|
|
23
|
+
padded[length] = 0x80;
|
|
24
|
+
const view = new DataView(padded.buffer);
|
|
25
|
+
view.setUint32(padded.length - 8, Math.floor(length / 0x20000000)); // the length in bits, big-endian
|
|
26
|
+
view.setUint32(padded.length - 4, (length << 3) >>> 0);
|
|
27
|
+
const h = new Uint32Array([0x6a09e667, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a, 0x510e527f, 0x9b05688c, 0x1f83d9ab, 0x5be0cd19]);
|
|
28
|
+
const w = new Uint32Array(64);
|
|
29
|
+
for (let block = 0; block < padded.length; block += 64) {
|
|
30
|
+
for (let t = 0; t < 16; t++)
|
|
31
|
+
w[t] = view.getUint32(block + t * 4);
|
|
32
|
+
for (let t = 16; t < 64; t++) {
|
|
33
|
+
const a = w[t - 15], b = w[t - 2];
|
|
34
|
+
const s0 = ((a >>> 7) | (a << 25)) ^ ((a >>> 18) | (a << 14)) ^ (a >>> 3);
|
|
35
|
+
const s1 = ((b >>> 17) | (b << 15)) ^ ((b >>> 19) | (b << 13)) ^ (b >>> 10);
|
|
36
|
+
w[t] = (w[t - 16] + s0 + w[t - 7] + s1) | 0;
|
|
37
|
+
}
|
|
38
|
+
let a = h[0], b = h[1], c = h[2], d = h[3], e = h[4], f = h[5], g = h[6], k = h[7];
|
|
39
|
+
for (let t = 0; t < 64; t++) {
|
|
40
|
+
const s1 = ((e >>> 6) | (e << 26)) ^ ((e >>> 11) | (e << 21)) ^ ((e >>> 25) | (e << 7));
|
|
41
|
+
const t1 = (k + s1 + ((e & f) ^ (~e & g)) + K[t] + w[t]) | 0;
|
|
42
|
+
const s0 = ((a >>> 2) | (a << 30)) ^ ((a >>> 13) | (a << 19)) ^ ((a >>> 22) | (a << 10));
|
|
43
|
+
const t2 = (s0 + ((a & b) ^ (a & c) ^ (b & c))) | 0;
|
|
44
|
+
k = g;
|
|
45
|
+
g = f;
|
|
46
|
+
f = e;
|
|
47
|
+
e = (d + t1) | 0;
|
|
48
|
+
d = c;
|
|
49
|
+
c = b;
|
|
50
|
+
b = a;
|
|
51
|
+
a = (t1 + t2) | 0;
|
|
52
|
+
}
|
|
53
|
+
h[0] += a;
|
|
54
|
+
h[1] += b;
|
|
55
|
+
h[2] += c;
|
|
56
|
+
h[3] += d;
|
|
57
|
+
h[4] += e;
|
|
58
|
+
h[5] += f;
|
|
59
|
+
h[6] += g;
|
|
60
|
+
h[7] += k;
|
|
61
|
+
}
|
|
62
|
+
const digest = new Uint8Array(32);
|
|
63
|
+
const out = new DataView(digest.buffer);
|
|
64
|
+
for (let t = 0; t < 8; t++)
|
|
65
|
+
out.setUint32(t * 4, h[t]);
|
|
66
|
+
return digest;
|
|
67
|
+
}
|
|
68
|
+
/** Lowercase hexadecimal digits, as the schema ids of the headers. */
|
|
69
|
+
export function toHex(bytes, start = 0, end = bytes.length) {
|
|
70
|
+
let hex = '';
|
|
71
|
+
for (let t = start; t < end; t++)
|
|
72
|
+
hex += (bytes[t] < 16 ? '0' : '') + bytes[t].toString(16);
|
|
73
|
+
return hex;
|
|
74
|
+
}
|
|
75
|
+
//# sourceMappingURL=sha256.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sha256.js","sourceRoot":"","sources":["../src/sha256.ts"],"names":[],"mappings":"AAAA,0JAA0J;AAE1J,MAAM,CAAC,GAAG,IAAI,WAAW,CAAC;IACxB,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU;IAC9F,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU;IAC9F,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE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