@depup/typebox 1.3.27-depup.0 → 1.3.30-depup.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 +2 -2
- package/build/schema/build.mjs +2 -2
- package/build/schema/check.mjs +1 -1
- package/build/schema/engine/_context.d.mts +5 -1
- package/build/schema/engine/_context.mjs +16 -3
- package/build/schema/engine/_functions.d.mts +2 -2
- package/build/schema/engine/_functions.mjs +1 -1
- package/build/schema/engine/_reducer.d.mts +3 -3
- package/build/schema/engine/_refine.d.mts +5 -5
- package/build/schema/engine/_refine.mjs +4 -7
- package/build/schema/engine/_stack.d.mts +34 -20
- package/build/schema/engine/_stack.mjs +143 -202
- package/build/schema/engine/additionalItems.d.mts +4 -4
- package/build/schema/engine/additionalProperties.d.mts +8 -8
- package/build/schema/engine/additionalProperties.mjs +10 -14
- package/build/schema/engine/allOf.d.mts +4 -4
- package/build/schema/engine/allOf.mjs +1 -1
- package/build/schema/engine/anyOf.d.mts +4 -4
- package/build/schema/engine/anyOf.mjs +4 -9
- package/build/schema/engine/boolean.d.mts +4 -4
- package/build/schema/engine/boolean.mjs +2 -6
- package/build/schema/engine/const.d.mts +4 -4
- package/build/schema/engine/const.mjs +2 -6
- package/build/schema/engine/contains.d.mts +4 -4
- package/build/schema/engine/contains.mjs +2 -6
- package/build/schema/engine/dependencies.d.mts +4 -4
- package/build/schema/engine/dependencies.mjs +3 -6
- package/build/schema/engine/dependentRequired.d.mts +4 -4
- package/build/schema/engine/dependentRequired.mjs +2 -6
- package/build/schema/engine/dependentSchemas.d.mts +4 -4
- package/build/schema/engine/dynamicRef.d.mts +4 -4
- package/build/schema/engine/dynamicRef.mjs +11 -7
- package/build/schema/engine/enum.d.mts +4 -4
- package/build/schema/engine/enum.mjs +2 -6
- package/build/schema/engine/exclusiveMaximum.d.mts +4 -4
- package/build/schema/engine/exclusiveMaximum.mjs +2 -6
- package/build/schema/engine/exclusiveMinimum.d.mts +4 -4
- package/build/schema/engine/exclusiveMinimum.mjs +2 -6
- package/build/schema/engine/format.d.mts +4 -4
- package/build/schema/engine/format.mjs +2 -6
- package/build/schema/engine/if.d.mts +4 -4
- package/build/schema/engine/if.mjs +5 -13
- package/build/schema/engine/items.d.mts +4 -4
- package/build/schema/engine/items.mjs +1 -1
- package/build/schema/engine/maxContains.d.mts +4 -4
- package/build/schema/engine/maxContains.mjs +2 -6
- package/build/schema/engine/maxItems.d.mts +4 -4
- package/build/schema/engine/maxItems.mjs +2 -6
- package/build/schema/engine/maxLength.d.mts +4 -4
- package/build/schema/engine/maxLength.mjs +2 -6
- package/build/schema/engine/maxProperties.d.mts +4 -4
- package/build/schema/engine/maxProperties.mjs +2 -6
- package/build/schema/engine/maximum.d.mts +4 -4
- package/build/schema/engine/maximum.mjs +2 -6
- package/build/schema/engine/minContains.d.mts +4 -4
- package/build/schema/engine/minContains.mjs +2 -6
- package/build/schema/engine/minItems.d.mts +5 -5
- package/build/schema/engine/minItems.mjs +2 -6
- package/build/schema/engine/minLength.d.mts +4 -4
- package/build/schema/engine/minLength.mjs +2 -6
- package/build/schema/engine/minProperties.d.mts +4 -4
- package/build/schema/engine/minProperties.mjs +2 -6
- package/build/schema/engine/minimum.d.mts +4 -4
- package/build/schema/engine/minimum.mjs +2 -6
- package/build/schema/engine/multipleOf.d.mts +4 -4
- package/build/schema/engine/multipleOf.mjs +2 -6
- package/build/schema/engine/not.d.mts +4 -4
- package/build/schema/engine/not.mjs +4 -8
- package/build/schema/engine/oneOf.d.mts +4 -4
- package/build/schema/engine/oneOf.mjs +5 -10
- package/build/schema/engine/pattern.d.mts +4 -4
- package/build/schema/engine/pattern.mjs +3 -7
- package/build/schema/engine/patternProperties.d.mts +4 -4
- package/build/schema/engine/patternProperties.mjs +1 -1
- package/build/schema/engine/prefixItems.d.mts +4 -4
- package/build/schema/engine/prefixItems.mjs +1 -1
- package/build/schema/engine/properties.d.mts +4 -4
- package/build/schema/engine/properties.mjs +1 -1
- package/build/schema/engine/propertyNames.d.mts +4 -4
- package/build/schema/engine/propertyNames.mjs +3 -7
- package/build/schema/engine/recursiveRef.d.mts +4 -4
- package/build/schema/engine/recursiveRef.mjs +11 -7
- package/build/schema/engine/ref.d.mts +4 -4
- package/build/schema/engine/ref.mjs +17 -13
- package/build/schema/engine/required.d.mts +4 -4
- package/build/schema/engine/required.mjs +2 -6
- package/build/schema/engine/schema.d.mts +7 -7
- package/build/schema/engine/schema.mjs +131 -133
- package/build/schema/engine/type.d.mts +4 -4
- package/build/schema/engine/type.mjs +2 -6
- package/build/schema/engine/unevaluatedItems.d.mts +4 -4
- package/build/schema/engine/unevaluatedItems.mjs +3 -7
- package/build/schema/engine/unevaluatedProperties.d.mts +4 -4
- package/build/schema/engine/unevaluatedProperties.mjs +3 -7
- package/build/schema/engine/uniqueItems.d.mts +4 -4
- package/build/schema/engine/uniqueItems.mjs +2 -6
- package/build/schema/errors.mjs +1 -1
- package/build/schema/intern/intern.d.mts +6 -9
- package/build/schema/intern/intern.mjs +90 -56
- package/build/schema/meta/draft_2019_09.d.mts +2 -0
- package/build/schema/meta/draft_2019_09.mjs +288 -0
- package/build/schema/meta/draft_2020_12.d.mts +2 -0
- package/build/schema/meta/draft_2020_12.mjs +300 -0
- package/build/schema/meta/draft_3.d.mts +2 -0
- package/build/schema/meta/draft_3.mjs +143 -0
- package/build/schema/meta/draft_4.d.mts +2 -0
- package/build/schema/meta/draft_4.mjs +149 -0
- package/build/schema/meta/draft_6.d.mts +2 -0
- package/build/schema/meta/draft_6.mjs +155 -0
- package/build/schema/meta/draft_7.d.mts +2 -0
- package/build/schema/meta/draft_7.mjs +172 -0
- package/build/schema/meta/index.d.mts +2 -0
- package/build/schema/meta/index.mjs +2 -0
- package/build/schema/meta/meta.d.mts +9 -0
- package/build/schema/meta/meta.mjs +15 -0
- package/build/schema/meta/schema.d.mts +6 -0
- package/build/schema/meta/schema.mjs +1 -0
- package/build/schema/resolve/resolve.d.mts +6 -32
- package/build/schema/resolve/resolve.mjs +231 -227
- package/build/schema/schema.d.mts +1 -0
- package/build/schema/schema.mjs +1 -0
- package/changes.json +1 -1
- package/package.json +3 -3
- package/readme.md +51 -85
package/README.md
CHANGED
|
@@ -13,8 +13,8 @@ npm install @depup/typebox
|
|
|
13
13
|
|
|
14
14
|
| Field | Value |
|
|
15
15
|
|-------|-------|
|
|
16
|
-
| Original | [typebox](https://www.npmjs.com/package/typebox) @ 1.3.
|
|
17
|
-
| Processed | 2026-09-
|
|
16
|
+
| Original | [typebox](https://www.npmjs.com/package/typebox) @ 1.3.30 |
|
|
17
|
+
| Processed | 2026-09-13 |
|
|
18
18
|
| Smoke test | passed |
|
|
19
19
|
| Deps updated | 0 |
|
|
20
20
|
|
package/build/schema/build.mjs
CHANGED
|
@@ -27,7 +27,7 @@ function CreateEvaluatedCheck(build, code) {
|
|
|
27
27
|
// CreateDynamicCheck
|
|
28
28
|
// ------------------------------------------------------------------
|
|
29
29
|
function CreateDynamicCheck(build) {
|
|
30
|
-
const stack =
|
|
30
|
+
const stack = Engine.Stack(build.Context(), build.Schema());
|
|
31
31
|
const context = new Engine.CheckContext();
|
|
32
32
|
return (value) => Engine.CheckSchema(stack, context, build.Schema(), value);
|
|
33
33
|
}
|
|
@@ -109,7 +109,7 @@ export function Build(...args) {
|
|
|
109
109
|
});
|
|
110
110
|
Engine.ResetExternal();
|
|
111
111
|
Engine.ResetFunctions();
|
|
112
|
-
const stack =
|
|
112
|
+
const stack = Engine.Stack(context, schema);
|
|
113
113
|
const build = new Engine.BuildContext(Engine.HasUnevaluated(context, schema));
|
|
114
114
|
const call = Engine.CreateFunction(stack, build, schema, 'value');
|
|
115
115
|
const functions = Engine.GetFunctions();
|
package/build/schema/check.mjs
CHANGED
|
@@ -8,7 +8,7 @@ export function Check(...args) {
|
|
|
8
8
|
3: (context, schema, value) => [context, schema, value],
|
|
9
9
|
2: (schema, value) => [{}, schema, value]
|
|
10
10
|
});
|
|
11
|
-
const stack =
|
|
11
|
+
const stack = Engine.Stack(context, schema);
|
|
12
12
|
const checkContext = new Engine.CheckContext();
|
|
13
13
|
return Engine.CheckSchema(stack, checkContext, schema, value);
|
|
14
14
|
}
|
|
@@ -25,6 +25,10 @@ export declare class ErrorContext extends CheckContext {
|
|
|
25
25
|
private readonly errors;
|
|
26
26
|
constructor();
|
|
27
27
|
AtCapacity(): boolean;
|
|
28
|
-
AddError(
|
|
28
|
+
AddError<Keyword extends TValidationError['keyword']>(keyword: Keyword, schemaPath: string, instancePath: string, params: Extract<TValidationError, {
|
|
29
|
+
keyword: Keyword;
|
|
30
|
+
}>['params']): false;
|
|
31
|
+
AddErrors(error: TValidationError[]): false;
|
|
29
32
|
GetErrors(): TValidationError[];
|
|
33
|
+
private AddErrorObject;
|
|
30
34
|
}
|
|
@@ -110,15 +110,28 @@ export class ErrorContext extends CheckContext {
|
|
|
110
110
|
super();
|
|
111
111
|
this.errors = [];
|
|
112
112
|
}
|
|
113
|
+
// ----------------------------------------------------------------
|
|
114
|
+
// Public
|
|
115
|
+
// ----------------------------------------------------------------
|
|
113
116
|
AtCapacity() {
|
|
114
117
|
return this.errors.length >= Settings.Get().maxErrors;
|
|
115
118
|
}
|
|
116
|
-
AddError(
|
|
117
|
-
|
|
118
|
-
|
|
119
|
+
AddError(keyword, schemaPath, instancePath, params) {
|
|
120
|
+
return this.AddErrorObject({ keyword, schemaPath, instancePath, params });
|
|
121
|
+
}
|
|
122
|
+
AddErrors(error) {
|
|
123
|
+
error.forEach(error => this.AddErrorObject(error));
|
|
119
124
|
return false;
|
|
120
125
|
}
|
|
121
126
|
GetErrors() {
|
|
122
127
|
return this.errors;
|
|
123
128
|
}
|
|
129
|
+
// ----------------------------------------------------------------
|
|
130
|
+
// Private
|
|
131
|
+
// ----------------------------------------------------------------
|
|
132
|
+
AddErrorObject(error) {
|
|
133
|
+
if (!this.AtCapacity())
|
|
134
|
+
this.errors.push(error);
|
|
135
|
+
return false;
|
|
136
|
+
}
|
|
124
137
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as Schema from '../types/index.mjs';
|
|
2
|
-
import
|
|
2
|
+
import * as Stack from './_stack.mjs';
|
|
3
3
|
import { BuildContext } from './_context.mjs';
|
|
4
4
|
export declare function ResetFunctions(): void;
|
|
5
5
|
export declare function GetFunctions(): string[];
|
|
6
|
-
export declare function CreateFunction(stack: Stack, context: BuildContext, schema: Schema.XSchema, value: string): string;
|
|
6
|
+
export declare function CreateFunction(stack: Stack.XStack, context: BuildContext, schema: Schema.XSchema, value: string): string;
|
|
@@ -55,7 +55,7 @@ export function GetFunctions() {
|
|
|
55
55
|
// CreateFunction
|
|
56
56
|
// ------------------------------------------------------------------
|
|
57
57
|
export function CreateFunction(stack, context, schema, value) {
|
|
58
|
-
const name = CreateName(schema, stack.
|
|
58
|
+
const name = CreateName(schema, stack.lexicalBase);
|
|
59
59
|
const call = CreateCallExpression(context, schema, name, value);
|
|
60
60
|
if (funcs.has(name))
|
|
61
61
|
return call;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import * as
|
|
2
|
-
import
|
|
1
|
+
import * as Schema from '../types/index.mjs';
|
|
2
|
+
import * as Stack from './_stack.mjs';
|
|
3
3
|
import { BuildContext } from './_context.mjs';
|
|
4
|
-
export declare function Reducer(stack: Stack, context: BuildContext, schemas:
|
|
4
|
+
export declare function Reducer(stack: Stack.XStack, context: BuildContext, schemas: Schema.XSchema[], value: string, check: string): string;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import * as
|
|
2
|
-
import
|
|
1
|
+
import * as Schema from '../types/index.mjs';
|
|
2
|
+
import * as Stack from './_stack.mjs';
|
|
3
3
|
import { BuildContext, CheckContext, ErrorContext } from './_context.mjs';
|
|
4
|
-
export declare function BuildRefine(_stack: Stack, _context: BuildContext, schema:
|
|
5
|
-
export declare function CheckRefine(_stack: Stack, _context: CheckContext, schema:
|
|
6
|
-
export declare function ErrorRefine(_stack: Stack, context: ErrorContext, schemaPath: string, instancePath: string, schema:
|
|
4
|
+
export declare function BuildRefine(_stack: Stack.XStack, _context: BuildContext, schema: Schema.XRefine, value: string): string;
|
|
5
|
+
export declare function CheckRefine(_stack: Stack.XStack, _context: CheckContext, schema: Schema.XRefine, value: unknown): boolean;
|
|
6
|
+
export declare function ErrorRefine(_stack: Stack.XStack, context: ErrorContext, schemaPath: string, instancePath: string, schema: Schema.XRefine, value: unknown): boolean;
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
// deno-fmt-ignore-file
|
|
2
|
-
import * as
|
|
2
|
+
import * as Externals from './_externals.mjs';
|
|
3
3
|
import { EmitGuard as E, Guard as G } from '../../guard/index.mjs';
|
|
4
4
|
// ------------------------------------------------------------------
|
|
5
5
|
// Build
|
|
6
6
|
// ------------------------------------------------------------------
|
|
7
7
|
export function BuildRefine(_stack, _context, schema, value) {
|
|
8
|
-
const refinements =
|
|
8
|
+
const refinements = Externals.CreateVariable(schema['~refine'].map((refinement) => refinement));
|
|
9
9
|
return E.Every(refinements, E.Constant(0), ['refinement', '_'], E.Call(E.Member('refinement', 'check'), [value]));
|
|
10
10
|
}
|
|
11
11
|
// ------------------------------------------------------------------
|
|
@@ -19,11 +19,8 @@ export function CheckRefine(_stack, _context, schema, value) {
|
|
|
19
19
|
// ------------------------------------------------------------------
|
|
20
20
|
export function ErrorRefine(_stack, context, schemaPath, instancePath, schema, value) {
|
|
21
21
|
return G.EveryAll(schema['~refine'], 0, (refinement, index) => {
|
|
22
|
-
return refinement.check(value) || context.AddError({
|
|
23
|
-
|
|
24
|
-
schemaPath,
|
|
25
|
-
instancePath,
|
|
26
|
-
params: { index, message: refinement.error(value) },
|
|
22
|
+
return refinement.check(value) || context.AddError('~refine', schemaPath, instancePath, {
|
|
23
|
+
index, message: refinement.error(value)
|
|
27
24
|
});
|
|
28
25
|
});
|
|
29
26
|
}
|
|
@@ -1,22 +1,36 @@
|
|
|
1
1
|
import * as Schema from '../types/index.mjs';
|
|
2
|
-
export declare
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
2
|
+
export declare const DefaultUri = "urn:typebox:root";
|
|
3
|
+
export interface XStack {
|
|
4
|
+
/** The schema context. */
|
|
5
|
+
readonly context: Record<string, Schema.XSchema>;
|
|
6
|
+
/** The entry schema. */
|
|
7
|
+
readonly schema: Schema.XSchema;
|
|
8
|
+
/** Visited $id schemas, kept only to detect resource re-entry (see resolve.ts FindResolvedResource). */
|
|
9
|
+
readonly ids: Schema.XId[];
|
|
10
|
+
/** Nearest enclosing $id schema, used as the root for local pointer resolution. */
|
|
11
|
+
readonly lexicalSchema: Schema.XSchema;
|
|
12
|
+
/** First $recursiveAnchor: true schema seen on the path. */
|
|
13
|
+
readonly recursiveAnchor: Schema.XRecursiveAnchor | undefined;
|
|
14
|
+
/** Dynamic anchors visible at this point in the traversal. */
|
|
15
|
+
readonly dynamicAnchors: Schema.XDynamicAnchor[];
|
|
16
|
+
/** Lexical base URL, used to resolve relative $id and $ref values within the current schema. */
|
|
17
|
+
readonly lexicalBase: string;
|
|
18
|
+
/** Base URL of the current resource, reset each time a new resource $id is entered. */
|
|
19
|
+
readonly resourceBase: string;
|
|
20
|
+
/** Base URL that $ref values resolve against. */
|
|
21
|
+
readonly referenceBase: string;
|
|
22
|
+
/** Resource entry point bookkeeping: schema -> the base/root to apply when that schema is next pushed. */
|
|
23
|
+
readonly resourceEntries: Map<Schema.XSchemaObject, {
|
|
24
|
+
base: string;
|
|
25
|
+
root: Schema.XSchemaObject;
|
|
26
|
+
}>;
|
|
27
|
+
/** True while referenceBase should track resourceBase rather than lexicalBase. */
|
|
28
|
+
readonly useResourceBaseForReference: boolean;
|
|
29
|
+
/** True until the next $id schema is entered, marking it as a fresh resource root. */
|
|
30
|
+
readonly pendingResource: boolean;
|
|
31
|
+
/** True once traversal has entered a retrieved or legacy resource. */
|
|
32
|
+
readonly enteredResource: boolean;
|
|
22
33
|
}
|
|
34
|
+
export declare function NextUri(ref: string, base: string): URL;
|
|
35
|
+
export declare function Stack(context: Record<string, Schema.XSchema>, schema: Schema.XSchema): XStack;
|
|
36
|
+
export declare function NextStack(stack: XStack, schema: Schema.XSchema): XStack;
|
|
@@ -1,209 +1,150 @@
|
|
|
1
|
-
// deno-fmt-ignore-file
|
|
2
|
-
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
3
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
4
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
5
|
-
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
6
|
-
};
|
|
7
|
-
var _Stack_instances, _Stack_StackFrame, _Stack_ApplyRefResult, _Stack_BuildBase, _Stack_ResourceBaseURL, _Stack_ReferenceBaseURL, _Stack_LexicalSchema, _Stack_RegisterResourceAnchorArray, _Stack_UnregisterResourceAnchorArray, _Stack_RegisterResourceAnchors, _Stack_UnregisterResourceAnchors, _Stack_RegisterResource, _Stack_UnregisterResource, _Stack_EnterResolvedResource, _Stack_ExitResolvedResource;
|
|
8
|
-
import * as Schema from '../types/index.mjs';
|
|
9
1
|
import { Guard } from '../../guard/index.mjs';
|
|
10
|
-
import
|
|
11
|
-
//
|
|
2
|
+
import * as Schema from '../types/index.mjs';
|
|
3
|
+
// ------------------------------------------------------------------
|
|
4
|
+
// DefaultUri
|
|
5
|
+
// ------------------------------------------------------------------
|
|
6
|
+
export const DefaultUri = 'urn:typebox:root';
|
|
7
|
+
// ------------------------------------------------------------------
|
|
8
|
+
// NextUri
|
|
9
|
+
//
|
|
10
|
+
// Resolves a relative or absolute ref against a base URI or URN.
|
|
11
|
+
// Hierarchical bases (http, https, etc.) resolve using the normal
|
|
12
|
+
// URL rules. URN bases have no path to resolve against, so the ref
|
|
13
|
+
// is appended after the base's last ':' segment instead.
|
|
14
|
+
// ------------------------------------------------------------------
|
|
15
|
+
export function NextUri(ref, base) {
|
|
16
|
+
return (URL.canParse(ref, base)) ? new URL(ref, base) : Guard.IsEqual(base, DefaultUri) ? new URL(`${base}:${ref}`) : new URL(`${base.slice(0, base.lastIndexOf(':'))}:${ref}`);
|
|
17
|
+
}
|
|
18
|
+
// ------------------------------------------------------------------
|
|
12
19
|
// Stack
|
|
13
20
|
//
|
|
14
|
-
//
|
|
15
|
-
//
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
export class Stack {
|
|
19
|
-
constructor(context, schema) {
|
|
20
|
-
_Stack_instances.add(this);
|
|
21
|
-
this.context = context;
|
|
22
|
-
this.schema = schema;
|
|
23
|
-
this.ids = [];
|
|
24
|
-
this.resourceIds = [];
|
|
25
|
-
this.anchors = [];
|
|
26
|
-
this.recursiveAnchors = [];
|
|
27
|
-
this.dynamicAnchors = [];
|
|
28
|
-
this.retrievedResources = new Map();
|
|
29
|
-
this.retrievedFrames = [];
|
|
30
|
-
this.resolvedResources = new Map();
|
|
31
|
-
this.pendingResource = true;
|
|
32
|
-
}
|
|
33
|
-
// ----------------------------------------------------------------
|
|
34
|
-
// LexicalBaseURL
|
|
35
|
-
// ----------------------------------------------------------------
|
|
36
|
-
LexicalBaseURL() {
|
|
37
|
-
return __classPrivateFieldGet(this, _Stack_instances, "m", _Stack_BuildBase).call(this, this.ids);
|
|
38
|
-
}
|
|
39
|
-
// ----------------------------------------------------------------
|
|
40
|
-
// Push
|
|
41
|
-
// ----------------------------------------------------------------
|
|
42
|
-
Push(schema) {
|
|
43
|
-
if (!Schema.IsSchemaObject(schema))
|
|
44
|
-
return;
|
|
45
|
-
if (Schema.IsId(schema))
|
|
46
|
-
__classPrivateFieldGet(this, _Stack_instances, "m", _Stack_RegisterResource).call(this, schema);
|
|
47
|
-
if (Schema.IsAnchor(schema))
|
|
48
|
-
this.anchors.push(schema);
|
|
49
|
-
if (Schema.IsRecursiveAnchorTrue(schema))
|
|
50
|
-
this.recursiveAnchors.push(schema);
|
|
51
|
-
if (Schema.IsDynamicAnchor(schema))
|
|
52
|
-
this.dynamicAnchors.push(schema);
|
|
53
|
-
const retrievedResource = this.retrievedResources.get(schema);
|
|
54
|
-
if (retrievedResource) {
|
|
55
|
-
this.retrievedFrames.push({
|
|
56
|
-
schema: retrievedResource.root,
|
|
57
|
-
base: retrievedResource.base,
|
|
58
|
-
idDepth: this.ids.length,
|
|
59
|
-
resourceDepth: this.resourceIds.length
|
|
60
|
-
});
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
// ----------------------------------------------------------------
|
|
64
|
-
// Pop
|
|
65
|
-
// ----------------------------------------------------------------
|
|
66
|
-
Pop(schema) {
|
|
67
|
-
if (!Schema.IsSchemaObject(schema))
|
|
68
|
-
return;
|
|
69
|
-
if (Schema.IsId(schema))
|
|
70
|
-
__classPrivateFieldGet(this, _Stack_instances, "m", _Stack_UnregisterResource).call(this, schema);
|
|
71
|
-
if (Schema.IsAnchor(schema))
|
|
72
|
-
this.anchors.pop();
|
|
73
|
-
if (Schema.IsRecursiveAnchorTrue(schema))
|
|
74
|
-
this.recursiveAnchors.pop();
|
|
75
|
-
if (Schema.IsDynamicAnchor(schema))
|
|
76
|
-
this.dynamicAnchors.pop();
|
|
77
|
-
if (this.retrievedResources.has(schema))
|
|
78
|
-
this.retrievedFrames.pop();
|
|
79
|
-
__classPrivateFieldGet(this, _Stack_instances, "m", _Stack_ExitResolvedResource).call(this, schema);
|
|
80
|
-
}
|
|
81
|
-
// ----------------------------------------------------------------
|
|
82
|
-
// Ref
|
|
83
|
-
// ----------------------------------------------------------------
|
|
84
|
-
Ref(ref) {
|
|
85
|
-
const result = Resolve.ResolveRef(__classPrivateFieldGet(this, _Stack_instances, "m", _Stack_StackFrame).call(this), ref);
|
|
86
|
-
__classPrivateFieldGet(this, _Stack_instances, "m", _Stack_ApplyRefResult).call(this, result);
|
|
87
|
-
return result.schema;
|
|
88
|
-
}
|
|
89
|
-
// ----------------------------------------------------------------
|
|
90
|
-
// RecursiveRef
|
|
91
|
-
// ----------------------------------------------------------------
|
|
92
|
-
RecursiveRef(recursiveRef) {
|
|
93
|
-
const result = Resolve.ResolveRecursiveRef(__classPrivateFieldGet(this, _Stack_instances, "m", _Stack_StackFrame).call(this), recursiveRef);
|
|
94
|
-
if (result)
|
|
95
|
-
this.pendingResource = true;
|
|
96
|
-
return result;
|
|
97
|
-
}
|
|
98
|
-
// ----------------------------------------------------------------
|
|
99
|
-
// DynamicRef
|
|
100
|
-
// ----------------------------------------------------------------
|
|
101
|
-
DynamicRef(dynamicRef) {
|
|
102
|
-
const result = Resolve.ResolveDynamicRef(__classPrivateFieldGet(this, _Stack_instances, "m", _Stack_StackFrame).call(this), dynamicRef);
|
|
103
|
-
if (result)
|
|
104
|
-
this.pendingResource = true;
|
|
105
|
-
return result;
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
_Stack_instances = new WeakSet(), _Stack_StackFrame = function _Stack_StackFrame() {
|
|
21
|
+
// Creates the root frame a schema traversal starts from.
|
|
22
|
+
// ------------------------------------------------------------------
|
|
23
|
+
export function Stack(context, schema) {
|
|
24
|
+
const base = Schema.IsSchemaObject(schema) && Schema.IsId(schema) ? NextUri(schema.$id, DefaultUri).href : DefaultUri;
|
|
109
25
|
return {
|
|
110
|
-
context
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
referenceBase:
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
26
|
+
context,
|
|
27
|
+
schema,
|
|
28
|
+
lexicalSchema: schema,
|
|
29
|
+
lexicalBase: base,
|
|
30
|
+
resourceBase: base,
|
|
31
|
+
referenceBase: base,
|
|
32
|
+
ids: [],
|
|
33
|
+
useResourceBaseForReference: true,
|
|
34
|
+
recursiveAnchor: undefined,
|
|
35
|
+
dynamicAnchors: [],
|
|
36
|
+
resourceEntries: new Map(),
|
|
37
|
+
pendingResource: true,
|
|
38
|
+
enteredResource: false
|
|
120
39
|
};
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
base: result.retrievedResource.base,
|
|
130
|
-
root: result.retrievedResource.root
|
|
131
|
-
});
|
|
132
|
-
}
|
|
133
|
-
}, _Stack_BuildBase = function _Stack_BuildBase(stack) {
|
|
134
|
-
const frame = this.retrievedFrames[this.retrievedFrames.length - 1];
|
|
135
|
-
const base = frame ? new URL(frame.base) : new URL(Resolve.DefaultBase);
|
|
136
|
-
const scoped = frame ? stack.slice(frame.idDepth) : stack;
|
|
137
|
-
return scoped.reduce((result, schema) => new URL(schema.$id, result), base).href;
|
|
138
|
-
}, _Stack_ResourceBaseURL = function _Stack_ResourceBaseURL() {
|
|
139
|
-
const frame = this.retrievedFrames[this.retrievedFrames.length - 1];
|
|
140
|
-
if (!frame)
|
|
141
|
-
return __classPrivateFieldGet(this, _Stack_instances, "m", _Stack_BuildBase).call(this, this.resourceIds);
|
|
142
|
-
return this.resourceIds.slice(frame.resourceDepth).reduce((result, schema) => new URL(schema.$id, result), new URL(frame.base)).href;
|
|
143
|
-
}, _Stack_ReferenceBaseURL = function _Stack_ReferenceBaseURL() {
|
|
144
|
-
if (this.retrievedFrames.length > 0)
|
|
145
|
-
return __classPrivateFieldGet(this, _Stack_instances, "m", _Stack_ResourceBaseURL).call(this);
|
|
146
|
-
const lexical = this.ids[this.ids.length - 1];
|
|
147
|
-
if (lexical && !/^[A-Za-z][A-Za-z0-9+.-]*:/.test(lexical.$id))
|
|
148
|
-
return this.LexicalBaseURL();
|
|
149
|
-
return __classPrivateFieldGet(this, _Stack_instances, "m", _Stack_ResourceBaseURL).call(this);
|
|
150
|
-
}, _Stack_LexicalSchema = function _Stack_LexicalSchema() {
|
|
151
|
-
const frame = this.retrievedFrames[this.retrievedFrames.length - 1];
|
|
152
|
-
if (frame)
|
|
153
|
-
return this.ids.length > frame.idDepth ? this.ids[this.ids.length - 1] : frame.schema;
|
|
154
|
-
return this.ids.length > 0 ? this.ids[this.ids.length - 1] : this.schema;
|
|
155
|
-
}, _Stack_RegisterResourceAnchorArray = function _Stack_RegisterResourceAnchorArray(schema) {
|
|
156
|
-
schema.forEach((schema) => __classPrivateFieldGet(this, _Stack_instances, "m", _Stack_RegisterResourceAnchors).call(this, schema, false));
|
|
157
|
-
}, _Stack_UnregisterResourceAnchorArray = function _Stack_UnregisterResourceAnchorArray(schema) {
|
|
158
|
-
schema.forEach((schema) => __classPrivateFieldGet(this, _Stack_instances, "m", _Stack_UnregisterResourceAnchors).call(this, schema, false));
|
|
159
|
-
}, _Stack_RegisterResourceAnchors = function _Stack_RegisterResourceAnchors(schema, isRoot = true) {
|
|
160
|
-
if (Schema.IsSchemaBoolean(schema))
|
|
161
|
-
return;
|
|
162
|
-
if (Guard.IsArray(schema))
|
|
163
|
-
return __classPrivateFieldGet(this, _Stack_instances, "m", _Stack_RegisterResourceAnchorArray).call(this, schema);
|
|
164
|
-
if (!Schema.IsSchemaObject(schema))
|
|
165
|
-
return;
|
|
166
|
-
const current = schema;
|
|
167
|
-
if (!isRoot && Schema.IsId(current))
|
|
168
|
-
return;
|
|
169
|
-
if (!isRoot && Schema.IsDynamicAnchor(current))
|
|
170
|
-
this.dynamicAnchors.push(current);
|
|
171
|
-
for (const key of Guard.Keys(current))
|
|
172
|
-
__classPrivateFieldGet(this, _Stack_instances, "m", _Stack_RegisterResourceAnchors).call(this, current[key], false);
|
|
173
|
-
}, _Stack_UnregisterResourceAnchors = function _Stack_UnregisterResourceAnchors(schema, isRoot = true) {
|
|
40
|
+
}
|
|
41
|
+
// ------------------------------------------------------------------
|
|
42
|
+
// RegisterResourceAnchors
|
|
43
|
+
//
|
|
44
|
+
// Collects $dynamicAnchor schemas reachable from a resource root,
|
|
45
|
+
// stopping at nested $id boundaries which own their own anchors.
|
|
46
|
+
// ------------------------------------------------------------------
|
|
47
|
+
function RegisterResourceAnchors(anchors, schema, isRoot = true) {
|
|
174
48
|
if (Schema.IsSchemaBoolean(schema))
|
|
175
|
-
return;
|
|
176
|
-
if (
|
|
177
|
-
return
|
|
49
|
+
return anchors;
|
|
50
|
+
if (Array.isArray(schema))
|
|
51
|
+
return schema.reduce((result, item) => RegisterResourceAnchors(result, item, false), anchors);
|
|
178
52
|
if (!Schema.IsSchemaObject(schema))
|
|
179
|
-
return;
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
}
|
|
53
|
+
return anchors;
|
|
54
|
+
if (!isRoot && Schema.IsId(schema))
|
|
55
|
+
return anchors;
|
|
56
|
+
const next = !isRoot && Schema.IsDynamicAnchor(schema) ? [...anchors, schema] : anchors;
|
|
57
|
+
return Object.keys(schema).reduce((result, key) => RegisterResourceAnchors(result, schema[key], false), next);
|
|
58
|
+
}
|
|
59
|
+
// ------------------------------------------------------------------
|
|
60
|
+
// ResourceEntry
|
|
61
|
+
//
|
|
62
|
+
// A ref crossing (Resolve.Ref) may have marked `schema` as the entry
|
|
63
|
+
// point of a retrieved/legacy resource. If so the frame resets to
|
|
64
|
+
// that resource's base/root instead of chaining onto the parent.
|
|
65
|
+
// ------------------------------------------------------------------
|
|
66
|
+
function ResourceEntry(stack, schema) {
|
|
67
|
+
return stack.resourceEntries.get(schema);
|
|
68
|
+
}
|
|
69
|
+
function NextEnteredResource(stack, schema) {
|
|
70
|
+
return stack.enteredResource || ResourceEntry(stack, schema) !== undefined;
|
|
71
|
+
}
|
|
72
|
+
// ------------------------------------------------------------------
|
|
73
|
+
// NextStack
|
|
74
|
+
//
|
|
75
|
+
// Each Next* helper below computes one XStack field in isolation from
|
|
76
|
+
// the previous frame and the schema being pushed.
|
|
77
|
+
// ------------------------------------------------------------------
|
|
78
|
+
function IsRelativeId(schema) {
|
|
79
|
+
return !/^[A-Za-z][A-Za-z0-9+.-]*:/.test(schema.$id);
|
|
80
|
+
}
|
|
81
|
+
function NextIds(stack, schema) {
|
|
82
|
+
return Schema.IsId(schema) ? [...stack.ids, schema] : stack.ids;
|
|
83
|
+
}
|
|
84
|
+
function NextRecursiveAnchor(stack, schema) {
|
|
85
|
+
return stack.recursiveAnchor ?? (Schema.IsRecursiveAnchorTrue(schema) ? schema : undefined);
|
|
86
|
+
}
|
|
87
|
+
function NextDynamicAnchors(stack, schema) {
|
|
88
|
+
const registered = Schema.IsId(schema) ? RegisterResourceAnchors(stack.dynamicAnchors, schema) : stack.dynamicAnchors;
|
|
89
|
+
return Schema.IsDynamicAnchor(schema) ? [...registered, schema] : registered;
|
|
90
|
+
}
|
|
91
|
+
function NextPendingResource(stack, schema) {
|
|
92
|
+
return Schema.IsId(schema) ? false : stack.pendingResource;
|
|
93
|
+
}
|
|
94
|
+
function NextLexicalBase(stack, schema) {
|
|
95
|
+
const entry = ResourceEntry(stack, schema);
|
|
96
|
+
if (entry)
|
|
97
|
+
return entry.base;
|
|
98
|
+
return Schema.IsId(schema) ? NextUri(schema.$id, stack.lexicalBase).href : stack.lexicalBase;
|
|
99
|
+
}
|
|
100
|
+
function NextResourceBase(stack, schema) {
|
|
101
|
+
const entry = ResourceEntry(stack, schema);
|
|
102
|
+
if (entry)
|
|
103
|
+
return entry.base;
|
|
104
|
+
return (Schema.IsId(schema) && stack.pendingResource) ? NextUri(schema.$id, stack.resourceBase).href : stack.resourceBase;
|
|
105
|
+
}
|
|
106
|
+
function NextUseResourceBaseForReference(stack, schema) {
|
|
107
|
+
return Schema.IsId(schema) ? !IsRelativeId(schema) : stack.useResourceBaseForReference;
|
|
108
|
+
}
|
|
109
|
+
function NextReferenceBase(stack, schema) {
|
|
110
|
+
const isRetrieved = NextEnteredResource(stack, schema);
|
|
111
|
+
const useResourceBaseForReference = NextUseResourceBaseForReference(stack, schema);
|
|
112
|
+
return (isRetrieved || useResourceBaseForReference) ? NextResourceBase(stack, schema) : NextLexicalBase(stack, schema);
|
|
113
|
+
}
|
|
114
|
+
function NextLexicalSchema(stack, schema) {
|
|
115
|
+
const entry = ResourceEntry(stack, schema);
|
|
116
|
+
if (entry)
|
|
117
|
+
return entry.root;
|
|
118
|
+
return Schema.IsId(schema) ? schema : stack.lexicalSchema;
|
|
119
|
+
}
|
|
120
|
+
// ------------------------------------------------------------------
|
|
121
|
+
// NextStack | HasStackKeywords (Optimization)
|
|
122
|
+
//
|
|
123
|
+
// HasStackKeywords narrows schema to an object and checks whether it
|
|
124
|
+
// carries $id, $dynamicAnchor, a first-seen $recursiveAnchor, or a
|
|
125
|
+
// resource-entry point. When none apply, NextStack skips the frame
|
|
126
|
+
// rebuild and returns the parent stack as-is.
|
|
127
|
+
// ------------------------------------------------------------------
|
|
128
|
+
function HasStackKeywords(stack, schema) {
|
|
129
|
+
return Schema.IsSchemaObject(schema) && (Schema.IsId(schema) ||
|
|
130
|
+
Schema.IsDynamicAnchor(schema) ||
|
|
131
|
+
(Guard.IsUndefined(stack.recursiveAnchor) && Schema.IsRecursiveAnchorTrue(schema)) ||
|
|
132
|
+
!Guard.IsUndefined(ResourceEntry(stack, schema)));
|
|
133
|
+
}
|
|
134
|
+
export function NextStack(stack, schema) {
|
|
135
|
+
return HasStackKeywords(stack, schema)
|
|
136
|
+
? {
|
|
137
|
+
...stack,
|
|
138
|
+
ids: NextIds(stack, schema),
|
|
139
|
+
dynamicAnchors: NextDynamicAnchors(stack, schema),
|
|
140
|
+
recursiveAnchor: NextRecursiveAnchor(stack, schema),
|
|
141
|
+
pendingResource: NextPendingResource(stack, schema),
|
|
142
|
+
lexicalBase: NextLexicalBase(stack, schema),
|
|
143
|
+
resourceBase: NextResourceBase(stack, schema),
|
|
144
|
+
useResourceBaseForReference: NextUseResourceBaseForReference(stack, schema),
|
|
145
|
+
referenceBase: NextReferenceBase(stack, schema),
|
|
146
|
+
lexicalSchema: NextLexicalSchema(stack, schema),
|
|
147
|
+
enteredResource: NextEnteredResource(stack, schema)
|
|
148
|
+
}
|
|
149
|
+
: stack;
|
|
150
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as Schema from '../types/index.mjs';
|
|
2
|
-
import
|
|
2
|
+
import * as Stack from './_stack.mjs';
|
|
3
3
|
import { BuildContext, CheckContext, ErrorContext } from './_context.mjs';
|
|
4
|
-
export declare function BuildAdditionalItems(stack: Stack, context: BuildContext, schema: Schema.XAdditionalItems, value: string): string;
|
|
5
|
-
export declare function CheckAdditionalItems(stack: Stack, context: CheckContext, schema: Schema.XAdditionalItems, value: unknown[]): boolean;
|
|
6
|
-
export declare function ErrorAdditionalItems(stack: Stack, context: ErrorContext, schemaPath: string, instancePath: string, schema: Schema.XAdditionalItems, value: unknown[]): boolean;
|
|
4
|
+
export declare function BuildAdditionalItems(stack: Stack.XStack, context: BuildContext, schema: Schema.XAdditionalItems, value: string): string;
|
|
5
|
+
export declare function CheckAdditionalItems(stack: Stack.XStack, context: CheckContext, schema: Schema.XAdditionalItems, value: unknown[]): boolean;
|
|
6
|
+
export declare function ErrorAdditionalItems(stack: Stack.XStack, context: ErrorContext, schemaPath: string, instancePath: string, schema: Schema.XAdditionalItems, value: unknown[]): boolean;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import * as
|
|
2
|
-
import
|
|
1
|
+
import * as Schema from '../types/index.mjs';
|
|
2
|
+
import * as Stack from './_stack.mjs';
|
|
3
3
|
import { BuildContext, CheckContext, ErrorContext } from './_context.mjs';
|
|
4
|
-
export declare function CanAdditionalPropertiesFast(_context: BuildContext, schema:
|
|
5
|
-
export declare function BuildAdditionalPropertiesFast(_context: BuildContext, schema:
|
|
6
|
-
export declare function BuildAdditionalPropertiesStandard(stack: Stack, context: BuildContext, schema:
|
|
7
|
-
export declare function BuildAdditionalProperties(stack: Stack, context: BuildContext, schema:
|
|
8
|
-
export declare function CheckAdditionalProperties(stack: Stack, context: CheckContext, schema:
|
|
9
|
-
export declare function ErrorAdditionalProperties(stack: Stack, context: ErrorContext, schemaPath: string, instancePath: string, schema:
|
|
4
|
+
export declare function CanAdditionalPropertiesFast(_context: BuildContext, schema: Schema.XAdditionalProperties, _value: string): schema is Schema.XAdditionalProperties & Schema.XRequired;
|
|
5
|
+
export declare function BuildAdditionalPropertiesFast(_context: BuildContext, schema: Schema.XAdditionalProperties & Schema.XRequired, value: string): string;
|
|
6
|
+
export declare function BuildAdditionalPropertiesStandard(stack: Stack.XStack, context: BuildContext, schema: Schema.XAdditionalProperties, value: string): string;
|
|
7
|
+
export declare function BuildAdditionalProperties(stack: Stack.XStack, context: BuildContext, schema: Schema.XAdditionalProperties, value: string): string;
|
|
8
|
+
export declare function CheckAdditionalProperties(stack: Stack.XStack, context: CheckContext, schema: Schema.XAdditionalProperties, value: Record<PropertyKey, unknown>): boolean;
|
|
9
|
+
export declare function ErrorAdditionalProperties(stack: Stack.XStack, context: ErrorContext, schemaPath: string, instancePath: string, schema: Schema.XAdditionalProperties, value: Record<PropertyKey, unknown>): boolean;
|