@bleedingdev/modern-js-plugin-bff 3.2.0-ultramodern.11 → 3.2.0-ultramodern.111
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.js +9 -5
- package/dist/cjs/constants.js +13 -9
- package/dist/cjs/index.js +9 -5
- package/dist/cjs/loader.js +32 -5
- package/dist/cjs/runtime/create-request/index.js +9 -5
- package/dist/cjs/runtime/data-platform/index.js +48 -13
- package/dist/cjs/runtime/effect/adapter.js +24 -87
- package/dist/cjs/runtime/effect/context.js +19 -7
- package/dist/cjs/runtime/effect/edge.js +173 -0
- package/dist/cjs/runtime/effect/handler.js +597 -0
- package/dist/cjs/runtime/effect/index.js +30 -547
- package/dist/cjs/runtime/effect/module.js +142 -0
- package/dist/cjs/runtime/effect/operation-context.js +115 -0
- package/dist/cjs/runtime/effect-client/index.js +22 -6
- package/dist/cjs/runtime/hono/adapter.js +9 -5
- package/dist/cjs/runtime/hono/index.js +9 -5
- package/dist/cjs/runtime/hono/operators.js +9 -5
- package/dist/cjs/server.js +9 -5
- package/dist/cjs/utils/clientGenerator.js +9 -5
- package/dist/cjs/utils/createHonoRoutes.js +9 -5
- package/dist/cjs/utils/crossProjectApiPlugin.js +9 -5
- package/dist/cjs/utils/effectClientGenerator.js +26 -5
- package/dist/cjs/utils/pluginGenerator.js +9 -5
- package/dist/cjs/utils/runtimeGenerator.js +9 -5
- package/dist/esm/loader.mjs +23 -0
- package/dist/esm/runtime/data-platform/index.mjs +31 -9
- package/dist/esm/runtime/effect/adapter.mjs +16 -83
- package/dist/esm/runtime/effect/context.mjs +3 -1
- package/dist/esm/runtime/effect/edge.mjs +90 -0
- package/dist/esm/runtime/effect/handler.mjs +438 -0
- package/dist/esm/runtime/effect/index.mjs +3 -437
- package/dist/esm/runtime/effect/module.mjs +104 -0
- package/dist/esm/runtime/effect/operation-context.mjs +77 -0
- package/dist/esm/runtime/effect-client/index.mjs +14 -2
- package/dist/esm/utils/effectClientGenerator.mjs +17 -0
- package/dist/esm-node/loader.mjs +23 -0
- package/dist/esm-node/runtime/data-platform/index.mjs +31 -9
- package/dist/esm-node/runtime/effect/adapter.mjs +16 -83
- package/dist/esm-node/runtime/effect/context.mjs +3 -1
- package/dist/esm-node/runtime/effect/edge.mjs +91 -0
- package/dist/esm-node/runtime/effect/handler.mjs +439 -0
- package/dist/esm-node/runtime/effect/index.mjs +3 -437
- package/dist/esm-node/runtime/effect/module.mjs +105 -0
- package/dist/esm-node/runtime/effect/operation-context.mjs +78 -0
- package/dist/esm-node/runtime/effect-client/index.mjs +14 -2
- package/dist/esm-node/utils/effectClientGenerator.mjs +17 -0
- package/dist/types/runtime/create-request/index.d.ts +1 -0
- package/dist/types/runtime/data-platform/index.d.ts +4 -0
- package/dist/types/runtime/effect/context.d.ts +3 -6
- package/dist/types/runtime/effect/edge.d.ts +25 -0
- package/dist/types/runtime/effect/handler.d.ts +173 -0
- package/dist/types/runtime/effect/index.d.ts +2 -170
- package/dist/types/runtime/effect/module.d.ts +28 -0
- package/dist/types/runtime/effect/operation-context.d.ts +10 -0
- package/dist/types/runtime/effect-client/index.d.ts +6 -1
- package/dist/types/utils/createHonoRoutes.d.ts +3 -3
- package/dist/types/utils/effectClientGenerator.d.ts +1 -1
- package/package.json +27 -18
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __webpack_modules__ = {
|
|
3
|
+
"./handler" (module) {
|
|
4
|
+
module.exports = require("./handler.js");
|
|
5
|
+
},
|
|
6
|
+
"./module" (module) {
|
|
7
|
+
module.exports = require("./module.js");
|
|
8
|
+
},
|
|
9
|
+
"./operation-context" (module) {
|
|
10
|
+
module.exports = require("./operation-context.js");
|
|
11
|
+
}
|
|
12
|
+
};
|
|
13
|
+
var __webpack_module_cache__ = {};
|
|
14
|
+
function __webpack_require__(moduleId) {
|
|
15
|
+
var cachedModule = __webpack_module_cache__[moduleId];
|
|
16
|
+
if (void 0 !== cachedModule) return cachedModule.exports;
|
|
17
|
+
var module = __webpack_module_cache__[moduleId] = {
|
|
18
|
+
exports: {}
|
|
19
|
+
};
|
|
20
|
+
__webpack_modules__[moduleId](module, module.exports, __webpack_require__);
|
|
21
|
+
return module.exports;
|
|
22
|
+
}
|
|
23
|
+
(()=>{
|
|
24
|
+
__webpack_require__.n = (module)=>{
|
|
25
|
+
var getter = module && module.__esModule ? ()=>module['default'] : ()=>module;
|
|
26
|
+
__webpack_require__.d(getter, {
|
|
27
|
+
a: getter
|
|
28
|
+
});
|
|
29
|
+
return getter;
|
|
30
|
+
};
|
|
31
|
+
})();
|
|
32
|
+
(()=>{
|
|
33
|
+
__webpack_require__.d = (exports1, getters, values)=>{
|
|
34
|
+
var define = (defs, kind)=>{
|
|
35
|
+
for(var key in defs)if (__webpack_require__.o(defs, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
|
|
36
|
+
enumerable: true,
|
|
37
|
+
[kind]: defs[key]
|
|
38
|
+
});
|
|
39
|
+
};
|
|
40
|
+
define(getters, "get");
|
|
41
|
+
define(values, "value");
|
|
42
|
+
};
|
|
43
|
+
})();
|
|
44
|
+
(()=>{
|
|
45
|
+
__webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
|
|
46
|
+
})();
|
|
47
|
+
(()=>{
|
|
48
|
+
__webpack_require__.r = (exports1)=>{
|
|
49
|
+
if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
|
|
50
|
+
value: 'Module'
|
|
51
|
+
});
|
|
52
|
+
Object.defineProperty(exports1, '__esModule', {
|
|
53
|
+
value: true
|
|
54
|
+
});
|
|
55
|
+
};
|
|
56
|
+
})();
|
|
57
|
+
var __webpack_exports__ = {};
|
|
58
|
+
(()=>{
|
|
59
|
+
__webpack_require__.r(__webpack_exports__);
|
|
60
|
+
var _module__rspack_import_0 = __webpack_require__("./module");
|
|
61
|
+
var _operation_context__rspack_import_1 = __webpack_require__("./operation-context");
|
|
62
|
+
var _handler__rspack_import_2 = __webpack_require__("./handler");
|
|
63
|
+
var __rspack_reexport = {};
|
|
64
|
+
for(const __rspack_import_key in _handler__rspack_import_2)if ([
|
|
65
|
+
"default",
|
|
66
|
+
"dispatchEffectBffRequest",
|
|
67
|
+
"createEffectOperationContext",
|
|
68
|
+
"createEffectBffEdgeHandler"
|
|
69
|
+
].indexOf(__rspack_import_key) < 0) __rspack_reexport[__rspack_import_key] = ()=>_handler__rspack_import_2[__rspack_import_key];
|
|
70
|
+
__webpack_require__.d(__webpack_exports__, __rspack_reexport);
|
|
71
|
+
function normalizePrefix(prefix) {
|
|
72
|
+
if (!prefix || '/' === prefix) return '';
|
|
73
|
+
return prefix.endsWith('/') ? prefix.slice(0, -1) : prefix;
|
|
74
|
+
}
|
|
75
|
+
function removePrefixFromPath(pathname, prefix) {
|
|
76
|
+
const normalized = normalizePrefix(prefix);
|
|
77
|
+
if (!normalized || pathname !== normalized && !pathname.startsWith(`${normalized}/`)) return pathname;
|
|
78
|
+
const sliced = pathname.slice(normalized.length);
|
|
79
|
+
return sliced.startsWith('/') ? sliced : `/${sliced}`;
|
|
80
|
+
}
|
|
81
|
+
function matchesPrefix(pathname, prefix) {
|
|
82
|
+
const normalized = normalizePrefix(prefix);
|
|
83
|
+
return !normalized || pathname === normalized || pathname.startsWith(`${normalized}/`);
|
|
84
|
+
}
|
|
85
|
+
function createRequestForMountedPrefix(req, prefix) {
|
|
86
|
+
const url = new URL(req.url);
|
|
87
|
+
const nextPath = removePrefixFromPath(url.pathname, prefix);
|
|
88
|
+
if (nextPath === url.pathname) return req;
|
|
89
|
+
url.pathname = nextPath;
|
|
90
|
+
return new Request(url, req);
|
|
91
|
+
}
|
|
92
|
+
function createEdgeEffectContext(originalRequest, effectRequest, options) {
|
|
93
|
+
const originalPath = options.path || new URL(originalRequest.url).pathname;
|
|
94
|
+
const method = options.method || originalRequest.method;
|
|
95
|
+
return {
|
|
96
|
+
request: effectRequest,
|
|
97
|
+
env: options.env || {},
|
|
98
|
+
path: originalPath,
|
|
99
|
+
method,
|
|
100
|
+
operationContext: (0, _operation_context__rspack_import_1.createEffectOperationContext)({
|
|
101
|
+
request: effectRequest,
|
|
102
|
+
env: options.env || {},
|
|
103
|
+
path: originalPath,
|
|
104
|
+
method
|
|
105
|
+
})
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
function createRuntimeErrorResponse(error) {
|
|
109
|
+
const status = 'object' == typeof error && null !== error && 'status' in error && 'number' == typeof error.status ? error.status : 500;
|
|
110
|
+
return new Response(JSON.stringify({
|
|
111
|
+
message: error instanceof Error ? error.message : '[BFF] Internal Server Error'
|
|
112
|
+
}), {
|
|
113
|
+
status,
|
|
114
|
+
headers: {
|
|
115
|
+
'content-type': 'application/json; charset=utf-8'
|
|
116
|
+
}
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
async function dispatchEffectBffRequest(handler, request, options = {}) {
|
|
120
|
+
const requestPathname = new URL(request.url).pathname;
|
|
121
|
+
if (!matchesPrefix(requestPathname, options.prefix)) return new Response(null, {
|
|
122
|
+
status: 404
|
|
123
|
+
});
|
|
124
|
+
const effectRequest = createRequestForMountedPrefix(request, options.prefix);
|
|
125
|
+
const effectContext = createEdgeEffectContext(request, effectRequest, options);
|
|
126
|
+
try {
|
|
127
|
+
const response = handler.length > 1 ? await handler(effectRequest, effectContext) : await handler(effectRequest);
|
|
128
|
+
if (!(response instanceof Response)) throw new Error('[BFF][Effect] Effect handler must return a Response instance.');
|
|
129
|
+
return new Response(response.body, response);
|
|
130
|
+
} catch (error) {
|
|
131
|
+
if (error instanceof Response) return new Response(error.body, error);
|
|
132
|
+
if (options.onError) {
|
|
133
|
+
const errorResponse = await options.onError(error, effectContext);
|
|
134
|
+
if (errorResponse instanceof Response) return errorResponse;
|
|
135
|
+
}
|
|
136
|
+
return createRuntimeErrorResponse(error);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
async function createEffectBffEdgeHandler(options) {
|
|
140
|
+
const loaded = await (0, _module__rspack_import_0.resolveEffectBffModuleHandler)(options.module, {
|
|
141
|
+
openapi: options.openapi,
|
|
142
|
+
dataPlatform: options.dataPlatform,
|
|
143
|
+
onWarning: options.onWarning
|
|
144
|
+
});
|
|
145
|
+
if (!loaded) throw new Error('[BFF][Effect] Invalid Effect edge module. Export { api, layer }, createHandler, or handler.');
|
|
146
|
+
return {
|
|
147
|
+
handler: (request, dispatchOptions = {})=>dispatchEffectBffRequest(loaded.handler, request, {
|
|
148
|
+
...dispatchOptions,
|
|
149
|
+
prefix: options.prefix,
|
|
150
|
+
onError: options.onError
|
|
151
|
+
}),
|
|
152
|
+
dispose: async ()=>{
|
|
153
|
+
await loaded.dispose?.();
|
|
154
|
+
}
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
158
|
+
createEffectBffEdgeHandler: ()=>createEffectBffEdgeHandler,
|
|
159
|
+
createEffectOperationContext: ()=>_operation_context__rspack_import_1.createEffectOperationContext,
|
|
160
|
+
dispatchEffectBffRequest: ()=>dispatchEffectBffRequest
|
|
161
|
+
});
|
|
162
|
+
})();
|
|
163
|
+
exports.createEffectBffEdgeHandler = __webpack_exports__.createEffectBffEdgeHandler;
|
|
164
|
+
exports.createEffectOperationContext = __webpack_exports__.createEffectOperationContext;
|
|
165
|
+
exports.dispatchEffectBffRequest = __webpack_exports__.dispatchEffectBffRequest;
|
|
166
|
+
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
167
|
+
"createEffectBffEdgeHandler",
|
|
168
|
+
"createEffectOperationContext",
|
|
169
|
+
"dispatchEffectBffRequest"
|
|
170
|
+
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
171
|
+
Object.defineProperty(exports, '__esModule', {
|
|
172
|
+
value: true
|
|
173
|
+
});
|