@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,180 @@
|
|
|
1
|
+
import { compileJsonSchema } from '../../../src/validation/jsonSchema/index.js';
|
|
2
|
+
import { freezeJsonCopy } from '../../../src/validation/jsonSchema/jsonValue.js';
|
|
3
|
+
import { InterceptionDeclarationError } from '../contracts/errors.js';
|
|
4
|
+
/** Source name the interception hardcore records observations under. */
|
|
5
|
+
const OBSERVATION_SOURCE = 'brud.core.interception';
|
|
6
|
+
/** Arguments must be a plain JSON array within the kernel validator's limits. */
|
|
7
|
+
const ARGS_SCHEMA = (() => {
|
|
8
|
+
const compiled = compileJsonSchema({ type: 'array' });
|
|
9
|
+
if (!compiled.ok) {
|
|
10
|
+
throw new Error('interception argument schema failed to compile');
|
|
11
|
+
}
|
|
12
|
+
return compiled.schema;
|
|
13
|
+
})();
|
|
14
|
+
function majorOf(version) {
|
|
15
|
+
if (version === undefined) {
|
|
16
|
+
return 1;
|
|
17
|
+
}
|
|
18
|
+
return typeof version === 'number' ? version : Number.parseInt(version.split('.')[0] ?? '', 10);
|
|
19
|
+
}
|
|
20
|
+
function pointKey(name, version) {
|
|
21
|
+
return `${name}@${String(majorOf(version))}`;
|
|
22
|
+
}
|
|
23
|
+
function isInterceptor(value) {
|
|
24
|
+
return typeof value?.intercept === 'function';
|
|
25
|
+
}
|
|
26
|
+
function isValidArgs(value) {
|
|
27
|
+
return Array.isArray(value) && ARGS_SCHEMA.validate(value).valid;
|
|
28
|
+
}
|
|
29
|
+
export class InterceptionService {
|
|
30
|
+
authority;
|
|
31
|
+
#points = new Map();
|
|
32
|
+
bindAuthority(value) {
|
|
33
|
+
this.authority = value;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Builds the interception-point table from the composition's manifests.
|
|
37
|
+
*
|
|
38
|
+
* A point must sit on an exposure its giver declares; every admitted token
|
|
39
|
+
* must be a participant that declares an interception of that point; every
|
|
40
|
+
* declared interception must be admitted by a point. Anything else refuses
|
|
41
|
+
* the boot.
|
|
42
|
+
*/
|
|
43
|
+
registerComposition(participants) {
|
|
44
|
+
const byToken = new Map(participants.map((participant) => [participant.token, participant]));
|
|
45
|
+
const requests = new Map();
|
|
46
|
+
for (const participant of participants) {
|
|
47
|
+
for (const interception of participant.manifest.interceptions) {
|
|
48
|
+
const key = pointKey(interception.target, interception.version);
|
|
49
|
+
const tokens = requests.get(key) ?? new Set();
|
|
50
|
+
tokens.add(participant.token);
|
|
51
|
+
requests.set(key, tokens);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
for (const participant of participants) {
|
|
55
|
+
if (participant.manifest.interceptionPoints.length === 0) {
|
|
56
|
+
continue;
|
|
57
|
+
}
|
|
58
|
+
const owner = participant.identity;
|
|
59
|
+
if (owner === undefined) {
|
|
60
|
+
throw new InterceptionDeclarationError(participant.token, 'declares interception points but has no kernel identity');
|
|
61
|
+
}
|
|
62
|
+
for (const point of participant.manifest.interceptionPoints) {
|
|
63
|
+
const key = pointKey(point.exposure, point.version);
|
|
64
|
+
const gives = participant.manifest.exposures.some((exposure) => pointKey(exposure.name, exposure.version) === key);
|
|
65
|
+
if (!gives) {
|
|
66
|
+
throw new InterceptionDeclarationError(participant.token, `opens an interception point on "${key}", which it does not expose`);
|
|
67
|
+
}
|
|
68
|
+
if (this.#points.has(key)) {
|
|
69
|
+
throw new InterceptionDeclarationError(participant.token, `interception point "${key}" is declared twice`);
|
|
70
|
+
}
|
|
71
|
+
const interceptors = point.admit.map((token) => {
|
|
72
|
+
const interceptor = byToken.get(token);
|
|
73
|
+
if (interceptor === undefined) {
|
|
74
|
+
throw new InterceptionDeclarationError(participant.token, `admits "${token}", which is not in the composition`);
|
|
75
|
+
}
|
|
76
|
+
if (token === participant.token) {
|
|
77
|
+
throw new InterceptionDeclarationError(participant.token, `cannot admit itself on "${key}"`);
|
|
78
|
+
}
|
|
79
|
+
if (requests.get(key)?.has(token) !== true) {
|
|
80
|
+
throw new InterceptionDeclarationError(participant.token, `admits "${token}", which declares no interception of "${key}"`);
|
|
81
|
+
}
|
|
82
|
+
if (interceptor.identity === undefined) {
|
|
83
|
+
throw new InterceptionDeclarationError(token, 'is admitted as an interceptor but has no kernel identity');
|
|
84
|
+
}
|
|
85
|
+
return Object.freeze({ token, identity: interceptor.identity });
|
|
86
|
+
});
|
|
87
|
+
this.#points.set(key, Object.freeze({ key, owner, interceptors: Object.freeze(interceptors) }));
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
for (const [key, tokens] of requests) {
|
|
91
|
+
for (const token of tokens) {
|
|
92
|
+
if (this.#points.get(key)?.interceptors.some((interceptor) => interceptor.token === token) !== true) {
|
|
93
|
+
throw new InterceptionDeclarationError(token, `declares an interception of "${key}" that no giver admits`);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
evaluate(target, method, args, options) {
|
|
99
|
+
const context = this.authority?.current();
|
|
100
|
+
const caller = context === undefined ? undefined : { ...context.caller, origin: context.origin };
|
|
101
|
+
return this.evaluateAs(caller, target, method, args, options);
|
|
102
|
+
}
|
|
103
|
+
list() {
|
|
104
|
+
return Array.from(this.#points.keys());
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Evaluates the point for `resolver`, which must be the point's owner. The
|
|
108
|
+
* interceptors run in the giver's admitted order, each as itself: the first
|
|
109
|
+
* `block` wins; `modify` chains; a throw or an invalid verdict blocks
|
|
110
|
+
* (fail closed).
|
|
111
|
+
*/
|
|
112
|
+
evaluateAs(resolver, target, method, args, options) {
|
|
113
|
+
const key = target.includes('@') ? target : `${target}@1`;
|
|
114
|
+
const point = this.#points.get(key);
|
|
115
|
+
const authority = this.authority;
|
|
116
|
+
if (authority === undefined) {
|
|
117
|
+
return this.#refuse(key, 'interception is not bound');
|
|
118
|
+
}
|
|
119
|
+
if (point === undefined) {
|
|
120
|
+
return this.#refuse(key, 'unknown interception point');
|
|
121
|
+
}
|
|
122
|
+
if (resolver?.identity === null || resolver?.identity === undefined || resolver.identity !== point.owner) {
|
|
123
|
+
return this.#refuse(key, 'only the interception point owner may evaluate it');
|
|
124
|
+
}
|
|
125
|
+
if (typeof method !== 'string' || method.length === 0 || !isValidArgs(args)) {
|
|
126
|
+
return this.#refuse(key, 'method must be a non-empty string and args a plain JSON array');
|
|
127
|
+
}
|
|
128
|
+
const caller = options?.caller ?? resolver;
|
|
129
|
+
let call = Object.freeze({
|
|
130
|
+
target: key,
|
|
131
|
+
method,
|
|
132
|
+
args: freezeJsonCopy(args),
|
|
133
|
+
caller: Object.freeze({
|
|
134
|
+
identity: caller.identity,
|
|
135
|
+
callerClass: caller.callerClass,
|
|
136
|
+
official: caller.official,
|
|
137
|
+
capabilities: Object.freeze(Array.from(caller.capabilities ?? []).sort()),
|
|
138
|
+
origin: caller.origin,
|
|
139
|
+
}),
|
|
140
|
+
});
|
|
141
|
+
const modifiedBy = [];
|
|
142
|
+
for (const interceptor of point.interceptors) {
|
|
143
|
+
let verdict;
|
|
144
|
+
try {
|
|
145
|
+
const instance = authority.instanceOf(interceptor.identity);
|
|
146
|
+
if (!isInterceptor(instance)) {
|
|
147
|
+
throw new Error('the interceptor does not implement intercept');
|
|
148
|
+
}
|
|
149
|
+
const current = call;
|
|
150
|
+
verdict = authority.runAs(interceptor.identity, () => instance.intercept(current));
|
|
151
|
+
}
|
|
152
|
+
catch (error) {
|
|
153
|
+
return this.#fail(key, interceptor.token, error instanceof Error ? error.message : 'interceptor threw');
|
|
154
|
+
}
|
|
155
|
+
if (verdict?.verdict === 'allow') {
|
|
156
|
+
continue;
|
|
157
|
+
}
|
|
158
|
+
if (verdict?.verdict === 'block' && typeof verdict.reason === 'string') {
|
|
159
|
+
authority.observe(OBSERVATION_SOURCE, 'interception.blocked', { target: key, method, interceptor: interceptor.token, reason: verdict.reason });
|
|
160
|
+
return Object.freeze({ allowed: false, reason: verdict.reason, interceptor: interceptor.token });
|
|
161
|
+
}
|
|
162
|
+
if (verdict?.verdict === 'modify' && isValidArgs(verdict.args)) {
|
|
163
|
+
call = Object.freeze({ ...call, args: freezeJsonCopy(verdict.args) });
|
|
164
|
+
modifiedBy.push(interceptor.token);
|
|
165
|
+
authority.observe(OBSERVATION_SOURCE, 'interception.modified', { target: key, method, interceptor: interceptor.token });
|
|
166
|
+
continue;
|
|
167
|
+
}
|
|
168
|
+
return this.#fail(key, interceptor.token, 'invalid verdict');
|
|
169
|
+
}
|
|
170
|
+
return Object.freeze({ allowed: true, args: call.args, modifiedBy: Object.freeze(modifiedBy) });
|
|
171
|
+
}
|
|
172
|
+
#refuse(key, reason) {
|
|
173
|
+
this.authority?.observe(OBSERVATION_SOURCE, 'interception.refused', { target: key, reason });
|
|
174
|
+
return Object.freeze({ allowed: false, reason });
|
|
175
|
+
}
|
|
176
|
+
#fail(key, interceptor, reason) {
|
|
177
|
+
this.authority?.observe(OBSERVATION_SOURCE, 'interception.failed', { target: key, interceptor, reason });
|
|
178
|
+
return Object.freeze({ allowed: false, reason: `interceptor-failed: ${reason}`, interceptor });
|
|
179
|
+
}
|
|
180
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './InterceptionService.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './InterceptionService.js';
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import type { KernelServiceModuleContext } from '../../src/bootstrap/bootTypes.js';
|
|
2
|
+
export declare function createService(context: KernelServiceModuleContext): import("../../index.js").ServiceDescriptor<import("./index.js").IInterceptionService, import("./index.js").InterceptionService>;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { BrudParseOptions, BrudParseResult } from './types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Level-1 Brud Protocol v2 Parser.
|
|
4
|
+
*
|
|
5
|
+
* Converts a raw `[BRUD]` document into an ordered list of internal
|
|
6
|
+
* operations. The service is deliberately schema-agnostic and routing-agnostic:
|
|
7
|
+
* it neither looks up a tool or action nor knows which service will consume
|
|
8
|
+
* the result.
|
|
9
|
+
*/
|
|
10
|
+
export interface IBrudParserService {
|
|
11
|
+
/**
|
|
12
|
+
* Scans a raw document into operations without dispatching anything.
|
|
13
|
+
*
|
|
14
|
+
* The parser is fail-closed: a malformed document returns `ok: false` and no
|
|
15
|
+
* partial operation list. Brace regions are captured literally.
|
|
16
|
+
*
|
|
17
|
+
* @param rawInput - Raw model output, including any surrounding prose.
|
|
18
|
+
* @param options - Operation bound.
|
|
19
|
+
*/
|
|
20
|
+
parse(rawInput: string, options?: BrudParseOptions): BrudParseResult;
|
|
21
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/** Stable, machine-readable codes for Parser failures. */
|
|
2
|
+
export type ParserErrorCode = 'PARSER_DISPOSED' | 'PARSE_ERROR' | 'OPERATION_LIMIT_EXCEEDED';
|
|
3
|
+
/** Raised when the parser is used after disposal. */
|
|
4
|
+
export declare class ParserDisposedError extends Error {
|
|
5
|
+
readonly code: "PARSER_DISPOSED";
|
|
6
|
+
constructor();
|
|
7
|
+
}
|
|
8
|
+
/** Base class for parser-domain failures other than structural parse errors. */
|
|
9
|
+
export declare abstract class ParserError extends Error {
|
|
10
|
+
abstract readonly code: ParserErrorCode;
|
|
11
|
+
protected constructor(message: string, options?: ErrorOptions);
|
|
12
|
+
}
|
|
13
|
+
/** Raised when a document exceeds the configured operation bound. */
|
|
14
|
+
export declare class OperationLimitExceededError extends ParserError {
|
|
15
|
+
readonly code: "OPERATION_LIMIT_EXCEEDED";
|
|
16
|
+
/** Number of operations the document contained. */
|
|
17
|
+
readonly observed: number;
|
|
18
|
+
/** Configured maximum. */
|
|
19
|
+
readonly limit: number;
|
|
20
|
+
/**
|
|
21
|
+
* @param observed - Operations found in the document.
|
|
22
|
+
* @param limit - Configured maximum.
|
|
23
|
+
*/
|
|
24
|
+
constructor(observed: number, limit: number);
|
|
25
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/** Raised when the parser is used after disposal. */
|
|
2
|
+
export class ParserDisposedError extends Error {
|
|
3
|
+
code = 'PARSER_DISPOSED';
|
|
4
|
+
constructor() {
|
|
5
|
+
super('Brud parser has been disposed');
|
|
6
|
+
this.name = 'ParserDisposedError';
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
/** Base class for parser-domain failures other than structural parse errors. */
|
|
10
|
+
export class ParserError extends Error {
|
|
11
|
+
constructor(message, options) {
|
|
12
|
+
super(message, options);
|
|
13
|
+
this.name = 'ParserError';
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
/** Raised when a document exceeds the configured operation bound. */
|
|
17
|
+
export class OperationLimitExceededError extends ParserError {
|
|
18
|
+
code = 'OPERATION_LIMIT_EXCEEDED';
|
|
19
|
+
/** Number of operations the document contained. */
|
|
20
|
+
observed;
|
|
21
|
+
/** Configured maximum. */
|
|
22
|
+
limit;
|
|
23
|
+
/**
|
|
24
|
+
* @param observed - Operations found in the document.
|
|
25
|
+
* @param limit - Configured maximum.
|
|
26
|
+
*/
|
|
27
|
+
constructor(observed, limit) {
|
|
28
|
+
super(`document contains ${String(observed)} operations; the limit is ${String(limit)}`);
|
|
29
|
+
this.name = 'OperationLimitExceededError';
|
|
30
|
+
this.observed = observed;
|
|
31
|
+
this.limit = limit;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export type { IBrudParserService } from './IParserService.js';
|
|
2
|
+
export type { BrudOperation, BrudParseFailure, BrudParseOptions, BrudParseResult, } from './types.js';
|
|
3
|
+
export type { ParserErrorCode } from './errors.js';
|
|
4
|
+
export { OperationLimitExceededError, ParserDisposedError, ParserError, } from './errors.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { OperationLimitExceededError, ParserDisposedError, ParserError, } from './errors.js';
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import type { BrudOperationKind } from '../../../src/contracts/brudOperation.js';
|
|
2
|
+
/**
|
|
3
|
+
* One parsed `[BRUD]` operation.
|
|
4
|
+
*
|
|
5
|
+
* This service knows only the wire syntax: an operation carries its
|
|
6
|
+
* synthesized document index, the shared kind token, the name written on the
|
|
7
|
+
* header, and the parameter map. It never resolves a target or a service.
|
|
8
|
+
*/
|
|
9
|
+
export interface BrudOperation {
|
|
10
|
+
/** 1-based document index synthesized from operation order. */
|
|
11
|
+
readonly index: string;
|
|
12
|
+
/** Shared operation kind, e.g. `tool` or `action`. */
|
|
13
|
+
readonly kind: BrudOperationKind;
|
|
14
|
+
/** Operation name written after the kind, e.g. `read_file`. */
|
|
15
|
+
readonly name: string;
|
|
16
|
+
/** Parsed payload. Protected regions are literal strings. */
|
|
17
|
+
readonly parameters: Readonly<Record<string, unknown>>;
|
|
18
|
+
}
|
|
19
|
+
/** Structured, fail-closed parse failure. */
|
|
20
|
+
export interface BrudParseFailure {
|
|
21
|
+
/** Stable machine-readable code. */
|
|
22
|
+
readonly code: string;
|
|
23
|
+
/** Human-readable summary. */
|
|
24
|
+
readonly friendly: string;
|
|
25
|
+
/** Diagnostic detail, including the document line when known. */
|
|
26
|
+
readonly details: string;
|
|
27
|
+
/** Absolute 1-based document line, when the failure is positional. */
|
|
28
|
+
readonly line?: number;
|
|
29
|
+
}
|
|
30
|
+
/** Bounds accepted by {@link IBrudParserService.parse}. */
|
|
31
|
+
export interface BrudParseOptions {
|
|
32
|
+
/** Upper bound on parsed operations. Default 1_000. */
|
|
33
|
+
readonly maxOperations?: number;
|
|
34
|
+
}
|
|
35
|
+
/** Result of a pure scan/parse. */
|
|
36
|
+
export type BrudParseResult = {
|
|
37
|
+
readonly ok: true;
|
|
38
|
+
readonly operations: readonly BrudOperation[];
|
|
39
|
+
} | {
|
|
40
|
+
readonly ok: false;
|
|
41
|
+
readonly error: BrudParseFailure;
|
|
42
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { ServiceTier } from '../../../src/contracts/lifecycle.js';
|
|
2
|
+
import type { ServiceDescriptor } from '../../../src/contracts/serviceDescriptor.js';
|
|
3
|
+
import type { IBrudParserService } from '../contracts/IParserService.js';
|
|
4
|
+
import { ParserService } from '../orchestrator/index.js';
|
|
5
|
+
/** The Parser's v1 entry exposure. */
|
|
6
|
+
export declare const PARSER_EXPOSURE = "syntax.parse";
|
|
7
|
+
/** Tier assigned to the Parser descriptor. */
|
|
8
|
+
export declare const PARSER_SERVICE_TIER: ServiceTier;
|
|
9
|
+
/** Contract version declared for the Parser interface. */
|
|
10
|
+
export declare const PARSER_CONTRACT_VERSION = "1.0.0";
|
|
11
|
+
/** Methods declared for the Parser interface. */
|
|
12
|
+
export declare const PARSER_CONTRACT_METHODS: readonly ["parse"];
|
|
13
|
+
/**
|
|
14
|
+
* Builds the `brud.core.parser` service descriptor.
|
|
15
|
+
*
|
|
16
|
+
* It declares no dependencies: it is a pure syntax engine. It sits before the
|
|
17
|
+
* routing service and every routing consumer in the standard boot order.
|
|
18
|
+
*
|
|
19
|
+
* @returns A core-tier descriptor for `brud.core.parser`.
|
|
20
|
+
*/
|
|
21
|
+
export declare function createParserDescriptor(): ServiceDescriptor<IBrudParserService, ParserService>;
|
|
22
|
+
/** Standard parser descriptor with no overrides. */
|
|
23
|
+
export declare const ParserDescriptor: ServiceDescriptor<IBrudParserService, ParserService>;
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { ParserService } from '../orchestrator/index.js';
|
|
2
|
+
import { ParserToken } from './tokens.js';
|
|
3
|
+
import { withExposureBindings } from '../../ExposedApiRegistry/contracts/registrant.js';
|
|
4
|
+
/** The Parser's v1 entry exposure. */
|
|
5
|
+
export const PARSER_EXPOSURE = 'syntax.parse';
|
|
6
|
+
/** Tier assigned to the Parser descriptor. */
|
|
7
|
+
export const PARSER_SERVICE_TIER = 'core';
|
|
8
|
+
/** Contract version declared for the Parser interface. */
|
|
9
|
+
export const PARSER_CONTRACT_VERSION = '1.0.0';
|
|
10
|
+
/** Methods declared for the Parser interface. */
|
|
11
|
+
export const PARSER_CONTRACT_METHODS = ['parse'];
|
|
12
|
+
/**
|
|
13
|
+
* Builds the `brud.core.parser` service descriptor.
|
|
14
|
+
*
|
|
15
|
+
* It declares no dependencies: it is a pure syntax engine. It sits before the
|
|
16
|
+
* routing service and every routing consumer in the standard boot order.
|
|
17
|
+
*
|
|
18
|
+
* @returns A core-tier descriptor for `brud.core.parser`.
|
|
19
|
+
*/
|
|
20
|
+
export function createParserDescriptor() {
|
|
21
|
+
return {
|
|
22
|
+
token: ParserToken,
|
|
23
|
+
tier: PARSER_SERVICE_TIER,
|
|
24
|
+
dependencies: [],
|
|
25
|
+
contract: {
|
|
26
|
+
version: PARSER_CONTRACT_VERSION,
|
|
27
|
+
methods: PARSER_CONTRACT_METHODS,
|
|
28
|
+
},
|
|
29
|
+
// Token access is kernel-internal (the Router). Every other caller uses the
|
|
30
|
+
// `syntax.parse@1` exposure; parsing is pure, so it carries no policy.
|
|
31
|
+
accessPolicy: {
|
|
32
|
+
allowedCallers: ['kernel', 'brud.core.router'],
|
|
33
|
+
},
|
|
34
|
+
manifest: {
|
|
35
|
+
exposures: [{ name: PARSER_EXPOSURE, version: 1, scope: 'any' }],
|
|
36
|
+
},
|
|
37
|
+
factory: () => {
|
|
38
|
+
const service = new ParserService();
|
|
39
|
+
return withExposureBindings(service, {
|
|
40
|
+
[`${PARSER_EXPOSURE}@1`]: {
|
|
41
|
+
projection: () => Object.freeze({
|
|
42
|
+
parse: (rawInput, options) => service.parse(rawInput, options),
|
|
43
|
+
}),
|
|
44
|
+
},
|
|
45
|
+
});
|
|
46
|
+
},
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
/** Standard parser descriptor with no overrides. */
|
|
50
|
+
export const ParserDescriptor = createParserDescriptor();
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { IBrudParserService } from '../contracts/IParserService.js';
|
|
2
|
+
/**
|
|
3
|
+
* Kernel service token for `brud.core.parser`.
|
|
4
|
+
*
|
|
5
|
+
* Resolution grants pure syntax parsing only. The parser holds no registry,
|
|
6
|
+
* broker, or routing authority.
|
|
7
|
+
*/
|
|
8
|
+
export declare const ParserToken: import("../../../src/contracts/serviceToken.js").ServiceToken<IBrudParserService>;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { createServiceToken } from '../../../src/contracts/serviceToken.js';
|
|
2
|
+
/**
|
|
3
|
+
* Kernel service token for `brud.core.parser`.
|
|
4
|
+
*
|
|
5
|
+
* Resolution grants pure syntax parsing only. The parser holds no registry,
|
|
6
|
+
* broker, or routing authority.
|
|
7
|
+
*/
|
|
8
|
+
export const ParserToken = createServiceToken('brud.core.parser', 'Brud Protocol v2 syntax parser producing kind-tagged operations');
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export * from './contracts/index.js';
|
|
2
|
+
export * from './descriptor/ParserDescriptor.js';
|
|
3
|
+
export * from './descriptor/tokens.js';
|
|
4
|
+
export * from './orchestrator/index.js';
|
|
5
|
+
export { extractWrapper, scanBrudDocument, type ProtectedParameterResolver, type ScannedCall, } from './parser/scanner.js';
|
|
6
|
+
export { parseParameters } from './parser/parameters.js';
|
|
7
|
+
export { synthesizeIndex } from './parser/indexSynthesis.js';
|
|
8
|
+
export { BRUD_PARSE_ERROR, BrudParseError } from './parser/syntax.js';
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export * from './contracts/index.js';
|
|
2
|
+
export * from './descriptor/ParserDescriptor.js';
|
|
3
|
+
export * from './descriptor/tokens.js';
|
|
4
|
+
export * from './orchestrator/index.js';
|
|
5
|
+
export { extractWrapper, scanBrudDocument, } from './parser/scanner.js';
|
|
6
|
+
export { parseParameters } from './parser/parameters.js';
|
|
7
|
+
export { synthesizeIndex } from './parser/indexSynthesis.js';
|
|
8
|
+
export { BRUD_PARSE_ERROR, BrudParseError } from './parser/syntax.js';
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { IServiceLifecycle } from '../../../src/contracts/lifecycle.js';
|
|
2
|
+
import type { IBrudParserService } from '../contracts/IParserService.js';
|
|
3
|
+
import type { BrudParseOptions, BrudParseResult } from '../contracts/types.js';
|
|
4
|
+
/**
|
|
5
|
+
* Level-1 Brud Protocol v2 Parser.
|
|
6
|
+
*
|
|
7
|
+
* Owns the `[BRUD]` scanner and nothing else. It has no registry, no broker
|
|
8
|
+
* dependency, and no knowledge of the kind vocabulary beyond validating the
|
|
9
|
+
* kind token written on the header. Routing belongs to `brud.core.router`.
|
|
10
|
+
*/
|
|
11
|
+
export declare class ParserService implements IBrudParserService, IServiceLifecycle {
|
|
12
|
+
private disposed;
|
|
13
|
+
/** Lifecycle no-op: bootstrap is synchronous. */
|
|
14
|
+
initialize(): Promise<void>;
|
|
15
|
+
/** Refuses every later parse. */
|
|
16
|
+
dispose(): Promise<void>;
|
|
17
|
+
/** Whether {@link dispose} has run. */
|
|
18
|
+
get isDisposed(): boolean;
|
|
19
|
+
parse(rawInput: string, options?: BrudParseOptions): BrudParseResult;
|
|
20
|
+
}
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import { OperationLimitExceededError, ParserDisposedError, } from '../contracts/errors.js';
|
|
2
|
+
import { synthesizeIndex } from '../parser/indexSynthesis.js';
|
|
3
|
+
import { BrudParseError, scanBrudDocument } from '../parser/scanner.js';
|
|
4
|
+
/** Default DoS bound for one parsed document. */
|
|
5
|
+
const DEFAULT_MAX_OPERATIONS = 1_000;
|
|
6
|
+
/**
|
|
7
|
+
* Level-1 Brud Protocol v2 Parser.
|
|
8
|
+
*
|
|
9
|
+
* Owns the `[BRUD]` scanner and nothing else. It has no registry, no broker
|
|
10
|
+
* dependency, and no knowledge of the kind vocabulary beyond validating the
|
|
11
|
+
* kind token written on the header. Routing belongs to `brud.core.router`.
|
|
12
|
+
*/
|
|
13
|
+
export class ParserService {
|
|
14
|
+
disposed = false;
|
|
15
|
+
/** Lifecycle no-op: bootstrap is synchronous. */
|
|
16
|
+
async initialize() {
|
|
17
|
+
return undefined;
|
|
18
|
+
}
|
|
19
|
+
/** Refuses every later parse. */
|
|
20
|
+
async dispose() {
|
|
21
|
+
this.disposed = true;
|
|
22
|
+
}
|
|
23
|
+
/** Whether {@link dispose} has run. */
|
|
24
|
+
get isDisposed() {
|
|
25
|
+
return this.disposed;
|
|
26
|
+
}
|
|
27
|
+
parse(rawInput, options = {}) {
|
|
28
|
+
if (this.disposed) {
|
|
29
|
+
return { ok: false, error: parseFailure(new ParserDisposedError()) };
|
|
30
|
+
}
|
|
31
|
+
const maxOperations = options.maxOperations ?? DEFAULT_MAX_OPERATIONS;
|
|
32
|
+
if (!Number.isSafeInteger(maxOperations) || maxOperations < 1) {
|
|
33
|
+
return {
|
|
34
|
+
ok: false,
|
|
35
|
+
error: {
|
|
36
|
+
code: 'PARSE_ERROR',
|
|
37
|
+
friendly: 'invalid operation bound',
|
|
38
|
+
details: `maxOperations must be a positive integer, received ${String(maxOperations)}`,
|
|
39
|
+
},
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
try {
|
|
43
|
+
// The Parser is schema-agnostic: every brace region is opaque. The
|
|
44
|
+
// resolver is still passed so the scanner's protected-region semantics
|
|
45
|
+
// remain one implementation.
|
|
46
|
+
const calls = scanBrudDocument(rawInput, () => undefined);
|
|
47
|
+
if (calls.length > maxOperations) {
|
|
48
|
+
return {
|
|
49
|
+
ok: false,
|
|
50
|
+
error: parseFailure(new OperationLimitExceededError(calls.length, maxOperations)),
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
const operations = calls.map((call, sequence) => Object.freeze({
|
|
54
|
+
index: synthesizeIndex(sequence),
|
|
55
|
+
kind: call.kind,
|
|
56
|
+
name: call.name,
|
|
57
|
+
parameters: call.parameters,
|
|
58
|
+
}));
|
|
59
|
+
return { ok: true, operations: Object.freeze(operations) };
|
|
60
|
+
}
|
|
61
|
+
catch (error) {
|
|
62
|
+
return { ok: false, error: parseFailure(error) };
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
/** Converts a thrown failure into the public parse-failure shape. */
|
|
67
|
+
function parseFailure(error) {
|
|
68
|
+
if (error instanceof BrudParseError) {
|
|
69
|
+
return {
|
|
70
|
+
code: error.code,
|
|
71
|
+
friendly: error.message,
|
|
72
|
+
details: error.message,
|
|
73
|
+
line: error.line,
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
if (error instanceof OperationLimitExceededError) {
|
|
77
|
+
return {
|
|
78
|
+
code: error.code,
|
|
79
|
+
friendly: 'too many operations',
|
|
80
|
+
details: error.message,
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
if (error instanceof ParserDisposedError) {
|
|
84
|
+
return {
|
|
85
|
+
code: error.code,
|
|
86
|
+
friendly: error.message,
|
|
87
|
+
details: error.message,
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
if (error instanceof Error && 'code' in error) {
|
|
91
|
+
const code = error.code;
|
|
92
|
+
if (typeof code === 'string') {
|
|
93
|
+
return { code, friendly: error.message, details: error.message };
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
return {
|
|
97
|
+
code: 'PARSE_ERROR',
|
|
98
|
+
friendly: describe(error),
|
|
99
|
+
details: describe(error),
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
/** Renders an unknown thrown value for a diagnostic message. */
|
|
103
|
+
function describe(error) {
|
|
104
|
+
return error instanceof Error ? error.message : String(error);
|
|
105
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { ParserService } from './ParserService.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { ParserService } from './ParserService.js';
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Synthesizes the document index for a parsed Brud operation.
|
|
3
|
+
*
|
|
4
|
+
* The `[BRUD]` wire grammar has no index marker, so the scanner derives it
|
|
5
|
+
* from document position. `sequence` is zero-based; the first operation is
|
|
6
|
+
* `'1'`, matching the frozen 21-kind matrix which requires `index`.
|
|
7
|
+
*
|
|
8
|
+
* @param sequence - Zero-based document position of the operation.
|
|
9
|
+
* @returns The 1-based index as a decimal string.
|
|
10
|
+
*/
|
|
11
|
+
export declare function synthesizeIndex(sequence: number): string;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Synthesizes the document index for a parsed Brud operation.
|
|
3
|
+
*
|
|
4
|
+
* The `[BRUD]` wire grammar has no index marker, so the scanner derives it
|
|
5
|
+
* from document position. `sequence` is zero-based; the first operation is
|
|
6
|
+
* `'1'`, matching the frozen 21-kind matrix which requires `index`.
|
|
7
|
+
*
|
|
8
|
+
* @param sequence - Zero-based document position of the operation.
|
|
9
|
+
* @returns The 1-based index as a decimal string.
|
|
10
|
+
*/
|
|
11
|
+
export function synthesizeIndex(sequence) {
|
|
12
|
+
return String(sequence + 1);
|
|
13
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Parses `key: value` parameters and `{param}` … `{/param}` protected regions.
|
|
3
|
+
*
|
|
4
|
+
* Plain parameters are single-line and trimmed. Protected content is captured
|
|
5
|
+
* byte-for-byte between its own-line markers, including blank lines, braces and
|
|
6
|
+
* protocol-like markers. Duplicate keys and malformed lines fail closed.
|
|
7
|
+
*
|
|
8
|
+
* @param lines - Block body lines, opener excluded and `[END]` excluded.
|
|
9
|
+
* @param protectedNames - Protected names for the operation, or `undefined`
|
|
10
|
+
* when every brace region is opaque (the schema-agnostic Parser default).
|
|
11
|
+
* @param firstLine - Absolute 1-based line number of the first body line.
|
|
12
|
+
* @returns The parsed parameter map.
|
|
13
|
+
*/
|
|
14
|
+
export declare function parseParameters(lines: readonly string[], protectedNames: readonly string[] | undefined, firstLine: number): Readonly<Record<string, unknown>>;
|