arktype 1.0.10-alpha → 1.0.11-alpha

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 (84) hide show
  1. package/README.md +22 -4
  2. package/dist/cjs/main.js +26 -24
  3. package/dist/cjs/nodes/branch.js +18 -18
  4. package/dist/cjs/nodes/compose.js +28 -11
  5. package/dist/cjs/nodes/discriminate.js +27 -27
  6. package/dist/cjs/nodes/node.js +24 -24
  7. package/dist/cjs/nodes/predicate.js +17 -17
  8. package/dist/cjs/nodes/rules/class.js +5 -5
  9. package/dist/cjs/nodes/rules/collapsibleSet.js +3 -3
  10. package/dist/cjs/nodes/rules/divisor.js +2 -2
  11. package/dist/cjs/nodes/rules/props.js +19 -19
  12. package/dist/cjs/nodes/rules/range.js +6 -6
  13. package/dist/cjs/nodes/rules/regex.js +3 -3
  14. package/dist/cjs/nodes/rules/rules.js +20 -20
  15. package/dist/cjs/parse/ast/config.js +2 -2
  16. package/dist/cjs/parse/ast/distributableFunction.js +9 -9
  17. package/dist/cjs/parse/ast/intersection.js +5 -5
  18. package/dist/cjs/parse/ast/keyof.js +31 -30
  19. package/dist/cjs/parse/ast/morph.js +10 -10
  20. package/dist/cjs/parse/ast/narrow.js +6 -6
  21. package/dist/cjs/parse/ast/tuple.js +21 -21
  22. package/dist/cjs/parse/definition.js +18 -20
  23. package/dist/cjs/parse/record.js +4 -4
  24. package/dist/cjs/parse/string/reduce/dynamic.js +44 -26
  25. package/dist/cjs/parse/string/reduce/shared.js +2 -2
  26. package/dist/cjs/parse/string/shift/operand/enclosed.js +2 -2
  27. package/dist/cjs/parse/string/shift/operand/operand.js +3 -3
  28. package/dist/cjs/parse/string/shift/operand/unenclosed.js +3 -3
  29. package/dist/cjs/parse/string/shift/operator/bounds.js +18 -18
  30. package/dist/cjs/parse/string/shift/operator/divisor.js +6 -6
  31. package/dist/cjs/parse/string/shift/operator/operator.js +6 -6
  32. package/dist/cjs/parse/string/shift/scanner.js +16 -1
  33. package/dist/cjs/parse/string/string.js +8 -8
  34. package/dist/cjs/scopes/ark.js +15 -15
  35. package/dist/cjs/scopes/cache.js +16 -3
  36. package/dist/cjs/scopes/expressions.js +9 -9
  37. package/dist/cjs/scopes/jsObjects.js +2 -42
  38. package/dist/cjs/scopes/scope.js +59 -31
  39. package/dist/cjs/scopes/tsKeywords.js +2 -2
  40. package/dist/cjs/scopes/type.js +6 -6
  41. package/dist/cjs/scopes/validation/creditCard.js +2 -2
  42. package/dist/cjs/scopes/validation/date.js +4 -4
  43. package/dist/cjs/scopes/validation/validation.js +17 -17
  44. package/dist/cjs/traverse/problems.js +41 -21
  45. package/dist/cjs/traverse/traverse.js +56 -31
  46. package/dist/cjs/utils/data.js +18 -4
  47. package/dist/cjs/utils/generics.js +3 -3
  48. package/dist/cjs/utils/numericLiterals.js +4 -4
  49. package/dist/cjs/utils/objectKinds.js +4 -4
  50. package/dist/cjs/utils/serialize.js +6 -6
  51. package/dist/mjs/main.js +2 -1
  52. package/dist/mjs/nodes/compose.js +17 -0
  53. package/dist/mjs/parse/ast/config.js +5 -1
  54. package/dist/mjs/parse/ast/keyof.js +2 -1
  55. package/dist/mjs/parse/definition.js +0 -1
  56. package/dist/mjs/parse/string/reduce/dynamic.js +18 -0
  57. package/dist/mjs/parse/string/shift/scanner.js +16 -1
  58. package/dist/mjs/scopes/cache.js +14 -1
  59. package/dist/mjs/scopes/expressions.js +88 -8
  60. package/dist/mjs/scopes/jsObjects.js +2 -41
  61. package/dist/mjs/scopes/scope.js +30 -2
  62. package/dist/mjs/scopes/tsKeywords.js +2 -1
  63. package/dist/mjs/scopes/validation/validation.js +2 -1
  64. package/dist/mjs/traverse/problems.js +22 -2
  65. package/dist/mjs/traverse/traverse.js +25 -0
  66. package/dist/mjs/utils/data.js +14 -0
  67. package/dist/tsconfig.temp.tsbuildinfo +1 -1
  68. package/dist/types/main.d.ts +5 -1
  69. package/dist/types/nodes/node.d.ts +6 -0
  70. package/dist/types/parse/ast/bound.d.ts +14 -0
  71. package/dist/types/parse/ast/config.d.ts +5 -0
  72. package/dist/types/parse/ast/divisor.d.ts +5 -0
  73. package/dist/types/parse/definition.d.ts +2 -6
  74. package/dist/types/parse/string/reduce/static.d.ts +12 -2
  75. package/dist/types/parse/string/shift/operand/operand.d.ts +3 -3
  76. package/dist/types/parse/string/shift/operand/unenclosed.d.ts +5 -5
  77. package/dist/types/parse/string/string.d.ts +1 -2
  78. package/dist/types/scopes/ark.d.ts +10 -22
  79. package/dist/types/scopes/expressions.d.ts +88 -0
  80. package/dist/types/scopes/jsObjects.d.ts +2 -11
  81. package/dist/types/scopes/tsKeywords.d.ts +2 -1
  82. package/dist/types/scopes/validation/validation.d.ts +2 -1
  83. package/dist/types/utils/generics.d.ts +1 -1
  84. package/package.json +15 -16
@@ -2,7 +2,7 @@ import type { Node } from "../nodes/node.js";
2
2
  import type { Type } from "../scopes/type.js";
3
3
  import type { Primitive } from "../utils/domains.js";
4
4
  import { domainOf } from "../utils/domains.js";
5
- import type { Dict, evaluate, isAny, isUnknown, List } from "../utils/generics.js";
5
+ import type { Dict, evaluate, isAny, isUnknown, List, stringKeyOf } from "../utils/generics.js";
6
6
  import { objectKindOf } from "../utils/objectKinds.js";
7
7
  import type { Path } from "../utils/paths.js";
8
8
  import type { validateString } from "./ast/ast.js";
@@ -15,17 +15,13 @@ export type ParseContext = {
15
15
  };
16
16
  export declare const parseDefinition: (def: unknown, ctx: ParseContext) => Node;
17
17
  export type inferDefinition<def, $> = isAny<def> extends true ? never : def extends Infer<infer t> | InferredThunk<infer t> ? t : def extends string ? inferString<def, $> : def extends List ? inferTuple<def, $> : def extends RegExp ? string : def extends Dict ? inferRecord<def, $> : never;
18
- export type validateDefinition<def, $> = [def] extends [(...args: any[]) => any] ? def : [def] extends [Terminal] ? def : [def] extends [string] ? validateString<def, $> : [def] extends [TupleExpression] ? validateTupleExpression<def, $> : [def] extends [BadDefinitionType] ? writeBadDefinitionTypeMessage<objectKindOf<def> extends string ? objectKindOf<def> : domainOf<def>> : isUnknown<def> extends true ? unknownDefinitionMessage : [def] extends [readonly unknown[]] ? {
19
- [k in keyof def]: validateDefinition<def[k], $>;
20
- } : evaluate<{
18
+ export type validateDefinition<def, $> = [def] extends [(...args: any[]) => any] ? def : def extends Terminal ? def : def extends string ? validateString<def, $> : def extends TupleExpression ? validateTupleExpression<def, $> : def extends BadDefinitionType ? writeBadDefinitionTypeMessage<objectKindOf<def> extends string ? objectKindOf<def> : domainOf<def>> : isUnknown<def> extends true ? stringKeyOf<$> : evaluate<{
21
19
  [k in keyof def]: validateDefinition<def[k], $>;
22
20
  }>;
23
21
  export declare const as: unique symbol;
24
22
  export type Infer<t> = {
25
23
  [as]?: t;
26
24
  };
27
- export declare const unknownDefinitionMessage = "Cannot statically parse a definition inferred as unknown. Consider using 'as Infer<...>' to cast it.";
28
- export type unknownDefinitionMessage = typeof unknownDefinitionMessage;
29
25
  type InferredThunk<t = unknown> = () => Infer<t>;
30
26
  type Terminal = RegExp | Infer<unknown> | InferredThunk;
31
27
  type BadDefinitionType = Exclude<Primitive, string>;
@@ -1,13 +1,13 @@
1
1
  import type { MaxComparator, MinComparator } from "../../../nodes/rules/range.js";
2
2
  import type { defined, error } from "../../../utils/generics.js";
3
3
  import type { NumberLiteral } from "../../../utils/numericLiterals.js";
4
- import type { astToString } from "../../ast/utils.js";
5
4
  import type { Scanner } from "../shift/scanner.js";
6
5
  import type { unclosedGroupMessage, writeMultipleLeftBoundsMessage, writeOpenRangeMessage, writeUnmatchedGroupCloseMessage, writeUnpairableComparatorMessage } from "./shared.js";
7
6
  export type StaticState = {
8
7
  root: unknown;
9
8
  branches: BranchState;
10
9
  groups: BranchState[];
10
+ scanned: string;
11
11
  unscanned: string;
12
12
  };
13
13
  type StaticOpenLeftBound = {
@@ -24,6 +24,7 @@ export declare namespace state {
24
24
  root: undefined;
25
25
  branches: initialBranches;
26
26
  groups: [];
27
+ scanned: "";
27
28
  unscanned: def;
28
29
  }>;
29
30
  type initialBranches = branchesFrom<{
@@ -31,10 +32,12 @@ export declare namespace state {
31
32
  "&": undefined;
32
33
  "|": undefined;
33
34
  }>;
35
+ type updateScanned<previousScanned extends string, previousUnscanned extends string, updatedUnscanned extends string> = previousUnscanned extends `${infer justScanned}${updatedUnscanned}` ? `${previousScanned}${justScanned}` : previousScanned;
34
36
  export type setRoot<s extends StaticState, root, unscanned extends string> = from<{
35
37
  root: root;
36
38
  branches: s["branches"];
37
39
  groups: s["groups"];
40
+ scanned: updateScanned<s["scanned"], s["unscanned"], unscanned>;
38
41
  unscanned: unscanned;
39
42
  }>;
40
43
  export type reduceBranch<s extends StaticState, token extends Scanner.BranchToken, unscanned extends string> = s["branches"]["range"] extends {} ? openRangeError<s["branches"]["range"]> : from<{
@@ -45,6 +48,7 @@ export declare namespace state {
45
48
  "|": token extends "|" ? mergeToUnion<s> : s["branches"]["|"];
46
49
  };
47
50
  groups: s["groups"];
51
+ scanned: updateScanned<s["scanned"], s["unscanned"], unscanned>;
48
52
  unscanned: unscanned;
49
53
  }>;
50
54
  export type reduceLeftBound<s extends StaticState, limit extends NumberLiteral, comparator extends Scanner.Comparator, unscanned extends string> = comparator extends "<" | "<=" ? s["branches"]["range"] extends {} ? error<writeMultipleLeftBoundsMessage<s["branches"]["range"]["limit"], s["branches"]["range"]["comparator"], limit, Scanner.InvertedComparators[comparator]>> : from<{
@@ -58,6 +62,7 @@ export declare namespace state {
58
62
  "|": s["branches"]["|"];
59
63
  };
60
64
  groups: s["groups"];
65
+ scanned: updateScanned<s["scanned"], s["unscanned"], unscanned>;
61
66
  unscanned: unscanned;
62
67
  }> : error<writeUnpairableComparatorMessage<comparator>>;
63
68
  export type reduceRange<s extends StaticState, minLimit extends NumberLiteral, minComparator extends MinComparator, maxComparator extends MaxComparator, maxLimit extends NumberLiteral, unscanned extends string> = state.from<{
@@ -68,6 +73,7 @@ export declare namespace state {
68
73
  "|": s["branches"]["|"];
69
74
  };
70
75
  groups: s["groups"];
76
+ scanned: updateScanned<s["scanned"], s["unscanned"], unscanned>;
71
77
  unscanned: unscanned;
72
78
  }>;
73
79
  export type reduceSingleBound<s extends StaticState, comparator extends Scanner.Comparator, limit extends NumberLiteral, unscanned extends string> = state.from<{
@@ -78,6 +84,7 @@ export declare namespace state {
78
84
  "|": s["branches"]["|"];
79
85
  };
80
86
  groups: s["groups"];
87
+ scanned: updateScanned<s["scanned"], s["unscanned"], unscanned>;
81
88
  unscanned: unscanned;
82
89
  }>;
83
90
  type mergeToUnion<s extends StaticState> = s["branches"]["|"] extends undefined ? mergeToIntersection<s> : [s["branches"]["|"], "|", mergeToIntersection<s>];
@@ -90,18 +97,21 @@ export declare namespace state {
90
97
  groups: stack;
91
98
  branches: top;
92
99
  root: mergeToUnion<s>;
100
+ scanned: updateScanned<s["scanned"], s["unscanned"], unscanned>;
93
101
  unscanned: unscanned;
94
102
  }> : error<writeUnmatchedGroupCloseMessage<unscanned>>;
95
103
  export type reduceGroupOpen<s extends StaticState, unscanned extends string> = from<{
96
104
  groups: [...s["groups"], s["branches"]];
97
105
  branches: initialBranches;
98
106
  root: undefined;
107
+ scanned: updateScanned<s["scanned"], s["unscanned"], unscanned>;
99
108
  unscanned: unscanned;
100
109
  }>;
101
110
  export type finalize<s extends StaticState> = s["groups"] extends [] ? s["branches"]["range"] extends {} ? openRangeError<s["branches"]["range"]> : from<{
102
111
  root: mergeToUnion<s>;
103
112
  groups: s["groups"];
104
113
  branches: initialBranches;
114
+ scanned: s["scanned"];
105
115
  unscanned: Scanner.finalized;
106
116
  }> : error<unclosedGroupMessage>;
107
117
  type openRangeError<range extends defined<BranchState["range"]>> = error<writeOpenRangeMessage<range["limit"], range["comparator"]>>;
@@ -110,9 +120,9 @@ export declare namespace state {
110
120
  root: s["root"];
111
121
  branches: s["branches"];
112
122
  groups: s["groups"];
123
+ scanned: updateScanned<s["scanned"], s["unscanned"], unscanned>;
113
124
  unscanned: unscanned;
114
125
  }>;
115
- export type toString<s extends StaticState> = astToString<mergeToUnion<s>>;
116
126
  export type from<s extends StaticState> = s;
117
127
  export type branchesFrom<b extends BranchState> = b;
118
128
  export {};
@@ -1,9 +1,9 @@
1
- import type { error } from "../../../../utils/generics.js";
1
+ import type { error, stringKeyOf } from "../../../../utils/generics.js";
2
2
  import type { DynamicState } from "../../reduce/dynamic.js";
3
3
  import type { state, StaticState } from "../../reduce/static.js";
4
4
  import type { Scanner } from "../scanner.js";
5
5
  import type { EnclosingChar } from "./enclosed.js";
6
6
  import { parseEnclosed } from "./enclosed.js";
7
- import { parseUnenclosed, writeMissingOperandMessage } from "./unenclosed.js";
7
+ import { parseUnenclosed } from "./unenclosed.js";
8
8
  export declare const parseOperand: (s: DynamicState) => void;
9
- export type parseOperand<s extends StaticState, $> = s["unscanned"] extends Scanner.shift<infer lookahead, infer unscanned> ? lookahead extends "(" ? state.reduceGroupOpen<s, unscanned> : lookahead extends EnclosingChar ? parseEnclosed<s, lookahead, unscanned> : lookahead extends " " ? parseOperand<state.scanTo<s, unscanned>, $> : parseUnenclosed<s, $> : error<writeMissingOperandMessage<s>>;
9
+ export type parseOperand<s extends StaticState, $> = s["unscanned"] extends Scanner.shift<infer lookahead, infer unscanned> ? lookahead extends "(" ? state.reduceGroupOpen<s, unscanned> : lookahead extends EnclosingChar ? parseEnclosed<s, lookahead, unscanned> : lookahead extends " " ? parseOperand<state.scanTo<s, unscanned>, $> : parseUnenclosed<s, $> : error<`${s["scanned"]}${stringKeyOf<$>}`>;
@@ -1,18 +1,18 @@
1
- import type { error, stringKeyOf } from "../../../../utils/generics.js";
1
+ import type { error } from "../../../../utils/generics.js";
2
2
  import type { BigintLiteral, NumberLiteral } from "../../../../utils/numericLiterals.js";
3
3
  import type { DynamicState } from "../../reduce/dynamic.js";
4
4
  import type { state, StaticState } from "../../reduce/static.js";
5
5
  import type { Scanner } from "../scanner.js";
6
6
  export declare const parseUnenclosed: (s: DynamicState) => void;
7
7
  export type parseUnenclosed<s extends StaticState, $> = Scanner.shiftUntilNextTerminator<s["unscanned"]> extends Scanner.shiftResult<infer scanned, infer nextUnscanned> ? tryResolve<s, scanned, $> extends infer result ? result extends error<infer message> ? error<message> : state.setRoot<s, result, nextUnscanned> : never : never;
8
- export type isResolvableIdentifier<token, $> = token extends stringKeyOf<$> ? true : false;
9
- type tryResolve<s extends StaticState, token extends string, $> = isResolvableIdentifier<token, $> extends true ? token : token extends NumberLiteral ? token : token extends BigintLiteral ? token : error<token extends "" ? writeMissingOperandMessage<s> : writeUnresolvableMessage<token>>;
8
+ type tryResolve<s extends StaticState, token extends string, $> = token extends keyof $ ? token : token extends NumberLiteral ? token : token extends BigintLiteral ? token : possibleCompletions<s, token, $>;
9
+ export type possibleCompletions<s extends StaticState, token extends string, $> = Extract<keyof $, `${token}${string}`> extends never ? error<writeUnresolvableMessage<token>> : error<`${s["scanned"]}${Extract<keyof $, `${token}${string}`>}`>;
10
10
  export declare const writeUnresolvableMessage: <token extends string>(token: token) => `'${token}' is unresolvable`;
11
11
  type writeUnresolvableMessage<token extends string> = `'${token}' is unresolvable`;
12
- export declare const writeMissingOperandMessage: <s extends DynamicState>(s: s) => `Token '|' requires a right operand before '${string}'` | `Token '&' requires a right operand before '${string}'` | `Expected an expression before '${string}'`;
12
+ export declare const writeMissingOperandMessage: <s extends DynamicState>(s: s) => string;
13
13
  export type writeMissingOperandMessage<s extends StaticState, operator extends Scanner.InfixToken | undefined = state.previousOperator<s>> = operator extends {} ? writeMissingRightOperandMessage<operator, s["unscanned"]> : writeExpressionExpectedMessage<s["unscanned"]>;
14
14
  export type writeMissingRightOperandMessage<token extends Scanner.InfixToken, unscanned extends string> = `Token '${token}' requires a right operand${unscanned extends "" ? "" : ` before '${unscanned}'`}`;
15
15
  export declare const writeMissingRightOperandMessage: <token extends Scanner.InfixToken, unscanned extends string>(token: token, unscanned: unscanned) => `Token '${token}' requires a right operand${unscanned extends "" ? "" : ` before '${unscanned}'`}`;
16
- export declare const writeExpressionExpectedMessage: <unscanned extends string>(unscanned: unscanned) => `Expected an expression${unscanned extends "" ? "" : ` before '${unscanned}'`}`;
16
+ export declare const writeExpressionExpectedMessage: <unscanned extends string>(unscanned: unscanned) => string;
17
17
  export type writeExpressionExpectedMessage<unscanned extends string> = `Expected an expression${unscanned extends "" ? "" : ` before '${unscanned}'`}`;
18
18
  export {};
@@ -4,7 +4,6 @@ import type { ParseContext } from "../definition.js";
4
4
  import { DynamicState } from "./reduce/dynamic.js";
5
5
  import type { state, StaticState } from "./reduce/static.js";
6
6
  import { parseOperand } from "./shift/operand/operand.js";
7
- import type { isResolvableIdentifier } from "./shift/operand/unenclosed.js";
8
7
  import { parseOperator } from "./shift/operator/operator.js";
9
8
  import type { Scanner } from "./shift/scanner.js";
10
9
  export declare const parseString: (def: string, ctx: ParseContext) => import("../../nodes/node.js").Node;
@@ -14,7 +13,7 @@ export type inferString<def extends string, $> = inferAst<parseString<def, $>, $
14
13
  * Try to parse the definition from right to left using the most common syntax.
15
14
  * This can be much more efficient for simple definitions.
16
15
  */
17
- type maybeNaiveParse<def extends string, $> = def extends `${infer child}[]` ? isResolvableIdentifier<child, $> extends true ? [child, "[]"] : fullStringParse<def, $> : isResolvableIdentifier<def, $> extends true ? def : fullStringParse<def, $>;
16
+ type maybeNaiveParse<def extends string, $> = def extends `${infer child}[]` ? child extends keyof $ ? [child, "[]"] : fullStringParse<def, $> : def extends keyof $ ? def : fullStringParse<def, $>;
18
17
  export declare const maybeNaiveParse: (def: string, ctx: ParseContext) => string | import("../../nodes/node.js").ResolvedNode<import("../../utils/generics.js").Dict> | undefined;
19
18
  export declare const fullStringParse: (def: string, ctx: ParseContext) => import("../../nodes/node.js").Node;
20
19
  type fullStringParse<def extends string, $> = loop<state.initialize<def>, $>;
@@ -1,4 +1,3 @@
1
- import type { InferredObjectKinds } from "../utils/objectKinds.js";
2
1
  import type { Space } from "./scope.js";
3
2
  import type { TypeParser } from "./type.js";
4
3
  export declare const arkScope: import("./scope.js").Scope<[{
@@ -17,16 +16,11 @@ export declare const arkScope: import("./scope.js").Scope<[{
17
16
  void: void;
18
17
  undefined: undefined;
19
18
  Function: (...args: any[]) => unknown;
20
- Array: unknown[];
21
19
  Date: Date;
22
20
  Error: Error;
23
21
  Map: Map<unknown, unknown>;
24
22
  RegExp: RegExp;
25
23
  Set: Set<unknown>;
26
- Object: Record<string, unknown>;
27
- String: String;
28
- Number: Number;
29
- Boolean: Boolean;
30
24
  WeakMap: WeakMap<object, unknown>;
31
25
  WeakSet: WeakSet<object>;
32
26
  Promise: Promise<unknown>;
@@ -65,16 +59,11 @@ export declare const scopes: {
65
59
  }, {}, false]>;
66
60
  jsObjects: import("./scope.js").Scope<[{
67
61
  Function: (...args: any[]) => unknown;
68
- Array: unknown[];
69
62
  Date: Date;
70
63
  Error: Error;
71
64
  Map: Map<unknown, unknown>;
72
65
  RegExp: RegExp;
73
66
  Set: Set<unknown>;
74
- Object: Record<string, unknown>;
75
- String: String;
76
- Number: Number;
77
- Boolean: Boolean;
78
67
  WeakMap: WeakMap<object, unknown>;
79
68
  WeakSet: WeakSet<object>;
80
69
  Promise: Promise<unknown>;
@@ -110,16 +99,11 @@ export declare const scopes: {
110
99
  void: void;
111
100
  undefined: undefined;
112
101
  Function: (...args: any[]) => unknown;
113
- Array: unknown[];
114
102
  Date: Date;
115
103
  Error: Error;
116
104
  Map: Map<unknown, unknown>;
117
105
  RegExp: RegExp;
118
106
  Set: Set<unknown>;
119
- Object: Record<string, unknown>;
120
- String: String;
121
- Number: Number;
122
- Boolean: Boolean;
123
107
  WeakMap: WeakMap<object, unknown>;
124
108
  WeakSet: WeakSet<object>;
125
109
  Promise: Promise<unknown>;
@@ -157,16 +141,11 @@ export declare const spaces: {
157
141
  }>;
158
142
  jsObjects: Space<{
159
143
  Function: (...args: any[]) => unknown;
160
- Array: unknown[];
161
144
  Date: Date;
162
145
  Error: Error;
163
146
  Map: Map<unknown, unknown>;
164
147
  RegExp: RegExp;
165
148
  Set: Set<unknown>;
166
- Object: Record<string, unknown>;
167
- String: String;
168
- Number: Number;
169
- Boolean: Boolean;
170
149
  WeakMap: WeakMap<object, unknown>;
171
150
  WeakSet: WeakSet<object>;
172
151
  Promise: Promise<unknown>;
@@ -216,5 +195,14 @@ export type PrecompiledDefaults = {
216
195
  parsedNumber: (In: string) => number;
217
196
  parsedInteger: (In: string) => number;
218
197
  parsedDate: (In: string) => Date;
219
- } & InferredObjectKinds;
198
+ Function: (...args: any[]) => unknown;
199
+ Date: Date;
200
+ Error: Error;
201
+ Map: Map<unknown, unknown>;
202
+ RegExp: RegExp;
203
+ Set: Set<unknown>;
204
+ WeakMap: WeakMap<object, unknown>;
205
+ WeakSet: WeakSet<object>;
206
+ Promise: Promise<unknown>;
207
+ };
220
208
  export declare const type: TypeParser<PrecompiledDefaults>;
@@ -18,13 +18,101 @@ export type Expressions<$> = {
18
18
  morph: FunctionalExpressionParser<$, "|>">;
19
19
  };
20
20
  type Ark = Expressions<PrecompiledDefaults>;
21
+ /**
22
+ * @operator {@link intersection | &}
23
+ * @docgenTable
24
+ * @string "L&R"
25
+ * @tuple [L, "&", R]
26
+ * @helper intersection(L,R)
27
+ * @example string
28
+ * const intersection = type("/@arktype\.io$/ & email")
29
+ * @example tuple
30
+ * const tupleIntersection = type(["/@arktype\.io$/", "&", "email"])
31
+ * @example helper
32
+ * const helperIntersection = intersection("/@arktype\.io$/","email")
33
+ */
21
34
  export declare const intersection: Ark["intersection"];
35
+ /**
36
+ * @operator {@link union | |}
37
+ * @docgenTable
38
+ * @string "L|R"
39
+ * @tuple [L, "|" , R]
40
+ * @helper union(L,R)
41
+ * @example string
42
+ * const union = type("string|number")
43
+ * @example tuple
44
+ * const tupleUnion = type(["string", "|", "number"])
45
+ * @example helper
46
+ * const helperUnion = union("string", "number")
47
+ */
22
48
  export declare const union: Ark["union"];
49
+ /**
50
+ * @operator {@link arrayOf}
51
+ * @docgenTable
52
+ * @string "T[]"
53
+ * @tuple [T, "[]"]
54
+ * @helper arrayOf(T)
55
+ * @example string
56
+ * const numberArray = type("number[]")
57
+ * @example tuple
58
+ * const tupleArray = type(["number", "[]"])
59
+ * @example helper
60
+ * const helperArray = arrayOf("number")
61
+ */
23
62
  export declare const arrayOf: Ark["arrayOf"];
63
+ /**
64
+ * @operator {@link keyOf}
65
+ * @docgenTable
66
+ * @tuple "["keyOf", T]"
67
+ * @helper keyOf(T)
68
+ * @example tuple
69
+ * const tupleKeyOf = type(["keyOf", {a:"string"}])
70
+ * @example helper
71
+ * const helperKeyOf = keyOf({a:"string"})
72
+ */
24
73
  export declare const keyOf: Ark["keyOf"];
74
+ /**
75
+ * @operator {@link instanceOf}
76
+ * @docgenTable
77
+ * @tuple ["instanceOf", T]
78
+ * @helper instanceOf(T)
79
+ * @example tuple
80
+ * const tupleInstanceOf = type(["instanceOf", Date])
81
+ * @example helper
82
+ * const helperInstanceOf = instanceOf(Date)
83
+ */
25
84
  export declare const instanceOf: Ark["instanceOf"];
85
+ /**
86
+ * @operator {@link valueOf | ===}
87
+ * @docgenTable
88
+ * @tuple ["===", T]
89
+ * @helper valueOf(T)
90
+ * @example tuple
91
+ * const tupleValueOf = type(["valueOf", {a:"string"}])
92
+ * @example helper
93
+ * const helperValueOf = valueOf({a:"string"})
94
+ */
26
95
  export declare const valueOf: Ark["valueOf"];
96
+ /**
97
+ * @operator {@link narrow | =>}
98
+ * @docgenTable
99
+ * @tuple ["type", "=>" , condition]
100
+ * @example tuple
101
+ * const narrow = type( ["number", "=>" , (n) => n % 2 === 0])
102
+ * @example
103
+ * const isEven = (x: unknown): x is number => x % 2 === 0
104
+ */
27
105
  export declare const narrow: Ark["narrow"];
106
+ /**
107
+ * @operator {@link morph | |>}
108
+ * @docgenTable
109
+ * @tuple [inputType, "|>", (data) => output]
110
+ * @helper morph(inputType, (data) => output)
111
+ * @example tuple
112
+ * const tupleMorph = type( ["string", "|>" , (data) => `morphed ${data}`])
113
+ * @example helper
114
+ * const helperMorph = morph("string", (data) => `morphed ${data}`)
115
+ */
28
116
  export declare const morph: Ark["morph"];
29
117
  export type BinaryExpressionParser<$, operator extends "&" | "|"> = {
30
118
  <l, r>(l: validateDefinition<l, $>, r: validateDefinition<r, $>): parseTupleExpression<[l, operator, r], $>;
@@ -1,34 +1,25 @@
1
1
  /**
2
- * @scope
2
+ * @docgenScope
3
+ * @docgenTable
3
4
  */
4
5
  export declare const jsObjectsScope: import("./scope.js").Scope<[{
5
6
  Function: (...args: any[]) => unknown;
6
- Array: unknown[];
7
7
  Date: Date;
8
8
  Error: Error;
9
9
  Map: Map<unknown, unknown>;
10
10
  RegExp: RegExp;
11
11
  Set: Set<unknown>;
12
- Object: Record<string, unknown>;
13
- String: String;
14
- Number: Number;
15
- Boolean: Boolean;
16
12
  WeakMap: WeakMap<object, unknown>;
17
13
  WeakSet: WeakSet<object>;
18
14
  Promise: Promise<unknown>;
19
15
  }, {}, false]>;
20
16
  export declare const jsObjects: import("./scope.js").Space<{
21
17
  Function: (...args: any[]) => unknown;
22
- Array: unknown[];
23
18
  Date: Date;
24
19
  Error: Error;
25
20
  Map: Map<unknown, unknown>;
26
21
  RegExp: RegExp;
27
22
  Set: Set<unknown>;
28
- Object: Record<string, unknown>;
29
- String: String;
30
- Number: Number;
31
- Boolean: Boolean;
32
23
  WeakMap: WeakMap<object, unknown>;
33
24
  WeakSet: WeakSet<object>;
34
25
  Promise: Promise<unknown>;
@@ -13,7 +13,8 @@
13
13
  "unknown": "unknown",
14
14
  "void": "void",
15
15
  "undefined": "undefined"}
16
- * @scope
16
+ * @docgenScope
17
+ * @docgenTable
17
18
  */
18
19
  export declare const tsKeywordsScope: import("./scope.js").Scope<[{
19
20
  any: any;
@@ -14,7 +14,8 @@
14
14
  "json": "a JSON-parsable string",
15
15
  "integer": "an integer"
16
16
  }
17
- * @scope
17
+ * @docgenScope
18
+ * @docgenTable
18
19
  */
19
20
  export declare const validationScope: import("../scope.js").Scope<[{
20
21
  alpha: string;
@@ -88,7 +88,7 @@ export type requiredKeyOf<o> = {
88
88
  export type optionalKeyOf<o> = Exclude<keyof o, requiredKeyOf<o>>;
89
89
  /** Type equivalent of ?? */
90
90
  export type coalesce<t, fallback> = t extends {} ? t : fallback;
91
- export type error<message extends string = string> = nominal<`!${message}`, "error">;
91
+ export type error<message extends string = string> = `!${message}`;
92
92
  export type castOnError<t, to> = isTopType<t> extends true ? t : t extends never ? t : t extends error ? to : t;
93
93
  export type tryCatch<t, onValid> = isAny<t> extends true ? onValid : t extends never ? onValid : t extends error ? t : onValid;
94
94
  export type RegexLiteral<expression extends string = string> = `/${expression}/`;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "arktype",
3
3
  "description": "TypeScript's 1:1 validator, optimized from editor to runtime",
4
- "version": "1.0.10-alpha",
4
+ "version": "1.0.11-alpha",
5
5
  "author": {
6
6
  "name": "David Blass",
7
7
  "email": "david@arktype.io",
@@ -31,33 +31,33 @@
31
31
  ],
32
32
  "packageManager": "pnpm@7.27.0",
33
33
  "devDependencies": {
34
- "@changesets/cli": "2.26.0",
35
34
  "@changesets/changelog-github": "0.4.8",
35
+ "@changesets/cli": "2.26.1",
36
36
  "@swc/cli": "0.1.62",
37
- "@swc/core": "1.3.35",
37
+ "@swc/core": "1.3.42",
38
38
  "@types/mocha": "10.0.1",
39
- "@types/node": "18.14.0",
40
- "@typescript-eslint/eslint-plugin": "5.53.0",
41
- "@typescript-eslint/parser": "5.53.0",
39
+ "@types/node": "18.15.5",
40
+ "@typescript-eslint/eslint-plugin": "5.56.0",
41
+ "@typescript-eslint/parser": "5.56.0",
42
42
  "c8": "7.13.0",
43
- "eslint": "8.34.0",
44
- "eslint-config-prettier": "8.6.0",
45
- "eslint-define-config": "1.15.0",
43
+ "eslint": "8.36.0",
44
+ "eslint-config-prettier": "8.8.0",
45
+ "eslint-define-config": "1.17.0",
46
46
  "eslint-import-resolver-typescript": "3.5.3",
47
47
  "eslint-plugin-import": "2.27.5",
48
48
  "eslint-plugin-only-warn": "1.1.0",
49
49
  "eslint-plugin-prefer-arrow": "1.2.3",
50
- "eslint-plugin-unicorn": "45.0.2",
51
- "fast-check": "3.6.3",
50
+ "eslint-plugin-unicorn": "46.0.0",
51
+ "fast-check": "3.7.1",
52
52
  "get-current-line": "6.6.0",
53
53
  "husky": "8.0.3",
54
54
  "mocha": "10.2.0",
55
- "prettier": "2.8.4",
55
+ "prettier": "2.8.6",
56
56
  "prettier-plugin-jsdoc": "0.4.2",
57
57
  "pretty-quick": "3.1.3",
58
- "ts-morph": "17.0.1",
58
+ "ts-morph": "18.0.0",
59
59
  "ts-node": "10.9.1",
60
- "typescript": "5.0.1-rc",
60
+ "typescript": "5.0.3",
61
61
  "zod": "3.21.4"
62
62
  },
63
63
  "c8": {
@@ -99,11 +99,10 @@
99
99
  "docgen": "ts-node ./dev/scripts/docgen.ts",
100
100
  "test": "ts-node ./dev/attest/cli.ts --coverage --cmd mocha",
101
101
  "tnt": "ts-node ./dev/attest/cli.ts --coverage --skipTypes --cmd mocha",
102
- "testRepo": " pnpm testBuild && pnpm testTsVersions && pnpm testAttest && pnpm testDeno",
102
+ "testRepo": " pnpm testBuild && pnpm testTsVersions && pnpm testAttest",
103
103
  "testBuild": "ts-node ./dev/scripts/testBuild.ts",
104
104
  "testAttest": "ts-node ./dev/scripts/testAttest.ts",
105
105
  "testTsVersions": "ts-node ./dev/scripts/testTsVersions.ts",
106
- "testDeno": "deno test -c ./dev/configs/deno.jsonc --no-check --allow-all --no-npm -- --skipTypes",
107
106
  "bench": "ts-node ./dev/attest/cli.ts bench --benchmarksPath ./test/benchmarks.json",
108
107
  "lint": "eslint --max-warnings=0 .",
109
108
  "format": "prettier --write --ignore-path ./dev/configs/.prettierignore .",