@jskit-ai/kernel 0.1.159 → 0.1.161

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 (102) 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.test.js +2 -2
  7. package/internal/node/installedPackages.js +2 -7
  8. package/internal/node/installedPackages.test.js +26 -5
  9. package/package.json +3 -5
  10. package/server/actions/actionCatalogue.js +162 -0
  11. package/server/actions/actionEvents.js +66 -0
  12. package/server/actions/actionProvider.js +23 -0
  13. package/server/actions/index.js +3 -6
  14. package/server/features/defineFeature.js +131 -0
  15. package/server/features/defineFeature.test.js +238 -0
  16. package/server/features/index.js +1 -0
  17. package/server/http/HttpProvider.js +23 -0
  18. package/server/http/_testable/index.js +0 -1
  19. package/server/http/capabilityHttpRuntime.js +123 -0
  20. package/server/http/capabilityHttpRuntime.test.js +161 -0
  21. package/server/http/directRequestActionExecutor.js +78 -0
  22. package/server/http/index.js +2 -1
  23. package/server/http/lib/index.js +1 -13
  24. package/server/http/lib/routeRegistration.js +9 -25
  25. package/server/platform/index.js +2 -2
  26. package/server/platform/installedRuntime.js +122 -0
  27. package/server/platform/installedRuntime.test.js +103 -0
  28. package/server/platform/providerRuntime/capabilityProviderLoader.js +100 -0
  29. package/server/platform/providerRuntime/capabilityProviderLoader.test.js +80 -0
  30. package/server/platform/providerRuntime/packageCatalog.js +4 -1
  31. package/server/platform/surfaceRuntime.js +1 -15
  32. package/server/runtime/BootstrapProvider.js +69 -0
  33. package/server/runtime/EventProvider.js +74 -0
  34. package/server/runtime/EventProvider.test.js +32 -0
  35. package/server/runtime/entityChangeEvents.js +7 -7
  36. package/server/runtime/entityChangeEvents.test.js +2 -2
  37. package/server/runtime/fastifyBootstrap.js +0 -40
  38. package/server/runtime/index.js +2 -3
  39. package/server/surface/index.js +0 -1
  40. package/shared/actions/actionDefinitions.js +20 -0
  41. package/shared/actions/pipeline.js +22 -0
  42. package/shared/actions/policies.js +1 -1
  43. package/shared/actions/registry.js +3 -0
  44. package/shared/capabilities/defineProvider.js +99 -0
  45. package/shared/capabilities/index.js +2 -0
  46. package/shared/capabilities/runtime.js +243 -0
  47. package/shared/capabilities/runtime.test.js +170 -0
  48. package/test/barrelExposure.test.js +36 -13
  49. package/test/exportsContract.test.js +8 -3
  50. package/server/actions/ActionRuntimeServiceProvider.js +0 -304
  51. package/server/actions/ActionRuntimeServiceProvider.test.js +0 -558
  52. package/server/container/ContainerCoreServiceProvider.js +0 -27
  53. package/server/container/index.js +0 -10
  54. package/server/http/HttpFastifyServiceProvider.js +0 -25
  55. package/server/http/lib/httpRuntime.js +0 -83
  56. package/server/http/lib/kernel.js +0 -15
  57. package/server/http/lib/kernel.test.js +0 -1565
  58. package/server/http/lib/requestActionExecutor.js +0 -265
  59. package/server/http/lib/requestScope.js +0 -57
  60. package/server/kernel/KernelCoreServiceProvider.js +0 -27
  61. package/server/kernel/index.js +0 -10
  62. package/server/platform/PlatformServerRuntimeServiceProvider.js +0 -30
  63. package/server/platform/providerRuntime/providerLoader.js +0 -283
  64. package/server/platform/providerRuntime.js +0 -146
  65. package/server/platform/providerRuntime.test.js +0 -214
  66. package/server/platform/runtime.js +0 -40
  67. package/server/registries/actionSurfaceSourceRegistry.js +0 -148
  68. package/server/registries/bootstrapPayloadContributorRegistry.js +0 -51
  69. package/server/registries/domainEventListenerRegistry.js +0 -58
  70. package/server/registries/index.js +0 -32
  71. package/server/registries/primitives.js +0 -63
  72. package/server/registries/routeVisibilityResolverRegistry.js +0 -84
  73. package/server/registries/serviceRegistrationRegistry.js +0 -488
  74. package/server/runtime/ServerRuntimeCoreServiceProvider.js +0 -64
  75. package/server/runtime/ServerRuntimeCoreServiceProvider.test.js +0 -53
  76. package/server/runtime/apiRoutePolicyParity.test.js +0 -109
  77. package/server/runtime/apiRouteRegistration.js +0 -65
  78. package/server/runtime/bootBootstrapRoutes.js +0 -29
  79. package/server/runtime/bootBootstrapRoutes.test.js +0 -69
  80. package/server/runtime/bootstrapContributors.test.js +0 -166
  81. package/server/runtime/composition.js +0 -142
  82. package/server/runtime/domainEvents.test.js +0 -114
  83. package/server/runtime/domainRules.js +0 -50
  84. package/server/runtime/domainRules.test.js +0 -87
  85. package/server/runtime/runtimeAssembly.js +0 -113
  86. package/server/runtime/runtimeKernel.js +0 -55
  87. package/server/runtime/serviceRegistration.test.js +0 -251
  88. package/server/support/SupportCoreServiceProvider.js +0 -27
  89. package/server/surface/SurfaceRoutingServiceProvider.js +0 -27
  90. package/shared/actions/index.js +0 -2
  91. package/shared/runtime/application.js +0 -324
  92. package/shared/runtime/container.js +0 -261
  93. package/shared/runtime/containerErrors.js +0 -22
  94. package/shared/runtime/index.js +0 -18
  95. package/shared/runtime/kernelErrors.js +0 -25
  96. package/shared/runtime/kernelErrors.test.js +0 -120
  97. package/shared/runtime/serviceProvider.js +0 -13
  98. package/shared/support/containerToken.js +0 -8
  99. package/shared/support/generatedUiContract.js +0 -542
  100. package/shared/support/generatedUiContract.test.js +0 -218
  101. package/shared/support/tokens.js +0 -1
  102. package/shared/support/tokens.test.js +0 -17
@@ -1,558 +0,0 @@
1
- import assert from "node:assert/strict";
2
- import test from "node:test";
3
- import { createSchema } from "json-rest-schema";
4
-
5
- import {
6
- emptyInputValidator
7
- } from "../../shared/actions/actionContributorHelpers.js";
8
- import {
9
- ActionRuntimeServiceProvider,
10
- registerActionContextContributor,
11
- resolveActionContributors,
12
- resolveActionContextContributors
13
- } from "./ActionRuntimeServiceProvider.js";
14
-
15
- function createSingletonApp() {
16
- const singletons = new Map();
17
- const instances = new Map();
18
- const tags = new Map();
19
- return {
20
- singletons,
21
- has(token) {
22
- return singletons.has(token) || instances.has(token);
23
- },
24
- singleton(token, factory) {
25
- singletons.set(token, {
26
- factory,
27
- resolved: false,
28
- value: undefined
29
- });
30
- },
31
- tag(token, tagName) {
32
- if (!this.has(token)) {
33
- throw new Error(`Cannot tag unresolved token "${String(token)}".`);
34
- }
35
- if (!tags.has(tagName)) {
36
- tags.set(tagName, new Set());
37
- }
38
- tags.get(tagName).add(token);
39
- },
40
- resolveTag(tagName) {
41
- const tagged = tags.get(tagName);
42
- if (!tagged) {
43
- return [];
44
- }
45
- return [...tagged].map((token) => this.make(token));
46
- },
47
- make(token) {
48
- if (instances.has(token)) {
49
- return instances.get(token);
50
- }
51
- if (!singletons.has(token)) {
52
- throw new Error(`Token "${String(token)}" is not registered.`);
53
- }
54
- const entry = singletons.get(token);
55
- if (!entry.resolved) {
56
- entry.value = entry.factory(this);
57
- entry.resolved = true;
58
- instances.set(token, entry.value);
59
- }
60
- return entry.value;
61
- }
62
- };
63
- }
64
-
65
- test("ActionRuntimeServiceProvider registers runtime actions api and action executor", () => {
66
- const app = createSingletonApp();
67
- const provider = new ActionRuntimeServiceProvider();
68
- provider.register(app);
69
-
70
- assert.equal(app.singletons.has("runtime.actions"), true);
71
- assert.equal(app.singletons.has("actionRegistry"), true);
72
- assert.equal(app.singletons.has("actionExecutor"), true);
73
- assert.equal(app.singletons.has("jskit.surface.runtime"), true);
74
- assert.equal(typeof app.action, "function");
75
- assert.equal(typeof app.actions, "function");
76
- assert.equal(typeof app.actionSurfaceSource, "function");
77
- assert.equal(typeof app.service, "function");
78
-
79
- const api = app.make("runtime.actions");
80
- assert.equal(typeof api.createActionRegistry, "function");
81
- assert.equal(typeof app.make("actionExecutor")?.execute, "function");
82
- });
83
-
84
- test("ActionRuntimeServiceProvider materializes dependencies and surfaces for app.actions arrays", async () => {
85
- const app = createSingletonApp();
86
- const provider = new ActionRuntimeServiceProvider();
87
- provider.register(app);
88
-
89
- app.singleton("jskit.surface.runtime", () => ({
90
- listEnabledSurfaceIds() {
91
- return ["app", "admin", "console"];
92
- }
93
- }));
94
-
95
- app.singleton("test.echo.service", () => ({
96
- echo(input) {
97
- return { echoed: input, ok: true };
98
- }
99
- }));
100
-
101
- app.actions([
102
- {
103
- id: "test.echo",
104
- domain: "workspace",
105
- version: 1,
106
- kind: "query",
107
- channels: ["internal"],
108
- surfacesFrom: "enabled",
109
- dependencies: {
110
- echoService: "test.echo.service"
111
- },
112
- input: {
113
- schema: createSchema({
114
- value: {
115
- type: "string",
116
- required: false
117
- }
118
- }),
119
- mode: "patch"
120
- },
121
- idempotency: "none",
122
- audit: { actionName: "test.echo" },
123
- observability: {},
124
- async execute(input, _context, deps) {
125
- return deps.echoService.echo(input);
126
- }
127
- }
128
- ]);
129
-
130
- const actionExecutor = app.make("actionExecutor");
131
- const definitions = actionExecutor.listDefinitions();
132
- assert.equal(definitions.some((definition) => definition.id === "test.echo"), true);
133
- assert.deepEqual(definitions.find((definition) => definition.id === "test.echo")?.surfaces, ["app", "admin", "console"]);
134
-
135
- const result = await actionExecutor.execute({
136
- actionId: "test.echo",
137
- input: { value: "ok" },
138
- context: { channel: "internal", surface: "app" }
139
- });
140
- assert.deepEqual(result, { echoed: { value: "ok" }, ok: true });
141
- });
142
-
143
- test("ActionRuntimeServiceProvider registers SurfaceRuntime from appConfig when token is absent", async () => {
144
- const app = createSingletonApp();
145
- const provider = new ActionRuntimeServiceProvider();
146
- provider.register(app);
147
-
148
- app.singleton("appConfig", () => ({
149
- surfaceModeAll: "all",
150
- surfaceDefaultId: "home",
151
- surfaceDefinitions: {
152
- home: { id: "home", pagesRoot: "", enabled: true, requiresAuth: false, requiresWorkspace: false },
153
- console: { id: "console", pagesRoot: "console", enabled: true, requiresAuth: true, requiresWorkspace: false }
154
- }
155
- }));
156
-
157
- app.actions([
158
- {
159
- id: "test.surfaces.from.appconfig",
160
- domain: "workspace",
161
- version: 1,
162
- kind: "query",
163
- channels: ["internal"],
164
- surfacesFrom: "enabled",
165
- input: emptyInputValidator,
166
- idempotency: "none",
167
- audit: { actionName: "test.surfaces.from.appconfig" },
168
- observability: {},
169
- async execute() {
170
- return { ok: true };
171
- }
172
- }
173
- ]);
174
-
175
- const actionExecutor = app.make("actionExecutor");
176
- const definition = actionExecutor.getDefinition("test.surfaces.from.appconfig");
177
- assert.deepEqual(definition.surfaces, ["home", "console"]);
178
- });
179
-
180
- test("ActionRuntimeServiceProvider materializes custom surfacesFrom aliases registered via app.actionSurfaceSource", async () => {
181
- const app = createSingletonApp();
182
- const provider = new ActionRuntimeServiceProvider();
183
- provider.register(app);
184
-
185
- app.singleton("jskit.surface.runtime", () => ({
186
- listEnabledSurfaceIds() {
187
- return ["home", "app", "admin", "console"];
188
- }
189
- }));
190
-
191
- app.actionSurfaceSource("workspace", () => ["app", "admin"]);
192
-
193
- app.actions([
194
- {
195
- id: "test.workspace.alias",
196
- domain: "workspace",
197
- version: 1,
198
- kind: "query",
199
- channels: ["internal"],
200
- surfacesFrom: "workspace",
201
- input: emptyInputValidator,
202
- idempotency: "none",
203
- audit: { actionName: "test.workspace.alias" },
204
- observability: {},
205
- async execute() {
206
- return { ok: true };
207
- }
208
- }
209
- ]);
210
-
211
- const actionExecutor = app.make("actionExecutor");
212
- const definition = actionExecutor.getDefinition("test.workspace.alias");
213
- assert.deepEqual(definition?.surfaces, ["app", "admin"]);
214
- });
215
-
216
- test("ActionRuntimeServiceProvider does not infer service method bindings from action source", () => {
217
- const app = createSingletonApp();
218
- const provider = new ActionRuntimeServiceProvider();
219
- provider.register(app);
220
-
221
- app.singleton("test.customer.service", () => ({
222
- createRecord(input) {
223
- return input;
224
- }
225
- }));
226
-
227
- app.actions([
228
- {
229
- id: "test.customer.create",
230
- domain: "workspace",
231
- version: 1,
232
- kind: "command",
233
- channels: ["internal"],
234
- surfaces: ["admin"],
235
- dependencies: {
236
- customerService: "test.customer.service"
237
- },
238
- input: emptyInputValidator,
239
- idempotency: "optional",
240
- audit: { actionName: "test.customer.create" },
241
- observability: {},
242
- async execute(input, _context, deps) {
243
- return deps.customerService.createRecord(input);
244
- }
245
- }
246
- ]);
247
-
248
- const contributors = resolveActionContributors(app);
249
- const action = contributors[0]?.actions?.[0];
250
- assert.equal(Object.hasOwn(action || {}, "serviceMethodBindings"), false);
251
- });
252
-
253
- test("app.actions + resolveActionContributors provide canonical contributor wiring", () => {
254
- const app = createSingletonApp();
255
- const provider = new ActionRuntimeServiceProvider();
256
- provider.register(app);
257
- app.singleton("jskit.surface.runtime", () => ({
258
- listEnabledSurfaceIds() {
259
- return ["app", "admin", "console"];
260
- }
261
- }));
262
-
263
- app.actions([
264
- {
265
- id: "alpha.one",
266
- domain: "settings",
267
- version: 1,
268
- kind: "query",
269
- channels: ["internal"],
270
- surfaces: ["app"],
271
- input: emptyInputValidator,
272
- idempotency: "none",
273
- audit: { actionName: "alpha.one" },
274
- observability: {},
275
- async execute() {
276
- return { ok: true };
277
- }
278
- }
279
- ]);
280
- app.actions([
281
- {
282
- id: "beta.one",
283
- domain: "auth",
284
- version: 1,
285
- kind: "query",
286
- channels: ["internal"],
287
- surfaces: ["app"],
288
- input: emptyInputValidator,
289
- idempotency: "none",
290
- audit: { actionName: "beta.one" },
291
- observability: {},
292
- async execute() {
293
- return { ok: true };
294
- }
295
- }
296
- ]);
297
-
298
- const contributors = resolveActionContributors(app);
299
- assert.deepEqual(
300
- contributors.map((entry) => entry.contributorId).sort(),
301
- ["action.alpha.one", "action.beta.one"]
302
- );
303
- });
304
-
305
- test("action runtime execute merges static and per-execution dependencies", async () => {
306
- const app = createSingletonApp();
307
- const provider = new ActionRuntimeServiceProvider();
308
- provider.register(app);
309
-
310
- app.singleton("jskit.surface.runtime", () => ({
311
- listEnabledSurfaceIds() {
312
- return ["app"];
313
- }
314
- }));
315
-
316
- app.singleton("test.static.service", () => ({
317
- label: "static"
318
- }));
319
-
320
- app.actions([
321
- {
322
- id: "test.deps.merge",
323
- domain: "workspace",
324
- version: 1,
325
- kind: "query",
326
- channels: ["internal"],
327
- surfaces: ["app"],
328
- dependencies: {
329
- staticService: "test.static.service"
330
- },
331
- input: emptyInputValidator,
332
- idempotency: "none",
333
- audit: { actionName: "test.deps.merge" },
334
- observability: {},
335
- async execute(_input, _context, deps) {
336
- return {
337
- staticLabel: deps.staticService?.label || "",
338
- dynamicValue: deps.dynamicValue || ""
339
- };
340
- }
341
- }
342
- ]);
343
-
344
- const actionExecutor = app.make("actionExecutor");
345
- const result = await actionExecutor.execute({
346
- actionId: "test.deps.merge",
347
- context: {
348
- channel: "internal",
349
- surface: "app"
350
- },
351
- deps: {
352
- dynamicValue: "runtime"
353
- }
354
- });
355
-
356
- assert.deepEqual(result, {
357
- staticLabel: "static",
358
- dynamicValue: "runtime"
359
- });
360
- });
361
-
362
- test("app.actions accepts custom action domains", () => {
363
- const app = createSingletonApp();
364
- const provider = new ActionRuntimeServiceProvider();
365
- provider.register(app);
366
-
367
- app.actions([
368
- {
369
- id: "custom.domain.check",
370
- domain: "completeCalendar",
371
- version: 1,
372
- kind: "query",
373
- channels: ["internal"],
374
- surfaces: ["app"],
375
- input: emptyInputValidator,
376
- idempotency: "none",
377
- audit: { actionName: "custom.domain.check" },
378
- observability: {},
379
- async execute() {
380
- return { ok: true };
381
- }
382
- }
383
- ]);
384
-
385
- const contributors = resolveActionContributors(app);
386
- assert.equal(contributors.length, 1);
387
- assert.equal(contributors[0].contributorId, "action.custom.domain.check");
388
- assert.equal(contributors[0].domain, "completecalendar");
389
- });
390
-
391
- test("app.action registers a single action with default contributor id", () => {
392
- const app = createSingletonApp();
393
- const provider = new ActionRuntimeServiceProvider();
394
- provider.register(app);
395
-
396
- app.action({
397
- id: "test.single",
398
- domain: "workspace",
399
- kind: "query",
400
- channels: ["internal"],
401
- surfaces: ["app"],
402
- input: emptyInputValidator,
403
- idempotency: "none",
404
- audit: { actionName: "test.single" },
405
- observability: {},
406
- async execute() {
407
- return { ok: true };
408
- }
409
- });
410
-
411
- const contributors = resolveActionContributors(app);
412
- assert.equal(contributors.length, 1);
413
- assert.equal(contributors[0].contributorId, "action.test.single");
414
- assert.equal(contributors[0].actions.length, 1);
415
- assert.equal(contributors[0].actions[0].id, "test.single");
416
- });
417
-
418
- test("app.actions requires an array", () => {
419
- const app = createSingletonApp();
420
- const provider = new ActionRuntimeServiceProvider();
421
- provider.register(app);
422
-
423
- assert.throws(() => app.actions({}), /requires an array/);
424
- });
425
-
426
- test("emptyInputValidator allows empty input and rejects unexpected fields", async () => {
427
- const app = createSingletonApp();
428
- const provider = new ActionRuntimeServiceProvider();
429
- provider.register(app);
430
-
431
- app.singleton("jskit.surface.runtime", () => ({
432
- listEnabledSurfaceIds() {
433
- return ["app"];
434
- }
435
- }));
436
-
437
- app.actions([
438
- {
439
- id: "test.empty-input",
440
- domain: "settings",
441
- version: 1,
442
- kind: "query",
443
- channels: ["internal"],
444
- surfaces: ["app"],
445
- input: emptyInputValidator,
446
- idempotency: "none",
447
- audit: { actionName: "test.empty-input" },
448
- observability: {},
449
- async execute() {
450
- return { ok: true };
451
- }
452
- }
453
- ]);
454
-
455
- const actionExecutor = app.make("actionExecutor");
456
-
457
- const okResult = await actionExecutor.execute({
458
- actionId: "test.empty-input",
459
- context: { channel: "internal", surface: "app" }
460
- });
461
- assert.deepEqual(okResult, { ok: true });
462
-
463
- await assert.rejects(
464
- () =>
465
- actionExecutor.execute({
466
- actionId: "test.empty-input",
467
- input: { unexpected: true },
468
- context: { channel: "internal", surface: "app" }
469
- }),
470
- (error) => error?.code === "ACTION_VALIDATION_FAILED"
471
- );
472
- });
473
-
474
- test("registerActionContextContributor + resolveActionContextContributors provide context contributor wiring", () => {
475
- const app = createSingletonApp();
476
-
477
- registerActionContextContributor(app, "test.actionContextContributor.alpha", () => ({
478
- contributorId: "alpha",
479
- contribute() {
480
- return { actor: null };
481
- }
482
- }));
483
- registerActionContextContributor(app, "test.actionContextContributor.beta", () => ({
484
- contributorId: "beta",
485
- contribute() {
486
- return { permissions: [] };
487
- }
488
- }));
489
-
490
- const contributors = resolveActionContextContributors(app);
491
- assert.deepEqual(
492
- contributors.map((entry) => entry.contributorId).sort(),
493
- ["alpha", "beta"]
494
- );
495
- });
496
-
497
- test("app.actions rejects invalid domain identifiers", () => {
498
- const app = createSingletonApp();
499
- const provider = new ActionRuntimeServiceProvider();
500
- provider.register(app);
501
-
502
- assert.throws(
503
- () =>
504
- app.actions([
505
- {
506
- id: "invalid.domain",
507
- domain: "invalid domain",
508
- version: 1,
509
- kind: "query",
510
- channels: ["internal"],
511
- surfaces: ["app"],
512
- input: emptyInputValidator,
513
- idempotency: "none",
514
- audit: { actionName: "invalid.domain" },
515
- observability: {},
516
- async execute() {
517
- return {};
518
- }
519
- }
520
- ]),
521
- /must match/
522
- );
523
- });
524
-
525
- test("app.actions rejects unsupported surfacesFrom aliases", () => {
526
- const app = createSingletonApp();
527
- const provider = new ActionRuntimeServiceProvider();
528
- provider.register(app);
529
-
530
- app.singleton("jskit.surface.runtime", () => ({
531
- listEnabledSurfaceIds() {
532
- return ["app", "admin"];
533
- }
534
- }));
535
-
536
- app.actions([
537
- {
538
- id: "workspace.alias.invalid",
539
- domain: "workspace",
540
- version: 1,
541
- kind: "query",
542
- channels: ["internal"],
543
- surfacesFrom: "workspace",
544
- input: emptyInputValidator,
545
- idempotency: "none",
546
- audit: { actionName: "workspace.alias.invalid" },
547
- observability: {},
548
- async execute() {
549
- return {};
550
- }
551
- }
552
- ]);
553
-
554
- assert.throws(
555
- () => app.make("actionExecutor"),
556
- /references unknown surface source "workspace". Register it via app.actionSurfaceSource\(\)\./
557
- );
558
- });
@@ -1,27 +0,0 @@
1
- import { Container, createContainer, tokenLabel } from "../../shared/runtime/container.js";
2
- import * as containerErrors from "../../shared/runtime/containerErrors.js";
3
-
4
- const CONTAINER_CORE_API = Object.freeze({
5
- Container,
6
- createContainer,
7
- tokenLabel,
8
- errors: Object.freeze({
9
- ...containerErrors
10
- })
11
- });
12
-
13
- class ContainerCoreServiceProvider {
14
- static id = "runtime.container";
15
-
16
- register(app) {
17
- if (!app || typeof app.singleton !== "function") {
18
- throw new Error("ContainerCoreServiceProvider requires application singleton().");
19
- }
20
-
21
- app.singleton("runtime.container", () => CONTAINER_CORE_API);
22
- }
23
-
24
- boot() {}
25
- }
26
-
27
- export { ContainerCoreServiceProvider };
@@ -1,10 +0,0 @@
1
- export { Container, createContainer, tokenLabel } from "../../shared/runtime/container.js";
2
- export {
3
- ContainerError,
4
- InvalidTokenError,
5
- InvalidFactoryError,
6
- DuplicateBindingError,
7
- UnresolvedTokenError,
8
- CircularDependencyError
9
- } from "../../shared/runtime/containerErrors.js";
10
- export { ContainerCoreServiceProvider } from "./ContainerCoreServiceProvider.js";
@@ -1,25 +0,0 @@
1
- import * as errors from "./lib/errors.js";
2
- import * as router from "./lib/router.js";
3
- import * as kernel from "./lib/kernel.js";
4
-
5
- const HTTP_FASTIFY_SERVER_API = Object.freeze({
6
- errors: Object.freeze({ ...errors }),
7
- router: Object.freeze({ ...router }),
8
- kernel: Object.freeze({ ...kernel })
9
- });
10
-
11
- class HttpFastifyServiceProvider {
12
- static id = "runtime.http-fastify";
13
-
14
- register(app) {
15
- if (!app || typeof app.singleton !== "function") {
16
- throw new Error("HttpFastifyServiceProvider requires application singleton().");
17
- }
18
-
19
- app.singleton("runtime.http-fastify", () => HTTP_FASTIFY_SERVER_API);
20
- }
21
-
22
- boot() {}
23
- }
24
-
25
- export { HttpFastifyServiceProvider };
@@ -1,83 +0,0 @@
1
- import { normalizeObject } from "../../../shared/support/normalize.js";
2
- import { ensureApiErrorHandling, registerBodylessContentTypeNormalizer } from "../../runtime/fastifyBootstrap.js";
3
- import { resolveDefaultSurfaceId } from "../../support/appConfig.js";
4
- import { RouteRegistrationError } from "./errors.js";
5
- import { createRouter } from "./router.js";
6
- import { registerRoutes } from "./routeRegistration.js";
7
-
8
- function registerHttpRuntime(app, options = {}) {
9
- if (!app || typeof app.make !== "function") {
10
- throw new RouteRegistrationError("registerHttpRuntime requires an application instance.");
11
- }
12
-
13
- const runtimeOptions = normalizeObject(options);
14
- const {
15
- fastifyToken = "jskit.fastify",
16
- routerToken = "jskit.http.router",
17
- autoRegisterApiErrorHandling = true,
18
- apiErrorHandling = {},
19
- ...routeRegistrationOptions
20
- } = runtimeOptions;
21
- const fastify = app.make(fastifyToken);
22
- const router = app.make(routerToken);
23
- const routes = typeof router?.list === "function" ? router.list() : [];
24
- const resolvedDefaultActionSurface = resolveDefaultSurfaceId(app, {
25
- defaultSurfaceId: routeRegistrationOptions.requestActionDefaultSurface
26
- });
27
-
28
- registerBodylessContentTypeNormalizer(fastify);
29
-
30
- if (autoRegisterApiErrorHandling !== false) {
31
- ensureApiErrorHandling(app, {
32
- fastifyToken,
33
- ...normalizeObject(apiErrorHandling)
34
- });
35
- }
36
-
37
- return registerRoutes(fastify, {
38
- ...routeRegistrationOptions,
39
- requestActionDefaultSurface: resolvedDefaultActionSurface,
40
- app,
41
- routes
42
- });
43
- }
44
-
45
- function createHttpRuntime(
46
- {
47
- app = null,
48
- fastify = null,
49
- router = null,
50
- autoRegisterApiErrorHandling = true,
51
- apiErrorHandling = {}
52
- } = {}
53
- ) {
54
- if (!app || typeof app.singleton !== "function") {
55
- throw new RouteRegistrationError("createHttpRuntime requires an application instance.");
56
- }
57
-
58
- const runtimeRouter = router || createRouter();
59
- app.singleton("jskit.http.router", () => runtimeRouter);
60
-
61
- if (fastify) {
62
- app.instance("jskit.fastify", fastify);
63
- if (autoRegisterApiErrorHandling !== false) {
64
- ensureApiErrorHandling(app, {
65
- fastifyToken: "jskit.fastify",
66
- ...normalizeObject(apiErrorHandling)
67
- });
68
- }
69
- }
70
-
71
- return {
72
- router: runtimeRouter,
73
- registerRoutes(runtimeOptions = {}) {
74
- return registerHttpRuntime(app, {
75
- autoRegisterApiErrorHandling,
76
- apiErrorHandling: normalizeObject(apiErrorHandling),
77
- ...normalizeObject(runtimeOptions)
78
- });
79
- }
80
- };
81
- }
82
-
83
- export { registerHttpRuntime, createHttpRuntime };