arktype 2.0.0-rc.26 → 2.0.0-rc.28

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 (99) hide show
  1. package/out/attributes.d.ts +61 -241
  2. package/out/attributes.js +2 -1
  3. package/out/generic.d.ts +4 -4
  4. package/out/keywords/{constructors/Array.d.ts → Array.d.ts} +2 -2
  5. package/out/keywords/{constructors/Array.js → Array.js} +1 -1
  6. package/out/keywords/{constructors/FormData.d.ts → FormData.d.ts} +2 -2
  7. package/out/keywords/{constructors/FormData.js → FormData.js} +1 -1
  8. package/out/keywords/{constructors/TypedArray.d.ts → TypedArray.d.ts} +1 -1
  9. package/out/keywords/{constructors/TypedArray.js → TypedArray.js} +1 -1
  10. package/out/keywords/{constructors/constructors.d.ts → constructors.d.ts} +1 -1
  11. package/out/keywords/{constructors/constructors.js → constructors.js} +1 -1
  12. package/out/keywords/keywords.d.ts +6 -9
  13. package/out/keywords/keywords.js +3 -3
  14. package/out/keywords/number.d.ts +23 -0
  15. package/out/keywords/{number/epoch.js → number.js} +23 -1
  16. package/out/keywords/string.d.ts +327 -0
  17. package/out/keywords/string.js +398 -0
  18. package/out/methods/array.d.ts +6 -7
  19. package/out/methods/base.d.ts +10 -14
  20. package/out/methods/date.d.ts +5 -6
  21. package/out/methods/number.d.ts +6 -7
  22. package/out/methods/object.d.ts +5 -5
  23. package/out/methods/string.d.ts +7 -8
  24. package/out/parser/ast/generic.d.ts +17 -0
  25. package/out/parser/ast/infer.d.ts +4 -18
  26. package/out/parser/ast/validate.d.ts +10 -6
  27. package/out/parser/ast/validate.js +2 -0
  28. package/out/parser/definition.d.ts +17 -8
  29. package/out/parser/definition.js +20 -2
  30. package/out/parser/objectLiteral.d.ts +39 -39
  31. package/out/parser/objectLiteral.js +75 -49
  32. package/out/parser/property.d.ts +37 -0
  33. package/out/parser/property.js +16 -0
  34. package/out/parser/reduce/dynamic.d.ts +1 -1
  35. package/out/parser/shift/operand/enclosed.d.ts +1 -3
  36. package/out/parser/shift/operand/unenclosed.d.ts +2 -1
  37. package/out/parser/shift/operator/default.d.ts +2 -1
  38. package/out/parser/shift/operator/default.js +1 -1
  39. package/out/parser/string.d.ts +5 -4
  40. package/out/parser/string.js +18 -1
  41. package/out/parser/tupleExpressions.d.ts +47 -0
  42. package/out/parser/tupleExpressions.js +67 -0
  43. package/out/parser/tupleLiteral.d.ts +80 -0
  44. package/out/parser/tupleLiteral.js +119 -0
  45. package/out/scope.d.ts +8 -7
  46. package/out/scope.js +12 -32
  47. package/out/type.d.ts +5 -5
  48. package/package.json +3 -3
  49. package/out/keywords/constructors/Date.d.ts +0 -37
  50. package/out/keywords/number/epoch.d.ts +0 -10
  51. package/out/keywords/number/integer.d.ts +0 -3
  52. package/out/keywords/number/integer.js +0 -5
  53. package/out/keywords/number/number.d.ts +0 -58
  54. package/out/keywords/number/number.js +0 -21
  55. package/out/keywords/string/alpha.d.ts +0 -7
  56. package/out/keywords/string/alpha.js +0 -2
  57. package/out/keywords/string/alphanumeric.d.ts +0 -7
  58. package/out/keywords/string/alphanumeric.js +0 -2
  59. package/out/keywords/string/base64.d.ts +0 -21
  60. package/out/keywords/string/base64.js +0 -6
  61. package/out/keywords/string/capitalize.d.ts +0 -15
  62. package/out/keywords/string/capitalize.js +0 -12
  63. package/out/keywords/string/creditCard.d.ts +0 -8
  64. package/out/keywords/string/creditCard.js +0 -37
  65. package/out/keywords/string/date.d.ts +0 -55
  66. package/out/keywords/string/date.js +0 -98
  67. package/out/keywords/string/digits.d.ts +0 -7
  68. package/out/keywords/string/digits.js +0 -2
  69. package/out/keywords/string/email.d.ts +0 -7
  70. package/out/keywords/string/email.js +0 -4
  71. package/out/keywords/string/integer.d.ts +0 -16
  72. package/out/keywords/string/integer.js +0 -16
  73. package/out/keywords/string/ip.d.ts +0 -20
  74. package/out/keywords/string/ip.js +0 -23
  75. package/out/keywords/string/json.d.ts +0 -16
  76. package/out/keywords/string/json.js +0 -54
  77. package/out/keywords/string/lower.d.ts +0 -15
  78. package/out/keywords/string/lower.js +0 -12
  79. package/out/keywords/string/normalize.d.ts +0 -88
  80. package/out/keywords/string/normalize.js +0 -43
  81. package/out/keywords/string/numeric.d.ts +0 -15
  82. package/out/keywords/string/numeric.js +0 -13
  83. package/out/keywords/string/semver.d.ts +0 -7
  84. package/out/keywords/string/semver.js +0 -4
  85. package/out/keywords/string/string.d.ts +0 -135
  86. package/out/keywords/string/string.js +0 -43
  87. package/out/keywords/string/trim.d.ts +0 -15
  88. package/out/keywords/string/trim.js +0 -14
  89. package/out/keywords/string/upper.d.ts +0 -15
  90. package/out/keywords/string/upper.js +0 -12
  91. package/out/keywords/string/url.d.ts +0 -15
  92. package/out/keywords/string/url.js +0 -37
  93. package/out/keywords/string/utils.d.ts +0 -2
  94. package/out/keywords/string/utils.js +0 -10
  95. package/out/keywords/string/uuid.d.ts +0 -42
  96. package/out/keywords/string/uuid.js +0 -19
  97. package/out/parser/tuple.d.ts +0 -148
  98. package/out/parser/tuple.js +0 -164
  99. /package/out/{keywords/constructors/Date.js → parser/ast/generic.js} +0 -0
@@ -1,148 +0,0 @@
1
- import { type BaseParseContext, type BaseRoot, type MetaSchema, type Morph, type Predicate } from "@ark/schema";
2
- import { type anyOrNever, type array, type BuiltinObjectKind, type conform, type Constructor, type Domain, type ErrorMessage, type show, type Thunk } from "@ark/util";
3
- import type { associateAttributes, Default, DefaultFor, distill, inferIntersection, inferMorphOut, inferPredicate, InferredOptional, Optional, Out } from "../attributes.ts";
4
- import type { type } from "../keywords/keywords.ts";
5
- import type { PostfixExpression } from "./ast/infer.ts";
6
- import type { inferDefinition, validateDefinition } from "./definition.ts";
7
- import { writeMissingRightOperandMessage } from "./shift/operand/unenclosed.ts";
8
- import type { ArkTypeScanner } from "./shift/scanner.ts";
9
- import type { BaseCompletions } from "./string.ts";
10
- export declare const parseTuple: (def: array, ctx: BaseParseContext) => BaseRoot;
11
- export declare const parseTupleLiteral: (def: array, ctx: BaseParseContext) => BaseRoot;
12
- type InfixExpression = readonly [
13
- unknown,
14
- ArkTypeScanner.InfixToken,
15
- ...unknown[]
16
- ];
17
- export type validateTuple<def extends array, $, args> = def extends IndexZeroExpression ? validatePrefixExpression<def, $, args> : def extends PostfixExpression ? validatePostfixExpression<def, $, args> : def extends InfixExpression ? validateInfixExpression<def, $, args> : def extends (readonly ["", ...unknown[]] | readonly [unknown, "", ...unknown[]]) ? readonly [
18
- def[0] extends "" ? BaseCompletions<$, args, IndexZeroOperator | "..."> : def[0],
19
- def[1] extends "" ? BaseCompletions<$, args, IndexOneOperator | "..."> : def[1]
20
- ] : validateTupleLiteral<def, $, args>;
21
- export type validateTupleLiteral<def extends array, $, args> = parseSequence<def, $, args> extends infer s extends SequenceParseState ? Readonly<s["validated"]> : never;
22
- type inferTupleLiteral<def extends array, $, args> = parseSequence<def, $, args> extends infer s extends SequenceParseState ? s["inferred"] : never;
23
- type SequenceParseState = {
24
- unscanned: array;
25
- inferred: array;
26
- validated: array;
27
- includesOptional: boolean;
28
- };
29
- type parseSequence<def extends array, $, args> = parseNextElement<{
30
- unscanned: def;
31
- inferred: [];
32
- validated: [];
33
- includesOptional: false;
34
- }, $, args>;
35
- type PreparsedElement = {
36
- head: unknown;
37
- tail: array;
38
- inferred: unknown;
39
- optional: boolean;
40
- spread: boolean;
41
- };
42
- declare namespace PreparsedElement {
43
- type from<result extends PreparsedElement> = result;
44
- }
45
- type preparseNextElement<s extends SequenceParseState, $, args> = s["unscanned"] extends readonly ["...", infer head, ...infer tail] ? inferDefinition<head, $, args> extends infer t ? [
46
- t
47
- ] extends [anyOrNever] ? PreparsedElement.from<{
48
- head: head;
49
- tail: tail;
50
- inferred: t;
51
- optional: false;
52
- spread: true;
53
- }> : [t] extends [InferredOptional<infer base>] ? PreparsedElement.from<{
54
- head: head;
55
- tail: tail;
56
- inferred: base;
57
- optional: true;
58
- spread: true;
59
- }> : PreparsedElement.from<{
60
- head: head;
61
- tail: tail;
62
- inferred: t;
63
- optional: false;
64
- spread: true;
65
- }> : never : s["unscanned"] extends readonly [infer head, ...infer tail] ? inferDefinition<head, $, args> extends infer t ? [
66
- t
67
- ] extends [anyOrNever] ? PreparsedElement.from<{
68
- head: head;
69
- tail: tail;
70
- inferred: t;
71
- optional: false;
72
- spread: false;
73
- }> : [t] extends [InferredOptional<infer base>] ? PreparsedElement.from<{
74
- head: head;
75
- tail: tail;
76
- inferred: base;
77
- optional: true;
78
- spread: false;
79
- }> : PreparsedElement.from<{
80
- head: head;
81
- tail: tail;
82
- inferred: t;
83
- optional: false;
84
- spread: false;
85
- }> : never : null;
86
- type parseNextElement<s extends SequenceParseState, $, args> = preparseNextElement<s, $, args> extends infer next extends PreparsedElement ? parseNextElement<{
87
- unscanned: next["tail"];
88
- inferred: next["spread"] extends true ? [
89
- ...s["inferred"],
90
- ...conform<next["inferred"], array>
91
- ] : next["optional"] extends true ? [...s["inferred"], next["inferred"]?] : [...s["inferred"], next["inferred"]];
92
- validated: [
93
- ...s["validated"],
94
- ...(next["spread"] extends true ? [
95
- next["inferred"] extends infer spreadOperand extends array ? [
96
- number,
97
- number
98
- ] extends ([
99
- s["inferred"]["length"],
100
- spreadOperand["length"]
101
- ]) ? ErrorMessage<multipleVariadicMessage> : "..." : ErrorMessage<writeNonArraySpreadMessage<next["head"]>>
102
- ] : []),
103
- next["optional"] extends true ? next["spread"] extends true ? ErrorMessage<spreadOptionalMessage> : number extends s["inferred"]["length"] ? ErrorMessage<optionalPostVariadicMessage> : validateDefinition<next["head"], $, args> : [s["includesOptional"], next["spread"]] extends [true, false] ? ErrorMessage<requiredPostOptionalMessage> : validateDefinition<next["head"], $, args>
104
- ];
105
- includesOptional: s["includesOptional"] | next["optional"] extends (false) ? false : true;
106
- }, $, args> : s;
107
- export declare const writeNonArraySpreadMessage: <operand extends string>(operand: operand) => writeNonArraySpreadMessage<operand>;
108
- type writeNonArraySpreadMessage<operand> = `Spread element must be an array${operand extends string ? ` (was ${operand})` : ""}`;
109
- export declare const multipleVariadicMesage = "A tuple may have at most one variadic element";
110
- type multipleVariadicMessage = typeof multipleVariadicMesage;
111
- export declare const requiredPostOptionalMessage = "A required element may not follow an optional element";
112
- type requiredPostOptionalMessage = typeof requiredPostOptionalMessage;
113
- export declare const optionalPostVariadicMessage = "An optional element may not follow a variadic element";
114
- type optionalPostVariadicMessage = typeof optionalPostVariadicMessage;
115
- export declare const spreadOptionalMessage = "A spread element cannot be optional";
116
- type spreadOptionalMessage = typeof optionalPostVariadicMessage;
117
- export type inferTuple<def extends array, $, args> = def extends TupleExpression ? inferTupleExpression<def, $, args> : inferTupleLiteral<def, $, args>;
118
- export type inferTupleExpression<def extends TupleExpression, $, args> = def[1] extends "[]" ? inferDefinition<def[0], $, args>[] : def[1] extends "&" ? inferIntersection<inferDefinition<def[0], $, args>, inferDefinition<def[2], $, args>> : def[1] extends "|" ? inferDefinition<def[0], $, args> | inferDefinition<def[2], $, args> : def[1] extends ":" ? inferPredicate<inferDefinition<def[0], $, args>, def[2]> : def[1] extends "=>" ? parseMorph<def[0], def[2], $, args> : def[1] extends "@" ? inferDefinition<def[0], $, args> : def[1] extends "=" ? associateAttributes<inferDefinition<def[0], $, args>, Default<def[2] extends Thunk<infer returnValue> ? returnValue : def[2]>> : def[1] extends "?" ? associateAttributes<inferDefinition<def[0], $, args>, Optional> : def extends readonly ["===", ...infer values] ? values[number] : def extends (readonly ["instanceof", ...infer constructors extends Constructor[]]) ? InstanceType<constructors[number]> : def[0] extends "keyof" ? inferKeyOfExpression<def[1], $, args> : never;
119
- export type validatePrefixExpression<def extends IndexZeroExpression, $, args> = def["length"] extends 1 ? readonly [writeMissingRightOperandMessage<def[0]>] : def[0] extends "keyof" ? readonly [def[0], validateDefinition<def[1], $, args>] : def[0] extends "===" ? readonly [def[0], ...unknown[]] : def[0] extends "instanceof" ? readonly [def[0], ...Constructor[]] : never;
120
- export type validatePostfixExpression<def extends PostfixExpression, $, args> = conform<def, readonly [validateDefinition<def[0], $, args>, "[]" | "?"]>;
121
- export type validateInfixExpression<def extends InfixExpression, $, args> = def["length"] extends 2 ? readonly [def[0], writeMissingRightOperandMessage<def[1]>] : readonly [
122
- validateDefinition<def[0], $, args>,
123
- def[1],
124
- def[1] extends "|" ? validateDefinition<def[2], $, args> : def[1] extends "&" ? validateDefinition<def[2], $, args> : def[1] extends ":" ? Predicate<type.infer.Out<def[0], $, args>> : def[1] extends "=>" ? Morph<type.infer.Out<def[0], $, args>> : def[1] extends "@" ? MetaSchema : def[1] extends "=" ? DefaultFor<type.infer.In<def[0], $, args>> : validateDefinition<def[2], $, args>
125
- ];
126
- export type UnparsedTupleExpressionInput = {
127
- instanceof: Constructor;
128
- "===": unknown;
129
- };
130
- export type UnparsedTupleOperator = show<keyof UnparsedTupleExpressionInput>;
131
- export declare const parseKeyOfTuple: PrefixParser<"keyof">;
132
- export type inferKeyOfExpression<operandDef, $, args> = show<keyof inferDefinition<operandDef, $, args>>;
133
- export type IndexOneParser<token extends IndexOneOperator> = (def: IndexOneExpression<token>, ctx: BaseParseContext) => BaseRoot;
134
- export type PrefixParser<token extends IndexZeroOperator> = (def: IndexZeroExpression<token>, ctx: BaseParseContext) => BaseRoot;
135
- export type TupleExpression = IndexZeroExpression | IndexOneExpression;
136
- export type TupleExpressionOperator = IndexZeroOperator | IndexOneOperator;
137
- export type IndexOneOperator = TuplePostfixOperator | TupleInfixOperator;
138
- export type TuplePostfixOperator = "[]" | "?";
139
- export type TupleInfixOperator = "&" | "|" | "=>" | ":" | "@" | "=";
140
- export type IndexOneExpression<token extends IndexOneOperator = IndexOneOperator> = readonly [unknown, token, ...unknown[]];
141
- export declare const parseMorphTuple: IndexOneParser<"=>">;
142
- export declare const writeMalformedFunctionalExpressionMessage: (operator: ":" | "=>", value: unknown) => string;
143
- export type parseMorph<inDef, morph, $, args> = morph extends Morph ? inferMorphOut<morph> extends infer out ? (In: distill.withAttributes.In<inferDefinition<inDef, $, args>>) => Out<out> : never : never;
144
- export declare const parseNarrowTuple: IndexOneParser<":">;
145
- export type IndexZeroOperator = "keyof" | "instanceof" | "===";
146
- export type IndexZeroExpression<token extends IndexZeroOperator = IndexZeroOperator> = readonly [token, ...unknown[]];
147
- export declare const writeInvalidConstructorMessage: <actual extends Domain | BuiltinObjectKind>(actual: actual) => string;
148
- export {};
@@ -1,164 +0,0 @@
1
- import { $ark, Disjoint, intersectNodesRoot, makeRootAndArrayPropertiesMutable } from "@ark/schema";
2
- import { append, isEmptyObject, objectKindOrDomainOf, throwParseError } from "@ark/util";
3
- import { writeMissingRightOperandMessage } from "./shift/operand/unenclosed.js";
4
- export const parseTuple = (def, ctx) => maybeParseTupleExpression(def, ctx) ?? parseTupleLiteral(def, ctx);
5
- export const parseTupleLiteral = (def, ctx) => {
6
- let sequences = [{}];
7
- let i = 0;
8
- while (i < def.length) {
9
- let spread = false;
10
- if (def[i] === "..." && i < def.length - 1) {
11
- spread = true;
12
- i++;
13
- }
14
- const element = ctx.$.parseOwnDefinitionFormat(def[i], ctx);
15
- i++;
16
- if (spread) {
17
- if (!element.extends($ark.intrinsic.Array))
18
- return throwParseError(writeNonArraySpreadMessage(element.expression));
19
- // a spread must be distributed over branches e.g.:
20
- // def: [string, ...(number[] | [true, false])]
21
- // nodes: [string, ...number[]] | [string, true, false]
22
- sequences = sequences.flatMap(base =>
23
- // since appendElement mutates base, we have to shallow-ish clone it for each branch
24
- element.distribute(branch => appendSpreadBranch(makeRootAndArrayPropertiesMutable(base), branch)));
25
- }
26
- else {
27
- sequences = sequences.map(base => appendElement(base, element.meta.optional ? "optional" : "required", element));
28
- }
29
- }
30
- return ctx.$.parseSchema(sequences.map(sequence => isEmptyObject(sequence) ?
31
- {
32
- proto: Array,
33
- exactLength: 0
34
- }
35
- : {
36
- proto: Array,
37
- sequence
38
- }));
39
- };
40
- const appendElement = (base, kind, element) => {
41
- switch (kind) {
42
- case "required":
43
- if (base.optionals)
44
- // e.g. [string?, number]
45
- return throwParseError(requiredPostOptionalMessage);
46
- if (base.variadic) {
47
- // e.g. [...string[], number]
48
- base.postfix = append(base.postfix, element);
49
- }
50
- else {
51
- // e.g. [string, number]
52
- base.prefix = append(base.prefix, element);
53
- }
54
- return base;
55
- case "optional":
56
- if (base.variadic)
57
- // e.g. [...string[], number?]
58
- return throwParseError(optionalPostVariadicMessage);
59
- // e.g. [string, number?]
60
- base.optionals = append(base.optionals, element);
61
- return base;
62
- case "variadic":
63
- // e.g. [...string[], number, ...string[]]
64
- if (base.postfix)
65
- throwParseError(multipleVariadicMesage);
66
- if (base.variadic) {
67
- if (!base.variadic.equals(element)) {
68
- // e.g. [...string[], ...number[]]
69
- throwParseError(multipleVariadicMesage);
70
- }
71
- // e.g. [...string[], ...string[]]
72
- // do nothing, second spread doesn't change the type
73
- }
74
- else {
75
- // e.g. [string, ...number[]]
76
- base.variadic = element.internal;
77
- }
78
- return base;
79
- }
80
- };
81
- const appendSpreadBranch = (base, branch) => {
82
- const spread = branch.firstReferenceOfKind("sequence");
83
- if (!spread) {
84
- // the only array with no sequence reference is unknown[]
85
- return appendElement(base, "variadic", $ark.intrinsic.unknown);
86
- }
87
- spread.prefix?.forEach(node => appendElement(base, "required", node));
88
- spread.optionals?.forEach(node => appendElement(base, "optional", node));
89
- if (spread.variadic)
90
- appendElement(base, "variadic", spread.variadic);
91
- spread.postfix?.forEach(node => appendElement(base, "required", node));
92
- return base;
93
- };
94
- const maybeParseTupleExpression = (def, ctx) => {
95
- const tupleExpressionResult = isIndexZeroExpression(def) ? prefixParsers[def[0]](def, ctx)
96
- : isIndexOneExpression(def) ? indexOneParsers[def[1]](def, ctx)
97
- : undefined;
98
- return tupleExpressionResult;
99
- };
100
- export const writeNonArraySpreadMessage = (operand) => `Spread element must be an array (was ${operand})`;
101
- export const multipleVariadicMesage = "A tuple may have at most one variadic element";
102
- export const requiredPostOptionalMessage = "A required element may not follow an optional element";
103
- export const optionalPostVariadicMessage = "An optional element may not follow a variadic element";
104
- export const spreadOptionalMessage = "A spread element cannot be optional";
105
- export const parseKeyOfTuple = (def, ctx) => ctx.$.parseOwnDefinitionFormat(def[1], ctx).keyof();
106
- const parseBranchTuple = (def, ctx) => {
107
- if (def[2] === undefined)
108
- return throwParseError(writeMissingRightOperandMessage(def[1], ""));
109
- const l = ctx.$.parseOwnDefinitionFormat(def[0], ctx);
110
- const r = ctx.$.parseOwnDefinitionFormat(def[2], ctx);
111
- if (def[1] === "|")
112
- return ctx.$.node("union", { branches: [l, r] });
113
- const result = intersectNodesRoot(l, r, ctx.$);
114
- if (result instanceof Disjoint)
115
- return result.throw();
116
- return result;
117
- };
118
- const parseArrayTuple = (def, ctx) => ctx.$.parseOwnDefinitionFormat(def[0], ctx).array();
119
- const isIndexOneExpression = (def) => indexOneParsers[def[1]] !== undefined;
120
- export const parseMorphTuple = (def, ctx) => {
121
- if (typeof def[2] !== "function") {
122
- return throwParseError(writeMalformedFunctionalExpressionMessage("=>", def[2]));
123
- }
124
- return ctx.$.parseOwnDefinitionFormat(def[0], ctx).pipe(def[2]);
125
- };
126
- export const writeMalformedFunctionalExpressionMessage = (operator, value) => `${operator === ":" ? "Narrow" : "Morph"} expression requires a function following '${operator}' (was ${typeof value})`;
127
- export const parseNarrowTuple = (def, ctx) => {
128
- if (typeof def[2] !== "function") {
129
- return throwParseError(writeMalformedFunctionalExpressionMessage(":", def[2]));
130
- }
131
- return ctx.$.parseOwnDefinitionFormat(def[0], ctx).constrain("predicate", def[2]);
132
- };
133
- const parseAttributeTuple = (def, ctx) => ctx.$.parseOwnDefinitionFormat(def[0], ctx).configureShallowDescendants(def[2]);
134
- const parseDefaultTuple = (def, ctx) => ctx.$.parseOwnDefinitionFormat(def[0], ctx).default(def[2]);
135
- const parseOptionalTuple = (def, ctx) => ctx.$.parseOwnDefinitionFormat(def[0], ctx).optional();
136
- const indexOneParsers = {
137
- "[]": parseArrayTuple,
138
- "?": parseOptionalTuple,
139
- "|": parseBranchTuple,
140
- "&": parseBranchTuple,
141
- ":": parseNarrowTuple,
142
- "=>": parseMorphTuple,
143
- "@": parseAttributeTuple,
144
- "=": parseDefaultTuple
145
- };
146
- const prefixParsers = {
147
- keyof: parseKeyOfTuple,
148
- instanceof: (def, ctx) => {
149
- if (typeof def[1] !== "function") {
150
- return throwParseError(writeInvalidConstructorMessage(objectKindOrDomainOf(def[1])));
151
- }
152
- const branches = def
153
- .slice(1)
154
- .map(ctor => typeof ctor === "function" ?
155
- ctx.$.node("proto", { proto: ctor })
156
- : throwParseError(writeInvalidConstructorMessage(objectKindOrDomainOf(ctor))));
157
- return branches.length === 1 ?
158
- branches[0]
159
- : ctx.$.node("union", { branches });
160
- },
161
- "===": (def, ctx) => ctx.$.units(def.slice(1))
162
- };
163
- const isIndexZeroExpression = (def) => prefixParsers[def[0]] !== undefined;
164
- export const writeInvalidConstructorMessage = (actual) => `Expected a constructor following 'instanceof' operator (was ${actual})`;