affinirum 1.4.2 → 1.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (75) hide show
  1. package/README.md +214 -151
  2. package/dst/Affinirum.js +24 -15
  3. package/dst/Atom.d.ts +3 -1
  4. package/dst/Constant.js +1 -1
  5. package/dst/Functions.js +7 -4
  6. package/dst/Keywords.js +4 -4
  7. package/dst/ParserState.d.ts +2 -1
  8. package/dst/ParserState.js +22 -5
  9. package/dst/Type.d.ts +11 -7
  10. package/dst/Type.js +113 -38
  11. package/dst/Value.d.ts +1 -0
  12. package/dst/Value.js +19 -1
  13. package/dst/atom/ArrayAtom.d.ts +7 -3
  14. package/dst/atom/ArrayAtom.js +50 -8
  15. package/dst/atom/FunctionAtom.d.ts +4 -1
  16. package/dst/atom/FunctionAtom.js +65 -15
  17. package/dst/atom/ObjectAtom.d.ts +7 -5
  18. package/dst/atom/ObjectAtom.js +35 -13
  19. package/dst/atom/PrimitiveAtom.d.ts +3 -1
  20. package/dst/atom/PrimitiveAtom.js +10 -1
  21. package/dst/cjs/Affinirum.js +24 -15
  22. package/dst/cjs/Constant.js +1 -1
  23. package/dst/cjs/Functions.js +6 -3
  24. package/dst/cjs/Keywords.js +4 -4
  25. package/dst/cjs/ParserState.js +22 -5
  26. package/dst/cjs/Type.js +113 -38
  27. package/dst/cjs/Value.js +21 -0
  28. package/dst/cjs/atom/ArrayAtom.js +50 -8
  29. package/dst/cjs/atom/FunctionAtom.js +65 -15
  30. package/dst/cjs/atom/ObjectAtom.js +35 -13
  31. package/dst/cjs/atom/PrimitiveAtom.js +10 -1
  32. package/dst/cjs/native/Aggregable.js +2 -1
  33. package/dst/cjs/native/Array.js +10 -8
  34. package/dst/cjs/native/Boolean.js +5 -4
  35. package/dst/cjs/native/Enumerable.js +5 -4
  36. package/dst/cjs/native/Float.js +9 -8
  37. package/dst/cjs/native/Integer.js +23 -15
  38. package/dst/cjs/native/Iterable.js +2 -1
  39. package/dst/cjs/native/Number.js +18 -33
  40. package/dst/cjs/native/Object.js +2 -1
  41. package/dst/cjs/native/String.js +3 -2
  42. package/dst/cjs/native/Timestamp.js +2 -1
  43. package/dst/cjs/native/notation/IP.js +3 -2
  44. package/dst/cjs/node/ArrayNode.js +6 -6
  45. package/dst/cjs/node/CallNode.js +27 -23
  46. package/dst/cjs/node/CastNode.js +42 -0
  47. package/dst/cjs/node/ObjectNode.js +2 -4
  48. package/dst/cjs/node/SwitchNode.js +3 -1
  49. package/dst/cjs/node/VariableNode.js +3 -1
  50. package/dst/native/Aggregable.js +2 -1
  51. package/dst/native/Array.js +10 -8
  52. package/dst/native/Boolean.d.ts +1 -0
  53. package/dst/native/Boolean.js +4 -3
  54. package/dst/native/Enumerable.js +5 -4
  55. package/dst/native/Float.d.ts +2 -0
  56. package/dst/native/Float.js +8 -7
  57. package/dst/native/Integer.d.ts +5 -1
  58. package/dst/native/Integer.js +20 -14
  59. package/dst/native/Iterable.js +2 -1
  60. package/dst/native/Number.d.ts +0 -3
  61. package/dst/native/Number.js +17 -32
  62. package/dst/native/Object.js +2 -1
  63. package/dst/native/String.js +3 -2
  64. package/dst/native/Timestamp.js +2 -1
  65. package/dst/native/notation/IP.js +3 -2
  66. package/dst/node/ArrayNode.d.ts +1 -1
  67. package/dst/node/ArrayNode.js +6 -6
  68. package/dst/node/CallNode.js +27 -23
  69. package/dst/node/CastNode.d.ts +15 -0
  70. package/dst/node/CastNode.js +38 -0
  71. package/dst/node/ObjectNode.d.ts +1 -1
  72. package/dst/node/ObjectNode.js +2 -4
  73. package/dst/node/SwitchNode.js +3 -1
  74. package/dst/node/VariableNode.js +3 -1
  75. package/package.json +5 -4
@@ -9,29 +9,71 @@ class ArrayAtom {
9
9
  get _undefined() {
10
10
  return this._valTypes.length === 0;
11
11
  }
12
- subtypes() {
12
+ _intersectLength(length) {
13
+ return !this.isTuple || this._valTypes.slice(length).every((type) => type.isOptional);
14
+ }
15
+ get isTuple() {
16
+ return this._valTypes.length > 1;
17
+ }
18
+ valTypes() {
13
19
  return this._valTypes;
14
20
  }
15
- valueType(index) {
21
+ valType(index) {
16
22
  return this._valTypes[index];
17
23
  }
18
- match(atom) {
24
+ equate(atom) {
25
+ return atom instanceof ArrayAtom
26
+ && this._valTypes.length === atom._valTypes.length
27
+ && this._valTypes.every((type, index) => type.equate(atom._valTypes[index]));
28
+ }
29
+ accept(atom) {
19
30
  if (atom instanceof ArrayAtom) {
20
31
  if (this._undefined || atom._undefined) {
21
32
  return true;
22
33
  }
23
- for (let i = 0; i < this._valTypes.length; ++i) {
24
- const vtype = atom.valueType(i);
25
- if (!vtype || !this._valTypes[i].match(vtype)) {
26
- return false;
34
+ if (this.isTuple) {
35
+ for (let i = 0; i < this._valTypes.length; ++i) {
36
+ const vtype = atom.isTuple ? atom.valType(i) : atom.valType(0);
37
+ if (!vtype || !this._valTypes[i].accept(vtype)) {
38
+ return false;
39
+ }
40
+ }
41
+ }
42
+ else {
43
+ for (let i = 0; i < atom.valTypes().length; ++i) {
44
+ const vtype = atom.valType(i);
45
+ if (!vtype || !this._valTypes[0].accept(vtype)) {
46
+ return false;
47
+ }
27
48
  }
28
49
  }
29
50
  return true;
30
51
  }
31
52
  return false;
32
53
  }
54
+ intersect(atom) {
55
+ if (!(atom instanceof ArrayAtom)) {
56
+ return false;
57
+ }
58
+ if (this._undefined || atom._undefined) {
59
+ return true;
60
+ }
61
+ const length = this.isTuple
62
+ ? atom.isTuple ? Math.min(this._valTypes.length, atom._valTypes.length) : this._valTypes.length
63
+ : atom.isTuple ? atom._valTypes.length : 1;
64
+ for (let i = 0; i < length; ++i) {
65
+ const type = this.isTuple ? this._valTypes[i] : this._valTypes[0];
66
+ const atype = atom.isTuple ? atom._valTypes[i] : atom._valTypes[0];
67
+ if (!type.intersect(atype)) {
68
+ return (this.isTuple || atom.isTuple)
69
+ && this._intersectLength(i)
70
+ && atom._intersectLength(i);
71
+ }
72
+ }
73
+ return true;
74
+ }
33
75
  weight() {
34
- return 0x10000 + this.subtypes().reduce((acc, i) => acc + i.weight(), 0);
76
+ return 0x10000 + this.valTypes().reduce((acc, i) => acc + i.weight(), 0);
35
77
  }
36
78
  toString() {
37
79
  if (this._undefined) {
@@ -46,27 +46,77 @@ class FunctionAtom {
46
46
  argType(index) {
47
47
  return this._argTypes[index] ?? (this._isVariadic ? this._argTypes[this._argTypes.length - 1] : undefined);
48
48
  }
49
- match(atom) {
50
- if (atom instanceof FunctionAtom) {
51
- if (this._undefined || atom._undefined) {
52
- return true;
53
- }
54
- if (!this._retType.match(atom._retType) || this.minArity > atom.maxArity || this.maxArity < atom.minArity) {
49
+ paramType(index) {
50
+ if (!this._isVariadic) {
51
+ return this.argType(index);
52
+ }
53
+ if (!this._argTypes.length) {
54
+ return Type_js_1.Type.Unknown;
55
+ }
56
+ const variadicIndex = this._argTypes.length - 1;
57
+ if (index < variadicIndex) {
58
+ return this.argType(index);
59
+ }
60
+ return this.argType(variadicIndex)
61
+ ?.arrayAtomValType(index - variadicIndex);
62
+ }
63
+ equate(atom) {
64
+ return atom instanceof FunctionAtom
65
+ && this._isVariadic === atom._isVariadic
66
+ && this._argTypes.length === atom._argTypes.length
67
+ && this._retType.equate(atom._retType)
68
+ && this._argTypes.every((type, index) => type.equate(atom._argTypes[index]));
69
+ }
70
+ accept(atom) {
71
+ if (!(atom instanceof FunctionAtom)) {
72
+ return false;
73
+ }
74
+ if (this._undefined || atom._undefined) {
75
+ return true;
76
+ }
77
+ if (this._isVariadic !== atom._isVariadic
78
+ || this._isVariadic && this.arity !== atom.arity
79
+ || !this._retType.accept(atom._retType)
80
+ || this.minArity > atom.maxArity
81
+ || this.maxArity < atom.minArity) {
82
+ return false;
83
+ }
84
+ const argc = Math.min(this.arity, atom.arity);
85
+ for (let i = 0; i < argc; ++i) {
86
+ const type = this.argType(i)?.toMandatory();
87
+ const atype = atom.argType(i);
88
+ if (type && (!atype || !atype.accept(type))) {
55
89
  return false;
56
90
  }
57
- const argc = Math.max(this.minArity, atom.minArity);
58
- for (let i = 0; i < argc; ++i) {
59
- const atype = atom.argType(i);
60
- if (!atype || !this.argType(i)?.match(atype)) {
61
- return false;
62
- }
63
- }
91
+ }
92
+ return true;
93
+ }
94
+ intersect(atom) {
95
+ if (!(atom instanceof FunctionAtom)) {
96
+ return false;
97
+ }
98
+ if (this._undefined || atom._undefined) {
64
99
  return true;
65
100
  }
66
- return false;
101
+ if (this._isVariadic !== atom._isVariadic
102
+ || this._isVariadic && this.arity !== atom.arity
103
+ || !this._retType.intersect(atom._retType)
104
+ || this.minArity > atom.maxArity
105
+ || this.maxArity < atom.minArity) {
106
+ return false;
107
+ }
108
+ const argc = Math.max(this.minArity, atom.minArity);
109
+ for (let i = 0; i < argc; ++i) {
110
+ const type = this.argType(i);
111
+ const atype = atom.argType(i);
112
+ if (!type || !atype || !type.intersect(atype)) {
113
+ return false;
114
+ }
115
+ }
116
+ return true;
67
117
  }
68
118
  weight() {
69
- return 0x1000000000000 + (this._retType ? [this._retType, ...this._argTypes] : []).reduce((acc, i) => acc + i.weight(), 0);
119
+ return 0x1000000000000 + this._argTypes.reduce((acc, i) => acc + i.weight(), this._retType.weight());
70
120
  }
71
121
  toString() {
72
122
  if (this._undefined) {
@@ -1,28 +1,35 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ObjectAtom = void 0;
4
+ const Type_js_1 = require("../Type.js");
4
5
  class ObjectAtom {
5
6
  _valTypes;
6
- constructor(_valTypes = Object.create(null)) {
7
- this._valTypes = _valTypes;
7
+ constructor(valTypes = []) {
8
+ this._valTypes = [...new Map(valTypes)];
8
9
  }
9
10
  get _undefined() {
10
- return Object.keys(this._valTypes).length === 0;
11
+ return this._valTypes.length === 0;
11
12
  }
12
- subtypes() {
13
- return Object.values(this._valTypes);
13
+ valTypes() {
14
+ return this._valTypes;
14
15
  }
15
- valueType(key) {
16
- return this._valTypes[key];
16
+ valType(key) {
17
+ return this._valTypes.find((i) => i[0] === key)?.[1];
17
18
  }
18
- match(atom) {
19
+ equate(atom) {
20
+ if (!(atom instanceof ObjectAtom)) {
21
+ return false;
22
+ }
23
+ return this._valTypes.length === atom._valTypes.length && this._valTypes.every(([key, type]) => type.equate(atom.valType(key)));
24
+ }
25
+ accept(atom) {
19
26
  if (atom instanceof ObjectAtom) {
20
27
  if (this._undefined || atom._undefined) {
21
28
  return true;
22
29
  }
23
- for (const key in this._valTypes) {
24
- const vtype = atom.valueType(key);
25
- if (!vtype || !this._valTypes[key].match(vtype)) {
30
+ for (const [key, type] of this._valTypes) {
31
+ const atype = atom.valType(key) ?? Type_js_1.Type.Void;
32
+ if (!type.accept(atype)) {
26
33
  return false;
27
34
  }
28
35
  }
@@ -30,14 +37,29 @@ class ObjectAtom {
30
37
  }
31
38
  return false;
32
39
  }
40
+ intersect(atom) {
41
+ if (!(atom instanceof ObjectAtom)) {
42
+ return false;
43
+ }
44
+ if (this._undefined || atom._undefined) {
45
+ return true;
46
+ }
47
+ for (const [key, type] of this._valTypes) {
48
+ const atype = atom.valType(key);
49
+ if (atype && !type.intersect(atype)) {
50
+ return false;
51
+ }
52
+ }
53
+ return true;
54
+ }
33
55
  weight() {
34
- return 0x100000000 + this.subtypes().reduce((acc, i) => acc + i.weight(), 0);
56
+ return 0x100000000 + this._valTypes.reduce((acc, i) => acc + i[1].weight(), 0);
35
57
  }
36
58
  toString() {
37
59
  if (this._undefined) {
38
60
  return "object";
39
61
  }
40
- return `[${Object.entries(this._valTypes).map(([k, v]) => `"${k}":${v}`).join(",")}]`;
62
+ return `[${this._valTypes.map(([k, v]) => `"${k}":${v}`).join(",")}]`;
41
63
  }
42
64
  }
43
65
  exports.ObjectAtom = ObjectAtom;
@@ -9,12 +9,21 @@ class PrimitiveAtom {
9
9
  get undef() {
10
10
  return this._primitive === "void";
11
11
  }
12
- match(atom) {
12
+ equate(atom) {
13
13
  if (atom instanceof PrimitiveAtom) {
14
14
  return atom._primitive === this._primitive;
15
15
  }
16
16
  return false;
17
17
  }
18
+ accept(atom) {
19
+ if (atom instanceof PrimitiveAtom) {
20
+ return atom._primitive === this._primitive;
21
+ }
22
+ return false;
23
+ }
24
+ intersect(atom) {
25
+ return this.equate(atom);
26
+ }
18
27
  weight() {
19
28
  switch (this._primitive) {
20
29
  case "void": return 0x1;
@@ -4,6 +4,7 @@ exports.funcAdd = exports.aggregate = void 0;
4
4
  const Constant_js_1 = require("../Constant.js");
5
5
  const Type_js_1 = require("../Type.js");
6
6
  const Buffer_js_1 = require("./Buffer.js");
7
+ const Integer_js_1 = require("./Integer.js");
7
8
  const aggregate = (value1, value2) => {
8
9
  if (value1 == null || value2 == null) {
9
10
  return undefined;
@@ -19,7 +20,7 @@ const aggregate = (value1, value2) => {
19
20
  exports.aggregate = aggregate;
20
21
  const add = (value1, value2) => {
21
22
  if (typeof value1 === "bigint" && typeof value2 === "bigint") {
22
- return BigInt.asIntN(64, value1 + value2);
23
+ return (0, Integer_js_1.boundInteger)(value1 + value2);
23
24
  }
24
25
  if ((typeof value1 === "number" || typeof value1 === "bigint") && (typeof value2 === "number" || typeof value2 === "bigint")) {
25
26
  return Number(value1) + Number(value2);
@@ -3,12 +3,13 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.constArray = exports.funcAppend = exports.funcPrepend = exports.funcCompose = exports.funcReduce = exports.funcFilter = exports.funcDerive = exports.funcReverse = exports.funcFlatten = exports.funcAny = exports.funcEvery = exports.funcLastIndex = exports.funcFirstIndex = exports.funcLast = exports.funcFirst = void 0;
4
4
  const Constant_js_1 = require("../Constant.js");
5
5
  const Type_js_1 = require("../Type.js");
6
+ const Integer_js_1 = require("./Integer.js");
6
7
  const Unknown_js_1 = require("./Unknown.js");
7
8
  const typePredicate = Type_js_1.Type.functionType(Type_js_1.Type.Boolean, [Type_js_1.Type.Unknown, Type_js_1.Type.OptionalInteger, Type_js_1.Type.OptionalArray]);
8
9
  const typeItemFinder = Type_js_1.Type.functionType(Type_js_1.Type.Unknown, [Type_js_1.Type.Array, typePredicate]);
9
10
  const typeIndexFinder = Type_js_1.Type.functionType(Type_js_1.Type.OptionalInteger, [Type_js_1.Type.Array, typePredicate]);
10
11
  const typeConditionSet = Type_js_1.Type.functionType(Type_js_1.Type.Boolean, [Type_js_1.Type.Array, typePredicate]);
11
- const typeVariadicInsert = Type_js_1.Type.functionType(Type_js_1.Type.Array, [Type_js_1.Type.Array, Type_js_1.Type.Unknown], true);
12
+ const typeVariadicInsert = Type_js_1.Type.functionType(Type_js_1.Type.Array, [Type_js_1.Type.Array, Type_js_1.Type.Array], true);
12
13
  const typeArrayOperator = Type_js_1.Type.functionType(Type_js_1.Type.Array, [Type_js_1.Type.Array, Type_js_1.Type.Array]);
13
14
  exports.funcFirst = new Constant_js_1.Constant((value, predicate) => value?.find((v, i, a) => predicate(v, BigInt(i), a)), typeItemFinder);
14
15
  exports.funcLast = new Constant_js_1.Constant((value, predicate) => {
@@ -27,7 +28,7 @@ exports.funcFirstIndex = new Constant_js_1.Constant((value, predicate) => {
27
28
  return undefined;
28
29
  }
29
30
  const ix = value.findIndex((v, i, a) => predicate(v, BigInt(i), a));
30
- return ix < 0 ? undefined : BigInt.asIntN(64, BigInt(ix));
31
+ return ix < 0 ? undefined : (0, Integer_js_1.boundInteger)(BigInt(ix));
31
32
  }, typeIndexFinder);
32
33
  exports.funcLastIndex = new Constant_js_1.Constant((value, predicate) => {
33
34
  if (value == null) {
@@ -35,7 +36,7 @@ exports.funcLastIndex = new Constant_js_1.Constant((value, predicate) => {
35
36
  }
36
37
  for (let i = value.length - 1; i >= 0; i--) {
37
38
  if (predicate(value[i], BigInt(i), value)) {
38
- return BigInt.asIntN(64, BigInt(i));
39
+ return (0, Integer_js_1.boundInteger)(BigInt(i));
39
40
  }
40
41
  }
41
42
  return undefined;
@@ -60,18 +61,19 @@ exports.funcCompose = new Constant_js_1.Constant((value, callback) => {
60
61
  }
61
62
  return obj;
62
63
  }, Type_js_1.Type.functionType(Type_js_1.Type.Object, [Type_js_1.Type.Array, Type_js_1.Type.functionType(Type_js_1.Type.Unknown, [Type_js_1.Type.Object, Type_js_1.Type.String, Type_js_1.Type.OptionalInteger, Type_js_1.Type.OptionalArray])]));
63
- exports.funcPrepend = new Constant_js_1.Constant((value, ...items) => {
64
+ exports.funcPrepend = new Constant_js_1.Constant((value, items) => {
64
65
  value?.unshift(items);
65
66
  return value;
66
67
  }, typeVariadicInsert);
67
- exports.funcAppend = new Constant_js_1.Constant((value, ...items) => {
68
+ exports.funcAppend = new Constant_js_1.Constant((value, items) => {
68
69
  value?.push(items);
69
70
  return value;
70
71
  }, typeVariadicInsert);
71
- const funcJoin = new Constant_js_1.Constant((...values) => values.flat(Infinity), Type_js_1.Type.functionType(Type_js_1.Type.Array, [Type_js_1.Type.Array], true));
72
+ const funcJoin = new Constant_js_1.Constant((values) => values.flat(Infinity), Type_js_1.Type.functionType(Type_js_1.Type.Array, [Type_js_1.Type.arrayType([Type_js_1.Type.Array])], true));
72
73
  const funcRange = new Constant_js_1.Constant((value1, value2) => {
73
- const min = value1 < value2 ? value1 : value2;
74
- const max = value1 > value2 ? value1 : value2;
74
+ const v1 = (0, Integer_js_1.boundInteger)(value1);
75
+ const v2 = (0, Integer_js_1.boundInteger)(value2);
76
+ const [min, max] = v1 < v2 ? [v1, v2] : [v2, v1];
75
77
  return [...Array(Number(max - min)).keys()].map((i) => BigInt(i) + min);
76
78
  }, Type_js_1.Type.functionType(Type_js_1.Type.Array, [Type_js_1.Type.Integer, Type_js_1.Type.Integer]));
77
79
  const funcUnique = new Constant_js_1.Constant((value) => {
@@ -1,12 +1,12 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.constBoolean = exports.funcNot = exports.funcAnd = exports.funcOr = void 0;
3
+ exports.constBoolean = exports.funcBoolean = exports.funcNot = exports.funcAnd = exports.funcOr = void 0;
4
4
  const Constant_js_1 = require("../Constant.js");
5
5
  const Type_js_1 = require("../Type.js");
6
6
  const typeBooleanOrArray = Type_js_1.Type.union(Type_js_1.Type.Boolean, Type_js_1.Type.arrayType([Type_js_1.Type.Boolean]));
7
- const typeBooleanLogic = Type_js_1.Type.functionType(Type_js_1.Type.Boolean, [typeBooleanOrArray], true);
8
- exports.funcOr = new Constant_js_1.Constant((...values) => values.flat().some((v) => v), typeBooleanLogic);
9
- exports.funcAnd = new Constant_js_1.Constant((...values) => values.flat().every((v) => v), typeBooleanLogic);
7
+ const typeBooleanLogic = Type_js_1.Type.functionType(Type_js_1.Type.Boolean, [Type_js_1.Type.arrayType([typeBooleanOrArray])], true);
8
+ exports.funcOr = new Constant_js_1.Constant((values) => values.flat().some((v) => v), typeBooleanLogic);
9
+ exports.funcAnd = new Constant_js_1.Constant((values) => values.flat().every((v) => v), typeBooleanLogic);
10
10
  exports.funcNot = new Constant_js_1.Constant((value) => !value, Type_js_1.Type.functionType(Type_js_1.Type.Boolean, [Type_js_1.Type.Boolean]));
11
11
  const funcDecodeBoolean = new Constant_js_1.Constant((value, byteOffset) => {
12
12
  const offset = byteOffset == null ? 0 : Number(byteOffset);
@@ -19,6 +19,7 @@ const funcParseBoolean = new Constant_js_1.Constant((value) => {
19
19
  const v = value.toLowerCase();
20
20
  return v === "true" ? true : v === "false" ? false : undefined;
21
21
  }, Type_js_1.Type.functionType(Type_js_1.Type.OptionalBoolean, [Type_js_1.Type.OptionalString]));
22
+ exports.funcBoolean = new Constant_js_1.Constant((value) => typeof value === "bigint" ? value !== 0n : Boolean(Number(value)), Type_js_1.Type.union(Type_js_1.Type.functionType(Type_js_1.Type.Boolean, [Type_js_1.Type.Timestamp]), Type_js_1.Type.functionType(Type_js_1.Type.Boolean, [Type_js_1.Type.Float]), Type_js_1.Type.functionType(Type_js_1.Type.Boolean, [Type_js_1.Type.Integer])));
22
23
  exports.constBoolean = Object.assign(Object.create(null), {
23
24
  Or: exports.funcOr,
24
25
  And: exports.funcAnd,
@@ -4,12 +4,13 @@ exports.funcInject = exports.funcSplice = exports.funcSlice = void 0;
4
4
  const Constant_js_1 = require("../Constant.js");
5
5
  const Type_js_1 = require("../Type.js");
6
6
  const Aggregable_js_1 = require("./Aggregable.js");
7
+ const typeEnumerableArray = Type_js_1.Type.arrayType([Type_js_1.Type.Enumerable]);
7
8
  exports.funcSlice = new Constant_js_1.Constant((value, start = 0n, end) => value == null
8
9
  ? undefined
9
10
  : value.slice(Number(start), end == null ? undefined : Number(end)), Type_js_1.Type.union(Type_js_1.Type.functionType(Type_js_1.Type.Buffer, [Type_js_1.Type.Buffer, Type_js_1.Type.OptionalInteger, Type_js_1.Type.OptionalInteger]), Type_js_1.Type.functionType(Type_js_1.Type.String, [Type_js_1.Type.String, Type_js_1.Type.OptionalInteger, Type_js_1.Type.OptionalInteger]), Type_js_1.Type.functionType(Type_js_1.Type.Array, [Type_js_1.Type.Array, Type_js_1.Type.OptionalInteger, Type_js_1.Type.OptionalInteger])));
10
- exports.funcSplice = new Constant_js_1.Constant((value, start, remove, ...inject) => value == null
11
+ exports.funcSplice = new Constant_js_1.Constant((value, start, remove, inject) => value == null
11
12
  ? undefined
12
- : (0, Aggregable_js_1.aggregate)(inject.reduce((acc, val) => (0, Aggregable_js_1.aggregate)(acc, val), value.slice(0, Number(start))), value.slice(Number(start + remove))), Type_js_1.Type.union(Type_js_1.Type.functionType(Type_js_1.Type.Buffer, [Type_js_1.Type.Buffer, Type_js_1.Type.Integer, Type_js_1.Type.Integer, Type_js_1.Type.Enumerable], true), Type_js_1.Type.functionType(Type_js_1.Type.String, [Type_js_1.Type.String, Type_js_1.Type.Integer, Type_js_1.Type.Integer, Type_js_1.Type.Enumerable], true), Type_js_1.Type.functionType(Type_js_1.Type.Array, [Type_js_1.Type.Array, Type_js_1.Type.Integer, Type_js_1.Type.Integer, Type_js_1.Type.Enumerable], true)));
13
- exports.funcInject = new Constant_js_1.Constant((value, start, ...inject) => value == null
13
+ : (0, Aggregable_js_1.aggregate)(inject.reduce((acc, val) => (0, Aggregable_js_1.aggregate)(acc, val), value.slice(0, Number(start))), value.slice(Number(start + remove))), Type_js_1.Type.union(Type_js_1.Type.functionType(Type_js_1.Type.Buffer, [Type_js_1.Type.Buffer, Type_js_1.Type.Integer, Type_js_1.Type.Integer, typeEnumerableArray], true), Type_js_1.Type.functionType(Type_js_1.Type.String, [Type_js_1.Type.String, Type_js_1.Type.Integer, Type_js_1.Type.Integer, typeEnumerableArray], true), Type_js_1.Type.functionType(Type_js_1.Type.Array, [Type_js_1.Type.Array, Type_js_1.Type.Integer, Type_js_1.Type.Integer, typeEnumerableArray], true)));
14
+ exports.funcInject = new Constant_js_1.Constant((value, start, inject) => value == null
14
15
  ? undefined
15
- : (0, Aggregable_js_1.aggregate)(inject.reduce((acc, val) => (0, Aggregable_js_1.aggregate)(acc, val), value.slice(0, Number(start))), value.slice(Number(start))), Type_js_1.Type.union(Type_js_1.Type.functionType(Type_js_1.Type.Buffer, [Type_js_1.Type.Buffer, Type_js_1.Type.Integer, Type_js_1.Type.Enumerable], true), Type_js_1.Type.functionType(Type_js_1.Type.String, [Type_js_1.Type.String, Type_js_1.Type.Integer, Type_js_1.Type.Enumerable], true), Type_js_1.Type.functionType(Type_js_1.Type.Array, [Type_js_1.Type.Array, Type_js_1.Type.Integer, Type_js_1.Type.Enumerable], true)));
16
+ : (0, Aggregable_js_1.aggregate)(inject.reduce((acc, val) => (0, Aggregable_js_1.aggregate)(acc, val), value.slice(0, Number(start))), value.slice(Number(start))), Type_js_1.Type.union(Type_js_1.Type.functionType(Type_js_1.Type.Buffer, [Type_js_1.Type.Buffer, Type_js_1.Type.Integer, typeEnumerableArray], true), Type_js_1.Type.functionType(Type_js_1.Type.String, [Type_js_1.Type.String, Type_js_1.Type.Integer, typeEnumerableArray], true), Type_js_1.Type.functionType(Type_js_1.Type.Array, [Type_js_1.Type.Array, Type_js_1.Type.Integer, typeEnumerableArray], true)));
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.constFloat = exports.encodeFloat = void 0;
3
+ exports.constFloat = exports.funcFloat = exports.encodeFloat = void 0;
4
4
  const Constant_js_1 = require("../Constant.js");
5
5
  const Type_js_1 = require("../Type.js");
6
6
  const encodeFloat = (value, encoding = "f64") => {
@@ -43,12 +43,12 @@ const decodeFloat = (value, encoding = "f64", byteOffset) => {
43
43
  default: throw new Error(`${encoding} encoding not supported`);
44
44
  }
45
45
  };
46
- const typeNumberOrArray = Type_js_1.Type.union(Type_js_1.Type.Float, Type_js_1.Type.arrayType([Type_js_1.Type.Float]));
47
- const typeAggregator = Type_js_1.Type.functionType(Type_js_1.Type.Float, [typeNumberOrArray], true);
48
- const typeTransform = Type_js_1.Type.functionType(Type_js_1.Type.Float, [Type_js_1.Type.Float]);
49
- const funcSum = new Constant_js_1.Constant((...values) => values.flat().reduce((acc, val) => acc + Number(val), 0), typeAggregator);
50
- const funcMin = new Constant_js_1.Constant((...values) => Math.min(Number.POSITIVE_INFINITY, ...values.flat().map((i) => Number(i))), typeAggregator);
51
- const funcMax = new Constant_js_1.Constant((...values) => Math.max(Number.NEGATIVE_INFINITY, ...values.flat().map((i) => Number(i))), typeAggregator);
46
+ const typeNumberOrArray = Type_js_1.Type.union(Type_js_1.Type.Number, Type_js_1.Type.arrayType([Type_js_1.Type.Number]));
47
+ const typeAggregator = Type_js_1.Type.functionType(Type_js_1.Type.Float, [Type_js_1.Type.arrayType([typeNumberOrArray])], true);
48
+ const typeTransform = Type_js_1.Type.functionType(Type_js_1.Type.Float, [Type_js_1.Type.Number]);
49
+ const funcSum = new Constant_js_1.Constant((values) => values.flat().reduce((acc, val) => acc + Number(val), 0), typeAggregator);
50
+ const funcMin = new Constant_js_1.Constant((values) => Math.min(Number.POSITIVE_INFINITY, ...values.flat().map((i) => Number(i))), typeAggregator);
51
+ const funcMax = new Constant_js_1.Constant((values) => Math.max(Number.NEGATIVE_INFINITY, ...values.flat().map((i) => Number(i))), typeAggregator);
52
52
  const funcExponent = new Constant_js_1.Constant((value) => Math.exp(Number(value)), typeTransform);
53
53
  const funcLogarithm = new Constant_js_1.Constant((value) => Math.log(Number(value)), typeTransform);
54
54
  const funcAbs = new Constant_js_1.Constant((value) => Math.abs(Number(value)), typeTransform);
@@ -56,9 +56,10 @@ const funcCeil = new Constant_js_1.Constant((value) => Math.ceil(Number(value)),
56
56
  const funcFloor = new Constant_js_1.Constant((value) => Math.floor(Number(value)), typeTransform);
57
57
  const funcRound = new Constant_js_1.Constant((value) => Math.round(Number(value)), typeTransform);
58
58
  const funcTruncate = new Constant_js_1.Constant((value) => Math.trunc(Number(value)), typeTransform);
59
- const funcRandomFloat = new Constant_js_1.Constant((value) => value == null ? undefined : Math.random() * Number(value), Type_js_1.Type.functionType(Type_js_1.Type.Float, [Type_js_1.Type.Float]), false);
59
+ const funcRandomFloat = new Constant_js_1.Constant((value) => value == null ? undefined : Math.random() * Number(value), typeTransform, false);
60
60
  const funcDecodeFloat = new Constant_js_1.Constant((value, encoding = "f64", byteOffset) => decodeFloat(value, encoding, byteOffset == null ? undefined : Number(byteOffset)), Type_js_1.Type.functionType(Type_js_1.Type.OptionalFloat, [Type_js_1.Type.OptionalBuffer, Type_js_1.Type.OptionalString, Type_js_1.Type.OptionalInteger]));
61
61
  const funcParseFloat = new Constant_js_1.Constant((value) => value ? Number.parseFloat(value) : undefined, Type_js_1.Type.functionType(Type_js_1.Type.OptionalFloat, [Type_js_1.Type.OptionalString]));
62
+ exports.funcFloat = new Constant_js_1.Constant((value) => Number(value), Type_js_1.Type.union(Type_js_1.Type.functionType(Type_js_1.Type.Float, [Type_js_1.Type.Boolean]), Type_js_1.Type.functionType(Type_js_1.Type.Float, [Type_js_1.Type.Timestamp]), Type_js_1.Type.functionType(Type_js_1.Type.Float, [Type_js_1.Type.Integer])));
62
63
  exports.constFloat = Object.assign(Object.create(null), {
63
64
  NAN: new Constant_js_1.Constant(Number.NaN),
64
65
  PositiveInfinity: new Constant_js_1.Constant(Number.POSITIVE_INFINITY),
@@ -1,8 +1,23 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.constInteger = exports.encodeInteger = void 0;
3
+ exports.constInteger = exports.funcInteger = exports.encodeInteger = exports.createInteger = exports.boundInteger = void 0;
4
4
  const Constant_js_1 = require("../Constant.js");
5
5
  const Type_js_1 = require("../Type.js");
6
+ const boundInteger = (value) => BigInt.asIntN(64, value);
7
+ exports.boundInteger = boundInteger;
8
+ const createInteger = (value) => {
9
+ if (value == null || Number.isNaN(value)) {
10
+ return undefined;
11
+ }
12
+ if (value === Number.NEGATIVE_INFINITY) {
13
+ return -0x8000000000000000n;
14
+ }
15
+ if (value === Number.POSITIVE_INFINITY) {
16
+ return 0x7fffffffffffffffn;
17
+ }
18
+ return (0, exports.boundInteger)(BigInt(Math.trunc(value)));
19
+ };
20
+ exports.createInteger = createInteger;
6
21
  const encodeInteger = (value, encoding = "i64") => {
7
22
  let bits = "";
8
23
  for (let i = 0; i < encoding.length; ++i) {
@@ -49,12 +64,6 @@ const encodeInteger = (value, encoding = "i64") => {
49
64
  case "i64le":
50
65
  dv.setBigInt64(0, value, true);
51
66
  break;
52
- case "n64":
53
- dv.setBigUint64(0, value);
54
- break;
55
- case "n64le":
56
- dv.setBigUint64(0, value, true);
57
- break;
58
67
  default: throw new Error(`${encoding} encoding not supported`);
59
68
  }
60
69
  return dv.buffer;
@@ -78,25 +87,24 @@ const decodeInteger = (value, encoding = "i64", byteOffset) => {
78
87
  case "n16le": return BigInt(dv.getUint16(0, true));
79
88
  case "n32": return BigInt(dv.getUint32(0));
80
89
  case "n32le": return BigInt(dv.getUint32(0, true));
81
- case "n64": return dv.getBigUint64(0);
82
- case "n64le": return dv.getBigUint64(0, true);
83
90
  default: throw new Error(`${encoding} encoding not supported`);
84
91
  }
85
92
  };
86
93
  const typeIntegerOrArray = Type_js_1.Type.union(Type_js_1.Type.Integer, Type_js_1.Type.arrayType([Type_js_1.Type.Integer]));
87
- const typeAggregator = Type_js_1.Type.functionType(Type_js_1.Type.Integer, [typeIntegerOrArray], true);
88
- const funcSum = new Constant_js_1.Constant((...values) => BigInt.asIntN(64, values.flat().reduce((acc, val) => acc + val, 0n)), typeAggregator);
89
- const funcMin = new Constant_js_1.Constant((...values) => BigInt.asIntN(64, values.flat().reduce((min, val) => val < min ? val : min)), typeAggregator);
90
- const funcMax = new Constant_js_1.Constant((...values) => BigInt.asIntN(64, values.flat().reduce((max, val) => val > max ? val : max)), typeAggregator);
91
- const funcRandomInteger = new Constant_js_1.Constant((value) => value == null ? undefined : BigInt.asIntN(64, BigInt(Math.floor(Math.random() * Number(value)))), Type_js_1.Type.functionType(Type_js_1.Type.Integer, [Type_js_1.Type.Integer]), false);
94
+ const typeAggregator = Type_js_1.Type.functionType(Type_js_1.Type.Integer, [Type_js_1.Type.arrayType([typeIntegerOrArray])], true);
95
+ const funcSum = new Constant_js_1.Constant((values) => (0, exports.boundInteger)(values.flat().reduce((acc, val) => acc + val, 0n)), typeAggregator);
96
+ const funcMin = new Constant_js_1.Constant((values) => (0, exports.boundInteger)(values.flat().reduce((min, val) => val < min ? val : min)), typeAggregator);
97
+ const funcMax = new Constant_js_1.Constant((values) => (0, exports.boundInteger)(values.flat().reduce((max, val) => val > max ? val : max)), typeAggregator);
98
+ const funcRandomInteger = new Constant_js_1.Constant((value) => value == null ? undefined : (0, exports.boundInteger)(BigInt(Math.floor(Math.random() * Number(value)))), Type_js_1.Type.functionType(Type_js_1.Type.Integer, [Type_js_1.Type.Integer]), false);
92
99
  const funcDecodeInteger = new Constant_js_1.Constant((value, encoding = "i64", byteOffset) => decodeInteger(value, encoding, byteOffset == null ? undefined : Number(byteOffset)), Type_js_1.Type.functionType(Type_js_1.Type.OptionalInteger, [Type_js_1.Type.OptionalBuffer, Type_js_1.Type.OptionalString, Type_js_1.Type.OptionalInteger]));
93
100
  const funcParseInteger = new Constant_js_1.Constant((value) => {
94
101
  try {
95
- return value ? BigInt.asIntN(64, BigInt(value)) : undefined;
102
+ return value ? (0, exports.boundInteger)(BigInt(value)) : undefined;
96
103
  }
97
104
  catch { }
98
105
  return undefined;
99
106
  }, Type_js_1.Type.functionType(Type_js_1.Type.OptionalInteger, [Type_js_1.Type.OptionalString]));
107
+ exports.funcInteger = new Constant_js_1.Constant((value) => (0, exports.createInteger)(Number(value)) ?? 0n, Type_js_1.Type.union(Type_js_1.Type.functionType(Type_js_1.Type.Integer, [Type_js_1.Type.Boolean]), Type_js_1.Type.functionType(Type_js_1.Type.Integer, [Type_js_1.Type.Timestamp]), Type_js_1.Type.functionType(Type_js_1.Type.Integer, [Type_js_1.Type.Float])));
100
108
  exports.constInteger = Object.assign(Object.create(null), {
101
109
  Sum: funcSum,
102
110
  Min: funcMin,
@@ -5,7 +5,8 @@ const Constant_js_1 = require("../Constant.js");
5
5
  const Type_js_1 = require("../Type.js");
6
6
  const Buffer_js_1 = require("./Buffer.js");
7
7
  const String_js_1 = require("./String.js");
8
- exports.funcLength = new Constant_js_1.Constant((value) => BigInt.asIntN(64, BigInt(value == null
8
+ const Integer_js_1 = require("./Integer.js");
9
+ exports.funcLength = new Constant_js_1.Constant((value) => (0, Integer_js_1.boundInteger)(BigInt(value == null
9
10
  ? 0
10
11
  : value instanceof ArrayBuffer
11
12
  ? value.byteLength
@@ -1,8 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.funcCastToInteger = exports.funcCastToFloat = exports.funcCast = 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 = void 0;
4
4
  const Constant_js_1 = require("../Constant.js");
5
5
  const Type_js_1 = require("../Type.js");
6
+ const Integer_js_1 = require("./Integer.js");
6
7
  const formatNumber = (value, formatting) => {
7
8
  if (formatting) {
8
9
  const nformat = JSON.parse(`{${formatting}}`);
@@ -22,18 +23,6 @@ const formatNumber = (value, formatting) => {
22
23
  : value.toString();
23
24
  };
24
25
  exports.formatNumber = formatNumber;
25
- const castToInteger = (value) => {
26
- if (value == null || Number.isNaN(value)) {
27
- return 0n;
28
- }
29
- if (value === Number.NEGATIVE_INFINITY) {
30
- return -0x8000000000000000n;
31
- }
32
- if (value === Number.POSITIVE_INFINITY) {
33
- return 0x7fffffffffffffffn;
34
- }
35
- return BigInt.asIntN(64, BigInt(Math.trunc(value)));
36
- };
37
26
  const typeComparator = Type_js_1.Type.functionType(Type_js_1.Type.Boolean, [Type_js_1.Type.Number, Type_js_1.Type.Number]);
38
27
  const typeOperator = Type_js_1.Type.union(Type_js_1.Type.functionType(Type_js_1.Type.Float, [Type_js_1.Type.Float, Type_js_1.Type.Integer]), Type_js_1.Type.functionType(Type_js_1.Type.Float, [Type_js_1.Type.Integer, Type_js_1.Type.Float]), Type_js_1.Type.functionType(Type_js_1.Type.Integer, [Type_js_1.Type.Integer, Type_js_1.Type.Integer]));
39
28
  exports.funcGreaterThan = new Constant_js_1.Constant((value1, value2) => value1 > value2, typeComparator);
@@ -41,40 +30,41 @@ exports.funcLessThan = new Constant_js_1.Constant((value1, value2) => value1 < v
41
30
  exports.funcGreaterOrEqual = new Constant_js_1.Constant((value1, value2) => value1 >= value2, typeComparator);
42
31
  exports.funcLessOrEqual = new Constant_js_1.Constant((value1, value2) => value1 <= value2, typeComparator);
43
32
  exports.funcSubtract = new Constant_js_1.Constant((value, subtrahend) => typeof value === "bigint" && typeof subtrahend === "bigint"
44
- ? BigInt.asIntN(64, value - subtrahend)
33
+ ? (0, Integer_js_1.boundInteger)(value - subtrahend)
45
34
  : Number(value) - Number(subtrahend), typeOperator);
46
35
  exports.funcMultiply = new Constant_js_1.Constant((value1, value2) => typeof value1 === "bigint" && typeof value2 === "bigint"
47
- ? BigInt.asIntN(64, value1 * value2)
36
+ ? (0, Integer_js_1.boundInteger)(value1 * value2)
48
37
  : Number(value1) * Number(value2), typeOperator);
49
38
  exports.funcDivide = new Constant_js_1.Constant((value, divisor) => typeof value === "bigint" && typeof divisor === "bigint"
50
- ? BigInt.asIntN(64, value / divisor)
39
+ ? (0, Integer_js_1.boundInteger)(value / divisor)
51
40
  : Number(value) / Number(divisor), typeOperator);
52
41
  exports.funcRemainder = new Constant_js_1.Constant((value, divisor) => typeof value === "bigint" && typeof divisor === "bigint"
53
- ? BigInt.asIntN(64, value % divisor)
42
+ ? (0, Integer_js_1.boundInteger)(value % divisor)
54
43
  : Number(value) % Number(divisor), typeOperator);
55
44
  exports.funcModulo = new Constant_js_1.Constant((value, divisor) => typeof value === "bigint" && typeof divisor === "bigint"
56
- ? BigInt.asIntN(64, (value % divisor + divisor) % divisor)
45
+ ? (0, Integer_js_1.boundInteger)((value % divisor + divisor) % divisor)
57
46
  : (Number(value) % Number(divisor) + Number(divisor)) % Number(divisor), typeOperator);
58
47
  exports.funcPower = new Constant_js_1.Constant((value, exponent) => typeof value === "bigint" && typeof exponent === "bigint"
59
- ? BigInt.asIntN(64, value ** BigInt(exponent))
48
+ ? (0, Integer_js_1.boundInteger)(value ** BigInt(exponent))
60
49
  : Number(value) ** Number(exponent), typeOperator);
61
50
  exports.funcRoot = new Constant_js_1.Constant((value, exponent) => {
62
51
  if (typeof value === "bigint" && typeof exponent === "bigint") {
63
- const e = BigInt(exponent);
64
- if (value < 0n && e % 2n === 0n) {
52
+ const v = (0, Integer_js_1.boundInteger)(value);
53
+ const e = (0, Integer_js_1.boundInteger)(exponent);
54
+ if (v < 0n && e % 2n === 0n) {
65
55
  return undefined;
66
56
  }
67
- if (value < 2n || e === 1n) {
68
- return value;
57
+ if (v <= 1n || e === 1n) {
58
+ return v;
69
59
  }
70
- let low = 0n, high = value, result = 0n;
60
+ let low = 0n, high = v, result = 0n;
71
61
  while (low <= high) {
72
62
  const mid = low + high >> 1n;
73
63
  const midPow = mid ** e;
74
- if (midPow === value) {
64
+ if (midPow === v) {
75
65
  return mid;
76
66
  }
77
- else if (midPow < value) {
67
+ else if (midPow < v) {
78
68
  result = mid;
79
69
  low = mid + 1n;
80
70
  }
@@ -82,13 +72,8 @@ exports.funcRoot = new Constant_js_1.Constant((value, exponent) => {
82
72
  high = mid - 1n;
83
73
  }
84
74
  }
85
- return BigInt.asIntN(64, result);
75
+ return result;
86
76
  }
87
77
  return Math.pow(Number(value), 1 / Number(exponent));
88
78
  }, typeOperator);
89
- exports.funcNegate = new Constant_js_1.Constant((value) => value == null ? undefined : typeof value === "number" ? -value : BigInt.asIntN(64, -value), Type_js_1.Type.union(Type_js_1.Type.functionType(Type_js_1.Type.Float, [Type_js_1.Type.Float]), Type_js_1.Type.functionType(Type_js_1.Type.Integer, [Type_js_1.Type.Integer])));
90
- exports.funcCast = new Constant_js_1.Constant((value) => typeof value !== "number"
91
- ? Number(value)
92
- : castToInteger(value), Type_js_1.Type.union(Type_js_1.Type.functionType(Type_js_1.Type.Float, [Type_js_1.Type.Integer]), Type_js_1.Type.functionType(Type_js_1.Type.Integer, [Type_js_1.Type.Float])));
93
- exports.funcCastToFloat = new Constant_js_1.Constant((value) => Number(value), Type_js_1.Type.functionType(Type_js_1.Type.Float, [Type_js_1.Type.Integer]));
94
- exports.funcCastToInteger = new Constant_js_1.Constant((value) => castToInteger(value), Type_js_1.Type.functionType(Type_js_1.Type.Integer, [Type_js_1.Type.Float]));
79
+ exports.funcNegate = new Constant_js_1.Constant((value) => value == null ? undefined : typeof value === "number" ? -value : (0, Integer_js_1.boundInteger)(-value), Type_js_1.Type.union(Type_js_1.Type.functionType(Type_js_1.Type.Float, [Type_js_1.Type.Float]), Type_js_1.Type.functionType(Type_js_1.Type.Integer, [Type_js_1.Type.Integer])));
@@ -4,10 +4,11 @@ exports.constObject = exports.funcValues = exports.funcKeys = exports.funcEntrie
4
4
  const Constant_js_1 = require("../Constant.js");
5
5
  const Type_js_1 = require("../Type.js");
6
6
  const typeAccessor = Type_js_1.Type.functionType(Type_js_1.Type.Array, [Type_js_1.Type.Object]);
7
+ const typeObjectOrArray = Type_js_1.Type.union(Type_js_1.Type.Object, Type_js_1.Type.arrayType([Type_js_1.Type.Object]));
7
8
  exports.funcEntries = new Constant_js_1.Constant((value) => value ? Object.entries(value) : undefined, typeAccessor);
8
9
  exports.funcKeys = new Constant_js_1.Constant((value) => value ? Object.keys(value) : undefined, Type_js_1.Type.functionType(Type_js_1.Type.arrayType([Type_js_1.Type.String]), [Type_js_1.Type.Object]));
9
10
  exports.funcValues = new Constant_js_1.Constant((value) => value ? Object.values(value) : undefined, typeAccessor);
10
- const funcMerge = new Constant_js_1.Constant((...values) => values.flat().reduce((acc, val) => Object.assign(acc, val), Object.create(null)), Type_js_1.Type.functionType(Type_js_1.Type.Object, [Type_js_1.Type.union(Type_js_1.Type.arrayType([Type_js_1.Type.Object]), Type_js_1.Type.Object)], true));
11
+ const funcMerge = new Constant_js_1.Constant((values) => values.flat().reduce((acc, val) => Object.assign(acc, val), Object.create(null)), Type_js_1.Type.functionType(Type_js_1.Type.Object, [Type_js_1.Type.arrayType([typeObjectOrArray])], true));
11
12
  exports.constObject = Object.assign(Object.create(null), {
12
13
  Merge: funcMerge,
13
14
  });