@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,178 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __webpack_require__ = {};
|
|
3
|
+
(()=>{
|
|
4
|
+
__webpack_require__.d = (exports1, definition)=>{
|
|
5
|
+
for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: definition[key]
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
})();
|
|
11
|
+
(()=>{
|
|
12
|
+
__webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
|
|
13
|
+
})();
|
|
14
|
+
(()=>{
|
|
15
|
+
__webpack_require__.r = (exports1)=>{
|
|
16
|
+
if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
|
|
17
|
+
value: 'Module'
|
|
18
|
+
});
|
|
19
|
+
Object.defineProperty(exports1, '__esModule', {
|
|
20
|
+
value: true
|
|
21
|
+
});
|
|
22
|
+
};
|
|
23
|
+
})();
|
|
24
|
+
var __webpack_exports__ = {};
|
|
25
|
+
__webpack_require__.r(__webpack_exports__);
|
|
26
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
27
|
+
Effect: ()=>Effect_namespaceObject,
|
|
28
|
+
HttpApi: ()=>httpapi_namespaceObject.HttpApi,
|
|
29
|
+
HttpApiClient: ()=>httpapi_namespaceObject.HttpApiClient,
|
|
30
|
+
HttpApiEndpoint: ()=>httpapi_namespaceObject.HttpApiEndpoint,
|
|
31
|
+
HttpApiGroup: ()=>httpapi_namespaceObject.HttpApiGroup,
|
|
32
|
+
HttpApiSchema: ()=>httpapi_namespaceObject.HttpApiSchema,
|
|
33
|
+
Layer: ()=>Layer_namespaceObject,
|
|
34
|
+
Rpc: ()=>rpc_namespaceObject.Rpc,
|
|
35
|
+
RpcClient: ()=>rpc_namespaceObject.RpcClient,
|
|
36
|
+
RpcGroup: ()=>rpc_namespaceObject.RpcGroup,
|
|
37
|
+
RpcSchema: ()=>rpc_namespaceObject.RpcSchema,
|
|
38
|
+
RpcSerialization: ()=>rpc_namespaceObject.RpcSerialization,
|
|
39
|
+
Schema: ()=>Schema_namespaceObject,
|
|
40
|
+
makeEffectHttpApiClient: ()=>makeEffectHttpApiClient,
|
|
41
|
+
makeEffectRpcClient: ()=>makeEffectRpcClient,
|
|
42
|
+
mask: ()=>mask,
|
|
43
|
+
runEffectRequest: ()=>runEffectRequest,
|
|
44
|
+
runEffectView: ()=>runEffectView,
|
|
45
|
+
view: ()=>view
|
|
46
|
+
});
|
|
47
|
+
const Effect_namespaceObject = require("effect/Effect");
|
|
48
|
+
const Exit_namespaceObject = require("effect/Exit");
|
|
49
|
+
const Layer_namespaceObject = require("effect/Layer");
|
|
50
|
+
const ManagedRuntime_namespaceObject = require("effect/ManagedRuntime");
|
|
51
|
+
const Scope_namespaceObject = require("effect/Scope");
|
|
52
|
+
const http_namespaceObject = require("effect/unstable/http");
|
|
53
|
+
const httpapi_namespaceObject = require("effect/unstable/httpapi");
|
|
54
|
+
const rpc_namespaceObject = require("effect/unstable/rpc");
|
|
55
|
+
const Schema_namespaceObject = require("effect/Schema");
|
|
56
|
+
function isRecord(value) {
|
|
57
|
+
return 'object' == typeof value && null !== value && !Array.isArray(value);
|
|
58
|
+
}
|
|
59
|
+
function applySelection(value, selection) {
|
|
60
|
+
if (true === selection || void 0 === selection) return value;
|
|
61
|
+
if (Array.isArray(value)) return value.map((item)=>applySelection(item, selection));
|
|
62
|
+
if (!isRecord(value) || !isRecord(selection)) return value;
|
|
63
|
+
const masked = {};
|
|
64
|
+
for (const key of Object.keys(selection))if (key in value) masked[key] = applySelection(value[key], selection[key]);
|
|
65
|
+
return masked;
|
|
66
|
+
}
|
|
67
|
+
function view() {
|
|
68
|
+
return (selection)=>selection;
|
|
69
|
+
}
|
|
70
|
+
function mask(value, selection) {
|
|
71
|
+
return applySelection(value, selection);
|
|
72
|
+
}
|
|
73
|
+
function runEffectView(request, selection) {
|
|
74
|
+
return new Promise((resolve, reject)=>{
|
|
75
|
+
request.then((value)=>resolve(mask(value, selection)), (reason)=>reject(reason));
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
function getRpcSerializationLayer(serialization) {
|
|
79
|
+
switch(serialization){
|
|
80
|
+
case 'ndjson':
|
|
81
|
+
return rpc_namespaceObject.RpcSerialization.layerNdjson;
|
|
82
|
+
case 'jsonRpc':
|
|
83
|
+
return rpc_namespaceObject.RpcSerialization.layerJsonRpc();
|
|
84
|
+
case 'ndJsonRpc':
|
|
85
|
+
return rpc_namespaceObject.RpcSerialization.layerNdJsonRpc();
|
|
86
|
+
case 'msgPack':
|
|
87
|
+
return rpc_namespaceObject.RpcSerialization.layerMsgPack;
|
|
88
|
+
default:
|
|
89
|
+
return rpc_namespaceObject.RpcSerialization.layerJsonRpc();
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
function makeEffectHttpApiClient(api, options) {
|
|
93
|
+
return httpapi_namespaceObject.HttpApiClient.make(api, {
|
|
94
|
+
baseUrl: options?.baseUrl
|
|
95
|
+
}).pipe(Effect_namespaceObject.provide(http_namespaceObject.FetchHttpClient.layer));
|
|
96
|
+
}
|
|
97
|
+
function makeEffectRpcClient(group, options) {
|
|
98
|
+
const protocolLayer = Layer_namespaceObject.provide(rpc_namespaceObject.RpcClient.layerProtocolHttp({
|
|
99
|
+
url: options.url
|
|
100
|
+
}), Layer_namespaceObject.mergeAll(getRpcSerializationLayer(options.serialization), http_namespaceObject.FetchHttpClient.layer));
|
|
101
|
+
const middlewareLayer = options.middlewareLayer ?? Layer_namespaceObject.empty;
|
|
102
|
+
const runtimeLayer = Layer_namespaceObject.mergeAll(protocolLayer, middlewareLayer);
|
|
103
|
+
return Effect_namespaceObject.tryPromise({
|
|
104
|
+
try: async ()=>{
|
|
105
|
+
const runtime = ManagedRuntime_namespaceObject.make(runtimeLayer);
|
|
106
|
+
const scope = await runtime.runPromise(Scope_namespaceObject.make());
|
|
107
|
+
try {
|
|
108
|
+
const client = await runtime.runPromise(rpc_namespaceObject.RpcClient.make(group, {
|
|
109
|
+
flatten: options.flatten
|
|
110
|
+
}).pipe(Effect_namespaceObject.provideService(Scope_namespaceObject.Scope, scope)));
|
|
111
|
+
let disposed = false;
|
|
112
|
+
const clientWithDispose = Object.assign(client, {
|
|
113
|
+
dispose: async ()=>{
|
|
114
|
+
if (!disposed) {
|
|
115
|
+
disposed = true;
|
|
116
|
+
await runtime.runPromise(Scope_namespaceObject.close(scope, Exit_namespaceObject["void"]));
|
|
117
|
+
}
|
|
118
|
+
await runtime.dispose();
|
|
119
|
+
}
|
|
120
|
+
});
|
|
121
|
+
return clientWithDispose;
|
|
122
|
+
} catch (error) {
|
|
123
|
+
try {
|
|
124
|
+
await runtime.runPromise(Scope_namespaceObject.close(scope, Exit_namespaceObject["void"]));
|
|
125
|
+
} catch {}
|
|
126
|
+
try {
|
|
127
|
+
await runtime.dispose();
|
|
128
|
+
} catch {}
|
|
129
|
+
throw error;
|
|
130
|
+
}
|
|
131
|
+
},
|
|
132
|
+
catch: (error)=>error instanceof Error ? error : new Error(String(error))
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
const runEffectRequest = Effect_namespaceObject.runPromise;
|
|
136
|
+
exports.Effect = __webpack_exports__.Effect;
|
|
137
|
+
exports.HttpApi = __webpack_exports__.HttpApi;
|
|
138
|
+
exports.HttpApiClient = __webpack_exports__.HttpApiClient;
|
|
139
|
+
exports.HttpApiEndpoint = __webpack_exports__.HttpApiEndpoint;
|
|
140
|
+
exports.HttpApiGroup = __webpack_exports__.HttpApiGroup;
|
|
141
|
+
exports.HttpApiSchema = __webpack_exports__.HttpApiSchema;
|
|
142
|
+
exports.Layer = __webpack_exports__.Layer;
|
|
143
|
+
exports.Rpc = __webpack_exports__.Rpc;
|
|
144
|
+
exports.RpcClient = __webpack_exports__.RpcClient;
|
|
145
|
+
exports.RpcGroup = __webpack_exports__.RpcGroup;
|
|
146
|
+
exports.RpcSchema = __webpack_exports__.RpcSchema;
|
|
147
|
+
exports.RpcSerialization = __webpack_exports__.RpcSerialization;
|
|
148
|
+
exports.Schema = __webpack_exports__.Schema;
|
|
149
|
+
exports.makeEffectHttpApiClient = __webpack_exports__.makeEffectHttpApiClient;
|
|
150
|
+
exports.makeEffectRpcClient = __webpack_exports__.makeEffectRpcClient;
|
|
151
|
+
exports.mask = __webpack_exports__.mask;
|
|
152
|
+
exports.runEffectRequest = __webpack_exports__.runEffectRequest;
|
|
153
|
+
exports.runEffectView = __webpack_exports__.runEffectView;
|
|
154
|
+
exports.view = __webpack_exports__.view;
|
|
155
|
+
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
156
|
+
"Effect",
|
|
157
|
+
"HttpApi",
|
|
158
|
+
"HttpApiClient",
|
|
159
|
+
"HttpApiEndpoint",
|
|
160
|
+
"HttpApiGroup",
|
|
161
|
+
"HttpApiSchema",
|
|
162
|
+
"Layer",
|
|
163
|
+
"Rpc",
|
|
164
|
+
"RpcClient",
|
|
165
|
+
"RpcGroup",
|
|
166
|
+
"RpcSchema",
|
|
167
|
+
"RpcSerialization",
|
|
168
|
+
"Schema",
|
|
169
|
+
"makeEffectHttpApiClient",
|
|
170
|
+
"makeEffectRpcClient",
|
|
171
|
+
"mask",
|
|
172
|
+
"runEffectRequest",
|
|
173
|
+
"runEffectView",
|
|
174
|
+
"view"
|
|
175
|
+
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
176
|
+
Object.defineProperty(exports, '__esModule', {
|
|
177
|
+
value: true
|
|
178
|
+
});
|
|
@@ -0,0 +1,168 @@
|
|
|
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
|
+
HonoAdapter: ()=>HonoAdapter
|
|
37
|
+
});
|
|
38
|
+
const server_core_namespaceObject = require("@modern-js/server-core");
|
|
39
|
+
const utils_namespaceObject = require("@modern-js/utils");
|
|
40
|
+
const createHonoRoutes_js_namespaceObject = require("../../utils/createHonoRoutes.js");
|
|
41
|
+
var createHonoRoutes_js_default = /*#__PURE__*/ __webpack_require__.n(createHonoRoutes_js_namespaceObject);
|
|
42
|
+
const before = [
|
|
43
|
+
'custom-server-hook',
|
|
44
|
+
'custom-server-middleware',
|
|
45
|
+
'render'
|
|
46
|
+
];
|
|
47
|
+
const kParentHonoVars = Symbol.for('modernjs.hono.parentVars');
|
|
48
|
+
class HonoAdapter {
|
|
49
|
+
wrapInArray(handler) {
|
|
50
|
+
if (Array.isArray(handler)) return handler;
|
|
51
|
+
return [
|
|
52
|
+
handler
|
|
53
|
+
];
|
|
54
|
+
}
|
|
55
|
+
constructor(api){
|
|
56
|
+
this.apiMiddleware = [];
|
|
57
|
+
this.apiServer = null;
|
|
58
|
+
this.isHono = true;
|
|
59
|
+
this.setHandlers = async ()=>{
|
|
60
|
+
if (!this.isHono) return;
|
|
61
|
+
const { apiHandlerInfos } = this.api.getServerContext();
|
|
62
|
+
const honoHandlers = createHonoRoutes_js_default()(apiHandlerInfos);
|
|
63
|
+
this.apiMiddleware = honoHandlers.map(({ path, method, handler })=>({
|
|
64
|
+
name: 'hono-bff-api',
|
|
65
|
+
path,
|
|
66
|
+
method,
|
|
67
|
+
handler,
|
|
68
|
+
order: 'post',
|
|
69
|
+
before
|
|
70
|
+
}));
|
|
71
|
+
};
|
|
72
|
+
this.registerApiRoutes = async ()=>{
|
|
73
|
+
if (!this.isHono) return;
|
|
74
|
+
this.apiServer = new server_core_namespaceObject.Hono();
|
|
75
|
+
this.apiServer.use('*', server_core_namespaceObject.run);
|
|
76
|
+
this.apiServer.use('*', async (c, next)=>{
|
|
77
|
+
const nodeReq = c.env?.node?.req;
|
|
78
|
+
const parentVars = nodeReq?.[kParentHonoVars];
|
|
79
|
+
if (parentVars && 'object' == typeof parentVars) {
|
|
80
|
+
delete nodeReq[kParentHonoVars];
|
|
81
|
+
for (const [key, value] of Object.entries(parentVars))if (void 0 === c.get(key)) c.set(key, value);
|
|
82
|
+
}
|
|
83
|
+
await next();
|
|
84
|
+
});
|
|
85
|
+
this.apiMiddleware.forEach(({ path = '*', method = 'all', handler })=>{
|
|
86
|
+
const handlers = this.wrapInArray(handler);
|
|
87
|
+
if (0 === handlers.length) return;
|
|
88
|
+
const firstHandler = handlers[0];
|
|
89
|
+
const restHandlers = handlers.slice(1);
|
|
90
|
+
const m = method;
|
|
91
|
+
const server = this.apiServer;
|
|
92
|
+
if (!server) return;
|
|
93
|
+
const register = server[m];
|
|
94
|
+
register.call(server, path, firstHandler, ...restHandlers);
|
|
95
|
+
});
|
|
96
|
+
this.apiServer.onError(async (err, c)=>{
|
|
97
|
+
try {
|
|
98
|
+
const serverConfig = this.api.getServerConfig();
|
|
99
|
+
const onErrorHandler = serverConfig?.onError;
|
|
100
|
+
if (onErrorHandler) {
|
|
101
|
+
const result = await onErrorHandler(err, c);
|
|
102
|
+
if (result instanceof Response) return result;
|
|
103
|
+
} else utils_namespaceObject.logger.error(err);
|
|
104
|
+
} catch (configError) {
|
|
105
|
+
utils_namespaceObject.logger.error(`Error in serverConfig.onError handler: ${configError}`);
|
|
106
|
+
}
|
|
107
|
+
const status = 'object' == typeof err && null !== err && 'status' in err && 'number' == typeof err.status ? err.status : 500;
|
|
108
|
+
return new Response(JSON.stringify({
|
|
109
|
+
message: err instanceof Error ? err.message : '[BFF] Internal Server Error'
|
|
110
|
+
}), {
|
|
111
|
+
status,
|
|
112
|
+
headers: {
|
|
113
|
+
'content-type': 'application/json; charset=utf-8'
|
|
114
|
+
}
|
|
115
|
+
});
|
|
116
|
+
});
|
|
117
|
+
};
|
|
118
|
+
this.registerMiddleware = async (options)=>{
|
|
119
|
+
const { prefix } = options;
|
|
120
|
+
const { bffRuntimeFramework } = this.api.getServerContext();
|
|
121
|
+
if ('hono' !== bffRuntimeFramework) {
|
|
122
|
+
this.isHono = false;
|
|
123
|
+
return;
|
|
124
|
+
}
|
|
125
|
+
const { middlewares: globalMiddlewares } = this.api.getServerContext();
|
|
126
|
+
await this.setHandlers();
|
|
127
|
+
if ((0, utils_namespaceObject.isProd)()) globalMiddlewares.push(...this.apiMiddleware);
|
|
128
|
+
else {
|
|
129
|
+
await this.registerApiRoutes();
|
|
130
|
+
const dynamicApiMiddleware = {
|
|
131
|
+
name: 'dynamic-bff-handler',
|
|
132
|
+
path: `${prefix}/*`,
|
|
133
|
+
method: 'all',
|
|
134
|
+
order: 'post',
|
|
135
|
+
before,
|
|
136
|
+
handler: async (c, next)=>{
|
|
137
|
+
if (this.apiServer) {
|
|
138
|
+
const nodeReq = c.env?.node?.req;
|
|
139
|
+
if (nodeReq) {
|
|
140
|
+
const parentVars = c?.var;
|
|
141
|
+
nodeReq[kParentHonoVars] = parentVars && 'object' == typeof parentVars ? {
|
|
142
|
+
...parentVars
|
|
143
|
+
} : parentVars;
|
|
144
|
+
}
|
|
145
|
+
const response = await this.apiServer.fetch(c.req.raw, c.env);
|
|
146
|
+
if (404 !== response.status) return new Response(response.body, response);
|
|
147
|
+
}
|
|
148
|
+
await next();
|
|
149
|
+
}
|
|
150
|
+
};
|
|
151
|
+
globalMiddlewares.push(dynamicApiMiddleware);
|
|
152
|
+
}
|
|
153
|
+
};
|
|
154
|
+
this.onApiHandlersUpdated = async ()=>{
|
|
155
|
+
if (!this.isHono) return;
|
|
156
|
+
await this.setHandlers();
|
|
157
|
+
await this.registerApiRoutes();
|
|
158
|
+
};
|
|
159
|
+
this.api = api;
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
exports.HonoAdapter = __webpack_exports__.HonoAdapter;
|
|
163
|
+
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
164
|
+
"HonoAdapter"
|
|
165
|
+
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
166
|
+
Object.defineProperty(exports, '__esModule', {
|
|
167
|
+
value: true
|
|
168
|
+
});
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __webpack_modules__ = {
|
|
3
|
+
"./operators" (module) {
|
|
4
|
+
module.exports = require("./operators.js");
|
|
5
|
+
},
|
|
6
|
+
"@modern-js/bff-core" (module) {
|
|
7
|
+
module.exports = require("@modern-js/bff-core");
|
|
8
|
+
}
|
|
9
|
+
};
|
|
10
|
+
var __webpack_module_cache__ = {};
|
|
11
|
+
function __webpack_require__(moduleId) {
|
|
12
|
+
var cachedModule = __webpack_module_cache__[moduleId];
|
|
13
|
+
if (void 0 !== cachedModule) return cachedModule.exports;
|
|
14
|
+
var module = __webpack_module_cache__[moduleId] = {
|
|
15
|
+
exports: {}
|
|
16
|
+
};
|
|
17
|
+
__webpack_modules__[moduleId](module, module.exports, __webpack_require__);
|
|
18
|
+
return module.exports;
|
|
19
|
+
}
|
|
20
|
+
(()=>{
|
|
21
|
+
__webpack_require__.n = (module)=>{
|
|
22
|
+
var getter = module && module.__esModule ? ()=>module['default'] : ()=>module;
|
|
23
|
+
__webpack_require__.d(getter, {
|
|
24
|
+
a: getter
|
|
25
|
+
});
|
|
26
|
+
return getter;
|
|
27
|
+
};
|
|
28
|
+
})();
|
|
29
|
+
(()=>{
|
|
30
|
+
__webpack_require__.d = (exports1, definition)=>{
|
|
31
|
+
for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
|
|
32
|
+
enumerable: true,
|
|
33
|
+
get: definition[key]
|
|
34
|
+
});
|
|
35
|
+
};
|
|
36
|
+
})();
|
|
37
|
+
(()=>{
|
|
38
|
+
__webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
|
|
39
|
+
})();
|
|
40
|
+
(()=>{
|
|
41
|
+
__webpack_require__.r = (exports1)=>{
|
|
42
|
+
if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
|
|
43
|
+
value: 'Module'
|
|
44
|
+
});
|
|
45
|
+
Object.defineProperty(exports1, '__esModule', {
|
|
46
|
+
value: true
|
|
47
|
+
});
|
|
48
|
+
};
|
|
49
|
+
})();
|
|
50
|
+
var __webpack_exports__ = {};
|
|
51
|
+
(()=>{
|
|
52
|
+
__webpack_require__.r(__webpack_exports__);
|
|
53
|
+
var _modern_js_bff_core__rspack_import_0 = __webpack_require__("@modern-js/bff-core");
|
|
54
|
+
var __rspack_reexport = {};
|
|
55
|
+
for(const __rspack_import_key in _modern_js_bff_core__rspack_import_0)if ("default" !== __rspack_import_key) __rspack_reexport[__rspack_import_key] = ()=>_modern_js_bff_core__rspack_import_0[__rspack_import_key];
|
|
56
|
+
__webpack_require__.d(__webpack_exports__, __rspack_reexport);
|
|
57
|
+
var _operators__rspack_import_1 = __webpack_require__("./operators");
|
|
58
|
+
var __rspack_reexport = {};
|
|
59
|
+
for(const __rspack_import_key in _operators__rspack_import_1)if ("default" !== __rspack_import_key) __rspack_reexport[__rspack_import_key] = ()=>_operators__rspack_import_1[__rspack_import_key];
|
|
60
|
+
__webpack_require__.d(__webpack_exports__, __rspack_reexport);
|
|
61
|
+
})();
|
|
62
|
+
for(var __rspack_i in __webpack_exports__)exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
63
|
+
Object.defineProperty(exports, '__esModule', {
|
|
64
|
+
value: true
|
|
65
|
+
});
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __webpack_require__ = {};
|
|
3
|
+
(()=>{
|
|
4
|
+
__webpack_require__.d = (exports1, definition)=>{
|
|
5
|
+
for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: definition[key]
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
})();
|
|
11
|
+
(()=>{
|
|
12
|
+
__webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
|
|
13
|
+
})();
|
|
14
|
+
(()=>{
|
|
15
|
+
__webpack_require__.r = (exports1)=>{
|
|
16
|
+
if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
|
|
17
|
+
value: 'Module'
|
|
18
|
+
});
|
|
19
|
+
Object.defineProperty(exports1, '__esModule', {
|
|
20
|
+
value: true
|
|
21
|
+
});
|
|
22
|
+
};
|
|
23
|
+
})();
|
|
24
|
+
var __webpack_exports__ = {};
|
|
25
|
+
__webpack_require__.r(__webpack_exports__);
|
|
26
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
27
|
+
Middleware: ()=>Middleware,
|
|
28
|
+
Pipe: ()=>Pipe
|
|
29
|
+
});
|
|
30
|
+
const server_core_namespaceObject = require("@modern-js/server-core");
|
|
31
|
+
const Pipe = (func)=>({
|
|
32
|
+
name: 'pipe',
|
|
33
|
+
async execute (executeHelper, next) {
|
|
34
|
+
const { inputs } = executeHelper;
|
|
35
|
+
const ctx = (0, server_core_namespaceObject.useHonoContext)();
|
|
36
|
+
const { res } = ctx;
|
|
37
|
+
if ('function' == typeof func) {
|
|
38
|
+
let isPiped = true;
|
|
39
|
+
const end = (value)=>{
|
|
40
|
+
isPiped = false;
|
|
41
|
+
if ('function' == typeof value) return void value(res);
|
|
42
|
+
return value;
|
|
43
|
+
};
|
|
44
|
+
const output = await func(inputs, end);
|
|
45
|
+
if (!isPiped) if (output) return executeHelper.result = output;
|
|
46
|
+
else return;
|
|
47
|
+
executeHelper.inputs = output;
|
|
48
|
+
await next();
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
const Middleware = (middleware)=>({
|
|
53
|
+
name: 'middleware',
|
|
54
|
+
metadata (helper) {
|
|
55
|
+
const middlewares = helper.getMetadata('pipe') || [];
|
|
56
|
+
middlewares.push(middleware);
|
|
57
|
+
helper.setMetadata('middleware', middlewares);
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
exports.Middleware = __webpack_exports__.Middleware;
|
|
61
|
+
exports.Pipe = __webpack_exports__.Pipe;
|
|
62
|
+
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
63
|
+
"Middleware",
|
|
64
|
+
"Pipe"
|
|
65
|
+
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
66
|
+
Object.defineProperty(exports, '__esModule', {
|
|
67
|
+
value: true
|
|
68
|
+
});
|
|
@@ -0,0 +1,179 @@
|
|
|
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
|
+
default: ()=>server
|
|
37
|
+
});
|
|
38
|
+
const bff_core_namespaceObject = require("@modern-js/bff-core");
|
|
39
|
+
const utils_namespaceObject = require("@modern-js/utils");
|
|
40
|
+
const external_path_namespaceObject = require("path");
|
|
41
|
+
var external_path_default = /*#__PURE__*/ __webpack_require__.n(external_path_namespaceObject);
|
|
42
|
+
const adapter_js_namespaceObject = require("./runtime/effect/adapter.js");
|
|
43
|
+
const hono_adapter_js_namespaceObject = require("./runtime/hono/adapter.js");
|
|
44
|
+
const RUNTIME_ADAPTER_FACTORIES = {
|
|
45
|
+
hono: [
|
|
46
|
+
(api)=>new hono_adapter_js_namespaceObject.HonoAdapter(api)
|
|
47
|
+
],
|
|
48
|
+
effect: [
|
|
49
|
+
(api)=>new adapter_js_namespaceObject.EffectAdapter(api)
|
|
50
|
+
]
|
|
51
|
+
};
|
|
52
|
+
const normalizePrefixList = (prefix)=>{
|
|
53
|
+
if (Array.isArray(prefix)) return prefix.filter(Boolean);
|
|
54
|
+
return [
|
|
55
|
+
prefix || '/api'
|
|
56
|
+
];
|
|
57
|
+
};
|
|
58
|
+
const getPrimaryPrefix = (prefix)=>normalizePrefixList(prefix)[0] || '/api';
|
|
59
|
+
function resolveRuntimeFramework(runtimeFramework) {
|
|
60
|
+
return 'hono' === runtimeFramework ? 'hono' : 'effect';
|
|
61
|
+
}
|
|
62
|
+
class Storage {
|
|
63
|
+
reset() {
|
|
64
|
+
this.middlewares = [];
|
|
65
|
+
}
|
|
66
|
+
constructor(){
|
|
67
|
+
this.middlewares = [];
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
const server = ()=>({
|
|
71
|
+
name: '@modern-js/plugin-bff',
|
|
72
|
+
setup: (api)=>{
|
|
73
|
+
const storage = new Storage();
|
|
74
|
+
let apiRouter = null;
|
|
75
|
+
const appContext = api.getServerContext();
|
|
76
|
+
const runtimeFramework = resolveRuntimeFramework(appContext.bffRuntimeFramework);
|
|
77
|
+
const runtimeAdapters = RUNTIME_ADAPTER_FACTORIES[runtimeFramework].map((createAdapter)=>createAdapter(api));
|
|
78
|
+
api.onPrepare(async ()=>{
|
|
79
|
+
const appContext = api.getServerContext();
|
|
80
|
+
const { render } = appContext;
|
|
81
|
+
const { middlewares } = storage;
|
|
82
|
+
api.updateServerContext({
|
|
83
|
+
...appContext,
|
|
84
|
+
apiMiddlewares: middlewares
|
|
85
|
+
});
|
|
86
|
+
const config = api.getServerConfig();
|
|
87
|
+
const prefixList = normalizePrefixList(config?.bff?.prefix);
|
|
88
|
+
const prefix = getPrimaryPrefix(config?.bff?.prefix);
|
|
89
|
+
const enableHandleWeb = config?.bff?.enableHandleWeb;
|
|
90
|
+
const httpMethodDecider = config?.bff?.httpMethodDecider;
|
|
91
|
+
const { distDirectory: pwd, middlewares: globalMiddlewares } = api.getServerContext();
|
|
92
|
+
const webOnly = await (0, utils_namespaceObject.isWebOnly)();
|
|
93
|
+
if ('hono' === runtimeFramework) {
|
|
94
|
+
let handler;
|
|
95
|
+
if (webOnly) handler = async (c, next)=>{
|
|
96
|
+
c.body('');
|
|
97
|
+
await next();
|
|
98
|
+
};
|
|
99
|
+
else {
|
|
100
|
+
const runner = api.getHooks();
|
|
101
|
+
const renderHandler = enableHandleWeb ? render : null;
|
|
102
|
+
handler = await runner.prepareApiServer.call({
|
|
103
|
+
pwd: pwd,
|
|
104
|
+
prefix,
|
|
105
|
+
render: renderHandler,
|
|
106
|
+
httpMethodDecider
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
if (handler && (0, utils_namespaceObject.isFunction)(handler)) globalMiddlewares.push({
|
|
110
|
+
name: 'bind-bff',
|
|
111
|
+
handler: (c, next)=>{
|
|
112
|
+
if (!prefixList.some((item)=>c.req.path.startsWith(item)) && !enableHandleWeb) return next();
|
|
113
|
+
return handler(c, next);
|
|
114
|
+
},
|
|
115
|
+
order: 'post',
|
|
116
|
+
before: [
|
|
117
|
+
'custom-server-hook',
|
|
118
|
+
'custom-server-middleware',
|
|
119
|
+
'render'
|
|
120
|
+
]
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
await Promise.all(runtimeAdapters.map((adapter)=>adapter.registerMiddleware({
|
|
124
|
+
prefix,
|
|
125
|
+
enableHandleWeb
|
|
126
|
+
})));
|
|
127
|
+
});
|
|
128
|
+
api.onReset(async ({ event })=>{
|
|
129
|
+
storage.reset();
|
|
130
|
+
const appContext = api.getServerContext();
|
|
131
|
+
const { middlewares } = storage;
|
|
132
|
+
api.updateServerContext({
|
|
133
|
+
...appContext,
|
|
134
|
+
apiMiddlewares: middlewares
|
|
135
|
+
});
|
|
136
|
+
if ('file-change' === event.type) {
|
|
137
|
+
if ('hono' === runtimeFramework && apiRouter) {
|
|
138
|
+
const apiHandlerInfos = await apiRouter.getApiHandlers();
|
|
139
|
+
const appContext = api.getServerContext();
|
|
140
|
+
api.updateServerContext({
|
|
141
|
+
...appContext,
|
|
142
|
+
apiHandlerInfos
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
await Promise.all(runtimeAdapters.map((adapter)=>adapter.onApiHandlersUpdated?.()));
|
|
146
|
+
}
|
|
147
|
+
});
|
|
148
|
+
const prepareApiServer = async (input, next)=>{
|
|
149
|
+
if ('hono' !== runtimeFramework) return next(input);
|
|
150
|
+
const { pwd, prefix, httpMethodDecider } = input;
|
|
151
|
+
const defaultApiDirectory = external_path_default().resolve(pwd, utils_namespaceObject.API_DIR);
|
|
152
|
+
const appContext = api.getServerContext();
|
|
153
|
+
const apiDirectory = 'string' == typeof appContext.apiDirectory ? appContext.apiDirectory : defaultApiDirectory;
|
|
154
|
+
const lambdaDirectory = 'string' == typeof appContext.lambdaDirectory ? appContext.lambdaDirectory : void 0;
|
|
155
|
+
apiRouter = new bff_core_namespaceObject.ApiRouter({
|
|
156
|
+
appDir: pwd,
|
|
157
|
+
apiDir: apiDirectory,
|
|
158
|
+
lambdaDir: lambdaDirectory,
|
|
159
|
+
prefix,
|
|
160
|
+
httpMethodDecider
|
|
161
|
+
});
|
|
162
|
+
const apiHandlerInfos = await apiRouter.getApiHandlers();
|
|
163
|
+
api.updateServerContext({
|
|
164
|
+
...appContext,
|
|
165
|
+
apiRouter,
|
|
166
|
+
apiHandlerInfos
|
|
167
|
+
});
|
|
168
|
+
return next(input);
|
|
169
|
+
};
|
|
170
|
+
api.prepareApiServer(prepareApiServer);
|
|
171
|
+
}
|
|
172
|
+
});
|
|
173
|
+
exports["default"] = __webpack_exports__["default"];
|
|
174
|
+
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
175
|
+
"default"
|
|
176
|
+
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
177
|
+
Object.defineProperty(exports, '__esModule', {
|
|
178
|
+
value: true
|
|
179
|
+
});
|