affinirum 1.5.0 → 1.5.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 +30 -14
- package/dst/Affinirum.d.ts +33 -26
- package/dst/Affinirum.js +58 -44
- package/dst/ParserState.js +23 -79
- package/dst/Scope.d.ts +16 -0
- package/dst/Scope.js +49 -0
- package/dst/atom/ArrayAtom.js +4 -1
- package/dst/cjs/Affinirum.js +57 -43
- package/dst/cjs/ParserState.js +22 -78
- package/dst/cjs/Scope.js +53 -0
- package/dst/cjs/atom/ArrayAtom.js +4 -1
- package/dst/cjs/native/Aggregable.js +1 -1
- package/dst/cjs/native/Boolean.js +3 -1
- package/dst/cjs/native/Buffer.js +32 -3
- package/dst/cjs/native/Enumerable.js +5 -3
- package/dst/cjs/native/Float.js +17 -5
- package/dst/cjs/native/Integer.js +41 -13
- package/dst/cjs/native/Iterable.js +6 -4
- package/dst/cjs/native/Number.js +45 -1
- package/dst/cjs/native/String.js +68 -22
- package/dst/cjs/native/Timestamp.js +74 -17
- package/dst/cjs/native/Unknown.js +1 -1
- package/dst/cjs/native/notation/AN.js +152 -11
- package/dst/cjs/native/notation/IP.js +1 -1
- package/dst/cjs/native/notation/JSON.js +1 -1
- package/dst/cjs/node/BlockNode.js +5 -4
- package/dst/cjs/node/CallNode.js +7 -5
- package/dst/cjs/node/SwitchNode.js +7 -9
- package/dst/native/Aggregable.js +1 -1
- package/dst/native/Boolean.js +3 -1
- package/dst/native/Buffer.d.ts +2 -0
- package/dst/native/Buffer.js +29 -2
- package/dst/native/Enumerable.js +5 -3
- package/dst/native/Float.js +17 -5
- package/dst/native/Integer.js +41 -13
- package/dst/native/Iterable.js +6 -4
- package/dst/native/Number.d.ts +4 -0
- package/dst/native/Number.js +40 -0
- package/dst/native/String.d.ts +2 -7
- package/dst/native/String.js +65 -14
- package/dst/native/Timestamp.d.ts +4 -2
- package/dst/native/Timestamp.js +71 -16
- package/dst/native/Unknown.js +1 -1
- package/dst/native/notation/AN.d.ts +1 -0
- package/dst/native/notation/AN.js +152 -12
- package/dst/native/notation/IP.js +1 -1
- package/dst/native/notation/JSON.js +1 -1
- package/dst/node/BlockNode.js +5 -4
- package/dst/node/CallNode.js +7 -5
- package/dst/node/SwitchNode.js +7 -9
- package/package.json +1 -1
- package/dst/StaticScope.d.ts +0 -13
- package/dst/StaticScope.js +0 -44
- package/dst/cjs/StaticScope.js +0 -48
package/dst/cjs/native/Number.js
CHANGED
|
@@ -1,9 +1,53 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.funcNegate = exports.funcRoot = exports.funcPower = exports.funcModulo = exports.funcRemainder = exports.funcDivide = exports.funcMultiply = exports.funcSubtract = exports.funcLessOrEqual = exports.funcGreaterOrEqual = exports.funcLessThan = exports.funcGreaterThan = exports.formatNumber = void 0;
|
|
3
|
+
exports.funcNegate = exports.funcRoot = exports.funcPower = exports.funcModulo = exports.funcRemainder = exports.funcDivide = exports.funcMultiply = exports.funcSubtract = exports.funcLessOrEqual = exports.funcGreaterOrEqual = exports.funcLessThan = exports.funcGreaterThan = exports.formatNumber = exports.parseLiteralNumber = exports.formatLiteralNumber = exports.isNumericSymbol = exports.isSignSymbol = void 0;
|
|
4
4
|
const Constant_js_1 = require("../Constant.js");
|
|
5
5
|
const Type_js_1 = require("../Type.js");
|
|
6
6
|
const Integer_js_1 = require("./Integer.js");
|
|
7
|
+
const isSignSymbol = (c) => c === "+" || c === "-";
|
|
8
|
+
exports.isSignSymbol = isSignSymbol;
|
|
9
|
+
const isNumericSymbol = (c) => c >= "0" && c <= "9";
|
|
10
|
+
exports.isNumericSymbol = isNumericSymbol;
|
|
11
|
+
const formatLiteralNumber = (value) => {
|
|
12
|
+
return typeof value === "number" && Number.isInteger(value)
|
|
13
|
+
? `${value.toString()}.0`
|
|
14
|
+
: value.toString();
|
|
15
|
+
};
|
|
16
|
+
exports.formatLiteralNumber = formatLiteralNumber;
|
|
17
|
+
const parseLiteralNumber = (value, offset = 0) => {
|
|
18
|
+
let i = offset;
|
|
19
|
+
let integer = true;
|
|
20
|
+
while ((0, exports.isNumericSymbol)(value.charAt(i))) {
|
|
21
|
+
++i;
|
|
22
|
+
}
|
|
23
|
+
if (value.charAt(i) === ".") {
|
|
24
|
+
++i;
|
|
25
|
+
if ((0, exports.isNumericSymbol)(value.charAt(i))) {
|
|
26
|
+
++i;
|
|
27
|
+
while ((0, exports.isNumericSymbol)(value.charAt(i))) {
|
|
28
|
+
++i;
|
|
29
|
+
}
|
|
30
|
+
integer = false;
|
|
31
|
+
}
|
|
32
|
+
else {
|
|
33
|
+
--i;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
if (value.charAt(i) === "e") {
|
|
37
|
+
++i;
|
|
38
|
+
if ((0, exports.isNumericSymbol)(value.charAt(i))
|
|
39
|
+
|| (0, exports.isSignSymbol)(value.charAt(i))) {
|
|
40
|
+
++i;
|
|
41
|
+
while ((0, exports.isNumericSymbol)(value.charAt(i))) {
|
|
42
|
+
++i;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
integer = false;
|
|
46
|
+
}
|
|
47
|
+
const str = value.slice(offset, i);
|
|
48
|
+
return [integer ? (0, Integer_js_1.boundInteger)(BigInt(str)) : parseFloat(str), i];
|
|
49
|
+
};
|
|
50
|
+
exports.parseLiteralNumber = parseLiteralNumber;
|
|
7
51
|
const formatNumber = (value, formatting) => {
|
|
8
52
|
if (formatting) {
|
|
9
53
|
const nformat = JSON.parse(`{${formatting}}`);
|
package/dst/cjs/native/String.js
CHANGED
|
@@ -1,31 +1,72 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.constString = exports.funcReplaceWith = exports.funcSplit = exports.funcUpperCase = exports.funcLowerCase = exports.funcTrimEnd = exports.funcTrimStart = exports.funcTrim = exports.funcCharCode = exports.funcChar = exports.funcEndsWith = exports.funcStartsWith = exports.funcUnlike = exports.funcLike = exports.encodeString = exports.endsWithString = exports.startsWithString = exports.containsString = exports.equateStrings = exports.replaceWith = exports.
|
|
3
|
+
exports.constString = exports.funcReplaceWith = exports.funcSplit = exports.funcUpperCase = exports.funcLowerCase = exports.funcTrimEnd = exports.funcTrimStart = exports.funcTrim = exports.funcCharCode = exports.funcChar = exports.funcEndsWith = exports.funcStartsWith = exports.funcUnlike = exports.funcLike = exports.encodeString = exports.endsWithString = exports.startsWithString = exports.containsString = exports.equateStrings = exports.replaceWith = exports.parseLiteralString = exports.formatLiteralString = exports.isHexadecimalSymbol = exports.isTokenSymbol = exports.isTokenStartSymbol = exports.isAlphanumericSymbol = void 0;
|
|
4
4
|
const Constant_js_1 = require("../Constant.js");
|
|
5
5
|
const Type_js_1 = require("../Type.js");
|
|
6
6
|
const Integer_js_1 = require("./Integer.js");
|
|
7
|
-
const isSignSymbol = (c) => c === "+" || c === "-";
|
|
8
|
-
exports.isSignSymbol = isSignSymbol;
|
|
9
|
-
const isNumericSymbol = (c) => c >= "0" && c <= "9";
|
|
10
|
-
exports.isNumericSymbol = isNumericSymbol;
|
|
11
7
|
const isAlphanumericSymbol = (c) => c >= "a" && c <= "z" || c >= "0" && c <= "9";
|
|
12
8
|
exports.isAlphanumericSymbol = isAlphanumericSymbol;
|
|
13
9
|
const isTokenStartSymbol = (c) => c >= "a" && c <= "z" || c >= "A" && c <= "Z" || c === "_" || c === "#" || c === "$";
|
|
14
10
|
exports.isTokenStartSymbol = isTokenStartSymbol;
|
|
15
|
-
const isTokenSymbol = (c) => (0, exports.isTokenStartSymbol)(c) ||
|
|
11
|
+
const isTokenSymbol = (c) => (0, exports.isTokenStartSymbol)(c) || c >= "0" && c <= "9";
|
|
16
12
|
exports.isTokenSymbol = isTokenSymbol;
|
|
17
|
-
const
|
|
18
|
-
exports.isDateSeparatorSymbol = isDateSeparatorSymbol;
|
|
19
|
-
const isTimeSeparatorSymbol = (c) => c === ":";
|
|
20
|
-
exports.isTimeSeparatorSymbol = isTimeSeparatorSymbol;
|
|
21
|
-
const isDateTimeSeparatorSymbol = (c) => c === "T" || c === " " || c === "@";
|
|
22
|
-
exports.isDateTimeSeparatorSymbol = isDateTimeSeparatorSymbol;
|
|
23
|
-
const isDateSymbol = (c) => (0, exports.isNumericSymbol)(c) || (0, exports.isDateSeparatorSymbol)(c);
|
|
24
|
-
exports.isDateSymbol = isDateSymbol;
|
|
25
|
-
const isTimeSymbol = (c) => (0, exports.isNumericSymbol)(c) || (0, exports.isTimeSeparatorSymbol)(c);
|
|
26
|
-
exports.isTimeSymbol = isTimeSymbol;
|
|
27
|
-
const isHexadecimalSymbol = (c) => (0, exports.isNumericSymbol)(c) || c >= "a" && c <= "f" || c >= "A" && c <= "F";
|
|
13
|
+
const isHexadecimalSymbol = (c) => c >= "0" && c <= "9" || c >= "a" && c <= "f" || c >= "A" && c <= "F";
|
|
28
14
|
exports.isHexadecimalSymbol = isHexadecimalSymbol;
|
|
15
|
+
const formatLiteralString = (value) => {
|
|
16
|
+
let str = "\"";
|
|
17
|
+
for (let i = 0; i < value.length; ++i) {
|
|
18
|
+
const c = value.charAt(i);
|
|
19
|
+
if (c === "\r") {
|
|
20
|
+
str += "\\r";
|
|
21
|
+
}
|
|
22
|
+
else if (c === "\n") {
|
|
23
|
+
str += "\\n";
|
|
24
|
+
}
|
|
25
|
+
else if (c === "\t") {
|
|
26
|
+
str += "\\t";
|
|
27
|
+
}
|
|
28
|
+
else if (c === "\\" || c === "\"") {
|
|
29
|
+
str += `\\${c}`;
|
|
30
|
+
}
|
|
31
|
+
else {
|
|
32
|
+
str += c;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
return str + "\"";
|
|
36
|
+
};
|
|
37
|
+
exports.formatLiteralString = formatLiteralString;
|
|
38
|
+
const parseLiteralString = (value, offset = 0) => {
|
|
39
|
+
const q = value.charAt(offset);
|
|
40
|
+
for (let i = offset + 1, str = ""; i < value.length; ++i) {
|
|
41
|
+
const c = value.charAt(i);
|
|
42
|
+
if (c === q) {
|
|
43
|
+
return [str, i + 1];
|
|
44
|
+
}
|
|
45
|
+
if (c === "\\") {
|
|
46
|
+
if (++i === value.length) {
|
|
47
|
+
break;
|
|
48
|
+
}
|
|
49
|
+
const nc = value.charAt(i);
|
|
50
|
+
if (nc === "r") {
|
|
51
|
+
str += "\r";
|
|
52
|
+
}
|
|
53
|
+
else if (nc === "n") {
|
|
54
|
+
str += "\n";
|
|
55
|
+
}
|
|
56
|
+
else if (nc === "t") {
|
|
57
|
+
str += "\t";
|
|
58
|
+
}
|
|
59
|
+
else {
|
|
60
|
+
str += nc;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
else {
|
|
64
|
+
str += c;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
throw new Error(`missing closing string quotation mark ${q}`);
|
|
68
|
+
};
|
|
69
|
+
exports.parseLiteralString = parseLiteralString;
|
|
29
70
|
const replaceWith = (value, replacement, ...search) => {
|
|
30
71
|
if (value == null) {
|
|
31
72
|
return undefined;
|
|
@@ -186,7 +227,10 @@ const encodeString = (value, encoding = "utf8") => {
|
|
|
186
227
|
};
|
|
187
228
|
exports.encodeString = encodeString;
|
|
188
229
|
const decodeString = (value, encoding = "utf8", byteOffset, byteLength) => {
|
|
189
|
-
if (value == null
|
|
230
|
+
if (value == null ||
|
|
231
|
+
byteOffset != null && byteOffset < 0 ||
|
|
232
|
+
byteLength != null && byteLength < 0 ||
|
|
233
|
+
value.byteLength < (byteOffset ?? 0) + (byteLength ?? 0)) {
|
|
190
234
|
return undefined;
|
|
191
235
|
}
|
|
192
236
|
switch (encoding) {
|
|
@@ -207,7 +251,9 @@ const decodeString = (value, encoding = "utf8", byteOffset, byteLength) => {
|
|
|
207
251
|
const littleEndian = encoding.endsWith("le");
|
|
208
252
|
let str = "";
|
|
209
253
|
for (let i = 0; i < dv.byteLength; i += 2) {
|
|
210
|
-
|
|
254
|
+
if (dv.byteLength > i + 1) {
|
|
255
|
+
str += String.fromCharCode(dv.getUint16(i, littleEndian));
|
|
256
|
+
}
|
|
211
257
|
}
|
|
212
258
|
return str;
|
|
213
259
|
};
|
|
@@ -236,10 +282,10 @@ const funcAlphanum = new Constant_js_1.Constant((value) => {
|
|
|
236
282
|
if (!value) {
|
|
237
283
|
return undefined;
|
|
238
284
|
}
|
|
239
|
-
const
|
|
285
|
+
const str = value.toLowerCase();
|
|
240
286
|
let result = "";
|
|
241
|
-
for (let i = 0; i <
|
|
242
|
-
if ((0, exports.isAlphanumericSymbol)(
|
|
287
|
+
for (let i = 0; i < str.length; ++i) {
|
|
288
|
+
if ((0, exports.isAlphanumericSymbol)(str[i])) {
|
|
243
289
|
result += value[i];
|
|
244
290
|
}
|
|
245
291
|
}
|
|
@@ -1,35 +1,89 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.constTimestamp = exports.funcSecondsSince = exports.funcMinutesSince = exports.funcHoursSince = exports.funcDaysSince = exports.funcEpochTime = exports.funcMillisecond = exports.funcSecond = exports.funcMinute = exports.funcHour = exports.funcDay = exports.funcWeekdayIndex = exports.funcMonthIndex = exports.funcMonth = exports.funcYear = exports.formatTimestamp = exports.decodeTimestamp = exports.encodeTimestamp = void 0;
|
|
3
|
+
exports.constTimestamp = exports.funcSecondsSince = exports.funcMinutesSince = exports.funcHoursSince = exports.funcDaysSince = exports.funcEpochTime = exports.funcMillisecond = exports.funcSecond = exports.funcMinute = exports.funcHour = exports.funcDay = exports.funcWeekdayIndex = exports.funcMonthIndex = exports.funcMonth = exports.funcYear = exports.formatTimestamp = exports.decodeTimestamp = exports.encodeTimestamp = exports.parseLiteralTimestamp = exports.formatLiteralTimestamp = void 0;
|
|
4
4
|
const Constant_js_1 = require("../Constant.js");
|
|
5
5
|
const Type_js_1 = require("../Type.js");
|
|
6
6
|
const Integer_js_1 = require("./Integer.js");
|
|
7
|
+
const Number_js_1 = require("./Number.js");
|
|
8
|
+
const minuteMilliseconds = 60000;
|
|
7
9
|
const typeTimestampPart = Type_js_1.Type.functionType(Type_js_1.Type.Integer, [Type_js_1.Type.Timestamp, Type_js_1.Type.OptionalBoolean]);
|
|
8
10
|
const typeTimestampSince = Type_js_1.Type.functionType(Type_js_1.Type.Float, [Type_js_1.Type.Timestamp, Type_js_1.Type.Timestamp]);
|
|
11
|
+
const isDateSeparatorSymbol = (c) => c === "-";
|
|
12
|
+
const isTimeSeparatorSymbol = (c) => c === ":";
|
|
13
|
+
const isDateTimeSeparatorSymbol = (c) => c === "T" || c === " " || c === "@";
|
|
14
|
+
const isDateSymbol = (c) => (0, Number_js_1.isNumericSymbol)(c) || isDateSeparatorSymbol(c);
|
|
15
|
+
const isTimeSymbol = (c) => (0, Number_js_1.isNumericSymbol)(c) || isTimeSeparatorSymbol(c);
|
|
16
|
+
const formatLiteralTimestamp = (value) => `@${(0, exports.formatTimestamp)(value)}`;
|
|
17
|
+
exports.formatLiteralTimestamp = formatLiteralTimestamp;
|
|
18
|
+
const parseLiteralTimestamp = (value, offset = 0) => {
|
|
19
|
+
let i = offset + 1;
|
|
20
|
+
while (isDateSymbol(value.charAt(i))) {
|
|
21
|
+
++i;
|
|
22
|
+
}
|
|
23
|
+
if (isDateTimeSeparatorSymbol(value.charAt(i))) {
|
|
24
|
+
++i;
|
|
25
|
+
while (isTimeSymbol(value.charAt(i))) {
|
|
26
|
+
++i;
|
|
27
|
+
}
|
|
28
|
+
if (value.charAt(i) === "."
|
|
29
|
+
&& (0, Number_js_1.isNumericSymbol)(value.charAt(i + 1))) {
|
|
30
|
+
++i;
|
|
31
|
+
while ((0, Number_js_1.isNumericSymbol)(value.charAt(i))) {
|
|
32
|
+
++i;
|
|
33
|
+
}
|
|
34
|
+
if (value.charAt(i) === "Z") {
|
|
35
|
+
++i;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
return [new Date(value.slice(offset + 1, i)), i];
|
|
40
|
+
};
|
|
41
|
+
exports.parseLiteralTimestamp = parseLiteralTimestamp;
|
|
9
42
|
const encodeTimestamp = (value, encoding = "i64") => {
|
|
43
|
+
const littleEndian = encoding.endsWith("le");
|
|
10
44
|
switch (encoding) {
|
|
11
|
-
case "
|
|
12
|
-
case "
|
|
45
|
+
case "i32":
|
|
46
|
+
case "i32le": {
|
|
47
|
+
const dv = new DataView(new Int32Array(1).buffer);
|
|
48
|
+
const timer = value?.getTime() ?? 0;
|
|
49
|
+
dv.setInt32(0, (Number.isNaN(timer) ? 0 : timer) / minuteMilliseconds, littleEndian);
|
|
50
|
+
return dv.buffer;
|
|
51
|
+
}
|
|
52
|
+
case "i64":
|
|
53
|
+
case "i64le": {
|
|
54
|
+
const dv = new DataView(new BigInt64Array(1).buffer);
|
|
55
|
+
const timer = value?.getTime() ?? 0;
|
|
56
|
+
dv.setBigInt64(0, BigInt(Number.isNaN(timer) ? 0 : timer), littleEndian);
|
|
57
|
+
return dv.buffer;
|
|
58
|
+
}
|
|
13
59
|
default: throw new Error(`${encoding} encoding not supported`);
|
|
14
60
|
}
|
|
15
|
-
const dv = new DataView(new BigInt64Array(1).buffer);
|
|
16
|
-
const littleEndian = encoding.endsWith("le");
|
|
17
|
-
dv.setBigInt64(0, BigInt(value?.getTime() ?? 0), littleEndian);
|
|
18
|
-
return dv.buffer;
|
|
19
61
|
};
|
|
20
62
|
exports.encodeTimestamp = encodeTimestamp;
|
|
21
63
|
const decodeTimestamp = (value, encoding = "i64", byteOffset) => {
|
|
64
|
+
const littleEndian = encoding.endsWith("le");
|
|
65
|
+
const offset = byteOffset ?? 0;
|
|
66
|
+
if (!value || offset < 0) {
|
|
67
|
+
return undefined;
|
|
68
|
+
}
|
|
69
|
+
const dv = new DataView(value);
|
|
22
70
|
switch (encoding) {
|
|
23
|
-
case "
|
|
24
|
-
case "
|
|
71
|
+
case "i32":
|
|
72
|
+
case "i32le": {
|
|
73
|
+
const ts = value.byteLength < offset + 4
|
|
74
|
+
? undefined
|
|
75
|
+
: new Date(dv.getInt32(offset, littleEndian) * minuteMilliseconds);
|
|
76
|
+
return !ts || Number.isNaN(ts.getTime()) ? undefined : ts;
|
|
77
|
+
}
|
|
78
|
+
case "i64":
|
|
79
|
+
case "i64le": {
|
|
80
|
+
const ts = value.byteLength < offset + 8
|
|
81
|
+
? undefined
|
|
82
|
+
: new Date(Number(dv.getBigInt64(offset, littleEndian)));
|
|
83
|
+
return !ts || Number.isNaN(ts.getTime()) ? undefined : ts;
|
|
84
|
+
}
|
|
25
85
|
default: throw new Error(`${encoding} encoding not supported`);
|
|
26
86
|
}
|
|
27
|
-
const offset = byteOffset == null ? 0 : Number(byteOffset);
|
|
28
|
-
if (!value || offset < 0 || value.byteLength < offset + 8) {
|
|
29
|
-
return undefined;
|
|
30
|
-
}
|
|
31
|
-
const littleEndian = encoding.endsWith("le");
|
|
32
|
-
return new Date(Number(new DataView(value).getBigInt64(offset, littleEndian)));
|
|
33
87
|
};
|
|
34
88
|
exports.decodeTimestamp = decodeTimestamp;
|
|
35
89
|
const formatTimestamp = (value, template) => {
|
|
@@ -90,8 +144,11 @@ exports.funcDaysSince = new Constant_js_1.Constant((value1, value2) => (value1?.
|
|
|
90
144
|
exports.funcHoursSince = new Constant_js_1.Constant((value1, value2) => (value1?.getTime() - value2?.getTime()) / 3600000.0, typeTimestampSince);
|
|
91
145
|
exports.funcMinutesSince = new Constant_js_1.Constant((value1, value2) => (value1?.getTime() - value2?.getTime()) / 60000.0, typeTimestampSince);
|
|
92
146
|
exports.funcSecondsSince = new Constant_js_1.Constant((value1, value2) => (value1?.getTime() - value2?.getTime()) / 1000.0, typeTimestampSince);
|
|
93
|
-
const funcEpochTimestamp = new Constant_js_1.Constant((value, epoch = new Date(0)) =>
|
|
94
|
-
const
|
|
147
|
+
const funcEpochTimestamp = new Constant_js_1.Constant((value, epoch = new Date(0)) => {
|
|
148
|
+
const ts = new Date(Number(value ?? 0) + epoch?.getTime());
|
|
149
|
+
return Number.isNaN(ts.getTime()) ? undefined : ts;
|
|
150
|
+
}, Type_js_1.Type.functionType(Type_js_1.Type.Timestamp, [Type_js_1.Type.Number, Type_js_1.Type.OptionalTimestamp]));
|
|
151
|
+
const funcDecodeTimestamp = new Constant_js_1.Constant((value, encoding = "i64", byteOffset) => (0, exports.decodeTimestamp)(value, encoding, byteOffset == null ? undefined : Number(byteOffset)), Type_js_1.Type.functionType(Type_js_1.Type.OptionalTimestamp, [Type_js_1.Type.OptionalBuffer, Type_js_1.Type.OptionalString, Type_js_1.Type.OptionalInteger]));
|
|
95
152
|
const funcParseTimestamp = new Constant_js_1.Constant((value) => parseTimestamp(value), Type_js_1.Type.functionType(Type_js_1.Type.OptionalTimestamp, [Type_js_1.Type.OptionalString]));
|
|
96
153
|
exports.constTimestamp = Object.assign(Object.create(null), {
|
|
97
154
|
Now: funcNow,
|
|
@@ -3,10 +3,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.funcFormat = exports.funcEncode = exports.funcNotEqual = exports.funcEqual = exports.funcCoalesce = exports.format = exports.encode = exports.equate = void 0;
|
|
4
4
|
const Constant_js_1 = require("../Constant.js");
|
|
5
5
|
const Type_js_1 = require("../Type.js");
|
|
6
|
+
const Buffer_js_1 = require("./Buffer.js");
|
|
6
7
|
const Float_js_1 = require("./Float.js");
|
|
7
8
|
const Integer_js_1 = require("./Integer.js");
|
|
8
9
|
const Number_js_1 = require("./Number.js");
|
|
9
|
-
const Buffer_js_1 = require("./Buffer.js");
|
|
10
10
|
const String_js_1 = require("./String.js");
|
|
11
11
|
const Timestamp_js_1 = require("./Timestamp.js");
|
|
12
12
|
const equate = (value1, value2) => {
|
|
@@ -1,31 +1,34 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.constAN = exports.formatAN = void 0;
|
|
3
|
+
exports.constAN = exports.parseAN = exports.formatAN = void 0;
|
|
4
4
|
const Constant_js_1 = require("../../Constant.js");
|
|
5
|
+
const ParserState_js_1 = require("../../ParserState.js");
|
|
5
6
|
const Type_js_1 = require("../../Type.js");
|
|
7
|
+
const Aggregable_js_1 = require("../Aggregable.js");
|
|
8
|
+
const Integer_js_1 = require("../Integer.js");
|
|
6
9
|
const Number_js_1 = require("../Number.js");
|
|
7
10
|
const Buffer_js_1 = require("../Buffer.js");
|
|
11
|
+
const String_js_1 = require("../String.js");
|
|
12
|
+
const Timestamp_js_1 = require("../Timestamp.js");
|
|
13
|
+
const typeAN = Type_js_1.Type.union(Type_js_1.Type.Void, Type_js_1.Type.Boolean, Type_js_1.Type.Timestamp, Type_js_1.Type.Float, Type_js_1.Type.Integer, Type_js_1.Type.Buffer, Type_js_1.Type.String, Type_js_1.Type.Array, Type_js_1.Type.Object);
|
|
8
14
|
const formatAN = (value, whitespace) => {
|
|
9
15
|
if (value == null) {
|
|
10
16
|
return "";
|
|
11
17
|
}
|
|
12
18
|
if (typeof value === "boolean") {
|
|
13
|
-
return value
|
|
19
|
+
return value ? "true" : "false";
|
|
14
20
|
}
|
|
15
21
|
if (value instanceof Date) {
|
|
16
|
-
return
|
|
22
|
+
return (0, Timestamp_js_1.formatLiteralTimestamp)(value);
|
|
17
23
|
}
|
|
18
|
-
if (typeof value === "number") {
|
|
19
|
-
return (0, Number_js_1.
|
|
20
|
-
}
|
|
21
|
-
if (typeof value === "bigint") {
|
|
22
|
-
return (0, Number_js_1.formatNumber)(value);
|
|
24
|
+
if (typeof value === "bigint" || typeof value === "number") {
|
|
25
|
+
return (0, Number_js_1.formatLiteralNumber)(value);
|
|
23
26
|
}
|
|
24
27
|
if (value instanceof ArrayBuffer) {
|
|
25
|
-
return
|
|
28
|
+
return (0, Buffer_js_1.formatLiteralBuffer)(value);
|
|
26
29
|
}
|
|
27
30
|
if (typeof value === "string") {
|
|
28
|
-
return
|
|
31
|
+
return (0, String_js_1.formatLiteralString)(value);
|
|
29
32
|
}
|
|
30
33
|
if (Array.isArray(value)) {
|
|
31
34
|
const [prefix, suffix] = whitespace ? ["\n" + whitespace, "\n"] : ["", ""];
|
|
@@ -34,13 +37,151 @@ const formatAN = (value, whitespace) => {
|
|
|
34
37
|
}
|
|
35
38
|
if (typeof value === "object") {
|
|
36
39
|
const [prefix, suffix, separator] = whitespace ? ["\n" + whitespace, "\n", ": "] : ["", "", ":"];
|
|
37
|
-
const lines = Object.entries(value).map(([k, v]) => `${prefix}
|
|
40
|
+
const lines = Object.entries(value).map(([k, v]) => `${prefix}${(0, String_js_1.formatLiteralString)(k)}${separator}${(0, exports.formatAN)(v, whitespace).split("\n").join(prefix) ?? ""}`);
|
|
38
41
|
return lines.length ? `[${lines.join(",")}${suffix}]` : "[:]";
|
|
39
42
|
}
|
|
40
43
|
return "function";
|
|
41
44
|
};
|
|
42
45
|
exports.formatAN = formatAN;
|
|
46
|
+
const parseArray = (state, firstValue) => {
|
|
47
|
+
const arr = [firstValue];
|
|
48
|
+
while (!state.isEmpty) {
|
|
49
|
+
if (state.isBracketsClose) {
|
|
50
|
+
state.next();
|
|
51
|
+
return arr;
|
|
52
|
+
}
|
|
53
|
+
if (!state.isComma) {
|
|
54
|
+
state.throwError("missing array value separator");
|
|
55
|
+
}
|
|
56
|
+
state.next();
|
|
57
|
+
if (state.isBracketsClose) {
|
|
58
|
+
state.next();
|
|
59
|
+
return arr;
|
|
60
|
+
}
|
|
61
|
+
if (state.isComma) {
|
|
62
|
+
arr.push(undefined);
|
|
63
|
+
continue;
|
|
64
|
+
}
|
|
65
|
+
arr.push(parseLiteral(state));
|
|
66
|
+
}
|
|
67
|
+
state.throwError("missing closing array bracket");
|
|
68
|
+
};
|
|
69
|
+
const parseObject = (state, firstKey) => {
|
|
70
|
+
const obj = Object.create(null);
|
|
71
|
+
let key = firstKey;
|
|
72
|
+
while (!state.isEmpty) {
|
|
73
|
+
if (!state.isColon) {
|
|
74
|
+
state.throwError("missing object key separator");
|
|
75
|
+
}
|
|
76
|
+
state.next();
|
|
77
|
+
obj[key] = state.isComma || state.isBracketsClose ? undefined : parseLiteral(state);
|
|
78
|
+
if (state.isBracketsClose) {
|
|
79
|
+
state.next();
|
|
80
|
+
return obj;
|
|
81
|
+
}
|
|
82
|
+
if (!state.isComma) {
|
|
83
|
+
state.throwError("missing object property separator");
|
|
84
|
+
}
|
|
85
|
+
state.next();
|
|
86
|
+
if (state.isBracketsClose) {
|
|
87
|
+
state.next();
|
|
88
|
+
return obj;
|
|
89
|
+
}
|
|
90
|
+
const nextKey = parseLiteral(state);
|
|
91
|
+
if (typeof nextKey !== "string") {
|
|
92
|
+
state.throwError("object key must be a string");
|
|
93
|
+
}
|
|
94
|
+
key = nextKey;
|
|
95
|
+
}
|
|
96
|
+
state.throwError("missing closing object bracket");
|
|
97
|
+
};
|
|
98
|
+
const parseLiteral = (state) => {
|
|
99
|
+
if (state.isLiteral) {
|
|
100
|
+
const value = state.literal.value;
|
|
101
|
+
if (value instanceof Date && Number.isNaN(value.getTime())) {
|
|
102
|
+
state.throwError("invalid timestamp");
|
|
103
|
+
}
|
|
104
|
+
state.next();
|
|
105
|
+
return value;
|
|
106
|
+
}
|
|
107
|
+
if (state.isType && state.type.isVoid) {
|
|
108
|
+
state.next();
|
|
109
|
+
return undefined;
|
|
110
|
+
}
|
|
111
|
+
if (state.isToken) {
|
|
112
|
+
const token = state.token;
|
|
113
|
+
if (token === "NaN") {
|
|
114
|
+
state.next();
|
|
115
|
+
return NaN;
|
|
116
|
+
}
|
|
117
|
+
if (token === "Infinity") {
|
|
118
|
+
state.next();
|
|
119
|
+
return Infinity;
|
|
120
|
+
}
|
|
121
|
+
state.throwError(`invalid value ${token}`);
|
|
122
|
+
}
|
|
123
|
+
if (state.isOperator && (state.operator === Aggregable_js_1.funcAdd || state.operator === Number_js_1.funcSubtract)) {
|
|
124
|
+
const negative = state.operator === Number_js_1.funcSubtract;
|
|
125
|
+
state.next();
|
|
126
|
+
if (state.isToken && state.token === "Infinity") {
|
|
127
|
+
state.next();
|
|
128
|
+
return negative ? -Infinity : Infinity;
|
|
129
|
+
}
|
|
130
|
+
if (!state.isLiteral || typeof state.literal.value !== "number" && typeof state.literal.value !== "bigint") {
|
|
131
|
+
state.throwError("numeric literal expected after sign");
|
|
132
|
+
}
|
|
133
|
+
const value = state.literal.value;
|
|
134
|
+
state.next();
|
|
135
|
+
return negative
|
|
136
|
+
? typeof value === "bigint" ? (0, Integer_js_1.boundInteger)(-value) : -value
|
|
137
|
+
: value;
|
|
138
|
+
}
|
|
139
|
+
if (state.isBracketsOpen) {
|
|
140
|
+
state.next();
|
|
141
|
+
if (state.isBracketsClose) {
|
|
142
|
+
state.next();
|
|
143
|
+
return [];
|
|
144
|
+
}
|
|
145
|
+
if (state.isColon) {
|
|
146
|
+
state.next();
|
|
147
|
+
if (!state.isBracketsClose) {
|
|
148
|
+
state.throwError("missing closing object bracket");
|
|
149
|
+
}
|
|
150
|
+
state.next();
|
|
151
|
+
return Object.create(null);
|
|
152
|
+
}
|
|
153
|
+
if (state.isComma) {
|
|
154
|
+
return parseArray(state, undefined);
|
|
155
|
+
}
|
|
156
|
+
const first = parseLiteral(state);
|
|
157
|
+
if (state.isColon) {
|
|
158
|
+
if (typeof first !== "string") {
|
|
159
|
+
state.throwError("object key must be a string");
|
|
160
|
+
}
|
|
161
|
+
return parseObject(state, first);
|
|
162
|
+
}
|
|
163
|
+
return parseArray(state, first);
|
|
164
|
+
}
|
|
165
|
+
state.throwError("missing value");
|
|
166
|
+
};
|
|
167
|
+
const parseAN = (value) => {
|
|
168
|
+
if (value == null) {
|
|
169
|
+
return undefined;
|
|
170
|
+
}
|
|
171
|
+
const state = new ParserState_js_1.ParserState(value).next();
|
|
172
|
+
if (state.isEmpty) {
|
|
173
|
+
return undefined;
|
|
174
|
+
}
|
|
175
|
+
const result = parseLiteral(state);
|
|
176
|
+
if (!state.isEmpty) {
|
|
177
|
+
state.throwError("unexpected token");
|
|
178
|
+
}
|
|
179
|
+
return result;
|
|
180
|
+
};
|
|
181
|
+
exports.parseAN = parseAN;
|
|
43
182
|
const funcFormatAN = new Constant_js_1.Constant((value, whitespace) => (0, exports.formatAN)(value, whitespace), Type_js_1.Type.functionType(Type_js_1.Type.String, [Type_js_1.Type.Unknown, Type_js_1.Type.OptionalString]));
|
|
183
|
+
const funcParseAN = new Constant_js_1.Constant((value) => (0, exports.parseAN)(value), Type_js_1.Type.functionType(typeAN, [Type_js_1.Type.OptionalString]));
|
|
44
184
|
exports.constAN = Object.assign(Object.create(null), {
|
|
45
185
|
Format: funcFormatAN,
|
|
186
|
+
Parse: funcParseAN,
|
|
46
187
|
});
|
|
@@ -135,7 +135,7 @@ function decodeIP(value) {
|
|
|
135
135
|
}
|
|
136
136
|
return prefix == null ? address : `${address}/${prefix}`;
|
|
137
137
|
}
|
|
138
|
-
throw new
|
|
138
|
+
throw new RangeError(`Invalid IP buffer length: ${dv.byteLength}`);
|
|
139
139
|
}
|
|
140
140
|
class IPSet {
|
|
141
141
|
_ipv4Sets = Array(33).fill(undefined);
|
|
@@ -4,7 +4,7 @@ exports.constJSON = exports.formatJSON = void 0;
|
|
|
4
4
|
const Constant_js_1 = require("../../Constant.js");
|
|
5
5
|
const Type_js_1 = require("../../Type.js");
|
|
6
6
|
const typeJson = Type_js_1.Type.union(Type_js_1.Type.Void, Type_js_1.Type.Boolean, Type_js_1.Type.Timestamp, Type_js_1.Type.Float, Type_js_1.Type.Integer, Type_js_1.Type.String, Type_js_1.Type.Array, Type_js_1.Type.Object);
|
|
7
|
-
const formatJSON = (value, whitespace) => value == null ? "" : JSON.stringify(value, (_key, value) => typeof value === "bigint" ?
|
|
7
|
+
const formatJSON = (value, whitespace) => value == null ? "" : JSON.stringify(value, (_key, value) => typeof value === "bigint" ? value.toString() : value, whitespace);
|
|
8
8
|
exports.formatJSON = formatJSON;
|
|
9
9
|
const funcFormatJSON = new Constant_js_1.Constant((value, whitespace) => (0, exports.formatJSON)(value, whitespace), Type_js_1.Type.functionType(Type_js_1.Type.String, [typeJson, Type_js_1.Type.OptionalString]));
|
|
10
10
|
const funcParseJSON = new Constant_js_1.Constant((value) => value == null ? undefined : JSON.parse(value), Type_js_1.Type.functionType(typeJson, [Type_js_1.Type.OptionalString]));
|
|
@@ -12,9 +12,13 @@ class BlockNode extends Node_js_1.Node {
|
|
|
12
12
|
this._subnodes = _subnodes;
|
|
13
13
|
}
|
|
14
14
|
get type() {
|
|
15
|
-
return this._subnodes[this._subnodes.length - 1].type;
|
|
15
|
+
return this._subnodes.length ? this._subnodes[this._subnodes.length - 1].type : Type_js_1.Type.Void;
|
|
16
16
|
}
|
|
17
17
|
compile(type) {
|
|
18
|
+
if (this._subnodes.length === 0) {
|
|
19
|
+
this.reduceType(type);
|
|
20
|
+
return new ConstantNode_js_1.ConstantNode(this, Constant_js_1.Constant.Null);
|
|
21
|
+
}
|
|
18
22
|
let constant = true;
|
|
19
23
|
for (let i = 0, last = this._subnodes.length - 1; i < this._subnodes.length; ++i) {
|
|
20
24
|
this._subnodes[i] = this._subnodes[i].compile(i < last ? Type_js_1.Type.Unknown : type);
|
|
@@ -23,9 +27,6 @@ class BlockNode extends Node_js_1.Node {
|
|
|
23
27
|
if (constant) {
|
|
24
28
|
return new ConstantNode_js_1.ConstantNode(this, new Constant_js_1.Constant(this.evaluate(), this.type));
|
|
25
29
|
}
|
|
26
|
-
if (this._subnodes.length === 0) {
|
|
27
|
-
return new ConstantNode_js_1.ConstantNode(this, Constant_js_1.Constant.Null);
|
|
28
|
-
}
|
|
29
30
|
if (this._subnodes.length === 1) {
|
|
30
31
|
return this._subnodes[0];
|
|
31
32
|
}
|
package/dst/cjs/node/CallNode.js
CHANGED
|
@@ -28,11 +28,11 @@ class CallNode extends Node_js_1.Node {
|
|
|
28
28
|
compile(type) {
|
|
29
29
|
this._fnode = this._fnode.compile(this._fnode.type);
|
|
30
30
|
const functionAtoms_ = this._fnode.type.functionAtoms(type, this._subnodes.length);
|
|
31
|
-
let functionAtoms = functionAtoms_.filter((atom) => !atom.isVariadic);
|
|
32
|
-
if (!functionAtoms.length
|
|
33
|
-
functionAtoms = functionAtoms_.filter((atom) => atom.isVariadic);
|
|
31
|
+
let functionAtoms = functionAtoms_.filter((atom) => !atom.isVariadic && this._subnodes.every((node, index) => node.type.intersect(atom.paramType(index) ?? Type_js_1.Type.Unknown)));
|
|
32
|
+
if (!functionAtoms.length) {
|
|
33
|
+
functionAtoms = functionAtoms_.filter((atom) => atom.isVariadic && this._subnodes.every((node, index) => node.type.intersect(atom.paramType(index) ?? Type_js_1.Type.Unknown)));
|
|
34
34
|
}
|
|
35
|
-
if (!functionAtoms.length
|
|
35
|
+
if (!functionAtoms.length) {
|
|
36
36
|
this.throwError(`value of type ${this._fnode.type} cannot be called with ${this._subnodes.length} argument(s) and return a type compatible with ${type}`);
|
|
37
37
|
}
|
|
38
38
|
this._type = Type_js_1.Type.union(...functionAtoms.map((i) => i.retType));
|
|
@@ -47,7 +47,9 @@ class CallNode extends Node_js_1.Node {
|
|
|
47
47
|
let constant = this._fnode.constant;
|
|
48
48
|
for (let i = 0; i < this._subnodes.length; ++i) {
|
|
49
49
|
const argTypes = functionAtoms.map((a) => a.argType(i));
|
|
50
|
-
const argType =
|
|
50
|
+
const argType = arity > 0 && i === arity - 1
|
|
51
|
+
? Type_js_1.Type.arrayType([Type_js_1.Type.union(...functionAtoms.map((a) => a.paramType(i) ?? Type_js_1.Type.Unknown))])
|
|
52
|
+
: Type_js_1.Type.union(...argTypes.filter((t) => t != null));
|
|
51
53
|
this._subnodes[i] = this._subnodes[i].compile(argType);
|
|
52
54
|
constant &&= this._subnodes[i].constant;
|
|
53
55
|
}
|
|
@@ -24,15 +24,13 @@ class SwitchNode extends Node_js_1.Node {
|
|
|
24
24
|
compile(type) {
|
|
25
25
|
this._cnode = this._cnode.compile(Type_js_1.Type.Boolean);
|
|
26
26
|
this._type = type;
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
return new ConstantNode_js_1.ConstantNode(this, new Constant_js_1.Constant(this.evaluate(), this.type));
|
|
35
|
-
}
|
|
27
|
+
let constant = this._cnode.constant;
|
|
28
|
+
for (let i = 0; i < this._subnodes.length; ++i) {
|
|
29
|
+
this._subnodes[i] = this._subnodes[i].compile(type);
|
|
30
|
+
constant &&= this._subnodes[i].constant;
|
|
31
|
+
}
|
|
32
|
+
if (constant) {
|
|
33
|
+
return new ConstantNode_js_1.ConstantNode(this, new Constant_js_1.Constant(this.evaluate(), this.type));
|
|
36
34
|
}
|
|
37
35
|
return this;
|
|
38
36
|
}
|
package/dst/native/Aggregable.js
CHANGED
|
@@ -23,4 +23,4 @@ const add = (value1, value2) => {
|
|
|
23
23
|
}
|
|
24
24
|
return aggregate(value1, value2);
|
|
25
25
|
};
|
|
26
|
-
export const funcAdd = new Constant((value1, value2) => add(value1, value2), Type.union(Type.functionType(Type.Float, [Type.Float, Type.Integer]), Type.functionType(Type.Float, [Type.Integer, Type.Float]), Type.functionType(Type.Integer, [Type.Integer, Type.Integer]), Type.functionType(Type.Buffer, [Type.Buffer, Type.Buffer]), Type.functionType(Type.String, [Type.String, Type.String]), Type.functionType(Type.Array, [Type.Array, Type.Array])));
|
|
26
|
+
export const funcAdd = new Constant((value1, value2) => add(value1, value2), Type.union(Type.functionType(Type.Float, [Type.Float, Type.Float]), Type.functionType(Type.Float, [Type.Float, Type.Integer]), Type.functionType(Type.Float, [Type.Integer, Type.Float]), Type.functionType(Type.Integer, [Type.Integer, Type.Integer]), Type.functionType(Type.Buffer, [Type.Buffer, Type.Buffer]), Type.functionType(Type.String, [Type.String, Type.String]), Type.functionType(Type.Array, [Type.Array, Type.Array])));
|
package/dst/native/Boolean.js
CHANGED
|
@@ -7,7 +7,9 @@ export const funcAnd = new Constant((values) => values.flat().every((v) => v), t
|
|
|
7
7
|
export const funcNot = new Constant((value) => !value, Type.functionType(Type.Boolean, [Type.Boolean]));
|
|
8
8
|
const funcDecodeBoolean = new Constant((value, byteOffset) => {
|
|
9
9
|
const offset = byteOffset == null ? 0 : Number(byteOffset);
|
|
10
|
-
return value
|
|
10
|
+
return !value || offset < 0 || value.byteLength < offset + 1
|
|
11
|
+
? undefined
|
|
12
|
+
: Boolean(new Uint8Array(value)[offset]);
|
|
11
13
|
}, Type.functionType(Type.OptionalBoolean, [Type.OptionalBuffer, Type.OptionalInteger]));
|
|
12
14
|
const funcParseBoolean = new Constant((value) => {
|
|
13
15
|
if (value == null) {
|
package/dst/native/Buffer.d.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { Constant } from "../Constant.js";
|
|
2
2
|
export type BufferFormatting = "hex" | "base64";
|
|
3
3
|
export declare const EmptyBuffer: ArrayBuffer;
|
|
4
|
+
export declare const formatLiteralBuffer: (value: ArrayBuffer) => string;
|
|
5
|
+
export declare const parseLiteralBuffer: (value: string, offset?: number) => readonly [ArrayBuffer, number];
|
|
4
6
|
export declare const parseBoundedInteger: (input: string, base: 10 | 16, min: number, max: number) => number;
|
|
5
7
|
export declare const equateBuffers: (value1: ArrayBuffer, value2: ArrayBuffer) => boolean;
|
|
6
8
|
export declare const containsBuffer: (value: ArrayBuffer, search: ArrayBuffer, startPos?: number) => boolean;
|