@bleedingdev/modern-js-plugin-bff 3.5.0-ultramodern.4 → 3.5.0-ultramodern.40
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 +284 -0
- package/dist/cjs/runtime/data-platform/batch/request.js +98 -0
- package/dist/cjs/runtime/data-platform/batch/response.js +64 -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 +20 -154
- 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 +62 -0
- package/dist/cjs/runtime/effect/backend-federation.js +61 -0
- package/dist/cjs/runtime/effect/dispatch.js +101 -0
- package/dist/cjs/runtime/effect/edge.js +58 -69
- package/dist/cjs/runtime/effect/endpoint-contracts.js +7 -21
- package/dist/cjs/runtime/effect/entry-shape.js +84 -0
- 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 +37 -529
- package/dist/cjs/runtime/effect/index.js +91 -15
- package/dist/cjs/runtime/effect/module.js +23 -80
- 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 +21 -145
- 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 -0
- package/dist/esm/runtime/effect/backend-federation.mjs +4 -0
- package/dist/esm/runtime/effect/dispatch.mjs +63 -0
- package/dist/esm/runtime/effect/edge.mjs +17 -63
- package/dist/esm/runtime/effect/endpoint-contracts.mjs +8 -13
- package/dist/esm/runtime/effect/entry-shape.mjs +36 -0
- 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 +11 -506
- package/dist/esm/runtime/effect/index.mjs +5 -2
- package/dist/esm/runtime/effect/module.mjs +25 -82
- 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 +27 -37
- 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 +21 -145
- 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 +2 -0
- package/dist/esm-node/runtime/effect/backend-federation.mjs +5 -0
- package/dist/esm-node/runtime/effect/dispatch.mjs +64 -0
- package/dist/esm-node/runtime/effect/edge.mjs +17 -63
- package/dist/esm-node/runtime/effect/endpoint-contracts.mjs +8 -13
- package/dist/esm-node/runtime/effect/entry-shape.mjs +37 -0
- 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 +11 -506
- package/dist/esm-node/runtime/effect/index.mjs +5 -2
- package/dist/esm-node/runtime/effect/module.mjs +25 -82
- 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 +27 -37
- 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 +8 -0
- package/dist/types/runtime/data-platform/batch/request.d.ts +13 -0
- package/dist/types/runtime/data-platform/batch/response.d.ts +3 -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 +7 -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 -0
- package/dist/types/runtime/effect/backend-federation.d.ts +6 -0
- package/dist/types/runtime/effect/dispatch.d.ts +13 -0
- package/dist/types/runtime/effect/edge.d.ts +8 -8
- package/dist/types/runtime/effect/endpoint-contracts.d.ts +5 -7
- package/dist/types/runtime/effect/entry-shape.d.ts +31 -0
- 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 +4 -190
- package/dist/types/runtime/effect/index.d.ts +3 -0
- package/dist/types/runtime/effect/module.d.ts +3 -2
- 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/index.d.ts +1 -1
- 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 +34 -28
package/dist/esm-node/cli.mjs
CHANGED
|
@@ -1,34 +1,14 @@
|
|
|
1
1
|
import "node:module";
|
|
2
2
|
import { ApiRouter } from "@modern-js/bff-core";
|
|
3
|
-
import {
|
|
4
|
-
import { API_DIR, DEFAULT_API_PREFIX, SHARED_DIR, fs, normalizeOutputPath, resolveServerTsconfig } from "@modern-js/utils";
|
|
3
|
+
import { normalizeOutputPath } from "@modern-js/utils";
|
|
5
4
|
import path from "path";
|
|
6
|
-
import
|
|
7
|
-
import
|
|
8
|
-
import
|
|
5
|
+
import { createCompressConfig } from "./cli/compress.mjs";
|
|
6
|
+
import { createBffGenerator } from "./cli/generator.mjs";
|
|
7
|
+
import { getPrimaryPrefix } from "./cli/prefix.mjs";
|
|
8
|
+
import { isWatchableBffFile } from "./cli/watch.mjs";
|
|
9
9
|
import { fileURLToPath as __rspack_fileURLToPath } from "node:url";
|
|
10
10
|
import { dirname as __rspack_dirname } from "node:path";
|
|
11
11
|
var __rspack_import_meta_dirname__ = __rspack_dirname(__rspack_fileURLToPath(import.meta.url));
|
|
12
|
-
const RUNTIME_CREATE_REQUEST = '@modern-js/plugin-bff/client';
|
|
13
|
-
const WATCHABLE_EXTENSIONS = [
|
|
14
|
-
'.ts',
|
|
15
|
-
'.tsx',
|
|
16
|
-
'.js',
|
|
17
|
-
'.jsx',
|
|
18
|
-
'.mts',
|
|
19
|
-
'.cts',
|
|
20
|
-
'.mjs',
|
|
21
|
-
'.cjs',
|
|
22
|
-
'.json'
|
|
23
|
-
];
|
|
24
|
-
const isWatchableBffFile = (filename)=>WATCHABLE_EXTENSIONS.some((ext)=>filename.endsWith(ext));
|
|
25
|
-
const normalizePrefixList = (prefix)=>{
|
|
26
|
-
if (Array.isArray(prefix)) return prefix.filter(Boolean);
|
|
27
|
-
return [
|
|
28
|
-
prefix || DEFAULT_API_PREFIX
|
|
29
|
-
];
|
|
30
|
-
};
|
|
31
|
-
const getPrimaryPrefix = (prefix)=>normalizePrefixList(prefix)[0] || DEFAULT_API_PREFIX;
|
|
32
12
|
const bffPlugin = ()=>({
|
|
33
13
|
name: '@modern-js/plugin-bff',
|
|
34
14
|
setup: (api)=>{
|
|
@@ -40,106 +20,14 @@ const bffPlugin = ()=>({
|
|
|
40
20
|
bffRuntimeFramework: 'hono' === userRuntimeFramework ? 'hono' : 'effect'
|
|
41
21
|
});
|
|
42
22
|
}
|
|
43
|
-
const compileApi =
|
|
44
|
-
const { appDirectory, distDirectory, apiDirectory, sharedDirectory, moduleType } = api.getAppContext();
|
|
45
|
-
const modernConfig = api.getNormalizedConfig();
|
|
46
|
-
const distDir = path.resolve(distDirectory);
|
|
47
|
-
const apiDir = apiDirectory || path.resolve(appDirectory, API_DIR);
|
|
48
|
-
const sharedDir = sharedDirectory || path.resolve(appDirectory, SHARED_DIR);
|
|
49
|
-
const tsconfigPath = resolveServerTsconfig(appDirectory, modernConfig?.server?.tsconfigPath);
|
|
50
|
-
const sourceDirs = [];
|
|
51
|
-
if (await fs.pathExists(apiDir)) sourceDirs.push(apiDir);
|
|
52
|
-
if (await fs.pathExists(sharedDir)) sourceDirs.push(sharedDir);
|
|
53
|
-
const { alias } = modernConfig.source;
|
|
54
|
-
const { alias: resolveAlias } = modernConfig.resolve;
|
|
55
|
-
if (sourceDirs.length > 0) {
|
|
56
|
-
const combinedAlias = [].concat(alias ?? []).concat(resolveAlias ?? []);
|
|
57
|
-
await compile(appDirectory, {
|
|
58
|
-
alias: combinedAlias
|
|
59
|
-
}, {
|
|
60
|
-
sourceDirs,
|
|
61
|
-
distDir,
|
|
62
|
-
tsconfigPath,
|
|
63
|
-
moduleType,
|
|
64
|
-
throwErrorInsteadOfExit: true
|
|
65
|
-
});
|
|
66
|
-
}
|
|
67
|
-
};
|
|
68
|
-
const generator = async ()=>{
|
|
69
|
-
const { appDirectory, apiDirectory, lambdaDirectory, port, bffRuntimeFramework } = api.getAppContext();
|
|
70
|
-
const modernConfig = api.getNormalizedConfig();
|
|
71
|
-
const relativeDistPath = modernConfig?.output?.distPath?.root || 'dist';
|
|
72
|
-
const { bff } = modernConfig || {};
|
|
73
|
-
const prefix = getPrimaryPrefix(bff?.prefix);
|
|
74
|
-
const httpMethodDecider = bff?.httpMethodDecider;
|
|
75
|
-
const apiRouter = new ApiRouter({
|
|
76
|
-
apiDir: apiDirectory,
|
|
77
|
-
appDir: appDirectory,
|
|
78
|
-
lambdaDir: lambdaDirectory,
|
|
79
|
-
prefix,
|
|
80
|
-
httpMethodDecider,
|
|
81
|
-
isBuild: true
|
|
82
|
-
});
|
|
83
|
-
const lambdaDir = apiRouter.getLambdaDir();
|
|
84
|
-
const existLambda = apiRouter.isExistLambda();
|
|
85
|
-
const runtime = bff?.runtimeCreateRequest || RUNTIME_CREATE_REQUEST;
|
|
86
|
-
const relativeApiPath = path.relative(appDirectory, apiDirectory);
|
|
87
|
-
const relativeLambdaPath = path.relative(appDirectory, lambdaDir);
|
|
88
|
-
await pluginGenerator({
|
|
89
|
-
prefix,
|
|
90
|
-
appDirectory,
|
|
91
|
-
relativeDistPath,
|
|
92
|
-
relativeApiPath,
|
|
93
|
-
relativeLambdaPath,
|
|
94
|
-
runtimeFramework: 'hono' === bffRuntimeFramework ? 'hono' : 'effect'
|
|
95
|
-
});
|
|
96
|
-
await clientGenerator({
|
|
97
|
-
prefix,
|
|
98
|
-
appDir: appDirectory,
|
|
99
|
-
apiDir: apiDirectory,
|
|
100
|
-
lambdaDir,
|
|
101
|
-
existLambda,
|
|
102
|
-
port,
|
|
103
|
-
requestCreator: bff?.requestCreator,
|
|
104
|
-
httpMethodDecider,
|
|
105
|
-
relativeDistPath,
|
|
106
|
-
relativeApiPath,
|
|
107
|
-
bffRuntimeFramework,
|
|
108
|
-
effectEntry: bff?.effect?.entry,
|
|
109
|
-
effectDataPlatformBatch: bff?.effect?.dataPlatform?.batch
|
|
110
|
-
});
|
|
111
|
-
await runtimeGenerator({
|
|
112
|
-
runtime,
|
|
113
|
-
appDirectory,
|
|
114
|
-
relativeDistPath
|
|
115
|
-
});
|
|
116
|
-
};
|
|
117
|
-
const handleCrossProjectInvocation = async (isBuild = false)=>{
|
|
118
|
-
const { bff } = api.getNormalizedConfig();
|
|
119
|
-
if (bff?.crossProject) {
|
|
120
|
-
if (!isBuild) await compileApi();
|
|
121
|
-
await generator();
|
|
122
|
-
}
|
|
123
|
-
};
|
|
23
|
+
const { compileApi, handleCrossProjectInvocation } = createBffGenerator(api);
|
|
124
24
|
const isHono = ()=>{
|
|
125
25
|
const { bffRuntimeFramework } = api.getAppContext();
|
|
126
26
|
return 'hono' === bffRuntimeFramework;
|
|
127
27
|
};
|
|
128
|
-
const createCompressConfig = (devServer, prefix)=>{
|
|
129
|
-
if (!devServer || 'object' != typeof devServer || Array.isArray(devServer)) return;
|
|
130
|
-
const { compress } = devServer;
|
|
131
|
-
if (void 0 === compress || true === compress) {
|
|
132
|
-
const prefixes = normalizePrefixList(prefix);
|
|
133
|
-
return {
|
|
134
|
-
filter: (req)=>!prefixes.some((item)=>req.url?.includes(item))
|
|
135
|
-
};
|
|
136
|
-
}
|
|
137
|
-
if (false === compress) return false;
|
|
138
|
-
return compress;
|
|
139
|
-
};
|
|
140
28
|
api.config(async ()=>{
|
|
141
29
|
const devServer = api.getConfig()?.tools?.devServer;
|
|
142
|
-
const prefix = api.getConfig()?.bff?.prefix
|
|
30
|
+
const prefix = api.getConfig()?.bff?.prefix;
|
|
143
31
|
const compress = createCompressConfig(devServer, prefix);
|
|
144
32
|
return {
|
|
145
33
|
tools: {
|
|
@@ -244,6 +132,4 @@ const bffPlugin = ()=>({
|
|
|
244
132
|
});
|
|
245
133
|
}
|
|
246
134
|
});
|
|
247
|
-
const cli = bffPlugin;
|
|
248
|
-
export default cli;
|
|
249
135
|
export { bffPlugin };
|
|
@@ -0,0 +1,247 @@
|
|
|
1
|
+
import "node:module";
|
|
2
|
+
import { stableStringify } from "../codec.mjs";
|
|
3
|
+
import { DEFAULT_DATA_BATCH_HEADER } from "../types.mjs";
|
|
4
|
+
import { createBatchId, measureTextBytes, normalizeMethod, shouldBatchRequest, toHeaderRecord, toRequestBody } from "./request.mjs";
|
|
5
|
+
import { isBatchResponsePayload, parseResponseLikeCreateRequest } from "./response.mjs";
|
|
6
|
+
import { emitDataBatchTransportEvent } from "./telemetry.mjs";
|
|
7
|
+
import { normalizeBatchEndpoint, toAbsoluteUrl } from "./url.mjs";
|
|
8
|
+
function ensureBucket(buckets, endpoint) {
|
|
9
|
+
const existing = buckets.get(endpoint);
|
|
10
|
+
if (existing) return existing;
|
|
11
|
+
const next = {
|
|
12
|
+
items: [],
|
|
13
|
+
bytes: 0,
|
|
14
|
+
timer: null,
|
|
15
|
+
flushing: false
|
|
16
|
+
};
|
|
17
|
+
buckets.set(endpoint, next);
|
|
18
|
+
return next;
|
|
19
|
+
}
|
|
20
|
+
function createBatchTransportQueue({ options, baseFetch }) {
|
|
21
|
+
const flushIntervalMs = Math.max(0, options.flushIntervalMs ?? 8);
|
|
22
|
+
const maxBatchSize = Math.max(1, options.maxBatchSize ?? 16);
|
|
23
|
+
const maxBatchBytes = Math.max(1024, options.maxBatchBytes ?? 65536);
|
|
24
|
+
const requestTimeoutMs = options.requestTimeoutMs;
|
|
25
|
+
const allowedMethods = new Set((options.allowedMethods && options.allowedMethods.length > 0 ? options.allowedMethods : [
|
|
26
|
+
'GET'
|
|
27
|
+
]).map((method)=>method.toUpperCase()));
|
|
28
|
+
const onEvent = options.onEvent;
|
|
29
|
+
const buckets = new Map();
|
|
30
|
+
const pendingByKey = new Map();
|
|
31
|
+
const disabledEndpoints = new Set();
|
|
32
|
+
let nextItemId = 0;
|
|
33
|
+
const runSingle = async (request)=>{
|
|
34
|
+
const response = await baseFetch(request.requestUrl, request.requestInit);
|
|
35
|
+
return parseResponseLikeCreateRequest(response);
|
|
36
|
+
};
|
|
37
|
+
const settleRequests = async (items, runner)=>{
|
|
38
|
+
await Promise.all(items.map(async (item)=>{
|
|
39
|
+
try {
|
|
40
|
+
const value = await runner(item);
|
|
41
|
+
item.resolve(value);
|
|
42
|
+
} catch (error) {
|
|
43
|
+
item.reject(error);
|
|
44
|
+
} finally{
|
|
45
|
+
pendingByKey.delete(item.key);
|
|
46
|
+
}
|
|
47
|
+
}));
|
|
48
|
+
};
|
|
49
|
+
const flushBucket = async (endpoint)=>{
|
|
50
|
+
const bucket = buckets.get(endpoint);
|
|
51
|
+
if (!bucket || bucket.flushing) return;
|
|
52
|
+
if (bucket.timer) {
|
|
53
|
+
clearTimeout(bucket.timer);
|
|
54
|
+
bucket.timer = null;
|
|
55
|
+
}
|
|
56
|
+
if (0 === bucket.items.length) return;
|
|
57
|
+
bucket.flushing = true;
|
|
58
|
+
const items = bucket.items;
|
|
59
|
+
bucket.items = [];
|
|
60
|
+
bucket.bytes = 0;
|
|
61
|
+
if (1 === items.length || disabledEndpoints.has(endpoint)) {
|
|
62
|
+
emitDataBatchTransportEvent(onEvent, {
|
|
63
|
+
type: disabledEndpoints.has(endpoint) ? 'fallback' : 'flush',
|
|
64
|
+
endpoint,
|
|
65
|
+
size: items.length,
|
|
66
|
+
reason: disabledEndpoints.has(endpoint) ? 'batch-disabled' : void 0
|
|
67
|
+
});
|
|
68
|
+
await settleRequests(items, runSingle);
|
|
69
|
+
bucket.flushing = false;
|
|
70
|
+
if (bucket.items.length > 0 && !bucket.timer) flushBucket(endpoint);
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
const batchId = createBatchId();
|
|
74
|
+
const payload = {
|
|
75
|
+
protocolVersion: 1,
|
|
76
|
+
batchId,
|
|
77
|
+
sentAt: Date.now(),
|
|
78
|
+
items: items.map((item)=>item.item)
|
|
79
|
+
};
|
|
80
|
+
emitDataBatchTransportEvent(onEvent, {
|
|
81
|
+
type: 'flush',
|
|
82
|
+
endpoint,
|
|
83
|
+
batchId,
|
|
84
|
+
size: items.length
|
|
85
|
+
});
|
|
86
|
+
const payloadJson = JSON.stringify(payload);
|
|
87
|
+
const traceparent = items.find((item)=>'string' == typeof item.item.headers?.traceparent)?.item.headers?.traceparent || void 0;
|
|
88
|
+
const requestInit = {
|
|
89
|
+
method: 'POST',
|
|
90
|
+
headers: {
|
|
91
|
+
accept: 'application/json, */*;q=0.8',
|
|
92
|
+
'content-type': 'application/json; charset=utf-8',
|
|
93
|
+
[DEFAULT_DATA_BATCH_HEADER]: '1',
|
|
94
|
+
...traceparent ? {
|
|
95
|
+
traceparent
|
|
96
|
+
} : {}
|
|
97
|
+
},
|
|
98
|
+
body: payloadJson
|
|
99
|
+
};
|
|
100
|
+
let timeoutHandle = null;
|
|
101
|
+
try {
|
|
102
|
+
const controller = requestTimeoutMs && requestTimeoutMs > 0 ? new AbortController() : void 0;
|
|
103
|
+
if (controller) {
|
|
104
|
+
requestInit.signal = controller.signal;
|
|
105
|
+
timeoutHandle = setTimeout(()=>{
|
|
106
|
+
controller.abort();
|
|
107
|
+
emitDataBatchTransportEvent(onEvent, {
|
|
108
|
+
type: 'fallback',
|
|
109
|
+
endpoint,
|
|
110
|
+
batchId,
|
|
111
|
+
size: items.length,
|
|
112
|
+
reason: 'batch-timeout'
|
|
113
|
+
});
|
|
114
|
+
}, requestTimeoutMs);
|
|
115
|
+
}
|
|
116
|
+
const response = await baseFetch(endpoint, requestInit);
|
|
117
|
+
if (!response.ok) {
|
|
118
|
+
if (404 === response.status || 405 === response.status) {
|
|
119
|
+
disabledEndpoints.add(endpoint);
|
|
120
|
+
emitDataBatchTransportEvent(onEvent, {
|
|
121
|
+
type: 'disable',
|
|
122
|
+
endpoint,
|
|
123
|
+
batchId,
|
|
124
|
+
reason: `batch-endpoint-unavailable-${String(response.status)}`
|
|
125
|
+
});
|
|
126
|
+
} else emitDataBatchTransportEvent(onEvent, {
|
|
127
|
+
type: 'fallback',
|
|
128
|
+
endpoint,
|
|
129
|
+
batchId,
|
|
130
|
+
size: items.length,
|
|
131
|
+
reason: `batch-response-${String(response.status)}`
|
|
132
|
+
});
|
|
133
|
+
await settleRequests(items, runSingle);
|
|
134
|
+
bucket.flushing = false;
|
|
135
|
+
return;
|
|
136
|
+
}
|
|
137
|
+
const result = await response.json();
|
|
138
|
+
if (!isBatchResponsePayload(result)) {
|
|
139
|
+
emitDataBatchTransportEvent(onEvent, {
|
|
140
|
+
type: 'fallback',
|
|
141
|
+
endpoint,
|
|
142
|
+
batchId,
|
|
143
|
+
size: items.length,
|
|
144
|
+
reason: 'invalid-batch-response'
|
|
145
|
+
});
|
|
146
|
+
await settleRequests(items, runSingle);
|
|
147
|
+
bucket.flushing = false;
|
|
148
|
+
return;
|
|
149
|
+
}
|
|
150
|
+
const itemMap = new Map();
|
|
151
|
+
for (const item of result.items)itemMap.set(item.id, item);
|
|
152
|
+
await settleRequests(items, async (request)=>{
|
|
153
|
+
const resultItem = itemMap.get(request.item.id);
|
|
154
|
+
if (!resultItem) return runSingle(request);
|
|
155
|
+
const reconstructedResponse = new Response(resultItem.body ?? '', {
|
|
156
|
+
status: resultItem.status,
|
|
157
|
+
headers: resultItem.headers
|
|
158
|
+
});
|
|
159
|
+
return parseResponseLikeCreateRequest(reconstructedResponse);
|
|
160
|
+
});
|
|
161
|
+
} catch (error) {
|
|
162
|
+
emitDataBatchTransportEvent(onEvent, {
|
|
163
|
+
type: 'fallback',
|
|
164
|
+
endpoint,
|
|
165
|
+
batchId,
|
|
166
|
+
size: items.length,
|
|
167
|
+
reason: 'batch-transport-error'
|
|
168
|
+
});
|
|
169
|
+
await settleRequests(items, runSingle);
|
|
170
|
+
} finally{
|
|
171
|
+
if (timeoutHandle) clearTimeout(timeoutHandle);
|
|
172
|
+
bucket.flushing = false;
|
|
173
|
+
if (bucket.items.length > 0 && !bucket.timer) flushBucket(endpoint);
|
|
174
|
+
}
|
|
175
|
+
};
|
|
176
|
+
return (input, init)=>{
|
|
177
|
+
const requestUrl = toAbsoluteUrl(input);
|
|
178
|
+
const batchEndpointUrl = normalizeBatchEndpoint(requestUrl, options.endpoint);
|
|
179
|
+
const endpoint = batchEndpointUrl.toString();
|
|
180
|
+
const method = normalizeMethod(init?.method);
|
|
181
|
+
const body = toRequestBody(init?.body ?? null);
|
|
182
|
+
const headers = toHeaderRecord(init?.headers);
|
|
183
|
+
const normalizedInit = {
|
|
184
|
+
...init,
|
|
185
|
+
method,
|
|
186
|
+
headers,
|
|
187
|
+
body
|
|
188
|
+
};
|
|
189
|
+
if (disabledEndpoints.has(endpoint) || !shouldBatchRequest({
|
|
190
|
+
method,
|
|
191
|
+
body,
|
|
192
|
+
headers,
|
|
193
|
+
allowedMethods,
|
|
194
|
+
batchEndpoint: endpoint,
|
|
195
|
+
requestUrl
|
|
196
|
+
})) return baseFetch(requestUrl.toString(), normalizedInit).then(parseResponseLikeCreateRequest);
|
|
197
|
+
const itemId = `${Date.now().toString(36)}_${nextItemId.toString(36)}_${Math.random().toString(16).slice(2, 8)}`;
|
|
198
|
+
nextItemId += 1;
|
|
199
|
+
const item = {
|
|
200
|
+
id: itemId,
|
|
201
|
+
path: `${requestUrl.pathname}${requestUrl.search}`,
|
|
202
|
+
method,
|
|
203
|
+
headers,
|
|
204
|
+
...body ? {
|
|
205
|
+
body
|
|
206
|
+
} : {}
|
|
207
|
+
};
|
|
208
|
+
const key = stableStringify({
|
|
209
|
+
endpoint,
|
|
210
|
+
path: item.path,
|
|
211
|
+
method: item.method,
|
|
212
|
+
headers: item.headers,
|
|
213
|
+
body: item.body ?? null
|
|
214
|
+
});
|
|
215
|
+
const existing = pendingByKey.get(key);
|
|
216
|
+
if (existing) return existing;
|
|
217
|
+
const size = measureTextBytes(stableStringify(item));
|
|
218
|
+
const promise = new Promise((resolve, reject)=>{
|
|
219
|
+
const bucket = ensureBucket(buckets, endpoint);
|
|
220
|
+
const queued = {
|
|
221
|
+
key,
|
|
222
|
+
endpoint,
|
|
223
|
+
requestUrl: requestUrl.toString(),
|
|
224
|
+
requestInit: normalizedInit,
|
|
225
|
+
item,
|
|
226
|
+
size,
|
|
227
|
+
resolve,
|
|
228
|
+
reject
|
|
229
|
+
};
|
|
230
|
+
bucket.items.push(queued);
|
|
231
|
+
bucket.bytes += size;
|
|
232
|
+
emitDataBatchTransportEvent(onEvent, {
|
|
233
|
+
type: 'enqueue',
|
|
234
|
+
endpoint,
|
|
235
|
+
size: bucket.items.length
|
|
236
|
+
});
|
|
237
|
+
if (bucket.items.length >= maxBatchSize || bucket.bytes >= maxBatchBytes) return void flushBucket(endpoint);
|
|
238
|
+
if (!bucket.timer) bucket.timer = setTimeout(()=>{
|
|
239
|
+
bucket.timer = null;
|
|
240
|
+
flushBucket(endpoint);
|
|
241
|
+
}, flushIntervalMs);
|
|
242
|
+
});
|
|
243
|
+
pendingByKey.set(key, promise);
|
|
244
|
+
return promise;
|
|
245
|
+
};
|
|
246
|
+
}
|
|
247
|
+
export { createBatchTransportQueue };
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import "node:module";
|
|
2
|
+
import { DEFAULT_DATA_BATCH_HEADER } from "../types.mjs";
|
|
3
|
+
function toHeaderRecord(headers) {
|
|
4
|
+
if (!headers) return {};
|
|
5
|
+
if (headers instanceof Headers) {
|
|
6
|
+
const next = {};
|
|
7
|
+
headers.forEach((value, key)=>{
|
|
8
|
+
next[key.toLowerCase()] = value;
|
|
9
|
+
});
|
|
10
|
+
return next;
|
|
11
|
+
}
|
|
12
|
+
if (Array.isArray(headers)) return headers.reduce((acc, [key, value])=>{
|
|
13
|
+
acc[String(key).toLowerCase()] = String(value);
|
|
14
|
+
return acc;
|
|
15
|
+
}, {});
|
|
16
|
+
return Object.entries(headers).reduce((acc, [key, value])=>{
|
|
17
|
+
if (void 0 === value) return acc;
|
|
18
|
+
acc[String(key).toLowerCase()] = Array.isArray(value) ? value.join(', ') : String(value);
|
|
19
|
+
return acc;
|
|
20
|
+
}, {});
|
|
21
|
+
}
|
|
22
|
+
function measureTextBytes(value) {
|
|
23
|
+
if ("u" > typeof TextEncoder) return new TextEncoder().encode(value).length;
|
|
24
|
+
if ("u" > typeof Buffer) return Buffer.byteLength(value);
|
|
25
|
+
return value.length;
|
|
26
|
+
}
|
|
27
|
+
function createBatchId() {
|
|
28
|
+
const now = Date.now().toString(36);
|
|
29
|
+
const random = Math.random().toString(16).slice(2, 10);
|
|
30
|
+
return `batch_${now}_${random}`;
|
|
31
|
+
}
|
|
32
|
+
function normalizeMethod(method) {
|
|
33
|
+
return (method || 'GET').toUpperCase();
|
|
34
|
+
}
|
|
35
|
+
function toRequestBody(initBody) {
|
|
36
|
+
if ('string' == typeof initBody) return initBody;
|
|
37
|
+
if ("u" > typeof URLSearchParams && initBody instanceof URLSearchParams) return initBody.toString();
|
|
38
|
+
}
|
|
39
|
+
function shouldBatchRequest(input) {
|
|
40
|
+
if (input.requestUrl.href === input.batchEndpoint) return false;
|
|
41
|
+
if ('off' === input.headers[DEFAULT_DATA_BATCH_HEADER]) return false;
|
|
42
|
+
if (!input.allowedMethods.has(input.method)) return false;
|
|
43
|
+
if (void 0 !== input.body) return false;
|
|
44
|
+
return true;
|
|
45
|
+
}
|
|
46
|
+
export { createBatchId, measureTextBytes, normalizeMethod, shouldBatchRequest, toHeaderRecord, toRequestBody };
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import "node:module";
|
|
2
|
+
import { isPlainObject } from "../codec.mjs";
|
|
3
|
+
function isBatchResponseItem(value) {
|
|
4
|
+
return isPlainObject(value) && 'string' == typeof value.id && 'number' == typeof value.status;
|
|
5
|
+
}
|
|
6
|
+
function isBatchResponsePayload(value) {
|
|
7
|
+
return isPlainObject(value) && 1 === value.protocolVersion && 'string' == typeof value.batchId && 'number' == typeof value.receivedAt && Array.isArray(value.items) && value.items.every((item)=>isBatchResponseItem(item));
|
|
8
|
+
}
|
|
9
|
+
async function parseResponseLikeCreateRequest(response) {
|
|
10
|
+
const contentType = (response.headers.get('content-type') || '').toLowerCase();
|
|
11
|
+
if (!response.ok) {
|
|
12
|
+
let data = null;
|
|
13
|
+
data = contentType.includes('application/json') ? await response.json() : await response.text();
|
|
14
|
+
response.data = data;
|
|
15
|
+
throw response;
|
|
16
|
+
}
|
|
17
|
+
if (contentType.includes('application/json') || contentType.includes('text/json')) return response.json();
|
|
18
|
+
if (contentType.includes('text/html') || contentType.includes('text/plain')) return response.text();
|
|
19
|
+
if (contentType.includes('application/x-www-form-urlencoded') || contentType.includes('multipart/form-data')) return response.formData();
|
|
20
|
+
if (contentType.includes('application/octet-stream')) return response.arrayBuffer();
|
|
21
|
+
if (contentType.includes('image/png')) return response;
|
|
22
|
+
return response.text();
|
|
23
|
+
}
|
|
24
|
+
export { isBatchResponsePayload, parseResponseLikeCreateRequest };
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import "node:module";
|
|
2
|
+
import { trace } from "@opentelemetry/api";
|
|
3
|
+
const DATA_BATCH_TRANSPORT_OTEL_EVENT = 'modernjs.data.batch';
|
|
4
|
+
function createDataBatchTransportTelemetryAttributes(event) {
|
|
5
|
+
return {
|
|
6
|
+
'modernjs.data.batch.type': event.type,
|
|
7
|
+
'modernjs.data.batch.endpoint': event.endpoint,
|
|
8
|
+
'modernjs.data.batch.degraded': 'fallback' === event.type || 'disable' === event.type,
|
|
9
|
+
...event.batchId ? {
|
|
10
|
+
'modernjs.data.batch.id': event.batchId
|
|
11
|
+
} : {},
|
|
12
|
+
...'number' == typeof event.size ? {
|
|
13
|
+
'modernjs.data.batch.size': event.size
|
|
14
|
+
} : {},
|
|
15
|
+
...event.reason ? {
|
|
16
|
+
'modernjs.data.batch.reason': event.reason
|
|
17
|
+
} : {}
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
function emitDataBatchTransportEvent(onEvent, event) {
|
|
21
|
+
onEvent?.(event);
|
|
22
|
+
trace.getActiveSpan()?.addEvent(DATA_BATCH_TRANSPORT_OTEL_EVENT, createDataBatchTransportTelemetryAttributes(event));
|
|
23
|
+
}
|
|
24
|
+
export { DATA_BATCH_TRANSPORT_OTEL_EVENT, createDataBatchTransportTelemetryAttributes, emitDataBatchTransportEvent };
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import "node:module";
|
|
2
|
+
import { DEFAULT_DATA_BATCH_ENDPOINT } from "../types.mjs";
|
|
3
|
+
function resolveRuntimeOrigin() {
|
|
4
|
+
if ("u" > typeof window && window.location && 'string' == typeof window.location.origin && window.location.origin) return window.location.origin;
|
|
5
|
+
if ("u" > typeof globalThis && globalThis.location && 'string' == typeof globalThis.location?.origin) return globalThis.location.origin;
|
|
6
|
+
return 'http://localhost';
|
|
7
|
+
}
|
|
8
|
+
function toAbsoluteUrl(input) {
|
|
9
|
+
if (input instanceof URL) return input;
|
|
10
|
+
if ("u" > typeof Request && input instanceof Request) return new URL(input.url);
|
|
11
|
+
const value = String(input);
|
|
12
|
+
try {
|
|
13
|
+
return new URL(value);
|
|
14
|
+
} catch {
|
|
15
|
+
return new URL(value, resolveRuntimeOrigin());
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
function normalizeBatchEndpoint(requestUrl, endpoint) {
|
|
19
|
+
const value = endpoint || DEFAULT_DATA_BATCH_ENDPOINT;
|
|
20
|
+
try {
|
|
21
|
+
return new URL(value);
|
|
22
|
+
} catch {
|
|
23
|
+
return new URL(value, requestUrl.origin);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
export { normalizeBatchEndpoint, resolveRuntimeOrigin, toAbsoluteUrl };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import "node:module";
|
|
2
|
+
import { createBatchTransportQueue } from "./batch/queue.mjs";
|
|
3
|
+
function createDataBatchTransport(options = {}) {
|
|
4
|
+
const fallbackFetch = 'function' == typeof fetch ? fetch.bind(globalThis) : void 0;
|
|
5
|
+
const baseFetch = options.fetch || fallbackFetch;
|
|
6
|
+
if (!baseFetch) throw new Error('createDataBatchTransport requires a fetch implementation');
|
|
7
|
+
return createBatchTransportQueue({
|
|
8
|
+
options,
|
|
9
|
+
baseFetch
|
|
10
|
+
});
|
|
11
|
+
}
|
|
12
|
+
export { DATA_BATCH_TRANSPORT_OTEL_EVENT, createDataBatchTransportTelemetryAttributes, emitDataBatchTransportEvent } from "./batch/telemetry.mjs";
|
|
13
|
+
export { createDataBatchTransport };
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import "node:module";
|
|
2
|
+
function isPlainObject(value) {
|
|
3
|
+
if ('object' != typeof value || null === value || Array.isArray(value)) return false;
|
|
4
|
+
const proto = Object.getPrototypeOf(value);
|
|
5
|
+
return proto === Object.prototype || null === proto;
|
|
6
|
+
}
|
|
7
|
+
function canonicalize(value) {
|
|
8
|
+
if (Array.isArray(value)) return value.map((item)=>canonicalize(item));
|
|
9
|
+
if (isPlainObject(value)) return Object.keys(value).sort().reduce((acc, key)=>{
|
|
10
|
+
acc[key] = canonicalize(value[key]);
|
|
11
|
+
return acc;
|
|
12
|
+
}, {});
|
|
13
|
+
return value;
|
|
14
|
+
}
|
|
15
|
+
function stableStringify(value) {
|
|
16
|
+
return JSON.stringify(canonicalize(value));
|
|
17
|
+
}
|
|
18
|
+
function encodeRequestEnvelopeHeader(envelope) {
|
|
19
|
+
return encodeURIComponent(stableStringify(envelope));
|
|
20
|
+
}
|
|
21
|
+
function isRequestEnvelopeShape(value) {
|
|
22
|
+
if (!isPlainObject(value)) return false;
|
|
23
|
+
return 1 === value.protocolVersion && 'string' == typeof value.operationId && 'string' == typeof value.appNamespace && 'string' == typeof value.origin && 'string' == typeof value.scopeKey && 'string' == typeof value.inputHash && 'number' == typeof value.timestamp;
|
|
24
|
+
}
|
|
25
|
+
function decodeRequestEnvelopeHeader(value) {
|
|
26
|
+
try {
|
|
27
|
+
const decoded = decodeURIComponent(value);
|
|
28
|
+
const parsed = JSON.parse(decoded);
|
|
29
|
+
if (!isRequestEnvelopeShape(parsed)) return null;
|
|
30
|
+
return parsed;
|
|
31
|
+
} catch {
|
|
32
|
+
return null;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
function hashString(value) {
|
|
36
|
+
let hash = 0x811c9dc5;
|
|
37
|
+
for(let index = 0; index < value.length; index++){
|
|
38
|
+
hash ^= value.charCodeAt(index);
|
|
39
|
+
hash = Math.imul(hash, 0x01000193);
|
|
40
|
+
}
|
|
41
|
+
return (hash >>> 0).toString(16).padStart(8, '0');
|
|
42
|
+
}
|
|
43
|
+
function sanitizeSegment(segment) {
|
|
44
|
+
const normalized = segment.trim().replace(/[^a-zA-Z0-9_-]+/g, '_');
|
|
45
|
+
return normalized.length > 0 ? normalized : 'unknown';
|
|
46
|
+
}
|
|
47
|
+
function normalizeOrigin(origin) {
|
|
48
|
+
const normalized = origin.trim();
|
|
49
|
+
try {
|
|
50
|
+
const url = new URL(normalized);
|
|
51
|
+
return `${url.protocol}//${url.host}`.toLowerCase();
|
|
52
|
+
} catch {
|
|
53
|
+
return normalized.toLowerCase();
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
function normalizeOperationDescriptor(input) {
|
|
57
|
+
return {
|
|
58
|
+
appNamespace: sanitizeSegment(input.appNamespace),
|
|
59
|
+
apiId: sanitizeSegment(input.apiId),
|
|
60
|
+
group: sanitizeSegment(input.group),
|
|
61
|
+
endpoint: sanitizeSegment(input.endpoint),
|
|
62
|
+
schemaHash: input.schemaHash || null,
|
|
63
|
+
version: input.version ?? 1
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
function createOperationId(input) {
|
|
67
|
+
const descriptor = normalizeOperationDescriptor(input);
|
|
68
|
+
const readable = `${descriptor.appNamespace}.${descriptor.apiId}.${descriptor.group}.${descriptor.endpoint}.v${String(descriptor.version)}`;
|
|
69
|
+
return `${readable}:${hashString(stableStringify(descriptor))}`;
|
|
70
|
+
}
|
|
71
|
+
function buildScopeKey(scope) {
|
|
72
|
+
const canonical = {
|
|
73
|
+
appNamespace: sanitizeSegment(scope.appNamespace),
|
|
74
|
+
origin: normalizeOrigin(scope.origin),
|
|
75
|
+
tenantId: scope.tenantId ?? null,
|
|
76
|
+
userId: scope.userId ?? null,
|
|
77
|
+
sessionId: scope.sessionId ?? null
|
|
78
|
+
};
|
|
79
|
+
return `${canonical.appNamespace}:${hashString(stableStringify(canonical))}`;
|
|
80
|
+
}
|
|
81
|
+
function buildQueryKey(input) {
|
|
82
|
+
const canonical = {
|
|
83
|
+
operationId: input.operationId,
|
|
84
|
+
scopeKey: input.scopeKey,
|
|
85
|
+
requestMode: input.requestMode ?? 'cache-first',
|
|
86
|
+
requestInput: input.requestInput ?? null,
|
|
87
|
+
selectionPlan: input.selectionPlan ?? null
|
|
88
|
+
};
|
|
89
|
+
return `${input.operationId}:${hashString(stableStringify(canonical))}`;
|
|
90
|
+
}
|
|
91
|
+
export { buildQueryKey, buildScopeKey, createOperationId, decodeRequestEnvelopeHeader, encodeRequestEnvelopeHeader, hashString, isPlainObject, normalizeOrigin, sanitizeSegment, stableStringify };
|