@bleedingdev/modern-js-plugin-bff 3.5.0-ultramodern.9 → 3.5.0-ultramodern.90
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 +184 -0
- package/dist/cjs/cli/prefix.js +50 -0
- package/dist/cjs/cli/serverGlobalVars.js +127 -0
- package/dist/cjs/cli/watch.js +51 -0
- package/dist/cjs/cli.js +11 -130
- package/dist/cjs/loader.js +19 -2
- 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 +92 -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 +26 -146
- package/dist/cjs/runtime/effect/backend-federation/entry.js +99 -0
- package/dist/cjs/runtime/effect/backend-federation/identity.js +82 -0
- package/dist/cjs/runtime/effect/backend-federation/load.js +66 -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 +94 -0
- package/dist/cjs/runtime/effect/backend-federation-manifest/metadata.js +101 -0
- package/dist/cjs/runtime/effect/backend-federation-manifest/reference.js +120 -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 +109 -0
- package/dist/cjs/runtime/effect/backend-federation-manifest.js +62 -0
- package/dist/cjs/runtime/effect/backend-federation.js +65 -0
- package/dist/cjs/runtime/effect/dispatch.js +101 -0
- package/dist/cjs/runtime/effect/edge.js +64 -71
- 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 +68 -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 +85 -0
- package/dist/cjs/utils/effect-client-generator/types.js +18 -0
- package/dist/cjs/utils/effectClientGenerator.js +5 -262
- package/dist/cjs/utils/effectSourceLoader.js +252 -0
- package/dist/esm/cli/compress.mjs +14 -0
- package/dist/esm/cli/generator.mjs +133 -0
- package/dist/esm/cli/prefix.mjs +9 -0
- package/dist/esm/cli/serverGlobalVars.mjs +76 -0
- package/dist/esm/cli/watch.mjs +13 -0
- package/dist/esm/cli.mjs +7 -121
- package/dist/esm/loader.mjs +19 -2
- 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 +44 -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 +27 -147
- package/dist/esm/runtime/effect/backend-federation/entry.mjs +61 -0
- package/dist/esm/runtime/effect/backend-federation/identity.mjs +41 -0
- package/dist/esm/runtime/effect/backend-federation/load.mjs +28 -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 +56 -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 +65 -0
- package/dist/esm/runtime/effect/backend-federation-manifest.mjs +1 -0
- package/dist/esm/runtime/effect/backend-federation.mjs +5 -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 +27 -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 +34 -0
- package/dist/esm/utils/effect-client-generator/types.mjs +0 -0
- package/dist/esm/utils/effectClientGenerator.mjs +1 -249
- package/dist/esm/utils/effectSourceLoader.mjs +199 -0
- package/dist/esm-node/cli/compress.mjs +15 -0
- package/dist/esm-node/cli/generator.mjs +134 -0
- package/dist/esm-node/cli/prefix.mjs +10 -0
- package/dist/esm-node/cli/serverGlobalVars.mjs +77 -0
- package/dist/esm-node/cli/watch.mjs +14 -0
- package/dist/esm-node/cli.mjs +7 -121
- package/dist/esm-node/loader.mjs +19 -2
- 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 +45 -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 +28 -149
- package/dist/esm-node/runtime/effect/backend-federation/entry.mjs +62 -0
- package/dist/esm-node/runtime/effect/backend-federation/identity.mjs +42 -0
- package/dist/esm-node/runtime/effect/backend-federation/load.mjs +29 -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 +57 -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 +66 -0
- package/dist/esm-node/runtime/effect/backend-federation-manifest.mjs +2 -0
- package/dist/esm-node/runtime/effect/backend-federation.mjs +6 -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 +28 -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 +36 -0
- package/dist/esm-node/utils/effect-client-generator/types.mjs +1 -0
- package/dist/esm-node/utils/effectClientGenerator.mjs +2 -251
- package/dist/esm-node/utils/effectSourceLoader.mjs +200 -0
- 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/serverGlobalVars.d.ts +4 -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/identity.d.ts +30 -0
- package/dist/types/runtime/effect/backend-federation/load.d.ts +13 -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 +73 -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 +4 -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 +7 -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 +12 -0
- package/dist/types/utils/effect-client-generator/types.d.ts +27 -0
- package/dist/types/utils/effectClientGenerator.d.ts +2 -41
- package/dist/types/utils/effectSourceLoader.d.ts +15 -0
- package/package.json +45 -33
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
import "node:module";
|
|
2
|
+
import { buildScopeKey, createOperationId, hashString, isPlainObject, normalizeOrigin, sanitizeSegment, stableStringify } from "./codec.mjs";
|
|
3
|
+
import { formatTraceparentHeader, parseTraceparentHeader } from "./trace.mjs";
|
|
4
|
+
function validateSelectionPlan(plan, options = {}) {
|
|
5
|
+
const maxDepthLimit = options.maxDepth ?? 8;
|
|
6
|
+
const maxFieldsLimit = options.maxFields ?? 256;
|
|
7
|
+
const allowedLeafPaths = options.allowedLeafPaths ? new Set(options.allowedLeafPaths) : null;
|
|
8
|
+
const errors = [];
|
|
9
|
+
let maxDepth = 0;
|
|
10
|
+
let fieldCount = 0;
|
|
11
|
+
const walk = (node, path)=>{
|
|
12
|
+
if (!isPlainObject(node)) return void errors.push(`Selection node at "${path.join('.') || '<root>'}" must be an object`);
|
|
13
|
+
const keys = Object.keys(node);
|
|
14
|
+
if (0 === keys.length) return void errors.push(`Selection node at "${path.join('.') || '<root>'}" cannot be empty`);
|
|
15
|
+
for (const key of keys){
|
|
16
|
+
fieldCount += 1;
|
|
17
|
+
if (fieldCount > maxFieldsLimit) return void errors.push(`Selection has too many fields: ${String(fieldCount)} > ${String(maxFieldsLimit)}`);
|
|
18
|
+
const nextPath = [
|
|
19
|
+
...path,
|
|
20
|
+
key
|
|
21
|
+
];
|
|
22
|
+
const depth = nextPath.length;
|
|
23
|
+
if (depth > maxDepth) maxDepth = depth;
|
|
24
|
+
if (depth > maxDepthLimit) return void errors.push(`Selection exceeds maxDepth at "${nextPath.join('.')}" (${String(depth)} > ${String(maxDepthLimit)})`);
|
|
25
|
+
const value = node[key];
|
|
26
|
+
if (true === value) {
|
|
27
|
+
if (allowedLeafPaths && !allowedLeafPaths.has(nextPath.join('.'))) errors.push(`Unknown selected field "${nextPath.join('.')}"`);
|
|
28
|
+
continue;
|
|
29
|
+
}
|
|
30
|
+
if (!isPlainObject(value)) {
|
|
31
|
+
errors.push(`Invalid selection value at "${nextPath.join('.')}"; expected true or nested object`);
|
|
32
|
+
continue;
|
|
33
|
+
}
|
|
34
|
+
walk(value, nextPath);
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
walk(plan, []);
|
|
38
|
+
return {
|
|
39
|
+
ok: 0 === errors.length,
|
|
40
|
+
errors,
|
|
41
|
+
stats: {
|
|
42
|
+
maxDepth,
|
|
43
|
+
fieldCount
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
function createRequestEnvelope(input) {
|
|
48
|
+
if (input.requireTraceContext && !input.traceContext) throw new Error('Trace context is required for this request envelope');
|
|
49
|
+
const traceparent = input.traceContext ? formatTraceparentHeader(input.traceContext) : void 0;
|
|
50
|
+
const envelope = {
|
|
51
|
+
protocolVersion: input.protocolVersion ?? 1,
|
|
52
|
+
operationId: createOperationId(input.operation),
|
|
53
|
+
appNamespace: sanitizeSegment(input.scope.appNamespace),
|
|
54
|
+
origin: normalizeOrigin(input.scope.origin),
|
|
55
|
+
requestMode: input.requestMode ?? 'cache-first',
|
|
56
|
+
mutationMode: input.mutationMode,
|
|
57
|
+
scopeKey: buildScopeKey(input.scope),
|
|
58
|
+
input: input.requestInput,
|
|
59
|
+
inputHash: hashString(stableStringify(input.requestInput ?? null)),
|
|
60
|
+
selectionPlan: input.selectionPlan,
|
|
61
|
+
selectionHash: input.selectionPlan ? hashString(stableStringify(input.selectionPlan)) : void 0,
|
|
62
|
+
traceparent,
|
|
63
|
+
timestamp: input.timestamp ?? Date.now()
|
|
64
|
+
};
|
|
65
|
+
return envelope;
|
|
66
|
+
}
|
|
67
|
+
function validateRequestEnvelope(envelope, options = {}) {
|
|
68
|
+
const errors = [];
|
|
69
|
+
if (void 0 !== options.expectedProtocolVersion && envelope.protocolVersion !== options.expectedProtocolVersion) errors.push(`Protocol mismatch: expected ${String(options.expectedProtocolVersion)} but received ${String(envelope.protocolVersion)}`);
|
|
70
|
+
if (options.expectedNamespace && envelope.appNamespace !== options.expectedNamespace) errors.push(`Namespace mismatch: expected ${options.expectedNamespace} but received ${envelope.appNamespace}`);
|
|
71
|
+
if (options.expectedOrigin) {
|
|
72
|
+
const expectedOrigin = normalizeOrigin(options.expectedOrigin);
|
|
73
|
+
if (envelope.origin !== expectedOrigin) errors.push(`Origin mismatch: expected ${expectedOrigin} but received ${envelope.origin}`);
|
|
74
|
+
}
|
|
75
|
+
if (!envelope.operationId) errors.push('Missing operationId');
|
|
76
|
+
if (!envelope.scopeKey) errors.push('Missing scopeKey');
|
|
77
|
+
if (options.requireTraceContext && !envelope.traceparent) errors.push('Missing trace context');
|
|
78
|
+
if (envelope.traceparent && !parseTraceparentHeader(envelope.traceparent)) errors.push('Invalid traceparent header');
|
|
79
|
+
const computedInputHash = hashString(stableStringify(envelope.input ?? null));
|
|
80
|
+
if (computedInputHash !== envelope.inputHash) errors.push('Input hash mismatch');
|
|
81
|
+
if (envelope.selectionPlan) {
|
|
82
|
+
const computedSelectionHash = hashString(stableStringify(envelope.selectionPlan));
|
|
83
|
+
if (computedSelectionHash !== envelope.selectionHash) errors.push('Selection hash mismatch');
|
|
84
|
+
}
|
|
85
|
+
return {
|
|
86
|
+
ok: 0 === errors.length,
|
|
87
|
+
errors
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
function createHydrationEnvelope(input) {
|
|
91
|
+
const envelopeWithoutChecksum = {
|
|
92
|
+
protocolVersion: input.protocolVersion ?? 1,
|
|
93
|
+
runtimeVersion: input.runtimeVersion,
|
|
94
|
+
appNamespace: sanitizeSegment(input.scope.appNamespace),
|
|
95
|
+
origin: normalizeOrigin(input.scope.origin),
|
|
96
|
+
createdAt: input.createdAt ?? Date.now(),
|
|
97
|
+
payload: input.payload
|
|
98
|
+
};
|
|
99
|
+
const checksum = hashString(stableStringify(envelopeWithoutChecksum));
|
|
100
|
+
return {
|
|
101
|
+
...envelopeWithoutChecksum,
|
|
102
|
+
checksum
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
function validateHydrationEnvelope(envelope, options = {}) {
|
|
106
|
+
const errors = [];
|
|
107
|
+
if (void 0 !== options.expectedProtocolVersion && envelope.protocolVersion !== options.expectedProtocolVersion) errors.push(`Protocol mismatch: expected ${String(options.expectedProtocolVersion)} but received ${String(envelope.protocolVersion)}`);
|
|
108
|
+
if (options.expectedNamespace && envelope.appNamespace !== options.expectedNamespace) errors.push(`Namespace mismatch: expected ${options.expectedNamespace} but received ${envelope.appNamespace}`);
|
|
109
|
+
if (options.expectedOrigin) {
|
|
110
|
+
const expectedOrigin = normalizeOrigin(options.expectedOrigin);
|
|
111
|
+
if (envelope.origin !== expectedOrigin) errors.push(`Origin mismatch: expected ${expectedOrigin} but received ${envelope.origin}`);
|
|
112
|
+
}
|
|
113
|
+
if (options.expectedRuntimeVersion && envelope.runtimeVersion !== options.expectedRuntimeVersion) errors.push(`Runtime version mismatch: expected ${options.expectedRuntimeVersion} but received ${envelope.runtimeVersion}`);
|
|
114
|
+
const checksumBase = {
|
|
115
|
+
protocolVersion: envelope.protocolVersion,
|
|
116
|
+
runtimeVersion: envelope.runtimeVersion,
|
|
117
|
+
appNamespace: envelope.appNamespace,
|
|
118
|
+
origin: envelope.origin,
|
|
119
|
+
createdAt: envelope.createdAt,
|
|
120
|
+
payload: envelope.payload
|
|
121
|
+
};
|
|
122
|
+
const checksum = hashString(stableStringify(checksumBase));
|
|
123
|
+
if (checksum !== envelope.checksum) errors.push('Hydration checksum mismatch');
|
|
124
|
+
return {
|
|
125
|
+
ok: 0 === errors.length,
|
|
126
|
+
errors
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
export { createHydrationEnvelope, createRequestEnvelope, validateHydrationEnvelope, validateRequestEnvelope, validateSelectionPlan };
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import "node:module";
|
|
2
|
+
import { logger } from "@modern-js/utils";
|
|
3
|
+
import { HttpApi } from "effect/unstable/httpapi";
|
|
4
|
+
import { resolveAdapterCrossProjectPolicy } from "../../../utils/crossProjectServerPolicy.mjs";
|
|
5
|
+
import { collectEffectEndpoints, extractHttpApiFromModule, toOperationContractSources } from "../endpoint-contracts.mjs";
|
|
6
|
+
async function resolveEffectAdapterCrossProjectPolicy(api, prefix, mod) {
|
|
7
|
+
let contractSources = [];
|
|
8
|
+
if (mod) try {
|
|
9
|
+
const effectApi = await extractHttpApiFromModule(mod, HttpApi.isHttpApi);
|
|
10
|
+
if (effectApi) {
|
|
11
|
+
const reflect = (apiValue, handlers)=>HttpApi.reflect(apiValue, {
|
|
12
|
+
onGroup: handlers.onGroup ?? (()=>{}),
|
|
13
|
+
onEndpoint: handlers.onEndpoint
|
|
14
|
+
});
|
|
15
|
+
contractSources = toOperationContractSources(collectEffectEndpoints(reflect, effectApi, prefix));
|
|
16
|
+
}
|
|
17
|
+
} catch (error) {
|
|
18
|
+
logger.warn(`[BFF][Effect] Failed reflect HttpApi endpoints cross-project policy: ${String(error)}`);
|
|
19
|
+
}
|
|
20
|
+
const policy = resolveAdapterCrossProjectPolicy(api, contractSources);
|
|
21
|
+
if (policy?.enabled && 0 === contractSources.length) logger.warn('[BFF][Effect] Cross-project policy enabled but no HttpApi endpoints could be reflected; requests fail operation-contract matching unless allowUnknownOperations is enabled.');
|
|
22
|
+
return policy;
|
|
23
|
+
}
|
|
24
|
+
export { resolveEffectAdapterCrossProjectPolicy };
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import "node:module";
|
|
2
|
+
import { API_DIR, findExists, fs, isProd } from "@modern-js/utils";
|
|
3
|
+
import path from "path";
|
|
4
|
+
const JS_OR_TS_EXTS = [
|
|
5
|
+
'.js',
|
|
6
|
+
'.jsx',
|
|
7
|
+
'.ts',
|
|
8
|
+
'.tsx',
|
|
9
|
+
'.mjs',
|
|
10
|
+
'.mts',
|
|
11
|
+
'.cjs',
|
|
12
|
+
'.cts'
|
|
13
|
+
];
|
|
14
|
+
function resolveJsOrTsEntry(entryWithoutOrWithExt) {
|
|
15
|
+
const extension = path.extname(entryWithoutOrWithExt);
|
|
16
|
+
if (JS_OR_TS_EXTS.includes(extension)) return fs.existsSync(entryWithoutOrWithExt) ? entryWithoutOrWithExt : void 0;
|
|
17
|
+
return findExists(JS_OR_TS_EXTS.map((ext)=>`${entryWithoutOrWithExt}${ext}`)) || void 0;
|
|
18
|
+
}
|
|
19
|
+
function builtEntryPath(entryPath) {
|
|
20
|
+
return entryPath.replace(/\.(?:[cm]?ts|tsx|jsx)$/u, '.js');
|
|
21
|
+
}
|
|
22
|
+
function relativeAppPath(appDirectory, entryPath) {
|
|
23
|
+
const relativePath = path.relative(appDirectory, entryPath);
|
|
24
|
+
return '..' === relativePath || relativePath.startsWith(`..${path.sep}`) ? void 0 : relativePath;
|
|
25
|
+
}
|
|
26
|
+
function resolveEffectAdapterEntryFile(api) {
|
|
27
|
+
const { appDirectory, apiDirectory, distDirectory } = api.getServerContext();
|
|
28
|
+
const appRoot = path.resolve(appDirectory || process.cwd());
|
|
29
|
+
const productionRoot = isProd() && distDirectory ? distDirectory : void 0;
|
|
30
|
+
const bffConfig = api.getServerConfig()?.bff;
|
|
31
|
+
const configuredEntry = bffConfig?.effect?.entry;
|
|
32
|
+
if (configuredEntry) {
|
|
33
|
+
const sourceEntry = path.isAbsolute(configuredEntry) ? configuredEntry : path.resolve(appRoot, configuredEntry);
|
|
34
|
+
if (productionRoot) {
|
|
35
|
+
const relativeEntry = relativeAppPath(appRoot, sourceEntry);
|
|
36
|
+
return relativeEntry ? resolveJsOrTsEntry(builtEntryPath(path.resolve(productionRoot, relativeEntry))) : void 0;
|
|
37
|
+
}
|
|
38
|
+
return resolveJsOrTsEntry(sourceEntry);
|
|
39
|
+
}
|
|
40
|
+
const relativeApiDirectory = apiDirectory ? path.isAbsolute(apiDirectory) ? relativeAppPath(appRoot, apiDirectory) : apiDirectory : API_DIR;
|
|
41
|
+
if (!relativeApiDirectory) return;
|
|
42
|
+
const apiRoot = path.resolve(productionRoot || appRoot, relativeApiDirectory);
|
|
43
|
+
return resolveJsOrTsEntry(path.resolve(apiRoot, 'index'));
|
|
44
|
+
}
|
|
45
|
+
export { resolveEffectAdapterEntryFile };
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import "node:module";
|
|
2
|
+
import { logger } from "@modern-js/utils";
|
|
3
|
+
import { createSafeFailureResponse } from "../../safe-failure.mjs";
|
|
4
|
+
async function createEffectAdapterRuntimeErrorResponse(api, error, c) {
|
|
5
|
+
try {
|
|
6
|
+
const serverConfig = api.getServerConfig();
|
|
7
|
+
const onErrorHandler = serverConfig?.onError;
|
|
8
|
+
if (onErrorHandler) {
|
|
9
|
+
const onErrorContext = ensureJsonContext(c);
|
|
10
|
+
const result = await onErrorHandler(error instanceof Error ? error : new Error(String(error)), onErrorContext);
|
|
11
|
+
if (result instanceof Response) return result;
|
|
12
|
+
} else logger.error(error);
|
|
13
|
+
} catch (configError) {
|
|
14
|
+
logger.error(`Error in serverConfig.onError handler: ${configError}`);
|
|
15
|
+
}
|
|
16
|
+
return createSafeFailureResponse(error);
|
|
17
|
+
}
|
|
18
|
+
function ensureJsonContext(c) {
|
|
19
|
+
const maybeJsonContext = c;
|
|
20
|
+
if ('function' == typeof maybeJsonContext.json) return c;
|
|
21
|
+
const headers = {
|
|
22
|
+
'content-type': 'application/json; charset=utf-8'
|
|
23
|
+
};
|
|
24
|
+
const withJson = Object.assign({}, c, {
|
|
25
|
+
json (data, statusOrInit = 200, extraHeaders) {
|
|
26
|
+
const responseInit = 'number' == typeof statusOrInit ? {
|
|
27
|
+
status: statusOrInit,
|
|
28
|
+
headers: extraHeaders
|
|
29
|
+
} : statusOrInit;
|
|
30
|
+
const responseHeaders = new Headers(headers);
|
|
31
|
+
if (responseInit.headers) new Headers(responseInit.headers).forEach((value, key)=>{
|
|
32
|
+
responseHeaders.set(key, value);
|
|
33
|
+
});
|
|
34
|
+
return new Response(JSON.stringify(data), {
|
|
35
|
+
...responseInit,
|
|
36
|
+
headers: responseHeaders
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
return withJson;
|
|
41
|
+
}
|
|
42
|
+
export { createEffectAdapterRuntimeErrorResponse };
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import "node:module";
|
|
2
|
+
import { logger } from "@modern-js/utils";
|
|
3
|
+
import { checkCrossProjectPolicyForRequest } from "../../../utils/crossProjectServerPolicy.mjs";
|
|
4
|
+
import { resolveEffectBffModuleHandler } from "../module.mjs";
|
|
5
|
+
async function loadEffectAdapterHandlerFromModule(api, mod, crossProjectPolicy) {
|
|
6
|
+
const effectConfig = api.getServerConfig()?.bff?.effect;
|
|
7
|
+
return resolveEffectBffModuleHandler(mod, {
|
|
8
|
+
openapi: effectConfig?.openapi,
|
|
9
|
+
dataPlatform: effectConfig?.dataPlatform,
|
|
10
|
+
validateRequest: (request)=>checkCrossProjectPolicyForRequest(request, crossProjectPolicy),
|
|
11
|
+
onWarning: (message)=>{
|
|
12
|
+
logger.warn(message);
|
|
13
|
+
}
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
export { loadEffectAdapterHandlerFromModule };
|
|
@@ -1,93 +1,17 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
import { API_DIR, compatibleRequire, findExists, fs, isProd, logger } from "@modern-js/utils";
|
|
4
|
-
import { HttpApi } from "effect/unstable/httpapi";
|
|
1
|
+
import "node:module";
|
|
2
|
+
import { fs, isProd, logger } from "@modern-js/utils";
|
|
5
3
|
import path from "path";
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
'render'
|
|
15
|
-
];
|
|
16
|
-
const JS_OR_TS_EXTS = [
|
|
17
|
-
'.js',
|
|
18
|
-
'.jsx',
|
|
19
|
-
'.ts',
|
|
20
|
-
'.tsx',
|
|
21
|
-
'.mjs',
|
|
22
|
-
'.mts',
|
|
23
|
-
'.cjs',
|
|
24
|
-
'.cts'
|
|
25
|
-
];
|
|
26
|
-
function resolveJsOrTsEntry(entryWithoutOrWithExt) {
|
|
27
|
-
const extension = path.extname(entryWithoutOrWithExt);
|
|
28
|
-
if (JS_OR_TS_EXTS.includes(extension)) return fs.existsSync(entryWithoutOrWithExt) ? entryWithoutOrWithExt : void 0;
|
|
29
|
-
return findExists(JS_OR_TS_EXTS.map((ext)=>`${entryWithoutOrWithExt}${ext}`));
|
|
30
|
-
}
|
|
31
|
-
function normalizePrefix(prefix) {
|
|
32
|
-
if ('/' === prefix) return '';
|
|
33
|
-
return prefix.endsWith('/') ? prefix.slice(0, -1) : prefix;
|
|
34
|
-
}
|
|
35
|
-
function removePrefixFromPath(pathname, prefix) {
|
|
36
|
-
const normalized = normalizePrefix(prefix);
|
|
37
|
-
if (!normalized || pathname !== normalized && !pathname.startsWith(`${normalized}/`)) return pathname;
|
|
38
|
-
const sliced = pathname.slice(normalized.length);
|
|
39
|
-
return sliced.startsWith('/') ? sliced : `/${sliced}`;
|
|
40
|
-
}
|
|
41
|
-
function createRequestForMountedPrefix(req, prefix) {
|
|
42
|
-
const url = new URL(req.url);
|
|
43
|
-
const nextPath = removePrefixFromPath(url.pathname, prefix);
|
|
44
|
-
if (nextPath === url.pathname) return req;
|
|
45
|
-
url.pathname = nextPath;
|
|
46
|
-
return new Request(url, req);
|
|
47
|
-
}
|
|
48
|
-
function maybeResponse(value) {
|
|
49
|
-
return value instanceof Response;
|
|
50
|
-
}
|
|
4
|
+
import { loadEffectSourceModule } from "../../utils/effectSourceLoader.mjs";
|
|
5
|
+
import { before } from "./adapter/constants.mjs";
|
|
6
|
+
import { resolveEffectAdapterCrossProjectPolicy } from "./adapter/cross-project-policy.mjs";
|
|
7
|
+
import { resolveEffectAdapterEntryFile } from "./adapter/entry.mjs";
|
|
8
|
+
import { createEffectAdapterRuntimeErrorResponse } from "./adapter/error-response.mjs";
|
|
9
|
+
import { loadEffectAdapterHandlerFromModule } from "./adapter/handler.mjs";
|
|
10
|
+
import { runWithEffectContext } from "./context.mjs";
|
|
11
|
+
import { dispatchEffectBffRequestWithContext } from "./dispatch.mjs";
|
|
51
12
|
class EffectAdapter {
|
|
52
13
|
resolveEntryFile() {
|
|
53
|
-
|
|
54
|
-
const bffConfig = this.api.getServerConfig()?.bff;
|
|
55
|
-
const configuredEntry = bffConfig?.effect?.entry;
|
|
56
|
-
if (configuredEntry) {
|
|
57
|
-
const entryWithoutExt = path.isAbsolute(configuredEntry) ? configuredEntry : path.resolve(appDirectory || process.cwd(), configuredEntry);
|
|
58
|
-
return resolveJsOrTsEntry(entryWithoutExt);
|
|
59
|
-
}
|
|
60
|
-
const apiRoot = path.resolve(appDirectory || process.cwd(), apiDirectory || API_DIR);
|
|
61
|
-
return resolveJsOrTsEntry(path.resolve(apiRoot, 'index'));
|
|
62
|
-
}
|
|
63
|
-
async refreshCrossProjectPolicy(mod) {
|
|
64
|
-
let contractSources = [];
|
|
65
|
-
if (mod) try {
|
|
66
|
-
const api = await extractHttpApiFromModule(mod, HttpApi.isHttpApi);
|
|
67
|
-
if (api) {
|
|
68
|
-
const reflect = (apiValue, handlers)=>HttpApi.reflect(apiValue, {
|
|
69
|
-
onGroup: handlers.onGroup ?? (()=>{}),
|
|
70
|
-
onEndpoint: handlers.onEndpoint
|
|
71
|
-
});
|
|
72
|
-
contractSources = toOperationContractSources(collectEffectEndpoints(reflect, api, this.prefix));
|
|
73
|
-
}
|
|
74
|
-
} catch (error) {
|
|
75
|
-
logger.warn(`[BFF][Effect] Failed to reflect HttpApi endpoints for the cross-project policy: ${String(error)}`);
|
|
76
|
-
}
|
|
77
|
-
const policy = resolveAdapterCrossProjectPolicy(this.api, contractSources);
|
|
78
|
-
this.crossProjectPolicy = policy;
|
|
79
|
-
if (this.crossProjectPolicy?.enabled && 0 === contractSources.length) logger.warn('[BFF][Effect] Cross-project policy is enabled but no HttpApi endpoints could be reflected; operation-contract matching is disabled for this server (envelope and operation-context checks still apply).');
|
|
80
|
-
}
|
|
81
|
-
async loadEffectHandlerFromModule(mod) {
|
|
82
|
-
const effectConfig = this.api.getServerConfig()?.bff?.effect;
|
|
83
|
-
return resolveEffectBffModuleHandler(mod, {
|
|
84
|
-
openapi: effectConfig?.openapi,
|
|
85
|
-
dataPlatform: effectConfig?.dataPlatform,
|
|
86
|
-
validateRequest: (request)=>checkCrossProjectPolicyForRequest(request, this.crossProjectPolicy),
|
|
87
|
-
onWarning: (message)=>{
|
|
88
|
-
logger.warn(message);
|
|
89
|
-
}
|
|
90
|
-
});
|
|
14
|
+
return resolveEffectAdapterEntryFile(this.api);
|
|
91
15
|
}
|
|
92
16
|
async reloadHandler() {
|
|
93
17
|
if (!this.isEffect) return;
|
|
@@ -103,18 +27,20 @@ class EffectAdapter {
|
|
|
103
27
|
return;
|
|
104
28
|
}
|
|
105
29
|
await this.disposeCurrentHandler();
|
|
106
|
-
const resolvedEntryFile = require.resolve(entryFile);
|
|
107
|
-
if (Object.hasOwn(require.cache, resolvedEntryFile)) delete require.cache[resolvedEntryFile];
|
|
108
30
|
let mod;
|
|
109
31
|
try {
|
|
110
|
-
|
|
32
|
+
const { appDirectory } = this.api.getServerContext();
|
|
33
|
+
mod = await loadEffectSourceModule({
|
|
34
|
+
resourcePath: entryFile,
|
|
35
|
+
appDir: appDirectory || path.dirname(entryFile)
|
|
36
|
+
});
|
|
111
37
|
} catch (error) {
|
|
112
38
|
logger.error(`[BFF][Effect] Failed to load Effect entry: ${entryFile}\n${String(error)}`);
|
|
113
39
|
this.handler = null;
|
|
114
40
|
return;
|
|
115
41
|
}
|
|
116
|
-
await this.
|
|
117
|
-
const loaded = await this.
|
|
42
|
+
this.crossProjectPolicy = await resolveEffectAdapterCrossProjectPolicy(this.api, this.prefix, mod);
|
|
43
|
+
const loaded = await loadEffectAdapterHandlerFromModule(this.api, mod, this.crossProjectPolicy);
|
|
118
44
|
if (!loaded) {
|
|
119
45
|
logger.warn(`[BFF][Effect] Invalid Effect entry module: ${entryFile}. Export defineEffectBff(...) or a { api, layer } HttpApi module.`);
|
|
120
46
|
this.handler = null;
|
|
@@ -128,48 +54,13 @@ class EffectAdapter {
|
|
|
128
54
|
try {
|
|
129
55
|
await this.dispose();
|
|
130
56
|
} catch (error) {
|
|
131
|
-
logger.warn(`[BFF][Effect] Failed
|
|
57
|
+
logger.warn(`[BFF][Effect] Failed dispose previous handler: ${String(error)}`);
|
|
132
58
|
} finally{
|
|
133
59
|
this.dispose = null;
|
|
134
60
|
}
|
|
135
61
|
}
|
|
136
|
-
async handleRuntimeError(error, c) {
|
|
137
|
-
try {
|
|
138
|
-
const serverConfig = this.api.getServerConfig();
|
|
139
|
-
const onErrorHandler = serverConfig?.onError;
|
|
140
|
-
if (onErrorHandler) {
|
|
141
|
-
const onErrorContext = this.ensureJsonContext(c);
|
|
142
|
-
const result = await onErrorHandler(error instanceof Error ? error : new Error(String(error)), onErrorContext);
|
|
143
|
-
if (result instanceof Response) return result;
|
|
144
|
-
} else logger.error(error);
|
|
145
|
-
} catch (configError) {
|
|
146
|
-
logger.error(`Error in serverConfig.onError handler: ${configError}`);
|
|
147
|
-
}
|
|
148
|
-
return createSafeFailureResponse(error);
|
|
149
|
-
}
|
|
150
|
-
ensureJsonContext(c) {
|
|
151
|
-
const maybeJsonContext = c;
|
|
152
|
-
if ('function' == typeof maybeJsonContext.json) return c;
|
|
153
|
-
const headers = {
|
|
154
|
-
'content-type': 'application/json; charset=utf-8'
|
|
155
|
-
};
|
|
156
|
-
const withJson = Object.assign({}, c, {
|
|
157
|
-
json: (data, status = 200, extraHeaders)=>{
|
|
158
|
-
const responseHeaders = new Headers(headers);
|
|
159
|
-
if (extraHeaders) new Headers(extraHeaders).forEach((value, key)=>{
|
|
160
|
-
responseHeaders.set(key, value);
|
|
161
|
-
});
|
|
162
|
-
return new Response(JSON.stringify(data), {
|
|
163
|
-
status,
|
|
164
|
-
headers: responseHeaders
|
|
165
|
-
});
|
|
166
|
-
}
|
|
167
|
-
});
|
|
168
|
-
return withJson;
|
|
169
|
-
}
|
|
170
62
|
constructor(api){
|
|
171
63
|
this.isEffect = true;
|
|
172
|
-
this.effectMiddleware = null;
|
|
173
64
|
this.handler = null;
|
|
174
65
|
this.dispose = null;
|
|
175
66
|
this.prefix = '/api';
|
|
@@ -191,28 +82,16 @@ class EffectAdapter {
|
|
|
191
82
|
handler: async (c, next)=>{
|
|
192
83
|
if (!this.handler) {
|
|
193
84
|
if (enableHandleWeb) return void await next();
|
|
194
|
-
return this.
|
|
85
|
+
return createEffectAdapterRuntimeErrorResponse(this.api, new Error('[BFF][Effect] Missing Effect entry. Define api/index or configure bff.effect.entry.'), c);
|
|
195
86
|
}
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
operationContext: createEffectOperationContext({
|
|
205
|
-
request: effectRequest,
|
|
206
|
-
env: c.env,
|
|
207
|
-
path: c.req.path,
|
|
208
|
-
method: c.req.method
|
|
209
|
-
})
|
|
210
|
-
};
|
|
211
|
-
response = await runWithEffectContext(effectContext, ()=>this.handler.length > 1 ? this.handler(effectRequest, effectContext) : this.handler(effectRequest));
|
|
212
|
-
} catch (error) {
|
|
213
|
-
return this.handleRuntimeError(error, c);
|
|
214
|
-
}
|
|
215
|
-
if (!maybeResponse(response)) return this.handleRuntimeError(new Error('[BFF][Effect] Effect handler must return a Response instance.'), c);
|
|
87
|
+
const response = await dispatchEffectBffRequestWithContext(this.handler, c.req.raw, {
|
|
88
|
+
prefix,
|
|
89
|
+
env: c.env,
|
|
90
|
+
path: c.req.path,
|
|
91
|
+
method: c.req.method,
|
|
92
|
+
runWithEffectContext: runWithEffectContext,
|
|
93
|
+
onError: (error)=>createEffectAdapterRuntimeErrorResponse(this.api, error, c)
|
|
94
|
+
});
|
|
216
95
|
if (404 === response.status && enableHandleWeb) return void await next();
|
|
217
96
|
return new Response(response.body, response);
|
|
218
97
|
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import "node:module";
|
|
2
|
+
import { isRecord, normalizeExpose } from "./utils.mjs";
|
|
3
|
+
function decodeDataUrl(url) {
|
|
4
|
+
const commaIndex = url.indexOf(',');
|
|
5
|
+
if (commaIndex < 0) throw new Error('[BFF][Effect] Invalid backend federation data URL entry.');
|
|
6
|
+
return decodeURIComponent(url.slice(commaIndex + 1));
|
|
7
|
+
}
|
|
8
|
+
async function readCommonJsEntrySource(remote) {
|
|
9
|
+
if (remote.entry.startsWith('data:')) return decodeDataUrl(remote.entry);
|
|
10
|
+
if (remote.entry.startsWith('http://') || remote.entry.startsWith('https://')) {
|
|
11
|
+
const response = await fetch(remote.entry);
|
|
12
|
+
if (!response.ok) throw new Error(`[BFF][Effect] Failed to load backend federation remote ${remote.name}: ${response.status}`);
|
|
13
|
+
return response.text();
|
|
14
|
+
}
|
|
15
|
+
throw new Error(`[BFF][Effect] Backend federation remote ${remote.name} cannot load CommonJS entry ${remote.entry}.`);
|
|
16
|
+
}
|
|
17
|
+
function evaluateCommonJsEntry(remote, source) {
|
|
18
|
+
const module = {
|
|
19
|
+
exports: {}
|
|
20
|
+
};
|
|
21
|
+
const exports = module.exports;
|
|
22
|
+
const evaluate = new Function('module', 'exports', 'globalThis', source);
|
|
23
|
+
evaluate(module, exports, globalThis);
|
|
24
|
+
const entry = module.exports.default ?? module.exports;
|
|
25
|
+
if (!isRecord(entry)) throw new Error(`[BFF][Effect] Backend federation remote ${remote.name} entry must load object module.`);
|
|
26
|
+
return entry;
|
|
27
|
+
}
|
|
28
|
+
async function importModuleEntry(remote) {
|
|
29
|
+
const entry = await import(remote.entry);
|
|
30
|
+
return entry.default ?? entry;
|
|
31
|
+
}
|
|
32
|
+
async function resolvePluginEntry(remote, plugins) {
|
|
33
|
+
for (const plugin of plugins ?? []){
|
|
34
|
+
const loadEntry = plugin.loadEntry;
|
|
35
|
+
if ('function' != typeof loadEntry) continue;
|
|
36
|
+
const entry = await loadEntry({
|
|
37
|
+
remoteInfo: remote
|
|
38
|
+
});
|
|
39
|
+
if (entry) return entry;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
async function loadBackendFederationEntry(remote, plugins) {
|
|
43
|
+
const pluginEntry = await resolvePluginEntry(remote, plugins);
|
|
44
|
+
if (pluginEntry) return pluginEntry;
|
|
45
|
+
if (remote.entryGlobalName) {
|
|
46
|
+
const globalEntry = globalThis[remote.entryGlobalName];
|
|
47
|
+
if (isRecord(globalEntry)) return globalEntry;
|
|
48
|
+
}
|
|
49
|
+
if ('module' === remote.type || remote.entry.startsWith('file:')) return importModuleEntry(remote);
|
|
50
|
+
return evaluateCommonJsEntry(remote, await readCommonJsEntrySource(remote));
|
|
51
|
+
}
|
|
52
|
+
async function loadBackendFederationExpose(remote, expose, options) {
|
|
53
|
+
const entry = await loadBackendFederationEntry(remote, options.plugins);
|
|
54
|
+
if ('function' == typeof entry.init) await entry.init({
|
|
55
|
+
hostName: options.hostName
|
|
56
|
+
});
|
|
57
|
+
if ('function' != typeof entry.get) throw new Error(`[BFF][Effect] Backend federation remote ${remote.name} entry must expose get().`);
|
|
58
|
+
const factory = await entry.get(expose);
|
|
59
|
+
if ('function' != typeof factory) throw new Error(`[BFF][Effect] Backend federation expose ${remote.name}/${normalizeExpose(expose)} must load factory function.`);
|
|
60
|
+
return factory();
|
|
61
|
+
}
|
|
62
|
+
export { loadBackendFederationExpose };
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import "node:module";
|
|
2
|
+
import { isRecord } from "./utils.mjs";
|
|
3
|
+
function validateExpectedBackendFederationIdentity(loaded, expected, options = {}) {
|
|
4
|
+
const allowMissing = true === options.allowMissingIdentityMetadata;
|
|
5
|
+
const issues = [];
|
|
6
|
+
const contract = isRecord(loaded) ? loaded.backendFederationContract : void 0;
|
|
7
|
+
const compatibility = isRecord(contract) ? contract.compatibility : void 0;
|
|
8
|
+
if (!isRecord(compatibility)) {
|
|
9
|
+
if (allowMissing) return [];
|
|
10
|
+
return [
|
|
11
|
+
{
|
|
12
|
+
path: 'backendFederationContract.compatibility',
|
|
13
|
+
message: 'loaded module declares no compatibility metadata; delivery-unit identity cannot be validated'
|
|
14
|
+
}
|
|
15
|
+
];
|
|
16
|
+
}
|
|
17
|
+
const unitId = compatibility.unitId;
|
|
18
|
+
if ('string' != typeof unitId || 0 === unitId.length) {
|
|
19
|
+
if (!allowMissing) issues.push({
|
|
20
|
+
path: 'backendFederationContract.compatibility.unitId',
|
|
21
|
+
message: `missing delivery-unit id; expected ${expected.unitId}`
|
|
22
|
+
});
|
|
23
|
+
} else if (unitId !== expected.unitId) issues.push({
|
|
24
|
+
path: 'backendFederationContract.compatibility.unitId',
|
|
25
|
+
message: `expected ${expected.unitId}, received ${unitId}`
|
|
26
|
+
});
|
|
27
|
+
const build = compatibility.build;
|
|
28
|
+
if ('string' != typeof build || 0 === build.length) {
|
|
29
|
+
if (!allowMissing) issues.push({
|
|
30
|
+
path: 'backendFederationContract.compatibility.build',
|
|
31
|
+
message: `missing build marker; expected ${expected.buildMarker}`
|
|
32
|
+
});
|
|
33
|
+
} else if (build !== expected.buildMarker) issues.push({
|
|
34
|
+
path: 'backendFederationContract.compatibility.build',
|
|
35
|
+
message: `expected ${expected.buildMarker}, received ${build}`
|
|
36
|
+
});
|
|
37
|
+
return issues;
|
|
38
|
+
}
|
|
39
|
+
function formatBackendFederationIdentityIssues(issues) {
|
|
40
|
+
return issues.map((issue)=>`${issue.path}: ${issue.message}`).join('; ');
|
|
41
|
+
}
|
|
42
|
+
export { formatBackendFederationIdentityIssues, validateExpectedBackendFederationIdentity };
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import "node:module";
|
|
2
|
+
import { BACKEND_FEDERATION_EFFECT_EXPOSE } from "@modern-js/utils/universal";
|
|
3
|
+
import { formatBackendFederationIdentityIssues, validateExpectedBackendFederationIdentity } from "./identity.mjs";
|
|
4
|
+
import { createBackendFederationRuntime } from "./runtime.mjs";
|
|
5
|
+
import { isRecord, normalizeExpose } from "./utils.mjs";
|
|
6
|
+
const LEGACY_LOAD_WARNING = '[BFF][Effect] loadBackendFederatedEffectApi was called without an expected delivery-unit identity (expected.unitId + expected.buildMarker). Identity-less public backend loads are deprecated (ADR-0019/MV-G23) and will be rejected in a future major.';
|
|
7
|
+
async function loadBackendFederatedEffectApi(options) {
|
|
8
|
+
const remoteName = options.remote?.name ?? options.remoteName;
|
|
9
|
+
if (!remoteName) throw new Error('[BFF][Effect] Missing backend federation remote name.');
|
|
10
|
+
if (void 0 === options.expected) console.warn(LEGACY_LOAD_WARNING);
|
|
11
|
+
const runtime = options.runtime ?? createBackendFederationRuntime(options);
|
|
12
|
+
const expose = options.expose ?? options.remote?.expose ?? BACKEND_FEDERATION_EFFECT_EXPOSE;
|
|
13
|
+
const remoteRequest = `${remoteName}/${normalizeExpose(expose)}`;
|
|
14
|
+
const loaded = await runtime.loadRemote(remoteRequest);
|
|
15
|
+
if (!isRecord(loaded)) throw new Error(`[BFF][Effect] Backend federation expose ${remoteRequest} must load an object module.`);
|
|
16
|
+
const backendContract = loaded.backendFederationContract;
|
|
17
|
+
if (!isRecord(backendContract) || true !== backendContract.strictEffectApproach) throw new Error(`[BFF][Effect] Backend federation expose ${remoteRequest} must expose strict Effect metadata (strictEffectApproach: true).`);
|
|
18
|
+
if ('effect' !== backendContract.runtimeFramework) throw new Error(`[BFF][Effect] Backend federation expose ${remoteRequest} must expose strict Effect metadata (runtimeFramework: "effect").`);
|
|
19
|
+
if ('string' == typeof backendContract.name && backendContract.name !== remoteName) throw new Error(`[BFF][Effect] Backend federation expose ${remoteRequest} metadata name mismatch: expected ${remoteName}, received ${backendContract.name}.`);
|
|
20
|
+
if (!('runtime' in loaded)) throw new Error(`[BFF][Effect] Backend federation expose ${remoteRequest} must expose api and runtime.`);
|
|
21
|
+
if (void 0 !== options.expected) {
|
|
22
|
+
const issues = validateExpectedBackendFederationIdentity(loaded, options.expected, {
|
|
23
|
+
allowMissingIdentityMetadata: true === options.allowMissingIdentityMetadata
|
|
24
|
+
});
|
|
25
|
+
if (issues.length > 0) throw new Error(`[BFF][Effect] Backend federation expose ${remoteRequest} delivery-unit identity mismatch: ${formatBackendFederationIdentityIssues(issues)}.`);
|
|
26
|
+
}
|
|
27
|
+
return loaded;
|
|
28
|
+
}
|
|
29
|
+
export { loadBackendFederatedEffectApi };
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import "node:module";
|
|
2
|
+
function createBackendFederationLoadEntryPlugin(options) {
|
|
3
|
+
return {
|
|
4
|
+
name: 'modernjs-backend-federation-load-entry',
|
|
5
|
+
async loadEntry ({ remoteInfo }) {
|
|
6
|
+
return options.resolveEntry({
|
|
7
|
+
name: remoteInfo.name,
|
|
8
|
+
entry: remoteInfo.entry,
|
|
9
|
+
type: remoteInfo.type,
|
|
10
|
+
entryGlobalName: remoteInfo.entryGlobalName,
|
|
11
|
+
shareScope: remoteInfo.shareScope
|
|
12
|
+
});
|
|
13
|
+
}
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
export { createBackendFederationLoadEntryPlugin };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import "node:module";
|
|
2
|
+
function collectRemotes(options) {
|
|
3
|
+
const remotes = [
|
|
4
|
+
...options.remotes ?? []
|
|
5
|
+
];
|
|
6
|
+
if (options.remote) {
|
|
7
|
+
const existingIndex = remotes.findIndex((remote)=>remote.name === options.remote?.name);
|
|
8
|
+
if (existingIndex >= 0) remotes[existingIndex] = options.remote;
|
|
9
|
+
else remotes.push(options.remote);
|
|
10
|
+
}
|
|
11
|
+
return remotes;
|
|
12
|
+
}
|
|
13
|
+
export { collectRemotes };
|