@bleedingdev/modern-js-plugin-bff 3.5.0-ultramodern.102 → 3.5.0-ultramodern.103
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/dist/cjs/cli/compress.js +1 -1
- package/dist/cjs/cli/generator.js +106 -108
- package/dist/cjs/cli/serverGlobalVars.js +43 -57
- package/dist/cjs/loader.js +1 -1
- package/dist/cjs/runtime/effect/adapter/cross-project-policy.js +17 -12
- package/dist/cjs/runtime/effect/adapter/error-response.js +11 -9
- package/dist/cjs/runtime/effect/adapter.js +2 -2
- package/dist/cjs/runtime/effect/backend-federation/load.js +26 -17
- package/dist/cjs/runtime/effect/backend-federation/plugin.js +12 -2
- package/dist/cjs/runtime/effect/backend-federation/remotes.js +5 -4
- package/dist/cjs/runtime/effect/backend-federation/runtime.js +80 -16
- package/dist/cjs/runtime/effect/edge-dispatcher.js +148 -0
- package/dist/cjs/runtime/effect/edge.js +19 -100
- package/dist/cjs/utils/effect-client-generator/generator.js +17 -16
- package/dist/cjs/utils/effect-client-generator/paths.js +4 -15
- package/dist/cjs/utils/effect-client-generator/rendering.js +8 -19
- package/dist/cjs/utils/effect-client-generator/runtime.js +15 -32
- package/dist/cjs/utils/effectSourceLoader.js +10 -6
- package/dist/esm/cli/compress.mjs +1 -1
- package/dist/esm/cli/generator.mjs +107 -108
- package/dist/esm/cli/serverGlobalVars.mjs +44 -48
- package/dist/esm/loader.mjs +1 -1
- package/dist/esm/runtime/effect/adapter/cross-project-policy.mjs +17 -12
- package/dist/esm/runtime/effect/adapter/error-response.mjs +11 -9
- package/dist/esm/runtime/effect/adapter.mjs +3 -3
- package/dist/esm/runtime/effect/backend-federation/load.mjs +26 -17
- package/dist/esm/runtime/effect/backend-federation/plugin.mjs +12 -2
- package/dist/esm/runtime/effect/backend-federation/remotes.mjs +5 -4
- package/dist/esm/runtime/effect/backend-federation/runtime.mjs +80 -16
- package/dist/esm/runtime/effect/edge-dispatcher.mjs +38 -0
- package/dist/esm/runtime/effect/edge.mjs +1 -38
- package/dist/esm/utils/effect-client-generator/generator.mjs +17 -16
- package/dist/esm/utils/effect-client-generator/paths.mjs +5 -6
- package/dist/esm/utils/effect-client-generator/rendering.mjs +9 -10
- package/dist/esm/utils/effect-client-generator/runtime.mjs +16 -23
- package/dist/esm/utils/effectSourceLoader.mjs +8 -7
- package/dist/esm-node/cli/compress.mjs +1 -1
- package/dist/esm-node/cli/generator.mjs +107 -108
- package/dist/esm-node/cli/serverGlobalVars.mjs +44 -48
- package/dist/esm-node/loader.mjs +1 -1
- package/dist/esm-node/runtime/effect/adapter/cross-project-policy.mjs +17 -12
- package/dist/esm-node/runtime/effect/adapter/error-response.mjs +11 -9
- package/dist/esm-node/runtime/effect/adapter.mjs +3 -3
- package/dist/esm-node/runtime/effect/backend-federation/load.mjs +26 -17
- package/dist/esm-node/runtime/effect/backend-federation/plugin.mjs +12 -2
- package/dist/esm-node/runtime/effect/backend-federation/remotes.mjs +5 -4
- package/dist/esm-node/runtime/effect/backend-federation/runtime.mjs +80 -16
- package/dist/esm-node/runtime/effect/edge-dispatcher.mjs +39 -0
- package/dist/esm-node/runtime/effect/edge.mjs +1 -38
- package/dist/esm-node/utils/effect-client-generator/generator.mjs +17 -16
- package/dist/esm-node/utils/effect-client-generator/paths.mjs +5 -6
- package/dist/esm-node/utils/effect-client-generator/rendering.mjs +9 -10
- package/dist/esm-node/utils/effect-client-generator/runtime.mjs +16 -23
- package/dist/esm-node/utils/effectSourceLoader.mjs +8 -7
- package/dist/types/cli/generator.d.ts +2 -2
- package/dist/types/cli/serverGlobalVars.d.ts +4 -2
- package/dist/types/runtime/effect/adapter/cross-project-policy.d.ts +1 -1
- package/dist/types/runtime/effect/backend-federation/runtime.d.ts +1 -1
- package/dist/types/runtime/effect/edge-dispatcher.d.ts +26 -0
- package/dist/types/runtime/effect/edge.d.ts +1 -26
- package/dist/types/utils/effectSourceLoader.d.ts +10 -0
- package/package.json +34 -18
|
@@ -1,26 +1,90 @@
|
|
|
1
|
+
import { ModuleFederation } from "@module-federation/runtime";
|
|
1
2
|
import { loadBackendFederationExpose } from "./entry.mjs";
|
|
3
|
+
import { createBackendFederationLoadEntryPlugin } from "./plugin.mjs";
|
|
2
4
|
import { collectRemotes } from "./remotes.mjs";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
return `./${normalizeExpose(expose)}`;
|
|
5
|
+
function _check_private_redeclaration(obj, privateCollection) {
|
|
6
|
+
if (privateCollection.has(obj)) throw new TypeError("Cannot initialize the same private elements twice on an object");
|
|
6
7
|
}
|
|
8
|
+
function _class_apply_descriptor_get(receiver, descriptor) {
|
|
9
|
+
if (descriptor.get) return descriptor.get.call(receiver);
|
|
10
|
+
return descriptor.value;
|
|
11
|
+
}
|
|
12
|
+
function _class_apply_descriptor_set(receiver, descriptor, value) {
|
|
13
|
+
if (descriptor.set) descriptor.set.call(receiver, value);
|
|
14
|
+
else {
|
|
15
|
+
if (!descriptor.writable) throw new TypeError("attempted to set read only private field");
|
|
16
|
+
descriptor.value = value;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
function _class_extract_field_descriptor(receiver, privateMap, action) {
|
|
20
|
+
if (!privateMap.has(receiver)) throw new TypeError("attempted to " + action + " private field on non-instance");
|
|
21
|
+
return privateMap.get(receiver);
|
|
22
|
+
}
|
|
23
|
+
function _class_private_field_get(receiver, privateMap) {
|
|
24
|
+
var descriptor = _class_extract_field_descriptor(receiver, privateMap, "get");
|
|
25
|
+
return _class_apply_descriptor_get(receiver, descriptor);
|
|
26
|
+
}
|
|
27
|
+
function _class_private_field_init(obj, privateMap, value) {
|
|
28
|
+
_check_private_redeclaration(obj, privateMap);
|
|
29
|
+
privateMap.set(obj, value);
|
|
30
|
+
}
|
|
31
|
+
function _class_private_field_set(receiver, privateMap, value) {
|
|
32
|
+
var descriptor = _class_extract_field_descriptor(receiver, privateMap, "set");
|
|
33
|
+
_class_apply_descriptor_set(receiver, descriptor, value);
|
|
34
|
+
return value;
|
|
35
|
+
}
|
|
36
|
+
let nextRuntimeId = 0;
|
|
7
37
|
function parseRemoteRequest(request) {
|
|
8
38
|
const [remoteName, ...exposeParts] = request.split('/');
|
|
9
|
-
if (
|
|
10
|
-
return
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
39
|
+
if (void 0 === remoteName || 0 === remoteName.length || 0 === exposeParts.length) return;
|
|
40
|
+
return remoteName;
|
|
41
|
+
}
|
|
42
|
+
function createLocalEntryPlugin(options, remotes) {
|
|
43
|
+
return createBackendFederationLoadEntryPlugin({
|
|
44
|
+
resolveEntry (resolvedRemote) {
|
|
45
|
+
const remote = remotes.find((candidate)=>candidate.name === resolvedRemote.name);
|
|
46
|
+
if (void 0 === remote) return;
|
|
47
|
+
return {
|
|
48
|
+
get (expose) {
|
|
49
|
+
return ()=>loadBackendFederationExpose(remote, expose, options);
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
function isolateRegisteredRemoteEntries(remotes) {
|
|
56
|
+
const runtimeId = nextRuntimeId;
|
|
57
|
+
nextRuntimeId += 1;
|
|
58
|
+
return remotes.map((remote)=>({
|
|
59
|
+
...remote,
|
|
60
|
+
entry: `${remote.entry}#modernjs-backend-runtime-${runtimeId}`
|
|
61
|
+
}));
|
|
62
|
+
}
|
|
63
|
+
var _remoteNames = /*#__PURE__*/ new WeakMap();
|
|
64
|
+
class BackendFederationRuntime extends ModuleFederation {
|
|
65
|
+
loadRemote(request, loadOptions) {
|
|
66
|
+
const remoteName = parseRemoteRequest(request);
|
|
67
|
+
if (void 0 === remoteName) return Promise.reject(new Error(`[BFF][Effect] Invalid backend federation request ${request}.`));
|
|
68
|
+
if (!_class_private_field_get(this, _remoteNames).has(remoteName)) return Promise.reject(new Error(`[BFF][Effect] Missing backend federation remote ${remoteName}.`));
|
|
69
|
+
return super.loadRemote(request, loadOptions);
|
|
70
|
+
}
|
|
71
|
+
constructor(options, remotes){
|
|
72
|
+
super({
|
|
73
|
+
name: options.hostName,
|
|
74
|
+
remotes: isolateRegisteredRemoteEntries(remotes),
|
|
75
|
+
shared: {},
|
|
76
|
+
plugins: [
|
|
77
|
+
createLocalEntryPlugin(options, remotes)
|
|
78
|
+
]
|
|
79
|
+
}), _class_private_field_init(this, _remoteNames, {
|
|
80
|
+
writable: true,
|
|
81
|
+
value: void 0
|
|
82
|
+
});
|
|
83
|
+
_class_private_field_set(this, _remoteNames, new Set(remotes.map((remote)=>remote.name)));
|
|
84
|
+
}
|
|
14
85
|
}
|
|
15
86
|
function createBackendFederationRuntime(options) {
|
|
16
87
|
const remotes = collectRemotes(options);
|
|
17
|
-
return
|
|
18
|
-
async loadRemote (request) {
|
|
19
|
-
const { remoteName, expose } = parseRemoteRequest(request);
|
|
20
|
-
const remote = remotes.find((candidate)=>candidate.name === remoteName);
|
|
21
|
-
if (!remote) throw new Error(`[BFF][Effect] Missing backend federation remote ${remoteName}.`);
|
|
22
|
-
return loadBackendFederationExpose(remote, expose, options);
|
|
23
|
-
}
|
|
24
|
-
};
|
|
88
|
+
return new BackendFederationRuntime(options, remotes);
|
|
25
89
|
}
|
|
26
90
|
export { createBackendFederationRuntime };
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { dispatchEffectBffRequestWithContext } from "./dispatch.mjs";
|
|
2
|
+
import { runWithEffectContext, useEffectContext, useOperationContext } from "./edge-context.mjs";
|
|
3
|
+
import { resolveEffectBffModuleHandler } from "./module.mjs";
|
|
4
|
+
export * from "./handler.mjs";
|
|
5
|
+
async function dispatchEffectBffRequest(handler, request, options = {}) {
|
|
6
|
+
return dispatchEffectBffRequestWithContext(handler, request, {
|
|
7
|
+
...options,
|
|
8
|
+
runWithEffectContext: runWithEffectContext
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
async function createEffectBffEdgeDispatcher(options) {
|
|
12
|
+
const loaded = await resolveEffectBffModuleHandler(options.module, {
|
|
13
|
+
openapi: options.openapi,
|
|
14
|
+
dataPlatform: options.dataPlatform,
|
|
15
|
+
onWarning: options.onWarning
|
|
16
|
+
});
|
|
17
|
+
if (!loaded) throw new Error('[BFF][Effect] Invalid Effect edge module. Export defineEffectBff(...) or a { api, layer } HttpApi module.');
|
|
18
|
+
return {
|
|
19
|
+
dispatch: (request, dispatchOptions = {})=>dispatchEffectBffRequest(loaded.handler, request, {
|
|
20
|
+
...dispatchOptions,
|
|
21
|
+
prefix: options.prefix,
|
|
22
|
+
onError: options.onError
|
|
23
|
+
}),
|
|
24
|
+
dispose: async ()=>{
|
|
25
|
+
await loaded.dispose?.();
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
const createEffectBffTestHandler = createEffectBffEdgeHandler;
|
|
30
|
+
async function createEffectBffEdgeHandler(options) {
|
|
31
|
+
const dispatcher = await createEffectBffEdgeDispatcher(options);
|
|
32
|
+
return {
|
|
33
|
+
handler: dispatcher.dispatch,
|
|
34
|
+
dispose: dispatcher.dispose
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
export { createEffectOperationContext } from "./operation-context.mjs";
|
|
38
|
+
export { createEffectBffEdgeDispatcher, createEffectBffEdgeHandler, createEffectBffTestHandler, dispatchEffectBffRequest, runWithEffectContext, useEffectContext, useOperationContext };
|
|
@@ -1,39 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
import { runWithEffectContext, useEffectContext, useOperationContext } from "./edge-context.mjs";
|
|
3
|
-
import { resolveEffectBffModuleHandler } from "./module.mjs";
|
|
4
|
-
export * from "./handler.mjs";
|
|
5
|
-
async function dispatchEffectBffRequest(handler, request, options = {}) {
|
|
6
|
-
return dispatchEffectBffRequestWithContext(handler, request, {
|
|
7
|
-
...options,
|
|
8
|
-
runWithEffectContext: runWithEffectContext
|
|
9
|
-
});
|
|
10
|
-
}
|
|
11
|
-
async function createEffectBffEdgeDispatcher(options) {
|
|
12
|
-
const loaded = await resolveEffectBffModuleHandler(options.module, {
|
|
13
|
-
openapi: options.openapi,
|
|
14
|
-
dataPlatform: options.dataPlatform,
|
|
15
|
-
onWarning: options.onWarning
|
|
16
|
-
});
|
|
17
|
-
if (!loaded) throw new Error('[BFF][Effect] Invalid Effect edge module. Export defineEffectBff(...) or a { api, layer } HttpApi module.');
|
|
18
|
-
return {
|
|
19
|
-
dispatch: (request, dispatchOptions = {})=>dispatchEffectBffRequest(loaded.handler, request, {
|
|
20
|
-
...dispatchOptions,
|
|
21
|
-
prefix: options.prefix,
|
|
22
|
-
onError: options.onError
|
|
23
|
-
}),
|
|
24
|
-
dispose: async ()=>{
|
|
25
|
-
await loaded.dispose?.();
|
|
26
|
-
}
|
|
27
|
-
};
|
|
28
|
-
}
|
|
29
|
-
const createEffectBffTestHandler = createEffectBffEdgeHandler;
|
|
30
|
-
async function createEffectBffEdgeHandler(options) {
|
|
31
|
-
const dispatcher = await createEffectBffEdgeDispatcher(options);
|
|
32
|
-
return {
|
|
33
|
-
handler: dispatcher.dispatch,
|
|
34
|
-
dispose: dispatcher.dispose
|
|
35
|
-
};
|
|
36
|
-
}
|
|
1
|
+
export * from "./edge-dispatcher.mjs";
|
|
37
2
|
export { BACKEND_FEDERATION_CONTRACT_VERSION, BACKEND_FEDERATION_EFFECT_EXPOSE, BACKEND_FEDERATION_MANIFEST_FILE, BACKEND_FEDERATION_NODE_ADAPTER_VERSION, createBackendFederationLoadEntryPlugin, createBackendFederationRuntime, loadBackendFederatedEffectApi, validateExpectedBackendFederationIdentity } from "./backend-federation.mjs";
|
|
38
|
-
export { createEffectOperationContext } from "./operation-context.mjs";
|
|
39
|
-
export { createEffectBffEdgeDispatcher, createEffectBffEdgeHandler, createEffectBffTestHandler, dispatchEffectBffRequest, runWithEffectContext, useEffectContext, useOperationContext };
|
|
@@ -2,26 +2,27 @@ import { logger } from "@modern-js/utils";
|
|
|
2
2
|
import { collectEffectEndpoints } from "../../runtime/effect/endpoint-contracts.mjs";
|
|
3
3
|
import { renderEffectClientCode, renderEffectClientDeclaration } from "./rendering.mjs";
|
|
4
4
|
import { getHttpApiRuntime, loadEffectApi } from "./runtime.mjs";
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
function generateEffectClient(options) {
|
|
6
|
+
return loadEffectApi({
|
|
7
7
|
appDir: options.appDir,
|
|
8
8
|
resourcePath: options.resourcePath,
|
|
9
9
|
onDependency: options.onDependency
|
|
10
|
+
}).then((api)=>{
|
|
11
|
+
if (null === api) {
|
|
12
|
+
logger.warn(`[BFF][Effect] Failed to generate client for ${options.resourcePath}: unable to resolve exported HttpApi.`);
|
|
13
|
+
return null;
|
|
14
|
+
}
|
|
15
|
+
return getHttpApiRuntime().then((httpApiRuntime)=>{
|
|
16
|
+
const endpoints = collectEffectEndpoints(httpApiRuntime.reflect, api, options.prefix);
|
|
17
|
+
return {
|
|
18
|
+
code: renderEffectClientCode(endpoints, options),
|
|
19
|
+
declaration: renderEffectClientDeclaration(endpoints),
|
|
20
|
+
endpoints
|
|
21
|
+
};
|
|
22
|
+
});
|
|
10
23
|
});
|
|
11
|
-
if (!api) {
|
|
12
|
-
logger.warn(`[BFF][Effect] Failed to generate client for ${options.resourcePath}: unable to resolve exported HttpApi.`);
|
|
13
|
-
return null;
|
|
14
|
-
}
|
|
15
|
-
const httpApiRuntime = await getHttpApiRuntime();
|
|
16
|
-
const endpoints = collectEffectEndpoints(httpApiRuntime.reflect, api, options.prefix);
|
|
17
|
-
return {
|
|
18
|
-
code: renderEffectClientCode(endpoints, options),
|
|
19
|
-
declaration: renderEffectClientDeclaration(endpoints),
|
|
20
|
-
endpoints
|
|
21
|
-
};
|
|
22
24
|
}
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
return artifacts ? artifacts.code : null;
|
|
25
|
+
function generateEffectClientCode(options) {
|
|
26
|
+
return generateEffectClient(options).then((artifacts)=>null === artifacts ? null : artifacts.code);
|
|
26
27
|
}
|
|
27
28
|
export { generateEffectClient, generateEffectClientCode };
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { findExists, fs } from "@modern-js/utils";
|
|
2
|
-
import path from "path";
|
|
1
|
+
import { findExists, fs, upath } from "@modern-js/utils";
|
|
3
2
|
const JS_OR_TS_EXTS = [
|
|
4
3
|
'.js',
|
|
5
4
|
'.jsx',
|
|
@@ -13,13 +12,13 @@ const JS_OR_TS_EXTS = [
|
|
|
13
12
|
function resolveEffectEntryFile(options) {
|
|
14
13
|
const { appDir, apiDir, effectEntry } = options;
|
|
15
14
|
const resolveEntry = (entryWithoutExt)=>{
|
|
16
|
-
if (
|
|
15
|
+
if ('' !== upath.extname(entryWithoutExt)) return fs.existsSync(entryWithoutExt) ? entryWithoutExt : void 0;
|
|
17
16
|
return findExists(JS_OR_TS_EXTS.map((ext)=>`${entryWithoutExt}${ext}`));
|
|
18
17
|
};
|
|
19
|
-
if (effectEntry) {
|
|
20
|
-
const entryWithoutExt =
|
|
18
|
+
if (void 0 !== effectEntry && '' !== effectEntry) {
|
|
19
|
+
const entryWithoutExt = upath.isAbsolute(effectEntry) ? effectEntry : upath.resolve(appDir, effectEntry);
|
|
21
20
|
return resolveEntry(entryWithoutExt);
|
|
22
21
|
}
|
|
23
|
-
return resolveEntry(
|
|
22
|
+
return resolveEntry(upath.resolve(apiDir, 'index'));
|
|
24
23
|
}
|
|
25
24
|
export { resolveEffectEntryFile };
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { deriveOperationVersion } from "@modern-js/bff-core";
|
|
2
|
-
import { fs } from "@modern-js/utils";
|
|
3
|
-
import path from "path";
|
|
2
|
+
import { fs, upath } from "@modern-js/utils";
|
|
4
3
|
import { createEffectEndpointContractHash, ensureLeadingSlash, normalizeEffectPrefix } from "../../runtime/effect/endpoint-contracts.mjs";
|
|
5
4
|
const DEFAULT_REQUEST_CREATOR = '@modern-js/plugin-bff/client';
|
|
6
5
|
const EFFECT_CLIENT_RUNTIME_IMPORT = '@modern-js/plugin-bff/effect-client-runtime';
|
|
@@ -13,17 +12,17 @@ function isAbsoluteUrl(value) {
|
|
|
13
12
|
}
|
|
14
13
|
}
|
|
15
14
|
function resolveBatchEndpoint(prefix, endpoint) {
|
|
16
|
-
const value = endpoint || '/_data/batch';
|
|
15
|
+
const value = void 0 === endpoint || '' === endpoint ? '/_data/batch' : endpoint;
|
|
17
16
|
if (isAbsoluteUrl(value)) return value;
|
|
18
17
|
const normalizedPrefix = normalizeEffectPrefix(prefix);
|
|
19
18
|
const normalizedEndpoint = ensureLeadingSlash(value);
|
|
20
|
-
if (
|
|
19
|
+
if ('' === normalizedPrefix) return normalizedEndpoint;
|
|
21
20
|
if (normalizedEndpoint === normalizedPrefix || normalizedEndpoint.startsWith(`${normalizedPrefix}/`)) return normalizedEndpoint;
|
|
22
21
|
return `${normalizedPrefix}${'/' === normalizedEndpoint ? '' : normalizedEndpoint}`;
|
|
23
22
|
}
|
|
24
23
|
function getPackageInfo(appDir) {
|
|
25
24
|
try {
|
|
26
|
-
const packageJsonPath =
|
|
25
|
+
const packageJsonPath = upath.resolve(appDir, './package.json');
|
|
27
26
|
const packageJson = fs.readJSONSync(packageJsonPath);
|
|
28
27
|
return {
|
|
29
28
|
name: packageJson.name,
|
|
@@ -38,9 +37,9 @@ function renderEffectClientCode(endpoints, options) {
|
|
|
38
37
|
const httpMethodDecider = options.httpMethodDecider || 'functionName';
|
|
39
38
|
const packageInfo = getPackageInfo(options.appDir);
|
|
40
39
|
const packageName = packageInfo.name;
|
|
41
|
-
const dataPlatformAppNamespace = packageName || 'unknown-app';
|
|
42
|
-
const requestId = 'bundle' === options.target ? packageName
|
|
43
|
-
const normalizedRequestId = requestId || 'default';
|
|
40
|
+
const dataPlatformAppNamespace = void 0 === packageName || '' === packageName ? 'unknown-app' : packageName;
|
|
41
|
+
const requestId = 'bundle' === options.target ? void 0 !== packageName && '' !== packageName ? packageName : void 0 : void 0;
|
|
42
|
+
const normalizedRequestId = void 0 === requestId || '' === requestId ? 'default' : requestId;
|
|
44
43
|
const operationVersion = deriveOperationVersion(packageInfo.version);
|
|
45
44
|
const batchConfig = options.dataPlatformBatch;
|
|
46
45
|
const batchEndpoint = resolveBatchEndpoint(options.prefix, batchConfig?.endpoint);
|
|
@@ -57,7 +56,7 @@ function renderEffectClientCode(endpoints, options) {
|
|
|
57
56
|
};
|
|
58
57
|
const config = {
|
|
59
58
|
appNamespace: dataPlatformAppNamespace,
|
|
60
|
-
...requestId ? {
|
|
59
|
+
...void 0 !== requestId && '' !== requestId ? {
|
|
61
60
|
requestId
|
|
62
61
|
} : {},
|
|
63
62
|
port: options.port,
|
|
@@ -71,7 +70,7 @@ function renderEffectClientCode(endpoints, options) {
|
|
|
71
70
|
maxBatchSize: batchConfig?.maxBatchSize ?? 16,
|
|
72
71
|
maxBatchBytes: batchConfig?.maxBatchBytes ?? 65536,
|
|
73
72
|
requestTimeoutMs: batchConfig?.requestTimeoutMs ?? 10000,
|
|
74
|
-
allowedMethods: batchConfig?.allowedMethods && batchConfig.allowedMethods.length > 0 ? batchConfig.allowedMethods : [
|
|
73
|
+
allowedMethods: batchConfig?.allowedMethods !== void 0 && batchConfig.allowedMethods.length > 0 ? batchConfig.allowedMethods : [
|
|
75
74
|
'GET'
|
|
76
75
|
]
|
|
77
76
|
}
|
|
@@ -1,34 +1,27 @@
|
|
|
1
|
-
import { compatibleRequire } from "@modern-js/utils";
|
|
2
|
-
import path from "path";
|
|
1
|
+
import { compatibleRequire, upath } from "@modern-js/utils";
|
|
3
2
|
import { extractHttpApiFromModule } from "../../runtime/effect/endpoint-contracts.mjs";
|
|
4
3
|
import { loadEffectSourceModule } from "../effectSourceLoader.mjs";
|
|
5
4
|
let httpApiRuntimePromise;
|
|
6
5
|
function isRecord(value) {
|
|
7
6
|
return 'object' == typeof value && null !== value;
|
|
8
7
|
}
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
if (isRecord(mod) && isRecord(mod.HttpApi)) {
|
|
22
|
-
const maybeHttpApi = mod.HttpApi;
|
|
23
|
-
if ('function' == typeof maybeHttpApi.isHttpApi && 'function' == typeof maybeHttpApi.reflect) return maybeHttpApi;
|
|
24
|
-
}
|
|
8
|
+
function isHttpApiRuntime(value) {
|
|
9
|
+
return isRecord(value) && 'function' == typeof value.isHttpApi && 'function' == typeof value.reflect;
|
|
10
|
+
}
|
|
11
|
+
function getHttpApiRuntime() {
|
|
12
|
+
if (void 0 === httpApiRuntimePromise) httpApiRuntimePromise = compatibleRequire('effect/unstable/httpapi', false).catch((error)=>{
|
|
13
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
14
|
+
if (!message.includes("Cannot find module 'effect/unstable/httpapi'")) throw error;
|
|
15
|
+
const effectPackageJson = require.resolve('effect/package.json');
|
|
16
|
+
const effectHttpApiRuntimePath = upath.join(upath.dirname(effectPackageJson), 'dist', 'unstable', 'httpapi', 'index.js');
|
|
17
|
+
return compatibleRequire(effectHttpApiRuntimePath, false);
|
|
18
|
+
}).then((mod)=>{
|
|
19
|
+
if (isRecord(mod) && isHttpApiRuntime(mod.HttpApi)) return mod.HttpApi;
|
|
25
20
|
throw new Error('[BFF][Effect] Unable to resolve HttpApi runtime from effect/unstable/httpapi.');
|
|
26
|
-
})
|
|
21
|
+
});
|
|
27
22
|
return httpApiRuntimePromise;
|
|
28
23
|
}
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
const mod = await loadEffectSourceModule(options);
|
|
32
|
-
return extractHttpApiFromModule(mod, httpApiRuntime.isHttpApi);
|
|
24
|
+
function loadEffectApi(options) {
|
|
25
|
+
return getHttpApiRuntime().then((httpApiRuntime)=>loadEffectSourceModule(options).then((mod)=>extractHttpApiFromModule(mod, httpApiRuntime.isHttpApi)));
|
|
33
26
|
}
|
|
34
27
|
export { getHttpApiRuntime, loadEffectApi };
|
|
@@ -151,9 +151,7 @@ function externalizeInstalledDependencies(options) {
|
|
|
151
151
|
pluginData: resolution.pluginData,
|
|
152
152
|
sideEffects: resolution.sideEffects,
|
|
153
153
|
suffix: resolution.suffix,
|
|
154
|
-
warnings: resolution.warnings
|
|
155
|
-
watchDirs: resolution.watchDirs,
|
|
156
|
-
watchFiles: resolution.watchFiles
|
|
154
|
+
warnings: resolution.warnings
|
|
157
155
|
};
|
|
158
156
|
}
|
|
159
157
|
return {
|
|
@@ -168,9 +166,7 @@ function externalizeInstalledDependencies(options) {
|
|
|
168
166
|
pluginData: resolution.pluginData,
|
|
169
167
|
sideEffects: resolution.sideEffects,
|
|
170
168
|
suffix: resolution.suffix,
|
|
171
|
-
warnings: resolution.warnings
|
|
172
|
-
watchDirs: resolution.watchDirs,
|
|
173
|
-
watchFiles: resolution.watchFiles
|
|
169
|
+
warnings: resolution.warnings
|
|
174
170
|
};
|
|
175
171
|
});
|
|
176
172
|
}
|
|
@@ -208,6 +204,11 @@ function normalizeImportedModule(module) {
|
|
|
208
204
|
if (1 === Object.keys(namespace).length && null !== commonJsModule && 'object' == typeof commonJsModule && true === commonJsModule.__esModule) return commonJsModule;
|
|
209
205
|
return module;
|
|
210
206
|
}
|
|
207
|
+
async function loadEffectBuiltModule(resourcePath) {
|
|
208
|
+
const canonicalPath = await node_fs.promises.realpath(node_path.resolve(resourcePath));
|
|
209
|
+
if (!await isEsmOnlyFile(canonicalPath)) return createRequire(canonicalPath)(canonicalPath);
|
|
210
|
+
return normalizeImportedModule(await dynamicImport(pathToFileURL(canonicalPath).href));
|
|
211
|
+
}
|
|
211
212
|
async function loadEffectSourceModule(options) {
|
|
212
213
|
const resourcePath = node_path.resolve(options.resourcePath);
|
|
213
214
|
const appDir = node_path.resolve(options.appDir ?? node_path.dirname(resourcePath));
|
|
@@ -252,4 +253,4 @@ async function loadEffectSourceModule(options) {
|
|
|
252
253
|
const revision = node_crypto.createHash('sha256').update(output).digest('hex');
|
|
253
254
|
return normalizeImportedModule(await dynamicImport(`${pathToFileURL(outputPath).href}?v=${revision}`));
|
|
254
255
|
}
|
|
255
|
-
export { bundleEffectEntryForNode, loadEffectSourceModule };
|
|
256
|
+
export { bundleEffectEntryForNode, loadEffectBuiltModule, loadEffectSourceModule };
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import "node:module";
|
|
2
2
|
import { normalizePrefixList } from "./prefix.mjs";
|
|
3
3
|
const createCompressConfig = (devServer, prefix)=>{
|
|
4
|
-
if (
|
|
4
|
+
if (void 0 === devServer || 'object' != typeof devServer || Array.isArray(devServer)) return;
|
|
5
5
|
const { compress } = devServer;
|
|
6
6
|
if (void 0 === compress || true === compress) {
|
|
7
7
|
const prefixes = normalizePrefixList(prefix);
|