@bleedingdev/modern-js-plugin-bff 3.9.0-ultramodern.2 → 3.9.0-ultramodern.20
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/generator.js +118 -117
- package/dist/cjs/cli.js +12 -7
- package/dist/cjs/loader.js +9 -65
- package/dist/cjs/runtime/create-request/index.js +0 -6
- package/dist/cjs/runtime/hono/adapter.js +8 -12
- package/dist/cjs/server.js +41 -50
- package/dist/cjs/utils/client-generator/files.js +1 -1
- package/dist/cjs/utils/client-generator/generate.js +46 -45
- package/dist/cjs/utils/client-generator/package-json.js +2 -2
- package/dist/cjs/utils/client-generator/write-package.js +18 -1
- package/dist/cjs/utils/createHonoRoutes.js +1 -1
- package/dist/cjs/utils/crossProjectApiPlugin.js +26 -83
- package/dist/cjs/utils/pluginGenerator.js +26 -26
- package/dist/cjs/utils/runtimeGenerator.js +26 -75
- package/dist/esm/cli/generator.mjs +121 -120
- package/dist/esm/cli.mjs +12 -7
- package/dist/esm/loader.mjs +9 -55
- package/dist/esm/runtime/create-request/index.mjs +1 -1
- package/dist/esm/runtime/hono/adapter.mjs +8 -12
- package/dist/esm/server.mjs +42 -51
- package/dist/esm/utils/client-generator/files.mjs +1 -1
- package/dist/esm/utils/client-generator/generate.mjs +47 -46
- package/dist/esm/utils/client-generator/package-json.mjs +3 -3
- package/dist/esm/utils/client-generator/write-package.mjs +18 -1
- package/dist/esm/utils/createHonoRoutes.mjs +1 -1
- package/dist/esm/utils/crossProjectApiPlugin.mjs +24 -54
- package/dist/esm/utils/pluginGenerator.mjs +23 -25
- package/dist/esm/utils/runtimeGenerator.mjs +23 -74
- package/dist/esm-node/cli/generator.mjs +121 -120
- package/dist/esm-node/cli.mjs +12 -7
- package/dist/esm-node/loader.mjs +9 -55
- package/dist/esm-node/runtime/create-request/index.mjs +1 -1
- package/dist/esm-node/runtime/hono/adapter.mjs +8 -12
- package/dist/esm-node/server.mjs +42 -51
- package/dist/esm-node/utils/client-generator/files.mjs +1 -1
- package/dist/esm-node/utils/client-generator/generate.mjs +47 -46
- package/dist/esm-node/utils/client-generator/package-json.mjs +3 -3
- package/dist/esm-node/utils/client-generator/write-package.mjs +18 -1
- package/dist/esm-node/utils/createHonoRoutes.mjs +1 -1
- package/dist/esm-node/utils/crossProjectApiPlugin.mjs +24 -54
- package/dist/esm-node/utils/pluginGenerator.mjs +23 -28
- package/dist/esm-node/utils/runtimeGenerator.mjs +24 -76
- package/dist/types/cli/generator.d.ts +2 -2
- package/dist/types/loader.d.ts +1 -11
- package/dist/types/runtime/create-request/index.d.ts +1 -3
- package/dist/types/runtime/hono/adapter.d.ts +9 -2
- package/dist/types/server.d.ts +4 -1
- package/dist/types/utils/client-generator/generate.d.ts +8 -12
- package/dist/types/utils/client-generator/write-package.d.ts +1 -1
- package/dist/types/utils/crossProjectApiPlugin.d.ts +18 -12
- package/dist/types/utils/pluginGenerator.d.ts +6 -7
- package/dist/types/utils/runtimeGenerator.d.ts +6 -3
- package/package.json +31 -124
- package/dist/cjs/cli/serverGlobalVars.js +0 -113
- package/dist/cjs/runtime/data-platform/index.js +0 -62
- package/dist/cjs/runtime/effect/edge-dispatcher.js +0 -62
- package/dist/cjs/runtime/effect/edge.js +0 -69
- package/dist/cjs/runtime/effect/index.js +0 -305
- package/dist/cjs/runtime/effect-client/index.js +0 -62
- package/dist/cjs/runtime/effect-client/runtime.js +0 -62
- package/dist/esm/cli/serverGlobalVars.mjs +0 -72
- package/dist/esm/runtime/data-platform/index.mjs +0 -1
- package/dist/esm/runtime/effect/edge-dispatcher.mjs +0 -1
- package/dist/esm/runtime/effect/edge.mjs +0 -2
- package/dist/esm/runtime/effect/index.mjs +0 -16
- package/dist/esm/runtime/effect-client/index.mjs +0 -1
- package/dist/esm/runtime/effect-client/runtime.mjs +0 -1
- package/dist/esm-node/cli/serverGlobalVars.mjs +0 -73
- package/dist/esm-node/runtime/data-platform/index.mjs +0 -2
- package/dist/esm-node/runtime/effect/edge-dispatcher.mjs +0 -2
- package/dist/esm-node/runtime/effect/edge.mjs +0 -3
- package/dist/esm-node/runtime/effect/index.mjs +0 -17
- package/dist/esm-node/runtime/effect-client/index.mjs +0 -2
- package/dist/esm-node/runtime/effect-client/runtime.mjs +0 -2
- package/dist/types/cli/serverGlobalVars.d.ts +0 -6
- package/dist/types/runtime/data-platform/index.d.ts +0 -1
- package/dist/types/runtime/effect/edge-dispatcher.d.ts +0 -1
- package/dist/types/runtime/effect/edge.d.ts +0 -2
- package/dist/types/runtime/effect/index.d.ts +0 -15
- package/dist/types/runtime/effect-client/index.d.ts +0 -1
- package/dist/types/runtime/effect-client/runtime.d.ts +0 -1
|
@@ -49,128 +49,129 @@ var pluginGenerator_js_default = /*#__PURE__*/ __webpack_require__.n(pluginGener
|
|
|
49
49
|
const runtimeGenerator_js_namespaceObject = require("../utils/runtimeGenerator.js");
|
|
50
50
|
var runtimeGenerator_js_default = /*#__PURE__*/ __webpack_require__.n(runtimeGenerator_js_namespaceObject);
|
|
51
51
|
const external_prefix_js_namespaceObject = require("./prefix.js");
|
|
52
|
-
const external_serverGlobalVars_js_namespaceObject = require("./serverGlobalVars.js");
|
|
53
52
|
const RUNTIME_CREATE_REQUEST = '@modern-js/plugin-bff/client';
|
|
54
53
|
const createBffGenerator = (api)=>{
|
|
55
|
-
const compileApi = ()=>
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
format: 'module' === moduleType ? 'esm' : 'cjs'
|
|
90
|
-
});
|
|
91
|
-
});
|
|
92
|
-
});
|
|
54
|
+
const compileApi = async ()=>{
|
|
55
|
+
const { appDirectory, distDirectory, apiDirectory, sharedDirectory, moduleType } = api.getAppContext();
|
|
56
|
+
const config = api.getNormalizedConfig();
|
|
57
|
+
const distDir = utils_namespaceObject.upath.resolve(distDirectory);
|
|
58
|
+
const apiDir = apiDirectory || utils_namespaceObject.upath.resolve(appDirectory, utils_namespaceObject.API_DIR);
|
|
59
|
+
const sharedDir = sharedDirectory || utils_namespaceObject.upath.resolve(appDirectory, utils_namespaceObject.SHARED_DIR);
|
|
60
|
+
const tsconfigPath = (0, utils_namespaceObject.resolveServerTsconfig)(appDirectory, config.server?.tsconfigPath);
|
|
61
|
+
const sourceDirs = [];
|
|
62
|
+
for (const directory of [
|
|
63
|
+
apiDir,
|
|
64
|
+
sharedDir
|
|
65
|
+
])if (await utils_namespaceObject.fs.pathExists(directory)) sourceDirs.push(directory);
|
|
66
|
+
if (0 === sourceDirs.length) return;
|
|
67
|
+
const combinedAlias = [].concat(config.source.alias ?? []).concat(config.resolve.alias ?? []);
|
|
68
|
+
const context = {
|
|
69
|
+
appDirectory,
|
|
70
|
+
apiDirectory: apiDir,
|
|
71
|
+
sourceDirectories: sourceDirs,
|
|
72
|
+
outputDirectories: sourceDirs.map((directory)=>utils_namespaceObject.upath.resolve(distDir, utils_namespaceObject.upath.relative(appDirectory, directory))),
|
|
73
|
+
distDirectory: distDir,
|
|
74
|
+
tsconfigPath,
|
|
75
|
+
moduleType
|
|
76
|
+
};
|
|
77
|
+
const hooks = api.getHooks();
|
|
78
|
+
await hooks.onBeforeBffCompile.call(context);
|
|
79
|
+
await (0, server_utils_namespaceObject.compile)(appDirectory, {
|
|
80
|
+
alias: combinedAlias
|
|
81
|
+
}, {
|
|
82
|
+
sourceDirs,
|
|
83
|
+
distDir,
|
|
84
|
+
tsconfigPath,
|
|
85
|
+
moduleType,
|
|
86
|
+
excludeFiles: api.getAppContext().serverCompileExcludedFiles,
|
|
87
|
+
throwErrorInsteadOfExit: true
|
|
93
88
|
});
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
const lambdaDir = apiRouter.getLambdaDir();
|
|
110
|
-
const existLambda = apiRouter.isExistLambda();
|
|
111
|
-
const packageJson = utils_namespaceObject.fs.readJSONSync(utils_namespaceObject.upath.resolve(appDirectory, 'package.json'));
|
|
112
|
-
const requestId = bff?.requestId || packageJson.name || packageName || 'default';
|
|
113
|
-
const operationContractsPromise = 'effect' !== bffRuntimeFramework && existLambda ? apiRouter.getApiHandlers().then((handlers)=>(0, bff_core_namespaceObject.buildOperationContractMap)({
|
|
114
|
-
handlers,
|
|
115
|
-
requestId,
|
|
116
|
-
operationVersion: (0, bff_core_namespaceObject.deriveOperationVersion)(packageJson.version)
|
|
117
|
-
})) : Promise.resolve({});
|
|
118
|
-
const runtime = bff?.runtimeCreateRequest || RUNTIME_CREATE_REQUEST;
|
|
119
|
-
const relativeApiPath = utils_namespaceObject.upath.relative(appDirectory, apiDirectory);
|
|
120
|
-
const relativeLambdaPath = utils_namespaceObject.upath.relative(appDirectory, lambdaDir);
|
|
121
|
-
const { sourceEffectEntry, relativeEffectEntry } = 'effect' === bffRuntimeFramework ? (await import("@modern-js/plugin-bff-extensions/client-generator")).resolveEffectEntryPaths({
|
|
122
|
-
appDir: appDirectory,
|
|
123
|
-
apiDir: apiDirectory,
|
|
124
|
-
effectEntry: bff?.effect?.entry
|
|
125
|
-
}) : {
|
|
126
|
-
sourceEffectEntry: void 0,
|
|
127
|
-
relativeEffectEntry: ''
|
|
128
|
-
};
|
|
129
|
-
const clientGenerationPromise = clientGenerator_js_default()({
|
|
130
|
-
prefix,
|
|
131
|
-
appDir: appDirectory,
|
|
132
|
-
apiDir: apiDirectory,
|
|
133
|
-
lambdaDir,
|
|
134
|
-
existLambda,
|
|
135
|
-
port,
|
|
136
|
-
requestId,
|
|
137
|
-
requestCreator: bff?.requestCreator,
|
|
138
|
-
httpMethodDecider,
|
|
139
|
-
relativeDistPath,
|
|
140
|
-
relativeApiPath,
|
|
141
|
-
apiFiles: apiRouter.getApiFiles(),
|
|
142
|
-
bffRuntimeFramework,
|
|
143
|
-
effectEntry: bff?.effect?.entry,
|
|
144
|
-
effectDataPlatformBatch: bff?.effect?.dataPlatform?.batch
|
|
145
|
-
});
|
|
146
|
-
return Promise.all([
|
|
147
|
-
operationContractsPromise,
|
|
148
|
-
clientGenerationPromise
|
|
149
|
-
]).then(([lambdaContracts, generatedEffectClient])=>{
|
|
150
|
-
if ('effect' === bffRuntimeFramework && null === generatedEffectClient) throw new Error(`Effect cross-project client generation failed for ${sourceEffectEntry ?? apiDirectory}.`);
|
|
151
|
-
const operationContracts = 'effect' === bffRuntimeFramework ? generatedEffectClient?.operationContracts ?? {} : lambdaContracts;
|
|
152
|
-
return pluginGenerator_js_default()({
|
|
153
|
-
prefix,
|
|
154
|
-
appDirectory,
|
|
155
|
-
requestId,
|
|
156
|
-
relativeDistPath,
|
|
157
|
-
relativeApiPath,
|
|
158
|
-
relativeLambdaPath,
|
|
159
|
-
runtimeFramework: 'hono' === bffRuntimeFramework ? 'hono' : 'effect',
|
|
160
|
-
relativeEffectEntry,
|
|
161
|
-
operationContracts
|
|
162
|
-
}).then(()=>runtimeGenerator_js_default()({
|
|
163
|
-
runtime,
|
|
164
|
-
appDirectory,
|
|
165
|
-
relativeDistPath
|
|
166
|
-
}));
|
|
167
|
-
});
|
|
89
|
+
await hooks.onAfterBffCompile.call(context);
|
|
90
|
+
};
|
|
91
|
+
const generate = async ()=>{
|
|
92
|
+
const { appDirectory, apiDirectory, lambdaDirectory, port, packageName } = api.getAppContext();
|
|
93
|
+
const config = api.getNormalizedConfig();
|
|
94
|
+
const relativeDistPath = config.output?.distPath?.root || 'dist';
|
|
95
|
+
const bff = config.bff;
|
|
96
|
+
const prefix = (0, external_prefix_js_namespaceObject.getPrimaryPrefix)(bff?.prefix);
|
|
97
|
+
const apiRouter = new bff_core_namespaceObject.ApiRouter({
|
|
98
|
+
apiDir: apiDirectory,
|
|
99
|
+
appDir: appDirectory,
|
|
100
|
+
lambdaDir: lambdaDirectory,
|
|
101
|
+
prefix,
|
|
102
|
+
httpMethodDecider: bff?.httpMethodDecider,
|
|
103
|
+
isBuild: true
|
|
168
104
|
});
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
105
|
+
const lambdaDir = apiRouter.getLambdaDir();
|
|
106
|
+
const packageJson = await utils_namespaceObject.fs.readJSON(utils_namespaceObject.upath.resolve(appDirectory, 'package.json'));
|
|
107
|
+
const generation = {
|
|
108
|
+
appDirectory,
|
|
109
|
+
apiDirectory,
|
|
110
|
+
lambdaDirectory: lambdaDir,
|
|
111
|
+
existLambda: apiRouter.isExistLambda(),
|
|
112
|
+
apiFiles: apiRouter.getApiFiles(),
|
|
113
|
+
relativeDistPath,
|
|
114
|
+
prefix,
|
|
115
|
+
port,
|
|
116
|
+
requestId: bff?.requestId || packageJson.name || packageName || 'default',
|
|
117
|
+
requestCreator: bff?.requestCreator,
|
|
118
|
+
httpMethodDecider: bff?.httpMethodDecider
|
|
119
|
+
};
|
|
120
|
+
const pluginOptions = {
|
|
121
|
+
prefix,
|
|
122
|
+
appDirectory,
|
|
123
|
+
relativeDistPath,
|
|
124
|
+
relativeApiPath: utils_namespaceObject.upath.relative(appDirectory, apiDirectory),
|
|
125
|
+
relativeLambdaPath: utils_namespaceObject.upath.relative(appDirectory, lambdaDir)
|
|
126
|
+
};
|
|
127
|
+
const runtimeOptions = {
|
|
128
|
+
runtime: bff?.runtimeCreateRequest || RUNTIME_CREATE_REQUEST,
|
|
129
|
+
appDirectory,
|
|
130
|
+
relativeDistPath
|
|
131
|
+
};
|
|
132
|
+
const hooks = api.getHooks();
|
|
133
|
+
await clientGenerator_js_default()({
|
|
134
|
+
prefix,
|
|
135
|
+
appDir: appDirectory,
|
|
136
|
+
apiDir: apiDirectory,
|
|
137
|
+
lambdaDir,
|
|
138
|
+
existLambda: generation.existLambda,
|
|
139
|
+
apiFiles: [
|
|
140
|
+
...generation.apiFiles
|
|
141
|
+
],
|
|
142
|
+
port,
|
|
143
|
+
requestId: generation.requestId,
|
|
144
|
+
requestCreator: generation.requestCreator,
|
|
145
|
+
clientCodegenPlugin: bff?.clientCodegenPlugin,
|
|
146
|
+
httpMethodDecider: generation.httpMethodDecider,
|
|
147
|
+
relativeDistPath,
|
|
148
|
+
relativeApiPath: pluginOptions.relativeApiPath
|
|
149
|
+
}, {
|
|
150
|
+
generation,
|
|
151
|
+
modifyArtifacts: async (context)=>{
|
|
152
|
+
const result = await hooks.modifyBffClientArtifacts.call(context);
|
|
153
|
+
if (result.generation !== generation) throw new Error('modifyBffClientArtifacts must preserve generation identity.');
|
|
154
|
+
return result;
|
|
155
|
+
},
|
|
156
|
+
beforePublish: async ()=>{
|
|
157
|
+
const entries = await hooks.modifyBffGeneratedEntries.call({
|
|
158
|
+
generation,
|
|
159
|
+
plugin: await (0, pluginGenerator_js_namespaceObject.renderBffPlugin)(pluginOptions),
|
|
160
|
+
runtime: (0, runtimeGenerator_js_namespaceObject.renderBffRuntime)(runtimeOptions),
|
|
161
|
+
packageDependencies: {}
|
|
162
|
+
});
|
|
163
|
+
if (entries.generation !== generation) throw new Error('modifyBffGeneratedEntries must preserve generation identity.');
|
|
164
|
+
await pluginGenerator_js_default()(pluginOptions, entries.plugin);
|
|
165
|
+
await runtimeGenerator_js_default()(runtimeOptions, entries.runtime);
|
|
166
|
+
return entries.packageDependencies;
|
|
167
|
+
}
|
|
173
168
|
});
|
|
169
|
+
};
|
|
170
|
+
const handleCrossProjectInvocation = async (isBuild = false)=>{
|
|
171
|
+
if (api.getNormalizedConfig().bff?.crossProject !== true) return;
|
|
172
|
+
if (!isBuild) await compileApi();
|
|
173
|
+
await generate();
|
|
174
|
+
};
|
|
174
175
|
return {
|
|
175
176
|
compileApi,
|
|
176
177
|
generate,
|
package/dist/cjs/cli.js
CHANGED
|
@@ -41,6 +41,7 @@ __webpack_require__.d(__webpack_exports__, {
|
|
|
41
41
|
default: ()=>cli
|
|
42
42
|
});
|
|
43
43
|
const bff_core_namespaceObject = require("@modern-js/bff-core");
|
|
44
|
+
const plugin_namespaceObject = require("@modern-js/plugin");
|
|
44
45
|
const utils_namespaceObject = require("@modern-js/utils");
|
|
45
46
|
const external_path_namespaceObject = require("path");
|
|
46
47
|
var external_path_default = /*#__PURE__*/ __webpack_require__.n(external_path_namespaceObject);
|
|
@@ -50,13 +51,19 @@ const prefix_js_namespaceObject = require("./cli/prefix.js");
|
|
|
50
51
|
const watch_js_namespaceObject = require("./cli/watch.js");
|
|
51
52
|
const bffPlugin = ()=>({
|
|
52
53
|
name: '@modern-js/plugin-bff',
|
|
54
|
+
registryHooks: {
|
|
55
|
+
onBeforeBffCompile: (0, plugin_namespaceObject.createAsyncHook)(),
|
|
56
|
+
onAfterBffCompile: (0, plugin_namespaceObject.createAsyncHook)(),
|
|
57
|
+
modifyBffClientArtifacts: (0, plugin_namespaceObject.createAsyncHook)(),
|
|
58
|
+
modifyBffGeneratedEntries: (0, plugin_namespaceObject.createAsyncHook)()
|
|
59
|
+
},
|
|
53
60
|
setup: (api)=>{
|
|
54
61
|
{
|
|
55
62
|
const appContext = api.getAppContext();
|
|
56
63
|
const userRuntimeFramework = api.getConfig()?.bff?.runtimeFramework;
|
|
57
64
|
api.updateAppContext({
|
|
58
65
|
...appContext,
|
|
59
|
-
bffRuntimeFramework:
|
|
66
|
+
bffRuntimeFramework: userRuntimeFramework ?? 'hono'
|
|
60
67
|
});
|
|
61
68
|
}
|
|
62
69
|
const { compileApi, handleCrossProjectInvocation } = (0, generator_js_namespaceObject.createBffGenerator)(api);
|
|
@@ -74,7 +81,7 @@ const bffPlugin = ()=>({
|
|
|
74
81
|
compress
|
|
75
82
|
},
|
|
76
83
|
bundlerChain: (chain, { CHAIN_ID, isServer })=>{
|
|
77
|
-
const { port, appDirectory, apiDirectory, lambdaDirectory
|
|
84
|
+
const { port, appDirectory, apiDirectory, lambdaDirectory } = api.getAppContext();
|
|
78
85
|
const modernConfig = api.getNormalizedConfig();
|
|
79
86
|
const { bff } = modernConfig || {};
|
|
80
87
|
const prefix = (0, prefix_js_namespaceObject.getPrimaryPrefix)(bff?.prefix);
|
|
@@ -104,10 +111,8 @@ const bffPlugin = ()=>({
|
|
|
104
111
|
requestId: bff?.requestId,
|
|
105
112
|
target: name,
|
|
106
113
|
requestCreator: bff?.requestCreator,
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
effectEntry: bff?.effect?.entry,
|
|
110
|
-
effectDataPlatformBatch: bff?.effect?.dataPlatform?.batch
|
|
114
|
+
clientCodegenPlugin: bff?.clientCodegenPlugin,
|
|
115
|
+
httpMethodDecider
|
|
111
116
|
});
|
|
112
117
|
}
|
|
113
118
|
}
|
|
@@ -159,7 +164,7 @@ const bffPlugin = ()=>({
|
|
|
159
164
|
appContext.apiDirectory,
|
|
160
165
|
appContext.sharedDirectory
|
|
161
166
|
].filter(Boolean);
|
|
162
|
-
return [];
|
|
167
|
+
else return [];
|
|
163
168
|
});
|
|
164
169
|
api.onFileChanged(async (e)=>{
|
|
165
170
|
const { filename, eventType, isPrivate } = e;
|
package/dist/cjs/loader.js
CHANGED
|
@@ -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,67 +31,14 @@ __webpack_require__.d(__webpack_exports__, {
|
|
|
40
31
|
default: ()=>src_loader
|
|
41
32
|
});
|
|
42
33
|
const bff_core_namespaceObject = require("@modern-js/bff-core");
|
|
43
|
-
const effect_source_loader_namespaceObject = require("@modern-js/plugin-bff-extensions/effect-source-loader");
|
|
44
34
|
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
|
-
const EFFECT_BFF_WORKER_RUNTIME_QUERY = 'modern-bff-runtime';
|
|
48
|
-
const EFFECT_BFF_WORKER_RUNTIME_SOURCE_QUERY = 'modern-bff-runtime-source';
|
|
49
35
|
const createErrorModule = (message)=>`throw new Error(${JSON.stringify(message)});`;
|
|
50
|
-
async function transformEffectRuntimeSource(source, filename) {
|
|
51
|
-
const swc = await import("@swc/core");
|
|
52
|
-
const result = await swc.transform(source, {
|
|
53
|
-
filename,
|
|
54
|
-
sourceMaps: false,
|
|
55
|
-
jsc: {
|
|
56
|
-
parser: {
|
|
57
|
-
syntax: "typescript",
|
|
58
|
-
tsx: filename.endsWith('.tsx') || filename.endsWith('.jsx')
|
|
59
|
-
},
|
|
60
|
-
target: 'es2024'
|
|
61
|
-
},
|
|
62
|
-
module: {
|
|
63
|
-
type: 'es6'
|
|
64
|
-
}
|
|
65
|
-
});
|
|
66
|
-
return result.code;
|
|
67
|
-
}
|
|
68
36
|
async function loader(source) {
|
|
69
37
|
this.cacheable();
|
|
70
38
|
const { resourcePath } = this;
|
|
71
39
|
delete require.cache[resourcePath];
|
|
72
40
|
const callback = this.async();
|
|
73
41
|
const draftOptions = this.getOptions();
|
|
74
|
-
const resourceQueries = new URLSearchParams(this.resourceQuery);
|
|
75
|
-
const effectEntryFile = (0, effect_source_loader_namespaceObject.resolveEffectEntryFile)({
|
|
76
|
-
appDir: draftOptions.appDir,
|
|
77
|
-
apiDir: draftOptions.apiDir,
|
|
78
|
-
effectEntry: draftOptions.effectEntry
|
|
79
|
-
});
|
|
80
|
-
if ('effect' === draftOptions.bffRuntimeFramework && effectEntryFile && external_path_default().resolve(effectEntryFile) === external_path_default().resolve(resourcePath) && resourceQueries.has(EFFECT_BFF_WORKER_RUNTIME_SOURCE_QUERY)) {
|
|
81
|
-
const code = await transformEffectRuntimeSource(source, resourcePath);
|
|
82
|
-
callback(void 0, code);
|
|
83
|
-
return;
|
|
84
|
-
}
|
|
85
|
-
if ('effect' === draftOptions.bffRuntimeFramework && effectEntryFile && external_path_default().resolve(effectEntryFile) === external_path_default().resolve(resourcePath) && resourceQueries.has(EFFECT_BFF_WORKER_RUNTIME_QUERY)) return void callback(void 0, await (0, effect_source_loader_namespaceObject.generateEffectWorkerRuntimeWrapper)(this, draftOptions, resourcePath));
|
|
86
|
-
if ('effect' === draftOptions.bffRuntimeFramework && effectEntryFile && external_path_default().resolve(effectEntryFile) === external_path_default().resolve(resourcePath)) {
|
|
87
|
-
const code = await (0, effect_source_loader_namespaceObject.generateEffectClientCode)({
|
|
88
|
-
appDir: draftOptions.appDir,
|
|
89
|
-
apiDir: draftOptions.apiDir,
|
|
90
|
-
resourcePath,
|
|
91
|
-
prefix: Array.isArray(draftOptions.prefix) ? draftOptions.prefix[0] : draftOptions.prefix,
|
|
92
|
-
port: Number(draftOptions.port),
|
|
93
|
-
target: draftOptions.target,
|
|
94
|
-
requestId: draftOptions.requestId,
|
|
95
|
-
requestCreator: draftOptions.requestCreator,
|
|
96
|
-
httpMethodDecider: draftOptions.httpMethodDecider,
|
|
97
|
-
dataPlatformBatch: draftOptions.effectDataPlatformBatch,
|
|
98
|
-
onDependency: (dependency)=>this.addDependency(dependency)
|
|
99
|
-
});
|
|
100
|
-
if (code) return void callback(void 0, code);
|
|
101
|
-
callback(new Error(`Failed to generate Effect client for ${resourcePath}`));
|
|
102
|
-
return;
|
|
103
|
-
}
|
|
104
42
|
const warning = `The file ${resourcePath} is not allowed to be imported in src directory, only API definition files are allowed.`;
|
|
105
43
|
if (!draftOptions.existLambda) {
|
|
106
44
|
utils_namespaceObject.logger.warn(warning);
|
|
@@ -116,7 +54,9 @@ async function loader(source) {
|
|
|
116
54
|
port: Number(draftOptions.port),
|
|
117
55
|
source,
|
|
118
56
|
resourcePath,
|
|
119
|
-
httpMethodDecider: draftOptions.httpMethodDecider
|
|
57
|
+
httpMethodDecider: draftOptions.httpMethodDecider,
|
|
58
|
+
clientCodegenPlugin: draftOptions.clientCodegenPlugin,
|
|
59
|
+
requestId: draftOptions.requestId
|
|
120
60
|
};
|
|
121
61
|
const { lambdaDir } = draftOptions;
|
|
122
62
|
if (!resourcePath.startsWith(lambdaDir)) {
|
|
@@ -127,8 +67,12 @@ async function loader(source) {
|
|
|
127
67
|
if (draftOptions.fetcher) options.fetcher = draftOptions.fetcher;
|
|
128
68
|
if (draftOptions.requestCreator) options.requestCreator = draftOptions.requestCreator;
|
|
129
69
|
options.requireResolve = require.resolve;
|
|
130
|
-
|
|
131
|
-
|
|
70
|
+
try {
|
|
71
|
+
const result = await (0, bff_core_namespaceObject.generateClient)(options);
|
|
72
|
+
callback(void 0, result.isOk ? result.value : createErrorModule(result.value));
|
|
73
|
+
} catch (error) {
|
|
74
|
+
callback(error instanceof Error ? error : new Error(String(error)));
|
|
75
|
+
}
|
|
132
76
|
}
|
|
133
77
|
const src_loader = loader;
|
|
134
78
|
exports["default"] = __webpack_exports__["default"];
|
|
@@ -30,21 +30,15 @@ __webpack_require__.r(__webpack_exports__);
|
|
|
30
30
|
__webpack_require__.d(__webpack_exports__, {
|
|
31
31
|
configure: ()=>create_request_namespaceObject.configure,
|
|
32
32
|
createRequest: ()=>create_request_namespaceObject.createRequest,
|
|
33
|
-
createRequestContextHeaders: ()=>create_request_namespaceObject.createRequestContextHeaders,
|
|
34
|
-
createRequestContextSnapshot: ()=>create_request_namespaceObject.createRequestContextSnapshot,
|
|
35
33
|
createUploader: ()=>create_request_namespaceObject.createUploader
|
|
36
34
|
});
|
|
37
35
|
const create_request_namespaceObject = require("@modern-js/create-request");
|
|
38
36
|
exports.configure = __webpack_exports__.configure;
|
|
39
37
|
exports.createRequest = __webpack_exports__.createRequest;
|
|
40
|
-
exports.createRequestContextHeaders = __webpack_exports__.createRequestContextHeaders;
|
|
41
|
-
exports.createRequestContextSnapshot = __webpack_exports__.createRequestContextSnapshot;
|
|
42
38
|
exports.createUploader = __webpack_exports__.createUploader;
|
|
43
39
|
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
44
40
|
"configure",
|
|
45
41
|
"createRequest",
|
|
46
|
-
"createRequestContextHeaders",
|
|
47
|
-
"createRequestContextSnapshot",
|
|
48
42
|
"createUploader"
|
|
49
43
|
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
50
44
|
Object.defineProperty(exports, '__esModule', {
|
|
@@ -39,9 +39,6 @@ __webpack_require__.r(__webpack_exports__);
|
|
|
39
39
|
__webpack_require__.d(__webpack_exports__, {
|
|
40
40
|
HonoAdapter: ()=>HonoAdapter
|
|
41
41
|
});
|
|
42
|
-
const cross_project_policy_namespaceObject = require("@modern-js/plugin-bff-extensions/cross-project-policy");
|
|
43
|
-
const hono_namespaceObject = require("@modern-js/plugin-bff-extensions/hono");
|
|
44
|
-
const utils_namespaceObject = require("@modern-js/utils");
|
|
45
42
|
const createHonoRoutes_js_namespaceObject = require("../../utils/createHonoRoutes.js");
|
|
46
43
|
var createHonoRoutes_js_default = /*#__PURE__*/ __webpack_require__.n(createHonoRoutes_js_namespaceObject);
|
|
47
44
|
const before = [
|
|
@@ -50,7 +47,8 @@ const before = [
|
|
|
50
47
|
'render'
|
|
51
48
|
];
|
|
52
49
|
class HonoAdapter {
|
|
53
|
-
constructor(api){
|
|
50
|
+
constructor(api, createRouteBinder){
|
|
51
|
+
this.createRouteBinder = createRouteBinder;
|
|
54
52
|
this.apiMiddleware = [];
|
|
55
53
|
this.isHono = true;
|
|
56
54
|
this.setHandlers = async ()=>{
|
|
@@ -58,25 +56,23 @@ class HonoAdapter {
|
|
|
58
56
|
const { apiHandlerInfos } = this.api.getServerContext();
|
|
59
57
|
const handlers = apiHandlerInfos ?? [];
|
|
60
58
|
const honoHandlers = createHonoRoutes_js_default()(handlers);
|
|
61
|
-
const
|
|
59
|
+
const bindRoute = this.createRouteBinder?.(this.api, handlers);
|
|
60
|
+
if (this.createRouteBinder && 'function' != typeof bindRoute) throw new TypeError('Hono route binder factory must return a function.');
|
|
62
61
|
this.apiMiddleware = honoHandlers.map(({ path, method, handler })=>({
|
|
63
62
|
name: 'hono-bff-api',
|
|
64
63
|
path,
|
|
65
64
|
method,
|
|
66
|
-
handler:
|
|
65
|
+
handler: bindRoute ? bindRoute({
|
|
67
66
|
handler,
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
onError: this.api.getServerConfig()?.onError,
|
|
71
|
-
reportError: (error)=>utils_namespaceObject.logger.error(error)
|
|
72
|
-
}),
|
|
67
|
+
routePath: path
|
|
68
|
+
}) : handler,
|
|
73
69
|
order: 'post',
|
|
74
70
|
before
|
|
75
71
|
}));
|
|
76
72
|
};
|
|
77
73
|
this.registerMiddleware = async (_options)=>{
|
|
78
74
|
const { bffRuntimeFramework } = this.api.getServerContext();
|
|
79
|
-
if ('hono' !== bffRuntimeFramework) {
|
|
75
|
+
if (void 0 !== bffRuntimeFramework && 'hono' !== bffRuntimeFramework) {
|
|
80
76
|
this.isHono = false;
|
|
81
77
|
return;
|
|
82
78
|
}
|
package/dist/cjs/server.js
CHANGED
|
@@ -44,17 +44,6 @@ const utils_namespaceObject = require("@modern-js/utils");
|
|
|
44
44
|
const external_path_namespaceObject = require("path");
|
|
45
45
|
var external_path_default = /*#__PURE__*/ __webpack_require__.n(external_path_namespaceObject);
|
|
46
46
|
const adapter_js_namespaceObject = require("./runtime/hono/adapter.js");
|
|
47
|
-
const RUNTIME_ADAPTER_LOADERS = {
|
|
48
|
-
hono: async (api)=>[
|
|
49
|
-
new adapter_js_namespaceObject.HonoAdapter(api)
|
|
50
|
-
],
|
|
51
|
-
effect: async (api)=>{
|
|
52
|
-
const { EffectAdapter } = await import("@modern-js/plugin-bff-extensions/effect-adapter");
|
|
53
|
-
return [
|
|
54
|
-
new EffectAdapter(api)
|
|
55
|
-
];
|
|
56
|
-
}
|
|
57
|
-
};
|
|
58
47
|
const normalizePrefixList = (prefix)=>{
|
|
59
48
|
if (Array.isArray(prefix)) return prefix.filter(Boolean);
|
|
60
49
|
return [
|
|
@@ -62,21 +51,19 @@ const normalizePrefixList = (prefix)=>{
|
|
|
62
51
|
];
|
|
63
52
|
};
|
|
64
53
|
const getPrimaryPrefix = (prefix)=>normalizePrefixList(prefix)[0] || '/api';
|
|
65
|
-
function resolveRuntimeFramework(runtimeFramework) {
|
|
66
|
-
return 'hono' === runtimeFramework ? 'hono' : 'effect';
|
|
67
|
-
}
|
|
68
54
|
class Storage {
|
|
69
55
|
constructor(){
|
|
70
56
|
this.middlewares = [];
|
|
71
57
|
}
|
|
72
58
|
}
|
|
73
|
-
const server = ()=>({
|
|
59
|
+
const server = (options = {})=>({
|
|
74
60
|
name: '@modern-js/plugin-bff',
|
|
75
61
|
setup: (api)=>{
|
|
76
62
|
const storage = new Storage();
|
|
77
63
|
let apiRouter = null;
|
|
78
64
|
const appContext = api.getServerContext();
|
|
79
|
-
const runtimeFramework =
|
|
65
|
+
const runtimeFramework = appContext.bffRuntimeFramework ?? 'hono';
|
|
66
|
+
if ('hono' !== runtimeFramework) throw new Error(`Native BFF server plugin requires Hono; received "${runtimeFramework}".`);
|
|
80
67
|
api.onPrepare(async ()=>{
|
|
81
68
|
const appContext = api.getServerContext();
|
|
82
69
|
const { render } = appContext;
|
|
@@ -92,41 +79,46 @@ const server = ()=>({
|
|
|
92
79
|
const httpMethodDecider = config?.bff?.httpMethodDecider;
|
|
93
80
|
const { distDirectory: pwd, middlewares: globalMiddlewares } = api.getServerContext();
|
|
94
81
|
const webOnly = await (0, utils_namespaceObject.isWebOnly)();
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
httpMethodDecider
|
|
109
|
-
});
|
|
110
|
-
}
|
|
111
|
-
if (handler && (0, utils_namespaceObject.isFunction)(handler)) globalMiddlewares.push({
|
|
112
|
-
name: 'bind-bff',
|
|
113
|
-
handler: (c, next)=>{
|
|
114
|
-
if (!prefixList.some((item)=>c.req.path.startsWith(item)) && !enableHandleWeb) return next();
|
|
115
|
-
return handler(c, next);
|
|
116
|
-
},
|
|
117
|
-
order: 'post',
|
|
118
|
-
before: [
|
|
119
|
-
'custom-server-hook',
|
|
120
|
-
'custom-server-middleware',
|
|
121
|
-
'render'
|
|
122
|
-
]
|
|
82
|
+
let handler;
|
|
83
|
+
if (webOnly) handler = async (c, next)=>{
|
|
84
|
+
c.body('');
|
|
85
|
+
await next();
|
|
86
|
+
};
|
|
87
|
+
else {
|
|
88
|
+
const runner = api.getHooks();
|
|
89
|
+
const renderHandler = enableHandleWeb ? render : null;
|
|
90
|
+
handler = await runner.prepareApiServer.call({
|
|
91
|
+
pwd: pwd,
|
|
92
|
+
prefix,
|
|
93
|
+
render: renderHandler,
|
|
94
|
+
httpMethodDecider
|
|
123
95
|
});
|
|
124
96
|
}
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
enableHandleWeb
|
|
129
|
-
|
|
97
|
+
if (handler && (0, utils_namespaceObject.isFunction)(handler)) globalMiddlewares.push({
|
|
98
|
+
name: 'bind-bff',
|
|
99
|
+
handler: (c, next)=>{
|
|
100
|
+
if (!prefixList.some((item)=>c.req.path.startsWith(item)) && !enableHandleWeb) return next();
|
|
101
|
+
return handler(c, next);
|
|
102
|
+
},
|
|
103
|
+
order: 'post',
|
|
104
|
+
before: [
|
|
105
|
+
'custom-server-hook',
|
|
106
|
+
'custom-server-middleware',
|
|
107
|
+
'render'
|
|
108
|
+
]
|
|
109
|
+
});
|
|
110
|
+
let createHonoRouteBinder;
|
|
111
|
+
if (void 0 !== options.honoRouteBinder) {
|
|
112
|
+
if ('string' != typeof options.honoRouteBinder || '' === options.honoRouteBinder.trim()) throw new Error('The Hono BFF route binder must be a module specifier.');
|
|
113
|
+
const context = api.getServerContext();
|
|
114
|
+
const module = await (0, utils_namespaceObject.compatibleRequire)((0, utils_namespaceObject.tryResolve)(options.honoRouteBinder, context.appDirectory || context.distDirectory || process.cwd()), false);
|
|
115
|
+
if (!module || 'function' != typeof module.createHonoRouteBinder) throw new Error(`BFF route binder module "${options.honoRouteBinder}" must export createHonoRouteBinder.`);
|
|
116
|
+
createHonoRouteBinder = module.createHonoRouteBinder;
|
|
117
|
+
}
|
|
118
|
+
await new adapter_js_namespaceObject.HonoAdapter(api, createHonoRouteBinder).registerMiddleware({
|
|
119
|
+
prefix,
|
|
120
|
+
enableHandleWeb
|
|
121
|
+
});
|
|
130
122
|
});
|
|
131
123
|
api.onReset(async ({ event })=>{
|
|
132
124
|
if ('file-change' === event.type && apiRouter) {
|
|
@@ -139,7 +131,6 @@ const server = ()=>({
|
|
|
139
131
|
}
|
|
140
132
|
});
|
|
141
133
|
const prepareApiServer = async (input, next)=>{
|
|
142
|
-
if ('hono' !== runtimeFramework) return next(input);
|
|
143
134
|
const { pwd, prefix, httpMethodDecider } = input;
|
|
144
135
|
const defaultApiDirectory = external_path_default().resolve(pwd, utils_namespaceObject.API_DIR);
|
|
145
136
|
const appContext = api.getServerContext();
|
|
@@ -71,7 +71,7 @@ function createFileDetails(options) {
|
|
|
71
71
|
const relativePath = external_path_default().relative(baseDirectory, resourcePath);
|
|
72
72
|
const parsedPath = external_path_default().parse(relativePath);
|
|
73
73
|
const targetDir = posixJoin(`./${relativeDistPath}/${CLIENT_DIR}`, parsedPath.dir, `${parsedPath.name}.js`);
|
|
74
|
-
const absTargetDir = external_path_default().resolve(targetDir);
|
|
74
|
+
const absTargetDir = external_path_default().resolve(appDirectory, targetDir);
|
|
75
75
|
const relativePathFromAppDirectory = external_path_default().relative(appDirectory, external_path_default().dirname(resourcePath));
|
|
76
76
|
const typesFilePath = posixJoin(`./${relativeDistPath}`, relativePathFromAppDirectory, `${parsedPath.name}.d.ts`);
|
|
77
77
|
return {
|