@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,89 @@
|
|
|
1
|
+
import { BRACE_PATTERN, BrudParseError, KEY_PATTERN } from './syntax.js';
|
|
2
|
+
/**
|
|
3
|
+
* Parses `key: value` parameters and `{param}` … `{/param}` protected regions.
|
|
4
|
+
*
|
|
5
|
+
* Plain parameters are single-line and trimmed. Protected content is captured
|
|
6
|
+
* byte-for-byte between its own-line markers, including blank lines, braces and
|
|
7
|
+
* protocol-like markers. Duplicate keys and malformed lines fail closed.
|
|
8
|
+
*
|
|
9
|
+
* @param lines - Block body lines, opener excluded and `[END]` excluded.
|
|
10
|
+
* @param protectedNames - Protected names for the operation, or `undefined`
|
|
11
|
+
* when every brace region is opaque (the schema-agnostic Parser default).
|
|
12
|
+
* @param firstLine - Absolute 1-based line number of the first body line.
|
|
13
|
+
* @returns The parsed parameter map.
|
|
14
|
+
*/
|
|
15
|
+
export function parseParameters(lines, protectedNames, firstLine) {
|
|
16
|
+
const parameters = {};
|
|
17
|
+
const seen = new Set();
|
|
18
|
+
let index = 0;
|
|
19
|
+
while (index < lines.length) {
|
|
20
|
+
const rawLine = lines[index] ?? '';
|
|
21
|
+
const line = firstLine + index;
|
|
22
|
+
const trimmed = rawLine.trim();
|
|
23
|
+
if (trimmed === '') {
|
|
24
|
+
index += 1;
|
|
25
|
+
continue;
|
|
26
|
+
}
|
|
27
|
+
const brace = BRACE_PATTERN.exec(trimmed);
|
|
28
|
+
const braceName = brace?.[1] ?? '';
|
|
29
|
+
if (brace !== null && !braceName.startsWith('/') && isProtected(protectedNames, braceName)) {
|
|
30
|
+
if (seen.has(braceName)) {
|
|
31
|
+
throw new BrudParseError(`duplicate parameter "${braceName}"`, line);
|
|
32
|
+
}
|
|
33
|
+
const closedAt = findCloser(lines, index + 1, braceName);
|
|
34
|
+
if (closedAt < 0) {
|
|
35
|
+
throw new BrudParseError(`unterminated protected parameter "${braceName}"`, line);
|
|
36
|
+
}
|
|
37
|
+
seen.add(braceName);
|
|
38
|
+
parameters[braceName] = lines.slice(index + 1, closedAt).join('\n');
|
|
39
|
+
index = closedAt + 1;
|
|
40
|
+
continue;
|
|
41
|
+
}
|
|
42
|
+
if (brace !== null) {
|
|
43
|
+
throw new BrudParseError(`unprotected parameter "${braceName}" must not use brace form`, line);
|
|
44
|
+
}
|
|
45
|
+
const parameter = KEY_PATTERN.exec(trimmed);
|
|
46
|
+
if (parameter === null) {
|
|
47
|
+
throw new BrudParseError('expected a "key: value" parameter', line);
|
|
48
|
+
}
|
|
49
|
+
const key = parameter[1] ?? '';
|
|
50
|
+
const value = (parameter[2] ?? '').trim();
|
|
51
|
+
if (isDeclaredProtected(protectedNames, key)) {
|
|
52
|
+
throw new BrudParseError(`protected parameter "${key}" requires the {${key}} … {/${key}} form`, line);
|
|
53
|
+
}
|
|
54
|
+
if (seen.has(key)) {
|
|
55
|
+
throw new BrudParseError(`duplicate parameter "${key}"`, line);
|
|
56
|
+
}
|
|
57
|
+
seen.add(key);
|
|
58
|
+
parameters[key] = value;
|
|
59
|
+
index += 1;
|
|
60
|
+
}
|
|
61
|
+
return Object.freeze(parameters);
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Whether a brace region is protected.
|
|
65
|
+
*
|
|
66
|
+
* `undefined` means the schema is unknown and every brace region is opaque.
|
|
67
|
+
*/
|
|
68
|
+
function isProtected(protectedNames, name) {
|
|
69
|
+
return protectedNames === undefined || protectedNames.includes(name);
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Whether a plain `key: value` parameter is declared protected.
|
|
73
|
+
*
|
|
74
|
+
* Only an explicit schema declaration can force the brace form; when the
|
|
75
|
+
* schema is unknown, plain parameters remain admissible.
|
|
76
|
+
*/
|
|
77
|
+
function isDeclaredProtected(protectedNames, name) {
|
|
78
|
+
return protectedNames !== undefined && protectedNames.includes(name);
|
|
79
|
+
}
|
|
80
|
+
/** Finds the own-line closer for a protected region, or -1 when absent. */
|
|
81
|
+
function findCloser(lines, from, name) {
|
|
82
|
+
const expected = `{/${name}}`;
|
|
83
|
+
for (let index = from; index < lines.length; index += 1) {
|
|
84
|
+
if ((lines[index] ?? '').trim() === expected) {
|
|
85
|
+
return index;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
return -1;
|
|
89
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { type BrudOperationKind } from '../../../src/contracts/brudOperation.js';
|
|
2
|
+
export { BRUD_PARSE_ERROR, BrudParseError } from './syntax.js';
|
|
3
|
+
/** One `[CALL …]` … `[END]` block with its kind, name and parsed parameters. */
|
|
4
|
+
export interface ScannedCall {
|
|
5
|
+
/** Operation kind declared by the header. */
|
|
6
|
+
readonly kind: BrudOperationKind;
|
|
7
|
+
/** Operation name (tool or action name) taken from the opening marker. */
|
|
8
|
+
readonly name: string;
|
|
9
|
+
/** Parsed parameter map; protected values are literal strings. */
|
|
10
|
+
readonly parameters: Readonly<Record<string, unknown>>;
|
|
11
|
+
/** Absolute 1-based line number of the opening marker. */
|
|
12
|
+
readonly line: number;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Resolves the protected parameter names for an operation.
|
|
16
|
+
*
|
|
17
|
+
* The Parser is schema-agnostic and passes `undefined`, which makes every
|
|
18
|
+
* brace region opaque. The hook stays injectable so a future syntax-only
|
|
19
|
+
* profile can narrow the protected set without changing the scanner.
|
|
20
|
+
*/
|
|
21
|
+
export type ProtectedParameterResolver = (kind: BrudOperationKind, name: string) => readonly string[] | undefined;
|
|
22
|
+
/**
|
|
23
|
+
* Extracts the first `[BRUD]` … `[/BRUD]` wrapper body.
|
|
24
|
+
*
|
|
25
|
+
* Text outside the wrapper is ignored. A missing, reversed or unterminated
|
|
26
|
+
* wrapper is a parse error.
|
|
27
|
+
*
|
|
28
|
+
* @param raw - Untrusted model output.
|
|
29
|
+
* @returns The body between the markers and its first-line number.
|
|
30
|
+
*/
|
|
31
|
+
export declare function extractWrapper(raw: string): {
|
|
32
|
+
readonly body: string;
|
|
33
|
+
readonly line: number;
|
|
34
|
+
};
|
|
35
|
+
/**
|
|
36
|
+
* Scans a full document into ordered operations.
|
|
37
|
+
*
|
|
38
|
+
* The wrapper is extracted first, then every `[CALL …]` is split at the first
|
|
39
|
+
* `[END]` that is not inside a protected parameter.
|
|
40
|
+
*
|
|
41
|
+
* Header form: `[CALL <kind> <name>]`, e.g. `[CALL action list_sessions]`.
|
|
42
|
+
* A bare `[CALL <name>]` header names no kind and is refused.
|
|
43
|
+
*
|
|
44
|
+
* @param raw - Untrusted model output.
|
|
45
|
+
* @param resolveProtected - Protected-parameter resolver.
|
|
46
|
+
* @returns Ordered calls, each with parsed parameters.
|
|
47
|
+
*/
|
|
48
|
+
export declare function scanBrudDocument(raw: string, resolveProtected: ProtectedParameterResolver): readonly ScannedCall[];
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
import { isValidBrudKind, } from '../../../src/contracts/brudOperation.js';
|
|
2
|
+
import { parseParameters } from './parameters.js';
|
|
3
|
+
import { BRACE_PATTERN, BrudParseError, CALL_PATTERN } from './syntax.js';
|
|
4
|
+
export { BRUD_PARSE_ERROR, BrudParseError } from './syntax.js';
|
|
5
|
+
const WRAPPER_OPEN = '[BRUD]';
|
|
6
|
+
const WRAPPER_CLOSE = '[/BRUD]';
|
|
7
|
+
const END_MARKER = '[END]';
|
|
8
|
+
/**
|
|
9
|
+
* Extracts the first `[BRUD]` … `[/BRUD]` wrapper body.
|
|
10
|
+
*
|
|
11
|
+
* Text outside the wrapper is ignored. A missing, reversed or unterminated
|
|
12
|
+
* wrapper is a parse error.
|
|
13
|
+
*
|
|
14
|
+
* @param raw - Untrusted model output.
|
|
15
|
+
* @returns The body between the markers and its first-line number.
|
|
16
|
+
*/
|
|
17
|
+
export function extractWrapper(raw) {
|
|
18
|
+
const text = raw.replace(/\r\n/g, '\n').replace(/\r/g, '\n');
|
|
19
|
+
const open = text.indexOf(WRAPPER_OPEN);
|
|
20
|
+
if (open < 0) {
|
|
21
|
+
throw new BrudParseError('missing [BRUD] wrapper', lineAt(text, 0));
|
|
22
|
+
}
|
|
23
|
+
const close = text.indexOf(WRAPPER_CLOSE, open + WRAPPER_OPEN.length);
|
|
24
|
+
if (close < 0) {
|
|
25
|
+
throw new BrudParseError('unterminated [BRUD] wrapper', lineAt(text, open));
|
|
26
|
+
}
|
|
27
|
+
const bodyStart = open + WRAPPER_OPEN.length;
|
|
28
|
+
return { body: text.slice(bodyStart, close), line: lineAt(text, bodyStart) };
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Scans a full document into ordered operations.
|
|
32
|
+
*
|
|
33
|
+
* The wrapper is extracted first, then every `[CALL …]` is split at the first
|
|
34
|
+
* `[END]` that is not inside a protected parameter.
|
|
35
|
+
*
|
|
36
|
+
* Header form: `[CALL <kind> <name>]`, e.g. `[CALL action list_sessions]`.
|
|
37
|
+
* A bare `[CALL <name>]` header names no kind and is refused.
|
|
38
|
+
*
|
|
39
|
+
* @param raw - Untrusted model output.
|
|
40
|
+
* @param resolveProtected - Protected-parameter resolver.
|
|
41
|
+
* @returns Ordered calls, each with parsed parameters.
|
|
42
|
+
*/
|
|
43
|
+
export function scanBrudDocument(raw, resolveProtected) {
|
|
44
|
+
const { body, line } = extractWrapper(raw);
|
|
45
|
+
const lines = body.split('\n');
|
|
46
|
+
const calls = [];
|
|
47
|
+
let index = 0;
|
|
48
|
+
while (index < lines.length) {
|
|
49
|
+
const candidate = lines[index] ?? '';
|
|
50
|
+
if (candidate.trim() === '') {
|
|
51
|
+
index += 1;
|
|
52
|
+
continue;
|
|
53
|
+
}
|
|
54
|
+
const header = parseCallHeader(candidate.trim(), line + index);
|
|
55
|
+
if (header === undefined) {
|
|
56
|
+
throw new BrudParseError('expected [CALL <kind> <name>]', line + index);
|
|
57
|
+
}
|
|
58
|
+
const openingLine = line + index;
|
|
59
|
+
const protectedNames = resolveProtected(header.kind, header.name);
|
|
60
|
+
const bodyLines = [];
|
|
61
|
+
index += 1;
|
|
62
|
+
let closed = false;
|
|
63
|
+
let activeProtected = null;
|
|
64
|
+
while (index < lines.length) {
|
|
65
|
+
const current = lines[index] ?? '';
|
|
66
|
+
const trimmed = current.trim();
|
|
67
|
+
if (activeProtected !== null) {
|
|
68
|
+
if (trimmed === closer(activeProtected)) {
|
|
69
|
+
activeProtected = null;
|
|
70
|
+
}
|
|
71
|
+
bodyLines.push(current);
|
|
72
|
+
index += 1;
|
|
73
|
+
continue;
|
|
74
|
+
}
|
|
75
|
+
if (trimmed === END_MARKER) {
|
|
76
|
+
closed = true;
|
|
77
|
+
index += 1;
|
|
78
|
+
break;
|
|
79
|
+
}
|
|
80
|
+
const brace = BRACE_PATTERN.exec(trimmed);
|
|
81
|
+
const braceName = brace?.[1] ?? '';
|
|
82
|
+
if (brace !== null
|
|
83
|
+
&& !braceName.startsWith('/')
|
|
84
|
+
&& isProtected(protectedNames, braceName)) {
|
|
85
|
+
activeProtected = braceName;
|
|
86
|
+
}
|
|
87
|
+
if (CALL_PATTERN.test(trimmed)) {
|
|
88
|
+
throw new BrudParseError('nested [CALL] is not allowed', line + index);
|
|
89
|
+
}
|
|
90
|
+
bodyLines.push(current);
|
|
91
|
+
index += 1;
|
|
92
|
+
}
|
|
93
|
+
if (!closed) {
|
|
94
|
+
throw new BrudParseError('missing [END] for [CALL]', openingLine);
|
|
95
|
+
}
|
|
96
|
+
calls.push({
|
|
97
|
+
kind: header.kind,
|
|
98
|
+
name: header.name,
|
|
99
|
+
parameters: parseParameters(bodyLines, protectedNames, openingLine + 1),
|
|
100
|
+
line: openingLine,
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
if (calls.length === 0) {
|
|
104
|
+
throw new BrudParseError('wrapper contains no [CALL] block', line);
|
|
105
|
+
}
|
|
106
|
+
return calls;
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Parses a `[CALL …]` header.
|
|
110
|
+
*
|
|
111
|
+
* Two tokens are `<kind> <name>`. The kind must satisfy the shared kind
|
|
112
|
+
* grammar. One token names no kind, so the header is refused.
|
|
113
|
+
*
|
|
114
|
+
* @param trimmed - Trimmed header line.
|
|
115
|
+
* @param line - Absolute 1-based line number for diagnostics.
|
|
116
|
+
* @returns The header, or `undefined` when the line is not a call header.
|
|
117
|
+
*/
|
|
118
|
+
function parseCallHeader(trimmed, line) {
|
|
119
|
+
const match = CALL_PATTERN.exec(trimmed);
|
|
120
|
+
if (match === null) {
|
|
121
|
+
return undefined;
|
|
122
|
+
}
|
|
123
|
+
const first = match[1] ?? '';
|
|
124
|
+
const second = match[2];
|
|
125
|
+
if (first === '') {
|
|
126
|
+
throw new BrudParseError('empty operation name in [CALL]', line);
|
|
127
|
+
}
|
|
128
|
+
if (second === undefined) {
|
|
129
|
+
throw new BrudParseError('operation kind is required in [CALL]', line);
|
|
130
|
+
}
|
|
131
|
+
if (second === '') {
|
|
132
|
+
throw new BrudParseError('empty operation name in [CALL]', line);
|
|
133
|
+
}
|
|
134
|
+
if (!isValidBrudKind(first)) {
|
|
135
|
+
throw new BrudParseError(`invalid operation kind "${first}"`, line);
|
|
136
|
+
}
|
|
137
|
+
return { kind: first, name: second };
|
|
138
|
+
}
|
|
139
|
+
/** Whether a parameter is protected for an operation whose schema is known. */
|
|
140
|
+
function isProtected(protectedNames, name) {
|
|
141
|
+
return protectedNames === undefined || protectedNames.includes(name);
|
|
142
|
+
}
|
|
143
|
+
/** The own-line closer form for a protected parameter. */
|
|
144
|
+
function closer(name) {
|
|
145
|
+
return `{/${name}}`;
|
|
146
|
+
}
|
|
147
|
+
/** Computes the 1-based line number of a string offset. */
|
|
148
|
+
function lineAt(text, offset) {
|
|
149
|
+
let line = 1;
|
|
150
|
+
for (let index = 0; index < offset; index += 1) {
|
|
151
|
+
if (text[index] === '\n') {
|
|
152
|
+
line += 1;
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
return line;
|
|
156
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/** Stable code for every Brud Protocol v2 structural failure. */
|
|
2
|
+
export declare const BRUD_PARSE_ERROR: "PARSE_ERROR";
|
|
3
|
+
/** Bare parameter key: `key: value`. */
|
|
4
|
+
export declare const KEY_PATTERN: RegExp;
|
|
5
|
+
/** Own-line brace marker: `{name}` or `{/name}`. */
|
|
6
|
+
export declare const BRACE_PATTERN: RegExp;
|
|
7
|
+
/**
|
|
8
|
+
* Call header: `[CALL <name>]` or `[CALL <kind> <name>]`.
|
|
9
|
+
*
|
|
10
|
+
* Group 1 is the first token and group 2 the optional second token. The
|
|
11
|
+
* scanner requires the two-token form and refuses the bare single-token form,
|
|
12
|
+
* because a bare header names no kind.
|
|
13
|
+
*/
|
|
14
|
+
export declare const CALL_PATTERN: RegExp;
|
|
15
|
+
/**
|
|
16
|
+
* Fail-closed scanner error.
|
|
17
|
+
*
|
|
18
|
+
* Carries the document line number so a caller can point at the offending
|
|
19
|
+
* construct without re-scanning the input.
|
|
20
|
+
*/
|
|
21
|
+
export declare class BrudParseError extends Error {
|
|
22
|
+
readonly code: "PARSE_ERROR";
|
|
23
|
+
/** Absolute 1-based line number in the original document. */
|
|
24
|
+
readonly line: number;
|
|
25
|
+
/**
|
|
26
|
+
* @param message - Human-readable failure description.
|
|
27
|
+
* @param line - Absolute 1-based line number in the original document.
|
|
28
|
+
*/
|
|
29
|
+
constructor(message: string, line: number);
|
|
30
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/** Stable code for every Brud Protocol v2 structural failure. */
|
|
2
|
+
export const BRUD_PARSE_ERROR = 'PARSE_ERROR';
|
|
3
|
+
/** Bare parameter key: `key: value`. */
|
|
4
|
+
export const KEY_PATTERN = /^([A-Za-z_][A-Za-z0-9_]*):\s*(.*)$/;
|
|
5
|
+
/** Own-line brace marker: `{name}` or `{/name}`. */
|
|
6
|
+
export const BRACE_PATTERN = /^\{([^{}]+)\}$/;
|
|
7
|
+
/**
|
|
8
|
+
* Call header: `[CALL <name>]` or `[CALL <kind> <name>]`.
|
|
9
|
+
*
|
|
10
|
+
* Group 1 is the first token and group 2 the optional second token. The
|
|
11
|
+
* scanner requires the two-token form and refuses the bare single-token form,
|
|
12
|
+
* because a bare header names no kind.
|
|
13
|
+
*/
|
|
14
|
+
export const CALL_PATTERN = /^\[CALL\s+([^\s\]]+)(?:\s+([^\s\]]+))?\s*\]$/;
|
|
15
|
+
/**
|
|
16
|
+
* Fail-closed scanner error.
|
|
17
|
+
*
|
|
18
|
+
* Carries the document line number so a caller can point at the offending
|
|
19
|
+
* construct without re-scanning the input.
|
|
20
|
+
*/
|
|
21
|
+
export class BrudParseError extends Error {
|
|
22
|
+
code = BRUD_PARSE_ERROR;
|
|
23
|
+
/** Absolute 1-based line number in the original document. */
|
|
24
|
+
line;
|
|
25
|
+
/**
|
|
26
|
+
* @param message - Human-readable failure description.
|
|
27
|
+
* @param line - Absolute 1-based line number in the original document.
|
|
28
|
+
*/
|
|
29
|
+
constructor(message, line) {
|
|
30
|
+
super(`${message} (line ${String(line)})`);
|
|
31
|
+
this.name = 'BrudParseError';
|
|
32
|
+
this.line = line;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
@@ -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").IBrudParserService, import("./index.js").ParserService>;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import type { BrudOperationKind } from '../../../src/contracts/brudOperation.js';
|
|
2
|
+
import type { BrudOperation } from '../../Parser/contracts/index.js';
|
|
3
|
+
import type { BrudKindInfo, BrudDispatchCaller, BrudRouteOptions, BrudRouteRegistration, BrudRouteResult } from './types.js';
|
|
4
|
+
/**
|
|
5
|
+
* Level-1 Brud kind Router.
|
|
6
|
+
*
|
|
7
|
+
* Accepts boot-time kind registrations from kernel services, resolves the
|
|
8
|
+
* owning service through the kernel access broker with its `ServiceToken`, and
|
|
9
|
+
* dispatches parsed operations. It never routes to a plugin directly.
|
|
10
|
+
*/
|
|
11
|
+
export interface IRouterService {
|
|
12
|
+
/**
|
|
13
|
+
* Claims a kind on behalf of a Level-1 service.
|
|
14
|
+
*
|
|
15
|
+
* @throws RouterRegistrationClosedError when the boot window has closed.
|
|
16
|
+
* @throws RouterInvalidKindError when the kind token is malformed.
|
|
17
|
+
* @throws RouterKindCollisionError when another service already owns it.
|
|
18
|
+
* @throws RouterUnknownServiceError when the token is not registered.
|
|
19
|
+
*/
|
|
20
|
+
register(registration: BrudRouteRegistration): void;
|
|
21
|
+
/** Seals the registration window. Idempotent. */
|
|
22
|
+
closeRegistration(): void;
|
|
23
|
+
/** Whether new kinds may still be claimed. */
|
|
24
|
+
isRegistrationOpen(): boolean;
|
|
25
|
+
/** Kinds currently claimed, in registration order. */
|
|
26
|
+
registeredKinds(): readonly BrudOperationKind[];
|
|
27
|
+
/** Public vocabulary: registered kinds with declared descriptions. */
|
|
28
|
+
kinds(): readonly BrudKindInfo[];
|
|
29
|
+
/**
|
|
30
|
+
* Parses a raw document with `brud.core.parser` and routes every operation.
|
|
31
|
+
*
|
|
32
|
+
* @param rawInput - Raw `[BRUD]` document.
|
|
33
|
+
* @param options - Caller context and routing bounds.
|
|
34
|
+
*/
|
|
35
|
+
route(rawInput: string, options?: BrudRouteOptions, caller?: BrudDispatchCaller): Promise<BrudRouteResult>;
|
|
36
|
+
/**
|
|
37
|
+
* Routes an already-parsed operation list.
|
|
38
|
+
*
|
|
39
|
+
* @param operations - Operations emitted by the Parser.
|
|
40
|
+
* @param options - Caller context and routing bounds.
|
|
41
|
+
*/
|
|
42
|
+
dispatch(operations: readonly BrudOperation[], options?: BrudRouteOptions, caller?: BrudDispatchCaller): Promise<BrudRouteResult>;
|
|
43
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/** Stable, machine-readable codes for Router failures. */
|
|
2
|
+
export type RouterErrorCode = 'ROUTER_REGISTRATION_CLOSED' | 'ROUTER_KIND_COLLISION' | 'ROUTER_INVALID_KIND' | 'ROUTER_UNKNOWN_SERVICE' | 'ROUTER_DISPOSED';
|
|
3
|
+
/** Base class for every Router domain failure. */
|
|
4
|
+
export declare abstract class RouterError extends Error {
|
|
5
|
+
/** Stable, machine-readable error code. */
|
|
6
|
+
abstract readonly code: RouterErrorCode;
|
|
7
|
+
protected constructor(message: string, options?: ErrorOptions);
|
|
8
|
+
}
|
|
9
|
+
/** Raised when a kind is claimed after the boot registration window closed. */
|
|
10
|
+
export declare class RouterRegistrationClosedError extends RouterError {
|
|
11
|
+
readonly code: "ROUTER_REGISTRATION_CLOSED";
|
|
12
|
+
/** Kind the late registrant attempted to claim. */
|
|
13
|
+
readonly kind: string;
|
|
14
|
+
/**
|
|
15
|
+
* @param kind - Kind the late registrant attempted to claim.
|
|
16
|
+
*/
|
|
17
|
+
constructor(kind: string);
|
|
18
|
+
}
|
|
19
|
+
/** Raised when two services claim the same kind. */
|
|
20
|
+
export declare class RouterKindCollisionError extends RouterError {
|
|
21
|
+
readonly code: "ROUTER_KIND_COLLISION";
|
|
22
|
+
/** Contested kind. */
|
|
23
|
+
readonly kind: string;
|
|
24
|
+
/** Token id that already owns the kind. */
|
|
25
|
+
readonly existingTokenId: string;
|
|
26
|
+
/**
|
|
27
|
+
* @param kind - Contested kind.
|
|
28
|
+
* @param existingTokenId - Token id that already owns the kind.
|
|
29
|
+
*/
|
|
30
|
+
constructor(kind: string, existingTokenId: string);
|
|
31
|
+
}
|
|
32
|
+
/** Raised when a registrant supplies a malformed kind token. */
|
|
33
|
+
export declare class RouterInvalidKindError extends RouterError {
|
|
34
|
+
readonly code: "ROUTER_INVALID_KIND";
|
|
35
|
+
/** Rejected value. */
|
|
36
|
+
readonly kind: string;
|
|
37
|
+
/**
|
|
38
|
+
* @param kind - Rejected value.
|
|
39
|
+
*/
|
|
40
|
+
constructor(kind: string);
|
|
41
|
+
}
|
|
42
|
+
/** Raised when a registrant names a service the kernel does not own. */
|
|
43
|
+
export declare class RouterUnknownServiceError extends RouterError {
|
|
44
|
+
readonly code: "ROUTER_UNKNOWN_SERVICE";
|
|
45
|
+
/** Token id that could not be resolved. */
|
|
46
|
+
readonly tokenId: string;
|
|
47
|
+
/**
|
|
48
|
+
* @param tokenId - Token id that could not be resolved.
|
|
49
|
+
*/
|
|
50
|
+
constructor(tokenId: string);
|
|
51
|
+
}
|
|
52
|
+
/** Raised when routing is attempted after disposal. */
|
|
53
|
+
export declare class RouterDisposedError extends RouterError {
|
|
54
|
+
readonly code: "ROUTER_DISPOSED";
|
|
55
|
+
constructor();
|
|
56
|
+
}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
/** Base class for every Router domain failure. */
|
|
2
|
+
export class RouterError extends Error {
|
|
3
|
+
constructor(message, options) {
|
|
4
|
+
super(message, options);
|
|
5
|
+
this.name = 'RouterError';
|
|
6
|
+
}
|
|
7
|
+
}
|
|
8
|
+
/** Raised when a kind is claimed after the boot registration window closed. */
|
|
9
|
+
export class RouterRegistrationClosedError extends RouterError {
|
|
10
|
+
code = 'ROUTER_REGISTRATION_CLOSED';
|
|
11
|
+
/** Kind the late registrant attempted to claim. */
|
|
12
|
+
kind;
|
|
13
|
+
/**
|
|
14
|
+
* @param kind - Kind the late registrant attempted to claim.
|
|
15
|
+
*/
|
|
16
|
+
constructor(kind) {
|
|
17
|
+
super(`Router registration window is closed; kind "${kind}" was rejected`);
|
|
18
|
+
this.name = 'RouterRegistrationClosedError';
|
|
19
|
+
this.kind = kind;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
/** Raised when two services claim the same kind. */
|
|
23
|
+
export class RouterKindCollisionError extends RouterError {
|
|
24
|
+
code = 'ROUTER_KIND_COLLISION';
|
|
25
|
+
/** Contested kind. */
|
|
26
|
+
kind;
|
|
27
|
+
/** Token id that already owns the kind. */
|
|
28
|
+
existingTokenId;
|
|
29
|
+
/**
|
|
30
|
+
* @param kind - Contested kind.
|
|
31
|
+
* @param existingTokenId - Token id that already owns the kind.
|
|
32
|
+
*/
|
|
33
|
+
constructor(kind, existingTokenId) {
|
|
34
|
+
super(`Kind "${kind}" is already claimed by service "${existingTokenId}"`);
|
|
35
|
+
this.name = 'RouterKindCollisionError';
|
|
36
|
+
this.kind = kind;
|
|
37
|
+
this.existingTokenId = existingTokenId;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
/** Raised when a registrant supplies a malformed kind token. */
|
|
41
|
+
export class RouterInvalidKindError extends RouterError {
|
|
42
|
+
code = 'ROUTER_INVALID_KIND';
|
|
43
|
+
/** Rejected value. */
|
|
44
|
+
kind;
|
|
45
|
+
/**
|
|
46
|
+
* @param kind - Rejected value.
|
|
47
|
+
*/
|
|
48
|
+
constructor(kind) {
|
|
49
|
+
super(`Invalid operation kind "${kind}"`);
|
|
50
|
+
this.name = 'RouterInvalidKindError';
|
|
51
|
+
this.kind = kind;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
/** Raised when a registrant names a service the kernel does not own. */
|
|
55
|
+
export class RouterUnknownServiceError extends RouterError {
|
|
56
|
+
code = 'ROUTER_UNKNOWN_SERVICE';
|
|
57
|
+
/** Token id that could not be resolved. */
|
|
58
|
+
tokenId;
|
|
59
|
+
/**
|
|
60
|
+
* @param tokenId - Token id that could not be resolved.
|
|
61
|
+
*/
|
|
62
|
+
constructor(tokenId) {
|
|
63
|
+
super(`Router cannot register a kind for unregistered service "${tokenId}"`);
|
|
64
|
+
this.name = 'RouterUnknownServiceError';
|
|
65
|
+
this.tokenId = tokenId;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
/** Raised when routing is attempted after disposal. */
|
|
69
|
+
export class RouterDisposedError extends RouterError {
|
|
70
|
+
code = 'ROUTER_DISPOSED';
|
|
71
|
+
constructor() {
|
|
72
|
+
super('Brud router has been disposed');
|
|
73
|
+
this.name = 'RouterDisposedError';
|
|
74
|
+
}
|
|
75
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export { ROUTER_CALLER_ID } from './caller.js';
|
|
2
|
+
export { isValidRouterKind } from './kind.js';
|
|
3
|
+
export type { IRouterService } from './IRouterService.js';
|
|
4
|
+
export type { IRouterRegistrant } from './registrant.js';
|
|
5
|
+
export { isRouterRegistrant } from './registrant.js';
|
|
6
|
+
export type { BrudDispatchContext, BrudRouteOptions, BrudRouteRegistration, BrudRouteResult, RouteStatus, RoutedOperationOutcome, RoutedOperationStatus, } from './types.js';
|
|
7
|
+
export type { RouterErrorCode } from './errors.js';
|
|
8
|
+
export { RouterDisposedError, RouterError, RouterInvalidKindError, RouterKindCollisionError, RouterRegistrationClosedError, RouterUnknownServiceError, } from './errors.js';
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { ROUTER_CALLER_ID } from './caller.js';
|
|
2
|
+
export { isValidRouterKind } from './kind.js';
|
|
3
|
+
export { isRouterRegistrant } from './registrant.js';
|
|
4
|
+
export { RouterDisposedError, RouterError, RouterInvalidKindError, RouterKindCollisionError, RouterRegistrationClosedError, RouterUnknownServiceError, } from './errors.js';
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Validates a kind token claimed during the registration window.
|
|
3
|
+
*
|
|
4
|
+
* The shape is the kernel's open kind mechanism. The boot-time claim and the
|
|
5
|
+
* refusal it produces belong to this package.
|
|
6
|
+
*/
|
|
7
|
+
export declare function isValidRouterKind(value: string): boolean;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { BRUD_KIND_PATTERN } from '../../../src/contracts/brudOperation.js';
|
|
2
|
+
/**
|
|
3
|
+
* Validates a kind token claimed during the registration window.
|
|
4
|
+
*
|
|
5
|
+
* The shape is the kernel's open kind mechanism. The boot-time claim and the
|
|
6
|
+
* refusal it produces belong to this package.
|
|
7
|
+
*/
|
|
8
|
+
export function isValidRouterKind(value) {
|
|
9
|
+
return BRUD_KIND_PATTERN.test(value);
|
|
10
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { IRouterService } from './IRouterService.js';
|
|
2
|
+
/**
|
|
3
|
+
* Implemented by a Level-1 service that wants to claim a kind at boot.
|
|
4
|
+
*
|
|
5
|
+
* The standard composition calls the hook while the kernel is still BOOTING
|
|
6
|
+
* and the access broker's lifecycle gate is suspended, before the router
|
|
7
|
+
* seals its registration window.
|
|
8
|
+
*/
|
|
9
|
+
export interface IRouterRegistrant {
|
|
10
|
+
/**
|
|
11
|
+
* Claims one or more kinds on the router.
|
|
12
|
+
*
|
|
13
|
+
* @param router - Router accepting boot-time registrations.
|
|
14
|
+
*/
|
|
15
|
+
registerWithRouter(router: IRouterService): void;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Narrows an unknown initialized service to {@link IRouterRegistrant}.
|
|
19
|
+
*
|
|
20
|
+
* @param value - Constructed kernel service.
|
|
21
|
+
* @returns `true` when the service declares {@link IRouterRegistrant}.
|
|
22
|
+
*/
|
|
23
|
+
export declare function isRouterRegistrant(value: unknown): value is IRouterRegistrant;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Narrows an unknown initialized service to {@link IRouterRegistrant}.
|
|
3
|
+
*
|
|
4
|
+
* @param value - Constructed kernel service.
|
|
5
|
+
* @returns `true` when the service declares {@link IRouterRegistrant}.
|
|
6
|
+
*/
|
|
7
|
+
export function isRouterRegistrant(value) {
|
|
8
|
+
if (value === null || typeof value !== 'object') {
|
|
9
|
+
return false;
|
|
10
|
+
}
|
|
11
|
+
return typeof value.registerWithRouter
|
|
12
|
+
=== 'function';
|
|
13
|
+
}
|