@lsmsgpack/client 0.0.0-stage → 2026.10.2201
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 +174 -0
- package/dist/decoder.js +720 -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/store.d.ts
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { Schema } from './schema.js';
|
|
2
|
+
export interface SchemaStoreOptions {
|
|
3
|
+
/** The most schemas kept (1024 by default). A full store keeps working, it stops learning new schemas (they keep coming inline). */
|
|
4
|
+
maxSchemas?: number;
|
|
5
|
+
/** The most schema ids sent per server (the most recently used ones, then the preloaded ones), 64 by default. */
|
|
6
|
+
maxAdvertisedSchemas?: number;
|
|
7
|
+
}
|
|
8
|
+
/** What export() writes: JSON-compatible, e.g. for localStorage or IndexedDB. */
|
|
9
|
+
export interface SchemaStoreExport {
|
|
10
|
+
/** The schema bytes, base64. Their ids are computed again when imported. */
|
|
11
|
+
schemas: string[];
|
|
12
|
+
/** The ids per origin, most recent first. */
|
|
13
|
+
origins: Record<string, string[]>;
|
|
14
|
+
}
|
|
15
|
+
export declare class SchemaStore {
|
|
16
|
+
readonly maxSchemas: number;
|
|
17
|
+
readonly maxAdvertisedSchemas: number;
|
|
18
|
+
private readonly schemas;
|
|
19
|
+
private readonly origins;
|
|
20
|
+
/** The ids of the preloaded schemas: advertised to every server (or to the origins they were preloaded for). */
|
|
21
|
+
private readonly preloaded;
|
|
22
|
+
private readonly preloadedFor;
|
|
23
|
+
constructor(options?: SchemaStoreOptions);
|
|
24
|
+
/**
|
|
25
|
+
* Holds schemas before the server sends them (the schema set of lsmsgpack-ts: base64 per response type), so the first response of each type refers to its schema.
|
|
26
|
+
* Their ids are computed from the bytes. A schema the server does not write (other classes or options) does no harm: it is listed until the limit pushes it out.
|
|
27
|
+
* @param schemas base64 (or bytes) of schemas, e.g. the schemas export of the generated file
|
|
28
|
+
* @param origin the server (scheme://host:port) they are for, default: every server
|
|
29
|
+
* @returns the number of schemas held
|
|
30
|
+
*/
|
|
31
|
+
preload(schemas: Readonly<Record<string, string | Uint8Array>> | Iterable<string | Uint8Array>, origin?: string): number;
|
|
32
|
+
get size(): number;
|
|
33
|
+
get(id: string): Schema | undefined;
|
|
34
|
+
has(id: string): boolean;
|
|
35
|
+
/**
|
|
36
|
+
* Learns the schema a server sent inline: kept when its id (the hash of its bytes) is the one of the response header MsgPack-Schema, and from now on advertised to that origin.
|
|
37
|
+
* @returns true when the store holds it
|
|
38
|
+
*/
|
|
39
|
+
learn(origin: string, schemaHeader: string | null | undefined, schema: Schema): boolean;
|
|
40
|
+
/** Remembers that the server of the origin uses the schema (most recent first). */
|
|
41
|
+
touch(origin: string, id: string): void;
|
|
42
|
+
/** The value of the request header MsgPack-Schemas for the origin (undefined when the client holds none of its schemas): the ones it used most recently, then the preloaded ones. */
|
|
43
|
+
advertise(origin: string): string | undefined;
|
|
44
|
+
/** Forgets everything, also the preloaded schemas. */
|
|
45
|
+
clear(): void;
|
|
46
|
+
export(): SchemaStoreExport;
|
|
47
|
+
/** Adds what export() wrote (the ids are computed from the bytes again, schemas that do not parse are skipped). */
|
|
48
|
+
import(data: SchemaStoreExport): void;
|
|
49
|
+
}
|
package/dist/store.js
ADDED
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
// Keeps the schemas received from servers, so the next requests can say which ones the client holds (request header MsgPack-Schemas)
|
|
2
|
+
// and the server refers to them (18 bytes) instead of sending them. As LtMsgPackHttpSerializer.GetSchemasHeader / LearnSchema on the .NET side.
|
|
3
|
+
import { Schema } from './schema.js';
|
|
4
|
+
export class SchemaStore {
|
|
5
|
+
constructor(options = {}) {
|
|
6
|
+
this.schemas = new Map();
|
|
7
|
+
this.origins = new Map();
|
|
8
|
+
/** The ids of the preloaded schemas: advertised to every server (or to the origins they were preloaded for). */
|
|
9
|
+
this.preloaded = [];
|
|
10
|
+
this.preloadedFor = new Map();
|
|
11
|
+
this.maxSchemas = options.maxSchemas ?? 1024;
|
|
12
|
+
this.maxAdvertisedSchemas = options.maxAdvertisedSchemas ?? 64;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Holds schemas before the server sends them (the schema set of lsmsgpack-ts: base64 per response type), so the first response of each type refers to its schema.
|
|
16
|
+
* Their ids are computed from the bytes. A schema the server does not write (other classes or options) does no harm: it is listed until the limit pushes it out.
|
|
17
|
+
* @param schemas base64 (or bytes) of schemas, e.g. the schemas export of the generated file
|
|
18
|
+
* @param origin the server (scheme://host:port) they are for, default: every server
|
|
19
|
+
* @returns the number of schemas held
|
|
20
|
+
*/
|
|
21
|
+
preload(schemas, origin) {
|
|
22
|
+
const values = Symbol.iterator in Object(schemas) ? [...schemas] : Object.values(schemas);
|
|
23
|
+
const ids = origin === undefined ? this.preloaded : (this.preloadedFor.get(origin) ?? (this.preloadedFor.set(origin, []), this.preloadedFor.get(origin)));
|
|
24
|
+
let held = 0;
|
|
25
|
+
for (const value of values) {
|
|
26
|
+
const schema = new Schema(typeof value === 'string' ? fromBase64(value) : value); // throws for bytes that are not a schema: the file is generated, a mistake should show
|
|
27
|
+
if (!this.schemas.has(schema.id)) {
|
|
28
|
+
if (this.schemas.size >= this.maxSchemas)
|
|
29
|
+
break;
|
|
30
|
+
this.schemas.set(schema.id, schema);
|
|
31
|
+
}
|
|
32
|
+
if (!ids.includes(schema.id))
|
|
33
|
+
ids.push(schema.id);
|
|
34
|
+
held++;
|
|
35
|
+
}
|
|
36
|
+
return held;
|
|
37
|
+
}
|
|
38
|
+
get size() {
|
|
39
|
+
return this.schemas.size;
|
|
40
|
+
}
|
|
41
|
+
get(id) {
|
|
42
|
+
return this.schemas.get(id.toLowerCase());
|
|
43
|
+
}
|
|
44
|
+
has(id) {
|
|
45
|
+
return this.schemas.has(id.toLowerCase());
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Learns the schema a server sent inline: kept when its id (the hash of its bytes) is the one of the response header MsgPack-Schema, and from now on advertised to that origin.
|
|
49
|
+
* @returns true when the store holds it
|
|
50
|
+
*/
|
|
51
|
+
learn(origin, schemaHeader, schema) {
|
|
52
|
+
if (!schemaHeader || this.maxAdvertisedSchemas <= 0)
|
|
53
|
+
return false;
|
|
54
|
+
const id = schemaHeader.trim().toLowerCase();
|
|
55
|
+
if (!this.schemas.has(id)) {
|
|
56
|
+
if (schema.id !== id || this.schemas.size >= this.maxSchemas)
|
|
57
|
+
return false; // not the schema the header claims, or full
|
|
58
|
+
this.schemas.set(id, schema);
|
|
59
|
+
}
|
|
60
|
+
this.touch(origin, id);
|
|
61
|
+
return true;
|
|
62
|
+
}
|
|
63
|
+
/** Remembers that the server of the origin uses the schema (most recent first). */
|
|
64
|
+
touch(origin, id) {
|
|
65
|
+
id = id.toLowerCase();
|
|
66
|
+
if (!this.schemas.has(id))
|
|
67
|
+
return;
|
|
68
|
+
let ids = this.origins.get(origin);
|
|
69
|
+
if (ids === undefined)
|
|
70
|
+
this.origins.set(origin, (ids = []));
|
|
71
|
+
if (ids[0] === id)
|
|
72
|
+
return;
|
|
73
|
+
const at = ids.indexOf(id);
|
|
74
|
+
if (at >= 0)
|
|
75
|
+
ids.splice(at, 1);
|
|
76
|
+
ids.unshift(id);
|
|
77
|
+
if (ids.length > this.maxAdvertisedSchemas)
|
|
78
|
+
ids.length = this.maxAdvertisedSchemas;
|
|
79
|
+
}
|
|
80
|
+
/** The value of the request header MsgPack-Schemas for the origin (undefined when the client holds none of its schemas): the ones it used most recently, then the preloaded ones. */
|
|
81
|
+
advertise(origin) {
|
|
82
|
+
if (this.maxAdvertisedSchemas <= 0)
|
|
83
|
+
return undefined;
|
|
84
|
+
const ids = this.origins.get(origin) ?? [];
|
|
85
|
+
const preloaded = this.preloadedFor.get(origin);
|
|
86
|
+
let held = ids.filter((id) => this.schemas.has(id));
|
|
87
|
+
if (preloaded !== undefined || this.preloaded.length > 0) {
|
|
88
|
+
const seen = new Set(held);
|
|
89
|
+
for (const id of [...(preloaded ?? []), ...this.preloaded]) {
|
|
90
|
+
if (held.length >= this.maxAdvertisedSchemas)
|
|
91
|
+
break;
|
|
92
|
+
if (!seen.has(id) && this.schemas.has(id)) {
|
|
93
|
+
seen.add(id);
|
|
94
|
+
held.push(id);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
if (held.length > this.maxAdvertisedSchemas)
|
|
99
|
+
held = held.slice(0, this.maxAdvertisedSchemas);
|
|
100
|
+
return held.length === 0 ? undefined : held.join(',');
|
|
101
|
+
}
|
|
102
|
+
/** Forgets everything, also the preloaded schemas. */
|
|
103
|
+
clear() {
|
|
104
|
+
this.schemas.clear();
|
|
105
|
+
this.origins.clear();
|
|
106
|
+
this.preloaded.length = 0;
|
|
107
|
+
this.preloadedFor.clear();
|
|
108
|
+
}
|
|
109
|
+
export() {
|
|
110
|
+
const origins = {};
|
|
111
|
+
for (const [origin, ids] of this.origins)
|
|
112
|
+
origins[origin] = ids.slice();
|
|
113
|
+
return { schemas: [...this.schemas.values()].map((s) => toBase64(s.bytes)), origins };
|
|
114
|
+
}
|
|
115
|
+
/** Adds what export() wrote (the ids are computed from the bytes again, schemas that do not parse are skipped). */
|
|
116
|
+
import(data) {
|
|
117
|
+
for (const encoded of data.schemas ?? []) {
|
|
118
|
+
if (this.schemas.size >= this.maxSchemas)
|
|
119
|
+
break;
|
|
120
|
+
try {
|
|
121
|
+
const schema = new Schema(fromBase64(encoded));
|
|
122
|
+
this.schemas.set(schema.id, schema);
|
|
123
|
+
}
|
|
124
|
+
catch {
|
|
125
|
+
// not a schema: skipped
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
for (const origin of Object.keys(data.origins ?? {})) {
|
|
129
|
+
const ids = data.origins[origin];
|
|
130
|
+
for (let t = ids.length - 1; t >= 0; t--)
|
|
131
|
+
this.touch(origin, ids[t]);
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
function toBase64(bytes) {
|
|
136
|
+
let s = '';
|
|
137
|
+
for (let t = 0; t < bytes.length; t++)
|
|
138
|
+
s += String.fromCharCode(bytes[t]);
|
|
139
|
+
return btoa(s);
|
|
140
|
+
}
|
|
141
|
+
function fromBase64(text) {
|
|
142
|
+
const s = atob(text);
|
|
143
|
+
const bytes = new Uint8Array(s.length);
|
|
144
|
+
for (let t = 0; t < s.length; t++)
|
|
145
|
+
bytes[t] = s.charCodeAt(t);
|
|
146
|
+
return bytes;
|
|
147
|
+
}
|
|
148
|
+
//# sourceMappingURL=store.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"store.js","sourceRoot":"","sources":["../src/store.ts"],"names":[],"mappings":"AAAA,qIAAqI;AACrI,gJAAgJ;AAEhJ,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAiBrC,MAAM,OAAO,WAAW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C,EAAE,CAAC,GAAG,KAAK,CAAC,MAAM,EAAE,CAAC,EAAE;QAAE,CAAC,IAAI,MAAM,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;IAC1E,OAAO,IAAI,CAAC,CAAC,CAAC,CAAC;AACjB,CAAC;AAED,SAAS,UAAU,CAAC,IAAY;IAC9B,MAAM,CAAC,GAAG,IAAI,CAAC,IAAI,CAAC,CAAC;IACrB,MAAM,KAAK,GAAG,IAAI,UAAU,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC;IACvC,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,CAAC,EAAE;QAAE,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC;IAC9D,OAAO,KAAK,CAAC;AACf,CAAC"}
|
package/dist/values.d.ts
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/** How decimals are returned: 'number' (default, as JSON.parse gives them), 'string' (the text of decimal.ToString(), keeps the scale and all digits), 'raw' (the extension), or a function of that text (e.g. a decimal library). */
|
|
2
|
+
export type DecimalMode = 'number' | 'string' | 'raw' | ((text: string) => unknown);
|
|
3
|
+
/** Extension type 1: System.Decimal as it is in memory (flags, hi, lo, mid: little-endian 32 bit integers, see LsMsgPack's MpDecimal). */
|
|
4
|
+
export declare function decodeDecimal(bytes: Uint8Array, start: number, mode: DecimalMode): unknown;
|
|
5
|
+
/** A decimal written as text or a number (DecimalFormat.String, or a default value) in the requested mode. */
|
|
6
|
+
export declare function convertDecimal(value: unknown, mode: DecimalMode): unknown;
|
|
7
|
+
/** A Guid as bin 16 (Guid.ToByteArray(): the first three groups little-endian) as its text, e.g. "0f8fad5b-d9cb-469f-a165-70867728950e". */
|
|
8
|
+
export declare function guidString(b: Uint8Array, p?: number): string;
|
|
9
|
+
/** The bytes of a Guid as .NET writes them (the reverse of guidString). */
|
|
10
|
+
export declare function guidBytes(guid: string): Uint8Array;
|
|
11
|
+
export declare const EmptyGuid = "00000000-0000-0000-0000-000000000000";
|
|
12
|
+
/** DateTime.MinValue (0001-01-01T00:00:00Z) in milliseconds since 1970. */
|
|
13
|
+
export declare const MinDateTimeMs = -62135596800000;
|
|
14
|
+
/** TimeSpan ticks (100 ns) as TimeSpan.ToString("c") and System.Text.Json write it: [-][d.]hh:mm:ss[.fffffff]. */
|
|
15
|
+
export declare function timeSpanText(ticks: number | bigint): string;
|
|
16
|
+
/** DateOnly's day number (days since 0001-01-01) as yyyy-MM-dd. */
|
|
17
|
+
export declare function dateOnlyText(dayNumber: number): string;
|
|
18
|
+
/** TimeOnly's ticks as HH:mm:ss[.fffffff] (as System.Text.Json writes it: seven digits when there is a fraction). */
|
|
19
|
+
export declare function timeOnlyText(ticks: number | bigint): string;
|
|
20
|
+
/** A moment with its offset as ISO 8601 text with that offset, e.g. 2026-01-01T12:00:00.000+02:00. */
|
|
21
|
+
export declare function offsetText(moment: Date, offsetMinutes: number): string;
|
|
22
|
+
/** The ticks of TimeSpan.ToString("c") text ([-][d.]hh:mm:ss[.fffffff]), undefined when it is not one. */
|
|
23
|
+
export declare function timeSpanTicks(text: string): number | bigint | undefined;
|
|
24
|
+
/** The ticks of TimeOnly text (HH:mm[:ss[.fffffff]]). */
|
|
25
|
+
export declare function timeOnlyTicks(text: string): number | undefined;
|
|
26
|
+
/** DateOnly's day number (days since 0001-01-01) of yyyy-MM-dd text. */
|
|
27
|
+
export declare function dateOnlyDayNumber(text: string): number | undefined;
|
|
28
|
+
/** The moment and offset (minutes) of ISO 8601 text: the offset of a +hh:mm suffix, 0 for Z or none. */
|
|
29
|
+
export declare function parseOffsetText(text: string): {
|
|
30
|
+
moment: Date;
|
|
31
|
+
offset: number;
|
|
32
|
+
} | undefined;
|
|
33
|
+
/** Extension type 1 (System.Decimal as in memory, see decodeDecimal) of decimal text, undefined when it does not fit (more than 96 bits or 28 decimals). */
|
|
34
|
+
export declare function encodeDecimal(text: string): Uint8Array | undefined;
|
package/dist/values.js
ADDED
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
// Conversions of the .NET value formats (see docs/Compatibility.md and docs/TypeScriptClient.md).
|
|
2
|
+
const twoPow32 = 4294967296;
|
|
3
|
+
/** Extension type 1: System.Decimal as it is in memory (flags, hi, lo, mid: little-endian 32 bit integers, see LsMsgPack's MpDecimal). */
|
|
4
|
+
export function decodeDecimal(bytes, start, mode) {
|
|
5
|
+
const flags = int32le(bytes, start); // read in place: a DataView per value costs more than the rest
|
|
6
|
+
const hi = int32le(bytes, start + 4) >>> 0;
|
|
7
|
+
const lo = int32le(bytes, start + 8) >>> 0;
|
|
8
|
+
const mid = int32le(bytes, start + 12) >>> 0;
|
|
9
|
+
const scale = (flags >>> 16) & 0xff;
|
|
10
|
+
const negative = flags < 0;
|
|
11
|
+
if (mode === 'number' && hi === 0 && mid < 0x200000 && scale <= 22) { // the mantissa and the power of ten are exact doubles: one correctly rounded division
|
|
12
|
+
const mantissa = mid * twoPow32 + lo;
|
|
13
|
+
if (mantissa === 0)
|
|
14
|
+
return 0;
|
|
15
|
+
const value = scale === 0 ? mantissa : mantissa / 10 ** scale;
|
|
16
|
+
return negative ? -value : value;
|
|
17
|
+
}
|
|
18
|
+
const text = decimalText(hi, mid, lo, scale, negative);
|
|
19
|
+
if (mode === 'string' || mode === 'raw')
|
|
20
|
+
return text;
|
|
21
|
+
if (mode === 'number')
|
|
22
|
+
return Number(text);
|
|
23
|
+
return mode(text);
|
|
24
|
+
}
|
|
25
|
+
function int32le(b, p) {
|
|
26
|
+
return b[p] | (b[p + 1] << 8) | (b[p + 2] << 16) | (b[p + 3] << 24);
|
|
27
|
+
}
|
|
28
|
+
function decimalText(hi, mid, lo, scale, negative) {
|
|
29
|
+
let digits = hi === 0 && mid < 0x200000 ? String(mid * twoPow32 + lo) : ((BigInt(hi) << 64n) | (BigInt(mid) << 32n) | BigInt(lo)).toString();
|
|
30
|
+
const zero = digits === '0';
|
|
31
|
+
if (scale > 0) {
|
|
32
|
+
if (digits.length <= scale)
|
|
33
|
+
digits = '0'.repeat(scale - digits.length + 1) + digits;
|
|
34
|
+
digits = digits.slice(0, digits.length - scale) + '.' + digits.slice(digits.length - scale);
|
|
35
|
+
}
|
|
36
|
+
return negative && !zero ? '-' + digits : digits;
|
|
37
|
+
}
|
|
38
|
+
/** A decimal written as text or a number (DecimalFormat.String, or a default value) in the requested mode. */
|
|
39
|
+
export function convertDecimal(value, mode) {
|
|
40
|
+
if (typeof value === 'number')
|
|
41
|
+
return mode === 'string' || mode === 'raw' ? String(value) : typeof mode === 'function' ? mode(String(value)) : value;
|
|
42
|
+
if (typeof value === 'string')
|
|
43
|
+
return mode === 'number' ? Number(value) : typeof mode === 'function' ? mode(value) : value;
|
|
44
|
+
return value;
|
|
45
|
+
}
|
|
46
|
+
const hex = [];
|
|
47
|
+
for (let t = 0; t < 256; t++)
|
|
48
|
+
hex.push((t < 16 ? '0' : '') + t.toString(16));
|
|
49
|
+
/** A Guid as bin 16 (Guid.ToByteArray(): the first three groups little-endian) as its text, e.g. "0f8fad5b-d9cb-469f-a165-70867728950e". */
|
|
50
|
+
export function guidString(b, p = 0) {
|
|
51
|
+
return hex[b[p + 3]] + hex[b[p + 2]] + hex[b[p + 1]] + hex[b[p]] + '-' + hex[b[p + 5]] + hex[b[p + 4]] + '-' + hex[b[p + 7]] + hex[b[p + 6]] + '-' +
|
|
52
|
+
hex[b[p + 8]] + hex[b[p + 9]] + '-' + hex[b[p + 10]] + hex[b[p + 11]] + hex[b[p + 12]] + hex[b[p + 13]] + hex[b[p + 14]] + hex[b[p + 15]];
|
|
53
|
+
}
|
|
54
|
+
/** The bytes of a Guid as .NET writes them (the reverse of guidString). */
|
|
55
|
+
export function guidBytes(guid) {
|
|
56
|
+
const h = guid.replace(/[-{}]/g, '');
|
|
57
|
+
if (!/^[0-9a-fA-F]{32}$/.test(h))
|
|
58
|
+
throw new Error(`"${guid}" is not a Guid.`);
|
|
59
|
+
const b = new Uint8Array(16);
|
|
60
|
+
for (let t = 0; t < 16; t++)
|
|
61
|
+
b[t] = parseInt(h.substr(t * 2, 2), 16);
|
|
62
|
+
const swap = (i, j) => { const x = b[i]; b[i] = b[j]; b[j] = x; };
|
|
63
|
+
swap(0, 3);
|
|
64
|
+
swap(1, 2);
|
|
65
|
+
swap(4, 5);
|
|
66
|
+
swap(6, 7);
|
|
67
|
+
return b;
|
|
68
|
+
}
|
|
69
|
+
export const EmptyGuid = '00000000-0000-0000-0000-000000000000';
|
|
70
|
+
/** DateTime.MinValue (0001-01-01T00:00:00Z) in milliseconds since 1970. */
|
|
71
|
+
export const MinDateTimeMs = -62135596800000;
|
|
72
|
+
const TicksPerSecond = 10000000;
|
|
73
|
+
function pad(value, length) {
|
|
74
|
+
let s = String(value);
|
|
75
|
+
while (s.length < length)
|
|
76
|
+
s = '0' + s;
|
|
77
|
+
return s;
|
|
78
|
+
}
|
|
79
|
+
/** TimeSpan ticks (100 ns) as TimeSpan.ToString("c") and System.Text.Json write it: [-][d.]hh:mm:ss[.fffffff]. */
|
|
80
|
+
export function timeSpanText(ticks) {
|
|
81
|
+
let t = typeof ticks === 'bigint' ? ticks : BigInt(Math.trunc(ticks));
|
|
82
|
+
const negative = t < 0n;
|
|
83
|
+
if (negative)
|
|
84
|
+
t = -t;
|
|
85
|
+
const fraction = Number(t % 10000000n);
|
|
86
|
+
let seconds = t / 10000000n;
|
|
87
|
+
const s = Number(seconds % 60n);
|
|
88
|
+
seconds /= 60n;
|
|
89
|
+
const m = Number(seconds % 60n);
|
|
90
|
+
seconds /= 60n;
|
|
91
|
+
const h = Number(seconds % 24n);
|
|
92
|
+
const days = seconds / 24n;
|
|
93
|
+
return (negative ? '-' : '') + (days > 0n ? days.toString() + '.' : '') + pad(h, 2) + ':' + pad(m, 2) + ':' + pad(s, 2) + (fraction > 0 ? '.' + pad(fraction, 7) : '');
|
|
94
|
+
}
|
|
95
|
+
/** DateOnly's day number (days since 0001-01-01) as yyyy-MM-dd. */
|
|
96
|
+
export function dateOnlyText(dayNumber) {
|
|
97
|
+
const date = new Date(MinDateTimeMs + dayNumber * 86400000);
|
|
98
|
+
return pad(date.getUTCFullYear(), 4) + '-' + pad(date.getUTCMonth() + 1, 2) + '-' + pad(date.getUTCDate(), 2);
|
|
99
|
+
}
|
|
100
|
+
/** TimeOnly's ticks as HH:mm:ss[.fffffff] (as System.Text.Json writes it: seven digits when there is a fraction). */
|
|
101
|
+
export function timeOnlyText(ticks) {
|
|
102
|
+
const t = Number(ticks);
|
|
103
|
+
const fraction = t % TicksPerSecond;
|
|
104
|
+
const seconds = Math.floor(t / TicksPerSecond);
|
|
105
|
+
const text = pad(Math.floor(seconds / 3600), 2) + ':' + pad(Math.floor(seconds / 60) % 60, 2) + ':' + pad(seconds % 60, 2);
|
|
106
|
+
return fraction === 0 ? text : text + '.' + pad(fraction, 7);
|
|
107
|
+
}
|
|
108
|
+
/** A moment with its offset as ISO 8601 text with that offset, e.g. 2026-01-01T12:00:00.000+02:00. */
|
|
109
|
+
export function offsetText(moment, offsetMinutes) {
|
|
110
|
+
const clock = new Date(moment.getTime() + offsetMinutes * 60000).toISOString(); // ends with Z
|
|
111
|
+
const sign = offsetMinutes < 0 ? '-' : '+';
|
|
112
|
+
const abs = Math.abs(offsetMinutes);
|
|
113
|
+
return clock.slice(0, clock.length - 1) + sign + pad(Math.floor(abs / 60), 2) + ':' + pad(abs % 60, 2);
|
|
114
|
+
}
|
|
115
|
+
// The reverse, for request bodies with models (writer.ts): the text forms back to what the .NET readers take.
|
|
116
|
+
/** The ticks of TimeSpan.ToString("c") text ([-][d.]hh:mm:ss[.fffffff]), undefined when it is not one. */
|
|
117
|
+
export function timeSpanTicks(text) {
|
|
118
|
+
const m = /^(-)?(?:(\d+)\.)?(\d{1,2}):(\d{1,2}):(\d{1,2})(?:\.(\d{1,7}))?$/.exec(text.trim());
|
|
119
|
+
if (m === null)
|
|
120
|
+
return undefined;
|
|
121
|
+
const ticks = (((BigInt(m[2] ?? 0) * 24n + BigInt(m[3])) * 60n + BigInt(m[4])) * 60n + BigInt(m[5])) * 10000000n + BigInt((m[6] ?? '').padEnd(7, '0'));
|
|
122
|
+
const signed = m[1] ? -ticks : ticks;
|
|
123
|
+
return signed >= BigInt(Number.MIN_SAFE_INTEGER) && signed <= BigInt(Number.MAX_SAFE_INTEGER) ? Number(signed) : signed;
|
|
124
|
+
}
|
|
125
|
+
/** The ticks of TimeOnly text (HH:mm[:ss[.fffffff]]). */
|
|
126
|
+
export function timeOnlyTicks(text) {
|
|
127
|
+
const m = /^(\d{1,2}):(\d{2})(?::(\d{2})(?:\.(\d{1,7}))?)?$/.exec(text.trim());
|
|
128
|
+
if (m === null)
|
|
129
|
+
return undefined;
|
|
130
|
+
return ((+m[1] * 60 + +m[2]) * 60 + +(m[3] ?? 0)) * TicksPerSecond + +(m[4] ?? '').padEnd(7, '0');
|
|
131
|
+
}
|
|
132
|
+
/** DateOnly's day number (days since 0001-01-01) of yyyy-MM-dd text. */
|
|
133
|
+
export function dateOnlyDayNumber(text) {
|
|
134
|
+
const m = /^(\d{4})-(\d{2})-(\d{2})$/.exec(text.trim());
|
|
135
|
+
if (m === null)
|
|
136
|
+
return undefined;
|
|
137
|
+
const date = new Date(0);
|
|
138
|
+
date.setUTCFullYear(+m[1], +m[2] - 1, +m[3]); // not Date.UTC: it takes years below 100 as 19xx
|
|
139
|
+
return Math.round((date.getTime() - MinDateTimeMs) / 86400000);
|
|
140
|
+
}
|
|
141
|
+
/** The moment and offset (minutes) of ISO 8601 text: the offset of a +hh:mm suffix, 0 for Z or none. */
|
|
142
|
+
export function parseOffsetText(text) {
|
|
143
|
+
const ms = Date.parse(text);
|
|
144
|
+
if (Number.isNaN(ms))
|
|
145
|
+
return undefined;
|
|
146
|
+
const m = /([+-])(\d{2}):?(\d{2})$/.exec(text.trim());
|
|
147
|
+
const offset = m === null ? 0 : (m[1] === '-' ? -1 : 1) * (+m[2] * 60 + +m[3]);
|
|
148
|
+
return { moment: new Date(ms), offset };
|
|
149
|
+
}
|
|
150
|
+
/** Extension type 1 (System.Decimal as in memory, see decodeDecimal) of decimal text, undefined when it does not fit (more than 96 bits or 28 decimals). */
|
|
151
|
+
export function encodeDecimal(text) {
|
|
152
|
+
const m = /^\s*([+-])?(\d*)(?:\.(\d*))?\s*$/.exec(text);
|
|
153
|
+
if (m === null || (m[2] === '' && (m[3] ?? '') === ''))
|
|
154
|
+
return undefined;
|
|
155
|
+
const fraction = m[3] ?? '';
|
|
156
|
+
if (fraction.length > 28)
|
|
157
|
+
return undefined;
|
|
158
|
+
const mantissa = BigInt((m[2] || '0') + fraction);
|
|
159
|
+
if (mantissa >= 1n << 96n)
|
|
160
|
+
return undefined;
|
|
161
|
+
const bytes = new Uint8Array(16);
|
|
162
|
+
const view = new DataView(bytes.buffer);
|
|
163
|
+
view.setUint32(0, (fraction.length << 16) | (m[1] === '-' && mantissa !== 0n ? 0x80000000 : 0), true);
|
|
164
|
+
view.setUint32(4, Number((mantissa >> 64n) & 0xffffffffn), true); // hi
|
|
165
|
+
view.setUint32(8, Number(mantissa & 0xffffffffn), true); // lo
|
|
166
|
+
view.setUint32(12, Number((mantissa >> 32n) & 0xffffffffn), true); // mid
|
|
167
|
+
return bytes;
|
|
168
|
+
}
|
|
169
|
+
//# sourceMappingURL=values.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"values.js","sourceRoot":"","sources":["../src/values.ts"],"names":[],"mappings":"AAAA,kGAAkG;AAKlG,MAAM,QAAQ,GAAG,UAAU,CAAC;AAE5B,0IAA0I;AAC1I,MAAM,UAAU,aAAa,CAAC,KAAiB,EAAE,KAAa,EAAE,IAAiB;IAC/E,MAAM,KAAK,GAAG,OAAO,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC,CAAC,+DAA+D;IACpG,MAAM,EAAE,GAAG,OAAO,CAAC,KAAK,EAAE,KAAK,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC;IAC3C,MAA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IAAI,CAAC,CAAC,CAAC,KAAK;IACvE,IAAI,CAAC,SAAS,CAAC,CAAC,EAAE,MAAM,CAAC,QAAQ,GAAG,WAAW,CAAC,EAAE,IAAI,CAAC,CAAC,CAAC,KAAK;IAC9D,IAAI,CAAC,SAAS,CAAC,EAAE,EAAE,MAAM,CAAC,CAAC,QAAQ,IAAI,GAAG,CAAC,GAAG,WAAW,CAAC,EAAE,IAAI,CAAC,CAAC,CAAC,MAAM;IACzE,OAAO,KAAK,CAAC;AACf,CAAC"}
|
package/dist/writer.d.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { ModelSet } from './models.js';
|
|
2
|
+
export interface EncodeOptions {
|
|
3
|
+
/** Objects and arrays nested deeper are refused (cycles), 256 by default. */
|
|
4
|
+
maxDepth?: number;
|
|
5
|
+
/**
|
|
6
|
+
* The generated models (lsmsgpack-ts): an instance of a model class is written as its properties are declared (a Guid string as its 16 bytes, TimeSpan, DateOnly and
|
|
7
|
+
* TimeOnly text as the numbers .NET writes, decimal text as a decimal...), and with its type id only where the declared type is not its class.
|
|
8
|
+
*/
|
|
9
|
+
models?: ModelSet;
|
|
10
|
+
/** Generate the code that writes the properties of each model class (new Function, the property names as string literals), default true. Without it (or when a Content-Security-Policy does not allow it) a generic loop does the same. */
|
|
11
|
+
generateCode?: boolean;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Encodes a value: null and undefined as nil (undefined properties are left out), numbers as the smallest integer or a float64, bigint as a 64 bit integer,
|
|
15
|
+
* Date as a timestamp, Uint8Array (and other typed arrays, ArrayBuffer) as bin, Map and plain objects as maps, MsgPackExtension as an extension.
|
|
16
|
+
* The property $type of an object (a string: the .NET type name, as the decoder sets it) is written as the type id, the key "" (a Map is written as it is).
|
|
17
|
+
*/
|
|
18
|
+
export declare function encode(value: unknown, options?: EncodeOptions): Uint8Array;
|