@bleedingdev/modern-js-plugin-bff 3.5.0-ultramodern.98 → 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/endpoint-contracts.js +6 -1
- package/dist/cjs/runtime/effect/handler/definition.js +1 -0
- package/dist/cjs/runtime/effect/handler/http.js +17 -6
- package/dist/cjs/runtime/hono/adapter.js +32 -79
- package/dist/cjs/server.js +19 -30
- package/dist/cjs/utils/client-generator/write-package.js +1 -1
- 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/endpoint-contracts.mjs +6 -1
- package/dist/esm/runtime/effect/handler/definition.mjs +1 -0
- package/dist/esm/runtime/effect/handler/http.mjs +17 -6
- package/dist/esm/runtime/hono/adapter.mjs +33 -80
- package/dist/esm/server.mjs +18 -29
- package/dist/esm/utils/client-generator/write-package.mjs +1 -1
- 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/endpoint-contracts.mjs +6 -1
- 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/runtime/hono/adapter.mjs +33 -80
- package/dist/esm-node/server.mjs +18 -29
- package/dist/esm-node/utils/client-generator/write-package.mjs +1 -1
- 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/endpoint-contracts.d.ts +6 -0
- package/dist/types/runtime/effect/handler/definition.d.ts +2 -12
- package/dist/types/runtime/effect/handler/http.d.ts +3 -2
- package/dist/types/runtime/effect/handler/openapi.d.ts +1 -1
- package/dist/types/runtime/effect/handler/types.d.ts +10 -5
- package/dist/types/runtime/effect-client/index.d.ts +1 -1
- package/dist/types/runtime/hono/adapter.d.ts +14 -8
- 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 +44 -16
|
@@ -39,7 +39,6 @@ __webpack_require__.r(__webpack_exports__);
|
|
|
39
39
|
__webpack_require__.d(__webpack_exports__, {
|
|
40
40
|
HonoAdapter: ()=>HonoAdapter
|
|
41
41
|
});
|
|
42
|
-
const server_core_namespaceObject = require("@modern-js/server-core");
|
|
43
42
|
const utils_namespaceObject = require("@modern-js/utils");
|
|
44
43
|
const createHonoRoutes_js_namespaceObject = require("../../utils/createHonoRoutes.js");
|
|
45
44
|
var createHonoRoutes_js_default = /*#__PURE__*/ __webpack_require__.n(createHonoRoutes_js_namespaceObject);
|
|
@@ -50,17 +49,9 @@ const before = [
|
|
|
50
49
|
'custom-server-middleware',
|
|
51
50
|
'render'
|
|
52
51
|
];
|
|
53
|
-
const kParentHonoVars = Symbol.for('modernjs.hono.parentVars');
|
|
54
52
|
class HonoAdapter {
|
|
55
|
-
wrapInArray(handler) {
|
|
56
|
-
if (Array.isArray(handler)) return handler;
|
|
57
|
-
return [
|
|
58
|
-
handler
|
|
59
|
-
];
|
|
60
|
-
}
|
|
61
53
|
constructor(api){
|
|
62
54
|
this.apiMiddleware = [];
|
|
63
|
-
this.apiServer = null;
|
|
64
55
|
this.isHono = true;
|
|
65
56
|
this.prefix = '/api';
|
|
66
57
|
this.setHandlers = async ()=>{
|
|
@@ -71,7 +62,7 @@ class HonoAdapter {
|
|
|
71
62
|
name: 'hono-bff-api',
|
|
72
63
|
path,
|
|
73
64
|
method,
|
|
74
|
-
handler,
|
|
65
|
+
handler: this.withErrorBoundary(handler),
|
|
75
66
|
order: 'post',
|
|
76
67
|
before
|
|
77
68
|
}));
|
|
@@ -92,85 +83,47 @@ class HonoAdapter {
|
|
|
92
83
|
});
|
|
93
84
|
}
|
|
94
85
|
};
|
|
95
|
-
this.
|
|
96
|
-
if (!this.isHono) return;
|
|
97
|
-
this.apiServer = new server_core_namespaceObject.Hono();
|
|
98
|
-
this.apiServer.use('*', server_core_namespaceObject.run);
|
|
99
|
-
this.apiServer.use('*', async (c, next)=>{
|
|
100
|
-
const nodeReq = c.env?.node?.req;
|
|
101
|
-
const parentVars = nodeReq?.[kParentHonoVars];
|
|
102
|
-
if (parentVars && 'object' == typeof parentVars) {
|
|
103
|
-
delete nodeReq[kParentHonoVars];
|
|
104
|
-
for (const [key, value] of Object.entries(parentVars))if (void 0 === c.get(key)) c.set(key, value);
|
|
105
|
-
}
|
|
106
|
-
await next();
|
|
107
|
-
});
|
|
108
|
-
this.apiMiddleware.forEach(({ path = '*', method = 'all', handler })=>{
|
|
109
|
-
const handlers = this.wrapInArray(handler);
|
|
110
|
-
if (0 === handlers.length) return;
|
|
111
|
-
const firstHandler = handlers[0];
|
|
112
|
-
const restHandlers = handlers.slice(1);
|
|
113
|
-
const m = method;
|
|
114
|
-
const server = this.apiServer;
|
|
115
|
-
if (!server) return;
|
|
116
|
-
const register = server[m];
|
|
117
|
-
register.call(server, path, firstHandler, ...restHandlers);
|
|
118
|
-
});
|
|
119
|
-
this.apiServer.onError(async (err, c)=>{
|
|
120
|
-
try {
|
|
121
|
-
const serverConfig = this.api.getServerConfig();
|
|
122
|
-
const onErrorHandler = serverConfig?.onError;
|
|
123
|
-
if (onErrorHandler) {
|
|
124
|
-
const result = await onErrorHandler(err, c);
|
|
125
|
-
if (result instanceof Response) return result;
|
|
126
|
-
} else utils_namespaceObject.logger.error(err);
|
|
127
|
-
} catch (configError) {
|
|
128
|
-
utils_namespaceObject.logger.error(`Error in serverConfig.onError handler: ${configError}`);
|
|
129
|
-
}
|
|
130
|
-
return (0, external_safe_failure_js_namespaceObject.createSafeFailureResponse)(err);
|
|
131
|
-
});
|
|
132
|
-
};
|
|
133
|
-
this.registerMiddleware = async (options)=>{
|
|
134
|
-
const { prefix } = options;
|
|
86
|
+
this.registerMiddleware = async (options = {})=>{
|
|
135
87
|
const { bffRuntimeFramework } = this.api.getServerContext();
|
|
136
88
|
if ('hono' !== bffRuntimeFramework) {
|
|
137
89
|
this.isHono = false;
|
|
138
90
|
return;
|
|
139
91
|
}
|
|
92
|
+
const { prefix } = options;
|
|
140
93
|
this.prefix = prefix || this.prefix;
|
|
141
94
|
const { middlewares: globalMiddlewares } = this.api.getServerContext();
|
|
142
95
|
await this.setHandlers();
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
const nodeReq = c.env?.node?.req;
|
|
155
|
-
if (nodeReq) {
|
|
156
|
-
const parentVars = c?.var;
|
|
157
|
-
nodeReq[kParentHonoVars] = parentVars && 'object' == typeof parentVars ? {
|
|
158
|
-
...parentVars
|
|
159
|
-
} : parentVars;
|
|
160
|
-
}
|
|
161
|
-
const response = await this.apiServer.fetch(c.req.raw, c.env);
|
|
162
|
-
if (404 !== response.status) return new Response(response.body, response);
|
|
163
|
-
}
|
|
164
|
-
await next();
|
|
165
|
-
}
|
|
166
|
-
};
|
|
167
|
-
globalMiddlewares.push(dynamicApiMiddleware);
|
|
96
|
+
globalMiddlewares.push(...this.apiMiddleware);
|
|
97
|
+
};
|
|
98
|
+
this.handleRouteError = async (error, c)=>{
|
|
99
|
+
try {
|
|
100
|
+
const onErrorHandler = this.api.getServerConfig()?.onError;
|
|
101
|
+
if (onErrorHandler) {
|
|
102
|
+
const result = await onErrorHandler(error, c);
|
|
103
|
+
if (result instanceof Response) return result;
|
|
104
|
+
} else utils_namespaceObject.logger.error(error);
|
|
105
|
+
} catch (configError) {
|
|
106
|
+
utils_namespaceObject.logger.error(`Error in serverConfig.onError handler: ${configError}`);
|
|
168
107
|
}
|
|
108
|
+
return (0, external_safe_failure_js_namespaceObject.createSafeFailureResponse)(error);
|
|
169
109
|
};
|
|
170
|
-
this.
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
110
|
+
this.withErrorBoundary = (handler)=>{
|
|
111
|
+
const handlers = Array.isArray(handler) ? handler : [
|
|
112
|
+
handler
|
|
113
|
+
];
|
|
114
|
+
const [firstHandler, ...restHandlers] = handlers;
|
|
115
|
+
if (!firstHandler) return handler;
|
|
116
|
+
const boundary = async (c, next)=>{
|
|
117
|
+
try {
|
|
118
|
+
return await firstHandler(c, next);
|
|
119
|
+
} catch (error) {
|
|
120
|
+
return this.handleRouteError(error, c);
|
|
121
|
+
}
|
|
122
|
+
};
|
|
123
|
+
return Array.isArray(handler) ? [
|
|
124
|
+
boundary,
|
|
125
|
+
...restHandlers
|
|
126
|
+
] : boundary;
|
|
174
127
|
};
|
|
175
128
|
this.api = api;
|
|
176
129
|
}
|
package/dist/cjs/server.js
CHANGED
|
@@ -43,15 +43,17 @@ const bff_core_namespaceObject = require("@modern-js/bff-core");
|
|
|
43
43
|
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
|
-
const adapter_js_namespaceObject = require("./runtime/
|
|
47
|
-
const
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
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("./runtime/effect/adapter.js");
|
|
53
|
+
return [
|
|
54
|
+
new EffectAdapter(api)
|
|
55
|
+
];
|
|
56
|
+
}
|
|
55
57
|
};
|
|
56
58
|
const normalizePrefixList = (prefix)=>{
|
|
57
59
|
if (Array.isArray(prefix)) return prefix.filter(Boolean);
|
|
@@ -64,9 +66,6 @@ function resolveRuntimeFramework(runtimeFramework) {
|
|
|
64
66
|
return 'hono' === runtimeFramework ? 'hono' : 'effect';
|
|
65
67
|
}
|
|
66
68
|
class Storage {
|
|
67
|
-
reset() {
|
|
68
|
-
this.middlewares = [];
|
|
69
|
-
}
|
|
70
69
|
constructor(){
|
|
71
70
|
this.middlewares = [];
|
|
72
71
|
}
|
|
@@ -78,7 +77,6 @@ const server = ()=>({
|
|
|
78
77
|
let apiRouter = null;
|
|
79
78
|
const appContext = api.getServerContext();
|
|
80
79
|
const runtimeFramework = resolveRuntimeFramework(appContext.bffRuntimeFramework);
|
|
81
|
-
const runtimeAdapters = RUNTIME_ADAPTER_FACTORIES[runtimeFramework].map((createAdapter)=>createAdapter(api));
|
|
82
80
|
api.onPrepare(async ()=>{
|
|
83
81
|
const appContext = api.getServerContext();
|
|
84
82
|
const { render } = appContext;
|
|
@@ -124,29 +122,20 @@ const server = ()=>({
|
|
|
124
122
|
]
|
|
125
123
|
});
|
|
126
124
|
}
|
|
125
|
+
const runtimeAdapters = await RUNTIME_ADAPTER_LOADERS[runtimeFramework](api);
|
|
127
126
|
await Promise.all(runtimeAdapters.map((adapter)=>adapter.registerMiddleware({
|
|
128
127
|
prefix,
|
|
129
128
|
enableHandleWeb
|
|
130
129
|
})));
|
|
131
130
|
});
|
|
132
131
|
api.onReset(async ({ event })=>{
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
if ('file-change' === event.type) {
|
|
141
|
-
if ('hono' === runtimeFramework && apiRouter) {
|
|
142
|
-
const apiHandlerInfos = await apiRouter.getApiHandlers();
|
|
143
|
-
const appContext = api.getServerContext();
|
|
144
|
-
api.updateServerContext({
|
|
145
|
-
...appContext,
|
|
146
|
-
apiHandlerInfos
|
|
147
|
-
});
|
|
148
|
-
}
|
|
149
|
-
await Promise.all(runtimeAdapters.map((adapter)=>adapter.onApiHandlersUpdated?.()));
|
|
132
|
+
if ('file-change' === event.type && apiRouter) {
|
|
133
|
+
const appContext = api.getServerContext();
|
|
134
|
+
const apiHandlerInfos = await apiRouter.getApiHandlers();
|
|
135
|
+
api.updateServerContext({
|
|
136
|
+
...appContext,
|
|
137
|
+
apiHandlerInfos
|
|
138
|
+
});
|
|
150
139
|
}
|
|
151
140
|
});
|
|
152
141
|
const prepareApiServer = async (input, next)=>{
|
|
@@ -112,7 +112,7 @@ async function setPackage(files, appDirectory, relativeDistPath) {
|
|
|
112
112
|
}
|
|
113
113
|
});
|
|
114
114
|
(0, external_package_json_js_namespaceObject.mergePackageJson)(packageJson, addFiles, typesVersions, exports1, relativeDistPath);
|
|
115
|
-
await utils_namespaceObject.fs.promises.writeFile(packagePath, JSON.stringify(packageJson, null, 2));
|
|
115
|
+
await utils_namespaceObject.fs.promises.writeFile(packagePath, `${JSON.stringify(packageJson, null, 2)}\n`);
|
|
116
116
|
}
|
|
117
117
|
exports.setPackage = __webpack_exports__.setPackage;
|
|
118
118
|
exports.writeClientModuleBoundary = __webpack_exports__.writeClientModuleBoundary;
|
|
@@ -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;
|