arktype 0.1.1 → 0.1.3

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 (71) hide show
  1. package/dist/api.cjs +4 -1
  2. package/dist/api.d.ts +1 -0
  3. package/dist/api.mjs +1 -0
  4. package/dist/cjs/main.js +127 -15
  5. package/dist/cjs/nodes/branches.js +7 -7
  6. package/dist/cjs/nodes/compose.js +3 -2
  7. package/dist/cjs/nodes/discriminate.js +5 -4
  8. package/dist/cjs/nodes/functors.js +3 -3
  9. package/dist/cjs/nodes/node.js +1 -1
  10. package/dist/cjs/nodes/predicate.js +19 -14
  11. package/dist/cjs/nodes/rules/collapsibleSet.js +3 -4
  12. package/dist/cjs/nodes/rules/objectKind.js +78 -0
  13. package/dist/cjs/nodes/rules/range.js +2 -2
  14. package/dist/cjs/nodes/rules/rules.js +4 -4
  15. package/dist/cjs/parse/definition.js +26 -6
  16. package/dist/cjs/parse/string/shift/operator/bounds.js +1 -1
  17. package/dist/cjs/parse/tuple/morph.js +2 -2
  18. package/dist/cjs/parse/tuple/tuple.js +1 -1
  19. package/dist/cjs/traverse/problems.js +18 -32
  20. package/dist/cjs/traverse/traverse.js +12 -12
  21. package/dist/cjs/utils/domains.js +10 -47
  22. package/dist/cjs/utils/generics.js +1 -3
  23. package/dist/cjs/utils/objectKinds.js +64 -0
  24. package/dist/cjs/utils/serialize.js +8 -8
  25. package/dist/cjs/utils/size.js +16 -0
  26. package/dist/mjs/main.js +127 -15
  27. package/dist/mjs/nodes/branches.js +7 -7
  28. package/dist/mjs/nodes/compose.js +3 -2
  29. package/dist/mjs/nodes/discriminate.js +6 -5
  30. package/dist/mjs/nodes/functors.js +3 -3
  31. package/dist/mjs/nodes/node.js +1 -1
  32. package/dist/mjs/nodes/predicate.js +20 -15
  33. package/dist/mjs/nodes/rules/collapsibleSet.js +3 -4
  34. package/dist/mjs/nodes/rules/{subdomain.js → objectKind.js} +10 -10
  35. package/dist/mjs/nodes/rules/range.js +1 -1
  36. package/dist/mjs/nodes/rules/rules.js +4 -4
  37. package/dist/mjs/parse/definition.js +27 -7
  38. package/dist/mjs/parse/string/shift/operator/bounds.js +1 -1
  39. package/dist/mjs/parse/tuple/morph.js +2 -2
  40. package/dist/mjs/parse/tuple/tuple.js +1 -1
  41. package/dist/mjs/traverse/problems.js +18 -31
  42. package/dist/mjs/traverse/traverse.js +12 -12
  43. package/dist/mjs/utils/domains.js +9 -42
  44. package/dist/mjs/utils/generics.js +0 -1
  45. package/dist/mjs/utils/objectKinds.js +48 -0
  46. package/dist/mjs/utils/serialize.js +8 -8
  47. package/dist/mjs/utils/size.js +2 -0
  48. package/dist/tsconfig.temp.tsbuildinfo +1 -1
  49. package/dist/types/main.d.ts +73 -9
  50. package/dist/types/nodes/branches.d.ts +4 -4
  51. package/dist/types/nodes/compose.d.ts +12 -5
  52. package/dist/types/nodes/discriminate.d.ts +3 -2
  53. package/dist/types/nodes/infer.d.ts +11 -10
  54. package/dist/types/nodes/predicate.d.ts +2 -2
  55. package/dist/types/nodes/rules/objectKind.d.ts +15 -0
  56. package/dist/types/nodes/rules/range.d.ts +1 -1
  57. package/dist/types/nodes/rules/rules.d.ts +4 -4
  58. package/dist/types/parse/definition.d.ts +6 -5
  59. package/dist/types/parse/string/ast.d.ts +4 -2
  60. package/dist/types/parse/string/reduce/shared.d.ts +1 -1
  61. package/dist/types/parse/string/shift/operator/bounds.d.ts +1 -1
  62. package/dist/types/traverse/problems.d.ts +25 -41
  63. package/dist/types/traverse/traverse.d.ts +24 -4
  64. package/dist/types/utils/domains.d.ts +11 -37
  65. package/dist/types/utils/generics.d.ts +0 -1
  66. package/dist/types/utils/objectKinds.d.ts +83 -0
  67. package/dist/types/utils/serialize.d.ts +2 -2
  68. package/dist/types/utils/size.d.ts +3 -0
  69. package/package.json +10 -5
  70. package/dist/cjs/nodes/rules/subdomain.js +0 -78
  71. package/dist/types/nodes/rules/subdomain.d.ts +0 -15
@@ -1,8 +1,9 @@
1
1
  import type { Type } from "../main.js";
2
2
  import type { TypeNode } from "../nodes/node.js";
3
- import type { Primitive, Subdomain } from "../utils/domains.js";
4
- import { subdomainOf } from "../utils/domains.js";
3
+ import type { Primitive } from "../utils/domains.js";
4
+ import { domainOf } from "../utils/domains.js";
5
5
  import type { Dict, evaluateObject, isAny, isUnknown, List } from "../utils/generics.js";
6
+ import { objectKindOf } from "../utils/objectKinds.js";
6
7
  import type { Path } from "../utils/paths.js";
7
8
  import type { inferRecord } from "./record.js";
8
9
  import type { inferString, validateString } from "./string/string.js";
@@ -13,7 +14,7 @@ export type ParseContext = {
13
14
  };
14
15
  export declare const parseDefinition: (def: unknown, ctx: ParseContext) => TypeNode;
15
16
  export type inferDefinition<def, $> = isAny<def> extends true ? never : def extends inferred<infer t> ? t : def extends string ? inferString<def, $> : def extends List ? inferTuple<def, $> : def extends RegExp ? string : def extends Dict ? inferRecord<def, $> : never;
16
- export type validateDefinition<def, $> = def extends Terminal ? def : def extends string ? validateString<def, $> : def extends TupleExpression ? validateTupleExpression<def, $> : def extends BadDefinitionType ? writeBadDefinitionTypeMessage<subdomainOf<def>> : isUnknown<def> extends true ? unknownDefinitionMessage : evaluateObject<{
17
+ export type validateDefinition<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 : evaluateObject<{
17
18
  [k in keyof def]: validateDefinition<def[k], $>;
18
19
  }>;
19
20
  export declare const as: unique symbol;
@@ -24,6 +25,6 @@ export declare const unknownDefinitionMessage = "Cannot statically parse a defin
24
25
  export type unknownDefinitionMessage = typeof unknownDefinitionMessage;
25
26
  type Terminal = RegExp | inferred<unknown>;
26
27
  type BadDefinitionType = Exclude<Primitive, string> | Function;
27
- export declare const writeBadDefinitionTypeMessage: <actual extends Subdomain>(actual: actual) => `Type definitions must be strings or objects (was ${actual})`;
28
- type writeBadDefinitionTypeMessage<actual extends Subdomain> = `Type definitions must be strings or objects (was ${actual})`;
28
+ export declare const writeBadDefinitionTypeMessage: <actual extends string>(actual: actual) => `Type definitions must be strings or objects (was ${actual})`;
29
+ type writeBadDefinitionTypeMessage<actual extends string> = `Type definitions must be strings or objects (was ${actual})`;
29
30
  export {};
@@ -1,8 +1,10 @@
1
1
  import type { asIn, resolve } from "../../main.js";
2
2
  import type { DisjointsByPath } from "../../nodes/compose.js";
3
- import type { SizedData, subdomainOf } from "../../utils/domains.js";
3
+ import type { domainOf } from "../../utils/domains.js";
4
4
  import type { asConst, castOnError, Dict, equals, error, evaluate, evaluateObject, extractValues, isAny, List, Literalable, RegexLiteral, requiredKeyOf, stringKeyOf, tryCatch } from "../../utils/generics.js";
5
+ import type { objectKindOf } from "../../utils/objectKinds.js";
5
6
  import type { Path, pathToString } from "../../utils/paths.js";
7
+ import type { SizedData } from "../../utils/size.js";
6
8
  import type { Out, ParsedMorph } from "../tuple/morph.js";
7
9
  import type { StringLiteral } from "./shift/operand/enclosed.js";
8
10
  import type { Scanner } from "./shift/scanner.js";
@@ -19,7 +21,7 @@ type inferIntersectionRecurse<l, r, path extends string[]> = path["length"] exte
19
21
  type bubblePropErrors<o> = extractValues<o, error> extends never ? o : extractValues<o, error>;
20
22
  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;
21
23
  type discriminatable<l, r> = discriminatableRecurse<l, r, []> extends never ? false : true;
22
- type discriminatableRecurse<l, r, path extends string[]> = path["length"] extends 10 ? never : l & r extends never ? path : subdomainOf<l> & subdomainOf<r> extends never ? path : [subdomainOf<l>, subdomainOf<r>] extends ["object", "object"] ? extractValues<{
24
+ type discriminatableRecurse<l, r, path extends string[]> = path["length"] extends 10 ? never : l & r extends never ? path : domainOf<l> & domainOf<r> extends never ? path : objectKindOf<l> & objectKindOf<r> extends never ? path : [objectKindOf<l>, objectKindOf<r>] extends ["Object", "Object"] ? extractValues<{
23
25
  [k in requiredKeyOf<l>]: k extends requiredKeyOf<r> ? discriminatableRecurse<l[k], r[k], [...path, k & string]> : never;
24
26
  }, string[]> : never;
25
27
  export declare const compileDisjointReasonsMessage: (disjoints: DisjointsByPath) => string;
@@ -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 ">": "<";
@@ -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";
@@ -1,7 +1,9 @@
1
1
  import type { FlatBound } from "../nodes/rules/range.js";
2
- import type { Subdomain } from "../utils/domains.js";
3
- import { domainOf, subdomainOf } from "../utils/domains.js";
2
+ import type { Domain } from "../utils/domains.js";
3
+ import { domainOf } from "../utils/domains.js";
4
4
  import type { constructor, evaluate, evaluateObject, instanceOf } from "../utils/generics.js";
5
+ import type { DefaultObjectKind } from "../utils/objectKinds.js";
6
+ import { objectKindOf } from "../utils/objectKinds.js";
5
7
  import { Path } from "../utils/paths.js";
6
8
  import type { ConstrainedRuleTraversalData, TraversalState } from "./traverse.js";
7
9
  export declare class ArkTypeError extends TypeError {
@@ -34,31 +36,14 @@ export declare const Problems: new (state: TraversalState) => readonly Problem[]
34
36
  [k in Exclude<keyof ProblemArray, keyof unknown[]>]: ProblemArray[k];
35
37
  };
36
38
  export type Problems = instanceOf<typeof Problems>;
37
- export declare const describeSubdomains: (subdomains: Subdomain[]) => string;
39
+ export declare const describeDomains: (domains: Domain[]) => string;
38
40
  export declare const describeBranches: (descriptions: string[]) => string;
39
- /** Each Subdomain's completion for the phrase "Must be _____" */
40
- export declare const subdomainDescriptions: {
41
- readonly bigint: "a bigint";
42
- readonly boolean: "boolean";
43
- readonly null: "null";
44
- readonly number: "a number";
45
- readonly object: "an object";
46
- readonly string: "a string";
47
- readonly symbol: "a symbol";
48
- readonly undefined: "undefined";
49
- readonly Array: "an array";
50
- readonly Function: "a function";
51
- readonly Date: "a Date";
52
- readonly RegExp: "a RegExp";
53
- readonly Error: "an Error";
54
- readonly Map: "a Map";
55
- readonly Set: "a Set";
56
- };
57
41
  type ProblemRuleInputs = {
58
42
  divisor: number;
59
43
  class: constructor;
60
- domain: Subdomain;
61
- domainBranches: Subdomain[];
44
+ domain: Domain;
45
+ domainBranches: Domain[];
46
+ objectKind: DefaultObjectKind;
62
47
  missing: undefined;
63
48
  bound: FlatBound;
64
49
  regex: RegExp;
@@ -89,25 +74,24 @@ export declare class DataWrapper<value = unknown> {
89
74
  constructor(value: value);
90
75
  toString(): string;
91
76
  get domain(): domainOf<value>;
92
- get subdomain(): subdomainOf<value>;
77
+ get objectKind(): "non-object" | NonNullable<objectKindOf<value, {
78
+ Array: ArrayConstructor;
79
+ Date: DateConstructor;
80
+ Error: ErrorConstructor;
81
+ Function: FunctionConstructor;
82
+ Map: MapConstructor;
83
+ RegExp: RegExpConstructor;
84
+ Set: SetConstructor;
85
+ Object: ObjectConstructor;
86
+ String: StringConstructor;
87
+ Number: NumberConstructor;
88
+ Boolean: BooleanConstructor;
89
+ WeakMap: WeakMapConstructor;
90
+ WeakSet: WeakSetConstructor;
91
+ Promise: PromiseConstructor;
92
+ }>>;
93
93
  get size(): number;
94
- get units(): "" | NonNullable<{
95
- string?: string;
96
- number?: string;
97
- bigint?: string;
98
- boolean?: string;
99
- symbol?: string;
100
- undefined?: string;
101
- object?: string;
102
- null?: string;
103
- Array?: string;
104
- Date?: string;
105
- Error?: string;
106
- Function?: string;
107
- Map?: string;
108
- RegExp?: string;
109
- Set?: string;
110
- }[subdomainOf<value>]>;
94
+ get units(): "" | "characters" | "items";
111
95
  get className(): any;
112
96
  }
113
97
  export declare const defaultProblemWriters: ProblemsConfig;
@@ -1,8 +1,8 @@
1
1
  import type { Type } from "../main.js";
2
2
  import type { TraversalEntry, TraversalKey, TraversalNode } from "../nodes/node.js";
3
- import type { SizedData, Subdomain } from "../utils/domains.js";
4
3
  import type { Dict, extend, List } from "../utils/generics.js";
5
4
  import { Path } from "../utils/paths.js";
5
+ import type { SizedData } from "../utils/size.js";
6
6
  import type { Problem } from "./problems.js";
7
7
  export declare class TraversalState {
8
8
  #private;
@@ -13,8 +13,27 @@ export declare class TraversalState {
13
13
  add: <code extends keyof {
14
14
  divisor: number;
15
15
  class: import("../utils/generics.js").constructor;
16
- domain: Subdomain;
17
- domainBranches: Subdomain[];
16
+ domain: keyof {
17
+ bigint: bigint;
18
+ boolean: boolean;
19
+ number: number;
20
+ object: object;
21
+ string: string;
22
+ symbol: symbol;
23
+ undefined: undefined;
24
+ null: null;
25
+ };
26
+ domainBranches: (keyof {
27
+ bigint: bigint;
28
+ boolean: boolean;
29
+ number: number;
30
+ object: object;
31
+ string: string;
32
+ symbol: symbol;
33
+ undefined: undefined;
34
+ null: null;
35
+ })[];
36
+ objectKind: "Array" | "Date" | "Error" | "Function" | "Map" | "RegExp" | "Set" | "Object" | "String" | "Number" | "Boolean" | "WeakMap" | "WeakSet" | "Promise";
18
37
  missing: undefined;
19
38
  bound: import("../nodes/rules/range.js").FlatBound;
20
39
  regex: RegExp;
@@ -33,7 +52,7 @@ export declare class TraversalState {
33
52
  }
34
53
  export declare const traverse: (data: unknown, node: TraversalNode, state: TraversalState) => unknown;
35
54
  export declare const checkEntries: (data: unknown, entries: List<TraversalEntry>, state: TraversalState) => unknown;
36
- export declare const checkSubdomain: TraversalCheck<"subdomain">;
55
+ export declare const checkObjectKind: TraversalCheck<"objectKind">;
37
56
  export type TraversalCheck<k extends TraversalKey> = (data: RuleData<k>, rule: Extract<TraversalEntry, [k, unknown]>[1], state: TraversalState) => void;
38
57
  export type ConstrainedRuleTraversalData = extend<{
39
58
  [k in TraversalKey]?: unknown;
@@ -43,6 +62,7 @@ export type ConstrainedRuleTraversalData = extend<{
43
62
  bound: SizedData;
44
63
  requiredProps: Dict;
45
64
  optionalProps: Dict;
65
+ objectKind: object;
46
66
  class: object;
47
67
  }>;
48
68
  export type RuleData<k extends TraversalKey> = k extends keyof ConstrainedRuleTraversalData ? ConstrainedRuleTraversalData[k] : unknown;
@@ -1,4 +1,4 @@
1
- import type { Dict, evaluate, isTopType, List } from "./generics.js";
1
+ import type { evaluate, isTopType } from "./generics.js";
2
2
  export declare const hasDomain: <data, domain extends keyof DomainTypes>(data: data, domain: domain) => data is data & inferDomain<domain>;
3
3
  type DomainTypes = {
4
4
  bigint: bigint;
@@ -18,41 +18,15 @@ export type PrimitiveDomain = Exclude<Domain, "object">;
18
18
  export type Primitive = inferDomain<PrimitiveDomain>;
19
19
  export type domainOf<data> = isTopType<data> extends true ? Domain : data extends object ? "object" : data extends string ? "string" : data extends number ? "number" : data extends boolean ? "boolean" : data extends undefined ? "undefined" : data extends null ? "null" : data extends bigint ? "bigint" : data extends symbol ? "symbol" : never;
20
20
  export declare const domainOf: <data>(data: data) => domainOf<data>;
21
- export type ObjectSubdomains = {
22
- Array: readonly unknown[];
23
- Date: Date;
24
- Error: Error;
25
- Function: Function;
26
- Map: Map<unknown, unknown>;
27
- RegExp: RegExp;
28
- Set: Set<unknown>;
29
- object: Dict;
21
+ /** Each domain's completion for the phrase "Must be _____" */
22
+ export declare const domainDescriptions: {
23
+ readonly bigint: "a bigint";
24
+ readonly boolean: "boolean";
25
+ readonly null: "null";
26
+ readonly number: "a number";
27
+ readonly object: "an object";
28
+ readonly string: "a string";
29
+ readonly symbol: "a symbol";
30
+ readonly undefined: "undefined";
30
31
  };
31
- export type ObjectSubdomain = keyof ObjectSubdomains;
32
- export type Subdomain<domain extends Domain = Domain> = domain | (domain extends "object" ? ObjectSubdomain : never);
33
- export type subdomainOf<data> = isTopType<data> extends true ? Subdomain : data extends object ? object extends data ? ObjectSubdomain : data extends List ? "Array" : data extends Date ? "Date" : data extends Error ? "Error" : data extends Function ? "Function" : data extends Map<unknown, unknown> ? "Map" : data extends RegExp ? "RegExp" : data extends Set<unknown> ? "Set" : "object" : domainOf<data>;
34
- export declare const subdomainOf: <data>(data: data) => subdomainOf<data>;
35
- export type inferSubdomain<subdomain extends Subdomain> = subdomain extends ObjectSubdomain ? ObjectSubdomains[subdomain] : subdomain extends Domain ? DomainTypes[subdomain] : never;
36
- export declare const hasSubdomain: <subdomain extends Subdomain<keyof DomainTypes>>(data: unknown, subdomain: subdomain) => data is inferSubdomain<subdomain>;
37
- export declare const sizeOf: <data>(data: data) => number;
38
- export declare const unitsOf: <data>(data: data) => "" | NonNullable<{
39
- string?: string;
40
- number?: string;
41
- bigint?: string;
42
- boolean?: string;
43
- symbol?: string;
44
- undefined?: string;
45
- object?: string;
46
- null?: string;
47
- Array?: string;
48
- Date?: string;
49
- Error?: string;
50
- Function?: string;
51
- Map?: string;
52
- RegExp?: string;
53
- Set?: string;
54
- }[subdomainOf<data>]>;
55
- export type SizedSubdomain = "number" | "string" | "Array";
56
- export type SizedData = inferSubdomain<SizedSubdomain>;
57
- export declare const classNameOf: <data>(data: data) => any;
58
32
  export {};
@@ -104,7 +104,6 @@ export type NonEmptyList<t = unknown> = readonly [t, ...t[]];
104
104
  export type HomogenousTuple<item, length extends number, result extends item[] = []> = result["length"] extends length ? result : HomogenousTuple<item, length, [...result, item]>;
105
105
  export declare const listFrom: <t>(data: t) => t extends List<unknown> ? t : readonly t[];
106
106
  export type CollapsibleList<t> = t | readonly t[];
107
- export declare const collapseIfSingleton: <t extends List<unknown>>(array: t) => t | t[number];
108
107
  /** Either:
109
108
  * A, with all properties of B undefined
110
109
  * OR
@@ -0,0 +1,83 @@
1
+ import type { constructor, instanceOf, isTopType } from "./generics.js";
2
+ declare const defaultObjectKinds: {
3
+ Array: ArrayConstructor;
4
+ Date: DateConstructor;
5
+ Error: ErrorConstructor;
6
+ Function: FunctionConstructor;
7
+ Map: MapConstructor;
8
+ RegExp: RegExpConstructor;
9
+ Set: SetConstructor;
10
+ Object: ObjectConstructor;
11
+ String: StringConstructor;
12
+ Number: NumberConstructor;
13
+ Boolean: BooleanConstructor;
14
+ WeakMap: WeakMapConstructor;
15
+ WeakSet: WeakSetConstructor;
16
+ Promise: PromiseConstructor;
17
+ };
18
+ export type InferredObjectKinds = {
19
+ [kind in DefaultObjectKind]: inferObjectKind<kind>;
20
+ };
21
+ export type inferObjectKind<kind extends keyof kinds, kinds extends ObjectKindSet = DefaultObjectKindSet> = kind extends "Function" ? (...args: any[]) => unknown : kind extends "Object" ? Record<string, unknown> : instanceOf<kinds[kind]>;
22
+ export type BuiltinClassName = Exclude<DefaultObjectKind, "Object" | "Function" | "Array">;
23
+ type BuiltinClassesByName = {
24
+ [kind in BuiltinClassName]: instanceOf<DefaultObjectKindSet[kind]>;
25
+ };
26
+ export type BuiltinClass = BuiltinClassesByName[BuiltinClassName];
27
+ export type ObjectKindSet = Record<string, constructor>;
28
+ export type DefaultObjectKindSet = typeof defaultObjectKinds;
29
+ export type DefaultObjectKind = keyof DefaultObjectKindSet;
30
+ export type objectKindOf<data, kinds extends ObjectKindSet = DefaultObjectKindSet> = isTopType<data> extends true ? undefined | keyof kinds : data extends object ? object extends data ? keyof kinds : {
31
+ [kind in keyof kinds]: kinds[kind] extends constructor<data> ? kind : data extends (...args: any[]) => unknown ? "Function" : "Object";
32
+ }[keyof kinds] : undefined;
33
+ export declare const objectKindOf: <data, kinds extends ObjectKindSet = {
34
+ Array: ArrayConstructor;
35
+ Date: DateConstructor;
36
+ Error: ErrorConstructor;
37
+ Function: FunctionConstructor;
38
+ Map: MapConstructor;
39
+ RegExp: RegExpConstructor;
40
+ Set: SetConstructor;
41
+ Object: ObjectConstructor;
42
+ String: StringConstructor;
43
+ Number: NumberConstructor;
44
+ Boolean: BooleanConstructor;
45
+ WeakMap: WeakMapConstructor;
46
+ WeakSet: WeakSetConstructor;
47
+ Promise: PromiseConstructor;
48
+ }>(data: data, kinds?: kinds | undefined) => objectKindOf<data, kinds> | undefined;
49
+ export declare const hasObjectKind: <kind extends keyof kinds, kinds extends ObjectKindSet = {
50
+ Array: ArrayConstructor;
51
+ Date: DateConstructor;
52
+ Error: ErrorConstructor;
53
+ Function: FunctionConstructor;
54
+ Map: MapConstructor;
55
+ RegExp: RegExpConstructor;
56
+ Set: SetConstructor;
57
+ Object: ObjectConstructor;
58
+ String: StringConstructor;
59
+ Number: NumberConstructor;
60
+ Boolean: BooleanConstructor;
61
+ WeakMap: WeakMapConstructor;
62
+ WeakSet: WeakSetConstructor;
63
+ Promise: PromiseConstructor;
64
+ }>(data: unknown, kind: kind, kinds?: kinds | undefined) => data is inferObjectKind<kind, kinds>;
65
+ export declare const isArray: <data>(data: data) => data is Extract<data, readonly unknown[]>;
66
+ /** Each defaultObjectKind's completion for the phrase "Must be _____" */
67
+ export declare const objectKindDescriptions: {
68
+ readonly Object: "an object";
69
+ readonly Array: "an array";
70
+ readonly Function: "a function";
71
+ readonly Date: "a Date";
72
+ readonly RegExp: "a RegExp";
73
+ readonly Error: "an Error";
74
+ readonly Map: "a Map";
75
+ readonly Set: "a Set";
76
+ readonly String: "a String object";
77
+ readonly Number: "a Number object";
78
+ readonly Boolean: "a Boolean object";
79
+ readonly Promise: "a Promise";
80
+ readonly WeakMap: "a WeakMap";
81
+ readonly WeakSet: "a WeakSet";
82
+ };
83
+ export {};
@@ -11,8 +11,8 @@ export type snapshot<t, depth extends 1[] = []> = isTopType<t> extends true ? un
11
11
  [k in keyof t]: snapshot<t[k], [...depth, 1]>;
12
12
  };
13
13
  type snapshotPrimitive<t> = t extends undefined ? "(undefined)" : t extends bigint ? `${t}n` : t extends symbol ? `(symbol${string})` : t;
14
- export declare const serialize: (data: unknown, opts?: SerializationOptions) => string;
15
- export declare const stringify: (data: unknown) => string;
14
+ export declare const serialize: (data: unknown, opts?: SerializationOptions, indent?: number) => string;
15
+ export declare const stringify: (data: unknown, indent?: number) => string;
16
16
  type SerializedString = `'${string}'`;
17
17
  export type SerializedPrimitives = {
18
18
  string: SerializedString;
@@ -0,0 +1,3 @@
1
+ export type SizedData = string | number | readonly unknown[];
2
+ export declare const sizeOf: (data: unknown) => number;
3
+ export declare const unitsOf: (data: unknown) => "" | "characters" | "items";
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "arktype",
3
3
  "description": "Isomorphic type syntax for TS/JS",
4
- "version": "0.1.1",
4
+ "version": "0.1.3",
5
5
  "author": {
6
6
  "name": "David Blass",
7
7
  "email": "david@arktype.io",
@@ -19,12 +19,17 @@
19
19
  "types": "./dist/api.d.ts",
20
20
  "import": "./dist/api.mjs",
21
21
  "require": "./dist/api.cjs"
22
+ },
23
+ "./internal/*": {
24
+ "types": "./dist/types/*",
25
+ "import": "./dist/mjs/*",
26
+ "require": "./dist/cjs/*"
22
27
  }
23
28
  },
24
- "packageManager": "pnpm@7.18.0",
25
29
  "files": [
26
30
  "dist"
27
31
  ],
32
+ "packageManager": "pnpm@7.18.0",
28
33
  "devDependencies": {
29
34
  "@changesets/cli": "2.26.0",
30
35
  "@swc/cli": "0.1.59",
@@ -78,11 +83,11 @@
78
83
  },
79
84
  "scripts": {
80
85
  "//temporarily disabled pr checks": "pnpm testRepo",
81
- "prChecks": "pnpm install && pnpm build && pnpm typecheck && pnpm lint && pnpm test && pnpm buildDocs",
86
+ "prChecks": "pnpm install && pnpm build && pnpm typecheck && pnpm lint && pnpm test && pnpm docgen && pnpm buildSite",
82
87
  "typecheck": "tsc --noEmit",
83
88
  "build": "ts-node ./dev/scripts/build.ts",
84
- "buildRepo": "pnpm build && pnpm buildDocs",
85
- "buildDocs": "pnpm docgen && cd dev/arktype.io && pnpm install && pnpm build",
89
+ "buildRepo": "pnpm build && pnpm docgen && pnpm buildSite",
90
+ "buildSite": "cd dev/arktype.io && pnpm install && pnpm build",
86
91
  "docgen": "ts-node ./dev/scripts/docgen.ts",
87
92
  "test": "ts-node ./dev/attest/cli.ts --cmd mocha",
88
93
  "testCov": "c8 pnpm test",
@@ -1,78 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", {
3
- value: true
4
- });
5
- function _export(target, all) {
6
- for(var name in all)Object.defineProperty(target, name, {
7
- enumerable: true,
8
- get: all[name]
9
- });
10
- }
11
- _export(exports, {
12
- subdomainIntersection: ()=>subdomainIntersection,
13
- subdomainPathSegments: ()=>subdomainPathSegments,
14
- flattenSubdomain: ()=>flattenSubdomain
15
- });
16
- const _errorsTs = require("../../utils/errors.js");
17
- const _composeTs = require("../compose.js");
18
- const _nodeTs = require("../node.js");
19
- const subdomainIntersection = (0, _composeTs.composeIntersection)((l, r, state)=>{
20
- if (typeof l === "string") {
21
- if (typeof r === "string") {
22
- return l === r ? (0, _composeTs.equality)() : state.addDisjoint("subdomain", l, r);
23
- }
24
- return l === r[0] ? r : state.addDisjoint("subdomain", l, r[0]);
25
- }
26
- if (typeof r === "string") {
27
- return l[0] === r ? l : state.addDisjoint("subdomain", l[0], r);
28
- }
29
- if (l[0] !== r[0]) {
30
- return state.addDisjoint("subdomain", l[0], r[0]);
31
- }
32
- const result = [
33
- l[0]
34
- ];
35
- let lImpliesR = true;
36
- let rImpliesL = true;
37
- for(let i = 1; i < l.length; i++){
38
- const lNode = l[i];
39
- const rNode = r[i];
40
- state.path.push(subdomainParameterToPathSegment(l[0], i));
41
- const parameterResult = (0, _nodeTs.nodeIntersection)(lNode, rNode, state);
42
- state.path.pop();
43
- if ((0, _composeTs.isEquality)(parameterResult)) {
44
- result[i] = lNode;
45
- } else if (parameterResult === l) {
46
- result[i] = lNode;
47
- rImpliesL = false;
48
- } else if (parameterResult === r) {
49
- result[i] = rNode;
50
- lImpliesR = false;
51
- } else if ((0, _composeTs.isDisjoint)(parameterResult)) {
52
- return parameterResult;
53
- } else {
54
- result[i] = parameterResult;
55
- lImpliesR = false;
56
- rImpliesL = false;
57
- }
58
- }
59
- return lImpliesR ? rImpliesL ? (0, _composeTs.equality)() : l : rImpliesL ? r : result;
60
- });
61
- const subdomainParameterToPathSegment = (subdomain, i)=>subdomain === "Array" ? "${number}" : subdomain === "Set" ? "${item}" : subdomain === "Map" ? i === 1 ? "${key}" : "${value}" : (0, _errorsTs.throwInternalError)(`Unexpected parameterized subdomain '${subdomain}'`);
62
- const subdomainPathSegments = {
63
- "${number}": true,
64
- "${item}": true,
65
- "${key}": true,
66
- "${value}": true
67
- };
68
- const flattenSubdomain = (entries, rule, ctx)=>entries.push([
69
- "subdomain",
70
- typeof rule === "string" ? rule : rule[0] === "Map" ? [
71
- rule[0],
72
- (0, _nodeTs.flattenNode)(rule[1], ctx),
73
- (0, _nodeTs.flattenNode)(rule[2], ctx)
74
- ] : [
75
- rule[0],
76
- (0, _nodeTs.flattenNode)(rule[1], ctx)
77
- ]
78
- ]);
@@ -1,15 +0,0 @@
1
- import type { Subdomain } from "../../utils/domains.js";
2
- import type { Dict } from "../../utils/generics.js";
3
- import type { TraversalNode, TypeNode } from "../node.js";
4
- import type { FlattenAndPushRule } from "./rules.js";
5
- export type SubdomainRule<$ = Dict> = Subdomain | readonly ["Array", TypeNode<$>] | readonly ["Array", TypeNode<$>] | readonly ["Set", TypeNode<$>] | readonly ["Map", TypeNode<$>, TypeNode<$>];
6
- export type TraversalSubdomainRule = Subdomain | readonly ["Array", TraversalNode] | readonly ["Array", TraversalNode] | readonly ["Set", TraversalNode] | readonly ["Map", TraversalNode, TraversalNode];
7
- export declare const subdomainIntersection: import("../compose.js").Intersector<SubdomainRule<Dict> | undefined>;
8
- export declare const subdomainPathSegments: {
9
- readonly "${number}": true;
10
- readonly "${item}": true;
11
- readonly "${key}": true;
12
- readonly "${value}": true;
13
- };
14
- export type SubdomainPathSegment = keyof typeof subdomainPathSegments;
15
- export declare const flattenSubdomain: FlattenAndPushRule<SubdomainRule>;