@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.
Files changed (286) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +63 -2
  3. package/dist/index.d.ts +15 -0
  4. package/dist/index.js +13 -0
  5. package/dist/serviceModules/events.d.ts +1 -0
  6. package/dist/serviceModules/events.js +1 -0
  7. package/dist/serviceModules/exposedApiRegistry.d.ts +1 -0
  8. package/dist/serviceModules/exposedApiRegistry.js +1 -0
  9. package/dist/serviceModules/identityRegistry.d.ts +1 -0
  10. package/dist/serviceModules/identityRegistry.js +1 -0
  11. package/dist/serviceModules/interception.d.ts +1 -0
  12. package/dist/serviceModules/interception.js +1 -0
  13. package/dist/serviceModules/parser.d.ts +1 -0
  14. package/dist/serviceModules/parser.js +1 -0
  15. package/dist/serviceModules/router.d.ts +1 -0
  16. package/dist/serviceModules/router.js +1 -0
  17. package/dist/serviceModules/wasmCage.d.ts +1 -0
  18. package/dist/serviceModules/wasmCage.js +1 -0
  19. package/dist/services/Events/contracts/IEventsService.d.ts +64 -0
  20. package/dist/services/Events/contracts/IEventsService.js +1 -0
  21. package/dist/services/Events/contracts/errors.d.ts +31 -0
  22. package/dist/services/Events/contracts/errors.js +40 -0
  23. package/dist/services/Events/contracts/index.d.ts +3 -0
  24. package/dist/services/Events/contracts/index.js +3 -0
  25. package/dist/services/Events/contracts/tokens.d.ts +2 -0
  26. package/dist/services/Events/contracts/tokens.js +2 -0
  27. package/dist/services/Events/descriptor/EventsDescriptor.d.ts +9 -0
  28. package/dist/services/Events/descriptor/EventsDescriptor.js +56 -0
  29. package/dist/services/Events/descriptor/tokens.d.ts +1 -0
  30. package/dist/services/Events/descriptor/tokens.js +1 -0
  31. package/dist/services/Events/index.d.ts +4 -0
  32. package/dist/services/Events/index.js +4 -0
  33. package/dist/services/Events/orchestrator/EventsService.d.ts +51 -0
  34. package/dist/services/Events/orchestrator/EventsService.js +339 -0
  35. package/dist/services/Events/orchestrator/index.d.ts +2 -0
  36. package/dist/services/Events/orchestrator/index.js +2 -0
  37. package/dist/services/Events/orchestrator/limits.d.ts +22 -0
  38. package/dist/services/Events/orchestrator/limits.js +33 -0
  39. package/dist/services/Events/serviceModule.d.ts +2 -0
  40. package/dist/services/Events/serviceModule.js +5 -0
  41. package/dist/services/ExposedApiRegistry/contracts/IExposedApiRegistry.d.ts +56 -0
  42. package/dist/services/ExposedApiRegistry/contracts/IExposedApiRegistry.js +1 -0
  43. package/dist/services/ExposedApiRegistry/contracts/errors.d.ts +132 -0
  44. package/dist/services/ExposedApiRegistry/contracts/errors.js +195 -0
  45. package/dist/services/ExposedApiRegistry/contracts/index.d.ts +9 -0
  46. package/dist/services/ExposedApiRegistry/contracts/index.js +4 -0
  47. package/dist/services/ExposedApiRegistry/contracts/policy.d.ts +90 -0
  48. package/dist/services/ExposedApiRegistry/contracts/policy.js +169 -0
  49. package/dist/services/ExposedApiRegistry/contracts/registrant.d.ts +37 -0
  50. package/dist/services/ExposedApiRegistry/contracts/registrant.js +36 -0
  51. package/dist/services/ExposedApiRegistry/contracts/types.d.ts +133 -0
  52. package/dist/services/ExposedApiRegistry/contracts/types.js +73 -0
  53. package/dist/services/ExposedApiRegistry/descriptor/ExposedApiRegistryDescriptor.d.ts +44 -0
  54. package/dist/services/ExposedApiRegistry/descriptor/ExposedApiRegistryDescriptor.js +58 -0
  55. package/dist/services/ExposedApiRegistry/descriptor/tokens.d.ts +8 -0
  56. package/dist/services/ExposedApiRegistry/descriptor/tokens.js +8 -0
  57. package/dist/services/ExposedApiRegistry/index.d.ts +6 -0
  58. package/dist/services/ExposedApiRegistry/index.js +5 -0
  59. package/dist/services/ExposedApiRegistry/orchestrator/ExposedApiRegistryService.d.ts +68 -0
  60. package/dist/services/ExposedApiRegistry/orchestrator/ExposedApiRegistryService.js +452 -0
  61. package/dist/services/ExposedApiRegistry/orchestrator/index.d.ts +2 -0
  62. package/dist/services/ExposedApiRegistry/orchestrator/index.js +1 -0
  63. package/dist/services/ExposedApiRegistry/serviceModule.d.ts +10 -0
  64. package/dist/services/ExposedApiRegistry/serviceModule.js +20 -0
  65. package/dist/services/ExposedApiRegistry/storage/protection.d.ts +21 -0
  66. package/dist/services/ExposedApiRegistry/storage/protection.js +35 -0
  67. package/dist/services/ExposedApiRegistry/storage/scopeRecord.d.ts +45 -0
  68. package/dist/services/ExposedApiRegistry/storage/scopeRecord.js +178 -0
  69. package/dist/services/IdentityRegistry/contracts/errors.d.ts +88 -0
  70. package/dist/services/IdentityRegistry/contracts/errors.js +128 -0
  71. package/dist/services/IdentityRegistry/contracts/index.d.ts +5 -0
  72. package/dist/services/IdentityRegistry/contracts/index.js +3 -0
  73. package/dist/services/IdentityRegistry/contracts/types.d.ts +77 -0
  74. package/dist/services/IdentityRegistry/contracts/types.js +18 -0
  75. package/dist/services/IdentityRegistry/descriptor/descriptor.d.ts +36 -0
  76. package/dist/services/IdentityRegistry/descriptor/descriptor.js +44 -0
  77. package/dist/services/IdentityRegistry/descriptor/tokens.d.ts +8 -0
  78. package/dist/services/IdentityRegistry/descriptor/tokens.js +8 -0
  79. package/dist/services/IdentityRegistry/index.d.ts +11 -0
  80. package/dist/services/IdentityRegistry/index.js +6 -0
  81. package/dist/services/IdentityRegistry/orchestrator/IdentityRegistryService.d.ts +47 -0
  82. package/dist/services/IdentityRegistry/orchestrator/IdentityRegistryService.js +240 -0
  83. package/dist/services/IdentityRegistry/serviceModule.d.ts +10 -0
  84. package/dist/services/IdentityRegistry/serviceModule.js +24 -0
  85. package/dist/services/IdentityRegistry/storage/registryDocument.d.ts +55 -0
  86. package/dist/services/IdentityRegistry/storage/registryDocument.js +235 -0
  87. package/dist/services/Interception/contracts/IInterceptionService.d.ts +155 -0
  88. package/dist/services/Interception/contracts/IInterceptionService.js +12 -0
  89. package/dist/services/Interception/contracts/errors.d.ts +26 -0
  90. package/dist/services/Interception/contracts/errors.js +35 -0
  91. package/dist/services/Interception/contracts/index.d.ts +3 -0
  92. package/dist/services/Interception/contracts/index.js +3 -0
  93. package/dist/services/Interception/contracts/tokens.d.ts +2 -0
  94. package/dist/services/Interception/contracts/tokens.js +2 -0
  95. package/dist/services/Interception/descriptor/InterceptionDescriptor.d.ts +9 -0
  96. package/dist/services/Interception/descriptor/InterceptionDescriptor.js +50 -0
  97. package/dist/services/Interception/descriptor/tokens.d.ts +1 -0
  98. package/dist/services/Interception/descriptor/tokens.js +1 -0
  99. package/dist/services/Interception/index.d.ts +4 -0
  100. package/dist/services/Interception/index.js +4 -0
  101. package/dist/services/Interception/orchestrator/InterceptionService.d.ts +40 -0
  102. package/dist/services/Interception/orchestrator/InterceptionService.js +343 -0
  103. package/dist/services/Interception/orchestrator/index.d.ts +1 -0
  104. package/dist/services/Interception/orchestrator/index.js +1 -0
  105. package/dist/services/Interception/serviceModule.d.ts +2 -0
  106. package/dist/services/Interception/serviceModule.js +5 -0
  107. package/dist/services/Parser/contracts/IParserService.d.ts +21 -0
  108. package/dist/services/Parser/contracts/IParserService.js +1 -0
  109. package/dist/services/Parser/contracts/errors.d.ts +25 -0
  110. package/dist/services/Parser/contracts/errors.js +33 -0
  111. package/dist/services/Parser/contracts/index.d.ts +4 -0
  112. package/dist/services/Parser/contracts/index.js +1 -0
  113. package/dist/services/Parser/contracts/types.d.ts +42 -0
  114. package/dist/services/Parser/contracts/types.js +1 -0
  115. package/dist/services/Parser/descriptor/ParserDescriptor.d.ts +23 -0
  116. package/dist/services/Parser/descriptor/ParserDescriptor.js +50 -0
  117. package/dist/services/Parser/descriptor/tokens.d.ts +8 -0
  118. package/dist/services/Parser/descriptor/tokens.js +8 -0
  119. package/dist/services/Parser/index.d.ts +8 -0
  120. package/dist/services/Parser/index.js +8 -0
  121. package/dist/services/Parser/orchestrator/ParserService.d.ts +20 -0
  122. package/dist/services/Parser/orchestrator/ParserService.js +105 -0
  123. package/dist/services/Parser/orchestrator/index.d.ts +1 -0
  124. package/dist/services/Parser/orchestrator/index.js +1 -0
  125. package/dist/services/Parser/parser/indexSynthesis.d.ts +11 -0
  126. package/dist/services/Parser/parser/indexSynthesis.js +13 -0
  127. package/dist/services/Parser/parser/parameters.d.ts +14 -0
  128. package/dist/services/Parser/parser/parameters.js +89 -0
  129. package/dist/services/Parser/parser/scanner.d.ts +48 -0
  130. package/dist/services/Parser/parser/scanner.js +156 -0
  131. package/dist/services/Parser/parser/syntax.d.ts +30 -0
  132. package/dist/services/Parser/parser/syntax.js +34 -0
  133. package/dist/services/Parser/serviceModule.d.ts +2 -0
  134. package/dist/services/Parser/serviceModule.js +5 -0
  135. package/dist/services/Router/bootOptions.d.ts +2 -0
  136. package/dist/services/Router/bootOptions.js +2 -0
  137. package/dist/services/Router/contracts/IRouterService.d.ts +43 -0
  138. package/dist/services/Router/contracts/IRouterService.js +1 -0
  139. package/dist/services/Router/contracts/caller.d.ts +6 -0
  140. package/dist/services/Router/contracts/caller.js +6 -0
  141. package/dist/services/Router/contracts/errors.d.ts +67 -0
  142. package/dist/services/Router/contracts/errors.js +90 -0
  143. package/dist/services/Router/contracts/index.d.ts +8 -0
  144. package/dist/services/Router/contracts/index.js +4 -0
  145. package/dist/services/Router/contracts/kind.d.ts +7 -0
  146. package/dist/services/Router/contracts/kind.js +10 -0
  147. package/dist/services/Router/contracts/registrant.d.ts +23 -0
  148. package/dist/services/Router/contracts/registrant.js +13 -0
  149. package/dist/services/Router/contracts/types.d.ts +110 -0
  150. package/dist/services/Router/contracts/types.js +1 -0
  151. package/dist/services/Router/descriptor/RouterDescriptor.d.ts +32 -0
  152. package/dist/services/Router/descriptor/RouterDescriptor.js +92 -0
  153. package/dist/services/Router/descriptor/tokens.d.ts +9 -0
  154. package/dist/services/Router/descriptor/tokens.js +9 -0
  155. package/dist/services/Router/index.d.ts +4 -0
  156. package/dist/services/Router/index.js +4 -0
  157. package/dist/services/Router/orchestrator/RouterService.d.ts +93 -0
  158. package/dist/services/Router/orchestrator/RouterService.js +457 -0
  159. package/dist/services/Router/orchestrator/index.d.ts +2 -0
  160. package/dist/services/Router/orchestrator/index.js +1 -0
  161. package/dist/services/Router/serviceModule.d.ts +4 -0
  162. package/dist/services/Router/serviceModule.js +22 -0
  163. package/dist/services/WasmCage/index.d.ts +7 -0
  164. package/dist/services/WasmCage/index.js +4 -0
  165. package/dist/services/WasmCage/scripts/prepin.d.ts +1 -0
  166. package/dist/services/WasmCage/scripts/prepin.js +38 -0
  167. package/dist/services/WasmCage/serviceModule.d.ts +12 -0
  168. package/dist/services/WasmCage/serviceModule.js +18 -0
  169. package/dist/services/WasmCage/src/caged.d.ts +121 -0
  170. package/dist/services/WasmCage/src/caged.js +460 -0
  171. package/dist/services/WasmCage/src/descriptor.d.ts +47 -0
  172. package/dist/services/WasmCage/src/descriptor.js +56 -0
  173. package/dist/services/WasmCage/src/native.d.ts +29 -0
  174. package/dist/services/WasmCage/src/native.js +66 -0
  175. package/dist/services/WasmCage/src/nativeDigests.d.ts +9 -0
  176. package/dist/services/WasmCage/src/nativeDigests.js +15 -0
  177. package/dist/services/WasmCage/src/package.d.ts +36 -0
  178. package/dist/services/WasmCage/src/package.js +122 -0
  179. package/dist/services/shared/canonicalJson.d.ts +29 -0
  180. package/dist/services/shared/canonicalJson.js +93 -0
  181. package/dist/services/shared/documentStore.d.ts +16 -0
  182. package/dist/services/shared/documentStore.js +98 -0
  183. package/dist/src/bootstrap/bootKernelInternal.d.ts +19 -0
  184. package/dist/src/bootstrap/bootKernelInternal.js +633 -0
  185. package/dist/src/bootstrap/bootTypes.d.ts +113 -0
  186. package/dist/src/bootstrap/bootTypes.js +1 -0
  187. package/dist/src/bootstrap/config/index.d.ts +3 -0
  188. package/dist/src/bootstrap/config/index.js +2 -0
  189. package/dist/src/bootstrap/config/integrity.d.ts +45 -0
  190. package/dist/src/bootstrap/config/integrity.js +92 -0
  191. package/dist/src/bootstrap/config/parse.d.ts +15 -0
  192. package/dist/src/bootstrap/config/parse.js +81 -0
  193. package/dist/src/bootstrap/config/pathWriteGuard.d.ts +20 -0
  194. package/dist/src/bootstrap/config/pathWriteGuard.js +349 -0
  195. package/dist/src/bootstrap/config/types.d.ts +41 -0
  196. package/dist/src/bootstrap/config/types.js +15 -0
  197. package/dist/src/bootstrap/hardcore.d.ts +212 -0
  198. package/dist/src/bootstrap/hardcore.js +312 -0
  199. package/dist/src/bootstrap/hardcoreServices.d.ts +10 -0
  200. package/dist/src/bootstrap/hardcoreServices.js +258 -0
  201. package/dist/src/bootstrap/index.d.ts +13 -0
  202. package/dist/src/bootstrap/index.js +7 -0
  203. package/dist/src/bootstrap/loaded.d.ts +30 -0
  204. package/dist/src/bootstrap/loaded.js +45 -0
  205. package/dist/src/bootstrap/packageRequirements.d.ts +26 -0
  206. package/dist/src/bootstrap/packageRequirements.js +52 -0
  207. package/dist/src/bootstrap/reload.d.ts +44 -0
  208. package/dist/src/bootstrap/reload.js +45 -0
  209. package/dist/src/bootstrap/seal.d.ts +32 -0
  210. package/dist/src/bootstrap/seal.js +101 -0
  211. package/dist/src/contracts/accessBroker.d.ts +53 -0
  212. package/dist/src/contracts/accessBroker.js +1 -0
  213. package/dist/src/contracts/brudOperation.d.ts +20 -0
  214. package/dist/src/contracts/brudOperation.js +20 -0
  215. package/dist/src/contracts/callChain.d.ts +161 -0
  216. package/dist/src/contracts/callChain.js +19 -0
  217. package/dist/src/contracts/capability.d.ts +26 -0
  218. package/dist/src/contracts/capability.js +26 -0
  219. package/dist/src/contracts/capabilitySet.d.ts +23 -0
  220. package/dist/src/contracts/capabilitySet.js +72 -0
  221. package/dist/src/contracts/container.d.ts +17 -0
  222. package/dist/src/contracts/container.js +8 -0
  223. package/dist/src/contracts/context.d.ts +19 -0
  224. package/dist/src/contracts/context.js +1 -0
  225. package/dist/src/contracts/contextContract.d.ts +132 -0
  226. package/dist/src/contracts/contextContract.js +274 -0
  227. package/dist/src/contracts/dispatchView.d.ts +21 -0
  228. package/dist/src/contracts/dispatchView.js +1 -0
  229. package/dist/src/contracts/handler.d.ts +21 -0
  230. package/dist/src/contracts/handler.js +1 -0
  231. package/dist/src/contracts/index.d.ts +26 -0
  232. package/dist/src/contracts/index.js +9 -0
  233. package/dist/src/contracts/kernel.d.ts +60 -0
  234. package/dist/src/contracts/kernel.js +1 -0
  235. package/dist/src/contracts/lifecycle.d.ts +59 -0
  236. package/dist/src/contracts/lifecycle.js +1 -0
  237. package/dist/src/contracts/manifest.d.ts +180 -0
  238. package/dist/src/contracts/manifest.js +334 -0
  239. package/dist/src/contracts/pipeline.d.ts +8 -0
  240. package/dist/src/contracts/pipeline.js +1 -0
  241. package/dist/src/contracts/policy.d.ts +75 -0
  242. package/dist/src/contracts/policy.js +77 -0
  243. package/dist/src/contracts/registry.d.ts +7 -0
  244. package/dist/src/contracts/registry.js +1 -0
  245. package/dist/src/contracts/serviceDescriptor.d.ts +67 -0
  246. package/dist/src/contracts/serviceDescriptor.js +1 -0
  247. package/dist/src/contracts/serviceToken.d.ts +36 -0
  248. package/dist/src/contracts/serviceToken.js +16 -0
  249. package/dist/src/engine/BrudKernel.d.ts +120 -0
  250. package/dist/src/engine/BrudKernel.js +395 -0
  251. package/dist/src/engine/ExecutionPipeline.d.ts +13 -0
  252. package/dist/src/engine/ExecutionPipeline.js +62 -0
  253. package/dist/src/engine/KernelAccessBroker.d.ts +47 -0
  254. package/dist/src/engine/KernelAccessBroker.js +107 -0
  255. package/dist/src/engine/KernelRegistry.d.ts +14 -0
  256. package/dist/src/engine/KernelRegistry.js +33 -0
  257. package/dist/src/engine/OperationRegistry.d.ts +9 -0
  258. package/dist/src/engine/OperationRegistry.js +18 -0
  259. package/dist/src/engine/ServiceContainer.d.ts +13 -0
  260. package/dist/src/engine/ServiceContainer.js +53 -0
  261. package/dist/src/engine/callChain.d.ts +68 -0
  262. package/dist/src/engine/callChain.js +175 -0
  263. package/dist/src/engine/dag.d.ts +2 -0
  264. package/dist/src/engine/dag.js +34 -0
  265. package/dist/src/engine/errors.d.ts +26 -0
  266. package/dist/src/engine/errors.js +52 -0
  267. package/dist/src/engine/index.d.ts +11 -0
  268. package/dist/src/engine/index.js +8 -0
  269. package/dist/src/engine/state.d.ts +1 -0
  270. package/dist/src/engine/state.js +1 -0
  271. package/dist/src/validation/jsonSchema/compile.d.ts +8 -0
  272. package/dist/src/validation/jsonSchema/compile.js +386 -0
  273. package/dist/src/validation/jsonSchema/index.d.ts +3 -0
  274. package/dist/src/validation/jsonSchema/index.js +2 -0
  275. package/dist/src/validation/jsonSchema/jsonValue.d.ts +29 -0
  276. package/dist/src/validation/jsonSchema/jsonValue.js +190 -0
  277. package/dist/src/validation/jsonSchema/pattern.d.ts +28 -0
  278. package/dist/src/validation/jsonSchema/pattern.js +155 -0
  279. package/dist/src/validation/jsonSchema/types.d.ts +71 -0
  280. package/dist/src/validation/jsonSchema/types.js +15 -0
  281. package/package.json +59 -4
  282. package/services/WasmCage/native/brud-wasm-cage.darwin-arm64.node +0 -0
  283. package/services/WasmCage/native/brud-wasm-cage.darwin-x64.node +0 -0
  284. package/services/WasmCage/native/brud-wasm-cage.linux-arm64-gnu.node +0 -0
  285. package/services/WasmCage/native/brud-wasm-cage.linux-x64-gnu.node +0 -0
  286. package/services/WasmCage/native/brud-wasm-cage.win32-x64-msvc.node +0 -0
@@ -0,0 +1,90 @@
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 a kind's operations or permissions are missing or invalid. Refuses boot. */
23
+ export class RouterInvalidDeclarationError extends RouterError {
24
+ code = 'ROUTER_INVALID_DECLARATION';
25
+ /** Kind whose declaration was refused. */
26
+ kind;
27
+ /**
28
+ * @param kind - Kind whose declaration was refused.
29
+ * @param reason - What is wrong with it.
30
+ */
31
+ constructor(kind, reason) {
32
+ super(`Kind "${kind}" declaration refused: ${reason}`);
33
+ this.name = 'RouterInvalidDeclarationError';
34
+ this.kind = kind;
35
+ }
36
+ }
37
+ /** Raised when two services claim the same kind. */
38
+ export class RouterKindCollisionError extends RouterError {
39
+ code = 'ROUTER_KIND_COLLISION';
40
+ /** Contested kind. */
41
+ kind;
42
+ /** Token id that already owns the kind. */
43
+ existingTokenId;
44
+ /**
45
+ * @param kind - Contested kind.
46
+ * @param existingTokenId - Token id that already owns the kind.
47
+ */
48
+ constructor(kind, existingTokenId) {
49
+ super(`Kind "${kind}" is already claimed by service "${existingTokenId}"`);
50
+ this.name = 'RouterKindCollisionError';
51
+ this.kind = kind;
52
+ this.existingTokenId = existingTokenId;
53
+ }
54
+ }
55
+ /** Raised when a registrant supplies a malformed kind token. */
56
+ export class RouterInvalidKindError extends RouterError {
57
+ code = 'ROUTER_INVALID_KIND';
58
+ /** Rejected value. */
59
+ kind;
60
+ /**
61
+ * @param kind - Rejected value.
62
+ */
63
+ constructor(kind) {
64
+ super(`Invalid operation kind "${kind}"`);
65
+ this.name = 'RouterInvalidKindError';
66
+ this.kind = kind;
67
+ }
68
+ }
69
+ /** Raised when a registrant names a service the kernel does not own. */
70
+ export class RouterUnknownServiceError extends RouterError {
71
+ code = 'ROUTER_UNKNOWN_SERVICE';
72
+ /** Token id that could not be resolved. */
73
+ tokenId;
74
+ /**
75
+ * @param tokenId - Token id that could not be resolved.
76
+ */
77
+ constructor(tokenId) {
78
+ super(`Router cannot register a kind for unregistered service "${tokenId}"`);
79
+ this.name = 'RouterUnknownServiceError';
80
+ this.tokenId = tokenId;
81
+ }
82
+ }
83
+ /** Raised when routing is attempted after disposal. */
84
+ export class RouterDisposedError extends RouterError {
85
+ code = 'ROUTER_DISPOSED';
86
+ constructor() {
87
+ super('Brud router has been disposed');
88
+ this.name = 'RouterDisposedError';
89
+ }
90
+ }
@@ -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, BrudKindOperation, BrudPublicKindOperation, BrudRouteOptions, BrudRouteRegistration, BrudRouteResult, RouteStatus, RoutedOperationOutcome, RoutedOperationStatus, } from './types.js';
7
+ export type { RouterErrorCode } from './errors.js';
8
+ export { RouterDisposedError, RouterError, RouterInvalidDeclarationError, 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, RouterInvalidDeclarationError, 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
+ }
@@ -0,0 +1,110 @@
1
+ import type { BrudOperationKind } from '../../../src/contracts/brudOperation.js';
2
+ import type { OperationResult } from '../../../src/contracts/handler.js';
3
+ import type { BrudOperation, BrudParseFailure } from '../../Parser/contracts/index.js';
4
+ /** Terminal status of one routed operation. */
5
+ export type RoutedOperationStatus = 'success' | 'failed' | 'skipped' | 'aborted' | 'kind_not_registered' | 'operation_not_declared' | 'permission_denied';
6
+ /**
7
+ * The real caller of a routed operation, captured by the Router from the
8
+ * kernel call chain (delegation by the owner). Never supplied by the caller.
9
+ */
10
+ export interface BrudDispatchCaller {
11
+ readonly identity: string | null;
12
+ readonly callerClass: string;
13
+ readonly official: boolean;
14
+ readonly capabilities: ReadonlySet<string>;
15
+ readonly origin: string;
16
+ }
17
+ /** Context handed to a kind owner's dispatch exposure for one operation. */
18
+ export interface BrudDispatchContext {
19
+ /** Kernel-derived caller of the route request. */
20
+ readonly caller: BrudDispatchCaller;
21
+ /** Cancellation signal, when the transport supplied one. */
22
+ readonly signal?: AbortSignal;
23
+ /** Validate only; do not execute. */
24
+ readonly dryRun?: boolean;
25
+ }
26
+ /**
27
+ * Options for one route request. Caller identity and capabilities are not
28
+ * options: the Router takes them from the kernel call chain.
29
+ */
30
+ export interface BrudRouteOptions {
31
+ readonly signal?: AbortSignal;
32
+ readonly stopOnFailure?: boolean;
33
+ readonly dryRun?: boolean;
34
+ readonly maxOperations?: number;
35
+ }
36
+ /** Outcome of routing one parsed operation. */
37
+ export interface RoutedOperationOutcome {
38
+ /** Synthesized 1-based document index. */
39
+ readonly operationIndex: string;
40
+ /** Zero-based document position. */
41
+ readonly sequence: number;
42
+ /** Shared kind token. */
43
+ readonly kind: BrudOperationKind;
44
+ /** Operation name written on the header. */
45
+ readonly name: string;
46
+ /** Terminal status of this operation. */
47
+ readonly status: RoutedOperationStatus;
48
+ /** Target result, when a target ran. */
49
+ readonly result?: OperationResult;
50
+ /** Diagnostic message for routing-level failures. */
51
+ readonly error?: string;
52
+ }
53
+ /** Aggregate status of a routed document. */
54
+ export type RouteStatus = 'success' | 'partial' | 'failed' | 'empty';
55
+ /** Result of parsing and routing one document. */
56
+ export interface BrudRouteResult {
57
+ readonly status: RouteStatus;
58
+ readonly operations: readonly RoutedOperationOutcome[];
59
+ readonly parseError?: BrudParseFailure;
60
+ readonly dispatched: number;
61
+ readonly failed: number;
62
+ }
63
+ /**
64
+ * A kind and the exposure that dispatches it, registered at boot. Each
65
+ * operation is dispatched through that exposure, which is looked up on the
66
+ * kernel call chain.
67
+ */
68
+ export interface BrudRouteRegistration {
69
+ readonly kind: BrudOperationKind;
70
+ /** Name of the owner's dispatch exposure (`name`, major `version`). */
71
+ readonly exposure: string;
72
+ readonly version?: number;
73
+ /** Public description declared with the kind. */
74
+ readonly description?: string;
75
+ /**
76
+ * Every operation the kind serves. Required: an operation not listed here is
77
+ * refused before the owner is reached.
78
+ */
79
+ readonly operations: Readonly<Record<string, BrudKindOperation>> | 'open';
80
+ /**
81
+ * Default permission for operations that declare none (a Layer 1 policy
82
+ * object). Required when `operations` is `'open'`: the owner defines the
83
+ * names, and this permission is enforced on every call.
84
+ */
85
+ readonly permission?: Readonly<Record<string, unknown>>;
86
+ }
87
+ /** One declared operation of a kind. */
88
+ export interface BrudKindOperation {
89
+ readonly description?: string;
90
+ readonly input?: Readonly<Record<string, unknown>>;
91
+ /** Who may call it (a Layer 1 policy object). Falls back to the kind's. */
92
+ readonly permission?: Readonly<Record<string, unknown>>;
93
+ }
94
+ /** One operation as remote clients see it. The permission is not public. */
95
+ export interface BrudPublicKindOperation {
96
+ readonly description?: string;
97
+ readonly input?: Readonly<Record<string, unknown>>;
98
+ }
99
+ /** One kind as remote clients see it: the public vocabulary of Brud syntax. */
100
+ export interface BrudKindInfo {
101
+ readonly kind: BrudOperationKind;
102
+ readonly description?: string;
103
+ readonly operations?: Readonly<Record<string, BrudPublicKindOperation>>;
104
+ /** True when the owner defines the operation names itself, so none are listed. */
105
+ readonly open?: true;
106
+ }
107
+ /** The surface a kind owner's dispatch exposure must provide. */
108
+ export interface BrudKindDispatcher {
109
+ dispatch(operation: BrudOperation, context: BrudDispatchContext): Promise<OperationResult> | OperationResult;
110
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,32 @@
1
+ import type { ServiceTier } from '../../../src/contracts/lifecycle.js';
2
+ import type { ServiceDescriptor } from '../../../src/contracts/serviceDescriptor.js';
3
+ import type { IBrudParserService } from '../../Parser/contracts/IParserService.js';
4
+ import type { IRouterService } from '../contracts/IRouterService.js';
5
+ import { RouterService } from '../orchestrator/index.js';
6
+ /** The Router's v1 entry exposure. */
7
+ export declare const ROUTER_EXPOSURE = "syntax.route";
8
+ /** Tier assigned to the Router descriptor. */
9
+ export declare const ROUTER_SERVICE_TIER: ServiceTier;
10
+ /** Contract version declared for the Router interface. */
11
+ export declare const ROUTER_CONTRACT_VERSION = "2.0.0";
12
+ /** Methods declared for the Router interface. */
13
+ export declare const ROUTER_CONTRACT_METHODS: readonly ["register", "closeRegistration", "isRegistrationOpen", "registeredKinds", "kinds", "route", "dispatch"];
14
+ /** Configuration for {@link createRouterDescriptor}. */
15
+ export interface RouterDescriptorOptions {
16
+ /** Parser override for standalone construction and tests. */
17
+ readonly parser?: IBrudParserService;
18
+ /** Observation hook used by the standard composition to capture the instance. */
19
+ readonly onConstruct?: (service: RouterService) => void;
20
+ }
21
+ /**
22
+ * Builds the `brud.core.router` service descriptor.
23
+ *
24
+ * It declares the syntax service token as an ordering dependency. The syntax
25
+ * service is resolved lazily through the broker on the first `route` call,
26
+ * because the broker serves requests only once the kernel is RUNNING.
27
+ *
28
+ * @param options - Parser override and construction hook.
29
+ * @returns A core-tier descriptor for `brud.core.router`.
30
+ */
31
+ export declare function createRouterDescriptor(options?: RouterDescriptorOptions): ServiceDescriptor<IRouterService, RouterService>;
32
+ export declare const RouterDescriptor: ServiceDescriptor<IRouterService, RouterService>;
@@ -0,0 +1,92 @@
1
+ import { ParserToken } from '../../Parser/descriptor/tokens.js';
2
+ import { ROUTER_CALLER_ID } from '../contracts/caller.js';
3
+ import { RouterService } from '../orchestrator/index.js';
4
+ import { RouterToken } from './tokens.js';
5
+ import { withExposureBindings } from '../../ExposedApiRegistry/contracts/registrant.js';
6
+ import { ExposedApiRegistryToken } from '../../ExposedApiRegistry/descriptor/tokens.js';
7
+ /** The Router's v1 entry exposure. */
8
+ export const ROUTER_EXPOSURE = 'syntax.route';
9
+ /** Tier assigned to the Router descriptor. */
10
+ export const ROUTER_SERVICE_TIER = 'core';
11
+ /** Contract version declared for the Router interface. */
12
+ export const ROUTER_CONTRACT_VERSION = '2.0.0';
13
+ /** Methods declared for the Router interface. */
14
+ export const ROUTER_CONTRACT_METHODS = [
15
+ 'register',
16
+ 'closeRegistration',
17
+ 'isRegistrationOpen',
18
+ 'registeredKinds',
19
+ 'kinds',
20
+ 'route',
21
+ 'dispatch',
22
+ ];
23
+ /**
24
+ * Builds the `brud.core.router` service descriptor.
25
+ *
26
+ * It declares the syntax service token as an ordering dependency. The syntax
27
+ * service is resolved lazily through the broker on the first `route` call,
28
+ * because the broker serves requests only once the kernel is RUNNING.
29
+ *
30
+ * @param options - Parser override and construction hook.
31
+ * @returns A core-tier descriptor for `brud.core.router`.
32
+ */
33
+ export function createRouterDescriptor(options) {
34
+ return {
35
+ token: RouterToken,
36
+ tier: ROUTER_SERVICE_TIER,
37
+ dependencies: [ParserToken],
38
+ contract: {
39
+ version: ROUTER_CONTRACT_VERSION,
40
+ methods: ROUTER_CONTRACT_METHODS,
41
+ },
42
+ // Token access is kernel-internal. Every other caller enters through the
43
+ // `syntax.route@1` exposure, where the caller comes from the call chain.
44
+ accessPolicy: {
45
+ allowedCallers: ['kernel', ROUTER_CALLER_ID],
46
+ },
47
+ manifest: {
48
+ exposures: [{ name: ROUTER_EXPOSURE, version: 1, scope: 'any' }],
49
+ },
50
+ factory: (context, broker) => {
51
+ const callerContext = {
52
+ callerId: ROUTER_CALLER_ID,
53
+ tier: 'core',
54
+ options: context.options,
55
+ };
56
+ let registry;
57
+ const service = new RouterService({
58
+ resolveOwner: (exposure, version, owner) => {
59
+ registry ??= broker.requestAccess(callerContext, ExposedApiRegistryToken);
60
+ return registry.resolve(exposure, {
61
+ ...(version === undefined ? {} : { version }),
62
+ ...(owner === undefined ? {} : { expectedOwner: owner }),
63
+ });
64
+ },
65
+ getParser: () => options?.parser
66
+ ?? broker.requestAccess(callerContext, ParserToken),
67
+ });
68
+ options?.onConstruct?.(service);
69
+ // Delegation by the owner: the real caller is captured here, at resolve
70
+ // time, and carried to every kind owner the request reaches.
71
+ return withExposureBindings(service, {
72
+ [`${ROUTER_EXPOSURE}@1`]: {
73
+ projection: (_service, caller) => {
74
+ const view = Object.freeze({
75
+ identity: caller.identity,
76
+ callerClass: caller.callerClass,
77
+ official: caller.official,
78
+ capabilities: caller.capabilities,
79
+ origin: caller.origin,
80
+ });
81
+ return Object.freeze({
82
+ route: (rawInput, routeOptions) => service.route(rawInput, routeOptions, view),
83
+ registeredKinds: () => service.registeredKinds(),
84
+ kinds: () => service.kinds(),
85
+ });
86
+ },
87
+ },
88
+ });
89
+ },
90
+ };
91
+ }
92
+ export const RouterDescriptor = createRouterDescriptor();
@@ -0,0 +1,9 @@
1
+ import type { IRouterService } from '../contracts/IRouterService.js';
2
+ /**
3
+ * Kernel service token for `brud.core.router`.
4
+ *
5
+ * Resolution grants the ability to parse and route a `[BRUD]` document to
6
+ * registered Level-1 services. Registration is a boot-only capability and is
7
+ * not reachable through this token after the window closes.
8
+ */
9
+ export declare const RouterToken: import("../../../src/contracts/serviceToken.js").ServiceToken<IRouterService>;
@@ -0,0 +1,9 @@
1
+ import { createServiceToken } from '../../../src/contracts/serviceToken.js';
2
+ /**
3
+ * Kernel service token for `brud.core.router`.
4
+ *
5
+ * Resolution grants the ability to parse and route a `[BRUD]` document to
6
+ * registered Level-1 services. Registration is a boot-only capability and is
7
+ * not reachable through this token after the window closes.
8
+ */
9
+ export const RouterToken = createServiceToken('brud.core.router', 'Boot-registered kind router dispatching parsed operations to Level-1 services');
@@ -0,0 +1,4 @@
1
+ export * from './contracts/index.js';
2
+ export * from './descriptor/RouterDescriptor.js';
3
+ export * from './descriptor/tokens.js';
4
+ export * from './orchestrator/index.js';
@@ -0,0 +1,4 @@
1
+ export * from './contracts/index.js';
2
+ export * from './descriptor/RouterDescriptor.js';
3
+ export * from './descriptor/tokens.js';
4
+ export * from './orchestrator/index.js';
@@ -0,0 +1,93 @@
1
+ import type { KernelCallAuthority } from '../../../src/contracts/callChain.js';
2
+ import type { IServiceLifecycle } from '../../../src/contracts/lifecycle.js';
3
+ import type { BrudOperation, IBrudParserService } from '../../Parser/contracts/index.js';
4
+ import type { IRouterService } from '../contracts/IRouterService.js';
5
+ import type { BrudDispatchCaller, BrudKindDispatcher, BrudRouteOptions, BrudKindInfo, BrudRouteRegistration, BrudRouteResult } from '../contracts/types.js';
6
+ /** Collaborators injected into {@link RouterService}. */
7
+ export interface RouterDependencies {
8
+ /** Resolves a kind owner's dispatch exposure on the current kernel call chain. */
9
+ readonly resolveOwner: (exposure: string, version: number | undefined, owner: string | undefined) => BrudKindDispatcher | null;
10
+ readonly getParser: () => IBrudParserService;
11
+ }
12
+ /**
13
+ * Level-1 Brud kind Router.
14
+ *
15
+ * The registration window is open only while the kernel is booting. The
16
+ * standard composition calls {@link closeRegistration} at the end of boot,
17
+ * before the kernel announces `RUNNING`; the `onRunning` hook is a second
18
+ * guard for alternate compositions.
19
+ *
20
+ * Dispatch resolves every target through the access broker with the token the
21
+ * owning service supplied, so access policies still apply and only the
22
+ * owning service can be a routing target.
23
+ */
24
+ export declare class RouterService implements IRouterService, IServiceLifecycle {
25
+ private readonly registrations;
26
+ /** The parsed permission of every declared operation, by kind then operation. Frozen at registration. */
27
+ private readonly permissions;
28
+ /** The one permission of every kind whose owner defines its operation names. */
29
+ private readonly openKinds;
30
+ private authority;
31
+ private readonly dependencies;
32
+ private parser;
33
+ private closed;
34
+ private disposed;
35
+ /**
36
+ * @param dependencies - Broker, router identity, and lazy parser resolution.
37
+ */
38
+ constructor(dependencies: RouterDependencies);
39
+ /** Lifecycle no-op: registrations arrive from the boot pinner. */
40
+ /** Binds the kernel call chain (hardcore boot). */
41
+ bindAuthority(value: KernelCallAuthority): void;
42
+ /** The kernel-derived caller of the current chain, if any. */
43
+ private currentCaller;
44
+ initialize(): Promise<void>;
45
+ /** Seals the window even when no boot pinner ran. */
46
+ onRunning(): Promise<void>;
47
+ /** Clears every claim and refuses later routing. */
48
+ dispose(): Promise<void>;
49
+ /** Whether {@link dispose} has run. */
50
+ get isDisposed(): boolean;
51
+ /**
52
+ * Registers a kind a participant declared in `manifest.kinds` (hardcore
53
+ * boot). The owner's kernel identity is pinned, so only that participant's
54
+ * exposure can serve the kind.
55
+ */
56
+ registerDeclared(owner: string, declaration: {
57
+ readonly kind: string;
58
+ readonly exposure: string;
59
+ readonly version?: number | string;
60
+ readonly description?: string;
61
+ readonly operations: BrudRouteRegistration['operations'];
62
+ readonly permission?: BrudRouteRegistration['permission'];
63
+ }): void;
64
+ register(registration: BrudRouteRegistration, owner?: string): void;
65
+ /**
66
+ * Builds the operation registry for one kind: every operation must be
67
+ * declared and carry a valid permission, its own or the kind's. Refuses the
68
+ * declaration, and so the boot, otherwise.
69
+ */
70
+ private compilePermissions;
71
+ closeRegistration(): void;
72
+ isRegistrationOpen(): boolean;
73
+ registeredKinds(): readonly string[];
74
+ /**
75
+ * The public vocabulary: every registered kind with its declared
76
+ * description and operations. What lives inside a kind is its owner's
77
+ * business (an optional `describe` operation by convention).
78
+ */
79
+ kinds(): readonly BrudKindInfo[];
80
+ route(rawInput: string, options?: BrudRouteOptions, caller?: BrudDispatchCaller): Promise<BrudRouteResult>;
81
+ dispatch(operations: readonly BrudOperation[], options?: BrudRouteOptions, caller?: BrudDispatchCaller): Promise<BrudRouteResult>;
82
+ /**
83
+ * The operation registry check, run before the owner is resolved: the
84
+ * operation must be declared for its kind, and the caller must hold the
85
+ * operation's permission. The reason a permission is denied goes to the
86
+ * observation stream, never to the caller.
87
+ */
88
+ private refuseBeforeOwner;
89
+ private observeRefusal;
90
+ private resolveParser;
91
+ private buildDispatchContext;
92
+ private failureResult;
93
+ }