@bleedingdev/modern-js-plugin-bff-build-extensions 0.0.0 → 3.9.0-ultramodern.5
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/dist/cjs/client-artifacts.js +106 -0
- package/dist/cjs/compile.js +63 -0
- package/dist/cjs/cross-project.js +92 -0
- package/dist/cjs/generated-entries.js +92 -0
- package/dist/cjs/hono-client-codegen.js +107 -0
- package/dist/cjs/index.js +133 -0
- package/dist/cjs/server-global-vars.js +113 -0
- package/dist/esm/client-artifacts.mjs +65 -0
- package/dist/esm/compile.mjs +25 -0
- package/dist/esm/cross-project.mjs +44 -0
- package/dist/esm/generated-entries.mjs +54 -0
- package/dist/esm/hono-client-codegen.mjs +59 -0
- package/dist/esm/index.mjs +93 -0
- package/dist/esm/server-global-vars.mjs +72 -0
- package/dist/esm-node/client-artifacts.mjs +66 -0
- package/dist/esm-node/compile.mjs +26 -0
- package/dist/esm-node/cross-project.mjs +45 -0
- package/dist/esm-node/generated-entries.mjs +56 -0
- package/dist/esm-node/hono-client-codegen.mjs +61 -0
- package/dist/esm-node/index.mjs +95 -0
- package/dist/esm-node/server-global-vars.mjs +73 -0
- package/dist/types/client-artifacts.d.ts +12 -0
- package/dist/types/compile.d.ts +3 -0
- package/dist/types/cross-project.d.ts +11 -0
- package/dist/types/generated-entries.d.ts +4 -0
- package/dist/types/hono-client-codegen.d.ts +2 -0
- package/dist/types/index.d.ts +4 -0
- package/dist/types/server-global-vars.d.ts +6 -0
- package/package.json +104 -8
- package/src/client-artifacts.ts +101 -0
- package/src/compile.ts +37 -0
- package/src/cross-project.ts +72 -0
- package/src/generated-entries.ts +100 -0
- package/src/hono-client-codegen.ts +83 -0
- package/src/index.ts +131 -0
- package/src/server-global-vars.ts +145 -0
- package/README.md +0 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2021-present Modern.js
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __webpack_require__ = {};
|
|
3
|
+
(()=>{
|
|
4
|
+
__webpack_require__.d = (exports1, getters, values)=>{
|
|
5
|
+
var define = (defs, kind)=>{
|
|
6
|
+
for(var key in defs)if (__webpack_require__.o(defs, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
[kind]: defs[key]
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
define(getters, "get");
|
|
12
|
+
define(values, "value");
|
|
13
|
+
};
|
|
14
|
+
})();
|
|
15
|
+
(()=>{
|
|
16
|
+
__webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
|
|
17
|
+
})();
|
|
18
|
+
(()=>{
|
|
19
|
+
__webpack_require__.r = (exports1)=>{
|
|
20
|
+
if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
|
|
21
|
+
value: 'Module'
|
|
22
|
+
});
|
|
23
|
+
Object.defineProperty(exports1, '__esModule', {
|
|
24
|
+
value: true
|
|
25
|
+
});
|
|
26
|
+
};
|
|
27
|
+
})();
|
|
28
|
+
var __webpack_exports__ = {};
|
|
29
|
+
__webpack_require__.r(__webpack_exports__);
|
|
30
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
31
|
+
BFF_REQUEST_RUNTIME: ()=>BFF_REQUEST_RUNTIME,
|
|
32
|
+
registerBffClientArtifacts: ()=>registerBffClientArtifacts
|
|
33
|
+
});
|
|
34
|
+
const bff_core_namespaceObject = require("@modern-js/bff-core");
|
|
35
|
+
const node_namespaceObject = require("@modern-js/server-runtime-extensions/bff-policy/node");
|
|
36
|
+
const utils_namespaceObject = require("@modern-js/utils");
|
|
37
|
+
const BFF_REQUEST_RUNTIME = '@modern-js/runtime-extensions/request-policy';
|
|
38
|
+
function registerBffClientArtifacts(api, metadata) {
|
|
39
|
+
api.modifyBffClientArtifacts(async (context)=>{
|
|
40
|
+
const { generation } = context;
|
|
41
|
+
const config = api.getNormalizedConfig();
|
|
42
|
+
if ('effect' === api.getAppContext().bffRuntimeFramework) {
|
|
43
|
+
const { generateEffectClient, resolveEffectEntryPaths } = await import("@modern-js/plugin-bff-extensions/client-generator");
|
|
44
|
+
const { sourceEffectEntry, relativeEffectEntry } = resolveEffectEntryPaths({
|
|
45
|
+
appDir: generation.appDirectory,
|
|
46
|
+
apiDir: generation.apiDirectory,
|
|
47
|
+
effectEntry: config.bff?.effect?.entry
|
|
48
|
+
});
|
|
49
|
+
if (!sourceEffectEntry) throw new Error(`Cannot resolve Effect BFF entry in ${generation.apiDirectory}.`);
|
|
50
|
+
const artifacts = await generateEffectClient({
|
|
51
|
+
appDir: generation.appDirectory,
|
|
52
|
+
apiDir: generation.apiDirectory,
|
|
53
|
+
resourcePath: sourceEffectEntry,
|
|
54
|
+
prefix: generation.prefix,
|
|
55
|
+
port: Number(generation.port),
|
|
56
|
+
target: 'bundle',
|
|
57
|
+
requestId: generation.requestId,
|
|
58
|
+
requestCreator: generation.requestCreator || BFF_REQUEST_RUNTIME,
|
|
59
|
+
httpMethodDecider: generation.httpMethodDecider,
|
|
60
|
+
dataPlatformBatch: config.bff?.effect?.dataPlatform?.batch
|
|
61
|
+
});
|
|
62
|
+
if (!artifacts) throw new Error(`Effect cross-project client generation failed for ${sourceEffectEntry}.`);
|
|
63
|
+
context.additionalArtifacts.push({
|
|
64
|
+
sourcePath: utils_namespaceObject.upath.relative(generation.apiDirectory, sourceEffectEntry),
|
|
65
|
+
code: artifacts.code,
|
|
66
|
+
declaration: artifacts.declaration
|
|
67
|
+
});
|
|
68
|
+
metadata.set(generation, {
|
|
69
|
+
runtimeFramework: 'effect',
|
|
70
|
+
relativeEffectEntry,
|
|
71
|
+
operationContracts: artifacts.operationContracts,
|
|
72
|
+
effectArtifacts: artifacts
|
|
73
|
+
});
|
|
74
|
+
} else {
|
|
75
|
+
const router = new bff_core_namespaceObject.ApiRouter({
|
|
76
|
+
appDir: generation.appDirectory,
|
|
77
|
+
apiDir: generation.apiDirectory,
|
|
78
|
+
lambdaDir: generation.lambdaDirectory,
|
|
79
|
+
prefix: generation.prefix,
|
|
80
|
+
httpMethodDecider: generation.httpMethodDecider,
|
|
81
|
+
isBuild: true
|
|
82
|
+
});
|
|
83
|
+
const packageJson = await utils_namespaceObject.fs.readJSON(utils_namespaceObject.upath.join(generation.appDirectory, 'package.json'));
|
|
84
|
+
const operationContracts = generation.existLambda ? (0, node_namespaceObject.buildOperationContractMap)({
|
|
85
|
+
handlers: await router.getApiHandlers(),
|
|
86
|
+
requestId: generation.requestId,
|
|
87
|
+
operationVersion: (0, node_namespaceObject.deriveOperationVersion)(packageJson.version)
|
|
88
|
+
}) : {};
|
|
89
|
+
metadata.set(generation, {
|
|
90
|
+
runtimeFramework: 'hono',
|
|
91
|
+
relativeEffectEntry: '',
|
|
92
|
+
operationContracts
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
return context;
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
exports.BFF_REQUEST_RUNTIME = __webpack_exports__.BFF_REQUEST_RUNTIME;
|
|
99
|
+
exports.registerBffClientArtifacts = __webpack_exports__.registerBffClientArtifacts;
|
|
100
|
+
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
101
|
+
"BFF_REQUEST_RUNTIME",
|
|
102
|
+
"registerBffClientArtifacts"
|
|
103
|
+
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
104
|
+
Object.defineProperty(exports, '__esModule', {
|
|
105
|
+
value: true
|
|
106
|
+
});
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __webpack_require__ = {};
|
|
3
|
+
(()=>{
|
|
4
|
+
__webpack_require__.d = (exports1, getters, values)=>{
|
|
5
|
+
var define = (defs, kind)=>{
|
|
6
|
+
for(var key in defs)if (__webpack_require__.o(defs, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
[kind]: defs[key]
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
define(getters, "get");
|
|
12
|
+
define(values, "value");
|
|
13
|
+
};
|
|
14
|
+
})();
|
|
15
|
+
(()=>{
|
|
16
|
+
__webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
|
|
17
|
+
})();
|
|
18
|
+
(()=>{
|
|
19
|
+
__webpack_require__.r = (exports1)=>{
|
|
20
|
+
if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
|
|
21
|
+
value: 'Module'
|
|
22
|
+
});
|
|
23
|
+
Object.defineProperty(exports1, '__esModule', {
|
|
24
|
+
value: true
|
|
25
|
+
});
|
|
26
|
+
};
|
|
27
|
+
})();
|
|
28
|
+
var __webpack_exports__ = {};
|
|
29
|
+
__webpack_require__.r(__webpack_exports__);
|
|
30
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
31
|
+
registerBffCompilation: ()=>registerBffCompilation
|
|
32
|
+
});
|
|
33
|
+
const external_server_global_vars_js_namespaceObject = require("./server-global-vars.js");
|
|
34
|
+
function registerBffCompilation(api) {
|
|
35
|
+
const serialized = new WeakMap();
|
|
36
|
+
api.onBeforeBffCompile((context)=>{
|
|
37
|
+
serialized.set(context, (0, external_server_global_vars_js_namespaceObject.serializeServerGlobalVars)(api.getNormalizedConfig().source.globalVars));
|
|
38
|
+
});
|
|
39
|
+
api.onAfterBffCompile(async (context)=>{
|
|
40
|
+
const globals = serialized.get(context);
|
|
41
|
+
if (!globals) throw new Error('BFF compilation completed without its before hook.');
|
|
42
|
+
serialized.delete(context);
|
|
43
|
+
await (0, external_server_global_vars_js_namespaceObject.transformServerGlobalVars)([
|
|
44
|
+
...context.outputDirectories
|
|
45
|
+
], globals);
|
|
46
|
+
if ('effect' !== api.getAppContext().bffRuntimeFramework) return;
|
|
47
|
+
const { bundleBuiltEffectEntryForNode } = await import("@modern-js/plugin-bff-extensions/client-generator");
|
|
48
|
+
await bundleBuiltEffectEntryForNode({
|
|
49
|
+
appDir: context.appDirectory,
|
|
50
|
+
apiDir: context.apiDirectory,
|
|
51
|
+
distDir: context.distDirectory,
|
|
52
|
+
effectEntry: api.getNormalizedConfig().bff?.effect?.entry,
|
|
53
|
+
format: 'module' === context.moduleType ? 'esm' : 'cjs'
|
|
54
|
+
});
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
exports.registerBffCompilation = __webpack_exports__.registerBffCompilation;
|
|
58
|
+
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
59
|
+
"registerBffCompilation"
|
|
60
|
+
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
61
|
+
Object.defineProperty(exports, '__esModule', {
|
|
62
|
+
value: true
|
|
63
|
+
});
|
|
@@ -0,0 +1,92 @@
|
|
|
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, getters, values)=>{
|
|
14
|
+
var define = (defs, kind)=>{
|
|
15
|
+
for(var key in defs)if (__webpack_require__.o(defs, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
|
|
16
|
+
enumerable: true,
|
|
17
|
+
[kind]: defs[key]
|
|
18
|
+
});
|
|
19
|
+
};
|
|
20
|
+
define(getters, "get");
|
|
21
|
+
define(values, "value");
|
|
22
|
+
};
|
|
23
|
+
})();
|
|
24
|
+
(()=>{
|
|
25
|
+
__webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
|
|
26
|
+
})();
|
|
27
|
+
(()=>{
|
|
28
|
+
__webpack_require__.r = (exports1)=>{
|
|
29
|
+
if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
|
|
30
|
+
value: 'Module'
|
|
31
|
+
});
|
|
32
|
+
Object.defineProperty(exports1, '__esModule', {
|
|
33
|
+
value: true
|
|
34
|
+
});
|
|
35
|
+
};
|
|
36
|
+
})();
|
|
37
|
+
var __webpack_exports__ = {};
|
|
38
|
+
__webpack_require__.r(__webpack_exports__);
|
|
39
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
40
|
+
createCrossProjectBffPlugin: ()=>createCrossProjectBffPlugin
|
|
41
|
+
});
|
|
42
|
+
require("@modern-js/server-runtime-extensions/server-config");
|
|
43
|
+
const external_node_path_namespaceObject = require("node:path");
|
|
44
|
+
var external_node_path_default = /*#__PURE__*/ __webpack_require__.n(external_node_path_namespaceObject);
|
|
45
|
+
const cross_project_namespaceObject = require("@modern-js/plugin-bff/cross-project");
|
|
46
|
+
function createCrossProjectBffPlugin(descriptor) {
|
|
47
|
+
return (0, cross_project_namespaceObject.createCrossProjectApiPlugin)({
|
|
48
|
+
...descriptor.native,
|
|
49
|
+
modifyResolvedConfig: (resolvedConfig, { sdkDistDirectory, api })=>{
|
|
50
|
+
const config = api.getConfig();
|
|
51
|
+
const configuredRuntimeFramework = config?.bff?.runtimeFramework;
|
|
52
|
+
if (configuredRuntimeFramework && configuredRuntimeFramework !== descriptor.runtimeFramework) throw new Error(`[${descriptor.native.packageName}] Runtime framework mismatch for cross-project BFF. Detected "${configuredRuntimeFramework}", but producer SDK requires "${descriptor.runtimeFramework}".`);
|
|
53
|
+
const effectEntry = descriptor.relativeEffectEntry ? external_node_path_default().join(sdkDistDirectory, descriptor.relativeEffectEntry) : void 0;
|
|
54
|
+
api.updateAppContext({
|
|
55
|
+
...effectEntry ? {
|
|
56
|
+
apiDirectory: external_node_path_default().dirname(effectEntry)
|
|
57
|
+
} : {},
|
|
58
|
+
bffRuntimeFramework: descriptor.runtimeFramework
|
|
59
|
+
});
|
|
60
|
+
resolvedConfig.bff ??= {};
|
|
61
|
+
resolvedConfig.bff.runtimeFramework = descriptor.runtimeFramework;
|
|
62
|
+
if (effectEntry) resolvedConfig.bff.effect = {
|
|
63
|
+
...resolvedConfig.bff.effect,
|
|
64
|
+
entry: effectEntry
|
|
65
|
+
};
|
|
66
|
+
resolvedConfig.bff.requestId = resolvedConfig.bff.requestId || config?.bff?.requestId || descriptor.requestId || descriptor.native.packageName || 'default';
|
|
67
|
+
const policy = resolvedConfig.bff.crossProjectPolicy;
|
|
68
|
+
resolvedConfig.bff.crossProjectPolicy = {
|
|
69
|
+
...policy,
|
|
70
|
+
enabled: policy?.enabled ?? true,
|
|
71
|
+
requireEnvelope: policy?.requireEnvelope ?? true,
|
|
72
|
+
requireOperationContext: policy?.requireOperationContext ?? true,
|
|
73
|
+
requireOperationContextDetails: policy?.requireOperationContextDetails ?? true,
|
|
74
|
+
requireOperationSchemaHash: policy?.requireOperationSchemaHash ?? true,
|
|
75
|
+
requireOperationVersion: policy?.requireOperationVersion ?? true,
|
|
76
|
+
allowUnknownOperations: policy?.allowUnknownOperations ?? false,
|
|
77
|
+
expectedOperationContracts: {
|
|
78
|
+
...policy?.expectedOperationContracts,
|
|
79
|
+
...descriptor.operationContracts
|
|
80
|
+
}
|
|
81
|
+
};
|
|
82
|
+
return resolvedConfig;
|
|
83
|
+
}
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
exports.createCrossProjectBffPlugin = __webpack_exports__.createCrossProjectBffPlugin;
|
|
87
|
+
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
88
|
+
"createCrossProjectBffPlugin"
|
|
89
|
+
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
90
|
+
Object.defineProperty(exports, '__esModule', {
|
|
91
|
+
value: true
|
|
92
|
+
});
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __webpack_require__ = {};
|
|
3
|
+
(()=>{
|
|
4
|
+
__webpack_require__.d = (exports1, getters, values)=>{
|
|
5
|
+
var define = (defs, kind)=>{
|
|
6
|
+
for(var key in defs)if (__webpack_require__.o(defs, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
[kind]: defs[key]
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
define(getters, "get");
|
|
12
|
+
define(values, "value");
|
|
13
|
+
};
|
|
14
|
+
})();
|
|
15
|
+
(()=>{
|
|
16
|
+
__webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
|
|
17
|
+
})();
|
|
18
|
+
(()=>{
|
|
19
|
+
__webpack_require__.r = (exports1)=>{
|
|
20
|
+
if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
|
|
21
|
+
value: 'Module'
|
|
22
|
+
});
|
|
23
|
+
Object.defineProperty(exports1, '__esModule', {
|
|
24
|
+
value: true
|
|
25
|
+
});
|
|
26
|
+
};
|
|
27
|
+
})();
|
|
28
|
+
var __webpack_exports__ = {};
|
|
29
|
+
__webpack_require__.r(__webpack_exports__);
|
|
30
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
31
|
+
registerBffGeneratedEntries: ()=>registerBffGeneratedEntries
|
|
32
|
+
});
|
|
33
|
+
const external_node_url_namespaceObject = require("node:url");
|
|
34
|
+
const utils_namespaceObject = require("@modern-js/utils");
|
|
35
|
+
const external_client_artifacts_js_namespaceObject = require("./client-artifacts.js");
|
|
36
|
+
function registerBffGeneratedEntries(api, metadata) {
|
|
37
|
+
api.modifyBffGeneratedEntries(async (entries)=>{
|
|
38
|
+
const { generation } = entries;
|
|
39
|
+
const details = metadata.get(generation);
|
|
40
|
+
if (!details) throw new Error('BFF entries require completed client artifact generation.');
|
|
41
|
+
metadata.delete(generation);
|
|
42
|
+
const packageJson = await utils_namespaceObject.fs.readJSON(utils_namespaceObject.upath.join(generation.appDirectory, 'package.json'));
|
|
43
|
+
const runtimeSpecifier = api.getNormalizedConfig().bff?.runtimeCreateRequest || external_client_artifacts_js_namespaceObject.BFF_REQUEST_RUNTIME;
|
|
44
|
+
const dependencies = [
|
|
45
|
+
'@modern-js/plugin-bff-build-extensions',
|
|
46
|
+
'@modern-js/plugin-bff-extensions'
|
|
47
|
+
];
|
|
48
|
+
const emitsClient = 'effect' === details.runtimeFramework || generation.apiFiles.length > 0;
|
|
49
|
+
if (runtimeSpecifier === external_client_artifacts_js_namespaceObject.BFF_REQUEST_RUNTIME || emitsClient && (generation.requestCreator || external_client_artifacts_js_namespaceObject.BFF_REQUEST_RUNTIME) === external_client_artifacts_js_namespaceObject.BFF_REQUEST_RUNTIME) dependencies.push('@modern-js/runtime-extensions');
|
|
50
|
+
for (const name of dependencies){
|
|
51
|
+
const specifier = packageJson.dependencies?.[name] || packageJson.devDependencies?.[name] || utils_namespaceObject.fs.readJSONSync(require.resolve(`${name}/package.json`)).version;
|
|
52
|
+
entries.packageDependencies[name] = specifier;
|
|
53
|
+
}
|
|
54
|
+
const descriptor = {
|
|
55
|
+
native: {
|
|
56
|
+
packageName: packageJson.name,
|
|
57
|
+
prefix: generation.prefix,
|
|
58
|
+
relativeDistPath: utils_namespaceObject.upath.normalize(generation.relativeDistPath),
|
|
59
|
+
relativeApiPath: utils_namespaceObject.upath.relative(generation.appDirectory, generation.apiDirectory),
|
|
60
|
+
relativeLambdaPath: utils_namespaceObject.upath.relative(generation.appDirectory, generation.lambdaDirectory)
|
|
61
|
+
},
|
|
62
|
+
runtimeFramework: details.runtimeFramework,
|
|
63
|
+
relativeEffectEntry: details.relativeEffectEntry,
|
|
64
|
+
requestId: generation.requestId,
|
|
65
|
+
operationContracts: details.operationContracts
|
|
66
|
+
};
|
|
67
|
+
const isModule = 'module' === api.getAppContext().moduleType || 'module' === packageJson.type;
|
|
68
|
+
entries.plugin = {
|
|
69
|
+
code: isModule ? `import { createCrossProjectBffPlugin } from '@modern-js/plugin-bff-build-extensions/cross-project';\nexport const crossProjectApiPlugin = () => createCrossProjectBffPlugin(${JSON.stringify(descriptor)});\n` : `'use strict';\nconst { createCrossProjectBffPlugin } = require('@modern-js/plugin-bff-build-extensions/cross-project');\nexports.crossProjectApiPlugin = () => createCrossProjectBffPlugin(${JSON.stringify(descriptor)});\n`,
|
|
70
|
+
declaration: `import type { AppTools, CliPlugin } from '@modern-js/app-tools';
|
|
71
|
+
export declare const crossProjectApiPlugin: () => CliPlugin<AppTools>;
|
|
72
|
+
`
|
|
73
|
+
};
|
|
74
|
+
const runtime = JSON.stringify(runtimeSpecifier);
|
|
75
|
+
const esmRuntime = JSON.stringify(utils_namespaceObject.upath.isAbsolute(runtimeSpecifier) ? (0, external_node_url_namespaceObject.pathToFileURL)(runtimeSpecifier).href : runtimeSpecifier);
|
|
76
|
+
entries.runtime = {
|
|
77
|
+
code: isModule ? `import { configure as _configure } from ${esmRuntime};\nimport { createProducerClient } from '@modern-js/plugin-bff-extensions/producer-runtime';\nexport const configure = createProducerClient(_configure, { requestId: ${JSON.stringify(generation.requestId)} });\nexport const initProducerClient = configure;\n` : `'use strict';\nconst { configure: _configure } = require(${runtime});\nconst { createProducerClient } = require('@modern-js/plugin-bff-extensions/producer-runtime');\nconst configure = createProducerClient(_configure, { requestId: ${JSON.stringify(generation.requestId)} });\nexports.configure = configure;\nexports.initProducerClient = configure;\n`,
|
|
78
|
+
declaration: `type Runtime = typeof import(${runtime});
|
|
79
|
+
export declare const initProducerClient: (options?: Parameters<Runtime['configure']>[0]) => ReturnType<Runtime['configure']>;
|
|
80
|
+
export declare const configure: typeof initProducerClient;
|
|
81
|
+
`
|
|
82
|
+
};
|
|
83
|
+
return entries;
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
exports.registerBffGeneratedEntries = __webpack_exports__.registerBffGeneratedEntries;
|
|
87
|
+
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
88
|
+
"registerBffGeneratedEntries"
|
|
89
|
+
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
90
|
+
Object.defineProperty(exports, '__esModule', {
|
|
91
|
+
value: true
|
|
92
|
+
});
|
|
@@ -0,0 +1,107 @@
|
|
|
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, getters, values)=>{
|
|
14
|
+
var define = (defs, kind)=>{
|
|
15
|
+
for(var key in defs)if (__webpack_require__.o(defs, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
|
|
16
|
+
enumerable: true,
|
|
17
|
+
[kind]: defs[key]
|
|
18
|
+
});
|
|
19
|
+
};
|
|
20
|
+
define(getters, "get");
|
|
21
|
+
define(values, "value");
|
|
22
|
+
};
|
|
23
|
+
})();
|
|
24
|
+
(()=>{
|
|
25
|
+
__webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
|
|
26
|
+
})();
|
|
27
|
+
(()=>{
|
|
28
|
+
__webpack_require__.r = (exports1)=>{
|
|
29
|
+
if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
|
|
30
|
+
value: 'Module'
|
|
31
|
+
});
|
|
32
|
+
Object.defineProperty(exports1, '__esModule', {
|
|
33
|
+
value: true
|
|
34
|
+
});
|
|
35
|
+
};
|
|
36
|
+
})();
|
|
37
|
+
var __webpack_exports__ = {};
|
|
38
|
+
__webpack_require__.r(__webpack_exports__);
|
|
39
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
40
|
+
modifyClient: ()=>modifyClient
|
|
41
|
+
});
|
|
42
|
+
const external_node_path_namespaceObject = require("node:path");
|
|
43
|
+
var external_node_path_default = /*#__PURE__*/ __webpack_require__.n(external_node_path_namespaceObject);
|
|
44
|
+
const node_namespaceObject = require("@modern-js/server-runtime-extensions/bff-policy/node");
|
|
45
|
+
const REQUEST_RUNTIME = '@modern-js/runtime-extensions/request-policy';
|
|
46
|
+
const modifyClient = (draft, context)=>{
|
|
47
|
+
const { appDir, requestId } = context.options;
|
|
48
|
+
draft.requestCreator = context.options.requestCreator || REQUEST_RUNTIME;
|
|
49
|
+
let version;
|
|
50
|
+
try {
|
|
51
|
+
version = require(external_node_path_default().resolve(appDir, 'package.json')).version;
|
|
52
|
+
} catch {}
|
|
53
|
+
const operationVersion = (0, node_namespaceObject.deriveOperationVersion)(version);
|
|
54
|
+
const normalizedRequestId = requestId || 'default';
|
|
55
|
+
const operationContracts = (0, node_namespaceObject.buildOperationContractMap)({
|
|
56
|
+
handlers: [
|
|
57
|
+
...context.handlerInfos
|
|
58
|
+
],
|
|
59
|
+
requestId: normalizedRequestId,
|
|
60
|
+
operationVersion
|
|
61
|
+
});
|
|
62
|
+
const operationEntries = context.handlerInfos.map((handlerInfo)=>{
|
|
63
|
+
const httpMethod = handlerInfo.httpMethod.toUpperCase();
|
|
64
|
+
return {
|
|
65
|
+
name: handlerInfo.name,
|
|
66
|
+
httpMethod,
|
|
67
|
+
routePath: handlerInfo.routePath,
|
|
68
|
+
schemaHash: operationContracts[`${httpMethod}:${handlerInfo.routePath}`]?.schemaHash ?? ''
|
|
69
|
+
};
|
|
70
|
+
}).sort((a, b)=>`${a.routePath}:${a.httpMethod}:${a.name}`.localeCompare(`${b.routePath}:${b.httpMethod}:${b.name}`));
|
|
71
|
+
const schemaHash = (0, node_namespaceObject.createOperationSchemaHash)(operationEntries, normalizedRequestId);
|
|
72
|
+
for (const { handlerInfo, optionProperties } of draft.handlers){
|
|
73
|
+
if ('upload' === handlerInfo.action && !requestId) continue;
|
|
74
|
+
const method = handlerInfo.httpMethod.toUpperCase();
|
|
75
|
+
const operationContext = {
|
|
76
|
+
operationId: handlerInfo.name,
|
|
77
|
+
routePath: handlerInfo.routePath,
|
|
78
|
+
method,
|
|
79
|
+
schemaHash: operationContracts[`${method}:${handlerInfo.routePath}`]?.schemaHash ?? '',
|
|
80
|
+
operationVersion
|
|
81
|
+
};
|
|
82
|
+
optionProperties.push(`operationContext: ${JSON.stringify(operationContext)}`);
|
|
83
|
+
}
|
|
84
|
+
if (requestId) {
|
|
85
|
+
draft.imports.push(`import * as requestRuntime from ${JSON.stringify(draft.requestCreator)};`, 'import { createProducerClient } from "@modern-js/plugin-bff-extensions/producer-runtime";');
|
|
86
|
+
draft.statements.push(`export const initProducerClient = (options = {}) => {
|
|
87
|
+
const configure = requestRuntime.configure;
|
|
88
|
+
if (typeof configure !== 'function') {
|
|
89
|
+
console.warn('[modernjs] Compatibility request creator path does not expose configure(); use default @modern-js/create-request or migrate the compatibility path.');
|
|
90
|
+
return undefined;
|
|
91
|
+
}
|
|
92
|
+
return createProducerClient(configure, { requestId: ${JSON.stringify(requestId)} })(options);
|
|
93
|
+
};`);
|
|
94
|
+
}
|
|
95
|
+
draft.statements.push(`export const operationVersion = ${String(operationVersion)};`, `export const operationSchemaHash = ${JSON.stringify(schemaHash)};`, `export const operationManifest = ${JSON.stringify({
|
|
96
|
+
operationVersion,
|
|
97
|
+
schemaHash,
|
|
98
|
+
operations: operationEntries
|
|
99
|
+
}, null, 2)};`);
|
|
100
|
+
};
|
|
101
|
+
exports.modifyClient = __webpack_exports__.modifyClient;
|
|
102
|
+
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
103
|
+
"modifyClient"
|
|
104
|
+
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
105
|
+
Object.defineProperty(exports, '__esModule', {
|
|
106
|
+
value: true
|
|
107
|
+
});
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __webpack_require__ = {};
|
|
3
|
+
(()=>{
|
|
4
|
+
__webpack_require__.d = (exports1, getters, values)=>{
|
|
5
|
+
var define = (defs, kind)=>{
|
|
6
|
+
for(var key in defs)if (__webpack_require__.o(defs, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
[kind]: defs[key]
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
define(getters, "get");
|
|
12
|
+
define(values, "value");
|
|
13
|
+
};
|
|
14
|
+
})();
|
|
15
|
+
(()=>{
|
|
16
|
+
__webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
|
|
17
|
+
})();
|
|
18
|
+
(()=>{
|
|
19
|
+
__webpack_require__.r = (exports1)=>{
|
|
20
|
+
if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
|
|
21
|
+
value: 'Module'
|
|
22
|
+
});
|
|
23
|
+
Object.defineProperty(exports1, '__esModule', {
|
|
24
|
+
value: true
|
|
25
|
+
});
|
|
26
|
+
};
|
|
27
|
+
})();
|
|
28
|
+
var __webpack_exports__ = {};
|
|
29
|
+
__webpack_require__.r(__webpack_exports__);
|
|
30
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
31
|
+
bffPlugin: ()=>bffPlugin,
|
|
32
|
+
default: ()=>src
|
|
33
|
+
});
|
|
34
|
+
require("@modern-js/server-runtime-extensions/server-config");
|
|
35
|
+
const plugin_bff_namespaceObject = require("@modern-js/plugin-bff");
|
|
36
|
+
const utils_namespaceObject = require("@modern-js/utils");
|
|
37
|
+
const external_client_artifacts_js_namespaceObject = require("./client-artifacts.js");
|
|
38
|
+
const external_compile_js_namespaceObject = require("./compile.js");
|
|
39
|
+
const external_generated_entries_js_namespaceObject = require("./generated-entries.js");
|
|
40
|
+
const bffPlugin = ()=>({
|
|
41
|
+
name: '@modern-js/plugin-bff-build-extensions',
|
|
42
|
+
usePlugins: [
|
|
43
|
+
(0, plugin_bff_namespaceObject.bffPlugin)()
|
|
44
|
+
],
|
|
45
|
+
pre: [
|
|
46
|
+
'@modern-js/plugin-bff'
|
|
47
|
+
],
|
|
48
|
+
setup: (api)=>{
|
|
49
|
+
const hooks = api.getHooks();
|
|
50
|
+
for (const name of [
|
|
51
|
+
'onBeforeBffCompile',
|
|
52
|
+
'onAfterBffCompile',
|
|
53
|
+
'modifyBffClientArtifacts',
|
|
54
|
+
'modifyBffGeneratedEntries'
|
|
55
|
+
])if ('function' != typeof hooks[name]?.tap) throw new Error(`Native BFF build hook ${name} is unavailable.`);
|
|
56
|
+
api.config(()=>({
|
|
57
|
+
bff: {
|
|
58
|
+
requestCreator: external_client_artifacts_js_namespaceObject.BFF_REQUEST_RUNTIME,
|
|
59
|
+
runtimeCreateRequest: external_client_artifacts_js_namespaceObject.BFF_REQUEST_RUNTIME,
|
|
60
|
+
clientCodegenPlugin: require.resolve('@modern-js/plugin-bff-build-extensions/hono-client-codegen')
|
|
61
|
+
}
|
|
62
|
+
}));
|
|
63
|
+
const runtimeFramework = api.getConfig()?.bff?.runtimeFramework;
|
|
64
|
+
if (void 0 !== runtimeFramework && 'hono' !== runtimeFramework && 'effect' !== runtimeFramework) throw new Error(`Unsupported Effect BFF runtime "${runtimeFramework}".`);
|
|
65
|
+
api.updateAppContext({
|
|
66
|
+
bffRuntimeFramework: runtimeFramework ?? 'effect'
|
|
67
|
+
});
|
|
68
|
+
api._internalServerPlugins(({ plugins })=>{
|
|
69
|
+
const nativePlugins = plugins.filter((plugin)=>'@modern-js/plugin-bff/server-plugin' === plugin.name);
|
|
70
|
+
if (1 !== nativePlugins.length) throw new Error('Expected exactly one native BFF server plugin.');
|
|
71
|
+
const native = nativePlugins[0];
|
|
72
|
+
const runtimeAdapters = native.options?.runtimeAdapters ?? {};
|
|
73
|
+
const effect = '@modern-js/plugin-bff-extensions/effect-adapter';
|
|
74
|
+
const honoRouteBinder = '@modern-js/plugin-bff-extensions/hono/node';
|
|
75
|
+
if (native.options?.honoRouteBinder !== void 0 && native.options.honoRouteBinder !== honoRouteBinder) throw new Error('The Hono BFF route binder is already configured.');
|
|
76
|
+
if (void 0 !== runtimeAdapters.effect && runtimeAdapters.effect !== effect) throw new Error('The Effect BFF runtime adapter is already configured.');
|
|
77
|
+
native.options = {
|
|
78
|
+
...native.options,
|
|
79
|
+
honoRouteBinder,
|
|
80
|
+
runtimeAdapters: {
|
|
81
|
+
...runtimeAdapters,
|
|
82
|
+
effect
|
|
83
|
+
}
|
|
84
|
+
};
|
|
85
|
+
return {
|
|
86
|
+
plugins
|
|
87
|
+
};
|
|
88
|
+
});
|
|
89
|
+
const metadata = new WeakMap();
|
|
90
|
+
(0, external_compile_js_namespaceObject.registerBffCompilation)(api);
|
|
91
|
+
(0, external_client_artifacts_js_namespaceObject.registerBffClientArtifacts)(api, metadata);
|
|
92
|
+
(0, external_generated_entries_js_namespaceObject.registerBffGeneratedEntries)(api, metadata);
|
|
93
|
+
api.modifyBundlerChain(async (chain, { isServer, CHAIN_ID })=>{
|
|
94
|
+
if ('effect' !== api.getAppContext().bffRuntimeFramework) return;
|
|
95
|
+
const { appDirectory, apiDirectory, port } = api.getAppContext();
|
|
96
|
+
const bff = api.getNormalizedConfig().bff;
|
|
97
|
+
const { resolveEffectEntryFile } = await import("@modern-js/plugin-bff-extensions/client-generator");
|
|
98
|
+
const entry = resolveEffectEntryFile({
|
|
99
|
+
appDir: appDirectory,
|
|
100
|
+
apiDir: apiDirectory,
|
|
101
|
+
effectEntry: bff?.effect?.entry
|
|
102
|
+
});
|
|
103
|
+
if (!entry) throw new Error(`Cannot resolve Effect BFF entry in ${apiDirectory}.`);
|
|
104
|
+
const canonical = (file)=>utils_namespaceObject.upath.normalize(utils_namespaceObject.fs.existsSync(file) ? utils_namespaceObject.fs.realpathSync(file) : utils_namespaceObject.upath.resolve(file));
|
|
105
|
+
const entryPath = canonical(entry);
|
|
106
|
+
const isEntry = (resource)=>canonical(resource) === entryPath;
|
|
107
|
+
chain.module.rule(CHAIN_ID.RULE.JS).exclude.add(isEntry);
|
|
108
|
+
chain.module.rule('js-bff-api').exclude.add(isEntry);
|
|
109
|
+
chain.module.rule('js-bff-effect-entry').test(isEntry).use('effect-bff-loader').loader(require.resolve('@modern-js/plugin-bff-extensions/effect-source-loader/rspack-loader')).options({
|
|
110
|
+
appDir: appDirectory,
|
|
111
|
+
apiDir: apiDirectory,
|
|
112
|
+
effectEntry: entry,
|
|
113
|
+
prefix: Array.isArray(bff?.prefix) ? bff.prefix[0] : bff?.prefix || '/api',
|
|
114
|
+
port,
|
|
115
|
+
target: isServer ? 'server' : 'client',
|
|
116
|
+
requestId: bff?.requestId,
|
|
117
|
+
requestCreator: bff?.requestCreator || external_client_artifacts_js_namespaceObject.BFF_REQUEST_RUNTIME,
|
|
118
|
+
httpMethodDecider: bff?.httpMethodDecider,
|
|
119
|
+
effectDataPlatformBatch: bff?.effect?.dataPlatform?.batch
|
|
120
|
+
});
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
});
|
|
124
|
+
const src = bffPlugin;
|
|
125
|
+
exports.bffPlugin = __webpack_exports__.bffPlugin;
|
|
126
|
+
exports["default"] = __webpack_exports__["default"];
|
|
127
|
+
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
128
|
+
"bffPlugin",
|
|
129
|
+
"default"
|
|
130
|
+
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
131
|
+
Object.defineProperty(exports, '__esModule', {
|
|
132
|
+
value: true
|
|
133
|
+
});
|