arktype 2.0.0-beta.5 → 2.0.0-beta.6
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.
- package/out/ast.d.ts +7 -10
- package/out/ast.js +0 -1
- package/out/config.d.ts +17 -2
- package/out/generic.d.ts +9 -16
- package/out/generic.js +1 -2
- package/out/index.d.ts +6 -7
- package/out/index.js +1 -1
- package/out/intersect.d.ts +1 -1
- package/out/keys.d.ts +2 -2
- package/out/keywords/ark.d.ts +40 -0
- package/out/keywords/ark.js +28 -0
- package/out/keywords/builtin.d.ts +26 -0
- package/out/keywords/builtin.js +21 -0
- package/out/keywords/format.d.ts +13 -10
- package/out/keywords/format.js +4 -1
- package/out/keywords/js.d.ts +18 -0
- package/out/keywords/{jsObjects.js → js.js} +4 -1
- package/out/keywords/number.d.ts +23 -0
- package/out/keywords/number.js +44 -0
- package/out/keywords/parse.d.ts +19 -0
- package/out/keywords/{parsing.js → parse.js} +9 -4
- package/out/keywords/platform.d.ts +16 -0
- package/out/keywords/{platformObjects.js → platform.js} +4 -1
- package/out/keywords/string.d.ts +31 -0
- package/out/keywords/string.js +89 -0
- package/out/keywords/ts.d.ts +58 -0
- package/out/keywords/ts.js +55 -0
- package/out/keywords/typedArray.d.ts +18 -15
- package/out/keywords/typedArray.js +4 -1
- package/out/keywords/utils/date.d.ts +1 -0
- package/out/keywords/utils/date.js +1 -1
- package/out/keywords/utils/ip.d.ts +16 -3
- package/out/keywords/utils/ip.js +10 -4
- package/out/keywords/utils/regex.d.ts +3 -2
- package/out/keywords/utils/uuid.d.ts +30 -0
- package/out/keywords/utils/uuid.js +22 -0
- package/out/module.d.ts +2 -2
- package/out/parser/definition.d.ts +9 -9
- package/out/parser/objectLiteral.d.ts +8 -6
- package/out/parser/semantic/bounds.d.ts +6 -6
- package/out/parser/semantic/default.d.ts +4 -4
- package/out/parser/semantic/divisor.d.ts +2 -2
- package/out/parser/semantic/infer.d.ts +8 -8
- package/out/parser/semantic/keyof.d.ts +2 -2
- package/out/parser/semantic/utils.d.ts +2 -2
- package/out/parser/semantic/validate.d.ts +12 -12
- package/out/parser/string/reduce/dynamic.d.ts +8 -8
- package/out/parser/string/reduce/dynamic.js +3 -3
- package/out/parser/string/reduce/shared.d.ts +1 -1
- package/out/parser/string/reduce/static.d.ts +19 -20
- package/out/parser/string/shift/operand/date.d.ts +1 -3
- package/out/parser/string/shift/operand/enclosed.d.ts +3 -3
- package/out/parser/string/shift/operand/genericArgs.d.ts +4 -4
- package/out/parser/string/shift/operand/operand.d.ts +6 -6
- package/out/parser/string/shift/operand/unenclosed.d.ts +12 -10
- package/out/parser/string/shift/operand/unenclosed.js +2 -2
- package/out/parser/string/shift/operator/bounds.d.ts +8 -12
- package/out/parser/string/shift/operator/bounds.js +0 -4
- package/out/parser/string/shift/operator/default.d.ts +4 -10
- package/out/parser/string/shift/operator/default.js +0 -6
- package/out/parser/string/shift/operator/divisor.d.ts +3 -3
- package/out/parser/string/shift/operator/operator.d.ts +5 -5
- package/out/parser/string/shift/scanner.d.ts +16 -16
- package/out/parser/string/shift/scanner.js +6 -8
- package/out/parser/string/string.d.ts +9 -9
- package/out/parser/tuple.d.ts +7 -7
- package/out/parser/tuple.js +2 -1
- package/out/scope.d.ts +24 -19
- package/out/scope.js +65 -111
- package/out/subtypes/array.d.ts +2 -2
- package/out/subtypes/base.d.ts +9 -8
- package/out/subtypes/date.d.ts +2 -2
- package/out/subtypes/instantiate.d.ts +8 -8
- package/out/subtypes/morph.d.ts +4 -4
- package/out/subtypes/number.d.ts +2 -2
- package/out/subtypes/object.d.ts +6 -6
- package/out/subtypes/string.d.ts +2 -2
- package/out/subtypes/validator.d.ts +3 -3
- package/out/type.d.ts +7 -7
- package/package.json +17 -8
- package/out/ark.d.ts +0 -33
- package/out/ark.js +0 -28
- package/out/keywords/arkGenerics.d.ts +0 -19
- package/out/keywords/arkGenerics.js +0 -19
- package/out/keywords/internal.d.ts +0 -11
- package/out/keywords/internal.js +0 -25
- package/out/keywords/jsObjects.d.ts +0 -15
- package/out/keywords/parsing.d.ts +0 -16
- package/out/keywords/platformObjects.d.ts +0 -13
- package/out/keywords/tsGenerics.d.ts +0 -37
- package/out/keywords/tsGenerics.js +0 -45
- package/out/keywords/tsKeywords.d.ts +0 -18
- package/out/keywords/tsKeywords.js +0 -17
- package/out/keywords/validation.d.ts +0 -19
- package/out/keywords/validation.js +0 -84
package/out/ast.d.ts
CHANGED
|
@@ -1,12 +1,10 @@
|
|
|
1
1
|
import type { ArkError, ArkErrors, Constraint, constraintKindOf, Morph, NodeSchema } from "@ark/schema";
|
|
2
2
|
import { type anyOrNever, type array, type BuiltinObjectKind, type BuiltinObjects, type conform, type equals, type leftIfEqual, type Primitive, type propValueOf, type show } from "@ark/util";
|
|
3
|
-
import type {
|
|
4
|
-
import type {
|
|
5
|
-
import type {
|
|
6
|
-
import type {
|
|
7
|
-
import type { Type } from "./type.
|
|
8
|
-
export declare const inferred: " arkInferred";
|
|
9
|
-
export type inferred = typeof inferred;
|
|
3
|
+
import type { inferPipe } from "./intersect.ts";
|
|
4
|
+
import type { type } from "./keywords/ark.ts";
|
|
5
|
+
import type { arkPlatform } from "./keywords/platform.ts";
|
|
6
|
+
import type { arkTypedArray } from "./keywords/typedArray.ts";
|
|
7
|
+
import type { Type } from "./type.ts";
|
|
10
8
|
export type Comparator = "<" | "<=" | ">" | ">=" | "==";
|
|
11
9
|
export type RegexLiteral<source extends string = string> = `/${source}/`;
|
|
12
10
|
export type DateLiteral<source extends string = string> = `d"${source}"` | `d'${source}'`;
|
|
@@ -46,10 +44,9 @@ export type Length<rule> = {
|
|
|
46
44
|
export type Matching<rule> = {
|
|
47
45
|
matching: constraint<rule>;
|
|
48
46
|
};
|
|
49
|
-
export type anonymous = "?";
|
|
50
47
|
export type Narrowed = {
|
|
51
48
|
predicate: {
|
|
52
|
-
[k in
|
|
49
|
+
[k in "?"]: 1;
|
|
53
50
|
};
|
|
54
51
|
};
|
|
55
52
|
export type primitiveConstraintKindOf<In> = Extract<Constraint.PrimitiveKind, constraintKindOf<In>>;
|
|
@@ -203,7 +200,7 @@ type distillPostfix<t extends array, io extends IoKind, constraints extends Dist
|
|
|
203
200
|
[i in keyof t]: _distill<t[i], io, constraints>;
|
|
204
201
|
}, ...postfix];
|
|
205
202
|
/** Objects we don't want to expand during inference like Date or Promise */
|
|
206
|
-
type TerminallyInferredObjectKind = ArkEnv.prototypes | BuiltinObjects[Exclude<BuiltinObjectKind, "Array" | "Function">] | propValueOf<
|
|
203
|
+
type TerminallyInferredObjectKind = ArkEnv.prototypes | BuiltinObjects[Exclude<BuiltinObjectKind, "Array" | "Function">] | propValueOf<arkPlatform.keywords> | propValueOf<arkTypedArray.submodule>;
|
|
207
204
|
export type inferPredicate<t, predicate> = predicate extends (data: any, ...args: any[]) => data is infer narrowed ? t extends constrain<unknown, infer constraints> ? applyConstraint<constrain<narrowed, constraints>, "predicate", any> : applyConstraint<narrowed, "predicate", any> : applyConstraint<t, "predicate", any>;
|
|
208
205
|
export type constrainWithPredicate<t> = t extends constrain<unknown, infer constraints> ? applyConstraint<constrain<t, constraints>, "predicate", any> : applyConstraint<t, "predicate", any>;
|
|
209
206
|
export type inferPipes<t, pipes extends Morph[]> = pipes extends [infer head extends Morph, ...infer tail extends Morph[]] ? inferPipes<pipes[0] extends type.cast<infer tPipe> ? inferPipe<t, tPipe> : inferMorphOut<head> extends infer out ? (In: distillConstrainableIn<t>) => Out<out> : never, tail> : t;
|
package/out/ast.js
CHANGED
package/out/config.d.ts
CHANGED
|
@@ -1,13 +1,28 @@
|
|
|
1
1
|
import type { ArkSchemaRegistry } from "@ark/schema";
|
|
2
|
-
import type { Ark } from "./ark.
|
|
3
|
-
import type { exportScope } from "./module.
|
|
2
|
+
import type { Ark } from "./keywords/ark.ts";
|
|
3
|
+
import type { exportScope } from "./module.ts";
|
|
4
4
|
export * from "@ark/schema/config";
|
|
5
5
|
export interface ArkTypeRegistryContents extends ArkSchemaRegistry {
|
|
6
6
|
ambient: exportScope<Ark>;
|
|
7
7
|
}
|
|
8
8
|
declare global {
|
|
9
9
|
export interface ArkEnv {
|
|
10
|
+
$(): Ark;
|
|
10
11
|
}
|
|
11
12
|
export namespace ArkEnv {
|
|
13
|
+
type $ = ReturnType<ArkEnv["$"]>;
|
|
12
14
|
}
|
|
13
15
|
}
|
|
16
|
+
/**
|
|
17
|
+
* This mirrors the global ArkEnv namespace as a local export. We use it instead
|
|
18
|
+
* of the global internally due to a bug in twoslash that prevents `ark/docs`
|
|
19
|
+
* from building if we refer to the global directly.
|
|
20
|
+
*
|
|
21
|
+
* If, in the future, docs can build while arktype refers to `ArkEnv.$` directly,
|
|
22
|
+
* this can be removed.
|
|
23
|
+
*/
|
|
24
|
+
export declare namespace ArkAmbient {
|
|
25
|
+
type $ = ArkEnv.$;
|
|
26
|
+
type meta = ArkEnv.meta;
|
|
27
|
+
type prototypes = ArkEnv.prototypes;
|
|
28
|
+
}
|
package/out/generic.d.ts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import type { arkKind, GenericAst, GenericParamAst, GenericParamDef, genericParamNames, GenericRoot, LazyGenericBody } from "@ark/schema";
|
|
2
2
|
import { type array, type Callable, type conform, type ErrorMessage, type ErrorType, type Hkt, type WhiteSpaceToken } from "@ark/util";
|
|
3
|
-
import type { inferDefinition } from "./parser/definition.
|
|
4
|
-
import type { inferAstRoot } from "./parser/semantic/infer.
|
|
5
|
-
import type { validateAst } from "./parser/semantic/validate.
|
|
6
|
-
import type { state, StaticState } from "./parser/string/reduce/static.
|
|
7
|
-
import { Scanner } from "./parser/string/shift/scanner.
|
|
8
|
-
import { parseUntilFinalizer } from "./parser/string/string.
|
|
9
|
-
import type { ParseContext, Scope } from "./scope.
|
|
10
|
-
import type { inferTypeRoot, Type, validateTypeRoot } from "./type.
|
|
3
|
+
import type { inferDefinition } 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";
|
|
11
11
|
export type ParameterString<params extends string = string> = `<${params}>`;
|
|
12
12
|
export type extractParams<s extends ParameterString> = s extends ParameterString<infer params> ? params : never;
|
|
13
13
|
export type validateParameterString<s extends ParameterString, $> = parseGenericParams<extractParams<s>, $> extends infer e extends ErrorMessage ? e : s;
|
|
@@ -126,14 +126,7 @@ export type emptyGenericParameterMessage = typeof emptyGenericParameterMessage;
|
|
|
126
126
|
export declare const parseGenericParams: (def: string, ctx: ParseContext) => array<GenericParamDef>;
|
|
127
127
|
export type parseGenericParams<def extends string, $> = parseNextNameChar<Scanner.skipWhitespace<def>, "", [
|
|
128
128
|
], $>;
|
|
129
|
-
|
|
130
|
-
",": boolean;
|
|
131
|
-
":": boolean;
|
|
132
|
-
" ": true;
|
|
133
|
-
"\n": true;
|
|
134
|
-
"\t": true;
|
|
135
|
-
};
|
|
136
|
-
type ParamsTerminator = keyof typeof paramsTerminators;
|
|
129
|
+
type ParamsTerminator = WhiteSpaceToken | "," | ":";
|
|
137
130
|
declare const parseName: (scanner: Scanner, result: GenericParamDef[], ctx: ParseContext) => GenericParamDef[];
|
|
138
131
|
type parseName<unscanned extends string, result extends array<GenericParamAst>, $> = parseNextNameChar<Scanner.skipWhitespace<unscanned>, "", result, $>;
|
|
139
132
|
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<unscanned, name, result, $> : never : parseNextNameChar<nextUnscanned, `${name}${lookahead}`, result, $> : name extends "" ? result : [...result, [name, unknown]];
|
package/out/generic.js
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
import { throwParseError
|
|
1
|
+
import { throwParseError } from "@ark/util";
|
|
2
2
|
import { DynamicState } from "./parser/string/reduce/dynamic.js";
|
|
3
3
|
import { Scanner } from "./parser/string/shift/scanner.js";
|
|
4
4
|
import { parseUntilFinalizer } from "./parser/string/string.js";
|
|
5
5
|
export const emptyGenericParameterMessage = "An empty string is not a valid generic parameter name";
|
|
6
6
|
export const parseGenericParams = (def, ctx) => parseName(new Scanner(def), [], ctx);
|
|
7
|
-
const paramsTerminators = { ...whiteSpaceTokens, ",": true, ":": true };
|
|
8
7
|
const parseName = (scanner, result, ctx) => {
|
|
9
8
|
scanner.shiftUntilNonWhitespace();
|
|
10
9
|
const name = scanner.shiftUntilNextTerminator();
|
package/out/index.d.ts
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
export { ArkError, ArkErrors } from "@ark/schema";
|
|
2
|
-
export type { ArkConfig, ArkScopeConfig } from "@ark/schema";
|
|
1
|
+
export { ArkError, ArkErrors, type ArkConfig, type ArkScopeConfig, type JsonSchema } from "@ark/schema";
|
|
3
2
|
export { Hkt } from "@ark/util";
|
|
4
|
-
export {
|
|
5
|
-
export
|
|
6
|
-
export { Module, type
|
|
7
|
-
export { scope, type Scope, type inferScope, type validateScope } from "./scope.
|
|
8
|
-
export { Type, type inferAmbient, type inferTypeRoot, type validateAmbient, type validateTypeRoot } from "./type.
|
|
3
|
+
export type { Generic } from "./generic.ts";
|
|
4
|
+
export { ambient, ark, declare, define, generic, type } from "./keywords/ark.ts";
|
|
5
|
+
export { Module, type BoundModule, type Submodule } from "./module.ts";
|
|
6
|
+
export { scope, type Scope, type inferScope, type validateScope } from "./scope.ts";
|
|
7
|
+
export { Type, type inferAmbient, type inferTypeRoot, type validateAmbient, type validateTypeRoot } from "./type.ts";
|
package/out/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export { ArkError, ArkErrors } from "@ark/schema";
|
|
2
2
|
export { Hkt } from "@ark/util";
|
|
3
|
-
export { ambient, ark, declare, define, generic, type } from "./ark.js";
|
|
3
|
+
export { ambient, ark, declare, define, generic, type } from "./keywords/ark.js";
|
|
4
4
|
export { Module } from "./module.js";
|
|
5
5
|
export { scope } from "./scope.js";
|
|
6
6
|
export { Type } from "./type.js";
|
package/out/intersect.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { anyOrNever, array, Hkt, intersectArrays, show } from "@ark/util";
|
|
2
|
-
import type { constrain, Constraints, MorphAst, parseConstraints, To } from "./ast.
|
|
2
|
+
import type { constrain, Constraints, MorphAst, parseConstraints, To } from "./ast.ts";
|
|
3
3
|
export type inferIntersection<l, r> = _inferIntersection<l, r, false>;
|
|
4
4
|
export type inferPipe<l, r> = _inferIntersection<l, r, true>;
|
|
5
5
|
type _inferIntersection<l, r, piped extends boolean> = [
|
package/out/keys.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { array, join, Key, NonNegativeIntegerLiteral, typeToString } from "@ark/util";
|
|
2
|
-
import type {
|
|
3
|
-
import type {
|
|
2
|
+
import type { termOrType } from "./ast.ts";
|
|
3
|
+
import type { type } from "./keywords/ark.ts";
|
|
4
4
|
export type toArkKey<o, k extends keyof o> = k extends number ? [
|
|
5
5
|
o,
|
|
6
6
|
number
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import type { ArkErrors } from "@ark/schema";
|
|
2
|
+
import type { inferred } from "@ark/util";
|
|
3
|
+
import type { GenericHktParser } from "../generic.ts";
|
|
4
|
+
import type { Module } from "../module.ts";
|
|
5
|
+
import { type Scope } from "../scope.ts";
|
|
6
|
+
import type { DeclarationParser, DefinitionParser, TypeParser } from "../type.ts";
|
|
7
|
+
import { arkBuiltin } from "./builtin.ts";
|
|
8
|
+
import { arkFormat } from "./format.ts";
|
|
9
|
+
import { arkJs } from "./js.ts";
|
|
10
|
+
import { arkNumber } from "./number.ts";
|
|
11
|
+
import { arkParse } from "./parse.ts";
|
|
12
|
+
import { arkPlatform } from "./platform.ts";
|
|
13
|
+
import { arkString } from "./string.ts";
|
|
14
|
+
import { arkTs } from "./ts.ts";
|
|
15
|
+
import { arkTypedArray } from "./typedArray.ts";
|
|
16
|
+
export interface Ark extends Omit<Ark.keywords, keyof Ark.Wrapped>, Ark.Wrapped {
|
|
17
|
+
TypedArray: arkTypedArray.submodule;
|
|
18
|
+
parse: arkParse.submodule;
|
|
19
|
+
format: arkFormat.submodule;
|
|
20
|
+
}
|
|
21
|
+
export declare namespace Ark {
|
|
22
|
+
interface keywords extends arkTs.keywords, arkJs.keywords, arkPlatform.keywords, arkString.keywords, arkNumber.keywords, arkBuiltin.keywords {
|
|
23
|
+
}
|
|
24
|
+
interface Wrapped {
|
|
25
|
+
string: arkString.submodule;
|
|
26
|
+
number: arkNumber.submodule;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
export declare const ambient: Scope<Ark>;
|
|
30
|
+
export declare const ark: Module<Ark>;
|
|
31
|
+
export declare const type: TypeParser<{}>;
|
|
32
|
+
export declare namespace type {
|
|
33
|
+
type cast<t> = {
|
|
34
|
+
[inferred]?: t;
|
|
35
|
+
};
|
|
36
|
+
type errors = ArkErrors;
|
|
37
|
+
}
|
|
38
|
+
export declare const generic: GenericHktParser<{}>;
|
|
39
|
+
export declare const define: DefinitionParser<{}>;
|
|
40
|
+
export declare const declare: DeclarationParser<{}>;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { scope } from "../scope.js";
|
|
2
|
+
import { arkBuiltin } from "./builtin.js";
|
|
3
|
+
import { arkFormat } from "./format.js";
|
|
4
|
+
import { arkJs } from "./js.js";
|
|
5
|
+
import { arkNumber } from "./number.js";
|
|
6
|
+
import { arkParse } from "./parse.js";
|
|
7
|
+
import { arkPlatform } from "./platform.js";
|
|
8
|
+
import { arkString } from "./string.js";
|
|
9
|
+
import { arkTs } from "./ts.js";
|
|
10
|
+
import { arkTypedArray } from "./typedArray.js";
|
|
11
|
+
export const ambient = scope({
|
|
12
|
+
...arkTs.keywords,
|
|
13
|
+
...arkJs.keywords,
|
|
14
|
+
...arkPlatform.keywords,
|
|
15
|
+
...arkString.keywords,
|
|
16
|
+
...arkNumber.keywords,
|
|
17
|
+
...arkBuiltin.keywords,
|
|
18
|
+
string: arkString.submodule,
|
|
19
|
+
number: arkNumber.submodule,
|
|
20
|
+
TypedArray: arkTypedArray.submodule,
|
|
21
|
+
parse: arkParse.submodule,
|
|
22
|
+
format: arkFormat.submodule
|
|
23
|
+
}, { prereducedAliases: true, ambient: true });
|
|
24
|
+
export const ark = ambient.export();
|
|
25
|
+
export const type = ambient.type;
|
|
26
|
+
export const generic = ambient.generic;
|
|
27
|
+
export const define = ambient.define;
|
|
28
|
+
export const declare = ambient.declare;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import * as util from "@ark/util";
|
|
2
|
+
import { Hkt, type Digit, type Key } from "@ark/util";
|
|
3
|
+
import type { Module } from "../module.ts";
|
|
4
|
+
import type { Out } from "../ast.ts";
|
|
5
|
+
import "./ts.ts";
|
|
6
|
+
declare class liftArrayHkt extends Hkt<[element: unknown]> {
|
|
7
|
+
body: util.liftArray<this[0]> extends infer lifted ? (In: this[0] | lifted) => Out<lifted> : never;
|
|
8
|
+
}
|
|
9
|
+
declare const liftArray: import("@ark/schema").GenericRoot<readonly [["element", unknown]], liftArrayHkt>;
|
|
10
|
+
declare class mergeHkt extends Hkt<[base: object, props: object]> {
|
|
11
|
+
body: util.merge<this[0], this[1]>;
|
|
12
|
+
}
|
|
13
|
+
declare const merge: import("@ark/schema").GenericRoot<readonly [["base", object], ["props", object]], mergeHkt>;
|
|
14
|
+
export type NonNegativeIntegerString = `${Digit}` | (`${Exclude<Digit, 0>}${string}` & `${bigint}`);
|
|
15
|
+
export declare const arkBuiltin: {
|
|
16
|
+
keywords: Module<arkBuiltin.keywords>;
|
|
17
|
+
};
|
|
18
|
+
export declare namespace arkBuiltin {
|
|
19
|
+
interface keywords {
|
|
20
|
+
key: Key;
|
|
21
|
+
nonNegativeIntegerString: NonNegativeIntegerString;
|
|
22
|
+
liftArray: typeof liftArray.t;
|
|
23
|
+
merge: typeof merge.t;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
export {};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import * as util from "@ark/util";
|
|
2
|
+
import { Hkt } from "@ark/util";
|
|
3
|
+
import { scope } from "../scope.js";
|
|
4
|
+
// these are needed to create some internal types
|
|
5
|
+
import { genericNode, intrinsic } from "@ark/schema";
|
|
6
|
+
import "./ts.js";
|
|
7
|
+
class liftArrayHkt extends Hkt {
|
|
8
|
+
}
|
|
9
|
+
const liftArray = genericNode("element")(args => args.element.or(args.element.array()).pipe(util.liftArray), liftArrayHkt);
|
|
10
|
+
class mergeHkt extends Hkt {
|
|
11
|
+
}
|
|
12
|
+
const merge = genericNode(["base", intrinsic.object], ["props", intrinsic.object])(args => args.base.merge(args.props), mergeHkt);
|
|
13
|
+
const keywords = scope({
|
|
14
|
+
key: intrinsic.key,
|
|
15
|
+
nonNegativeIntegerString: intrinsic.nonNegativeIntegerString,
|
|
16
|
+
liftArray,
|
|
17
|
+
merge
|
|
18
|
+
}).export();
|
|
19
|
+
export const arkBuiltin = {
|
|
20
|
+
keywords
|
|
21
|
+
};
|
package/out/keywords/format.d.ts
CHANGED
|
@@ -1,11 +1,14 @@
|
|
|
1
|
-
import type { Out } from "../ast.
|
|
2
|
-
import type { Module } from "../module.
|
|
3
|
-
export
|
|
4
|
-
|
|
5
|
-
uppercase: (In: string) => Out<string>;
|
|
6
|
-
lowercase: (In: string) => Out<string>;
|
|
7
|
-
capitalize: (In: string) => Out<string>;
|
|
8
|
-
normalize: (In: string) => Out<string>;
|
|
1
|
+
import type { Out } from "../ast.ts";
|
|
2
|
+
import type { Module, Submodule } from "../module.ts";
|
|
3
|
+
export declare const arkFormat: {
|
|
4
|
+
submodule: Module<arkFormat.submodule>;
|
|
9
5
|
};
|
|
10
|
-
export
|
|
11
|
-
|
|
6
|
+
export declare namespace arkFormat {
|
|
7
|
+
type submodule = Submodule<{
|
|
8
|
+
trim: (In: string) => Out<string>;
|
|
9
|
+
uppercase: (In: string) => Out<string>;
|
|
10
|
+
lowercase: (In: string) => Out<string>;
|
|
11
|
+
capitalize: (In: string) => Out<string>;
|
|
12
|
+
normalize: (In: string) => Out<string>;
|
|
13
|
+
}>;
|
|
14
|
+
}
|
package/out/keywords/format.js
CHANGED
|
@@ -20,7 +20,7 @@ const normalize = rootNode({
|
|
|
20
20
|
in: "string",
|
|
21
21
|
morphs: (s) => s.normalize()
|
|
22
22
|
});
|
|
23
|
-
|
|
23
|
+
const submodule = scope({
|
|
24
24
|
trim,
|
|
25
25
|
uppercase,
|
|
26
26
|
lowercase,
|
|
@@ -29,3 +29,6 @@ export const formatting = scope({
|
|
|
29
29
|
}, {
|
|
30
30
|
prereducedAliases: true
|
|
31
31
|
}).export();
|
|
32
|
+
export const arkFormat = {
|
|
33
|
+
submodule
|
|
34
|
+
};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { Module } from "../module.ts";
|
|
2
|
+
export declare const arkJs: {
|
|
3
|
+
keywords: Module<arkJs.keywords>;
|
|
4
|
+
};
|
|
5
|
+
export declare namespace arkJs {
|
|
6
|
+
interface keywords {
|
|
7
|
+
Array: Array<unknown>;
|
|
8
|
+
Date: Date;
|
|
9
|
+
Error: Error;
|
|
10
|
+
Function: Function;
|
|
11
|
+
Map: Map<unknown, unknown>;
|
|
12
|
+
RegExp: RegExp;
|
|
13
|
+
Set: Set<unknown>;
|
|
14
|
+
WeakMap: WeakMap<object, unknown>;
|
|
15
|
+
WeakSet: WeakSet<object>;
|
|
16
|
+
Promise: Promise<unknown>;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { scope } from "../scope.js";
|
|
2
|
-
|
|
2
|
+
const keywords = scope({
|
|
3
3
|
Array: ["instanceof", Array],
|
|
4
4
|
Date: ["instanceof", Date],
|
|
5
5
|
Error: ["instanceof", Error],
|
|
@@ -11,3 +11,6 @@ export const jsObjects = scope({
|
|
|
11
11
|
WeakSet: ["instanceof", WeakSet],
|
|
12
12
|
Promise: ["instanceof", Promise]
|
|
13
13
|
}, { prereducedAliases: true }).export();
|
|
14
|
+
export const arkJs = {
|
|
15
|
+
keywords
|
|
16
|
+
};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { AtLeast, AtMost, DivisibleBy, number } from "../ast.ts";
|
|
2
|
+
import type { Module, Submodule } from "../module.ts";
|
|
3
|
+
/**
|
|
4
|
+
* As per the ECMA-262 specification:
|
|
5
|
+
* A time value supports a slightly smaller range of -8,640,000,000,000,000 to 8,640,000,000,000,000 milliseconds.
|
|
6
|
+
*
|
|
7
|
+
* @see https://262.ecma-international.org/15.0/index.html#sec-time-values-and-time-range
|
|
8
|
+
*/
|
|
9
|
+
export declare const epoch: import("@ark/schema").BaseRoot<import("@ark/schema").InternalRootDeclaration>;
|
|
10
|
+
export declare namespace arkNumber {
|
|
11
|
+
interface keywords {
|
|
12
|
+
integer: number.divisibleBy<1>;
|
|
13
|
+
}
|
|
14
|
+
interface $ extends keywords {
|
|
15
|
+
$root: number;
|
|
16
|
+
epoch: number.is<DivisibleBy<1> & AtMost<8640000000000000> & AtLeast<-8640000000000000>>;
|
|
17
|
+
}
|
|
18
|
+
type submodule = Submodule<$>;
|
|
19
|
+
}
|
|
20
|
+
export declare const arkNumber: {
|
|
21
|
+
keywords: Module<arkNumber.keywords>;
|
|
22
|
+
submodule: Module<arkNumber.submodule>;
|
|
23
|
+
};
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { intrinsic, rootNode } from "@ark/schema";
|
|
2
|
+
import { scope } from "../scope.js";
|
|
3
|
+
/**
|
|
4
|
+
* As per the ECMA-262 specification:
|
|
5
|
+
* A time value supports a slightly smaller range of -8,640,000,000,000,000 to 8,640,000,000,000,000 milliseconds.
|
|
6
|
+
*
|
|
7
|
+
* @see https://262.ecma-international.org/15.0/index.html#sec-time-values-and-time-range
|
|
8
|
+
*/
|
|
9
|
+
export const epoch = rootNode({
|
|
10
|
+
domain: {
|
|
11
|
+
domain: "number",
|
|
12
|
+
meta: "a number representing a Unix timestamp"
|
|
13
|
+
},
|
|
14
|
+
divisor: {
|
|
15
|
+
rule: 1,
|
|
16
|
+
meta: `an integer representing a Unix timestamp`
|
|
17
|
+
},
|
|
18
|
+
min: {
|
|
19
|
+
rule: -8640000000000000,
|
|
20
|
+
meta: `a Unix timestamp after -8640000000000000`
|
|
21
|
+
},
|
|
22
|
+
max: {
|
|
23
|
+
rule: 8640000000000000,
|
|
24
|
+
meta: "a Unix timestamp before 8640000000000000"
|
|
25
|
+
},
|
|
26
|
+
meta: "an integer representing a safe Unix timestamp"
|
|
27
|
+
});
|
|
28
|
+
const keywords = scope({
|
|
29
|
+
integer: rootNode({
|
|
30
|
+
domain: "number",
|
|
31
|
+
divisor: 1
|
|
32
|
+
})
|
|
33
|
+
}, { prereducedAliases: true }).export();
|
|
34
|
+
const submodule = scope({
|
|
35
|
+
...keywords,
|
|
36
|
+
$root: intrinsic.number,
|
|
37
|
+
epoch
|
|
38
|
+
}, {
|
|
39
|
+
prereducedAliases: true
|
|
40
|
+
}).export();
|
|
41
|
+
export const arkNumber = {
|
|
42
|
+
keywords,
|
|
43
|
+
submodule
|
|
44
|
+
};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { Out, number } from "../ast.ts";
|
|
2
|
+
import type { Module, Submodule } from "../module.ts";
|
|
3
|
+
declare const number: import("@ark/schema").BaseRoot<import("@ark/schema").InternalRootDeclaration>;
|
|
4
|
+
export type FormDataValue = string | File;
|
|
5
|
+
export type ParsedFormData = Record<string, FormDataValue | FormDataValue[]>;
|
|
6
|
+
export declare const arkParse: {
|
|
7
|
+
submodule: Module<arkParse.submodule>;
|
|
8
|
+
};
|
|
9
|
+
export declare namespace arkParse {
|
|
10
|
+
type submodule = Submodule<{
|
|
11
|
+
url: (In: string) => Out<URL>;
|
|
12
|
+
number: (In: string) => Out<number>;
|
|
13
|
+
integer: (In: string) => Out<number.divisibleBy<1>>;
|
|
14
|
+
date: (In: string) => Out<Date>;
|
|
15
|
+
json: (In: string) => Out<object>;
|
|
16
|
+
formData: (In: FormData) => Out<ParsedFormData>;
|
|
17
|
+
}>;
|
|
18
|
+
}
|
|
19
|
+
export {};
|
|
@@ -1,14 +1,16 @@
|
|
|
1
1
|
import { rootNode } from "@ark/schema";
|
|
2
|
-
import { isWellFormedInteger,
|
|
2
|
+
import { isWellFormedInteger, wellFormedNumberMatcher } from "@ark/util";
|
|
3
3
|
import { scope } from "../scope.js";
|
|
4
|
+
import { arkString } from "./string.js";
|
|
4
5
|
import { tryParseDatePattern } from "./utils/date.js";
|
|
5
6
|
import { regexStringNode } from "./utils/regex.js";
|
|
7
|
+
const parsableNumber = regexStringNode(wellFormedNumberMatcher, "a well-formed numeric string").internal;
|
|
6
8
|
const number = rootNode({
|
|
7
|
-
in:
|
|
9
|
+
in: parsableNumber,
|
|
8
10
|
morphs: (s) => Number.parseFloat(s)
|
|
9
11
|
});
|
|
10
12
|
const integer = rootNode({
|
|
11
|
-
in:
|
|
13
|
+
in: arkString.submodule.integer,
|
|
12
14
|
morphs: (s, ctx) => {
|
|
13
15
|
if (!isWellFormedInteger(s))
|
|
14
16
|
return ctx.error("a well-formed integer string");
|
|
@@ -65,7 +67,7 @@ const formData = rootNode({
|
|
|
65
67
|
return result;
|
|
66
68
|
}
|
|
67
69
|
});
|
|
68
|
-
|
|
70
|
+
const submodule = scope({
|
|
69
71
|
url,
|
|
70
72
|
number,
|
|
71
73
|
integer,
|
|
@@ -75,3 +77,6 @@ export const parsing = scope({
|
|
|
75
77
|
}, {
|
|
76
78
|
prereducedAliases: true
|
|
77
79
|
}).export();
|
|
80
|
+
export const arkParse = {
|
|
81
|
+
submodule
|
|
82
|
+
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { Module } from "../module.ts";
|
|
2
|
+
export declare const arkPlatform: {
|
|
3
|
+
keywords: Module<arkPlatform.keywords>;
|
|
4
|
+
};
|
|
5
|
+
export declare namespace arkPlatform {
|
|
6
|
+
type keywords = {
|
|
7
|
+
ArrayBuffer: ArrayBuffer;
|
|
8
|
+
Blob: Blob;
|
|
9
|
+
File: File;
|
|
10
|
+
FormData: FormData;
|
|
11
|
+
Headers: Headers;
|
|
12
|
+
Request: Request;
|
|
13
|
+
Response: Response;
|
|
14
|
+
URL: URL;
|
|
15
|
+
};
|
|
16
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { scope } from "../scope.js";
|
|
2
|
-
|
|
2
|
+
const keywords = scope({
|
|
3
3
|
ArrayBuffer: ["instanceof", ArrayBuffer],
|
|
4
4
|
Blob: ["instanceof", Blob],
|
|
5
5
|
// support Node18
|
|
@@ -10,3 +10,6 @@ export const platformObjects = scope({
|
|
|
10
10
|
Response: ["instanceof", Response],
|
|
11
11
|
URL: ["instanceof", URL]
|
|
12
12
|
}, { prereducedAliases: true }).export();
|
|
13
|
+
export const arkPlatform = {
|
|
14
|
+
keywords
|
|
15
|
+
};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { string } from "../ast.ts";
|
|
2
|
+
import type { Module, Submodule } from "../module.ts";
|
|
3
|
+
import { arkIp } from "./utils/ip.ts";
|
|
4
|
+
import { arkUuid } from "./utils/uuid.ts";
|
|
5
|
+
export declare const arkString: {
|
|
6
|
+
keywords: Module<arkString.keywords>;
|
|
7
|
+
submodule: Module<arkString.submodule>;
|
|
8
|
+
};
|
|
9
|
+
export declare namespace arkString {
|
|
10
|
+
interface keywords {
|
|
11
|
+
creditCard: string.matching<"?">;
|
|
12
|
+
email: string.matching<"?">;
|
|
13
|
+
uuid: arkUuid.submodule;
|
|
14
|
+
url: string.matching<"?">;
|
|
15
|
+
semver: string.matching<"?">;
|
|
16
|
+
ip: arkIp.submodule;
|
|
17
|
+
}
|
|
18
|
+
interface $ extends keywords {
|
|
19
|
+
$root: string;
|
|
20
|
+
alpha: string.matching<"?">;
|
|
21
|
+
alphanumeric: string.matching<"?">;
|
|
22
|
+
digits: string.matching<"?">;
|
|
23
|
+
lower: string.matching<"?">;
|
|
24
|
+
upper: string.matching<"?">;
|
|
25
|
+
numeric: string.narrowed;
|
|
26
|
+
integer: string.narrowed;
|
|
27
|
+
iso8601: string.narrowed;
|
|
28
|
+
epoch: string.narrowed;
|
|
29
|
+
}
|
|
30
|
+
type submodule = Submodule<$>;
|
|
31
|
+
}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { ArkErrors, intrinsic, rootNode } from "@ark/schema";
|
|
2
|
+
import { wellFormedIntegerMatcher, wellFormedNumberMatcher } from "@ark/util";
|
|
3
|
+
import { scope } from "../scope.js";
|
|
4
|
+
import { arkNumber } from "./number.js";
|
|
5
|
+
import { creditCardMatcher, isLuhnValid } from "./utils/creditCard.js";
|
|
6
|
+
import { iso8601Matcher } from "./utils/date.js";
|
|
7
|
+
import { arkIp } from "./utils/ip.js";
|
|
8
|
+
import { regexStringNode } from "./utils/regex.js";
|
|
9
|
+
import { arkUuid } from "./utils/uuid.js";
|
|
10
|
+
// Non-trivial expressions should have an explanation or attribution
|
|
11
|
+
const isValidUrl = (s) => {
|
|
12
|
+
if (URL.canParse)
|
|
13
|
+
return URL.canParse(s);
|
|
14
|
+
// Can be removed once Node 18 is EOL
|
|
15
|
+
try {
|
|
16
|
+
new URL(s);
|
|
17
|
+
}
|
|
18
|
+
catch {
|
|
19
|
+
return false;
|
|
20
|
+
}
|
|
21
|
+
return true;
|
|
22
|
+
};
|
|
23
|
+
const url = rootNode({
|
|
24
|
+
domain: "string",
|
|
25
|
+
predicate: {
|
|
26
|
+
meta: "a URL",
|
|
27
|
+
predicate: isValidUrl
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
// https://www.regular-expressions.info/email.html
|
|
31
|
+
const emailMatcher = /^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}$/;
|
|
32
|
+
const email = regexStringNode(emailMatcher, "an email address");
|
|
33
|
+
// https://semver.org/
|
|
34
|
+
const semverMatcher = /^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$/;
|
|
35
|
+
const semver = regexStringNode(semverMatcher, "a semantic version (see https://semver.org/)");
|
|
36
|
+
const creditCard = rootNode({
|
|
37
|
+
domain: "string",
|
|
38
|
+
pattern: {
|
|
39
|
+
meta: "a credit card number",
|
|
40
|
+
rule: creditCardMatcher.source
|
|
41
|
+
},
|
|
42
|
+
predicate: {
|
|
43
|
+
meta: "a credit card number",
|
|
44
|
+
predicate: isLuhnValid
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
const numericString = regexStringNode(wellFormedNumberMatcher, "a well-formed numeric string");
|
|
48
|
+
const integerString = regexStringNode(wellFormedIntegerMatcher, "a well-formed integer string");
|
|
49
|
+
const epoch = integerString
|
|
50
|
+
.narrow((s, ctx) => {
|
|
51
|
+
// we know this is safe since it has already
|
|
52
|
+
// been validated as an integer string
|
|
53
|
+
const n = Number.parseInt(s);
|
|
54
|
+
const out = arkNumber.submodule.epoch(n);
|
|
55
|
+
if (out instanceof ArkErrors) {
|
|
56
|
+
ctx.errors.merge(out);
|
|
57
|
+
return false;
|
|
58
|
+
}
|
|
59
|
+
return true;
|
|
60
|
+
})
|
|
61
|
+
.describe("an integer string representing a safe Unix timestamp");
|
|
62
|
+
const iso8601 = regexStringNode(iso8601Matcher, "an ISO 8601 (YYYY-MM-DDTHH:mm:ss.sssZ) date");
|
|
63
|
+
const keywords = scope({
|
|
64
|
+
creditCard,
|
|
65
|
+
email,
|
|
66
|
+
uuid: arkUuid.submodule,
|
|
67
|
+
url,
|
|
68
|
+
semver,
|
|
69
|
+
ip: arkIp.submodule
|
|
70
|
+
}, { prereducedAliases: true }).export();
|
|
71
|
+
const submodule = scope({
|
|
72
|
+
$root: intrinsic.string,
|
|
73
|
+
numeric: numericString,
|
|
74
|
+
integer: integerString,
|
|
75
|
+
alpha: regexStringNode(/^[A-Za-z]*$/, "only letters"),
|
|
76
|
+
alphanumeric: regexStringNode(/^[A-Za-z\d]*$/, "only letters and digits 0-9"),
|
|
77
|
+
digits: regexStringNode(/^\d*$/, "only digits 0-9"),
|
|
78
|
+
lower: regexStringNode(/^[a-z]*$/, "only lowercase letters"),
|
|
79
|
+
upper: regexStringNode(/^[A-Z]*$/, "only uppercase letters"),
|
|
80
|
+
iso8601,
|
|
81
|
+
epoch,
|
|
82
|
+
...keywords
|
|
83
|
+
}, {
|
|
84
|
+
prereducedAliases: true
|
|
85
|
+
}).export();
|
|
86
|
+
export const arkString = {
|
|
87
|
+
keywords,
|
|
88
|
+
submodule
|
|
89
|
+
};
|