@bleedingdev/modern-js-bff-effect 3.9.0-ultramodern.4 → 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/dist/cjs/assembly.js +50 -0
- package/dist/cjs/data-platform/trace.js +2 -2
- package/dist/cjs/effect/edge-dispatcher.js +7 -7
- package/dist/cjs/effect/edge.js +15 -2
- package/dist/cjs/effect/endpoint-contracts.js +2 -2
- package/dist/cjs/effect/generated-entry.js +57 -0
- package/dist/cjs/effect/handler/batch-handler.js +5 -4
- package/dist/cjs/effect/handler/batch.js +8 -1
- package/dist/cjs/effect/operation-context.js +7 -7
- package/dist/cjs/effect-client/index.js +2 -2
- package/dist/cjs/microvertical-api.js +120 -0
- package/dist/esm/assembly.mjs +12 -0
- package/dist/esm/data-platform/trace.mjs +1 -1
- package/dist/esm/effect/edge-dispatcher.mjs +5 -5
- package/dist/esm/effect/edge.mjs +1 -0
- package/dist/esm/effect/endpoint-contracts.mjs +1 -1
- package/dist/esm/effect/generated-entry.mjs +19 -0
- package/dist/esm/effect/handler/batch-handler.mjs +5 -4
- package/dist/esm/effect/handler/batch.mjs +8 -1
- package/dist/esm/effect/operation-context.mjs +1 -1
- package/dist/esm/effect-client/index.mjs +1 -1
- package/dist/esm/microvertical-api.mjs +67 -0
- package/dist/esm-node/assembly.mjs +13 -0
- package/dist/esm-node/data-platform/trace.mjs +1 -1
- package/dist/esm-node/effect/edge-dispatcher.mjs +5 -5
- package/dist/esm-node/effect/edge.mjs +1 -0
- package/dist/esm-node/effect/endpoint-contracts.mjs +1 -1
- package/dist/esm-node/effect/generated-entry.mjs +20 -0
- package/dist/esm-node/effect/handler/batch-handler.mjs +5 -4
- package/dist/esm-node/effect/handler/batch.mjs +8 -1
- package/dist/esm-node/effect/operation-context.mjs +1 -1
- package/dist/esm-node/effect-client/index.mjs +1 -1
- package/dist/esm-node/microvertical-api.mjs +68 -0
- package/dist/types/assembly.d.ts +10 -0
- package/dist/types/effect/context.d.ts +1 -1
- package/dist/types/effect/edge-context.d.ts +1 -1
- package/dist/types/effect/edge-dispatcher.d.ts +1 -1
- package/dist/types/effect/edge.d.ts +1 -0
- package/dist/types/effect/endpoint-contracts.d.ts +1 -1
- package/dist/types/effect/generated-entry.d.ts +7 -0
- package/dist/types/effect/handler/batch.d.ts +7 -1
- package/dist/types/effect/operation-context.d.ts +1 -1
- package/dist/types/effect-client/index.d.ts +1 -1
- package/dist/types/effect-client/types.d.ts +1 -1
- package/dist/types/microvertical-api.d.ts +65 -0
- package/package.json +30 -4
- package/src/assembly.ts +43 -0
- package/src/data-platform/batch/queue.ts +2 -3
- package/src/data-platform/trace.ts +1 -1
- package/src/effect/edge-dispatcher.ts +7 -4
- package/src/effect/edge.ts +1 -0
- package/src/effect/endpoint-contracts.ts +1 -1
- package/src/effect/entry-shape.ts +4 -1
- package/src/effect/generated-entry.ts +36 -0
- package/src/effect/handler/batch-handler.ts +21 -16
- package/src/effect/handler/batch.ts +9 -1
- package/src/effect/operation-context.ts +1 -1
- package/src/effect-client/index.ts +1 -1
- package/src/effect-client/types.ts +1 -1
- package/src/microvertical-api.ts +102 -0
|
@@ -0,0 +1,50 @@
|
|
|
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
|
+
assembleEffectBffRuntime: ()=>assembleEffectBffRuntime
|
|
32
|
+
});
|
|
33
|
+
const Layer_namespaceObject = require("effect/Layer");
|
|
34
|
+
const httpapi_namespaceObject = require("effect/unstable/httpapi");
|
|
35
|
+
const definition_js_namespaceObject = require("./effect/handler/definition.js");
|
|
36
|
+
const assembleEffectBffRuntime = ({ api, handlers, transport })=>{
|
|
37
|
+
const apiLayer = httpapi_namespaceObject.HttpApiBuilder.layer(api).pipe(Layer_namespaceObject.provide(handlers));
|
|
38
|
+
const layer = void 0 === transport ? apiLayer : apiLayer.pipe(Layer_namespaceObject.merge(transport));
|
|
39
|
+
return (0, definition_js_namespaceObject.defineEffectBff)({
|
|
40
|
+
api,
|
|
41
|
+
layer
|
|
42
|
+
});
|
|
43
|
+
};
|
|
44
|
+
exports.assembleEffectBffRuntime = __webpack_exports__.assembleEffectBffRuntime;
|
|
45
|
+
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
46
|
+
"assembleEffectBffRuntime"
|
|
47
|
+
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
48
|
+
Object.defineProperty(exports, '__esModule', {
|
|
49
|
+
value: true
|
|
50
|
+
});
|
|
@@ -32,7 +32,7 @@ __webpack_require__.d(__webpack_exports__, {
|
|
|
32
32
|
formatTraceparentHeader: ()=>formatTraceparentHeader,
|
|
33
33
|
parseTraceparentHeader: ()=>parseTraceparentHeader
|
|
34
34
|
});
|
|
35
|
-
const
|
|
35
|
+
const request_context_namespaceObject = require("@modern-js/runtime-extensions/request-context");
|
|
36
36
|
function isAllZeroHex(value) {
|
|
37
37
|
return /^0+$/.test(value);
|
|
38
38
|
}
|
|
@@ -40,7 +40,7 @@ function isValidHex(value, length) {
|
|
|
40
40
|
return value.length === length && /^[0-9a-f]+$/.test(value);
|
|
41
41
|
}
|
|
42
42
|
function parseTraceparentHeader(header) {
|
|
43
|
-
return (0,
|
|
43
|
+
return (0, request_context_namespaceObject.parseTraceparent)(header) ?? null;
|
|
44
44
|
}
|
|
45
45
|
function formatTraceparentHeader(trace) {
|
|
46
46
|
const traceId = trace.traceId.toLowerCase();
|
|
@@ -97,13 +97,13 @@ __webpack_require__.d(__webpack_exports__, {
|
|
|
97
97
|
useEffectContext: ()=>external_edge_context_js_namespaceObject.useEffectContext,
|
|
98
98
|
useOperationContext: ()=>external_edge_context_js_namespaceObject.useOperationContext
|
|
99
99
|
});
|
|
100
|
-
const
|
|
100
|
+
const bff_policy_namespaceObject = require("@modern-js/server-runtime-extensions/bff-policy");
|
|
101
|
+
const Effect_namespaceObject = require("effect/Effect");
|
|
101
102
|
const external_headers_js_namespaceObject = require("../headers.js");
|
|
102
103
|
const external_dispatch_js_namespaceObject = require("./dispatch.js");
|
|
103
104
|
const external_edge_context_js_namespaceObject = require("./edge-context.js");
|
|
104
105
|
const external_module_js_namespaceObject = require("./module.js");
|
|
105
106
|
const Config_namespaceObject = require("effect/Config");
|
|
106
|
-
const Effect_namespaceObject = require("effect/Effect");
|
|
107
107
|
const Layer_namespaceObject = require("effect/Layer");
|
|
108
108
|
const Option_namespaceObject = require("effect/Option");
|
|
109
109
|
const Schema_namespaceObject = require("effect/Schema");
|
|
@@ -147,14 +147,14 @@ async function createEffectBffEdgeDispatcher(options) {
|
|
|
147
147
|
dataPlatform: options.dataPlatform,
|
|
148
148
|
validateRequest: crossProjectPolicy?.enabled === true ? (request)=>{
|
|
149
149
|
const pathname = new URL(request.url).pathname;
|
|
150
|
-
const observedRequest = (0,
|
|
150
|
+
const observedRequest = (0, bff_policy_namespaceObject.resolveCrossProjectRequestObservation)({
|
|
151
151
|
method: request.method,
|
|
152
152
|
pathname
|
|
153
153
|
}, crossProjectPolicy) ?? {
|
|
154
154
|
method: request.method,
|
|
155
155
|
routePath: restoreEffectBffMountPath(request, options.prefix)
|
|
156
156
|
};
|
|
157
|
-
const violation = (0,
|
|
157
|
+
const violation = (0, bff_policy_namespaceObject.evaluateCrossProjectPolicy)((0, external_headers_js_namespaceObject.toHeaderRecord)(request.headers), crossProjectPolicy, observedRequest);
|
|
158
158
|
if (!violation) return null;
|
|
159
159
|
return new Response(JSON.stringify({
|
|
160
160
|
code: violation.code,
|
|
@@ -194,9 +194,9 @@ async function createEffectBffEdgeDispatcher(options) {
|
|
|
194
194
|
dispose: ()=>{
|
|
195
195
|
disposePromise ??= (async ()=>{
|
|
196
196
|
acceptingRequests = false;
|
|
197
|
-
if (activeDispatches > 0) await
|
|
198
|
-
resolveDrain =
|
|
199
|
-
});
|
|
197
|
+
if (activeDispatches > 0) await Effect_namespaceObject.runPromise(Effect_namespaceObject.callback((resume)=>{
|
|
198
|
+
resolveDrain = ()=>resume(Effect_namespaceObject["void"]);
|
|
199
|
+
}));
|
|
200
200
|
await loaded.dispose?.();
|
|
201
201
|
})();
|
|
202
202
|
return disposePromise;
|
package/dist/cjs/effect/edge.js
CHANGED
|
@@ -2,6 +2,9 @@
|
|
|
2
2
|
var __webpack_modules__ = {
|
|
3
3
|
"./edge-dispatcher" (module) {
|
|
4
4
|
module.exports = require("./edge-dispatcher.js");
|
|
5
|
+
},
|
|
6
|
+
"./generated-entry" (module) {
|
|
7
|
+
module.exports = require("./generated-entry.js");
|
|
5
8
|
}
|
|
6
9
|
};
|
|
7
10
|
var __webpack_module_cache__ = {};
|
|
@@ -53,10 +56,20 @@ var __webpack_exports__ = {};
|
|
|
53
56
|
__webpack_require__.r(__webpack_exports__);
|
|
54
57
|
var _edge_dispatcher__rspack_import_0 = __webpack_require__("./edge-dispatcher");
|
|
55
58
|
var __rspack_reexport = {};
|
|
56
|
-
for(const __rspack_import_key in _edge_dispatcher__rspack_import_0)if (
|
|
59
|
+
for(const __rspack_import_key in _edge_dispatcher__rspack_import_0)if ([
|
|
60
|
+
"createEffectBffEdgeDispatcherFactory",
|
|
61
|
+
"default"
|
|
62
|
+
].indexOf(__rspack_import_key) < 0) __rspack_reexport[__rspack_import_key] = ()=>_edge_dispatcher__rspack_import_0[__rspack_import_key];
|
|
57
63
|
__webpack_require__.d(__webpack_exports__, __rspack_reexport);
|
|
64
|
+
var _generated_entry__rspack_import_1 = __webpack_require__("./generated-entry");
|
|
65
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
66
|
+
createEffectBffEdgeDispatcherFactory: ()=>_generated_entry__rspack_import_1.createEffectBffEdgeDispatcherFactory
|
|
67
|
+
});
|
|
58
68
|
})();
|
|
59
|
-
|
|
69
|
+
exports.createEffectBffEdgeDispatcherFactory = __webpack_exports__.createEffectBffEdgeDispatcherFactory;
|
|
70
|
+
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
71
|
+
"createEffectBffEdgeDispatcherFactory"
|
|
72
|
+
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
60
73
|
Object.defineProperty(exports, '__esModule', {
|
|
61
74
|
value: true
|
|
62
75
|
});
|
|
@@ -35,7 +35,7 @@ __webpack_require__.d(__webpack_exports__, {
|
|
|
35
35
|
normalizeEffectPrefix: ()=>normalizeEffectPrefix,
|
|
36
36
|
toOperationContractSources: ()=>toOperationContractSources
|
|
37
37
|
});
|
|
38
|
-
const
|
|
38
|
+
const node_namespaceObject = require("@modern-js/server-runtime-extensions/bff-policy/node");
|
|
39
39
|
const external_entry_shape_js_namespaceObject = require("./entry-shape.js");
|
|
40
40
|
function resolveEffectEndpointName(endpoint) {
|
|
41
41
|
if ('string' == typeof endpoint.identifier && endpoint.identifier) return endpoint.identifier;
|
|
@@ -100,7 +100,7 @@ async function extractHttpApiFromModule(mod, isHttpApi) {
|
|
|
100
100
|
return !facts?.legacyShape && facts?.api !== void 0 && facts.hasRuntimeLayer && (void 0 === facts.createHandler || facts.createHandlerValidatorAware) ? facts.api : null;
|
|
101
101
|
}
|
|
102
102
|
function createEffectEndpointContractHash(endpoint, requestId) {
|
|
103
|
-
return (0,
|
|
103
|
+
return (0, node_namespaceObject.createOperationContractHash)(createEffectOperationContractSource(endpoint), requestId);
|
|
104
104
|
}
|
|
105
105
|
exports.collectEffectEndpoints = __webpack_exports__.collectEffectEndpoints;
|
|
106
106
|
exports.createEffectEndpointContractHash = __webpack_exports__.createEffectEndpointContractHash;
|
|
@@ -0,0 +1,57 @@
|
|
|
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
|
+
createEffectBffEdgeDispatcherFactory: ()=>createEffectBffEdgeDispatcherFactory
|
|
32
|
+
});
|
|
33
|
+
const external_edge_dispatcher_js_namespaceObject = require("./edge-dispatcher.js");
|
|
34
|
+
function createEffectBffEdgeDispatcherFactory(module, generatedOperationContracts) {
|
|
35
|
+
return (options)=>{
|
|
36
|
+
const policy = options?.crossProjectPolicy;
|
|
37
|
+
const crossProjectPolicy = null == policy || null === policy.expectedOperationContracts || 'object' != typeof policy.expectedOperationContracts || Array.isArray(policy.expectedOperationContracts) ? policy : {
|
|
38
|
+
...policy,
|
|
39
|
+
expectedOperationContracts: {
|
|
40
|
+
...policy.expectedOperationContracts,
|
|
41
|
+
...generatedOperationContracts
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
return (0, external_edge_dispatcher_js_namespaceObject.createEffectBffEdgeDispatcher)({
|
|
45
|
+
...options,
|
|
46
|
+
crossProjectPolicy,
|
|
47
|
+
module
|
|
48
|
+
});
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
exports.createEffectBffEdgeDispatcherFactory = __webpack_exports__.createEffectBffEdgeDispatcherFactory;
|
|
52
|
+
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
53
|
+
"createEffectBffEdgeDispatcherFactory"
|
|
54
|
+
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
55
|
+
Object.defineProperty(exports, '__esModule', {
|
|
56
|
+
value: true
|
|
57
|
+
});
|
|
@@ -30,6 +30,7 @@ __webpack_require__.r(__webpack_exports__);
|
|
|
30
30
|
__webpack_require__.d(__webpack_exports__, {
|
|
31
31
|
createDataPlatformBatchRequestHandler: ()=>createDataPlatformBatchRequestHandler
|
|
32
32
|
});
|
|
33
|
+
const Effect_namespaceObject = require("effect/Effect");
|
|
33
34
|
const index_js_namespaceObject = require("../../data-platform/index.js");
|
|
34
35
|
const protocol_js_namespaceObject = require("../../data-platform/batch/protocol.js");
|
|
35
36
|
const external_batch_js_namespaceObject = require("./batch.js");
|
|
@@ -216,25 +217,25 @@ function createDataPlatformBatchRequestHandler(options) {
|
|
|
216
217
|
return (0, protocol_js_namespaceObject.toBatchResponseItem)(itemId, itemResponse, 'HEAD' === itemMethod);
|
|
217
218
|
} catch (error) {
|
|
218
219
|
if (error instanceof external_batch_js_namespaceObject.BatchItemTimeoutError) {
|
|
219
|
-
|
|
220
|
+
Effect_namespaceObject.runSync(Effect_namespaceObject.logError({
|
|
220
221
|
event: 'bff.batch.item.timeout',
|
|
221
222
|
batchId: payload.batchId,
|
|
222
223
|
itemId,
|
|
223
224
|
method: itemMethod,
|
|
224
225
|
path: itemPathname,
|
|
225
226
|
errorName: error.name
|
|
226
|
-
});
|
|
227
|
+
}));
|
|
227
228
|
return (0, external_batch_js_namespaceObject.toBatchItemError)(itemId, 504, 'Batch item request timed out');
|
|
228
229
|
}
|
|
229
230
|
if (error instanceof Response) return (0, protocol_js_namespaceObject.toBatchResponseItem)(itemId, error, 'HEAD' === itemMethod);
|
|
230
|
-
|
|
231
|
+
Effect_namespaceObject.runSync(Effect_namespaceObject.logError({
|
|
231
232
|
event: 'bff.batch.item.failure',
|
|
232
233
|
batchId: payload.batchId,
|
|
233
234
|
itemId,
|
|
234
235
|
method: itemMethod,
|
|
235
236
|
path: itemPathname,
|
|
236
237
|
errorName: error instanceof Error ? error.name : 'UnknownError'
|
|
237
|
-
});
|
|
238
|
+
}));
|
|
238
239
|
return (0, external_batch_js_namespaceObject.toBatchItemError)(itemId, 500, 'Internal Server Error');
|
|
239
240
|
} finally{
|
|
240
241
|
request.signal.removeEventListener('abort', abortFromBatchRequest);
|
|
@@ -39,6 +39,7 @@ __webpack_require__.d(__webpack_exports__, {
|
|
|
39
39
|
toBatchItemError: ()=>toBatchItemError,
|
|
40
40
|
toHeaderRecord: ()=>external_headers_js_namespaceObject.toHeaderRecord
|
|
41
41
|
});
|
|
42
|
+
const Data_namespaceObject = require("effect/Data");
|
|
42
43
|
const index_js_namespaceObject = require("../../data-platform/index.js");
|
|
43
44
|
const protocol_js_namespaceObject = require("../../data-platform/batch/protocol.js");
|
|
44
45
|
const external_headers_js_namespaceObject = require("../../headers.js");
|
|
@@ -106,7 +107,13 @@ function toBatchItemError(id, status, message) {
|
|
|
106
107
|
}))
|
|
107
108
|
};
|
|
108
109
|
}
|
|
109
|
-
class BatchItemTimeoutError extends
|
|
110
|
+
class BatchItemTimeoutError extends Data_namespaceObject.TaggedError('BatchItemTimeoutError') {
|
|
111
|
+
constructor(message){
|
|
112
|
+
super({
|
|
113
|
+
message
|
|
114
|
+
});
|
|
115
|
+
this.name = 'Error';
|
|
116
|
+
}
|
|
110
117
|
}
|
|
111
118
|
function promiseWithTimeout(effect, timeoutMs, onTimeout) {
|
|
112
119
|
if (timeoutMs <= 0) return effect;
|
|
@@ -31,7 +31,7 @@ __webpack_require__.d(__webpack_exports__, {
|
|
|
31
31
|
createEffectOperationContext: ()=>createEffectOperationContext,
|
|
32
32
|
kEffectContextStorage: ()=>kEffectContextStorage
|
|
33
33
|
});
|
|
34
|
-
const
|
|
34
|
+
const request_context_namespaceObject = require("@modern-js/runtime-extensions/request-context");
|
|
35
35
|
const kEffectContextStorage = Symbol.for('modernjs.plugin-bff.effectContextStorage');
|
|
36
36
|
const readHeader = (headers, header)=>{
|
|
37
37
|
const value = headers.get(header);
|
|
@@ -42,7 +42,7 @@ const copyStringField = (target, details, key)=>{
|
|
|
42
42
|
if ('string' == typeof value && value.length > 0) target[key] = value;
|
|
43
43
|
};
|
|
44
44
|
const readOperationContextDetails = (request)=>{
|
|
45
|
-
const rawDetails = readHeader(request.headers,
|
|
45
|
+
const rawDetails = readHeader(request.headers, request_context_namespaceObject.BFF_OPERATION_CONTEXT_DETAIL_HEADER);
|
|
46
46
|
if (!rawDetails) return {};
|
|
47
47
|
try {
|
|
48
48
|
const parsed = JSON.parse(rawDetails);
|
|
@@ -70,16 +70,16 @@ const createEffectOperationContext = ({ request, path, method })=>{
|
|
|
70
70
|
delete operationDetails.traceId;
|
|
71
71
|
delete operationDetails.spanId;
|
|
72
72
|
const servicePath = new URL(request.url).pathname;
|
|
73
|
-
const headerTraceparent = readHeader(request.headers,
|
|
74
|
-
const headerTraceContext = (0,
|
|
75
|
-
const detailTraceContext = (0,
|
|
73
|
+
const headerTraceparent = readHeader(request.headers, request_context_namespaceObject.BFF_TRACEPARENT_HEADER);
|
|
74
|
+
const headerTraceContext = (0, request_context_namespaceObject.parseTraceparent)(headerTraceparent);
|
|
75
|
+
const detailTraceContext = (0, request_context_namespaceObject.parseTraceparent)(details.traceparent);
|
|
76
76
|
const traceparent = headerTraceContext ? headerTraceparent : detailTraceContext ? details.traceparent : void 0;
|
|
77
77
|
const parsedTraceparent = headerTraceContext || detailTraceContext || (details.traceId && details.spanId ? {
|
|
78
78
|
traceId: details.traceId,
|
|
79
79
|
spanId: details.spanId
|
|
80
80
|
} : void 0);
|
|
81
|
-
const locale = readHeader(request.headers,
|
|
82
|
-
const headerOperationId = readHeader(request.headers,
|
|
81
|
+
const locale = readHeader(request.headers, request_context_namespaceObject.BFF_LOCALE_HEADER);
|
|
82
|
+
const headerOperationId = readHeader(request.headers, request_context_namespaceObject.BFF_OPERATION_CONTEXT_HEADER);
|
|
83
83
|
return {
|
|
84
84
|
...operationDetails,
|
|
85
85
|
...headerOperationId || details.operationId ? {
|
|
@@ -50,7 +50,7 @@ __webpack_require__.d(__webpack_exports__, {
|
|
|
50
50
|
runEffectView: ()=>runEffectView,
|
|
51
51
|
view: ()=>view
|
|
52
52
|
});
|
|
53
|
-
const
|
|
53
|
+
const request_context_namespaceObject = require("@modern-js/runtime-extensions/request-context");
|
|
54
54
|
const Data_namespaceObject = require("effect/Data");
|
|
55
55
|
const Effect_namespaceObject = require("effect/Effect");
|
|
56
56
|
const Exit_namespaceObject = require("effect/Exit");
|
|
@@ -91,7 +91,7 @@ function runEffectView(request, selection) {
|
|
|
91
91
|
});
|
|
92
92
|
}
|
|
93
93
|
function makeEffectHttpApiClient(api, options) {
|
|
94
|
-
const requestContextHeaders = (0,
|
|
94
|
+
const requestContextHeaders = (0, request_context_namespaceObject.createRequestContextHeaders)(options?.requestContext);
|
|
95
95
|
const transformClient = (client)=>{
|
|
96
96
|
const contextClient = 0 === Object.keys(requestContextHeaders).length ? client : client.pipe(http_namespaceObject.HttpClient.mapRequest((request)=>{
|
|
97
97
|
let nextRequest = request;
|
|
@@ -0,0 +1,120 @@
|
|
|
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
|
+
MicroVerticalBuildMarkerSchema: ()=>MicroVerticalBuildMarkerSchema,
|
|
32
|
+
MicroVerticalOperationContextSchema: ()=>MicroVerticalOperationContextSchema,
|
|
33
|
+
MicroVerticalOperationSourceSchema: ()=>MicroVerticalOperationSourceSchema,
|
|
34
|
+
MicroVerticalReadinessSchema: ()=>MicroVerticalReadinessSchema,
|
|
35
|
+
createMicroVerticalOperationContext: ()=>createMicroVerticalOperationContext,
|
|
36
|
+
microVerticalOperationAttributes: ()=>microVerticalOperationAttributes
|
|
37
|
+
});
|
|
38
|
+
const external_effect_namespaceObject = require("effect");
|
|
39
|
+
const MicroVerticalAppIdSchema = external_effect_namespaceObject.Schema.String.pipe(external_effect_namespaceObject.Schema.brand('MicroVerticalAppId'), external_effect_namespaceObject.Schema.decodeTo(external_effect_namespaceObject.Schema.String));
|
|
40
|
+
const MicroVerticalUnitIdSchema = external_effect_namespaceObject.Schema.String.pipe(external_effect_namespaceObject.Schema.brand('MicroVerticalUnitId'), external_effect_namespaceObject.Schema.decodeTo(external_effect_namespaceObject.Schema.String));
|
|
41
|
+
const MicroVerticalOperationIdSchema = external_effect_namespaceObject.Schema.String.pipe(external_effect_namespaceObject.Schema.brand('MicroVerticalOperationId'), external_effect_namespaceObject.Schema.decodeTo(external_effect_namespaceObject.Schema.String));
|
|
42
|
+
const MicroVerticalTraceIdSchema = external_effect_namespaceObject.Schema.String.pipe(external_effect_namespaceObject.Schema.brand('MicroVerticalTraceId'), external_effect_namespaceObject.Schema.decodeTo(external_effect_namespaceObject.Schema.String));
|
|
43
|
+
const MicroVerticalBuildMarkerSchema = external_effect_namespaceObject.Schema.Struct({
|
|
44
|
+
appId: MicroVerticalAppIdSchema,
|
|
45
|
+
build: external_effect_namespaceObject.Schema.String,
|
|
46
|
+
buildMarker: external_effect_namespaceObject.Schema.String,
|
|
47
|
+
deployProfile: external_effect_namespaceObject.Schema.String,
|
|
48
|
+
packageName: external_effect_namespaceObject.Schema.String,
|
|
49
|
+
sourceRevision: external_effect_namespaceObject.Schema.String,
|
|
50
|
+
surface: external_effect_namespaceObject.Schema.String,
|
|
51
|
+
unitId: MicroVerticalUnitIdSchema,
|
|
52
|
+
version: external_effect_namespaceObject.Schema.String
|
|
53
|
+
});
|
|
54
|
+
const MicroVerticalReadinessSchema = external_effect_namespaceObject.Schema.Struct({
|
|
55
|
+
checks: external_effect_namespaceObject.Schema.Struct({
|
|
56
|
+
api: external_effect_namespaceObject.Schema.Literal('ready'),
|
|
57
|
+
moduleFederation: external_effect_namespaceObject.Schema.Literal('ready'),
|
|
58
|
+
ssr: external_effect_namespaceObject.Schema.Literal('ready'),
|
|
59
|
+
translations: external_effect_namespaceObject.Schema.Literal('ready')
|
|
60
|
+
}),
|
|
61
|
+
marker: MicroVerticalBuildMarkerSchema,
|
|
62
|
+
status: external_effect_namespaceObject.Schema.Literal('ready'),
|
|
63
|
+
versionSkew: external_effect_namespaceObject.Schema.Literal('none')
|
|
64
|
+
});
|
|
65
|
+
const MicroVerticalOperationSourceSchema = external_effect_namespaceObject.Schema.Literals([
|
|
66
|
+
'client',
|
|
67
|
+
'server',
|
|
68
|
+
'generated-client',
|
|
69
|
+
'effect-adapter',
|
|
70
|
+
'data-platform',
|
|
71
|
+
'unknown'
|
|
72
|
+
]);
|
|
73
|
+
const MicroVerticalOperationContextSchema = external_effect_namespaceObject.Schema.Struct({
|
|
74
|
+
method: external_effect_namespaceObject.Schema.String,
|
|
75
|
+
operationId: MicroVerticalOperationIdSchema,
|
|
76
|
+
routePath: external_effect_namespaceObject.Schema.String,
|
|
77
|
+
source: MicroVerticalOperationSourceSchema,
|
|
78
|
+
traceId: external_effect_namespaceObject.Schema.optionalKey(MicroVerticalTraceIdSchema)
|
|
79
|
+
});
|
|
80
|
+
const createMicroVerticalOperationContext = (input)=>{
|
|
81
|
+
const context = {
|
|
82
|
+
method: input.method,
|
|
83
|
+
operationId: input.operationId,
|
|
84
|
+
routePath: input.routePath,
|
|
85
|
+
source: 'generated-client'
|
|
86
|
+
};
|
|
87
|
+
return void 0 === input.traceId ? context : {
|
|
88
|
+
...context,
|
|
89
|
+
traceId: input.traceId
|
|
90
|
+
};
|
|
91
|
+
};
|
|
92
|
+
const microVerticalOperationAttributes = (operationContext)=>{
|
|
93
|
+
const attributes = {
|
|
94
|
+
'modernjs.operation.id': operationContext.operationId,
|
|
95
|
+
'modernjs.operation.method': operationContext.method,
|
|
96
|
+
'modernjs.operation.route': operationContext.routePath,
|
|
97
|
+
'modernjs.operation.source': operationContext.source
|
|
98
|
+
};
|
|
99
|
+
return void 0 === operationContext.traceId ? attributes : {
|
|
100
|
+
...attributes,
|
|
101
|
+
'modernjs.trace.id': operationContext.traceId
|
|
102
|
+
};
|
|
103
|
+
};
|
|
104
|
+
exports.MicroVerticalBuildMarkerSchema = __webpack_exports__.MicroVerticalBuildMarkerSchema;
|
|
105
|
+
exports.MicroVerticalOperationContextSchema = __webpack_exports__.MicroVerticalOperationContextSchema;
|
|
106
|
+
exports.MicroVerticalOperationSourceSchema = __webpack_exports__.MicroVerticalOperationSourceSchema;
|
|
107
|
+
exports.MicroVerticalReadinessSchema = __webpack_exports__.MicroVerticalReadinessSchema;
|
|
108
|
+
exports.createMicroVerticalOperationContext = __webpack_exports__.createMicroVerticalOperationContext;
|
|
109
|
+
exports.microVerticalOperationAttributes = __webpack_exports__.microVerticalOperationAttributes;
|
|
110
|
+
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
111
|
+
"MicroVerticalBuildMarkerSchema",
|
|
112
|
+
"MicroVerticalOperationContextSchema",
|
|
113
|
+
"MicroVerticalOperationSourceSchema",
|
|
114
|
+
"MicroVerticalReadinessSchema",
|
|
115
|
+
"createMicroVerticalOperationContext",
|
|
116
|
+
"microVerticalOperationAttributes"
|
|
117
|
+
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
118
|
+
Object.defineProperty(exports, '__esModule', {
|
|
119
|
+
value: true
|
|
120
|
+
});
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { HttpApiBuilder } from "effect/unstable/httpapi";
|
|
2
|
+
import { defineEffectBff } from "./effect/handler/definition.mjs";
|
|
3
|
+
import * as __rspack_external_effect_Layer_69c46453 from "effect/Layer";
|
|
4
|
+
const assembleEffectBffRuntime = ({ api, handlers, transport })=>{
|
|
5
|
+
const apiLayer = HttpApiBuilder.layer(api).pipe(__rspack_external_effect_Layer_69c46453.provide(handlers));
|
|
6
|
+
const layer = void 0 === transport ? apiLayer : apiLayer.pipe(__rspack_external_effect_Layer_69c46453.merge(transport));
|
|
7
|
+
return defineEffectBff({
|
|
8
|
+
api,
|
|
9
|
+
layer
|
|
10
|
+
});
|
|
11
|
+
};
|
|
12
|
+
export { assembleEffectBffRuntime };
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { evaluateCrossProjectPolicy, resolveCrossProjectRequestObservation } from "@modern-js/
|
|
1
|
+
import { evaluateCrossProjectPolicy, resolveCrossProjectRequestObservation } from "@modern-js/server-runtime-extensions/bff-policy";
|
|
2
|
+
import * as __rspack_external_effect_Effect_41060786 from "effect/Effect";
|
|
2
3
|
import { toHeaderRecord } from "../headers.mjs";
|
|
3
4
|
import { dispatchEffectBffRequestWithContext } from "./dispatch.mjs";
|
|
4
5
|
import { runWithEffectContext, useEffectContext, useOperationContext } from "./edge-context.mjs";
|
|
5
6
|
import { resolveEffectBffModuleHandler } from "./module.mjs";
|
|
6
7
|
import * as __rspack_external_effect_Config_76cfa59d from "effect/Config";
|
|
7
|
-
import * as __rspack_external_effect_Effect_41060786 from "effect/Effect";
|
|
8
8
|
import * as __rspack_external_effect_Layer_69c46453 from "effect/Layer";
|
|
9
9
|
import * as __rspack_external_effect_Option_0498e63a from "effect/Option";
|
|
10
10
|
import * as __rspack_external_effect_Schema_6065f72d from "effect/Schema";
|
|
@@ -90,9 +90,9 @@ async function createEffectBffEdgeDispatcher(options) {
|
|
|
90
90
|
dispose: ()=>{
|
|
91
91
|
disposePromise ??= (async ()=>{
|
|
92
92
|
acceptingRequests = false;
|
|
93
|
-
if (activeDispatches > 0) await
|
|
94
|
-
resolveDrain =
|
|
95
|
-
});
|
|
93
|
+
if (activeDispatches > 0) await __rspack_external_effect_Effect_41060786.runPromise(__rspack_external_effect_Effect_41060786.callback((resume)=>{
|
|
94
|
+
resolveDrain = ()=>resume(__rspack_external_effect_Effect_41060786["void"]);
|
|
95
|
+
}));
|
|
96
96
|
await loaded.dispose?.();
|
|
97
97
|
})();
|
|
98
98
|
return disposePromise;
|
package/dist/esm/effect/edge.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { createOperationContractHash } from "@modern-js/bff-
|
|
1
|
+
import { createOperationContractHash } from "@modern-js/server-runtime-extensions/bff-policy/node";
|
|
2
2
|
import { classifyEffectBffEntryModule, isValidatorAwareHandlerFactory } from "./entry-shape.mjs";
|
|
3
3
|
function resolveEffectEndpointName(endpoint) {
|
|
4
4
|
if ('string' == typeof endpoint.identifier && endpoint.identifier) return endpoint.identifier;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { createEffectBffEdgeDispatcher } from "./edge-dispatcher.mjs";
|
|
2
|
+
function createEffectBffEdgeDispatcherFactory(module, generatedOperationContracts) {
|
|
3
|
+
return (options)=>{
|
|
4
|
+
const policy = options?.crossProjectPolicy;
|
|
5
|
+
const crossProjectPolicy = null == policy || null === policy.expectedOperationContracts || 'object' != typeof policy.expectedOperationContracts || Array.isArray(policy.expectedOperationContracts) ? policy : {
|
|
6
|
+
...policy,
|
|
7
|
+
expectedOperationContracts: {
|
|
8
|
+
...policy.expectedOperationContracts,
|
|
9
|
+
...generatedOperationContracts
|
|
10
|
+
}
|
|
11
|
+
};
|
|
12
|
+
return createEffectBffEdgeDispatcher({
|
|
13
|
+
...options,
|
|
14
|
+
crossProjectPolicy,
|
|
15
|
+
module
|
|
16
|
+
});
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
export { createEffectBffEdgeDispatcherFactory };
|
|
@@ -2,6 +2,7 @@ import { DEFAULT_DATA_BATCH_HEADER, DEFAULT_DATA_ENVELOPE_HEADER, decodeRequestE
|
|
|
2
2
|
import { decodeBatchBody, isBatchBody, toBatchResponseItem } from "../../data-platform/batch/protocol.mjs";
|
|
3
3
|
import { BatchItemTimeoutError, createBatchValidationResponse, isBatchRequestPayload, mapWithConcurrency, normalizeBatchAllowedMethods, normalizeBatchPath, promiseWithTimeout, toBatchItemError } from "./batch.mjs";
|
|
4
4
|
import { getMountedPrefixFromContext, removeMountedPrefixFromBatchPath } from "./routing.mjs";
|
|
5
|
+
import * as __rspack_external_effect_Effect_41060786 from "effect/Effect";
|
|
5
6
|
const HOP_BY_HOP_BATCH_ITEM_HEADERS = new Set([
|
|
6
7
|
'connection',
|
|
7
8
|
'keep-alive',
|
|
@@ -184,25 +185,25 @@ function createDataPlatformBatchRequestHandler(options) {
|
|
|
184
185
|
return toBatchResponseItem(itemId, itemResponse, 'HEAD' === itemMethod);
|
|
185
186
|
} catch (error) {
|
|
186
187
|
if (error instanceof BatchItemTimeoutError) {
|
|
187
|
-
|
|
188
|
+
__rspack_external_effect_Effect_41060786.runSync(__rspack_external_effect_Effect_41060786.logError({
|
|
188
189
|
event: 'bff.batch.item.timeout',
|
|
189
190
|
batchId: payload.batchId,
|
|
190
191
|
itemId,
|
|
191
192
|
method: itemMethod,
|
|
192
193
|
path: itemPathname,
|
|
193
194
|
errorName: error.name
|
|
194
|
-
});
|
|
195
|
+
}));
|
|
195
196
|
return toBatchItemError(itemId, 504, 'Batch item request timed out');
|
|
196
197
|
}
|
|
197
198
|
if (error instanceof Response) return toBatchResponseItem(itemId, error, 'HEAD' === itemMethod);
|
|
198
|
-
|
|
199
|
+
__rspack_external_effect_Effect_41060786.runSync(__rspack_external_effect_Effect_41060786.logError({
|
|
199
200
|
event: 'bff.batch.item.failure',
|
|
200
201
|
batchId: payload.batchId,
|
|
201
202
|
itemId,
|
|
202
203
|
method: itemMethod,
|
|
203
204
|
path: itemPathname,
|
|
204
205
|
errorName: error instanceof Error ? error.name : 'UnknownError'
|
|
205
|
-
});
|
|
206
|
+
}));
|
|
206
207
|
return toBatchItemError(itemId, 500, 'Internal Server Error');
|
|
207
208
|
} finally{
|
|
208
209
|
request.signal.removeEventListener('abort', abortFromBatchRequest);
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { DEFAULT_DATA_BATCH_ENDPOINT, isPlainObject, normalizeMethod } from "../../data-platform/index.mjs";
|
|
2
2
|
import { encodeBatchText } from "../../data-platform/batch/protocol.mjs";
|
|
3
|
+
import * as __rspack_external_effect_Data_2b3f4efb from "effect/Data";
|
|
3
4
|
function normalizeBatchPath(pathname) {
|
|
4
5
|
if (!pathname || '/' === pathname) return DEFAULT_DATA_BATCH_ENDPOINT;
|
|
5
6
|
if (!pathname.startsWith('/')) return `/${pathname}`;
|
|
@@ -64,7 +65,13 @@ function toBatchItemError(id, status, message) {
|
|
|
64
65
|
}))
|
|
65
66
|
};
|
|
66
67
|
}
|
|
67
|
-
class BatchItemTimeoutError extends
|
|
68
|
+
class BatchItemTimeoutError extends __rspack_external_effect_Data_2b3f4efb.TaggedError('BatchItemTimeoutError') {
|
|
69
|
+
constructor(message){
|
|
70
|
+
super({
|
|
71
|
+
message
|
|
72
|
+
});
|
|
73
|
+
this.name = 'Error';
|
|
74
|
+
}
|
|
68
75
|
}
|
|
69
76
|
function promiseWithTimeout(effect, timeoutMs, onTimeout) {
|
|
70
77
|
if (timeoutMs <= 0) return effect;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { BFF_LOCALE_HEADER, BFF_OPERATION_CONTEXT_DETAIL_HEADER, BFF_OPERATION_CONTEXT_HEADER, BFF_TRACEPARENT_HEADER, parseTraceparent } from "@modern-js/
|
|
1
|
+
import { BFF_LOCALE_HEADER, BFF_OPERATION_CONTEXT_DETAIL_HEADER, BFF_OPERATION_CONTEXT_HEADER, BFF_TRACEPARENT_HEADER, parseTraceparent } from "@modern-js/runtime-extensions/request-context";
|
|
2
2
|
const kEffectContextStorage = Symbol.for('modernjs.plugin-bff.effectContextStorage');
|
|
3
3
|
const readHeader = (headers, header)=>{
|
|
4
4
|
const value = headers.get(header);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { createRequestContextHeaders } from "@modern-js/
|
|
1
|
+
import { createRequestContextHeaders } from "@modern-js/runtime-extensions/request-context";
|
|
2
2
|
import * as __rspack_external_effect_Effect_41060786 from "effect/Effect";
|
|
3
3
|
import * as __rspack_external_effect_Layer_69c46453 from "effect/Layer";
|
|
4
4
|
import { FetchHttpClient, HttpClient, HttpClientRequest } from "effect/unstable/http";
|