@brud/kernel 0.0.0-stage → 0.0.1
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/LICENSE +201 -0
- package/README.md +63 -2
- package/dist/index.d.ts +15 -0
- package/dist/index.js +13 -0
- package/dist/serviceModules/events.d.ts +1 -0
- package/dist/serviceModules/events.js +1 -0
- package/dist/serviceModules/exposedApiRegistry.d.ts +1 -0
- package/dist/serviceModules/exposedApiRegistry.js +1 -0
- package/dist/serviceModules/identityRegistry.d.ts +1 -0
- package/dist/serviceModules/identityRegistry.js +1 -0
- package/dist/serviceModules/interception.d.ts +1 -0
- package/dist/serviceModules/interception.js +1 -0
- package/dist/serviceModules/parser.d.ts +1 -0
- package/dist/serviceModules/parser.js +1 -0
- package/dist/serviceModules/router.d.ts +1 -0
- package/dist/serviceModules/router.js +1 -0
- package/dist/serviceModules/wasmCage.d.ts +1 -0
- package/dist/serviceModules/wasmCage.js +1 -0
- package/dist/services/Events/contracts/IEventsService.d.ts +64 -0
- package/dist/services/Events/contracts/IEventsService.js +1 -0
- package/dist/services/Events/contracts/errors.d.ts +31 -0
- package/dist/services/Events/contracts/errors.js +40 -0
- package/dist/services/Events/contracts/index.d.ts +3 -0
- package/dist/services/Events/contracts/index.js +3 -0
- package/dist/services/Events/contracts/tokens.d.ts +2 -0
- package/dist/services/Events/contracts/tokens.js +2 -0
- package/dist/services/Events/descriptor/EventsDescriptor.d.ts +9 -0
- package/dist/services/Events/descriptor/EventsDescriptor.js +56 -0
- package/dist/services/Events/descriptor/tokens.d.ts +1 -0
- package/dist/services/Events/descriptor/tokens.js +1 -0
- package/dist/services/Events/index.d.ts +4 -0
- package/dist/services/Events/index.js +4 -0
- package/dist/services/Events/orchestrator/EventsService.d.ts +51 -0
- package/dist/services/Events/orchestrator/EventsService.js +339 -0
- package/dist/services/Events/orchestrator/index.d.ts +2 -0
- package/dist/services/Events/orchestrator/index.js +2 -0
- package/dist/services/Events/orchestrator/limits.d.ts +22 -0
- package/dist/services/Events/orchestrator/limits.js +33 -0
- package/dist/services/Events/serviceModule.d.ts +2 -0
- package/dist/services/Events/serviceModule.js +5 -0
- package/dist/services/ExposedApiRegistry/contracts/IExposedApiRegistry.d.ts +44 -0
- package/dist/services/ExposedApiRegistry/contracts/IExposedApiRegistry.js +1 -0
- package/dist/services/ExposedApiRegistry/contracts/errors.d.ts +132 -0
- package/dist/services/ExposedApiRegistry/contracts/errors.js +195 -0
- package/dist/services/ExposedApiRegistry/contracts/index.d.ts +9 -0
- package/dist/services/ExposedApiRegistry/contracts/index.js +4 -0
- package/dist/services/ExposedApiRegistry/contracts/policy.d.ts +90 -0
- package/dist/services/ExposedApiRegistry/contracts/policy.js +169 -0
- package/dist/services/ExposedApiRegistry/contracts/registrant.d.ts +37 -0
- package/dist/services/ExposedApiRegistry/contracts/registrant.js +36 -0
- package/dist/services/ExposedApiRegistry/contracts/types.d.ts +112 -0
- package/dist/services/ExposedApiRegistry/contracts/types.js +73 -0
- package/dist/services/ExposedApiRegistry/descriptor/ExposedApiRegistryDescriptor.d.ts +44 -0
- package/dist/services/ExposedApiRegistry/descriptor/ExposedApiRegistryDescriptor.js +58 -0
- package/dist/services/ExposedApiRegistry/descriptor/tokens.d.ts +8 -0
- package/dist/services/ExposedApiRegistry/descriptor/tokens.js +8 -0
- package/dist/services/ExposedApiRegistry/index.d.ts +6 -0
- package/dist/services/ExposedApiRegistry/index.js +5 -0
- package/dist/services/ExposedApiRegistry/orchestrator/ExposedApiRegistryService.d.ts +61 -0
- package/dist/services/ExposedApiRegistry/orchestrator/ExposedApiRegistryService.js +407 -0
- package/dist/services/ExposedApiRegistry/orchestrator/index.d.ts +2 -0
- package/dist/services/ExposedApiRegistry/orchestrator/index.js +1 -0
- package/dist/services/ExposedApiRegistry/serviceModule.d.ts +10 -0
- package/dist/services/ExposedApiRegistry/serviceModule.js +20 -0
- package/dist/services/ExposedApiRegistry/storage/protection.d.ts +21 -0
- package/dist/services/ExposedApiRegistry/storage/protection.js +35 -0
- package/dist/services/ExposedApiRegistry/storage/scopeRecord.d.ts +45 -0
- package/dist/services/ExposedApiRegistry/storage/scopeRecord.js +178 -0
- package/dist/services/IdentityRegistry/contracts/errors.d.ts +88 -0
- package/dist/services/IdentityRegistry/contracts/errors.js +128 -0
- package/dist/services/IdentityRegistry/contracts/index.d.ts +5 -0
- package/dist/services/IdentityRegistry/contracts/index.js +3 -0
- package/dist/services/IdentityRegistry/contracts/types.d.ts +77 -0
- package/dist/services/IdentityRegistry/contracts/types.js +18 -0
- package/dist/services/IdentityRegistry/descriptor/descriptor.d.ts +36 -0
- package/dist/services/IdentityRegistry/descriptor/descriptor.js +44 -0
- package/dist/services/IdentityRegistry/descriptor/tokens.d.ts +8 -0
- package/dist/services/IdentityRegistry/descriptor/tokens.js +8 -0
- package/dist/services/IdentityRegistry/index.d.ts +11 -0
- package/dist/services/IdentityRegistry/index.js +6 -0
- package/dist/services/IdentityRegistry/orchestrator/IdentityRegistryService.d.ts +47 -0
- package/dist/services/IdentityRegistry/orchestrator/IdentityRegistryService.js +240 -0
- package/dist/services/IdentityRegistry/serviceModule.d.ts +10 -0
- package/dist/services/IdentityRegistry/serviceModule.js +24 -0
- package/dist/services/IdentityRegistry/storage/registryDocument.d.ts +55 -0
- package/dist/services/IdentityRegistry/storage/registryDocument.js +235 -0
- package/dist/services/Interception/contracts/IInterceptionService.d.ts +65 -0
- package/dist/services/Interception/contracts/IInterceptionService.js +1 -0
- package/dist/services/Interception/contracts/errors.d.ts +26 -0
- package/dist/services/Interception/contracts/errors.js +35 -0
- package/dist/services/Interception/contracts/index.d.ts +3 -0
- package/dist/services/Interception/contracts/index.js +3 -0
- package/dist/services/Interception/contracts/tokens.d.ts +2 -0
- package/dist/services/Interception/contracts/tokens.js +2 -0
- package/dist/services/Interception/descriptor/InterceptionDescriptor.d.ts +9 -0
- package/dist/services/Interception/descriptor/InterceptionDescriptor.js +49 -0
- package/dist/services/Interception/descriptor/tokens.d.ts +1 -0
- package/dist/services/Interception/descriptor/tokens.js +1 -0
- package/dist/services/Interception/index.d.ts +4 -0
- package/dist/services/Interception/index.js +4 -0
- package/dist/services/Interception/orchestrator/InterceptionService.d.ts +32 -0
- package/dist/services/Interception/orchestrator/InterceptionService.js +180 -0
- package/dist/services/Interception/orchestrator/index.d.ts +1 -0
- package/dist/services/Interception/orchestrator/index.js +1 -0
- package/dist/services/Interception/serviceModule.d.ts +2 -0
- package/dist/services/Interception/serviceModule.js +5 -0
- package/dist/services/Parser/contracts/IParserService.d.ts +21 -0
- package/dist/services/Parser/contracts/IParserService.js +1 -0
- package/dist/services/Parser/contracts/errors.d.ts +25 -0
- package/dist/services/Parser/contracts/errors.js +33 -0
- package/dist/services/Parser/contracts/index.d.ts +4 -0
- package/dist/services/Parser/contracts/index.js +1 -0
- package/dist/services/Parser/contracts/types.d.ts +42 -0
- package/dist/services/Parser/contracts/types.js +1 -0
- package/dist/services/Parser/descriptor/ParserDescriptor.d.ts +23 -0
- package/dist/services/Parser/descriptor/ParserDescriptor.js +50 -0
- package/dist/services/Parser/descriptor/tokens.d.ts +8 -0
- package/dist/services/Parser/descriptor/tokens.js +8 -0
- package/dist/services/Parser/index.d.ts +8 -0
- package/dist/services/Parser/index.js +8 -0
- package/dist/services/Parser/orchestrator/ParserService.d.ts +20 -0
- package/dist/services/Parser/orchestrator/ParserService.js +105 -0
- package/dist/services/Parser/orchestrator/index.d.ts +1 -0
- package/dist/services/Parser/orchestrator/index.js +1 -0
- package/dist/services/Parser/parser/indexSynthesis.d.ts +11 -0
- package/dist/services/Parser/parser/indexSynthesis.js +13 -0
- package/dist/services/Parser/parser/parameters.d.ts +14 -0
- package/dist/services/Parser/parser/parameters.js +89 -0
- package/dist/services/Parser/parser/scanner.d.ts +48 -0
- package/dist/services/Parser/parser/scanner.js +156 -0
- package/dist/services/Parser/parser/syntax.d.ts +30 -0
- package/dist/services/Parser/parser/syntax.js +34 -0
- package/dist/services/Parser/serviceModule.d.ts +2 -0
- package/dist/services/Parser/serviceModule.js +5 -0
- package/dist/services/Router/bootOptions.d.ts +2 -0
- package/dist/services/Router/bootOptions.js +2 -0
- package/dist/services/Router/contracts/IRouterService.d.ts +43 -0
- package/dist/services/Router/contracts/IRouterService.js +1 -0
- package/dist/services/Router/contracts/caller.d.ts +6 -0
- package/dist/services/Router/contracts/caller.js +6 -0
- package/dist/services/Router/contracts/errors.d.ts +56 -0
- package/dist/services/Router/contracts/errors.js +75 -0
- package/dist/services/Router/contracts/index.d.ts +8 -0
- package/dist/services/Router/contracts/index.js +4 -0
- package/dist/services/Router/contracts/kind.d.ts +7 -0
- package/dist/services/Router/contracts/kind.js +10 -0
- package/dist/services/Router/contracts/registrant.d.ts +23 -0
- package/dist/services/Router/contracts/registrant.js +13 -0
- package/dist/services/Router/contracts/types.d.ts +90 -0
- package/dist/services/Router/contracts/types.js +1 -0
- package/dist/services/Router/descriptor/RouterDescriptor.d.ts +32 -0
- package/dist/services/Router/descriptor/RouterDescriptor.js +92 -0
- package/dist/services/Router/descriptor/tokens.d.ts +9 -0
- package/dist/services/Router/descriptor/tokens.js +9 -0
- package/dist/services/Router/index.d.ts +4 -0
- package/dist/services/Router/index.js +4 -0
- package/dist/services/Router/orchestrator/RouterService.d.ts +74 -0
- package/dist/services/Router/orchestrator/RouterService.js +332 -0
- package/dist/services/Router/orchestrator/index.d.ts +2 -0
- package/dist/services/Router/orchestrator/index.js +1 -0
- package/dist/services/Router/serviceModule.d.ts +4 -0
- package/dist/services/Router/serviceModule.js +22 -0
- package/dist/services/WasmCage/index.d.ts +7 -0
- package/dist/services/WasmCage/index.js +4 -0
- package/dist/services/WasmCage/scripts/prepin.d.ts +1 -0
- package/dist/services/WasmCage/scripts/prepin.js +38 -0
- package/dist/services/WasmCage/serviceModule.d.ts +12 -0
- package/dist/services/WasmCage/serviceModule.js +18 -0
- package/dist/services/WasmCage/src/caged.d.ts +104 -0
- package/dist/services/WasmCage/src/caged.js +381 -0
- package/dist/services/WasmCage/src/descriptor.d.ts +47 -0
- package/dist/services/WasmCage/src/descriptor.js +56 -0
- package/dist/services/WasmCage/src/native.d.ts +29 -0
- package/dist/services/WasmCage/src/native.js +66 -0
- package/dist/services/WasmCage/src/nativeDigests.d.ts +9 -0
- package/dist/services/WasmCage/src/nativeDigests.js +15 -0
- package/dist/services/WasmCage/src/package.d.ts +36 -0
- package/dist/services/WasmCage/src/package.js +122 -0
- package/dist/services/shared/canonicalJson.d.ts +29 -0
- package/dist/services/shared/canonicalJson.js +93 -0
- package/dist/services/shared/documentStore.d.ts +16 -0
- package/dist/services/shared/documentStore.js +98 -0
- package/dist/src/bootstrap/bootKernelInternal.d.ts +18 -0
- package/dist/src/bootstrap/bootKernelInternal.js +420 -0
- package/dist/src/bootstrap/bootTypes.d.ts +89 -0
- package/dist/src/bootstrap/bootTypes.js +1 -0
- package/dist/src/bootstrap/config/index.d.ts +3 -0
- package/dist/src/bootstrap/config/index.js +2 -0
- package/dist/src/bootstrap/config/integrity.d.ts +34 -0
- package/dist/src/bootstrap/config/integrity.js +79 -0
- package/dist/src/bootstrap/config/parse.d.ts +15 -0
- package/dist/src/bootstrap/config/parse.js +81 -0
- package/dist/src/bootstrap/config/pathWriteGuard.d.ts +20 -0
- package/dist/src/bootstrap/config/pathWriteGuard.js +349 -0
- package/dist/src/bootstrap/config/types.d.ts +41 -0
- package/dist/src/bootstrap/config/types.js +15 -0
- package/dist/src/bootstrap/hardcore.d.ts +212 -0
- package/dist/src/bootstrap/hardcore.js +312 -0
- package/dist/src/bootstrap/hardcoreServices.d.ts +10 -0
- package/dist/src/bootstrap/hardcoreServices.js +258 -0
- package/dist/src/bootstrap/index.d.ts +8 -0
- package/dist/src/bootstrap/index.js +5 -0
- package/dist/src/bootstrap/packageRequirements.d.ts +26 -0
- package/dist/src/bootstrap/packageRequirements.js +52 -0
- package/dist/src/contracts/accessBroker.d.ts +53 -0
- package/dist/src/contracts/accessBroker.js +1 -0
- package/dist/src/contracts/brudOperation.d.ts +20 -0
- package/dist/src/contracts/brudOperation.js +20 -0
- package/dist/src/contracts/callChain.d.ts +161 -0
- package/dist/src/contracts/callChain.js +19 -0
- package/dist/src/contracts/capability.d.ts +26 -0
- package/dist/src/contracts/capability.js +26 -0
- package/dist/src/contracts/container.d.ts +17 -0
- package/dist/src/contracts/container.js +8 -0
- package/dist/src/contracts/context.d.ts +19 -0
- package/dist/src/contracts/context.js +1 -0
- package/dist/src/contracts/contextContract.d.ts +129 -0
- package/dist/src/contracts/contextContract.js +285 -0
- package/dist/src/contracts/dispatchView.d.ts +21 -0
- package/dist/src/contracts/dispatchView.js +1 -0
- package/dist/src/contracts/handler.d.ts +28 -0
- package/dist/src/contracts/handler.js +1 -0
- package/dist/src/contracts/index.d.ts +25 -0
- package/dist/src/contracts/index.js +8 -0
- package/dist/src/contracts/kernel.d.ts +60 -0
- package/dist/src/contracts/kernel.js +1 -0
- package/dist/src/contracts/lifecycle.d.ts +59 -0
- package/dist/src/contracts/lifecycle.js +1 -0
- package/dist/src/contracts/manifest.d.ts +145 -0
- package/dist/src/contracts/manifest.js +295 -0
- package/dist/src/contracts/pipeline.d.ts +8 -0
- package/dist/src/contracts/pipeline.js +1 -0
- package/dist/src/contracts/policy.d.ts +75 -0
- package/dist/src/contracts/policy.js +77 -0
- package/dist/src/contracts/registry.d.ts +7 -0
- package/dist/src/contracts/registry.js +1 -0
- package/dist/src/contracts/serviceDescriptor.d.ts +67 -0
- package/dist/src/contracts/serviceDescriptor.js +1 -0
- package/dist/src/contracts/serviceToken.d.ts +36 -0
- package/dist/src/contracts/serviceToken.js +16 -0
- package/dist/src/engine/BrudKernel.d.ts +118 -0
- package/dist/src/engine/BrudKernel.js +366 -0
- package/dist/src/engine/ExecutionPipeline.d.ts +13 -0
- package/dist/src/engine/ExecutionPipeline.js +62 -0
- package/dist/src/engine/KernelAccessBroker.d.ts +47 -0
- package/dist/src/engine/KernelAccessBroker.js +107 -0
- package/dist/src/engine/KernelRegistry.d.ts +14 -0
- package/dist/src/engine/KernelRegistry.js +33 -0
- package/dist/src/engine/OperationRegistry.d.ts +9 -0
- package/dist/src/engine/OperationRegistry.js +18 -0
- package/dist/src/engine/ServiceContainer.d.ts +13 -0
- package/dist/src/engine/ServiceContainer.js +53 -0
- package/dist/src/engine/callChain.d.ts +68 -0
- package/dist/src/engine/callChain.js +180 -0
- package/dist/src/engine/dag.d.ts +2 -0
- package/dist/src/engine/dag.js +34 -0
- package/dist/src/engine/errors.d.ts +26 -0
- package/dist/src/engine/errors.js +52 -0
- package/dist/src/engine/index.d.ts +11 -0
- package/dist/src/engine/index.js +8 -0
- package/dist/src/engine/state.d.ts +1 -0
- package/dist/src/engine/state.js +1 -0
- package/dist/src/validation/jsonSchema/compile.d.ts +8 -0
- package/dist/src/validation/jsonSchema/compile.js +386 -0
- package/dist/src/validation/jsonSchema/index.d.ts +3 -0
- package/dist/src/validation/jsonSchema/index.js +2 -0
- package/dist/src/validation/jsonSchema/jsonValue.d.ts +29 -0
- package/dist/src/validation/jsonSchema/jsonValue.js +190 -0
- package/dist/src/validation/jsonSchema/pattern.d.ts +28 -0
- package/dist/src/validation/jsonSchema/pattern.js +155 -0
- package/dist/src/validation/jsonSchema/types.d.ts +71 -0
- package/dist/src/validation/jsonSchema/types.js +15 -0
- package/package.json +59 -4
- package/services/WasmCage/native/brud-wasm-cage.darwin-arm64.node +0 -0
- package/services/WasmCage/native/brud-wasm-cage.darwin-x64.node +0 -0
- package/services/WasmCage/native/brud-wasm-cage.linux-arm64-gnu.node +0 -0
- package/services/WasmCage/native/brud-wasm-cage.linux-x64-gnu.node +0 -0
- package/services/WasmCage/native/brud-wasm-cage.win32-x64-msvc.node +0 -0
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
export class LifecycleStateError extends Error {
|
|
2
|
+
code = 'INVALID_LIFECYCLE_STATE';
|
|
3
|
+
operation;
|
|
4
|
+
currentState;
|
|
5
|
+
expectedState;
|
|
6
|
+
constructor(operation, currentState, expectedState) {
|
|
7
|
+
super(LifecycleStateError.formatMessage(operation, currentState, expectedState));
|
|
8
|
+
this.name = 'LifecycleStateError';
|
|
9
|
+
this.operation = operation;
|
|
10
|
+
this.currentState = currentState;
|
|
11
|
+
this.expectedState = expectedState;
|
|
12
|
+
}
|
|
13
|
+
static formatMessage(operation, currentState, expectedState) {
|
|
14
|
+
if (currentState === undefined) {
|
|
15
|
+
return `Operation "${operation}" is not permitted in the current kernel lifecycle state`;
|
|
16
|
+
}
|
|
17
|
+
if (expectedState === undefined) {
|
|
18
|
+
return `Operation "${operation}" is not permitted while the kernel is ${currentState}`;
|
|
19
|
+
}
|
|
20
|
+
return `Operation "${operation}" requires kernel state ${expectedState} but the kernel is ${currentState}`;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
export class CircularDependencyError extends Error {
|
|
24
|
+
code = 'CIRCULAR_DEPENDENCY';
|
|
25
|
+
cyclePath;
|
|
26
|
+
constructor(cyclePath) {
|
|
27
|
+
super(`Circular dependency detected: ${cyclePath.join(' -> ')}`);
|
|
28
|
+
this.name = 'CircularDependencyError';
|
|
29
|
+
this.cyclePath = [...cyclePath];
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
export class MissingDependencyError extends Error {
|
|
33
|
+
code = 'MISSING_DEPENDENCY';
|
|
34
|
+
missingTokenId;
|
|
35
|
+
dependentTokenId;
|
|
36
|
+
constructor(missingTokenId, dependentTokenId) {
|
|
37
|
+
super(`Service "${dependentTokenId}" depends on unregistered service "${missingTokenId}"`);
|
|
38
|
+
this.name = 'MissingDependencyError';
|
|
39
|
+
this.missingTokenId = missingTokenId;
|
|
40
|
+
this.dependentTokenId = dependentTokenId;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
export class ServiceNotFoundError extends Error {
|
|
44
|
+
code = 'SERVICE_NOT_FOUND';
|
|
45
|
+
tokenId;
|
|
46
|
+
constructor(tokenId) {
|
|
47
|
+
super(`Service "${tokenId}" is not registered`);
|
|
48
|
+
this.name = 'ServiceNotFoundError';
|
|
49
|
+
this.tokenId = tokenId;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
export { AccessDeniedError, BlacklistedAccessViolationError, AllowlistViolationError, } from '../contracts/policy.js';
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export { ServiceContainer } from './ServiceContainer.js';
|
|
2
|
+
export { OperationRegistry } from './OperationRegistry.js';
|
|
3
|
+
export { ExecutionPipeline } from './ExecutionPipeline.js';
|
|
4
|
+
export { BrudKernel } from './BrudKernel.js';
|
|
5
|
+
export type { KernelExecuteOptions, PromptManifest, PromptManifestEntry } from './BrudKernel.js';
|
|
6
|
+
export { KernelRegistry } from './KernelRegistry.js';
|
|
7
|
+
export { KernelAccessBroker } from './KernelAccessBroker.js';
|
|
8
|
+
export type { KernelStateChecker } from './KernelAccessBroker.js';
|
|
9
|
+
export { topologicalSort } from './dag.js';
|
|
10
|
+
export { LifecycleStateError, CircularDependencyError, MissingDependencyError, ServiceNotFoundError, } from './errors.js';
|
|
11
|
+
export type { KernelLifecycleState } from './state.js';
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export { ServiceContainer } from './ServiceContainer.js';
|
|
2
|
+
export { OperationRegistry } from './OperationRegistry.js';
|
|
3
|
+
export { ExecutionPipeline } from './ExecutionPipeline.js';
|
|
4
|
+
export { BrudKernel } from './BrudKernel.js';
|
|
5
|
+
export { KernelRegistry } from './KernelRegistry.js';
|
|
6
|
+
export { KernelAccessBroker } from './KernelAccessBroker.js';
|
|
7
|
+
export { topologicalSort } from './dag.js';
|
|
8
|
+
export { LifecycleStateError, CircularDependencyError, MissingDependencyError, ServiceNotFoundError, } from './errors.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export type KernelLifecycleState = 'UNINITIALIZED' | 'BOOTING' | 'RUNNING' | 'SHUTTING_DOWN' | 'DISPOSED';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { JsonSchemaCompileResult, JsonSchemaLimits } from './types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Compiles an untrusted JSON Schema into a frozen, reusable validator.
|
|
4
|
+
*
|
|
5
|
+
* @param schema - Schema to compile. It is copied; later changes to it have no effect.
|
|
6
|
+
* @param limits - Optional overrides of {@link DEFAULT_JSON_SCHEMA_LIMITS}.
|
|
7
|
+
*/
|
|
8
|
+
export declare function compileJsonSchema(schema: unknown, limits?: Partial<JsonSchemaLimits>): JsonSchemaCompileResult;
|
|
@@ -0,0 +1,386 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* JSON Schema subset compiler and validator.
|
|
3
|
+
*
|
|
4
|
+
* `compileJsonSchema` checks an untrusted schema once, rejecting every keyword
|
|
5
|
+
* outside the supported subset (fail closed), and returns a frozen validator.
|
|
6
|
+
* Neither function throws, and neither mutates its arguments.
|
|
7
|
+
*/
|
|
8
|
+
import { codePointLength, freezeJsonCopy, inspectJsonValue, jsonEqual, jsonTypeOf, pointerJoin, } from './jsonValue.js';
|
|
9
|
+
import { screenPattern } from './pattern.js';
|
|
10
|
+
import { DEFAULT_JSON_SCHEMA_LIMITS } from './types.js';
|
|
11
|
+
const TYPE_NAMES = new Set([
|
|
12
|
+
'null', 'boolean', 'number', 'integer', 'string', 'array', 'object',
|
|
13
|
+
]);
|
|
14
|
+
const CONSTRAINT_KEYWORDS = new Set([
|
|
15
|
+
'type', 'properties', 'required', 'additionalProperties', 'enum', 'const',
|
|
16
|
+
'items', 'minItems', 'maxItems', 'minimum', 'maximum', 'exclusiveMinimum',
|
|
17
|
+
'exclusiveMaximum', 'minLength', 'maxLength', 'pattern', 'oneOf',
|
|
18
|
+
]);
|
|
19
|
+
const ANNOTATION_KEYWORDS = new Set([
|
|
20
|
+
'$schema', '$id', 'title', 'description', '$comment', 'default', 'examples',
|
|
21
|
+
'protected',
|
|
22
|
+
]);
|
|
23
|
+
function isNonNegativeInteger(value) {
|
|
24
|
+
return typeof value === 'number' && Number.isSafeInteger(value) && value >= 0;
|
|
25
|
+
}
|
|
26
|
+
function isFiniteNumber(value) {
|
|
27
|
+
return typeof value === 'number' && Number.isFinite(value);
|
|
28
|
+
}
|
|
29
|
+
function resolveLimits(overrides) {
|
|
30
|
+
const merged = { ...DEFAULT_JSON_SCHEMA_LIMITS };
|
|
31
|
+
for (const [key, value] of Object.entries(overrides ?? {})) {
|
|
32
|
+
if (!(key in DEFAULT_JSON_SCHEMA_LIMITS)) {
|
|
33
|
+
return `unknown limit "${key}"`;
|
|
34
|
+
}
|
|
35
|
+
if (typeof value !== 'number' || !Number.isSafeInteger(value) || value < 1) {
|
|
36
|
+
return `limit "${key}" must be a positive integer`;
|
|
37
|
+
}
|
|
38
|
+
merged[key] = value;
|
|
39
|
+
}
|
|
40
|
+
return Object.freeze(merged);
|
|
41
|
+
}
|
|
42
|
+
class SchemaCompiler {
|
|
43
|
+
limits;
|
|
44
|
+
errors = [];
|
|
45
|
+
nodes = 0;
|
|
46
|
+
constructor(limits) {
|
|
47
|
+
this.limits = limits;
|
|
48
|
+
}
|
|
49
|
+
compile(schema, schemaPath, depth) {
|
|
50
|
+
this.nodes += 1;
|
|
51
|
+
if (this.nodes > this.limits.maxSchemaNodes) {
|
|
52
|
+
this.error('SCHEMA_LIMIT_EXCEEDED', schemaPath, `schema has more than ${this.limits.maxSchemaNodes} nodes`);
|
|
53
|
+
return false;
|
|
54
|
+
}
|
|
55
|
+
if (depth > this.limits.maxSchemaDepth) {
|
|
56
|
+
this.error('SCHEMA_LIMIT_EXCEEDED', schemaPath, `schema is nested deeper than ${this.limits.maxSchemaDepth} levels`);
|
|
57
|
+
return false;
|
|
58
|
+
}
|
|
59
|
+
if (typeof schema === 'boolean') {
|
|
60
|
+
return schema;
|
|
61
|
+
}
|
|
62
|
+
if (schema === null || typeof schema !== 'object' || Array.isArray(schema)) {
|
|
63
|
+
this.error('INVALID_SCHEMA', schemaPath, 'a schema must be an object or a boolean');
|
|
64
|
+
return false;
|
|
65
|
+
}
|
|
66
|
+
const source = schema;
|
|
67
|
+
const node = { schemaPath, hasConst: false };
|
|
68
|
+
for (const key of Object.keys(source)) {
|
|
69
|
+
if (!CONSTRAINT_KEYWORDS.has(key) && !ANNOTATION_KEYWORDS.has(key)) {
|
|
70
|
+
this.error('UNSUPPORTED_KEYWORD', pointerJoin(schemaPath, key), `keyword "${key}" is not supported`);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
const at = (keyword) => pointerJoin(schemaPath, keyword);
|
|
74
|
+
const has = (keyword) => Object.prototype.hasOwnProperty.call(source, keyword);
|
|
75
|
+
if (has('type')) {
|
|
76
|
+
const raw = source.type;
|
|
77
|
+
const list = typeof raw === 'string' ? [raw] : raw;
|
|
78
|
+
if (!Array.isArray(list)
|
|
79
|
+
|| list.length === 0
|
|
80
|
+
|| list.some((name) => typeof name !== 'string' || !TYPE_NAMES.has(name))
|
|
81
|
+
|| new Set(list).size !== list.length) {
|
|
82
|
+
this.error('INVALID_KEYWORD_VALUE', at('type'), 'type must be a type name or a non-empty array of unique type names');
|
|
83
|
+
}
|
|
84
|
+
else {
|
|
85
|
+
node.types = Object.freeze([...list]);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
if (has('properties')) {
|
|
89
|
+
const raw = source.properties;
|
|
90
|
+
if (raw === null || typeof raw !== 'object' || Array.isArray(raw)) {
|
|
91
|
+
this.error('INVALID_KEYWORD_VALUE', at('properties'), 'properties must be an object of schemas');
|
|
92
|
+
}
|
|
93
|
+
else {
|
|
94
|
+
const entries = [];
|
|
95
|
+
for (const [name, child] of Object.entries(raw)) {
|
|
96
|
+
entries.push(Object.freeze([name, this.compile(child, pointerJoin(at('properties'), name), depth + 1)]));
|
|
97
|
+
}
|
|
98
|
+
node.properties = Object.freeze(entries);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
if (has('required')) {
|
|
102
|
+
const raw = source.required;
|
|
103
|
+
if (!Array.isArray(raw) || raw.some((name) => typeof name !== 'string') || new Set(raw).size !== raw.length) {
|
|
104
|
+
this.error('INVALID_KEYWORD_VALUE', at('required'), 'required must be an array of unique strings');
|
|
105
|
+
}
|
|
106
|
+
else {
|
|
107
|
+
node.required = Object.freeze([...raw]);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
if (has('additionalProperties')) {
|
|
111
|
+
node.additionalProperties = this.compile(source.additionalProperties, at('additionalProperties'), depth + 1);
|
|
112
|
+
}
|
|
113
|
+
if (has('enum')) {
|
|
114
|
+
const raw = source.enum;
|
|
115
|
+
if (!Array.isArray(raw) || raw.length === 0) {
|
|
116
|
+
this.error('INVALID_KEYWORD_VALUE', at('enum'), 'enum must be a non-empty array');
|
|
117
|
+
}
|
|
118
|
+
else if (raw.length > this.limits.maxEnumValues) {
|
|
119
|
+
this.error('SCHEMA_LIMIT_EXCEEDED', at('enum'), `enum has more than ${this.limits.maxEnumValues} values`);
|
|
120
|
+
}
|
|
121
|
+
else if (raw.some((value, index) => raw.findIndex((other) => jsonEqual(other, value)) !== index)) {
|
|
122
|
+
this.error('INVALID_KEYWORD_VALUE', at('enum'), 'enum values must be unique');
|
|
123
|
+
}
|
|
124
|
+
else {
|
|
125
|
+
node.enumValues = freezeJsonCopy(raw);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
if (has('const')) {
|
|
129
|
+
node.hasConst = true;
|
|
130
|
+
node.constValue = freezeJsonCopy(source.const);
|
|
131
|
+
}
|
|
132
|
+
if (has('items')) {
|
|
133
|
+
if (Array.isArray(source.items)) {
|
|
134
|
+
this.error('UNSUPPORTED_KEYWORD', at('items'), 'the tuple form of items is not supported');
|
|
135
|
+
}
|
|
136
|
+
else {
|
|
137
|
+
node.items = this.compile(source.items, at('items'), depth + 1);
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
for (const keyword of ['minItems', 'maxItems', 'minLength', 'maxLength']) {
|
|
141
|
+
if (has(keyword)) {
|
|
142
|
+
if (!isNonNegativeInteger(source[keyword])) {
|
|
143
|
+
this.error('INVALID_KEYWORD_VALUE', at(keyword), `${keyword} must be a non-negative integer`);
|
|
144
|
+
}
|
|
145
|
+
else {
|
|
146
|
+
node[keyword] = source[keyword];
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
for (const keyword of ['minimum', 'maximum', 'exclusiveMinimum', 'exclusiveMaximum']) {
|
|
151
|
+
if (has(keyword)) {
|
|
152
|
+
if (!isFiniteNumber(source[keyword])) {
|
|
153
|
+
this.error('INVALID_KEYWORD_VALUE', at(keyword), `${keyword} must be a finite number`);
|
|
154
|
+
}
|
|
155
|
+
else {
|
|
156
|
+
node[keyword] = source[keyword];
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
if (has('pattern')) {
|
|
161
|
+
const raw = source.pattern;
|
|
162
|
+
if (typeof raw !== 'string') {
|
|
163
|
+
this.error('INVALID_KEYWORD_VALUE', at('pattern'), 'pattern must be a string');
|
|
164
|
+
}
|
|
165
|
+
else {
|
|
166
|
+
const screened = screenPattern(raw, this.limits.maxPatternLength);
|
|
167
|
+
if (screened.ok) {
|
|
168
|
+
node.pattern = screened.regex;
|
|
169
|
+
}
|
|
170
|
+
else {
|
|
171
|
+
this.error(screened.code, at('pattern'), screened.reason);
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
if (has('oneOf')) {
|
|
176
|
+
const raw = source.oneOf;
|
|
177
|
+
if (!Array.isArray(raw) || raw.length === 0) {
|
|
178
|
+
this.error('INVALID_KEYWORD_VALUE', at('oneOf'), 'oneOf must be a non-empty array of schemas');
|
|
179
|
+
}
|
|
180
|
+
else {
|
|
181
|
+
node.oneOf = Object.freeze(raw.map((child, index) => this.compile(child, pointerJoin(at('oneOf'), index), depth + 1)));
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
return Object.freeze(node);
|
|
185
|
+
}
|
|
186
|
+
error(code, schemaPath, message) {
|
|
187
|
+
this.errors.push(Object.freeze({ code, schemaPath, message }));
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
/** Collects violations up to the configured cap. */
|
|
191
|
+
class ViolationSink {
|
|
192
|
+
max;
|
|
193
|
+
violations = [];
|
|
194
|
+
full = false;
|
|
195
|
+
constructor(max) {
|
|
196
|
+
this.max = max;
|
|
197
|
+
}
|
|
198
|
+
add(instancePath, schemaPath, keyword, message) {
|
|
199
|
+
if (this.full) {
|
|
200
|
+
return;
|
|
201
|
+
}
|
|
202
|
+
if (this.violations.length === this.max) {
|
|
203
|
+
this.full = true;
|
|
204
|
+
this.violations.push({ instancePath: '', schemaPath: '', keyword: 'limit', message: `more than ${this.max} violations; the rest were omitted` });
|
|
205
|
+
return;
|
|
206
|
+
}
|
|
207
|
+
this.violations.push({ instancePath, schemaPath, keyword, message });
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
function matchesType(value, types) {
|
|
211
|
+
const actual = jsonTypeOf(value);
|
|
212
|
+
return types.some((name) => name === actual || (name === 'number' && actual === 'integer'));
|
|
213
|
+
}
|
|
214
|
+
function validateNode(node, value, instancePath, schemaPath, limits, sink) {
|
|
215
|
+
if (node === true) {
|
|
216
|
+
return;
|
|
217
|
+
}
|
|
218
|
+
if (node === false) {
|
|
219
|
+
sink.add(instancePath, schemaPath, 'type', 'no value is allowed here');
|
|
220
|
+
return;
|
|
221
|
+
}
|
|
222
|
+
const at = (keyword) => pointerJoin(node.schemaPath, keyword);
|
|
223
|
+
if (node.types !== undefined && !matchesType(value, node.types)) {
|
|
224
|
+
sink.add(instancePath, at('type'), 'type', `must be of type ${node.types.join(' or ')}`);
|
|
225
|
+
}
|
|
226
|
+
if (node.enumValues !== undefined && !node.enumValues.some((candidate) => jsonEqual(candidate, value))) {
|
|
227
|
+
sink.add(instancePath, at('enum'), 'enum', 'must be one of the enumerated values');
|
|
228
|
+
}
|
|
229
|
+
if (node.hasConst && !jsonEqual(node.constValue, value)) {
|
|
230
|
+
sink.add(instancePath, at('const'), 'const', 'must equal the constant value');
|
|
231
|
+
}
|
|
232
|
+
if (typeof value === 'number') {
|
|
233
|
+
if (node.minimum !== undefined && value < node.minimum) {
|
|
234
|
+
sink.add(instancePath, at('minimum'), 'minimum', `must be >= ${node.minimum}`);
|
|
235
|
+
}
|
|
236
|
+
if (node.maximum !== undefined && value > node.maximum) {
|
|
237
|
+
sink.add(instancePath, at('maximum'), 'maximum', `must be <= ${node.maximum}`);
|
|
238
|
+
}
|
|
239
|
+
if (node.exclusiveMinimum !== undefined && value <= node.exclusiveMinimum) {
|
|
240
|
+
sink.add(instancePath, at('exclusiveMinimum'), 'exclusiveMinimum', `must be > ${node.exclusiveMinimum}`);
|
|
241
|
+
}
|
|
242
|
+
if (node.exclusiveMaximum !== undefined && value >= node.exclusiveMaximum) {
|
|
243
|
+
sink.add(instancePath, at('exclusiveMaximum'), 'exclusiveMaximum', `must be < ${node.exclusiveMaximum}`);
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
if (typeof value === 'string') {
|
|
247
|
+
const needsLength = node.minLength !== undefined || node.maxLength !== undefined || node.pattern !== undefined;
|
|
248
|
+
const length = needsLength ? codePointLength(value) : 0;
|
|
249
|
+
if (node.minLength !== undefined && length < node.minLength) {
|
|
250
|
+
sink.add(instancePath, at('minLength'), 'minLength', `must have at least ${node.minLength} characters`);
|
|
251
|
+
}
|
|
252
|
+
if (node.maxLength !== undefined && length > node.maxLength) {
|
|
253
|
+
sink.add(instancePath, at('maxLength'), 'maxLength', `must have at most ${node.maxLength} characters`);
|
|
254
|
+
}
|
|
255
|
+
if (node.pattern !== undefined) {
|
|
256
|
+
if (length > limits.maxPatternInputLength) {
|
|
257
|
+
sink.add(instancePath, at('pattern'), 'limit', `strings longer than ${limits.maxPatternInputLength} characters are not matched against pattern`);
|
|
258
|
+
}
|
|
259
|
+
else if (!node.pattern.test(value)) {
|
|
260
|
+
sink.add(instancePath, at('pattern'), 'pattern', 'must match the pattern');
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
if (Array.isArray(value)) {
|
|
265
|
+
if (node.minItems !== undefined && value.length < node.minItems) {
|
|
266
|
+
sink.add(instancePath, at('minItems'), 'minItems', `must have at least ${node.minItems} items`);
|
|
267
|
+
}
|
|
268
|
+
if (node.maxItems !== undefined && value.length > node.maxItems) {
|
|
269
|
+
sink.add(instancePath, at('maxItems'), 'maxItems', `must have at most ${node.maxItems} items`);
|
|
270
|
+
}
|
|
271
|
+
if (node.items !== undefined) {
|
|
272
|
+
for (let index = 0; index < value.length && !sink.full; index += 1) {
|
|
273
|
+
validateNode(node.items, value[index], pointerJoin(instancePath, index), at('items'), limits, sink);
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
else if (value !== null && typeof value === 'object') {
|
|
278
|
+
const record = value;
|
|
279
|
+
const own = (key) => Object.prototype.hasOwnProperty.call(record, key);
|
|
280
|
+
for (const name of node.required ?? []) {
|
|
281
|
+
if (!own(name)) {
|
|
282
|
+
sink.add(instancePath, at('required'), 'required', `must have required property "${name}"`);
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
const declared = new Set();
|
|
286
|
+
for (const [name, child] of node.properties ?? []) {
|
|
287
|
+
declared.add(name);
|
|
288
|
+
if (own(name) && !sink.full) {
|
|
289
|
+
validateNode(child, record[name], pointerJoin(instancePath, name), pointerJoin(at('properties'), name), limits, sink);
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
if (node.additionalProperties !== undefined && node.additionalProperties !== true) {
|
|
293
|
+
const extras = Object.keys(record).filter((key) => !declared.has(key)).sort();
|
|
294
|
+
for (const key of extras) {
|
|
295
|
+
if (sink.full) {
|
|
296
|
+
break;
|
|
297
|
+
}
|
|
298
|
+
if (node.additionalProperties === false) {
|
|
299
|
+
sink.add(pointerJoin(instancePath, key), at('additionalProperties'), 'additionalProperties', 'additional properties are not allowed');
|
|
300
|
+
}
|
|
301
|
+
else {
|
|
302
|
+
validateNode(node.additionalProperties, record[key], pointerJoin(instancePath, key), at('additionalProperties'), limits, sink);
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
if (node.oneOf !== undefined && !sink.full) {
|
|
308
|
+
let matches = 0;
|
|
309
|
+
for (const [index, branch] of node.oneOf.entries()) {
|
|
310
|
+
const probe = new ViolationSink(1);
|
|
311
|
+
validateNode(branch, value, instancePath, pointerJoin(at('oneOf'), index), limits, probe);
|
|
312
|
+
if (probe.violations.length === 0) {
|
|
313
|
+
matches += 1;
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
if (matches !== 1) {
|
|
317
|
+
sink.add(instancePath, at('oneOf'), 'oneOf', `must match exactly one schema in oneOf (matched ${matches} of ${node.oneOf.length})`);
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
/**
|
|
322
|
+
* Compiles an untrusted JSON Schema into a frozen, reusable validator.
|
|
323
|
+
*
|
|
324
|
+
* @param schema - Schema to compile. It is copied; later changes to it have no effect.
|
|
325
|
+
* @param limits - Optional overrides of {@link DEFAULT_JSON_SCHEMA_LIMITS}.
|
|
326
|
+
*/
|
|
327
|
+
export function compileJsonSchema(schema, limits) {
|
|
328
|
+
try {
|
|
329
|
+
const resolved = resolveLimits(limits);
|
|
330
|
+
if (typeof resolved === 'string') {
|
|
331
|
+
return { ok: false, errors: [{ code: 'INVALID_SCHEMA', schemaPath: '', message: resolved }] };
|
|
332
|
+
}
|
|
333
|
+
const shape = inspectJsonValue(schema, {
|
|
334
|
+
maxDepth: resolved.maxSchemaDepth * 4,
|
|
335
|
+
maxNodes: resolved.maxSchemaNodes * 64,
|
|
336
|
+
});
|
|
337
|
+
if (shape !== null) {
|
|
338
|
+
return {
|
|
339
|
+
ok: false,
|
|
340
|
+
errors: [{
|
|
341
|
+
code: shape.keyword === 'limit' ? 'SCHEMA_LIMIT_EXCEEDED' : 'INVALID_SCHEMA',
|
|
342
|
+
schemaPath: shape.instancePath,
|
|
343
|
+
message: `schema is not plain JSON: ${shape.message}`,
|
|
344
|
+
}],
|
|
345
|
+
};
|
|
346
|
+
}
|
|
347
|
+
const compiler = new SchemaCompiler(resolved);
|
|
348
|
+
const root = compiler.compile(schema, '', 0);
|
|
349
|
+
if (compiler.errors.length > 0) {
|
|
350
|
+
return { ok: false, errors: Object.freeze([...compiler.errors]) };
|
|
351
|
+
}
|
|
352
|
+
const compiled = Object.freeze({
|
|
353
|
+
validate(value) {
|
|
354
|
+
try {
|
|
355
|
+
const shapeProblem = inspectJsonValue(value, {
|
|
356
|
+
maxDepth: resolved.maxValueDepth,
|
|
357
|
+
maxNodes: resolved.maxValueNodes,
|
|
358
|
+
});
|
|
359
|
+
if (shapeProblem !== null) {
|
|
360
|
+
return { valid: false, violations: Object.freeze([Object.freeze(shapeProblem)]) };
|
|
361
|
+
}
|
|
362
|
+
const sink = new ViolationSink(resolved.maxViolations);
|
|
363
|
+
validateNode(root, value, '', '', resolved, sink);
|
|
364
|
+
return sink.violations.length === 0
|
|
365
|
+
? { valid: true }
|
|
366
|
+
: { valid: false, violations: Object.freeze(sink.violations.map((violation) => Object.freeze(violation))) };
|
|
367
|
+
}
|
|
368
|
+
catch {
|
|
369
|
+
return {
|
|
370
|
+
valid: false,
|
|
371
|
+
violations: Object.freeze([Object.freeze({
|
|
372
|
+
instancePath: '',
|
|
373
|
+
schemaPath: '',
|
|
374
|
+
keyword: 'limit',
|
|
375
|
+
message: 'internal validation error',
|
|
376
|
+
})]),
|
|
377
|
+
};
|
|
378
|
+
}
|
|
379
|
+
},
|
|
380
|
+
});
|
|
381
|
+
return { ok: true, schema: compiled };
|
|
382
|
+
}
|
|
383
|
+
catch {
|
|
384
|
+
return { ok: false, errors: [{ code: 'INVALID_SCHEMA', schemaPath: '', message: 'schema could not be compiled' }] };
|
|
385
|
+
}
|
|
386
|
+
}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export { compileJsonSchema } from './compile.js';
|
|
2
|
+
export { DEFAULT_JSON_SCHEMA_LIMITS } from './types.js';
|
|
3
|
+
export type { CompiledJsonSchema, JsonSchemaCompileResult, JsonSchemaDefinitionError, JsonSchemaDefinitionErrorCode, JsonSchemaKeyword, JsonSchemaLimits, JsonSchemaTypeName, JsonSchemaValidationResult, JsonSchemaViolation, } from './types.js';
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Plain-JSON value helpers: shape inspection, deep equality, cloning, and
|
|
3
|
+
* JSON Pointer encoding. Pure ECMAScript.
|
|
4
|
+
*/
|
|
5
|
+
import type { JsonSchemaTypeName, JsonSchemaViolation } from './types.js';
|
|
6
|
+
/** Encodes one JSON Pointer reference token (RFC 6901). */
|
|
7
|
+
export declare function pointerToken(token: string | number): string;
|
|
8
|
+
/** Appends a token to a JSON Pointer. */
|
|
9
|
+
export declare function pointerJoin(base: string, token: string | number): string;
|
|
10
|
+
/** Length in Unicode code points, as JSON Schema counts string length. */
|
|
11
|
+
export declare function codePointLength(value: string): number;
|
|
12
|
+
/** JSON type of a value already known to be plain JSON. */
|
|
13
|
+
export declare function jsonTypeOf(value: unknown): Exclude<JsonSchemaTypeName, 'number'> | 'number';
|
|
14
|
+
export interface JsonInspectionLimits {
|
|
15
|
+
readonly maxDepth: number;
|
|
16
|
+
readonly maxNodes: number;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Checks that a value is plain JSON: it would survive `JSON.stringify` then
|
|
20
|
+
* `JSON.parse` unchanged. Never invokes user code (accessors are rejected
|
|
21
|
+
* without being read). Stops at the first problem.
|
|
22
|
+
*
|
|
23
|
+
* @returns `null` when the value is plain JSON, otherwise one violation.
|
|
24
|
+
*/
|
|
25
|
+
export declare function inspectJsonValue(value: unknown, limits: JsonInspectionLimits): JsonSchemaViolation | null;
|
|
26
|
+
/** Deep equality for plain JSON values (key order ignored, `-0` equals `0`). */
|
|
27
|
+
export declare function jsonEqual(left: unknown, right: unknown): boolean;
|
|
28
|
+
/** Deep-frozen copy of a plain JSON value. */
|
|
29
|
+
export declare function freezeJsonCopy<T>(value: T): T;
|