arktype 2.0.0-dev.13 → 2.0.0-dev.15
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/LICENSE +7 -0
- package/out/api.d.ts +1 -1
- package/out/api.js +1 -1
- package/out/generic.d.ts +1 -1
- package/out/match.js +50 -52
- package/out/parser/definition.d.ts +1 -1
- package/out/parser/string/shift/operand/operand.d.ts +1 -1
- package/out/parser/string/shift/operand/operand.js +3 -3
- package/out/parser/string/shift/scanner.d.ts +6 -5
- package/out/parser/string/shift/scanner.js +3 -0
- package/out/scope.d.ts +1 -2
- package/out/type.d.ts +2 -2
- package/package.json +33 -36
- package/out/main.d.ts +0 -6
- package/out/main.js +0 -5
- package/out/package.json +0 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
Copyright 2023 ArkType
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
4
|
+
|
|
5
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
6
|
+
|
|
7
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/out/api.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { ArkError
|
|
1
|
+
export { ArkError, ArkErrors } from "@arktype/schema";
|
|
2
2
|
export type { Ark, ArkConfig, Out } from "@arktype/schema";
|
|
3
3
|
export { ambient, ark, declare, define, match, type } from "./ark.js";
|
|
4
4
|
export { Module } from "./module.js";
|
package/out/api.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { ArkError
|
|
1
|
+
export { ArkError, ArkErrors } from "@arktype/schema";
|
|
2
2
|
export { ambient, ark, declare, define, match, type } from "./ark.js";
|
|
3
3
|
export { Module } from "./module.js";
|
|
4
4
|
export { scope } from "./scope.js";
|
package/out/generic.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type GenericNodeInstantiation, type GenericProps, type RootScope
|
|
1
|
+
import { arkKind, type GenericNodeInstantiation, type GenericProps, type RootScope } from "@arktype/schema";
|
|
2
2
|
import { Callable, type conform } from "@arktype/util";
|
|
3
3
|
import type { inferDefinition } from "./parser/definition.js";
|
|
4
4
|
import type { GenericParamsParseError, parseGenericParams } from "./parser/generic.js";
|
package/out/match.js
CHANGED
|
@@ -1,52 +1,50 @@
|
|
|
1
|
-
export const createMatchParser = ($) => {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
// }) as never
|
|
52
|
-
};
|
|
1
|
+
export const createMatchParser = ($) => (() => { }).bind($);
|
|
2
|
+
// const matchParser = (isRestricted: boolean) => {
|
|
3
|
+
// const handledCases: { when: RawRoot; then: Morph }[] = []
|
|
4
|
+
// let defaultCase: ((x: unknown) => unknown) | null = null
|
|
5
|
+
// const parser = {
|
|
6
|
+
// when: (when: unknown, then: Morph) => {
|
|
7
|
+
// handledCases.push({ when: $.parseRoot(when, {}), then })
|
|
8
|
+
// return parser
|
|
9
|
+
// },
|
|
10
|
+
// finalize: () => {
|
|
11
|
+
// // TODO: exhaustiveness checking
|
|
12
|
+
// const branches = handledCases.flatMap(({ when, then }) => {
|
|
13
|
+
// if (when.kind === "union") {
|
|
14
|
+
// return when.branches.map((branch) => ({
|
|
15
|
+
// in: branch,
|
|
16
|
+
// morph: then
|
|
17
|
+
// }))
|
|
18
|
+
// }
|
|
19
|
+
// if (when.kind === "morph") {
|
|
20
|
+
// return [{ in: when, morph: [when.morph, then] }]
|
|
21
|
+
// }
|
|
22
|
+
// return [{ in: when, morph: then }]
|
|
23
|
+
// })
|
|
24
|
+
// if (defaultCase) {
|
|
25
|
+
// branches.push({ in: keywordNodes.unknown, morph: defaultCase })
|
|
26
|
+
// }
|
|
27
|
+
// const matchers = $.node("union", {
|
|
28
|
+
// branches,
|
|
29
|
+
// ordered: true
|
|
30
|
+
// })
|
|
31
|
+
// return matchers.assert
|
|
32
|
+
// },
|
|
33
|
+
// orThrow: () => {
|
|
34
|
+
// // implicitly finalize, we don't need to do anything else because we throw either way
|
|
35
|
+
// return parser.finalize()
|
|
36
|
+
// },
|
|
37
|
+
// default: (x: unknown) => {
|
|
38
|
+
// if (x instanceof Function) {
|
|
39
|
+
// defaultCase = x as never
|
|
40
|
+
// } else {
|
|
41
|
+
// defaultCase = () => x
|
|
42
|
+
// }
|
|
43
|
+
// return parser.finalize()
|
|
44
|
+
// }
|
|
45
|
+
// }
|
|
46
|
+
// return parser
|
|
47
|
+
// }
|
|
48
|
+
// return Object.assign(() => matchParser(false), {
|
|
49
|
+
// only: () => matchParser(true)
|
|
50
|
+
// }) as never
|
|
@@ -9,7 +9,7 @@ import { type TupleExpression, type inferTuple, type validateTuple } from "./tup
|
|
|
9
9
|
export declare const parseObject: (def: object, ctx: ParseContext) => BaseRoot;
|
|
10
10
|
export type inferDefinition<def, $, args> = [
|
|
11
11
|
def
|
|
12
|
-
] extends [anyOrNever] ? def : def extends type.cast<infer t> | ThunkCast<infer t> ? t : def extends string ? inferString<def, $, args> : def extends array ? inferTuple<def, $, args> : def extends RegExp ? string.matching<string> : def extends object ? inferObjectLiteral<def, $, args> : never;
|
|
12
|
+
] extends [anyOrNever] ? def extends never ? never : any : def extends type.cast<infer t> | ThunkCast<infer t> ? t : def extends string ? inferString<def, $, args> : def extends array ? inferTuple<def, $, args> : def extends RegExp ? string.matching<string> : def extends object ? inferObjectLiteral<def, $, args> : never;
|
|
13
13
|
export type validateDefinition<def, $, args> = null extends undefined ? ErrorMessage<`'strict' or 'strictNullChecks' must be set to true in your tsconfig's 'compilerOptions'`> : [def] extends [Terminal] ? def : def extends string ? validateString<def, $, args> : def extends array ? validateTuple<def, $, args> : def extends BadDefinitionType ? ErrorMessage<writeBadDefinitionTypeMessage<objectKindOrDomainOf<def>>> : isUnknown<def> extends true ? BaseCompletions<$, args> | {} : validateObjectLiteral<def, $, args>;
|
|
14
14
|
export type validateDeclared<declared, def, $, args> = def extends validateDefinition<def, $, args> ? validateInference<def, declared, $, args> : validateDefinition<def, $, args>;
|
|
15
15
|
type validateInference<def, declared, $, args> = def extends RegExp | type.cast<unknown> | ThunkCast | TupleExpression ? validateShallowInference<def, declared, $, args> : def extends array ? declared extends array ? {
|
|
@@ -2,7 +2,7 @@ import type { DynamicState } from "../../reduce/dynamic.js";
|
|
|
2
2
|
import type { StaticState, state } from "../../reduce/static.js";
|
|
3
3
|
import type { BaseCompletions } from "../../string.js";
|
|
4
4
|
import { Scanner } from "../scanner.js";
|
|
5
|
-
import { type EnclosingQuote, type EnclosingStartToken
|
|
5
|
+
import { parseEnclosed, type EnclosingQuote, type EnclosingStartToken } from "./enclosed.js";
|
|
6
6
|
import { parseUnenclosed } from "./unenclosed.js";
|
|
7
7
|
export declare const parseOperand: (s: DynamicState) => void;
|
|
8
8
|
export type parseOperand<s extends StaticState, $, args> = s["unscanned"] extends Scanner.shift<infer lookahead, infer unscanned> ? lookahead extends "(" ? state.reduceGroupOpen<s, unscanned> : lookahead extends EnclosingStartToken ? parseEnclosed<s, lookahead, unscanned> : lookahead extends Scanner.WhiteSpaceToken ? parseOperand<state.scanTo<s, unscanned>, $, args> : lookahead extends "d" ? unscanned extends (Scanner.shift<infer enclosing extends EnclosingQuote, infer nextUnscanned>) ? parseEnclosed<s, `d${enclosing}`, nextUnscanned> : parseUnenclosed<s, $, args> : parseUnenclosed<s, $, args> : state.completion<`${s["scanned"]}${BaseCompletions<$, args>}`>;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Scanner } from "../scanner.js";
|
|
2
|
-
import { enclosingChar, parseEnclosed } from "./enclosed.js";
|
|
2
|
+
import { enclosingChar, enclosingQuote, parseEnclosed } from "./enclosed.js";
|
|
3
3
|
import { parseUnenclosed, writeMissingOperandMessage } from "./unenclosed.js";
|
|
4
4
|
export const parseOperand = (s) => s.scanner.lookahead === "" ? s.error(writeMissingOperandMessage(s))
|
|
5
5
|
: s.scanner.lookahead === "(" ? s.shiftedByOne().reduceGroupOpen()
|
|
@@ -7,7 +7,7 @@ export const parseOperand = (s) => s.scanner.lookahead === "" ? s.error(writeMis
|
|
|
7
7
|
: s.scanner.lookaheadIsIn(Scanner.whiteSpaceTokens) ?
|
|
8
8
|
parseOperand(s.shiftedByOne())
|
|
9
9
|
: s.scanner.lookahead === "d" ?
|
|
10
|
-
s.
|
|
11
|
-
parseEnclosed(s,
|
|
10
|
+
s.scanner.nextLookahead in enclosingQuote ?
|
|
11
|
+
parseEnclosed(s, `${s.scanner.shift()}${s.scanner.shift()}`)
|
|
12
12
|
: parseUnenclosed(s)
|
|
13
13
|
: parseUnenclosed(s);
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import { type Dict } from "@arktype/util";
|
|
2
2
|
import type { Comparator } from "../reduce/shared.js";
|
|
3
|
-
export declare class Scanner<
|
|
3
|
+
export declare class Scanner<lookahead extends string = string> {
|
|
4
4
|
private chars;
|
|
5
5
|
private i;
|
|
6
6
|
constructor(def: string);
|
|
7
7
|
/** Get lookahead and advance scanner by one */
|
|
8
|
-
shift():
|
|
9
|
-
get lookahead():
|
|
8
|
+
shift(): lookahead;
|
|
9
|
+
get lookahead(): lookahead;
|
|
10
|
+
get nextLookahead(): string;
|
|
10
11
|
get length(): number;
|
|
11
12
|
shiftUntil(condition: Scanner.UntilCondition): string;
|
|
12
13
|
shiftUntilNextTerminator(): string;
|
|
@@ -16,8 +17,8 @@ export declare class Scanner<Lookahead extends string = string> {
|
|
|
16
17
|
get unscanned(): string;
|
|
17
18
|
get scanned(): string;
|
|
18
19
|
sliceChars(start: number, end?: number): string;
|
|
19
|
-
lookaheadIs<
|
|
20
|
-
lookaheadIsIn<
|
|
20
|
+
lookaheadIs<char extends lookahead>(char: char): this is Scanner<char>;
|
|
21
|
+
lookaheadIsIn<tokens extends Dict>(tokens: tokens): this is Scanner<Extract<keyof tokens, string>>;
|
|
21
22
|
}
|
|
22
23
|
export declare namespace Scanner {
|
|
23
24
|
type UntilCondition = (scanner: Scanner, shifted: string) => boolean;
|
package/out/scope.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { RawRootScope, type ArkConfig, type BaseRoot, type GenericProps, type PreparsedNodeResolution, type PrivateDeclaration, type RawRootResolutions, type RootScope, type UnknownRoot, type ambient, type arkKind, type destructuredExportContext, type destructuredImportContext, type exportedNameOf, type writeDuplicateAliasError } from "@arktype/schema";
|
|
2
2
|
import { type anyOrNever, type keyError, type nominal, type show } from "@arktype/util";
|
|
3
|
-
import type { type } from "./ark.js";
|
|
4
3
|
import { Generic } from "./generic.js";
|
|
5
4
|
import { type MatchParser } from "./match.js";
|
|
6
5
|
import type { Module } from "./module.js";
|
|
@@ -40,7 +39,7 @@ export type moduleKeyOf<$> = {
|
|
|
40
39
|
[arkKind]: "module";
|
|
41
40
|
} ? k & string : never;
|
|
42
41
|
}[keyof $];
|
|
43
|
-
export type tryInferSubmoduleReference<$, token> = token extends `${infer submodule extends moduleKeyOf<$>}.${infer subalias}` ? subalias extends keyof $[submodule] ? $[submodule][subalias]
|
|
42
|
+
export type tryInferSubmoduleReference<$, token> = token extends `${infer submodule extends moduleKeyOf<$>}.${infer subalias}` ? subalias extends keyof $[submodule] ? $[submodule][subalias] : never : never;
|
|
44
43
|
export interface ParseContext {
|
|
45
44
|
$: RawScope;
|
|
46
45
|
args?: Record<string, UnknownRoot>;
|
package/out/type.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ArkErrors, BaseRoot, type BaseMeta, type Disjoint, type InnerRoot, type Morph, type NodeSchema, type Out, type Predicate, type PrimitiveConstraintKind, type Root, type ambient, type constrain, type constraintKindOf, type
|
|
1
|
+
import { ArkErrors, BaseRoot, type BaseMeta, type Disjoint, type InnerRoot, type Morph, type NodeSchema, type Out, type Predicate, type PrimitiveConstraintKind, type Root, type ambient, type constrain, type constraintKindOf, type distillIn, type distillOut, type includesMorphs, type inferIntersection, type inferMorphOut, type inferNarrow, type inferPipes, type internalImplementationOf } from "@arktype/schema";
|
|
2
2
|
import { Callable, type Constructor, type array, type conform } from "@arktype/util";
|
|
3
3
|
import { Generic, type validateParameterString } from "./generic.js";
|
|
4
4
|
import type { inferDefinition, validateDeclared, validateDefinition } from "./parser/definition.js";
|
|
@@ -37,7 +37,7 @@ declare class _Type<t = unknown, $ = any> extends InnerRoot<t, $> implements int
|
|
|
37
37
|
pipe<a extends Morph<this["infer"]>, b extends Morph<inferMorphOut<a>>, c extends Morph<inferMorphOut<b>>, d extends Morph<inferMorphOut<c>>, e extends Morph<inferMorphOut<d>>>(a: a, b: b, c: c, d: d, e: e): Type<inferPipes<t, [a, b, c, d, e]>, $>;
|
|
38
38
|
pipe<a extends Morph<this["infer"]>, b extends Morph<inferMorphOut<a>>, c extends Morph<inferMorphOut<b>>, d extends Morph<inferMorphOut<c>>, e extends Morph<inferMorphOut<d>>, f extends Morph<inferMorphOut<e>>>(a: a, b: b, c: c, d: d, e: e, f: f): Type<inferPipes<t, [a, b, c, d, e, f]>, $>;
|
|
39
39
|
pipe<a extends Morph<this["infer"]>, b extends Morph<inferMorphOut<a>>, c extends Morph<inferMorphOut<b>>, d extends Morph<inferMorphOut<c>>, e extends Morph<inferMorphOut<d>>, f extends Morph<inferMorphOut<e>>, g extends Morph<inferMorphOut<f>>>(a: a, b: b, c: c, d: d, e: e, f: f, g: g): Type<inferPipes<t, [a, b, c, d, e, f, g]>, $>;
|
|
40
|
-
narrow<def extends Predicate<
|
|
40
|
+
narrow<def extends Predicate<distillOut<t>>>(def: def): Type<includesMorphs<t> extends true ? (In: this["tIn"]) => Out<inferNarrow<this["tOut"], def>> : inferNarrow<t, def>, $>;
|
|
41
41
|
equals<def>(def: validateTypeRoot<def, $>): this is Type<inferTypeRoot<def>, $>;
|
|
42
42
|
extract<def>(r: validateTypeRoot<def, $>): Type<t, $>;
|
|
43
43
|
exclude<def>(r: validateTypeRoot<def, $>): Type<t, $>;
|
package/package.json
CHANGED
|
@@ -1,37 +1,34 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
"@arktype/schema": "0.1.5"
|
|
36
|
-
}
|
|
37
|
-
}
|
|
2
|
+
"name": "arktype",
|
|
3
|
+
"description": "TypeScript's 1:1 validator, optimized from editor to runtime",
|
|
4
|
+
"version": "2.0.0-dev.15",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"author": {
|
|
7
|
+
"name": "David Blass",
|
|
8
|
+
"email": "david@arktype.io",
|
|
9
|
+
"url": "https://arktype.io"
|
|
10
|
+
},
|
|
11
|
+
"repository": {
|
|
12
|
+
"type": "git",
|
|
13
|
+
"url": "https://github.com/arktypeio/arktype.git"
|
|
14
|
+
},
|
|
15
|
+
"type": "module",
|
|
16
|
+
"main": "./out/api.js",
|
|
17
|
+
"types": "./out/api.d.ts",
|
|
18
|
+
"exports": {
|
|
19
|
+
".": "./out/api.js",
|
|
20
|
+
"./config": "./out/config.js",
|
|
21
|
+
"./internal/*": "./out/*"
|
|
22
|
+
},
|
|
23
|
+
"files": [
|
|
24
|
+
"out"
|
|
25
|
+
],
|
|
26
|
+
"dependencies": {
|
|
27
|
+
"@arktype/util": "0.0.45",
|
|
28
|
+
"@arktype/schema": "0.1.7"
|
|
29
|
+
},
|
|
30
|
+
"scripts": {
|
|
31
|
+
"build": "tsx ../repo/build.ts",
|
|
32
|
+
"test": "tsx ../repo/testPackage.ts"
|
|
33
|
+
}
|
|
34
|
+
}
|
package/out/main.d.ts
DELETED
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
export { ArkError, ArkErrors, ArkTypeError } from "@arktype/schema";
|
|
2
|
-
export type { Ark, ArkConfig, Out } from "@arktype/schema";
|
|
3
|
-
export { ambient, ark, declare, define, match, type } from "./ark.js";
|
|
4
|
-
export { Module } from "./module.js";
|
|
5
|
-
export { scope, type Scope } from "./scope.js";
|
|
6
|
-
export { Type, type inferTypeRoot, type validateTypeRoot } from "./type.js";
|
package/out/main.js
DELETED
package/out/package.json
DELETED