arktype 0.6.0 → 1.0.1-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 (82) hide show
  1. package/README.md +4 -2
  2. package/dist/api.cjs +2 -2
  3. package/dist/api.d.ts +2 -1
  4. package/dist/api.mjs +1 -1
  5. package/dist/cjs/nodes/compose.js +4 -4
  6. package/dist/cjs/nodes/discriminate.js +1 -1
  7. package/dist/cjs/nodes/node.js +30 -22
  8. package/dist/cjs/nodes/predicate.js +0 -1
  9. package/dist/cjs/nodes/rules/range.js +3 -3
  10. package/dist/cjs/parse/ast/config.js +4 -6
  11. package/dist/cjs/parse/ast/distributableFunction.js +6 -6
  12. package/dist/cjs/parse/ast/intersection.js +2 -2
  13. package/dist/cjs/parse/ast/keyof.js +3 -3
  14. package/dist/cjs/parse/ast/morph.js +2 -1
  15. package/dist/cjs/parse/ast/narrow.js +8 -1
  16. package/dist/cjs/parse/definition.js +2 -2
  17. package/dist/cjs/parse/string/reduce/dynamic.js +1 -1
  18. package/dist/cjs/parse/string/shift/operand/unenclosed.js +1 -1
  19. package/dist/cjs/parse/string/shift/scanner.js +1 -1
  20. package/dist/cjs/parse/string/string.js +2 -2
  21. package/dist/cjs/scopes/ark.js +6 -6
  22. package/dist/cjs/scopes/scope.js +47 -59
  23. package/dist/cjs/scopes/type.js +19 -14
  24. package/dist/cjs/scopes/validation/date.js +2 -3
  25. package/dist/cjs/scopes/validation/validation.js +14 -0
  26. package/dist/cjs/traverse/problems.js +3 -3
  27. package/dist/cjs/traverse/traverse.js +21 -3
  28. package/dist/cjs/utils/data.js +1 -1
  29. package/dist/cjs/utils/generics.js +16 -0
  30. package/dist/cjs/utils/serialize.js +29 -53
  31. package/dist/mjs/nodes/compose.js +5 -5
  32. package/dist/mjs/nodes/discriminate.js +1 -1
  33. package/dist/mjs/nodes/node.js +28 -22
  34. package/dist/mjs/nodes/predicate.js +0 -1
  35. package/dist/mjs/nodes/rules/range.js +3 -3
  36. package/dist/mjs/parse/ast/config.js +4 -6
  37. package/dist/mjs/parse/ast/distributableFunction.js +6 -6
  38. package/dist/mjs/parse/ast/intersection.js +2 -2
  39. package/dist/mjs/parse/ast/keyof.js +3 -3
  40. package/dist/mjs/parse/ast/morph.js +2 -1
  41. package/dist/mjs/parse/ast/narrow.js +9 -2
  42. package/dist/mjs/parse/definition.js +2 -2
  43. package/dist/mjs/parse/string/reduce/dynamic.js +1 -1
  44. package/dist/mjs/parse/string/shift/operand/unenclosed.js +1 -1
  45. package/dist/mjs/parse/string/shift/scanner.js +1 -1
  46. package/dist/mjs/parse/string/string.js +2 -2
  47. package/dist/mjs/scopes/ark.js +5 -5
  48. package/dist/mjs/scopes/scope.js +48 -60
  49. package/dist/mjs/scopes/type.js +16 -13
  50. package/dist/mjs/scopes/validation/date.js +2 -3
  51. package/dist/mjs/scopes/validation/validation.js +14 -0
  52. package/dist/mjs/traverse/problems.js +3 -3
  53. package/dist/mjs/traverse/traverse.js +21 -3
  54. package/dist/mjs/utils/data.js +1 -1
  55. package/dist/mjs/utils/generics.js +11 -0
  56. package/dist/mjs/utils/serialize.js +29 -52
  57. package/dist/tsconfig.temp.tsbuildinfo +1 -1
  58. package/dist/types/nodes/branch.d.ts +5 -3
  59. package/dist/types/nodes/node.d.ts +15 -8
  60. package/dist/types/nodes/predicate.d.ts +3 -3
  61. package/dist/types/nodes/rules/props.d.ts +8 -8
  62. package/dist/types/parse/ast/distributableFunction.d.ts +1 -1
  63. package/dist/types/parse/ast/intersection.d.ts +2 -2
  64. package/dist/types/parse/ast/morph.d.ts +3 -5
  65. package/dist/types/parse/ast/node.d.ts +6 -7
  66. package/dist/types/parse/ast/tuple.d.ts +4 -4
  67. package/dist/types/parse/definition.d.ts +2 -2
  68. package/dist/types/parse/string/reduce/dynamic.d.ts +5 -5
  69. package/dist/types/parse/string/shift/scanner.d.ts +1 -1
  70. package/dist/types/parse/string/string.d.ts +3 -3
  71. package/dist/types/scopes/ark.d.ts +28 -103
  72. package/dist/types/scopes/expressions.d.ts +9 -9
  73. package/dist/types/scopes/scope.d.ts +11 -10
  74. package/dist/types/scopes/type.d.ts +23 -14
  75. package/dist/types/scopes/validation/date.d.ts +1 -1
  76. package/dist/types/scopes/validation/validation.d.ts +10 -6
  77. package/dist/types/traverse/problems.d.ts +3 -3
  78. package/dist/types/traverse/traverse.d.ts +8 -68
  79. package/dist/types/utils/data.d.ts +2 -2
  80. package/dist/types/utils/generics.d.ts +5 -0
  81. package/dist/types/utils/serialize.d.ts +0 -1
  82. package/package.json +15 -15
@@ -1,8 +1,7 @@
1
- import type { Out } from "../parse/ast/morph.js";
2
1
  import type { InferredObjectKinds } from "../utils/objectKinds.js";
3
2
  import type { Space } from "./scope.js";
4
3
  import type { TypeParser } from "./type.js";
5
- export declare const ark: import("./scope.js").Scope<[{
4
+ export declare const arkscope: import("./scope.js").Scope<[{
6
5
  any: any;
7
6
  bigint: bigint;
8
7
  boolean: boolean;
@@ -40,54 +39,14 @@ export declare const ark: import("./scope.js").Scope<[{
40
39
  creditCard: string;
41
40
  email: string;
42
41
  uuid: string;
43
- parsedNumber: (In: string) => Out<number>;
44
- parsedInteger: (In: string) => Out<number>;
45
- parsedDate: (In: string) => Out<Date>;
42
+ parsedNumber: (In: string) => number;
43
+ parsedInteger: (In: string) => number;
44
+ parsedDate: (In: string) => Date;
45
+ semver: string;
46
+ json: (In: string) => unknown;
46
47
  integer: number;
47
48
  }, {}, false]>;
48
- export declare const arktypes: Space<{
49
- any: any;
50
- bigint: bigint;
51
- boolean: boolean;
52
- false: false;
53
- never: never;
54
- null: null;
55
- number: number;
56
- object: object;
57
- string: string;
58
- symbol: symbol;
59
- true: true;
60
- unknown: unknown;
61
- void: void;
62
- undefined: undefined;
63
- Function: (...args: any[]) => unknown;
64
- Array: unknown[];
65
- Date: Date;
66
- Error: Error;
67
- Map: Map<unknown, unknown>;
68
- RegExp: RegExp;
69
- Set: Set<unknown>;
70
- Object: {
71
- [x: string]: unknown;
72
- };
73
- String: String;
74
- Number: Number;
75
- Boolean: Boolean;
76
- WeakMap: WeakMap<object, unknown>;
77
- WeakSet: WeakSet<object>;
78
- Promise: Promise<unknown>;
79
- alpha: string;
80
- alphanumeric: string;
81
- lowercase: string;
82
- uppercase: string;
83
- creditCard: string;
84
- email: string;
85
- uuid: string;
86
- parsedNumber: (In: string) => Out<number>;
87
- parsedInteger: (In: string) => Out<number>;
88
- parsedDate: (In: string) => Out<Date>;
89
- integer: number;
90
- }>;
49
+ export declare const ark: Space<PrecompiledDefaults>;
91
50
  export declare const scopes: {
92
51
  root: import("./scope.js").Scope<[{}, {}, false]>;
93
52
  tsKeywords: import("./scope.js").Scope<[{
@@ -132,9 +91,11 @@ export declare const scopes: {
132
91
  creditCard: string;
133
92
  email: string;
134
93
  uuid: string;
135
- parsedNumber: (In: string) => Out<number>;
136
- parsedInteger: (In: string) => Out<number>;
137
- parsedDate: (In: string) => Out<Date>;
94
+ parsedNumber: (In: string) => number;
95
+ parsedInteger: (In: string) => number;
96
+ parsedDate: (In: string) => Date;
97
+ semver: string;
98
+ json: (In: string) => unknown;
138
99
  integer: number;
139
100
  }, {}, false]>;
140
101
  ark: import("./scope.js").Scope<[{
@@ -175,9 +136,11 @@ export declare const scopes: {
175
136
  creditCard: string;
176
137
  email: string;
177
138
  uuid: string;
178
- parsedNumber: (In: string) => Out<number>;
179
- parsedInteger: (In: string) => Out<number>;
180
- parsedDate: (In: string) => Out<Date>;
139
+ parsedNumber: (In: string) => number;
140
+ parsedInteger: (In: string) => number;
141
+ parsedDate: (In: string) => Date;
142
+ semver: string;
143
+ json: (In: string) => unknown;
181
144
  integer: number;
182
145
  }, {}, false]>;
183
146
  };
@@ -224,54 +187,14 @@ export declare const spaces: {
224
187
  creditCard: string;
225
188
  email: string;
226
189
  uuid: string;
227
- parsedNumber: (In: string) => Out<number>;
228
- parsedInteger: (In: string) => Out<number>;
229
- parsedDate: (In: string) => Out<Date>;
230
- integer: number;
231
- }>;
232
- ark: Space<{
233
- any: any;
234
- bigint: bigint;
235
- boolean: boolean;
236
- false: false;
237
- never: never;
238
- null: null;
239
- number: number;
240
- object: object;
241
- string: string;
242
- symbol: symbol;
243
- true: true;
244
- unknown: unknown;
245
- void: void;
246
- undefined: undefined;
247
- Function: (...args: any[]) => unknown;
248
- Array: unknown[];
249
- Date: Date;
250
- Error: Error;
251
- Map: Map<unknown, unknown>;
252
- RegExp: RegExp;
253
- Set: Set<unknown>;
254
- Object: {
255
- [x: string]: unknown;
256
- };
257
- String: String;
258
- Number: Number;
259
- Boolean: Boolean;
260
- WeakMap: WeakMap<object, unknown>;
261
- WeakSet: WeakSet<object>;
262
- Promise: Promise<unknown>;
263
- alpha: string;
264
- alphanumeric: string;
265
- lowercase: string;
266
- uppercase: string;
267
- creditCard: string;
268
- email: string;
269
- uuid: string;
270
- parsedNumber: (In: string) => Out<number>;
271
- parsedInteger: (In: string) => Out<number>;
272
- parsedDate: (In: string) => Out<Date>;
190
+ parsedNumber: (In: string) => number;
191
+ parsedInteger: (In: string) => number;
192
+ parsedDate: (In: string) => Date;
193
+ semver: string;
194
+ json: (In: string) => unknown;
273
195
  integer: number;
274
196
  }>;
197
+ ark: Space<PrecompiledDefaults>;
275
198
  };
276
199
  export type PrecompiledDefaults = {
277
200
  any: any;
@@ -296,8 +219,10 @@ export type PrecompiledDefaults = {
296
219
  creditCard: string;
297
220
  email: string;
298
221
  uuid: string;
299
- parsedNumber: (In: string) => Out<number>;
300
- parsedInteger: (In: string) => Out<number>;
301
- parsedDate: (In: string) => Out<Date>;
222
+ semver: string;
223
+ json: (In: string) => unknown;
224
+ parsedNumber: (In: string) => number;
225
+ parsedInteger: (In: string) => number;
226
+ parsedDate: (In: string) => Date;
302
227
  } & InferredObjectKinds;
303
228
  export declare const type: TypeParser<PrecompiledDefaults>;
@@ -17,15 +17,15 @@ export type Expressions<$> = {
17
17
  narrow: FunctionalExpressionParser<$, "=>">;
18
18
  morph: FunctionalExpressionParser<$, "|>">;
19
19
  };
20
- type Standard = Expressions<PrecompiledDefaults>;
21
- export declare const intersection: Standard["intersection"];
22
- export declare const union: Standard["union"];
23
- export declare const arrayOf: Standard["arrayOf"];
24
- export declare const keyOf: Standard["keyOf"];
25
- export declare const instanceOf: Standard["instanceOf"];
26
- export declare const valueOf: Standard["valueOf"];
27
- export declare const narrow: Standard["narrow"];
28
- export declare const morph: Standard["morph"];
20
+ type Ark = Expressions<PrecompiledDefaults>;
21
+ export declare const intersection: Ark["intersection"];
22
+ export declare const union: Ark["union"];
23
+ export declare const arrayOf: Ark["arrayOf"];
24
+ export declare const keyOf: Ark["keyOf"];
25
+ export declare const instanceOf: Ark["instanceOf"];
26
+ export declare const valueOf: Ark["valueOf"];
27
+ export declare const narrow: Ark["narrow"];
28
+ export declare const morph: Ark["morph"];
29
29
  export type BinaryExpressionParser<$, operator extends "&" | "|"> = {
30
30
  <l, r>(l: validateDefinition<l, $>, r: validateDefinition<r, $>): parseTupleExpression<[l, operator, r], $>;
31
31
  <l, r>(l: validateDefinition<l, $>, r: validateDefinition<r, $>, opts: TypeOptions): parseTupleExpression<[l, operator, r], $>;
@@ -1,4 +1,4 @@
1
- import type { ResolvedNode, TypeNode } from "../nodes/node.js";
1
+ import type { Node, ResolvedNode, TypeNode } from "../nodes/node.js";
2
2
  import type { ConfigTuple } from "../parse/ast/config.js";
3
3
  import type { inferDefinition, ParseContext, validateDefinition } from "../parse/definition.js";
4
4
  import type { ProblemsConfig, ProblemWritersByCode } from "../traverse/problems.js";
@@ -7,14 +7,14 @@ import type { stringifyUnion } from "../utils/unionToTuple.js";
7
7
  import type { PrecompiledDefaults } from "./ark.js";
8
8
  import { FreezingCache } from "./cache.js";
9
9
  import type { Expressions } from "./expressions.js";
10
- import type { KeyCheckKind, Type, TypeParser } from "./type.js";
10
+ import type { AnonymousTypeName, KeyCheckKind, QualifiedTypeName, Type, TypeParser } from "./type.js";
11
11
  type ScopeParser = {
12
12
  <aliases>(aliases: validateAliases<aliases, {}>): Scope<parseScope<aliases, {}>>;
13
13
  <aliases, opts extends ScopeOptions>(aliases: validateAliases<aliases, opts>, opts: validateOptions<opts>): Scope<parseScope<aliases, opts>>;
14
14
  };
15
- type validateAliases<aliases, opts extends ScopeOptions> = {
15
+ type validateAliases<aliases, opts extends ScopeOptions> = evaluate<{
16
16
  [name in keyof aliases]: name extends keyof preresolved<opts> ? writeDuplicateAliasesMessage<name & string> : validateDefinition<aliases[name], bootstrapScope<aliases, opts>>;
17
- };
17
+ }>;
18
18
  export type ScopeOptions = {
19
19
  imports?: Space[] | [];
20
20
  includes?: Space[] | [];
@@ -68,15 +68,16 @@ export declare class Scope<context extends ScopeContext = any> {
68
68
  aliases: Dict;
69
69
  name: string;
70
70
  config: ScopeConfig;
71
- parseCache: FreezingCache<TypeNode>;
71
+ parseCache: FreezingCache<Node>;
72
72
  constructor(aliases: Dict, opts?: ScopeOptions);
73
- getAnonymousTypeName(ctx?: ParseContext): string;
74
- addAnonymous(type: Type, ctx: ParseContext): string;
73
+ getAnonymousQualifiedName(base: AnonymousTypeName): QualifiedTypeName;
74
+ addAnonymousTypeReference(referencedType: Type, ctx: ParseContext): Node;
75
75
  get infer(): exportsOf<context>;
76
76
  compile(): Space<exportsOf<context>>;
77
- addReferenceIfResolvable(name: name<context>, ctx: ParseContext): boolean;
77
+ addParsedReferenceIfResolvable(name: name<context>, ctx: ParseContext): boolean;
78
78
  resolve(name: name<context>): Type;
79
- resolveNode(node: TypeNode): ResolvedNode;
79
+ resolveNode(node: Node): ResolvedNode;
80
+ resolveTypeNode(node: Node): TypeNode;
80
81
  expressions: Expressions<resolutions<context>>;
81
82
  intersection: import("./expressions.js").BinaryExpressionParser<resolutions<context>, "&">;
82
83
  union: import("./expressions.js").BinaryExpressionParser<resolutions<context>, "|">;
@@ -87,7 +88,7 @@ export declare class Scope<context extends ScopeContext = any> {
87
88
  narrow: import("./expressions.js").FunctionalExpressionParser<resolutions<context>, "=>">;
88
89
  morph: import("./expressions.js").FunctionalExpressionParser<resolutions<context>, "|>">;
89
90
  type: TypeParser<resolutions<context>>;
90
- isInternallyResolvable(name: string): unknown;
91
+ isResolvable(name: string): unknown;
91
92
  }
92
93
  export declare const scope: ScopeParser;
93
94
  export declare const rootScope: Scope<[{}, {}, false]>;
@@ -1,8 +1,8 @@
1
- import type { TraversalNode, TypeNode } from "../nodes/node.js";
1
+ import type { Node, TraversalNode } from "../nodes/node.js";
2
2
  import type { ParsedMorph } from "../parse/ast/morph.js";
3
3
  import type { as, inferDefinition, validateDefinition } from "../parse/definition.js";
4
4
  import type { ProblemOptions, Problems } from "../traverse/problems.js";
5
- import type { defer, evaluate, xor } from "../utils/generics.js";
5
+ import type { defer, evaluate, nominal, xor } from "../utils/generics.js";
6
6
  import type { BuiltinClass } from "../utils/objectKinds.js";
7
7
  import type { Expressions } from "./expressions.js";
8
8
  import type { Scope } from "./scope.js";
@@ -13,44 +13,53 @@ export type TypeParser<$> = {
13
13
  export type TypeParserProps<$> = {
14
14
  from: Expressions<$>["node"];
15
15
  };
16
- export type parseType<def, $> = [def] extends [validateDefinition<def, $>] ? Type<inferDefinition<def, $>> : never;
16
+ export type parseType<def, $> = [def] extends [validateDefinition<def, $>] ? Type<inferDefinition<def, $>> : Type<never>;
17
17
  type TypeRoot<t = unknown> = evaluate<{
18
18
  [as]: t;
19
19
  infer: asOut<t>;
20
- node: TypeNode;
20
+ allows: (data: unknown) => data is t;
21
+ node: Node;
21
22
  flat: TraversalNode;
22
23
  qualifiedName: QualifiedTypeName;
23
24
  definition: unknown;
24
25
  scope: Scope;
25
26
  includesMorph: boolean;
26
- config: TypeConfig | undefined;
27
+ config: TypeConfig;
27
28
  }>;
28
29
  export type KeyCheckKind = "loose" | "strict" | "distilled";
29
30
  export type TypeOptions = evaluate<{
30
31
  keys?: KeyCheckKind;
31
- name?: string;
32
32
  } & ProblemOptions>;
33
- export type TypeConfig = Omit<TypeOptions, "name">;
34
- export declare const initializeType: (name: string, definition: unknown, config: TypeConfig | undefined, scope: Scope) => Checker<unknown> & {
33
+ export type TypeConfig = TypeOptions;
34
+ export declare const initializeType: (name: string, definition: unknown, config: TypeConfig, scope: Scope) => Checker<unknown> & {
35
35
  infer: unknown;
36
- node: TypeNode;
36
+ allows: (data: unknown) => data is unknown;
37
+ node: Node;
37
38
  flat: TraversalNode;
38
39
  qualifiedName: QualifiedTypeName;
39
40
  definition: unknown;
40
41
  scope: Scope;
41
42
  includesMorph: boolean;
42
- config: TypeConfig | undefined;
43
+ config: {
44
+ keys?: KeyCheckKind;
45
+ mustBe?: import("../traverse/problems.js").MustBeWriter<import("../traverse/problems.js").ProblemCode>;
46
+ writeReason?: import("../traverse/problems.js").ReasonWriter<import("../traverse/problems.js").ProblemCode>;
47
+ addContext?: import("../traverse/problems.js").ContextWriter;
48
+ };
43
49
  [as]: unknown;
44
50
  };
45
51
  export declare const isType: (value: unknown) => value is Type<unknown>;
46
- export type CheckResult<t> = xor<{
47
- data: asOut<t>;
52
+ export type CheckResult<out = unknown> = nominal<xor<{
53
+ data: out;
48
54
  }, {
49
55
  problems: Problems;
50
- }>;
51
- type Checker<t> = (data: unknown) => CheckResult<t>;
56
+ }>, string>;
57
+ export declare const isCheckResult: (value: unknown) => value is CheckResult<unknown>;
58
+ type Checker<t> = (data: unknown) => CheckResult<asOut<t>>;
52
59
  export type Type<t = unknown> = defer<Checker<t> & TypeRoot<t>>;
53
60
  export type QualifiedTypeName = `${string}.${string}`;
61
+ export type AnonymousTypeName = `λ${string}`;
62
+ export declare const isAnonymousName: (name: string) => name is `\u03BB${string}`;
54
63
  export type asIn<t> = asIo<t, "in">;
55
64
  export type asOut<t> = asIo<t, "out">;
56
65
  type asIo<t, io extends "in" | "out"> = t extends ParsedMorph<infer i, infer o> ? io extends "in" ? i : o : t extends object ? t extends BuiltinClass | ((...args: any[]) => any) ? t : {
@@ -19,5 +19,5 @@ export type DateOptions = {
19
19
  format?: DateFormat;
20
20
  };
21
21
  export declare const tryParseDate: (data: string, opts?: DateOptions) => Date | string;
22
- export declare const parsedDate: import("../type.js").Type<(In: string) => import("../../parse/ast/morph.js").Out<Date>>;
22
+ export declare const parsedDate: import("../type.js").Type<(In: string) => Date>;
23
23
  export {};
@@ -6,9 +6,11 @@ export declare const validationScope: import("../scope.js").Scope<[{
6
6
  creditCard: string;
7
7
  email: string;
8
8
  uuid: string;
9
- parsedNumber: (In: string) => import("../../parse/ast/morph.js").Out<number>;
10
- parsedInteger: (In: string) => import("../../parse/ast/morph.js").Out<number>;
11
- parsedDate: (In: string) => import("../../parse/ast/morph.js").Out<Date>;
9
+ parsedNumber: (In: string) => number;
10
+ parsedInteger: (In: string) => number;
11
+ parsedDate: (In: string) => Date;
12
+ semver: string;
13
+ json: (In: string) => unknown;
12
14
  integer: number;
13
15
  }, {}, false]>;
14
16
  export declare const validation: import("../scope.js").Space<{
@@ -19,8 +21,10 @@ export declare const validation: import("../scope.js").Space<{
19
21
  creditCard: string;
20
22
  email: string;
21
23
  uuid: string;
22
- parsedNumber: (In: string) => import("../../parse/ast/morph.js").Out<number>;
23
- parsedInteger: (In: string) => import("../../parse/ast/morph.js").Out<number>;
24
- parsedDate: (In: string) => import("../../parse/ast/morph.js").Out<Date>;
24
+ parsedNumber: (In: string) => number;
25
+ parsedInteger: (In: string) => number;
26
+ parsedDate: (In: string) => Date;
27
+ semver: string;
28
+ json: (In: string) => unknown;
25
29
  integer: number;
26
30
  }>;
@@ -1,7 +1,7 @@
1
1
  import type { FlatBound } from "../nodes/rules/range.js";
2
2
  import { DataWrapper } from "../utils/data.js";
3
3
  import type { Domain } from "../utils/domains.js";
4
- import type { arraySubclassToReadonly, constructor, evaluate, instanceOf, RegexLiteral } from "../utils/generics.js";
4
+ import type { arraySubclassToReadonly, constructor, evaluate, RegexLiteral } from "../utils/generics.js";
5
5
  import type { DefaultObjectKind } from "../utils/objectKinds.js";
6
6
  import { Path } from "../utils/paths.js";
7
7
  import type { ConstrainedRuleTraversalData, TraversalState } from "./traverse.js";
@@ -38,8 +38,8 @@ declare class ProblemArray extends Array<Problem> {
38
38
  toString(): string;
39
39
  throw(): never;
40
40
  }
41
- export declare const Problems: new (state: TraversalState) => arraySubclassToReadonly<ProblemArray>;
42
- export type Problems = instanceOf<typeof Problems>;
41
+ export declare const Problems: new (state: TraversalState) => Problems;
42
+ export type Problems = arraySubclassToReadonly<ProblemArray>;
43
43
  export declare const domainsToDescriptions: (domains: Domain[]) => ("boolean" | "undefined" | "null" | "a bigint" | "a number" | "an object" | "a string" | "a symbol")[];
44
44
  export declare const objectKindsToDescriptions: (kinds: DefaultObjectKind[]) => ("an object" | "an array" | "a function" | "a Date" | "a RegExp" | "an Error" | "a Map" | "a Set" | "a String object" | "a Number object" | "a Boolean object" | "a Promise" | "a WeakMap" | "a WeakSet")[];
45
45
  export declare const describeBranches: (descriptions: string[]) => string;
@@ -6,84 +6,24 @@ import type { SizedData } from "../utils/data.js";
6
6
  import type { extend, stringKeyOf } from "../utils/generics.js";
7
7
  import { Path } from "../utils/paths.js";
8
8
  import type { ProblemCode, ProblemWriters } from "./problems.js";
9
- import { Problem } from "./problems.js";
9
+ import { Problems } from "./problems.js";
10
10
  export declare class TraversalState<data = unknown> {
11
11
  #private;
12
12
  data: data;
13
13
  type: Type;
14
14
  path: Path;
15
- problems: import("../utils/generics.js").arraySubclassToReadonly<{
16
- [n: number]: Problem<any>;
17
- byPath: Record<string, Problem<any>>;
18
- count: number;
19
- "__#2@#state": TraversalState<unknown>;
20
- mustBe(description: string, opts?: import("./problems.js").AddProblemOptions<unknown> | undefined): Problem<any>;
21
- add<code extends ProblemCode>(code: code, source: import("./problems.js").ProblemSource<code>, opts?: import("./problems.js").AddProblemOptions<import("./problems.js").ProblemData<code>> | undefined): Problem<any>;
22
- addProblem(problem: Problem<any>): void;
23
- readonly summary: string;
24
- toString(): string;
25
- throw(): never;
26
- length: number;
27
- toLocaleString(): string;
28
- pop(): Problem<any> | undefined;
29
- push(...items: Problem<any>[]): number;
30
- concat(...items: ConcatArray<Problem<any>>[]): Problem<any>[];
31
- concat(...items: (Problem<any> | ConcatArray<Problem<any>>)[]): Problem<any>[];
32
- join(separator?: string | undefined): string;
33
- reverse(): Problem<any>[];
34
- shift(): Problem<any> | undefined;
35
- slice(start?: number | undefined, end?: number | undefined): Problem<any>[];
36
- sort(compareFn?: ((a: Problem<any>, b: Problem<any>) => number) | undefined): any;
37
- splice(start: number, deleteCount?: number | undefined): Problem<any>[];
38
- splice(start: number, deleteCount: number, ...items: Problem<any>[]): Problem<any>[];
39
- unshift(...items: Problem<any>[]): number;
40
- indexOf(searchElement: Problem<any>, fromIndex?: number | undefined): number;
41
- lastIndexOf(searchElement: Problem<any>, fromIndex?: number | undefined): number;
42
- every<S extends Problem<any>>(predicate: (value: Problem<any>, index: number, array: Problem<any>[]) => value is S, thisArg?: any): this is S[];
43
- every(predicate: (value: Problem<any>, index: number, array: Problem<any>[]) => unknown, thisArg?: any): boolean;
44
- some(predicate: (value: Problem<any>, index: number, array: Problem<any>[]) => unknown, thisArg?: any): boolean;
45
- forEach(callbackfn: (value: Problem<any>, index: number, array: Problem<any>[]) => void, thisArg?: any): void;
46
- map<U>(callbackfn: (value: Problem<any>, index: number, array: Problem<any>[]) => U, thisArg?: any): U[];
47
- filter<S_1 extends Problem<any>>(predicate: (value: Problem<any>, index: number, array: Problem<any>[]) => value is S_1, thisArg?: any): S_1[];
48
- filter(predicate: (value: Problem<any>, index: number, array: Problem<any>[]) => unknown, thisArg?: any): Problem<any>[];
49
- reduce(callbackfn: (previousValue: Problem<any>, currentValue: Problem<any>, currentIndex: number, array: Problem<any>[]) => Problem<any>): Problem<any>;
50
- reduce(callbackfn: (previousValue: Problem<any>, currentValue: Problem<any>, currentIndex: number, array: Problem<any>[]) => Problem<any>, initialValue: Problem<any>): Problem<any>;
51
- reduce<U_1>(callbackfn: (previousValue: U_1, currentValue: Problem<any>, currentIndex: number, array: Problem<any>[]) => U_1, initialValue: U_1): U_1;
52
- reduceRight(callbackfn: (previousValue: Problem<any>, currentValue: Problem<any>, currentIndex: number, array: Problem<any>[]) => Problem<any>): Problem<any>;
53
- reduceRight(callbackfn: (previousValue: Problem<any>, currentValue: Problem<any>, currentIndex: number, array: Problem<any>[]) => Problem<any>, initialValue: Problem<any>): Problem<any>;
54
- reduceRight<U_2>(callbackfn: (previousValue: U_2, currentValue: Problem<any>, currentIndex: number, array: Problem<any>[]) => U_2, initialValue: U_2): U_2;
55
- find<S_2 extends Problem<any>>(predicate: (value: Problem<any>, index: number, obj: Problem<any>[]) => value is S_2, thisArg?: any): S_2 | undefined;
56
- find(predicate: (value: Problem<any>, index: number, obj: Problem<any>[]) => unknown, thisArg?: any): Problem<any> | undefined;
57
- findIndex(predicate: (value: Problem<any>, index: number, obj: Problem<any>[]) => unknown, thisArg?: any): number;
58
- fill(value: Problem<any>, start?: number | undefined, end?: number | undefined): any;
59
- copyWithin(target: number, start: number, end?: number | undefined): any;
60
- entries(): IterableIterator<[number, Problem<any>]>;
61
- keys(): IterableIterator<number>;
62
- values(): IterableIterator<Problem<any>>;
63
- includes(searchElement: Problem<any>, fromIndex?: number | undefined): boolean;
64
- flatMap<U_3, This = undefined>(callback: (this: This, value: Problem<any>, index: number, array: Problem<any>[]) => U_3 | readonly U_3[], thisArg?: This | undefined): U_3[];
65
- flat<A, D extends number = 1>(this: A, depth?: D | undefined): FlatArray<A, D>[];
66
- at(index: number): Problem<any> | undefined;
67
- findLast<S_3 extends Problem<any>>(predicate: (value: Problem<any>, index: number, array: Problem<any>[]) => value is S_3, thisArg?: any): S_3 | undefined;
68
- findLast(predicate: (value: Problem<any>, index: number, array: Problem<any>[]) => unknown, thisArg?: any): Problem<any> | undefined;
69
- findLastIndex(predicate: (value: Problem<any>, index: number, array: Problem<any>[]) => unknown, thisArg?: any): number;
70
- [Symbol.iterator](): IterableIterator<Problem<any>>;
71
- [Symbol.unscopables](): {
72
- copyWithin: boolean;
73
- entries: boolean;
74
- fill: boolean;
75
- find: boolean;
76
- findIndex: boolean;
77
- keys: boolean;
78
- values: boolean;
79
- };
80
- }>;
15
+ problems: Problems;
81
16
  failFast: boolean;
82
17
  traversalConfig: TraversalConfig;
83
18
  readonly rootScope: Scope;
84
19
  constructor(data: data, type: Type);
85
20
  getProblemConfig<code extends ProblemCode>(code: code): ProblemWriters<code>;
86
- getConfigKey<k extends keyof TypeConfig>(k: k): TypeConfig[k] | undefined;
21
+ getConfigKey<k extends keyof TypeConfig>(k: k): {
22
+ keys?: import("../scopes/type.js").KeyCheckKind;
23
+ mustBe?: import("./problems.js").MustBeWriter<ProblemCode>;
24
+ writeReason?: import("./problems.js").ReasonWriter<ProblemCode>;
25
+ addContext?: import("./problems.js").ContextWriter;
26
+ }[k] | undefined;
87
27
  traverseConfig(configEntries: ConfigEntry[], node: TraversalNode): boolean;
88
28
  traverseKey(key: stringKeyOf<this["data"]>, node: TraversalNode): boolean;
89
29
  traverseResolution(name: string): boolean;
@@ -1,13 +1,13 @@
1
1
  import { domainOf } from "./domains.js";
2
2
  export type SizedData = string | number | readonly unknown[];
3
3
  export declare const sizeOf: (data: unknown) => number;
4
- export declare const unitsOf: (data: unknown) => "" | "characters" | "items";
4
+ export declare const unitsOf: (data: unknown) => "" | "characters" | "items long";
5
5
  export declare class DataWrapper<value = unknown> {
6
6
  value: value;
7
7
  constructor(value: value);
8
8
  toString(): string;
9
9
  get domain(): domainOf<value>;
10
10
  get size(): number;
11
- get units(): "" | "characters" | "items";
11
+ get units(): "" | "characters" | "items long";
12
12
  get className(): any;
13
13
  }
@@ -45,6 +45,7 @@ export type stringKeyOf<o> = keyof o & string;
45
45
  /** Mimics output of TS's keyof operator at runtime */
46
46
  export declare const prototypeKeysOf: <t>(value: t) => (keyof t)[];
47
47
  export declare const hasKey: <o, k extends string>(o: o, k: k) => o is Extract<o, { [_ in k]: {}; }>;
48
+ export declare const hasSingleKey: <o extends object, k extends string>(o: o, k: k) => o is o & { [_ in k]: {}; };
48
49
  export declare const keyCount: (o: object) => number;
49
50
  export type keySet<key extends string = string> = {
50
51
  readonly [_ in key]?: true;
@@ -62,9 +63,13 @@ export type deepImmutable<o> = [o] extends [object] ? {
62
63
  /** Check for type equality without breaking TS for this repo. Fails on some types like Dict/{} */
63
64
  export type equals<t, u> = identity<t> extends identity<u> ? true : false;
64
65
  declare const id: unique symbol;
66
+ export declare const nominal: <o extends object, name extends string>(o: o, name: name) => nominal<o, name>;
67
+ export declare const composeNamed: <args extends any[], returns extends object, name extends string>(f: (...args: args) => returns, name: name) => (...args: args) => nominal<returns, name>;
65
68
  export type nominal<t, id extends string> = t & {
66
69
  readonly [id]: id;
67
70
  };
71
+ export declare const getNominalId: <data>(data: data) => unknown;
72
+ export declare const hasNominalId: <data, name extends string>(data: data, name: name) => data is nominal<data, name>;
68
73
  export type assertEqual<t, u> = equals<t, u> extends true ? t : error<`types were not equivalent`>;
69
74
  export type identity<in out t> = (_: t) => t;
70
75
  export type extend<t, u extends t> = u;
@@ -11,7 +11,6 @@ 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, indent?: number) => string;
15
14
  export declare const stringify: (data: unknown, indent?: number) => string;
16
15
  type SerializedString = `'${string}'`;
17
16
  export type SerializedPrimitives = {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "arktype",
3
- "description": "Isomorphic types for TS/JS",
4
- "version": "0.6.0",
3
+ "description": "The first isomorphic type system for TS/JS",
4
+ "version": "1.0.1-alpha",
5
5
  "author": {
6
6
  "name": "David Blass",
7
7
  "email": "david@arktype.io",
@@ -29,29 +29,29 @@
29
29
  "files": [
30
30
  "dist"
31
31
  ],
32
- "packageManager": "pnpm@7.18.0",
32
+ "packageManager": "pnpm@7.27.0",
33
33
  "devDependencies": {
34
34
  "@changesets/cli": "2.26.0",
35
- "@swc/cli": "0.1.59",
36
- "@swc/core": "1.3.24",
35
+ "@swc/cli": "0.1.62",
36
+ "@swc/core": "1.3.35",
37
37
  "@types/mocha": "10.0.1",
38
- "@types/node": "18.11.18",
39
- "@typescript-eslint/eslint-plugin": "5.48.0",
40
- "@typescript-eslint/parser": "5.48.0",
41
- "c8": "7.12.0",
42
- "eslint": "8.31.0",
38
+ "@types/node": "18.14.0",
39
+ "@typescript-eslint/eslint-plugin": "5.53.0",
40
+ "@typescript-eslint/parser": "5.53.0",
41
+ "c8": "7.13.0",
42
+ "eslint": "8.34.0",
43
43
  "eslint-config-prettier": "8.6.0",
44
- "eslint-define-config": "1.13.0",
45
- "eslint-import-resolver-typescript": "3.5.2",
46
- "eslint-plugin-import": "2.26.0",
44
+ "eslint-define-config": "1.15.0",
45
+ "eslint-import-resolver-typescript": "3.5.3",
46
+ "eslint-plugin-import": "2.27.5",
47
47
  "eslint-plugin-only-warn": "1.1.0",
48
48
  "eslint-plugin-prefer-arrow": "1.2.3",
49
49
  "eslint-plugin-unicorn": "45.0.2",
50
- "fast-check": "3.5.0",
50
+ "fast-check": "3.6.3",
51
51
  "get-current-line": "6.6.0",
52
52
  "husky": "8.0.3",
53
53
  "mocha": "10.2.0",
54
- "prettier": "2.8.1",
54
+ "prettier": "2.8.4",
55
55
  "prettier-plugin-jsdoc": "0.4.2",
56
56
  "pretty-quick": "3.1.3",
57
57
  "ts-morph": "17.0.1",