@bleedingdev/modern-js-plugin-bff 3.5.0-ultramodern.30 → 3.5.0-ultramodern.31
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/cli/compress.js +52 -0
- package/dist/cjs/cli/generator.js +149 -0
- package/dist/cjs/cli/prefix.js +50 -0
- package/dist/cjs/cli/watch.js +51 -0
- package/dist/cjs/cli.js +11 -130
- package/dist/cjs/runtime/data-platform/batch/queue.js +287 -0
- package/dist/cjs/runtime/data-platform/batch/request.js +98 -0
- package/dist/cjs/runtime/data-platform/batch/response.js +67 -0
- package/dist/cjs/runtime/data-platform/batch/telemetry.js +67 -0
- package/dist/cjs/runtime/data-platform/batch/url.js +69 -0
- package/dist/cjs/runtime/data-platform/batch-transport.js +59 -0
- package/dist/cjs/runtime/data-platform/codec.js +155 -0
- package/dist/cjs/runtime/data-platform/index.js +30 -633
- package/dist/cjs/runtime/data-platform/invalidation.js +61 -0
- package/dist/cjs/runtime/data-platform/trace.js +73 -0
- package/dist/cjs/runtime/data-platform/types.js +48 -0
- package/dist/cjs/runtime/data-platform/validation.js +178 -0
- package/dist/cjs/runtime/effect/adapter/constants.js +44 -0
- package/dist/cjs/runtime/effect/adapter/cross-project-policy.js +61 -0
- package/dist/cjs/runtime/effect/adapter/entry.js +77 -0
- package/dist/cjs/runtime/effect/adapter/error-response.js +79 -0
- package/dist/cjs/runtime/effect/adapter/handler.js +53 -0
- package/dist/cjs/runtime/effect/adapter.js +12 -115
- package/dist/cjs/runtime/effect/backend-federation/entry.js +99 -0
- package/dist/cjs/runtime/effect/backend-federation/load.js +57 -0
- package/dist/cjs/runtime/effect/backend-federation/plugin.js +53 -0
- package/dist/cjs/runtime/effect/backend-federation/remotes.js +50 -0
- package/dist/cjs/runtime/effect/backend-federation/runtime.js +64 -0
- package/dist/cjs/runtime/effect/backend-federation/types.js +18 -0
- package/dist/cjs/runtime/effect/backend-federation/utils.js +48 -0
- package/dist/cjs/runtime/effect/backend-federation-manifest/errors.js +83 -0
- package/dist/cjs/runtime/effect/backend-federation-manifest/index.js +55 -0
- package/dist/cjs/runtime/effect/backend-federation-manifest/load.js +74 -0
- package/dist/cjs/runtime/effect/backend-federation-manifest/metadata.js +101 -0
- package/dist/cjs/runtime/effect/backend-federation-manifest/reference.js +117 -0
- package/dist/cjs/runtime/effect/backend-federation-manifest/remote.js +68 -0
- package/dist/cjs/runtime/effect/backend-federation-manifest/types.js +18 -0
- package/dist/cjs/runtime/effect/backend-federation-manifest/validation.js +108 -0
- package/dist/cjs/runtime/effect/backend-federation-manifest.js +32 -257
- package/dist/cjs/runtime/effect/backend-federation.js +11 -139
- package/dist/cjs/runtime/effect/handler/batch-handler.js +161 -0
- package/dist/cjs/runtime/effect/handler/batch.js +195 -0
- package/dist/cjs/runtime/effect/handler/definition.js +101 -0
- package/dist/cjs/runtime/effect/handler/envelope.js +104 -0
- package/dist/cjs/runtime/effect/handler/http.js +96 -0
- package/dist/cjs/runtime/effect/handler/openapi.js +57 -0
- package/dist/cjs/runtime/effect/handler/routing.js +100 -0
- package/dist/cjs/runtime/effect/handler/rpc.js +63 -0
- package/dist/cjs/runtime/effect/handler/types.js +43 -0
- package/dist/cjs/runtime/effect/handler.js +35 -526
- package/dist/cjs/runtime/effect/rpcSerialization.js +54 -0
- package/dist/cjs/runtime/effect-client/batch.js +73 -0
- package/dist/cjs/runtime/effect-client/envelope.js +145 -0
- package/dist/cjs/runtime/effect-client/guards.js +44 -0
- package/dist/cjs/runtime/effect-client/index.js +6 -16
- package/dist/cjs/runtime/effect-client/request-context.js +64 -0
- package/dist/cjs/runtime/effect-client/request.js +66 -0
- package/dist/cjs/runtime/effect-client/runtime.js +12 -178
- package/dist/cjs/runtime/effect-client/types.js +18 -0
- package/dist/cjs/runtime/safe-failure.js +2 -1
- package/dist/cjs/utils/client-generator/files.js +152 -0
- package/dist/cjs/utils/client-generator/generate.js +138 -0
- package/dist/cjs/utils/client-generator/index.js +83 -0
- package/dist/cjs/utils/client-generator/package-json.js +132 -0
- package/dist/cjs/utils/client-generator/write-package.js +125 -0
- package/dist/cjs/utils/clientGenerator.js +26 -303
- package/dist/cjs/utils/effect-client-generator/generator.js +64 -0
- package/dist/cjs/utils/effect-client-generator/index.js +51 -0
- package/dist/cjs/utils/effect-client-generator/paths.js +73 -0
- package/dist/cjs/utils/effect-client-generator/rendering.js +231 -0
- package/dist/cjs/utils/effect-client-generator/runtime.js +84 -0
- package/dist/cjs/utils/effect-client-generator/types.js +18 -0
- package/dist/cjs/utils/effectClientGenerator.js +5 -262
- package/dist/esm/cli/compress.mjs +14 -0
- package/dist/esm/cli/generator.mjs +98 -0
- package/dist/esm/cli/prefix.mjs +9 -0
- package/dist/esm/cli/watch.mjs +13 -0
- package/dist/esm/cli.mjs +7 -121
- package/dist/esm/runtime/data-platform/batch/queue.mjs +246 -0
- package/dist/esm/runtime/data-platform/batch/request.mjs +45 -0
- package/dist/esm/runtime/data-platform/batch/response.mjs +23 -0
- package/dist/esm/runtime/data-platform/batch/telemetry.mjs +23 -0
- package/dist/esm/runtime/data-platform/batch/url.mjs +25 -0
- package/dist/esm/runtime/data-platform/batch-transport.mjs +12 -0
- package/dist/esm/runtime/data-platform/codec.mjs +90 -0
- package/dist/esm/runtime/data-platform/index.mjs +6 -610
- package/dist/esm/runtime/data-platform/invalidation.mjs +20 -0
- package/dist/esm/runtime/data-platform/trace.mjs +29 -0
- package/dist/esm/runtime/data-platform/types.mjs +4 -0
- package/dist/esm/runtime/data-platform/validation.mjs +128 -0
- package/dist/esm/runtime/effect/adapter/constants.mjs +6 -0
- package/dist/esm/runtime/effect/adapter/cross-project-policy.mjs +23 -0
- package/dist/esm/runtime/effect/adapter/entry.mjs +29 -0
- package/dist/esm/runtime/effect/adapter/error-response.mjs +41 -0
- package/dist/esm/runtime/effect/adapter/handler.mjs +15 -0
- package/dist/esm/runtime/effect/adapter.mjs +12 -105
- package/dist/esm/runtime/effect/backend-federation/entry.mjs +61 -0
- package/dist/esm/runtime/effect/backend-federation/load.mjs +19 -0
- package/dist/esm/runtime/effect/backend-federation/plugin.mjs +15 -0
- package/dist/esm/runtime/effect/backend-federation/remotes.mjs +12 -0
- package/dist/esm/runtime/effect/backend-federation/runtime.mjs +26 -0
- package/dist/esm/runtime/effect/backend-federation/types.mjs +0 -0
- package/dist/esm/runtime/effect/backend-federation/utils.mjs +7 -0
- package/dist/esm/runtime/effect/backend-federation-manifest/errors.mjs +32 -0
- package/dist/esm/runtime/effect/backend-federation-manifest/index.mjs +4 -0
- package/dist/esm/runtime/effect/backend-federation-manifest/load.mjs +36 -0
- package/dist/esm/runtime/effect/backend-federation-manifest/metadata.mjs +42 -0
- package/dist/esm/runtime/effect/backend-federation-manifest/reference.mjs +76 -0
- package/dist/esm/runtime/effect/backend-federation-manifest/remote.mjs +30 -0
- package/dist/esm/runtime/effect/backend-federation-manifest/types.mjs +0 -0
- package/dist/esm/runtime/effect/backend-federation-manifest/validation.mjs +64 -0
- package/dist/esm/runtime/effect/backend-federation-manifest.mjs +1 -237
- package/dist/esm/runtime/effect/backend-federation.mjs +4 -132
- package/dist/esm/runtime/effect/handler/batch-handler.mjs +123 -0
- package/dist/esm/runtime/effect/handler/batch.mjs +124 -0
- package/dist/esm/runtime/effect/handler/definition.mjs +60 -0
- package/dist/esm/runtime/effect/handler/envelope.mjs +63 -0
- package/dist/esm/runtime/effect/handler/http.mjs +58 -0
- package/dist/esm/runtime/effect/handler/openapi.mjs +19 -0
- package/dist/esm/runtime/effect/handler/routing.mjs +50 -0
- package/dist/esm/runtime/effect/handler/rpc.mjs +22 -0
- package/dist/esm/runtime/effect/handler/types.mjs +5 -0
- package/dist/esm/runtime/effect/handler.mjs +7 -499
- package/dist/esm/runtime/effect/rpcSerialization.mjs +16 -0
- package/dist/esm/runtime/effect-client/batch.mjs +35 -0
- package/dist/esm/runtime/effect-client/envelope.mjs +104 -0
- package/dist/esm/runtime/effect-client/guards.mjs +3 -0
- package/dist/esm/runtime/effect-client/index.mjs +5 -15
- package/dist/esm/runtime/effect-client/request-context.mjs +23 -0
- package/dist/esm/runtime/effect-client/request.mjs +28 -0
- package/dist/esm/runtime/effect-client/runtime.mjs +12 -178
- package/dist/esm/runtime/effect-client/types.mjs +0 -0
- package/dist/esm/runtime/safe-failure.mjs +2 -1
- package/dist/esm/utils/client-generator/files.mjs +68 -0
- package/dist/esm/utils/client-generator/generate.mjs +88 -0
- package/dist/esm/utils/client-generator/index.mjs +4 -0
- package/dist/esm/utils/client-generator/package-json.mjs +78 -0
- package/dist/esm/utils/client-generator/write-package.mjs +74 -0
- package/dist/esm/utils/clientGenerator.mjs +2 -293
- package/dist/esm/utils/effect-client-generator/generator.mjs +23 -0
- package/dist/esm/utils/effect-client-generator/index.mjs +3 -0
- package/dist/esm/utils/effect-client-generator/paths.mjs +25 -0
- package/dist/esm/utils/effect-client-generator/rendering.mjs +180 -0
- package/dist/esm/utils/effect-client-generator/runtime.mjs +33 -0
- package/dist/esm/utils/effect-client-generator/types.mjs +0 -0
- package/dist/esm/utils/effectClientGenerator.mjs +1 -249
- package/dist/esm-node/cli/compress.mjs +15 -0
- package/dist/esm-node/cli/generator.mjs +99 -0
- package/dist/esm-node/cli/prefix.mjs +10 -0
- package/dist/esm-node/cli/watch.mjs +14 -0
- package/dist/esm-node/cli.mjs +7 -121
- package/dist/esm-node/runtime/data-platform/batch/queue.mjs +247 -0
- package/dist/esm-node/runtime/data-platform/batch/request.mjs +46 -0
- package/dist/esm-node/runtime/data-platform/batch/response.mjs +24 -0
- package/dist/esm-node/runtime/data-platform/batch/telemetry.mjs +24 -0
- package/dist/esm-node/runtime/data-platform/batch/url.mjs +26 -0
- package/dist/esm-node/runtime/data-platform/batch-transport.mjs +13 -0
- package/dist/esm-node/runtime/data-platform/codec.mjs +91 -0
- package/dist/esm-node/runtime/data-platform/index.mjs +6 -610
- package/dist/esm-node/runtime/data-platform/invalidation.mjs +21 -0
- package/dist/esm-node/runtime/data-platform/trace.mjs +30 -0
- package/dist/esm-node/runtime/data-platform/types.mjs +5 -0
- package/dist/esm-node/runtime/data-platform/validation.mjs +129 -0
- package/dist/esm-node/runtime/effect/adapter/constants.mjs +7 -0
- package/dist/esm-node/runtime/effect/adapter/cross-project-policy.mjs +24 -0
- package/dist/esm-node/runtime/effect/adapter/entry.mjs +30 -0
- package/dist/esm-node/runtime/effect/adapter/error-response.mjs +42 -0
- package/dist/esm-node/runtime/effect/adapter/handler.mjs +16 -0
- package/dist/esm-node/runtime/effect/adapter.mjs +12 -105
- package/dist/esm-node/runtime/effect/backend-federation/entry.mjs +62 -0
- package/dist/esm-node/runtime/effect/backend-federation/load.mjs +20 -0
- package/dist/esm-node/runtime/effect/backend-federation/plugin.mjs +16 -0
- package/dist/esm-node/runtime/effect/backend-federation/remotes.mjs +13 -0
- package/dist/esm-node/runtime/effect/backend-federation/runtime.mjs +27 -0
- package/dist/esm-node/runtime/effect/backend-federation/types.mjs +1 -0
- package/dist/esm-node/runtime/effect/backend-federation/utils.mjs +8 -0
- package/dist/esm-node/runtime/effect/backend-federation-manifest/errors.mjs +33 -0
- package/dist/esm-node/runtime/effect/backend-federation-manifest/index.mjs +5 -0
- package/dist/esm-node/runtime/effect/backend-federation-manifest/load.mjs +37 -0
- package/dist/esm-node/runtime/effect/backend-federation-manifest/metadata.mjs +43 -0
- package/dist/esm-node/runtime/effect/backend-federation-manifest/reference.mjs +77 -0
- package/dist/esm-node/runtime/effect/backend-federation-manifest/remote.mjs +31 -0
- package/dist/esm-node/runtime/effect/backend-federation-manifest/types.mjs +1 -0
- package/dist/esm-node/runtime/effect/backend-federation-manifest/validation.mjs +65 -0
- package/dist/esm-node/runtime/effect/backend-federation-manifest.mjs +1 -237
- package/dist/esm-node/runtime/effect/backend-federation.mjs +4 -132
- package/dist/esm-node/runtime/effect/handler/batch-handler.mjs +124 -0
- package/dist/esm-node/runtime/effect/handler/batch.mjs +125 -0
- package/dist/esm-node/runtime/effect/handler/definition.mjs +61 -0
- package/dist/esm-node/runtime/effect/handler/envelope.mjs +64 -0
- package/dist/esm-node/runtime/effect/handler/http.mjs +59 -0
- package/dist/esm-node/runtime/effect/handler/openapi.mjs +20 -0
- package/dist/esm-node/runtime/effect/handler/routing.mjs +51 -0
- package/dist/esm-node/runtime/effect/handler/rpc.mjs +23 -0
- package/dist/esm-node/runtime/effect/handler/types.mjs +6 -0
- package/dist/esm-node/runtime/effect/handler.mjs +7 -499
- package/dist/esm-node/runtime/effect/rpcSerialization.mjs +17 -0
- package/dist/esm-node/runtime/effect-client/batch.mjs +36 -0
- package/dist/esm-node/runtime/effect-client/envelope.mjs +105 -0
- package/dist/esm-node/runtime/effect-client/guards.mjs +4 -0
- package/dist/esm-node/runtime/effect-client/index.mjs +5 -15
- package/dist/esm-node/runtime/effect-client/request-context.mjs +24 -0
- package/dist/esm-node/runtime/effect-client/request.mjs +29 -0
- package/dist/esm-node/runtime/effect-client/runtime.mjs +12 -178
- package/dist/esm-node/runtime/effect-client/types.mjs +1 -0
- package/dist/esm-node/runtime/safe-failure.mjs +2 -1
- package/dist/esm-node/utils/client-generator/files.mjs +69 -0
- package/dist/esm-node/utils/client-generator/generate.mjs +89 -0
- package/dist/esm-node/utils/client-generator/index.mjs +5 -0
- package/dist/esm-node/utils/client-generator/package-json.mjs +79 -0
- package/dist/esm-node/utils/client-generator/write-package.mjs +75 -0
- package/dist/esm-node/utils/clientGenerator.mjs +2 -293
- package/dist/esm-node/utils/effect-client-generator/generator.mjs +24 -0
- package/dist/esm-node/utils/effect-client-generator/index.mjs +4 -0
- package/dist/esm-node/utils/effect-client-generator/paths.mjs +26 -0
- package/dist/esm-node/utils/effect-client-generator/rendering.mjs +181 -0
- package/dist/esm-node/utils/effect-client-generator/runtime.mjs +35 -0
- package/dist/esm-node/utils/effect-client-generator/types.mjs +1 -0
- package/dist/esm-node/utils/effectClientGenerator.mjs +2 -251
- package/dist/types/cli/compress.d.ts +2 -0
- package/dist/types/cli/generator.d.ts +7 -0
- package/dist/types/cli/prefix.d.ts +2 -0
- package/dist/types/cli/watch.d.ts +1 -0
- package/dist/types/cli.d.ts +0 -1
- package/dist/types/runtime/data-platform/batch/queue.d.ts +25 -0
- package/dist/types/runtime/data-platform/batch/request.d.ts +13 -0
- package/dist/types/runtime/data-platform/batch/response.d.ts +4 -0
- package/dist/types/runtime/data-platform/batch/telemetry.d.ts +4 -0
- package/dist/types/runtime/data-platform/batch/url.d.ts +4 -0
- package/dist/types/runtime/data-platform/batch-transport.d.ts +3 -0
- package/dist/types/runtime/data-platform/codec.d.ts +17 -0
- package/dist/types/runtime/data-platform/index.d.ts +7 -191
- package/dist/types/runtime/data-platform/invalidation.d.ts +8 -0
- package/dist/types/runtime/data-platform/trace.d.ts +4 -0
- package/dist/types/runtime/data-platform/types.d.ts +146 -0
- package/dist/types/runtime/data-platform/validation.d.ts +29 -0
- package/dist/types/runtime/effect/adapter/constants.d.ts +1 -0
- package/dist/types/runtime/effect/adapter/cross-project-policy.d.ts +4 -0
- package/dist/types/runtime/effect/adapter/entry.d.ts +2 -0
- package/dist/types/runtime/effect/adapter/error-response.d.ts +2 -0
- package/dist/types/runtime/effect/adapter/handler.d.ts +4 -0
- package/dist/types/runtime/effect/adapter.d.ts +4 -13
- package/dist/types/runtime/effect/backend-federation/entry.d.ts +2 -0
- package/dist/types/runtime/effect/backend-federation/load.d.ts +2 -0
- package/dist/types/runtime/effect/backend-federation/plugin.d.ts +3 -0
- package/dist/types/runtime/effect/backend-federation/remotes.d.ts +2 -0
- package/dist/types/runtime/effect/backend-federation/runtime.d.ts +3 -0
- package/dist/types/runtime/effect/backend-federation/types.d.ts +58 -0
- package/dist/types/runtime/effect/backend-federation/utils.d.ts +2 -0
- package/dist/types/runtime/effect/backend-federation-manifest/errors.d.ts +11 -0
- package/dist/types/runtime/effect/backend-federation-manifest/index.d.ts +6 -0
- package/dist/types/runtime/effect/backend-federation-manifest/load.d.ts +3 -0
- package/dist/types/runtime/effect/backend-federation-manifest/metadata.d.ts +18 -0
- package/dist/types/runtime/effect/backend-federation-manifest/reference.d.ts +3 -0
- package/dist/types/runtime/effect/backend-federation-manifest/remote.d.ts +3 -0
- package/dist/types/runtime/effect/backend-federation-manifest/types.d.ts +51 -0
- package/dist/types/runtime/effect/backend-federation-manifest/validation.d.ts +5 -0
- package/dist/types/runtime/effect/backend-federation-manifest.d.ts +1 -60
- package/dist/types/runtime/effect/backend-federation.d.ts +6 -60
- package/dist/types/runtime/effect/handler/batch-handler.d.ts +11 -0
- package/dist/types/runtime/effect/handler/batch.d.ts +17 -0
- package/dist/types/runtime/effect/handler/definition.d.ts +17 -0
- package/dist/types/runtime/effect/handler/envelope.d.ts +13 -0
- package/dist/types/runtime/effect/handler/http.d.ts +14 -0
- package/dist/types/runtime/effect/handler/openapi.d.ts +4 -0
- package/dist/types/runtime/effect/handler/routing.d.ts +5 -0
- package/dist/types/runtime/effect/handler/rpc.d.ts +7 -0
- package/dist/types/runtime/effect/handler/types.d.ts +148 -0
- package/dist/types/runtime/effect/handler.d.ts +3 -173
- package/dist/types/runtime/effect/rpcSerialization.d.ts +3 -0
- package/dist/types/runtime/effect-client/batch.d.ts +2 -0
- package/dist/types/runtime/effect-client/envelope.d.ts +15 -0
- package/dist/types/runtime/effect-client/guards.d.ts +2 -0
- package/dist/types/runtime/effect-client/request-context.d.ts +3 -0
- package/dist/types/runtime/effect-client/request.d.ts +1 -0
- package/dist/types/runtime/effect-client/runtime.d.ts +2 -68
- package/dist/types/runtime/effect-client/types.d.ts +68 -0
- package/dist/types/utils/client-generator/files.d.ts +28 -0
- package/dist/types/utils/client-generator/generate.d.ts +26 -0
- package/dist/types/utils/client-generator/index.d.ts +7 -0
- package/dist/types/utils/client-generator/package-json.d.ts +16 -0
- package/dist/types/utils/client-generator/write-package.d.ts +6 -0
- package/dist/types/utils/clientGenerator.d.ts +2 -37
- package/dist/types/utils/crossProjectServerPolicy.d.ts +3 -2
- package/dist/types/utils/effect-client-generator/generator.d.ts +10 -0
- package/dist/types/utils/effect-client-generator/index.d.ts +4 -0
- package/dist/types/utils/effect-client-generator/paths.d.ts +5 -0
- package/dist/types/utils/effect-client-generator/rendering.d.ts +4 -0
- package/dist/types/utils/effect-client-generator/runtime.d.ts +8 -0
- package/dist/types/utils/effect-client-generator/types.d.ts +26 -0
- package/dist/types/utils/effectClientGenerator.d.ts +2 -41
- package/package.json +12 -12
|
@@ -5,6 +5,7 @@ import * as __rspack_external_effect_Layer_16f7a8fc from "effect/Layer";
|
|
|
5
5
|
import { FetchHttpClient, HttpClient, HttpClientRequest } from "effect/unstable/http";
|
|
6
6
|
import { HttpApi, HttpApiClient, HttpApiEndpoint, HttpApiGroup, HttpApiSchema } from "effect/unstable/httpapi";
|
|
7
7
|
import { Rpc, RpcClient, RpcGroup, RpcSchema, RpcSerialization } from "effect/unstable/rpc";
|
|
8
|
+
import { getRpcSerializationLayer } from "../effect/rpcSerialization.mjs";
|
|
8
9
|
import * as __rspack_external_effect_Schema_f8472650 from "effect/Schema";
|
|
9
10
|
import * as __rspack_external_effect_unstable_http_HttpClientError_b9ead235 from "effect/unstable/http/HttpClientError";
|
|
10
11
|
import * as __rspack_external_effect_Data_7c33fca9 from "effect/Data";
|
|
@@ -21,7 +22,10 @@ function applySelection(value, selection) {
|
|
|
21
22
|
if (Array.isArray(value)) return value.map((item)=>applySelection(item, selection));
|
|
22
23
|
if (!isRecord(value) || !isRecord(selection)) return value;
|
|
23
24
|
const masked = {};
|
|
24
|
-
for (const key of Object.keys(selection))
|
|
25
|
+
for (const key of Object.keys(selection)){
|
|
26
|
+
const selected = selection[key];
|
|
27
|
+
if (void 0 !== selected && key in value) masked[key] = applySelection(value[key], selected);
|
|
28
|
+
}
|
|
25
29
|
return masked;
|
|
26
30
|
}
|
|
27
31
|
function view() {
|
|
@@ -35,20 +39,6 @@ function runEffectView(request, selection) {
|
|
|
35
39
|
request.then((value)=>resolve(mask(value, selection)), (reason)=>reject(reason));
|
|
36
40
|
});
|
|
37
41
|
}
|
|
38
|
-
function getRpcSerializationLayer(serialization) {
|
|
39
|
-
switch(serialization){
|
|
40
|
-
case 'ndjson':
|
|
41
|
-
return RpcSerialization.layerNdjson;
|
|
42
|
-
case 'jsonRpc':
|
|
43
|
-
return RpcSerialization.layerJsonRpc();
|
|
44
|
-
case 'ndJsonRpc':
|
|
45
|
-
return RpcSerialization.layerNdJsonRpc();
|
|
46
|
-
case 'msgPack':
|
|
47
|
-
return RpcSerialization.layerMsgPack;
|
|
48
|
-
default:
|
|
49
|
-
return RpcSerialization.layerJsonRpc();
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
42
|
function makeEffectHttpApiClient(api, options) {
|
|
53
43
|
const requestContextHeaders = createRequestContextHeaders(options?.requestContext);
|
|
54
44
|
const transformClient = (client)=>{
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import "node:module";
|
|
2
|
+
import { isRecord } from "./guards.mjs";
|
|
3
|
+
const createEffectRequestContext = (createRequestContextHeaders, requestContext)=>{
|
|
4
|
+
if (!isRecord(requestContext)) return {};
|
|
5
|
+
const headers = createRequestContextHeaders ? createRequestContextHeaders(requestContext) : {};
|
|
6
|
+
return {
|
|
7
|
+
...requestContext,
|
|
8
|
+
headers
|
|
9
|
+
};
|
|
10
|
+
};
|
|
11
|
+
const applyRequestContext = (normalizedRequest, request, createRequestContext)=>{
|
|
12
|
+
if (!isRecord(request) || !isRecord(request.requestContext)) return normalizedRequest;
|
|
13
|
+
const requestContext = createRequestContext(request.requestContext);
|
|
14
|
+
const requestHeaders = isRecord(requestContext.headers) ? requestContext.headers : {};
|
|
15
|
+
if (0 === Object.keys(requestHeaders).length) return normalizedRequest;
|
|
16
|
+
return {
|
|
17
|
+
...normalizedRequest,
|
|
18
|
+
headers: {
|
|
19
|
+
...isRecord(normalizedRequest.headers) ? normalizedRequest.headers : {},
|
|
20
|
+
...requestHeaders
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
};
|
|
24
|
+
export { applyRequestContext, createEffectRequestContext };
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import "node:module";
|
|
2
|
+
import { isRecord } from "./guards.mjs";
|
|
3
|
+
const METHODS_WITHOUT_BODY = new Set([
|
|
4
|
+
'GET',
|
|
5
|
+
'DELETE',
|
|
6
|
+
'HEAD',
|
|
7
|
+
'OPTIONS'
|
|
8
|
+
]);
|
|
9
|
+
const normalizeRequest = (method, request)=>{
|
|
10
|
+
if (!isRecord(request)) return {};
|
|
11
|
+
const payload = {
|
|
12
|
+
...request
|
|
13
|
+
};
|
|
14
|
+
if (isRecord(request.path) && !isRecord(payload.params)) payload.params = request.path;
|
|
15
|
+
if (isRecord(request.urlParams) && !isRecord(payload.query)) payload.query = request.urlParams;
|
|
16
|
+
if (isRecord(request.headers) && !isRecord(payload.headers)) payload.headers = request.headers;
|
|
17
|
+
if ('payload' in request && void 0 !== request.payload) if ("u" > typeof FormData && request.payload instanceof FormData && !('formData' in payload)) payload.formData = request.payload;
|
|
18
|
+
else if (METHODS_WITHOUT_BODY.has(method)) {
|
|
19
|
+
if (isRecord(request.payload)) payload.query = isRecord(payload.query) ? {
|
|
20
|
+
...payload.query,
|
|
21
|
+
...request.payload
|
|
22
|
+
} : request.payload;
|
|
23
|
+
else if (!('body' in payload)) payload.body = request.payload;
|
|
24
|
+
} else if (!isRecord(request.payload) || 'data' in payload) {
|
|
25
|
+
if (!('body' in payload)) payload.body = request.payload;
|
|
26
|
+
} else payload.data = request.payload;
|
|
27
|
+
return payload;
|
|
28
|
+
};
|
|
29
|
+
export { normalizeRequest };
|
|
@@ -1,187 +1,15 @@
|
|
|
1
1
|
import "node:module";
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
'DELETE',
|
|
6
|
-
'HEAD',
|
|
7
|
-
'OPTIONS'
|
|
8
|
-
]);
|
|
9
|
-
const DATA_REQUEST_MODES = new Set([
|
|
10
|
-
'cache-first',
|
|
11
|
-
'stale-while-revalidate',
|
|
12
|
-
'network-only'
|
|
13
|
-
]);
|
|
14
|
-
const DATA_MUTATION_MODES = new Set([
|
|
15
|
-
'optimistic',
|
|
16
|
-
'pessimistic',
|
|
17
|
-
'fire-and-forget'
|
|
18
|
-
]);
|
|
19
|
-
const isRecord = (value)=>'object' == typeof value && null !== value;
|
|
20
|
-
const stringOrUndefined = (value)=>'string' == typeof value && value.length > 0 ? value : void 0;
|
|
21
|
-
const isDataRequestMode = (value)=>'string' == typeof value && DATA_REQUEST_MODES.has(value);
|
|
22
|
-
const isDataMutationMode = (value)=>'string' == typeof value && DATA_MUTATION_MODES.has(value);
|
|
23
|
-
const normalizeOrigin = (value)=>{
|
|
24
|
-
if ('string' != typeof value || 0 === value.length) return;
|
|
25
|
-
try {
|
|
26
|
-
return new URL(value).origin;
|
|
27
|
-
} catch {
|
|
28
|
-
return;
|
|
29
|
-
}
|
|
30
|
-
};
|
|
31
|
-
const resolveRuntimeFetch = ()=>'function' == typeof fetch ? fetch.bind(globalThis) : void 0;
|
|
32
|
-
const resolveOrigin = (defaultOrigin)=>{
|
|
33
|
-
if ("u" > typeof window && window.location && 'string' == typeof window.location.origin && window.location.origin) return window.location.origin;
|
|
34
|
-
const globalLocation = globalThis?.location;
|
|
35
|
-
if (globalLocation && 'string' == typeof globalLocation.origin && globalLocation.origin) return globalLocation.origin;
|
|
36
|
-
return defaultOrigin;
|
|
37
|
-
};
|
|
38
|
-
const normalizeRequest = (method, request)=>{
|
|
39
|
-
if (!isRecord(request)) return {};
|
|
40
|
-
const payload = {
|
|
41
|
-
...request
|
|
42
|
-
};
|
|
43
|
-
if (isRecord(request.path) && !isRecord(payload.params)) payload.params = request.path;
|
|
44
|
-
if (isRecord(request.urlParams) && !isRecord(payload.query)) payload.query = request.urlParams;
|
|
45
|
-
if (isRecord(request.headers) && !isRecord(payload.headers)) payload.headers = request.headers;
|
|
46
|
-
if ('payload' in request && void 0 !== request.payload) if ("u" > typeof FormData && request.payload instanceof FormData && !('formData' in payload)) payload.formData = request.payload;
|
|
47
|
-
else if (METHODS_WITHOUT_BODY.has(method)) {
|
|
48
|
-
if (isRecord(request.payload)) payload.query = isRecord(payload.query) ? {
|
|
49
|
-
...payload.query,
|
|
50
|
-
...request.payload
|
|
51
|
-
} : request.payload;
|
|
52
|
-
else if (!('body' in payload)) payload.body = request.payload;
|
|
53
|
-
} else if (!isRecord(request.payload) || 'data' in payload) {
|
|
54
|
-
if (!('body' in payload)) payload.body = request.payload;
|
|
55
|
-
} else payload.data = request.payload;
|
|
56
|
-
return payload;
|
|
57
|
-
};
|
|
58
|
-
const resolveTargetOrigin = (dataPlatform, defaultOrigin)=>{
|
|
59
|
-
const explicitTargetOrigin = stringOrUndefined(dataPlatform.targetOrigin) || stringOrUndefined(dataPlatform.endpointOrigin);
|
|
60
|
-
if (explicitTargetOrigin) return explicitTargetOrigin;
|
|
61
|
-
return defaultOrigin;
|
|
62
|
-
};
|
|
63
|
-
const shouldAttachEnvelopeHeader = (dataPlatform, defaultOrigin)=>{
|
|
64
|
-
if (true === dataPlatform.allowCrossOriginEnvelope) return true;
|
|
65
|
-
const currentOrigin = normalizeOrigin(resolveOrigin(defaultOrigin));
|
|
66
|
-
const targetOrigin = normalizeOrigin(resolveTargetOrigin(dataPlatform, defaultOrigin));
|
|
67
|
-
if (!currentOrigin || !targetOrigin) return true;
|
|
68
|
-
return currentOrigin === targetOrigin;
|
|
69
|
-
};
|
|
70
|
-
const toEnvelopeInput = (normalizedRequest)=>{
|
|
71
|
-
const payload = {};
|
|
72
|
-
if (isRecord(normalizedRequest.params)) payload.path = normalizedRequest.params;
|
|
73
|
-
if (isRecord(normalizedRequest.query)) payload.query = normalizedRequest.query;
|
|
74
|
-
if ('data' in normalizedRequest && void 0 !== normalizedRequest.data) payload.data = normalizedRequest.data;
|
|
75
|
-
if ('body' in normalizedRequest && void 0 !== normalizedRequest.body) payload.body = normalizedRequest.body;
|
|
76
|
-
if ("u" > typeof FormData && normalizedRequest.formData instanceof FormData) payload.formData = Array.from(normalizedRequest.formData.entries()).map(([key, value])=>[
|
|
77
|
-
key,
|
|
78
|
-
String(value)
|
|
79
|
-
]);
|
|
80
|
-
if ("u" > typeof URLSearchParams && normalizedRequest.formUrlencoded instanceof URLSearchParams) payload.formUrlencoded = normalizedRequest.formUrlencoded.toString();
|
|
81
|
-
return payload;
|
|
82
|
-
};
|
|
2
|
+
import { configureGeneratedEffectClientRuntime } from "./batch.mjs";
|
|
3
|
+
import { prepareEffectRequest } from "./envelope.mjs";
|
|
4
|
+
import { createEffectRequestContext as external_request_context_mjs_createEffectRequestContext } from "./request-context.mjs";
|
|
83
5
|
const createGeneratedEffectClient = (manifest, config, requestRuntime)=>{
|
|
84
6
|
const createRequest = requestRuntime.createRequest;
|
|
85
7
|
const configureRequest = 'function' == typeof requestRuntime.configure ? requestRuntime.configure : void 0;
|
|
86
8
|
const createRequestContextHeaders = 'function' == typeof requestRuntime.createRequestContextHeaders ? requestRuntime.createRequestContextHeaders : void 0;
|
|
87
|
-
const defaultOrigin = config.defaultOrigin;
|
|
88
9
|
const httpMethodDecider = config.httpMethodDecider || 'functionName';
|
|
89
10
|
const port = config.useEnvPort && "u" > typeof process && process.env && process.env.PORT ? process.env.PORT : config.port;
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
requestId: config.requestId,
|
|
93
|
-
requireEnvelope: true,
|
|
94
|
-
identityBinding: {
|
|
95
|
-
enabled: true,
|
|
96
|
-
strict: true
|
|
97
|
-
},
|
|
98
|
-
operationContract: {
|
|
99
|
-
enabled: true,
|
|
100
|
-
strict: true,
|
|
101
|
-
requireSchemaHash: true,
|
|
102
|
-
requireOperationVersion: true
|
|
103
|
-
},
|
|
104
|
-
setDomain: ()=>resolveOrigin(defaultOrigin)
|
|
105
|
-
};
|
|
106
|
-
const runtimeFetch = resolveRuntimeFetch();
|
|
107
|
-
if (false !== config.batch.enabled && runtimeFetch) configurePayload.request = createDataBatchTransport({
|
|
108
|
-
fetch: runtimeFetch,
|
|
109
|
-
endpoint: config.batch.endpoint,
|
|
110
|
-
flushIntervalMs: config.batch.flushIntervalMs,
|
|
111
|
-
maxBatchSize: config.batch.maxBatchSize,
|
|
112
|
-
maxBatchBytes: config.batch.maxBatchBytes,
|
|
113
|
-
requestTimeoutMs: config.batch.requestTimeoutMs,
|
|
114
|
-
allowedMethods: config.batch.allowedMethods
|
|
115
|
-
});
|
|
116
|
-
configureRequest(configurePayload);
|
|
117
|
-
}
|
|
118
|
-
const createEffectRequestContext = (requestContext)=>{
|
|
119
|
-
if (!isRecord(requestContext)) return {};
|
|
120
|
-
const headers = createRequestContextHeaders ? createRequestContextHeaders(requestContext) : {};
|
|
121
|
-
return {
|
|
122
|
-
...requestContext,
|
|
123
|
-
headers
|
|
124
|
-
};
|
|
125
|
-
};
|
|
126
|
-
const applyRequestContext = (normalizedRequest, request)=>{
|
|
127
|
-
if (!isRecord(request) || !isRecord(request.requestContext)) return normalizedRequest;
|
|
128
|
-
const requestContext = createEffectRequestContext(request.requestContext);
|
|
129
|
-
const requestHeaders = isRecord(requestContext.headers) ? requestContext.headers : {};
|
|
130
|
-
if (0 === Object.keys(requestHeaders).length) return normalizedRequest;
|
|
131
|
-
return {
|
|
132
|
-
...normalizedRequest,
|
|
133
|
-
headers: {
|
|
134
|
-
...requestHeaders,
|
|
135
|
-
...isRecord(normalizedRequest.headers) ? normalizedRequest.headers : {}
|
|
136
|
-
}
|
|
137
|
-
};
|
|
138
|
-
};
|
|
139
|
-
const prepareEffectRequest = (endpoint, operation, request)=>{
|
|
140
|
-
const normalizedRequest = applyRequestContext(normalizeRequest(endpoint.method, request), request);
|
|
141
|
-
const dataPlatform = isRecord(request) && isRecord(request.dataPlatform) ? request.dataPlatform : {};
|
|
142
|
-
const strictEnvelope = true === dataPlatform.requireEnvelope || true === dataPlatform.strict;
|
|
143
|
-
if (!strictEnvelope && !shouldAttachEnvelopeHeader(dataPlatform, defaultOrigin)) return normalizedRequest;
|
|
144
|
-
try {
|
|
145
|
-
const namespace = stringOrUndefined(dataPlatform.appNamespace) || config.appNamespace;
|
|
146
|
-
const origin = stringOrUndefined(dataPlatform.origin) || resolveOrigin(defaultOrigin);
|
|
147
|
-
const envelope = createRequestEnvelope({
|
|
148
|
-
operation: {
|
|
149
|
-
...operation,
|
|
150
|
-
appNamespace: namespace
|
|
151
|
-
},
|
|
152
|
-
scope: {
|
|
153
|
-
appNamespace: namespace,
|
|
154
|
-
origin,
|
|
155
|
-
tenantId: stringOrUndefined(dataPlatform.tenantId),
|
|
156
|
-
userId: stringOrUndefined(dataPlatform.userId),
|
|
157
|
-
sessionId: stringOrUndefined(dataPlatform.sessionId)
|
|
158
|
-
},
|
|
159
|
-
requestInput: {
|
|
160
|
-
method: endpoint.method,
|
|
161
|
-
routePath: endpoint.routePath,
|
|
162
|
-
payload: toEnvelopeInput(normalizedRequest)
|
|
163
|
-
},
|
|
164
|
-
requestMode: isDataRequestMode(dataPlatform.requestMode) ? dataPlatform.requestMode : void 0,
|
|
165
|
-
mutationMode: isDataMutationMode(dataPlatform.mutationMode) ? dataPlatform.mutationMode : void 0,
|
|
166
|
-
selectionPlan: isRecord(dataPlatform.selectionPlan) ? dataPlatform.selectionPlan : void 0,
|
|
167
|
-
traceContext: isRecord(dataPlatform.traceContext) ? dataPlatform.traceContext : void 0,
|
|
168
|
-
requireTraceContext: true === dataPlatform.requireTraceContext
|
|
169
|
-
});
|
|
170
|
-
const headerName = stringOrUndefined(dataPlatform.envelopeHeader) || DEFAULT_DATA_ENVELOPE_HEADER;
|
|
171
|
-
const headers = isRecord(normalizedRequest.headers) ? {
|
|
172
|
-
...normalizedRequest.headers
|
|
173
|
-
} : {};
|
|
174
|
-
if (false === dataPlatform.batch) headers[DEFAULT_DATA_BATCH_HEADER] = 'off';
|
|
175
|
-
headers[headerName] = encodeRequestEnvelopeHeader(envelope);
|
|
176
|
-
return {
|
|
177
|
-
...normalizedRequest,
|
|
178
|
-
headers
|
|
179
|
-
};
|
|
180
|
-
} catch (error) {
|
|
181
|
-
if (strictEnvelope) throw error;
|
|
182
|
-
return normalizedRequest;
|
|
183
|
-
}
|
|
184
|
-
};
|
|
11
|
+
configureGeneratedEffectClientRuntime(config, configureRequest);
|
|
12
|
+
const createEffectRequestContext = (requestContext)=>external_request_context_mjs_createEffectRequestContext(createRequestContextHeaders, requestContext);
|
|
185
13
|
const client = {};
|
|
186
14
|
const operationManifest = {};
|
|
187
15
|
for (const endpoint of manifest.endpoints){
|
|
@@ -214,7 +42,13 @@ const createGeneratedEffectClient = (manifest, config, requestRuntime)=>{
|
|
|
214
42
|
requestId: config.requestId
|
|
215
43
|
} : {}
|
|
216
44
|
});
|
|
217
|
-
const call = (request = {})=>sender(prepareEffectRequest(
|
|
45
|
+
const call = (request = {})=>sender(prepareEffectRequest({
|
|
46
|
+
endpoint,
|
|
47
|
+
operation,
|
|
48
|
+
request,
|
|
49
|
+
config,
|
|
50
|
+
createEffectRequestContext
|
|
51
|
+
}));
|
|
218
52
|
client[endpoint.group] ??= {};
|
|
219
53
|
client[endpoint.group][endpoint.endpoint] = call;
|
|
220
54
|
operationManifest[endpoint.group] ??= {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import "node:module";
|
|
@@ -7,6 +7,7 @@ const SAFE_FAILURE_CODES = {
|
|
|
7
7
|
500: 'INTERNAL_SERVER_ERROR',
|
|
8
8
|
503: 'SERVICE_UNAVAILABLE'
|
|
9
9
|
};
|
|
10
|
+
const INVALID_HTTP_HEADER_VALUE = /[\0-\x08\x0a-\x1f\x7f]/u;
|
|
10
11
|
const readErrorProperty = (error, key)=>{
|
|
11
12
|
if ('object' != typeof error || null === error || !(key in error)) return;
|
|
12
13
|
return error[key];
|
|
@@ -19,7 +20,7 @@ const normalizeRetryAfter = (value)=>{
|
|
|
19
20
|
if ('number' == typeof value && Number.isFinite(value) && value >= 0) return String(Math.ceil(value));
|
|
20
21
|
if ('string' == typeof value) {
|
|
21
22
|
const trimmed = value.trim();
|
|
22
|
-
return trimmed.length > 0 ? trimmed : void 0;
|
|
23
|
+
return trimmed.length > 0 && !INVALID_HTTP_HEADER_VALUE.test(trimmed) ? trimmed : void 0;
|
|
23
24
|
}
|
|
24
25
|
if (value instanceof Date) return value.toUTCString();
|
|
25
26
|
};
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import "node:module";
|
|
2
|
+
import { fs } from "@modern-js/utils";
|
|
3
|
+
import path from "path";
|
|
4
|
+
const API_DIR = 'api';
|
|
5
|
+
const PLUGIN_DIR = 'plugin';
|
|
6
|
+
const RUNTIME_DIR = 'runtime';
|
|
7
|
+
const CLIENT_DIR = 'client';
|
|
8
|
+
const EXPORT_PREFIX = `./${API_DIR}/`;
|
|
9
|
+
const TYPE_PREFIX = `${API_DIR}/`;
|
|
10
|
+
const GENERATED_RUNTIME_DIRS = [
|
|
11
|
+
CLIENT_DIR,
|
|
12
|
+
PLUGIN_DIR,
|
|
13
|
+
RUNTIME_DIR
|
|
14
|
+
];
|
|
15
|
+
const toPosixPath = (p)=>p.replace(/\\/g, '/');
|
|
16
|
+
const posixJoin = (...args)=>toPosixPath(path.join(...args));
|
|
17
|
+
function createFileDetails(options) {
|
|
18
|
+
const { appDirectory, baseDirectory, resourcePath, source, relativeDistPath } = options;
|
|
19
|
+
const relativePath = path.relative(baseDirectory, resourcePath);
|
|
20
|
+
const parsedPath = path.parse(relativePath);
|
|
21
|
+
const targetDir = posixJoin(`./${relativeDistPath}/${CLIENT_DIR}`, parsedPath.dir, `${parsedPath.name}.js`);
|
|
22
|
+
const absTargetDir = path.resolve(targetDir);
|
|
23
|
+
const relativePathFromAppDirectory = path.relative(appDirectory, path.dirname(resourcePath));
|
|
24
|
+
const typesFilePath = posixJoin(`./${relativeDistPath}`, relativePathFromAppDirectory, `${parsedPath.name}.d.ts`);
|
|
25
|
+
return {
|
|
26
|
+
resourcePath,
|
|
27
|
+
source,
|
|
28
|
+
targetDir,
|
|
29
|
+
name: parsedPath.name,
|
|
30
|
+
absTargetDir,
|
|
31
|
+
relativeTargetDistDir: `./${typesFilePath}`,
|
|
32
|
+
exportKey: toPosixPath(path.join(parsedPath.dir, parsedPath.name))
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
async function readDirectoryFiles(appDirectory, directory, relativeDistPath) {
|
|
36
|
+
const filesList = [];
|
|
37
|
+
async function readFiles(currentPath) {
|
|
38
|
+
const entries = await fs.readdir(currentPath, {
|
|
39
|
+
withFileTypes: true
|
|
40
|
+
});
|
|
41
|
+
for (const entry of entries){
|
|
42
|
+
if ('_app.ts' === entry.name) continue;
|
|
43
|
+
const resourcePath = path.join(currentPath, entry.name);
|
|
44
|
+
if (entry.isDirectory()) await readFiles(resourcePath);
|
|
45
|
+
else {
|
|
46
|
+
const source = await fs.readFile(resourcePath, 'utf8');
|
|
47
|
+
filesList.push(createFileDetails({
|
|
48
|
+
appDirectory,
|
|
49
|
+
baseDirectory: directory,
|
|
50
|
+
resourcePath,
|
|
51
|
+
source,
|
|
52
|
+
relativeDistPath
|
|
53
|
+
}));
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
await readFiles(directory);
|
|
58
|
+
return filesList;
|
|
59
|
+
}
|
|
60
|
+
async function writeTargetFile(absTargetDir, content) {
|
|
61
|
+
await fs.mkdir(path.dirname(absTargetDir), {
|
|
62
|
+
recursive: true
|
|
63
|
+
});
|
|
64
|
+
await fs.writeFile(absTargetDir, content);
|
|
65
|
+
}
|
|
66
|
+
async function copyFiles(from, to) {
|
|
67
|
+
if (await fs.pathExists(from)) await fs.copy(toPosixPath(from), toPosixPath(to));
|
|
68
|
+
}
|
|
69
|
+
export { API_DIR, CLIENT_DIR, EXPORT_PREFIX, GENERATED_RUNTIME_DIRS, PLUGIN_DIR, RUNTIME_DIR, TYPE_PREFIX, copyFiles, createFileDetails, posixJoin, readDirectoryFiles, toPosixPath, writeTargetFile };
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import "node:module";
|
|
2
|
+
import { generateClient } from "@modern-js/bff-core";
|
|
3
|
+
import { fs, logger } from "@modern-js/utils";
|
|
4
|
+
import path from "path";
|
|
5
|
+
import { generateEffectClient, resolveEffectEntryFile } from "../effectClientGenerator.mjs";
|
|
6
|
+
import { CLIENT_DIR, copyFiles, createFileDetails, readDirectoryFiles, writeTargetFile } from "./files.mjs";
|
|
7
|
+
import { getPackageName } from "./package-json.mjs";
|
|
8
|
+
import { setPackage, writeClientModuleBoundary } from "./write-package.mjs";
|
|
9
|
+
async function clientGenerator(draftOptions) {
|
|
10
|
+
const generatedClientDir = path.resolve(draftOptions.appDir, draftOptions.relativeDistPath, CLIENT_DIR);
|
|
11
|
+
await fs.remove(generatedClientDir);
|
|
12
|
+
const requestId = getPackageName(draftOptions.appDir) || process.env.npm_package_name;
|
|
13
|
+
const lambdaSourceList = draftOptions.existLambda ? await readDirectoryFiles(draftOptions.appDir, draftOptions.lambdaDir, draftOptions.relativeDistPath) : [];
|
|
14
|
+
const generatedSourceList = [
|
|
15
|
+
...lambdaSourceList
|
|
16
|
+
];
|
|
17
|
+
const getClitentCode = async (resourcePath, source)=>{
|
|
18
|
+
const warning = `The file ${resourcePath} is not allowed to be imported in src directory, only API definition files are allowed.`;
|
|
19
|
+
if (!draftOptions.existLambda) return void logger.warn(warning);
|
|
20
|
+
const options = {
|
|
21
|
+
prefix: Array.isArray(draftOptions.prefix) ? draftOptions.prefix[0] : draftOptions.prefix,
|
|
22
|
+
appDir: draftOptions.appDir,
|
|
23
|
+
apiDir: draftOptions.apiDir,
|
|
24
|
+
lambdaDir: draftOptions.lambdaDir,
|
|
25
|
+
port: Number(draftOptions.port),
|
|
26
|
+
source,
|
|
27
|
+
resourcePath,
|
|
28
|
+
target: 'bundle',
|
|
29
|
+
httpMethodDecider: draftOptions.httpMethodDecider,
|
|
30
|
+
requestCreator: draftOptions.requestCreator,
|
|
31
|
+
requestId
|
|
32
|
+
};
|
|
33
|
+
const { lambdaDir } = draftOptions;
|
|
34
|
+
if (!resourcePath.startsWith(lambdaDir)) return void logger.warn(warning);
|
|
35
|
+
const result = await generateClient(options);
|
|
36
|
+
return result;
|
|
37
|
+
};
|
|
38
|
+
try {
|
|
39
|
+
for (const source of lambdaSourceList){
|
|
40
|
+
const code = await getClitentCode(source.resourcePath, source.source);
|
|
41
|
+
if (code?.value) {
|
|
42
|
+
await writeTargetFile(source.absTargetDir, code.value);
|
|
43
|
+
await copyFiles(source.relativeTargetDistDir, source.targetDir.replace("js", 'd.ts'));
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
if ('effect' === draftOptions.bffRuntimeFramework) {
|
|
47
|
+
const effectEntryFile = resolveEffectEntryFile({
|
|
48
|
+
appDir: draftOptions.appDir,
|
|
49
|
+
apiDir: draftOptions.apiDir,
|
|
50
|
+
effectEntry: draftOptions.effectEntry
|
|
51
|
+
});
|
|
52
|
+
if (effectEntryFile) {
|
|
53
|
+
const effectSource = await fs.readFile(effectEntryFile, 'utf8');
|
|
54
|
+
const effectFileDetails = createFileDetails({
|
|
55
|
+
appDirectory: draftOptions.appDir,
|
|
56
|
+
baseDirectory: draftOptions.apiDir,
|
|
57
|
+
resourcePath: effectEntryFile,
|
|
58
|
+
source: effectSource,
|
|
59
|
+
relativeDistPath: draftOptions.relativeDistPath
|
|
60
|
+
});
|
|
61
|
+
const effectClientArtifacts = await generateEffectClient({
|
|
62
|
+
appDir: draftOptions.appDir,
|
|
63
|
+
apiDir: draftOptions.apiDir,
|
|
64
|
+
resourcePath: effectEntryFile,
|
|
65
|
+
prefix: Array.isArray(draftOptions.prefix) ? draftOptions.prefix[0] : draftOptions.prefix,
|
|
66
|
+
port: Number(draftOptions.port),
|
|
67
|
+
target: 'bundle',
|
|
68
|
+
requestCreator: draftOptions.requestCreator,
|
|
69
|
+
httpMethodDecider: draftOptions.httpMethodDecider,
|
|
70
|
+
dataPlatformBatch: draftOptions.effectDataPlatformBatch
|
|
71
|
+
});
|
|
72
|
+
if (effectClientArtifacts) {
|
|
73
|
+
const targetTypeFile = effectFileDetails.targetDir.replace(/\.js$/, '.d.ts');
|
|
74
|
+
await writeTargetFile(effectFileDetails.absTargetDir, effectClientArtifacts.code);
|
|
75
|
+
await writeTargetFile(path.resolve(targetTypeFile), effectClientArtifacts.declaration);
|
|
76
|
+
generatedSourceList.push(effectFileDetails);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
logger.info("Client bundle generate succeed");
|
|
81
|
+
} catch (error) {
|
|
82
|
+
logger.error(`Client bundle generate failed: ${error}`);
|
|
83
|
+
}
|
|
84
|
+
if (generatedSourceList.length > 0) await writeClientModuleBoundary(draftOptions.appDir, draftOptions.relativeDistPath);
|
|
85
|
+
await setPackage(generatedSourceList, draftOptions.appDir, draftOptions.relativeDistPath);
|
|
86
|
+
}
|
|
87
|
+
const generate = clientGenerator;
|
|
88
|
+
export default generate;
|
|
89
|
+
export { clientGenerator };
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import "node:module";
|
|
2
|
+
export { copyFiles, createFileDetails, readDirectoryFiles, writeTargetFile } from "./files.mjs";
|
|
3
|
+
export { clientGenerator, default } from "./generate.mjs";
|
|
4
|
+
export { getClientPackageName, getPackageName, mergePackageJson } from "./package-json.mjs";
|
|
5
|
+
export { setPackage, writeClientModuleBoundary } from "./write-package.mjs";
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import "node:module";
|
|
2
|
+
import { fs } from "@modern-js/utils";
|
|
3
|
+
import path from "path";
|
|
4
|
+
import { EXPORT_PREFIX, GENERATED_RUNTIME_DIRS, TYPE_PREFIX, toPosixPath } from "./files.mjs";
|
|
5
|
+
function getPackageName(appDirectory) {
|
|
6
|
+
try {
|
|
7
|
+
const packageJsonPath = path.resolve(appDirectory, './package.json');
|
|
8
|
+
const packageJson = fs.readJSONSync(packageJsonPath);
|
|
9
|
+
return packageJson.name;
|
|
10
|
+
} catch {
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
function mergePackageJson(packageJson, files, typesVersion, exports, relativeDistPath) {
|
|
15
|
+
const distPrefix = toPosixPath(`./${relativeDistPath}/`);
|
|
16
|
+
const generatedPrefixes = GENERATED_RUNTIME_DIRS.map((dir)=>toPosixPath(`${distPrefix}${dir}/`));
|
|
17
|
+
const isManagedExportEntry = (value)=>{
|
|
18
|
+
if (!value) return false;
|
|
19
|
+
const values = [
|
|
20
|
+
value.import,
|
|
21
|
+
value.require,
|
|
22
|
+
value.types
|
|
23
|
+
].filter(Boolean);
|
|
24
|
+
return values.every((entry)=>generatedPrefixes.some((prefix)=>entry.startsWith(prefix)));
|
|
25
|
+
};
|
|
26
|
+
const isManagedTypeEntry = (value)=>Array.isArray(value) && value.length > 0 && value.every((entry)=>generatedPrefixes.some((prefix)=>entry.startsWith(prefix)));
|
|
27
|
+
const normalizedFiles = [
|
|
28
|
+
...new Set(files.map((file)=>toPosixPath(file)))
|
|
29
|
+
];
|
|
30
|
+
const currentFiles = packageJson.files || [];
|
|
31
|
+
packageJson.files = [
|
|
32
|
+
...new Set([
|
|
33
|
+
...currentFiles.map((file)=>toPosixPath(file)),
|
|
34
|
+
...normalizedFiles
|
|
35
|
+
])
|
|
36
|
+
];
|
|
37
|
+
packageJson.typesVersions ??= {};
|
|
38
|
+
const typesVersions = packageJson.typesVersions;
|
|
39
|
+
const starTypes = typesVersions['*'] || {};
|
|
40
|
+
const generatedTypeEntries = typesVersion['*'] || {};
|
|
41
|
+
const generatedTypeKeys = new Set(Object.keys(generatedTypeEntries));
|
|
42
|
+
const typeConflicts = Object.entries(starTypes).filter(([key, value])=>{
|
|
43
|
+
if (!generatedTypeKeys.has(key) && !key.startsWith(TYPE_PREFIX)) return false;
|
|
44
|
+
const generatedValue = generatedTypeEntries[key];
|
|
45
|
+
if (generatedValue) return JSON.stringify(value) !== JSON.stringify(generatedValue) && !isManagedTypeEntry(value);
|
|
46
|
+
return !isManagedTypeEntry(value);
|
|
47
|
+
}).map(([key])=>key);
|
|
48
|
+
if (typeConflicts.length > 0) throw new Error(`[plugin-bff] package.json typesVersions conflict on keys: ${typeConflicts.sort().join(', ')}. Rename these keys or move them outside "${TYPE_PREFIX}" namespace.`);
|
|
49
|
+
Object.keys(starTypes).forEach((key)=>{
|
|
50
|
+
if (generatedTypeKeys.has(key) || key.startsWith(TYPE_PREFIX)) delete starTypes[key];
|
|
51
|
+
});
|
|
52
|
+
typesVersions['*'] = {
|
|
53
|
+
...starTypes,
|
|
54
|
+
...generatedTypeEntries
|
|
55
|
+
};
|
|
56
|
+
packageJson.exports ??= {};
|
|
57
|
+
const packageExports = packageJson.exports;
|
|
58
|
+
const generatedExportKeys = new Set(Object.keys(exports));
|
|
59
|
+
const exportConflicts = Object.entries(packageExports).filter(([key, value])=>{
|
|
60
|
+
if (!generatedExportKeys.has(key) && !key.startsWith(EXPORT_PREFIX)) return false;
|
|
61
|
+
const generatedValue = exports[key];
|
|
62
|
+
if (generatedValue) return JSON.stringify(value) !== JSON.stringify(generatedValue) && !isManagedExportEntry(value);
|
|
63
|
+
return !isManagedExportEntry(value);
|
|
64
|
+
}).map(([key])=>key);
|
|
65
|
+
if (exportConflicts.length > 0) throw new Error(`[plugin-bff] package.json exports conflict on keys: ${exportConflicts.sort().join(', ')}. Rename these exports or move them outside "${EXPORT_PREFIX}" namespace.`);
|
|
66
|
+
Object.keys(packageExports).forEach((key)=>{
|
|
67
|
+
if (generatedExportKeys.has(key) || key.startsWith(EXPORT_PREFIX)) delete packageExports[key];
|
|
68
|
+
});
|
|
69
|
+
Object.assign(packageExports, exports);
|
|
70
|
+
}
|
|
71
|
+
function getClientPackageName(appDirectory) {
|
|
72
|
+
const packageName = getPackageName(appDirectory) || path.basename(appDirectory);
|
|
73
|
+
if (packageName.startsWith('@') && packageName.includes('/')) {
|
|
74
|
+
const [scope, name] = packageName.split('/');
|
|
75
|
+
return `${scope}/${name}-bff-client`;
|
|
76
|
+
}
|
|
77
|
+
return `${packageName}-bff-client`;
|
|
78
|
+
}
|
|
79
|
+
export { getClientPackageName, getPackageName, mergePackageJson };
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import "node:module";
|
|
2
|
+
import { fs } from "@modern-js/utils";
|
|
3
|
+
import path from "path";
|
|
4
|
+
import { API_DIR, CLIENT_DIR, EXPORT_PREFIX, PLUGIN_DIR, RUNTIME_DIR, TYPE_PREFIX, posixJoin, toPosixPath, writeTargetFile } from "./files.mjs";
|
|
5
|
+
import { getClientPackageName, mergePackageJson } from "./package-json.mjs";
|
|
6
|
+
async function writeClientModuleBoundary(appDirectory, relativeDistPath) {
|
|
7
|
+
await writeTargetFile(path.resolve(appDirectory, relativeDistPath, CLIENT_DIR, 'package.json'), `${JSON.stringify({
|
|
8
|
+
private: true,
|
|
9
|
+
name: getClientPackageName(appDirectory),
|
|
10
|
+
type: 'module'
|
|
11
|
+
}, null, 2)}\n`);
|
|
12
|
+
}
|
|
13
|
+
async function setPackage(files, appDirectory, relativeDistPath) {
|
|
14
|
+
const packagePath = path.resolve(appDirectory, './package.json');
|
|
15
|
+
const packageContent = await fs.readFile(packagePath, 'utf8');
|
|
16
|
+
const packageJson = JSON.parse(packageContent);
|
|
17
|
+
const sortedFiles = [
|
|
18
|
+
...files
|
|
19
|
+
].sort((a, b)=>a.exportKey.localeCompare(b.exportKey));
|
|
20
|
+
const addFiles = [
|
|
21
|
+
posixJoin(relativeDistPath, CLIENT_DIR, '**', '*'),
|
|
22
|
+
posixJoin(relativeDistPath, RUNTIME_DIR, '**', '*'),
|
|
23
|
+
posixJoin(relativeDistPath, PLUGIN_DIR, '**', '*')
|
|
24
|
+
];
|
|
25
|
+
const typesVersions = {
|
|
26
|
+
'*': sortedFiles.reduce((acc, file)=>{
|
|
27
|
+
const typeFilePath = toPosixPath(`./${file.targetDir}`).replace(/\.js$/, '.d.ts');
|
|
28
|
+
return {
|
|
29
|
+
...acc,
|
|
30
|
+
[toPosixPath(`${TYPE_PREFIX}${file.exportKey}`)]: [
|
|
31
|
+
typeFilePath
|
|
32
|
+
]
|
|
33
|
+
};
|
|
34
|
+
}, {
|
|
35
|
+
[`${API_DIR}/*`]: [
|
|
36
|
+
toPosixPath(`./${relativeDistPath}/${CLIENT_DIR}/*.d.ts`)
|
|
37
|
+
],
|
|
38
|
+
[RUNTIME_DIR]: [
|
|
39
|
+
toPosixPath(`./${relativeDistPath}/${RUNTIME_DIR}/index.d.ts`)
|
|
40
|
+
],
|
|
41
|
+
[PLUGIN_DIR]: [
|
|
42
|
+
toPosixPath(`./${relativeDistPath}/${PLUGIN_DIR}/index.d.ts`)
|
|
43
|
+
]
|
|
44
|
+
})
|
|
45
|
+
};
|
|
46
|
+
const exports = sortedFiles.reduce((acc, file)=>{
|
|
47
|
+
const exportKey = `${EXPORT_PREFIX}${file.exportKey}`;
|
|
48
|
+
const jsFilePath = toPosixPath(`./${file.targetDir}`);
|
|
49
|
+
return {
|
|
50
|
+
...acc,
|
|
51
|
+
[toPosixPath(exportKey)]: {
|
|
52
|
+
import: jsFilePath,
|
|
53
|
+
types: toPosixPath(jsFilePath.replace(/\.js$/, '.d.ts'))
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
}, {
|
|
57
|
+
[toPosixPath(`./${API_DIR}/*`)]: {
|
|
58
|
+
import: toPosixPath(`./${relativeDistPath}/${CLIENT_DIR}/*.js`),
|
|
59
|
+
types: toPosixPath(`./${relativeDistPath}/${CLIENT_DIR}/*.d.ts`)
|
|
60
|
+
},
|
|
61
|
+
[toPosixPath(`./${PLUGIN_DIR}`)]: {
|
|
62
|
+
import: toPosixPath(`./${relativeDistPath}/${PLUGIN_DIR}/index.js`),
|
|
63
|
+
require: toPosixPath(`./${relativeDistPath}/${PLUGIN_DIR}/index.js`),
|
|
64
|
+
types: toPosixPath(`./${relativeDistPath}/${PLUGIN_DIR}/index.d.ts`)
|
|
65
|
+
},
|
|
66
|
+
[toPosixPath(`./${RUNTIME_DIR}`)]: {
|
|
67
|
+
import: toPosixPath(`./${relativeDistPath}/${RUNTIME_DIR}/index.js`),
|
|
68
|
+
require: toPosixPath(`./${relativeDistPath}/${RUNTIME_DIR}/index.js`),
|
|
69
|
+
types: toPosixPath(`./${relativeDistPath}/${RUNTIME_DIR}/index.d.ts`)
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
mergePackageJson(packageJson, addFiles, typesVersions, exports, relativeDistPath);
|
|
73
|
+
await fs.promises.writeFile(packagePath, JSON.stringify(packageJson, null, 2));
|
|
74
|
+
}
|
|
75
|
+
export { setPackage, writeClientModuleBoundary };
|