@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.
Files changed (278) 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 +44 -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 +112 -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 +61 -0
  60. package/dist/services/ExposedApiRegistry/orchestrator/ExposedApiRegistryService.js +407 -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 +65 -0
  88. package/dist/services/Interception/contracts/IInterceptionService.js +1 -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 +49 -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 +32 -0
  102. package/dist/services/Interception/orchestrator/InterceptionService.js +180 -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 +56 -0
  142. package/dist/services/Router/contracts/errors.js +75 -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 +90 -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 +74 -0
  158. package/dist/services/Router/orchestrator/RouterService.js +332 -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 +104 -0
  170. package/dist/services/WasmCage/src/caged.js +381 -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 +18 -0
  184. package/dist/src/bootstrap/bootKernelInternal.js +420 -0
  185. package/dist/src/bootstrap/bootTypes.d.ts +89 -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 +34 -0
  190. package/dist/src/bootstrap/config/integrity.js +79 -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 +8 -0
  202. package/dist/src/bootstrap/index.js +5 -0
  203. package/dist/src/bootstrap/packageRequirements.d.ts +26 -0
  204. package/dist/src/bootstrap/packageRequirements.js +52 -0
  205. package/dist/src/contracts/accessBroker.d.ts +53 -0
  206. package/dist/src/contracts/accessBroker.js +1 -0
  207. package/dist/src/contracts/brudOperation.d.ts +20 -0
  208. package/dist/src/contracts/brudOperation.js +20 -0
  209. package/dist/src/contracts/callChain.d.ts +161 -0
  210. package/dist/src/contracts/callChain.js +19 -0
  211. package/dist/src/contracts/capability.d.ts +26 -0
  212. package/dist/src/contracts/capability.js +26 -0
  213. package/dist/src/contracts/container.d.ts +17 -0
  214. package/dist/src/contracts/container.js +8 -0
  215. package/dist/src/contracts/context.d.ts +19 -0
  216. package/dist/src/contracts/context.js +1 -0
  217. package/dist/src/contracts/contextContract.d.ts +129 -0
  218. package/dist/src/contracts/contextContract.js +285 -0
  219. package/dist/src/contracts/dispatchView.d.ts +21 -0
  220. package/dist/src/contracts/dispatchView.js +1 -0
  221. package/dist/src/contracts/handler.d.ts +28 -0
  222. package/dist/src/contracts/handler.js +1 -0
  223. package/dist/src/contracts/index.d.ts +25 -0
  224. package/dist/src/contracts/index.js +8 -0
  225. package/dist/src/contracts/kernel.d.ts +60 -0
  226. package/dist/src/contracts/kernel.js +1 -0
  227. package/dist/src/contracts/lifecycle.d.ts +59 -0
  228. package/dist/src/contracts/lifecycle.js +1 -0
  229. package/dist/src/contracts/manifest.d.ts +145 -0
  230. package/dist/src/contracts/manifest.js +295 -0
  231. package/dist/src/contracts/pipeline.d.ts +8 -0
  232. package/dist/src/contracts/pipeline.js +1 -0
  233. package/dist/src/contracts/policy.d.ts +75 -0
  234. package/dist/src/contracts/policy.js +77 -0
  235. package/dist/src/contracts/registry.d.ts +7 -0
  236. package/dist/src/contracts/registry.js +1 -0
  237. package/dist/src/contracts/serviceDescriptor.d.ts +67 -0
  238. package/dist/src/contracts/serviceDescriptor.js +1 -0
  239. package/dist/src/contracts/serviceToken.d.ts +36 -0
  240. package/dist/src/contracts/serviceToken.js +16 -0
  241. package/dist/src/engine/BrudKernel.d.ts +118 -0
  242. package/dist/src/engine/BrudKernel.js +366 -0
  243. package/dist/src/engine/ExecutionPipeline.d.ts +13 -0
  244. package/dist/src/engine/ExecutionPipeline.js +62 -0
  245. package/dist/src/engine/KernelAccessBroker.d.ts +47 -0
  246. package/dist/src/engine/KernelAccessBroker.js +107 -0
  247. package/dist/src/engine/KernelRegistry.d.ts +14 -0
  248. package/dist/src/engine/KernelRegistry.js +33 -0
  249. package/dist/src/engine/OperationRegistry.d.ts +9 -0
  250. package/dist/src/engine/OperationRegistry.js +18 -0
  251. package/dist/src/engine/ServiceContainer.d.ts +13 -0
  252. package/dist/src/engine/ServiceContainer.js +53 -0
  253. package/dist/src/engine/callChain.d.ts +68 -0
  254. package/dist/src/engine/callChain.js +180 -0
  255. package/dist/src/engine/dag.d.ts +2 -0
  256. package/dist/src/engine/dag.js +34 -0
  257. package/dist/src/engine/errors.d.ts +26 -0
  258. package/dist/src/engine/errors.js +52 -0
  259. package/dist/src/engine/index.d.ts +11 -0
  260. package/dist/src/engine/index.js +8 -0
  261. package/dist/src/engine/state.d.ts +1 -0
  262. package/dist/src/engine/state.js +1 -0
  263. package/dist/src/validation/jsonSchema/compile.d.ts +8 -0
  264. package/dist/src/validation/jsonSchema/compile.js +386 -0
  265. package/dist/src/validation/jsonSchema/index.d.ts +3 -0
  266. package/dist/src/validation/jsonSchema/index.js +2 -0
  267. package/dist/src/validation/jsonSchema/jsonValue.d.ts +29 -0
  268. package/dist/src/validation/jsonSchema/jsonValue.js +190 -0
  269. package/dist/src/validation/jsonSchema/pattern.d.ts +28 -0
  270. package/dist/src/validation/jsonSchema/pattern.js +155 -0
  271. package/dist/src/validation/jsonSchema/types.d.ts +71 -0
  272. package/dist/src/validation/jsonSchema/types.js +15 -0
  273. package/package.json +59 -4
  274. package/services/WasmCage/native/brud-wasm-cage.darwin-arm64.node +0 -0
  275. package/services/WasmCage/native/brud-wasm-cage.darwin-x64.node +0 -0
  276. package/services/WasmCage/native/brud-wasm-cage.linux-arm64-gnu.node +0 -0
  277. package/services/WasmCage/native/brud-wasm-cage.linux-x64-gnu.node +0 -0
  278. package/services/WasmCage/native/brud-wasm-cage.win32-x64-msvc.node +0 -0
@@ -0,0 +1,190 @@
1
+ /** Encodes one JSON Pointer reference token (RFC 6901). */
2
+ export function pointerToken(token) {
3
+ return String(token).replace(/~/gu, '~0').replace(/\//gu, '~1');
4
+ }
5
+ /** Appends a token to a JSON Pointer. */
6
+ export function pointerJoin(base, token) {
7
+ return `${base}/${pointerToken(token)}`;
8
+ }
9
+ /** Length in Unicode code points, as JSON Schema counts string length. */
10
+ export function codePointLength(value) {
11
+ let count = 0;
12
+ for (const _ of value) {
13
+ count += 1;
14
+ }
15
+ return count;
16
+ }
17
+ function isPlainObject(value) {
18
+ const prototype = Object.getPrototypeOf(value);
19
+ return prototype === Object.prototype || prototype === null;
20
+ }
21
+ /** JSON type of a value already known to be plain JSON. */
22
+ export function jsonTypeOf(value) {
23
+ if (value === null) {
24
+ return 'null';
25
+ }
26
+ if (typeof value === 'boolean') {
27
+ return 'boolean';
28
+ }
29
+ if (typeof value === 'number') {
30
+ return Number.isInteger(value) ? 'integer' : 'number';
31
+ }
32
+ if (typeof value === 'string') {
33
+ return 'string';
34
+ }
35
+ if (Array.isArray(value)) {
36
+ return 'array';
37
+ }
38
+ return 'object';
39
+ }
40
+ /**
41
+ * Checks that a value is plain JSON: it would survive `JSON.stringify` then
42
+ * `JSON.parse` unchanged. Never invokes user code (accessors are rejected
43
+ * without being read). Stops at the first problem.
44
+ *
45
+ * @returns `null` when the value is plain JSON, otherwise one violation.
46
+ */
47
+ export function inspectJsonValue(value, limits) {
48
+ let nodes = 0;
49
+ const ancestors = [];
50
+ const fail = (instancePath, keyword, message) => ({ instancePath, schemaPath: '', keyword, message });
51
+ const visit = (current, path, depth) => {
52
+ nodes += 1;
53
+ if (nodes > limits.maxNodes) {
54
+ return fail(path, 'limit', `value has more than ${limits.maxNodes} nodes`);
55
+ }
56
+ if (depth > limits.maxDepth) {
57
+ return fail(path, 'limit', `value is nested deeper than ${limits.maxDepth} levels`);
58
+ }
59
+ switch (typeof current) {
60
+ case 'string':
61
+ case 'boolean':
62
+ return null;
63
+ case 'number':
64
+ return Number.isFinite(current) ? null : fail(path, 'json', 'number must be finite');
65
+ case 'undefined':
66
+ return fail(path, 'json', 'undefined is not a JSON value');
67
+ case 'bigint':
68
+ return fail(path, 'json', 'bigint is not a JSON value');
69
+ case 'symbol':
70
+ return fail(path, 'json', 'symbol is not a JSON value');
71
+ case 'function':
72
+ return fail(path, 'json', 'function is not a JSON value');
73
+ default:
74
+ break;
75
+ }
76
+ if (current === null) {
77
+ return null;
78
+ }
79
+ const object = current;
80
+ if (ancestors.includes(object)) {
81
+ return fail(path, 'json', 'value contains a cycle');
82
+ }
83
+ if (Object.getOwnPropertySymbols(object).length > 0) {
84
+ return fail(path, 'json', 'symbol-keyed properties are not JSON');
85
+ }
86
+ ancestors.push(object);
87
+ try {
88
+ if (Array.isArray(object)) {
89
+ if (Object.getPrototypeOf(object) !== Array.prototype) {
90
+ return fail(path, 'json', 'array subclasses are not JSON');
91
+ }
92
+ const keys = Object.getOwnPropertyNames(object);
93
+ if (keys.length !== object.length + 1) {
94
+ return fail(path, 'json', 'arrays must be dense with no extra properties');
95
+ }
96
+ for (let index = 0; index < object.length; index += 1) {
97
+ const descriptor = Object.getOwnPropertyDescriptor(object, index);
98
+ if (descriptor === undefined) {
99
+ return fail(path, 'json', 'arrays must be dense with no extra properties');
100
+ }
101
+ if (!('value' in descriptor)) {
102
+ return fail(pointerJoin(path, index), 'json', 'accessor properties are not JSON');
103
+ }
104
+ const problem = visit(descriptor.value, pointerJoin(path, index), depth + 1);
105
+ if (problem !== null) {
106
+ return problem;
107
+ }
108
+ }
109
+ return null;
110
+ }
111
+ if (!isPlainObject(object)) {
112
+ return fail(path, 'json', 'only plain objects are JSON objects');
113
+ }
114
+ for (const key of Object.getOwnPropertyNames(object)) {
115
+ const descriptor = Object.getOwnPropertyDescriptor(object, key);
116
+ if (descriptor === undefined) {
117
+ continue;
118
+ }
119
+ if (!descriptor.enumerable) {
120
+ return fail(pointerJoin(path, key), 'json', 'non-enumerable properties are not JSON');
121
+ }
122
+ if (!('value' in descriptor)) {
123
+ return fail(pointerJoin(path, key), 'json', 'accessor properties are not JSON');
124
+ }
125
+ const problem = visit(descriptor.value, pointerJoin(path, key), depth + 1);
126
+ if (problem !== null) {
127
+ return problem;
128
+ }
129
+ }
130
+ return null;
131
+ }
132
+ finally {
133
+ ancestors.pop();
134
+ }
135
+ };
136
+ return visit(value, '', 0);
137
+ }
138
+ /** Deep equality for plain JSON values (key order ignored, `-0` equals `0`). */
139
+ export function jsonEqual(left, right) {
140
+ if (left === right) {
141
+ return true;
142
+ }
143
+ if (left === null || right === null || typeof left !== 'object' || typeof right !== 'object') {
144
+ return false;
145
+ }
146
+ if (Array.isArray(left) !== Array.isArray(right)) {
147
+ return false;
148
+ }
149
+ if (Array.isArray(left) && Array.isArray(right)) {
150
+ if (left.length !== right.length) {
151
+ return false;
152
+ }
153
+ for (let index = 0; index < left.length; index += 1) {
154
+ if (!jsonEqual(left[index], right[index])) {
155
+ return false;
156
+ }
157
+ }
158
+ return true;
159
+ }
160
+ const leftRecord = left;
161
+ const rightRecord = right;
162
+ const leftKeys = Object.keys(leftRecord);
163
+ const rightKeys = Object.keys(rightRecord);
164
+ if (leftKeys.length !== rightKeys.length) {
165
+ return false;
166
+ }
167
+ for (const key of leftKeys) {
168
+ if (!Object.prototype.hasOwnProperty.call(rightRecord, key)) {
169
+ return false;
170
+ }
171
+ if (!jsonEqual(leftRecord[key], rightRecord[key])) {
172
+ return false;
173
+ }
174
+ }
175
+ return true;
176
+ }
177
+ /** Deep-frozen copy of a plain JSON value. */
178
+ export function freezeJsonCopy(value) {
179
+ if (value === null || typeof value !== 'object') {
180
+ return value;
181
+ }
182
+ if (Array.isArray(value)) {
183
+ return Object.freeze(value.map((item) => freezeJsonCopy(item)));
184
+ }
185
+ const copy = {};
186
+ for (const [key, item] of Object.entries(value)) {
187
+ copy[key] = freezeJsonCopy(item);
188
+ }
189
+ return Object.freeze(copy);
190
+ }
@@ -0,0 +1,28 @@
1
+ /**
2
+ * `pattern` safety screen (decision U1-D2).
3
+ *
4
+ * ECMAScript `RegExp` has no time limit, so a hostile pattern can hang the
5
+ * kernel thread. Patterns are screened at compile time for the shapes behind
6
+ * catastrophic backtracking, then compiled once with the `u` flag. Combined
7
+ * with the input-length cap applied at validation time, this bounds the risk.
8
+ * It is a conservative heuristic, not a proof: some safe patterns (for example
9
+ * `(ab|cd)*`) are rejected too.
10
+ */
11
+ export type PatternScreenResult = {
12
+ readonly ok: true;
13
+ readonly regex: RegExp;
14
+ } | {
15
+ readonly ok: false;
16
+ readonly code: 'UNSAFE_PATTERN' | 'INVALID_KEYWORD_VALUE';
17
+ readonly reason: string;
18
+ };
19
+ /**
20
+ * Screens and compiles a JSON Schema `pattern`.
21
+ *
22
+ * Rejected as `UNSAFE_PATTERN`:
23
+ * - backreferences (`\1`…`\9`, `\k<name>`);
24
+ * - lookbehind (`(?<=`, `(?<!`);
25
+ * - a repeating quantifier applied to a group whose body contains a repeating
26
+ * quantifier (`(a+)+`, `(.*)*`) or an alternation (`(a|aa)*`).
27
+ */
28
+ export declare function screenPattern(source: string, maxLength: number): PatternScreenResult;
@@ -0,0 +1,155 @@
1
+ /**
2
+ * `pattern` safety screen (decision U1-D2).
3
+ *
4
+ * ECMAScript `RegExp` has no time limit, so a hostile pattern can hang the
5
+ * kernel thread. Patterns are screened at compile time for the shapes behind
6
+ * catastrophic backtracking, then compiled once with the `u` flag. Combined
7
+ * with the input-length cap applied at validation time, this bounds the risk.
8
+ * It is a conservative heuristic, not a proof: some safe patterns (for example
9
+ * `(ab|cd)*`) are rejected too.
10
+ */
11
+ /**
12
+ * Reads a quantifier starting at `index`.
13
+ *
14
+ * @returns The quantifier length and whether it can repeat its atom more than
15
+ * once, or `null` when no quantifier starts here.
16
+ */
17
+ function readQuantifier(source, index) {
18
+ const char = source[index];
19
+ if (char === '*' || char === '+') {
20
+ return { length: source[index + 1] === '?' ? 2 : 1, repeats: true };
21
+ }
22
+ if (char === '?') {
23
+ return { length: source[index + 1] === '?' ? 2 : 1, repeats: false };
24
+ }
25
+ if (char === '{') {
26
+ const match = /^\{(\d+)(,(\d*))?\}/u.exec(source.slice(index));
27
+ if (match === null) {
28
+ return null;
29
+ }
30
+ const min = Number(match[1]);
31
+ const hasComma = match[2] !== undefined;
32
+ const max = hasComma ? (match[3] === '' ? Number.POSITIVE_INFINITY : Number(match[3])) : min;
33
+ const length = match[0].length + (source[index + match[0].length] === '?' ? 1 : 0);
34
+ return { length, repeats: max > 1 };
35
+ }
36
+ return null;
37
+ }
38
+ /**
39
+ * Screens and compiles a JSON Schema `pattern`.
40
+ *
41
+ * Rejected as `UNSAFE_PATTERN`:
42
+ * - backreferences (`\1`…`\9`, `\k<name>`);
43
+ * - lookbehind (`(?<=`, `(?<!`);
44
+ * - a repeating quantifier applied to a group whose body contains a repeating
45
+ * quantifier (`(a+)+`, `(.*)*`) or an alternation (`(a|aa)*`).
46
+ */
47
+ export function screenPattern(source, maxLength) {
48
+ if (source.length > maxLength) {
49
+ return { ok: false, code: 'UNSAFE_PATTERN', reason: `pattern is longer than ${maxLength} characters` };
50
+ }
51
+ const stack = [{ hasRepeat: false, hasAlternation: false }];
52
+ let index = 0;
53
+ const top = () => stack[stack.length - 1];
54
+ while (index < source.length) {
55
+ const char = source[index];
56
+ if (char === '\\') {
57
+ const next = source[index + 1];
58
+ if (next !== undefined && /[1-9]/u.test(next)) {
59
+ return { ok: false, code: 'UNSAFE_PATTERN', reason: 'backreferences are not allowed' };
60
+ }
61
+ if (next === 'k' && source[index + 2] === '<') {
62
+ return { ok: false, code: 'UNSAFE_PATTERN', reason: 'named backreferences are not allowed' };
63
+ }
64
+ index += 2;
65
+ const quantifier = readQuantifier(source, index);
66
+ if (quantifier !== null) {
67
+ if (quantifier.repeats) {
68
+ top().hasRepeat = true;
69
+ }
70
+ index += quantifier.length;
71
+ }
72
+ continue;
73
+ }
74
+ if (char === '[') {
75
+ index += 1;
76
+ if (source[index] === '^') {
77
+ index += 1;
78
+ }
79
+ if (source[index] === ']') {
80
+ index += 1;
81
+ }
82
+ while (index < source.length && source[index] !== ']') {
83
+ index += source[index] === '\\' ? 2 : 1;
84
+ }
85
+ index += 1;
86
+ const quantifier = readQuantifier(source, index);
87
+ if (quantifier !== null) {
88
+ if (quantifier.repeats) {
89
+ top().hasRepeat = true;
90
+ }
91
+ index += quantifier.length;
92
+ }
93
+ continue;
94
+ }
95
+ if (char === '(') {
96
+ if (source.startsWith('(?<=', index) || source.startsWith('(?<!', index)) {
97
+ return { ok: false, code: 'UNSAFE_PATTERN', reason: 'lookbehind is not allowed' };
98
+ }
99
+ stack.push({ hasRepeat: false, hasAlternation: false });
100
+ index += 1;
101
+ continue;
102
+ }
103
+ if (char === ')') {
104
+ if (stack.length === 1) {
105
+ return { ok: false, code: 'INVALID_KEYWORD_VALUE', reason: 'unbalanced parenthesis' };
106
+ }
107
+ const frame = stack.pop();
108
+ index += 1;
109
+ const quantifier = readQuantifier(source, index);
110
+ if (quantifier !== null) {
111
+ if (quantifier.repeats && (frame.hasRepeat || frame.hasAlternation)) {
112
+ return {
113
+ ok: false,
114
+ code: 'UNSAFE_PATTERN',
115
+ reason: 'a repeated group may not contain a repeating quantifier or an alternation',
116
+ };
117
+ }
118
+ if (quantifier.repeats) {
119
+ top().hasRepeat = true;
120
+ }
121
+ index += quantifier.length;
122
+ }
123
+ if (frame.hasRepeat) {
124
+ top().hasRepeat = true;
125
+ }
126
+ if (frame.hasAlternation) {
127
+ top().hasAlternation = true;
128
+ }
129
+ continue;
130
+ }
131
+ if (char === '|') {
132
+ top().hasAlternation = true;
133
+ index += 1;
134
+ continue;
135
+ }
136
+ index += 1;
137
+ const quantifier = readQuantifier(source, index);
138
+ if (quantifier !== null) {
139
+ if (quantifier.repeats) {
140
+ top().hasRepeat = true;
141
+ }
142
+ index += quantifier.length;
143
+ }
144
+ }
145
+ try {
146
+ return { ok: true, regex: new RegExp(source, 'u') };
147
+ }
148
+ catch (error) {
149
+ return {
150
+ ok: false,
151
+ code: 'INVALID_KEYWORD_VALUE',
152
+ reason: `pattern is not a valid regular expression: ${error instanceof Error ? error.message : String(error)}`,
153
+ };
154
+ }
155
+ }
@@ -0,0 +1,71 @@
1
+ /**
2
+ * Zero-dependency JSON Schema subset validator: public types and limits.
3
+ *
4
+ * The module is pure ECMAScript: no `node:*` imports, no packages.
5
+ */
6
+ /**
7
+ * Constraint keywords the validator enforces. Anything else is rejected.
8
+ *
9
+ * `protected` is an accepted annotation keyword: it never constrains a value,
10
+ * it only marks a parameter the Brud Protocol v2 parser treats as protected.
11
+ */
12
+ export type JsonSchemaKeyword = 'type' | 'properties' | 'required' | 'additionalProperties' | 'enum' | 'const' | 'items' | 'minItems' | 'maxItems' | 'minimum' | 'maximum' | 'exclusiveMinimum' | 'exclusiveMaximum' | 'minLength' | 'maxLength' | 'pattern' | 'oneOf';
13
+ /** Primitive type names accepted by the `type` keyword. */
14
+ export type JsonSchemaTypeName = 'null' | 'boolean' | 'number' | 'integer' | 'string' | 'array' | 'object';
15
+ /** Why a schema could not be compiled. */
16
+ export type JsonSchemaDefinitionErrorCode = 'UNSUPPORTED_KEYWORD' | 'INVALID_KEYWORD_VALUE' | 'INVALID_SCHEMA' | 'UNSAFE_PATTERN' | 'SCHEMA_LIMIT_EXCEEDED';
17
+ /** A problem with the schema itself, found at compile time. */
18
+ export interface JsonSchemaDefinitionError {
19
+ readonly code: JsonSchemaDefinitionErrorCode;
20
+ /** JSON Pointer into the schema, e.g. `/properties/path/pattern`; `` for the root. */
21
+ readonly schemaPath: string;
22
+ readonly message: string;
23
+ }
24
+ /** A way in which a value does not satisfy a compiled schema. */
25
+ export interface JsonSchemaViolation {
26
+ /** JSON Pointer into the value; `` for the root. */
27
+ readonly instancePath: string;
28
+ /** JSON Pointer to the schema keyword that failed. */
29
+ readonly schemaPath: string;
30
+ /** `json`: the value is not plain JSON. `limit`: a safety limit was reached. */
31
+ readonly keyword: JsonSchemaKeyword | 'json' | 'limit';
32
+ /** Human-readable reason. Never contains the value itself. */
33
+ readonly message: string;
34
+ }
35
+ export type JsonSchemaValidationResult = {
36
+ readonly valid: true;
37
+ } | {
38
+ readonly valid: false;
39
+ readonly violations: readonly JsonSchemaViolation[];
40
+ };
41
+ /** A frozen, reusable validator produced by {@link compileJsonSchema}. */
42
+ export interface CompiledJsonSchema {
43
+ validate(value: unknown): JsonSchemaValidationResult;
44
+ }
45
+ export type JsonSchemaCompileResult = {
46
+ readonly ok: true;
47
+ readonly schema: CompiledJsonSchema;
48
+ } | {
49
+ readonly ok: false;
50
+ readonly errors: readonly JsonSchemaDefinitionError[];
51
+ };
52
+ /** Safety limits. Every field is a positive integer. */
53
+ export interface JsonSchemaLimits {
54
+ /** Maximum nesting of sub-schemas. */
55
+ readonly maxSchemaDepth: number;
56
+ /** Maximum number of schema nodes (objects and booleans). */
57
+ readonly maxSchemaNodes: number;
58
+ /** Maximum number of `enum` values. */
59
+ readonly maxEnumValues: number;
60
+ /** Maximum `pattern` source length in UTF-16 code units. */
61
+ readonly maxPatternLength: number;
62
+ /** Maximum nesting of the validated value. */
63
+ readonly maxValueDepth: number;
64
+ /** Maximum number of nodes in the validated value. */
65
+ readonly maxValueNodes: number;
66
+ /** Longest string, in Unicode code points, that `pattern` is run against. */
67
+ readonly maxPatternInputLength: number;
68
+ /** Maximum violations reported before truncation. */
69
+ readonly maxViolations: number;
70
+ }
71
+ export declare const DEFAULT_JSON_SCHEMA_LIMITS: JsonSchemaLimits;
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Zero-dependency JSON Schema subset validator: public types and limits.
3
+ *
4
+ * The module is pure ECMAScript: no `node:*` imports, no packages.
5
+ */
6
+ export const DEFAULT_JSON_SCHEMA_LIMITS = Object.freeze({
7
+ maxSchemaDepth: 32,
8
+ maxSchemaNodes: 1_000,
9
+ maxEnumValues: 256,
10
+ maxPatternLength: 256,
11
+ maxValueDepth: 64,
12
+ maxValueNodes: 100_000,
13
+ maxPatternInputLength: 10_000,
14
+ maxViolations: 100,
15
+ });
package/package.json CHANGED
@@ -1,6 +1,61 @@
1
1
  {
2
2
  "name": "@brud/kernel",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.0.1",
4
+ "type": "module",
5
+ "main": "dist/index.js",
6
+ "types": "dist/index.d.ts",
7
+ "exports": {
8
+ ".": {
9
+ "types": "./dist/index.d.ts",
10
+ "import": "./dist/index.js",
11
+ "default": "./dist/index.js"
12
+ },
13
+ "./services/*.js": {
14
+ "types": "./dist/services/*.d.ts",
15
+ "import": "./dist/services/*.js",
16
+ "default": "./dist/services/*.js"
17
+ },
18
+ "./package.json": "./package.json"
19
+ },
20
+ "files": [
21
+ "dist",
22
+ "services/WasmCage/native"
23
+ ],
24
+ "engines": {
25
+ "node": ">=22"
26
+ },
27
+ "scripts": {
28
+ "build": "node scripts/clean.mjs && tsc",
29
+ "test": "node scripts/run-tests.mjs",
30
+ "clean": "node scripts/clean.mjs",
31
+ "prepack": "npm run build && node scripts/verify-dist.mjs && node --import tsx scripts/repin.ts --check && node scripts/smoke-dist.mjs",
32
+ "repin": "node --import tsx scripts/repin.ts",
33
+ "smoke:dist": "node scripts/smoke-dist.mjs"
34
+ },
35
+ "dependencies": {},
36
+ "devDependencies": {
37
+ "@types/node": "22.x",
38
+ "tsx": "^4.0.0",
39
+ "typescript": "^5.9.3"
40
+ },
41
+ "description": "The BrudOS kernel: identity, giver-controlled exposures, call chains and the seven hardcore services.",
42
+ "license": "Apache-2.0",
43
+ "repository": {
44
+ "type": "git",
45
+ "url": "git+https://github.com/rahatarch/brud.git",
46
+ "directory": "packages/kernel"
47
+ },
48
+ "homepage": "https://github.com/rahatarch/brud/tree/main/docs-next",
49
+ "bugs": {
50
+ "url": "https://github.com/rahatarch/brud/issues"
51
+ },
52
+ "publishConfig": {
53
+ "access": "public"
54
+ },
55
+ "keywords": [
56
+ "brud",
57
+ "brudos",
58
+ "kernel",
59
+ "participants"
60
+ ]
61
+ }