arktype 2.2.3 → 2.2.5

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/README.md CHANGED
@@ -1,5 +1,5 @@
1
1
  <h1 align="center">ArkType</h1>
2
- <h3 align="center"><i>TypeScript's 1:1 validator, optimized from editor to runtime</i></h1>
2
+ <h3 align="center"><i>TypeScript's 1:1 validator, optimized from editor to runtime</i></h3>
3
3
 
4
4
  ArkType is a runtime validation library that parses optimized validators from familiar, type-safe syntax.
5
5
 
@@ -50,19 +50,9 @@ Otherwise, consider sending me an email (david@arktype.io) or [message me on Dis
50
50
 
51
51
  <table>
52
52
  <tr>
53
- <th>mintlify</th>
54
53
  <th>get-convex</th>
55
- <th>inspatiallabs</th>
56
- <th>sam-goodwin</th>
57
54
  </tr>
58
55
  <tr>
59
- <td>
60
- <a href="https://github.com/mintlify"
61
- ><img
62
- height="64px"
63
- src="https://avatars.githubusercontent.com/mintlify"
64
- /></a>
65
- </td>
66
56
  <td>
67
57
  <a href="https://github.com/get-convex"
68
58
  ><img
@@ -70,20 +60,6 @@ Otherwise, consider sending me an email (david@arktype.io) or [message me on Dis
70
60
  src="https://avatars.githubusercontent.com/get-convex"
71
61
  /></a>
72
62
  </td>
73
- <td>
74
- <a href="https://github.com/inspatiallabs"
75
- ><img
76
- height="64px"
77
- src="https://avatars.githubusercontent.com/inspatiallabs"
78
- /></a>
79
- </td>
80
- <td>
81
- <a href="https://github.com/sam-goodwin"
82
- ><img
83
- height="64px"
84
- src="https://avatars.githubusercontent.com/sam-goodwin"
85
- /></a>
86
- </td>
87
63
  </tr>
88
64
  </table>
89
65
 
@@ -91,74 +67,74 @@ Otherwise, consider sending me an email (david@arktype.io) or [message me on Dis
91
67
 
92
68
  <table>
93
69
  <tr>
94
- <th>tmm</th>
95
70
  <th>mewhhaha</th>
96
71
  <th>jahands</th>
97
- <th>drwpwrs</th>
98
72
  <th>Phalangers</th>
73
+ <th>WilliamConnatser</th>
74
+ <th>JameEnder</th>
99
75
  </tr>
100
76
  <tr>
101
77
  <td>
102
- <a href="https://github.com/tmm"
78
+ <a href="https://github.com/mewhhaha"
103
79
  ><img
104
80
  height="64px"
105
- src="https://avatars.githubusercontent.com/tmm"
81
+ src="https://avatars.githubusercontent.com/mewhhaha"
106
82
  /></a>
107
83
  </td>
108
84
  <td>
109
- <a href="https://github.com/mewhhaha"
85
+ <a href="https://github.com/jahands"
110
86
  ><img
111
87
  height="64px"
112
- src="https://avatars.githubusercontent.com/mewhhaha"
88
+ src="https://avatars.githubusercontent.com/jahands"
113
89
  /></a>
114
90
  </td>
115
91
  <td>
116
- <a href="https://github.com/jahands"
92
+ <a href="https://github.com/Phalangers"
117
93
  ><img
118
94
  height="64px"
119
- src="https://avatars.githubusercontent.com/jahands"
95
+ src="https://avatars.githubusercontent.com/Phalangers"
120
96
  /></a>
121
97
  </td>
122
98
  <td>
123
- <a href="https://github.com/drwpwrs"
99
+ <a href="https://github.com/WilliamConnatser"
124
100
  ><img
125
101
  height="64px"
126
- src="https://avatars.githubusercontent.com/drwpwrs"
102
+ src="https://avatars.githubusercontent.com/WilliamConnatser"
127
103
  /></a>
128
104
  </td>
129
105
  <td>
130
- <a href="https://github.com/Phalangers"
106
+ <a href="https://github.com/JameEnder"
131
107
  ><img
132
108
  height="64px"
133
- src="https://avatars.githubusercontent.com/Phalangers"
109
+ src="https://avatars.githubusercontent.com/JameEnder"
134
110
  /></a>
135
111
  </td>
136
112
  </tr>
137
113
  <tr>
138
- <th>WilliamConnatser</th>
139
- <th>JameEnder</th>
140
114
  <th>tylim88</th>
115
+ <th>tpetry</th>
116
+ <th>braden-w</th>
141
117
  </tr>
142
118
  <tr>
143
119
  <td>
144
- <a href="https://github.com/WilliamConnatser"
120
+ <a href="https://github.com/tylim88"
145
121
  ><img
146
122
  height="64px"
147
- src="https://avatars.githubusercontent.com/WilliamConnatser"
123
+ src="https://avatars.githubusercontent.com/tylim88"
148
124
  /></a>
149
125
  </td>
150
126
  <td>
151
- <a href="https://github.com/JameEnder"
127
+ <a href="https://github.com/tpetry"
152
128
  ><img
153
129
  height="64px"
154
- src="https://avatars.githubusercontent.com/JameEnder"
130
+ src="https://avatars.githubusercontent.com/tpetry"
155
131
  /></a>
156
132
  </td>
157
133
  <td>
158
- <a href="https://github.com/tylim88"
134
+ <a href="https://github.com/braden-w"
159
135
  ><img
160
136
  height="64px"
161
- src="https://avatars.githubusercontent.com/tylim88"
137
+ src="https://avatars.githubusercontent.com/braden-w"
162
138
  /></a>
163
139
  </td>
164
140
  </tr>
package/out/fn.d.ts CHANGED
@@ -8,7 +8,7 @@ import type { InternalScope, Scope } from "./scope.ts";
8
8
  import type { Type } from "./type.ts";
9
9
  export type BaseFnParser<$ = {}> = <const args extends readonly unknown[], paramsT extends readonly unknown[] = inferTupleLiteral<args extends readonly [...infer params, ":", unknown] ? params : args, $, {}>, returnT = args extends readonly [...unknown[], ":", infer returnDef] ? type.infer<returnDef, $> : unknown>(...args: {
10
10
  [i in keyof args]: conform<args[i], get<validateFnArgs<args, $>, i>>;
11
- }) => <internalSignature extends (...args: distill.Out<paramsT>) => distill.In<returnT>, externalSignature extends Fn = (...args: applyElementLabels<distill.In<paramsT>, Parameters<internalSignature>>) => args extends readonly [...unknown[], ":", unknown] ? distill.Out<returnT> : ReturnType<internalSignature>>(implementation: internalSignature) => TypedFn<externalSignature, $, args extends readonly [...unknown[], ":", unknown] ? Return.introspectable : {}>;
11
+ }) => <internalSignature extends (...args: distill.Out<paramsT>) => distill.In<returnT>, externalSignature extends Fn = (...args: applyElementLabels<distill.In<paramsT>, Required<Parameters<internalSignature>>>) => args extends readonly [...unknown[], ":", unknown] ? distill.Out<returnT> : ReturnType<internalSignature>>(implementation: internalSignature) => TypedFn<externalSignature, $, args extends readonly [...unknown[], ":", unknown] ? Return.introspectable : {}>;
12
12
  export interface FnParser<$ = {}> extends BaseFnParser<$> {
13
13
  /**
14
14
  * The {@link Scope} in which definitions passed to this function will be parsed.
@@ -1,8 +1,7 @@
1
1
  import type { writeUnassignableDefaultValueMessage } from "@ark/schema";
2
- import type { ErrorMessage } from "@ark/util";
3
- import type { type } from "../../keywords/keywords.ts";
4
- import type { UnitLiteral } from "../shift/operator/default.ts";
2
+ import type { EmptyObject, ErrorMessage } from "@ark/util";
3
+ import type { DefaultLiteral, inferDefaultLiteral } from "../shift/operator/default.ts";
5
4
  import type { inferAstIn } from "./infer.ts";
6
5
  import type { astToString } from "./utils.ts";
7
6
  import type { validateAst } from "./validate.ts";
8
- export type validateDefault<baseAst, unitLiteral extends UnitLiteral, $, args> = validateAst<baseAst, $, args> extends infer e extends ErrorMessage ? e : type.infer<unitLiteral> extends inferAstIn<baseAst, $, args> ? undefined : ErrorMessage<writeUnassignableDefaultValueMessage<astToString<baseAst>, unitLiteral>>;
7
+ export type validateDefault<baseAst, defaultLiteral extends DefaultLiteral, $, args> = validateAst<baseAst, $, args> extends infer e extends ErrorMessage ? e : inferDefaultLiteral<defaultLiteral> extends inferAstIn<baseAst, $, args> ? undefined : defaultLiteral extends "{}" ? EmptyObject extends inferAstIn<baseAst, $, args> ? undefined : ErrorMessage<writeUnassignableDefaultValueMessage<astToString<baseAst>, defaultLiteral>> : ErrorMessage<writeUnassignableDefaultValueMessage<astToString<baseAst>, defaultLiteral>>;
@@ -4,6 +4,7 @@ import type { type } from "../../keywords/keywords.ts";
4
4
  import type { inferDefinition } from "../definition.ts";
5
5
  import type { Comparator } from "../reduce/shared.ts";
6
6
  import type { InfixToken, PostfixToken } from "../shift/tokens.ts";
7
+ import type { inferDefaultLiteral } from "../shift/operator/default.ts";
7
8
  import type { GenericInstantiationAst, inferGenericInstantiation } from "./generic.ts";
8
9
  export type inferAstRoot<ast, $, args> = ast extends array ? inferExpression<ast, $, args> : never;
9
10
  export type inferAstIn<ast, $, args> = distill.In<inferAstRoot<ast, $, args>>;
@@ -18,7 +19,7 @@ export type InferredAst<t = unknown, def extends string = string> = [
18
19
  "inferred",
19
20
  def
20
21
  ];
21
- export type inferExpression<ast, $, args> = ast extends array ? ast extends InferredAst<infer resolution> ? resolution : ast extends DefAst<infer def> ? inferDefinition<def, $, args> : ast extends GenericInstantiationAst<infer g, infer argAsts> ? inferGenericInstantiation<g, argAsts, $, args> : ast[1] extends "[]" ? inferExpression<ast[0], $, args>[] : ast[1] extends "|" ? inferExpression<ast[0], $, args> | inferExpression<ast[2], $, args> : ast[1] extends "&" ? inferIntersection<inferExpression<ast[0], $, args>, inferExpression<ast[2], $, args>> : ast[1] extends "|>" ? inferPipe<inferExpression<ast[0], $, args>, inferExpression<ast[2], $, args>> : ast[1] extends "=" ? type.infer<ast[2]> extends infer defaultValue ? withDefault<inferExpression<ast[0], $, args>, defaultValue> : never : ast[1] extends "#" ? type.brand<inferExpression<ast[0], $, args>, ast[2]> : ast[1] extends Comparator ? ast[0] extends LimitLiteral ? inferExpression<ast[2], $, args> : inferExpression<ast[0], $, args> : ast[1] extends "%" ? inferExpression<ast[0], $, args> : ast[1] extends "?" ? inferExpression<ast[0], $, args> : ast[0] extends "keyof" ? arkKeyOf<inferExpression<ast[1], $, args>> : never : never;
22
+ export type inferExpression<ast, $, args> = ast extends array ? ast extends InferredAst<infer resolution> ? resolution : ast extends DefAst<infer def> ? inferDefinition<def, $, args> : ast extends GenericInstantiationAst<infer g, infer argAsts> ? inferGenericInstantiation<g, argAsts, $, args> : ast[1] extends "[]" ? inferExpression<ast[0], $, args>[] : ast[1] extends "|" ? inferExpression<ast[0], $, args> | inferExpression<ast[2], $, args> : ast[1] extends "&" ? inferIntersection<inferExpression<ast[0], $, args>, inferExpression<ast[2], $, args>> : ast[1] extends "|>" ? inferPipe<inferExpression<ast[0], $, args>, inferExpression<ast[2], $, args>> : ast[1] extends "=" ? inferDefaultLiteral<ast[2]> extends infer defaultValue ? withDefault<inferExpression<ast[0], $, args>, defaultValue> : never : ast[1] extends "#" ? type.brand<inferExpression<ast[0], $, args>, ast[2]> : ast[1] extends Comparator ? ast[0] extends LimitLiteral ? inferExpression<ast[2], $, args> : inferExpression<ast[0], $, args> : ast[1] extends "%" ? inferExpression<ast[0], $, args> : ast[1] extends "?" ? inferExpression<ast[0], $, args> : ast[0] extends "keyof" ? arkKeyOf<inferExpression<ast[1], $, args>> : never : never;
22
23
  export type PrefixOperator = "keyof" | "instanceof" | "===" | "node";
23
24
  export type PrefixExpression<operator extends PrefixOperator = PrefixOperator, operand = unknown> = [operator, operand];
24
25
  export type PostfixExpression<operator extends PostfixToken = PostfixToken, operand = unknown> = readonly [operand, operator];
@@ -3,7 +3,7 @@ import type { anyOrNever, BigintLiteral, Completion, ErrorMessage, NumberLiteral
3
3
  import type { Generic } from "../../generic.ts";
4
4
  import type { BranchOperator, Comparator } from "../reduce/shared.ts";
5
5
  import type { writeInvalidGenericArgCountMessage } from "../shift/operand/genericArgs.ts";
6
- import type { UnitLiteral } from "../shift/operator/default.ts";
6
+ import type { DefaultLiteral } from "../shift/operator/default.ts";
7
7
  import type { parseString } from "../string.ts";
8
8
  import type { validateRange } from "./bounds.ts";
9
9
  import type { validateDefault } from "./default.ts";
@@ -12,7 +12,7 @@ import type { GenericInstantiationAst, validateGenericInstantiation } from "./ge
12
12
  import type { DefAst, InferredAst, InfixExpression, PostfixExpression } from "./infer.ts";
13
13
  import type { validateKeyof } from "./keyof.ts";
14
14
  import type { astToString } from "./utils.ts";
15
- export type validateAst<ast, $, args> = ast extends ErrorMessage ? ast : ast extends InferredAst ? validateInferredAst<ast[0], ast[2]> : ast extends DefAst ? ast[2] extends PrivateDeclaration<infer name> ? ErrorMessage<writePrefixedPrivateReferenceMessage<name>> : undefined : ast extends PostfixExpression<"[]" | "?", infer operand> ? validateAst<operand, $, args> : ast extends InfixExpression<infer operator, infer l, infer r> ? operator extends BranchOperator ? validateInfix<ast, $, args> : operator extends Comparator ? validateRange<l, operator, r, $, args> : operator extends "%" ? validateDivisor<l, $, args> : operator extends "=" ? validateDefault<l, r & UnitLiteral, $, args> : operator extends "#" ? validateAst<l, $, args> : ErrorMessage<writeUnexpectedExpressionMessage<astToString<ast>>> : ast extends ["keyof", infer operand] ? validateKeyof<operand, $, args> : ast extends GenericInstantiationAst<infer g, infer argAsts> ? validateGenericInstantiation<g, argAsts, $, args> : ErrorMessage<writeUnexpectedExpressionMessage<astToString<ast>>> & {
15
+ export type validateAst<ast, $, args> = ast extends ErrorMessage ? ast : ast extends InferredAst ? validateInferredAst<ast[0], ast[2]> : ast extends DefAst ? ast[2] extends PrivateDeclaration<infer name> ? ErrorMessage<writePrefixedPrivateReferenceMessage<name>> : undefined : ast extends PostfixExpression<"[]" | "?", infer operand> ? validateAst<operand, $, args> : ast extends InfixExpression<infer operator, infer l, infer r> ? operator extends BranchOperator ? validateInfix<ast, $, args> : operator extends Comparator ? validateRange<l, operator, r, $, args> : operator extends "%" ? validateDivisor<l, $, args> : operator extends "=" ? validateDefault<l, r & DefaultLiteral, $, args> : operator extends "#" ? validateAst<l, $, args> : ErrorMessage<writeUnexpectedExpressionMessage<astToString<ast>>> : ast extends ["keyof", infer operand] ? validateKeyof<operand, $, args> : ast extends GenericInstantiationAst<infer g, infer argAsts> ? validateGenericInstantiation<g, argAsts, $, args> : ErrorMessage<writeUnexpectedExpressionMessage<astToString<ast>>> & {
16
16
  ast: ast;
17
17
  };
18
18
  type writeUnexpectedExpressionMessage<expression extends string> = `Failed to parse the expression resulting from ${expression}`;
@@ -4,7 +4,7 @@ import { parseObjectLiteral } from "./objectLiteral.js";
4
4
  import { parseString } from "./string.js";
5
5
  import { maybeParseTupleExpression } from "./tupleExpressions.js";
6
6
  import { parseTupleLiteral } from "./tupleLiteral.js";
7
- const parseCache = {};
7
+ const parseCache = new WeakMap();
8
8
  export const parseInnerDefinition = (def, ctx) => {
9
9
  if (typeof def === "string") {
10
10
  if (ctx.args && Object.keys(ctx.args).some(k => def.includes(k))) {
@@ -12,7 +12,11 @@ export const parseInnerDefinition = (def, ctx) => {
12
12
  // resolutions like "this" or generic args
13
13
  return parseString(def, ctx);
14
14
  }
15
- const scopeCache = (parseCache[ctx.$.name] ??= {});
15
+ let scopeCache = parseCache.get(ctx.$);
16
+ if (!scopeCache) {
17
+ scopeCache = {};
18
+ parseCache.set(ctx.$, scopeCache);
19
+ }
16
20
  return (scopeCache[def] ??= parseString(def, ctx));
17
21
  }
18
22
  return hasDomain(def, "object") ?
@@ -1,4 +1,4 @@
1
- import { type ErrorMessage, type Scanner } from "@ark/util";
1
+ import { Backslash, type ErrorMessage, type Scanner } from "@ark/util";
2
2
  import type { Regex, regex } from "arkregex";
3
3
  import type { Out } from "../../../attributes.ts";
4
4
  import type { InferredAst } from "../../ast/infer.ts";
@@ -8,7 +8,7 @@ export type StringLiteral<contents extends string = string> = DoubleQuotedString
8
8
  export type DoubleQuotedStringLiteral<contents extends string = string> = `"${contents}"`;
9
9
  export type SingleQuotedStringLiteral<contents extends string = string> = `'${contents}'`;
10
10
  export declare const parseEnclosed: (s: RuntimeState, enclosing: EnclosingStartToken) => void;
11
- export type parseEnclosed<s extends StaticState, enclosingStart extends EnclosingStartToken, unscanned extends string> = Scanner.shiftUntilEscapable<unscanned, EnclosingTokens[enclosingStart], ""> extends Scanner.shiftResult<infer scanned, infer nextUnscanned> ? _parseEnclosed<s, enclosingStart, scanned, nextUnscanned> : never;
11
+ export type parseEnclosed<s extends StaticState, enclosingStart extends EnclosingStartToken, unscanned extends string> = Scanner.shiftUntilEscapable<unscanned, EnclosingTokens[enclosingStart], enclosingStart extends EnclosingRegexToken ? Backslash : ""> extends Scanner.shiftResult<infer scanned, infer nextUnscanned> ? _parseEnclosed<s, enclosingStart, scanned, nextUnscanned> : never;
12
12
  type _parseEnclosed<s extends StaticState, enclosingStart extends EnclosingStartToken, scanned extends string, nextUnscanned extends string, def extends string = `${enclosingStart}${scanned}${EnclosingTokens[enclosingStart]}`> = nextUnscanned extends "" ? s.error<writeUnterminatedEnclosedMessage<scanned, enclosingStart>> : enclosingStart extends EnclosingQuote ? s.setRoot<s, InferredAst<scanned, def>, nextUnscanned extends Scanner.shift<string, infer unscanned> ? unscanned : ""> : enclosingStart extends EnclosingRegexToken ? regex.parse<scanned> extends infer r ? r extends Regex ? s.setRoot<s, InferredAst<enclosingStart extends "/" ? r["infer"] : (In: r["infer"]) => Out<r["inferExecArray"]>, def>, nextUnscanned extends Scanner.shift<string, infer unscanned> ? unscanned : ""> : r extends ErrorMessage<infer e> ? s.error<e> : never : never : s.setRoot<s, InferredAst<Date, def>, nextUnscanned extends Scanner.shift<string, infer unscanned> ? unscanned : "">;
13
13
  export declare const enclosingQuote: {
14
14
  readonly "'": 1;
@@ -1,5 +1,5 @@
1
1
  import { rootSchema } from "@ark/schema";
2
- import { isKeyOf, throwParseError } from "@ark/util";
2
+ import { Backslash, isKeyOf, throwParseError } from "@ark/util";
3
3
  import { tryParseDate, writeInvalidDateMessage } from "./date.js";
4
4
  const regexExecArray = rootSchema({
5
5
  proto: "Array",
@@ -10,7 +10,11 @@ const regexExecArray = rootSchema({
10
10
  }
11
11
  });
12
12
  export const parseEnclosed = (s, enclosing) => {
13
- const enclosed = s.scanner.shiftUntilEscapable(untilLookaheadIsClosing[enclosingTokens[enclosing]]);
13
+ const enclosed = s.scanner.shiftUntilEscapable(untilLookaheadIsClosing[enclosingTokens[enclosing]],
14
+ // within a regex literal, `\\` is a literal backslash and must be
15
+ // preserved verbatim in the pattern source; collapsing it to a single
16
+ // backslash would corrupt the regex (e.g. `\\d` -> `\d` digit class)
17
+ enclosing in enclosingRegexTokens ? Backslash : "");
14
18
  if (s.scanner.lookahead === "")
15
19
  return s.error(writeUnterminatedEnclosedMessage(enclosed, enclosing));
16
20
  // Shift the scanner one additional time for the second enclosing token
@@ -1,5 +1,6 @@
1
1
  import type { BaseRoot } from "@ark/schema";
2
- import type { BigintLiteral, ErrorMessage, NumberLiteral, Scanner, trim } from "@ark/util";
2
+ import { type BigintLiteral, type ErrorMessage, type NumberLiteral, type Scanner, type trim } from "@ark/util";
3
+ import type { type } from "../../../keywords/keywords.ts";
3
4
  import type { DateLiteral } from "../../../attributes.ts";
4
5
  import type { RootedRuntimeState } from "../../reduce/dynamic.ts";
5
6
  import type { EnclosingLiteralStartToken, EnclosingLiteralTokens, StringLiteral } from "../operand/enclosed.ts";
@@ -7,9 +8,17 @@ type UnitLiteralKeyword = "null" | "undefined" | "true" | "false";
7
8
  export type UnitLiteral = UnenclosedUnitLiteral | EnclosedUnitLiteral;
8
9
  export type UnenclosedUnitLiteral = BigintLiteral | NumberLiteral | UnitLiteralKeyword;
9
10
  export type EnclosedUnitLiteral = StringLiteral | DateLiteral;
11
+ /**
12
+ * Unlike a unit literal, an empty collection can't be reused across traversals
13
+ * since mutating the defaulted value would leak into subsequent ones. These are
14
+ * parsed to a thunk instead, mirroring `["string[]", "=", () => []]`.
15
+ */
16
+ export type EmptyCollectionLiteral = "[]" | "{}";
17
+ export type DefaultLiteral = UnitLiteral | EmptyCollectionLiteral;
18
+ export type inferDefaultLiteral<literal> = literal extends "[]" ? [] : literal extends "{}" ? {} : type.infer<literal>;
10
19
  export type ParsedDefaultableProperty = readonly [BaseRoot, "=", unknown];
11
20
  export declare const parseDefault: (s: RootedRuntimeState) => ParsedDefaultableProperty;
12
- export type parseDefault<root, unscanned extends string> = trim<unscanned> extends infer defaultExpression extends string ? defaultExpression extends UnenclosedUnitLiteral ? [
21
+ export type parseDefault<root, unscanned extends string> = trim<unscanned> extends infer defaultExpression extends string ? defaultExpression extends UnenclosedUnitLiteral | EmptyCollectionLiteral ? [
13
22
  root,
14
23
  "=",
15
24
  defaultExpression
@@ -1,6 +1,20 @@
1
+ import { keysOf } from "@ark/util";
2
+ const emptyCollectionDefaults = {
3
+ "[]": () => [],
4
+ "{}": () => ({})
5
+ };
6
+ const emptyCollectionLiterals = keysOf(emptyCollectionDefaults);
1
7
  export const parseDefault = (s) => {
2
8
  // store the node that will be bounded
3
9
  const baseNode = s.unsetRoot();
10
+ // an empty collection is not a unit literal, so it must be short-circuited
11
+ // here and represented as a thunk to keep each traversal's default distinct
12
+ s.scanner.shiftUntilNonWhitespace();
13
+ const emptyCollection = emptyCollectionLiterals.find(literal => s.scanner.unscanned.startsWith(literal));
14
+ if (emptyCollection !== undefined) {
15
+ s.scanner.jumpForward(emptyCollection.length);
16
+ return [baseNode, "=", emptyCollectionDefaults[emptyCollection]];
17
+ }
4
18
  s.parseOperand();
5
19
  const defaultNode = s.unsetRoot();
6
20
  // after parsing the next operand, use the locations to get the
@@ -22,6 +22,11 @@ interface Type<out t extends object = object, $ = {}> extends BaseType<t, $> {
22
22
  get<const k1 extends arkIndexableOf<t>, const k2 extends arkIndexableOf<arkGet<t, k1>>, const k3 extends arkIndexableOf<arkGet<arkGet<t, k1>, k2>>, r = instantiateType<arkGet<arkGet<arkGet<t, k1>, k2>, k3>, $>>(k1: k1 | type.cast<k1>, k2: k2 | type.cast<k2>, k3: k3 | type.cast<k3>): r extends infer _ ? _ : never;
23
23
  /**
24
24
  * Create a copy of this `Type` with only the specified properties.
25
+ *
26
+ * ⚠️ returns a new object built from the properties it extracts, so a root
27
+ * narrow, filter or metadata on this `Type` is not carried over
28
+ * ({@link https://arktype.io/docs/objects#properties-structural | docs})
29
+ *
25
30
  * @example type({ foo: "string", bar: "number" }).pick("foo") // Type<{ foo: string }>
26
31
  */
27
32
  pick<const key extends arkKeyOf<t> = never>(...keys: (key | type.cast<key>)[]): Type<{
@@ -29,6 +34,11 @@ interface Type<out t extends object = object, $ = {}> extends BaseType<t, $> {
29
34
  }, $>;
30
35
  /**
31
36
  * Create a copy of this `Type` with all properties except the specified ones.
37
+ *
38
+ * ⚠️ returns a new object built from the properties it extracts, so a root
39
+ * narrow, filter or metadata on this `Type` is not carried over
40
+ * ({@link https://arktype.io/docs/objects#properties-structural | docs})
41
+ *
32
42
  * @example type({ foo: "string", bar: "number" }).omit("foo") // Type<{ bar: number }>
33
43
  */
34
44
  omit<const key extends arkKeyOf<t> = never>(...keys: (key | type.cast<key>)[]): Type<{
@@ -36,11 +46,24 @@ interface Type<out t extends object = object, $ = {}> extends BaseType<t, $> {
36
46
  }, $>;
37
47
  /**
38
48
  * Merge another `Type` definition, overriding properties of this `Type` with the duplicate keys.
49
+ *
50
+ * ⚠️ returns a new object built from the properties it extracts, so a root
51
+ * narrow, filter or metadata on this `Type` is not carried over
52
+ * ({@link https://arktype.io/docs/objects#properties-structural | docs})
53
+ *
39
54
  * @example type({ a: "1", b: "2" }).merge({ b: "3", c: "4" }) // Type<{ a: 1, b: 3, c: 4 }>
40
55
  */
41
56
  merge<const def, inferredDef = type.infer<def, $>, r = Type<merge<t, inferredDef>, $>>(def: type.validate<def, $> & (inferredDef extends object ? unknown : ErrorType<[NonObjectMergeErrorMessage, actual: inferredDef]>)): r extends infer _ ? _ : never;
42
57
  /**
43
58
  * Create a copy of this `Type` with all properties required.
59
+ *
60
+ * ⚠️ returns a new object built from the properties it extracts, so a root
61
+ * narrow, filter or metadata on this `Type` is not carried over
62
+ * ({@link https://arktype.io/docs/objects#properties-structural | docs})
63
+ *
64
+ * 🔗 like TS's `Required`, an array or tuple base is preserved and
65
+ * applied to its elements, e.g. `type(["string", "number"]).required()`
66
+ *
44
67
  * @example const T = type({ "foo?"": "string" }).required() // Type<{ foo: string }>
45
68
  */
46
69
  required(): Type<{
@@ -48,11 +71,29 @@ interface Type<out t extends object = object, $ = {}> extends BaseType<t, $> {
48
71
  }, $>;
49
72
  /**
50
73
  * Create a copy of this `Type` with all properties optional.
74
+ *
75
+ * ⚠️ returns a new object built from the properties it extracts, so a root
76
+ * narrow, filter or metadata on this `Type` is not carried over
77
+ * ({@link https://arktype.io/docs/objects#properties-structural | docs})
78
+ *
79
+ * 🔗 like TS's `Partial`, an array or tuple base is preserved and
80
+ * applied to its elements, e.g. `type(["string", "number"]).partial()`
81
+ *
51
82
  * @example: const T = type({ foo: "string" }).optional() // Type<{ foo?: string }>
52
83
  */
53
84
  partial(): Type<{
54
85
  [k in keyof t]?: t[k];
55
86
  }, $>;
87
+ /**
88
+ * Create a copy of this `Type` with each of its properties transformed by
89
+ * the provided function. Return `[]` to remove a property.
90
+ *
91
+ * ⚠️ returns a new object built from the properties it extracts, so a root
92
+ * narrow, filter or metadata on this `Type` is not carried over
93
+ * ({@link https://arktype.io/docs/objects#properties-structural | docs})
94
+ *
95
+ * @example type({ foo: "string" }).map(prop => ({ key: prop.key, value: prop.value.or("null") })) // Type<{ foo: string | null }>
96
+ */
56
97
  map<transformed extends listable<MappedTypeProp>, r = Type<constructMapped<t, transformed>, $>>(flatMapEntry: (entry: typePropOf<t, $>) => transformed): r extends infer _ ? _ : never;
57
98
  /**
58
99
  * List of property info of this `Type<object>`.
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "arktype",
3
3
  "description": "TypeScript's 1:1 validator, optimized from editor to runtime",
4
- "version": "2.2.3",
4
+ "version": "2.2.5",
5
5
  "license": "MIT",
6
6
  "repository": {
7
7
  "type": "git",
@@ -38,9 +38,9 @@
38
38
  "out"
39
39
  ],
40
40
  "dependencies": {
41
- "@ark/util": "0.56.2",
42
- "arkregex": "0.0.8",
43
- "@ark/schema": "0.56.2"
41
+ "@ark/util": "0.56.4",
42
+ "@ark/schema": "0.56.4",
43
+ "arkregex": "0.0.10"
44
44
  },
45
45
  "publishConfig": {
46
46
  "access": "public"