@bleedingdev/modern-js-plugin-bff 3.5.0-ultramodern.99 → 3.8.1-ultramodern.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/cli/compress.js +1 -1
- package/dist/cjs/cli/generator.js +106 -97
- package/dist/cjs/cli/serverGlobalVars.js +43 -57
- package/dist/cjs/cli.js +6 -2
- package/dist/cjs/loader.js +6 -5
- package/dist/cjs/runtime/effect/adapter/cross-project-policy.js +17 -12
- package/dist/cjs/runtime/effect/adapter/entry.js +13 -5
- 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/runtime/effect/handler/definition.js +1 -0
- package/dist/cjs/runtime/effect/handler/http.js +17 -6
- package/dist/cjs/utils/crossProjectApiPlugin.js +21 -2
- 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 +70 -10
- package/dist/cjs/utils/pluginGenerator.js +4 -4
- package/dist/esm/cli/compress.mjs +1 -1
- package/dist/esm/cli/generator.mjs +108 -98
- package/dist/esm/cli/serverGlobalVars.mjs +44 -48
- package/dist/esm/cli.mjs +2 -0
- package/dist/esm/loader.mjs +6 -5
- package/dist/esm/runtime/effect/adapter/cross-project-policy.mjs +17 -12
- package/dist/esm/runtime/effect/adapter/entry.mjs +13 -5
- 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/runtime/effect/handler/definition.mjs +1 -0
- package/dist/esm/runtime/effect/handler/http.mjs +17 -6
- package/dist/esm/utils/crossProjectApiPlugin.mjs +16 -3
- 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 +69 -12
- package/dist/esm/utils/pluginGenerator.mjs +5 -5
- package/dist/esm-node/cli/compress.mjs +1 -1
- package/dist/esm-node/cli/generator.mjs +108 -98
- package/dist/esm-node/cli/serverGlobalVars.mjs +44 -48
- package/dist/esm-node/cli.mjs +2 -0
- package/dist/esm-node/loader.mjs +6 -5
- package/dist/esm-node/runtime/effect/adapter/cross-project-policy.mjs +17 -12
- package/dist/esm-node/runtime/effect/adapter/entry.mjs +13 -5
- 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/runtime/effect/handler/definition.mjs +1 -0
- package/dist/esm-node/runtime/effect/handler/http.mjs +17 -6
- package/dist/esm-node/utils/crossProjectApiPlugin.mjs +16 -3
- 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 +69 -12
- package/dist/esm-node/utils/pluginGenerator.mjs +5 -5
- package/dist/types/cli/generator.d.ts +2 -2
- package/dist/types/cli/serverGlobalVars.d.ts +4 -2
- package/dist/types/cli.d.ts +1 -0
- 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/runtime/effect/handler/definition.d.ts +2 -12
- package/dist/types/runtime/effect/handler/http.d.ts +2 -1
- package/dist/types/runtime/effect/handler/types.d.ts +5 -0
- package/dist/types/utils/crossProjectApiPlugin.d.ts +2 -0
- package/dist/types/utils/effectSourceLoader.d.ts +10 -0
- package/dist/types/utils/pluginGenerator.d.ts +3 -1
- package/package.json +34 -18
|
@@ -39,7 +39,9 @@ __webpack_require__.r(__webpack_exports__);
|
|
|
39
39
|
__webpack_require__.d(__webpack_exports__, {
|
|
40
40
|
API_DIR: ()=>API_DIR,
|
|
41
41
|
DIST_DIR: ()=>DIST_DIR,
|
|
42
|
+
EFFECT_ENTRY: ()=>EFFECT_ENTRY,
|
|
42
43
|
LAMBDA_DIR: ()=>LAMBDA_DIR,
|
|
44
|
+
OPERATION_CONTRACTS_JSON: ()=>OPERATION_CONTRACTS_JSON,
|
|
43
45
|
PACKAGE_NAME: ()=>PACKAGE_NAME,
|
|
44
46
|
PREFIX: ()=>PREFIX,
|
|
45
47
|
RUNTIME_FRAMEWORK: ()=>RUNTIME_FRAMEWORK,
|
|
@@ -54,6 +56,8 @@ const API_DIR = '{apiDirectory}';
|
|
|
54
56
|
const LAMBDA_DIR = '{lambdaDirectory}';
|
|
55
57
|
const DIST_DIR = '{distDirectory}';
|
|
56
58
|
const RUNTIME_FRAMEWORK = '{runtimeFramework}';
|
|
59
|
+
const EFFECT_ENTRY = '{effectEntry}';
|
|
60
|
+
const OPERATION_CONTRACTS_JSON = '{operationContracts}';
|
|
57
61
|
const NODE_MODULES = 'node_modules';
|
|
58
62
|
const crossProjectApiPlugin = ()=>({
|
|
59
63
|
name: '@modern-js/plugin-independent-bff',
|
|
@@ -65,7 +69,8 @@ const crossProjectApiPlugin = ()=>({
|
|
|
65
69
|
const { appDirectory: originAppDirectory } = api.getAppContext();
|
|
66
70
|
const sdkPath = external_path_default().join(originAppDirectory, NODE_MODULES, PACKAGE_NAME);
|
|
67
71
|
const sdkDistPath = external_path_default().join(sdkPath, DIST_DIR);
|
|
68
|
-
const
|
|
72
|
+
const effectEntry = EFFECT_ENTRY ? external_path_default().join(sdkDistPath, EFFECT_ENTRY) : void 0;
|
|
73
|
+
const apiDirectory = effectEntry ? external_path_default().dirname(effectEntry) : external_path_default().join(sdkDistPath, API_DIR);
|
|
69
74
|
const lambdaDirectory = external_path_default().resolve(sdkDistPath, LAMBDA_DIR);
|
|
70
75
|
api.updateAppContext({
|
|
71
76
|
apiDirectory,
|
|
@@ -80,10 +85,16 @@ const crossProjectApiPlugin = ()=>({
|
|
|
80
85
|
}
|
|
81
86
|
const configuredRuntimeFramework = config?.bff?.runtimeFramework;
|
|
82
87
|
if (configuredRuntimeFramework && configuredRuntimeFramework !== RUNTIME_FRAMEWORK) throw new Error(`[${PACKAGE_NAME}] Runtime framework mismatch for cross-project BFF. Detected "${configuredRuntimeFramework}", but producer SDK requires "${RUNTIME_FRAMEWORK}".`);
|
|
88
|
+
resolvedConfig.bff ??= {};
|
|
83
89
|
resolvedConfig.bff.prefix = PREFIX;
|
|
84
90
|
resolvedConfig.bff.runtimeFramework = RUNTIME_FRAMEWORK;
|
|
91
|
+
if (EFFECT_ENTRY) resolvedConfig.bff.effect = {
|
|
92
|
+
...resolvedConfig.bff.effect,
|
|
93
|
+
entry: effectEntry
|
|
94
|
+
};
|
|
85
95
|
resolvedConfig.bff.isCrossProjectServer = true;
|
|
86
96
|
resolvedConfig.bff.requestId = resolvedConfig.bff.requestId || config?.bff?.requestId || PACKAGE_NAME || 'default';
|
|
97
|
+
const generatedOperationContracts = "{operationContracts}" === OPERATION_CONTRACTS_JSON ? {} : JSON.parse(OPERATION_CONTRACTS_JSON);
|
|
87
98
|
resolvedConfig.bff.crossProjectPolicy = {
|
|
88
99
|
...resolvedConfig.bff.crossProjectPolicy || {},
|
|
89
100
|
enabled: resolvedConfig.bff.crossProjectPolicy?.enabled ?? true,
|
|
@@ -92,7 +103,11 @@ const crossProjectApiPlugin = ()=>({
|
|
|
92
103
|
requireOperationContextDetails: resolvedConfig.bff.crossProjectPolicy?.requireOperationContextDetails ?? true,
|
|
93
104
|
requireOperationSchemaHash: resolvedConfig.bff.crossProjectPolicy?.requireOperationSchemaHash ?? true,
|
|
94
105
|
requireOperationVersion: resolvedConfig.bff.crossProjectPolicy?.requireOperationVersion ?? true,
|
|
95
|
-
allowUnknownOperations: resolvedConfig.bff.crossProjectPolicy?.allowUnknownOperations ?? false
|
|
106
|
+
allowUnknownOperations: resolvedConfig.bff.crossProjectPolicy?.allowUnknownOperations ?? false,
|
|
107
|
+
expectedOperationContracts: {
|
|
108
|
+
...resolvedConfig.bff.crossProjectPolicy?.expectedOperationContracts || {},
|
|
109
|
+
...generatedOperationContracts
|
|
110
|
+
}
|
|
96
111
|
};
|
|
97
112
|
return resolvedConfig;
|
|
98
113
|
});
|
|
@@ -101,7 +116,9 @@ const crossProjectApiPlugin = ()=>({
|
|
|
101
116
|
const utils_crossProjectApiPlugin = crossProjectApiPlugin;
|
|
102
117
|
exports.API_DIR = __webpack_exports__.API_DIR;
|
|
103
118
|
exports.DIST_DIR = __webpack_exports__.DIST_DIR;
|
|
119
|
+
exports.EFFECT_ENTRY = __webpack_exports__.EFFECT_ENTRY;
|
|
104
120
|
exports.LAMBDA_DIR = __webpack_exports__.LAMBDA_DIR;
|
|
121
|
+
exports.OPERATION_CONTRACTS_JSON = __webpack_exports__.OPERATION_CONTRACTS_JSON;
|
|
105
122
|
exports.PACKAGE_NAME = __webpack_exports__.PACKAGE_NAME;
|
|
106
123
|
exports.PREFIX = __webpack_exports__.PREFIX;
|
|
107
124
|
exports.RUNTIME_FRAMEWORK = __webpack_exports__.RUNTIME_FRAMEWORK;
|
|
@@ -110,7 +127,9 @@ exports["default"] = __webpack_exports__["default"];
|
|
|
110
127
|
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
111
128
|
"API_DIR",
|
|
112
129
|
"DIST_DIR",
|
|
130
|
+
"EFFECT_ENTRY",
|
|
113
131
|
"LAMBDA_DIR",
|
|
132
|
+
"OPERATION_CONTRACTS_JSON",
|
|
114
133
|
"PACKAGE_NAME",
|
|
115
134
|
"PREFIX",
|
|
116
135
|
"RUNTIME_FRAMEWORK",
|
|
@@ -35,27 +35,28 @@ const utils_namespaceObject = require("@modern-js/utils");
|
|
|
35
35
|
const endpoint_contracts_js_namespaceObject = require("../../runtime/effect/endpoint-contracts.js");
|
|
36
36
|
const external_rendering_js_namespaceObject = require("./rendering.js");
|
|
37
37
|
const external_runtime_js_namespaceObject = require("./runtime.js");
|
|
38
|
-
|
|
39
|
-
|
|
38
|
+
function generateEffectClient(options) {
|
|
39
|
+
return (0, external_runtime_js_namespaceObject.loadEffectApi)({
|
|
40
40
|
appDir: options.appDir,
|
|
41
41
|
resourcePath: options.resourcePath,
|
|
42
42
|
onDependency: options.onDependency
|
|
43
|
+
}).then((api)=>{
|
|
44
|
+
if (null === api) {
|
|
45
|
+
utils_namespaceObject.logger.warn(`[BFF][Effect] Failed to generate client for ${options.resourcePath}: unable to resolve exported HttpApi.`);
|
|
46
|
+
return null;
|
|
47
|
+
}
|
|
48
|
+
return (0, external_runtime_js_namespaceObject.getHttpApiRuntime)().then((httpApiRuntime)=>{
|
|
49
|
+
const endpoints = (0, endpoint_contracts_js_namespaceObject.collectEffectEndpoints)(httpApiRuntime.reflect, api, options.prefix);
|
|
50
|
+
return {
|
|
51
|
+
code: (0, external_rendering_js_namespaceObject.renderEffectClientCode)(endpoints, options),
|
|
52
|
+
declaration: (0, external_rendering_js_namespaceObject.renderEffectClientDeclaration)(endpoints),
|
|
53
|
+
endpoints
|
|
54
|
+
};
|
|
55
|
+
});
|
|
43
56
|
});
|
|
44
|
-
if (!api) {
|
|
45
|
-
utils_namespaceObject.logger.warn(`[BFF][Effect] Failed to generate client for ${options.resourcePath}: unable to resolve exported HttpApi.`);
|
|
46
|
-
return null;
|
|
47
|
-
}
|
|
48
|
-
const httpApiRuntime = await (0, external_runtime_js_namespaceObject.getHttpApiRuntime)();
|
|
49
|
-
const endpoints = (0, endpoint_contracts_js_namespaceObject.collectEffectEndpoints)(httpApiRuntime.reflect, api, options.prefix);
|
|
50
|
-
return {
|
|
51
|
-
code: (0, external_rendering_js_namespaceObject.renderEffectClientCode)(endpoints, options),
|
|
52
|
-
declaration: (0, external_rendering_js_namespaceObject.renderEffectClientDeclaration)(endpoints),
|
|
53
|
-
endpoints
|
|
54
|
-
};
|
|
55
57
|
}
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
return artifacts ? artifacts.code : null;
|
|
58
|
+
function generateEffectClientCode(options) {
|
|
59
|
+
return generateEffectClient(options).then((artifacts)=>null === artifacts ? null : artifacts.code);
|
|
59
60
|
}
|
|
60
61
|
exports.generateEffectClient = __webpack_exports__.generateEffectClient;
|
|
61
62
|
exports.generateEffectClientCode = __webpack_exports__.generateEffectClientCode;
|
|
@@ -1,14 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var __webpack_require__ = {};
|
|
3
|
-
(()=>{
|
|
4
|
-
__webpack_require__.n = (module)=>{
|
|
5
|
-
var getter = module && module.__esModule ? ()=>module['default'] : ()=>module;
|
|
6
|
-
__webpack_require__.d(getter, {
|
|
7
|
-
a: getter
|
|
8
|
-
});
|
|
9
|
-
return getter;
|
|
10
|
-
};
|
|
11
|
-
})();
|
|
12
3
|
(()=>{
|
|
13
4
|
__webpack_require__.d = (exports1, getters, values)=>{
|
|
14
5
|
var define = (defs, kind)=>{
|
|
@@ -40,8 +31,6 @@ __webpack_require__.d(__webpack_exports__, {
|
|
|
40
31
|
resolveEffectEntryFile: ()=>resolveEffectEntryFile
|
|
41
32
|
});
|
|
42
33
|
const utils_namespaceObject = require("@modern-js/utils");
|
|
43
|
-
const external_path_namespaceObject = require("path");
|
|
44
|
-
var external_path_default = /*#__PURE__*/ __webpack_require__.n(external_path_namespaceObject);
|
|
45
34
|
const JS_OR_TS_EXTS = [
|
|
46
35
|
'.js',
|
|
47
36
|
'.jsx',
|
|
@@ -55,14 +44,14 @@ const JS_OR_TS_EXTS = [
|
|
|
55
44
|
function resolveEffectEntryFile(options) {
|
|
56
45
|
const { appDir, apiDir, effectEntry } = options;
|
|
57
46
|
const resolveEntry = (entryWithoutExt)=>{
|
|
58
|
-
if (
|
|
47
|
+
if ('' !== utils_namespaceObject.upath.extname(entryWithoutExt)) return utils_namespaceObject.fs.existsSync(entryWithoutExt) ? entryWithoutExt : void 0;
|
|
59
48
|
return (0, utils_namespaceObject.findExists)(JS_OR_TS_EXTS.map((ext)=>`${entryWithoutExt}${ext}`));
|
|
60
49
|
};
|
|
61
|
-
if (effectEntry) {
|
|
62
|
-
const entryWithoutExt =
|
|
50
|
+
if (void 0 !== effectEntry && '' !== effectEntry) {
|
|
51
|
+
const entryWithoutExt = utils_namespaceObject.upath.isAbsolute(effectEntry) ? effectEntry : utils_namespaceObject.upath.resolve(appDir, effectEntry);
|
|
63
52
|
return resolveEntry(entryWithoutExt);
|
|
64
53
|
}
|
|
65
|
-
return resolveEntry(
|
|
54
|
+
return resolveEntry(utils_namespaceObject.upath.resolve(apiDir, 'index'));
|
|
66
55
|
}
|
|
67
56
|
exports.resolveEffectEntryFile = __webpack_exports__.resolveEffectEntryFile;
|
|
68
57
|
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
@@ -1,14 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var __webpack_require__ = {};
|
|
3
|
-
(()=>{
|
|
4
|
-
__webpack_require__.n = (module)=>{
|
|
5
|
-
var getter = module && module.__esModule ? ()=>module['default'] : ()=>module;
|
|
6
|
-
__webpack_require__.d(getter, {
|
|
7
|
-
a: getter
|
|
8
|
-
});
|
|
9
|
-
return getter;
|
|
10
|
-
};
|
|
11
|
-
})();
|
|
12
3
|
(()=>{
|
|
13
4
|
__webpack_require__.d = (exports1, getters, values)=>{
|
|
14
5
|
var define = (defs, kind)=>{
|
|
@@ -42,8 +33,6 @@ __webpack_require__.d(__webpack_exports__, {
|
|
|
42
33
|
});
|
|
43
34
|
const bff_core_namespaceObject = require("@modern-js/bff-core");
|
|
44
35
|
const utils_namespaceObject = require("@modern-js/utils");
|
|
45
|
-
const external_path_namespaceObject = require("path");
|
|
46
|
-
var external_path_default = /*#__PURE__*/ __webpack_require__.n(external_path_namespaceObject);
|
|
47
36
|
const endpoint_contracts_js_namespaceObject = require("../../runtime/effect/endpoint-contracts.js");
|
|
48
37
|
const DEFAULT_REQUEST_CREATOR = '@modern-js/plugin-bff/client';
|
|
49
38
|
const EFFECT_CLIENT_RUNTIME_IMPORT = '@modern-js/plugin-bff/effect-client-runtime';
|
|
@@ -56,17 +45,17 @@ function isAbsoluteUrl(value) {
|
|
|
56
45
|
}
|
|
57
46
|
}
|
|
58
47
|
function resolveBatchEndpoint(prefix, endpoint) {
|
|
59
|
-
const value = endpoint || '/_data/batch';
|
|
48
|
+
const value = void 0 === endpoint || '' === endpoint ? '/_data/batch' : endpoint;
|
|
60
49
|
if (isAbsoluteUrl(value)) return value;
|
|
61
50
|
const normalizedPrefix = (0, endpoint_contracts_js_namespaceObject.normalizeEffectPrefix)(prefix);
|
|
62
51
|
const normalizedEndpoint = (0, endpoint_contracts_js_namespaceObject.ensureLeadingSlash)(value);
|
|
63
|
-
if (
|
|
52
|
+
if ('' === normalizedPrefix) return normalizedEndpoint;
|
|
64
53
|
if (normalizedEndpoint === normalizedPrefix || normalizedEndpoint.startsWith(`${normalizedPrefix}/`)) return normalizedEndpoint;
|
|
65
54
|
return `${normalizedPrefix}${'/' === normalizedEndpoint ? '' : normalizedEndpoint}`;
|
|
66
55
|
}
|
|
67
56
|
function getPackageInfo(appDir) {
|
|
68
57
|
try {
|
|
69
|
-
const packageJsonPath =
|
|
58
|
+
const packageJsonPath = utils_namespaceObject.upath.resolve(appDir, './package.json');
|
|
70
59
|
const packageJson = utils_namespaceObject.fs.readJSONSync(packageJsonPath);
|
|
71
60
|
return {
|
|
72
61
|
name: packageJson.name,
|
|
@@ -81,9 +70,9 @@ function renderEffectClientCode(endpoints, options) {
|
|
|
81
70
|
const httpMethodDecider = options.httpMethodDecider || 'functionName';
|
|
82
71
|
const packageInfo = getPackageInfo(options.appDir);
|
|
83
72
|
const packageName = packageInfo.name;
|
|
84
|
-
const dataPlatformAppNamespace = packageName || 'unknown-app';
|
|
85
|
-
const requestId = 'bundle' === options.target ? packageName
|
|
86
|
-
const normalizedRequestId = requestId || 'default';
|
|
73
|
+
const dataPlatformAppNamespace = void 0 === packageName || '' === packageName ? 'unknown-app' : packageName;
|
|
74
|
+
const requestId = 'bundle' === options.target ? void 0 !== packageName && '' !== packageName ? packageName : void 0 : void 0;
|
|
75
|
+
const normalizedRequestId = void 0 === requestId || '' === requestId ? 'default' : requestId;
|
|
87
76
|
const operationVersion = (0, bff_core_namespaceObject.deriveOperationVersion)(packageInfo.version);
|
|
88
77
|
const batchConfig = options.dataPlatformBatch;
|
|
89
78
|
const batchEndpoint = resolveBatchEndpoint(options.prefix, batchConfig?.endpoint);
|
|
@@ -100,7 +89,7 @@ function renderEffectClientCode(endpoints, options) {
|
|
|
100
89
|
};
|
|
101
90
|
const config = {
|
|
102
91
|
appNamespace: dataPlatformAppNamespace,
|
|
103
|
-
...requestId ? {
|
|
92
|
+
...void 0 !== requestId && '' !== requestId ? {
|
|
104
93
|
requestId
|
|
105
94
|
} : {},
|
|
106
95
|
port: options.port,
|
|
@@ -114,7 +103,7 @@ function renderEffectClientCode(endpoints, options) {
|
|
|
114
103
|
maxBatchSize: batchConfig?.maxBatchSize ?? 16,
|
|
115
104
|
maxBatchBytes: batchConfig?.maxBatchBytes ?? 65536,
|
|
116
105
|
requestTimeoutMs: batchConfig?.requestTimeoutMs ?? 10000,
|
|
117
|
-
allowedMethods: batchConfig?.allowedMethods && batchConfig.allowedMethods.length > 0 ? batchConfig.allowedMethods : [
|
|
106
|
+
allowedMethods: batchConfig?.allowedMethods !== void 0 && batchConfig.allowedMethods.length > 0 ? batchConfig.allowedMethods : [
|
|
118
107
|
'GET'
|
|
119
108
|
]
|
|
120
109
|
}
|
|
@@ -1,14 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var __webpack_require__ = {};
|
|
3
|
-
(()=>{
|
|
4
|
-
__webpack_require__.n = (module)=>{
|
|
5
|
-
var getter = module && module.__esModule ? ()=>module['default'] : ()=>module;
|
|
6
|
-
__webpack_require__.d(getter, {
|
|
7
|
-
a: getter
|
|
8
|
-
});
|
|
9
|
-
return getter;
|
|
10
|
-
};
|
|
11
|
-
})();
|
|
12
3
|
(()=>{
|
|
13
4
|
__webpack_require__.d = (exports1, getters, values)=>{
|
|
14
5
|
var define = (defs, kind)=>{
|
|
@@ -41,38 +32,30 @@ __webpack_require__.d(__webpack_exports__, {
|
|
|
41
32
|
loadEffectApi: ()=>loadEffectApi
|
|
42
33
|
});
|
|
43
34
|
const utils_namespaceObject = require("@modern-js/utils");
|
|
44
|
-
const external_path_namespaceObject = require("path");
|
|
45
|
-
var external_path_default = /*#__PURE__*/ __webpack_require__.n(external_path_namespaceObject);
|
|
46
35
|
const endpoint_contracts_js_namespaceObject = require("../../runtime/effect/endpoint-contracts.js");
|
|
47
36
|
const external_effectSourceLoader_js_namespaceObject = require("../effectSourceLoader.js");
|
|
48
37
|
let httpApiRuntimePromise;
|
|
49
38
|
function isRecord(value) {
|
|
50
39
|
return 'object' == typeof value && null !== value;
|
|
51
40
|
}
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
if (isRecord(mod) && isRecord(mod.HttpApi)) {
|
|
65
|
-
const maybeHttpApi = mod.HttpApi;
|
|
66
|
-
if ('function' == typeof maybeHttpApi.isHttpApi && 'function' == typeof maybeHttpApi.reflect) return maybeHttpApi;
|
|
67
|
-
}
|
|
41
|
+
function isHttpApiRuntime(value) {
|
|
42
|
+
return isRecord(value) && 'function' == typeof value.isHttpApi && 'function' == typeof value.reflect;
|
|
43
|
+
}
|
|
44
|
+
function getHttpApiRuntime() {
|
|
45
|
+
if (void 0 === httpApiRuntimePromise) httpApiRuntimePromise = (0, utils_namespaceObject.compatibleRequire)('effect/unstable/httpapi', false).catch((error)=>{
|
|
46
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
47
|
+
if (!message.includes("Cannot find module 'effect/unstable/httpapi'")) throw error;
|
|
48
|
+
const effectPackageJson = require.resolve('effect/package.json');
|
|
49
|
+
const effectHttpApiRuntimePath = utils_namespaceObject.upath.join(utils_namespaceObject.upath.dirname(effectPackageJson), 'dist', 'unstable', 'httpapi', 'index.js');
|
|
50
|
+
return (0, utils_namespaceObject.compatibleRequire)(effectHttpApiRuntimePath, false);
|
|
51
|
+
}).then((mod)=>{
|
|
52
|
+
if (isRecord(mod) && isHttpApiRuntime(mod.HttpApi)) return mod.HttpApi;
|
|
68
53
|
throw new Error('[BFF][Effect] Unable to resolve HttpApi runtime from effect/unstable/httpapi.');
|
|
69
|
-
})
|
|
54
|
+
});
|
|
70
55
|
return httpApiRuntimePromise;
|
|
71
56
|
}
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
const mod = await (0, external_effectSourceLoader_js_namespaceObject.loadEffectSourceModule)(options);
|
|
75
|
-
return (0, endpoint_contracts_js_namespaceObject.extractHttpApiFromModule)(mod, httpApiRuntime.isHttpApi);
|
|
57
|
+
function loadEffectApi(options) {
|
|
58
|
+
return getHttpApiRuntime().then((httpApiRuntime)=>(0, external_effectSourceLoader_js_namespaceObject.loadEffectSourceModule)(options).then((mod)=>(0, endpoint_contracts_js_namespaceObject.extractHttpApiFromModule)(mod, httpApiRuntime.isHttpApi)));
|
|
76
59
|
}
|
|
77
60
|
exports.getHttpApiRuntime = __webpack_exports__.getHttpApiRuntime;
|
|
78
61
|
exports.loadEffectApi = __webpack_exports__.loadEffectApi;
|
|
@@ -38,6 +38,7 @@ var __webpack_exports__ = {};
|
|
|
38
38
|
__webpack_require__.r(__webpack_exports__);
|
|
39
39
|
__webpack_require__.d(__webpack_exports__, {
|
|
40
40
|
bundleEffectEntryForNode: ()=>bundleEffectEntryForNode,
|
|
41
|
+
loadEffectBuiltModule: ()=>loadEffectBuiltModule,
|
|
41
42
|
loadEffectSourceModule: ()=>loadEffectSourceModule
|
|
42
43
|
});
|
|
43
44
|
const external_node_crypto_namespaceObject = require("node:crypto");
|
|
@@ -120,10 +121,29 @@ const nodeBuiltins = new Set([
|
|
|
120
121
|
...external_node_module_namespaceObject.builtinModules.map((name)=>`node:${name}`)
|
|
121
122
|
]);
|
|
122
123
|
const dependencyResolutionMarker = 'modern-js-effect-dependency-resolution';
|
|
124
|
+
async function isEsmOnlyFile(filename) {
|
|
125
|
+
const extension = external_node_path_default().extname(filename).toLowerCase();
|
|
126
|
+
if ('.mjs' === extension || '.mts' === extension) return true;
|
|
127
|
+
if ('.cjs' === extension || '.cts' === extension) return false;
|
|
128
|
+
let directory = external_node_path_default().dirname(filename);
|
|
129
|
+
while(true){
|
|
130
|
+
const packagePath = external_node_path_default().join(directory, 'package.json');
|
|
131
|
+
try {
|
|
132
|
+
const packageJson = JSON.parse(await external_node_fs_default().promises.readFile(packagePath, 'utf8'));
|
|
133
|
+
return 'module' === packageJson.type;
|
|
134
|
+
} catch (error) {
|
|
135
|
+
if (!error || 'object' != typeof error || !('code' in error) || 'ENOENT' !== error.code) throw error;
|
|
136
|
+
}
|
|
137
|
+
const parent = external_node_path_default().dirname(directory);
|
|
138
|
+
if (parent === directory) return false;
|
|
139
|
+
directory = parent;
|
|
140
|
+
}
|
|
141
|
+
}
|
|
123
142
|
function isBareSpecifier(specifier) {
|
|
124
143
|
return !specifier.startsWith('.') && !specifier.startsWith('/') && !external_node_path_default().isAbsolute(specifier);
|
|
125
144
|
}
|
|
126
|
-
function externalizeInstalledDependencies() {
|
|
145
|
+
function externalizeInstalledDependencies(options) {
|
|
146
|
+
const runtimeRequire = (0, external_node_module_namespaceObject.createRequire)(external_node_path_default().join(options.runtimeResolveDir, '__modern_effect_entry.cjs'));
|
|
127
147
|
return {
|
|
128
148
|
name: 'modern-js-effect-installed-dependencies',
|
|
129
149
|
setup (buildApi) {
|
|
@@ -153,19 +173,46 @@ function externalizeInstalledDependencies() {
|
|
|
153
173
|
path: args.path
|
|
154
174
|
};
|
|
155
175
|
const realPath = await external_node_fs_default().promises.realpath(resolution.path).catch(()=>resolution.path);
|
|
156
|
-
if (realPath.includes(`${external_node_path_default().sep}node_modules${external_node_path_default().sep}`))
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
176
|
+
if (realPath.includes(`${external_node_path_default().sep}node_modules${external_node_path_default().sep}`)) {
|
|
177
|
+
const runtimeResolution = await buildApi.resolve(args.path, {
|
|
178
|
+
importer: '',
|
|
179
|
+
kind: args.kind,
|
|
180
|
+
namespace: 'file',
|
|
181
|
+
pluginData: {
|
|
182
|
+
[dependencyResolutionMarker]: true
|
|
183
|
+
},
|
|
184
|
+
resolveDir: options.runtimeResolveDir
|
|
185
|
+
});
|
|
186
|
+
if (0 === runtimeResolution.errors.length && runtimeResolution.path) {
|
|
187
|
+
if ('cjs' === options.format) {
|
|
188
|
+
let requiredPath;
|
|
189
|
+
try {
|
|
190
|
+
requiredPath = runtimeRequire.resolve(args.path);
|
|
191
|
+
} catch {
|
|
192
|
+
requiredPath = runtimeResolution.path;
|
|
193
|
+
}
|
|
194
|
+
if (await isEsmOnlyFile(requiredPath)) return {
|
|
195
|
+
namespace: resolution.namespace,
|
|
196
|
+
path: resolution.path,
|
|
197
|
+
pluginData: resolution.pluginData,
|
|
198
|
+
sideEffects: resolution.sideEffects,
|
|
199
|
+
suffix: resolution.suffix,
|
|
200
|
+
warnings: resolution.warnings
|
|
201
|
+
};
|
|
202
|
+
}
|
|
203
|
+
return {
|
|
204
|
+
external: true,
|
|
205
|
+
path: args.path
|
|
206
|
+
};
|
|
207
|
+
}
|
|
208
|
+
}
|
|
160
209
|
return {
|
|
161
210
|
namespace: resolution.namespace,
|
|
162
211
|
path: resolution.path,
|
|
163
212
|
pluginData: resolution.pluginData,
|
|
164
213
|
sideEffects: resolution.sideEffects,
|
|
165
214
|
suffix: resolution.suffix,
|
|
166
|
-
warnings: resolution.warnings
|
|
167
|
-
watchDirs: resolution.watchDirs,
|
|
168
|
-
watchFiles: resolution.watchFiles
|
|
215
|
+
warnings: resolution.warnings
|
|
169
216
|
};
|
|
170
217
|
});
|
|
171
218
|
}
|
|
@@ -184,7 +231,10 @@ async function bundleEffectEntryForNode(options) {
|
|
|
184
231
|
outfile: options.entryPath,
|
|
185
232
|
platform: 'node',
|
|
186
233
|
plugins: [
|
|
187
|
-
externalizeInstalledDependencies(
|
|
234
|
+
externalizeInstalledDependencies({
|
|
235
|
+
format: options.format,
|
|
236
|
+
runtimeResolveDir: options.appDir
|
|
237
|
+
}),
|
|
188
238
|
preserveSourceModuleSemantics()
|
|
189
239
|
],
|
|
190
240
|
target: 'node20'
|
|
@@ -200,6 +250,11 @@ function normalizeImportedModule(module) {
|
|
|
200
250
|
if (1 === Object.keys(namespace).length && null !== commonJsModule && 'object' == typeof commonJsModule && true === commonJsModule.__esModule) return commonJsModule;
|
|
201
251
|
return module;
|
|
202
252
|
}
|
|
253
|
+
async function loadEffectBuiltModule(resourcePath) {
|
|
254
|
+
const canonicalPath = await external_node_fs_default().promises.realpath(external_node_path_default().resolve(resourcePath));
|
|
255
|
+
if (!await isEsmOnlyFile(canonicalPath)) return (0, external_node_module_namespaceObject.createRequire)(canonicalPath)(canonicalPath);
|
|
256
|
+
return normalizeImportedModule(await dynamicImport((0, external_node_url_namespaceObject.pathToFileURL)(canonicalPath).href));
|
|
257
|
+
}
|
|
203
258
|
async function loadEffectSourceModule(options) {
|
|
204
259
|
const resourcePath = external_node_path_default().resolve(options.resourcePath);
|
|
205
260
|
const appDir = external_node_path_default().resolve(options.appDir ?? external_node_path_default().dirname(resourcePath));
|
|
@@ -226,7 +281,10 @@ async function loadEffectSourceModule(options) {
|
|
|
226
281
|
outfile: outputPath,
|
|
227
282
|
platform: 'node',
|
|
228
283
|
plugins: [
|
|
229
|
-
externalizeInstalledDependencies(
|
|
284
|
+
externalizeInstalledDependencies({
|
|
285
|
+
format: 'esm',
|
|
286
|
+
runtimeResolveDir: appDir
|
|
287
|
+
}),
|
|
230
288
|
preserveSourceModuleSemantics()
|
|
231
289
|
],
|
|
232
290
|
sourcemap: 'inline',
|
|
@@ -242,9 +300,11 @@ async function loadEffectSourceModule(options) {
|
|
|
242
300
|
return normalizeImportedModule(await dynamicImport(`${(0, external_node_url_namespaceObject.pathToFileURL)(outputPath).href}?v=${revision}`));
|
|
243
301
|
}
|
|
244
302
|
exports.bundleEffectEntryForNode = __webpack_exports__.bundleEffectEntryForNode;
|
|
303
|
+
exports.loadEffectBuiltModule = __webpack_exports__.loadEffectBuiltModule;
|
|
245
304
|
exports.loadEffectSourceModule = __webpack_exports__.loadEffectSourceModule;
|
|
246
305
|
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
247
306
|
"bundleEffectEntryForNode",
|
|
307
|
+
"loadEffectBuiltModule",
|
|
248
308
|
"loadEffectSourceModule"
|
|
249
309
|
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
250
310
|
Object.defineProperty(exports, '__esModule', {
|
|
@@ -43,18 +43,18 @@ const utils_namespaceObject = require("@modern-js/utils");
|
|
|
43
43
|
const external_path_namespaceObject = require("path");
|
|
44
44
|
var external_path_default = /*#__PURE__*/ __webpack_require__.n(external_path_namespaceObject);
|
|
45
45
|
const external_crossProjectApiPlugin_js_namespaceObject = require("./crossProjectApiPlugin.js");
|
|
46
|
-
function replaceContent(source, packageName, prefix, relativeDistPath, relativeApiPath, relativeLambdaPath, runtimeFramework) {
|
|
47
|
-
const updatedSource = source.replace(new RegExp(external_crossProjectApiPlugin_js_namespaceObject.PACKAGE_NAME, 'g'), packageName).replace(new RegExp(external_crossProjectApiPlugin_js_namespaceObject.PREFIX, 'g'), prefix).replace(new RegExp(external_crossProjectApiPlugin_js_namespaceObject.DIST_DIR, 'g'), (0, utils_namespaceObject.normalizeToPosixPath)(relativeDistPath)).replace(new RegExp(external_crossProjectApiPlugin_js_namespaceObject.API_DIR, 'g'), (0, utils_namespaceObject.normalizeToPosixPath)(relativeApiPath)).replace(new RegExp(external_crossProjectApiPlugin_js_namespaceObject.LAMBDA_DIR, 'g'), (0, utils_namespaceObject.normalizeToPosixPath)(relativeLambdaPath)).replace(new RegExp(external_crossProjectApiPlugin_js_namespaceObject.RUNTIME_FRAMEWORK, 'g'), runtimeFramework);
|
|
46
|
+
function replaceContent(source, packageName, prefix, relativeDistPath, relativeApiPath, relativeLambdaPath, runtimeFramework, relativeEffectEntry, operationContracts) {
|
|
47
|
+
const updatedSource = source.replace(new RegExp(external_crossProjectApiPlugin_js_namespaceObject.PACKAGE_NAME, 'g'), packageName).replace(new RegExp(external_crossProjectApiPlugin_js_namespaceObject.PREFIX, 'g'), prefix).replace(new RegExp(external_crossProjectApiPlugin_js_namespaceObject.DIST_DIR, 'g'), (0, utils_namespaceObject.normalizeToPosixPath)(relativeDistPath)).replace(new RegExp(external_crossProjectApiPlugin_js_namespaceObject.API_DIR, 'g'), (0, utils_namespaceObject.normalizeToPosixPath)(relativeApiPath)).replace(new RegExp(external_crossProjectApiPlugin_js_namespaceObject.LAMBDA_DIR, 'g'), (0, utils_namespaceObject.normalizeToPosixPath)(relativeLambdaPath)).replace(new RegExp(external_crossProjectApiPlugin_js_namespaceObject.RUNTIME_FRAMEWORK, 'g'), runtimeFramework).replace(new RegExp(external_crossProjectApiPlugin_js_namespaceObject.EFFECT_ENTRY, 'g'), (0, utils_namespaceObject.normalizeToPosixPath)(relativeEffectEntry)).replace(`'${external_crossProjectApiPlugin_js_namespaceObject.OPERATION_CONTRACTS_JSON}'`, ()=>JSON.stringify(JSON.stringify(operationContracts)));
|
|
48
48
|
return updatedSource;
|
|
49
49
|
}
|
|
50
|
-
async function pluginGenerator({ prefix, appDirectory, relativeDistPath, relativeApiPath, relativeLambdaPath, runtimeFramework }) {
|
|
50
|
+
async function pluginGenerator({ prefix, appDirectory, relativeDistPath, relativeApiPath, relativeLambdaPath, runtimeFramework, relativeEffectEntry, operationContracts }) {
|
|
51
51
|
try {
|
|
52
52
|
const packageContent = await utils_namespaceObject.fs.readFile(external_path_default().resolve(appDirectory, './package.json'), 'utf8');
|
|
53
53
|
const packageJson = JSON.parse(packageContent);
|
|
54
54
|
const pluginDir = external_path_default().resolve(appDirectory, `./${relativeDistPath}`, 'plugin');
|
|
55
55
|
const pluginPath = external_path_default().join(pluginDir, 'index.js');
|
|
56
56
|
const pluginTemplate = await utils_namespaceObject.fs.readFile(external_path_default().resolve(__dirname, 'crossProjectApiPlugin.js'), 'utf8');
|
|
57
|
-
const updatedPlugin = replaceContent(pluginTemplate, packageJson.name, prefix, relativeDistPath, relativeApiPath, relativeLambdaPath, runtimeFramework);
|
|
57
|
+
const updatedPlugin = replaceContent(pluginTemplate, packageJson.name, prefix, relativeDistPath, relativeApiPath, relativeLambdaPath, runtimeFramework, relativeEffectEntry, operationContracts);
|
|
58
58
|
await utils_namespaceObject.fs.ensureFile(pluginPath);
|
|
59
59
|
await utils_namespaceObject.fs.writeFile(pluginPath, updatedPlugin);
|
|
60
60
|
const typeContent = `import type { AppTools, CliPlugin } from '@modern-js/app-tools';
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { normalizePrefixList } from "./prefix.mjs";
|
|
2
2
|
const createCompressConfig = (devServer, prefix)=>{
|
|
3
|
-
if (
|
|
3
|
+
if (void 0 === devServer || 'object' != typeof devServer || Array.isArray(devServer)) return;
|
|
4
4
|
const { compress } = devServer;
|
|
5
5
|
if (void 0 === compress || true === compress) {
|
|
6
6
|
const prefixes = normalizePrefixList(prefix);
|