@bleedingdev/modern-js-plugin-bff 3.2.0-ultramodern.0
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/LICENSE +21 -0
- package/README.md +26 -0
- package/cli.js +1 -0
- package/dist/cjs/cli.js +294 -0
- package/dist/cjs/constants.js +48 -0
- package/dist/cjs/index.js +58 -0
- package/dist/cjs/loader.js +106 -0
- package/dist/cjs/runtime/create-request/index.js +48 -0
- package/dist/cjs/runtime/data-platform/index.js +693 -0
- package/dist/cjs/runtime/effect/adapter.js +311 -0
- package/dist/cjs/runtime/effect/context.js +48 -0
- package/dist/cjs/runtime/effect/index.js +608 -0
- package/dist/cjs/runtime/effect-client/index.js +178 -0
- package/dist/cjs/runtime/hono/adapter.js +168 -0
- package/dist/cjs/runtime/hono/index.js +65 -0
- package/dist/cjs/runtime/hono/operators.js +68 -0
- package/dist/cjs/server.js +179 -0
- package/dist/cjs/utils/clientGenerator.js +342 -0
- package/dist/cjs/utils/createHonoRoutes.js +138 -0
- package/dist/cjs/utils/crossProjectApiPlugin.js +118 -0
- package/dist/cjs/utils/effectClientGenerator.js +673 -0
- package/dist/cjs/utils/pluginGenerator.js +73 -0
- package/dist/cjs/utils/runtimeGenerator.js +133 -0
- package/dist/esm/cli.mjs +245 -0
- package/dist/esm/constants.mjs +11 -0
- package/dist/esm/index.mjs +1 -0
- package/dist/esm/loader.mjs +62 -0
- package/dist/esm/runtime/create-request/index.mjs +1 -0
- package/dist/esm/runtime/data-platform/index.mjs +599 -0
- package/dist/esm/runtime/effect/adapter.mjs +267 -0
- package/dist/esm/runtime/effect/context.mjs +11 -0
- package/dist/esm/runtime/effect/index.mjs +438 -0
- package/dist/esm/runtime/effect-client/index.mjs +90 -0
- package/dist/esm/runtime/hono/adapter.mjs +124 -0
- package/dist/esm/runtime/hono/index.mjs +2 -0
- package/dist/esm/runtime/hono/operators.mjs +31 -0
- package/dist/esm/server.mjs +135 -0
- package/dist/esm/utils/clientGenerator.mjs +293 -0
- package/dist/esm/utils/createHonoRoutes.mjs +92 -0
- package/dist/esm/utils/crossProjectApiPlugin.mjs +54 -0
- package/dist/esm/utils/effectClientGenerator.mjs +623 -0
- package/dist/esm/utils/pluginGenerator.mjs +29 -0
- package/dist/esm/utils/runtimeGenerator.mjs +89 -0
- package/dist/esm-node/cli.mjs +249 -0
- package/dist/esm-node/constants.mjs +12 -0
- package/dist/esm-node/index.mjs +2 -0
- package/dist/esm-node/loader.mjs +64 -0
- package/dist/esm-node/runtime/create-request/index.mjs +2 -0
- package/dist/esm-node/runtime/data-platform/index.mjs +600 -0
- package/dist/esm-node/runtime/effect/adapter.mjs +269 -0
- package/dist/esm-node/runtime/effect/context.mjs +12 -0
- package/dist/esm-node/runtime/effect/index.mjs +439 -0
- package/dist/esm-node/runtime/effect-client/index.mjs +91 -0
- package/dist/esm-node/runtime/hono/adapter.mjs +125 -0
- package/dist/esm-node/runtime/hono/index.mjs +3 -0
- package/dist/esm-node/runtime/hono/operators.mjs +32 -0
- package/dist/esm-node/server.mjs +136 -0
- package/dist/esm-node/utils/clientGenerator.mjs +294 -0
- package/dist/esm-node/utils/createHonoRoutes.mjs +93 -0
- package/dist/esm-node/utils/crossProjectApiPlugin.mjs +55 -0
- package/dist/esm-node/utils/effectClientGenerator.mjs +625 -0
- package/dist/esm-node/utils/pluginGenerator.mjs +33 -0
- package/dist/esm-node/utils/runtimeGenerator.mjs +91 -0
- package/dist/types/cli.d.ts +3 -0
- package/dist/types/constants.d.ts +2 -0
- package/dist/types/index.d.ts +1 -0
- package/dist/types/loader.d.ts +27 -0
- package/dist/types/runtime/create-request/index.d.ts +2 -0
- package/dist/types/runtime/data-platform/index.d.ts +187 -0
- package/dist/types/runtime/effect/adapter.d.ts +22 -0
- package/dist/types/runtime/effect/context.d.ts +8 -0
- package/dist/types/runtime/effect/index.d.ts +171 -0
- package/dist/types/runtime/effect-client/index.d.ts +47 -0
- package/dist/types/runtime/hono/adapter.d.ts +19 -0
- package/dist/types/runtime/hono/index.d.ts +2 -0
- package/dist/types/runtime/hono/operators.d.ts +10 -0
- package/dist/types/server.d.ts +3 -0
- package/dist/types/utils/clientGenerator.d.ts +37 -0
- package/dist/types/utils/createHonoRoutes.d.ts +10 -0
- package/dist/types/utils/crossProjectApiPlugin.d.ts +9 -0
- package/dist/types/utils/effectClientGenerator.d.ts +27 -0
- package/dist/types/utils/pluginGenerator.d.ts +9 -0
- package/dist/types/utils/runtimeGenerator.d.ts +7 -0
- package/docs/data-platform-architecture.md +61 -0
- package/package.json +172 -0
- package/rslib.config.mts +4 -0
- package/rstest.config.mts +10 -0
- package/server.js +1 -0
|
@@ -0,0 +1,342 @@
|
|
|
1
|
+
"use strict";
|
|
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
|
+
(()=>{
|
|
13
|
+
__webpack_require__.d = (exports1, definition)=>{
|
|
14
|
+
for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
|
|
15
|
+
enumerable: true,
|
|
16
|
+
get: definition[key]
|
|
17
|
+
});
|
|
18
|
+
};
|
|
19
|
+
})();
|
|
20
|
+
(()=>{
|
|
21
|
+
__webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
|
|
22
|
+
})();
|
|
23
|
+
(()=>{
|
|
24
|
+
__webpack_require__.r = (exports1)=>{
|
|
25
|
+
if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
|
|
26
|
+
value: 'Module'
|
|
27
|
+
});
|
|
28
|
+
Object.defineProperty(exports1, '__esModule', {
|
|
29
|
+
value: true
|
|
30
|
+
});
|
|
31
|
+
};
|
|
32
|
+
})();
|
|
33
|
+
var __webpack_exports__ = {};
|
|
34
|
+
__webpack_require__.r(__webpack_exports__);
|
|
35
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
36
|
+
copyFiles: ()=>copyFiles,
|
|
37
|
+
default: ()=>utils_clientGenerator,
|
|
38
|
+
readDirectoryFiles: ()=>readDirectoryFiles
|
|
39
|
+
});
|
|
40
|
+
const bff_core_namespaceObject = require("@modern-js/bff-core");
|
|
41
|
+
const utils_namespaceObject = require("@modern-js/utils");
|
|
42
|
+
const external_path_namespaceObject = require("path");
|
|
43
|
+
var external_path_default = /*#__PURE__*/ __webpack_require__.n(external_path_namespaceObject);
|
|
44
|
+
const external_effectClientGenerator_js_namespaceObject = require("./effectClientGenerator.js");
|
|
45
|
+
const API_DIR = 'api';
|
|
46
|
+
const PLUGIN_DIR = 'plugin';
|
|
47
|
+
const RUNTIME_DIR = 'runtime';
|
|
48
|
+
const CLIENT_DIR = 'client';
|
|
49
|
+
const EXPORT_PREFIX = `./${API_DIR}/`;
|
|
50
|
+
const TYPE_PREFIX = `${API_DIR}/`;
|
|
51
|
+
const GENERATED_RUNTIME_DIRS = [
|
|
52
|
+
CLIENT_DIR,
|
|
53
|
+
PLUGIN_DIR,
|
|
54
|
+
RUNTIME_DIR
|
|
55
|
+
];
|
|
56
|
+
const toPosixPath = (p)=>p.replace(/\\/g, '/');
|
|
57
|
+
const posixJoin = (...args)=>toPosixPath(external_path_default().join(...args));
|
|
58
|
+
function getPackageName(appDirectory) {
|
|
59
|
+
try {
|
|
60
|
+
const packageJsonPath = external_path_default().resolve(appDirectory, './package.json');
|
|
61
|
+
const packageJson = utils_namespaceObject.fs.readJSONSync(packageJsonPath);
|
|
62
|
+
return packageJson.name;
|
|
63
|
+
} catch {
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
function createFileDetails(options) {
|
|
68
|
+
const { appDirectory, baseDirectory, resourcePath, source, relativeDistPath } = options;
|
|
69
|
+
const relativePath = external_path_default().relative(baseDirectory, resourcePath);
|
|
70
|
+
const parsedPath = external_path_default().parse(relativePath);
|
|
71
|
+
const targetDir = posixJoin(`./${relativeDistPath}/${CLIENT_DIR}`, parsedPath.dir, `${parsedPath.name}.js`);
|
|
72
|
+
const absTargetDir = external_path_default().resolve(targetDir);
|
|
73
|
+
const relativePathFromAppDirectory = external_path_default().relative(appDirectory, external_path_default().dirname(resourcePath));
|
|
74
|
+
const typesFilePath = posixJoin(`./${relativeDistPath}`, relativePathFromAppDirectory, `${parsedPath.name}.d.ts`);
|
|
75
|
+
return {
|
|
76
|
+
resourcePath,
|
|
77
|
+
source,
|
|
78
|
+
targetDir,
|
|
79
|
+
name: parsedPath.name,
|
|
80
|
+
absTargetDir,
|
|
81
|
+
relativeTargetDistDir: `./${typesFilePath}`,
|
|
82
|
+
exportKey: toPosixPath(external_path_default().join(parsedPath.dir, parsedPath.name))
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
async function readDirectoryFiles(appDirectory, directory, relativeDistPath) {
|
|
86
|
+
const filesList = [];
|
|
87
|
+
async function readFiles(currentPath) {
|
|
88
|
+
const entries = await utils_namespaceObject.fs.readdir(currentPath, {
|
|
89
|
+
withFileTypes: true
|
|
90
|
+
});
|
|
91
|
+
for (const entry of entries){
|
|
92
|
+
if ('_app.ts' === entry.name) continue;
|
|
93
|
+
const resourcePath = external_path_default().join(currentPath, entry.name);
|
|
94
|
+
if (entry.isDirectory()) await readFiles(resourcePath);
|
|
95
|
+
else {
|
|
96
|
+
const source = await utils_namespaceObject.fs.readFile(resourcePath, 'utf8');
|
|
97
|
+
filesList.push(createFileDetails({
|
|
98
|
+
appDirectory,
|
|
99
|
+
baseDirectory: directory,
|
|
100
|
+
resourcePath,
|
|
101
|
+
source,
|
|
102
|
+
relativeDistPath
|
|
103
|
+
}));
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
await readFiles(directory);
|
|
108
|
+
return filesList;
|
|
109
|
+
}
|
|
110
|
+
function mergePackageJson(packageJson, files, typesVersion, exports1, relativeDistPath) {
|
|
111
|
+
const distPrefix = toPosixPath(`./${relativeDistPath}/`);
|
|
112
|
+
const generatedPrefixes = GENERATED_RUNTIME_DIRS.map((dir)=>toPosixPath(`${distPrefix}${dir}/`));
|
|
113
|
+
const isManagedExportEntry = (value)=>{
|
|
114
|
+
if (!value) return false;
|
|
115
|
+
const values = [
|
|
116
|
+
value.import,
|
|
117
|
+
value.require,
|
|
118
|
+
value.types
|
|
119
|
+
].filter(Boolean);
|
|
120
|
+
return values.every((entry)=>generatedPrefixes.some((prefix)=>entry.startsWith(prefix)));
|
|
121
|
+
};
|
|
122
|
+
const isManagedTypeEntry = (value)=>Array.isArray(value) && value.length > 0 && value.every((entry)=>generatedPrefixes.some((prefix)=>entry.startsWith(prefix)));
|
|
123
|
+
const normalizedFiles = [
|
|
124
|
+
...new Set(files.map((file)=>toPosixPath(file)))
|
|
125
|
+
];
|
|
126
|
+
const currentFiles = packageJson.files || [];
|
|
127
|
+
packageJson.files = [
|
|
128
|
+
...new Set([
|
|
129
|
+
...currentFiles.map((file)=>toPosixPath(file)),
|
|
130
|
+
...normalizedFiles
|
|
131
|
+
])
|
|
132
|
+
];
|
|
133
|
+
packageJson.typesVersions ??= {};
|
|
134
|
+
const typesVersions = packageJson.typesVersions;
|
|
135
|
+
const starTypes = typesVersions['*'] || {};
|
|
136
|
+
const generatedTypeEntries = typesVersion['*'] || {};
|
|
137
|
+
const generatedTypeKeys = new Set(Object.keys(generatedTypeEntries));
|
|
138
|
+
const typeConflicts = Object.entries(starTypes).filter(([key, value])=>{
|
|
139
|
+
if (!generatedTypeKeys.has(key) && !key.startsWith(TYPE_PREFIX)) return false;
|
|
140
|
+
const generatedValue = generatedTypeEntries[key];
|
|
141
|
+
if (generatedValue) return JSON.stringify(value) !== JSON.stringify(generatedValue) && !isManagedTypeEntry(value);
|
|
142
|
+
return !isManagedTypeEntry(value);
|
|
143
|
+
}).map(([key])=>key);
|
|
144
|
+
if (typeConflicts.length > 0) throw new Error(`[plugin-bff] package.json typesVersions conflict on keys: ${typeConflicts.sort().join(', ')}. Rename these keys or move them outside "${TYPE_PREFIX}" namespace.`);
|
|
145
|
+
Object.keys(starTypes).forEach((key)=>{
|
|
146
|
+
if (generatedTypeKeys.has(key) || key.startsWith(TYPE_PREFIX)) delete starTypes[key];
|
|
147
|
+
});
|
|
148
|
+
typesVersions['*'] = {
|
|
149
|
+
...starTypes,
|
|
150
|
+
...generatedTypeEntries
|
|
151
|
+
};
|
|
152
|
+
packageJson.exports ??= {};
|
|
153
|
+
const packageExports = packageJson.exports;
|
|
154
|
+
const generatedExportKeys = new Set(Object.keys(exports1));
|
|
155
|
+
const exportConflicts = Object.entries(packageExports).filter(([key, value])=>{
|
|
156
|
+
if (!generatedExportKeys.has(key) && !key.startsWith(EXPORT_PREFIX)) return false;
|
|
157
|
+
const generatedValue = exports1[key];
|
|
158
|
+
if (generatedValue) return JSON.stringify(value) !== JSON.stringify(generatedValue) && !isManagedExportEntry(value);
|
|
159
|
+
return !isManagedExportEntry(value);
|
|
160
|
+
}).map(([key])=>key);
|
|
161
|
+
if (exportConflicts.length > 0) throw new Error(`[plugin-bff] package.json exports conflict on keys: ${exportConflicts.sort().join(', ')}. Rename these exports or move them outside "${EXPORT_PREFIX}" namespace.`);
|
|
162
|
+
Object.keys(packageExports).forEach((key)=>{
|
|
163
|
+
if (generatedExportKeys.has(key) || key.startsWith(EXPORT_PREFIX)) delete packageExports[key];
|
|
164
|
+
});
|
|
165
|
+
Object.assign(packageExports, exports1);
|
|
166
|
+
}
|
|
167
|
+
async function writeTargetFile(absTargetDir, content) {
|
|
168
|
+
await utils_namespaceObject.fs.mkdir(external_path_default().dirname(absTargetDir), {
|
|
169
|
+
recursive: true
|
|
170
|
+
});
|
|
171
|
+
await utils_namespaceObject.fs.writeFile(absTargetDir, content);
|
|
172
|
+
}
|
|
173
|
+
function getClientPackageName(appDirectory) {
|
|
174
|
+
const packageName = getPackageName(appDirectory) || external_path_default().basename(appDirectory);
|
|
175
|
+
if (packageName.startsWith('@') && packageName.includes('/')) {
|
|
176
|
+
const [scope, name] = packageName.split('/');
|
|
177
|
+
return `${scope}/${name}-bff-client`;
|
|
178
|
+
}
|
|
179
|
+
return `${packageName}-bff-client`;
|
|
180
|
+
}
|
|
181
|
+
async function writeClientModuleBoundary(appDirectory, relativeDistPath) {
|
|
182
|
+
await writeTargetFile(external_path_default().resolve(appDirectory, relativeDistPath, CLIENT_DIR, 'package.json'), `${JSON.stringify({
|
|
183
|
+
private: true,
|
|
184
|
+
name: getClientPackageName(appDirectory),
|
|
185
|
+
type: 'module'
|
|
186
|
+
}, null, 2)}\n`);
|
|
187
|
+
}
|
|
188
|
+
async function setPackage(files, appDirectory, relativeDistPath) {
|
|
189
|
+
const packagePath = external_path_default().resolve(appDirectory, './package.json');
|
|
190
|
+
const packageContent = await utils_namespaceObject.fs.readFile(packagePath, 'utf8');
|
|
191
|
+
const packageJson = JSON.parse(packageContent);
|
|
192
|
+
const sortedFiles = [
|
|
193
|
+
...files
|
|
194
|
+
].sort((a, b)=>a.exportKey.localeCompare(b.exportKey));
|
|
195
|
+
const addFiles = [
|
|
196
|
+
posixJoin(relativeDistPath, CLIENT_DIR, '**', '*'),
|
|
197
|
+
posixJoin(relativeDistPath, RUNTIME_DIR, '**', '*'),
|
|
198
|
+
posixJoin(relativeDistPath, PLUGIN_DIR, '**', '*')
|
|
199
|
+
];
|
|
200
|
+
const typesVersions = {
|
|
201
|
+
'*': sortedFiles.reduce((acc, file)=>{
|
|
202
|
+
const typeFilePath = toPosixPath(`./${file.targetDir}`).replace(/\.js$/, '.d.ts');
|
|
203
|
+
return {
|
|
204
|
+
...acc,
|
|
205
|
+
[toPosixPath(`${TYPE_PREFIX}${file.exportKey}`)]: [
|
|
206
|
+
typeFilePath
|
|
207
|
+
]
|
|
208
|
+
};
|
|
209
|
+
}, {
|
|
210
|
+
[`${API_DIR}/*`]: [
|
|
211
|
+
toPosixPath(`./${relativeDistPath}/${CLIENT_DIR}/*.d.ts`)
|
|
212
|
+
],
|
|
213
|
+
[RUNTIME_DIR]: [
|
|
214
|
+
toPosixPath(`./${relativeDistPath}/${RUNTIME_DIR}/index.d.ts`)
|
|
215
|
+
],
|
|
216
|
+
[PLUGIN_DIR]: [
|
|
217
|
+
toPosixPath(`./${relativeDistPath}/${PLUGIN_DIR}/index.d.ts`)
|
|
218
|
+
]
|
|
219
|
+
})
|
|
220
|
+
};
|
|
221
|
+
const exports1 = sortedFiles.reduce((acc, file)=>{
|
|
222
|
+
const exportKey = `${EXPORT_PREFIX}${file.exportKey}`;
|
|
223
|
+
const jsFilePath = toPosixPath(`./${file.targetDir}`);
|
|
224
|
+
return {
|
|
225
|
+
...acc,
|
|
226
|
+
[toPosixPath(exportKey)]: {
|
|
227
|
+
import: jsFilePath,
|
|
228
|
+
types: toPosixPath(jsFilePath.replace(/\.js$/, '.d.ts'))
|
|
229
|
+
}
|
|
230
|
+
};
|
|
231
|
+
}, {
|
|
232
|
+
[toPosixPath(`./${API_DIR}/*`)]: {
|
|
233
|
+
import: toPosixPath(`./${relativeDistPath}/${CLIENT_DIR}/*.js`),
|
|
234
|
+
types: toPosixPath(`./${relativeDistPath}/${CLIENT_DIR}/*.d.ts`)
|
|
235
|
+
},
|
|
236
|
+
[toPosixPath(`./${PLUGIN_DIR}`)]: {
|
|
237
|
+
import: toPosixPath(`./${relativeDistPath}/${PLUGIN_DIR}/index.js`),
|
|
238
|
+
require: toPosixPath(`./${relativeDistPath}/${PLUGIN_DIR}/index.js`),
|
|
239
|
+
types: toPosixPath(`./${relativeDistPath}/${PLUGIN_DIR}/index.d.ts`)
|
|
240
|
+
},
|
|
241
|
+
[toPosixPath(`./${RUNTIME_DIR}`)]: {
|
|
242
|
+
import: toPosixPath(`./${relativeDistPath}/${RUNTIME_DIR}/index.js`),
|
|
243
|
+
require: toPosixPath(`./${relativeDistPath}/${RUNTIME_DIR}/index.js`),
|
|
244
|
+
types: toPosixPath(`./${relativeDistPath}/${RUNTIME_DIR}/index.d.ts`)
|
|
245
|
+
}
|
|
246
|
+
});
|
|
247
|
+
mergePackageJson(packageJson, addFiles, typesVersions, exports1, relativeDistPath);
|
|
248
|
+
await utils_namespaceObject.fs.promises.writeFile(packagePath, JSON.stringify(packageJson, null, 2));
|
|
249
|
+
}
|
|
250
|
+
async function copyFiles(from, to) {
|
|
251
|
+
if (await utils_namespaceObject.fs.pathExists(from)) await utils_namespaceObject.fs.copy(toPosixPath(from), toPosixPath(to));
|
|
252
|
+
}
|
|
253
|
+
async function clientGenerator(draftOptions) {
|
|
254
|
+
const generatedClientDir = external_path_default().resolve(draftOptions.appDir, draftOptions.relativeDistPath, CLIENT_DIR);
|
|
255
|
+
await utils_namespaceObject.fs.remove(generatedClientDir);
|
|
256
|
+
const requestId = getPackageName(draftOptions.appDir) || process.env.npm_package_name;
|
|
257
|
+
const lambdaSourceList = draftOptions.existLambda ? await readDirectoryFiles(draftOptions.appDir, draftOptions.lambdaDir, draftOptions.relativeDistPath) : [];
|
|
258
|
+
const generatedSourceList = [
|
|
259
|
+
...lambdaSourceList
|
|
260
|
+
];
|
|
261
|
+
const getClitentCode = async (resourcePath, source)=>{
|
|
262
|
+
const warning = `The file ${resourcePath} is not allowed to be imported in src directory, only API definition files are allowed.`;
|
|
263
|
+
if (!draftOptions.existLambda) return void utils_namespaceObject.logger.warn(warning);
|
|
264
|
+
const options = {
|
|
265
|
+
prefix: Array.isArray(draftOptions.prefix) ? draftOptions.prefix[0] : draftOptions.prefix,
|
|
266
|
+
appDir: draftOptions.appDir,
|
|
267
|
+
apiDir: draftOptions.apiDir,
|
|
268
|
+
lambdaDir: draftOptions.lambdaDir,
|
|
269
|
+
port: Number(draftOptions.port),
|
|
270
|
+
source,
|
|
271
|
+
resourcePath,
|
|
272
|
+
target: 'bundle',
|
|
273
|
+
httpMethodDecider: draftOptions.httpMethodDecider,
|
|
274
|
+
requestCreator: draftOptions.requestCreator,
|
|
275
|
+
requestId
|
|
276
|
+
};
|
|
277
|
+
const { lambdaDir } = draftOptions;
|
|
278
|
+
if (!resourcePath.startsWith(lambdaDir)) return void utils_namespaceObject.logger.warn(warning);
|
|
279
|
+
const result = await (0, bff_core_namespaceObject.generateClient)(options);
|
|
280
|
+
return result;
|
|
281
|
+
};
|
|
282
|
+
try {
|
|
283
|
+
for (const source of lambdaSourceList){
|
|
284
|
+
const code = await getClitentCode(source.resourcePath, source.source);
|
|
285
|
+
if (code?.value) {
|
|
286
|
+
await writeTargetFile(source.absTargetDir, code.value);
|
|
287
|
+
await copyFiles(source.relativeTargetDistDir, source.targetDir.replace("js", 'd.ts'));
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
if ('effect' === draftOptions.bffRuntimeFramework) {
|
|
291
|
+
const effectEntryFile = (0, external_effectClientGenerator_js_namespaceObject.resolveEffectEntryFile)({
|
|
292
|
+
appDir: draftOptions.appDir,
|
|
293
|
+
apiDir: draftOptions.apiDir,
|
|
294
|
+
effectEntry: draftOptions.effectEntry
|
|
295
|
+
});
|
|
296
|
+
if (effectEntryFile) {
|
|
297
|
+
const effectSource = await utils_namespaceObject.fs.readFile(effectEntryFile, 'utf8');
|
|
298
|
+
const effectFileDetails = createFileDetails({
|
|
299
|
+
appDirectory: draftOptions.appDir,
|
|
300
|
+
baseDirectory: draftOptions.apiDir,
|
|
301
|
+
resourcePath: effectEntryFile,
|
|
302
|
+
source: effectSource,
|
|
303
|
+
relativeDistPath: draftOptions.relativeDistPath
|
|
304
|
+
});
|
|
305
|
+
const effectClientCode = await (0, external_effectClientGenerator_js_namespaceObject.generateEffectClientCode)({
|
|
306
|
+
appDir: draftOptions.appDir,
|
|
307
|
+
apiDir: draftOptions.apiDir,
|
|
308
|
+
resourcePath: effectEntryFile,
|
|
309
|
+
prefix: Array.isArray(draftOptions.prefix) ? draftOptions.prefix[0] : draftOptions.prefix,
|
|
310
|
+
port: Number(draftOptions.port),
|
|
311
|
+
target: 'bundle',
|
|
312
|
+
requestCreator: draftOptions.requestCreator,
|
|
313
|
+
httpMethodDecider: draftOptions.httpMethodDecider,
|
|
314
|
+
dataPlatformBatch: draftOptions.effectDataPlatformBatch
|
|
315
|
+
});
|
|
316
|
+
if (effectClientCode) {
|
|
317
|
+
const targetTypeFile = effectFileDetails.targetDir.replace(/\.js$/, '.d.ts');
|
|
318
|
+
await writeTargetFile(effectFileDetails.absTargetDir, effectClientCode);
|
|
319
|
+
await writeTargetFile(external_path_default().resolve(targetTypeFile), (0, external_effectClientGenerator_js_namespaceObject.renderEffectClientDeclaration)());
|
|
320
|
+
generatedSourceList.push(effectFileDetails);
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
utils_namespaceObject.logger.info("Client bundle generate succeed");
|
|
325
|
+
} catch (error) {
|
|
326
|
+
utils_namespaceObject.logger.error(`Client bundle generate failed: ${error}`);
|
|
327
|
+
}
|
|
328
|
+
if (generatedSourceList.length > 0) await writeClientModuleBoundary(draftOptions.appDir, draftOptions.relativeDistPath);
|
|
329
|
+
await setPackage(generatedSourceList, draftOptions.appDir, draftOptions.relativeDistPath);
|
|
330
|
+
}
|
|
331
|
+
const utils_clientGenerator = clientGenerator;
|
|
332
|
+
exports.copyFiles = __webpack_exports__.copyFiles;
|
|
333
|
+
exports["default"] = __webpack_exports__["default"];
|
|
334
|
+
exports.readDirectoryFiles = __webpack_exports__.readDirectoryFiles;
|
|
335
|
+
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
336
|
+
"copyFiles",
|
|
337
|
+
"default",
|
|
338
|
+
"readDirectoryFiles"
|
|
339
|
+
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
340
|
+
Object.defineProperty(exports, '__esModule', {
|
|
341
|
+
value: true
|
|
342
|
+
});
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
"use strict";
|
|
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
|
+
(()=>{
|
|
13
|
+
__webpack_require__.d = (exports1, definition)=>{
|
|
14
|
+
for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
|
|
15
|
+
enumerable: true,
|
|
16
|
+
get: definition[key]
|
|
17
|
+
});
|
|
18
|
+
};
|
|
19
|
+
})();
|
|
20
|
+
(()=>{
|
|
21
|
+
__webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
|
|
22
|
+
})();
|
|
23
|
+
(()=>{
|
|
24
|
+
__webpack_require__.r = (exports1)=>{
|
|
25
|
+
if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
|
|
26
|
+
value: 'Module'
|
|
27
|
+
});
|
|
28
|
+
Object.defineProperty(exports1, '__esModule', {
|
|
29
|
+
value: true
|
|
30
|
+
});
|
|
31
|
+
};
|
|
32
|
+
})();
|
|
33
|
+
var __webpack_exports__ = {};
|
|
34
|
+
__webpack_require__.r(__webpack_exports__);
|
|
35
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
36
|
+
createHonoHandler: ()=>createHonoHandler,
|
|
37
|
+
default: ()=>utils_createHonoRoutes
|
|
38
|
+
});
|
|
39
|
+
const bff_core_namespaceObject = require("@modern-js/bff-core");
|
|
40
|
+
const external_qs_namespaceObject = require("qs");
|
|
41
|
+
const external_type_is_namespaceObject = require("type-is");
|
|
42
|
+
var external_type_is_default = /*#__PURE__*/ __webpack_require__.n(external_type_is_namespaceObject);
|
|
43
|
+
const createHonoRoutes = (handlerInfos = [])=>handlerInfos.map(({ routePath, handler, httpMethod })=>{
|
|
44
|
+
const routeMiddlwares = Reflect.getMetadata('middleware', handler) || [];
|
|
45
|
+
const honoHandler = createHonoHandler(handler);
|
|
46
|
+
return {
|
|
47
|
+
method: httpMethod.toLowerCase(),
|
|
48
|
+
path: routePath,
|
|
49
|
+
handler: routeMiddlwares.length > 0 ? [
|
|
50
|
+
...routeMiddlwares,
|
|
51
|
+
honoHandler
|
|
52
|
+
] : honoHandler
|
|
53
|
+
};
|
|
54
|
+
});
|
|
55
|
+
const handleResponseMeta = (c, handler)=>{
|
|
56
|
+
const responseMeta = Reflect.getMetadata(bff_core_namespaceObject.HttpMetadata.Response, handler);
|
|
57
|
+
if (Array.isArray(responseMeta)) for (const meta of responseMeta)switch(meta.type){
|
|
58
|
+
case bff_core_namespaceObject.ResponseMetaType.Headers:
|
|
59
|
+
for (const [key, value] of Object.entries(meta.value))c.header(key, value);
|
|
60
|
+
break;
|
|
61
|
+
case bff_core_namespaceObject.ResponseMetaType.Redirect:
|
|
62
|
+
return c.redirect(meta.value);
|
|
63
|
+
case bff_core_namespaceObject.ResponseMetaType.StatusCode:
|
|
64
|
+
c.status(meta.value);
|
|
65
|
+
break;
|
|
66
|
+
default:
|
|
67
|
+
break;
|
|
68
|
+
}
|
|
69
|
+
return null;
|
|
70
|
+
};
|
|
71
|
+
const createHonoHandler = (handler)=>async (c)=>{
|
|
72
|
+
const input = await getHonoInput(c);
|
|
73
|
+
if ((0, bff_core_namespaceObject.isWithMetaHandler)(handler)) try {
|
|
74
|
+
const response = handleResponseMeta(c, handler);
|
|
75
|
+
if (response) return response;
|
|
76
|
+
if (c.finalized) return;
|
|
77
|
+
const result = await handler(input);
|
|
78
|
+
if (result instanceof Response) return result;
|
|
79
|
+
return result && 'object' == typeof result ? c.json(result) : c.body(result);
|
|
80
|
+
} catch (error) {
|
|
81
|
+
if (error instanceof bff_core_namespaceObject.ValidationError) {
|
|
82
|
+
c.status(error.status);
|
|
83
|
+
return c.json({
|
|
84
|
+
message: error.message
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
throw error;
|
|
88
|
+
}
|
|
89
|
+
{
|
|
90
|
+
const routePath = c.req.routePath;
|
|
91
|
+
const paramNames = routePath.match(/:\w+/g)?.map((s)=>s.slice(1)) || [];
|
|
92
|
+
const params = Object.fromEntries(paramNames.map((name)=>[
|
|
93
|
+
name,
|
|
94
|
+
input.params[name]
|
|
95
|
+
]));
|
|
96
|
+
const args = Object.values(params).concat(input);
|
|
97
|
+
const body = await handler(...args);
|
|
98
|
+
if (c.finalized) return await Promise.resolve();
|
|
99
|
+
if (void 0 !== body) {
|
|
100
|
+
if (body instanceof Response) return body;
|
|
101
|
+
return c.json(body);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
};
|
|
105
|
+
const getHonoInput = async (c)=>{
|
|
106
|
+
const draft = {
|
|
107
|
+
params: c.req.param(),
|
|
108
|
+
query: (0, external_qs_namespaceObject.parse)(c.req.query()),
|
|
109
|
+
headers: c.req.header(),
|
|
110
|
+
cookies: c.req.header('cookie')
|
|
111
|
+
};
|
|
112
|
+
try {
|
|
113
|
+
const contentType = c.req.header('content-type') || '';
|
|
114
|
+
if (external_type_is_default().is(contentType, [
|
|
115
|
+
'application/json'
|
|
116
|
+
])) draft.data = await c.req.json();
|
|
117
|
+
else if (external_type_is_default().is(contentType, [
|
|
118
|
+
'multipart/form-data'
|
|
119
|
+
])) draft.formData = await c.req.parseBody();
|
|
120
|
+
else if (external_type_is_default().is(contentType, [
|
|
121
|
+
'application/x-www-form-urlencoded'
|
|
122
|
+
])) draft.formUrlencoded = await c.req.parseBody();
|
|
123
|
+
else draft.body = await c.req.json();
|
|
124
|
+
} catch (error) {
|
|
125
|
+
draft.body = null;
|
|
126
|
+
}
|
|
127
|
+
return draft;
|
|
128
|
+
};
|
|
129
|
+
const utils_createHonoRoutes = createHonoRoutes;
|
|
130
|
+
exports.createHonoHandler = __webpack_exports__.createHonoHandler;
|
|
131
|
+
exports["default"] = __webpack_exports__["default"];
|
|
132
|
+
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
133
|
+
"createHonoHandler",
|
|
134
|
+
"default"
|
|
135
|
+
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
136
|
+
Object.defineProperty(exports, '__esModule', {
|
|
137
|
+
value: true
|
|
138
|
+
});
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
"use strict";
|
|
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
|
+
(()=>{
|
|
13
|
+
__webpack_require__.d = (exports1, definition)=>{
|
|
14
|
+
for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
|
|
15
|
+
enumerable: true,
|
|
16
|
+
get: definition[key]
|
|
17
|
+
});
|
|
18
|
+
};
|
|
19
|
+
})();
|
|
20
|
+
(()=>{
|
|
21
|
+
__webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
|
|
22
|
+
})();
|
|
23
|
+
(()=>{
|
|
24
|
+
__webpack_require__.r = (exports1)=>{
|
|
25
|
+
if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
|
|
26
|
+
value: 'Module'
|
|
27
|
+
});
|
|
28
|
+
Object.defineProperty(exports1, '__esModule', {
|
|
29
|
+
value: true
|
|
30
|
+
});
|
|
31
|
+
};
|
|
32
|
+
})();
|
|
33
|
+
var __webpack_exports__ = {};
|
|
34
|
+
__webpack_require__.r(__webpack_exports__);
|
|
35
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
36
|
+
API_DIR: ()=>API_DIR,
|
|
37
|
+
DIST_DIR: ()=>DIST_DIR,
|
|
38
|
+
LAMBDA_DIR: ()=>LAMBDA_DIR,
|
|
39
|
+
PACKAGE_NAME: ()=>PACKAGE_NAME,
|
|
40
|
+
PREFIX: ()=>PREFIX,
|
|
41
|
+
RUNTIME_FRAMEWORK: ()=>RUNTIME_FRAMEWORK,
|
|
42
|
+
crossProjectApiPlugin: ()=>crossProjectApiPlugin,
|
|
43
|
+
default: ()=>utils_crossProjectApiPlugin
|
|
44
|
+
});
|
|
45
|
+
const external_path_namespaceObject = require("path");
|
|
46
|
+
var external_path_default = /*#__PURE__*/ __webpack_require__.n(external_path_namespaceObject);
|
|
47
|
+
const PACKAGE_NAME = '{packageName}';
|
|
48
|
+
const PREFIX = '{prefix}';
|
|
49
|
+
const API_DIR = '{apiDirectory}';
|
|
50
|
+
const LAMBDA_DIR = '{lambdaDirectory}';
|
|
51
|
+
const DIST_DIR = '{distDirectory}';
|
|
52
|
+
const RUNTIME_FRAMEWORK = '{runtimeFramework}';
|
|
53
|
+
const NODE_MODULES = 'node_modules';
|
|
54
|
+
const crossProjectApiPlugin = ()=>({
|
|
55
|
+
name: '@modern-js/plugin-independent-bff',
|
|
56
|
+
post: [
|
|
57
|
+
'@modern-js/plugin-bff'
|
|
58
|
+
],
|
|
59
|
+
setup: (api)=>{
|
|
60
|
+
api.modifyResolvedConfig((resolvedConfig)=>{
|
|
61
|
+
const { appDirectory: originAppDirectory } = api.getAppContext();
|
|
62
|
+
const sdkPath = external_path_default().join(originAppDirectory, NODE_MODULES, PACKAGE_NAME);
|
|
63
|
+
const sdkDistPath = external_path_default().join(sdkPath, DIST_DIR);
|
|
64
|
+
const apiDirectory = external_path_default().join(sdkDistPath, API_DIR);
|
|
65
|
+
const lambdaDirectory = external_path_default().resolve(sdkDistPath, LAMBDA_DIR);
|
|
66
|
+
api.updateAppContext({
|
|
67
|
+
apiDirectory,
|
|
68
|
+
lambdaDirectory,
|
|
69
|
+
bffRuntimeFramework: RUNTIME_FRAMEWORK
|
|
70
|
+
});
|
|
71
|
+
const config = api.getConfig();
|
|
72
|
+
const configuredPrefix = config?.bff?.prefix;
|
|
73
|
+
if (configuredPrefix) {
|
|
74
|
+
const isSamePrefix = Array.isArray(configuredPrefix) ? 1 === configuredPrefix.length && configuredPrefix[0] === PREFIX : configuredPrefix === PREFIX;
|
|
75
|
+
if (!isSamePrefix) throw new Error(`[${PACKAGE_NAME}] Invalid bff.prefix for cross-project BFF. Detected "${configuredPrefix}", expected "${PREFIX}". Remove bff.prefix from the consumer app, or set it exactly to "${PREFIX}".`);
|
|
76
|
+
}
|
|
77
|
+
const configuredRuntimeFramework = config?.bff?.runtimeFramework;
|
|
78
|
+
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}".`);
|
|
79
|
+
resolvedConfig.bff.prefix = PREFIX;
|
|
80
|
+
resolvedConfig.bff.runtimeFramework = RUNTIME_FRAMEWORK;
|
|
81
|
+
resolvedConfig.bff.isCrossProjectServer = true;
|
|
82
|
+
resolvedConfig.bff.requestId = resolvedConfig.bff.requestId || config?.bff?.requestId || PACKAGE_NAME || 'default';
|
|
83
|
+
resolvedConfig.bff.crossProjectPolicy = {
|
|
84
|
+
...resolvedConfig.bff.crossProjectPolicy || {},
|
|
85
|
+
enabled: resolvedConfig.bff.crossProjectPolicy?.enabled ?? true,
|
|
86
|
+
requireEnvelope: resolvedConfig.bff.crossProjectPolicy?.requireEnvelope ?? true,
|
|
87
|
+
requireOperationContext: resolvedConfig.bff.crossProjectPolicy?.requireOperationContext ?? true,
|
|
88
|
+
requireOperationContextDetails: resolvedConfig.bff.crossProjectPolicy?.requireOperationContextDetails ?? true,
|
|
89
|
+
requireOperationSchemaHash: resolvedConfig.bff.crossProjectPolicy?.requireOperationSchemaHash ?? true,
|
|
90
|
+
requireOperationVersion: resolvedConfig.bff.crossProjectPolicy?.requireOperationVersion ?? true,
|
|
91
|
+
allowUnknownOperations: resolvedConfig.bff.crossProjectPolicy?.allowUnknownOperations ?? false
|
|
92
|
+
};
|
|
93
|
+
return resolvedConfig;
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
});
|
|
97
|
+
const utils_crossProjectApiPlugin = crossProjectApiPlugin;
|
|
98
|
+
exports.API_DIR = __webpack_exports__.API_DIR;
|
|
99
|
+
exports.DIST_DIR = __webpack_exports__.DIST_DIR;
|
|
100
|
+
exports.LAMBDA_DIR = __webpack_exports__.LAMBDA_DIR;
|
|
101
|
+
exports.PACKAGE_NAME = __webpack_exports__.PACKAGE_NAME;
|
|
102
|
+
exports.PREFIX = __webpack_exports__.PREFIX;
|
|
103
|
+
exports.RUNTIME_FRAMEWORK = __webpack_exports__.RUNTIME_FRAMEWORK;
|
|
104
|
+
exports.crossProjectApiPlugin = __webpack_exports__.crossProjectApiPlugin;
|
|
105
|
+
exports["default"] = __webpack_exports__["default"];
|
|
106
|
+
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
107
|
+
"API_DIR",
|
|
108
|
+
"DIST_DIR",
|
|
109
|
+
"LAMBDA_DIR",
|
|
110
|
+
"PACKAGE_NAME",
|
|
111
|
+
"PREFIX",
|
|
112
|
+
"RUNTIME_FRAMEWORK",
|
|
113
|
+
"crossProjectApiPlugin",
|
|
114
|
+
"default"
|
|
115
|
+
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
116
|
+
Object.defineProperty(exports, '__esModule', {
|
|
117
|
+
value: true
|
|
118
|
+
});
|