@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.
Files changed (88) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +26 -0
  3. package/cli.js +1 -0
  4. package/dist/cjs/cli.js +294 -0
  5. package/dist/cjs/constants.js +48 -0
  6. package/dist/cjs/index.js +58 -0
  7. package/dist/cjs/loader.js +106 -0
  8. package/dist/cjs/runtime/create-request/index.js +48 -0
  9. package/dist/cjs/runtime/data-platform/index.js +693 -0
  10. package/dist/cjs/runtime/effect/adapter.js +311 -0
  11. package/dist/cjs/runtime/effect/context.js +48 -0
  12. package/dist/cjs/runtime/effect/index.js +608 -0
  13. package/dist/cjs/runtime/effect-client/index.js +178 -0
  14. package/dist/cjs/runtime/hono/adapter.js +168 -0
  15. package/dist/cjs/runtime/hono/index.js +65 -0
  16. package/dist/cjs/runtime/hono/operators.js +68 -0
  17. package/dist/cjs/server.js +179 -0
  18. package/dist/cjs/utils/clientGenerator.js +342 -0
  19. package/dist/cjs/utils/createHonoRoutes.js +138 -0
  20. package/dist/cjs/utils/crossProjectApiPlugin.js +118 -0
  21. package/dist/cjs/utils/effectClientGenerator.js +673 -0
  22. package/dist/cjs/utils/pluginGenerator.js +73 -0
  23. package/dist/cjs/utils/runtimeGenerator.js +133 -0
  24. package/dist/esm/cli.mjs +245 -0
  25. package/dist/esm/constants.mjs +11 -0
  26. package/dist/esm/index.mjs +1 -0
  27. package/dist/esm/loader.mjs +62 -0
  28. package/dist/esm/runtime/create-request/index.mjs +1 -0
  29. package/dist/esm/runtime/data-platform/index.mjs +599 -0
  30. package/dist/esm/runtime/effect/adapter.mjs +267 -0
  31. package/dist/esm/runtime/effect/context.mjs +11 -0
  32. package/dist/esm/runtime/effect/index.mjs +438 -0
  33. package/dist/esm/runtime/effect-client/index.mjs +90 -0
  34. package/dist/esm/runtime/hono/adapter.mjs +124 -0
  35. package/dist/esm/runtime/hono/index.mjs +2 -0
  36. package/dist/esm/runtime/hono/operators.mjs +31 -0
  37. package/dist/esm/server.mjs +135 -0
  38. package/dist/esm/utils/clientGenerator.mjs +293 -0
  39. package/dist/esm/utils/createHonoRoutes.mjs +92 -0
  40. package/dist/esm/utils/crossProjectApiPlugin.mjs +54 -0
  41. package/dist/esm/utils/effectClientGenerator.mjs +623 -0
  42. package/dist/esm/utils/pluginGenerator.mjs +29 -0
  43. package/dist/esm/utils/runtimeGenerator.mjs +89 -0
  44. package/dist/esm-node/cli.mjs +249 -0
  45. package/dist/esm-node/constants.mjs +12 -0
  46. package/dist/esm-node/index.mjs +2 -0
  47. package/dist/esm-node/loader.mjs +64 -0
  48. package/dist/esm-node/runtime/create-request/index.mjs +2 -0
  49. package/dist/esm-node/runtime/data-platform/index.mjs +600 -0
  50. package/dist/esm-node/runtime/effect/adapter.mjs +269 -0
  51. package/dist/esm-node/runtime/effect/context.mjs +12 -0
  52. package/dist/esm-node/runtime/effect/index.mjs +439 -0
  53. package/dist/esm-node/runtime/effect-client/index.mjs +91 -0
  54. package/dist/esm-node/runtime/hono/adapter.mjs +125 -0
  55. package/dist/esm-node/runtime/hono/index.mjs +3 -0
  56. package/dist/esm-node/runtime/hono/operators.mjs +32 -0
  57. package/dist/esm-node/server.mjs +136 -0
  58. package/dist/esm-node/utils/clientGenerator.mjs +294 -0
  59. package/dist/esm-node/utils/createHonoRoutes.mjs +93 -0
  60. package/dist/esm-node/utils/crossProjectApiPlugin.mjs +55 -0
  61. package/dist/esm-node/utils/effectClientGenerator.mjs +625 -0
  62. package/dist/esm-node/utils/pluginGenerator.mjs +33 -0
  63. package/dist/esm-node/utils/runtimeGenerator.mjs +91 -0
  64. package/dist/types/cli.d.ts +3 -0
  65. package/dist/types/constants.d.ts +2 -0
  66. package/dist/types/index.d.ts +1 -0
  67. package/dist/types/loader.d.ts +27 -0
  68. package/dist/types/runtime/create-request/index.d.ts +2 -0
  69. package/dist/types/runtime/data-platform/index.d.ts +187 -0
  70. package/dist/types/runtime/effect/adapter.d.ts +22 -0
  71. package/dist/types/runtime/effect/context.d.ts +8 -0
  72. package/dist/types/runtime/effect/index.d.ts +171 -0
  73. package/dist/types/runtime/effect-client/index.d.ts +47 -0
  74. package/dist/types/runtime/hono/adapter.d.ts +19 -0
  75. package/dist/types/runtime/hono/index.d.ts +2 -0
  76. package/dist/types/runtime/hono/operators.d.ts +10 -0
  77. package/dist/types/server.d.ts +3 -0
  78. package/dist/types/utils/clientGenerator.d.ts +37 -0
  79. package/dist/types/utils/createHonoRoutes.d.ts +10 -0
  80. package/dist/types/utils/crossProjectApiPlugin.d.ts +9 -0
  81. package/dist/types/utils/effectClientGenerator.d.ts +27 -0
  82. package/dist/types/utils/pluginGenerator.d.ts +9 -0
  83. package/dist/types/utils/runtimeGenerator.d.ts +7 -0
  84. package/docs/data-platform-architecture.md +61 -0
  85. package/package.json +172 -0
  86. package/rslib.config.mts +4 -0
  87. package/rstest.config.mts +10 -0
  88. package/server.js +1 -0
@@ -0,0 +1,608 @@
1
+ "use strict";
2
+ var __webpack_modules__ = {
3
+ "../data-platform" (module) {
4
+ module.exports = require("../data-platform/index.js");
5
+ },
6
+ "./context" (module) {
7
+ module.exports = require("./context.js");
8
+ },
9
+ "@effect/opentelemetry" (module) {
10
+ module.exports = require("@effect/opentelemetry");
11
+ },
12
+ "effect/Config" (module) {
13
+ module.exports = require("effect/Config");
14
+ },
15
+ "effect/Effect" (module) {
16
+ module.exports = require("effect/Effect");
17
+ },
18
+ "effect/Layer" (module) {
19
+ module.exports = require("effect/Layer");
20
+ },
21
+ "effect/Option" (module) {
22
+ module.exports = require("effect/Option");
23
+ },
24
+ "effect/Schema" (module) {
25
+ module.exports = require("effect/Schema");
26
+ },
27
+ "effect/unstable/http" (module) {
28
+ module.exports = require("effect/unstable/http");
29
+ },
30
+ "effect/unstable/httpapi" (module) {
31
+ module.exports = require("effect/unstable/httpapi");
32
+ },
33
+ "effect/unstable/rpc" (module) {
34
+ module.exports = require("effect/unstable/rpc");
35
+ }
36
+ };
37
+ var __webpack_module_cache__ = {};
38
+ function __webpack_require__(moduleId) {
39
+ var cachedModule = __webpack_module_cache__[moduleId];
40
+ if (void 0 !== cachedModule) return cachedModule.exports;
41
+ var module = __webpack_module_cache__[moduleId] = {
42
+ exports: {}
43
+ };
44
+ __webpack_modules__[moduleId](module, module.exports, __webpack_require__);
45
+ return module.exports;
46
+ }
47
+ (()=>{
48
+ __webpack_require__.n = (module)=>{
49
+ var getter = module && module.__esModule ? ()=>module['default'] : ()=>module;
50
+ __webpack_require__.d(getter, {
51
+ a: getter
52
+ });
53
+ return getter;
54
+ };
55
+ })();
56
+ (()=>{
57
+ __webpack_require__.d = (exports1, definition)=>{
58
+ for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
59
+ enumerable: true,
60
+ get: definition[key]
61
+ });
62
+ };
63
+ })();
64
+ (()=>{
65
+ __webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
66
+ })();
67
+ (()=>{
68
+ __webpack_require__.r = (exports1)=>{
69
+ if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
70
+ value: 'Module'
71
+ });
72
+ Object.defineProperty(exports1, '__esModule', {
73
+ value: true
74
+ });
75
+ };
76
+ })();
77
+ var __webpack_exports__ = {};
78
+ (()=>{
79
+ __webpack_require__.r(__webpack_exports__);
80
+ __webpack_require__.d(__webpack_exports__, {
81
+ Config: ()=>effect_Config__rspack_import_6,
82
+ Effect: ()=>effect_Effect__rspack_import_7,
83
+ HttpApiBuilder: ()=>effect_unstable_httpapi__rspack_import_2.HttpApiBuilder,
84
+ HttpTraceContext: ()=>effect_unstable_http__rspack_import_1.HttpTraceContext,
85
+ Layer: ()=>effect_Layer__rspack_import_0,
86
+ OpenTelemetry: ()=>_effect_opentelemetry__rspack_import_5,
87
+ Option: ()=>effect_Option__rspack_import_8,
88
+ Schema: ()=>effect_Schema__rspack_import_9,
89
+ createHttpApiHandler: ()=>createHttpApiHandler,
90
+ defineEffectBff: ()=>defineEffectBff,
91
+ defineEffectRpcBff: ()=>defineEffectRpcBff,
92
+ useEffectContext: ()=>_context__rspack_import_10.useEffectContext
93
+ });
94
+ var effect_Layer__rspack_import_0 = __webpack_require__("effect/Layer");
95
+ var effect_unstable_http__rspack_import_1 = __webpack_require__("effect/unstable/http");
96
+ var effect_unstable_httpapi__rspack_import_2 = __webpack_require__("effect/unstable/httpapi");
97
+ var effect_unstable_rpc__rspack_import_3 = __webpack_require__("effect/unstable/rpc");
98
+ var _data_platform__rspack_import_4 = __webpack_require__("../data-platform");
99
+ var _effect_opentelemetry__rspack_import_5 = __webpack_require__("@effect/opentelemetry");
100
+ var effect_Config__rspack_import_6 = __webpack_require__("effect/Config");
101
+ var effect_Effect__rspack_import_7 = __webpack_require__("effect/Effect");
102
+ var effect_Option__rspack_import_8 = __webpack_require__("effect/Option");
103
+ var effect_Schema__rspack_import_9 = __webpack_require__("effect/Schema");
104
+ var __rspack_reexport = {};
105
+ for(const __rspack_import_key in effect_unstable_http__rspack_import_1)if ([
106
+ "Config",
107
+ "Layer",
108
+ "Schema",
109
+ "HttpTraceContext",
110
+ "HttpApiBuilder",
111
+ "useEffectContext",
112
+ "defineEffectBff",
113
+ "Effect",
114
+ "default",
115
+ "defineEffectRpcBff",
116
+ "createHttpApiHandler",
117
+ "OpenTelemetry",
118
+ "Option"
119
+ ].indexOf(__rspack_import_key) < 0) __rspack_reexport[__rspack_import_key] = ()=>effect_unstable_http__rspack_import_1[__rspack_import_key];
120
+ __webpack_require__.d(__webpack_exports__, __rspack_reexport);
121
+ var __rspack_reexport = {};
122
+ for(const __rspack_import_key in effect_unstable_httpapi__rspack_import_2)if ([
123
+ "Config",
124
+ "Layer",
125
+ "Schema",
126
+ "HttpTraceContext",
127
+ "HttpApiBuilder",
128
+ "useEffectContext",
129
+ "defineEffectBff",
130
+ "Effect",
131
+ "default",
132
+ "defineEffectRpcBff",
133
+ "createHttpApiHandler",
134
+ "OpenTelemetry",
135
+ "Option"
136
+ ].indexOf(__rspack_import_key) < 0) __rspack_reexport[__rspack_import_key] = ()=>effect_unstable_httpapi__rspack_import_2[__rspack_import_key];
137
+ __webpack_require__.d(__webpack_exports__, __rspack_reexport);
138
+ var __rspack_reexport = {};
139
+ for(const __rspack_import_key in effect_unstable_rpc__rspack_import_3)if ([
140
+ "Config",
141
+ "Layer",
142
+ "Schema",
143
+ "HttpTraceContext",
144
+ "HttpApiBuilder",
145
+ "useEffectContext",
146
+ "defineEffectBff",
147
+ "Effect",
148
+ "default",
149
+ "defineEffectRpcBff",
150
+ "createHttpApiHandler",
151
+ "OpenTelemetry",
152
+ "Option"
153
+ ].indexOf(__rspack_import_key) < 0) __rspack_reexport[__rspack_import_key] = ()=>effect_unstable_rpc__rspack_import_3[__rspack_import_key];
154
+ __webpack_require__.d(__webpack_exports__, __rspack_reexport);
155
+ var _context__rspack_import_10 = __webpack_require__("./context");
156
+ function normalizeOpenApiPath(pathname) {
157
+ if (!pathname.startsWith('/')) return `/${pathname}`;
158
+ return pathname;
159
+ }
160
+ function getOpenApiOptions(openapi) {
161
+ if (!openapi || 'object' != typeof openapi) return;
162
+ if (!openapi.path) return;
163
+ return {
164
+ path: normalizeOpenApiPath(openapi.path)
165
+ };
166
+ }
167
+ function normalizeRpcPath(pathname) {
168
+ if (!pathname || '/' === pathname) return '/rpc';
169
+ if (!pathname.startsWith('/')) return `/${pathname}`;
170
+ return pathname;
171
+ }
172
+ function normalizeBatchPath(pathname) {
173
+ if (!pathname || '/' === pathname) return _data_platform__rspack_import_4.DEFAULT_DATA_BATCH_ENDPOINT;
174
+ if (!pathname.startsWith('/')) return `/${pathname}`;
175
+ return pathname;
176
+ }
177
+ function isPlainObject(value) {
178
+ return 'object' == typeof value && null !== value && !Array.isArray(value);
179
+ }
180
+ function toTextLength(value) {
181
+ if ("u" > typeof TextEncoder) return new TextEncoder().encode(value).length;
182
+ if ("u" > typeof Buffer) return Buffer.byteLength(value);
183
+ return value.length;
184
+ }
185
+ function toHeaderRecord(headers) {
186
+ const record = {};
187
+ headers.forEach((value, key)=>{
188
+ record[key] = value;
189
+ });
190
+ return record;
191
+ }
192
+ function normalizeItemMethod(method) {
193
+ return (method || 'GET').toUpperCase();
194
+ }
195
+ function normalizeBatchAllowedMethods(allowedMethods) {
196
+ const source = Array.isArray(allowedMethods) && allowedMethods.length > 0 ? allowedMethods : [
197
+ 'GET'
198
+ ];
199
+ return new Set(source.map((method)=>method.toUpperCase()));
200
+ }
201
+ function isBatchRequestPayload(value) {
202
+ return isPlainObject(value) && 1 === value.protocolVersion && 'string' == typeof value.batchId && 'number' == typeof value.sentAt && Array.isArray(value.items);
203
+ }
204
+ function createBatchValidationResponse(message, status = 400) {
205
+ return new Response(JSON.stringify({
206
+ message
207
+ }), {
208
+ status,
209
+ headers: {
210
+ 'content-type': 'application/json; charset=utf-8'
211
+ }
212
+ });
213
+ }
214
+ function toBatchItemError(id, status, message) {
215
+ return {
216
+ id,
217
+ status,
218
+ headers: {
219
+ 'content-type': 'application/json; charset=utf-8'
220
+ },
221
+ body: JSON.stringify({
222
+ message
223
+ })
224
+ };
225
+ }
226
+ function promiseWithTimeout(effect, timeoutMs) {
227
+ if (timeoutMs <= 0) return effect;
228
+ return new Promise((resolve, reject)=>{
229
+ const timer = setTimeout(()=>{
230
+ reject(new Error(`Batch item timeout after ${String(timeoutMs)}ms`));
231
+ }, timeoutMs);
232
+ effect.then((value)=>{
233
+ clearTimeout(timer);
234
+ resolve(value);
235
+ }, (error)=>{
236
+ clearTimeout(timer);
237
+ reject(error);
238
+ });
239
+ });
240
+ }
241
+ async function mapWithConcurrency(items, concurrency, mapper) {
242
+ if (0 === items.length) return [];
243
+ const normalizedConcurrency = Math.max(1, concurrency);
244
+ const output = new Array(items.length);
245
+ let index = 0;
246
+ const workers = Array.from({
247
+ length: Math.min(normalizedConcurrency, items.length)
248
+ }, async ()=>{
249
+ while(true){
250
+ const currentIndex = index;
251
+ index += 1;
252
+ if (currentIndex >= items.length) return;
253
+ output[currentIndex] = await mapper(items[currentIndex], currentIndex);
254
+ }
255
+ });
256
+ await Promise.all(workers);
257
+ return output;
258
+ }
259
+ function getRequestPathname(request) {
260
+ try {
261
+ return new URL(request.url).pathname;
262
+ } catch {
263
+ return new URL(request.url, 'http://localhost').pathname;
264
+ }
265
+ }
266
+ function normalizeMountPrefix(prefix) {
267
+ if (!prefix || '/' === prefix) return '';
268
+ return prefix.endsWith('/') ? prefix.slice(0, -1) : prefix;
269
+ }
270
+ function getMountedPrefixFromContext(request, context) {
271
+ if (!isPlainObject(context) || 'string' != typeof context.path) return '';
272
+ const contextPath = normalizeMountPrefix(context.path);
273
+ const requestPath = normalizeMountPrefix(getRequestPathname(request));
274
+ if (!contextPath || !requestPath || contextPath === requestPath || !contextPath.endsWith(requestPath)) return '';
275
+ return normalizeMountPrefix(contextPath.slice(0, contextPath.length - requestPath.length));
276
+ }
277
+ function removeMountedPrefixFromBatchPath(pathWithQuery, prefix) {
278
+ const normalizedPrefix = normalizeMountPrefix(prefix);
279
+ if (!normalizedPrefix) return pathWithQuery;
280
+ const [pathname, ...queryParts] = pathWithQuery.split('?');
281
+ if (!pathname) return pathWithQuery;
282
+ let nextPathname = pathname;
283
+ if (pathname === normalizedPrefix) nextPathname = '/';
284
+ else if (pathname.startsWith(`${normalizedPrefix}/`)) {
285
+ const sliced = pathname.slice(normalizedPrefix.length);
286
+ nextPathname = sliced.startsWith('/') ? sliced : `/${sliced}`;
287
+ }
288
+ if (0 === queryParts.length) return nextPathname;
289
+ return `${nextPathname}?${queryParts.join('?')}`;
290
+ }
291
+ function getRequestOrigin(request) {
292
+ try {
293
+ return new URL(request.url).origin;
294
+ } catch {
295
+ return new URL(request.url, 'http://localhost').origin;
296
+ }
297
+ }
298
+ function getExpectedEnvelopeOrigin(request) {
299
+ const origin = request.headers.get('origin');
300
+ if (origin && 'null' !== origin) return origin;
301
+ return getRequestOrigin(request);
302
+ }
303
+ function isRpcRequest(request, rpcPath) {
304
+ const pathname = getRequestPathname(request);
305
+ return pathname === rpcPath || pathname.startsWith(`${rpcPath}/`);
306
+ }
307
+ function getRpcSerializationLayer(serialization) {
308
+ switch(serialization){
309
+ case 'ndjson':
310
+ return effect_unstable_rpc__rspack_import_3.RpcSerialization.layerNdjson;
311
+ case 'jsonRpc':
312
+ return effect_unstable_rpc__rspack_import_3.RpcSerialization.layerJsonRpc();
313
+ case 'ndJsonRpc':
314
+ return effect_unstable_rpc__rspack_import_3.RpcSerialization.layerNdJsonRpc();
315
+ case 'msgPack':
316
+ return effect_unstable_rpc__rspack_import_3.RpcSerialization.layerMsgPack;
317
+ default:
318
+ return effect_unstable_rpc__rspack_import_3.RpcSerialization.layerJsonRpc();
319
+ }
320
+ }
321
+ function createRpcApiHandler(options) {
322
+ const rpcPath = normalizeRpcPath(options.path);
323
+ const rpcLayer = effect_Layer__rspack_import_0.provide(effect_unstable_rpc__rspack_import_3.RpcServer.layerHttp({
324
+ group: options.group,
325
+ path: rpcPath,
326
+ protocol: 'http',
327
+ disableTracing: options.disableTracing,
328
+ spanPrefix: options.spanPrefix,
329
+ spanAttributes: options.spanAttributes
330
+ }), effect_Layer__rspack_import_0.mergeAll(options.layer, getRpcSerializationLayer(options.serialization)));
331
+ return effect_unstable_http__rspack_import_1.HttpRouter.toWebHandler(rpcLayer);
332
+ }
333
+ function createOpenApiLayer(api, openapi) {
334
+ const openApiOptions = getOpenApiOptions(openapi);
335
+ if (!openApiOptions) return null;
336
+ return effect_unstable_http__rspack_import_1.HttpRouter.add('GET', openApiOptions.path, effect_unstable_http__rspack_import_1.HttpServerResponse.jsonUnsafe(effect_unstable_httpapi__rspack_import_2.OpenApi.fromApi(api)));
337
+ }
338
+ function createInvalidEnvelopeResponse(message, errors) {
339
+ return new Response(JSON.stringify({
340
+ message,
341
+ ...errors && errors.length > 0 ? {
342
+ errors
343
+ } : {}
344
+ }), {
345
+ status: 400,
346
+ headers: {
347
+ 'content-type': 'application/json; charset=utf-8'
348
+ }
349
+ });
350
+ }
351
+ function validateDataPlatformRequestEnvelope(request, options) {
352
+ const isEnabled = options?.enabled ?? true;
353
+ if (!isEnabled) return null;
354
+ const envelopeHeader = options?.envelopeHeader || _data_platform__rspack_import_4.DEFAULT_DATA_ENVELOPE_HEADER;
355
+ const encodedEnvelope = request.headers.get(envelopeHeader);
356
+ if (!encodedEnvelope) {
357
+ if (options?.requireEnvelope) return createInvalidEnvelopeResponse(`Missing required data envelope header: ${envelopeHeader}`);
358
+ return null;
359
+ }
360
+ const envelope = (0, _data_platform__rspack_import_4.decodeRequestEnvelopeHeader)(encodedEnvelope);
361
+ if (!envelope) return createInvalidEnvelopeResponse(`Invalid data envelope header format: ${envelopeHeader}`);
362
+ const validation = (0, _data_platform__rspack_import_4.validateRequestEnvelope)(envelope, {
363
+ expectedProtocolVersion: 1,
364
+ expectedNamespace: options?.expectedNamespace,
365
+ expectedOrigin: options?.validateOrigin === false ? void 0 : getExpectedEnvelopeOrigin(request),
366
+ requireTraceContext: options?.requireTraceContext
367
+ });
368
+ if (!validation.ok) return createInvalidEnvelopeResponse('Invalid data envelope', validation.errors);
369
+ if (envelope.selectionPlan) {
370
+ const selectionValidation = (0, _data_platform__rspack_import_4.validateSelectionPlan)(envelope.selectionPlan, {
371
+ maxDepth: options?.selection?.maxDepth,
372
+ maxFields: options?.selection?.maxFields,
373
+ allowedLeafPaths: options?.selection?.allowedLeafPaths
374
+ });
375
+ if (!selectionValidation.ok) return createInvalidEnvelopeResponse('Invalid data envelope selection plan', selectionValidation.errors);
376
+ }
377
+ return null;
378
+ }
379
+ function mergeDataPlatformOptions(base, override) {
380
+ if (!base && !override) return;
381
+ const baseSelection = base?.selection;
382
+ const overrideSelection = override?.selection;
383
+ const baseBatch = base?.batch;
384
+ const overrideBatch = override?.batch;
385
+ return {
386
+ ...base,
387
+ ...override,
388
+ selection: baseSelection || overrideSelection ? {
389
+ ...baseSelection,
390
+ ...overrideSelection
391
+ } : void 0,
392
+ batch: baseBatch || overrideBatch ? {
393
+ ...baseBatch,
394
+ ...overrideBatch
395
+ } : void 0
396
+ };
397
+ }
398
+ function defineEffectBff(definition) {
399
+ const createHandler = (options)=>{
400
+ const rpcDefinition = definition.rpc;
401
+ let mergedRpcOptions = rpcDefinition;
402
+ if (rpcDefinition && options?.rpc) mergedRpcOptions = {
403
+ ...rpcDefinition,
404
+ ...options.rpc
405
+ };
406
+ return createHttpApiHandler({
407
+ api: definition.api,
408
+ layer: definition.layer,
409
+ openapi: options?.openapi,
410
+ rpc: mergedRpcOptions,
411
+ dataPlatform: mergeDataPlatformOptions(definition.dataPlatform, options?.dataPlatform)
412
+ });
413
+ };
414
+ const client = void 0;
415
+ return {
416
+ ...definition,
417
+ createHandler,
418
+ client
419
+ };
420
+ }
421
+ function defineEffectRpcBff(definition) {
422
+ const createHandler = (options)=>createRpcApiHandler({
423
+ ...definition,
424
+ ...options
425
+ });
426
+ return {
427
+ ...definition,
428
+ createHandler
429
+ };
430
+ }
431
+ function createHttpApiHandler(options) {
432
+ const apiLayer = options.layer;
433
+ const openApiLayer = createOpenApiLayer(options.api, options.openapi);
434
+ const mergedLayer = openApiLayer ? effect_Layer__rspack_import_0.mergeAll(apiLayer, openApiLayer) : apiLayer;
435
+ const httpApiHandler = effect_unstable_http__rspack_import_1.HttpRouter.toWebHandler(mergedLayer);
436
+ const dataPlatformBatchOptions = options.dataPlatform?.batch;
437
+ const batchEnabled = dataPlatformBatchOptions?.enabled !== false;
438
+ const batchPath = normalizeBatchPath(dataPlatformBatchOptions?.endpoint);
439
+ const batchMaxSize = Math.max(1, dataPlatformBatchOptions?.maxBatchSize ?? 16);
440
+ const batchMaxBytes = Math.max(1024, dataPlatformBatchOptions?.maxBatchBytes ?? 65536);
441
+ const batchConcurrency = Math.max(1, dataPlatformBatchOptions?.maxConcurrency ?? 4);
442
+ const batchItemTimeoutMs = Math.max(0, dataPlatformBatchOptions?.requestTimeoutMs ?? 10000);
443
+ const batchAllowedMethods = normalizeBatchAllowedMethods(dataPlatformBatchOptions?.allowedMethods);
444
+ const envelopeHeader = options.dataPlatform?.envelopeHeader || _data_platform__rspack_import_4.DEFAULT_DATA_ENVELOPE_HEADER;
445
+ const normalizedEnvelopeHeader = envelopeHeader.toLowerCase();
446
+ const withDataPlatformValidation = async (request, context)=>{
447
+ const validationError = validateDataPlatformRequestEnvelope(request, options.dataPlatform);
448
+ if (validationError) return validationError;
449
+ return httpApiHandler.handler(request, context);
450
+ };
451
+ const handleBatchRequest = async (request, context)=>{
452
+ const mountedPrefix = getMountedPrefixFromContext(request, context);
453
+ const method = normalizeItemMethod(request.method);
454
+ if ('POST' !== method) return createBatchValidationResponse('Batch endpoint only supports POST requests', 405);
455
+ const contentType = request.headers.get('content-type') || '';
456
+ if (!contentType.includes('application/json')) return createBatchValidationResponse('Batch endpoint requires application/json content-type', 415);
457
+ const payloadText = await request.text();
458
+ if (toTextLength(payloadText) > batchMaxBytes) return createBatchValidationResponse(`Batch payload exceeds max size (${String(batchMaxBytes)} bytes)`, 413);
459
+ let payload;
460
+ try {
461
+ payload = JSON.parse(payloadText);
462
+ } catch {
463
+ return createBatchValidationResponse('Invalid batch payload JSON');
464
+ }
465
+ if (!isBatchRequestPayload(payload)) return createBatchValidationResponse('Invalid batch payload shape');
466
+ if (0 === payload.items.length) return createBatchValidationResponse('Batch payload items cannot be empty');
467
+ if (payload.items.length > batchMaxSize) return createBatchValidationResponse(`Batch item count exceeds max size (${String(batchMaxSize)})`, 413);
468
+ const responseItems = await mapWithConcurrency(payload.items, batchConcurrency, async (rawItem, index)=>{
469
+ const fallbackId = `item_${String(index)}`;
470
+ const itemId = isPlainObject(rawItem) && 'string' == typeof rawItem.id ? rawItem.id : fallbackId;
471
+ if (!isPlainObject(rawItem)) return toBatchItemError(itemId, 400, 'Invalid batch item; expected object');
472
+ if ('string' != typeof rawItem.path || 0 === rawItem.path.length) return toBatchItemError(itemId, 400, 'Invalid batch item path');
473
+ if (!rawItem.path.startsWith('/')) return toBatchItemError(itemId, 400, 'Batch item path must start with "/"');
474
+ const normalizedItemPath = removeMountedPrefixFromBatchPath(rawItem.path, mountedPrefix);
475
+ const itemPathname = normalizedItemPath.split('?')[0] || normalizedItemPath;
476
+ if (itemPathname === batchPath || itemPathname.startsWith(`${batchPath}/`)) return toBatchItemError(itemId, 400, 'Batch item path cannot target batch endpoint');
477
+ const itemMethod = normalizeItemMethod('string' == typeof rawItem.method ? rawItem.method : void 0);
478
+ if (!batchAllowedMethods.has(itemMethod)) return toBatchItemError(itemId, 405, `Batch item method ${itemMethod} is not allowed`);
479
+ if (void 0 !== rawItem.body && null !== rawItem.body && 'string' != typeof rawItem.body) return toBatchItemError(itemId, 400, 'Batch item body must be a string when provided');
480
+ if (('GET' === itemMethod || 'HEAD' === itemMethod) && 'string' == typeof rawItem.body) return toBatchItemError(itemId, 400, `${itemMethod} batch item cannot include body`);
481
+ const normalizedHeaders = {};
482
+ if (void 0 !== rawItem.headers) {
483
+ if (!isPlainObject(rawItem.headers)) return toBatchItemError(itemId, 400, 'Batch item headers must be an object');
484
+ for (const [key, value] of Object.entries(rawItem.headers)){
485
+ if ('string' != typeof value) return toBatchItemError(itemId, 400, `Invalid header "${key}" for batch item`);
486
+ normalizedHeaders[key.toLowerCase()] = value;
487
+ }
488
+ }
489
+ if (!normalizedHeaders.traceparent) {
490
+ const encodedEnvelope = normalizedHeaders[normalizedEnvelopeHeader];
491
+ if ('string' == typeof encodedEnvelope) {
492
+ const envelope = (0, _data_platform__rspack_import_4.decodeRequestEnvelopeHeader)(encodedEnvelope);
493
+ if (envelope?.traceparent) normalizedHeaders.traceparent = envelope.traceparent;
494
+ }
495
+ }
496
+ if (!normalizedHeaders.traceparent) {
497
+ const requestTraceparent = request.headers.get('traceparent');
498
+ if (requestTraceparent) normalizedHeaders.traceparent = requestTraceparent;
499
+ }
500
+ const targetUrl = new URL(normalizedItemPath, request.url);
501
+ const requestHeaders = new Headers(normalizedHeaders);
502
+ const body = 'GET' === itemMethod || 'HEAD' === itemMethod ? void 0 : rawItem.body;
503
+ if (void 0 === body) requestHeaders.delete('content-type');
504
+ const itemRequest = new Request(targetUrl.toString(), {
505
+ method: itemMethod,
506
+ headers: requestHeaders,
507
+ body
508
+ });
509
+ try {
510
+ const itemResponse = await promiseWithTimeout(withDataPlatformValidation(itemRequest, context), batchItemTimeoutMs);
511
+ if (!(itemResponse instanceof Response)) return toBatchItemError(itemId, 500, 'Invalid response returned by batch item handler');
512
+ const bodyText = await itemResponse.text();
513
+ const responseItem = {
514
+ id: itemId,
515
+ status: itemResponse.status,
516
+ headers: toHeaderRecord(itemResponse.headers),
517
+ ...bodyText ? {
518
+ body: bodyText
519
+ } : {}
520
+ };
521
+ return responseItem;
522
+ } catch (error) {
523
+ if (error instanceof Response) {
524
+ const bodyText = await error.text();
525
+ return {
526
+ id: itemId,
527
+ status: error.status,
528
+ headers: toHeaderRecord(error.headers),
529
+ ...bodyText ? {
530
+ body: bodyText
531
+ } : {}
532
+ };
533
+ }
534
+ const message = error instanceof Error ? error.message : String(error);
535
+ return toBatchItemError(itemId, 500, message);
536
+ }
537
+ });
538
+ const responsePayload = {
539
+ protocolVersion: 1,
540
+ batchId: payload.batchId,
541
+ receivedAt: Date.now(),
542
+ items: responseItems
543
+ };
544
+ return new Response(JSON.stringify(responsePayload), {
545
+ status: 200,
546
+ headers: {
547
+ 'content-type': 'application/json; charset=utf-8',
548
+ [_data_platform__rspack_import_4.DEFAULT_DATA_BATCH_HEADER]: '1',
549
+ 'x-modernjs-data-batch-id': payload.batchId
550
+ }
551
+ });
552
+ };
553
+ const handleHttpApiRequest = async (request, context)=>{
554
+ const pathname = getRequestPathname(request);
555
+ if (batchEnabled && pathname === batchPath) return handleBatchRequest(request, context);
556
+ return withDataPlatformValidation(request, context);
557
+ };
558
+ if (!options.rpc) return {
559
+ handler: handleHttpApiRequest,
560
+ dispose: async ()=>{
561
+ await httpApiHandler.dispose();
562
+ }
563
+ };
564
+ const rpcPath = normalizeRpcPath(options.rpc.path);
565
+ const rpcHandler = createRpcApiHandler(options.rpc);
566
+ return {
567
+ handler: async (request, context)=>{
568
+ if (isRpcRequest(request, rpcPath)) return rpcHandler.handler(request, context);
569
+ return handleHttpApiRequest(request);
570
+ },
571
+ dispose: async ()=>{
572
+ await Promise.all([
573
+ httpApiHandler.dispose(),
574
+ rpcHandler.dispose()
575
+ ]);
576
+ }
577
+ };
578
+ }
579
+ })();
580
+ exports.Config = __webpack_exports__.Config;
581
+ exports.Effect = __webpack_exports__.Effect;
582
+ exports.HttpApiBuilder = __webpack_exports__.HttpApiBuilder;
583
+ exports.HttpTraceContext = __webpack_exports__.HttpTraceContext;
584
+ exports.Layer = __webpack_exports__.Layer;
585
+ exports.OpenTelemetry = __webpack_exports__.OpenTelemetry;
586
+ exports.Option = __webpack_exports__.Option;
587
+ exports.Schema = __webpack_exports__.Schema;
588
+ exports.createHttpApiHandler = __webpack_exports__.createHttpApiHandler;
589
+ exports.defineEffectBff = __webpack_exports__.defineEffectBff;
590
+ exports.defineEffectRpcBff = __webpack_exports__.defineEffectRpcBff;
591
+ exports.useEffectContext = __webpack_exports__.useEffectContext;
592
+ for(var __rspack_i in __webpack_exports__)if (-1 === [
593
+ "Config",
594
+ "Effect",
595
+ "HttpApiBuilder",
596
+ "HttpTraceContext",
597
+ "Layer",
598
+ "OpenTelemetry",
599
+ "Option",
600
+ "Schema",
601
+ "createHttpApiHandler",
602
+ "defineEffectBff",
603
+ "defineEffectRpcBff",
604
+ "useEffectContext"
605
+ ].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
606
+ Object.defineProperty(exports, '__esModule', {
607
+ value: true
608
+ });