arktype 2.0.0-rc.1 → 2.0.0-rc.11

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 (141) hide show
  1. package/out/config.d.ts +1 -1
  2. package/out/generic.d.ts +47 -48
  3. package/out/generic.js +6 -8
  4. package/out/index.d.ts +4 -4
  5. package/out/index.js +2 -2
  6. package/out/keywords/builtins.js +2 -2
  7. package/out/keywords/constructors/Array.d.ts +2 -2
  8. package/out/keywords/constructors/Array.js +7 -7
  9. package/out/keywords/constructors/Date.d.ts +32 -0
  10. package/out/keywords/constructors/FormData.d.ts +2 -2
  11. package/out/keywords/constructors/FormData.js +8 -8
  12. package/out/keywords/constructors/TypedArray.js +2 -2
  13. package/out/keywords/constructors/constructors.d.ts +0 -1
  14. package/out/keywords/constructors/constructors.js +2 -2
  15. package/out/keywords/inference.d.ts +228 -0
  16. package/out/keywords/keywords.d.ts +62 -0
  17. package/out/keywords/{ark.js → keywords.js} +11 -8
  18. package/out/keywords/number/epoch.d.ts +1 -2
  19. package/out/keywords/number/epoch.js +2 -2
  20. package/out/keywords/number/integer.js +2 -2
  21. package/out/keywords/number/number.d.ts +32 -6
  22. package/out/keywords/number/number.js +17 -5
  23. package/out/keywords/string/alpha.d.ts +1 -1
  24. package/out/keywords/string/alphanumeric.d.ts +1 -1
  25. package/out/keywords/string/capitalize.d.ts +2 -2
  26. package/out/keywords/string/capitalize.js +4 -4
  27. package/out/keywords/string/creditCard.d.ts +1 -1
  28. package/out/keywords/string/creditCard.js +2 -2
  29. package/out/keywords/string/date.d.ts +4 -8
  30. package/out/keywords/string/date.js +16 -16
  31. package/out/keywords/string/digits.d.ts +1 -1
  32. package/out/keywords/string/email.d.ts +1 -1
  33. package/out/keywords/string/integer.d.ts +2 -2
  34. package/out/keywords/string/integer.js +7 -7
  35. package/out/keywords/string/ip.d.ts +2 -2
  36. package/out/keywords/string/ip.js +5 -5
  37. package/out/keywords/string/json.d.ts +3 -2
  38. package/out/keywords/string/json.js +24 -16
  39. package/out/keywords/string/lower.d.ts +2 -2
  40. package/out/keywords/string/lower.js +4 -4
  41. package/out/keywords/string/normalize.d.ts +23 -27
  42. package/out/keywords/string/normalize.js +14 -14
  43. package/out/keywords/string/numeric.d.ts +2 -2
  44. package/out/keywords/string/numeric.js +7 -7
  45. package/out/keywords/string/semver.d.ts +1 -1
  46. package/out/keywords/string/string.d.ts +39 -42
  47. package/out/keywords/string/string.js +3 -3
  48. package/out/keywords/string/trim.d.ts +2 -2
  49. package/out/keywords/string/trim.js +4 -4
  50. package/out/keywords/string/upper.d.ts +2 -2
  51. package/out/keywords/string/upper.js +4 -4
  52. package/out/keywords/string/url.d.ts +2 -2
  53. package/out/keywords/string/url.js +8 -8
  54. package/out/keywords/string/uuid.d.ts +11 -11
  55. package/out/keywords/string/uuid.js +3 -3
  56. package/out/keywords/ts.d.ts +38 -1
  57. package/out/keywords/ts.js +20 -4
  58. package/out/keywords/utils.d.ts +1 -1
  59. package/out/keywords/utils.js +1 -1
  60. package/out/{subtypes → methods}/array.d.ts +6 -6
  61. package/out/methods/base.d.ts +96 -0
  62. package/out/{subtypes → methods}/date.d.ts +5 -5
  63. package/out/{subtypes → methods}/instantiate.d.ts +5 -4
  64. package/out/methods/morph.d.ts +12 -0
  65. package/out/{subtypes → methods}/number.d.ts +6 -6
  66. package/out/methods/object.d.ts +81 -0
  67. package/out/{subtypes → methods}/string.d.ts +7 -7
  68. package/out/{subtypes → methods}/validator.d.ts +2 -2
  69. package/out/module.d.ts +2 -2
  70. package/out/parser/{semantic → ast}/bounds.d.ts +3 -3
  71. package/out/parser/ast/default.d.ts +8 -0
  72. package/out/parser/{semantic → ast}/infer.d.ts +11 -11
  73. package/out/parser/{semantic → ast}/utils.d.ts +1 -1
  74. package/out/parser/{semantic → ast}/validate.d.ts +6 -6
  75. package/out/parser/definition.d.ts +8 -9
  76. package/out/parser/objectLiteral.d.ts +11 -37
  77. package/out/parser/objectLiteral.js +6 -24
  78. package/out/parser/{string/reduce → reduce}/dynamic.d.ts +5 -7
  79. package/out/parser/{string/reduce → reduce}/dynamic.js +5 -6
  80. package/out/parser/{string/reduce → reduce}/shared.d.ts +1 -1
  81. package/out/parser/{string/reduce → reduce}/static.d.ts +1 -1
  82. package/out/parser/{string/shift → shift}/operand/date.d.ts +3 -1
  83. package/out/parser/{string/shift → shift}/operand/enclosed.d.ts +3 -2
  84. package/out/parser/{string/shift → shift}/operand/enclosed.js +7 -3
  85. package/out/parser/{string/shift → shift}/operand/unenclosed.d.ts +3 -3
  86. package/out/parser/{string/shift → shift}/operand/unenclosed.js +7 -3
  87. package/out/parser/{string/shift → shift}/operator/bounds.d.ts +3 -3
  88. package/out/parser/{string/shift → shift}/operator/default.d.ts +3 -6
  89. package/out/parser/{string/shift → shift}/operator/default.js +1 -6
  90. package/out/parser/{string/shift → shift}/scanner.d.ts +3 -1
  91. package/out/parser/{string/shift → shift}/scanner.js +5 -3
  92. package/out/parser/{string/string.d.ts → string.d.ts} +6 -7
  93. package/out/parser/{string/string.js → string.js} +2 -0
  94. package/out/parser/tuple.d.ts +54 -43
  95. package/out/parser/tuple.js +36 -30
  96. package/out/scope.d.ts +32 -39
  97. package/out/scope.js +43 -35
  98. package/out/type.d.ts +24 -21
  99. package/out/type.js +14 -10
  100. package/package.json +3 -3
  101. package/out/intersect.d.ts +0 -28
  102. package/out/keys.d.ts +0 -16
  103. package/out/keywords/ark.d.ts +0 -39
  104. package/out/keywords/ast.d.ts +0 -193
  105. package/out/parser/semantic/default.d.ts +0 -9
  106. package/out/parser/semantic/default.js +0 -1
  107. package/out/subtypes/base.d.ts +0 -85
  108. package/out/subtypes/morph.d.ts +0 -13
  109. package/out/subtypes/object.d.ts +0 -33
  110. /package/out/{intersect.js → keywords/constructors/Date.js} +0 -0
  111. /package/out/keywords/{ast.js → inference.js} +0 -0
  112. /package/out/{subtypes → methods}/array.js +0 -0
  113. /package/out/{subtypes → methods}/base.js +0 -0
  114. /package/out/{subtypes → methods}/date.js +0 -0
  115. /package/out/{subtypes → methods}/instantiate.js +0 -0
  116. /package/out/{subtypes → methods}/morph.js +0 -0
  117. /package/out/{subtypes → methods}/number.js +0 -0
  118. /package/out/{subtypes → methods}/object.js +0 -0
  119. /package/out/{subtypes → methods}/string.js +0 -0
  120. /package/out/{subtypes → methods}/validator.js +0 -0
  121. /package/out/parser/{semantic → ast}/bounds.js +0 -0
  122. /package/out/{keys.js → parser/ast/default.js} +0 -0
  123. /package/out/parser/{semantic → ast}/divisor.d.ts +0 -0
  124. /package/out/parser/{semantic → ast}/divisor.js +0 -0
  125. /package/out/parser/{semantic → ast}/infer.js +0 -0
  126. /package/out/parser/{semantic → ast}/keyof.d.ts +0 -0
  127. /package/out/parser/{semantic → ast}/keyof.js +0 -0
  128. /package/out/parser/{semantic → ast}/utils.js +0 -0
  129. /package/out/parser/{semantic → ast}/validate.js +0 -0
  130. /package/out/parser/{string/reduce → reduce}/shared.js +0 -0
  131. /package/out/parser/{string/reduce → reduce}/static.js +0 -0
  132. /package/out/parser/{string/shift → shift}/operand/date.js +0 -0
  133. /package/out/parser/{string/shift → shift}/operand/genericArgs.d.ts +0 -0
  134. /package/out/parser/{string/shift → shift}/operand/genericArgs.js +0 -0
  135. /package/out/parser/{string/shift → shift}/operand/operand.d.ts +0 -0
  136. /package/out/parser/{string/shift → shift}/operand/operand.js +0 -0
  137. /package/out/parser/{string/shift → shift}/operator/bounds.js +0 -0
  138. /package/out/parser/{string/shift → shift}/operator/divisor.d.ts +0 -0
  139. /package/out/parser/{string/shift → shift}/operator/divisor.js +0 -0
  140. /package/out/parser/{string/shift → shift}/operator/operator.d.ts +0 -0
  141. /package/out/parser/{string/shift → shift}/operator/operator.js +0 -0
package/out/config.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import type { ArkSchemaRegistry } from "@ark/schema";
2
- import type { Ark } from "./keywords/ark.ts";
2
+ import type { Ark } from "./keywords/keywords.ts";
3
3
  import type { exportScope } from "./module.ts";
4
4
  export * from "@ark/schema/config";
5
5
  export interface ArkTypeRegistryContents extends ArkSchemaRegistry {
package/out/generic.d.ts CHANGED
@@ -1,29 +1,30 @@
1
- import { GenericRoot, type arkKind, type GenericAst, type GenericParamAst, type GenericParamDef, type genericParamNames, type LazyGenericBody } from "@ark/schema";
1
+ import { GenericRoot, type arkKind, type BaseParseContext, type GenericAst, type GenericParamAst, type GenericParamDef, type genericParamNames, type LazyGenericBody } from "@ark/schema";
2
2
  import { type array, type Callable, type conform, type ErrorMessage, type ErrorType, type Hkt, type Json, type WhiteSpaceToken } from "@ark/util";
3
+ import type { type } from "./keywords/keywords.ts";
4
+ import type { inferAstRoot } from "./parser/ast/infer.ts";
5
+ import type { validateAst } from "./parser/ast/validate.ts";
3
6
  import type { inferDefinition, validateDefinition } from "./parser/definition.ts";
4
- import type { inferAstRoot } from "./parser/semantic/infer.ts";
5
- import type { validateAst } from "./parser/semantic/validate.ts";
6
- import type { state, StaticState } from "./parser/string/reduce/static.ts";
7
- import { Scanner } from "./parser/string/shift/scanner.ts";
8
- import { parseUntilFinalizer } from "./parser/string/string.ts";
9
- import type { ParseContext, Scope } from "./scope.ts";
10
- import type { inferTypeRoot, Type, validateTypeRoot } from "./type.ts";
7
+ import type { state, StaticState } from "./parser/reduce/static.ts";
8
+ import type { Scanner } from "./parser/shift/scanner.ts";
9
+ import { parseUntilFinalizer } from "./parser/string.ts";
10
+ import type { Scope } from "./scope.ts";
11
+ import type { Type } from "./type.ts";
11
12
  export type ParameterString<params extends string = string> = `<${params}>`;
12
13
  export type extractParams<s extends ParameterString> = s extends ParameterString<infer params> ? params : never;
13
14
  export type validateParameterString<s extends ParameterString, $> = parseGenericParams<extractParams<s>, $> extends infer e extends ErrorMessage ? e : s;
14
- export type validateGenericArg<arg, param extends GenericParamAst, $> = inferTypeRoot<arg, $> extends param[1] ? unknown : ErrorType<`Invalid argument for ${param[0]}`, [expected: param[1]]>;
15
+ export type validateGenericArg<arg, param extends GenericParamAst, $> = type.infer<arg, $> extends param[1] ? unknown : ErrorType<`Invalid argument for ${param[0]}`, [expected: param[1]]>;
15
16
  export type GenericInstantiator<params extends array<GenericParamAst>, def, $, args$> = params["length"] extends 1 ? {
16
- <const a, r = instantiateGeneric<def, params, [a], $, args$>>(a: validateTypeRoot<a, args$> & validateGenericArg<a, params[0], args$>): r;
17
+ <const a, r = instantiateGeneric<def, params, [a], $, args$>>(a: type.validate<a, args$> & validateGenericArg<a, params[0], args$>): r;
17
18
  } : params["length"] extends 2 ? {
18
- <const a, const b, r = instantiateGeneric<def, params, [a, b], $, args$>>(...args: [validateTypeRoot<a, args$>, validateTypeRoot<b, args$>] & [
19
- validateGenericArg<a, params[0], args$>,
20
- validateGenericArg<b, params[1], args$>
19
+ <const a, const b, r = instantiateGeneric<def, params, [a, b], $, args$>>(...args: [
20
+ type.validate<a, args$> & validateGenericArg<a, params[0], args$>,
21
+ type.validate<b, args$> & validateGenericArg<b, params[1], args$>
21
22
  ]): r;
22
23
  } : params["length"] extends 3 ? {
23
24
  <const a, const b, const c, r = instantiateGeneric<def, params, [a, b, c], $, args$>>(...args: [
24
- validateTypeRoot<a, args$>,
25
- validateTypeRoot<b, args$>,
26
- validateTypeRoot<c, args$>
25
+ type.validate<a, args$>,
26
+ type.validate<b, args$>,
27
+ type.validate<c, args$>
27
28
  ] & [
28
29
  validateGenericArg<a, params[0], args$>,
29
30
  validateGenericArg<b, params[1], args$>,
@@ -31,10 +32,10 @@ export type GenericInstantiator<params extends array<GenericParamAst>, def, $, a
31
32
  ]): r;
32
33
  } : params["length"] extends 4 ? {
33
34
  <const a, const b, const c, const d, r = instantiateGeneric<def, params, [a, b, c, d], $, args$>>(...args: [
34
- validateTypeRoot<a, args$>,
35
- validateTypeRoot<b, args$>,
36
- validateTypeRoot<c, args$>,
37
- validateTypeRoot<d, args$>
35
+ type.validate<a, args$>,
36
+ type.validate<b, args$>,
37
+ type.validate<c, args$>,
38
+ type.validate<d, args$>
38
39
  ] & [
39
40
  validateGenericArg<a, params[0], args$>,
40
41
  validateGenericArg<b, params[1], args$>,
@@ -43,11 +44,11 @@ export type GenericInstantiator<params extends array<GenericParamAst>, def, $, a
43
44
  ]): r;
44
45
  } : params["length"] extends 4 ? {
45
46
  <const a, const b, const c, const d, const e, r = instantiateGeneric<def, params, [a, b, c, d, e], $, args$>>(...args: [
46
- validateTypeRoot<a, args$>,
47
- validateTypeRoot<b, args$>,
48
- validateTypeRoot<c, args$>,
49
- validateTypeRoot<d, args$>,
50
- validateTypeRoot<e, args$>
47
+ type.validate<a, args$>,
48
+ type.validate<b, args$>,
49
+ type.validate<c, args$>,
50
+ type.validate<d, args$>,
51
+ type.validate<e, args$>
51
52
  ] & [
52
53
  validateGenericArg<a, params[0], args$>,
53
54
  validateGenericArg<b, params[1], args$>,
@@ -57,12 +58,12 @@ export type GenericInstantiator<params extends array<GenericParamAst>, def, $, a
57
58
  ]): r;
58
59
  } : params["length"] extends 5 ? {
59
60
  <const a, const b, const c, const d, const e, const f, r = instantiateGeneric<def, params, [a, b, c, d, e, f], $, args$>>(...args: [
60
- validateTypeRoot<a, args$>,
61
- validateTypeRoot<b, args$>,
62
- validateTypeRoot<c, args$>,
63
- validateTypeRoot<d, args$>,
64
- validateTypeRoot<e, args$>,
65
- validateTypeRoot<f, args$>
61
+ type.validate<a, args$>,
62
+ type.validate<b, args$>,
63
+ type.validate<c, args$>,
64
+ type.validate<d, args$>,
65
+ type.validate<e, args$>,
66
+ type.validate<f, args$>
66
67
  ] & [
67
68
  validateGenericArg<a, params[0], args$>,
68
69
  validateGenericArg<b, params[1], args$>,
@@ -73,13 +74,13 @@ export type GenericInstantiator<params extends array<GenericParamAst>, def, $, a
73
74
  ]): r;
74
75
  } : params["length"] extends 6 ? {
75
76
  <const a, const b, const c, const d, const e, const f, const g, r = instantiateGeneric<def, params, [a, b, c, d, e, f, g], $, args$>>(...args: [
76
- validateTypeRoot<a, args$>,
77
- validateTypeRoot<b, args$>,
78
- validateTypeRoot<c, args$>,
79
- validateTypeRoot<d, args$>,
80
- validateTypeRoot<e, args$>,
81
- validateTypeRoot<f, args$>,
82
- validateTypeRoot<g, args$>
77
+ type.validate<a, args$>,
78
+ type.validate<b, args$>,
79
+ type.validate<c, args$>,
80
+ type.validate<d, args$>,
81
+ type.validate<e, args$>,
82
+ type.validate<f, args$>,
83
+ type.validate<g, args$>
83
84
  ] & [
84
85
  validateGenericArg<a, params[0], args$>,
85
86
  validateGenericArg<b, params[1], args$>,
@@ -93,10 +94,10 @@ export type GenericInstantiator<params extends array<GenericParamAst>, def, $, a
93
94
  type instantiateGeneric<def, params extends array<GenericParamAst>, args, $, args$> = Type<[
94
95
  def
95
96
  ] extends [Hkt] ? Hkt.apply<def, {
96
- [i in keyof args]: inferTypeRoot<args[i], args$>;
97
+ [i in keyof args]: type.infer<args[i], args$>;
97
98
  }> : inferDefinition<def, $, bindGenericArgs<params, args$, args>>, args$>;
98
99
  type bindGenericArgs<params extends array<GenericParamAst>, $, args> = {
99
- [i in keyof params & `${number}` as params[i][0]]: inferTypeRoot<args[i & keyof args], $>;
100
+ [i in keyof params & `${number}` as params[i][0]]: type.infer<args[i & keyof args], $>;
100
101
  };
101
102
  type baseGenericResolutions<params extends array<GenericParamAst>, $> = baseGenericConstraints<params> extends infer baseConstraints ? {
102
103
  [k in keyof baseConstraints]: Type<baseConstraints[k], $>;
@@ -126,16 +127,15 @@ export type GenericDeclaration<name extends string = string, params extends Para
126
127
  export type parseValidGenericParams<def extends ParameterString, $> = conform<parseGenericParams<extractParams<def>, $>, array<GenericParamAst>>;
127
128
  export declare const emptyGenericParameterMessage = "An empty string is not a valid generic parameter name";
128
129
  export type emptyGenericParameterMessage = typeof emptyGenericParameterMessage;
129
- export declare const parseGenericParams: (def: string, ctx: ParseContext) => array<GenericParamDef>;
130
130
  export type parseGenericParams<def extends string, $> = parseNextNameChar<Scanner.skipWhitespace<def>, "", [
131
131
  ], $>;
132
132
  type ParamsTerminator = WhiteSpaceToken | ",";
133
- declare const parseName: (scanner: Scanner, result: GenericParamDef[], ctx: ParseContext) => GenericParamDef[];
133
+ export declare const parseGenericParamName: (scanner: Scanner, result: GenericParamDef[], ctx: BaseParseContext) => GenericParamDef[];
134
134
  type parseName<unscanned extends string, result extends array<GenericParamAst>, $> = parseNextNameChar<Scanner.skipWhitespace<unscanned>, "", result, $>;
135
135
  type parseNextNameChar<unscanned extends string, name extends string, result extends array<GenericParamAst>, $> = unscanned extends `${infer lookahead}${infer nextUnscanned}` ? lookahead extends ParamsTerminator ? name extends "" ? ErrorMessage<emptyGenericParameterMessage> : lookahead extends "," ? parseName<nextUnscanned, [...result, [name, unknown]], $> : lookahead extends WhiteSpaceToken ? _parseOptionalConstraint<nextUnscanned, name, result, $> : never : parseNextNameChar<nextUnscanned, `${name}${lookahead}`, result, $> : name extends "" ? result : [...result, [name, unknown]];
136
136
  declare const extendsToken = "extends ";
137
137
  type extendsToken = typeof extendsToken;
138
- declare const _parseOptionalConstraint: (scanner: Scanner, name: string, result: GenericParamDef[], ctx: ParseContext) => GenericParamDef[];
138
+ declare const _parseOptionalConstraint: (scanner: Scanner, name: string, result: GenericParamDef[], ctx: BaseParseContext) => GenericParamDef[];
139
139
  type _parseOptionalConstraint<unscanned extends string, name extends string, result extends array<GenericParamAst>, $> = Scanner.skipWhitespace<unscanned> extends (`${extendsToken}${infer nextUnscanned}`) ? parseUntilFinalizer<state.initialize<nextUnscanned>, $, {}> extends (infer finalArgState extends StaticState) ? validateAst<finalArgState["root"], $, {}> extends (infer e extends ErrorMessage) ? e : parseName<finalArgState["unscanned"], [
140
140
  ...result,
141
141
  [name, inferAstRoot<finalArgState["root"], $, {}>]
@@ -143,16 +143,15 @@ type _parseOptionalConstraint<unscanned extends string, name extends string, res
143
143
  ...result,
144
144
  [name, unknown]
145
145
  ], $>;
146
- type genericParamDefToAst<schema extends GenericParamDef, $> = schema extends string ? [schema, unknown] : schema extends readonly [infer name, infer def] ? [
147
- name,
148
- inferTypeRoot<def, $>
149
- ] : never;
146
+ type genericParamDefToAst<schema extends GenericParamDef, $> = schema extends string ? [schema, unknown] : schema extends readonly [infer name, infer def] ? [name, type.infer<def, $>] : never;
150
147
  export type genericParamDefsToAst<defs extends array<GenericParamDef>, $> = [
151
148
  ...{
152
149
  [i in keyof defs]: genericParamDefToAst<defs[i], $>;
153
150
  }
154
151
  ];
155
- export type GenericParser<$ = {}> = <const paramsDef extends array<GenericParamDef>>(...params: paramsDef) => GenericBodyParser<genericParamDefsToAst<paramsDef, $>, $>;
152
+ export type GenericParser<$ = {}> = <const paramsDef extends array<GenericParamDef>>(...params: {
153
+ [i in keyof paramsDef]: paramsDef[i] extends (readonly [infer name, infer def]) ? readonly [name, type.validate<def, $>] : paramsDef[i];
154
+ }) => GenericBodyParser<genericParamDefsToAst<paramsDef, $>, $>;
156
155
  interface GenericBodyParser<params extends array<GenericParamAst>, $> {
157
156
  <const body>(body: validateDefinition<body, $, baseGenericConstraints<params>>): Generic<params, body, $, $>;
158
157
  <hkt extends Hkt.constructor>(instantiateDef: LazyGenericBody<baseGenericResolutions<params, $>>, hkt: hkt): Generic<params, InstanceType<hkt>, $, $>;
package/out/generic.js CHANGED
@@ -1,12 +1,10 @@
1
1
  import { GenericRoot } from "@ark/schema";
2
2
  import { throwParseError } from "@ark/util";
3
- import { DynamicState } from "./parser/string/reduce/dynamic.js";
4
- import { Scanner } from "./parser/string/shift/scanner.js";
5
- import { parseUntilFinalizer } from "./parser/string/string.js";
3
+ import { DynamicState } from "./parser/reduce/dynamic.js";
4
+ import { parseUntilFinalizer } from "./parser/string.js";
6
5
  export const Generic = GenericRoot;
7
6
  export const emptyGenericParameterMessage = "An empty string is not a valid generic parameter name";
8
- export const parseGenericParams = (def, ctx) => parseName(new Scanner(def), [], ctx);
9
- const parseName = (scanner, result, ctx) => {
7
+ export const parseGenericParamName = (scanner, result, ctx) => {
10
8
  scanner.shiftUntilNonWhitespace();
11
9
  const name = scanner.shiftUntilNextTerminator();
12
10
  if (name === "") {
@@ -30,9 +28,9 @@ const _parseOptionalConstraint = (scanner, name, result, ctx) => {
30
28
  if (scanner.lookahead === ",")
31
29
  scanner.shift();
32
30
  result.push(name);
33
- return parseName(scanner, result, ctx);
31
+ return parseGenericParamName(scanner, result, ctx);
34
32
  }
35
- const s = parseUntilFinalizer(new DynamicState(scanner, ctx, false));
33
+ const s = parseUntilFinalizer(new DynamicState(scanner, ctx));
36
34
  result.push([name, s.root]);
37
- return parseName(scanner, result, ctx);
35
+ return parseGenericParamName(scanner, result, ctx);
38
36
  };
package/out/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  export { ArkError, ArkErrors, type ArkConfig, type ArkScopeConfig, type JsonSchema } from "@ark/schema";
2
- export { Hkt } from "@ark/util";
2
+ export { Hkt, inferred } from "@ark/util";
3
3
  export { Generic } from "./generic.ts";
4
- export { ambient, ark, declare, define, generic, type, type Ark } from "./keywords/ark.ts";
4
+ export { ark, declare, define, generic, keywords, type, type Ark } from "./keywords/keywords.ts";
5
5
  export { Module, type BoundModule, type Submodule } from "./module.ts";
6
- export { module, scope, type Scope, type inferScope, type validateScope } from "./scope.ts";
7
- export { Type, type inferAmbient, type inferTypeRoot, type validateAmbient, type validateTypeRoot } from "./type.ts";
6
+ export { module, scope, type Scope } from "./scope.ts";
7
+ export { Type } from "./type.ts";
package/out/index.js CHANGED
@@ -1,7 +1,7 @@
1
1
  export { ArkError, ArkErrors } from "@ark/schema";
2
- export { Hkt } from "@ark/util";
2
+ export { Hkt, inferred } from "@ark/util";
3
3
  export { Generic } from "./generic.js";
4
- export { ambient, ark, declare, define, generic, type } from "./keywords/ark.js";
4
+ export { ark, declare, define, generic, keywords, type } from "./keywords/keywords.js";
5
5
  export { Module } from "./module.js";
6
6
  export { module, scope } from "./scope.js";
7
7
  export { Type } from "./type.js";
@@ -1,10 +1,10 @@
1
1
  import { genericNode, intrinsic } from "@ark/schema";
2
2
  import { Hkt } from "@ark/util";
3
- import { submodule } from "./utils.js";
3
+ import { arkModule } from "./utils.js";
4
4
  class MergeHkt extends Hkt {
5
5
  }
6
6
  const Merge = genericNode(["base", intrinsic.object], ["props", intrinsic.object])(args => args.base.merge(args.props), MergeHkt);
7
- export const arkBuiltins = submodule({
7
+ export const arkBuiltins = arkModule({
8
8
  Key: intrinsic.key,
9
9
  Merge
10
10
  });
@@ -1,6 +1,6 @@
1
1
  import { Hkt, liftArray, type Digit } from "@ark/util";
2
2
  import type { Module, Submodule } from "../../module.ts";
3
- import type { To } from "../ast.ts";
3
+ import type { To } from "../inference.ts";
4
4
  declare class liftFromHkt extends Hkt<[element: unknown]> {
5
5
  body: liftArray<this[0]> extends infer lifted ? (In: this[0] | lifted) => To<lifted> : never;
6
6
  }
@@ -10,7 +10,7 @@ export declare namespace arkArray {
10
10
  type module = Module<submodule>;
11
11
  type submodule = Submodule<$>;
12
12
  type $ = {
13
- $root: unknown[];
13
+ root: unknown[];
14
14
  readonly: readonly unknown[];
15
15
  index: NonNegativeIntegerString;
16
16
  liftFrom: typeof liftFrom.t;
@@ -1,19 +1,19 @@
1
- import { genericNode, intrinsic, rootNode } from "@ark/schema";
1
+ import { genericNode, intrinsic, rootSchema } from "@ark/schema";
2
2
  import { Hkt, liftArray } from "@ark/util";
3
- import { submodule } from "../utils.js";
3
+ import { arkModule } from "../utils.js";
4
4
  class liftFromHkt extends Hkt {
5
5
  }
6
6
  const liftFrom = genericNode("element")(args => {
7
7
  const nonArrayElement = args.element.exclude(intrinsic.Array);
8
8
  const lifted = nonArrayElement.array();
9
9
  return nonArrayElement
10
- .or(lifted)
10
+ .rawOr(lifted)
11
11
  .pipe(liftArray)
12
- .distribute(branch => branch.assertHasKind("morph").declareOut(lifted), rootNode);
12
+ .distribute(branch => branch.assertHasKind("morph").declareOut(lifted), rootSchema);
13
13
  }, liftFromHkt);
14
- export const arkArray = submodule({
15
- $root: intrinsic.Array,
16
- readonly: "$root",
14
+ export const arkArray = arkModule({
15
+ root: intrinsic.Array,
16
+ readonly: "root",
17
17
  index: intrinsic.nonNegativeIntegerString,
18
18
  liftFrom
19
19
  });
@@ -0,0 +1,32 @@
1
+ import type { Branded, constrain, constraint, Constraints, Default, Literal, Narrowed, normalizeLimit, Optional } from "../inference.ts";
2
+ export type AtOrAfter<rule> = {
3
+ atOrAfter: constraint<rule>;
4
+ };
5
+ export type AtOrBefore<rule> = {
6
+ atOrBefore: constraint<rule>;
7
+ };
8
+ export type After<rule> = {
9
+ after: constraint<rule>;
10
+ };
11
+ export type Before<rule> = {
12
+ before: constraint<rule>;
13
+ };
14
+ export declare namespace Date {
15
+ type atOrAfter<rule> = constrain<Date, AtOrAfter<rule>>;
16
+ type after<rule> = constrain<Date, After<rule>>;
17
+ type atOrBefore<rule> = constrain<Date, AtOrBefore<rule>>;
18
+ type before<rule> = constrain<Date, Before<rule>>;
19
+ type narrowed = constrain<Date, Narrowed>;
20
+ type optional = constrain<Date, Optional>;
21
+ type defaultsTo<rule> = constrain<Date, Default<rule>>;
22
+ type branded<rule> = constrain<Date, Branded<rule>>;
23
+ type literal<rule> = constrain<Date, Literal<rule>>;
24
+ type is<constraints extends Constraints> = constrain<Date, constraints>;
25
+ type afterSchemaToConstraint<schema, rule> = schema extends {
26
+ exclusive: true;
27
+ } ? After<normalizeLimit<rule>> : AtOrAfter<normalizeLimit<rule>>;
28
+ type beforeSchemaToConstraint<schema, rule> = schema extends {
29
+ exclusive: true;
30
+ } ? Before<normalizeLimit<rule>> : AtOrBefore<normalizeLimit<rule>>;
31
+ type withConstraint<constraint> = constraint extends After<infer rule> ? after<rule> : constraint extends Before<infer rule> ? before<rule> : constraint extends AtOrAfter<infer rule> ? atOrAfter<rule> : constraint extends AtOrBefore<infer rule> ? atOrBefore<rule> : constraint extends Optional ? optional : constraint extends Default<infer rule> ? defaultsTo<rule> : constraint extends Narrowed ? narrowed : never;
32
+ }
@@ -1,5 +1,5 @@
1
1
  import type { Module, Submodule } from "../../module.ts";
2
- import type { To } from "../ast.ts";
2
+ import type { To } from "../inference.ts";
3
3
  export type FormDataValue = string | File;
4
4
  export type ParsedFormData = Record<string, FormDataValue | FormDataValue[]>;
5
5
  export declare const arkFormData: arkFormData.module;
@@ -7,7 +7,7 @@ export declare namespace arkFormData {
7
7
  type module = Module<submodule>;
8
8
  type submodule = Submodule<$>;
9
9
  type $ = {
10
- $root: FormData;
10
+ root: FormData;
11
11
  value: FormDataValue;
12
12
  parse: (In: FormData) => To<ParsedFormData>;
13
13
  parsed: ParsedFormData;
@@ -1,9 +1,9 @@
1
- import { rootNode } from "@ark/schema";
1
+ import { rootSchema } from "@ark/schema";
2
2
  import { registry } from "@ark/util";
3
- import { submodule } from "../utils.js";
4
- const value = rootNode(["string", registry.FileConstructor]);
5
- const parsedFormDataValue = value.or(value.array());
6
- const parsed = rootNode({
3
+ import { arkModule } from "../utils.js";
4
+ const value = rootSchema(["string", registry.FileConstructor]);
5
+ const parsedFormDataValue = value.rawOr(value.array());
6
+ const parsed = rootSchema({
7
7
  meta: "an object representing parsed form data",
8
8
  domain: "object",
9
9
  index: {
@@ -11,11 +11,11 @@ const parsed = rootNode({
11
11
  value: parsedFormDataValue
12
12
  }
13
13
  });
14
- export const arkFormData = submodule({
15
- $root: ["instanceof", FormData],
14
+ export const arkFormData = arkModule({
15
+ root: ["instanceof", FormData],
16
16
  value,
17
17
  parsed,
18
- parse: rootNode({
18
+ parse: rootSchema({
19
19
  in: FormData,
20
20
  morphs: (data) => {
21
21
  const result = {};
@@ -1,5 +1,5 @@
1
- import { submodule } from "../utils.js";
2
- export const TypedArray = submodule({
1
+ import { arkModule } from "../utils.js";
2
+ export const TypedArray = arkModule({
3
3
  Int8: ["instanceof", Int8Array],
4
4
  Uint8: ["instanceof", Uint8Array],
5
5
  Uint8Clamped: ["instanceof", Uint8ClampedArray],
@@ -26,6 +26,5 @@ export declare namespace arkPrototypes {
26
26
  interface instances extends ecmascript, platform {
27
27
  }
28
28
  type instanceOf<name extends keyof instances = keyof instances> = instances[name];
29
- type instanceOfExcluding<name extends keyof instances = keyof instances> = instances[Exclude<keyof instances, name>];
30
29
  }
31
30
  export {};
@@ -1,5 +1,5 @@
1
1
  import { ecmascriptConstructors, flatMorph, platformConstructors } from "@ark/util";
2
- import { submodule } from "../utils.js";
2
+ import { arkModule } from "../utils.js";
3
3
  import { arkArray } from "./Array.js";
4
4
  import { arkFormData } from "./FormData.js";
5
5
  import { TypedArray } from "./TypedArray.js";
@@ -8,7 +8,7 @@ const omittedPrototypes = {
8
8
  Number: 1,
9
9
  String: 1
10
10
  };
11
- export const arkPrototypes = submodule({
11
+ export const arkPrototypes = arkModule({
12
12
  ...flatMorph({ ...ecmascriptConstructors, ...platformConstructors }, (k, v) => (k in omittedPrototypes ? [] : [k, ["instanceof", v]])),
13
13
  Array: arkArray,
14
14
  TypedArray,