affinirum 1.4.0 → 1.4.2
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 +66 -48
- package/dst/Affinirum.js +3 -3
- package/dst/Constants.js +2 -0
- package/dst/StaticScope.js +1 -1
- package/dst/Type.js +1 -1
- package/dst/atom/FunctionAtom.js +1 -1
- package/dst/atom/ObjectAtom.js +1 -1
- package/dst/cjs/Affinirum.js +3 -3
- package/dst/cjs/Constants.js +2 -0
- package/dst/cjs/StaticScope.js +1 -1
- package/dst/cjs/Type.js +1 -1
- package/dst/cjs/atom/FunctionAtom.js +1 -1
- package/dst/cjs/atom/ObjectAtom.js +1 -1
- package/dst/cjs/native/Array.js +3 -3
- package/dst/cjs/native/Boolean.js +7 -4
- package/dst/cjs/native/Buffer.js +45 -13
- package/dst/cjs/native/Float.js +4 -7
- package/dst/cjs/native/Integer.js +10 -7
- package/dst/cjs/native/Iterable.js +2 -1
- package/dst/cjs/native/Object.js +3 -3
- package/dst/cjs/native/String.js +34 -17
- package/dst/cjs/native/Timestamp.js +27 -13
- package/dst/cjs/native/Unknown.js +10 -10
- package/dst/cjs/native/notation/AN.js +6 -6
- package/dst/cjs/native/notation/IP.js +239 -0
- package/dst/cjs/native/notation/JSON.js +5 -5
- package/dst/cjs/node/ObjectNode.js +1 -1
- package/dst/native/Array.d.ts +1 -7
- package/dst/native/Array.js +3 -3
- package/dst/native/Boolean.d.ts +1 -7
- package/dst/native/Boolean.js +7 -4
- package/dst/native/Buffer.d.ts +4 -5
- package/dst/native/Buffer.js +43 -12
- package/dst/native/Float.d.ts +2 -21
- package/dst/native/Float.js +4 -7
- package/dst/native/Integer.d.ts +2 -10
- package/dst/native/Integer.js +10 -7
- package/dst/native/Iterable.js +2 -1
- package/dst/native/Object.d.ts +1 -3
- package/dst/native/Object.js +3 -3
- package/dst/native/String.d.ts +3 -7
- package/dst/native/String.js +34 -17
- package/dst/native/Timestamp.d.ts +4 -9
- package/dst/native/Timestamp.js +27 -13
- package/dst/native/Unknown.js +11 -11
- package/dst/native/notation/AN.d.ts +1 -4
- package/dst/native/notation/AN.js +6 -6
- package/dst/native/notation/IP.d.ts +1 -0
- package/dst/native/notation/IP.js +236 -0
- package/dst/native/notation/JSON.d.ts +1 -5
- package/dst/native/notation/JSON.js +5 -5
- package/dst/node/ObjectNode.js +1 -1
- package/package.json +1 -1
package/dst/native/Buffer.js
CHANGED
|
@@ -1,5 +1,36 @@
|
|
|
1
1
|
import { Constant } from "../Constant.js";
|
|
2
2
|
import { Type } from "../Type.js";
|
|
3
|
+
export const EmptyBuffer = new ArrayBuffer(0);
|
|
4
|
+
const ZERO = "0".charCodeAt(0), NINE = "9".charCodeAt(0);
|
|
5
|
+
const UPPER_A = "A".charCodeAt(0), UPPER_F = "F".charCodeAt(0);
|
|
6
|
+
const LOWER_A = "a".charCodeAt(0), LOWER_F = "f".charCodeAt(0);
|
|
7
|
+
export const parseBoundedInteger = (input, base, min, max) => {
|
|
8
|
+
if (input.length === 0) {
|
|
9
|
+
throw new Error(`Invalid IP component: ${input}`);
|
|
10
|
+
}
|
|
11
|
+
let value = 0;
|
|
12
|
+
for (let i = 0; i < input.length; i++) {
|
|
13
|
+
const code = input.charCodeAt(i);
|
|
14
|
+
let digit;
|
|
15
|
+
if (code >= ZERO && code <= NINE) {
|
|
16
|
+
digit = code - ZERO;
|
|
17
|
+
}
|
|
18
|
+
else if (base === 16 && code >= UPPER_A && code <= UPPER_F) {
|
|
19
|
+
digit = code - UPPER_A + 10;
|
|
20
|
+
}
|
|
21
|
+
else if (base === 16 && code >= LOWER_A && code <= LOWER_F) {
|
|
22
|
+
digit = code - LOWER_A + 10;
|
|
23
|
+
}
|
|
24
|
+
else {
|
|
25
|
+
throw new Error(`Invalid IP component: ${input}`);
|
|
26
|
+
}
|
|
27
|
+
value = value * base + digit;
|
|
28
|
+
}
|
|
29
|
+
if (value < min || value > max) {
|
|
30
|
+
throw new Error(`Invalid IP component: ${input}`);
|
|
31
|
+
}
|
|
32
|
+
return value;
|
|
33
|
+
};
|
|
3
34
|
export const equateBuffers = (value1, value2) => {
|
|
4
35
|
if (value1.byteLength !== value2.byteLength) {
|
|
5
36
|
return false;
|
|
@@ -67,9 +98,6 @@ export const concatBuffers = (value1, value2) => {
|
|
|
67
98
|
return bytes.buffer;
|
|
68
99
|
};
|
|
69
100
|
export const formatBuffer = (value, formatting = "hex") => {
|
|
70
|
-
if (value == null) {
|
|
71
|
-
return "";
|
|
72
|
-
}
|
|
73
101
|
if (formatting === "base64") {
|
|
74
102
|
let binary = "";
|
|
75
103
|
const bytes = new Uint8Array(value);
|
|
@@ -80,12 +108,15 @@ export const formatBuffer = (value, formatting = "hex") => {
|
|
|
80
108
|
}
|
|
81
109
|
return btoa(binary);
|
|
82
110
|
}
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
111
|
+
else if (formatting === "hex") {
|
|
112
|
+
const bytes = new Uint8Array(value);
|
|
113
|
+
let str = "";
|
|
114
|
+
for (let i = 0; i < bytes.byteLength; ++i) {
|
|
115
|
+
str += bytes[i].toString(16).padStart(2, "0");
|
|
116
|
+
}
|
|
117
|
+
return str;
|
|
87
118
|
}
|
|
88
|
-
|
|
119
|
+
throw new Error(`${formatting} formatting not supported`);
|
|
89
120
|
};
|
|
90
121
|
export const parseBuffer = (value) => {
|
|
91
122
|
if (value == null) {
|
|
@@ -93,7 +124,7 @@ export const parseBuffer = (value) => {
|
|
|
93
124
|
}
|
|
94
125
|
const bytes = new Uint8Array(Math.ceil(value.length / 2));
|
|
95
126
|
for (let i = 0, c = 0; c < value.length; ++i) {
|
|
96
|
-
bytes[i] =
|
|
127
|
+
bytes[i] = parseBoundedInteger(value.slice(c, c += 2), 16, 0, 0xff);
|
|
97
128
|
}
|
|
98
129
|
return bytes.buffer;
|
|
99
130
|
};
|
|
@@ -101,8 +132,8 @@ export const funcByte = new Constant((value, pos) => value == null
|
|
|
101
132
|
? undefined
|
|
102
133
|
: value.slice(Number(pos), Number(pos) + 1), Type.functionType(Type.OptionalBuffer, [Type.Buffer, Type.Integer]));
|
|
103
134
|
const funcRandomBuffer = new Constant((value) => value == null || value <= 0n ? new Uint8Array(0).buffer : crypto.getRandomValues(new Uint8Array(Number(value))).buffer, Type.functionType(Type.Buffer, [Type.Integer]), false);
|
|
104
|
-
const funcParseBuffer = new Constant((value) => parseBuffer(value), Type.functionType(Type.OptionalBuffer, [Type.
|
|
105
|
-
export const constBuffer = {
|
|
135
|
+
const funcParseBuffer = new Constant((value) => parseBuffer(value), Type.functionType(Type.OptionalBuffer, [Type.OptionalString]));
|
|
136
|
+
export const constBuffer = Object.assign(Object.create(null), {
|
|
106
137
|
Random: funcRandomBuffer,
|
|
107
138
|
Parse: funcParseBuffer,
|
|
108
|
-
};
|
|
139
|
+
});
|
package/dst/native/Float.d.ts
CHANGED
|
@@ -1,22 +1,3 @@
|
|
|
1
|
-
import { Constant } from "../Constant.js";
|
|
2
1
|
export type FloatEncoding = "f32" | "f32le" | "f64" | "f64le";
|
|
3
|
-
export declare const encodeFloat: (value
|
|
4
|
-
export declare const constFloat:
|
|
5
|
-
NAN: Constant;
|
|
6
|
-
PositiveInfinity: Constant;
|
|
7
|
-
NegativeInfinity: Constant;
|
|
8
|
-
Epsilon: Constant;
|
|
9
|
-
Sum: Constant;
|
|
10
|
-
Min: Constant;
|
|
11
|
-
Max: Constant;
|
|
12
|
-
Exponent: Constant;
|
|
13
|
-
Logarithm: Constant;
|
|
14
|
-
Abs: Constant;
|
|
15
|
-
Ceil: Constant;
|
|
16
|
-
Floor: Constant;
|
|
17
|
-
Round: Constant;
|
|
18
|
-
Truncate: Constant;
|
|
19
|
-
Random: Constant;
|
|
20
|
-
Decode: Constant;
|
|
21
|
-
Parse: Constant;
|
|
22
|
-
};
|
|
2
|
+
export declare const encodeFloat: (value: number, encoding?: FloatEncoding) => ArrayBuffer;
|
|
3
|
+
export declare const constFloat: any;
|
package/dst/native/Float.js
CHANGED
|
@@ -1,9 +1,6 @@
|
|
|
1
1
|
import { Constant } from "../Constant.js";
|
|
2
2
|
import { Type } from "../Type.js";
|
|
3
3
|
export const encodeFloat = (value, encoding = "f64") => {
|
|
4
|
-
if (value == null) {
|
|
5
|
-
return new Uint8Array(0).buffer;
|
|
6
|
-
}
|
|
7
4
|
let bits = "";
|
|
8
5
|
for (let i = 0; i < encoding.length; ++i) {
|
|
9
6
|
const c = encoding[i];
|
|
@@ -56,9 +53,9 @@ const funcFloor = new Constant((value) => Math.floor(Number(value)), typeTransfo
|
|
|
56
53
|
const funcRound = new Constant((value) => Math.round(Number(value)), typeTransform);
|
|
57
54
|
const funcTruncate = new Constant((value) => Math.trunc(Number(value)), typeTransform);
|
|
58
55
|
const funcRandomFloat = new Constant((value) => value == null ? undefined : Math.random() * Number(value), Type.functionType(Type.Float, [Type.Float]), false);
|
|
59
|
-
const funcDecodeFloat = new Constant((value, encoding = "f64", byteOffset) => decodeFloat(value, encoding, byteOffset == null ? undefined : Number(byteOffset)), Type.functionType(Type.OptionalFloat, [Type.
|
|
60
|
-
const funcParseFloat = new Constant((value) => value ? Number.parseFloat(value) : undefined, Type.functionType(Type.OptionalFloat, [Type.
|
|
61
|
-
export const constFloat = {
|
|
56
|
+
const funcDecodeFloat = new Constant((value, encoding = "f64", byteOffset) => decodeFloat(value, encoding, byteOffset == null ? undefined : Number(byteOffset)), Type.functionType(Type.OptionalFloat, [Type.OptionalBuffer, Type.OptionalString, Type.OptionalInteger]));
|
|
57
|
+
const funcParseFloat = new Constant((value) => value ? Number.parseFloat(value) : undefined, Type.functionType(Type.OptionalFloat, [Type.OptionalString]));
|
|
58
|
+
export const constFloat = Object.assign(Object.create(null), {
|
|
62
59
|
NAN: new Constant(Number.NaN),
|
|
63
60
|
PositiveInfinity: new Constant(Number.POSITIVE_INFINITY),
|
|
64
61
|
NegativeInfinity: new Constant(Number.NEGATIVE_INFINITY),
|
|
@@ -76,4 +73,4 @@ export const constFloat = {
|
|
|
76
73
|
Random: funcRandomFloat,
|
|
77
74
|
Decode: funcDecodeFloat,
|
|
78
75
|
Parse: funcParseFloat,
|
|
79
|
-
};
|
|
76
|
+
});
|
package/dst/native/Integer.d.ts
CHANGED
|
@@ -1,11 +1,3 @@
|
|
|
1
|
-
import { Constant } from "../Constant.js";
|
|
2
1
|
export type IntegerEncoding = "i8" | "i16" | "i16le" | "i32" | "i32le" | "i64" | "i64le" | "n8" | "n16" | "n16le" | "n32" | "n32le" | "n64" | "n64le";
|
|
3
|
-
export declare const encodeInteger: (value
|
|
4
|
-
export declare const constInteger:
|
|
5
|
-
Sum: Constant;
|
|
6
|
-
Min: Constant;
|
|
7
|
-
Max: Constant;
|
|
8
|
-
Random: Constant;
|
|
9
|
-
Decode: Constant;
|
|
10
|
-
Parse: Constant;
|
|
11
|
-
};
|
|
2
|
+
export declare const encodeInteger: (value: bigint, encoding?: IntegerEncoding) => ArrayBuffer;
|
|
3
|
+
export declare const constInteger: any;
|
package/dst/native/Integer.js
CHANGED
|
@@ -1,9 +1,6 @@
|
|
|
1
1
|
import { Constant } from "../Constant.js";
|
|
2
2
|
import { Type } from "../Type.js";
|
|
3
3
|
export const encodeInteger = (value, encoding = "i64") => {
|
|
4
|
-
if (value == null) {
|
|
5
|
-
return new Uint8Array(0).buffer;
|
|
6
|
-
}
|
|
7
4
|
let bits = "";
|
|
8
5
|
for (let i = 0; i < encoding.length; ++i) {
|
|
9
6
|
const c = encoding[i];
|
|
@@ -88,13 +85,19 @@ const funcSum = new Constant((...values) => BigInt.asIntN(64, values.flat().redu
|
|
|
88
85
|
const funcMin = new Constant((...values) => BigInt.asIntN(64, values.flat().reduce((min, val) => val < min ? val : min)), typeAggregator);
|
|
89
86
|
const funcMax = new Constant((...values) => BigInt.asIntN(64, values.flat().reduce((max, val) => val > max ? val : max)), typeAggregator);
|
|
90
87
|
const funcRandomInteger = new Constant((value) => value == null ? undefined : BigInt.asIntN(64, BigInt(Math.floor(Math.random() * Number(value)))), Type.functionType(Type.Integer, [Type.Integer]), false);
|
|
91
|
-
const funcDecodeInteger = new Constant((value, encoding = "i64", byteOffset) => decodeInteger(value, encoding, byteOffset == null ? undefined : Number(byteOffset)), Type.functionType(Type.OptionalInteger, [Type.
|
|
92
|
-
const funcParseInteger = new Constant((value) =>
|
|
93
|
-
|
|
88
|
+
const funcDecodeInteger = new Constant((value, encoding = "i64", byteOffset) => decodeInteger(value, encoding, byteOffset == null ? undefined : Number(byteOffset)), Type.functionType(Type.OptionalInteger, [Type.OptionalBuffer, Type.OptionalString, Type.OptionalInteger]));
|
|
89
|
+
const funcParseInteger = new Constant((value) => {
|
|
90
|
+
try {
|
|
91
|
+
return value ? BigInt.asIntN(64, BigInt(value)) : undefined;
|
|
92
|
+
}
|
|
93
|
+
catch { }
|
|
94
|
+
return undefined;
|
|
95
|
+
}, Type.functionType(Type.OptionalInteger, [Type.OptionalString]));
|
|
96
|
+
export const constInteger = Object.assign(Object.create(null), {
|
|
94
97
|
Sum: funcSum,
|
|
95
98
|
Min: funcMin,
|
|
96
99
|
Max: funcMax,
|
|
97
100
|
Random: funcRandomInteger,
|
|
98
101
|
Decode: funcDecodeInteger,
|
|
99
102
|
Parse: funcParseInteger,
|
|
100
|
-
};
|
|
103
|
+
});
|
package/dst/native/Iterable.js
CHANGED
|
@@ -26,7 +26,8 @@ export const funcAt = new Constant((value, index) => {
|
|
|
26
26
|
const ix = Number(index);
|
|
27
27
|
return value[ix < 0 ? value.length + ix : ix];
|
|
28
28
|
}
|
|
29
|
-
|
|
29
|
+
const key = String(index);
|
|
30
|
+
return Object.hasOwn(value, key) ? value[key] : undefined;
|
|
30
31
|
}, Type.union(Type.functionType(Type.Unknown, [Type.Array, Type.Integer]), Type.functionType(Type.Unknown, [Type.Object, Type.String])));
|
|
31
32
|
export const funcHas = new Constant((value, index) => {
|
|
32
33
|
if (value == null) {
|
package/dst/native/Object.d.ts
CHANGED
|
@@ -2,6 +2,4 @@ import { Constant } from "../Constant.js";
|
|
|
2
2
|
export declare const funcEntries: Constant;
|
|
3
3
|
export declare const funcKeys: Constant;
|
|
4
4
|
export declare const funcValues: Constant;
|
|
5
|
-
export declare const constObject:
|
|
6
|
-
Merge: Constant;
|
|
7
|
-
};
|
|
5
|
+
export declare const constObject: any;
|
package/dst/native/Object.js
CHANGED
|
@@ -4,7 +4,7 @@ const typeAccessor = Type.functionType(Type.Array, [Type.Object]);
|
|
|
4
4
|
export const funcEntries = new Constant((value) => value ? Object.entries(value) : undefined, typeAccessor);
|
|
5
5
|
export const funcKeys = new Constant((value) => value ? Object.keys(value) : undefined, Type.functionType(Type.arrayType([Type.String]), [Type.Object]));
|
|
6
6
|
export const funcValues = new Constant((value) => value ? Object.values(value) : undefined, typeAccessor);
|
|
7
|
-
const funcMerge = new Constant((...values) => values.flat().reduce((acc, val) => Object.assign(acc, val),
|
|
8
|
-
export const constObject = {
|
|
7
|
+
const funcMerge = new Constant((...values) => values.flat().reduce((acc, val) => Object.assign(acc, val), Object.create(null)), Type.functionType(Type.Object, [Type.union(Type.arrayType([Type.Object]), Type.Object)], true));
|
|
8
|
+
export const constObject = Object.assign(Object.create(null), {
|
|
9
9
|
Merge: funcMerge,
|
|
10
|
-
};
|
|
10
|
+
});
|
package/dst/native/String.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Constant } from "../Constant.js";
|
|
2
|
-
export type StringEncoding = "utf8" | "ucs2" | "ucs2le";
|
|
2
|
+
export type StringEncoding = "utf8" | "sbcs" | "ucs2" | "ucs2le";
|
|
3
3
|
export declare const isSignSymbol: (c: string) => c is "+" | "-";
|
|
4
4
|
export declare const isNumericSymbol: (c: string) => boolean;
|
|
5
5
|
export declare const isAlphanumericSymbol: (c: string) => boolean;
|
|
@@ -16,7 +16,7 @@ export declare const equateStrings: (value1?: string, value2?: string, ignoreCas
|
|
|
16
16
|
export declare const containsString: (value?: string, search?: string, startPos?: number, ignoreCaseSpaceEtc?: boolean) => boolean;
|
|
17
17
|
export declare const startsWithString: (value?: string, search?: string, startPos?: number, ignoreCaseSpaceEtc?: boolean) => boolean;
|
|
18
18
|
export declare const endsWithString: (value?: string, search?: string, endPos?: number, ignoreCaseSpaceEtc?: boolean) => boolean;
|
|
19
|
-
export declare const encodeString: (value
|
|
19
|
+
export declare const encodeString: (value: string, encoding?: StringEncoding) => ArrayBuffer;
|
|
20
20
|
export declare const funcLike: Constant;
|
|
21
21
|
export declare const funcUnlike: Constant;
|
|
22
22
|
export declare const funcStartsWith: Constant;
|
|
@@ -30,8 +30,4 @@ export declare const funcLowerCase: Constant;
|
|
|
30
30
|
export declare const funcUpperCase: Constant;
|
|
31
31
|
export declare const funcSplit: Constant;
|
|
32
32
|
export declare const funcReplaceWith: Constant;
|
|
33
|
-
export declare const constString:
|
|
34
|
-
Alphanum: Constant;
|
|
35
|
-
Random: Constant;
|
|
36
|
-
Decode: Constant;
|
|
37
|
-
};
|
|
33
|
+
export declare const constString: any;
|
package/dst/native/String.js
CHANGED
|
@@ -143,16 +143,24 @@ export const endsWithString = (value, search, endPos, ignoreCaseSpaceEtc) => {
|
|
|
143
143
|
return true;
|
|
144
144
|
};
|
|
145
145
|
export const encodeString = (value, encoding = "utf8") => {
|
|
146
|
-
|
|
147
|
-
return new
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
146
|
+
switch (encoding) {
|
|
147
|
+
case "utf8": return new TextEncoder().encode(value).buffer;
|
|
148
|
+
case "sbcs": break;
|
|
149
|
+
case "ucs2": break;
|
|
150
|
+
case "ucs2le": break;
|
|
151
|
+
default: throw new Error(`${encoding} encoding not supported`);
|
|
152
|
+
}
|
|
153
|
+
if (encoding === "sbcs") {
|
|
154
|
+
const dv = new Uint8Array(value.length);
|
|
155
|
+
for (let i = 0; i < value.length; ++i) {
|
|
156
|
+
dv[i] = value.charCodeAt(i);
|
|
157
|
+
}
|
|
158
|
+
return dv.buffer;
|
|
151
159
|
}
|
|
152
160
|
const dv = new DataView(new Uint16Array(value.length).buffer);
|
|
153
|
-
const
|
|
161
|
+
const littleEndian = encoding.endsWith("le");
|
|
154
162
|
for (let i = 0; i < value.length; ++i) {
|
|
155
|
-
dv.setUint16(i << 1, value.charCodeAt(i),
|
|
163
|
+
dv.setUint16(i << 1, value.charCodeAt(i), littleEndian);
|
|
156
164
|
}
|
|
157
165
|
return dv.buffer;
|
|
158
166
|
};
|
|
@@ -160,18 +168,27 @@ const decodeString = (value, encoding = "utf8", byteOffset, byteLength) => {
|
|
|
160
168
|
if (value == null) {
|
|
161
169
|
return undefined;
|
|
162
170
|
}
|
|
163
|
-
|
|
164
|
-
return new TextDecoder().decode(new DataView(value, byteOffset, byteLength));
|
|
171
|
+
switch (encoding) {
|
|
172
|
+
case "utf8": return new TextDecoder().decode(new DataView(value, byteOffset, byteLength));
|
|
173
|
+
case "sbcs": break;
|
|
174
|
+
case "ucs2": break;
|
|
175
|
+
case "ucs2le": break;
|
|
176
|
+
default: throw new Error(`${encoding} encoding not supported`);
|
|
165
177
|
}
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
const lessOrEqual = encoding.endsWith("le");
|
|
178
|
+
const dv = new DataView(value, byteOffset, byteLength);
|
|
179
|
+
if (encoding === "sbcs") {
|
|
169
180
|
let str = "";
|
|
170
|
-
for (let i = 0; i < dv.byteLength; i
|
|
171
|
-
str += String.fromCharCode(dv.
|
|
181
|
+
for (let i = 0; i < dv.byteLength; ++i) {
|
|
182
|
+
str += String.fromCharCode(dv.getUint8(i));
|
|
172
183
|
}
|
|
173
184
|
return str;
|
|
174
185
|
}
|
|
186
|
+
const littleEndian = encoding.endsWith("le");
|
|
187
|
+
let str = "";
|
|
188
|
+
for (let i = 0; i < dv.byteLength; i += 2) {
|
|
189
|
+
str += String.fromCharCode(dv.getUint16(i, littleEndian));
|
|
190
|
+
}
|
|
191
|
+
return str;
|
|
175
192
|
};
|
|
176
193
|
const typeStringEquator = Type.functionType(Type.Boolean, [Type.String, Type.String]);
|
|
177
194
|
const typeStringComparator = Type.functionType(Type.Boolean, [Type.String, Type.String, Type.OptionalInteger, Type.OptionalBoolean]);
|
|
@@ -215,9 +232,9 @@ const funcRandomString = new Constant((value) => {
|
|
|
215
232
|
}
|
|
216
233
|
return str.slice(0, length);
|
|
217
234
|
}, Type.functionType(Type.String, [Type.Integer]), false);
|
|
218
|
-
const funcDecodeString = new Constant((value, encoding = "utf8", byteOffset, byteLength) => decodeString(value, encoding, byteOffset == null ? undefined : Number(byteOffset), byteLength == null ? undefined : Number(byteLength)), Type.functionType(Type.OptionalString, [Type.
|
|
219
|
-
export const constString = {
|
|
235
|
+
const funcDecodeString = new Constant((value, encoding = "utf8", byteOffset, byteLength) => decodeString(value, encoding, byteOffset == null ? undefined : Number(byteOffset), byteLength == null ? undefined : Number(byteLength)), Type.functionType(Type.OptionalString, [Type.OptionalBuffer, Type.OptionalString, Type.OptionalInteger, Type.OptionalInteger]));
|
|
236
|
+
export const constString = Object.assign(Object.create(null), {
|
|
220
237
|
Alphanum: funcAlphanum,
|
|
221
238
|
Random: funcRandomString,
|
|
222
239
|
Decode: funcDecodeString,
|
|
223
|
-
};
|
|
240
|
+
});
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { Constant } from "../Constant.js";
|
|
2
|
-
export type TimestampEncoding = "
|
|
3
|
-
export declare const encodeTimestamp: (value
|
|
2
|
+
export type TimestampEncoding = "i64" | "i64le";
|
|
3
|
+
export declare const encodeTimestamp: (value: Date, encoding?: TimestampEncoding) => ArrayBuffer;
|
|
4
4
|
export declare const decodeTimestamp: (value?: ArrayBuffer, encoding?: TimestampEncoding, byteOffset?: bigint) => Date | undefined;
|
|
5
|
-
export declare const formatTimestamp: (value
|
|
5
|
+
export declare const formatTimestamp: (value: Date, template?: string) => string;
|
|
6
6
|
export declare const funcYear: Constant;
|
|
7
7
|
export declare const funcMonth: Constant;
|
|
8
8
|
export declare const funcMonthIndex: Constant;
|
|
@@ -17,9 +17,4 @@ export declare const funcDaysSince: Constant;
|
|
|
17
17
|
export declare const funcHoursSince: Constant;
|
|
18
18
|
export declare const funcMinutesSince: Constant;
|
|
19
19
|
export declare const funcSecondsSince: Constant;
|
|
20
|
-
export declare const constTimestamp:
|
|
21
|
-
Now: Constant;
|
|
22
|
-
Epoch: Constant;
|
|
23
|
-
Decode: Constant;
|
|
24
|
-
Parse: Constant;
|
|
25
|
-
};
|
|
20
|
+
export declare const constTimestamp: any;
|
package/dst/native/Timestamp.js
CHANGED
|
@@ -2,17 +2,31 @@ import { Constant } from "../Constant.js";
|
|
|
2
2
|
import { Type } from "../Type.js";
|
|
3
3
|
const typeTimestampPart = Type.functionType(Type.Integer, [Type.Timestamp, Type.OptionalBoolean]);
|
|
4
4
|
const typeTimestampSince = Type.functionType(Type.Float, [Type.Timestamp, Type.Timestamp]);
|
|
5
|
-
export const encodeTimestamp = (value, encoding = "
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
5
|
+
export const encodeTimestamp = (value, encoding = "i64") => {
|
|
6
|
+
switch (encoding) {
|
|
7
|
+
case "i64": break;
|
|
8
|
+
case "i64le": break;
|
|
9
|
+
default: throw new Error(`${encoding} encoding not supported`);
|
|
10
|
+
}
|
|
11
|
+
const dv = new DataView(new BigInt64Array(1).buffer);
|
|
12
|
+
const littleEndian = encoding.endsWith("le");
|
|
13
|
+
dv.setBigInt64(0, BigInt(value?.getTime() ?? 0), littleEndian);
|
|
14
|
+
return dv.buffer;
|
|
10
15
|
};
|
|
11
|
-
export const decodeTimestamp = (value, encoding = "
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
16
|
+
export const decodeTimestamp = (value, encoding = "i64", byteOffset) => {
|
|
17
|
+
switch (encoding) {
|
|
18
|
+
case "i64": break;
|
|
19
|
+
case "i64le": break;
|
|
20
|
+
default: throw new Error(`${encoding} encoding not supported`);
|
|
21
|
+
}
|
|
22
|
+
const offset = byteOffset == null ? 0 : Number(byteOffset);
|
|
23
|
+
if (!value || offset < 0 || value.byteLength < offset + 8) {
|
|
24
|
+
return undefined;
|
|
15
25
|
}
|
|
26
|
+
const littleEndian = encoding.endsWith("le");
|
|
27
|
+
return new Date(Number(new DataView(value).getBigInt64(offset, littleEndian)));
|
|
28
|
+
};
|
|
29
|
+
export const formatTimestamp = (value, template) => {
|
|
16
30
|
if (!template || typeof template !== "string") {
|
|
17
31
|
return value.toISOString();
|
|
18
32
|
}
|
|
@@ -70,11 +84,11 @@ export const funcHoursSince = new Constant((value1, value2) => (value1?.getTime(
|
|
|
70
84
|
export const funcMinutesSince = new Constant((value1, value2) => (value1?.getTime() - value2?.getTime()) / 60000.0, typeTimestampSince);
|
|
71
85
|
export const funcSecondsSince = new Constant((value1, value2) => (value1?.getTime() - value2?.getTime()) / 1000.0, typeTimestampSince);
|
|
72
86
|
const funcEpochTimestamp = new Constant((value, epoch = new Date(0)) => new Date(Number(value ?? 0) + epoch?.getTime()), Type.functionType(Type.Timestamp, [Type.Number, Type.OptionalTimestamp]));
|
|
73
|
-
const funcDecodeTimestamp = new Constant((value, encoding = "
|
|
74
|
-
const funcParseTimestamp = new Constant((value) => parseTimestamp(value), Type.functionType(Type.OptionalTimestamp, [Type.
|
|
75
|
-
export const constTimestamp = {
|
|
87
|
+
const funcDecodeTimestamp = new Constant((value, encoding = "i64", byteOffset) => decodeTimestamp(value, encoding, byteOffset), Type.functionType(Type.OptionalTimestamp, [Type.OptionalBuffer, Type.OptionalString, Type.OptionalInteger]));
|
|
88
|
+
const funcParseTimestamp = new Constant((value) => parseTimestamp(value), Type.functionType(Type.OptionalTimestamp, [Type.OptionalString]));
|
|
89
|
+
export const constTimestamp = Object.assign(Object.create(null), {
|
|
76
90
|
Now: funcNow,
|
|
77
91
|
Epoch: funcEpochTimestamp,
|
|
78
92
|
Decode: funcDecodeTimestamp,
|
|
79
93
|
Parse: funcParseTimestamp,
|
|
80
|
-
};
|
|
94
|
+
});
|
package/dst/native/Unknown.js
CHANGED
|
@@ -3,7 +3,7 @@ import { Type } from "../Type.js";
|
|
|
3
3
|
import { encodeFloat } from "./Float.js";
|
|
4
4
|
import { encodeInteger } from "./Integer.js";
|
|
5
5
|
import { formatNumber } from "./Number.js";
|
|
6
|
-
import { formatBuffer, concatBuffers, equateBuffers } from "./Buffer.js";
|
|
6
|
+
import { formatBuffer, concatBuffers, equateBuffers, EmptyBuffer } from "./Buffer.js";
|
|
7
7
|
import { encodeString } from "./String.js";
|
|
8
8
|
import { encodeTimestamp, formatTimestamp } from "./Timestamp.js";
|
|
9
9
|
export const equate = (value1, value2) => {
|
|
@@ -51,7 +51,7 @@ export const equate = (value1, value2) => {
|
|
|
51
51
|
return true;
|
|
52
52
|
};
|
|
53
53
|
export const encode = (value, encoding) => value == null
|
|
54
|
-
?
|
|
54
|
+
? EmptyBuffer
|
|
55
55
|
: typeof value === "boolean"
|
|
56
56
|
? new Uint8Array([value ? 255 : 0]).buffer
|
|
57
57
|
: value instanceof Date
|
|
@@ -65,14 +65,14 @@ export const encode = (value, encoding) => value == null
|
|
|
65
65
|
: typeof value === "string"
|
|
66
66
|
? encodeString(value, encoding ?? "utf8")
|
|
67
67
|
: Array.isArray(value)
|
|
68
|
-
? value.map((i) => encode(i, encoding)).reduce((acc, val) => concatBuffers(acc, val))
|
|
68
|
+
? value.map((i) => encode(i, encoding)).reduce((acc, val) => concatBuffers(acc, val), EmptyBuffer)
|
|
69
69
|
: typeof value === "object"
|
|
70
70
|
? Object.entries(value)
|
|
71
71
|
.map(([k, v]) => concatBuffers(encode(k, encoding), encode(v, encoding)))
|
|
72
|
-
.reduce((acc, val) => concatBuffers(acc, val))
|
|
73
|
-
:
|
|
72
|
+
.reduce((acc, val) => concatBuffers(acc, val), EmptyBuffer)
|
|
73
|
+
: EmptyBuffer;
|
|
74
74
|
export const format = (value, formatting) => value == null
|
|
75
|
-
? "
|
|
75
|
+
? ""
|
|
76
76
|
: typeof value === "boolean"
|
|
77
77
|
? value.toString()
|
|
78
78
|
: value instanceof Date
|
|
@@ -86,15 +86,15 @@ export const format = (value, formatting) => value == null
|
|
|
86
86
|
: typeof value === "string"
|
|
87
87
|
? value
|
|
88
88
|
: Array.isArray(value)
|
|
89
|
-
? value.map((i) => format(i, formatting)).reduce((acc, val) => acc + val)
|
|
89
|
+
? value.map((i) => format(i, formatting)).reduce((acc, val) => acc + val, "")
|
|
90
90
|
: typeof value === "object"
|
|
91
91
|
? Object.entries(value)
|
|
92
92
|
.map(([k, v]) => format(k, formatting) + format(v, formatting))
|
|
93
|
-
.reduce((acc, val) => acc + val)
|
|
94
|
-
: "
|
|
93
|
+
.reduce((acc, val) => acc + val, "")
|
|
94
|
+
: "";
|
|
95
95
|
const typeEquator = Type.functionType(Type.Boolean, [Type.Unknown, Type.Unknown]);
|
|
96
96
|
export const funcCoalesce = new Constant((value, valueOtherwise) => value ?? valueOtherwise, Type.union(Type.functionType(Type.Unknown, [Type.Unknown, Type.Unknown]), Type.functionType(Type.OptionalFloat, [Type.OptionalFloat, Type.OptionalFloat]), Type.functionType(Type.OptionalBoolean, [Type.OptionalBoolean, Type.OptionalBoolean]), Type.functionType(Type.OptionalTimestamp, [Type.OptionalTimestamp, Type.OptionalTimestamp]), Type.functionType(Type.OptionalInteger, [Type.OptionalInteger, Type.OptionalInteger]), Type.functionType(Type.OptionalBuffer, [Type.OptionalBuffer, Type.OptionalBuffer]), Type.functionType(Type.OptionalString, [Type.OptionalString, Type.OptionalString]), Type.functionType(Type.OptionalArray, [Type.OptionalArray, Type.OptionalArray]), Type.functionType(Type.OptionalObject, [Type.OptionalObject, Type.OptionalObject]), Type.functionType(Type.OptionalFunction, [Type.OptionalFunction, Type.OptionalFunction])));
|
|
97
97
|
export const funcEqual = new Constant((value1, value2) => equate(value1, value2), typeEquator);
|
|
98
98
|
export const funcNotEqual = new Constant((value1, value2) => !equate(value1, value2), typeEquator);
|
|
99
|
-
export const funcEncode = new Constant((value, encoding) => encode(value, encoding), Type.union(Type.functionType(Type.Buffer, [Type.Boolean]), Type.functionType(Type.Buffer, [Type.Timestamp, Type.OptionalString]), Type.functionType(Type.Buffer, [Type.Float, Type.OptionalString]), Type.functionType(Type.Buffer, [Type.Integer, Type.OptionalString]), Type.functionType(Type.Buffer, [Type.Buffer]), Type.functionType(Type.Buffer, [Type.String, Type.OptionalString]), Type.functionType(Type.Buffer, [Type.Array, Type.OptionalString]), Type.functionType(Type.Buffer, [Type.Object, Type.OptionalString]), Type.functionType(Type.Buffer, [Type.Function])));
|
|
100
|
-
export const funcFormat = new Constant((value, formatting) => format(value, formatting), Type.union(Type.functionType(Type.String, [Type.Boolean]), Type.functionType(Type.String, [Type.Timestamp, Type.OptionalString]), Type.functionType(Type.String, [Type.Float, Type.OptionalString]), Type.functionType(Type.String, [Type.Integer, Type.OptionalString]), Type.functionType(Type.String, [Type.Buffer, Type.OptionalString]), Type.functionType(Type.String, [Type.String]), Type.functionType(Type.String, [Type.Array, Type.OptionalString]), Type.functionType(Type.String, [Type.Object, Type.OptionalString]), Type.functionType(Type.String, [Type.Function])));
|
|
99
|
+
export const funcEncode = new Constant((value, encoding) => encode(value, encoding), Type.union(Type.functionType(Type.Buffer, [Type.Void, Type.OptionalString]), Type.functionType(Type.Buffer, [Type.Boolean]), Type.functionType(Type.Buffer, [Type.Timestamp, Type.OptionalString]), Type.functionType(Type.Buffer, [Type.Float, Type.OptionalString]), Type.functionType(Type.Buffer, [Type.Integer, Type.OptionalString]), Type.functionType(Type.Buffer, [Type.Buffer]), Type.functionType(Type.Buffer, [Type.String, Type.OptionalString]), Type.functionType(Type.Buffer, [Type.Array, Type.OptionalString]), Type.functionType(Type.Buffer, [Type.Object, Type.OptionalString]), Type.functionType(Type.Buffer, [Type.Function])));
|
|
100
|
+
export const funcFormat = new Constant((value, formatting) => format(value, formatting), Type.union(Type.functionType(Type.String, [Type.Void, Type.OptionalString]), Type.functionType(Type.String, [Type.Boolean]), Type.functionType(Type.String, [Type.Timestamp, Type.OptionalString]), Type.functionType(Type.String, [Type.Float, Type.OptionalString]), Type.functionType(Type.String, [Type.Integer, Type.OptionalString]), Type.functionType(Type.String, [Type.Buffer, Type.OptionalString]), Type.functionType(Type.String, [Type.String]), Type.functionType(Type.String, [Type.Array, Type.OptionalString]), Type.functionType(Type.String, [Type.Object, Type.OptionalString]), Type.functionType(Type.String, [Type.Function])));
|
|
@@ -4,7 +4,7 @@ import { formatNumber } from "../Number.js";
|
|
|
4
4
|
import { formatBuffer } from "../Buffer.js";
|
|
5
5
|
export const formatAN = (value, whitespace) => {
|
|
6
6
|
if (value == null) {
|
|
7
|
-
return "
|
|
7
|
+
return "";
|
|
8
8
|
}
|
|
9
9
|
if (typeof value === "boolean") {
|
|
10
10
|
return value.toString();
|
|
@@ -26,17 +26,17 @@ export const formatAN = (value, whitespace) => {
|
|
|
26
26
|
}
|
|
27
27
|
if (Array.isArray(value)) {
|
|
28
28
|
const [prefix, suffix] = whitespace ? ["\n" + whitespace, "\n"] : ["", ""];
|
|
29
|
-
const lines = value.map((i) => `${prefix}${formatAN(i, whitespace)
|
|
29
|
+
const lines = value.map((i) => `${prefix}${formatAN(i, whitespace)?.split("\n").join(prefix) ?? ""}`);
|
|
30
30
|
return lines.length ? `[${lines.join(",")}${suffix}]` : "[]";
|
|
31
31
|
}
|
|
32
32
|
if (typeof value === "object") {
|
|
33
33
|
const [prefix, suffix, separator] = whitespace ? ["\n" + whitespace, "\n", ": "] : ["", "", ":"];
|
|
34
|
-
const lines = Object.entries(value).map(([k, v]) => `${prefix}"${k}"${separator}${formatAN(v, whitespace).split("\n").join(prefix)}`);
|
|
34
|
+
const lines = Object.entries(value).map(([k, v]) => `${prefix}"${k}"${separator}${formatAN(v, whitespace).split("\n").join(prefix) ?? ""}`);
|
|
35
35
|
return lines.length ? `[${lines.join(",")}${suffix}]` : "[:]";
|
|
36
36
|
}
|
|
37
37
|
return "function";
|
|
38
38
|
};
|
|
39
|
-
const funcFormatAN = new Constant((value, whitespace) => formatAN(value
|
|
40
|
-
export const constAN = {
|
|
39
|
+
const funcFormatAN = new Constant((value, whitespace) => formatAN(value, whitespace), Type.functionType(Type.String, [Type.Unknown, Type.OptionalString]));
|
|
40
|
+
export const constAN = Object.assign(Object.create(null), {
|
|
41
41
|
Format: funcFormatAN,
|
|
42
|
-
};
|
|
42
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const constIP: any;
|