arktype 2.0.0-dev.13 → 2.0.0-dev.14

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 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 as ArkError, ArkErrors } from "@arktype/schema";
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 as ArkError, ArkErrors } from "@arktype/schema";
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, arkKind } from "@arktype/schema";
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
- return (() => { }).bind($);
3
- // const matchParser = (isRestricted: boolean) => {
4
- // const handledCases: { when: RawRoot; then: Morph }[] = []
5
- // let defaultCase: ((x: unknown) => unknown) | null = null
6
- // const parser = {
7
- // when: (when: unknown, then: Morph) => {
8
- // handledCases.push({ when: $.parseRoot(when, {}), then })
9
- // return parser
10
- // },
11
- // finalize: () => {
12
- // // TODO: exhaustiveness checking
13
- // const branches = handledCases.flatMap(({ when, then }) => {
14
- // if (when.kind === "union") {
15
- // return when.branches.map((branch) => ({
16
- // in: branch,
17
- // morph: then
18
- // }))
19
- // }
20
- // if (when.kind === "morph") {
21
- // return [{ in: when, morph: [when.morph, then] }]
22
- // }
23
- // return [{ in: when, morph: then }]
24
- // })
25
- // if (defaultCase) {
26
- // branches.push({ in: keywordNodes.unknown, morph: defaultCase })
27
- // }
28
- // const matchers = $.node("union", {
29
- // branches,
30
- // ordered: true
31
- // })
32
- // return matchers.assert
33
- // },
34
- // orThrow: () => {
35
- // // implicitly finalize, we don't need to do anything else because we throw either way
36
- // return parser.finalize()
37
- // },
38
- // default: (x: unknown) => {
39
- // if (x instanceof Function) {
40
- // defaultCase = x as never
41
- // } else {
42
- // defaultCase = () => x
43
- // }
44
- // return parser.finalize()
45
- // }
46
- // }
47
- // return parser
48
- // }
49
- // return Object.assign(() => matchParser(false), {
50
- // only: () => matchParser(true)
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, parseEnclosed } from "./enclosed.js";
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.shiftedByOne().scanner.lookaheadIsIn(enclosingChar) ?
11
- parseEnclosed(s, `d${s.scanner.shift()}`)
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<Lookahead extends string = string> {
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(): Lookahead;
9
- get lookahead(): 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<Char extends Lookahead>(char: Char): this is Scanner<Char>;
20
- lookaheadIsIn<Tokens extends Dict>(tokens: Tokens): this is Scanner<Extract<keyof Tokens, string>>;
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;
@@ -13,6 +13,9 @@ export class Scanner {
13
13
  get lookahead() {
14
14
  return (this.chars[this.i] ?? "");
15
15
  }
16
+ get nextLookahead() {
17
+ return this.chars[this.i + 1] ?? "";
18
+ }
16
19
  get length() {
17
20
  return this.chars.length;
18
21
  }
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] extends type.cast<infer t> ? t : never : never : never;
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/package.json CHANGED
@@ -1,37 +1,34 @@
1
1
  {
2
- "name": "arktype",
3
- "description": "TypeScript's 1:1 validator, optimized from editor to runtime",
4
- "version": "2.0.0-dev.13",
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
- "imports": {
24
- "#foo": "../schema/api.ts"
25
- },
26
- "files": [
27
- "out"
28
- ],
29
- "scripts": {
30
- "build": "tsx ../repo/build.ts",
31
- "test": "tsx ../repo/testPackage.ts"
32
- },
33
- "dependencies": {
34
- "@arktype/util": "0.0.42",
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.14",
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.44",
28
+ "@arktype/schema": "0.1.6"
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
@@ -1,5 +0,0 @@
1
- export { ArkError, ArkErrors, ArkTypeError } from "@arktype/schema";
2
- export { ambient, ark, declare, define, match, type } from "./ark.js";
3
- export { Module } from "./module.js";
4
- export { scope } from "./scope.js";
5
- export { Type } from "./type.js";
package/out/package.json DELETED
@@ -1,3 +0,0 @@
1
- {
2
- "type": "commonjs"
3
- }