typebox 1.0.42 → 1.0.44
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/build/schema/build.d.mts +6 -6
- package/build/schema/build.mjs +6 -4
- package/build/schema/check.d.mts +3 -3
- package/build/schema/check.mjs +4 -2
- package/build/schema/engine/_context.d.mts +6 -16
- package/build/schema/engine/_context.mjs +11 -34
- package/build/schema/engine/_externals.d.mts +1 -1
- package/build/schema/engine/_externals.mjs +2 -2
- package/build/schema/engine/_functions.d.mts +3 -2
- package/build/schema/engine/_functions.mjs +6 -5
- package/build/schema/engine/_guard.d.mts +5 -4
- package/build/schema/engine/_guard.mjs +5 -5
- package/build/schema/engine/_reducer.d.mts +2 -1
- package/build/schema/engine/_reducer.mjs +3 -3
- package/build/schema/engine/_refine.d.mts +4 -3
- package/build/schema/engine/_refine.mjs +4 -4
- package/build/schema/engine/_stack.d.mts +18 -0
- package/build/schema/engine/_stack.mjs +73 -0
- package/build/schema/engine/_unique.d.mts +2 -0
- package/build/schema/engine/_unique.mjs +5 -0
- package/build/schema/engine/additionalItems.d.mts +5 -4
- package/build/schema/engine/additionalItems.mjs +15 -13
- package/build/schema/engine/additionalProperties.d.mts +5 -4
- package/build/schema/engine/additionalProperties.mjs +19 -16
- package/build/schema/engine/allOf.d.mts +5 -4
- package/build/schema/engine/allOf.mjs +15 -15
- package/build/schema/engine/anyOf.d.mts +5 -4
- package/build/schema/engine/anyOf.mjs +15 -15
- package/build/schema/engine/boolean.d.mts +4 -3
- package/build/schema/engine/boolean.mjs +4 -4
- package/build/schema/engine/const.d.mts +5 -4
- package/build/schema/engine/const.mjs +6 -6
- package/build/schema/engine/contains.d.mts +5 -4
- package/build/schema/engine/contains.mjs +10 -8
- package/build/schema/engine/dependencies.d.mts +5 -4
- package/build/schema/engine/dependencies.mjs +6 -6
- package/build/schema/engine/dependentRequired.d.mts +5 -4
- package/build/schema/engine/dependentRequired.mjs +3 -3
- package/build/schema/engine/dependentSchemas.d.mts +5 -4
- package/build/schema/engine/dependentSchemas.mjs +6 -6
- package/build/schema/engine/enum.d.mts +5 -4
- package/build/schema/engine/enum.mjs +6 -6
- package/build/schema/engine/exclusiveMaximum.d.mts +5 -4
- package/build/schema/engine/exclusiveMaximum.mjs +4 -4
- package/build/schema/engine/exclusiveMinimum.d.mts +5 -4
- package/build/schema/engine/exclusiveMinimum.mjs +4 -4
- package/build/schema/engine/format.d.mts +5 -4
- package/build/schema/engine/format.mjs +5 -5
- package/build/schema/engine/if.d.mts +5 -4
- package/build/schema/engine/if.mjs +19 -19
- package/build/schema/engine/index.d.mts +12 -11
- package/build/schema/engine/index.mjs +13 -12
- package/build/schema/engine/items.d.mts +5 -4
- package/build/schema/engine/items.mjs +22 -22
- package/build/schema/engine/maxContains.d.mts +5 -4
- package/build/schema/engine/maxContains.mjs +11 -9
- package/build/schema/engine/maxItems.d.mts +5 -4
- package/build/schema/engine/maxItems.mjs +4 -4
- package/build/schema/engine/maxLength.d.mts +5 -4
- package/build/schema/engine/maxLength.mjs +4 -4
- package/build/schema/engine/maxProperties.d.mts +5 -4
- package/build/schema/engine/maxProperties.mjs +4 -4
- package/build/schema/engine/maximum.d.mts +5 -4
- package/build/schema/engine/maximum.mjs +4 -4
- package/build/schema/engine/minContains.d.mts +5 -4
- package/build/schema/engine/minContains.mjs +10 -8
- package/build/schema/engine/minItems.d.mts +5 -4
- package/build/schema/engine/minItems.mjs +4 -4
- package/build/schema/engine/minLength.d.mts +5 -4
- package/build/schema/engine/minLength.mjs +4 -4
- package/build/schema/engine/minProperties.d.mts +5 -4
- package/build/schema/engine/minProperties.mjs +4 -4
- package/build/schema/engine/minimum.d.mts +5 -4
- package/build/schema/engine/minimum.mjs +4 -4
- package/build/schema/engine/multipleOf.d.mts +5 -4
- package/build/schema/engine/multipleOf.mjs +4 -4
- package/build/schema/engine/not.d.mts +5 -4
- package/build/schema/engine/not.mjs +14 -13
- package/build/schema/engine/oneOf.d.mts +5 -4
- package/build/schema/engine/oneOf.mjs +14 -14
- package/build/schema/engine/pattern.d.mts +5 -4
- package/build/schema/engine/pattern.mjs +6 -6
- package/build/schema/engine/patternProperties.d.mts +5 -4
- package/build/schema/engine/patternProperties.mjs +14 -12
- package/build/schema/engine/prefixItems.d.mts +5 -4
- package/build/schema/engine/prefixItems.mjs +6 -6
- package/build/schema/engine/properties.d.mts +5 -4
- package/build/schema/engine/properties.mjs +10 -10
- package/build/schema/engine/propertyNames.d.mts +5 -4
- package/build/schema/engine/propertyNames.mjs +11 -9
- package/build/schema/engine/recursiveRef.d.mts +5 -4
- package/build/schema/engine/recursiveRef.mjs +11 -22
- package/build/schema/engine/ref.d.mts +5 -4
- package/build/schema/engine/ref.mjs +44 -29
- package/build/schema/engine/required.d.mts +5 -4
- package/build/schema/engine/required.mjs +3 -3
- package/build/schema/engine/schema.d.mts +5 -4
- package/build/schema/engine/schema.mjs +216 -207
- package/build/schema/engine/type.d.mts +5 -4
- package/build/schema/engine/type.mjs +12 -12
- package/build/schema/engine/unevaluatedItems.d.mts +5 -4
- package/build/schema/engine/unevaluatedItems.mjs +15 -13
- package/build/schema/engine/unevaluatedProperties.d.mts +5 -4
- package/build/schema/engine/unevaluatedProperties.mjs +15 -13
- package/build/schema/engine/uniqueItems.d.mts +5 -4
- package/build/schema/engine/uniqueItems.mjs +3 -3
- package/build/schema/errors.d.mts +3 -3
- package/build/schema/errors.mjs +4 -4
- package/build/schema/pointer/pointer.mjs +10 -2
- package/build/schema/resolve/index.d.mts +1 -0
- package/build/schema/resolve/index.mjs +1 -0
- package/build/schema/resolve/ref.d.mts +2 -0
- package/build/schema/{resolver → resolve}/ref.mjs +43 -45
- package/build/schema/resolve/resolve.d.mts +1 -0
- package/build/schema/resolve/resolve.mjs +1 -0
- package/build/schema/schema.d.mts +1 -1
- package/build/schema/schema.mjs +1 -1
- package/build/schema/types/recursiveAnchor.d.mts +4 -0
- package/build/schema/types/recursiveAnchor.mjs +7 -0
- package/build/type/types/static.d.mts +4 -4
- package/package.json +1 -1
- package/build/schema/resolver/index.d.mts +0 -1
- package/build/schema/resolver/index.mjs +0 -1
- package/build/schema/resolver/recursiveRef.d.mts +0 -2
- package/build/schema/resolver/recursiveRef.mjs +0 -47
- package/build/schema/resolver/ref.d.mts +0 -1
- package/build/schema/resolver/resolver.d.mts +0 -2
- package/build/schema/resolver/resolver.mjs +0 -2
|
@@ -1,16 +1,18 @@
|
|
|
1
1
|
// deno-fmt-ignore-file
|
|
2
|
-
import {
|
|
2
|
+
import { Unique } from './_unique.mjs';
|
|
3
3
|
import { AccumulatedErrorContext } from './_context.mjs';
|
|
4
|
+
import { Guard as G, EmitGuard as E } from '../../guard/index.mjs';
|
|
4
5
|
import { BuildSchema, CheckSchema, ErrorSchema } from './schema.mjs';
|
|
5
6
|
// ------------------------------------------------------------------
|
|
6
7
|
// Build
|
|
7
8
|
// ------------------------------------------------------------------
|
|
8
|
-
export function BuildUnevaluatedItems(context, schema, value) {
|
|
9
|
+
export function BuildUnevaluatedItems(stack, context, schema, value) {
|
|
10
|
+
const [index, item] = [Unique(), Unique()];
|
|
9
11
|
const indices = E.Call(E.Member('context', 'GetIndices'), []);
|
|
10
|
-
const hasIndex = E.Call(E.Member('indices', 'has'), [
|
|
11
|
-
const isSchema = BuildSchema(context, schema.unevaluatedItems,
|
|
12
|
-
const addIndex = E.Call(E.Member('context', 'AddIndex'), [
|
|
13
|
-
const isEvery = E.Every(value, E.Constant(0), [
|
|
12
|
+
const hasIndex = E.Call(E.Member('indices', 'has'), [index]);
|
|
13
|
+
const isSchema = BuildSchema(stack, context, schema.unevaluatedItems, item);
|
|
14
|
+
const addIndex = E.Call(E.Member('context', 'AddIndex'), [index]);
|
|
15
|
+
const isEvery = E.Every(value, E.Constant(0), [item, index], E.And(E.Or(hasIndex, isSchema), addIndex));
|
|
14
16
|
return E.Call(E.ArrowFunction(['context'], E.Statements([
|
|
15
17
|
E.ConstDeclaration('indices', indices),
|
|
16
18
|
E.Return(isEvery)
|
|
@@ -19,22 +21,22 @@ export function BuildUnevaluatedItems(context, schema, value) {
|
|
|
19
21
|
// ------------------------------------------------------------------
|
|
20
22
|
// Check
|
|
21
23
|
// ------------------------------------------------------------------
|
|
22
|
-
export function CheckUnevaluatedItems(context, schema, value) {
|
|
24
|
+
export function CheckUnevaluatedItems(stack, context, schema, value) {
|
|
23
25
|
const indices = context.GetIndices();
|
|
24
|
-
return G.Every(value, 0, (
|
|
25
|
-
return (indices.has(index) || CheckSchema(context, schema.unevaluatedItems,
|
|
26
|
+
return G.Every(value, 0, (item, index) => {
|
|
27
|
+
return (indices.has(index) || CheckSchema(stack, context, schema.unevaluatedItems, item))
|
|
26
28
|
&& context.AddIndex(index);
|
|
27
29
|
});
|
|
28
30
|
}
|
|
29
31
|
// ------------------------------------------------------------------
|
|
30
32
|
// Error
|
|
31
33
|
// ------------------------------------------------------------------
|
|
32
|
-
export function ErrorUnevaluatedItems(context, schemaPath, instancePath, schema, value) {
|
|
34
|
+
export function ErrorUnevaluatedItems(stack, context, schemaPath, instancePath, schema, value) {
|
|
33
35
|
const indices = context.GetIndices();
|
|
34
36
|
const unevaluatedItems = [];
|
|
35
|
-
const isUnevaluatedItems = G.EveryAll(value, 0, (
|
|
36
|
-
const nextContext = new AccumulatedErrorContext(
|
|
37
|
-
const isEvaluatedItem = (indices.has(index) || ErrorSchema(nextContext, schemaPath, instancePath, schema.unevaluatedItems,
|
|
37
|
+
const isUnevaluatedItems = G.EveryAll(value, 0, (item, index) => {
|
|
38
|
+
const nextContext = new AccumulatedErrorContext();
|
|
39
|
+
const isEvaluatedItem = (indices.has(index) || ErrorSchema(stack, nextContext, schemaPath, instancePath, schema.unevaluatedItems, item))
|
|
38
40
|
&& context.AddIndex(index);
|
|
39
41
|
if (!isEvaluatedItem)
|
|
40
42
|
unevaluatedItems.push(index);
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import * as
|
|
1
|
+
import * as Schema from '../types/index.mjs';
|
|
2
|
+
import { Stack } from './_stack.mjs';
|
|
2
3
|
import { BuildContext, CheckContext, ErrorContext } from './_context.mjs';
|
|
3
|
-
export declare function BuildUnevaluatedProperties(context: BuildContext, schema:
|
|
4
|
-
export declare function CheckUnevaluatedProperties(context: CheckContext, schema:
|
|
5
|
-
export declare function ErrorUnevaluatedProperties(context: ErrorContext, schemaPath: string, instancePath: string, schema:
|
|
4
|
+
export declare function BuildUnevaluatedProperties(stack: Stack, context: BuildContext, schema: Schema.XUnevaluatedProperties, value: string): string;
|
|
5
|
+
export declare function CheckUnevaluatedProperties(stack: Stack, context: CheckContext, schema: Schema.XUnevaluatedProperties, value: Record<PropertyKey, unknown>): boolean;
|
|
6
|
+
export declare function ErrorUnevaluatedProperties(stack: Stack, context: ErrorContext, schemaPath: string, instancePath: string, schema: Schema.XUnevaluatedProperties, value: Record<PropertyKey, unknown>): boolean;
|
|
@@ -1,16 +1,18 @@
|
|
|
1
1
|
// deno-fmt-ignore-file
|
|
2
|
-
import {
|
|
2
|
+
import { Unique } from './_unique.mjs';
|
|
3
3
|
import { AccumulatedErrorContext } from './_context.mjs';
|
|
4
|
+
import { Guard as G, EmitGuard as E } from '../../guard/index.mjs';
|
|
4
5
|
import { BuildSchema, CheckSchema, ErrorSchema } from './schema.mjs';
|
|
5
6
|
// ------------------------------------------------------------------
|
|
6
7
|
// Build
|
|
7
8
|
// ------------------------------------------------------------------
|
|
8
|
-
export function BuildUnevaluatedProperties(context, schema, value) {
|
|
9
|
+
export function BuildUnevaluatedProperties(stack, context, schema, value) {
|
|
10
|
+
const [key, prop] = [Unique(), Unique()];
|
|
9
11
|
const keys = E.Call(E.Member('context', 'GetKeys'), []);
|
|
10
|
-
const hasKey = E.Call(E.Member('keys', 'has'), [
|
|
11
|
-
const addKey = E.Call(E.Member('context', 'AddKey'), [
|
|
12
|
-
const isSchema = BuildSchema(context, schema.unevaluatedProperties,
|
|
13
|
-
const isEvery = E.Every(E.Entries(value), E.Constant(0), [
|
|
12
|
+
const hasKey = E.Call(E.Member('keys', 'has'), [key]);
|
|
13
|
+
const addKey = E.Call(E.Member('context', 'AddKey'), [key]);
|
|
14
|
+
const isSchema = BuildSchema(stack, context, schema.unevaluatedProperties, prop);
|
|
15
|
+
const isEvery = E.Every(E.Entries(value), E.Constant(0), [`[${key}, ${prop}]`, '_'], E.Or(hasKey, E.And(isSchema, addKey)));
|
|
14
16
|
return E.Call(E.ArrowFunction(['context'], E.Statements([
|
|
15
17
|
E.ConstDeclaration('keys', keys),
|
|
16
18
|
E.Return(isEvery)
|
|
@@ -19,23 +21,23 @@ export function BuildUnevaluatedProperties(context, schema, value) {
|
|
|
19
21
|
// ------------------------------------------------------------------
|
|
20
22
|
// Check
|
|
21
23
|
// ------------------------------------------------------------------
|
|
22
|
-
export function CheckUnevaluatedProperties(context, schema, value) {
|
|
24
|
+
export function CheckUnevaluatedProperties(stack, context, schema, value) {
|
|
23
25
|
const keys = context.GetKeys();
|
|
24
|
-
return G.Every(G.Entries(value), 0, ([key,
|
|
26
|
+
return G.Every(G.Entries(value), 0, ([key, prop]) => {
|
|
25
27
|
return keys.has(key)
|
|
26
|
-
|| (CheckSchema(context, schema.unevaluatedProperties,
|
|
28
|
+
|| (CheckSchema(stack, context, schema.unevaluatedProperties, prop) && context.AddKey(key));
|
|
27
29
|
});
|
|
28
30
|
}
|
|
29
31
|
// ------------------------------------------------------------------
|
|
30
32
|
// Error
|
|
31
33
|
// ------------------------------------------------------------------
|
|
32
|
-
export function ErrorUnevaluatedProperties(context, schemaPath, instancePath, schema, value) {
|
|
34
|
+
export function ErrorUnevaluatedProperties(stack, context, schemaPath, instancePath, schema, value) {
|
|
33
35
|
const keys = context.GetKeys();
|
|
34
36
|
const unevaluatedProperties = [];
|
|
35
|
-
const isUnevaluatedProperties = G.EveryAll(G.Entries(value), 0, ([key,
|
|
36
|
-
const nextContext = new AccumulatedErrorContext(
|
|
37
|
+
const isUnevaluatedProperties = G.EveryAll(G.Entries(value), 0, ([key, prop]) => {
|
|
38
|
+
const nextContext = new AccumulatedErrorContext();
|
|
37
39
|
const isEvaluatedProperty = keys.has(key)
|
|
38
|
-
|| (ErrorSchema(nextContext, schemaPath, instancePath, schema.unevaluatedProperties,
|
|
40
|
+
|| (ErrorSchema(stack, nextContext, schemaPath, instancePath, schema.unevaluatedProperties, prop) && context.AddKey(key));
|
|
39
41
|
if (!isEvaluatedProperty)
|
|
40
42
|
unevaluatedProperties.push(key);
|
|
41
43
|
return isEvaluatedProperty;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import * as
|
|
1
|
+
import * as Schema from '../types/index.mjs';
|
|
2
|
+
import { Stack } from './_stack.mjs';
|
|
2
3
|
import { BuildContext, CheckContext, ErrorContext } from './_context.mjs';
|
|
3
|
-
export declare function BuildUniqueItems(context: BuildContext, schema:
|
|
4
|
-
export declare function CheckUniqueItems(context: CheckContext, schema:
|
|
5
|
-
export declare function ErrorUniqueItems(context: ErrorContext, schemaPath: string, instancePath: string, schema:
|
|
4
|
+
export declare function BuildUniqueItems(stack: Stack, context: BuildContext, schema: Schema.XUniqueItems, value: string): string;
|
|
5
|
+
export declare function CheckUniqueItems(stack: Stack, context: CheckContext, schema: Schema.XUniqueItems, value: unknown[]): boolean;
|
|
6
|
+
export declare function ErrorUniqueItems(stack: Stack, context: ErrorContext, schemaPath: string, instancePath: string, schema: Schema.XUniqueItems, value: unknown[]): boolean;
|
|
@@ -10,7 +10,7 @@ function IsValid(schema) {
|
|
|
10
10
|
// ------------------------------------------------------------------
|
|
11
11
|
// Build
|
|
12
12
|
// ------------------------------------------------------------------
|
|
13
|
-
export function BuildUniqueItems(context, schema, value) {
|
|
13
|
+
export function BuildUniqueItems(stack, context, schema, value) {
|
|
14
14
|
if (!IsValid(schema))
|
|
15
15
|
return E.Constant(true);
|
|
16
16
|
const set = E.Member(E.New('Set', [E.Call(E.Member(value, 'map'), [E.Member('Hashing', 'Hash')])]), 'size');
|
|
@@ -20,7 +20,7 @@ export function BuildUniqueItems(context, schema, value) {
|
|
|
20
20
|
// ------------------------------------------------------------------
|
|
21
21
|
// Check
|
|
22
22
|
// ------------------------------------------------------------------
|
|
23
|
-
export function CheckUniqueItems(context, schema, value) {
|
|
23
|
+
export function CheckUniqueItems(stack, context, schema, value) {
|
|
24
24
|
if (!IsValid(schema))
|
|
25
25
|
return true;
|
|
26
26
|
const set = new Set(value.map(Hashing.Hash)).size;
|
|
@@ -30,7 +30,7 @@ export function CheckUniqueItems(context, schema, value) {
|
|
|
30
30
|
// ------------------------------------------------------------------
|
|
31
31
|
// Error
|
|
32
32
|
// ------------------------------------------------------------------
|
|
33
|
-
export function ErrorUniqueItems(context, schemaPath, instancePath, schema, value) {
|
|
33
|
+
export function ErrorUniqueItems(stack, context, schemaPath, instancePath, schema, value) {
|
|
34
34
|
if (!IsValid(schema))
|
|
35
35
|
return true;
|
|
36
36
|
const set = new Set();
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { type TLocalizedValidationError } from '../error/index.mjs';
|
|
2
|
-
import
|
|
2
|
+
import * as Schema from './types/index.mjs';
|
|
3
3
|
/** Checks a value and returns validation errors */
|
|
4
|
-
export declare function Errors(schema: XSchema, value: unknown): [boolean, TLocalizedValidationError[]];
|
|
4
|
+
export declare function Errors(schema: Schema.XSchema, value: unknown): [boolean, TLocalizedValidationError[]];
|
|
5
5
|
/** Checks a value and returns validation errors */
|
|
6
|
-
export declare function Errors(context: Record<PropertyKey, XSchema>, schema: XSchema, value: unknown): [boolean, TLocalizedValidationError[]];
|
|
6
|
+
export declare function Errors(context: Record<PropertyKey, Schema.XSchema>, schema: Schema.XSchema, value: unknown): [boolean, TLocalizedValidationError[]];
|
package/build/schema/errors.mjs
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
// deno-fmt-ignore-file
|
|
2
|
-
// deno-lint-ignore-file
|
|
3
2
|
import { Arguments } from '../system/arguments/index.mjs';
|
|
4
3
|
import { Settings } from '../system/settings/index.mjs';
|
|
5
4
|
import { Get as LocaleGet } from '../system/locale/_config.mjs';
|
|
6
5
|
import { Guard } from '../guard/index.mjs';
|
|
7
|
-
import
|
|
6
|
+
import * as Engine from './engine/index.mjs';
|
|
8
7
|
/** Checks a value and returns validation errors */
|
|
9
8
|
export function Errors(...args) {
|
|
10
9
|
const [context, schema, value] = Arguments.Match(args, {
|
|
@@ -14,11 +13,12 @@ export function Errors(...args) {
|
|
|
14
13
|
const settings = Settings.Get();
|
|
15
14
|
const locale = LocaleGet();
|
|
16
15
|
const errors = [];
|
|
17
|
-
const
|
|
16
|
+
const stack = new Engine.Stack(context, schema);
|
|
17
|
+
const errorContext = new Engine.ErrorContext(error => {
|
|
18
18
|
if (Guard.IsGreaterEqualThan(errors.length, settings.maxErrors))
|
|
19
19
|
return;
|
|
20
20
|
return errors.push({ ...error, message: locale(error) });
|
|
21
21
|
});
|
|
22
|
-
const result = ErrorSchema(errorContext, '#', '', schema, value);
|
|
22
|
+
const result = Engine.ErrorSchema(stack, errorContext, '#', '', schema, value);
|
|
23
23
|
return [result, errors];
|
|
24
24
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// deno-fmt-ignore-file
|
|
2
2
|
import { Guard } from '../../guard/index.mjs';
|
|
3
3
|
// ------------------------------------------------------------------
|
|
4
|
-
//
|
|
4
|
+
// Asserts
|
|
5
5
|
// ------------------------------------------------------------------
|
|
6
6
|
function AssertNotRoot(indices) {
|
|
7
7
|
if (indices.length === 0)
|
|
@@ -14,6 +14,9 @@ function AssertCanSet(value) {
|
|
|
14
14
|
// ------------------------------------------------------------------
|
|
15
15
|
// Indices
|
|
16
16
|
// ------------------------------------------------------------------
|
|
17
|
+
function IsNumericIndex(index) {
|
|
18
|
+
return /^(0|[1-9]\d*)$/.test(index);
|
|
19
|
+
}
|
|
17
20
|
function TakeIndexRight(indices) {
|
|
18
21
|
return [
|
|
19
22
|
indices.slice(0, indices.length - 1),
|
|
@@ -83,6 +86,11 @@ export function Delete(value, pointer) {
|
|
|
83
86
|
const [head, index] = TakeIndexRight(indices);
|
|
84
87
|
const parent = GetIndices(head, value);
|
|
85
88
|
AssertCanSet(parent);
|
|
86
|
-
|
|
89
|
+
if (Guard.IsArray(parent) && IsNumericIndex(index)) {
|
|
90
|
+
parent.splice(+index, 1);
|
|
91
|
+
}
|
|
92
|
+
else {
|
|
93
|
+
delete parent[index];
|
|
94
|
+
}
|
|
87
95
|
return value;
|
|
88
96
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * as Resolve from './resolve.mjs';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * as Resolve from './resolve.mjs';
|
|
@@ -1,98 +1,96 @@
|
|
|
1
1
|
// deno-fmt-ignore-file
|
|
2
2
|
import { Guard } from '../../guard/index.mjs';
|
|
3
3
|
import { Pointer } from '../pointer/index.mjs';
|
|
4
|
-
import * as
|
|
4
|
+
import * as Schema from '../types/index.mjs';
|
|
5
5
|
// ------------------------------------------------------------------
|
|
6
|
-
//
|
|
6
|
+
// Match: Id
|
|
7
7
|
// ------------------------------------------------------------------
|
|
8
|
-
function MatchId(
|
|
9
|
-
if (
|
|
10
|
-
return
|
|
11
|
-
const absoluteId = new URL(
|
|
8
|
+
function MatchId(schema, base, ref) {
|
|
9
|
+
if (schema.$id === ref.hash)
|
|
10
|
+
return schema;
|
|
11
|
+
const absoluteId = new URL(schema.$id, base.href);
|
|
12
12
|
const absoluteRef = new URL(ref.href, base.href);
|
|
13
13
|
if (Guard.IsEqual(absoluteId.pathname, absoluteRef.pathname)) {
|
|
14
|
-
return ref.hash.startsWith('#') ? MatchHash(
|
|
14
|
+
return ref.hash.startsWith('#') ? MatchHash(schema, base, ref) : schema;
|
|
15
15
|
}
|
|
16
16
|
return undefined;
|
|
17
17
|
}
|
|
18
18
|
// ------------------------------------------------------------------
|
|
19
|
-
//
|
|
19
|
+
// Match: Anchor
|
|
20
20
|
// ------------------------------------------------------------------
|
|
21
|
-
function MatchAnchor(
|
|
22
|
-
const absoluteAnchor = new URL(`#${
|
|
21
|
+
function MatchAnchor(schema, base, ref) {
|
|
22
|
+
const absoluteAnchor = new URL(`#${schema.$anchor}`, base.href);
|
|
23
23
|
const absoluteRef = new URL(ref.href, base.href);
|
|
24
24
|
if (Guard.IsEqual(absoluteAnchor.href, absoluteRef.href))
|
|
25
|
-
return
|
|
25
|
+
return schema;
|
|
26
26
|
return undefined;
|
|
27
27
|
}
|
|
28
28
|
// ------------------------------------------------------------------
|
|
29
|
-
//
|
|
29
|
+
// Match: Hash
|
|
30
30
|
// ------------------------------------------------------------------
|
|
31
|
-
function MatchHash(
|
|
31
|
+
function MatchHash(schema, base, ref) {
|
|
32
32
|
if (ref.href.endsWith('#'))
|
|
33
|
-
return
|
|
33
|
+
return schema;
|
|
34
34
|
return ref.hash.startsWith('#')
|
|
35
|
-
? Pointer.Get(
|
|
35
|
+
? Pointer.Get(schema, decodeURIComponent(ref.hash.slice(1)))
|
|
36
36
|
: undefined;
|
|
37
37
|
}
|
|
38
38
|
// ------------------------------------------------------------------
|
|
39
39
|
// Match
|
|
40
40
|
// ------------------------------------------------------------------
|
|
41
|
-
function Match(
|
|
42
|
-
if (
|
|
43
|
-
const result = MatchId(
|
|
41
|
+
function Match(schema, base, ref) {
|
|
42
|
+
if (Schema.IsId(schema)) {
|
|
43
|
+
const result = MatchId(schema, base, ref);
|
|
44
44
|
if (!Guard.IsUndefined(result))
|
|
45
45
|
return result;
|
|
46
46
|
}
|
|
47
|
-
if (
|
|
48
|
-
const result = MatchAnchor(
|
|
47
|
+
if (Schema.IsAnchor(schema)) {
|
|
48
|
+
const result = MatchAnchor(schema, base, ref);
|
|
49
49
|
if (!Guard.IsUndefined(result))
|
|
50
50
|
return result;
|
|
51
51
|
}
|
|
52
|
-
return MatchHash(
|
|
52
|
+
return MatchHash(schema, base, ref);
|
|
53
53
|
}
|
|
54
54
|
// ------------------------------------------------------------------
|
|
55
55
|
// FromArray
|
|
56
56
|
// ------------------------------------------------------------------
|
|
57
|
-
function FromArray(
|
|
58
|
-
|
|
59
|
-
const
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
}
|
|
63
|
-
return undefined;
|
|
57
|
+
function FromArray(schema, base, ref) {
|
|
58
|
+
return schema.reduce((result, item) => {
|
|
59
|
+
const match = FromValue(item, base, ref);
|
|
60
|
+
return !Guard.IsUndefined(match) ? match : result;
|
|
61
|
+
}, undefined);
|
|
64
62
|
}
|
|
65
63
|
// ------------------------------------------------------------------
|
|
66
64
|
// FromObject
|
|
67
65
|
// ------------------------------------------------------------------
|
|
68
|
-
function FromObject(
|
|
69
|
-
|
|
70
|
-
const
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
}
|
|
74
|
-
return undefined;
|
|
66
|
+
function FromObject(schema, base, ref) {
|
|
67
|
+
return Guard.Keys(schema).reduce((result, key) => {
|
|
68
|
+
const match = FromValue(schema[key], base, ref);
|
|
69
|
+
return !Guard.IsUndefined(match) ? match : result;
|
|
70
|
+
}, undefined);
|
|
75
71
|
}
|
|
76
72
|
// ------------------------------------------------------------------
|
|
77
73
|
// FromValue
|
|
78
74
|
// ------------------------------------------------------------------
|
|
79
|
-
function FromValue(
|
|
80
|
-
|
|
81
|
-
if (
|
|
82
|
-
const result = Match(
|
|
75
|
+
function FromValue(schema, base, ref) {
|
|
76
|
+
base = Schema.IsSchemaObject(schema) && Schema.IsId(schema) ? new URL(schema.$id, base.href) : base;
|
|
77
|
+
if (Schema.IsSchemaObject(schema)) {
|
|
78
|
+
const result = Match(schema, base, ref);
|
|
83
79
|
if (!Guard.IsUndefined(result))
|
|
84
80
|
return result;
|
|
85
81
|
}
|
|
86
|
-
if (Guard.IsArray(
|
|
87
|
-
return FromArray(
|
|
88
|
-
if (Guard.IsObject(
|
|
89
|
-
return FromObject(
|
|
82
|
+
if (Guard.IsArray(schema))
|
|
83
|
+
return FromArray(schema, base, ref);
|
|
84
|
+
if (Guard.IsObject(schema))
|
|
85
|
+
return FromObject(schema, base, ref);
|
|
90
86
|
return undefined;
|
|
91
87
|
}
|
|
92
88
|
// ------------------------------------------------------------------
|
|
93
89
|
// Ref
|
|
94
90
|
// ------------------------------------------------------------------
|
|
95
91
|
export function Ref(schema, ref) {
|
|
96
|
-
const
|
|
97
|
-
|
|
92
|
+
const defaultBase = new URL('memory://root');
|
|
93
|
+
const initialBase = Schema.IsId(schema) ? new URL(schema.$id, defaultBase.href) : defaultBase;
|
|
94
|
+
const initialRef = new URL(ref, initialBase.href);
|
|
95
|
+
return FromValue(schema, initialBase, initialRef);
|
|
98
96
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './ref.mjs';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './ref.mjs';
|
package/build/schema/schema.mjs
CHANGED
|
@@ -6,3 +6,7 @@ export interface XRecursiveAnchor<Anchor extends string = string> {
|
|
|
6
6
|
* Returns true if the schema contains a valid $recursiveAnchor property
|
|
7
7
|
*/
|
|
8
8
|
export declare function IsRecursiveAnchor(schema: XSchemaObject): schema is XRecursiveAnchor;
|
|
9
|
+
/**
|
|
10
|
+
* Returns true if the schema contains a valid $recursiveAnchor property that is true
|
|
11
|
+
*/
|
|
12
|
+
export declare function IsRecursiveAnchorTrue(schema: XSchemaObject): schema is XRecursiveAnchor;
|
|
@@ -10,3 +10,10 @@ export function IsRecursiveAnchor(schema) {
|
|
|
10
10
|
return Guard.HasPropertyKey(schema, '$recursiveAnchor')
|
|
11
11
|
&& Guard.IsBoolean(schema.$recursiveAnchor);
|
|
12
12
|
}
|
|
13
|
+
/**
|
|
14
|
+
* Returns true if the schema contains a valid $recursiveAnchor property that is true
|
|
15
|
+
*/
|
|
16
|
+
export function IsRecursiveAnchorTrue(schema) {
|
|
17
|
+
return IsRecursiveAnchor(schema)
|
|
18
|
+
&& Guard.IsEqual(schema.$recursiveAnchor, true);
|
|
19
|
+
}
|
|
@@ -39,10 +39,10 @@ export type StaticEvaluate<T> = {
|
|
|
39
39
|
export type StaticDirection = 'Encode' | 'Decode';
|
|
40
40
|
export type StaticType<Stack extends string[], Direction extends StaticDirection, Context extends TProperties, This extends TProperties, Type extends TSchema> = (Type extends TCodec<infer Type extends TSchema, infer Decoded extends unknown> ? StaticCodec<Stack, Direction, Context, This, Type, Decoded> : Type extends TAny ? StaticAny : Type extends TArray<infer Items extends TSchema> ? StaticArray<Stack, Direction, Context, This, Type, Items> : Type extends TAsyncIterator<infer Type extends TSchema> ? StaticAsyncIterator<Stack, Direction, Context, This, Type> : Type extends Base<infer Value extends unknown> ? StaticBase<Value> : Type extends TBigInt ? StaticBigInt : Type extends TBoolean ? StaticBoolean : Type extends TConstructor<infer Parameters extends TSchema[], infer ReturnType extends TSchema> ? StaticConstructor<Stack, Direction, Context, This, Parameters, ReturnType> : Type extends TEnum<infer Values extends TEnumValue[]> ? StaticEnum<Values> : Type extends TFunction<infer Parameters extends TSchema[], infer ReturnType extends TSchema> ? StaticFunction<Stack, Direction, Context, This, Parameters, ReturnType> : Type extends TInteger ? StaticInteger : Type extends TIntersect<infer Types extends TSchema[]> ? StaticIntersect<Stack, Direction, Context, This, Types> : Type extends TIterator<infer Types extends TSchema> ? StaticIterator<Stack, Direction, Context, This, Types> : Type extends TLiteral<infer Value extends TLiteralValue> ? StaticLiteral<Value> : Type extends TNever ? StaticNever : Type extends TNull ? StaticNull : Type extends TNumber ? StaticNumber : Type extends TObject<infer Properties extends TProperties> ? StaticObject<Stack, Direction, Context, This, Properties> : Type extends TPromise<infer Type extends TSchema> ? StaticPromise<Stack, Direction, Context, This, Type> : Type extends TRecord<infer Key extends string, infer Value extends TSchema> ? StaticRecord<Stack, Direction, Context, This, Key, Value> : Type extends TCyclic<infer Defs extends TProperties, infer Ref extends string> ? StaticCyclic<Stack, Direction, Context, This, Defs, Ref> : Type extends TRef<infer Ref extends string> ? StaticRef<Stack, Direction, Context, This, Ref> : Type extends TString ? StaticString : Type extends TSymbol ? StaticSymbol : Type extends TTemplateLiteral<infer Pattern extends string> ? StaticTemplateLiteral<Pattern> : Type extends TThis ? StaticThis<Stack, Direction, Context, This> : Type extends TTuple<infer Items extends TSchema[]> ? StaticTuple<Stack, Direction, Context, This, Type, Items> : Type extends TUndefined ? StaticUndefined : Type extends TUnion<infer Types extends TSchema[]> ? StaticUnion<Stack, Direction, Context, This, Types> : Type extends TUnknown ? StaticUnknown : Type extends TUnsafe<infer Type extends unknown> ? StaticUnsafe<Type> : Type extends TVoid ? StaticVoid : XStatic<Type>);
|
|
41
41
|
/** Infers a static type from a TypeBox type using Parse logic. */
|
|
42
|
-
export type StaticParse<Type extends TSchema, Context extends TProperties = {}
|
|
42
|
+
export type StaticParse<Type extends TSchema, Context extends TProperties = {}, Result extends unknown = StaticType<[], 'Decode', Context, {}, Type>> = Result;
|
|
43
43
|
/** Infers a static type from a TypeBox type using Decode logic. */
|
|
44
|
-
export type StaticDecode<Type extends TSchema, Context extends TProperties = {}
|
|
44
|
+
export type StaticDecode<Type extends TSchema, Context extends TProperties = {}, Result extends unknown = StaticType<[], 'Decode', Context, {}, Type>> = Result;
|
|
45
45
|
/** Infers a static type from a TypeBox type using Encode logic. */
|
|
46
|
-
export type StaticEncode<Type extends TSchema, Context extends TProperties = {}
|
|
46
|
+
export type StaticEncode<Type extends TSchema, Context extends TProperties = {}, Result extends unknown = StaticType<[], 'Encode', Context, {}, Type>> = Result;
|
|
47
47
|
/** Infers a static type from a TypeBox type. */
|
|
48
|
-
export type Static<Type extends TSchema, Context extends TProperties = {}
|
|
48
|
+
export type Static<Type extends TSchema, Context extends TProperties = {}, Result extends unknown = StaticType<[], 'Encode', Context, {}, Type>> = Result;
|
package/package.json
CHANGED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * as Resolver from './resolver.mjs';
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * as Resolver from './resolver.mjs';
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
import { Guard } from '../../guard/index.mjs';
|
|
2
|
-
import * as S from '../types/index.mjs';
|
|
3
|
-
import { Ref } from './ref.mjs';
|
|
4
|
-
// ------------------------------------------------------------------
|
|
5
|
-
// FromArray
|
|
6
|
-
// ------------------------------------------------------------------
|
|
7
|
-
function FromArray(value, anchor, ref) {
|
|
8
|
-
for (const item of value) {
|
|
9
|
-
const resolved = FromValue(item, anchor, ref);
|
|
10
|
-
if (!Guard.IsUndefined(resolved))
|
|
11
|
-
return resolved;
|
|
12
|
-
}
|
|
13
|
-
return undefined;
|
|
14
|
-
}
|
|
15
|
-
// ------------------------------------------------------------------
|
|
16
|
-
// FromObject
|
|
17
|
-
// ------------------------------------------------------------------
|
|
18
|
-
function FromObject(value, anchor, ref) {
|
|
19
|
-
for (const key of Guard.Keys(value)) {
|
|
20
|
-
const resolved = FromValue(value[key], anchor, ref);
|
|
21
|
-
if (!Guard.IsUndefined(resolved))
|
|
22
|
-
return resolved;
|
|
23
|
-
}
|
|
24
|
-
return undefined;
|
|
25
|
-
}
|
|
26
|
-
// ------------------------------------------------------------------
|
|
27
|
-
// FromValue
|
|
28
|
-
// ------------------------------------------------------------------
|
|
29
|
-
function FromValue(value, anchor, ref) {
|
|
30
|
-
if (Guard.IsObjectNotArray(value) && S.IsRecursiveAnchor(value)) {
|
|
31
|
-
anchor = value;
|
|
32
|
-
}
|
|
33
|
-
if (value === ref)
|
|
34
|
-
return Ref(anchor, ref.$recursiveRef);
|
|
35
|
-
if (Guard.IsArray(value))
|
|
36
|
-
return FromArray(value, anchor, ref);
|
|
37
|
-
if (Guard.IsObject(value))
|
|
38
|
-
return FromObject(value, anchor, ref);
|
|
39
|
-
return undefined;
|
|
40
|
-
}
|
|
41
|
-
// ------------------------------------------------------------------
|
|
42
|
-
// RecursiveRef
|
|
43
|
-
// ------------------------------------------------------------------
|
|
44
|
-
export function RecursiveRef(schema, ref) {
|
|
45
|
-
const anchor = schema;
|
|
46
|
-
return FromValue(schema, anchor, ref);
|
|
47
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function Ref(schema: unknown, ref: string): unknown;
|