@bleedingdev/modern-js-plugin-bff-extensions 3.9.0-ultramodern.5 → 3.9.0-ultramodern.6

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.
Files changed (104) hide show
  1. package/README.md +6 -3
  2. package/dist/cjs/backend-federation/edge-runtime.js +3 -15
  3. package/dist/cjs/backend-federation/edge.js +2 -3
  4. package/dist/cjs/backend-federation/identity.js +17 -23
  5. package/dist/cjs/backend-federation/load.js +1 -11
  6. package/dist/cjs/backend-federation/validate-loaded.js +2 -4
  7. package/dist/cjs/backend-federation-manifest/load.js +9 -7
  8. package/dist/cjs/backend-federation-manifest/validation.js +4 -4
  9. package/dist/cjs/{client-generator → effect-source-loader}/built-entry.js +1 -1
  10. package/dist/cjs/{client-generator/runtime.js → effect-source-loader/http-api-runtime.js} +12 -20
  11. package/dist/cjs/effect-source-loader/index.js +14 -6
  12. package/dist/cjs/effect-source-loader/operation-contracts.js +83 -0
  13. package/dist/cjs/effect-source-loader/rspack-loader.js +1 -17
  14. package/dist/cjs/effect-source-loader/worker-runtime-wrapper.js +6 -21
  15. package/dist/esm/backend-federation/edge-runtime.mjs +2 -11
  16. package/dist/esm/backend-federation/edge.mjs +3 -4
  17. package/dist/esm/backend-federation/identity.mjs +17 -23
  18. package/dist/esm/backend-federation/load.mjs +1 -11
  19. package/dist/esm/backend-federation/validate-loaded.mjs +2 -4
  20. package/dist/esm/backend-federation-manifest/load.mjs +9 -7
  21. package/dist/esm/backend-federation-manifest/validation.mjs +4 -4
  22. package/dist/esm/{client-generator → effect-source-loader}/built-entry.mjs +1 -1
  23. package/dist/esm/effect-source-loader/http-api-runtime.mjs +19 -0
  24. package/dist/esm/effect-source-loader/index.mjs +4 -2
  25. package/dist/esm/effect-source-loader/operation-contracts.mjs +45 -0
  26. package/dist/esm/effect-source-loader/rspack-loader.mjs +2 -18
  27. package/dist/esm/effect-source-loader/worker-runtime-wrapper.mjs +4 -16
  28. package/dist/esm-node/backend-federation/edge-runtime.mjs +2 -11
  29. package/dist/esm-node/backend-federation/edge.mjs +3 -4
  30. package/dist/esm-node/backend-federation/identity.mjs +17 -23
  31. package/dist/esm-node/backend-federation/load.mjs +1 -11
  32. package/dist/esm-node/backend-federation/validate-loaded.mjs +2 -4
  33. package/dist/esm-node/backend-federation-manifest/load.mjs +9 -7
  34. package/dist/esm-node/backend-federation-manifest/validation.mjs +4 -4
  35. package/dist/esm-node/{client-generator → effect-source-loader}/built-entry.mjs +1 -1
  36. package/dist/esm-node/effect-source-loader/http-api-runtime.mjs +20 -0
  37. package/dist/esm-node/effect-source-loader/index.mjs +4 -2
  38. package/dist/esm-node/effect-source-loader/operation-contracts.mjs +46 -0
  39. package/dist/esm-node/effect-source-loader/rspack-loader.mjs +2 -18
  40. package/dist/esm-node/effect-source-loader/worker-runtime-wrapper.mjs +4 -16
  41. package/dist/types/backend-federation/edge-runtime.d.ts +0 -5
  42. package/dist/types/backend-federation/edge.d.ts +0 -2
  43. package/dist/types/backend-federation/identity.d.ts +2 -11
  44. package/dist/types/backend-federation/load.d.ts +1 -7
  45. package/dist/types/backend-federation/node.d.ts +1 -3
  46. package/dist/types/backend-federation/types.d.ts +0 -6
  47. package/dist/types/backend-federation/validate-loaded.d.ts +1 -2
  48. package/dist/types/backend-federation-manifest/metadata.d.ts +0 -6
  49. package/dist/types/effect-source-loader/index.d.ts +4 -2
  50. package/dist/types/effect-source-loader/operation-contracts.d.ts +8 -0
  51. package/dist/types/effect-source-loader/rspack-loader.d.ts +0 -14
  52. package/dist/types/effect-source-loader/worker-runtime-wrapper.d.ts +4 -22
  53. package/package.json +10 -22
  54. package/src/backend-federation/edge-runtime.ts +2 -13
  55. package/src/backend-federation/edge.ts +8 -16
  56. package/src/backend-federation/identity.ts +9 -27
  57. package/src/backend-federation/load.ts +6 -33
  58. package/src/backend-federation/node.ts +0 -11
  59. package/src/backend-federation/types.ts +0 -6
  60. package/src/backend-federation/validate-loaded.ts +2 -7
  61. package/src/backend-federation-manifest/load.ts +20 -14
  62. package/src/backend-federation-manifest/metadata.ts +0 -6
  63. package/src/backend-federation-manifest/validation.ts +9 -12
  64. package/src/{client-generator → effect-source-loader}/built-entry.ts +1 -3
  65. package/src/effect-source-loader/http-api-runtime.ts +39 -0
  66. package/src/effect-source-loader/index.ts +7 -5
  67. package/src/effect-source-loader/operation-contracts.ts +72 -0
  68. package/src/effect-source-loader/rspack-loader.ts +3 -33
  69. package/src/effect-source-loader/worker-runtime-wrapper.ts +4 -46
  70. package/dist/cjs/backend-federation/legacy-warning.js +0 -40
  71. package/dist/cjs/client-generator/generator.js +0 -73
  72. package/dist/cjs/client-generator/index.js +0 -54
  73. package/dist/cjs/client-generator/rendering.js +0 -253
  74. package/dist/cjs/client-generator/types.js +0 -18
  75. package/dist/esm/backend-federation/legacy-warning.mjs +0 -2
  76. package/dist/esm/client-generator/generator.mjs +0 -32
  77. package/dist/esm/client-generator/index.mjs +0 -3
  78. package/dist/esm/client-generator/rendering.mjs +0 -209
  79. package/dist/esm/client-generator/runtime.mjs +0 -27
  80. package/dist/esm/client-generator/types.mjs +0 -0
  81. package/dist/esm-node/backend-federation/legacy-warning.mjs +0 -3
  82. package/dist/esm-node/client-generator/generator.mjs +0 -33
  83. package/dist/esm-node/client-generator/index.mjs +0 -4
  84. package/dist/esm-node/client-generator/rendering.mjs +0 -210
  85. package/dist/esm-node/client-generator/runtime.mjs +0 -29
  86. package/dist/esm-node/client-generator/types.mjs +0 -1
  87. package/dist/types/backend-federation/legacy-warning.d.ts +0 -1
  88. package/dist/types/client-generator/generator.d.ts +0 -3
  89. package/dist/types/client-generator/index.d.ts +0 -4
  90. package/dist/types/client-generator/rendering.d.ts +0 -24
  91. package/dist/types/client-generator/types.d.ts +0 -33
  92. package/src/backend-federation/legacy-warning.ts +0 -2
  93. package/src/client-generator/generator.ts +0 -52
  94. package/src/client-generator/index.ts +0 -10
  95. package/src/client-generator/rendering.ts +0 -307
  96. package/src/client-generator/runtime.ts +0 -69
  97. package/src/client-generator/types.ts +0 -35
  98. /package/dist/cjs/{client-generator → effect-source-loader}/paths.js +0 -0
  99. /package/dist/esm/{client-generator → effect-source-loader}/paths.mjs +0 -0
  100. /package/dist/esm-node/{client-generator → effect-source-loader}/paths.mjs +0 -0
  101. /package/dist/types/{client-generator → effect-source-loader}/built-entry.d.ts +0 -0
  102. /package/dist/types/{client-generator/runtime.d.ts → effect-source-loader/http-api-runtime.d.ts} +0 -0
  103. /package/dist/types/{client-generator → effect-source-loader}/paths.d.ts +0 -0
  104. /package/src/{client-generator → effect-source-loader}/paths.ts +0 -0
@@ -1,253 +0,0 @@
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
- createEffectClientGeneration: ()=>createEffectClientGeneration,
32
- renderEffectClientCode: ()=>renderEffectClientCode,
33
- renderEffectClientDeclaration: ()=>renderEffectClientDeclaration
34
- });
35
- const effect_namespaceObject = require("@modern-js/bff-effect/effect");
36
- const node_namespaceObject = require("@modern-js/server-runtime-extensions/bff-policy/node");
37
- const utils_namespaceObject = require("@modern-js/utils");
38
- const DEFAULT_REQUEST_CREATOR = '@modern-js/plugin-bff/client';
39
- const EFFECT_CLIENT_RUNTIME_IMPORT = '@modern-js/bff-effect/effect-client-runtime';
40
- function isAbsoluteUrl(value) {
41
- try {
42
- new URL(value);
43
- return true;
44
- } catch {
45
- return false;
46
- }
47
- }
48
- function resolveBatchEndpoint(prefix, endpoint) {
49
- const value = void 0 === endpoint || '' === endpoint ? '/_data/batch' : endpoint;
50
- if (isAbsoluteUrl(value)) return value;
51
- const normalizedPrefix = (0, effect_namespaceObject.normalizeEffectPrefix)(prefix);
52
- const normalizedEndpoint = (0, effect_namespaceObject.ensureLeadingSlash)(value);
53
- if ('' === normalizedPrefix) return normalizedEndpoint;
54
- if (normalizedEndpoint === normalizedPrefix || normalizedEndpoint.startsWith(`${normalizedPrefix}/`)) return normalizedEndpoint;
55
- return `${normalizedPrefix}${'/' === normalizedEndpoint ? '' : normalizedEndpoint}`;
56
- }
57
- function getPackageInfo(resourcePath, appDir, onDependency) {
58
- for (const startDir of [
59
- utils_namespaceObject.upath.dirname(resourcePath),
60
- appDir
61
- ]){
62
- let current = utils_namespaceObject.upath.resolve(startDir);
63
- for(let depth = 0; depth < 32; depth += 1){
64
- const packageJsonPath = utils_namespaceObject.upath.join(current, 'package.json');
65
- if (utils_namespaceObject.fs.existsSync(packageJsonPath)) {
66
- onDependency?.(packageJsonPath);
67
- try {
68
- const packageJson = utils_namespaceObject.fs.readJSONSync(packageJsonPath);
69
- return {
70
- name: packageJson.name,
71
- version: packageJson.version
72
- };
73
- } catch {
74
- return {};
75
- }
76
- }
77
- const parent = utils_namespaceObject.upath.dirname(current);
78
- if (parent === current) break;
79
- current = parent;
80
- }
81
- }
82
- return {};
83
- }
84
- function renderEffectClientCode(generation) {
85
- const { config, manifest } = generation;
86
- return `import * as __requestRuntime from ${JSON.stringify(generation.requestCreator)};
87
- import { createGeneratedEffectClient } from ${JSON.stringify(EFFECT_CLIENT_RUNTIME_IMPORT)};
88
-
89
- const __manifest = ${JSON.stringify(manifest, null, 2)};
90
-
91
- const __config = ${JSON.stringify(config, null, 2)};
92
-
93
- const __generated = createGeneratedEffectClient(__manifest, __config, __requestRuntime);
94
-
95
- const client = __generated.client;
96
- const operationManifest = __generated.operationManifest;
97
- const createEffectRequestContext = __generated.createEffectRequestContext;
98
- const apiModule = {
99
- client,
100
- operationManifest,
101
- createEffectRequestContext,
102
- };
103
-
104
- export { client, createEffectRequestContext, operationManifest };
105
- export default apiModule;
106
- `;
107
- }
108
- function createEffectClientGeneration(endpoints, options) {
109
- const requestCreator = options.requestCreator || DEFAULT_REQUEST_CREATOR;
110
- const httpMethodDecider = options.httpMethodDecider || 'functionName';
111
- const packageInfo = getPackageInfo(options.resourcePath, options.appDir, options.onDependency);
112
- const packageName = packageInfo.name;
113
- const dataPlatformAppNamespace = void 0 === packageName || '' === packageName ? 'unknown-app' : packageName;
114
- const requestId = 'bundle' === options.target ? void 0 !== options.requestId && '' !== options.requestId.trim() ? options.requestId.trim() : void 0 !== packageName && '' !== packageName ? packageName : void 0 : void 0;
115
- const normalizedRequestId = void 0 === requestId || '' === requestId ? 'default' : requestId;
116
- const operationVersion = (0, node_namespaceObject.deriveOperationVersion)(packageInfo.version);
117
- const batchConfig = options.dataPlatformBatch;
118
- const batchEndpoint = resolveBatchEndpoint(options.prefix, batchConfig?.endpoint);
119
- const manifest = {
120
- endpoints: endpoints.map((endpoint)=>({
121
- apiId: endpoint.apiId,
122
- group: endpoint.groupName,
123
- endpoint: endpoint.endpointName,
124
- method: endpoint.method,
125
- routePath: endpoint.routePath,
126
- schemaHash: (0, effect_namespaceObject.createEffectEndpointContractHash)(endpoint, normalizedRequestId),
127
- operationVersion
128
- }))
129
- };
130
- const config = {
131
- appNamespace: dataPlatformAppNamespace,
132
- ...void 0 !== requestId && '' !== requestId ? {
133
- requestId
134
- } : {},
135
- port: options.port,
136
- useEnvPort: 'server' === options.target,
137
- defaultOrigin: `http://localhost:${String(options.port)}`,
138
- httpMethodDecider,
139
- batch: {
140
- enabled: batchConfig?.enabled ?? true,
141
- endpoint: batchEndpoint,
142
- flushIntervalMs: batchConfig?.flushIntervalMs ?? 8,
143
- maxBatchSize: batchConfig?.maxBatchSize ?? 16,
144
- maxBatchBytes: batchConfig?.maxBatchBytes ?? 65536,
145
- requestTimeoutMs: batchConfig?.requestTimeoutMs ?? 10000,
146
- allowedMethods: batchConfig?.allowedMethods !== void 0 && batchConfig.allowedMethods.length > 0 ? batchConfig.allowedMethods : [
147
- 'GET'
148
- ]
149
- }
150
- };
151
- return {
152
- config,
153
- manifest,
154
- operationContracts: (0, node_namespaceObject.buildOperationContractMap)({
155
- handlers: (0, effect_namespaceObject.toOperationContractSources)(endpoints),
156
- requestId: normalizedRequestId,
157
- operationVersion
158
- }),
159
- operationVersion,
160
- requestCreator,
161
- requestId: normalizedRequestId
162
- };
163
- }
164
- function renderClientShape(endpoints, valueType) {
165
- if (0 === endpoints.length) return `Record<string, Record<string, ${valueType}>>`;
166
- const groups = new Map();
167
- for (const endpoint of endpoints){
168
- const group = groups.get(endpoint.groupName) || [];
169
- group.push(endpoint.endpointName);
170
- groups.set(endpoint.groupName, group);
171
- }
172
- const groupEntries = [
173
- ...groups.entries()
174
- ].map(([groupName, names])=>{
175
- const endpointEntries = names.map((name)=>` ${JSON.stringify(name)}: ${valueType};`).join('\n');
176
- return ` ${JSON.stringify(groupName)}: {\n${endpointEntries}\n };`;
177
- });
178
- return `{\n${groupEntries.join('\n')}\n}`;
179
- }
180
- function renderEffectClientDeclaration(endpoints = []) {
181
- return `export type EffectClientOperation = (
182
- request?: unknown,
183
- ) => Promise<unknown>;
184
- export type EffectClientGroup = Record<string, EffectClientOperation>;
185
- export type EffectClient = Record<string, EffectClientGroup>;
186
- export type EffectOperationDescriptor = {
187
- appNamespace: string;
188
- apiId: string;
189
- group: string;
190
- endpoint: string;
191
- operationId: string;
192
- routePath: string;
193
- method: string;
194
- operationVersion: number;
195
- schemaHash: string;
196
- version: number;
197
- };
198
- export type EffectOperationManifest = Record<
199
- string,
200
- Record<string, EffectOperationDescriptor>
201
- >;
202
- export type EffectOperationContext = {
203
- requestId?: string;
204
- operationId?: string;
205
- routePath?: string;
206
- method?: string;
207
- schemaHash?: string;
208
- operationVersion?: number;
209
- locale?: string;
210
- traceparent?: string;
211
- traceId?: string;
212
- spanId?: string;
213
- source?: string;
214
- scope?: Record<string, unknown>;
215
- sessionClaims?: Record<string, unknown>;
216
- attributes?: Record<string, unknown>;
217
- };
218
- export type EffectRequestContext = {
219
- headers?: Record<string, string>;
220
- locale?: string;
221
- operationContext?: EffectOperationContext;
222
- traceparent?: string;
223
- traceId?: string;
224
- spanId?: string;
225
- };
226
- export type GeneratedEffectClient = ${renderClientShape(endpoints, 'EffectClientOperation')};
227
- export type GeneratedEffectOperationManifest = ${renderClientShape(endpoints, "EffectOperationDescriptor")};
228
-
229
- export declare const client: GeneratedEffectClient;
230
- export declare const createEffectRequestContext: (
231
- requestContext: Record<string, unknown>,
232
- ) => EffectRequestContext;
233
- export declare const operationManifest: GeneratedEffectOperationManifest;
234
- declare const apiModule: {
235
- client: GeneratedEffectClient;
236
- createEffectRequestContext: typeof createEffectRequestContext;
237
- operationManifest: GeneratedEffectOperationManifest;
238
- };
239
-
240
- export default apiModule;
241
- `;
242
- }
243
- exports.createEffectClientGeneration = __webpack_exports__.createEffectClientGeneration;
244
- exports.renderEffectClientCode = __webpack_exports__.renderEffectClientCode;
245
- exports.renderEffectClientDeclaration = __webpack_exports__.renderEffectClientDeclaration;
246
- for(var __rspack_i in __webpack_exports__)if (-1 === [
247
- "createEffectClientGeneration",
248
- "renderEffectClientCode",
249
- "renderEffectClientDeclaration"
250
- ].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
251
- Object.defineProperty(exports, '__esModule', {
252
- value: true
253
- });
@@ -1,18 +0,0 @@
1
- "use strict";
2
- var __webpack_require__ = {};
3
- (()=>{
4
- __webpack_require__.r = (exports1)=>{
5
- if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
6
- value: 'Module'
7
- });
8
- Object.defineProperty(exports1, '__esModule', {
9
- value: true
10
- });
11
- };
12
- })();
13
- var __webpack_exports__ = {};
14
- __webpack_require__.r(__webpack_exports__);
15
- for(var __rspack_i in __webpack_exports__)exports[__rspack_i] = __webpack_exports__[__rspack_i];
16
- Object.defineProperty(exports, '__esModule', {
17
- value: true
18
- });
@@ -1,2 +0,0 @@
1
- const LEGACY_LOAD_WARNING = '[BFF][Effect] loadBackendFederatedEffectApi was called without an expected delivery-unit identity (expected.unitId + expected.buildMarker). Identity-less public backend loads are deprecated (ADR-0019/MV-G23) and will be rejected in a future major.';
2
- export { LEGACY_LOAD_WARNING };
@@ -1,32 +0,0 @@
1
- import { collectEffectEndpoints } from "@modern-js/bff-effect/effect";
2
- import { logger } from "@modern-js/utils";
3
- import { createEffectClientGeneration, renderEffectClientCode, renderEffectClientDeclaration } from "./rendering.mjs";
4
- import { getHttpApiRuntime, loadEffectApi } from "./runtime.mjs";
5
- function generateEffectClient(options) {
6
- return loadEffectApi({
7
- appDir: options.appDir,
8
- resourcePath: options.resourcePath,
9
- onDependency: options.onDependency
10
- }).then((api)=>{
11
- if (null === api) {
12
- logger.warn(`[BFF][Effect] Failed to generate client for ${options.resourcePath}: unable to resolve exported HttpApi.`);
13
- return null;
14
- }
15
- return getHttpApiRuntime().then((httpApiRuntime)=>{
16
- const endpoints = collectEffectEndpoints(httpApiRuntime.reflect, api, options.prefix);
17
- const generation = createEffectClientGeneration(endpoints, options);
18
- return {
19
- code: renderEffectClientCode(generation),
20
- declaration: renderEffectClientDeclaration(endpoints),
21
- endpoints,
22
- operationContracts: generation.operationContracts,
23
- operationVersion: generation.operationVersion,
24
- requestId: generation.requestId
25
- };
26
- });
27
- });
28
- }
29
- function generateEffectClientCode(options) {
30
- return generateEffectClient(options).then((artifacts)=>null === artifacts ? null : artifacts.code);
31
- }
32
- export { generateEffectClient, generateEffectClientCode };
@@ -1,3 +0,0 @@
1
- export { bundleBuiltEffectEntryForNode, resolveEffectEntryPaths } from "./built-entry.mjs";
2
- export { generateEffectClient, generateEffectClientCode } from "./generator.mjs";
3
- export { resolveEffectEntryFile } from "./paths.mjs";
@@ -1,209 +0,0 @@
1
- import { createEffectEndpointContractHash, ensureLeadingSlash, normalizeEffectPrefix, toOperationContractSources } from "@modern-js/bff-effect/effect";
2
- import { buildOperationContractMap, deriveOperationVersion } from "@modern-js/server-runtime-extensions/bff-policy/node";
3
- import { fs, upath } from "@modern-js/utils";
4
- const DEFAULT_REQUEST_CREATOR = '@modern-js/plugin-bff/client';
5
- const EFFECT_CLIENT_RUNTIME_IMPORT = '@modern-js/bff-effect/effect-client-runtime';
6
- function isAbsoluteUrl(value) {
7
- try {
8
- new URL(value);
9
- return true;
10
- } catch {
11
- return false;
12
- }
13
- }
14
- function resolveBatchEndpoint(prefix, endpoint) {
15
- const value = void 0 === endpoint || '' === endpoint ? '/_data/batch' : endpoint;
16
- if (isAbsoluteUrl(value)) return value;
17
- const normalizedPrefix = normalizeEffectPrefix(prefix);
18
- const normalizedEndpoint = ensureLeadingSlash(value);
19
- if ('' === normalizedPrefix) return normalizedEndpoint;
20
- if (normalizedEndpoint === normalizedPrefix || normalizedEndpoint.startsWith(`${normalizedPrefix}/`)) return normalizedEndpoint;
21
- return `${normalizedPrefix}${'/' === normalizedEndpoint ? '' : normalizedEndpoint}`;
22
- }
23
- function getPackageInfo(resourcePath, appDir, onDependency) {
24
- for (const startDir of [
25
- upath.dirname(resourcePath),
26
- appDir
27
- ]){
28
- let current = upath.resolve(startDir);
29
- for(let depth = 0; depth < 32; depth += 1){
30
- const packageJsonPath = upath.join(current, 'package.json');
31
- if (fs.existsSync(packageJsonPath)) {
32
- onDependency?.(packageJsonPath);
33
- try {
34
- const packageJson = fs.readJSONSync(packageJsonPath);
35
- return {
36
- name: packageJson.name,
37
- version: packageJson.version
38
- };
39
- } catch {
40
- return {};
41
- }
42
- }
43
- const parent = upath.dirname(current);
44
- if (parent === current) break;
45
- current = parent;
46
- }
47
- }
48
- return {};
49
- }
50
- function renderEffectClientCode(generation) {
51
- const { config, manifest } = generation;
52
- return `import * as __requestRuntime from ${JSON.stringify(generation.requestCreator)};
53
- import { createGeneratedEffectClient } from ${JSON.stringify(EFFECT_CLIENT_RUNTIME_IMPORT)};
54
-
55
- const __manifest = ${JSON.stringify(manifest, null, 2)};
56
-
57
- const __config = ${JSON.stringify(config, null, 2)};
58
-
59
- const __generated = createGeneratedEffectClient(__manifest, __config, __requestRuntime);
60
-
61
- const client = __generated.client;
62
- const operationManifest = __generated.operationManifest;
63
- const createEffectRequestContext = __generated.createEffectRequestContext;
64
- const apiModule = {
65
- client,
66
- operationManifest,
67
- createEffectRequestContext,
68
- };
69
-
70
- export { client, createEffectRequestContext, operationManifest };
71
- export default apiModule;
72
- `;
73
- }
74
- function createEffectClientGeneration(endpoints, options) {
75
- const requestCreator = options.requestCreator || DEFAULT_REQUEST_CREATOR;
76
- const httpMethodDecider = options.httpMethodDecider || 'functionName';
77
- const packageInfo = getPackageInfo(options.resourcePath, options.appDir, options.onDependency);
78
- const packageName = packageInfo.name;
79
- const dataPlatformAppNamespace = void 0 === packageName || '' === packageName ? 'unknown-app' : packageName;
80
- const requestId = 'bundle' === options.target ? void 0 !== options.requestId && '' !== options.requestId.trim() ? options.requestId.trim() : void 0 !== packageName && '' !== packageName ? packageName : void 0 : void 0;
81
- const normalizedRequestId = void 0 === requestId || '' === requestId ? 'default' : requestId;
82
- const operationVersion = deriveOperationVersion(packageInfo.version);
83
- const batchConfig = options.dataPlatformBatch;
84
- const batchEndpoint = resolveBatchEndpoint(options.prefix, batchConfig?.endpoint);
85
- const manifest = {
86
- endpoints: endpoints.map((endpoint)=>({
87
- apiId: endpoint.apiId,
88
- group: endpoint.groupName,
89
- endpoint: endpoint.endpointName,
90
- method: endpoint.method,
91
- routePath: endpoint.routePath,
92
- schemaHash: createEffectEndpointContractHash(endpoint, normalizedRequestId),
93
- operationVersion
94
- }))
95
- };
96
- const config = {
97
- appNamespace: dataPlatformAppNamespace,
98
- ...void 0 !== requestId && '' !== requestId ? {
99
- requestId
100
- } : {},
101
- port: options.port,
102
- useEnvPort: 'server' === options.target,
103
- defaultOrigin: `http://localhost:${String(options.port)}`,
104
- httpMethodDecider,
105
- batch: {
106
- enabled: batchConfig?.enabled ?? true,
107
- endpoint: batchEndpoint,
108
- flushIntervalMs: batchConfig?.flushIntervalMs ?? 8,
109
- maxBatchSize: batchConfig?.maxBatchSize ?? 16,
110
- maxBatchBytes: batchConfig?.maxBatchBytes ?? 65536,
111
- requestTimeoutMs: batchConfig?.requestTimeoutMs ?? 10000,
112
- allowedMethods: batchConfig?.allowedMethods !== void 0 && batchConfig.allowedMethods.length > 0 ? batchConfig.allowedMethods : [
113
- 'GET'
114
- ]
115
- }
116
- };
117
- return {
118
- config,
119
- manifest,
120
- operationContracts: buildOperationContractMap({
121
- handlers: toOperationContractSources(endpoints),
122
- requestId: normalizedRequestId,
123
- operationVersion
124
- }),
125
- operationVersion,
126
- requestCreator,
127
- requestId: normalizedRequestId
128
- };
129
- }
130
- function renderClientShape(endpoints, valueType) {
131
- if (0 === endpoints.length) return `Record<string, Record<string, ${valueType}>>`;
132
- const groups = new Map();
133
- for (const endpoint of endpoints){
134
- const group = groups.get(endpoint.groupName) || [];
135
- group.push(endpoint.endpointName);
136
- groups.set(endpoint.groupName, group);
137
- }
138
- const groupEntries = [
139
- ...groups.entries()
140
- ].map(([groupName, names])=>{
141
- const endpointEntries = names.map((name)=>` ${JSON.stringify(name)}: ${valueType};`).join('\n');
142
- return ` ${JSON.stringify(groupName)}: {\n${endpointEntries}\n };`;
143
- });
144
- return `{\n${groupEntries.join('\n')}\n}`;
145
- }
146
- function renderEffectClientDeclaration(endpoints = []) {
147
- return `export type EffectClientOperation = (
148
- request?: unknown,
149
- ) => Promise<unknown>;
150
- export type EffectClientGroup = Record<string, EffectClientOperation>;
151
- export type EffectClient = Record<string, EffectClientGroup>;
152
- export type EffectOperationDescriptor = {
153
- appNamespace: string;
154
- apiId: string;
155
- group: string;
156
- endpoint: string;
157
- operationId: string;
158
- routePath: string;
159
- method: string;
160
- operationVersion: number;
161
- schemaHash: string;
162
- version: number;
163
- };
164
- export type EffectOperationManifest = Record<
165
- string,
166
- Record<string, EffectOperationDescriptor>
167
- >;
168
- export type EffectOperationContext = {
169
- requestId?: string;
170
- operationId?: string;
171
- routePath?: string;
172
- method?: string;
173
- schemaHash?: string;
174
- operationVersion?: number;
175
- locale?: string;
176
- traceparent?: string;
177
- traceId?: string;
178
- spanId?: string;
179
- source?: string;
180
- scope?: Record<string, unknown>;
181
- sessionClaims?: Record<string, unknown>;
182
- attributes?: Record<string, unknown>;
183
- };
184
- export type EffectRequestContext = {
185
- headers?: Record<string, string>;
186
- locale?: string;
187
- operationContext?: EffectOperationContext;
188
- traceparent?: string;
189
- traceId?: string;
190
- spanId?: string;
191
- };
192
- export type GeneratedEffectClient = ${renderClientShape(endpoints, 'EffectClientOperation')};
193
- export type GeneratedEffectOperationManifest = ${renderClientShape(endpoints, "EffectOperationDescriptor")};
194
-
195
- export declare const client: GeneratedEffectClient;
196
- export declare const createEffectRequestContext: (
197
- requestContext: Record<string, unknown>,
198
- ) => EffectRequestContext;
199
- export declare const operationManifest: GeneratedEffectOperationManifest;
200
- declare const apiModule: {
201
- client: GeneratedEffectClient;
202
- createEffectRequestContext: typeof createEffectRequestContext;
203
- operationManifest: GeneratedEffectOperationManifest;
204
- };
205
-
206
- export default apiModule;
207
- `;
208
- }
209
- export { createEffectClientGeneration, renderEffectClientCode, renderEffectClientDeclaration };
@@ -1,27 +0,0 @@
1
- import { extractHttpApiFromModule } from "@modern-js/bff-effect/effect";
2
- import { compatibleRequire, upath } from "@modern-js/utils";
3
- import { loadEffectSourceModule } from "../effect-source-loader/loader.mjs";
4
- let httpApiRuntimePromise;
5
- function isRecord(value) {
6
- return 'object' == typeof value && null !== value;
7
- }
8
- function isHttpApiRuntime(value) {
9
- return isRecord(value) && 'function' == typeof value.isHttpApi && 'function' == typeof value.reflect;
10
- }
11
- function getHttpApiRuntime() {
12
- if (void 0 === httpApiRuntimePromise) httpApiRuntimePromise = compatibleRequire('effect/unstable/httpapi', false).catch((error)=>{
13
- const message = error instanceof Error ? error.message : String(error);
14
- if (!message.includes("Cannot find module 'effect/unstable/httpapi'")) throw error;
15
- const effectPackageJson = require.resolve('effect/package.json');
16
- const effectHttpApiRuntimePath = upath.join(upath.dirname(effectPackageJson), 'dist', 'unstable', 'httpapi', 'index.js');
17
- return compatibleRequire(effectHttpApiRuntimePath, false);
18
- }).then((mod)=>{
19
- if (isRecord(mod) && isHttpApiRuntime(mod.HttpApi)) return mod.HttpApi;
20
- throw new Error('[BFF][Effect] Unable to resolve HttpApi runtime from effect/unstable/httpapi.');
21
- });
22
- return httpApiRuntimePromise;
23
- }
24
- function loadEffectApi(options) {
25
- return getHttpApiRuntime().then((httpApiRuntime)=>loadEffectSourceModule(options).then((mod)=>extractHttpApiFromModule(mod, httpApiRuntime.isHttpApi)));
26
- }
27
- export { getHttpApiRuntime, loadEffectApi };
File without changes
@@ -1,3 +0,0 @@
1
- import "node:module";
2
- const LEGACY_LOAD_WARNING = '[BFF][Effect] loadBackendFederatedEffectApi was called without an expected delivery-unit identity (expected.unitId + expected.buildMarker). Identity-less public backend loads are deprecated (ADR-0019/MV-G23) and will be rejected in a future major.';
3
- export { LEGACY_LOAD_WARNING };
@@ -1,33 +0,0 @@
1
- import "node:module";
2
- import { collectEffectEndpoints } from "@modern-js/bff-effect/effect";
3
- import { logger } from "@modern-js/utils";
4
- import { createEffectClientGeneration, renderEffectClientCode, renderEffectClientDeclaration } from "./rendering.mjs";
5
- import { getHttpApiRuntime, loadEffectApi } from "./runtime.mjs";
6
- function generateEffectClient(options) {
7
- return loadEffectApi({
8
- appDir: options.appDir,
9
- resourcePath: options.resourcePath,
10
- onDependency: options.onDependency
11
- }).then((api)=>{
12
- if (null === api) {
13
- logger.warn(`[BFF][Effect] Failed to generate client for ${options.resourcePath}: unable to resolve exported HttpApi.`);
14
- return null;
15
- }
16
- return getHttpApiRuntime().then((httpApiRuntime)=>{
17
- const endpoints = collectEffectEndpoints(httpApiRuntime.reflect, api, options.prefix);
18
- const generation = createEffectClientGeneration(endpoints, options);
19
- return {
20
- code: renderEffectClientCode(generation),
21
- declaration: renderEffectClientDeclaration(endpoints),
22
- endpoints,
23
- operationContracts: generation.operationContracts,
24
- operationVersion: generation.operationVersion,
25
- requestId: generation.requestId
26
- };
27
- });
28
- });
29
- }
30
- function generateEffectClientCode(options) {
31
- return generateEffectClient(options).then((artifacts)=>null === artifacts ? null : artifacts.code);
32
- }
33
- export { generateEffectClient, generateEffectClientCode };
@@ -1,4 +0,0 @@
1
- import "node:module";
2
- export { bundleBuiltEffectEntryForNode, resolveEffectEntryPaths } from "./built-entry.mjs";
3
- export { generateEffectClient, generateEffectClientCode } from "./generator.mjs";
4
- export { resolveEffectEntryFile } from "./paths.mjs";