arktype 3.0.0-beta.1 → 3.0.0-rc.0
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 +48 -144
- package/out/_internal/regex/charset.d.ts +24 -0
- package/out/_internal/regex/escape.d.ts +29 -0
- package/out/_internal/regex/execArray.d.ts +24 -0
- package/out/_internal/regex/group.d.ts +34 -0
- package/out/_internal/regex/index.d.ts +2 -0
- package/out/_internal/regex/internal.d.ts +9 -0
- package/out/_internal/regex/parse.d.ts +10 -0
- package/out/_internal/regex/quantify.d.ts +59 -0
- package/out/_internal/regex/regex.d.ts +38 -0
- package/out/_internal/regex/state.d.ts +383 -0
- package/out/_internal/schema/codecs.d.ts +2 -0
- package/out/_internal/schema/config.d.ts +103 -0
- package/out/_internal/schema/constraint.d.ts +78 -0
- package/out/_internal/schema/errors.d.ts +1 -0
- package/out/_internal/schema/generic.d.ts +85 -0
- package/out/_internal/schema/i18n.d.ts +3 -0
- package/out/_internal/schema/index.d.ts +54 -0
- package/out/_internal/schema/internal.d.ts +15 -0
- package/out/_internal/schema/intrinsic.d.ts +28 -0
- package/out/_internal/schema/kinds.d.ts +76 -0
- package/out/_internal/schema/module.d.ts +23 -0
- package/out/_internal/schema/mutatesInput.d.ts +2 -0
- package/out/_internal/schema/node.d.ts +349 -0
- package/out/_internal/schema/parse.d.ts +77 -0
- package/out/_internal/schema/parseSchema.d.ts +116 -0
- package/out/_internal/schema/predicate.d.ts +46 -0
- package/out/_internal/schema/refinements/after.d.ts +32 -0
- package/out/_internal/schema/refinements/before.d.ts +32 -0
- package/out/_internal/schema/refinements/divisor.d.ts +41 -0
- package/out/_internal/schema/refinements/exactLength.d.ts +43 -0
- package/out/_internal/schema/refinements/kinds.d.ts +40 -0
- package/out/_internal/schema/refinements/max.d.ts +33 -0
- package/out/_internal/schema/refinements/maxLength.d.ts +32 -0
- package/out/_internal/schema/refinements/min.d.ts +33 -0
- package/out/_internal/schema/refinements/minLength.d.ts +32 -0
- package/out/_internal/schema/refinements/notEqual.d.ts +38 -0
- package/out/_internal/schema/refinements/notEqualLength.d.ts +38 -0
- package/out/_internal/schema/refinements/pattern.d.ts +43 -0
- package/out/_internal/schema/refinements/range.d.ts +101 -0
- package/out/_internal/schema/roots/alias.d.ts +49 -0
- package/out/_internal/schema/roots/basis.d.ts +12 -0
- package/out/_internal/schema/roots/domain.d.ts +45 -0
- package/out/_internal/schema/roots/intersection.d.ts +72 -0
- package/out/_internal/schema/roots/morph.d.ts +59 -0
- package/out/_internal/schema/roots/proto.d.ts +42 -0
- package/out/_internal/schema/roots/root.d.ts +163 -0
- package/out/_internal/schema/roots/union.d.ts +146 -0
- package/out/_internal/schema/roots/unit.d.ts +36 -0
- package/out/_internal/schema/runtime.d.ts +29 -0
- package/out/_internal/schema/runtimeLean.d.ts +2 -0
- package/out/_internal/schema/runtimeNone.d.ts +2 -0
- package/out/_internal/schema/runtimeNoneLean.d.ts +2 -0
- package/out/_internal/schema/scope.d.ts +203 -0
- package/out/_internal/schema/shared/codecs.d.ts +5 -0
- package/out/_internal/schema/shared/compile.d.ts +144 -0
- package/out/_internal/schema/shared/configured.d.ts +14 -0
- package/out/_internal/schema/shared/declare.d.ts +100 -0
- package/out/_internal/schema/shared/disjoint.d.ts +45 -0
- package/out/_internal/schema/shared/enWriters.d.ts +30 -0
- package/out/_internal/schema/shared/errorModes.d.ts +25 -0
- package/out/_internal/schema/shared/errorWriters.d.ts +34 -0
- package/out/_internal/schema/shared/errors.d.ts +264 -0
- package/out/_internal/schema/shared/implement.d.ts +154 -0
- package/out/_internal/schema/shared/inPlace.d.ts +8 -0
- package/out/_internal/schema/shared/issueFeatures.d.ts +38 -0
- package/out/_internal/schema/shared/issues.d.ts +261 -0
- package/out/_internal/schema/shared/issuesLean.d.ts +80 -0
- package/out/_internal/schema/shared/issuesNone.d.ts +22 -0
- package/out/_internal/schema/shared/issuesNoneLean.d.ts +20 -0
- package/out/_internal/schema/shared/issuesUndetailed.d.ts +25 -0
- package/out/_internal/schema/shared/jsonSchema.d.ts +153 -0
- package/out/_internal/schema/shared/listed.d.ts +15 -0
- package/out/_internal/schema/shared/locale.d.ts +149 -0
- package/out/_internal/schema/shared/registry.d.ts +16 -0
- package/out/_internal/schema/shared/render.d.ts +3 -0
- package/out/_internal/schema/shared/rootApply.d.ts +19 -0
- package/out/_internal/schema/shared/sets.d.ts +26 -0
- package/out/_internal/schema/shared/standardFailure.d.ts +22 -0
- package/out/_internal/schema/shared/standardSchema.d.ts +124 -0
- package/out/_internal/schema/shared/toJsonSchema.d.ts +229 -0
- package/out/_internal/schema/shared/transform.d.ts +35 -0
- package/out/_internal/schema/shared/traversal.d.ts +288 -0
- package/out/_internal/schema/shared/utils.d.ts +59 -0
- package/out/_internal/schema/structure/index.d.ts +43 -0
- package/out/_internal/schema/structure/optional.d.ts +61 -0
- package/out/_internal/schema/structure/prop.d.ts +45 -0
- package/out/_internal/schema/structure/required.d.ts +49 -0
- package/out/_internal/schema/structure/sequence.d.ts +127 -0
- package/out/_internal/schema/structure/shared.d.ts +3 -0
- package/out/_internal/schema/structure/structure.d.ts +178 -0
- package/out/_internal/schema/units.d.ts +123 -0
- package/out/_internal/sets/algebra.d.ts +26 -0
- package/out/_internal/sets/constraint.d.ts +19 -0
- package/out/_internal/sets/engine.d.ts +2 -0
- package/out/_internal/sets/formats.d.ts +23 -0
- package/out/_internal/sets/fromJsonSchema.d.ts +15 -0
- package/out/_internal/sets/implement.d.ts +16 -0
- package/out/_internal/sets/index.d.ts +2 -0
- package/out/_internal/sets/internal.d.ts +20 -0
- package/out/_internal/sets/intersections.d.ts +5 -0
- package/out/_internal/sets/kinds.d.ts +3 -0
- package/out/_internal/sets/refinements.d.ts +14 -0
- package/out/_internal/sets/roots/alias.d.ts +3 -0
- package/out/_internal/sets/roots/domain.d.ts +3 -0
- package/out/_internal/sets/roots/intersection.d.ts +4 -0
- package/out/_internal/sets/roots/morph.d.ts +4 -0
- package/out/_internal/sets/roots/proto.d.ts +3 -0
- package/out/_internal/sets/roots/union.d.ts +16 -0
- package/out/_internal/sets/roots/unit.d.ts +3 -0
- package/out/_internal/sets/structure/index.d.ts +3 -0
- package/out/_internal/sets/structure/prop.d.ts +8 -0
- package/out/_internal/sets/structure/sequence.d.ts +3 -0
- package/out/_internal/sets/structure/structure.d.ts +3 -0
- package/out/_internal/sets/toJsonSchema.d.ts +25 -0
- package/out/_internal/util/arrays.d.ts +130 -0
- package/out/_internal/util/clone.d.ts +4 -0
- package/out/_internal/util/describe.d.ts +25 -0
- package/out/_internal/util/domain.d.ts +49 -0
- package/out/_internal/util/errors.d.ts +29 -0
- package/out/_internal/util/facts.d.ts +22 -0
- package/out/_internal/util/flatMorph.d.ts +41 -0
- package/out/_internal/util/formats.d.ts +8 -0
- package/out/_internal/util/functions.d.ts +33 -0
- package/out/_internal/util/generics.d.ts +65 -0
- package/out/_internal/util/get.d.ts +9 -0
- package/out/_internal/util/hkt.d.ts +27 -0
- package/out/_internal/util/i18n.d.ts +12 -0
- package/out/_internal/util/index.d.ts +28 -0
- package/out/_internal/util/internal.d.ts +2 -0
- package/out/_internal/util/intersections.d.ts +50 -0
- package/out/_internal/util/isomorphic.d.ts +8 -0
- package/out/_internal/util/keys.d.ts +18 -0
- package/out/_internal/util/lazily.d.ts +7 -0
- package/out/_internal/util/numbers.d.ts +82 -0
- package/out/_internal/util/objectKinds.d.ts +157 -0
- package/out/_internal/util/path.d.ts +16 -0
- package/out/_internal/util/primitive.d.ts +16 -0
- package/out/_internal/util/records.d.ts +173 -0
- package/out/_internal/util/registry.d.ts +13 -0
- package/out/_internal/util/scanner.d.ts +110 -0
- package/out/_internal/util/serialize.d.ts +40 -0
- package/out/_internal/util/strings.d.ts +35 -0
- package/out/_internal/util/traits.d.ts +89 -0
- package/out/_internal/util/unionToTuple.d.ts +14 -0
- package/out/_internal/util/weak.d.ts +8 -0
- package/out/attributes.d.ts +15 -11
- package/out/checkers.d.ts +1 -1
- package/out/chunk-22RQSVV3.js +0 -0
- package/out/chunk-3HZC67MT.js +965 -0
- package/out/chunk-3KBOPH3J.js +1564 -0
- package/out/chunk-3SH2BQ4T.js +15 -0
- package/out/chunk-46PLKNON.js +126 -0
- package/out/{chunk-G45P2CLE.js → chunk-4FTHWK63.js} +6 -1
- package/out/{chunk-UK5UGFOX.js → chunk-4HREHNIV.js} +23 -11
- package/out/chunk-4NZCLVBD.js +14 -0
- package/out/chunk-6FMBO47M.js +7 -0
- package/out/chunk-7TALAWYX.js +10 -0
- package/out/{chunk-DLWCO4RV.js → chunk-BCYKO54Z.js} +11 -2
- package/out/chunk-BDJVONP7.js +168 -0
- package/out/{chunk-E3DZXEZK.js → chunk-C2JOL5M2.js} +4 -2
- package/out/{chunk-2U2AWCI3.js → chunk-C2V6QPE3.js} +126 -97
- package/out/chunk-C3B4IFQL.js +6408 -0
- package/out/chunk-CWSF57VM.js +10 -0
- package/out/chunk-F5BACUJS.js +7 -0
- package/out/{chunk-EVCML554.js → chunk-FWRSDUJ2.js} +14 -5
- package/out/chunk-GID3FSQA.js +161 -0
- package/out/chunk-I2KLQ2HA.js +22 -0
- package/out/chunk-K7SLP5D2.js +84 -0
- package/out/chunk-KQPSKGUI.js +9 -0
- package/out/chunk-KXOC3JEX.js +8234 -0
- package/out/chunk-KXOSUYRA.js +405 -0
- package/out/chunk-LHNEY6QW.js +0 -0
- package/out/chunk-MTWKGAGO.js +323 -0
- package/out/chunk-NU73GNCX.js +170 -0
- package/out/{chunk-RAZ3TXOE.js → chunk-P5W67FQH.js} +34 -19
- package/out/chunk-PDLTEX6Z.js +1118 -0
- package/out/{chunk-VV6YDN2D.js → chunk-QUS4IAXJ.js} +304 -263
- package/out/chunk-R7WXIH5P.js +94 -0
- package/out/chunk-TACLEIDM.js +95 -0
- package/out/chunk-UJJGG4VQ.js +71 -0
- package/out/chunk-US6BWOGJ.js +109 -0
- package/out/chunk-VMMMOO4R.js +945 -0
- package/out/chunk-VYMXHSFR.js +439 -0
- package/out/chunk-W2XOI5DY.js +141 -0
- package/out/chunk-WC5L5YRP.js +25 -0
- package/out/{chunk-NRIGTMPM.js → chunk-WKOSL2G6.js} +4 -1
- package/out/chunk-XLG66ZDF.js +0 -0
- package/out/{chunk-5U2ZMDNI.js → chunk-XNUAQSJ4.js} +52 -30
- package/out/chunk-ZRYEHGSG.js +79 -0
- package/out/cli.d.ts +28 -0
- package/out/cli.js +636 -0
- package/out/codecs.d.ts +6 -5
- package/out/codecs.js +23 -7
- package/out/config.d.ts +5 -17
- package/out/config.js +11 -2
- package/out/declare.d.ts +40 -12
- package/out/deferred.d.ts +2 -2
- package/out/errors.d.ts +1 -1
- package/out/errors.js +10 -2
- package/out/fn.d.ts +20 -13
- package/out/fromJsonSchema.d.ts +18 -0
- package/out/generic.d.ts +9 -6
- package/out/i18n.d.ts +2 -2
- package/out/i18n.js +9 -2
- package/out/index.d.ts +16 -7
- package/out/index.js +25 -8
- package/out/internal.d.ts +4 -0
- package/out/internal.js +41 -17
- package/out/island.js +22 -6
- package/out/islandDependency.js +42 -18
- package/out/jsonSchema/infer.d.ts +805 -0
- package/out/jsonSchema/validate.d.ts +416 -0
- package/out/keywords/Array.d.ts +2 -2
- package/out/keywords/builtins.d.ts +3 -3
- package/out/keywords/constructors.d.ts +1 -1
- package/out/keywords/functions.d.ts +5 -192
- package/out/keywords/keywords.d.ts +3 -3
- package/out/keywords/number.d.ts +2 -2
- package/out/keywords/phrases.d.ts +4 -191
- package/out/keywords/string.d.ts +3 -3
- package/out/keywords/ts.d.ts +18 -18
- package/out/keywords/ts.js +19 -4
- package/out/locale.d.ts +6 -2
- package/out/locales/de.js +9 -2
- package/out/locales/en.js +21 -5
- package/out/match.d.ts +13 -10
- package/out/module.d.ts +2 -2
- package/out/mutatesInput.js +18 -3
- package/out/nary.d.ts +220 -194
- package/out/parser/ast/bounds.d.ts +2 -2
- package/out/parser/ast/default.d.ts +2 -2
- package/out/parser/ast/divisor.d.ts +2 -2
- package/out/parser/ast/generic.d.ts +2 -2
- package/out/parser/ast/infer.d.ts +1 -1
- package/out/parser/ast/keyof.d.ts +2 -2
- package/out/parser/ast/utils.d.ts +1 -1
- package/out/parser/ast/validate.d.ts +2 -2
- package/out/parser/definition.d.ts +4 -4
- package/out/parser/objectLiteral.d.ts +2 -2
- package/out/parser/property.d.ts +2 -2
- package/out/parser/reduce/dynamic.d.ts +2 -2
- package/out/parser/reduce/shared.d.ts +1 -1
- package/out/parser/reduce/static.d.ts +1 -1
- package/out/parser/shift/operand/enclosed.d.ts +2 -2
- package/out/parser/shift/operand/genericArgs.d.ts +2 -2
- package/out/parser/shift/operand/operand.d.ts +1 -1
- package/out/parser/shift/operand/unenclosed.d.ts +2 -2
- package/out/parser/shift/operand/unresolvable.d.ts +2 -2
- package/out/parser/shift/operator/bounds.d.ts +2 -2
- package/out/parser/shift/operator/brand.d.ts +2 -2
- package/out/parser/shift/operator/default.d.ts +4 -4
- package/out/parser/shift/operator/divisor.d.ts +1 -1
- package/out/parser/shift/operator/operator.d.ts +1 -1
- package/out/parser/shift/tokens.d.ts +1 -1
- package/out/parser/string.d.ts +2 -2
- package/out/parser/tupleExpressions.d.ts +6 -8
- package/out/parser/tupleLiteral.d.ts +2 -2
- package/out/precompiled.d.ts +1 -1
- package/out/precompiled.js +16 -2
- package/out/regex.d.ts +1 -0
- package/out/regex.js +2 -0
- package/out/runtime.d.ts +10 -8
- package/out/runtime.js +6 -4
- package/out/runtimeDevelopment.js +70 -52
- package/out/schema.d.ts +1 -0
- package/out/schema.js +15 -0
- package/out/schemaInternal.d.ts +1 -0
- package/out/schemaInternal.js +1401 -0
- package/out/schemaIssueFeatures.d.ts +1 -0
- package/out/schemaRuntime.d.ts +1 -0
- package/out/schemaRuntime.js +7 -0
- package/out/schemaRuntimeLean.d.ts +1 -0
- package/out/schemaRuntimeLean.js +1870 -0
- package/out/schemaRuntimeNone.d.ts +1 -0
- package/out/schemaRuntimeNone.js +1774 -0
- package/out/schemaRuntimeNoneLean.d.ts +1 -0
- package/out/schemaRuntimeNoneLean.js +1767 -0
- package/out/scope.d.ts +3 -4
- package/out/shared/issueFeatures.d.ts +38 -0
- package/out/shared/issueFeatures.js +40 -0
- package/out/standalone/artifact.d.ts +6 -6
- package/out/standalone/baking.d.ts +2 -2
- package/out/standalone/combinators.d.ts +1 -1
- package/out/standalone/compilers.d.ts +1 -1
- package/out/standalone/fallbacks.d.ts +1 -1
- package/out/standalone/keys.d.ts +1 -1
- package/out/standalone/sites.d.ts +3 -3
- package/out/standalone/units.d.ts +1 -1
- package/out/standalone/values.d.ts +1 -1
- package/out/type.d.ts +6 -6
- package/out/util.d.ts +1 -0
- package/out/util.js +137 -0
- package/out/variants/array.d.ts +6 -6
- package/out/variants/base.d.ts +61 -10
- package/out/variants/date.d.ts +5 -5
- package/out/variants/instantiate.d.ts +1 -1
- package/out/variants/number.d.ts +6 -6
- package/out/variants/object.d.ts +25 -12
- package/out/variants/string.d.ts +8 -8
- package/package.json +183 -8
- package/skills/arktype/SKILL.md +93 -93
- package/skills/arktype/references/migrating.md +144 -158
- package/skills/arktype/references/precompile.md +7 -7
- package/out/chunk-4CUA5XIP.js +0 -7
- package/out/chunk-GPNK5353.js +0 -2529
- package/out/chunk-MLKGABMK.js +0 -9
- package/out/chunk-PRTMQCHS.js +0 -3
- package/out/chunk-R5G57XC7.js +0 -7
- package/out/chunk-SWOOCAHN.js +0 -4
- package/out/chunk-TAHPKDNM.js +0 -3
- package/out/chunk-UETB6YE2.js +0 -14
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
import { type BuiltinObjectKind, type Domain, type ListType, type omit } from "../../util/index.js";
|
|
2
|
+
import type { MissingBasis, MissingValue } from "../structure/required.ts";
|
|
3
|
+
import { type ActualContext, type ArkError, type ArkErrorCode, type ExpectedContext, type getAssociatedDataForError, type LineContext, type MessageContext } from "./errors.ts";
|
|
4
|
+
import type { ArkEnv } from "./declare.ts";
|
|
5
|
+
export type PluralCategory = "zero" | "one" | "two" | "few" | "many" | "other";
|
|
6
|
+
/** a domain, a builtin object kind, or the types unknown and never */
|
|
7
|
+
export type NounId = Domain | BuiltinObjectKind | "unknown" | "never";
|
|
8
|
+
/**
|
|
9
|
+
* A locale you write: its tag and any part you replace, each part you leave
|
|
10
|
+
* out written as en writes it. Every key but `tag` is optional, so a locale
|
|
11
|
+
* written against one minor version still type-checks against the next, which
|
|
12
|
+
* may add an error code, a noun or a keyword. Annotate with `Locale.Complete`
|
|
13
|
+
* to find what's untranslated instead.
|
|
14
|
+
*/
|
|
15
|
+
export type Locale<keywordAlias extends string = string> = {
|
|
16
|
+
/** BCP 47 tag */
|
|
17
|
+
readonly tag: string;
|
|
18
|
+
} & {
|
|
19
|
+
readonly [k in Exclude<keyof Locale.Data<keywordAlias>, "tag" | "nouns">]?: Locale.Data<keywordAlias>[k];
|
|
20
|
+
} & {
|
|
21
|
+
readonly nouns?: {
|
|
22
|
+
readonly [id in NounId]?: string;
|
|
23
|
+
};
|
|
24
|
+
} & {
|
|
25
|
+
readonly [code in ArkErrorCode]?: codeWritersOf<code>;
|
|
26
|
+
};
|
|
27
|
+
export declare namespace Locale {
|
|
28
|
+
/** what every locale has: all a writer you configure sees */
|
|
29
|
+
interface Info {
|
|
30
|
+
/** BCP 47 tag */
|
|
31
|
+
readonly tag: string;
|
|
32
|
+
readonly list: (items: readonly string[], type: ListType) => string;
|
|
33
|
+
readonly plural: (n: number) => PluralCategory;
|
|
34
|
+
readonly number: (n: number | bigint) => string;
|
|
35
|
+
readonly date: (date: Date) => string;
|
|
36
|
+
/** wraps text shown as written: paths, printed values, names */
|
|
37
|
+
readonly verbatim: (text: string) => string;
|
|
38
|
+
}
|
|
39
|
+
interface Data<keywordAlias extends string = string> extends Info {
|
|
40
|
+
/** names expected text written without the locale, like a description */
|
|
41
|
+
readonly cite: (text: string) => string;
|
|
42
|
+
/** names one alternative of a missing value */
|
|
43
|
+
readonly basis: (basis: MissingBasis, locale: Resolved) => string;
|
|
44
|
+
/** each type's name, as the locale's "must be" takes it */
|
|
45
|
+
readonly nouns: {
|
|
46
|
+
readonly [id in NounId]: string;
|
|
47
|
+
};
|
|
48
|
+
readonly keywordPhrases: {
|
|
49
|
+
readonly [alias in keywordAlias]?: KeywordPhrase;
|
|
50
|
+
};
|
|
51
|
+
readonly actual: ActualWriter;
|
|
52
|
+
/** the message of a keyword's phrase or of expected text you wrote */
|
|
53
|
+
readonly message: MessageWriter;
|
|
54
|
+
/**
|
|
55
|
+
* an error's line of a summary: its message after the path it failed
|
|
56
|
+
* at. Only written below the root, and not for a union listing its
|
|
57
|
+
* branches' errors, each of which names its own path
|
|
58
|
+
*/
|
|
59
|
+
readonly line: LineWriter;
|
|
60
|
+
}
|
|
61
|
+
type Writers = {
|
|
62
|
+
readonly [code in ArkErrorCode]: codeWritersOf<code>;
|
|
63
|
+
};
|
|
64
|
+
/**
|
|
65
|
+
* A locale as its writers receive it: every part, those its author left
|
|
66
|
+
* out completed from en
|
|
67
|
+
*/
|
|
68
|
+
type Resolved<keywordAlias extends string = string> = Data<keywordAlias> & Writers;
|
|
69
|
+
type CodeWriters<code extends ArkErrorCode = ArkErrorCode> = {
|
|
70
|
+
/**
|
|
71
|
+
* the sentence for an error of this code, without its subject. Without
|
|
72
|
+
* one, the locale's `message` writes it from `expected`
|
|
73
|
+
*/
|
|
74
|
+
readonly message?: string | MessageWriter<code>;
|
|
75
|
+
/** what unions list, as "must be" takes it */
|
|
76
|
+
readonly expected?: string | ExpectedWriter<code>;
|
|
77
|
+
readonly actual?: string | ActualWriter<code>;
|
|
78
|
+
};
|
|
79
|
+
type ExpectedContext<code extends ArkErrorCode = ArkErrorCode> = localeExpectedContext<code>;
|
|
80
|
+
type ExpectedWriter<code extends ArkErrorCode = ArkErrorCode> = (error: ExpectedContext<code>, locale: Resolved) => string;
|
|
81
|
+
type ActualWriter<code extends ArkErrorCode = ArkErrorCode> = (data: getAssociatedDataForError<code>, error: ActualContext<code>, locale: Resolved) => string;
|
|
82
|
+
type MessageWriter<code extends ArkErrorCode = ArkErrorCode> = (error: MessageContext<code>, locale: Resolved) => string;
|
|
83
|
+
type LineWriter = (error: LineContext, locale: Resolved) => string;
|
|
84
|
+
type KeywordPhrase = string | KeywordWriters;
|
|
85
|
+
type KeywordWriters = Partial<Omit<CodeWriters, "expected">> & {
|
|
86
|
+
readonly noun: string;
|
|
87
|
+
readonly expected?: string | KeywordExpectedWriter;
|
|
88
|
+
};
|
|
89
|
+
/** describes an error, or a missing value by its basis */
|
|
90
|
+
type KeywordExpectedWriter = (error: ExpectedContext | MissingBasis, locale: Resolved) => string;
|
|
91
|
+
/**
|
|
92
|
+
* A locale with every part: a message and fragment for each code its
|
|
93
|
+
* errors are raised with, and a phrase for every keyword, which its
|
|
94
|
+
* unions may list. A minor version adding a code, noun or keyword adds
|
|
95
|
+
* it here, so annotate a locale with it to find what's untranslated,
|
|
96
|
+
* not one you publish
|
|
97
|
+
*/
|
|
98
|
+
type Complete<keywordAlias extends string = string> = Resolved<keywordAlias> & {
|
|
99
|
+
readonly [code in ArkErrorCode]: {
|
|
100
|
+
readonly message: string | MessageWriter<code>;
|
|
101
|
+
readonly expected: string | ExpectedWriter<code>;
|
|
102
|
+
};
|
|
103
|
+
} & {
|
|
104
|
+
readonly keywordPhrases: {
|
|
105
|
+
readonly [alias in keywordAlias]: KeywordPhrase;
|
|
106
|
+
};
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
type codeWritersOf<code extends ArkErrorCode> = code extends "required" ? Locale.CodeWriters<code> & {
|
|
110
|
+
readonly actual: string | Locale.ActualWriter<code>;
|
|
111
|
+
} : Locale.CodeWriters<code>;
|
|
112
|
+
type localeExpectedContext<code extends ArkErrorCode> = code extends "required" ? omit<ExpectedContext<code>, "description" | "missingValueDescription"> : code extends unknown ? omit<ExpectedContext<code>, "description"> : never;
|
|
113
|
+
/** the writer a locale has for an error's keyword in a slot other than expected */
|
|
114
|
+
export declare const keywordWriterOf: <slot extends "actual" | "message">(error: {
|
|
115
|
+
readonly meta?: ArkEnv.meta;
|
|
116
|
+
}, locale: Locale.Resolved, slot: slot) => Locale.KeywordWriters[slot] | undefined;
|
|
117
|
+
/** a locale's phrase for a keyword, if it has one, as expected text */
|
|
118
|
+
export declare const writeKeywordExpected: (error: Locale.ExpectedContext | MissingBasis, locale: Locale.Resolved) => string | undefined;
|
|
119
|
+
/** renders a missing value where expected text goes */
|
|
120
|
+
export declare const describeMissing: (missing: MissingValue, locale: Locale.Resolved) => string;
|
|
121
|
+
export interface PathGroup {
|
|
122
|
+
readonly propString: string;
|
|
123
|
+
/** the title of the value at the path */
|
|
124
|
+
readonly label: string | undefined;
|
|
125
|
+
/** each error's expected text, once */
|
|
126
|
+
readonly expected: readonly string[];
|
|
127
|
+
/** the errors' actual text, unless they differ */
|
|
128
|
+
readonly actual: string | undefined;
|
|
129
|
+
/** the value at the path */
|
|
130
|
+
readonly data: unknown;
|
|
131
|
+
}
|
|
132
|
+
/** a union's errors by path, in the order each path first failed */
|
|
133
|
+
export declare const groupByPath: (union: Locale.ExpectedContext<"union">, locale: Locale.Resolved) => PathGroup[];
|
|
134
|
+
/**
|
|
135
|
+
* what an error expects, as the alternatives a union lists once each: a
|
|
136
|
+
* missing value's branches or a discriminant's cases, as the branches it
|
|
137
|
+
* excluded would name them, unless its expected text is authored
|
|
138
|
+
*/
|
|
139
|
+
export declare const alternativesOf: (error: ArkError, locale: Locale.Resolved) => readonly string[];
|
|
140
|
+
/** the actual a union's errors agree on, if each is at the union's own path */
|
|
141
|
+
export declare const actualAtPathOf: (union: {
|
|
142
|
+
readonly propString: string;
|
|
143
|
+
readonly errors: readonly ArkError[];
|
|
144
|
+
}) => string | undefined;
|
|
145
|
+
/** a thrown value as text, though it may be a symbol or have no toString */
|
|
146
|
+
export declare const describeCause: (cause: unknown) => string;
|
|
147
|
+
/** the title of the value an error is about */
|
|
148
|
+
export declare const labelOf: (error: Locale.ExpectedContext) => string | undefined;
|
|
149
|
+
export {};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { type Brand, type NonNegativeIntegerLiteral } from "../../util/index.js";
|
|
2
|
+
import type { ArkSchemaRegistry } from "../config.ts";
|
|
3
|
+
import type { BaseNode } from "../node.ts";
|
|
4
|
+
import type { BaseParseContext } from "../parse.ts";
|
|
5
|
+
import type { BaseRoot } from "../roots/root.ts";
|
|
6
|
+
export declare const registryName: string;
|
|
7
|
+
export declare const $ark: ArkSchemaRegistry;
|
|
8
|
+
export type NodeId = Brand<string, "NodeId">;
|
|
9
|
+
export declare const nodesById: Record<NodeId, BaseNode | BaseParseContext | undefined>;
|
|
10
|
+
export declare const ambientResolver: {
|
|
11
|
+
resolve?: (name: string) => BaseRoot | undefined;
|
|
12
|
+
};
|
|
13
|
+
export declare const reference: (name: string) => RegisteredReference;
|
|
14
|
+
export declare const registeredReference: (value: object | symbol) => RegisteredReference;
|
|
15
|
+
export declare const namedReference: (value: object | symbol) => RegisteredReference;
|
|
16
|
+
export type RegisteredReference<to extends string = string> = `$ark${"" | NonNegativeIntegerLiteral}.${to}`;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { BaseRoot } from "../roots/root.ts";
|
|
2
|
+
import { applyUnread, ArkTraversal } from "./errors.ts";
|
|
3
|
+
import { TransformErrors } from "./transform.ts";
|
|
4
|
+
import { addMorphErrs, allowsAcyclic, allowsInContext, applyCyclic, transformResolution } from "./traversal.ts";
|
|
5
|
+
export declare const rootApplyRuntime: {
|
|
6
|
+
Traversal: typeof ArkTraversal;
|
|
7
|
+
TransformErrors: typeof TransformErrors;
|
|
8
|
+
addMorphErrs: typeof addMorphErrs;
|
|
9
|
+
applyCyclic: typeof applyCyclic;
|
|
10
|
+
applyRejected: typeof applyUnread;
|
|
11
|
+
allowsAcyclic: typeof allowsAcyclic;
|
|
12
|
+
allowsInContext: typeof allowsInContext;
|
|
13
|
+
transformResolution: typeof transformResolution;
|
|
14
|
+
};
|
|
15
|
+
export type RootApplyRuntime = typeof rootApplyRuntime;
|
|
16
|
+
export declare const rootApplyParams: readonly ["node", "config", ...string[]];
|
|
17
|
+
export type RootApplyParam = "config" | keyof RootApplyRuntime;
|
|
18
|
+
export declare const writeRootApply: (node: BaseRoot, name: string) => string;
|
|
19
|
+
export declare const rootApplyParts: (node: BaseRoot, name: string, refOf?: (param: RootApplyParam) => string) => [reads: string[], rootApply: string, applyFailed: string | undefined];
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { type dict } from "../../util/index.js";
|
|
2
|
+
import type { BaseNode } from "../node.ts";
|
|
3
|
+
import type { BaseRoot } from "../roots/root.ts";
|
|
4
|
+
import type { Intersection } from "../roots/intersection.ts";
|
|
5
|
+
import type { Discriminant, Union } from "../roots/union.ts";
|
|
6
|
+
import type { BaseScope } from "../scope.ts";
|
|
7
|
+
import type { Disjoint } from "./disjoint.ts";
|
|
8
|
+
import type { NodeKind, RootKind } from "./implement.ts";
|
|
9
|
+
import type { JsonSchema } from "./jsonSchema.ts";
|
|
10
|
+
import type { ToJsonSchema } from "./toJsonSchema.ts";
|
|
11
|
+
export interface SetEngine {
|
|
12
|
+
intersect: InternalNodeIntersection<BaseScope>;
|
|
13
|
+
pipe: InternalNodeIntersection<BaseScope>;
|
|
14
|
+
constrain(l: Intersection.Node, inner: Intersection.Inner, $: BaseScope): BaseRoot | Disjoint;
|
|
15
|
+
reduce(kind: NodeKind, inner: dict, $: BaseScope): BaseNode | Disjoint | undefined;
|
|
16
|
+
sort(kind: NodeKind, inner: dict): void;
|
|
17
|
+
discriminate(node: Union.Node): Discriminant | null;
|
|
18
|
+
toJsonSchema(node: BaseRoot, opts: ToJsonSchema.Options): JsonSchema;
|
|
19
|
+
toJsonSchemaRecurse(node: BaseRoot, ctx: ToJsonSchema.Context): JsonSchema;
|
|
20
|
+
disjointOf?(node: BaseNode): Disjoint | undefined;
|
|
21
|
+
registry?: unknown;
|
|
22
|
+
}
|
|
23
|
+
export type InternalNodeIntersection<ctx> = <l extends BaseNode, r extends BaseNode>(l: l, r: r, ctx: ctx) => l["kind"] | r["kind"] extends RootKind ? BaseRoot | Disjoint : BaseNode | Disjoint | null;
|
|
24
|
+
export declare const sets: () => SetEngine;
|
|
25
|
+
export declare const missingSetEngineMessage = "Set algebra is not installed (import \"arktype\" to install it)";
|
|
26
|
+
export type missingSetEngineMessage = typeof missingSetEngineMessage;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { StandardSchemaV1 } from "./standardSchema.ts";
|
|
2
|
+
/** what a failure is built from: errors of any class, each of which writes its own summary */
|
|
3
|
+
export type SummarizedErrors = {
|
|
4
|
+
readonly issues: StandardSchemaV1.FailureResult["issues"];
|
|
5
|
+
readonly summary: string;
|
|
6
|
+
toJSON?: () => readonly unknown[];
|
|
7
|
+
};
|
|
8
|
+
/**
|
|
9
|
+
* @internal a Standard Schema failure of errors: their issues, and their
|
|
10
|
+
* summary as its message once it's read.
|
|
11
|
+
*
|
|
12
|
+
* The summary is the errors' own rather than written from the issues, since
|
|
13
|
+
* each errors class writes its own: arktype's in the locale they were read
|
|
14
|
+
* in. What reads it is a function the failure holds, not the errors: a
|
|
15
|
+
* failure kept in a reactive store is read through a proxy that wraps each
|
|
16
|
+
* object it returns, and errors read through one can't tell their own. It's
|
|
17
|
+
* held where neither a copy, a print nor a comparison of the failure finds
|
|
18
|
+
* it, so the failure reads as Standard Schema's, and writable, as such a
|
|
19
|
+
* proxy may not return another value for a property that's neither writable
|
|
20
|
+
* nor configurable
|
|
21
|
+
*/
|
|
22
|
+
export declare const standardFailureOf: (errors: SummarizedErrors) => StandardSchemaV1.FailureResult;
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
/** From https://github.com/standard-schema/standard-schema */
|
|
2
|
+
/** The Standard Typed interface. This is a base type extended by other specs. */
|
|
3
|
+
export interface StandardTypedV1<Input = unknown, Output = Input> {
|
|
4
|
+
/** The Standard properties. */
|
|
5
|
+
readonly "~standard": StandardTypedV1.Props<Input, Output>;
|
|
6
|
+
}
|
|
7
|
+
export declare namespace StandardTypedV1 {
|
|
8
|
+
/** The Standard Typed properties interface. */
|
|
9
|
+
interface Props<Input = unknown, Output = Input> {
|
|
10
|
+
/** The version number of the standard. */
|
|
11
|
+
readonly version: 1;
|
|
12
|
+
/** The vendor name of the schema library. */
|
|
13
|
+
readonly vendor: string;
|
|
14
|
+
/** Inferred types associated with the schema. */
|
|
15
|
+
readonly types?: Types<Input, Output> | undefined;
|
|
16
|
+
}
|
|
17
|
+
/** The Standard Typed types interface. */
|
|
18
|
+
interface Types<Input = unknown, Output = Input> {
|
|
19
|
+
/** The input type of the schema. */
|
|
20
|
+
readonly input: Input;
|
|
21
|
+
/** The output type of the schema. */
|
|
22
|
+
readonly output: Output;
|
|
23
|
+
}
|
|
24
|
+
/** Infers the input type of a Standard Typed. */
|
|
25
|
+
type InferInput<Schema extends StandardTypedV1> = NonNullable<Schema["~standard"]["types"]>["input"];
|
|
26
|
+
/** Infers the output type of a Standard Typed. */
|
|
27
|
+
type InferOutput<Schema extends StandardTypedV1> = NonNullable<Schema["~standard"]["types"]>["output"];
|
|
28
|
+
}
|
|
29
|
+
/** The Standard Schema interface. */
|
|
30
|
+
export interface StandardSchemaV1<Input = unknown, Output = Input> {
|
|
31
|
+
/** The Standard Schema properties. */
|
|
32
|
+
readonly "~standard": StandardSchemaV1.Props<Input, Output>;
|
|
33
|
+
}
|
|
34
|
+
export declare namespace StandardSchemaV1 {
|
|
35
|
+
/** The Standard Schema properties interface. */
|
|
36
|
+
interface Props<Input = unknown, Output = Input> extends StandardTypedV1.Props<Input, Output> {
|
|
37
|
+
/** Validates unknown input values. */
|
|
38
|
+
readonly validate: (value: unknown, options?: StandardSchemaV1.Options | undefined) => Result<Output> | Promise<Result<Output>>;
|
|
39
|
+
}
|
|
40
|
+
/** The result interface of the validate function. */
|
|
41
|
+
type Result<Output> = SuccessResult<Output> | FailureResult;
|
|
42
|
+
/** The result interface if validation succeeds. */
|
|
43
|
+
interface SuccessResult<Output> {
|
|
44
|
+
/** The typed output value. */
|
|
45
|
+
readonly value: Output;
|
|
46
|
+
/** A falsy value for `issues` indicates success. */
|
|
47
|
+
readonly issues?: undefined;
|
|
48
|
+
}
|
|
49
|
+
interface Options {
|
|
50
|
+
/** Explicit support for additional vendor-specific parameters, if needed. */
|
|
51
|
+
readonly libraryOptions?: Record<string, unknown> | undefined;
|
|
52
|
+
}
|
|
53
|
+
/** The result interface if validation fails. */
|
|
54
|
+
interface FailureResult {
|
|
55
|
+
/** The issues of failed validation. */
|
|
56
|
+
readonly issues: ReadonlyArray<Issue>;
|
|
57
|
+
/** A human-readable summary of the failure, if the library provides one. When present, prefer it over a message built from `issues`. */
|
|
58
|
+
readonly message?: string | undefined;
|
|
59
|
+
}
|
|
60
|
+
/** The issue interface of the failure output. */
|
|
61
|
+
interface Issue {
|
|
62
|
+
/** The error message of the issue. */
|
|
63
|
+
readonly message: string;
|
|
64
|
+
/** The path of the issue, if any. */
|
|
65
|
+
readonly path?: ReadonlyArray<PropertyKey | PathSegment> | undefined;
|
|
66
|
+
}
|
|
67
|
+
/** The path segment interface of the issue. */
|
|
68
|
+
interface PathSegment {
|
|
69
|
+
/** The key representing a path segment. */
|
|
70
|
+
readonly key: PropertyKey;
|
|
71
|
+
}
|
|
72
|
+
/** The Standard types interface. */
|
|
73
|
+
interface Types<Input = unknown, Output = Input> extends StandardTypedV1.Types<Input, Output> {
|
|
74
|
+
}
|
|
75
|
+
/** Infers the input type of a Standard. */
|
|
76
|
+
type InferInput<Schema extends StandardTypedV1> = StandardTypedV1.InferInput<Schema>;
|
|
77
|
+
/** Infers the output type of a Standard. */
|
|
78
|
+
type InferOutput<Schema extends StandardTypedV1> = StandardTypedV1.InferOutput<Schema>;
|
|
79
|
+
/** ArkType-specific properties that extend the standard schema with JSON Schema support. */
|
|
80
|
+
interface ArkTypeProps<Input = unknown, Output = Input> extends Props<Input, Output>, StandardJSONSchemaV1.Props<Input, Output> {
|
|
81
|
+
vendor: "arktype";
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
/** The Standard JSON Schema interface. */
|
|
85
|
+
export interface StandardJSONSchemaV1<Input = unknown, Output = Input> {
|
|
86
|
+
/** The Standard JSON Schema properties. */
|
|
87
|
+
readonly "~standard": StandardJSONSchemaV1.Props<Input, Output>;
|
|
88
|
+
}
|
|
89
|
+
export declare namespace StandardJSONSchemaV1 {
|
|
90
|
+
/** The Standard JSON Schema properties interface. */
|
|
91
|
+
interface Props<Input = unknown, Output = Input> extends StandardTypedV1.Props<Input, Output> {
|
|
92
|
+
/** Methods for generating the input/output JSON Schema. */
|
|
93
|
+
readonly jsonSchema: StandardJSONSchemaV1.Converter;
|
|
94
|
+
}
|
|
95
|
+
/** The Standard JSON Schema converter interface. */
|
|
96
|
+
interface Converter {
|
|
97
|
+
/** Converts the input type to JSON Schema. May throw if conversion is not supported. */
|
|
98
|
+
readonly input: (options: StandardJSONSchemaV1.Options) => Record<string, unknown>;
|
|
99
|
+
/** Converts the output type to JSON Schema. May throw if conversion is not supported. */
|
|
100
|
+
readonly output: (options: StandardJSONSchemaV1.Options) => Record<string, unknown>;
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* The target version of the generated JSON Schema.
|
|
104
|
+
*
|
|
105
|
+
* It is *strongly recommended* that implementers support `"draft-2020-12"` and `"draft-07"`, as they are both in wide use. All other targets can be implemented on a best-effort basis. Libraries should throw if they don't support a specified target.
|
|
106
|
+
*
|
|
107
|
+
* The `"openapi-3.0"` target is intended as a standardized specifier for OpenAPI 3.0 which is a superset of JSON Schema `"draft-04"`.
|
|
108
|
+
*/
|
|
109
|
+
type Target = "draft-2020-12" | "draft-07" | "openapi-3.0" | ({} & string);
|
|
110
|
+
/** The options for the input/output methods. */
|
|
111
|
+
interface Options {
|
|
112
|
+
/** Specifies the target version of the generated JSON Schema. Support for all versions is on a best-effort basis. If a given version is not supported, the library should throw. */
|
|
113
|
+
readonly target: Target;
|
|
114
|
+
/** Explicit support for additional vendor-specific parameters, if needed. */
|
|
115
|
+
readonly libraryOptions?: Record<string, unknown> | undefined;
|
|
116
|
+
}
|
|
117
|
+
/** The Standard types interface. */
|
|
118
|
+
interface Types<Input = unknown, Output = Input> extends StandardTypedV1.Types<Input, Output> {
|
|
119
|
+
}
|
|
120
|
+
/** Infers the input type of a Standard. */
|
|
121
|
+
type InferInput<Schema extends StandardTypedV1> = StandardTypedV1.InferInput<Schema>;
|
|
122
|
+
/** Infers the output type of a Standard. */
|
|
123
|
+
type InferOutput<Schema extends StandardTypedV1> = StandardTypedV1.InferOutput<Schema>;
|
|
124
|
+
}
|
|
@@ -0,0 +1,229 @@
|
|
|
1
|
+
import { type Constructor, type Domain, type Json, type requireKeys, type satisfy } from "../../util/index.js";
|
|
2
|
+
import type { Predicate } from "../predicate.ts";
|
|
3
|
+
import { type ConstraintKind } from "./implement.ts";
|
|
4
|
+
import { ToJsonSchemaError, type JsonSchema, type writeNullableJsonSchema, type writeUnionJsonSchema } from "./jsonSchema.ts";
|
|
5
|
+
import type { StandardJSONSchemaV1, StandardSchemaV1 } from "./standardSchema.ts";
|
|
6
|
+
/** the Types from another copy of arktype, like 2.x, by the morph that validates with each */
|
|
7
|
+
export declare const foreignTypesByMorph: WeakMap<Function, StandardSchemaV1>;
|
|
8
|
+
export declare const annotatingFallback: ToJsonSchema.HandlerByCode;
|
|
9
|
+
export interface UnionJsonSchemaWriters {
|
|
10
|
+
union: typeof writeUnionJsonSchema;
|
|
11
|
+
nullable: typeof writeNullableJsonSchema;
|
|
12
|
+
}
|
|
13
|
+
export declare const unionJsonSchemaWritersKey: unique symbol;
|
|
14
|
+
export declare const ToJsonSchema: {
|
|
15
|
+
Error: typeof ToJsonSchemaError;
|
|
16
|
+
throw: (...args: ConstructorParameters<typeof ToJsonSchemaError>) => never;
|
|
17
|
+
throwOperandError: (kind: ConstraintKind, schema: JsonSchema) => never;
|
|
18
|
+
defaultConfig: ToJsonSchema.Context;
|
|
19
|
+
standardFallback: {
|
|
20
|
+
arrayObject: (ctx: ToJsonSchema.ArrayObjectContext) => JsonSchema.Structure;
|
|
21
|
+
arrayPostfix: (ctx: ToJsonSchema.ArrayPostfixContext) => ToJsonSchema.VariadicArraySchema;
|
|
22
|
+
arrayPrefix: (ctx: ToJsonSchema.ArrayPrefixContext) => JsonSchema.Array;
|
|
23
|
+
defaultValue: (ctx: ToJsonSchema.DefaultValueContext) => Json | undefined;
|
|
24
|
+
defs: (ctx: ToJsonSchema.DefsContext) => JsonSchema;
|
|
25
|
+
domain: (ctx: ToJsonSchema.DomainContext) => JsonSchema;
|
|
26
|
+
indexKey: (ctx: ToJsonSchema.IndexKeyContext) => JsonSchema.Object;
|
|
27
|
+
morph: (ctx: ToJsonSchema.MorphContext) => JsonSchema;
|
|
28
|
+
patternFlags: (ctx: ToJsonSchema.PatternFlagsContext) => JsonSchema.String;
|
|
29
|
+
patternIntersection: (ctx: ToJsonSchema.PatternIntersectionContext) => JsonSchema.String;
|
|
30
|
+
predicate: (ctx: ToJsonSchema.PredicateContext) => JsonSchema;
|
|
31
|
+
proto: (ctx: ToJsonSchema.ProtoContext) => JsonSchema;
|
|
32
|
+
symbolKey: (ctx: ToJsonSchema.SymbolKeyContext) => JsonSchema.Object;
|
|
33
|
+
unit: (ctx: ToJsonSchema.UnitContext) => JsonSchema;
|
|
34
|
+
date: (ctx: ToJsonSchema.DateContext) => JsonSchema;
|
|
35
|
+
};
|
|
36
|
+
};
|
|
37
|
+
export declare namespace ToJsonSchema {
|
|
38
|
+
type Unjsonifiable = object | symbol | bigint | undefined;
|
|
39
|
+
type Error = InstanceType<typeof ToJsonSchema.Error>;
|
|
40
|
+
interface BaseContext<code extends Code, base extends JsonSchema = JsonSchema> {
|
|
41
|
+
code: code;
|
|
42
|
+
base: base;
|
|
43
|
+
}
|
|
44
|
+
interface DefaultValueContext {
|
|
45
|
+
code: "defaultValue";
|
|
46
|
+
base?: undefined;
|
|
47
|
+
value: Unjsonifiable;
|
|
48
|
+
}
|
|
49
|
+
interface ArrayObjectContext extends BaseContext<"arrayObject", JsonSchema.Array> {
|
|
50
|
+
object: JsonSchema.Object;
|
|
51
|
+
}
|
|
52
|
+
interface ArrayPostfixContext extends BaseContext<"arrayPostfix", VariadicArraySchema> {
|
|
53
|
+
elements: readonly JsonSchema[];
|
|
54
|
+
}
|
|
55
|
+
interface ArrayPrefixContext extends BaseContext<"arrayPrefix", JsonSchema.Array> {
|
|
56
|
+
elements: readonly JsonSchema[];
|
|
57
|
+
/** the elements after the prefix, if any */
|
|
58
|
+
items?: JsonSchema;
|
|
59
|
+
}
|
|
60
|
+
interface DefsContext extends BaseContext<"defs", JsonSchema> {
|
|
61
|
+
defs: Record<string, JsonSchema>;
|
|
62
|
+
}
|
|
63
|
+
interface DomainContext extends BaseContext<"domain", JsonSchema> {
|
|
64
|
+
domain: satisfy<Domain, "symbol" | "bigint" | "undefined">;
|
|
65
|
+
}
|
|
66
|
+
interface IndexKeyContext extends BaseContext<"indexKey", JsonSchema.Object> {
|
|
67
|
+
key: JsonSchema.String;
|
|
68
|
+
value: JsonSchema;
|
|
69
|
+
}
|
|
70
|
+
interface MorphContext extends BaseContext<"morph", JsonSchema> {
|
|
71
|
+
out: JsonSchema | null;
|
|
72
|
+
}
|
|
73
|
+
interface PatternFlagsContext extends BaseContext<"patternFlags", JsonSchema.String> {
|
|
74
|
+
pattern: string;
|
|
75
|
+
flags: string;
|
|
76
|
+
}
|
|
77
|
+
interface PatternIntersectionContext extends BaseContext<"patternIntersection", StringSchemaWithPattern> {
|
|
78
|
+
pattern: string;
|
|
79
|
+
}
|
|
80
|
+
interface PredicateContext extends BaseContext<"predicate", JsonSchema> {
|
|
81
|
+
predicate: Predicate;
|
|
82
|
+
}
|
|
83
|
+
interface ProtoContext extends BaseContext<"proto", JsonSchema> {
|
|
84
|
+
proto: Constructor;
|
|
85
|
+
}
|
|
86
|
+
type SymbolKeyContext = IndexSymbolKeyContext | RequiredSymbolKeyContext | OptionalSymbolKeyContext;
|
|
87
|
+
interface IndexSymbolKeyContext extends BaseContext<"symbolKey", JsonSchema.Object> {
|
|
88
|
+
key: null;
|
|
89
|
+
value: JsonSchema;
|
|
90
|
+
optional: false;
|
|
91
|
+
}
|
|
92
|
+
interface RequiredSymbolKeyContext extends BaseContext<"symbolKey", JsonSchema.Object> {
|
|
93
|
+
key: symbol;
|
|
94
|
+
value: JsonSchema;
|
|
95
|
+
optional: false;
|
|
96
|
+
}
|
|
97
|
+
interface OptionalSymbolKeyContext extends BaseContext<"symbolKey", JsonSchema.Object> {
|
|
98
|
+
key: symbol;
|
|
99
|
+
value: JsonSchema;
|
|
100
|
+
optional: true;
|
|
101
|
+
default?: Json;
|
|
102
|
+
}
|
|
103
|
+
interface UnitContext extends BaseContext<"unit", JsonSchema> {
|
|
104
|
+
unit: Unjsonifiable;
|
|
105
|
+
}
|
|
106
|
+
interface DateContext extends BaseContext<"date", JsonSchema> {
|
|
107
|
+
before?: Date;
|
|
108
|
+
after?: Date;
|
|
109
|
+
/** each Date excluded with `!=` */
|
|
110
|
+
notEqual?: readonly Date[];
|
|
111
|
+
}
|
|
112
|
+
interface ContextByCode {
|
|
113
|
+
arrayObject: ArrayObjectContext;
|
|
114
|
+
arrayPostfix: ArrayPostfixContext;
|
|
115
|
+
arrayPrefix: ArrayPrefixContext;
|
|
116
|
+
defaultValue: DefaultValueContext;
|
|
117
|
+
defs: DefsContext;
|
|
118
|
+
domain: DomainContext;
|
|
119
|
+
indexKey: IndexKeyContext;
|
|
120
|
+
morph: MorphContext;
|
|
121
|
+
patternFlags: PatternFlagsContext;
|
|
122
|
+
patternIntersection: PatternIntersectionContext;
|
|
123
|
+
predicate: PredicateContext;
|
|
124
|
+
proto: ProtoContext;
|
|
125
|
+
symbolKey: SymbolKeyContext;
|
|
126
|
+
unit: UnitContext;
|
|
127
|
+
date: DateContext;
|
|
128
|
+
}
|
|
129
|
+
type Code = keyof ContextByCode;
|
|
130
|
+
type FallbackContext = ContextByCode[Code];
|
|
131
|
+
type HandlerByCode = satisfy<{
|
|
132
|
+
[code in Code]: (ctx: ContextByCode[code]) => unknown;
|
|
133
|
+
}, {
|
|
134
|
+
arrayObject: (ctx: ArrayObjectContext) => JsonSchema.Structure;
|
|
135
|
+
arrayPostfix: (ctx: ArrayPostfixContext) => VariadicArraySchema;
|
|
136
|
+
arrayPrefix: (ctx: ArrayPrefixContext) => JsonSchema.Array;
|
|
137
|
+
defaultValue: (ctx: DefaultValueContext) => Json | undefined;
|
|
138
|
+
defs: (ctx: DefsContext) => JsonSchema;
|
|
139
|
+
domain: (ctx: DomainContext) => JsonSchema;
|
|
140
|
+
indexKey: (ctx: IndexKeyContext) => JsonSchema.Object;
|
|
141
|
+
morph: (ctx: MorphContext) => JsonSchema;
|
|
142
|
+
patternFlags: (ctx: PatternFlagsContext) => JsonSchema.String;
|
|
143
|
+
patternIntersection: (ctx: PatternIntersectionContext) => JsonSchema.String;
|
|
144
|
+
predicate: (ctx: PredicateContext) => JsonSchema;
|
|
145
|
+
proto: (ctx: ProtoContext) => JsonSchema;
|
|
146
|
+
symbolKey: (ctx: SymbolKeyContext) => JsonSchema.Object;
|
|
147
|
+
unit: (ctx: UnitContext) => JsonSchema;
|
|
148
|
+
date: (ctx: DateContext) => JsonSchema;
|
|
149
|
+
}>;
|
|
150
|
+
type VariadicArraySchema = requireKeys<JsonSchema.Array, "items">;
|
|
151
|
+
type StringSchemaWithPattern = requireKeys<JsonSchema.String, "pattern">;
|
|
152
|
+
type UniversalFallback = (ctx: FallbackContext) => JsonSchema | undefined;
|
|
153
|
+
interface FallbackObject extends Partial<HandlerByCode> {
|
|
154
|
+
default?: UniversalFallback;
|
|
155
|
+
}
|
|
156
|
+
type FallbackOption = UniversalFallback | FallbackObject;
|
|
157
|
+
type Target = satisfy<StandardJSONSchemaV1.Target, "draft-2020-12" | "draft-07" | "openapi-3.0" | "openapi-3.1">;
|
|
158
|
+
interface Options {
|
|
159
|
+
/** value to assign to the generated $schema key
|
|
160
|
+
*
|
|
161
|
+
* - set to `null` to omit the `$schema` key
|
|
162
|
+
* - does not affect the contents of the generated schema
|
|
163
|
+
* - if `target` is also specified, `dialect` takes precedence
|
|
164
|
+
*
|
|
165
|
+
* @default "https://json-schema.org/draft/2020-12/schema"
|
|
166
|
+
*/
|
|
167
|
+
dialect?: string | null;
|
|
168
|
+
/**
|
|
169
|
+
* Shorthand for specifying the target JSON Schema version.
|
|
170
|
+
* Maps to the appropriate `dialect` URL.
|
|
171
|
+
*
|
|
172
|
+
* - "draft-2020-12" -> "https://json-schema.org/draft/2020-12/schema"
|
|
173
|
+
* - "draft-07" -> "http://json-schema.org/draft-07/schema#"
|
|
174
|
+
* - "openapi-3.0" -> no $schema, for an OpenAPI 3.0 Schema Object
|
|
175
|
+
* - "openapi-3.1" -> no $schema, for an OpenAPI 3.1 Schema Object,
|
|
176
|
+
* which is draft-2020-12 with its $refs into #/components/schemas
|
|
177
|
+
*
|
|
178
|
+
* If `dialect` is also specified, `dialect` takes precedence.
|
|
179
|
+
*/
|
|
180
|
+
target?: Target;
|
|
181
|
+
useRefs?: boolean;
|
|
182
|
+
/**
|
|
183
|
+
* Which aliases of the Type's scope are written once as definitions,
|
|
184
|
+
* named by the alias, with a `$ref` wherever they're used. A cyclic
|
|
185
|
+
* alias always is.
|
|
186
|
+
*
|
|
187
|
+
* - `true`: every exported alias, and each of a submodule's, but one
|
|
188
|
+
* that resolves to a basis like `string` or `"a"`
|
|
189
|
+
* - a list of names, private ones included, for exactly those
|
|
190
|
+
*
|
|
191
|
+
* A part is matched by what it is, not where it came from, so a part
|
|
192
|
+
* equal to an alias's resolution is a `$ref` to it too, and of aliases
|
|
193
|
+
* that resolve to the same thing, the first is its name.
|
|
194
|
+
*
|
|
195
|
+
* @default false
|
|
196
|
+
*/
|
|
197
|
+
aliasDefs?: boolean | readonly string[];
|
|
198
|
+
/**
|
|
199
|
+
* whether a union written as `oneOf`, since its object branches each
|
|
200
|
+
* require a different string at one key, names that key with OpenAPI's
|
|
201
|
+
* `discriminator`, and maps each value to a branch that's a `$ref`
|
|
202
|
+
*
|
|
203
|
+
* JSON Schema has no `discriminator` keyword, and a strict validator
|
|
204
|
+
* like Ajv rejects it unless configured to read it
|
|
205
|
+
*
|
|
206
|
+
* @default true for "openapi-3.0" and "openapi-3.1", otherwise false
|
|
207
|
+
*/
|
|
208
|
+
discriminator?: boolean;
|
|
209
|
+
/**
|
|
210
|
+
* Which side of a morph, defaulted key, `"+": "delete"` object, or
|
|
211
|
+
* `undefined`-allowing property to convert:
|
|
212
|
+
* - omitted (default): converts the Type as written (morphs and
|
|
213
|
+
* required `undefined` branches invoke `fallback`, defaults are
|
|
214
|
+
* written as `default`, and `"+": "delete"` omits `additionalProperties`)
|
|
215
|
+
* - `"in"`: the accepted JSON input (drops `undefined` union branches,
|
|
216
|
+
* converts morphs as their input, keeps defaults, allows keys
|
|
217
|
+
* `"+": "delete"` removes)
|
|
218
|
+
* - `"out"`: the serialized output (converts morphs as their output,
|
|
219
|
+
* applies defaults, writes `additionalProperties: false` for
|
|
220
|
+
* `"+": "delete"`, and drops `undefined` from object property/index
|
|
221
|
+
* values and `required`)
|
|
222
|
+
*/
|
|
223
|
+
io?: "in" | "out";
|
|
224
|
+
fallback?: FallbackOption;
|
|
225
|
+
}
|
|
226
|
+
interface Context extends Required<Omit<Options, "discriminator" | "io">>, Pick<Options, "discriminator" | "io"> {
|
|
227
|
+
fallback: HandlerByCode;
|
|
228
|
+
}
|
|
229
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { type Key } from "../../util/index.js";
|
|
2
|
+
import type { BaseNode, RootApply } from "../node.ts";
|
|
3
|
+
import type { BaseRoot } from "../roots/root.ts";
|
|
4
|
+
import type { ArkErrors } from "./issues.ts";
|
|
5
|
+
import type { RootApplyRuntime } from "./rootApply.ts";
|
|
6
|
+
export interface InPlaceTransforms {
|
|
7
|
+
checksUncompiled(root: BaseRoot): boolean;
|
|
8
|
+
checkedUncompiled(root: BaseRoot, apply: RootApply): RootApply | undefined;
|
|
9
|
+
readonly checking: ReadonlySet<BaseNode> | undefined;
|
|
10
|
+
applied(root: BaseRoot): BaseRoot;
|
|
11
|
+
runtimeOf(root: BaseRoot, runtime: RootApplyRuntime): RootApplyRuntime;
|
|
12
|
+
}
|
|
13
|
+
export declare class TransformErrors {
|
|
14
|
+
entries: TransformErrors.Entry[];
|
|
15
|
+
constructor(result: ArkErrors, data: unknown);
|
|
16
|
+
addTo(gathered: TransformErrors | undefined, key?: PropertyKey): TransformErrors;
|
|
17
|
+
}
|
|
18
|
+
export declare namespace TransformErrors {
|
|
19
|
+
interface Entry {
|
|
20
|
+
reversedPath: PropertyKey[];
|
|
21
|
+
result: ArkErrors;
|
|
22
|
+
data: unknown;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
export declare const holdsOnlyIndices: (data: unknown[]) => boolean;
|
|
26
|
+
export declare const copyOf: (data: object) => object;
|
|
27
|
+
export declare const setOwnValue: (out: object, k: PropertyKey, value: unknown) => void;
|
|
28
|
+
export declare const keepOwn: (out: object, data: object, k: Key) => void;
|
|
29
|
+
/**
|
|
30
|
+
* what deleting undeclared keys makes of data other than a plain object, a copy
|
|
31
|
+
* keeping its prototype: what its values transformed to, flat as
|
|
32
|
+
* [key, value, output], then without the keys it doesn't declare
|
|
33
|
+
*/
|
|
34
|
+
export declare const copyDeclared: (data: object, declared: readonly Key[], changes?: readonly unknown[]) => object;
|
|
35
|
+
export declare const mergeTransformed: (input: unknown, l: unknown, r: unknown) => unknown;
|