@jskit-ai/kernel 0.1.158 → 0.1.160

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 (103) hide show
  1. package/_testable/index.js +1 -3
  2. package/client/componentRegistry.js +44 -0
  3. package/client/componentRegistry.test.js +16 -0
  4. package/client/moduleBootstrap.js +54 -97
  5. package/client/moduleBootstrap.test.js +47 -32
  6. package/client/vite/clientBootstrapPlugin.js +12 -3
  7. package/client/vite/clientBootstrapPlugin.test.js +21 -6
  8. package/internal/node/installedPackages.js +2 -7
  9. package/internal/node/installedPackages.test.js +26 -5
  10. package/package.json +3 -5
  11. package/server/actions/actionCatalogue.js +162 -0
  12. package/server/actions/actionEvents.js +66 -0
  13. package/server/actions/actionProvider.js +23 -0
  14. package/server/actions/index.js +3 -6
  15. package/server/features/defineFeature.js +131 -0
  16. package/server/features/defineFeature.test.js +238 -0
  17. package/server/features/index.js +1 -0
  18. package/server/http/HttpProvider.js +23 -0
  19. package/server/http/_testable/index.js +0 -1
  20. package/server/http/capabilityHttpRuntime.js +123 -0
  21. package/server/http/capabilityHttpRuntime.test.js +161 -0
  22. package/server/http/directRequestActionExecutor.js +78 -0
  23. package/server/http/index.js +2 -1
  24. package/server/http/lib/index.js +1 -13
  25. package/server/http/lib/routeRegistration.js +9 -25
  26. package/server/platform/index.js +2 -2
  27. package/server/platform/installedRuntime.js +122 -0
  28. package/server/platform/installedRuntime.test.js +103 -0
  29. package/server/platform/providerRuntime/capabilityProviderLoader.js +100 -0
  30. package/server/platform/providerRuntime/capabilityProviderLoader.test.js +80 -0
  31. package/server/platform/providerRuntime/packageCatalog.js +4 -1
  32. package/server/platform/surfaceRuntime.js +1 -15
  33. package/server/runtime/BootstrapProvider.js +69 -0
  34. package/server/runtime/EventProvider.js +74 -0
  35. package/server/runtime/EventProvider.test.js +32 -0
  36. package/server/runtime/entityChangeEvents.js +7 -7
  37. package/server/runtime/entityChangeEvents.test.js +2 -2
  38. package/server/runtime/fastifyBootstrap.js +0 -40
  39. package/server/runtime/index.js +2 -3
  40. package/server/surface/index.js +0 -1
  41. package/shared/actions/actionDefinitions.js +20 -0
  42. package/shared/actions/pipeline.js +22 -0
  43. package/shared/actions/policies.js +1 -1
  44. package/shared/actions/registry.js +3 -0
  45. package/shared/capabilities/defineProvider.js +99 -0
  46. package/shared/capabilities/index.js +2 -0
  47. package/shared/capabilities/runtime.js +243 -0
  48. package/shared/capabilities/runtime.test.js +170 -0
  49. package/test/barrelExposure.test.js +36 -13
  50. package/test/exportsContract.test.js +8 -3
  51. package/server/actions/ActionRuntimeServiceProvider.js +0 -304
  52. package/server/actions/ActionRuntimeServiceProvider.test.js +0 -558
  53. package/server/container/ContainerCoreServiceProvider.js +0 -27
  54. package/server/container/index.js +0 -10
  55. package/server/http/HttpFastifyServiceProvider.js +0 -25
  56. package/server/http/lib/httpRuntime.js +0 -83
  57. package/server/http/lib/kernel.js +0 -15
  58. package/server/http/lib/kernel.test.js +0 -1565
  59. package/server/http/lib/requestActionExecutor.js +0 -265
  60. package/server/http/lib/requestScope.js +0 -57
  61. package/server/kernel/KernelCoreServiceProvider.js +0 -27
  62. package/server/kernel/index.js +0 -10
  63. package/server/platform/PlatformServerRuntimeServiceProvider.js +0 -30
  64. package/server/platform/providerRuntime/providerLoader.js +0 -283
  65. package/server/platform/providerRuntime.js +0 -146
  66. package/server/platform/providerRuntime.test.js +0 -214
  67. package/server/platform/runtime.js +0 -40
  68. package/server/registries/actionSurfaceSourceRegistry.js +0 -148
  69. package/server/registries/bootstrapPayloadContributorRegistry.js +0 -51
  70. package/server/registries/domainEventListenerRegistry.js +0 -58
  71. package/server/registries/index.js +0 -32
  72. package/server/registries/primitives.js +0 -63
  73. package/server/registries/routeVisibilityResolverRegistry.js +0 -84
  74. package/server/registries/serviceRegistrationRegistry.js +0 -488
  75. package/server/runtime/ServerRuntimeCoreServiceProvider.js +0 -64
  76. package/server/runtime/ServerRuntimeCoreServiceProvider.test.js +0 -53
  77. package/server/runtime/apiRoutePolicyParity.test.js +0 -109
  78. package/server/runtime/apiRouteRegistration.js +0 -65
  79. package/server/runtime/bootBootstrapRoutes.js +0 -29
  80. package/server/runtime/bootBootstrapRoutes.test.js +0 -69
  81. package/server/runtime/bootstrapContributors.test.js +0 -166
  82. package/server/runtime/composition.js +0 -142
  83. package/server/runtime/domainEvents.test.js +0 -114
  84. package/server/runtime/domainRules.js +0 -50
  85. package/server/runtime/domainRules.test.js +0 -87
  86. package/server/runtime/runtimeAssembly.js +0 -113
  87. package/server/runtime/runtimeKernel.js +0 -55
  88. package/server/runtime/serviceRegistration.test.js +0 -251
  89. package/server/support/SupportCoreServiceProvider.js +0 -27
  90. package/server/surface/SurfaceRoutingServiceProvider.js +0 -27
  91. package/shared/actions/index.js +0 -2
  92. package/shared/runtime/application.js +0 -324
  93. package/shared/runtime/container.js +0 -261
  94. package/shared/runtime/containerErrors.js +0 -22
  95. package/shared/runtime/index.js +0 -18
  96. package/shared/runtime/kernelErrors.js +0 -25
  97. package/shared/runtime/kernelErrors.test.js +0 -120
  98. package/shared/runtime/serviceProvider.js +0 -13
  99. package/shared/support/containerToken.js +0 -8
  100. package/shared/support/generatedUiContract.js +0 -542
  101. package/shared/support/generatedUiContract.test.js +0 -218
  102. package/shared/support/tokens.js +0 -1
  103. package/shared/support/tokens.test.js +0 -17
@@ -1,304 +0,0 @@
1
- import { normalizeActionDomain } from "../../shared/actions/actionDefinitions.js";
2
- import { createNoopAuditAdapter } from "../../shared/actions/audit.js";
3
- import { createNoopIdempotencyAdapter } from "../../shared/actions/idempotency.js";
4
- import { createNoopObservabilityAdapter } from "../../shared/actions/observability.js";
5
- import { createActionRegistry } from "../../shared/actions/registry.js";
6
- import { createSurfaceRuntime } from "../../shared/surface/runtime.js";
7
- import { isContainerToken } from "../../shared/support/containerToken.js";
8
- import { normalizeObject } from "../../shared/support/normalize.js";
9
- import { installServiceRegistrationApi } from "../registries/serviceRegistrationRegistry.js";
10
- import {
11
- ensureActionSurfaceSourceRegistry,
12
- resolveActionSurfaceSourceIds
13
- } from "../registries/actionSurfaceSourceRegistry.js";
14
- import {
15
- normalizeContributorEntry,
16
- normalizeNestedEntries,
17
- registerTaggedSingleton,
18
- resolveTaggedEntries as resolveRegistryTaggedEntries
19
- } from "../registries/primitives.js";
20
-
21
- const ACTION_RUNTIME_API = Object.freeze({
22
- createActionRegistry,
23
- createNoopIdempotencyAdapter,
24
- createNoopAuditAdapter,
25
- createNoopObservabilityAdapter
26
- });
27
- let ACTION_RUNTIME_CONTRIBUTOR_INDEX = 0;
28
-
29
- function createSurfaceRuntimeFromAppConfig(scope) {
30
- if (!scope || typeof scope.has !== "function" || typeof scope.make !== "function") {
31
- throw new Error("Surface runtime registration requires scope.has()/make().");
32
- }
33
-
34
- if (!scope.has("appConfig")) {
35
- throw new Error(
36
- "ActionRuntimeServiceProvider requires appConfig.surfaceDefinitions when jskit.surface.runtime is not registered."
37
- );
38
- }
39
-
40
- const appConfig = normalizeObject(scope.make("appConfig"));
41
- const surfaceDefinitions = normalizeObject(appConfig.surfaceDefinitions);
42
- if (Object.keys(surfaceDefinitions).length < 1) {
43
- throw new Error(
44
- "ActionRuntimeServiceProvider requires appConfig.surfaceDefinitions when jskit.surface.runtime is not registered."
45
- );
46
- }
47
-
48
- return createSurfaceRuntime({
49
- allMode: appConfig.surfaceModeAll,
50
- surfaces: surfaceDefinitions,
51
- defaultSurfaceId: appConfig.surfaceDefaultId
52
- });
53
- }
54
-
55
- function normalizeDependencyMap(value, { context = "action dependencies" } = {}) {
56
- const source = normalizeObject(value);
57
- const normalized = {};
58
-
59
- for (const [key, token] of Object.entries(source)) {
60
- const dependencyName = String(key || "").trim();
61
- if (!dependencyName) {
62
- throw new Error(`${context} keys must be non-empty strings.`);
63
- }
64
- if (!isContainerToken(token)) {
65
- throw new Error(`${context}.${dependencyName} must be a valid container token.`);
66
- }
67
- normalized[dependencyName] = token;
68
- }
69
-
70
- return Object.freeze(normalized);
71
- }
72
-
73
- function resolveActionContributors(scope) {
74
- return resolveRegistryTaggedEntries(scope, "jskit.runtime.actions.contributors").filter(
75
- (entry) => entry && typeof entry === "object" && !Array.isArray(entry)
76
- );
77
- }
78
-
79
- function resolveActionContextContributors(scope) {
80
- return resolveRegistryTaggedEntries(scope, "jskit.runtime.actions.contextContributors")
81
- .map((entry) => normalizeContributorEntry(entry))
82
- .filter(Boolean);
83
- }
84
-
85
- function createActionExecutor(actionRegistry) {
86
- return Object.freeze({
87
- execute(payload) {
88
- const source = normalizeObject(payload);
89
- return actionRegistry.execute({
90
- actionId: source.actionId,
91
- version: source.version == null ? null : source.version,
92
- input: normalizeObject(source.input),
93
- context: normalizeObject(source.context),
94
- deps: normalizeObject(source.deps)
95
- });
96
- },
97
- executeStream(payload) {
98
- const source = normalizeObject(payload);
99
- return actionRegistry.executeStream({
100
- actionId: source.actionId,
101
- version: source.version == null ? null : source.version,
102
- input: normalizeObject(source.input),
103
- context: normalizeObject(source.context),
104
- deps: normalizeObject(source.deps)
105
- });
106
- },
107
- listDefinitions() {
108
- return actionRegistry.listDefinitions();
109
- },
110
- getDefinition(actionId, version = null) {
111
- return actionRegistry.getDefinition(actionId, version);
112
- }
113
- });
114
- }
115
-
116
- function createActionContributorToken() {
117
- ACTION_RUNTIME_CONTRIBUTOR_INDEX += 1;
118
- return Symbol(`jskit.runtime.actions.contributor.${ACTION_RUNTIME_CONTRIBUTOR_INDEX}`);
119
- }
120
-
121
- function materializeDependencies(scope, dependencyMap, { context = "action.dependencies" } = {}) {
122
- const normalizedMap = normalizeDependencyMap(dependencyMap, { context });
123
- const resolved = {};
124
- for (const [name, token] of Object.entries(normalizedMap)) {
125
- resolved[name] = scope.make(token);
126
- }
127
- return Object.freeze(resolved);
128
- }
129
-
130
- function materializeAction(scope, actionDefinition) {
131
- const source = normalizeObject(actionDefinition);
132
- const materialized = { ...source };
133
- const actionDependencies = materializeDependencies(scope, source.dependencies, {
134
- context: `action ${String(source.id || "<unknown>")}.dependencies`
135
- });
136
- const resolvedDependencies = actionDependencies;
137
-
138
- if (Object.hasOwn(source, "surfaces") && Object.hasOwn(source, "surfacesFrom")) {
139
- throw new Error(`Action ${String(source.id || "<unknown>")} cannot define both surfaces and surfacesFrom.`);
140
- }
141
-
142
- delete materialized.dependencies;
143
- delete materialized.surfacesFrom;
144
-
145
- if (Object.hasOwn(source, "surfacesFrom")) {
146
- const resolvedSurfaces = resolveActionSurfaceSourceIds(scope, source.surfacesFrom, {
147
- context: `action ${String(source.id || "<unknown>")}.surfacesFrom`
148
- });
149
- if (resolvedSurfaces.length < 1) {
150
- return null;
151
- }
152
- materialized.surfaces = resolvedSurfaces;
153
- }
154
-
155
- if (typeof source.execute === "function") {
156
- materialized.execute = async function executeMaterializedAction(input, context, runtimeDependencies = {}) {
157
- const runtimeDeps = normalizeObject(runtimeDependencies);
158
- const mergedDependencies = Object.freeze({
159
- ...resolvedDependencies,
160
- ...runtimeDeps
161
- });
162
-
163
- return source.execute(input, context, mergedDependencies);
164
- };
165
- }
166
-
167
- return Object.freeze(materialized);
168
- }
169
-
170
- function registerActionDefinition(app, actionSpec, { context = "app.action" } = {}) {
171
- const token = createActionContributorToken();
172
- registerTaggedSingleton(
173
- app,
174
- token,
175
- (scope) => {
176
- const action = materializeAction(scope, actionSpec.action);
177
- if (!action) {
178
- return null;
179
- }
180
-
181
- return {
182
- contributorId: actionSpec.contributorId,
183
- domain: action.domain,
184
- actions: Object.freeze([action])
185
- };
186
- },
187
- "jskit.runtime.actions.contributors",
188
- { context }
189
- );
190
- }
191
-
192
- function normalizeSingleActionRegistration(actionDefinition, { context = "app.action" } = {}) {
193
- const source = normalizeObject(actionDefinition);
194
- const actionId = String(source.id || "").trim();
195
- const contributorId = String(source.contributorId || "").trim() || (actionId ? `action.${actionId}` : "");
196
- if (!contributorId) {
197
- throw new Error(`${context} requires action.id or action.contributorId.`);
198
- }
199
-
200
- const normalizedAction = {
201
- ...source
202
- };
203
- delete normalizedAction.contributorId;
204
- normalizedAction.domain = normalizeActionDomain(normalizedAction.domain, {
205
- context: `${context} domain`
206
- });
207
-
208
- return Object.freeze({
209
- contributorId,
210
- action: Object.freeze(normalizedAction)
211
- });
212
- }
213
-
214
- function installActionRegistrationApi(app) {
215
- if (typeof app.action === "function" && typeof app.actions === "function") {
216
- return;
217
- }
218
-
219
- const registerActions = function registerActions(actionDefinitions = []) {
220
- if (!Array.isArray(actionDefinitions)) {
221
- throw new Error("app.actions requires an array of action definitions.");
222
- }
223
-
224
- const entries = normalizeNestedEntries(actionDefinitions);
225
- for (const entry of entries) {
226
- this.action(entry);
227
- }
228
- return this;
229
- };
230
-
231
- const registerAction = function registerAction(actionDefinition = {}) {
232
- const actionSpec = normalizeSingleActionRegistration(actionDefinition, {
233
- context: "app.action"
234
- });
235
- registerActionDefinition(this, actionSpec, { context: "app.action" });
236
- return this;
237
- };
238
-
239
- Object.defineProperty(app, "actions", {
240
- configurable: true,
241
- writable: true,
242
- value: registerActions
243
- });
244
- Object.defineProperty(app, "action", {
245
- configurable: true,
246
- writable: true,
247
- value: registerAction
248
- });
249
- }
250
-
251
- function registerActionContextContributor(app, token, factory) {
252
- registerTaggedSingleton(
253
- app,
254
- token,
255
- factory,
256
- "jskit.runtime.actions.contextContributors",
257
- { context: "registerActionContextContributor" }
258
- );
259
- }
260
-
261
- class ActionRuntimeServiceProvider {
262
- static id = "runtime.actions";
263
-
264
- register(app) {
265
- if (!app || typeof app.singleton !== "function" || typeof app.has !== "function" || typeof app.tag !== "function") {
266
- throw new Error("ActionRuntimeServiceProvider requires application singleton()/has()/tag().");
267
- }
268
-
269
- installActionRegistrationApi(app);
270
- ensureActionSurfaceSourceRegistry(app);
271
- installServiceRegistrationApi(app);
272
-
273
- if (!app.has("jskit.surface.runtime")) {
274
- app.singleton("jskit.surface.runtime", (scope) => createSurfaceRuntimeFromAppConfig(scope));
275
- }
276
-
277
- app.singleton("runtime.actions", () => ACTION_RUNTIME_API);
278
-
279
- if (!app.has("actionRegistry")) {
280
- app.singleton("actionRegistry", (scope) => {
281
- return createActionRegistry({
282
- contributors: resolveActionContributors(scope),
283
- idempotencyAdapter: createNoopIdempotencyAdapter(),
284
- auditAdapter: createNoopAuditAdapter(),
285
- observabilityAdapter: createNoopObservabilityAdapter(),
286
- logger: scope.has("jskit.logger") ? scope.make("jskit.logger") : console
287
- });
288
- });
289
- }
290
-
291
- if (!app.has("actionExecutor")) {
292
- app.singleton("actionExecutor", (scope) => createActionExecutor(scope.make("actionRegistry")));
293
- }
294
- }
295
-
296
- boot() {}
297
- }
298
-
299
- export {
300
- resolveActionContributors,
301
- resolveActionContextContributors,
302
- registerActionContextContributor,
303
- ActionRuntimeServiceProvider
304
- };