@bleedingdev/modern-js-plugin-bff 3.5.0-ultramodern.1 → 3.5.0-ultramodern.100
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 +13 -22
- 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/hono/adapter.js +32 -79
- package/dist/cjs/runtime/safe-failure.js +2 -1
- package/dist/cjs/server.js +19 -30
- 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 +14 -14
- 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/hono/adapter.mjs +33 -80
- package/dist/esm/runtime/safe-failure.mjs +2 -1
- package/dist/esm/server.mjs +18 -29
- 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 +9 -123
- 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 +14 -14
- 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/hono/adapter.mjs +33 -80
- package/dist/esm-node/runtime/safe-failure.mjs +2 -1
- package/dist/esm-node/server.mjs +18 -29
- 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/esm-node/utils/pluginGenerator.mjs +2 -2
- 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 +11 -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/runtime/hono/adapter.d.ts +14 -8
- 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 +57 -33
|
@@ -1,249 +1 @@
|
|
|
1
|
-
|
|
2
|
-
import { compatibleRequire, findExists, fs, logger } from "@modern-js/utils";
|
|
3
|
-
import path from "path";
|
|
4
|
-
import { collectEffectEndpoints, createEffectEndpointContractHash, ensureLeadingSlash, extractHttpApiFromModule, normalizeEffectPrefix } from "../runtime/effect/endpoint-contracts.mjs";
|
|
5
|
-
const JS_OR_TS_EXTS = [
|
|
6
|
-
'.js',
|
|
7
|
-
'.jsx',
|
|
8
|
-
'.ts',
|
|
9
|
-
'.tsx',
|
|
10
|
-
'.mjs',
|
|
11
|
-
'.mts',
|
|
12
|
-
'.cjs',
|
|
13
|
-
'.cts'
|
|
14
|
-
];
|
|
15
|
-
const DEFAULT_REQUEST_CREATOR = '@modern-js/plugin-bff/client';
|
|
16
|
-
const EFFECT_CLIENT_RUNTIME_IMPORT = '@modern-js/plugin-bff/effect-client-runtime';
|
|
17
|
-
let httpApiRuntimePromise;
|
|
18
|
-
function isRecord(value) {
|
|
19
|
-
return 'object' == typeof value && null !== value;
|
|
20
|
-
}
|
|
21
|
-
function isAbsoluteUrl(value) {
|
|
22
|
-
try {
|
|
23
|
-
new URL(value);
|
|
24
|
-
return true;
|
|
25
|
-
} catch {
|
|
26
|
-
return false;
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
function resolveBatchEndpoint(prefix, endpoint) {
|
|
30
|
-
const value = endpoint || '/_data/batch';
|
|
31
|
-
if (isAbsoluteUrl(value)) return value;
|
|
32
|
-
const normalizedPrefix = normalizeEffectPrefix(prefix);
|
|
33
|
-
const normalizedEndpoint = ensureLeadingSlash(value);
|
|
34
|
-
if (!normalizedPrefix) return normalizedEndpoint;
|
|
35
|
-
if (normalizedEndpoint === normalizedPrefix || normalizedEndpoint.startsWith(`${normalizedPrefix}/`)) return normalizedEndpoint;
|
|
36
|
-
return `${normalizedPrefix}${'/' === normalizedEndpoint ? '' : normalizedEndpoint}`;
|
|
37
|
-
}
|
|
38
|
-
function getPackageInfo(appDir) {
|
|
39
|
-
try {
|
|
40
|
-
const packageJsonPath = path.resolve(appDir, './package.json');
|
|
41
|
-
const packageJson = fs.readJSONSync(packageJsonPath);
|
|
42
|
-
return {
|
|
43
|
-
name: packageJson.name,
|
|
44
|
-
version: packageJson.version
|
|
45
|
-
};
|
|
46
|
-
} catch {
|
|
47
|
-
return {};
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
async function getHttpApiRuntime() {
|
|
51
|
-
if (!httpApiRuntimePromise) httpApiRuntimePromise = (async ()=>{
|
|
52
|
-
let mod;
|
|
53
|
-
try {
|
|
54
|
-
mod = await compatibleRequire('effect/unstable/httpapi', false);
|
|
55
|
-
} catch (error) {
|
|
56
|
-
const message = error instanceof Error ? error.message : String(error);
|
|
57
|
-
if (!message.includes("Cannot find module 'effect/unstable/httpapi'")) throw error;
|
|
58
|
-
const effectPackageJson = require.resolve('effect/package.json');
|
|
59
|
-
const effectHttpApiRuntimePath = path.join(path.dirname(effectPackageJson), 'dist', 'unstable', 'httpapi', 'index.js');
|
|
60
|
-
mod = await compatibleRequire(effectHttpApiRuntimePath, false);
|
|
61
|
-
}
|
|
62
|
-
if (isRecord(mod) && isRecord(mod.HttpApi)) {
|
|
63
|
-
const maybeHttpApi = mod.HttpApi;
|
|
64
|
-
if ('function' == typeof maybeHttpApi.isHttpApi && 'function' == typeof maybeHttpApi.reflect) return maybeHttpApi;
|
|
65
|
-
}
|
|
66
|
-
throw new Error('[BFF][Effect] Unable to resolve HttpApi runtime from effect/unstable/httpapi.');
|
|
67
|
-
})();
|
|
68
|
-
return httpApiRuntimePromise;
|
|
69
|
-
}
|
|
70
|
-
async function loadEffectApi(resourcePath) {
|
|
71
|
-
const httpApiRuntime = await getHttpApiRuntime();
|
|
72
|
-
const mod = await compatibleRequire(resourcePath, false);
|
|
73
|
-
return extractHttpApiFromModule(mod, httpApiRuntime.isHttpApi);
|
|
74
|
-
}
|
|
75
|
-
function renderEffectClientCode(endpoints, options) {
|
|
76
|
-
const requestCreator = options.requestCreator || DEFAULT_REQUEST_CREATOR;
|
|
77
|
-
const httpMethodDecider = options.httpMethodDecider || 'functionName';
|
|
78
|
-
const packageInfo = getPackageInfo(options.appDir);
|
|
79
|
-
const packageName = packageInfo.name;
|
|
80
|
-
const dataPlatformAppNamespace = packageName || 'unknown-app';
|
|
81
|
-
const requestId = 'bundle' === options.target ? packageName || process.env.npm_package_name : void 0;
|
|
82
|
-
const normalizedRequestId = requestId || 'default';
|
|
83
|
-
const operationVersion = deriveOperationVersion(packageInfo.version);
|
|
84
|
-
const batchConfig = options.dataPlatformBatch;
|
|
85
|
-
const batchEndpoint = resolveBatchEndpoint(options.prefix, batchConfig?.endpoint);
|
|
86
|
-
const manifest = {
|
|
87
|
-
endpoints: endpoints.map((endpoint)=>({
|
|
88
|
-
apiId: endpoint.apiId,
|
|
89
|
-
group: endpoint.groupName,
|
|
90
|
-
endpoint: endpoint.endpointName,
|
|
91
|
-
method: endpoint.method,
|
|
92
|
-
routePath: endpoint.routePath,
|
|
93
|
-
schemaHash: createEffectEndpointContractHash(endpoint, normalizedRequestId),
|
|
94
|
-
operationVersion
|
|
95
|
-
}))
|
|
96
|
-
};
|
|
97
|
-
const config = {
|
|
98
|
-
appNamespace: dataPlatformAppNamespace,
|
|
99
|
-
...requestId ? {
|
|
100
|
-
requestId
|
|
101
|
-
} : {},
|
|
102
|
-
port: options.port,
|
|
103
|
-
useEnvPort: 'server' === options.target,
|
|
104
|
-
defaultOrigin: `http://localhost:${String(options.port)}`,
|
|
105
|
-
httpMethodDecider,
|
|
106
|
-
batch: {
|
|
107
|
-
enabled: batchConfig?.enabled ?? true,
|
|
108
|
-
endpoint: batchEndpoint,
|
|
109
|
-
flushIntervalMs: batchConfig?.flushIntervalMs ?? 8,
|
|
110
|
-
maxBatchSize: batchConfig?.maxBatchSize ?? 16,
|
|
111
|
-
maxBatchBytes: batchConfig?.maxBatchBytes ?? 65536,
|
|
112
|
-
requestTimeoutMs: batchConfig?.requestTimeoutMs ?? 10000,
|
|
113
|
-
allowedMethods: batchConfig?.allowedMethods && batchConfig.allowedMethods.length > 0 ? batchConfig.allowedMethods : [
|
|
114
|
-
'GET'
|
|
115
|
-
]
|
|
116
|
-
}
|
|
117
|
-
};
|
|
118
|
-
return `import * as __requestRuntime from ${JSON.stringify(requestCreator)};
|
|
119
|
-
import { createGeneratedEffectClient } from ${JSON.stringify(EFFECT_CLIENT_RUNTIME_IMPORT)};
|
|
120
|
-
|
|
121
|
-
const __manifest = ${JSON.stringify(manifest, null, 2)};
|
|
122
|
-
|
|
123
|
-
const __config = ${JSON.stringify(config, null, 2)};
|
|
124
|
-
|
|
125
|
-
const __generated = createGeneratedEffectClient(__manifest, __config, __requestRuntime);
|
|
126
|
-
|
|
127
|
-
const client = __generated.client;
|
|
128
|
-
const operationManifest = __generated.operationManifest;
|
|
129
|
-
const createEffectRequestContext = __generated.createEffectRequestContext;
|
|
130
|
-
const apiModule = {
|
|
131
|
-
client,
|
|
132
|
-
operationManifest,
|
|
133
|
-
createEffectRequestContext,
|
|
134
|
-
};
|
|
135
|
-
|
|
136
|
-
export { client, createEffectRequestContext, operationManifest };
|
|
137
|
-
export default apiModule;
|
|
138
|
-
`;
|
|
139
|
-
}
|
|
140
|
-
function renderClientShape(endpoints, valueType) {
|
|
141
|
-
if (0 === endpoints.length) return `Record<string, Record<string, ${valueType}>>`;
|
|
142
|
-
const groups = new Map();
|
|
143
|
-
for (const endpoint of endpoints){
|
|
144
|
-
const group = groups.get(endpoint.groupName) || [];
|
|
145
|
-
group.push(endpoint.endpointName);
|
|
146
|
-
groups.set(endpoint.groupName, group);
|
|
147
|
-
}
|
|
148
|
-
const groupEntries = [
|
|
149
|
-
...groups.entries()
|
|
150
|
-
].map(([groupName, names])=>{
|
|
151
|
-
const endpointEntries = names.map((name)=>` ${JSON.stringify(name)}: ${valueType};`).join('\n');
|
|
152
|
-
return ` ${JSON.stringify(groupName)}: {\n${endpointEntries}\n };`;
|
|
153
|
-
});
|
|
154
|
-
return `{\n${groupEntries.join('\n')}\n}`;
|
|
155
|
-
}
|
|
156
|
-
function renderEffectClientDeclaration(endpoints = []) {
|
|
157
|
-
return `export type EffectClientOperation = (
|
|
158
|
-
request?: unknown,
|
|
159
|
-
) => Promise<unknown>;
|
|
160
|
-
export type EffectClientGroup = Record<string, EffectClientOperation>;
|
|
161
|
-
export type EffectClient = Record<string, EffectClientGroup>;
|
|
162
|
-
export type EffectOperationDescriptor = {
|
|
163
|
-
appNamespace: string;
|
|
164
|
-
apiId: string;
|
|
165
|
-
group: string;
|
|
166
|
-
endpoint: string;
|
|
167
|
-
operationId: string;
|
|
168
|
-
routePath: string;
|
|
169
|
-
method: string;
|
|
170
|
-
operationVersion: number;
|
|
171
|
-
schemaHash: string;
|
|
172
|
-
version: number;
|
|
173
|
-
};
|
|
174
|
-
export type EffectOperationManifest = Record<
|
|
175
|
-
string,
|
|
176
|
-
Record<string, EffectOperationDescriptor>
|
|
177
|
-
>;
|
|
178
|
-
export type EffectOperationContext = {
|
|
179
|
-
requestId?: string;
|
|
180
|
-
operationId?: string;
|
|
181
|
-
routePath?: string;
|
|
182
|
-
method?: string;
|
|
183
|
-
schemaHash?: string;
|
|
184
|
-
operationVersion?: number;
|
|
185
|
-
locale?: string;
|
|
186
|
-
traceparent?: string;
|
|
187
|
-
traceId?: string;
|
|
188
|
-
spanId?: string;
|
|
189
|
-
source?: string;
|
|
190
|
-
scope?: Record<string, unknown>;
|
|
191
|
-
sessionClaims?: Record<string, unknown>;
|
|
192
|
-
attributes?: Record<string, unknown>;
|
|
193
|
-
};
|
|
194
|
-
export type EffectRequestContext = {
|
|
195
|
-
headers?: Record<string, string>;
|
|
196
|
-
locale?: string;
|
|
197
|
-
operationContext?: EffectOperationContext;
|
|
198
|
-
traceparent?: string;
|
|
199
|
-
traceId?: string;
|
|
200
|
-
spanId?: string;
|
|
201
|
-
};
|
|
202
|
-
export type GeneratedEffectClient = ${renderClientShape(endpoints, 'EffectClientOperation')};
|
|
203
|
-
export type GeneratedEffectOperationManifest = ${renderClientShape(endpoints, "EffectOperationDescriptor")};
|
|
204
|
-
|
|
205
|
-
export declare const client: GeneratedEffectClient;
|
|
206
|
-
export declare const createEffectRequestContext: (
|
|
207
|
-
requestContext: Record<string, unknown>,
|
|
208
|
-
) => EffectRequestContext;
|
|
209
|
-
export declare const operationManifest: GeneratedEffectOperationManifest;
|
|
210
|
-
declare const apiModule: {
|
|
211
|
-
client: GeneratedEffectClient;
|
|
212
|
-
createEffectRequestContext: typeof createEffectRequestContext;
|
|
213
|
-
operationManifest: GeneratedEffectOperationManifest;
|
|
214
|
-
};
|
|
215
|
-
|
|
216
|
-
export default apiModule;
|
|
217
|
-
`;
|
|
218
|
-
}
|
|
219
|
-
async function generateEffectClient(options) {
|
|
220
|
-
const api = await loadEffectApi(options.resourcePath);
|
|
221
|
-
if (!api) {
|
|
222
|
-
logger.warn(`[BFF][Effect] Failed to generate client for ${options.resourcePath}: unable to resolve exported HttpApi.`);
|
|
223
|
-
return null;
|
|
224
|
-
}
|
|
225
|
-
const httpApiRuntime = await getHttpApiRuntime();
|
|
226
|
-
const endpoints = collectEffectEndpoints(httpApiRuntime.reflect, api, options.prefix);
|
|
227
|
-
return {
|
|
228
|
-
code: renderEffectClientCode(endpoints, options),
|
|
229
|
-
declaration: renderEffectClientDeclaration(endpoints),
|
|
230
|
-
endpoints
|
|
231
|
-
};
|
|
232
|
-
}
|
|
233
|
-
async function generateEffectClientCode(options) {
|
|
234
|
-
const artifacts = await generateEffectClient(options);
|
|
235
|
-
return artifacts ? artifacts.code : null;
|
|
236
|
-
}
|
|
237
|
-
function resolveEffectEntryFile(options) {
|
|
238
|
-
const { appDir, apiDir, effectEntry } = options;
|
|
239
|
-
const resolveEntry = (entryWithoutExt)=>{
|
|
240
|
-
if (path.extname(entryWithoutExt)) return fs.existsSync(entryWithoutExt) ? entryWithoutExt : void 0;
|
|
241
|
-
return findExists(JS_OR_TS_EXTS.map((ext)=>`${entryWithoutExt}${ext}`));
|
|
242
|
-
};
|
|
243
|
-
if (effectEntry) {
|
|
244
|
-
const entryWithoutExt = path.isAbsolute(effectEntry) ? effectEntry : path.resolve(appDir, effectEntry);
|
|
245
|
-
return resolveEntry(entryWithoutExt);
|
|
246
|
-
}
|
|
247
|
-
return resolveEntry(path.resolve(apiDir, 'index'));
|
|
248
|
-
}
|
|
249
|
-
export { generateEffectClient, generateEffectClientCode, renderEffectClientDeclaration, resolveEffectEntryFile };
|
|
1
|
+
export { generateEffectClient, generateEffectClientCode, renderEffectClientDeclaration, resolveEffectEntryFile } from "./effect-client-generator/index.mjs";
|
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
import node_crypto from "node:crypto";
|
|
2
|
+
import node_fs from "node:fs";
|
|
3
|
+
import { builtinModules } from "node:module";
|
|
4
|
+
import node_path from "node:path";
|
|
5
|
+
import { pathToFileURL } from "node:url";
|
|
6
|
+
import { build, transform } from "esbuild";
|
|
7
|
+
const dynamicImport = new Function('specifier', 'return import(specifier)');
|
|
8
|
+
const SOURCE_LOADERS = new Map([
|
|
9
|
+
[
|
|
10
|
+
'.js',
|
|
11
|
+
'js'
|
|
12
|
+
],
|
|
13
|
+
[
|
|
14
|
+
'.jsx',
|
|
15
|
+
'jsx'
|
|
16
|
+
],
|
|
17
|
+
[
|
|
18
|
+
'.mjs',
|
|
19
|
+
'js'
|
|
20
|
+
],
|
|
21
|
+
[
|
|
22
|
+
'.cjs',
|
|
23
|
+
'js'
|
|
24
|
+
],
|
|
25
|
+
[
|
|
26
|
+
'.ts',
|
|
27
|
+
'ts'
|
|
28
|
+
],
|
|
29
|
+
[
|
|
30
|
+
'.tsx',
|
|
31
|
+
'tsx'
|
|
32
|
+
],
|
|
33
|
+
[
|
|
34
|
+
'.mts',
|
|
35
|
+
'ts'
|
|
36
|
+
],
|
|
37
|
+
[
|
|
38
|
+
'.cts',
|
|
39
|
+
'ts'
|
|
40
|
+
]
|
|
41
|
+
]);
|
|
42
|
+
function sourceLoader(args) {
|
|
43
|
+
return SOURCE_LOADERS.get(node_path.extname(args.path).toLowerCase());
|
|
44
|
+
}
|
|
45
|
+
function preserveSourceModuleSemantics() {
|
|
46
|
+
return {
|
|
47
|
+
name: 'modern-js-effect-source-semantics',
|
|
48
|
+
setup (buildApi) {
|
|
49
|
+
buildApi.onLoad({
|
|
50
|
+
filter: /\.[cm]?[jt]sx?$/
|
|
51
|
+
}, async (args)=>{
|
|
52
|
+
const loader = sourceLoader(args);
|
|
53
|
+
if (!loader) return;
|
|
54
|
+
const source = await node_fs.promises.readFile(args.path, 'utf8');
|
|
55
|
+
const compiled = await transform(source, {
|
|
56
|
+
define: {
|
|
57
|
+
'import.meta.url': JSON.stringify(pathToFileURL(args.path).href)
|
|
58
|
+
},
|
|
59
|
+
jsx: 'automatic',
|
|
60
|
+
loader,
|
|
61
|
+
sourcefile: args.path,
|
|
62
|
+
target: 'node20'
|
|
63
|
+
});
|
|
64
|
+
return {
|
|
65
|
+
contents: compiled.code,
|
|
66
|
+
loader: 'js',
|
|
67
|
+
resolveDir: node_path.dirname(args.path)
|
|
68
|
+
};
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
const nodeBuiltins = new Set([
|
|
74
|
+
...builtinModules,
|
|
75
|
+
...builtinModules.map((name)=>`node:${name}`)
|
|
76
|
+
]);
|
|
77
|
+
const dependencyResolutionMarker = 'modern-js-effect-dependency-resolution';
|
|
78
|
+
function isBareSpecifier(specifier) {
|
|
79
|
+
return !specifier.startsWith('.') && !specifier.startsWith('/') && !node_path.isAbsolute(specifier);
|
|
80
|
+
}
|
|
81
|
+
function externalizeInstalledDependencies() {
|
|
82
|
+
return {
|
|
83
|
+
name: 'modern-js-effect-installed-dependencies',
|
|
84
|
+
setup (buildApi) {
|
|
85
|
+
buildApi.onResolve({
|
|
86
|
+
filter: /.*/
|
|
87
|
+
}, async (args)=>{
|
|
88
|
+
if (!isBareSpecifier(args.path) || nodeBuiltins.has(args.path) || args.pluginData?.[dependencyResolutionMarker] === true) return nodeBuiltins.has(args.path) ? {
|
|
89
|
+
external: true,
|
|
90
|
+
path: args.path
|
|
91
|
+
} : void 0;
|
|
92
|
+
const resolution = await buildApi.resolve(args.path, {
|
|
93
|
+
importer: args.importer,
|
|
94
|
+
kind: args.kind,
|
|
95
|
+
namespace: args.namespace,
|
|
96
|
+
pluginData: {
|
|
97
|
+
...args.pluginData,
|
|
98
|
+
[dependencyResolutionMarker]: true
|
|
99
|
+
},
|
|
100
|
+
resolveDir: args.resolveDir
|
|
101
|
+
});
|
|
102
|
+
if (resolution.errors.length > 0) return {
|
|
103
|
+
external: true,
|
|
104
|
+
path: args.path
|
|
105
|
+
};
|
|
106
|
+
if (resolution.external || !resolution.path) return {
|
|
107
|
+
external: true,
|
|
108
|
+
path: args.path
|
|
109
|
+
};
|
|
110
|
+
const realPath = await node_fs.promises.realpath(resolution.path).catch(()=>resolution.path);
|
|
111
|
+
if (realPath.includes(`${node_path.sep}node_modules${node_path.sep}`)) return {
|
|
112
|
+
external: true,
|
|
113
|
+
path: args.path
|
|
114
|
+
};
|
|
115
|
+
return {
|
|
116
|
+
namespace: resolution.namespace,
|
|
117
|
+
path: resolution.path,
|
|
118
|
+
pluginData: resolution.pluginData,
|
|
119
|
+
sideEffects: resolution.sideEffects,
|
|
120
|
+
suffix: resolution.suffix,
|
|
121
|
+
warnings: resolution.warnings,
|
|
122
|
+
watchDirs: resolution.watchDirs,
|
|
123
|
+
watchFiles: resolution.watchFiles
|
|
124
|
+
};
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
async function bundleEffectEntryForNode(options) {
|
|
130
|
+
await build({
|
|
131
|
+
absWorkingDir: options.appDir,
|
|
132
|
+
allowOverwrite: true,
|
|
133
|
+
bundle: true,
|
|
134
|
+
entryPoints: [
|
|
135
|
+
options.entryPath
|
|
136
|
+
],
|
|
137
|
+
format: options.format,
|
|
138
|
+
logLevel: 'silent',
|
|
139
|
+
outfile: options.entryPath,
|
|
140
|
+
platform: 'node',
|
|
141
|
+
plugins: [
|
|
142
|
+
externalizeInstalledDependencies(),
|
|
143
|
+
preserveSourceModuleSemantics()
|
|
144
|
+
],
|
|
145
|
+
target: 'node20'
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
function isWatchableInput(filename) {
|
|
149
|
+
return !filename.includes(`${node_path.sep}node_modules${node_path.sep}`) && (SOURCE_LOADERS.has(node_path.extname(filename).toLowerCase()) || '.json' === node_path.extname(filename).toLowerCase());
|
|
150
|
+
}
|
|
151
|
+
function normalizeImportedModule(module) {
|
|
152
|
+
if (!module || 'object' != typeof module) return module;
|
|
153
|
+
const namespace = module;
|
|
154
|
+
const commonJsModule = namespace.default;
|
|
155
|
+
if (1 === Object.keys(namespace).length && null !== commonJsModule && 'object' == typeof commonJsModule && true === commonJsModule.__esModule) return commonJsModule;
|
|
156
|
+
return module;
|
|
157
|
+
}
|
|
158
|
+
async function loadEffectSourceModule(options) {
|
|
159
|
+
const resourcePath = node_path.resolve(options.resourcePath);
|
|
160
|
+
const appDir = node_path.resolve(options.appDir ?? node_path.dirname(resourcePath));
|
|
161
|
+
const tsconfigPath = node_path.join(appDir, 'tsconfig.json');
|
|
162
|
+
const cacheDirectory = node_path.join(appDir, 'node_modules', '.cache', 'modern-js', 'effect-source-loader');
|
|
163
|
+
const outputName = node_crypto.createHash('sha256').update(resourcePath).digest('hex').slice(0, 24);
|
|
164
|
+
const outputPath = node_path.join(cacheDirectory, `${outputName}.mjs`);
|
|
165
|
+
await node_fs.promises.mkdir(cacheDirectory, {
|
|
166
|
+
recursive: true
|
|
167
|
+
});
|
|
168
|
+
const result = await build({
|
|
169
|
+
absWorkingDir: appDir,
|
|
170
|
+
banner: {
|
|
171
|
+
js: `import { createRequire as __modernCreateEffectRequire } from 'node:module'; const require = __modernCreateEffectRequire(${JSON.stringify(pathToFileURL(resourcePath).href)});`
|
|
172
|
+
},
|
|
173
|
+
bundle: true,
|
|
174
|
+
entryPoints: [
|
|
175
|
+
resourcePath
|
|
176
|
+
],
|
|
177
|
+
format: 'esm',
|
|
178
|
+
jsx: 'automatic',
|
|
179
|
+
logLevel: 'silent',
|
|
180
|
+
metafile: true,
|
|
181
|
+
outfile: outputPath,
|
|
182
|
+
platform: 'node',
|
|
183
|
+
plugins: [
|
|
184
|
+
externalizeInstalledDependencies(),
|
|
185
|
+
preserveSourceModuleSemantics()
|
|
186
|
+
],
|
|
187
|
+
sourcemap: 'inline',
|
|
188
|
+
target: 'node20',
|
|
189
|
+
tsconfig: node_fs.existsSync(tsconfigPath) ? tsconfigPath : void 0
|
|
190
|
+
});
|
|
191
|
+
for (const input of Object.keys(result.metafile.inputs)){
|
|
192
|
+
const dependency = node_path.isAbsolute(input) ? node_path.normalize(input) : node_path.resolve(appDir, input);
|
|
193
|
+
if (isWatchableInput(dependency)) options.onDependency?.(dependency);
|
|
194
|
+
}
|
|
195
|
+
const output = await node_fs.promises.readFile(outputPath);
|
|
196
|
+
const revision = node_crypto.createHash('sha256').update(output).digest('hex');
|
|
197
|
+
return normalizeImportedModule(await dynamicImport(`${pathToFileURL(outputPath).href}?v=${revision}`));
|
|
198
|
+
}
|
|
199
|
+
export { bundleEffectEntryForNode, loadEffectSourceModule };
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import "node:module";
|
|
2
|
+
import { normalizePrefixList } from "./prefix.mjs";
|
|
3
|
+
const createCompressConfig = (devServer, prefix)=>{
|
|
4
|
+
if (!devServer || 'object' != typeof devServer || Array.isArray(devServer)) return;
|
|
5
|
+
const { compress } = devServer;
|
|
6
|
+
if (void 0 === compress || true === compress) {
|
|
7
|
+
const prefixes = normalizePrefixList(prefix);
|
|
8
|
+
return {
|
|
9
|
+
filter: (req)=>!prefixes.some((item)=>req.url?.includes(item))
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
if (false === compress) return false;
|
|
13
|
+
return compress;
|
|
14
|
+
};
|
|
15
|
+
export { createCompressConfig };
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
import "node:module";
|
|
2
|
+
import { ApiRouter } from "@modern-js/bff-core";
|
|
3
|
+
import { compile } from "@modern-js/server-utils";
|
|
4
|
+
import { API_DIR, SHARED_DIR, fs, resolveServerTsconfig } from "@modern-js/utils";
|
|
5
|
+
import path from "path";
|
|
6
|
+
import clientGenerator from "../utils/clientGenerator.mjs";
|
|
7
|
+
import { bundleEffectEntryForNode } from "../utils/effectSourceLoader.mjs";
|
|
8
|
+
import pluginGenerator from "../utils/pluginGenerator.mjs";
|
|
9
|
+
import runtimeGenerator from "../utils/runtimeGenerator.mjs";
|
|
10
|
+
import { getPrimaryPrefix } from "./prefix.mjs";
|
|
11
|
+
import { serializeServerGlobalVars, transformServerGlobalVars } from "./serverGlobalVars.mjs";
|
|
12
|
+
const RUNTIME_CREATE_REQUEST = '@modern-js/plugin-bff/client';
|
|
13
|
+
const effectEntryExtensions = [
|
|
14
|
+
'.js',
|
|
15
|
+
'.jsx',
|
|
16
|
+
'.ts',
|
|
17
|
+
'.tsx',
|
|
18
|
+
'.mjs',
|
|
19
|
+
'.mts',
|
|
20
|
+
'.cjs',
|
|
21
|
+
'.cts'
|
|
22
|
+
];
|
|
23
|
+
function resolveEffectSourceEntry(appDirectory, apiDirectory, configuredEntry) {
|
|
24
|
+
const entry = configuredEntry ? path.isAbsolute(configuredEntry) ? configuredEntry : path.resolve(appDirectory, configuredEntry) : path.resolve(apiDirectory, 'index');
|
|
25
|
+
return path.extname(entry) ? entry : effectEntryExtensions.map((extension)=>`${entry}${extension}`).find((candidate)=>fs.existsSync(candidate));
|
|
26
|
+
}
|
|
27
|
+
function resolveBuiltEffectEntry(appDirectory, distDirectory, sourceEntry) {
|
|
28
|
+
if (!sourceEntry) return;
|
|
29
|
+
const relativeEntry = path.relative(appDirectory, sourceEntry);
|
|
30
|
+
if ('..' === relativeEntry || relativeEntry.startsWith(`..${path.sep}`)) throw new Error(`Effect BFF entry must be inside the application directory: ${sourceEntry}`);
|
|
31
|
+
const builtEntry = path.resolve(distDirectory, relativeEntry).replace(/\.(?:[cm]?ts|tsx|jsx)$/u, '.js');
|
|
32
|
+
return fs.existsSync(builtEntry) ? builtEntry : void 0;
|
|
33
|
+
}
|
|
34
|
+
const createBffGenerator = (api)=>{
|
|
35
|
+
const compileApi = async ()=>{
|
|
36
|
+
const { appDirectory, distDirectory, apiDirectory, bffRuntimeFramework, sharedDirectory, moduleType } = api.getAppContext();
|
|
37
|
+
const modernConfig = api.getNormalizedConfig();
|
|
38
|
+
const distDir = path.resolve(distDirectory);
|
|
39
|
+
const apiDir = apiDirectory || path.resolve(appDirectory, API_DIR);
|
|
40
|
+
const sharedDir = sharedDirectory || path.resolve(appDirectory, SHARED_DIR);
|
|
41
|
+
const tsconfigPath = resolveServerTsconfig(appDirectory, modernConfig?.server?.tsconfigPath);
|
|
42
|
+
const sourceDirs = [];
|
|
43
|
+
if (await fs.pathExists(apiDir)) sourceDirs.push(apiDir);
|
|
44
|
+
if (await fs.pathExists(sharedDir)) sourceDirs.push(sharedDir);
|
|
45
|
+
const { alias, globalVars } = modernConfig.source;
|
|
46
|
+
const { alias: resolveAlias } = modernConfig.resolve;
|
|
47
|
+
if (sourceDirs.length > 0) {
|
|
48
|
+
const combinedAlias = [].concat(alias ?? []).concat(resolveAlias ?? []);
|
|
49
|
+
const serializedGlobalVars = serializeServerGlobalVars(globalVars);
|
|
50
|
+
await compile(appDirectory, {
|
|
51
|
+
alias: combinedAlias
|
|
52
|
+
}, {
|
|
53
|
+
sourceDirs,
|
|
54
|
+
distDir,
|
|
55
|
+
tsconfigPath,
|
|
56
|
+
moduleType,
|
|
57
|
+
throwErrorInsteadOfExit: true
|
|
58
|
+
});
|
|
59
|
+
await transformServerGlobalVars(sourceDirs.map((sourceDir)=>path.resolve(distDir, path.relative(appDirectory, sourceDir))), serializedGlobalVars);
|
|
60
|
+
if ('effect' === bffRuntimeFramework) {
|
|
61
|
+
const sourceEntry = resolveEffectSourceEntry(appDirectory, apiDir, modernConfig.bff?.effect?.entry);
|
|
62
|
+
const builtEntry = resolveBuiltEffectEntry(appDirectory, distDir, sourceEntry);
|
|
63
|
+
if (!builtEntry) throw new Error(`Effect BFF entry was not emitted into ${distDir}: ${sourceEntry ?? path.resolve(apiDir, 'index')}`);
|
|
64
|
+
await bundleEffectEntryForNode({
|
|
65
|
+
appDir: appDirectory,
|
|
66
|
+
entryPath: builtEntry,
|
|
67
|
+
format: 'module' === moduleType ? 'esm' : 'cjs'
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
const generate = async ()=>{
|
|
73
|
+
const { appDirectory, apiDirectory, lambdaDirectory, port, bffRuntimeFramework } = api.getAppContext();
|
|
74
|
+
const modernConfig = api.getNormalizedConfig();
|
|
75
|
+
const relativeDistPath = modernConfig?.output?.distPath?.root || 'dist';
|
|
76
|
+
const { bff } = modernConfig || {};
|
|
77
|
+
const prefix = getPrimaryPrefix(bff?.prefix);
|
|
78
|
+
const httpMethodDecider = bff?.httpMethodDecider;
|
|
79
|
+
const apiRouter = new ApiRouter({
|
|
80
|
+
apiDir: apiDirectory,
|
|
81
|
+
appDir: appDirectory,
|
|
82
|
+
lambdaDir: lambdaDirectory,
|
|
83
|
+
prefix,
|
|
84
|
+
httpMethodDecider,
|
|
85
|
+
isBuild: true
|
|
86
|
+
});
|
|
87
|
+
const lambdaDir = apiRouter.getLambdaDir();
|
|
88
|
+
const existLambda = apiRouter.isExistLambda();
|
|
89
|
+
const runtime = bff?.runtimeCreateRequest || RUNTIME_CREATE_REQUEST;
|
|
90
|
+
const relativeApiPath = path.relative(appDirectory, apiDirectory);
|
|
91
|
+
const relativeLambdaPath = path.relative(appDirectory, lambdaDir);
|
|
92
|
+
await pluginGenerator({
|
|
93
|
+
prefix,
|
|
94
|
+
appDirectory,
|
|
95
|
+
relativeDistPath,
|
|
96
|
+
relativeApiPath,
|
|
97
|
+
relativeLambdaPath,
|
|
98
|
+
runtimeFramework: 'hono' === bffRuntimeFramework ? 'hono' : 'effect'
|
|
99
|
+
});
|
|
100
|
+
await clientGenerator({
|
|
101
|
+
prefix,
|
|
102
|
+
appDir: appDirectory,
|
|
103
|
+
apiDir: apiDirectory,
|
|
104
|
+
lambdaDir,
|
|
105
|
+
existLambda,
|
|
106
|
+
port,
|
|
107
|
+
requestCreator: bff?.requestCreator,
|
|
108
|
+
httpMethodDecider,
|
|
109
|
+
relativeDistPath,
|
|
110
|
+
relativeApiPath,
|
|
111
|
+
bffRuntimeFramework,
|
|
112
|
+
effectEntry: bff?.effect?.entry,
|
|
113
|
+
effectDataPlatformBatch: bff?.effect?.dataPlatform?.batch
|
|
114
|
+
});
|
|
115
|
+
await runtimeGenerator({
|
|
116
|
+
runtime,
|
|
117
|
+
appDirectory,
|
|
118
|
+
relativeDistPath
|
|
119
|
+
});
|
|
120
|
+
};
|
|
121
|
+
const handleCrossProjectInvocation = async (isBuild = false)=>{
|
|
122
|
+
const { bff } = api.getNormalizedConfig();
|
|
123
|
+
if (bff?.crossProject) {
|
|
124
|
+
if (!isBuild) await compileApi();
|
|
125
|
+
await generate();
|
|
126
|
+
}
|
|
127
|
+
};
|
|
128
|
+
return {
|
|
129
|
+
compileApi,
|
|
130
|
+
generate,
|
|
131
|
+
handleCrossProjectInvocation
|
|
132
|
+
};
|
|
133
|
+
};
|
|
134
|
+
export { createBffGenerator };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import "node:module";
|
|
2
|
+
import { DEFAULT_API_PREFIX } from "@modern-js/utils";
|
|
3
|
+
const normalizePrefixList = (prefix)=>{
|
|
4
|
+
if (Array.isArray(prefix)) return prefix.filter(Boolean);
|
|
5
|
+
return [
|
|
6
|
+
prefix || DEFAULT_API_PREFIX
|
|
7
|
+
];
|
|
8
|
+
};
|
|
9
|
+
const getPrimaryPrefix = (prefix)=>normalizePrefixList(prefix)[0] || DEFAULT_API_PREFIX;
|
|
10
|
+
export { getPrimaryPrefix, normalizePrefixList };
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import "node:module";
|
|
2
|
+
import { applyOptionsChain, fs } from "@modern-js/utils";
|
|
3
|
+
import { transform } from "@swc/core";
|
|
4
|
+
import path from "path";
|
|
5
|
+
const RELEASE_IDENTITY_GLOBAL_NAMES = [
|
|
6
|
+
'ULTRAMODERN_BUILD_MARKER',
|
|
7
|
+
'ULTRAMODERN_SOURCE_REVISION',
|
|
8
|
+
'ULTRAMODERN_RELEASE_VERSION'
|
|
9
|
+
];
|
|
10
|
+
const collectJavaScriptFiles = async (directory)=>{
|
|
11
|
+
const entries = await fs.readdir(directory, {
|
|
12
|
+
withFileTypes: true
|
|
13
|
+
});
|
|
14
|
+
const nested = await Promise.all(entries.map(async (entry)=>{
|
|
15
|
+
const absolutePath = path.join(directory, entry.name);
|
|
16
|
+
if (entry.isDirectory()) return collectJavaScriptFiles(absolutePath);
|
|
17
|
+
return /\.(?:c|m)?js$/u.test(entry.name) ? [
|
|
18
|
+
absolutePath
|
|
19
|
+
] : [];
|
|
20
|
+
}));
|
|
21
|
+
return nested.flat();
|
|
22
|
+
};
|
|
23
|
+
const serializeServerGlobalVars = (options)=>{
|
|
24
|
+
const globalVars = applyOptionsChain({}, options, {
|
|
25
|
+
env: 'server',
|
|
26
|
+
target: 'node'
|
|
27
|
+
});
|
|
28
|
+
return Object.fromEntries(Object.entries(globalVars).map(([key, value])=>{
|
|
29
|
+
let serialized;
|
|
30
|
+
try {
|
|
31
|
+
serialized = JSON.stringify(value);
|
|
32
|
+
} catch (error) {
|
|
33
|
+
throw new Error(`source.globalVars["${key}"] cannot be serialized exactly for BFF compilation.`, {
|
|
34
|
+
cause: error
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
if (void 0 === serialized) throw new Error(`source.globalVars["${key}"] cannot be serialized exactly for BFF compilation.`);
|
|
38
|
+
return [
|
|
39
|
+
key,
|
|
40
|
+
serialized
|
|
41
|
+
];
|
|
42
|
+
}));
|
|
43
|
+
};
|
|
44
|
+
const transformServerGlobalVars = async (outputDirectories, globalVars)=>{
|
|
45
|
+
if (0 === Object.keys(globalVars).length) return;
|
|
46
|
+
const existingDirectories = (await Promise.all(outputDirectories.map(async (directory)=>await fs.pathExists(directory) ? directory : void 0))).filter((directory)=>Boolean(directory));
|
|
47
|
+
const files = (await Promise.all(existingDirectories.map(collectJavaScriptFiles))).flat();
|
|
48
|
+
const releaseIdentityBanner = RELEASE_IDENTITY_GLOBAL_NAMES.every((name)=>Object.hasOwn(globalVars, name)) ? `${RELEASE_IDENTITY_GLOBAL_NAMES.map((name)=>`void ${globalVars[name]};`).join('')}\n` : '';
|
|
49
|
+
await Promise.all(files.map(async (filename)=>{
|
|
50
|
+
const source = await fs.readFile(filename, 'utf8');
|
|
51
|
+
const sourceMapFilename = `${filename}.map`;
|
|
52
|
+
const sourceMapExists = await fs.pathExists(sourceMapFilename);
|
|
53
|
+
const inputSourceMap = sourceMapExists ? await fs.readFile(sourceMapFilename, 'utf8') : void 0;
|
|
54
|
+
const result = await transform(`${releaseIdentityBanner}${source}`, {
|
|
55
|
+
filename,
|
|
56
|
+
inputSourceMap,
|
|
57
|
+
sourceMaps: sourceMapExists,
|
|
58
|
+
jsc: {
|
|
59
|
+
parser: {
|
|
60
|
+
syntax: "ecmascript"
|
|
61
|
+
},
|
|
62
|
+
preserveAllComments: true,
|
|
63
|
+
target: 'es2022',
|
|
64
|
+
transform: {
|
|
65
|
+
optimizer: {
|
|
66
|
+
globals: {
|
|
67
|
+
vars: globalVars
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
});
|
|
73
|
+
await fs.writeFile(filename, result.code);
|
|
74
|
+
if (sourceMapExists && result.map) await fs.writeFile(sourceMapFilename, result.map);
|
|
75
|
+
}));
|
|
76
|
+
};
|
|
77
|
+
export { serializeServerGlobalVars, transformServerGlobalVars };
|