affinirum 1.3.1 → 1.4.1

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 (55) hide show
  1. package/README.md +174 -126
  2. package/dst/Affinirum.d.ts +1 -1
  3. package/dst/Affinirum.js +43 -47
  4. package/dst/Constants.js +2 -0
  5. package/dst/ParserState.js +2 -2
  6. package/dst/atom/ArrayAtom.d.ts +3 -3
  7. package/dst/atom/ArrayAtom.js +14 -13
  8. package/dst/atom/FunctionAtom.d.ts +1 -1
  9. package/dst/atom/FunctionAtom.js +11 -9
  10. package/dst/atom/ObjectAtom.d.ts +3 -3
  11. package/dst/atom/ObjectAtom.js +14 -18
  12. package/dst/atom/PrimitiveAtom.js +3 -3
  13. package/dst/cjs/Affinirum.js +43 -47
  14. package/dst/cjs/Constants.js +2 -0
  15. package/dst/cjs/ParserState.js +2 -2
  16. package/dst/cjs/atom/ArrayAtom.js +14 -13
  17. package/dst/cjs/atom/FunctionAtom.js +11 -9
  18. package/dst/cjs/atom/ObjectAtom.js +14 -18
  19. package/dst/cjs/atom/PrimitiveAtom.js +3 -3
  20. package/dst/cjs/native/Boolean.js +5 -2
  21. package/dst/cjs/native/Buffer.js +43 -11
  22. package/dst/cjs/native/Float.js +2 -5
  23. package/dst/cjs/native/Integer.js +8 -5
  24. package/dst/cjs/native/String.js +32 -15
  25. package/dst/cjs/native/Timestamp.js +25 -11
  26. package/dst/cjs/native/Unknown.js +10 -10
  27. package/dst/cjs/native/notation/AN.js +4 -4
  28. package/dst/cjs/native/notation/IP.js +239 -0
  29. package/dst/cjs/native/notation/JSON.js +3 -3
  30. package/dst/cjs/node/ArrayNode.js +7 -3
  31. package/dst/cjs/node/{FunctionNode.js → CallNode.js} +5 -4
  32. package/dst/cjs/node/ObjectNode.js +4 -2
  33. package/dst/native/Boolean.js +5 -2
  34. package/dst/native/Buffer.d.ts +3 -1
  35. package/dst/native/Buffer.js +41 -10
  36. package/dst/native/Float.d.ts +1 -1
  37. package/dst/native/Float.js +2 -5
  38. package/dst/native/Integer.d.ts +1 -1
  39. package/dst/native/Integer.js +8 -5
  40. package/dst/native/String.d.ts +2 -2
  41. package/dst/native/String.js +32 -15
  42. package/dst/native/Timestamp.d.ts +3 -3
  43. package/dst/native/Timestamp.js +25 -11
  44. package/dst/native/Unknown.js +11 -11
  45. package/dst/native/notation/AN.js +4 -4
  46. package/dst/native/notation/IP.d.ts +6 -0
  47. package/dst/native/notation/IP.js +236 -0
  48. package/dst/native/notation/JSON.js +3 -3
  49. package/dst/node/ArrayNode.d.ts +2 -1
  50. package/dst/node/ArrayNode.js +7 -3
  51. package/dst/node/{FunctionNode.d.ts → CallNode.d.ts} +1 -1
  52. package/dst/node/{FunctionNode.js → CallNode.js} +3 -2
  53. package/dst/node/ObjectNode.d.ts +1 -1
  54. package/dst/node/ObjectNode.js +4 -2
  55. package/package.json +1 -1
package/dst/Affinirum.js CHANGED
@@ -12,8 +12,8 @@ import { Constants } from "./Constants.js";
12
12
  import { Functions } from "./Functions.js";
13
13
  import { ArrayNode } from "./node/ArrayNode.js";
14
14
  import { BlockNode } from "./node/BlockNode.js";
15
+ import { CallNode } from "./node/CallNode.js";
15
16
  import { ConstantNode } from "./node/ConstantNode.js";
16
- import { FunctionNode } from "./node/FunctionNode.js";
17
17
  import { JumpNode } from "./node/JumpNode.js";
18
18
  import { LoopNode } from "./node/LoopNode.js";
19
19
  import { ObjectNode } from "./node/ObjectNode.js";
@@ -27,7 +27,7 @@ export class Affinirum {
27
27
  _script;
28
28
  _strict;
29
29
  _root;
30
- _vframes = new Map();
30
+ _varframes = new Map();
31
31
  _variables = new Map();
32
32
  _constants = new Map(Constants);
33
33
  _functions = new Map(Functions);
@@ -94,12 +94,12 @@ export class Affinirum {
94
94
  const variables = this._scope.variables();
95
95
  for (const name in variables) {
96
96
  if (!Object.prototype.hasOwnProperty.call(values, name)) {
97
- this._vframes.get(name)?.throwError(`undefined variable ${name}:\n`);
97
+ this._varframes.get(name)?.throwError(`undefined variable ${name}:\n`);
98
98
  }
99
99
  const variable = variables[name];
100
100
  const value = values?.[name] ?? undefined;
101
101
  if (!variable.type.match(Type.of(value))) {
102
- this._vframes.get(name)?.throwError(`unexpected type ${Type.of(value)} for variable ${name} of type ${variable.type}:\n`);
102
+ this._varframes.get(name)?.throwError(`unexpected type ${Type.of(value)} for variable ${name} of type ${variable.type}:\n`);
103
103
  }
104
104
  variable.value = value;
105
105
  }
@@ -148,7 +148,7 @@ export class Affinirum {
148
148
  let node = this._disjunction(state, scope);
149
149
  while (state.operator === funcCoalesce) {
150
150
  const fnode = new ConstantNode(state, state.operator);
151
- node = new FunctionNode(state, fnode, [node, this._disjunction(state.next(), scope)]);
151
+ node = new CallNode(state, fnode, [node, this._disjunction(state.next(), scope)]);
152
152
  }
153
153
  return node;
154
154
  }
@@ -156,7 +156,7 @@ export class Affinirum {
156
156
  let node = this._conjunction(state, scope);
157
157
  while (state.operator === funcOr) {
158
158
  const fnode = new ConstantNode(state, state.operator);
159
- node = new FunctionNode(state, fnode, [node, this._conjunction(state.next(), scope)]);
159
+ node = new CallNode(state, fnode, [node, this._conjunction(state.next(), scope)]);
160
160
  }
161
161
  return node;
162
162
  }
@@ -164,7 +164,7 @@ export class Affinirum {
164
164
  let node = this._negation(state, scope);
165
165
  while (state.operator === funcAnd) {
166
166
  const fnode = new ConstantNode(state, state.operator);
167
- node = new FunctionNode(state, fnode, [node, this._negation(state.next(), scope)]);
167
+ node = new CallNode(state, fnode, [node, this._negation(state.next(), scope)]);
168
168
  }
169
169
  return node;
170
170
  }
@@ -179,7 +179,7 @@ export class Affinirum {
179
179
  let node = this._comparison(state, scope);
180
180
  if (negate) {
181
181
  const fnode = new ConstantNode(frame, funcNot);
182
- node = new FunctionNode(frame, fnode, [node]);
182
+ node = new CallNode(frame, fnode, [node]);
183
183
  }
184
184
  return node;
185
185
  }
@@ -189,7 +189,7 @@ export class Affinirum {
189
189
  || state.operator === funcGreaterOrEqual || state.operator === funcLessOrEqual
190
190
  || state.operator === funcEqual || state.operator === funcNotEqual) {
191
191
  const fnode = new ConstantNode(state, state.operator);
192
- node = new FunctionNode(state, fnode, [node, this._aggregate(state.next(), scope)]);
192
+ node = new CallNode(state, fnode, [node, this._aggregate(state.next(), scope)]);
193
193
  }
194
194
  return node;
195
195
  }
@@ -197,7 +197,7 @@ export class Affinirum {
197
197
  let node = this._product(state, scope);
198
198
  while (state.operator === funcAdd || state.operator === funcSubtract) {
199
199
  const fnode = new ConstantNode(state, state.operator);
200
- node = new FunctionNode(state, fnode, [node, this._product(state.next(), scope)]);
200
+ node = new CallNode(state, fnode, [node, this._product(state.next(), scope)]);
201
201
  }
202
202
  return node;
203
203
  }
@@ -205,7 +205,7 @@ export class Affinirum {
205
205
  let node = this._signum(state, scope);
206
206
  while (state.operator === funcMultiply || state.operator === funcDivide || state.operator === funcRemainder) {
207
207
  const fnode = new ConstantNode(state, state.operator);
208
- node = new FunctionNode(state, fnode, [node, this._signum(state.next(), scope)]);
208
+ node = new CallNode(state, fnode, [node, this._signum(state.next(), scope)]);
209
209
  }
210
210
  return node;
211
211
  }
@@ -222,7 +222,7 @@ export class Affinirum {
222
222
  let node = this._factor(state, scope);
223
223
  if (negate) {
224
224
  const fnode = new ConstantNode(frame, funcNegate);
225
- node = new FunctionNode(frame, fnode, [node]);
225
+ node = new CallNode(frame, fnode, [node]);
226
226
  }
227
227
  return node;
228
228
  }
@@ -230,7 +230,7 @@ export class Affinirum {
230
230
  let node = this._accessor(state, scope);
231
231
  while (state.operator === funcPower) {
232
232
  const fnode = new ConstantNode(state, state.operator);
233
- node = new FunctionNode(state, fnode, [node, this._accessor(state.next(), scope)]);
233
+ node = new CallNode(state, fnode, [node, this._accessor(state.next(), scope)]);
234
234
  }
235
235
  return node;
236
236
  }
@@ -238,11 +238,11 @@ export class Affinirum {
238
238
  let node = this._term(state, scope);
239
239
  while (state.isDot || state.isQuestion || state.isParenthesesOpen || state.isBracketsOpen) {
240
240
  const frame = state.starts();
241
- if (state.isDot || state.isQuestion) {
241
+ if (state.isDot || state.isQuestion) { // property access or property existance operator
242
242
  const operator = state.isDot ? funcAt : funcHas;
243
243
  if (state.next().isLiteral && (typeof state.literal.value === "string" || typeof state.literal.value === "bigint")) {
244
244
  const fnode = new ConstantNode(frame.ends(state), operator);
245
- node = new FunctionNode(frame, fnode, [node, new ConstantNode(state, new Constant(state.literal.value))]);
245
+ node = new CallNode(frame, fnode, [node, new ConstantNode(state, new Constant(state.literal.value))]);
246
246
  state.next();
247
247
  }
248
248
  else if (state.isToken) {
@@ -257,17 +257,17 @@ export class Affinirum {
257
257
  }
258
258
  }
259
259
  const fnode = new ConstantNode(frame.ends(state), func);
260
- node = new FunctionNode(frame, fnode, subnodes);
260
+ node = new CallNode(frame, fnode, subnodes);
261
261
  state.closeParentheses().next();
262
262
  }
263
263
  else {
264
264
  const fnode = new ConstantNode(frame.ends(state), func);
265
- node = new FunctionNode(frame, fnode, [node]);
265
+ node = new CallNode(frame, fnode, [node]);
266
266
  }
267
267
  }
268
268
  else {
269
269
  const fnode = new ConstantNode(frame.ends(), operator);
270
- node = new FunctionNode(frame, fnode, [node, new ConstantNode(state, new Constant(state.token))]);
270
+ node = new CallNode(frame, fnode, [node, new ConstantNode(state, new Constant(state.token))]);
271
271
  state.next();
272
272
  }
273
273
  }
@@ -275,7 +275,7 @@ export class Affinirum {
275
275
  state.throwError("missing array index or object key");
276
276
  }
277
277
  }
278
- else if (state.isParenthesesOpen) {
278
+ else if (state.isParenthesesOpen) { // function call
279
279
  const subnodes = [];
280
280
  while (!state.next().isParenthesesClose) {
281
281
  subnodes.push(this._unit(state, scope));
@@ -283,25 +283,25 @@ export class Affinirum {
283
283
  break;
284
284
  }
285
285
  }
286
- node = new FunctionNode(frame.ends(state), node, subnodes);
286
+ node = new CallNode(frame.ends(state), node, subnodes);
287
287
  state.closeParentheses().next();
288
288
  }
289
- else if (state.isBracketsOpen) {
289
+ else if (state.isBracketsOpen) { // index access operator
290
290
  const fnode = new ConstantNode(frame, funcAt);
291
- node = new FunctionNode(frame, fnode, [node, this._unit(state.next(), scope)]);
291
+ node = new CallNode(frame, fnode, [node, this._unit(state.next(), scope)]);
292
292
  state.closeBrackets().next();
293
293
  }
294
294
  }
295
295
  return node;
296
296
  }
297
297
  _term(state, scope) {
298
- if (state.isLiteral) {
298
+ if (state.isLiteral) { // literal constant
299
299
  const frame = state.starts();
300
300
  const constant = new Constant(state.literal.value);
301
301
  state.next();
302
302
  return new ConstantNode(frame, constant);
303
303
  }
304
- else if (state.isToken) {
304
+ else if (state.isToken) { // variable
305
305
  const frame = state.starts();
306
306
  const constants = this._constants.get(state.token);
307
307
  if (constants != null) {
@@ -331,8 +331,8 @@ export class Affinirum {
331
331
  }
332
332
  scope.global(state.token, variable);
333
333
  }
334
- if (!this._vframes.has(state.token)) {
335
- this._vframes.set(state.token, state.starts());
334
+ if (!this._varframes.has(state.token)) {
335
+ this._varframes.set(state.token, state.starts());
336
336
  }
337
337
  if (state.next().isAssignment) {
338
338
  if (!variable.assignable) {
@@ -341,7 +341,7 @@ export class Affinirum {
341
341
  if (state.assignment.operator) {
342
342
  const operator = state.assignment.operator;
343
343
  const fnode = new ConstantNode(frame, operator);
344
- const subnode = new FunctionNode(frame, fnode, [new VariableNode(frame, variable), this._unit(state.next(), scope)]);
344
+ const subnode = new CallNode(frame, fnode, [new VariableNode(frame, variable), this._unit(state.next(), scope)]);
345
345
  return new VariableNode(frame, variable, subnode);
346
346
  }
347
347
  else {
@@ -351,7 +351,7 @@ export class Affinirum {
351
351
  }
352
352
  return new VariableNode(frame, variable);
353
353
  }
354
- else if (state.isBracesOpen) {
354
+ else if (state.isBracesOpen) { // code block
355
355
  const frame = state.starts();
356
356
  const subnodes = [];
357
357
  while (!state.next().isBracesClose) {
@@ -367,7 +367,7 @@ export class Affinirum {
367
367
  else if (state.isBracesClose) {
368
368
  state.throwError("unexpected closing braces");
369
369
  }
370
- else if (state.isParenthesesOpen) {
370
+ else if (state.isParenthesesOpen) { // unit grouping
371
371
  const node = this._unit(state.next(), scope);
372
372
  state.closeParentheses().next();
373
373
  return node;
@@ -375,7 +375,7 @@ export class Affinirum {
375
375
  else if (state.isParenthesesClose) {
376
376
  state.throwError("unexpected closing parentheses");
377
377
  }
378
- else if (state.isBracketsOpen) {
378
+ else if (state.isBracketsOpen) { // array or object
379
379
  const frame = state.starts();
380
380
  const subnodes = [];
381
381
  let index = 0, colon = false;
@@ -407,7 +407,7 @@ export class Affinirum {
407
407
  else if (state.isBracketsClose) {
408
408
  state.throwError("unexpected closing brackets");
409
409
  }
410
- else if (state.isVar || state.isVal) {
410
+ else if (state.isVar || state.isVal) { // variable declaration
411
411
  const assignable = state.isVar;
412
412
  if (!state.next().isToken) {
413
413
  state.throwError("missing variable name");
@@ -462,12 +462,8 @@ export class Affinirum {
462
462
  state.throwError("unexpected expression token");
463
463
  }
464
464
  _function(state, scope) {
465
+ state.next().openParentheses();
465
466
  const frame = state.starts();
466
- let retType = Type.Unknown;
467
- if (!state.next().isParenthesesOpen) {
468
- retType = this._type(state, scope);
469
- state.openParentheses();
470
- }
471
467
  let variadic = false;
472
468
  const variables = new Map();
473
469
  while (!state.next().isParenthesesClose) {
@@ -499,10 +495,11 @@ export class Affinirum {
499
495
  break;
500
496
  }
501
497
  }
502
- state.closeParentheses();
498
+ state.closeParentheses().next();
499
+ const retType = state.isColon ? this._type(state.next(), scope) : Type.Unknown;
503
500
  frame.ends(state);
504
501
  const args = Array.from(variables.values());
505
- const subnode = this._unit(state.next(), scope.subscope(variables));
502
+ const subnode = this._unit(state, scope.subscope(variables));
506
503
  const func = (...values) => {
507
504
  args.forEach((arg, ix) => arg.value = values[ix]);
508
505
  return subnode.evaluate();
@@ -527,7 +524,7 @@ export class Affinirum {
527
524
  return new SwitchNode(frame, cnode, [cthen, celse]);
528
525
  }
529
526
  _type(state, scope) {
530
- if (state.isType) {
527
+ if (state.isType) { // literal type
531
528
  let type = state.type;
532
529
  if (state.next().isQuestion) {
533
530
  type = type.toOptional();
@@ -561,11 +558,7 @@ export class Affinirum {
561
558
  : Type.arrayType(itemKeyTypes.map(([, v]) => v));
562
559
  }
563
560
  else if (state.isTilda) { // function type
564
- let retType = Type.Unknown;
565
- if (!state.next().isParenthesesOpen) {
566
- retType = this._type(state, scope);
567
- state.openParentheses();
568
- }
561
+ state.next().openParentheses();
569
562
  let variadic = false;
570
563
  const argTypes = [];
571
564
  while (!state.next().isParenthesesClose) {
@@ -588,11 +581,14 @@ export class Affinirum {
588
581
  }
589
582
  }
590
583
  state.closeParentheses().next();
591
- if (!retType && argTypes.length) {
592
- retType = Type.Unknown;
593
- }
584
+ const retType = state.isColon ? this._type(state.next(), scope) : Type.Unknown;
594
585
  return Type.functionType(retType, argTypes, variadic);
595
586
  }
587
+ else if (state.isParenthesesOpen) { // type grouping
588
+ const type = this._type(state.next(), scope);
589
+ state.closeParentheses().next();
590
+ return type;
591
+ }
596
592
  else {
597
593
  state.throwError("missing type name");
598
594
  }
package/dst/Constants.js CHANGED
@@ -7,6 +7,7 @@ import { constObject } from "./native/Object.js";
7
7
  import { constString } from "./native/String.js";
8
8
  import { constTimestamp } from "./native/Timestamp.js";
9
9
  import { constAN } from "./native/notation/AN.js";
10
+ import { constIP } from "./native/notation/IP.js";
10
11
  import { constJSON } from "./native/notation/JSON.js";
11
12
  export const Constants = [
12
13
  ["Array", constArray],
@@ -18,5 +19,6 @@ export const Constants = [
18
19
  ["String", constString],
19
20
  ["Timestamp", constTimestamp],
20
21
  ["AN", constAN],
22
+ ["IP", constIP],
21
23
  ["JSON", constJSON],
22
24
  ];
@@ -381,7 +381,7 @@ export class ParserState extends ParserFrame {
381
381
  this._fragment = funcDivideAssignment;
382
382
  break;
383
383
  case "/":
384
- if (this._expr.charAt(++this._end) === '/') {
384
+ if (this._expr.charAt(++this._end) === "/") {
385
385
  ++this._end;
386
386
  while (this._expr.charAt(this._end) !== ""
387
387
  && (this._expr.charAt(this._end) !== c
@@ -391,7 +391,7 @@ export class ParserState extends ParserFrame {
391
391
  }
392
392
  if (this._end >= this._expr.length) {
393
393
  this._start = this._expr.length;
394
- throw new Error(`missing closing comment mark`);
394
+ throw new Error("missing closing comment mark");
395
395
  }
396
396
  ++this._end;
397
397
  }
@@ -1,11 +1,11 @@
1
1
  import { IAtom } from "../Atom.js";
2
2
  import { Type } from "../Type.js";
3
3
  export declare class ArrayAtom implements IAtom {
4
- protected readonly _itemTypes: Type[];
5
- constructor(_itemTypes?: Type[]);
4
+ protected readonly _valTypes: Type[];
5
+ constructor(_valTypes?: Type[]);
6
6
  private get _undefined();
7
7
  subtypes(): Type[];
8
- itemType(index: number): Type | undefined;
8
+ valueType(index: number): Type | undefined;
9
9
  match(atom: IAtom): boolean;
10
10
  weight(): number;
11
11
  toString(): string;
@@ -1,27 +1,25 @@
1
1
  export class ArrayAtom {
2
- _itemTypes;
3
- constructor(_itemTypes = []) {
4
- this._itemTypes = _itemTypes;
2
+ _valTypes;
3
+ constructor(_valTypes = []) {
4
+ this._valTypes = _valTypes;
5
5
  }
6
6
  get _undefined() {
7
- return this._itemTypes.length === 0;
7
+ return this._valTypes.length === 0;
8
8
  }
9
9
  subtypes() {
10
- return this._itemTypes;
10
+ return this._valTypes;
11
11
  }
12
- itemType(index) {
13
- return this._itemTypes[index];
12
+ valueType(index) {
13
+ return this._valTypes[index];
14
14
  }
15
15
  match(atom) {
16
16
  if (atom instanceof ArrayAtom) {
17
17
  if (this._undefined || atom._undefined) {
18
18
  return true;
19
19
  }
20
- if (this.subtypes().length !== atom.subtypes().length) {
21
- return false;
22
- }
23
- for (let i = 0; i < this._itemTypes.length; ++i) {
24
- if (!this._itemTypes[i].match(atom._itemTypes[i])) {
20
+ for (let i = 0; i < this._valTypes.length; ++i) {
21
+ const vtype = atom.valueType(i);
22
+ if (!vtype || !this._valTypes[i].match(vtype)) {
25
23
  return false;
26
24
  }
27
25
  }
@@ -33,6 +31,9 @@ export class ArrayAtom {
33
31
  return 0x10000 + this.subtypes().reduce((acc, i) => acc + i.weight(), 0);
34
32
  }
35
33
  toString() {
36
- return this._undefined ? "array" : `[${this._itemTypes.join(",")}]`;
34
+ if (this._undefined) {
35
+ return "array";
36
+ }
37
+ return `[${this._valTypes.join(",")}]`;
37
38
  }
38
39
  }
@@ -12,7 +12,7 @@ export declare class FunctionAtom implements IAtom {
12
12
  get maxArity(): number;
13
13
  get isVariadic(): boolean;
14
14
  get arity(): number;
15
- argType(index: number): Type;
15
+ argType(index: number): Type | undefined;
16
16
  match(atom: IAtom): boolean;
17
17
  weight(): number;
18
18
  toString(): string;
@@ -26,7 +26,7 @@ export class FunctionAtom {
26
26
  return this._retType.isUnknown && this._argTypes.length === 0 && this._isVariadic;
27
27
  }
28
28
  get retType() {
29
- return Type.Unknown;
29
+ return this._retType;
30
30
  }
31
31
  get minArity() {
32
32
  return this._minArity;
@@ -41,7 +41,7 @@ export class FunctionAtom {
41
41
  return this._argTypes.length;
42
42
  }
43
43
  argType(index) {
44
- return this._argTypes[index] ?? this._argTypes[this._argTypes.length - 1] ?? Type.Unknown;
44
+ return this._argTypes[index] ?? (this._isVariadic ? this._argTypes[this._argTypes.length - 1] : undefined);
45
45
  }
46
46
  match(atom) {
47
47
  if (atom instanceof FunctionAtom) {
@@ -51,8 +51,10 @@ export class FunctionAtom {
51
51
  if (!this._retType.match(atom._retType) || this.minArity > atom.maxArity || this.maxArity < atom.minArity) {
52
52
  return false;
53
53
  }
54
- for (let i = 0, argc = Math.max(this.minArity, atom.minArity); i < argc; ++i) {
55
- if (!this.argType(i).match(atom.argType(i))) {
54
+ const argc = Math.max(this.minArity, atom.minArity);
55
+ for (let i = 0; i < argc; ++i) {
56
+ const atype = atom.argType(i);
57
+ if (!atype || !this.argType(i)?.match(atype)) {
56
58
  return false;
57
59
  }
58
60
  }
@@ -64,10 +66,10 @@ export class FunctionAtom {
64
66
  return 0x1000000000000 + (this._retType ? [this._retType, ...this._argTypes] : []).reduce((acc, i) => acc + i.weight(), 0);
65
67
  }
66
68
  toString() {
67
- const argTypes = this._argTypes.map((i, ix) => {
68
- const argType = i.toString();
69
- return (ix === (this._argTypes.length - 1) && this.isVariadic) ? "..." + argType : argType;
70
- }).join(",");
71
- return this._undefined ? "function" : `~${this._retType.toString()}(${argTypes})`;
69
+ if (this._undefined) {
70
+ return "function";
71
+ }
72
+ const argTypes = this._argTypes.map((i, ix) => ix === this._argTypes.length - 1 && this.isVariadic ? `...${i.toString()}` : i.toString()).join(",");
73
+ return `~(${argTypes}):${this._retType.toString()}`;
72
74
  }
73
75
  }
@@ -1,11 +1,11 @@
1
1
  import { IAtom } from "../Atom.js";
2
2
  import { Type } from "../Type.js";
3
3
  export declare class ObjectAtom implements IAtom {
4
- protected readonly _propTypes: Record<string, Type>;
5
- constructor(_propTypes?: Record<string, Type>);
4
+ protected readonly _valTypes: Record<string, Type>;
5
+ constructor(_valTypes?: Record<string, Type>);
6
6
  private get _undefined();
7
7
  subtypes(): Type[];
8
- propType(property: string): Type;
8
+ valueType(key: string): Type | undefined;
9
9
  match(atom: IAtom): boolean;
10
10
  weight(): number;
11
11
  toString(): string;
@@ -1,32 +1,25 @@
1
1
  export class ObjectAtom {
2
- _propTypes;
3
- constructor(_propTypes = {}) {
4
- this._propTypes = _propTypes;
2
+ _valTypes;
3
+ constructor(_valTypes = {}) {
4
+ this._valTypes = _valTypes;
5
5
  }
6
6
  get _undefined() {
7
- return Object.keys(this._propTypes).length === 0;
7
+ return Object.keys(this._valTypes).length === 0;
8
8
  }
9
9
  subtypes() {
10
- return Object.values(this._propTypes);
10
+ return Object.values(this._valTypes);
11
11
  }
12
- propType(property) {
13
- return this._propTypes[property];
12
+ valueType(key) {
13
+ return this._valTypes[key];
14
14
  }
15
15
  match(atom) {
16
16
  if (atom instanceof ObjectAtom) {
17
17
  if (this._undefined || atom._undefined) {
18
18
  return true;
19
19
  }
20
- for (const prop in this._propTypes) {
21
- if (!atom.propType(prop)) {
22
- return false;
23
- }
24
- if (!this._propTypes[prop].match(atom._propTypes[prop])) {
25
- return false;
26
- }
27
- }
28
- for (const prop in atom._propTypes) {
29
- if (!this.propType(prop)) {
20
+ for (const key in this._valTypes) {
21
+ const vtype = atom.valueType(key);
22
+ if (!vtype || !this._valTypes[key].match(vtype)) {
30
23
  return false;
31
24
  }
32
25
  }
@@ -38,6 +31,9 @@ export class ObjectAtom {
38
31
  return 0x100000000 + this.subtypes().reduce((acc, i) => acc + i.weight(), 0);
39
32
  }
40
33
  toString() {
41
- return this._undefined ? "object" : `[${Object.entries(this._propTypes).map((i) => `"${i[0]}":${i[1]}`).join(",")}]`;
34
+ if (this._undefined) {
35
+ return "object";
36
+ }
37
+ return `[${Object.entries(this._valTypes).map(([k, v]) => `"${k}":${v}`).join(",")}]`;
42
38
  }
43
39
  }
@@ -14,13 +14,13 @@ export class PrimitiveAtom {
14
14
  }
15
15
  weight() {
16
16
  switch (this._primitive) {
17
- case "void": return 0x0;
17
+ case "void": return 0x1;
18
18
  case "boolean": return 0x2;
19
- case "timestamp": return 0x3;
19
+ case "timestamp": return 0x4;
20
20
  case "float": return 0x8;
21
21
  case "integer": return 0x10;
22
22
  case "buffer": return 0x20;
23
- case "string": return 0x30;
23
+ case "string": return 0x40;
24
24
  }
25
25
  }
26
26
  toString() {