arktype 0.1.4 → 0.3.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 (106) hide show
  1. package/README.md +1 -1
  2. package/dist/api.cjs +4 -3
  3. package/dist/api.d.ts +3 -2
  4. package/dist/api.mjs +2 -1
  5. package/dist/cjs/nodes/{branches.js → branch.js} +56 -10
  6. package/dist/cjs/nodes/compose.js +1 -2
  7. package/dist/cjs/nodes/discriminate.js +7 -13
  8. package/dist/cjs/nodes/node.js +32 -4
  9. package/dist/cjs/nodes/predicate.js +7 -7
  10. package/dist/cjs/nodes/rules/class.js +10 -4
  11. package/dist/cjs/nodes/rules/divisor.js +1 -5
  12. package/dist/cjs/nodes/rules/props.js +75 -25
  13. package/dist/cjs/nodes/rules/range.js +1 -5
  14. package/dist/cjs/nodes/rules/regex.js +2 -44
  15. package/dist/cjs/nodes/rules/rules.js +21 -61
  16. package/dist/cjs/parse/definition.js +2 -2
  17. package/dist/cjs/parse/string/reduce/dynamic.js +1 -2
  18. package/dist/cjs/parse/string/shift/operator/bounds.js +1 -1
  19. package/dist/cjs/parse/string/string.js +2 -2
  20. package/dist/cjs/parse/tuple/keyof.js +37 -18
  21. package/dist/cjs/parse/tuple/morph.js +7 -6
  22. package/dist/cjs/parse/tuple/tuple.js +16 -9
  23. package/dist/cjs/scopes/cache.js +39 -0
  24. package/dist/cjs/scopes/jsObjects.js +133 -0
  25. package/dist/cjs/{main.js → scopes/scope.js} +31 -364
  26. package/dist/cjs/scopes/standard.js +44 -0
  27. package/dist/cjs/scopes/tsKeywords.js +113 -0
  28. package/dist/cjs/scopes/type.js +67 -0
  29. package/dist/cjs/scopes/validation.js +64 -0
  30. package/dist/cjs/traverse/problems.js +55 -95
  31. package/dist/cjs/traverse/traverse.js +127 -134
  32. package/dist/cjs/utils/numericLiterals.js +3 -0
  33. package/dist/cjs/utils/objectKinds.js +1 -2
  34. package/dist/mjs/nodes/{branches.js → branch.js} +45 -2
  35. package/dist/mjs/nodes/compose.js +1 -2
  36. package/dist/mjs/nodes/discriminate.js +6 -12
  37. package/dist/mjs/nodes/node.js +30 -3
  38. package/dist/mjs/nodes/predicate.js +2 -2
  39. package/dist/mjs/nodes/rules/class.js +10 -4
  40. package/dist/mjs/nodes/rules/divisor.js +1 -5
  41. package/dist/mjs/nodes/rules/props.js +74 -27
  42. package/dist/mjs/nodes/rules/range.js +1 -5
  43. package/dist/mjs/nodes/rules/regex.js +1 -43
  44. package/dist/mjs/nodes/rules/rules.js +22 -61
  45. package/dist/mjs/parse/definition.js +1 -1
  46. package/dist/mjs/parse/string/reduce/dynamic.js +2 -3
  47. package/dist/mjs/parse/string/shift/operator/bounds.js +1 -1
  48. package/dist/mjs/parse/string/string.js +2 -2
  49. package/dist/mjs/parse/tuple/keyof.js +38 -19
  50. package/dist/mjs/parse/tuple/morph.js +7 -6
  51. package/dist/mjs/parse/tuple/tuple.js +17 -10
  52. package/dist/mjs/scopes/cache.js +25 -0
  53. package/dist/mjs/scopes/jsObjects.js +119 -0
  54. package/dist/mjs/{main.js → scopes/scope.js} +15 -344
  55. package/dist/mjs/scopes/standard.js +27 -0
  56. package/dist/mjs/scopes/tsKeywords.js +99 -0
  57. package/dist/mjs/scopes/type.js +53 -0
  58. package/dist/mjs/scopes/validation.js +51 -0
  59. package/dist/mjs/traverse/problems.js +55 -95
  60. package/dist/mjs/traverse/traverse.js +129 -135
  61. package/dist/mjs/utils/numericLiterals.js +2 -1
  62. package/dist/mjs/utils/objectKinds.js +1 -1
  63. package/dist/tsconfig.temp.tsbuildinfo +1 -1
  64. package/dist/types/nodes/branch.d.ts +36 -0
  65. package/dist/types/nodes/compose.d.ts +6 -11
  66. package/dist/types/nodes/discriminate.d.ts +1 -1
  67. package/dist/types/nodes/infer.d.ts +16 -15
  68. package/dist/types/nodes/node.d.ts +18 -9
  69. package/dist/types/nodes/predicate.d.ts +18 -57
  70. package/dist/types/nodes/rules/class.d.ts +3 -2
  71. package/dist/types/nodes/rules/divisor.d.ts +2 -1
  72. package/dist/types/nodes/rules/props.d.ts +19 -11
  73. package/dist/types/nodes/rules/range.d.ts +2 -1
  74. package/dist/types/nodes/rules/regex.d.ts +2 -11
  75. package/dist/types/nodes/rules/rules.d.ts +11 -21
  76. package/dist/types/parse/definition.d.ts +1 -1
  77. package/dist/types/parse/string/ast.d.ts +4 -2
  78. package/dist/types/parse/string/reduce/shared.d.ts +1 -1
  79. package/dist/types/parse/string/reduce/static.d.ts +1 -1
  80. package/dist/types/parse/string/shift/operator/bounds.d.ts +1 -1
  81. package/dist/types/parse/string/string.d.ts +1 -1
  82. package/dist/types/parse/tuple/keyof.d.ts +2 -2
  83. package/dist/types/parse/tuple/morph.d.ts +1 -1
  84. package/dist/types/parse/tuple/narrow.d.ts +1 -1
  85. package/dist/types/parse/tuple/tuple.d.ts +1 -1
  86. package/dist/types/scopes/cache.d.ts +14 -0
  87. package/dist/types/scopes/jsObjects.d.ts +36 -0
  88. package/dist/types/scopes/scope.d.ts +76 -0
  89. package/dist/types/scopes/standard.d.ts +280 -0
  90. package/dist/types/scopes/tsKeywords.d.ts +32 -0
  91. package/dist/types/scopes/type.d.ts +47 -0
  92. package/dist/types/scopes/validation.d.ts +21 -0
  93. package/dist/types/traverse/problems.d.ts +35 -53
  94. package/dist/types/traverse/traverse.d.ts +30 -24
  95. package/dist/types/utils/generics.d.ts +0 -1
  96. package/dist/types/utils/numericLiterals.d.ts +2 -0
  97. package/dist/types/utils/objectKinds.d.ts +43 -43
  98. package/package.json +2 -3
  99. package/dist/cjs/nodes/functors.js +0 -35
  100. package/dist/cjs/nodes/rules/objectKind.js +0 -78
  101. package/dist/mjs/nodes/functors.js +0 -27
  102. package/dist/mjs/nodes/rules/objectKind.js +0 -63
  103. package/dist/types/main.d.ts +0 -324
  104. package/dist/types/nodes/branches.d.ts +0 -14
  105. package/dist/types/nodes/functors.d.ts +0 -6
  106. package/dist/types/nodes/rules/objectKind.d.ts +0 -15
@@ -1,44 +1,34 @@
1
- import type { Morph } from "../../parse/tuple/morph.js";
2
1
  import type { Narrow } from "../../parse/tuple/narrow.js";
3
2
  import type { Domain, inferDomain } from "../../utils/domains.js";
4
3
  import type { CollapsibleList, constructor, Dict } from "../../utils/generics.js";
4
+ import type { DefaultObjectKind } from "../../utils/objectKinds.js";
5
5
  import type { IntersectionState, Intersector } from "../compose.js";
6
- import type { FlattenContext, TraversalEntry } from "../node.js";
7
- import type { ObjectKindRule, TraversalObjectKindRule } from "./objectKind.js";
8
- import type { PropsRule, TraversalOptionalProps, TraversalRequiredProps } from "./props.js";
6
+ import type { FlattenContext, TraversalEntry, TraversalKey } from "../node.js";
7
+ import type { PropEntry, PropsRule } from "./props.js";
9
8
  import type { FlatBound, Range } from "./range.js";
10
9
  export type NarrowableRules<$ = Dict> = {
11
- readonly objectKind?: ObjectKindRule<$>;
12
10
  readonly regex?: CollapsibleList<string>;
13
11
  readonly divisor?: number;
14
12
  readonly range?: Range;
15
13
  readonly props?: PropsRule<$>;
16
- readonly class?: constructor;
14
+ readonly class?: DefaultObjectKind | constructor;
17
15
  readonly narrow?: NarrowRule;
18
16
  };
19
- export type LiteralRules<domain extends Domain = Domain> = {
20
- readonly value: inferDomain<domain>;
17
+ export type LiteralRules<domain extends Domain = Domain, value extends inferDomain<domain> = inferDomain<domain>> = {
18
+ readonly value: value;
21
19
  };
22
20
  export type NarrowRule = CollapsibleList<Narrow>;
23
- export type Branch<domain extends Domain = Domain, $ = Dict> = Rules<domain, $> | MorphBranch<domain, $>;
24
- export type MorphBranch<domain extends Domain = Domain, $ = Dict> = {
25
- input: Rules<domain, $>;
26
- morph: CollapsibleList<Morph>;
27
- };
28
- export type FlatBranch = FlatRules | FlatMorphedBranch;
29
21
  export type FlatRules = RuleEntry[];
30
- type FlatMorphedBranch = [...rules: FlatRules, morph: MorphEntry];
31
- export type RuleEntry = ["objectKind", TraversalObjectKindRule] | ["regex", RegExp] | ["divisor", number] | ["bound", FlatBound] | ["class", constructor] | TraversalRequiredProps | TraversalOptionalProps | ["narrow", Narrow] | ["value", unknown];
32
- export type MorphEntry = ["morph", CollapsibleList<Morph>];
33
- export type Rules<domain extends Domain = Domain, $ = Dict> = Domain extends domain ? NarrowableRules | LiteralRules : domain extends "object" ? defineRuleSet<domain, "objectKind" | "props" | "range" | "narrow" | "class", $> : domain extends "string" ? defineRuleSet<domain, "regex" | "range" | "narrow", $> : domain extends "number" ? defineRuleSet<domain, "divisor" | "range" | "narrow", $> : defineRuleSet<domain, "narrow", $>;
22
+ export type RuleEntry = ["regex", string] | ["divisor", number] | ["bound", FlatBound] | ["class", DefaultObjectKind | constructor] | PropEntry | ["narrow", Narrow] | ["value", unknown];
23
+ export type Rules<domain extends Domain = Domain, $ = Dict> = Domain extends domain ? NarrowableRules | LiteralRules : domain extends "object" ? defineRuleSet<domain, "props" | "range" | "narrow" | "class", $> : domain extends "string" ? defineRuleSet<domain, "regex" | "range" | "narrow", $> : domain extends "number" ? defineRuleSet<domain, "divisor" | "range" | "narrow", $> : defineRuleSet<domain, "narrow", $>;
34
24
  type defineRuleSet<domain extends Domain, keys extends keyof NarrowableRules, $> = Pick<NarrowableRules<$>, keys> | LiteralRules<domain>;
35
- export declare const branchIntersection: Intersector<Branch>;
36
25
  export declare const rulesIntersection: Intersector<Rules>;
37
26
  export declare const narrowableRulesIntersection: Intersector<NarrowableRules<Dict>>;
27
+ export declare const flattenRules: (rules: UnknownRules, ctx: FlattenContext) => TraversalEntry[];
38
28
  export type FlattenAndPushRule<t> = (entries: RuleEntry[], rule: t, ctx: FlattenContext) => void;
29
+ type UnknownRules = NarrowableRules & Partial<LiteralRules>;
39
30
  export declare const precedenceMap: {
40
- readonly [k in TraversalEntry[0]]: number;
31
+ readonly [k in TraversalKey]: number;
41
32
  };
42
- export declare const flattenBranch: (branch: Branch, ctx: FlattenContext) => FlatBranch;
43
33
  export declare const literalSatisfiesRules: (data: unknown, rules: NarrowableRules, state: IntersectionState) => boolean;
44
34
  export {};
@@ -1,5 +1,5 @@
1
- import type { Type } from "../main.js";
2
1
  import type { TypeNode } from "../nodes/node.js";
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
5
  import type { Dict, evaluateObject, isAny, isUnknown, List } from "../utils/generics.js";
@@ -1,5 +1,7 @@
1
- import type { asIn, resolve } from "../../main.js";
2
1
  import type { DisjointsByPath } from "../../nodes/compose.js";
2
+ import type { MappedKeys } from "../../nodes/rules/props.js";
3
+ import type { resolve } from "../../scopes/scope.js";
4
+ import type { asIn } from "../../scopes/type.js";
3
5
  import type { domainOf } from "../../utils/domains.js";
4
6
  import type { asConst, castOnError, Dict, equals, error, evaluate, evaluateObject, extractValues, isAny, List, Literalable, RegexLiteral, requiredKeyOf, stringKeyOf, tryCatch } from "../../utils/generics.js";
5
7
  import type { objectKindOf } from "../../utils/objectKinds.js";
@@ -16,7 +18,7 @@ type inferIntersectionRecurse<l, r, path extends string[]> = path["length"] exte
16
18
  [k in stringKeyOf<l>]: k extends keyof r ? inferIntersectionRecurse<l[k], r[k], [...path, k]> : l[k];
17
19
  } & Omit<r, keyof l>>> : [l, r] extends [List<infer lItem>, List<infer rItem>] ? inferIntersectionRecurse<lItem, rItem, [
18
20
  ...path,
19
- "${number}"
21
+ MappedKeys["index"]
20
22
  ]> extends infer result ? tryCatch<result, result[]> : never : l & r;
21
23
  type bubblePropErrors<o> = extractValues<o, error> extends never ? o : extractValues<o, error>;
22
24
  export type inferUnion<l, r> = isAny<l | r> extends true ? any : [l] extends [never] ? r : [r] extends [never] ? l : [asIn<l>, asIn<r>] extends [infer lIn, infer rIn] ? [equals<l, lIn>, equals<r, rIn>] extends [true, true] ? l | r : discriminatable<lIn, rIn> extends true ? l | r : error<undiscriminatableMorphUnionMessage> : never;
@@ -7,7 +7,7 @@ export type unclosedGroupMessage = typeof unclosedGroupMessage;
7
7
  export declare const writeOpenRangeMessage: <min extends number, comparator extends ">" | ">=">(min: min, comparator: comparator) => `Left bounds are only valid when paired with right bounds (try ...${comparator}${min})`;
8
8
  export type writeOpenRangeMessage<min extends number, comparator extends MinComparator> = `Left bounds are only valid when paired with right bounds (try ...${comparator}${min})`;
9
9
  export type writeUnpairableComparatorMessage<comparator extends Scanner.Comparator> = `Left-bounded expressions must specify their limits using < or <= (was ${comparator})`;
10
- export declare const writeUnpairableComparatorMessage: <comparator extends "==" | ">" | "<" | ">=" | "<=">(comparator: comparator) => `Left-bounded expressions must specify their limits using < or <= (was ${comparator})`;
10
+ export declare const writeUnpairableComparatorMessage: <comparator extends ">" | "<" | ">=" | "<=" | "==">(comparator: comparator) => `Left-bounded expressions must specify their limits using < or <= (was ${comparator})`;
11
11
  export declare const writeMultipleLeftBoundsMessage: <openLimit extends number, openComparator extends ">" | ">=", limit extends number, comparator extends ">" | ">=">(openLimit: openLimit, openComparator: openComparator, limit: limit, comparator: comparator) => `An expression may have at most one left bound (parsed ${openLimit}${{
12
12
  readonly "<": ">";
13
13
  readonly ">": "<";
@@ -81,7 +81,7 @@ export declare namespace state {
81
81
  ...stack,
82
82
  top
83
83
  ];
84
- export type finalizeGroup<s extends StaticState, unscanned extends string> = s["groups"] extends popGroup<infer stack, infer top> ? from<{
84
+ export type finalizeGroup<s extends StaticState, unscanned extends string> = s["branches"]["range"] extends {} ? openRangeError<s["branches"]["range"]> : s["groups"] extends popGroup<infer stack, infer top> ? from<{
85
85
  groups: stack;
86
86
  branches: top;
87
87
  root: mergeToUnion<s>;
@@ -13,7 +13,7 @@ export declare const singleEqualsMessage = "= is not a valid comparator. Use ==
13
13
  type singleEqualsMessage = typeof singleEqualsMessage;
14
14
  export declare const parseRightBound: (s: DynamicState, comparator: Scanner.Comparator) => void;
15
15
  export type parseRightBound<s extends StaticState, comparator extends Scanner.Comparator, unscanned extends string> = Scanner.shiftUntilNextTerminator<unscanned> extends Scanner.shiftResult<infer scanned, infer nextUnscanned> ? tryParseWellFormedNumber<scanned, writeInvalidLimitMessage<comparator, scanned>> extends infer limit ? limit extends number ? s["branches"]["range"] extends {} ? comparator extends MaxComparator ? state.reduceRange<s, s["branches"]["range"]["limit"], s["branches"]["range"]["comparator"], comparator, limit, nextUnscanned> : error<writeUnpairableComparatorMessage<comparator>> : state.reduceSingleBound<s, comparator, limit, nextUnscanned> : error<limit & string> : never : never;
16
- export declare const writeInvalidLimitMessage: <comparator extends "==" | ">" | "<" | ">=" | "<=", limit extends string>(comparator: comparator, limit: limit) => `Comparator ${comparator} must be followed by a number literal (was '${limit}')`;
16
+ export declare const writeInvalidLimitMessage: <comparator extends ">" | "<" | ">=" | "<=" | "==", limit extends string>(comparator: comparator, limit: limit) => `Comparator ${comparator} must be followed by a number literal (was '${limit}')`;
17
17
  export type writeInvalidLimitMessage<comparator extends Scanner.Comparator, limit extends string> = `Comparator ${comparator} must be followed by a number literal (was '${limit}')`;
18
18
  export declare const writeEmptyRangeMessage: (range: Range) => string;
19
19
  export type BoundableDomain = "string" | "number" | "object";
@@ -16,7 +16,7 @@ export type validateString<def extends string, $> = parseString<def, $> extends
16
16
  * This can be much more efficient for simple definitions.
17
17
  */
18
18
  type maybeNaiveParse<def extends string, $> = def extends `${infer child}[]` ? isResolvableIdentifier<child, $> extends true ? [child, "[]"] : fullStringParse<def, $> : isResolvableIdentifier<def, $> extends true ? def : fullStringParse<def, $>;
19
- export declare const maybeNaiveParse: (def: string, ctx: ParseContext) => string | import("../../nodes/node.js").ResolvedNode | undefined;
19
+ export declare const maybeNaiveParse: (def: string, ctx: ParseContext) => string | import("../../nodes/node.js").ResolvedNode<import("../../utils/generics.js").Dict> | undefined;
20
20
  export declare const fullStringParse: (def: string, ctx: ParseContext) => import("../../nodes/node.js").TypeNode;
21
21
  type fullStringParse<def extends string, $> = loop<state.initialize<def>, $>;
22
22
  declare const loop: (s: DynamicState) => import("../../nodes/node.js").TypeNode;
@@ -1,9 +1,9 @@
1
- import type { nonArrayKeyOf } from "../../utils/generics.js";
1
+ import type { keyOf } from "../../utils/generics.js";
2
2
  import type { inferDefinition, validateDefinition } from "../definition.js";
3
3
  import { writeImplicitNeverMessage } from "../string/ast.js";
4
4
  import type { PrefixParser } from "./tuple.js";
5
5
  export declare const parseKeyOfTuple: PrefixParser<"keyof">;
6
- export type inferKeyOfExpression<operandDef, $> = nonArrayKeyOf<inferDefinition<operandDef, $>>;
6
+ export type inferKeyOfExpression<operandDef, $> = keyOf<inferDefinition<operandDef, $>>;
7
7
  export type validateKeyOfExpression<operandDef, $> = [
8
8
  "keyof",
9
9
  inferKeyOfExpression<operandDef, $> extends never ? writeImplicitNeverMessage<[], "keyof"> : validateDefinition<operandDef, $>
@@ -1,4 +1,4 @@
1
- import type { asOut } from "../../main.js";
1
+ import type { asOut } from "../../scopes/type.js";
2
2
  import type { nominal } from "../../utils/generics.js";
3
3
  import type { inferDefinition, validateDefinition } from "../definition.js";
4
4
  import type { PostfixParser, TupleExpression } from "./tuple.js";
@@ -1,4 +1,4 @@
1
- import type { asIn } from "../../main.js";
1
+ import type { asIn } from "../../scopes/type.js";
2
2
  import type { Problems } from "../../traverse/problems.js";
3
3
  import type { inferDefinition, validateDefinition } from "../definition.js";
4
4
  import type { PostfixParser, TupleExpression } from "./tuple.js";
@@ -1,6 +1,6 @@
1
- import type { asIn, asOut } from "../../main.js";
2
1
  import type { inferNode } from "../../nodes/infer.js";
3
2
  import type { ResolvedNode, TypeNode } from "../../nodes/node.js";
3
+ import type { asIn, asOut } from "../../scopes/type.js";
4
4
  import type { conform, constructor, error, List, returnOf } from "../../utils/generics.js";
5
5
  import type { inferDefinition, ParseContext, validateDefinition } from "../definition.js";
6
6
  import type { inferIntersection, inferUnion } from "../string/ast.js";
@@ -0,0 +1,14 @@
1
+ export declare class Cache<item = unknown> {
2
+ protected cache: {
3
+ [name in string]?: item;
4
+ };
5
+ get root(): {
6
+ readonly [name in string]?: item;
7
+ };
8
+ has(name: string): boolean;
9
+ get(name: string): item | undefined;
10
+ set(name: string, item: item): item;
11
+ }
12
+ export declare class FreezingCache<item = unknown> extends Cache<item> {
13
+ set(name: string, item: item): item;
14
+ }
@@ -0,0 +1,36 @@
1
+ export declare const jsObjectsScope: import("./scope.js").Scope<[{
2
+ Function: (...args: any[]) => unknown;
3
+ Array: unknown[];
4
+ Date: Date;
5
+ Error: Error;
6
+ Map: Map<unknown, unknown>;
7
+ RegExp: RegExp;
8
+ Set: Set<unknown>;
9
+ Object: {
10
+ [x: string]: unknown;
11
+ };
12
+ String: String;
13
+ Number: Number;
14
+ Boolean: Boolean;
15
+ WeakMap: WeakMap<object, unknown>;
16
+ WeakSet: WeakSet<object>;
17
+ Promise: Promise<unknown>;
18
+ }, {}, false]>;
19
+ export declare const jsObjects: import("./scope.js").Space<{
20
+ Function: (...args: any[]) => unknown;
21
+ Array: unknown[];
22
+ Date: Date;
23
+ Error: Error;
24
+ Map: Map<unknown, unknown>;
25
+ RegExp: RegExp;
26
+ Set: Set<unknown>;
27
+ Object: {
28
+ [x: string]: unknown;
29
+ };
30
+ String: String;
31
+ Number: Number;
32
+ Boolean: Boolean;
33
+ WeakMap: WeakMap<object, unknown>;
34
+ WeakSet: WeakSet<object>;
35
+ Promise: Promise<unknown>;
36
+ }>;
@@ -0,0 +1,76 @@
1
+ import type { ResolvedNode, TypeNode } from "../nodes/node.js";
2
+ import type { inferDefinition, ParseContext, validateDefinition } from "../parse/definition.js";
3
+ import type { Dict, error, evaluateObject, isAny, List, nominal } from "../utils/generics.js";
4
+ import type { stringifyUnion } from "../utils/unionToTuple.js";
5
+ import { FreezingCache } from "./cache.js";
6
+ import type { PrecompiledDefaults } from "./standard.js";
7
+ import type { Type, TypeConfig, TypeParser } from "./type.js";
8
+ type ScopeParser = {
9
+ <aliases>(aliases: validateAliases<aliases, {}>): Scope<parseScope<aliases, {}>>;
10
+ <aliases, opts extends ScopeOptions>(aliases: validateAliases<aliases, opts>, opts: validateOptions<opts>): Scope<parseScope<aliases, opts>>;
11
+ };
12
+ export type ScopeOptions = {
13
+ imports?: Space[] | [];
14
+ includes?: Space[] | [];
15
+ standard?: boolean;
16
+ name?: string;
17
+ config?: TypeConfig;
18
+ };
19
+ type validateOptions<opts extends ScopeOptions> = {
20
+ [k in keyof opts]: k extends "imports" | "includes" ? mergeSpaces<opts[k], [
21
+ k,
22
+ "imports"
23
+ ] extends ["includes", keyof opts] ? mergeSpaces<opts["includes"]> : {}> extends error<infer e> ? e : opts[k] : opts[k];
24
+ };
25
+ export type ScopeContext = Dict | ScopeContextTuple;
26
+ type ScopeContextTuple = [exports: Dict, locals: Dict, standard?: false];
27
+ type parseScope<aliases, opts extends ScopeOptions> = opts["standard"] extends false ? [inferExports<aliases, opts>, importsOf<opts>, false] : opts["imports"] extends Space[] ? [inferExports<aliases, opts>, importsOf<opts>] : inferExports<aliases, opts>;
28
+ type importsOf<opts extends ScopeOptions> = unknown extends opts["imports"] ? {} : mergeSpaces<opts["imports"]>;
29
+ type includesOf<opts extends ScopeOptions> = unknown extends opts["includes"] ? {} : mergeSpaces<opts["includes"]>;
30
+ export type resolve<name extends keyof $, $> = isAny<$[name]> extends true ? any : $[name] extends alias<infer def> ? inferDefinition<def, $> : $[name];
31
+ type exportsOf<context extends ScopeContext> = context extends [
32
+ infer exports,
33
+ ...unknown[]
34
+ ] ? exports : context;
35
+ type localsOf<context extends ScopeContext> = context extends List ? context["1"] & (context["2"] extends false ? {} : PrecompiledDefaults) : PrecompiledDefaults;
36
+ type mergeSpaces<scopes, base extends Dict = {}> = scopes extends readonly [
37
+ Space<infer head>,
38
+ ...infer tail
39
+ ] ? keyof base & keyof head extends never ? mergeSpaces<tail, base & head> : error<writeDuplicateAliasesMessage<stringifyUnion<keyof base & keyof head & string>>> : base;
40
+ type validateAliases<aliases, opts extends ScopeOptions> = {
41
+ [name in keyof aliases]: name extends keyof preresolved<opts> ? writeDuplicateAliasesMessage<name & string> : validateDefinition<aliases[name], bootstrapScope<aliases, opts>>;
42
+ };
43
+ type preresolved<opts extends ScopeOptions> = includesOf<opts> & importsOf<opts> & (opts["standard"] extends false ? {} : PrecompiledDefaults);
44
+ type alias<def = {}> = nominal<def, "alias">;
45
+ type bootstrapScope<aliases, opts extends ScopeOptions> = {
46
+ [k in keyof aliases]: alias<aliases[k]>;
47
+ } & preresolved<opts>;
48
+ type inferExports<aliases, opts extends ScopeOptions> = evaluateObject<{
49
+ [k in keyof aliases]: inferDefinition<aliases[k], bootstrapScope<aliases, opts>>;
50
+ } & includesOf<opts>>;
51
+ export type Space<exports = Dict> = {
52
+ [k in keyof exports]: Type<exports[k]>;
53
+ };
54
+ type resolutions<context extends ScopeContext> = localsOf<context> & exportsOf<context>;
55
+ type name<context extends ScopeContext> = keyof resolutions<context> & string;
56
+ export declare class Scope<context extends ScopeContext = any> {
57
+ #private;
58
+ aliases: Dict;
59
+ opts: ScopeOptions;
60
+ name: string;
61
+ config: TypeConfig | undefined;
62
+ parseCache: FreezingCache<TypeNode>;
63
+ constructor(aliases: Dict, opts: ScopeOptions);
64
+ type: TypeParser<resolutions<context>>;
65
+ createAnonymousTypeSuffix(): number;
66
+ get infer(): exportsOf<context>;
67
+ compile(): Space<exportsOf<context>>;
68
+ addReferenceIfResolvable(name: name<context>, ctx: ParseContext): boolean;
69
+ resolve(name: name<context>): Type;
70
+ resolveNode(node: TypeNode): ResolvedNode;
71
+ }
72
+ export declare const writeShallowCycleErrorMessage: (name: string, seen: string[]) => string;
73
+ export declare const scope: ScopeParser;
74
+ export declare const writeDuplicateAliasesMessage: <name_1 extends string>(name: name_1) => `Alias '${name_1}' is already defined`;
75
+ type writeDuplicateAliasesMessage<name extends string> = `Alias '${name}' is already defined`;
76
+ export {};
@@ -0,0 +1,280 @@
1
+ import type { InferredObjectKinds } from "../utils/objectKinds.js";
2
+ import type { Space } from "./scope.js";
3
+ import type { TypeParser } from "./type.js";
4
+ export declare const standardScope: import("./scope.js").Scope<[{
5
+ any: any;
6
+ bigint: bigint;
7
+ boolean: boolean;
8
+ false: false;
9
+ never: never;
10
+ null: null;
11
+ number: number;
12
+ object: object;
13
+ string: string;
14
+ symbol: symbol;
15
+ true: true;
16
+ unknown: unknown;
17
+ void: void;
18
+ undefined: undefined;
19
+ Function: (...args: any[]) => unknown;
20
+ Array: unknown[];
21
+ Date: Date;
22
+ Error: Error;
23
+ Map: Map<unknown, unknown>;
24
+ RegExp: RegExp;
25
+ Set: Set<unknown>;
26
+ Object: {
27
+ [x: string]: unknown;
28
+ };
29
+ String: String;
30
+ Number: Number;
31
+ Boolean: Boolean;
32
+ WeakMap: WeakMap<object, unknown>;
33
+ WeakSet: WeakSet<object>;
34
+ Promise: Promise<unknown>;
35
+ alpha: string;
36
+ alphanumeric: string;
37
+ lowercase: string;
38
+ uppercase: string;
39
+ creditCard: string;
40
+ email: string;
41
+ uuid: string;
42
+ integer: number;
43
+ }, {}, false]>;
44
+ export declare const standard: Space<{
45
+ any: any;
46
+ bigint: bigint;
47
+ boolean: boolean;
48
+ false: false;
49
+ never: never;
50
+ null: null;
51
+ number: number;
52
+ object: object;
53
+ string: string;
54
+ symbol: symbol;
55
+ true: true;
56
+ unknown: unknown;
57
+ void: void;
58
+ undefined: undefined;
59
+ Function: (...args: any[]) => unknown;
60
+ Array: unknown[];
61
+ Date: Date;
62
+ Error: Error;
63
+ Map: Map<unknown, unknown>;
64
+ RegExp: RegExp;
65
+ Set: Set<unknown>;
66
+ Object: {
67
+ [x: string]: unknown;
68
+ };
69
+ String: String;
70
+ Number: Number;
71
+ Boolean: Boolean;
72
+ WeakMap: WeakMap<object, unknown>;
73
+ WeakSet: WeakSet<object>;
74
+ Promise: Promise<unknown>;
75
+ alpha: string;
76
+ alphanumeric: string;
77
+ lowercase: string;
78
+ uppercase: string;
79
+ creditCard: string;
80
+ email: string;
81
+ uuid: string;
82
+ integer: number;
83
+ }>;
84
+ export declare const scopes: {
85
+ tsKeywords: import("./scope.js").Scope<[{
86
+ any: any;
87
+ bigint: bigint;
88
+ boolean: boolean;
89
+ false: false;
90
+ never: never;
91
+ null: null;
92
+ number: number;
93
+ object: object;
94
+ string: string;
95
+ symbol: symbol;
96
+ true: true;
97
+ unknown: unknown;
98
+ void: void;
99
+ undefined: undefined;
100
+ }, {}, false]>;
101
+ jsObjects: import("./scope.js").Scope<[{
102
+ Function: (...args: any[]) => unknown;
103
+ Array: unknown[];
104
+ Date: Date;
105
+ Error: Error;
106
+ Map: Map<unknown, unknown>;
107
+ RegExp: RegExp;
108
+ Set: Set<unknown>;
109
+ Object: {
110
+ [x: string]: unknown;
111
+ };
112
+ String: String;
113
+ Number: Number;
114
+ Boolean: Boolean;
115
+ WeakMap: WeakMap<object, unknown>;
116
+ WeakSet: WeakSet<object>;
117
+ Promise: Promise<unknown>;
118
+ }, {}, false]>;
119
+ validation: import("./scope.js").Scope<[{
120
+ alpha: string;
121
+ alphanumeric: string;
122
+ lowercase: string;
123
+ uppercase: string;
124
+ creditCard: string;
125
+ email: string;
126
+ uuid: string;
127
+ integer: number;
128
+ }, {}, false]>;
129
+ standard: import("./scope.js").Scope<[{
130
+ any: any;
131
+ bigint: bigint;
132
+ boolean: boolean;
133
+ false: false;
134
+ never: never;
135
+ null: null;
136
+ number: number;
137
+ object: object;
138
+ string: string;
139
+ symbol: symbol;
140
+ true: true;
141
+ unknown: unknown;
142
+ void: void;
143
+ undefined: undefined;
144
+ Function: (...args: any[]) => unknown;
145
+ Array: unknown[];
146
+ Date: Date;
147
+ Error: Error;
148
+ Map: Map<unknown, unknown>;
149
+ RegExp: RegExp;
150
+ Set: Set<unknown>;
151
+ Object: {
152
+ [x: string]: unknown;
153
+ };
154
+ String: String;
155
+ Number: Number;
156
+ Boolean: Boolean;
157
+ WeakMap: WeakMap<object, unknown>;
158
+ WeakSet: WeakSet<object>;
159
+ Promise: Promise<unknown>;
160
+ alpha: string;
161
+ alphanumeric: string;
162
+ lowercase: string;
163
+ uppercase: string;
164
+ creditCard: string;
165
+ email: string;
166
+ uuid: string;
167
+ integer: number;
168
+ }, {}, false]>;
169
+ };
170
+ export declare const spaces: {
171
+ tsKeywords: Space<{
172
+ any: any;
173
+ bigint: bigint;
174
+ boolean: boolean;
175
+ false: false;
176
+ never: never;
177
+ null: null;
178
+ number: number;
179
+ object: object;
180
+ string: string;
181
+ symbol: symbol;
182
+ true: true;
183
+ unknown: unknown;
184
+ void: void;
185
+ undefined: undefined;
186
+ }>;
187
+ jsObjects: Space<{
188
+ Function: (...args: any[]) => unknown;
189
+ Array: unknown[];
190
+ Date: Date;
191
+ Error: Error;
192
+ Map: Map<unknown, unknown>;
193
+ RegExp: RegExp;
194
+ Set: Set<unknown>;
195
+ Object: {
196
+ [x: string]: unknown;
197
+ };
198
+ String: String;
199
+ Number: Number;
200
+ Boolean: Boolean;
201
+ WeakMap: WeakMap<object, unknown>;
202
+ WeakSet: WeakSet<object>;
203
+ Promise: Promise<unknown>;
204
+ }>;
205
+ validation: Space<{
206
+ alpha: string;
207
+ alphanumeric: string;
208
+ lowercase: string;
209
+ uppercase: string;
210
+ creditCard: string;
211
+ email: string;
212
+ uuid: string;
213
+ integer: number;
214
+ }>;
215
+ standard: Space<{
216
+ any: any;
217
+ bigint: bigint;
218
+ boolean: boolean;
219
+ false: false;
220
+ never: never;
221
+ null: null;
222
+ number: number;
223
+ object: object;
224
+ string: string;
225
+ symbol: symbol;
226
+ true: true;
227
+ unknown: unknown;
228
+ void: void;
229
+ undefined: undefined;
230
+ Function: (...args: any[]) => unknown;
231
+ Array: unknown[];
232
+ Date: Date;
233
+ Error: Error;
234
+ Map: Map<unknown, unknown>;
235
+ RegExp: RegExp;
236
+ Set: Set<unknown>;
237
+ Object: {
238
+ [x: string]: unknown;
239
+ };
240
+ String: String;
241
+ Number: Number;
242
+ Boolean: Boolean;
243
+ WeakMap: WeakMap<object, unknown>;
244
+ WeakSet: WeakSet<object>;
245
+ Promise: Promise<unknown>;
246
+ alpha: string;
247
+ alphanumeric: string;
248
+ lowercase: string;
249
+ uppercase: string;
250
+ creditCard: string;
251
+ email: string;
252
+ uuid: string;
253
+ integer: number;
254
+ }>;
255
+ };
256
+ export type PrecompiledDefaults = {
257
+ any: any;
258
+ bigint: bigint;
259
+ boolean: boolean;
260
+ false: false;
261
+ never: never;
262
+ null: null;
263
+ number: number;
264
+ object: object;
265
+ string: string;
266
+ symbol: symbol;
267
+ true: true;
268
+ unknown: unknown;
269
+ void: void;
270
+ undefined: undefined;
271
+ integer: number;
272
+ alpha: string;
273
+ alphanumeric: string;
274
+ lowercase: string;
275
+ uppercase: string;
276
+ creditCard: string;
277
+ email: string;
278
+ uuid: string;
279
+ } & InferredObjectKinds;
280
+ export declare const type: TypeParser<PrecompiledDefaults>;
@@ -0,0 +1,32 @@
1
+ export declare const tsKeywordsScope: import("./scope.js").Scope<[{
2
+ any: any;
3
+ bigint: bigint;
4
+ boolean: boolean;
5
+ false: false;
6
+ never: never;
7
+ null: null;
8
+ number: number;
9
+ object: object;
10
+ string: string;
11
+ symbol: symbol;
12
+ true: true;
13
+ unknown: unknown;
14
+ void: void;
15
+ undefined: undefined;
16
+ }, {}, false]>;
17
+ export declare const tsKeywords: import("./scope.js").Space<{
18
+ any: any;
19
+ bigint: bigint;
20
+ boolean: boolean;
21
+ false: false;
22
+ never: never;
23
+ null: null;
24
+ number: number;
25
+ object: object;
26
+ string: string;
27
+ symbol: symbol;
28
+ true: true;
29
+ unknown: unknown;
30
+ void: void;
31
+ undefined: undefined;
32
+ }>;
@@ -0,0 +1,47 @@
1
+ import type { TraversalNode, TypeNode } from "../nodes/node.js";
2
+ import type { as, inferDefinition, validateDefinition } from "../parse/definition.js";
3
+ import type { ParsedMorph } from "../parse/tuple/morph.js";
4
+ import type { Problems, ProblemsConfig } from "../traverse/problems.js";
5
+ import type { defer, evaluateObject, xor } from "../utils/generics.js";
6
+ import type { BuiltinClass } from "../utils/objectKinds.js";
7
+ import type { Scope } from "./scope.js";
8
+ export type TypeParser<$> = {
9
+ <def>(def: validateDefinition<def, $>): parseType<def, $>;
10
+ <def>(def: validateDefinition<def, $>, opts: TypeOptions): parseType<def, $>;
11
+ };
12
+ export type parseType<def, $> = def extends validateDefinition<def, $> ? Type<inferDefinition<def, $>> : never;
13
+ type TypeRoot<t = unknown> = {
14
+ [as]: t;
15
+ infer: asOut<t>;
16
+ node: TypeNode;
17
+ flat: TraversalNode;
18
+ meta: TypeMeta;
19
+ };
20
+ export type TypeOptions = evaluateObject<{
21
+ name?: string;
22
+ } & ProblemsConfig>;
23
+ export type TypeConfig = ProblemsConfig;
24
+ type TypeMeta = {
25
+ name: string;
26
+ id: QualifiedTypeName;
27
+ definition: unknown;
28
+ scope: Scope;
29
+ config: TypeConfig | undefined;
30
+ includesMorph: boolean;
31
+ };
32
+ export declare const initializeType: (definition: unknown, opts: TypeOptions | undefined, scope: Scope) => Type<unknown>;
33
+ export declare const isType: (value: unknown) => value is Type<unknown>;
34
+ export type CheckResult<t> = xor<{
35
+ data: asOut<t>;
36
+ }, {
37
+ problems: Problems;
38
+ }>;
39
+ type Checker<t> = (data: unknown) => CheckResult<t>;
40
+ export type Type<t = unknown> = defer<Checker<t> & TypeRoot<t>>;
41
+ export type QualifiedTypeName = `${string}.${string}`;
42
+ export type asIn<t> = asIo<t, "in">;
43
+ export type asOut<t> = asIo<t, "out">;
44
+ type asIo<t, io extends "in" | "out"> = t extends ParsedMorph<infer i, infer o> ? io extends "in" ? i : o : t extends object ? t extends Function | BuiltinClass ? t : {
45
+ [k in keyof t]: asIo<t[k], io>;
46
+ } : t;
47
+ export {};