@jskit-ai/kernel 0.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +24 -0
- package/_testable/index.js +4 -0
- package/client/appConfig.js +33 -0
- package/client/componentInteraction.js +51 -0
- package/client/componentInteraction.test.js +111 -0
- package/client/descriptorSections.js +75 -0
- package/client/index.d.ts +70 -0
- package/client/index.js +3 -0
- package/client/logging.js +38 -0
- package/client/moduleBootstrap.js +670 -0
- package/client/moduleBootstrap.test.js +403 -0
- package/client/shellBootstrap.js +233 -0
- package/client/shellBootstrap.test.js +185 -0
- package/client/shellRouting.js +321 -0
- package/client/shellRouting.test.js +113 -0
- package/client/vite/clientBootstrapPlugin.js +259 -0
- package/client/vite/clientBootstrapPlugin.test.js +563 -0
- package/client/vite/index.js +3 -0
- package/internal/node/fileSystem.js +21 -0
- package/internal/node/installedPackageDescriptor.js +104 -0
- package/package.json +43 -0
- package/server/actions/ActionRuntimeServiceProvider.js +309 -0
- package/server/actions/ActionRuntimeServiceProvider.test.js +551 -0
- package/server/actions/index.js +8 -0
- package/server/container/ContainerCoreServiceProvider.js +27 -0
- package/server/container/index.js +10 -0
- package/server/exportPolicy.test.js +68 -0
- package/server/http/HttpFastifyServiceProvider.js +25 -0
- package/server/http/_testable/index.js +2 -0
- package/server/http/index.js +1 -0
- package/server/http/lib/controller.js +183 -0
- package/server/http/lib/controller.test.js +143 -0
- package/server/http/lib/errors.js +12 -0
- package/server/http/lib/httpRuntime.js +82 -0
- package/server/http/lib/index.js +18 -0
- package/server/http/lib/kernel.js +15 -0
- package/server/http/lib/kernel.test.js +880 -0
- package/server/http/lib/middlewareRuntime.js +149 -0
- package/server/http/lib/requestActionExecutor.js +258 -0
- package/server/http/lib/requestScope.js +59 -0
- package/server/http/lib/routeRegistration.js +165 -0
- package/server/http/lib/routeSupport.js +45 -0
- package/server/http/lib/routeValidator.js +469 -0
- package/server/http/lib/routeValidator.test.js +474 -0
- package/server/http/lib/router.js +206 -0
- package/server/kernel/KernelCoreServiceProvider.js +27 -0
- package/server/kernel/index.js +10 -0
- package/server/platform/PlatformServerRuntimeServiceProvider.js +30 -0
- package/server/platform/index.js +5 -0
- package/server/platform/providerRuntime/descriptorCatalog.js +170 -0
- package/server/platform/providerRuntime/helpers.js +45 -0
- package/server/platform/providerRuntime/lockfile.js +27 -0
- package/server/platform/providerRuntime/providerLoader.js +283 -0
- package/server/platform/providerRuntime.js +142 -0
- package/server/platform/providerRuntime.test.js +217 -0
- package/server/platform/runtime.js +40 -0
- package/server/platform/surfaceRuntime.js +150 -0
- package/server/platform/surfaceRuntime.test.js +136 -0
- package/server/registries/actionSurfaceSourceRegistry.js +150 -0
- package/server/registries/bootstrapPayloadContributorRegistry.js +41 -0
- package/server/registries/domainEventListenerRegistry.js +61 -0
- package/server/registries/index.js +36 -0
- package/server/registries/primitives.js +63 -0
- package/server/registries/routeVisibilityResolverRegistry.js +87 -0
- package/server/registries/serviceRegistrationRegistry.js +431 -0
- package/server/runtime/ServerRuntimeCoreServiceProvider.js +65 -0
- package/server/runtime/ServerRuntimeCoreServiceProvider.test.js +53 -0
- package/server/runtime/apiRoutePolicyParity.test.js +109 -0
- package/server/runtime/apiRouteRegistration.js +65 -0
- package/server/runtime/bootBootstrapRoutes.js +46 -0
- package/server/runtime/bootBootstrapRoutes.test.js +79 -0
- package/server/runtime/bootstrapContributors.test.js +114 -0
- package/server/runtime/canonicalJson.js +74 -0
- package/server/runtime/composition.js +142 -0
- package/server/runtime/domainEvents.test.js +114 -0
- package/server/runtime/domainRules.js +50 -0
- package/server/runtime/domainRules.test.js +87 -0
- package/server/runtime/entityChangeEvents.js +182 -0
- package/server/runtime/entityChangeEvents.test.js +211 -0
- package/server/runtime/errors.js +68 -0
- package/server/runtime/errors.test.js +73 -0
- package/server/runtime/fastifyBootstrap.js +372 -0
- package/server/runtime/fastifyBootstrap.test.js +194 -0
- package/server/runtime/index.js +6 -0
- package/server/runtime/integers.js +13 -0
- package/server/runtime/moduleConfig.js +269 -0
- package/server/runtime/moduleConfig.test.js +141 -0
- package/server/runtime/pagination.js +13 -0
- package/server/runtime/realtimeNormalization.js +21 -0
- package/server/runtime/requestUrl.js +38 -0
- package/server/runtime/routeUtils.js +20 -0
- package/server/runtime/runtimeAssembly.js +113 -0
- package/server/runtime/runtimeKernel.js +55 -0
- package/server/runtime/securityAudit.js +269 -0
- package/server/runtime/securityAudit.test.js +41 -0
- package/server/runtime/serviceAuthorization.js +113 -0
- package/server/runtime/serviceAuthorization.test.js +100 -0
- package/server/runtime/serviceRegistration.test.js +197 -0
- package/server/support/SupportCoreServiceProvider.js +25 -0
- package/server/support/appConfig.js +37 -0
- package/server/support/appConfig.test.js +94 -0
- package/server/support/defaultMissingHandler.js +7 -0
- package/server/support/index.js +2 -0
- package/server/support/routePolicyConfig.js +51 -0
- package/server/support/symlinkSafeRequire.js +78 -0
- package/server/support/symlinkSafeRequire.test.js +27 -0
- package/server/surface/SurfaceRoutingServiceProvider.js +27 -0
- package/server/surface/index.js +19 -0
- package/shared/actions/actionContributorHelpers.js +34 -0
- package/shared/actions/actionContributorHelpers.test.js +16 -0
- package/shared/actions/actionDefinitions.js +488 -0
- package/shared/actions/actionDefinitions.test.js +212 -0
- package/shared/actions/audit.js +7 -0
- package/shared/actions/executionContext.js +97 -0
- package/shared/actions/executionContext.test.js +66 -0
- package/shared/actions/idempotency.js +62 -0
- package/shared/actions/index.js +2 -0
- package/shared/actions/observability.js +10 -0
- package/shared/actions/pipeline.js +287 -0
- package/shared/actions/policies.js +342 -0
- package/shared/actions/policies.test.js +233 -0
- package/shared/actions/registry.js +187 -0
- package/shared/actions/registry.test.js +381 -0
- package/shared/actions/requestMeta.js +36 -0
- package/shared/actions/textNormalization.js +3 -0
- package/shared/actions/withActionDefaults.js +34 -0
- package/shared/index.js +2 -0
- package/shared/runtime/application.js +323 -0
- package/shared/runtime/container.js +261 -0
- package/shared/runtime/containerErrors.js +22 -0
- package/shared/runtime/index.js +18 -0
- package/shared/runtime/kernelErrors.js +20 -0
- package/shared/runtime/serviceProvider.js +13 -0
- package/shared/support/formatDateTime.js +10 -0
- package/shared/support/formatDateTime.test.js +15 -0
- package/shared/support/index.js +14 -0
- package/shared/support/linkPath.js +67 -0
- package/shared/support/linkPath.test.js +35 -0
- package/shared/support/normalize.js +116 -0
- package/shared/support/normalize.test.js +48 -0
- package/shared/support/packageDescriptor.test.js +121 -0
- package/shared/support/permissions.js +50 -0
- package/shared/support/pickOwnProperties.js +17 -0
- package/shared/support/pickOwnProperties.test.js +25 -0
- package/shared/support/policies.js +11 -0
- package/shared/support/queryPath.js +33 -0
- package/shared/support/queryPath.test.js +19 -0
- package/shared/support/queryResilience.js +34 -0
- package/shared/support/queryResilience.test.js +33 -0
- package/shared/support/returnToPath.js +153 -0
- package/shared/support/returnToPath.test.js +123 -0
- package/shared/support/sorting.js +15 -0
- package/shared/support/tokens.js +23 -0
- package/shared/support/tokens.test.js +17 -0
- package/shared/support/visibility.js +56 -0
- package/shared/support/visibility.test.js +45 -0
- package/shared/surface/apiPaths.js +84 -0
- package/shared/surface/escapeRegExp.js +5 -0
- package/shared/surface/index.js +6 -0
- package/shared/surface/paths.js +273 -0
- package/shared/surface/registry.js +135 -0
- package/shared/surface/registry.test.js +44 -0
- package/shared/surface/runtime.js +357 -0
- package/shared/surface/runtime.test.js +319 -0
- package/shared/validators/createCursorListValidator.js +42 -0
- package/shared/validators/createCursorListValidator.test.js +34 -0
- package/shared/validators/cursorPaginationQueryValidator.js +31 -0
- package/shared/validators/cursorPaginationQueryValidator.test.js +21 -0
- package/shared/validators/index.js +12 -0
- package/shared/validators/inputNormalization.js +13 -0
- package/shared/validators/mergeObjectSchemas.js +31 -0
- package/shared/validators/mergeObjectSchemas.test.js +67 -0
- package/shared/validators/mergeValidators.js +89 -0
- package/shared/validators/mergeValidators.test.js +116 -0
- package/shared/validators/nestValidator.js +53 -0
- package/shared/validators/nestValidator.test.js +60 -0
- package/shared/validators/recordIdParamsValidator.js +36 -0
- package/shared/validators/recordIdParamsValidator.test.js +20 -0
- package/shared/validators/resourceRequiredMetadata.js +41 -0
- package/shared/validators/resourceRequiredMetadata.test.js +49 -0
- package/test/barrelExposure.test.js +106 -0
- package/test/dynamicImportPolicy.test.js +89 -0
- package/test/exportsContract.test.js +168 -0
- package/test/routeInputContractGuard.test.js +78 -0
- package/test/surfaceIndependence.test.js +109 -0
package/README.md
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
# kernel
|
|
2
|
+
|
|
3
|
+
Internal JSKIT framework runtime package.
|
|
4
|
+
|
|
5
|
+
This package contains the merged runtime internals:
|
|
6
|
+
- container
|
|
7
|
+
- kernel
|
|
8
|
+
- http fastify bridge
|
|
9
|
+
- server runtime primitives
|
|
10
|
+
- support primitives
|
|
11
|
+
- surface routing primitives
|
|
12
|
+
- platform runtime bootstrap
|
|
13
|
+
|
|
14
|
+
## Historical note
|
|
15
|
+
|
|
16
|
+
kernel was assembled moving code from these legacy packages and then deleting them:
|
|
17
|
+
|
|
18
|
+
- @jskit-ai/container-core
|
|
19
|
+
- @jskit-ai/http-fastify-core
|
|
20
|
+
- @jskit-ai/kernel
|
|
21
|
+
- @jskit-ai/platform-server-runtime
|
|
22
|
+
- @jskit-ai/server-runtime-core
|
|
23
|
+
- @jskit-ai/support-core
|
|
24
|
+
- @jskit-ai/surface-routing
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { createContainer } from "../server/container/index.js";
|
|
2
|
+
export { createApplication } from "../server/kernel/index.js";
|
|
3
|
+
export { createHttpRuntime, compileRouteValidator } from "../server/http/_testable/index.js";
|
|
4
|
+
export { deriveResourceRequiredMetadata } from "../shared/validators/index.js";
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { isRecord } from "../shared/support/normalize.js";
|
|
2
|
+
|
|
3
|
+
const CLIENT_APP_CONFIG_GLOBAL_KEY = "__JSKIT_CLIENT_APP_CONFIG__";
|
|
4
|
+
const EMPTY_CLIENT_APP_CONFIG = Object.freeze({});
|
|
5
|
+
|
|
6
|
+
function normalizeClientAppConfig(source = {}) {
|
|
7
|
+
if (!isRecord(source)) {
|
|
8
|
+
return EMPTY_CLIENT_APP_CONFIG;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
return Object.freeze({ ...source });
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
function setClientAppConfig(source = {}) {
|
|
15
|
+
const appConfig = normalizeClientAppConfig(source);
|
|
16
|
+
|
|
17
|
+
if (typeof globalThis === "object" && globalThis) {
|
|
18
|
+
globalThis[CLIENT_APP_CONFIG_GLOBAL_KEY] = appConfig;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
return appConfig;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function getClientAppConfig() {
|
|
25
|
+
if (typeof globalThis !== "object" || !globalThis) {
|
|
26
|
+
return EMPTY_CLIENT_APP_CONFIG;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const appConfig = globalThis[CLIENT_APP_CONFIG_GLOBAL_KEY];
|
|
30
|
+
return isRecord(appConfig) ? appConfig : EMPTY_CLIENT_APP_CONFIG;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export { CLIENT_APP_CONFIG_GLOBAL_KEY, setClientAppConfig, getClientAppConfig };
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import {
|
|
2
|
+
normalizeObject,
|
|
3
|
+
normalizeText
|
|
4
|
+
} from "../shared/support/normalize.js";
|
|
5
|
+
|
|
6
|
+
function createComponentInteractionEmitter(emit) {
|
|
7
|
+
if (typeof emit !== "function") {
|
|
8
|
+
throw new TypeError("createComponentInteractionEmitter expects emit to be a function.");
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
function emitInteraction(type, payload = {}) {
|
|
12
|
+
emit("interaction", {
|
|
13
|
+
type: normalizeText(type),
|
|
14
|
+
...normalizeObject(payload)
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
async function invokeAction(actionName, payload, callback) {
|
|
19
|
+
emit("action:started", {
|
|
20
|
+
action: normalizeText(actionName),
|
|
21
|
+
payload
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
try {
|
|
25
|
+
if (typeof callback === "function") {
|
|
26
|
+
await callback();
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
emit("action:succeeded", {
|
|
30
|
+
action: normalizeText(actionName),
|
|
31
|
+
payload
|
|
32
|
+
});
|
|
33
|
+
} catch (errorValue) {
|
|
34
|
+
emit("action:failed", {
|
|
35
|
+
action: normalizeText(actionName),
|
|
36
|
+
payload,
|
|
37
|
+
message: String(errorValue?.message || "Action failed")
|
|
38
|
+
});
|
|
39
|
+
throw errorValue;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
return Object.freeze({
|
|
44
|
+
emitInteraction,
|
|
45
|
+
invokeAction
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export {
|
|
50
|
+
createComponentInteractionEmitter
|
|
51
|
+
};
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import test from "node:test";
|
|
3
|
+
import { createComponentInteractionEmitter } from "./componentInteraction.js";
|
|
4
|
+
|
|
5
|
+
test("createComponentInteractionEmitter requires emit function", () => {
|
|
6
|
+
assert.throws(
|
|
7
|
+
() => createComponentInteractionEmitter(null),
|
|
8
|
+
/expects emit to be a function/
|
|
9
|
+
);
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
test("createComponentInteractionEmitter emits interaction payload", () => {
|
|
13
|
+
const events = [];
|
|
14
|
+
const helpers = createComponentInteractionEmitter((name, payload) => {
|
|
15
|
+
events.push({
|
|
16
|
+
name,
|
|
17
|
+
payload
|
|
18
|
+
});
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
helpers.emitInteraction("profile:submit", {
|
|
22
|
+
id: 42
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
assert.deepEqual(events, [
|
|
26
|
+
{
|
|
27
|
+
name: "interaction",
|
|
28
|
+
payload: {
|
|
29
|
+
type: "profile:submit",
|
|
30
|
+
id: 42
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
]);
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
test("createComponentInteractionEmitter emits action lifecycle for success", async () => {
|
|
37
|
+
const events = [];
|
|
38
|
+
const helpers = createComponentInteractionEmitter((name, payload) => {
|
|
39
|
+
events.push({
|
|
40
|
+
name,
|
|
41
|
+
payload
|
|
42
|
+
});
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
await helpers.invokeAction("save", {
|
|
46
|
+
id: 1
|
|
47
|
+
}, async () => {});
|
|
48
|
+
|
|
49
|
+
assert.deepEqual(events, [
|
|
50
|
+
{
|
|
51
|
+
name: "action:started",
|
|
52
|
+
payload: {
|
|
53
|
+
action: "save",
|
|
54
|
+
payload: {
|
|
55
|
+
id: 1
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
},
|
|
59
|
+
{
|
|
60
|
+
name: "action:succeeded",
|
|
61
|
+
payload: {
|
|
62
|
+
action: "save",
|
|
63
|
+
payload: {
|
|
64
|
+
id: 1
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
]);
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
test("createComponentInteractionEmitter emits action failure and rethrows", async () => {
|
|
72
|
+
const events = [];
|
|
73
|
+
const helpers = createComponentInteractionEmitter((name, payload) => {
|
|
74
|
+
events.push({
|
|
75
|
+
name,
|
|
76
|
+
payload
|
|
77
|
+
});
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
await assert.rejects(
|
|
81
|
+
() =>
|
|
82
|
+
helpers.invokeAction("save", {
|
|
83
|
+
id: 1
|
|
84
|
+
}, async () => {
|
|
85
|
+
throw new Error("boom");
|
|
86
|
+
}),
|
|
87
|
+
/boom/
|
|
88
|
+
);
|
|
89
|
+
|
|
90
|
+
assert.deepEqual(events, [
|
|
91
|
+
{
|
|
92
|
+
name: "action:started",
|
|
93
|
+
payload: {
|
|
94
|
+
action: "save",
|
|
95
|
+
payload: {
|
|
96
|
+
id: 1
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
},
|
|
100
|
+
{
|
|
101
|
+
name: "action:failed",
|
|
102
|
+
payload: {
|
|
103
|
+
action: "save",
|
|
104
|
+
payload: {
|
|
105
|
+
id: 1
|
|
106
|
+
},
|
|
107
|
+
message: "boom"
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
]);
|
|
111
|
+
});
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { isRecord } from "../shared/support/normalize.js";
|
|
2
|
+
import { sortStrings } from "../shared/support/sorting.js";
|
|
3
|
+
|
|
4
|
+
function normalizeDescriptorUiRoutes(value) {
|
|
5
|
+
const routeEntries = Array.isArray(value) ? value : [];
|
|
6
|
+
const normalizedRoutes = [];
|
|
7
|
+
|
|
8
|
+
for (const routeEntry of routeEntries) {
|
|
9
|
+
if (!isRecord(routeEntry)) {
|
|
10
|
+
continue;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
try {
|
|
14
|
+
normalizedRoutes.push(Object.freeze(JSON.parse(JSON.stringify(routeEntry))));
|
|
15
|
+
} catch {
|
|
16
|
+
// Skip non-serializable route declarations.
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
return Object.freeze(normalizedRoutes);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function normalizeDescriptorClientProviders(value) {
|
|
24
|
+
const entries = Array.isArray(value) ? value : [];
|
|
25
|
+
const providers = [];
|
|
26
|
+
|
|
27
|
+
for (const entry of entries) {
|
|
28
|
+
if (!isRecord(entry)) {
|
|
29
|
+
continue;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const exportName = String(entry.export || "").trim();
|
|
33
|
+
if (!exportName) {
|
|
34
|
+
continue;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
providers.push(
|
|
38
|
+
Object.freeze({
|
|
39
|
+
export: exportName,
|
|
40
|
+
entrypoint: String(entry.entrypoint || "").trim()
|
|
41
|
+
})
|
|
42
|
+
);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
return Object.freeze(providers);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function normalizeDescriptorClientOptimizeIncludeSpecifiers(value) {
|
|
49
|
+
return Object.freeze(sortStrings(value));
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function normalizeClientDescriptorSections(descriptorValue) {
|
|
53
|
+
const descriptor = isRecord(descriptorValue) ? descriptorValue : {};
|
|
54
|
+
const metadata = isRecord(descriptor.metadata) ? descriptor.metadata : {};
|
|
55
|
+
const runtime = isRecord(descriptor.runtime) ? descriptor.runtime : {};
|
|
56
|
+
const ui = isRecord(metadata.ui) ? metadata.ui : {};
|
|
57
|
+
const clientMetadata = isRecord(metadata.client) ? metadata.client : {};
|
|
58
|
+
const optimizeDeps = isRecord(clientMetadata.optimizeDeps) ? clientMetadata.optimizeDeps : {};
|
|
59
|
+
const runtimeClient = isRecord(runtime.client) ? runtime.client : {};
|
|
60
|
+
|
|
61
|
+
return Object.freeze({
|
|
62
|
+
descriptorUiRoutes: normalizeDescriptorUiRoutes(ui.routes),
|
|
63
|
+
descriptorClientProviders: normalizeDescriptorClientProviders(runtimeClient.providers),
|
|
64
|
+
descriptorClientOptimizeIncludeSpecifiers: normalizeDescriptorClientOptimizeIncludeSpecifiers(
|
|
65
|
+
optimizeDeps.include
|
|
66
|
+
)
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export {
|
|
71
|
+
normalizeDescriptorUiRoutes,
|
|
72
|
+
normalizeDescriptorClientProviders,
|
|
73
|
+
normalizeDescriptorClientOptimizeIncludeSpecifiers,
|
|
74
|
+
normalizeClientDescriptorSections
|
|
75
|
+
};
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
export type ClientLogger = {
|
|
2
|
+
info?: (...args: any[]) => void;
|
|
3
|
+
warn?: (...args: any[]) => void;
|
|
4
|
+
error?: (...args: any[]) => void;
|
|
5
|
+
debug?: (...args: any[]) => void;
|
|
6
|
+
isDebugEnabled?: boolean;
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
export function getClientAppConfig(): Readonly<Record<string, any>>;
|
|
10
|
+
|
|
11
|
+
export function resolveClientBootstrapDebugEnabled(options?: {
|
|
12
|
+
env?: Record<string, any>;
|
|
13
|
+
debugEnabled?: boolean;
|
|
14
|
+
debugEnvKey?: string;
|
|
15
|
+
}): boolean;
|
|
16
|
+
|
|
17
|
+
export function createShellRouter(options?: {
|
|
18
|
+
createRouter: (options: { history?: any; routes: any[] }) => any;
|
|
19
|
+
history?: any;
|
|
20
|
+
routes?: any[];
|
|
21
|
+
surfaceRuntime: any;
|
|
22
|
+
surfaceMode?: string;
|
|
23
|
+
fallbackRoute?: any;
|
|
24
|
+
notFoundComponent?: any;
|
|
25
|
+
guard?: false | ((to: any) => any) | Record<string, any>;
|
|
26
|
+
}): Readonly<{
|
|
27
|
+
router: any;
|
|
28
|
+
activeRoutes: readonly any[];
|
|
29
|
+
fallbackRoute: any;
|
|
30
|
+
}>;
|
|
31
|
+
|
|
32
|
+
export function bootstrapClientShellApp(options?: {
|
|
33
|
+
createApp: (rootComponent: any) => any;
|
|
34
|
+
rootComponent: any;
|
|
35
|
+
appConfig?: Record<string, any>;
|
|
36
|
+
appPlugins?: any[];
|
|
37
|
+
router: any;
|
|
38
|
+
bootClientModules: (context: any) => Promise<any>;
|
|
39
|
+
surfaceRuntime: any;
|
|
40
|
+
surfaceMode?: string;
|
|
41
|
+
env?: Record<string, any>;
|
|
42
|
+
fallbackRoute?: any;
|
|
43
|
+
logger?: ClientLogger;
|
|
44
|
+
createBootstrapLogger?: (options: {
|
|
45
|
+
env?: Record<string, any>;
|
|
46
|
+
logger?: ClientLogger;
|
|
47
|
+
debugEnabled?: boolean;
|
|
48
|
+
debugEnvKey?: string;
|
|
49
|
+
}) => ClientLogger;
|
|
50
|
+
debugEnabled?: boolean;
|
|
51
|
+
debugEnvKey?: string;
|
|
52
|
+
debugMessage?: string;
|
|
53
|
+
onAfterModulesBootstrapped?: (context: any) => void | Promise<void>;
|
|
54
|
+
mountSelector?: string;
|
|
55
|
+
}): Promise<
|
|
56
|
+
Readonly<{
|
|
57
|
+
app: any;
|
|
58
|
+
router: any;
|
|
59
|
+
clientBootstrap: any;
|
|
60
|
+
logger: Required<ClientLogger>;
|
|
61
|
+
debugEnabled: boolean;
|
|
62
|
+
}>
|
|
63
|
+
>;
|
|
64
|
+
|
|
65
|
+
export function createComponentInteractionEmitter(
|
|
66
|
+
emit: (eventName: string, payload: any) => void
|
|
67
|
+
): Readonly<{
|
|
68
|
+
emitInteraction: (type: string, payload?: Record<string, any>) => void;
|
|
69
|
+
invokeAction: (actionName: string, payload: any, callback?: () => Promise<any> | any) => Promise<void>;
|
|
70
|
+
}>;
|
package/client/index.js
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export { getClientAppConfig } from "./appConfig.js";
|
|
2
|
+
export { resolveClientBootstrapDebugEnabled, createSurfaceShellRouter as createShellRouter, bootstrapClientShellApp } from "./shellBootstrap.js";
|
|
3
|
+
export { createComponentInteractionEmitter } from "./componentInteraction.js";
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { isRecord } from "../shared/support/normalize.js";
|
|
2
|
+
|
|
3
|
+
function createStructuredLogger(logger = console) {
|
|
4
|
+
if (isRecord(logger)) {
|
|
5
|
+
return Object.freeze({
|
|
6
|
+
info: typeof logger.info === "function" ? logger.info.bind(logger) : console.info.bind(console),
|
|
7
|
+
warn: typeof logger.warn === "function" ? logger.warn.bind(logger) : console.warn.bind(console),
|
|
8
|
+
error: typeof logger.error === "function" ? logger.error.bind(logger) : console.error.bind(console),
|
|
9
|
+
debug: typeof logger.debug === "function" ? logger.debug.bind(logger) : () => {}
|
|
10
|
+
});
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
return Object.freeze({
|
|
14
|
+
info: console.info.bind(console),
|
|
15
|
+
warn: console.warn.bind(console),
|
|
16
|
+
error: console.error.bind(console),
|
|
17
|
+
debug: () => {}
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function summarizeRouterRoutes(router) {
|
|
22
|
+
if (!router || typeof router.getRoutes !== "function") {
|
|
23
|
+
return Object.freeze([]);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
return Object.freeze(
|
|
27
|
+
router.getRoutes().map((route) =>
|
|
28
|
+
Object.freeze({
|
|
29
|
+
name: String(route?.name || "").trim(),
|
|
30
|
+
path: String(route?.path || "").trim(),
|
|
31
|
+
metaScope: String(route?.meta?.jskit?.scope || "").trim(),
|
|
32
|
+
metaSurface: String(route?.meta?.jskit?.surface || "").trim()
|
|
33
|
+
})
|
|
34
|
+
)
|
|
35
|
+
);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export { createStructuredLogger, summarizeRouterRoutes };
|