@brud/kernel 0.0.0-stage → 0.0.2
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 +56 -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 +133 -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 +68 -0
- package/dist/services/ExposedApiRegistry/orchestrator/ExposedApiRegistryService.js +452 -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 +155 -0
- package/dist/services/Interception/contracts/IInterceptionService.js +12 -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 +50 -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 +40 -0
- package/dist/services/Interception/orchestrator/InterceptionService.js +343 -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 +67 -0
- package/dist/services/Router/contracts/errors.js +90 -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 +110 -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 +93 -0
- package/dist/services/Router/orchestrator/RouterService.js +457 -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 +121 -0
- package/dist/services/WasmCage/src/caged.js +460 -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 +19 -0
- package/dist/src/bootstrap/bootKernelInternal.js +633 -0
- package/dist/src/bootstrap/bootTypes.d.ts +113 -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 +45 -0
- package/dist/src/bootstrap/config/integrity.js +92 -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 +13 -0
- package/dist/src/bootstrap/index.js +7 -0
- package/dist/src/bootstrap/loaded.d.ts +30 -0
- package/dist/src/bootstrap/loaded.js +45 -0
- package/dist/src/bootstrap/packageRequirements.d.ts +26 -0
- package/dist/src/bootstrap/packageRequirements.js +52 -0
- package/dist/src/bootstrap/reload.d.ts +44 -0
- package/dist/src/bootstrap/reload.js +45 -0
- package/dist/src/bootstrap/seal.d.ts +32 -0
- package/dist/src/bootstrap/seal.js +101 -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/capabilitySet.d.ts +23 -0
- package/dist/src/contracts/capabilitySet.js +72 -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 +132 -0
- package/dist/src/contracts/contextContract.js +274 -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 +21 -0
- package/dist/src/contracts/handler.js +1 -0
- package/dist/src/contracts/index.d.ts +26 -0
- package/dist/src/contracts/index.js +9 -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 +180 -0
- package/dist/src/contracts/manifest.js +334 -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 +120 -0
- package/dist/src/engine/BrudKernel.js +395 -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 +175 -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,155 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `pattern` safety screen (decision U1-D2).
|
|
3
|
+
*
|
|
4
|
+
* ECMAScript `RegExp` has no time limit, so a hostile pattern can hang the
|
|
5
|
+
* kernel thread. Patterns are screened at compile time for the shapes behind
|
|
6
|
+
* catastrophic backtracking, then compiled once with the `u` flag. Combined
|
|
7
|
+
* with the input-length cap applied at validation time, this bounds the risk.
|
|
8
|
+
* It is a conservative heuristic, not a proof: some safe patterns (for example
|
|
9
|
+
* `(ab|cd)*`) are rejected too.
|
|
10
|
+
*/
|
|
11
|
+
/**
|
|
12
|
+
* Reads a quantifier starting at `index`.
|
|
13
|
+
*
|
|
14
|
+
* @returns The quantifier length and whether it can repeat its atom more than
|
|
15
|
+
* once, or `null` when no quantifier starts here.
|
|
16
|
+
*/
|
|
17
|
+
function readQuantifier(source, index) {
|
|
18
|
+
const char = source[index];
|
|
19
|
+
if (char === '*' || char === '+') {
|
|
20
|
+
return { length: source[index + 1] === '?' ? 2 : 1, repeats: true };
|
|
21
|
+
}
|
|
22
|
+
if (char === '?') {
|
|
23
|
+
return { length: source[index + 1] === '?' ? 2 : 1, repeats: false };
|
|
24
|
+
}
|
|
25
|
+
if (char === '{') {
|
|
26
|
+
const match = /^\{(\d+)(,(\d*))?\}/u.exec(source.slice(index));
|
|
27
|
+
if (match === null) {
|
|
28
|
+
return null;
|
|
29
|
+
}
|
|
30
|
+
const min = Number(match[1]);
|
|
31
|
+
const hasComma = match[2] !== undefined;
|
|
32
|
+
const max = hasComma ? (match[3] === '' ? Number.POSITIVE_INFINITY : Number(match[3])) : min;
|
|
33
|
+
const length = match[0].length + (source[index + match[0].length] === '?' ? 1 : 0);
|
|
34
|
+
return { length, repeats: max > 1 };
|
|
35
|
+
}
|
|
36
|
+
return null;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Screens and compiles a JSON Schema `pattern`.
|
|
40
|
+
*
|
|
41
|
+
* Rejected as `UNSAFE_PATTERN`:
|
|
42
|
+
* - backreferences (`\1`…`\9`, `\k<name>`);
|
|
43
|
+
* - lookbehind (`(?<=`, `(?<!`);
|
|
44
|
+
* - a repeating quantifier applied to a group whose body contains a repeating
|
|
45
|
+
* quantifier (`(a+)+`, `(.*)*`) or an alternation (`(a|aa)*`).
|
|
46
|
+
*/
|
|
47
|
+
export function screenPattern(source, maxLength) {
|
|
48
|
+
if (source.length > maxLength) {
|
|
49
|
+
return { ok: false, code: 'UNSAFE_PATTERN', reason: `pattern is longer than ${maxLength} characters` };
|
|
50
|
+
}
|
|
51
|
+
const stack = [{ hasRepeat: false, hasAlternation: false }];
|
|
52
|
+
let index = 0;
|
|
53
|
+
const top = () => stack[stack.length - 1];
|
|
54
|
+
while (index < source.length) {
|
|
55
|
+
const char = source[index];
|
|
56
|
+
if (char === '\\') {
|
|
57
|
+
const next = source[index + 1];
|
|
58
|
+
if (next !== undefined && /[1-9]/u.test(next)) {
|
|
59
|
+
return { ok: false, code: 'UNSAFE_PATTERN', reason: 'backreferences are not allowed' };
|
|
60
|
+
}
|
|
61
|
+
if (next === 'k' && source[index + 2] === '<') {
|
|
62
|
+
return { ok: false, code: 'UNSAFE_PATTERN', reason: 'named backreferences are not allowed' };
|
|
63
|
+
}
|
|
64
|
+
index += 2;
|
|
65
|
+
const quantifier = readQuantifier(source, index);
|
|
66
|
+
if (quantifier !== null) {
|
|
67
|
+
if (quantifier.repeats) {
|
|
68
|
+
top().hasRepeat = true;
|
|
69
|
+
}
|
|
70
|
+
index += quantifier.length;
|
|
71
|
+
}
|
|
72
|
+
continue;
|
|
73
|
+
}
|
|
74
|
+
if (char === '[') {
|
|
75
|
+
index += 1;
|
|
76
|
+
if (source[index] === '^') {
|
|
77
|
+
index += 1;
|
|
78
|
+
}
|
|
79
|
+
if (source[index] === ']') {
|
|
80
|
+
index += 1;
|
|
81
|
+
}
|
|
82
|
+
while (index < source.length && source[index] !== ']') {
|
|
83
|
+
index += source[index] === '\\' ? 2 : 1;
|
|
84
|
+
}
|
|
85
|
+
index += 1;
|
|
86
|
+
const quantifier = readQuantifier(source, index);
|
|
87
|
+
if (quantifier !== null) {
|
|
88
|
+
if (quantifier.repeats) {
|
|
89
|
+
top().hasRepeat = true;
|
|
90
|
+
}
|
|
91
|
+
index += quantifier.length;
|
|
92
|
+
}
|
|
93
|
+
continue;
|
|
94
|
+
}
|
|
95
|
+
if (char === '(') {
|
|
96
|
+
if (source.startsWith('(?<=', index) || source.startsWith('(?<!', index)) {
|
|
97
|
+
return { ok: false, code: 'UNSAFE_PATTERN', reason: 'lookbehind is not allowed' };
|
|
98
|
+
}
|
|
99
|
+
stack.push({ hasRepeat: false, hasAlternation: false });
|
|
100
|
+
index += 1;
|
|
101
|
+
continue;
|
|
102
|
+
}
|
|
103
|
+
if (char === ')') {
|
|
104
|
+
if (stack.length === 1) {
|
|
105
|
+
return { ok: false, code: 'INVALID_KEYWORD_VALUE', reason: 'unbalanced parenthesis' };
|
|
106
|
+
}
|
|
107
|
+
const frame = stack.pop();
|
|
108
|
+
index += 1;
|
|
109
|
+
const quantifier = readQuantifier(source, index);
|
|
110
|
+
if (quantifier !== null) {
|
|
111
|
+
if (quantifier.repeats && (frame.hasRepeat || frame.hasAlternation)) {
|
|
112
|
+
return {
|
|
113
|
+
ok: false,
|
|
114
|
+
code: 'UNSAFE_PATTERN',
|
|
115
|
+
reason: 'a repeated group may not contain a repeating quantifier or an alternation',
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
if (quantifier.repeats) {
|
|
119
|
+
top().hasRepeat = true;
|
|
120
|
+
}
|
|
121
|
+
index += quantifier.length;
|
|
122
|
+
}
|
|
123
|
+
if (frame.hasRepeat) {
|
|
124
|
+
top().hasRepeat = true;
|
|
125
|
+
}
|
|
126
|
+
if (frame.hasAlternation) {
|
|
127
|
+
top().hasAlternation = true;
|
|
128
|
+
}
|
|
129
|
+
continue;
|
|
130
|
+
}
|
|
131
|
+
if (char === '|') {
|
|
132
|
+
top().hasAlternation = true;
|
|
133
|
+
index += 1;
|
|
134
|
+
continue;
|
|
135
|
+
}
|
|
136
|
+
index += 1;
|
|
137
|
+
const quantifier = readQuantifier(source, index);
|
|
138
|
+
if (quantifier !== null) {
|
|
139
|
+
if (quantifier.repeats) {
|
|
140
|
+
top().hasRepeat = true;
|
|
141
|
+
}
|
|
142
|
+
index += quantifier.length;
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
try {
|
|
146
|
+
return { ok: true, regex: new RegExp(source, 'u') };
|
|
147
|
+
}
|
|
148
|
+
catch (error) {
|
|
149
|
+
return {
|
|
150
|
+
ok: false,
|
|
151
|
+
code: 'INVALID_KEYWORD_VALUE',
|
|
152
|
+
reason: `pattern is not a valid regular expression: ${error instanceof Error ? error.message : String(error)}`,
|
|
153
|
+
};
|
|
154
|
+
}
|
|
155
|
+
}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Zero-dependency JSON Schema subset validator: public types and limits.
|
|
3
|
+
*
|
|
4
|
+
* The module is pure ECMAScript: no `node:*` imports, no packages.
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Constraint keywords the validator enforces. Anything else is rejected.
|
|
8
|
+
*
|
|
9
|
+
* `protected` is an accepted annotation keyword: it never constrains a value,
|
|
10
|
+
* it only marks a parameter the Brud Protocol v2 parser treats as protected.
|
|
11
|
+
*/
|
|
12
|
+
export type JsonSchemaKeyword = 'type' | 'properties' | 'required' | 'additionalProperties' | 'enum' | 'const' | 'items' | 'minItems' | 'maxItems' | 'minimum' | 'maximum' | 'exclusiveMinimum' | 'exclusiveMaximum' | 'minLength' | 'maxLength' | 'pattern' | 'oneOf';
|
|
13
|
+
/** Primitive type names accepted by the `type` keyword. */
|
|
14
|
+
export type JsonSchemaTypeName = 'null' | 'boolean' | 'number' | 'integer' | 'string' | 'array' | 'object';
|
|
15
|
+
/** Why a schema could not be compiled. */
|
|
16
|
+
export type JsonSchemaDefinitionErrorCode = 'UNSUPPORTED_KEYWORD' | 'INVALID_KEYWORD_VALUE' | 'INVALID_SCHEMA' | 'UNSAFE_PATTERN' | 'SCHEMA_LIMIT_EXCEEDED';
|
|
17
|
+
/** A problem with the schema itself, found at compile time. */
|
|
18
|
+
export interface JsonSchemaDefinitionError {
|
|
19
|
+
readonly code: JsonSchemaDefinitionErrorCode;
|
|
20
|
+
/** JSON Pointer into the schema, e.g. `/properties/path/pattern`; `` for the root. */
|
|
21
|
+
readonly schemaPath: string;
|
|
22
|
+
readonly message: string;
|
|
23
|
+
}
|
|
24
|
+
/** A way in which a value does not satisfy a compiled schema. */
|
|
25
|
+
export interface JsonSchemaViolation {
|
|
26
|
+
/** JSON Pointer into the value; `` for the root. */
|
|
27
|
+
readonly instancePath: string;
|
|
28
|
+
/** JSON Pointer to the schema keyword that failed. */
|
|
29
|
+
readonly schemaPath: string;
|
|
30
|
+
/** `json`: the value is not plain JSON. `limit`: a safety limit was reached. */
|
|
31
|
+
readonly keyword: JsonSchemaKeyword | 'json' | 'limit';
|
|
32
|
+
/** Human-readable reason. Never contains the value itself. */
|
|
33
|
+
readonly message: string;
|
|
34
|
+
}
|
|
35
|
+
export type JsonSchemaValidationResult = {
|
|
36
|
+
readonly valid: true;
|
|
37
|
+
} | {
|
|
38
|
+
readonly valid: false;
|
|
39
|
+
readonly violations: readonly JsonSchemaViolation[];
|
|
40
|
+
};
|
|
41
|
+
/** A frozen, reusable validator produced by {@link compileJsonSchema}. */
|
|
42
|
+
export interface CompiledJsonSchema {
|
|
43
|
+
validate(value: unknown): JsonSchemaValidationResult;
|
|
44
|
+
}
|
|
45
|
+
export type JsonSchemaCompileResult = {
|
|
46
|
+
readonly ok: true;
|
|
47
|
+
readonly schema: CompiledJsonSchema;
|
|
48
|
+
} | {
|
|
49
|
+
readonly ok: false;
|
|
50
|
+
readonly errors: readonly JsonSchemaDefinitionError[];
|
|
51
|
+
};
|
|
52
|
+
/** Safety limits. Every field is a positive integer. */
|
|
53
|
+
export interface JsonSchemaLimits {
|
|
54
|
+
/** Maximum nesting of sub-schemas. */
|
|
55
|
+
readonly maxSchemaDepth: number;
|
|
56
|
+
/** Maximum number of schema nodes (objects and booleans). */
|
|
57
|
+
readonly maxSchemaNodes: number;
|
|
58
|
+
/** Maximum number of `enum` values. */
|
|
59
|
+
readonly maxEnumValues: number;
|
|
60
|
+
/** Maximum `pattern` source length in UTF-16 code units. */
|
|
61
|
+
readonly maxPatternLength: number;
|
|
62
|
+
/** Maximum nesting of the validated value. */
|
|
63
|
+
readonly maxValueDepth: number;
|
|
64
|
+
/** Maximum number of nodes in the validated value. */
|
|
65
|
+
readonly maxValueNodes: number;
|
|
66
|
+
/** Longest string, in Unicode code points, that `pattern` is run against. */
|
|
67
|
+
readonly maxPatternInputLength: number;
|
|
68
|
+
/** Maximum violations reported before truncation. */
|
|
69
|
+
readonly maxViolations: number;
|
|
70
|
+
}
|
|
71
|
+
export declare const DEFAULT_JSON_SCHEMA_LIMITS: JsonSchemaLimits;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Zero-dependency JSON Schema subset validator: public types and limits.
|
|
3
|
+
*
|
|
4
|
+
* The module is pure ECMAScript: no `node:*` imports, no packages.
|
|
5
|
+
*/
|
|
6
|
+
export const DEFAULT_JSON_SCHEMA_LIMITS = Object.freeze({
|
|
7
|
+
maxSchemaDepth: 32,
|
|
8
|
+
maxSchemaNodes: 1_000,
|
|
9
|
+
maxEnumValues: 256,
|
|
10
|
+
maxPatternLength: 256,
|
|
11
|
+
maxValueDepth: 64,
|
|
12
|
+
maxValueNodes: 100_000,
|
|
13
|
+
maxPatternInputLength: 10_000,
|
|
14
|
+
maxViolations: 100,
|
|
15
|
+
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,61 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@brud/kernel",
|
|
3
|
-
"version": "0.0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.0.2",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": {
|
|
9
|
+
"types": "./dist/index.d.ts",
|
|
10
|
+
"import": "./dist/index.js",
|
|
11
|
+
"default": "./dist/index.js"
|
|
12
|
+
},
|
|
13
|
+
"./services/*.js": {
|
|
14
|
+
"types": "./dist/services/*.d.ts",
|
|
15
|
+
"import": "./dist/services/*.js",
|
|
16
|
+
"default": "./dist/services/*.js"
|
|
17
|
+
},
|
|
18
|
+
"./package.json": "./package.json"
|
|
19
|
+
},
|
|
20
|
+
"files": [
|
|
21
|
+
"dist",
|
|
22
|
+
"services/WasmCage/native"
|
|
23
|
+
],
|
|
24
|
+
"engines": {
|
|
25
|
+
"node": ">=22"
|
|
26
|
+
},
|
|
27
|
+
"scripts": {
|
|
28
|
+
"build": "node scripts/clean.mjs && tsc",
|
|
29
|
+
"test": "node scripts/run-tests.mjs",
|
|
30
|
+
"clean": "node scripts/clean.mjs",
|
|
31
|
+
"prepack": "npm run build && node scripts/verify-dist.mjs && node --import tsx scripts/repin.ts --check && node scripts/smoke-dist.mjs",
|
|
32
|
+
"repin": "node --import tsx scripts/repin.ts",
|
|
33
|
+
"smoke:dist": "node scripts/smoke-dist.mjs"
|
|
34
|
+
},
|
|
35
|
+
"dependencies": {},
|
|
36
|
+
"devDependencies": {
|
|
37
|
+
"@types/node": "22.x",
|
|
38
|
+
"tsx": "^4.0.0",
|
|
39
|
+
"typescript": "^5.9.3"
|
|
40
|
+
},
|
|
41
|
+
"description": "The BrudOS kernel: identity, giver-controlled exposures, call chains and the seven hardcore services.",
|
|
42
|
+
"license": "Apache-2.0",
|
|
43
|
+
"repository": {
|
|
44
|
+
"type": "git",
|
|
45
|
+
"url": "git+https://github.com/rahatarch/brud.git",
|
|
46
|
+
"directory": "packages/kernel"
|
|
47
|
+
},
|
|
48
|
+
"homepage": "https://github.com/rahatarch/brud/tree/main/docs-next",
|
|
49
|
+
"bugs": {
|
|
50
|
+
"url": "https://github.com/rahatarch/brud/issues"
|
|
51
|
+
},
|
|
52
|
+
"publishConfig": {
|
|
53
|
+
"access": "public"
|
|
54
|
+
},
|
|
55
|
+
"keywords": [
|
|
56
|
+
"brud",
|
|
57
|
+
"brudos",
|
|
58
|
+
"kernel",
|
|
59
|
+
"participants"
|
|
60
|
+
]
|
|
61
|
+
}
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|