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,416 @@
|
|
|
1
|
+
import type { JsonSchema } from "../_internal/schema/index.js";
|
|
2
|
+
import type { anyOrNever, array, Digit, domainOf, ErrorMessage } from "../_internal/util/index.js";
|
|
3
|
+
import type { Anchor, AnnotationKeyword, IdentifiedSchema, isUnion, replaceAll, resolveRef, rootOf, TypedSchema, UnresolvedRef } from "./infer.ts";
|
|
4
|
+
export type validateJsonSchema<schema, root = schema> = null extends undefined ? ErrorMessage<"'strict' or 'strictNullChecks' must be set to true in your tsconfig's 'compilerOptions'"> : [schema] extends [anyOrNever] ? schema : [schema] extends [StaticallyValidDocument] ? KeywordCompletions : JsonSchema extends schema ? schema | KeywordCompletions : [schema] extends [boolean] ? schema : {
|
|
5
|
+
root: root;
|
|
6
|
+
schema: schema;
|
|
7
|
+
} extends {
|
|
8
|
+
root: schema;
|
|
9
|
+
schema: root;
|
|
10
|
+
} ? validateDocument<schema> : validateSchema<schema, root, "branch">;
|
|
11
|
+
/** each member is checked on its own, so a valid member can't accept an invalid one */
|
|
12
|
+
export type validateDocument<schema> = (schema extends unknown ? [
|
|
13
|
+
schema
|
|
14
|
+
] extends [checkDocument<schema>] ? never : schema : never) extends never ? Extract<schema, boolean> | KeywordCompletions : isUnion<schema> extends false ? validateMember<schema, schema, "document"> : invalidDocumentMemberOf<schema> extends infer invalid ? [
|
|
15
|
+
invalid
|
|
16
|
+
] extends [never] ? Extract<schema, boolean> | KeywordCompletions : validateDocumentMember<invalid> : never;
|
|
17
|
+
export type validateDocumentMember<schema> = schema extends unknown ? validateMember<schema, schema, "document"> : never;
|
|
18
|
+
export type invalidDocumentMemberOf<schema> = schema extends unknown ? [
|
|
19
|
+
schema
|
|
20
|
+
] extends [checkDocument<schema>] ? never : [schema] extends [validateMember<schema, schema, "document">] ? never : schema : never;
|
|
21
|
+
/** where a subschema appears, which determines whether its `required` keys
|
|
22
|
+
* are checked: only on a path from the document root along which no other
|
|
23
|
+
* schema could apply to the same instance */
|
|
24
|
+
export type SchemaPosition = "document" | "branch" | "subschema";
|
|
25
|
+
export type validateSchema<schema, root, position extends SchemaPosition> = [
|
|
26
|
+
schema
|
|
27
|
+
] extends [StaticallyValidSchemaObject] ? KeywordCompletions : [schema] extends [boolean] ? schema : JsonSchema extends schema ? schema : [schema] extends [checkSchema<schema, root>] ? Extract<schema, boolean> | KeywordCompletions : validateSubschema<schema, root, position>;
|
|
28
|
+
/** a member of a union that passes on its own expects only what it is, since
|
|
29
|
+
* the completions of its subschemas could accept an invalid sibling */
|
|
30
|
+
export type validateSubschema<schema, root, position extends SchemaPosition> = schema extends StaticallyValidSchema ? StaticallyValidSchema : [schema] extends [checkSchema<schema, root>] ? schema & closedKeywordsOf<schema> : validateMember<schema, root, position>;
|
|
31
|
+
/** keywords a schema doesn't have, so a sibling with more keywords isn't
|
|
32
|
+
* accepted as a subtype of it */
|
|
33
|
+
export type closedKeywordsOf<schema> = {
|
|
34
|
+
[k in Exclude<KeywordName, keyof schema>]?: never;
|
|
35
|
+
};
|
|
36
|
+
export type validateMember<schema, root, position extends SchemaPosition> = schema extends boolean ? schema : schema extends array ? ErrorMessage<writeInvalidSchemaMessage<"array">> : schema extends IdentifiedSchema ? validateKeywords<schema, position extends "document" ? schema : rootOf<schema, root>, position> : schema extends object ? validateKeywords<schema, root, position> : ErrorMessage<writeInvalidSchemaMessage<domainOf<schema>>>;
|
|
37
|
+
export type validateKeywords<schema, root, position extends SchemaPosition> = {
|
|
38
|
+
[k in keyof schema | KeywordName]?: k extends keyof schema ? k extends ValidatedKeyword ? (k extends "type" ? validateTypeKeyword<schema[k]> : k extends "required" ? position extends "branch" ? completeRequired<schema[k], schema> : schema extends SelfContainedSchema ? validateRequired<schema[k], propertyKeyOf<schema["properties"]>> : completeRequired<schema[k], schema> : k extends "properties" ? validateSchemaRecord<schema[k], root, propertyPositionOf<schema, position>> : k extends "additionalProperties" ? validateSchema<schema[k], root, propertyPositionOf<schema, position>> : k extends "items" ? validateItems<schema[k], root, itemPositionOf<schema, position>> : k extends "prefixItems" ? validateSchemaList<schema[k], root, itemPositionOf<schema, position>> : k extends SchemaKeyword | BranchKeyword ? validateSchema<schema[k], root, "branch"> : k extends CompositionKeyword ? validateSchemaList<schema[k], root, "branch"> : k extends "$ref" ? validateRef<schema[k], root> : k extends CountKeyword ? validateCount<schema[k], k> : k extends "multipleOf" ? validateMultipleOf<schema[k]> : k extends "nullable" ? validateNullable<schema[k], schema["type" & keyof schema]> : k extends keyof KeywordValueTypes ? KeywordValueTypes[k] : k extends SchemaRecordKeyword ? validateSchemaRecord<schema[k], root, "branch"> : k extends "dependencies" ? validateDependencies<schema[k], root> : k extends "dependentRequired" ? validateDependentRequired<schema[k]> : k extends "additionalItems" ? validateSchema<schema[k], root, "branch"> : k extends UnsupportedKeyword ? undefined extends schema[k] ? schema[k] : ErrorMessage<writeUnsupportedKeywordMessage<k>> : k extends ExclusiveBoundKeyword ? schema[k] extends boolean ? ErrorMessage<writeUnsupportedKeywordMessage<`boolean ${k}`>> : schema[k] extends number | boolean | undefined ? schema[k] : number : k extends "propertyNames" ? validatePropertyNames<schema[k], root> : schema[k]) | (undefined extends schema[k] ? undefined : never) : k extends "components" ? position extends "document" ? validateComponents<schema[k], root> : schema[k] : schema[k] : never;
|
|
39
|
+
};
|
|
40
|
+
export type validateSchemaRecord<schemas, root, position extends SchemaPosition> = schemas extends array ? {
|
|
41
|
+
readonly [k: string]: boolean | object;
|
|
42
|
+
} : schemas extends StaticallyValidSchemaRecord ? {
|
|
43
|
+
[k in keyof schemas]: StaticallyValidSchemaCompletions;
|
|
44
|
+
} : schemas extends object ? {
|
|
45
|
+
[k in keyof schemas]: validateSchema<schemas[k], root, position>;
|
|
46
|
+
} : {
|
|
47
|
+
readonly [k: string]: boolean | object;
|
|
48
|
+
};
|
|
49
|
+
/** schema lists (allOf, anyOf, oneOf, prefixItems and draft-07 items) must be non-empty */
|
|
50
|
+
export type validateSchemaList<schemas, root, position extends SchemaPosition> = schemas extends readonly [] ? readonly [boolean | object, ...(boolean | object)[]] : schemas extends array<StaticallyValidSchema> ? {
|
|
51
|
+
[i in keyof schemas]: StaticallyValidSchemaCompletions;
|
|
52
|
+
} : schemas extends array ? {
|
|
53
|
+
[i in keyof schemas]: validateSchema<schemas[i], root, position>;
|
|
54
|
+
} : readonly (boolean | object)[];
|
|
55
|
+
/** unlike prefixItems, a draft-07 items array is never on a checked path */
|
|
56
|
+
export type validateItems<items, root, position extends SchemaPosition> = JsonSchema extends items ? items : [items] extends [array] ? validateSchemaList<items, root, "branch"> : [items] extends [Exclude<items, array>] ? validateSchema<items, root, position> : validateSchemaList<Extract<items, array>, root, "branch"> | validateSubschema<Exclude<items, array>, root, position>;
|
|
57
|
+
export type validateDependencies<dependencies, root> = dependencies extends array ? {
|
|
58
|
+
readonly [k: string]: boolean | object | readonly string[];
|
|
59
|
+
} : dependencies extends StaticDependencies ? DependencyCompletions : dependencies extends object ? {
|
|
60
|
+
[k in keyof dependencies]: validateDependency<dependencies[k], root>;
|
|
61
|
+
} : {
|
|
62
|
+
readonly [k: string]: boolean | object | readonly string[];
|
|
63
|
+
};
|
|
64
|
+
export type validateDependency<dependency, root> = [
|
|
65
|
+
dependency
|
|
66
|
+
] extends [array] ? validateRequired<dependency, string> : [dependency] extends [Exclude<dependency, array>] ? validateSchema<dependency, root, "branch"> : validateRequired<Extract<dependency, array>, string> | validateSubschema<Exclude<dependency, array>, root, "branch">;
|
|
67
|
+
export type validateDependentRequired<dependencies> = dependencies extends array ? {
|
|
68
|
+
readonly [k: string]: readonly string[];
|
|
69
|
+
} : dependencies extends object ? {
|
|
70
|
+
[k in keyof dependencies]: validateRequired<dependencies[k], string>;
|
|
71
|
+
} : {
|
|
72
|
+
readonly [k: string]: readonly string[];
|
|
73
|
+
};
|
|
74
|
+
export type validateComponents<components, root> = components extends {
|
|
75
|
+
schemas: unknown;
|
|
76
|
+
} ? {
|
|
77
|
+
[k in keyof components]: k extends "schemas" ? validateSchemaRecord<components[k], root, "branch"> : components[k];
|
|
78
|
+
} : components;
|
|
79
|
+
/** a union of every type name (like JSONSchema6TypeName, which adds "any")
|
|
80
|
+
* is widened */
|
|
81
|
+
export type validateTypeKeyword<name> = JsonSchema.TypeName extends Extract<name, string> ? name : name extends readonly [] ? readonly [JsonSchema.TypeName, ...JsonSchema.TypeName[]] : name extends array ? {
|
|
82
|
+
[i in keyof name]: validateEntry<name[i], JsonSchema.TypeName>;
|
|
83
|
+
} : validateEntry<name, JsonSchema.TypeName>;
|
|
84
|
+
export type validateRequired<keys, key> = keys extends array<string> ? {
|
|
85
|
+
[i in keyof keys]: validateEntry<keys[i], key>;
|
|
86
|
+
} : readonly string[];
|
|
87
|
+
/** required keys another schema could declare: any string is valid, and the
|
|
88
|
+
* schema's own properties are offered */
|
|
89
|
+
export type completeRequired<keys, schema> = keys extends array<string> ? {
|
|
90
|
+
[i in keyof keys]: propertyKeyOf<schema["properties" & keyof schema]> | (string & {});
|
|
91
|
+
} : readonly string[];
|
|
92
|
+
export type validateEntry<value, entry> = value extends entry ? value : value extends string ? string extends value ? value : entry : entry;
|
|
93
|
+
export type validateCount<n, keyword extends string> = n extends number ? checkCount<n> extends never ? ErrorMessage<writeInvalidCountMessage<keyword, n>> : n : number;
|
|
94
|
+
export type validateMultipleOf<n> = n extends number ? checkMultipleOf<n> extends never ? ErrorMessage<writeInvalidMultipleOfMessage<n>> : n : number;
|
|
95
|
+
export type validateNullable<nullable, type> = [
|
|
96
|
+
nullable
|
|
97
|
+
] extends [anyOrNever] ? nullable : [nullable] extends [false] ? includesNullType<type> extends true ? ErrorMessage<NonNullableNullMessage> : false : boolean;
|
|
98
|
+
export type validateRef<ref, root> = ref extends LocalRef ? resolveRef<ref, root> extends UnresolvedRef ? {} extends Record<ref, 0> ? ref : root extends UnresolvedRef ? ref : ref extends PercentEncodedRef ? ref : "#" | definitionRefOf<root> : ref : ref extends "" ? ref | "#" | definitionRefOf<root> : ref extends string ? ref : string;
|
|
99
|
+
/** a percent-encoded ref, which isn't decoded and is accepted like a widened
|
|
100
|
+
* ref */
|
|
101
|
+
export type PercentEncodedRef = `${string}%${string}`;
|
|
102
|
+
/** a conditional, so a message prints the refs rather than this alias */
|
|
103
|
+
export type definitionRefOf<root> = root extends object ? (root extends {
|
|
104
|
+
$defs?: infer definitions;
|
|
105
|
+
} ? containerRefOf<definitions, "$defs"> : never) | (root extends {
|
|
106
|
+
definitions?: infer definitions;
|
|
107
|
+
} ? containerRefOf<definitions, "definitions"> : never) | (root extends {
|
|
108
|
+
components: {
|
|
109
|
+
schemas?: infer definitions;
|
|
110
|
+
};
|
|
111
|
+
} ? containerRefOf<definitions, "components/schemas"> : never) : never;
|
|
112
|
+
export type containerRefOf<definitions, path extends string> = definitions extends array ? never : definitions extends object ? `#/${path}/${escapePointerSegment<`${keyof definitions & (string | number)}`>}` : never;
|
|
113
|
+
/** escape a JSON pointer segment (RFC 6901), then the `%` of the URI fragment
|
|
114
|
+
* it is written in, which is percent-decoded before the pointer is split */
|
|
115
|
+
export type escapePointerSegment<segment extends string> = replaceAll<replaceAll<replaceAll<segment, "~", "~0">, "/", "~1">, "%", "%25">;
|
|
116
|
+
export type validatePropertyNames<schema, root> = [
|
|
117
|
+
nonStringNamesOf<schema>
|
|
118
|
+
] extends [never] ? validateSchema<schema, root, "branch"> : nonStringNamesOf<schema> extends infer invalid ? {
|
|
119
|
+
[k in keyof invalid]: k extends "type" ? invalid[k] extends array ? readonly ["string", ...JsonSchema.TypeName[]] : "string" : invalid[k];
|
|
120
|
+
} : never;
|
|
121
|
+
/** propertyNames schemas whose type admits no strings */
|
|
122
|
+
export type nonStringNamesOf<schema> = schema extends TypedSchema ? "string" extends typeNameOf<schema["type"]> ? never : schema : never;
|
|
123
|
+
export type typeNameOf<type> = type extends array ? type[number] : type;
|
|
124
|
+
/** the position of a `properties` or `additionalProperties` subschema, which
|
|
125
|
+
* no other subschema of an isolated schema applies to */
|
|
126
|
+
export type propertyPositionOf<schema, position extends SchemaPosition> = position extends "branch" ? "branch" : schema extends IsolatedSchema ? "subschema" : "branch";
|
|
127
|
+
/** the position of an `items` or `prefixItems` subschema, which `contains`
|
|
128
|
+
* may also apply to */
|
|
129
|
+
export type itemPositionOf<schema, position extends SchemaPosition> = "contains" extends keyof schema ? "branch" : propertyPositionOf<schema, position>;
|
|
130
|
+
export type propertyKeyOf<properties> = properties extends array ? string : properties extends object ? (keyof properties & string) | `${keyof properties & number}` : string;
|
|
131
|
+
/** a schema whose own `properties` are the only keys it can declare */
|
|
132
|
+
export interface SelfContainedSchema extends IsolatedSchema {
|
|
133
|
+
properties: unknown;
|
|
134
|
+
additionalProperties?: false;
|
|
135
|
+
}
|
|
136
|
+
/** a schema with no keyword that applies another subschema to the instance
|
|
137
|
+
* or to one of its properties. It extends KeywordObject so any schema shares
|
|
138
|
+
* a property with it, which TS requires of a type whose keys are optional. */
|
|
139
|
+
export interface IsolatedSchema extends KeywordObject {
|
|
140
|
+
patternProperties?: never;
|
|
141
|
+
unevaluatedProperties?: never;
|
|
142
|
+
allOf?: never;
|
|
143
|
+
anyOf?: never;
|
|
144
|
+
oneOf?: never;
|
|
145
|
+
if?: never;
|
|
146
|
+
then?: never;
|
|
147
|
+
else?: never;
|
|
148
|
+
dependentSchemas?: never;
|
|
149
|
+
dependencies?: never;
|
|
150
|
+
$ref?: never;
|
|
151
|
+
$dynamicRef?: never;
|
|
152
|
+
$recursiveRef?: never;
|
|
153
|
+
}
|
|
154
|
+
export type SchemaKeyword = "additionalProperties" | "contains" | "contentSchema";
|
|
155
|
+
/** keywords fromJsonSchema throws on, since it can't read them exactly */
|
|
156
|
+
export type UnsupportedKeyword = "$dynamicRef" | "$recursiveRef" | "unevaluatedItems" | "unevaluatedProperties";
|
|
157
|
+
/** a draft-04 boolean exclusive bound is unsupported */
|
|
158
|
+
export type ExclusiveBoundKeyword = "exclusiveMinimum" | "exclusiveMaximum";
|
|
159
|
+
export type BranchKeyword = "not" | "if" | "then" | "else";
|
|
160
|
+
export type CompositionKeyword = "allOf" | "anyOf" | "oneOf";
|
|
161
|
+
export type PropertiesKeyword = "properties" | "patternProperties";
|
|
162
|
+
export type SchemaRecordKeyword = PropertiesKeyword | "$defs" | "definitions" | "dependentSchemas";
|
|
163
|
+
export type CountKeyword = "minLength" | "maxLength" | "minItems" | "maxItems" | "minProperties" | "maxProperties" | "minContains" | "maxContains";
|
|
164
|
+
export type KeywordValueTypes = {
|
|
165
|
+
minimum: number;
|
|
166
|
+
maximum: number;
|
|
167
|
+
enum: readonly unknown[];
|
|
168
|
+
pattern: string | RegExp;
|
|
169
|
+
format: string;
|
|
170
|
+
uniqueItems: boolean;
|
|
171
|
+
};
|
|
172
|
+
export type ValidatedKeyword = SchemaKeyword | BranchKeyword | CompositionKeyword | SchemaRecordKeyword | CountKeyword | keyof KeywordValueTypes | "type" | "required" | "items" | "prefixItems" | "$ref" | "multipleOf" | "nullable" | "dependencies" | "dependentRequired" | "additionalItems" | UnsupportedKeyword | ExclusiveBoundKeyword | "propertyNames";
|
|
173
|
+
export type KeywordName = ValidatedKeyword | AnnotationKeyword | "const" | "$schema" | "$id" | "$anchor" | "$dynamicAnchor" | "$vocabulary" | "contentEncoding" | "contentMediaType";
|
|
174
|
+
/** schemas whose validity can be checked without generic instantiations */
|
|
175
|
+
export type StaticallyValidSchema = boolean | StaticallyValidSchemaObject;
|
|
176
|
+
export interface StaticallyValidSchemaObject extends ContextFreeKeywords {
|
|
177
|
+
nullable?: true;
|
|
178
|
+
required?: never;
|
|
179
|
+
$ref?: never;
|
|
180
|
+
multipleOf?: never;
|
|
181
|
+
minLength?: never;
|
|
182
|
+
maxLength?: never;
|
|
183
|
+
minItems?: never;
|
|
184
|
+
maxItems?: never;
|
|
185
|
+
minProperties?: never;
|
|
186
|
+
maxProperties?: never;
|
|
187
|
+
minContains?: never;
|
|
188
|
+
maxContains?: never;
|
|
189
|
+
additionalItems?: never;
|
|
190
|
+
propertyNames?: never;
|
|
191
|
+
properties?: StaticallyValidObjectRecord;
|
|
192
|
+
patternProperties?: StaticallyValidObjectRecord;
|
|
193
|
+
$defs?: StaticallyValidObjectRecord;
|
|
194
|
+
definitions?: StaticallyValidObjectRecord;
|
|
195
|
+
dependentSchemas?: StaticallyValidObjectRecord;
|
|
196
|
+
dependencies?: StaticDependencies;
|
|
197
|
+
items?: StaticallyValidSchema | StaticallyValidObjectList;
|
|
198
|
+
prefixItems?: StaticallyValidObjectList;
|
|
199
|
+
allOf?: StaticallyValidObjectList;
|
|
200
|
+
anyOf?: StaticallyValidObjectList;
|
|
201
|
+
oneOf?: StaticallyValidObjectList;
|
|
202
|
+
not?: StaticallyValidSchema;
|
|
203
|
+
if?: StaticallyValidSchema;
|
|
204
|
+
then?: StaticallyValidSchema;
|
|
205
|
+
else?: StaticallyValidSchema;
|
|
206
|
+
contains?: StaticallyValidSchema;
|
|
207
|
+
additionalProperties?: StaticallyValidSchema;
|
|
208
|
+
contentSchema?: StaticallyValidSchema;
|
|
209
|
+
unevaluatedProperties?: never;
|
|
210
|
+
unevaluatedItems?: never;
|
|
211
|
+
$dynamicRef?: never;
|
|
212
|
+
$recursiveRef?: never;
|
|
213
|
+
}
|
|
214
|
+
/** keywords whose values are valid whatever else the schema contains */
|
|
215
|
+
export interface ContextFreeKeywords {
|
|
216
|
+
type?: JsonSchema.TypeName | readonly [JsonSchema.TypeName, ...JsonSchema.TypeName[]];
|
|
217
|
+
dependentRequired?: DependentRequired;
|
|
218
|
+
minimum?: number;
|
|
219
|
+
maximum?: number;
|
|
220
|
+
exclusiveMinimum?: number;
|
|
221
|
+
exclusiveMaximum?: number;
|
|
222
|
+
enum?: readonly unknown[];
|
|
223
|
+
pattern?: string | RegExp;
|
|
224
|
+
format?: string;
|
|
225
|
+
uniqueItems?: boolean;
|
|
226
|
+
const?: unknown;
|
|
227
|
+
title?: unknown;
|
|
228
|
+
description?: unknown;
|
|
229
|
+
default?: unknown;
|
|
230
|
+
examples?: unknown;
|
|
231
|
+
deprecated?: unknown;
|
|
232
|
+
readOnly?: unknown;
|
|
233
|
+
writeOnly?: unknown;
|
|
234
|
+
$comment?: unknown;
|
|
235
|
+
$schema?: unknown;
|
|
236
|
+
$id?: unknown;
|
|
237
|
+
$anchor?: unknown;
|
|
238
|
+
$dynamicAnchor?: unknown;
|
|
239
|
+
$vocabulary?: unknown;
|
|
240
|
+
contentEncoding?: unknown;
|
|
241
|
+
contentMediaType?: unknown;
|
|
242
|
+
}
|
|
243
|
+
/** an OpenAPI document's `components.schemas` is a record of schemas */
|
|
244
|
+
export interface StaticallyValidDocument extends StaticallyValidSchemaObject {
|
|
245
|
+
components?: {
|
|
246
|
+
schemas?: StaticallyValidObjectRecord;
|
|
247
|
+
};
|
|
248
|
+
}
|
|
249
|
+
/** object schemas only, since relating each element to a union with
|
|
250
|
+
* `boolean` costs a level of relation depth (TS2321 past about 33 levels of
|
|
251
|
+
* nesting). A boolean element falls back to ValidSchemaObject. */
|
|
252
|
+
export type StaticallyValidObjectList = readonly [
|
|
253
|
+
StaticallyValidSchemaObject,
|
|
254
|
+
...StaticallyValidSchemaObject[]
|
|
255
|
+
];
|
|
256
|
+
export interface StaticallyValidObjectRecord {
|
|
257
|
+
readonly [k: string]: StaticallyValidSchemaObject;
|
|
258
|
+
}
|
|
259
|
+
export type StaticallyValidSchemaList = readonly [
|
|
260
|
+
StaticallyValidSchema,
|
|
261
|
+
...StaticallyValidSchema[]
|
|
262
|
+
];
|
|
263
|
+
export interface StaticallyValidSchemaRecord {
|
|
264
|
+
readonly [k: string]: StaticallyValidSchema;
|
|
265
|
+
}
|
|
266
|
+
export interface StaticDependencies {
|
|
267
|
+
readonly [k: string]: StaticallyValidSchema | readonly string[];
|
|
268
|
+
}
|
|
269
|
+
export interface DependentRequired {
|
|
270
|
+
readonly [k: string]: readonly string[];
|
|
271
|
+
}
|
|
272
|
+
/** a schema object whose keywords are checked in a single pass, falling back
|
|
273
|
+
* to validateKeywords for errors if any check fails */
|
|
274
|
+
export interface ValidSchemaObject<schema extends KeywordObject, root> extends ContextFreeKeywords {
|
|
275
|
+
nullable?: checkNullable<schema["nullable"], schema["type"]>;
|
|
276
|
+
required?: array<keyof schema["properties"] & string>;
|
|
277
|
+
$ref?: checkRef<schema["$ref"], root>;
|
|
278
|
+
multipleOf?: checkMultipleOf<schema["multipleOf"]>;
|
|
279
|
+
minLength?: checkCount<schema["minLength"]>;
|
|
280
|
+
maxLength?: checkCount<schema["maxLength"]>;
|
|
281
|
+
minItems?: checkCount<schema["minItems"]>;
|
|
282
|
+
maxItems?: checkCount<schema["maxItems"]>;
|
|
283
|
+
minProperties?: checkCount<schema["minProperties"]>;
|
|
284
|
+
maxProperties?: checkCount<schema["maxProperties"]>;
|
|
285
|
+
minContains?: checkCount<schema["minContains"]>;
|
|
286
|
+
maxContains?: checkCount<schema["maxContains"]>;
|
|
287
|
+
properties?: checkRecord<schema["properties"], root>;
|
|
288
|
+
patternProperties?: checkRecord<schema["patternProperties"], root>;
|
|
289
|
+
$defs?: checkRecord<schema["$defs"], root>;
|
|
290
|
+
definitions?: checkRecord<schema["definitions"], root>;
|
|
291
|
+
dependentSchemas?: checkRecord<schema["dependentSchemas"], root>;
|
|
292
|
+
dependencies?: checkDependencies<schema["dependencies"], root>;
|
|
293
|
+
items?: checkItems<schema["items"], root>;
|
|
294
|
+
prefixItems?: checkList<schema["prefixItems"], root>;
|
|
295
|
+
allOf?: checkList<schema["allOf"], root>;
|
|
296
|
+
anyOf?: checkList<schema["anyOf"], root>;
|
|
297
|
+
oneOf?: checkList<schema["oneOf"], root>;
|
|
298
|
+
not?: checkSchema<schema["not"], root>;
|
|
299
|
+
if?: checkSchema<schema["if"], root>;
|
|
300
|
+
then?: checkSchema<schema["then"], root>;
|
|
301
|
+
else?: checkSchema<schema["else"], root>;
|
|
302
|
+
contains?: checkSchema<schema["contains"], root>;
|
|
303
|
+
additionalProperties?: checkSchema<schema["additionalProperties"], root>;
|
|
304
|
+
unevaluatedProperties?: never;
|
|
305
|
+
unevaluatedItems?: never;
|
|
306
|
+
$dynamicRef?: never;
|
|
307
|
+
$recursiveRef?: never;
|
|
308
|
+
contentSchema?: checkSchema<schema["contentSchema"], root>;
|
|
309
|
+
additionalItems?: checkSchema<schema["additionalItems"], root>;
|
|
310
|
+
propertyNames?: checkPropertyNames<schema["propertyNames"], root>;
|
|
311
|
+
components?: checkComponents<schema["components" & keyof schema], root>;
|
|
312
|
+
}
|
|
313
|
+
export type checkDocument<schema> = schema extends KeywordObject ? ValidSchemaObject<schema, schema> : checkSchema<schema, schema>;
|
|
314
|
+
/** `unknown` is also the value of a keyword the schema doesn't have, which
|
|
315
|
+
* accepts nothing, so one union member's check can't accept another's */
|
|
316
|
+
export type checkSchema<schema, root> = JsonSchema extends schema ? unknown extends schema ? never : unknown : schema extends StaticallyValidSchema ? StaticallyValidSchema : schema extends ResourcelessKeywordObject ? ValidSchemaObject<schema, root> : schema extends KeywordObject ? ValidSchemaObject<schema, schema extends IdentifiedSchema ? rootOf<schema, root> : root> : never;
|
|
317
|
+
/** checks that return the value they were given, so a union member can't be
|
|
318
|
+
* mistaken for a valid sibling */
|
|
319
|
+
export type checkRecord<schemas, root> = schemas extends StaticallyValidSchemaRecord ? StaticallyValidSchemaRecord : schemas extends array ? never : schemas extends object ? {
|
|
320
|
+
[k in keyof schemas]: checkSchema<schemas[k], root>;
|
|
321
|
+
} : never;
|
|
322
|
+
export type checkList<schemas, root> = schemas extends StaticallyValidSchemaList ? StaticallyValidSchemaList : schemas extends readonly [] ? never : schemas extends array ? {
|
|
323
|
+
[i in keyof schemas]: checkSchema<schemas[i], root>;
|
|
324
|
+
} : never;
|
|
325
|
+
export type checkItems<items, root> = JsonSchema extends items ? unknown extends items ? never : unknown : items extends array ? checkList<items, root> : checkSchema<items, root>;
|
|
326
|
+
export type checkDependencies<dependencies, root> = dependencies extends StaticDependencies ? StaticDependencies : dependencies extends array ? never : dependencies extends object ? {
|
|
327
|
+
[k in keyof dependencies]: checkDependency<dependencies[k], root>;
|
|
328
|
+
} : never;
|
|
329
|
+
export type checkDependency<dependency, root> = dependency extends array<string> ? readonly string[] : checkSchema<dependency, root>;
|
|
330
|
+
export type checkComponents<components, root> = components extends {
|
|
331
|
+
schemas: unknown;
|
|
332
|
+
} ? {
|
|
333
|
+
schemas?: checkRecord<components["schemas"], root>;
|
|
334
|
+
} : components;
|
|
335
|
+
export type checkPropertyNames<schema, root> = [
|
|
336
|
+
nonStringNamesOf<schema>
|
|
337
|
+
] extends [never] ? checkSchema<schema, root> : never;
|
|
338
|
+
export type checkCount<n> = n extends number ? `${n}` extends NonCountString ? `${n}` extends LargeIntegerString ? n : never : n : n extends undefined ? n : never;
|
|
339
|
+
/** a number that may not be a non-negative integer when printed this way */
|
|
340
|
+
export type NonCountString = `-${string}` | `${string}${"." | "e"}${string}` | "Infinity";
|
|
341
|
+
/** positive numbers of at least 1e21 print in exponent form and are integers */
|
|
342
|
+
export type LargeIntegerString = `${Digit}${string}e+${string}`;
|
|
343
|
+
export type checkMultipleOf<n> = n extends number ? `${n}` extends NonPositiveString ? never : n : n extends undefined ? n : never;
|
|
344
|
+
export type checkNullable<nullable, type> = [
|
|
345
|
+
nullable
|
|
346
|
+
] extends [anyOrNever] ? nullable : [nullable] extends [false] ? includesNullType<type> extends true ? never : false : nullable extends boolean | undefined ? nullable : never;
|
|
347
|
+
export type includesNullType<type> = [
|
|
348
|
+
type
|
|
349
|
+
] extends [anyOrNever] ? false : JsonSchema.TypeName extends Extract<type, string> ? false : type extends array ? number extends type["length"] ? false : true extends ({
|
|
350
|
+
[i in keyof type]: [type[i]] extends [anyOrNever] ? false : [type[i]] extends ["null"] ? true : false;
|
|
351
|
+
}[number]) ? true : false : [type] extends ["null"] ? true : false;
|
|
352
|
+
export type NonPositiveString = `-${string}` | "0";
|
|
353
|
+
export type checkRef<ref, root> = ref extends LocalRef ? resolveRef<ref, root> extends UnresolvedRef ? {} extends Record<ref, 0> ? string : root extends UnresolvedRef ? string : ref extends PercentEncodedRef ? string : never : string : ref extends "" ? never : ref extends string | undefined ? ref : never;
|
|
354
|
+
export type LocalRef = "#" | `#/${string}`;
|
|
355
|
+
/** keyword names offered as completions for a valid schema, which any
|
|
356
|
+
* schema type (including an interface) is assignable to */
|
|
357
|
+
export interface KeywordCompletions extends SubschemaCompletions {
|
|
358
|
+
[k: string]: any;
|
|
359
|
+
}
|
|
360
|
+
/** completions without an index signature, which would make the elements
|
|
361
|
+
* of an array literal `any` in a slot that also accepts a list */
|
|
362
|
+
export interface SubschemaCompletions extends KeywordObject {
|
|
363
|
+
properties?: SchemaRecordCompletions;
|
|
364
|
+
patternProperties?: SchemaRecordCompletions;
|
|
365
|
+
$defs?: SchemaRecordCompletions;
|
|
366
|
+
definitions?: SchemaRecordCompletions;
|
|
367
|
+
dependentSchemas?: SchemaRecordCompletions;
|
|
368
|
+
dependencies?: DependencyCompletions;
|
|
369
|
+
items?: SchemaCompletions | readonly SchemaCompletions[];
|
|
370
|
+
prefixItems?: readonly SchemaCompletions[];
|
|
371
|
+
allOf?: readonly SchemaCompletions[];
|
|
372
|
+
anyOf?: readonly SchemaCompletions[];
|
|
373
|
+
oneOf?: readonly SchemaCompletions[];
|
|
374
|
+
not?: SchemaCompletions;
|
|
375
|
+
if?: SchemaCompletions;
|
|
376
|
+
then?: SchemaCompletions;
|
|
377
|
+
else?: SchemaCompletions;
|
|
378
|
+
contains?: SchemaCompletions;
|
|
379
|
+
additionalProperties?: SchemaCompletions;
|
|
380
|
+
additionalItems?: SchemaCompletions;
|
|
381
|
+
propertyNames?: SchemaCompletions;
|
|
382
|
+
contentSchema?: SchemaCompletions;
|
|
383
|
+
/** without `schemas`, an unknown keyword */
|
|
384
|
+
components?: {} | null | undefined | {
|
|
385
|
+
schemas?: SchemaRecordCompletions;
|
|
386
|
+
};
|
|
387
|
+
}
|
|
388
|
+
/** a statically valid schema, whose unknown keywords aren't excess properties */
|
|
389
|
+
export type StaticallyValidSchemaCompletions = boolean | StaticallyValidSchemaObjectCompletions;
|
|
390
|
+
export interface StaticallyValidSchemaObjectCompletions extends StaticallyValidSchemaObject {
|
|
391
|
+
[k: string]: any;
|
|
392
|
+
}
|
|
393
|
+
/** `{}` relates a subschema without comparing it to the deeply nested
|
|
394
|
+
* completions (it has already been validated), and with `null | undefined`
|
|
395
|
+
* admits a widened `unknown` subschema */
|
|
396
|
+
export type SchemaCompletions = {} | null | undefined | SubschemaCompletions;
|
|
397
|
+
/** `object` admits interfaces, which have no implicit index signature */
|
|
398
|
+
export type SchemaRecordCompletions = object | {
|
|
399
|
+
readonly [k: string]: SchemaCompletions;
|
|
400
|
+
};
|
|
401
|
+
export type DependencyCompletions = object | {
|
|
402
|
+
readonly [k: string]: SchemaCompletions | readonly string[];
|
|
403
|
+
};
|
|
404
|
+
export type KeywordObject = {
|
|
405
|
+
[k in KeywordName]?: unknown;
|
|
406
|
+
};
|
|
407
|
+
/** a schema object whose local refs resolve against the enclosing resource */
|
|
408
|
+
export interface ResourcelessKeywordObject extends KeywordObject {
|
|
409
|
+
$id?: Anchor;
|
|
410
|
+
id?: Anchor;
|
|
411
|
+
}
|
|
412
|
+
export type writeInvalidSchemaMessage<actual extends string> = `JSON Schema must be an object or a boolean (was ${actual})`;
|
|
413
|
+
export type writeInvalidCountMessage<keyword extends string, value extends number> = `${keyword} must be a non-negative integer (was ${value})`;
|
|
414
|
+
export type writeInvalidMultipleOfMessage<value extends number> = `multipleOf must be a positive number (was ${value})`;
|
|
415
|
+
export type writeUnsupportedKeywordMessage<keyword extends string> = `${keyword} isn't supported by fromJsonSchema`;
|
|
416
|
+
export type NonNullableNullMessage = "nullable can't be false beside a type that includes null";
|
package/out/keywords/Array.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { Hkt, liftArray, type Digit } from "
|
|
1
|
+
import { Hkt, liftArray, type Digit } from "../_internal/util/index.js";
|
|
2
2
|
import type { To } from "../attributes.ts";
|
|
3
3
|
import type { Module, Submodule } from "../module.ts";
|
|
4
4
|
declare class liftFromHkt extends Hkt<[element: unknown]> {
|
|
5
5
|
body: liftArray<this[0]> extends infer lifted ? (In: this[0] | lifted) => To<lifted> : never;
|
|
6
6
|
}
|
|
7
|
-
declare const liftFrom: () => import("
|
|
7
|
+
declare const liftFrom: () => import("../_internal/schema/index.js").GenericRoot<readonly [["element", unknown]], liftFromHkt>;
|
|
8
8
|
export declare const arkArray: arkArray.module;
|
|
9
9
|
export declare namespace arkArray {
|
|
10
10
|
type module = Module<submodule>;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { type BaseRoot, type GenericRoot } from "
|
|
2
|
-
import type * as util from "
|
|
3
|
-
import { Hkt, type Key, type Thunk } from "
|
|
1
|
+
import { type BaseRoot, type GenericRoot } from "../_internal/schema/index.js";
|
|
2
|
+
import type * as util from "../_internal/util/index.js";
|
|
3
|
+
import { Hkt, type Key, type Thunk } from "../_internal/util/index.js";
|
|
4
4
|
import type { Module, Submodule } from "../module.ts";
|
|
5
5
|
declare class MergeHkt extends Hkt<[base: object, props: object]> {
|
|
6
6
|
body: util.merge<this[0], this[1]>;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type EcmascriptObjects, type PlatformObjects } from "
|
|
1
|
+
import { type EcmascriptObjects, type PlatformObjects } from "../_internal/util/index.js";
|
|
2
2
|
import type { Module, Submodule } from "../module.ts";
|
|
3
3
|
import { arkArray } from "./Array.ts";
|
|
4
4
|
import { arkFormData } from "./FormData.ts";
|