arktype 2.0.0-rc.7 → 2.0.0-rc.9

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 (98) hide show
  1. package/out/config.d.ts +1 -1
  2. package/out/generic.d.ts +9 -9
  3. package/out/generic.js +2 -2
  4. package/out/index.d.ts +1 -1
  5. package/out/index.js +1 -1
  6. package/out/keywords/constructors/Array.d.ts +1 -1
  7. package/out/keywords/constructors/Date.d.ts +1 -1
  8. package/out/keywords/constructors/FormData.d.ts +1 -1
  9. package/out/keywords/{ast.d.ts → inference.d.ts} +42 -20
  10. package/out/keywords/{ark.d.ts → keywords.d.ts} +7 -3
  11. package/out/keywords/{ark.js → keywords.js} +7 -7
  12. package/out/keywords/number/number.d.ts +1 -1
  13. package/out/keywords/string/alpha.d.ts +1 -1
  14. package/out/keywords/string/alphanumeric.d.ts +1 -1
  15. package/out/keywords/string/capitalize.d.ts +1 -1
  16. package/out/keywords/string/creditCard.d.ts +1 -1
  17. package/out/keywords/string/date.d.ts +1 -1
  18. package/out/keywords/string/date.js +6 -6
  19. package/out/keywords/string/digits.d.ts +1 -1
  20. package/out/keywords/string/email.d.ts +1 -1
  21. package/out/keywords/string/integer.d.ts +1 -1
  22. package/out/keywords/string/ip.d.ts +1 -1
  23. package/out/keywords/string/json.d.ts +2 -1
  24. package/out/keywords/string/json.js +18 -10
  25. package/out/keywords/string/lower.d.ts +1 -1
  26. package/out/keywords/string/normalize.d.ts +1 -1
  27. package/out/keywords/string/numeric.d.ts +1 -1
  28. package/out/keywords/string/semver.d.ts +1 -1
  29. package/out/keywords/string/string.d.ts +7 -7
  30. package/out/keywords/string/trim.d.ts +1 -1
  31. package/out/keywords/string/upper.d.ts +1 -1
  32. package/out/keywords/string/url.d.ts +1 -1
  33. package/out/keywords/string/uuid.d.ts +1 -1
  34. package/out/methods/array.d.ts +1 -1
  35. package/out/methods/base.d.ts +26 -23
  36. package/out/methods/date.d.ts +1 -1
  37. package/out/methods/instantiate.d.ts +5 -4
  38. package/out/methods/morph.d.ts +3 -4
  39. package/out/methods/number.d.ts +1 -1
  40. package/out/methods/object.d.ts +55 -30
  41. package/out/methods/string.d.ts +1 -1
  42. package/out/methods/validator.d.ts +1 -1
  43. package/out/parser/{semantic → ast}/bounds.d.ts +3 -3
  44. package/out/parser/{semantic → ast}/default.d.ts +2 -2
  45. package/out/parser/{semantic → ast}/infer.d.ts +6 -8
  46. package/out/parser/{semantic → ast}/utils.d.ts +1 -1
  47. package/out/parser/{semantic → ast}/validate.d.ts +5 -5
  48. package/out/parser/definition.d.ts +5 -5
  49. package/out/parser/objectLiteral.d.ts +3 -3
  50. package/out/parser/{string/reduce → reduce}/dynamic.d.ts +2 -2
  51. package/out/parser/{string/reduce → reduce}/shared.d.ts +1 -1
  52. package/out/parser/{string/reduce → reduce}/static.d.ts +1 -1
  53. package/out/parser/{string/shift → shift}/operand/date.d.ts +1 -1
  54. package/out/parser/{string/shift → shift}/operand/enclosed.d.ts +3 -3
  55. package/out/parser/{string/shift → shift}/operand/unenclosed.d.ts +3 -3
  56. package/out/parser/{string/shift → shift}/operand/unenclosed.js +1 -1
  57. package/out/parser/{string/shift → shift}/operator/bounds.d.ts +3 -3
  58. package/out/parser/{string/shift → shift}/operator/default.d.ts +1 -1
  59. package/out/parser/{string/shift → shift}/scanner.d.ts +3 -1
  60. package/out/parser/{string/shift → shift}/scanner.js +5 -3
  61. package/out/parser/{string/string.d.ts → string.d.ts} +4 -4
  62. package/out/parser/{string/string.js → string.js} +2 -0
  63. package/out/parser/tuple.d.ts +47 -36
  64. package/out/parser/tuple.js +5 -10
  65. package/out/scope.d.ts +4 -4
  66. package/out/scope.js +4 -4
  67. package/out/type.d.ts +8 -10
  68. package/out/type.js +2 -1
  69. package/package.json +3 -3
  70. package/out/intersect.d.ts +0 -26
  71. package/out/intersect.js +0 -1
  72. package/out/keys.d.ts +0 -18
  73. package/out/keys.js +0 -1
  74. /package/out/keywords/{ast.js → inference.js} +0 -0
  75. /package/out/parser/{semantic → ast}/bounds.js +0 -0
  76. /package/out/parser/{semantic → ast}/default.js +0 -0
  77. /package/out/parser/{semantic → ast}/divisor.d.ts +0 -0
  78. /package/out/parser/{semantic → ast}/divisor.js +0 -0
  79. /package/out/parser/{semantic → ast}/infer.js +0 -0
  80. /package/out/parser/{semantic → ast}/keyof.d.ts +0 -0
  81. /package/out/parser/{semantic → ast}/keyof.js +0 -0
  82. /package/out/parser/{semantic → ast}/utils.js +0 -0
  83. /package/out/parser/{semantic → ast}/validate.js +0 -0
  84. /package/out/parser/{string/reduce → reduce}/dynamic.js +0 -0
  85. /package/out/parser/{string/reduce → reduce}/shared.js +0 -0
  86. /package/out/parser/{string/reduce → reduce}/static.js +0 -0
  87. /package/out/parser/{string/shift → shift}/operand/date.js +0 -0
  88. /package/out/parser/{string/shift → shift}/operand/enclosed.js +0 -0
  89. /package/out/parser/{string/shift → shift}/operand/genericArgs.d.ts +0 -0
  90. /package/out/parser/{string/shift → shift}/operand/genericArgs.js +0 -0
  91. /package/out/parser/{string/shift → shift}/operand/operand.d.ts +0 -0
  92. /package/out/parser/{string/shift → shift}/operand/operand.js +0 -0
  93. /package/out/parser/{string/shift → shift}/operator/bounds.js +0 -0
  94. /package/out/parser/{string/shift → shift}/operator/default.js +0 -0
  95. /package/out/parser/{string/shift → shift}/operator/divisor.d.ts +0 -0
  96. /package/out/parser/{string/shift → shift}/operator/divisor.js +0 -0
  97. /package/out/parser/{string/shift → shift}/operator/operator.d.ts +0 -0
  98. /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,12 +1,12 @@
1
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/ark.ts";
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";
4
6
  import type { inferDefinition, validateDefinition } from "./parser/definition.ts";
5
- import type { inferAstRoot } from "./parser/semantic/infer.ts";
6
- import type { validateAst } from "./parser/semantic/validate.ts";
7
- import type { state, StaticState } from "./parser/string/reduce/static.ts";
8
- import type { Scanner } from "./parser/string/shift/scanner.ts";
9
- import { parseUntilFinalizer } from "./parser/string/string.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
10
  import type { Scope } from "./scope.ts";
11
11
  import type { Type } from "./type.ts";
12
12
  export type ParameterString<params extends string = string> = `<${params}>`;
@@ -16,9 +16,9 @@ export type validateGenericArg<arg, param extends GenericParamAst, $> = type.inf
16
16
  export type GenericInstantiator<params extends array<GenericParamAst>, def, $, args$> = params["length"] extends 1 ? {
17
17
  <const a, r = instantiateGeneric<def, params, [a], $, args$>>(a: type.validate<a, args$> & validateGenericArg<a, params[0], args$>): r;
18
18
  } : params["length"] extends 2 ? {
19
- <const a, const b, r = instantiateGeneric<def, params, [a, b], $, args$>>(...args: [type.validate<a, args$>, type.validate<b, args$>] & [
20
- validateGenericArg<a, params[0], args$>,
21
- 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$>
22
22
  ]): r;
23
23
  } : params["length"] extends 3 ? {
24
24
  <const a, const b, const c, r = instantiateGeneric<def, params, [a, b, c], $, args$>>(...args: [
package/out/generic.js CHANGED
@@ -1,7 +1,7 @@
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 { parseUntilFinalizer } from "./parser/string/string.js";
3
+ import { DynamicState } from "./parser/reduce/dynamic.js";
4
+ import { parseUntilFinalizer } from "./parser/string.js";
5
5
  export const Generic = GenericRoot;
6
6
  export const emptyGenericParameterMessage = "An empty string is not a valid generic parameter name";
7
7
  export const parseGenericParamName = (scanner, result, ctx) => {
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
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
6
  export { module, scope, type Scope } from "./scope.ts";
7
7
  export { Type } from "./type.ts";
package/out/index.js CHANGED
@@ -1,7 +1,7 @@
1
1
  export { ArkError, ArkErrors } from "@ark/schema";
2
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,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
  }
@@ -1,4 +1,4 @@
1
- import type { Branded, constrain, constraint, Constraints, Literal, Narrowed, normalizeLimit, Optional } from "../ast.ts";
1
+ import type { Branded, constrain, constraint, Constraints, Literal, Narrowed, normalizeLimit, Optional } from "../inference.ts";
2
2
  export type AtOrAfter<rule> = {
3
3
  atOrAfter: constraint<rule>;
4
4
  };
@@ -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;
@@ -1,10 +1,9 @@
1
1
  import type { ArkError, ArkErrors, Constraint, constraintKindOf, Morph, NodeSchema } from "@ark/schema";
2
- import { type anyOrNever, type array, type conform, type equals, type isSafelyMappable, type leftIfEqual, type objectKindOf, type Primitive, type show } from "@ark/util";
3
- import type { inferPipe } from "../intersect.ts";
2
+ import { type anyOrNever, type array, type conform, type equals, type Hkt, type intersectArrays, type isSafelyMappable, type leftIfEqual, type objectKindOf, type Primitive, type show } from "@ark/util";
4
3
  import type { Type } from "../type.ts";
5
- import type { type } from "./ark.ts";
6
4
  import type { arkPrototypes } from "./constructors/constructors.ts";
7
5
  import type { Date } from "./constructors/Date.ts";
6
+ import type { type } from "./keywords.ts";
8
7
  import type { DivisibleBy, number } from "./number/number.ts";
9
8
  import type { Matching, string } from "./string/string.ts";
10
9
  export type { arkPrototypes as object } from "./constructors/constructors.ts";
@@ -53,7 +52,7 @@ export type ExactlyLength<rule> = {
53
52
  atLeastLength: constraint<rule>;
54
53
  atMostLength: constraint<rule>;
55
54
  };
56
- export type applyConstraintSchema<t, kind extends Constraint.PrimitiveKind, schema extends NodeSchema<kind>> = t extends MorphAst<infer i, infer o> ? (In: leftIfEqual<i, applyConstraint<i, schemaToConstraint<kind, schema>>>) => o : leftIfEqual<t, applyConstraint<t, schemaToConstraint<kind, schema>>>;
55
+ export type applyConstraintSchema<t, kind extends Constraint.PrimitiveKind, schema extends NodeSchema<kind>> = t extends InferredMorph<infer i, infer o> ? (In: leftIfEqual<i, applyConstraint<i, schemaToConstraint<kind, schema>>>) => o : leftIfEqual<t, applyConstraint<t, schemaToConstraint<kind, schema>>>;
57
56
  export type applyConstraint<t, constraint> = parseConstraints<t> extends ([
58
57
  infer base,
59
58
  infer constraints extends Constraints
@@ -152,25 +151,25 @@ export type includesMorphs<t> = [
152
151
  type _distill<t, opts extends distill.Options> = t extends undefined ? t : [t] extends [anyOrNever] ? t : parseConstraints<t> extends ([
153
152
  infer base,
154
153
  infer constraints extends Constraints
155
- ]) ? opts["branded"] extends true ? constrain<_distill<base, opts>, constraints> : _distill<base, opts> : unknown extends t ? unknown : t extends TerminallyInferredObject | Primitive ? t : t extends MorphAst<infer i, infer o> ? opts["branded"] extends true ? distillIo<i, o, opts> : distillUnbrandedIo<t, i, o, opts> : t extends array ? distillArray<t, opts> : t extends DefaultedAst<infer t> ? _distill<t, opts> : t extends Function ? t : isSafelyMappable<t> extends true ? distillMappable<t, opts> : t;
154
+ ]) ? opts["branded"] extends true ? constrain<_distill<base, opts>, constraints> : _distill<base, opts> : unknown extends t ? unknown : t extends TerminallyInferredObject | Primitive ? t : t extends InferredMorph<infer i, infer o> ? opts["branded"] extends true ? distillIo<i, o, opts> : distillUnbrandedIo<t, i, o, opts> : t extends array ? distillArray<t, opts> : t extends InferredDefault<infer t> ? _distill<t, opts> : t extends Function ? t : isSafelyMappable<t> extends true ? distillMappable<t, opts> : t;
156
155
  type distillMappable<o, opts extends distill.Options> = opts["endpoint"] extends "in" ? show<{
157
- [k in keyof o as k extends optionalInputKeyOf<o> ? never : k]: _distill<o[k], opts>;
156
+ [k in keyof o as k extends inferredOptionalOrDefaultKeyOf<o> ? never : k]: _distill<o[k], opts>;
158
157
  } & {
159
- [k in optionalInputKeyOf<o>]?: _distill<o[k], opts>;
158
+ [k in inferredOptionalOrDefaultKeyOf<o>]?: _distill<o[k], opts>;
160
159
  }> : show<{
161
- [k in keyof o as k extends metaOptionalKeyOf<o> ? never : k]: _distill<o[k], opts>;
160
+ [k in keyof o as k extends inferredOptionalKeyOf<o> ? never : k]: _distill<o[k], opts>;
162
161
  } & {
163
- [k in keyof o as k extends metaOptionalKeyOf<o> ? k : never]?: _distill<o[k], opts>;
162
+ [k in keyof o as k extends inferredOptionalKeyOf<o> ? k : never]?: _distill<o[k], opts>;
164
163
  }>;
165
- type distillUnbrandedIo<t extends MorphAst, i, o extends Out, opts extends distill.Options> = t extends (MorphAst<constrain<infer constrainedIn, any>, Out<constrain<infer constrainedOut, any>>>) ? distillIo<constrainedIn, o extends To ? To<constrainedOut> : Out<constrainedOut>, opts> : t extends MorphAst<constrain<infer constrainedIn, any>> ? distillIo<constrainedIn, o, opts> : t extends MorphAst<any, Out<constrain<infer constrainedOut, any>>> ? distillIo<i, o extends To ? To<constrainedOut> : Out<constrainedOut>, opts> : distillIo<i, o, opts>;
164
+ type distillUnbrandedIo<t extends InferredMorph, i, o extends Out, opts extends distill.Options> = t extends (InferredMorph<constrain<infer constrainedIn, any>, Out<constrain<infer constrainedOut, any>>>) ? distillIo<constrainedIn, o extends To ? To<constrainedOut> : Out<constrainedOut>, opts> : t extends InferredMorph<constrain<infer constrainedIn, any>> ? distillIo<constrainedIn, o, opts> : t extends InferredMorph<any, Out<constrain<infer constrainedOut, any>>> ? distillIo<i, o extends To ? To<constrainedOut> : Out<constrainedOut>, opts> : distillIo<i, o, opts>;
166
165
  type distillIo<i, o extends Out, opts extends distill.Options> = opts["endpoint"] extends "in" ? _distill<i, opts> : opts["endpoint"] extends "out.introspectable" ? o extends To<infer validatedOut> ? _distill<validatedOut, opts> : unknown : opts["endpoint"] extends "out" ? _distill<o[1], opts> : _distill<o[1], opts> extends infer r ? o extends To ? (In: i) => To<r> : (In: i) => Out<r> : never;
167
- type optionalInputKeyOf<o> = metaDefaultedKeyOf<o> | metaOptionalKeyOf<o>;
168
- type metaDefaultedKeyOf<o> = {
169
- [k in keyof o]: [o[k]] extends [anyOrNever] ? never : o[k] extends DefaultedAst ? k : never;
170
- }[keyof o];
171
- type metaOptionalKeyOf<o> = {
172
- [k in keyof o]: [o[k]] extends [anyOrNever] ? never : o[k] extends OptionalAst ? k : never;
173
- }[keyof o];
166
+ type inferredOptionalOrDefaultKeyOf<o> = inferredDefaultKeyOf<o> | inferredOptionalKeyOf<o>;
167
+ type inferredDefaultKeyOf<o> = keyof o extends infer k ? k extends keyof o ? [
168
+ o[k]
169
+ ] extends [anyOrNever] ? never : o[k] extends InferredDefault ? k : never : never : never;
170
+ type inferredOptionalKeyOf<o> = keyof o extends infer k ? k extends keyof o ? [
171
+ o[k]
172
+ ] extends [anyOrNever] ? never : o[k] extends InferredOptional ? k : never : never : never;
174
173
  type distillArray<t extends array, opts extends distill.Options> = _distillArray<[...t], opts, []> extends infer result ? distillNonArraykeys<t, t extends unknown[] ? result : Readonly<t>, opts> : never;
175
174
  type distillNonArraykeys<originalArray extends array, distilledArray, opts extends distill.Options> = keyof originalArray extends keyof distilledArray | constrained ? distilledArray : distilledArray & _distill<{
176
175
  [k in keyof originalArray as k extends (keyof distilledArray | (opts["branded"] extends true ? never : constrained)) ? never : k]: originalArray[k];
@@ -188,11 +187,34 @@ export type inferPipes<t, pipes extends Morph[]> = pipes extends [infer head ext
188
187
  export type inferMorphOut<morph extends Morph> = Exclude<ReturnType<morph>, ArkError | ArkErrors>;
189
188
  export type Out<o = any> = ["=>", o, boolean];
190
189
  export type To<o = any> = ["=>", o, true];
191
- export type MorphAst<i = any, o extends Out = Out> = (In: i) => o;
190
+ export type InferredMorph<i = any, o extends Out = Out> = (In: i) => o;
192
191
  export type Optional = {
193
192
  optional?: {};
194
193
  };
195
- export type OptionalAst<t = unknown> = constrain<t, Optional>;
194
+ export type InferredOptional<t = unknown> = constrain<t, Optional>;
196
195
  export type Default<v = any> = ["=", v];
197
- export type DefaultedAst<t = any, v = any> = (In?: t) => Default<v>;
196
+ export type InferredDefault<t = any, v = any> = (In?: t) => Default<v>;
198
197
  export type termOrType<t> = t | Type<t, any>;
198
+ export type inferIntersection<l, r> = _inferIntersection<l, r, false>;
199
+ export type inferPipe<l, r> = _inferIntersection<l, r, true>;
200
+ type _inferIntersection<l, r, piped extends boolean> = [
201
+ l & r
202
+ ] extends [infer t extends anyOrNever] ? t : l extends InferredMorph<infer lIn, infer lOut> ? r extends InferredMorph<any, infer rOut> ? piped extends true ? (In: lIn) => rOut : never : piped extends true ? (In: lIn) => To<r> : (In: _inferIntersection<lIn, r, false>) => lOut : r extends InferredMorph<infer rIn, infer rOut> ? (In: _inferIntersection<rIn, l, false>) => rOut : parseConstraints<l> extends ([
203
+ infer lBase,
204
+ infer lConstraints extends Constraints
205
+ ]) ? parseConstraints<r> extends ([
206
+ infer rBase,
207
+ infer rConstraints extends Constraints
208
+ ]) ? constrain<_inferIntersection<lBase, rBase, piped>, lConstraints & rConstraints> : constrain<_inferIntersection<lBase, r, piped>, lConstraints> : parseConstraints<r> extends ([
209
+ infer rBase,
210
+ infer rConstraints extends Constraints
211
+ ]) ? constrain<_inferIntersection<l, rBase, piped>, rConstraints> : [l, r] extends [object, object] ? intersectObjects<l, r, piped> extends infer result ? result : never : l & r;
212
+ interface MorphableIntersection<piped extends boolean> extends Hkt<[unknown, unknown]> {
213
+ body: _inferIntersection<this[0], this[1], piped>;
214
+ }
215
+ type intersectObjects<l, r, piped extends boolean> = l extends array ? r extends array ? intersectArrays<l, r, MorphableIntersection<piped>> : // for an intersection with exactly one array operand like { name: string } & string[],
216
+ l & r : r extends array ? l & r : show<{
217
+ [k in keyof l]: k extends keyof r ? _inferIntersection<l[k], r[k], piped> : l[k];
218
+ } & {
219
+ [k in keyof r]: k extends keyof l ? _inferIntersection<l[k], r[k], piped> : r[k];
220
+ }>;
@@ -1,13 +1,14 @@
1
1
  import type { ArkErrors, arkKind } from "@ark/schema";
2
2
  import type { inferred } from "@ark/util";
3
3
  import type { GenericParser } from "../generic.ts";
4
+ import type { BaseType } from "../methods/base.ts";
4
5
  import type { BoundModule, Module } from "../module.ts";
5
6
  import type { inferDefinition, validateDefinition } from "../parser/definition.ts";
6
7
  import { type bindThis, type Scope } from "../scope.ts";
7
8
  import type { DeclarationParser, DefinitionParser, SchemaParser, Type, TypeParser } from "../type.ts";
8
- import type { distill } from "./ast.ts";
9
9
  import { arkBuiltins } from "./builtins.ts";
10
10
  import { arkPrototypes } from "./constructors/constructors.ts";
11
+ import type { distill } from "./inference.ts";
11
12
  import { number } from "./number/number.ts";
12
13
  import { string } from "./string/string.ts";
13
14
  import { arkTsGenerics, arkTsKeywords, unknown } from "./ts.ts";
@@ -28,14 +29,17 @@ export declare namespace Ark {
28
29
  interface boundTypeAttachments<$> extends Omit<BoundModule<typeAttachments, $>, arkKind> {
29
30
  }
30
31
  }
31
- export declare const ambient: Scope<Ark>;
32
- export declare const ark: Module<Ark>;
32
+ export declare const ark: Scope<Ark>;
33
+ export declare const keywords: Module<Ark>;
33
34
  export declare const type: TypeParser<{}>;
34
35
  export declare namespace type {
35
36
  type cast<t> = {
36
37
  [inferred]?: t;
37
38
  };
38
39
  type errors = ArkErrors;
40
+ /** @ts-ignore cast variance */
41
+ interface Any<out t = any> extends BaseType<t, any> {
42
+ }
39
43
  type infer<def, $ = {}, args = bindThis<def>> = inferDefinition<def, $, args>;
40
44
  namespace infer {
41
45
  type In<def, $ = {}, args = {}> = distill.In<inferDefinition<def, $, args>>;
@@ -9,7 +9,7 @@ $arkTypeRegistry.typeAttachments = {
9
9
  Key: arkBuiltins.Key,
10
10
  Record: arkTsGenerics.Record
11
11
  };
12
- export const ambient = scope({
12
+ export const ark = scope({
13
13
  ...arkTsKeywords,
14
14
  ...arkTsGenerics,
15
15
  ...arkPrototypes,
@@ -18,9 +18,9 @@ export const ambient = scope({
18
18
  number,
19
19
  unknown
20
20
  }, { prereducedAliases: true, ambient: true });
21
- export const ark = ambient.export();
22
- export const type = ambient.type;
23
- export const generic = ambient.generic;
24
- export const schema = ambient.schema;
25
- export const define = ambient.define;
26
- export const declare = ambient.declare;
21
+ export const keywords = ark.export();
22
+ export const type = ark.type;
23
+ export const generic = ark.generic;
24
+ export const schema = ark.schema;
25
+ export const define = ark.define;
26
+ export const declare = ark.declare;
@@ -1,5 +1,5 @@
1
1
  import type { Module, Submodule } from "../../module.ts";
2
- import type { Branded, constrain, constraint, Constraints, Narrowed, Optional } from "../ast.ts";
2
+ import type { Branded, constrain, constraint, Constraints, Narrowed, Optional } from "../inference.ts";
3
3
  import { epoch } from "./epoch.ts";
4
4
  import { integer } from "./integer.ts";
5
5
  export declare const number: number.module;
@@ -1,4 +1,4 @@
1
- import type { Branded, constrain } from "../ast.ts";
1
+ import type { Branded, constrain } from "../inference.ts";
2
2
  declare namespace string {
3
3
  type alpha = constrain<string, Branded<"alpha">>;
4
4
  }
@@ -1,4 +1,4 @@
1
- import type { Branded, constrain } from "../ast.ts";
1
+ import type { Branded, constrain } from "../inference.ts";
2
2
  declare namespace string {
3
3
  type alphanumeric = constrain<string, Branded<"alphanumeric">>;
4
4
  }
@@ -1,5 +1,5 @@
1
1
  import type { Module, Submodule } from "../../module.ts";
2
- import type { Branded, constrain, To } from "../ast.ts";
2
+ import type { Branded, constrain, To } from "../inference.ts";
3
3
  declare namespace string {
4
4
  type capitalized = constrain<string, Branded<"capitalized">>;
5
5
  }
@@ -1,4 +1,4 @@
1
- import type { Branded, constrain } from "../ast.ts";
1
+ import type { Branded, constrain } from "../inference.ts";
2
2
  export declare const isLuhnValid: (creditCardInput: string) => boolean;
3
3
  declare namespace string {
4
4
  type creditCard = constrain<string, Branded<"creditCard">>;
@@ -1,5 +1,5 @@
1
1
  import type { Module, Submodule } from "../../module.ts";
2
- import type { Branded, To, constrain } from "../ast.ts";
2
+ import type { Branded, To, constrain } from "../inference.ts";
3
3
  type DayDelimiter = "." | "/" | "-";
4
4
  type DayPart = DayPatterns[PartKey];
5
5
  type PartKey = keyof DayPatterns;
@@ -47,7 +47,7 @@ const parsableDate = rootSchema({
47
47
  predicate: isParsableDate
48
48
  }
49
49
  }).assertHasKind("intersection");
50
- const epochroot = integer.root.internal
50
+ const epochRoot = integer.root.internal
51
51
  .narrow((s, ctx) => {
52
52
  // we know this is safe since it has already
53
53
  // been validated as an integer string
@@ -64,18 +64,18 @@ const epochroot = integer.root.internal
64
64
  })
65
65
  .assertHasKind("intersection");
66
66
  const epoch = arkModule({
67
- root: epochroot,
67
+ root: epochRoot,
68
68
  parse: rootSchema({
69
- in: epochroot,
69
+ in: epochRoot,
70
70
  morphs: (s) => new Date(s),
71
71
  declaredOut: intrinsic.Date
72
72
  })
73
73
  });
74
- const isoroot = regexStringNode(iso8601Matcher, "an ISO 8601 (YYYY-MM-DDTHH:mm:ss.sssZ) date").internal.assertHasKind("intersection");
74
+ const isoRoot = regexStringNode(iso8601Matcher, "an ISO 8601 (YYYY-MM-DDTHH:mm:ss.sssZ) date").internal.assertHasKind("intersection");
75
75
  const iso = arkModule({
76
- root: isoroot,
76
+ root: isoRoot,
77
77
  parse: rootSchema({
78
- in: isoroot,
78
+ in: isoRoot,
79
79
  morphs: (s) => new Date(s),
80
80
  declaredOut: intrinsic.Date
81
81
  })
@@ -1,4 +1,4 @@
1
- import type { Branded, constrain } from "../ast.ts";
1
+ import type { Branded, constrain } from "../inference.ts";
2
2
  declare namespace string {
3
3
  type digits = constrain<string, Branded<"digits">>;
4
4
  }
@@ -1,4 +1,4 @@
1
- import type { Branded, constrain } from "../ast.ts";
1
+ import type { Branded, constrain } from "../inference.ts";
2
2
  declare namespace string {
3
3
  type email = constrain<string, Branded<"email">>;
4
4
  }
@@ -1,5 +1,5 @@
1
1
  import type { Module, Submodule } from "../../module.ts";
2
- import type { Branded, constrain, To } from "../ast.ts";
2
+ import type { Branded, constrain, To } from "../inference.ts";
3
3
  import type { number } from "../number/number.ts";
4
4
  declare namespace string {
5
5
  type integer = constrain<string, Branded<"integer">>;
@@ -1,5 +1,5 @@
1
1
  import type { Module, Submodule } from "../../module.ts";
2
- import type { Branded, constrain } from "../ast.ts";
2
+ import type { Branded, constrain } from "../inference.ts";
3
3
  declare namespace string {
4
4
  type ip = constrain<string, Branded<"ip">>;
5
5
  namespace ip {
@@ -1,8 +1,9 @@
1
1
  import type { Module, Submodule } from "../../module.ts";
2
- import type { Branded, To, constrain } from "../ast.ts";
2
+ import type { Branded, To, constrain } from "../inference.ts";
3
3
  declare namespace string {
4
4
  type json = constrain<string, Branded<"json">>;
5
5
  }
6
+ export declare const writeJsonSyntaxErrorProblem: (error: unknown) => string;
6
7
  export declare const json: stringJson.module;
7
8
  export declare namespace stringJson {
8
9
  type module = Module<submodule>;
@@ -1,20 +1,28 @@
1
1
  import { intrinsic, rootSchema } from "@ark/schema";
2
2
  import { arkModule } from "../utils.js";
3
3
  const jsonStringDescription = "a JSON string";
4
- const isParsableJson = (s) => {
5
- try {
6
- JSON.parse(s);
7
- return true;
8
- }
9
- catch {
10
- return false;
11
- }
4
+ export const writeJsonSyntaxErrorProblem = (error) => {
5
+ if (!(error instanceof SyntaxError))
6
+ throw error;
7
+ return `must be ${jsonStringDescription} (${error})`;
12
8
  };
13
9
  const root = rootSchema({
14
10
  domain: "string",
15
11
  predicate: {
16
12
  meta: jsonStringDescription,
17
- predicate: isParsableJson
13
+ predicate: (s, ctx) => {
14
+ try {
15
+ JSON.parse(s);
16
+ return true;
17
+ }
18
+ catch (e) {
19
+ return ctx.reject({
20
+ code: "predicate",
21
+ expected: jsonStringDescription,
22
+ problem: writeJsonSyntaxErrorProblem(e)
23
+ });
24
+ }
25
+ }
18
26
  }
19
27
  });
20
28
  export const json = arkModule({
@@ -36,7 +44,7 @@ export const json = arkModule({
36
44
  return ctx.error({
37
45
  code: "predicate",
38
46
  expected: jsonStringDescription,
39
- problem: `must be ${jsonStringDescription} (${e})`
47
+ problem: writeJsonSyntaxErrorProblem(e)
40
48
  });
41
49
  }
42
50
  },
@@ -1,5 +1,5 @@
1
1
  import type { Module, Submodule } from "../../module.ts";
2
- import type { Branded, constrain, To } from "../ast.ts";
2
+ import type { Branded, constrain, To } from "../inference.ts";
3
3
  declare namespace string {
4
4
  type lowercase = constrain<string, Branded<"lowercase">>;
5
5
  }
@@ -1,5 +1,5 @@
1
1
  import type { Module, Submodule } from "../../module.ts";
2
- import type { Branded, constrain, To } from "../ast.ts";
2
+ import type { Branded, constrain, To } from "../inference.ts";
3
3
  declare namespace string {
4
4
  type normalized = normalized.NFC;
5
5
  namespace normalized {
@@ -1,5 +1,5 @@
1
1
  import type { Module, Submodule } from "../../module.ts";
2
- import type { Branded, constrain, To } from "../ast.ts";
2
+ import type { Branded, constrain, To } from "../inference.ts";
3
3
  declare namespace string {
4
4
  type numeric = constrain<string, Branded<"numeric">>;
5
5
  }
@@ -1,4 +1,4 @@
1
- import type { Branded, constrain } from "../ast.ts";
1
+ import type { Branded, constrain } from "../inference.ts";
2
2
  declare namespace string {
3
3
  type semver = constrain<string, Branded<"semver">>;
4
4
  }
@@ -1,5 +1,5 @@
1
1
  import type { Module, Submodule } from "../../module.ts";
2
- import type { AtLeastLength, AtMostLength, Branded, Constraints, ExactlyLength, LessThanLength, MoreThanLength, Narrowed, Optional, constrain, constraint } from "../ast.ts";
2
+ import type { AtLeastLength, AtMostLength, Branded, Constraints, ExactlyLength, LessThanLength, MoreThanLength, Narrowed, Optional, constrain, constraint } from "../inference.ts";
3
3
  import { alpha } from "./alpha.ts";
4
4
  import { alphanumeric } from "./alphanumeric.ts";
5
5
  import { capitalize } from "./capitalize.ts";
@@ -19,6 +19,7 @@ import { upper } from "./upper.ts";
19
19
  import { url } from "./url.ts";
20
20
  import { uuid } from "./uuid.ts";
21
21
  export declare const string: Module<{
22
+ root: unknown;
22
23
  trim: Submodule<trim.submodule>;
23
24
  normalize: Submodule<{
24
25
  root: unknown;
@@ -39,15 +40,12 @@ export declare const string: Module<{
39
40
  preformatted: unknown;
40
41
  }>;
41
42
  }>;
42
- root: unknown;
43
- date: Submodule<stringDate.submodule>;
44
- lower: Submodule<lower.submodule>;
45
- upper: Submodule<upper.submodule>;
46
- integer: Submodule<stringInteger.submodule>;
47
- json: Submodule<stringJson.submodule>;
48
43
  alpha: unknown;
49
44
  alphanumeric: unknown;
45
+ json: Submodule<stringJson.submodule>;
50
46
  creditCard: unknown;
47
+ integer: Submodule<stringInteger.submodule>;
48
+ date: Submodule<stringDate.submodule>;
51
49
  digits: unknown;
52
50
  email: unknown;
53
51
  ip: Submodule<ip.submodule>;
@@ -65,6 +63,8 @@ export declare const string: Module<{
65
63
  v7: unknown;
66
64
  v8: unknown;
67
65
  }>;
66
+ upper: Submodule<upper.submodule>;
67
+ lower: Submodule<lower.submodule>;
68
68
  capitalize: Submodule<capitalize.submodule>;
69
69
  }>;
70
70
  export type Matching<rule> = {
@@ -1,5 +1,5 @@
1
1
  import type { Module, Submodule } from "../../module.ts";
2
- import type { Branded, constrain, To } from "../ast.ts";
2
+ import type { Branded, constrain, To } from "../inference.ts";
3
3
  declare namespace string {
4
4
  type trimmed = constrain<string, Branded<"trimmed">>;
5
5
  }
@@ -1,5 +1,5 @@
1
1
  import type { Module, Submodule } from "../../module.ts";
2
- import type { Branded, constrain, To } from "../ast.ts";
2
+ import type { Branded, constrain, To } from "../inference.ts";
3
3
  declare namespace string {
4
4
  type uppercase = constrain<string, Branded<"uppercase">>;
5
5
  }
@@ -1,5 +1,5 @@
1
1
  import type { Module, Submodule } from "../../module.ts";
2
- import type { Branded, constrain, To } from "../ast.ts";
2
+ import type { Branded, constrain, To } from "../inference.ts";
3
3
  declare namespace string {
4
4
  type url = constrain<string, Branded<"url">>;
5
5
  }
@@ -1,5 +1,5 @@
1
1
  import type { Module, Submodule } from "../../module.ts";
2
- import type { Branded, constrain } from "../ast.ts";
2
+ import type { Branded, constrain } from "../inference.ts";
3
3
  export declare const uuid: Module<{
4
4
  root: import("./string.ts").string.matching<string> | "00000000-0000-0000-0000-000000000000" | "ffffffff-ffff-ffff-ffff-ffffffffffff";
5
5
  v4: unknown;
@@ -1,5 +1,5 @@
1
1
  import type { ExactLength, ExclusiveNumericRangeSchema, exclusivizeRangeSchema, InclusiveNumericRangeSchema } from "@ark/schema";
2
- import type { applyConstraintSchema } from "../keywords/ast.ts";
2
+ import type { applyConstraintSchema } from "../keywords/inference.ts";
3
3
  import type { ObjectType } from "./object.ts";
4
4
  interface Type<
5
5
  /** @ts-ignore cast variance */