@bleedingdev/modern-js-bff-effect 3.8.3-ultramodern.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +25 -0
- package/dist/cjs/data-platform/batch/protocol.js +130 -0
- package/dist/cjs/data-platform/batch/queue.js +623 -0
- package/dist/cjs/data-platform/batch/request.js +121 -0
- package/dist/cjs/data-platform/batch/response.js +65 -0
- package/dist/cjs/data-platform/batch/telemetry.js +71 -0
- package/dist/cjs/data-platform/batch/url.js +69 -0
- package/dist/cjs/data-platform/batch-transport.js +59 -0
- package/dist/cjs/data-platform/codec.js +155 -0
- package/dist/cjs/data-platform/index.js +124 -0
- package/dist/cjs/data-platform/invalidation.js +61 -0
- package/dist/cjs/data-platform/trace.js +73 -0
- package/dist/cjs/data-platform/types.js +48 -0
- package/dist/cjs/data-platform/validation.js +178 -0
- package/dist/cjs/effect/context.js +59 -0
- package/dist/cjs/effect/dispatch.js +101 -0
- package/dist/cjs/effect/edge-context.js +61 -0
- package/dist/cjs/effect/edge-dispatcher.js +354 -0
- package/dist/cjs/effect/edge.js +62 -0
- package/dist/cjs/effect/endpoint-contracts.js +121 -0
- package/dist/cjs/effect/entry-shape-registry.js +31 -0
- package/dist/cjs/effect/entry-shape.js +113 -0
- package/dist/cjs/effect/handler/batch-handler.js +270 -0
- package/dist/cjs/effect/handler/batch.js +170 -0
- package/dist/cjs/effect/handler/definition.js +99 -0
- package/dist/cjs/effect/handler/envelope.js +104 -0
- package/dist/cjs/effect/handler/http.js +107 -0
- package/dist/cjs/effect/handler/openapi.js +58 -0
- package/dist/cjs/effect/handler/routing.js +100 -0
- package/dist/cjs/effect/handler/rpc.js +63 -0
- package/dist/cjs/effect/handler/types.js +43 -0
- package/dist/cjs/effect/handler.js +173 -0
- package/dist/cjs/effect/index.js +137 -0
- package/dist/cjs/effect/module.js +118 -0
- package/dist/cjs/effect/operation-context.js +116 -0
- package/dist/cjs/effect/rpcSerialization.js +54 -0
- package/dist/cjs/effect-client/batch.js +73 -0
- package/dist/cjs/effect-client/envelope.js +145 -0
- package/dist/cjs/effect-client/guards.js +44 -0
- package/dist/cjs/effect-client/index.js +208 -0
- package/dist/cjs/effect-client/request-context.js +64 -0
- package/dist/cjs/effect-client/request.js +66 -0
- package/dist/cjs/effect-client/runtime.js +100 -0
- package/dist/cjs/effect-client/types.js +18 -0
- package/dist/cjs/headers.js +46 -0
- package/dist/cjs/index.js +83 -0
- package/dist/esm/data-platform/batch/protocol.mjs +71 -0
- package/dist/esm/data-platform/batch/queue.mjs +582 -0
- package/dist/esm/data-platform/batch/request.mjs +68 -0
- package/dist/esm/data-platform/batch/response.mjs +24 -0
- package/dist/esm/data-platform/batch/telemetry.mjs +27 -0
- package/dist/esm/data-platform/batch/url.mjs +25 -0
- package/dist/esm/data-platform/batch-transport.mjs +12 -0
- package/dist/esm/data-platform/codec.mjs +90 -0
- package/dist/esm/data-platform/index.mjs +7 -0
- package/dist/esm/data-platform/invalidation.mjs +20 -0
- package/dist/esm/data-platform/trace.mjs +29 -0
- package/dist/esm/data-platform/types.mjs +4 -0
- package/dist/esm/data-platform/validation.mjs +128 -0
- package/dist/esm/effect/context.mjs +12 -0
- package/dist/esm/effect/dispatch.mjs +63 -0
- package/dist/esm/effect/edge-context.mjs +14 -0
- package/dist/esm/effect/edge-dispatcher.mjs +115 -0
- package/dist/esm/effect/edge.mjs +1 -0
- package/dist/esm/effect/endpoint-contracts.mjs +68 -0
- package/dist/esm/effect/entry-shape-registry.mjs +17 -0
- package/dist/esm/effect/entry-shape.mjs +51 -0
- package/dist/esm/effect/handler/batch-handler.mjs +232 -0
- package/dist/esm/effect/handler/batch.mjs +105 -0
- package/dist/esm/effect/handler/definition.mjs +58 -0
- package/dist/esm/effect/handler/envelope.mjs +63 -0
- package/dist/esm/effect/handler/http.mjs +69 -0
- package/dist/esm/effect/handler/openapi.mjs +20 -0
- package/dist/esm/effect/handler/routing.mjs +50 -0
- package/dist/esm/effect/handler/rpc.mjs +22 -0
- package/dist/esm/effect/handler/types.mjs +5 -0
- package/dist/esm/effect/handler.mjs +13 -0
- package/dist/esm/effect/index.mjs +7 -0
- package/dist/esm/effect/module.mjs +80 -0
- package/dist/esm/effect/operation-context.mjs +75 -0
- package/dist/esm/effect/rpcSerialization.mjs +16 -0
- package/dist/esm/effect-client/batch.mjs +35 -0
- package/dist/esm/effect-client/envelope.mjs +104 -0
- package/dist/esm/effect-client/guards.mjs +3 -0
- package/dist/esm/effect-client/index.mjs +110 -0
- package/dist/esm/effect-client/request-context.mjs +23 -0
- package/dist/esm/effect-client/request.mjs +28 -0
- package/dist/esm/effect-client/runtime.mjs +62 -0
- package/dist/esm/effect-client/types.mjs +0 -0
- package/dist/esm/headers.mjs +8 -0
- package/dist/esm/index.mjs +4 -0
- package/dist/esm/rslib-runtime.mjs +18 -0
- package/dist/esm-node/data-platform/batch/protocol.mjs +72 -0
- package/dist/esm-node/data-platform/batch/queue.mjs +583 -0
- package/dist/esm-node/data-platform/batch/request.mjs +69 -0
- package/dist/esm-node/data-platform/batch/response.mjs +25 -0
- package/dist/esm-node/data-platform/batch/telemetry.mjs +28 -0
- package/dist/esm-node/data-platform/batch/url.mjs +26 -0
- package/dist/esm-node/data-platform/batch-transport.mjs +13 -0
- package/dist/esm-node/data-platform/codec.mjs +91 -0
- package/dist/esm-node/data-platform/index.mjs +8 -0
- package/dist/esm-node/data-platform/invalidation.mjs +21 -0
- package/dist/esm-node/data-platform/trace.mjs +30 -0
- package/dist/esm-node/data-platform/types.mjs +5 -0
- package/dist/esm-node/data-platform/validation.mjs +129 -0
- package/dist/esm-node/effect/context.mjs +13 -0
- package/dist/esm-node/effect/dispatch.mjs +64 -0
- package/dist/esm-node/effect/edge-context.mjs +15 -0
- package/dist/esm-node/effect/edge-dispatcher.mjs +116 -0
- package/dist/esm-node/effect/edge.mjs +2 -0
- package/dist/esm-node/effect/endpoint-contracts.mjs +69 -0
- package/dist/esm-node/effect/entry-shape-registry.mjs +18 -0
- package/dist/esm-node/effect/entry-shape.mjs +63 -0
- package/dist/esm-node/effect/handler/batch-handler.mjs +233 -0
- package/dist/esm-node/effect/handler/batch.mjs +106 -0
- package/dist/esm-node/effect/handler/definition.mjs +59 -0
- package/dist/esm-node/effect/handler/envelope.mjs +64 -0
- package/dist/esm-node/effect/handler/http.mjs +70 -0
- package/dist/esm-node/effect/handler/openapi.mjs +21 -0
- package/dist/esm-node/effect/handler/routing.mjs +51 -0
- package/dist/esm-node/effect/handler/rpc.mjs +23 -0
- package/dist/esm-node/effect/handler/types.mjs +6 -0
- package/dist/esm-node/effect/handler.mjs +14 -0
- package/dist/esm-node/effect/index.mjs +8 -0
- package/dist/esm-node/effect/module.mjs +81 -0
- package/dist/esm-node/effect/operation-context.mjs +76 -0
- package/dist/esm-node/effect/rpcSerialization.mjs +17 -0
- package/dist/esm-node/effect-client/batch.mjs +36 -0
- package/dist/esm-node/effect-client/envelope.mjs +105 -0
- package/dist/esm-node/effect-client/guards.mjs +4 -0
- package/dist/esm-node/effect-client/index.mjs +111 -0
- package/dist/esm-node/effect-client/request-context.mjs +24 -0
- package/dist/esm-node/effect-client/request.mjs +29 -0
- package/dist/esm-node/effect-client/runtime.mjs +63 -0
- package/dist/esm-node/effect-client/types.mjs +1 -0
- package/dist/esm-node/headers.mjs +9 -0
- package/dist/esm-node/index.mjs +5 -0
- package/dist/esm-node/rslib-runtime.mjs +19 -0
- package/dist/types/data-platform/batch/protocol.d.ts +9 -0
- package/dist/types/data-platform/batch/queue.d.ts +47 -0
- package/dist/types/data-platform/batch/request.d.ts +19 -0
- package/dist/types/data-platform/batch/response.d.ts +3 -0
- package/dist/types/data-platform/batch/telemetry.d.ts +4 -0
- package/dist/types/data-platform/batch/url.d.ts +4 -0
- package/dist/types/data-platform/batch-transport.d.ts +3 -0
- package/dist/types/data-platform/codec.d.ts +17 -0
- package/dist/types/data-platform/index.d.ts +8 -0
- package/dist/types/data-platform/invalidation.d.ts +8 -0
- package/dist/types/data-platform/trace.d.ts +4 -0
- package/dist/types/data-platform/types.d.ts +151 -0
- package/dist/types/data-platform/validation.d.ts +29 -0
- package/dist/types/effect/context.d.ts +5 -0
- package/dist/types/effect/dispatch.d.ts +13 -0
- package/dist/types/effect/edge-context.d.ts +5 -0
- package/dist/types/effect/edge-dispatcher.d.ts +37 -0
- package/dist/types/effect/edge.d.ts +1 -0
- package/dist/types/effect/endpoint-contracts.d.ts +67 -0
- package/dist/types/effect/entry-shape.d.ts +32 -0
- package/dist/types/effect/handler/batch-handler.d.ts +11 -0
- package/dist/types/effect/handler/batch.d.ts +15 -0
- package/dist/types/effect/handler/definition.d.ts +7 -0
- package/dist/types/effect/handler/envelope.d.ts +13 -0
- package/dist/types/effect/handler/http.d.ts +15 -0
- package/dist/types/effect/handler/openapi.d.ts +4 -0
- package/dist/types/effect/handler/routing.d.ts +5 -0
- package/dist/types/effect/handler/rpc.d.ts +7 -0
- package/dist/types/effect/handler/types.d.ts +153 -0
- package/dist/types/effect/handler.d.ts +13 -0
- package/dist/types/effect/index.d.ts +6 -0
- package/dist/types/effect/module.d.ts +36 -0
- package/dist/types/effect/operation-context.d.ts +15 -0
- package/dist/types/effect/rpcSerialization.d.ts +3 -0
- package/dist/types/effect-client/batch.d.ts +2 -0
- package/dist/types/effect-client/envelope.d.ts +15 -0
- package/dist/types/effect-client/guards.d.ts +2 -0
- package/dist/types/effect-client/index.d.ts +58 -0
- package/dist/types/effect-client/request-context.d.ts +3 -0
- package/dist/types/effect-client/request.d.ts +1 -0
- package/dist/types/effect-client/runtime.d.ts +5 -0
- package/dist/types/effect-client/types.d.ts +68 -0
- package/dist/types/headers.d.ts +1 -0
- package/dist/types/index.d.ts +3 -0
- package/package.json +164 -0
- package/src/data-platform/batch/protocol.ts +112 -0
- package/src/data-platform/batch/queue.ts +876 -0
- package/src/data-platform/batch/request.ts +130 -0
- package/src/data-platform/batch/response.ts +74 -0
- package/src/data-platform/batch/telemetry.ts +47 -0
- package/src/data-platform/batch/url.ts +54 -0
- package/src/data-platform/batch-transport.ts +22 -0
- package/src/data-platform/codec.ts +145 -0
- package/src/data-platform/index.ts +63 -0
- package/src/data-platform/invalidation.ts +57 -0
- package/src/data-platform/trace.ts +49 -0
- package/src/data-platform/types.ts +186 -0
- package/src/data-platform/validation.ts +303 -0
- package/src/effect/context.ts +37 -0
- package/src/effect/dispatch.ts +132 -0
- package/src/effect/edge-context.ts +51 -0
- package/src/effect/edge-dispatcher.ts +310 -0
- package/src/effect/edge.ts +1 -0
- package/src/effect/endpoint-contracts.ts +191 -0
- package/src/effect/entry-shape-registry.cjs +16 -0
- package/src/effect/entry-shape-registry.d.cts +6 -0
- package/src/effect/entry-shape.ts +155 -0
- package/src/effect/handler/batch-handler.ts +475 -0
- package/src/effect/handler/batch.ts +182 -0
- package/src/effect/handler/definition.ts +121 -0
- package/src/effect/handler/envelope.ts +133 -0
- package/src/effect/handler/http.ts +133 -0
- package/src/effect/handler/openapi.ts +45 -0
- package/src/effect/handler/routing.ts +91 -0
- package/src/effect/handler/rpc.ts +45 -0
- package/src/effect/handler/types.ts +255 -0
- package/src/effect/handler.ts +33 -0
- package/src/effect/index.ts +22 -0
- package/src/effect/module.ts +186 -0
- package/src/effect/operation-context.ts +144 -0
- package/src/effect/rpcSerialization.ts +20 -0
- package/src/effect-client/batch.ts +50 -0
- package/src/effect-client/envelope.ts +238 -0
- package/src/effect-client/guards.ts +6 -0
- package/src/effect-client/index.ts +325 -0
- package/src/effect-client/request-context.ts +54 -0
- package/src/effect-client/request.ts +51 -0
- package/src/effect-client/runtime.ts +122 -0
- package/src/effect-client/types.ts +84 -0
- package/src/headers.ts +7 -0
- package/src/index.ts +3 -0
|
@@ -0,0 +1,61 @@
|
|
|
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
|
+
createInvalidationEvent: ()=>createInvalidationEvent,
|
|
32
|
+
shouldApplyInvalidation: ()=>shouldApplyInvalidation
|
|
33
|
+
});
|
|
34
|
+
const external_codec_js_namespaceObject = require("./codec.js");
|
|
35
|
+
function createInvalidationEvent(input) {
|
|
36
|
+
return {
|
|
37
|
+
sourceNamespace: (0, external_codec_js_namespaceObject.sanitizeSegment)(input.sourceOperation.appNamespace),
|
|
38
|
+
sourceOperationId: (0, external_codec_js_namespaceObject.createOperationId)(input.sourceOperation),
|
|
39
|
+
scopeKey: (0, external_codec_js_namespaceObject.buildScopeKey)(input.sourceScope),
|
|
40
|
+
targetNamespaces: input.targetNamespaces?.map((namespace)=>(0, external_codec_js_namespaceObject.sanitizeSegment)(namespace)),
|
|
41
|
+
targetOperationIds: input.targetOperations?.map((operation)=>(0, external_codec_js_namespaceObject.createOperationId)(operation))
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
function shouldApplyInvalidation(event, subscriber) {
|
|
45
|
+
if (subscriber.scopeKey && subscriber.scopeKey !== event.scopeKey) return false;
|
|
46
|
+
const sameNamespace = subscriber.namespace === event.sourceNamespace;
|
|
47
|
+
const allowedCrossNamespace = true === subscriber.acceptCrossNamespace && event.targetNamespaces?.includes(subscriber.namespace) === true;
|
|
48
|
+
if (!sameNamespace && !allowedCrossNamespace) return false;
|
|
49
|
+
if (!subscriber.operationIds || 0 === subscriber.operationIds.length) return true;
|
|
50
|
+
if (!event.targetOperationIds || 0 === event.targetOperationIds.length) return true;
|
|
51
|
+
return subscriber.operationIds.some((operationId)=>event.targetOperationIds?.includes(operationId));
|
|
52
|
+
}
|
|
53
|
+
exports.createInvalidationEvent = __webpack_exports__.createInvalidationEvent;
|
|
54
|
+
exports.shouldApplyInvalidation = __webpack_exports__.shouldApplyInvalidation;
|
|
55
|
+
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
56
|
+
"createInvalidationEvent",
|
|
57
|
+
"shouldApplyInvalidation"
|
|
58
|
+
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
59
|
+
Object.defineProperty(exports, '__esModule', {
|
|
60
|
+
value: true
|
|
61
|
+
});
|
|
@@ -0,0 +1,73 @@
|
|
|
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
|
+
deriveChildTraceContext: ()=>deriveChildTraceContext,
|
|
32
|
+
formatTraceparentHeader: ()=>formatTraceparentHeader,
|
|
33
|
+
parseTraceparentHeader: ()=>parseTraceparentHeader
|
|
34
|
+
});
|
|
35
|
+
const create_request_namespaceObject = require("@modern-js/create-request");
|
|
36
|
+
function isAllZeroHex(value) {
|
|
37
|
+
return /^0+$/.test(value);
|
|
38
|
+
}
|
|
39
|
+
function isValidHex(value, length) {
|
|
40
|
+
return value.length === length && /^[0-9a-f]+$/.test(value);
|
|
41
|
+
}
|
|
42
|
+
function parseTraceparentHeader(header) {
|
|
43
|
+
return (0, create_request_namespaceObject.parseTraceparent)(header) ?? null;
|
|
44
|
+
}
|
|
45
|
+
function formatTraceparentHeader(trace) {
|
|
46
|
+
const traceId = trace.traceId.toLowerCase();
|
|
47
|
+
const spanId = trace.spanId.toLowerCase();
|
|
48
|
+
if (!isValidHex(traceId, 32) || !isValidHex(spanId, 16)) throw new Error('Invalid trace context: traceId/spanId format mismatch');
|
|
49
|
+
if (isAllZeroHex(traceId) || isAllZeroHex(spanId)) throw new Error('Invalid trace context: traceId/spanId cannot be zero');
|
|
50
|
+
const flags = trace.sampled ? '01' : '00';
|
|
51
|
+
return `00-${traceId}-${spanId}-${flags}`;
|
|
52
|
+
}
|
|
53
|
+
function deriveChildTraceContext(parent, childSpanId) {
|
|
54
|
+
const normalizedSpanId = childSpanId.toLowerCase();
|
|
55
|
+
if (!isValidHex(normalizedSpanId, 16) || isAllZeroHex(normalizedSpanId)) throw new Error('Invalid child span id');
|
|
56
|
+
return {
|
|
57
|
+
traceId: parent.traceId.toLowerCase(),
|
|
58
|
+
spanId: normalizedSpanId,
|
|
59
|
+
sampled: parent.sampled,
|
|
60
|
+
parentSpanId: parent.spanId.toLowerCase()
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
exports.deriveChildTraceContext = __webpack_exports__.deriveChildTraceContext;
|
|
64
|
+
exports.formatTraceparentHeader = __webpack_exports__.formatTraceparentHeader;
|
|
65
|
+
exports.parseTraceparentHeader = __webpack_exports__.parseTraceparentHeader;
|
|
66
|
+
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
67
|
+
"deriveChildTraceContext",
|
|
68
|
+
"formatTraceparentHeader",
|
|
69
|
+
"parseTraceparentHeader"
|
|
70
|
+
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
71
|
+
Object.defineProperty(exports, '__esModule', {
|
|
72
|
+
value: true
|
|
73
|
+
});
|
|
@@ -0,0 +1,48 @@
|
|
|
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
|
+
const DEFAULT_DATA_ENVELOPE_HEADER = 'x-modernjs-data-envelope';
|
|
31
|
+
const DEFAULT_DATA_BATCH_ENDPOINT = '/_data/batch';
|
|
32
|
+
const DEFAULT_DATA_BATCH_HEADER = 'x-modernjs-data-batch';
|
|
33
|
+
__webpack_require__.d(__webpack_exports__, {}, {
|
|
34
|
+
DEFAULT_DATA_BATCH_ENDPOINT: DEFAULT_DATA_BATCH_ENDPOINT,
|
|
35
|
+
DEFAULT_DATA_BATCH_HEADER: DEFAULT_DATA_BATCH_HEADER,
|
|
36
|
+
DEFAULT_DATA_ENVELOPE_HEADER: DEFAULT_DATA_ENVELOPE_HEADER
|
|
37
|
+
});
|
|
38
|
+
exports.DEFAULT_DATA_BATCH_ENDPOINT = __webpack_exports__.DEFAULT_DATA_BATCH_ENDPOINT;
|
|
39
|
+
exports.DEFAULT_DATA_BATCH_HEADER = __webpack_exports__.DEFAULT_DATA_BATCH_HEADER;
|
|
40
|
+
exports.DEFAULT_DATA_ENVELOPE_HEADER = __webpack_exports__.DEFAULT_DATA_ENVELOPE_HEADER;
|
|
41
|
+
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
42
|
+
"DEFAULT_DATA_BATCH_ENDPOINT",
|
|
43
|
+
"DEFAULT_DATA_BATCH_HEADER",
|
|
44
|
+
"DEFAULT_DATA_ENVELOPE_HEADER"
|
|
45
|
+
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
46
|
+
Object.defineProperty(exports, '__esModule', {
|
|
47
|
+
value: true
|
|
48
|
+
});
|
|
@@ -0,0 +1,178 @@
|
|
|
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
|
+
createHydrationEnvelope: ()=>createHydrationEnvelope,
|
|
32
|
+
createRequestEnvelope: ()=>createRequestEnvelope,
|
|
33
|
+
validateHydrationEnvelope: ()=>validateHydrationEnvelope,
|
|
34
|
+
validateRequestEnvelope: ()=>validateRequestEnvelope,
|
|
35
|
+
validateSelectionPlan: ()=>validateSelectionPlan
|
|
36
|
+
});
|
|
37
|
+
const external_codec_js_namespaceObject = require("./codec.js");
|
|
38
|
+
const external_trace_js_namespaceObject = require("./trace.js");
|
|
39
|
+
function validateSelectionPlan(plan, options = {}) {
|
|
40
|
+
const maxDepthLimit = options.maxDepth ?? 8;
|
|
41
|
+
const maxFieldsLimit = options.maxFields ?? 256;
|
|
42
|
+
const allowedLeafPaths = options.allowedLeafPaths ? new Set(options.allowedLeafPaths) : null;
|
|
43
|
+
const errors = [];
|
|
44
|
+
let maxDepth = 0;
|
|
45
|
+
let fieldCount = 0;
|
|
46
|
+
const walk = (node, path)=>{
|
|
47
|
+
if (!(0, external_codec_js_namespaceObject.isPlainObject)(node)) return void errors.push(`Selection node at "${path.join('.') || '<root>'}" must be an object`);
|
|
48
|
+
const keys = Object.keys(node);
|
|
49
|
+
if (0 === keys.length) return void errors.push(`Selection node at "${path.join('.') || '<root>'}" cannot be empty`);
|
|
50
|
+
for (const key of keys){
|
|
51
|
+
fieldCount += 1;
|
|
52
|
+
if (fieldCount > maxFieldsLimit) return void errors.push(`Selection has too many fields: ${String(fieldCount)} > ${String(maxFieldsLimit)}`);
|
|
53
|
+
const nextPath = [
|
|
54
|
+
...path,
|
|
55
|
+
key
|
|
56
|
+
];
|
|
57
|
+
const depth = nextPath.length;
|
|
58
|
+
if (depth > maxDepth) maxDepth = depth;
|
|
59
|
+
if (depth > maxDepthLimit) return void errors.push(`Selection exceeds maxDepth at "${nextPath.join('.')}" (${String(depth)} > ${String(maxDepthLimit)})`);
|
|
60
|
+
const value = node[key];
|
|
61
|
+
if (true === value) {
|
|
62
|
+
if (allowedLeafPaths && !allowedLeafPaths.has(nextPath.join('.'))) errors.push(`Unknown selected field "${nextPath.join('.')}"`);
|
|
63
|
+
continue;
|
|
64
|
+
}
|
|
65
|
+
if (!(0, external_codec_js_namespaceObject.isPlainObject)(value)) {
|
|
66
|
+
errors.push(`Invalid selection value at "${nextPath.join('.')}"; expected true or nested object`);
|
|
67
|
+
continue;
|
|
68
|
+
}
|
|
69
|
+
walk(value, nextPath);
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
walk(plan, []);
|
|
73
|
+
return {
|
|
74
|
+
ok: 0 === errors.length,
|
|
75
|
+
errors,
|
|
76
|
+
stats: {
|
|
77
|
+
maxDepth,
|
|
78
|
+
fieldCount
|
|
79
|
+
}
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
function createRequestEnvelope(input) {
|
|
83
|
+
if (input.requireTraceContext && !input.traceContext) throw new Error('Trace context is required for this request envelope');
|
|
84
|
+
const traceparent = input.traceContext ? (0, external_trace_js_namespaceObject.formatTraceparentHeader)(input.traceContext) : void 0;
|
|
85
|
+
const envelope = {
|
|
86
|
+
protocolVersion: input.protocolVersion ?? 1,
|
|
87
|
+
operationId: (0, external_codec_js_namespaceObject.createOperationId)(input.operation),
|
|
88
|
+
appNamespace: (0, external_codec_js_namespaceObject.sanitizeSegment)(input.scope.appNamespace),
|
|
89
|
+
origin: (0, external_codec_js_namespaceObject.normalizeOrigin)(input.scope.origin),
|
|
90
|
+
requestMode: input.requestMode ?? 'cache-first',
|
|
91
|
+
mutationMode: input.mutationMode,
|
|
92
|
+
scopeKey: (0, external_codec_js_namespaceObject.buildScopeKey)(input.scope),
|
|
93
|
+
input: input.requestInput,
|
|
94
|
+
inputHash: (0, external_codec_js_namespaceObject.hashString)((0, external_codec_js_namespaceObject.stableStringify)(input.requestInput ?? null)),
|
|
95
|
+
selectionPlan: input.selectionPlan,
|
|
96
|
+
selectionHash: input.selectionPlan ? (0, external_codec_js_namespaceObject.hashString)((0, external_codec_js_namespaceObject.stableStringify)(input.selectionPlan)) : void 0,
|
|
97
|
+
traceparent,
|
|
98
|
+
timestamp: input.timestamp ?? Date.now()
|
|
99
|
+
};
|
|
100
|
+
return envelope;
|
|
101
|
+
}
|
|
102
|
+
function validateRequestEnvelope(envelope, options = {}) {
|
|
103
|
+
const errors = [];
|
|
104
|
+
if (void 0 !== options.expectedProtocolVersion && envelope.protocolVersion !== options.expectedProtocolVersion) errors.push(`Protocol mismatch: expected ${String(options.expectedProtocolVersion)} but received ${String(envelope.protocolVersion)}`);
|
|
105
|
+
if (options.expectedNamespace && envelope.appNamespace !== options.expectedNamespace) errors.push(`Namespace mismatch: expected ${options.expectedNamespace} but received ${envelope.appNamespace}`);
|
|
106
|
+
if (options.expectedOrigin) {
|
|
107
|
+
const expectedOrigin = (0, external_codec_js_namespaceObject.normalizeOrigin)(options.expectedOrigin);
|
|
108
|
+
if (envelope.origin !== expectedOrigin) errors.push(`Origin mismatch: expected ${expectedOrigin} but received ${envelope.origin}`);
|
|
109
|
+
}
|
|
110
|
+
if (!envelope.operationId) errors.push('Missing operationId');
|
|
111
|
+
if (!envelope.scopeKey) errors.push('Missing scopeKey');
|
|
112
|
+
if (options.requireTraceContext && !envelope.traceparent) errors.push('Missing trace context');
|
|
113
|
+
if (envelope.traceparent && !(0, external_trace_js_namespaceObject.parseTraceparentHeader)(envelope.traceparent)) errors.push('Invalid traceparent header');
|
|
114
|
+
const computedInputHash = (0, external_codec_js_namespaceObject.hashString)((0, external_codec_js_namespaceObject.stableStringify)(envelope.input ?? null));
|
|
115
|
+
if (computedInputHash !== envelope.inputHash) errors.push('Input hash mismatch');
|
|
116
|
+
if (envelope.selectionPlan) {
|
|
117
|
+
const computedSelectionHash = (0, external_codec_js_namespaceObject.hashString)((0, external_codec_js_namespaceObject.stableStringify)(envelope.selectionPlan));
|
|
118
|
+
if (computedSelectionHash !== envelope.selectionHash) errors.push('Selection hash mismatch');
|
|
119
|
+
}
|
|
120
|
+
return {
|
|
121
|
+
ok: 0 === errors.length,
|
|
122
|
+
errors
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
function createHydrationEnvelope(input) {
|
|
126
|
+
const envelopeWithoutChecksum = {
|
|
127
|
+
protocolVersion: input.protocolVersion ?? 1,
|
|
128
|
+
runtimeVersion: input.runtimeVersion,
|
|
129
|
+
appNamespace: (0, external_codec_js_namespaceObject.sanitizeSegment)(input.scope.appNamespace),
|
|
130
|
+
origin: (0, external_codec_js_namespaceObject.normalizeOrigin)(input.scope.origin),
|
|
131
|
+
createdAt: input.createdAt ?? Date.now(),
|
|
132
|
+
payload: input.payload
|
|
133
|
+
};
|
|
134
|
+
const checksum = (0, external_codec_js_namespaceObject.hashString)((0, external_codec_js_namespaceObject.stableStringify)(envelopeWithoutChecksum));
|
|
135
|
+
return {
|
|
136
|
+
...envelopeWithoutChecksum,
|
|
137
|
+
checksum
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
function validateHydrationEnvelope(envelope, options = {}) {
|
|
141
|
+
const errors = [];
|
|
142
|
+
if (void 0 !== options.expectedProtocolVersion && envelope.protocolVersion !== options.expectedProtocolVersion) errors.push(`Protocol mismatch: expected ${String(options.expectedProtocolVersion)} but received ${String(envelope.protocolVersion)}`);
|
|
143
|
+
if (options.expectedNamespace && envelope.appNamespace !== options.expectedNamespace) errors.push(`Namespace mismatch: expected ${options.expectedNamespace} but received ${envelope.appNamespace}`);
|
|
144
|
+
if (options.expectedOrigin) {
|
|
145
|
+
const expectedOrigin = (0, external_codec_js_namespaceObject.normalizeOrigin)(options.expectedOrigin);
|
|
146
|
+
if (envelope.origin !== expectedOrigin) errors.push(`Origin mismatch: expected ${expectedOrigin} but received ${envelope.origin}`);
|
|
147
|
+
}
|
|
148
|
+
if (options.expectedRuntimeVersion && envelope.runtimeVersion !== options.expectedRuntimeVersion) errors.push(`Runtime version mismatch: expected ${options.expectedRuntimeVersion} but received ${envelope.runtimeVersion}`);
|
|
149
|
+
const checksumBase = {
|
|
150
|
+
protocolVersion: envelope.protocolVersion,
|
|
151
|
+
runtimeVersion: envelope.runtimeVersion,
|
|
152
|
+
appNamespace: envelope.appNamespace,
|
|
153
|
+
origin: envelope.origin,
|
|
154
|
+
createdAt: envelope.createdAt,
|
|
155
|
+
payload: envelope.payload
|
|
156
|
+
};
|
|
157
|
+
const checksum = (0, external_codec_js_namespaceObject.hashString)((0, external_codec_js_namespaceObject.stableStringify)(checksumBase));
|
|
158
|
+
if (checksum !== envelope.checksum) errors.push('Hydration checksum mismatch');
|
|
159
|
+
return {
|
|
160
|
+
ok: 0 === errors.length,
|
|
161
|
+
errors
|
|
162
|
+
};
|
|
163
|
+
}
|
|
164
|
+
exports.createHydrationEnvelope = __webpack_exports__.createHydrationEnvelope;
|
|
165
|
+
exports.createRequestEnvelope = __webpack_exports__.createRequestEnvelope;
|
|
166
|
+
exports.validateHydrationEnvelope = __webpack_exports__.validateHydrationEnvelope;
|
|
167
|
+
exports.validateRequestEnvelope = __webpack_exports__.validateRequestEnvelope;
|
|
168
|
+
exports.validateSelectionPlan = __webpack_exports__.validateSelectionPlan;
|
|
169
|
+
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
170
|
+
"createHydrationEnvelope",
|
|
171
|
+
"createRequestEnvelope",
|
|
172
|
+
"validateHydrationEnvelope",
|
|
173
|
+
"validateRequestEnvelope",
|
|
174
|
+
"validateSelectionPlan"
|
|
175
|
+
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
176
|
+
Object.defineProperty(exports, '__esModule', {
|
|
177
|
+
value: true
|
|
178
|
+
});
|
|
@@ -0,0 +1,59 @@
|
|
|
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
|
+
createEffectOperationContext: ()=>external_operation_context_js_namespaceObject.createEffectOperationContext,
|
|
32
|
+
runWithEffectContext: ()=>runWithEffectContext,
|
|
33
|
+
useEffectContext: ()=>useEffectContext,
|
|
34
|
+
useOperationContext: ()=>useOperationContext
|
|
35
|
+
});
|
|
36
|
+
const external_node_async_hooks_namespaceObject = require("node:async_hooks");
|
|
37
|
+
const external_operation_context_js_namespaceObject = require("./operation-context.js");
|
|
38
|
+
const globalStore = globalThis;
|
|
39
|
+
const effectContextStorage = globalStore[external_operation_context_js_namespaceObject.kEffectContextStorage] ?? (globalStore[external_operation_context_js_namespaceObject.kEffectContextStorage] = new external_node_async_hooks_namespaceObject.AsyncLocalStorage());
|
|
40
|
+
const runWithEffectContext = (context, cb)=>effectContextStorage.run(context, cb);
|
|
41
|
+
const useEffectContext = ()=>{
|
|
42
|
+
const context = effectContextStorage.getStore();
|
|
43
|
+
if (!context) throw new Error("Can't call useEffectContext out of Effect runtime scope");
|
|
44
|
+
return context;
|
|
45
|
+
};
|
|
46
|
+
const useOperationContext = ()=>useEffectContext().operationContext;
|
|
47
|
+
exports.createEffectOperationContext = __webpack_exports__.createEffectOperationContext;
|
|
48
|
+
exports.runWithEffectContext = __webpack_exports__.runWithEffectContext;
|
|
49
|
+
exports.useEffectContext = __webpack_exports__.useEffectContext;
|
|
50
|
+
exports.useOperationContext = __webpack_exports__.useOperationContext;
|
|
51
|
+
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
52
|
+
"createEffectOperationContext",
|
|
53
|
+
"runWithEffectContext",
|
|
54
|
+
"useEffectContext",
|
|
55
|
+
"useOperationContext"
|
|
56
|
+
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
57
|
+
Object.defineProperty(exports, '__esModule', {
|
|
58
|
+
value: true
|
|
59
|
+
});
|
|
@@ -0,0 +1,101 @@
|
|
|
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
|
+
dispatchEffectBffRequestWithContext: ()=>dispatchEffectBffRequestWithContext
|
|
32
|
+
});
|
|
33
|
+
const safe_failure_namespaceObject = require("@modern-js/runtime-extensions/safe-failure");
|
|
34
|
+
const external_operation_context_js_namespaceObject = require("./operation-context.js");
|
|
35
|
+
function normalizeEffectBffPrefix(prefix) {
|
|
36
|
+
if (!prefix || '/' === prefix) return '';
|
|
37
|
+
return prefix.endsWith('/') ? prefix.slice(0, -1) : prefix;
|
|
38
|
+
}
|
|
39
|
+
function removeEffectBffPrefixFromPath(pathname, prefix) {
|
|
40
|
+
const normalized = normalizeEffectBffPrefix(prefix);
|
|
41
|
+
if (!normalized || pathname !== normalized && !pathname.startsWith(`${normalized}/`)) return pathname;
|
|
42
|
+
const sliced = pathname.slice(normalized.length);
|
|
43
|
+
return sliced.startsWith('/') ? sliced : `/${sliced}`;
|
|
44
|
+
}
|
|
45
|
+
function matchesEffectBffPrefix(pathname, prefix) {
|
|
46
|
+
const normalized = normalizeEffectBffPrefix(prefix);
|
|
47
|
+
return !normalized || pathname === normalized || pathname.startsWith(`${normalized}/`);
|
|
48
|
+
}
|
|
49
|
+
function createEffectBffMountedRequest(req, prefix) {
|
|
50
|
+
const url = new URL(req.url);
|
|
51
|
+
const nextPath = removeEffectBffPrefixFromPath(url.pathname, prefix);
|
|
52
|
+
if (nextPath !== url.pathname) {
|
|
53
|
+
url.pathname = nextPath;
|
|
54
|
+
return new Request(url, req);
|
|
55
|
+
}
|
|
56
|
+
return req;
|
|
57
|
+
}
|
|
58
|
+
function createEffectBffDispatchContext(originalRequest, mountedRequest, options) {
|
|
59
|
+
const path = options.path ?? new URL(originalRequest.url).pathname;
|
|
60
|
+
const method = options.method ?? originalRequest.method;
|
|
61
|
+
const env = options.env ?? {};
|
|
62
|
+
return {
|
|
63
|
+
request: mountedRequest,
|
|
64
|
+
env,
|
|
65
|
+
path,
|
|
66
|
+
method,
|
|
67
|
+
operationContext: (0, external_operation_context_js_namespaceObject.createEffectOperationContext)({
|
|
68
|
+
request: mountedRequest,
|
|
69
|
+
env,
|
|
70
|
+
path,
|
|
71
|
+
method
|
|
72
|
+
})
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
async function dispatchEffectBffRequestWithContext(handler, request, options) {
|
|
76
|
+
const requestPath = new URL(request.url).pathname;
|
|
77
|
+
if (!matchesEffectBffPrefix(requestPath, options.prefix)) return new Response('', {
|
|
78
|
+
status: 404
|
|
79
|
+
});
|
|
80
|
+
const mountedRequest = createEffectBffMountedRequest(request, options.prefix);
|
|
81
|
+
const effectContext = createEffectBffDispatchContext(request, mountedRequest, options);
|
|
82
|
+
try {
|
|
83
|
+
const response = await options.runWithEffectContext(effectContext, ()=>handler(mountedRequest, effectContext));
|
|
84
|
+
if (!(response instanceof Response)) throw new Error('[BFF][Effect] Effect handler must return Response instance.');
|
|
85
|
+
return new Response(response.body, response);
|
|
86
|
+
} catch (error) {
|
|
87
|
+
if (error instanceof Response) return new Response(error.body, error);
|
|
88
|
+
if (options.onError) {
|
|
89
|
+
const errorResponse = await options.onError(error, effectContext);
|
|
90
|
+
if (errorResponse instanceof Response) return errorResponse;
|
|
91
|
+
}
|
|
92
|
+
return (0, safe_failure_namespaceObject.createSafeFailureResponse)(error);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
exports.dispatchEffectBffRequestWithContext = __webpack_exports__.dispatchEffectBffRequestWithContext;
|
|
96
|
+
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
97
|
+
"dispatchEffectBffRequestWithContext"
|
|
98
|
+
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
99
|
+
Object.defineProperty(exports, '__esModule', {
|
|
100
|
+
value: true
|
|
101
|
+
});
|
|
@@ -0,0 +1,61 @@
|
|
|
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
|
+
createEffectOperationContext: ()=>external_operation_context_js_namespaceObject.createEffectOperationContext,
|
|
32
|
+
runWithEffectContext: ()=>runWithEffectContext,
|
|
33
|
+
useEffectContext: ()=>useEffectContext,
|
|
34
|
+
useOperationContext: ()=>useOperationContext
|
|
35
|
+
});
|
|
36
|
+
const external_operation_context_js_namespaceObject = require("./operation-context.js");
|
|
37
|
+
const globalStore = globalThis;
|
|
38
|
+
const asyncHooks = globalStore.process?.getBuiltinModule?.('node:async_hooks');
|
|
39
|
+
const AsyncLocalStorage = asyncHooks?.AsyncLocalStorage;
|
|
40
|
+
if ('function' != typeof AsyncLocalStorage) throw new Error('[BFF][Effect] The edge runtime must provide AsyncLocalStorage. Enable Node.js compatibility or the nodejs_als compatibility flag.');
|
|
41
|
+
const effectContextStorage = globalStore[external_operation_context_js_namespaceObject.kEffectContextStorage] ?? (globalStore[external_operation_context_js_namespaceObject.kEffectContextStorage] = new AsyncLocalStorage());
|
|
42
|
+
const runWithEffectContext = (context, cb)=>effectContextStorage.run(context, cb);
|
|
43
|
+
const useEffectContext = ()=>{
|
|
44
|
+
const context = effectContextStorage.getStore();
|
|
45
|
+
if (!context) throw new Error("Can't call useEffectContext out of Effect runtime scope");
|
|
46
|
+
return context;
|
|
47
|
+
};
|
|
48
|
+
const useOperationContext = ()=>useEffectContext().operationContext;
|
|
49
|
+
exports.createEffectOperationContext = __webpack_exports__.createEffectOperationContext;
|
|
50
|
+
exports.runWithEffectContext = __webpack_exports__.runWithEffectContext;
|
|
51
|
+
exports.useEffectContext = __webpack_exports__.useEffectContext;
|
|
52
|
+
exports.useOperationContext = __webpack_exports__.useOperationContext;
|
|
53
|
+
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
54
|
+
"createEffectOperationContext",
|
|
55
|
+
"runWithEffectContext",
|
|
56
|
+
"useEffectContext",
|
|
57
|
+
"useOperationContext"
|
|
58
|
+
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
59
|
+
Object.defineProperty(exports, '__esModule', {
|
|
60
|
+
value: true
|
|
61
|
+
});
|