@bleedingdev/modern-js-plugin-bff 3.2.0-ultramodern.102 → 3.2.0-ultramodern.104
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.js +9 -5
- package/dist/cjs/constants.js +13 -9
- package/dist/cjs/index.js +9 -5
- package/dist/cjs/loader.js +9 -5
- package/dist/cjs/runtime/create-request/index.js +9 -5
- package/dist/cjs/runtime/data-platform/index.js +9 -5
- package/dist/cjs/runtime/effect/adapter.js +9 -5
- package/dist/cjs/runtime/effect/context.js +9 -5
- package/dist/cjs/runtime/effect/edge.js +14 -10
- package/dist/cjs/runtime/effect/handler.js +59 -60
- package/dist/cjs/runtime/effect/index.js +28 -16
- package/dist/cjs/runtime/effect/module.js +59 -32
- package/dist/cjs/runtime/effect/operation-context.js +9 -5
- package/dist/cjs/runtime/effect-client/index.js +10 -6
- package/dist/cjs/runtime/hono/adapter.js +9 -5
- package/dist/cjs/runtime/hono/index.js +9 -5
- package/dist/cjs/runtime/hono/operators.js +9 -5
- package/dist/cjs/server.js +9 -5
- package/dist/cjs/utils/clientGenerator.js +9 -5
- package/dist/cjs/utils/createHonoRoutes.js +9 -5
- package/dist/cjs/utils/crossProjectApiPlugin.js +9 -5
- package/dist/cjs/utils/effectClientGenerator.js +9 -5
- package/dist/cjs/utils/pluginGenerator.js +9 -5
- package/dist/cjs/utils/runtimeGenerator.js +9 -5
- package/dist/esm/runtime/effect/handler.mjs +7 -6
- package/dist/esm/runtime/effect/index.mjs +2 -0
- package/dist/esm/runtime/effect/module.mjs +50 -27
- package/dist/esm/runtime/effect-client/index.mjs +1 -1
- package/dist/esm-node/runtime/effect/handler.mjs +7 -6
- package/dist/esm-node/runtime/effect/index.mjs +2 -0
- package/dist/esm-node/runtime/effect/module.mjs +50 -27
- package/dist/esm-node/runtime/effect-client/index.mjs +1 -1
- package/dist/types/runtime/effect/context.d.ts +1 -1
- package/dist/types/runtime/effect/handler.d.ts +7 -4
- package/dist/types/runtime/effect/index.d.ts +1 -0
- package/dist/types/runtime/effect/module.d.ts +1 -1
- package/dist/types/utils/createHonoRoutes.d.ts +3 -3
- package/dist/types/utils/effectClientGenerator.d.ts +1 -1
- package/package.json +13 -13
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import "node:module";
|
|
2
2
|
import { HttpApi } from "effect/unstable/httpapi";
|
|
3
3
|
import { createHttpApiHandler } from "./handler.mjs";
|
|
4
|
+
import * as __rspack_external_effect_Context_f1289ca3 from "effect/Context";
|
|
4
5
|
function isRecord(value) {
|
|
5
6
|
return 'object' == typeof value && null !== value;
|
|
6
7
|
}
|
|
@@ -13,15 +14,29 @@ function isRequestHandler(value) {
|
|
|
13
14
|
function isEffectApiDefinition(module) {
|
|
14
15
|
return HttpApi.isHttpApi(module.api) && void 0 !== module.layer;
|
|
15
16
|
}
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
17
|
+
function isEffectServiceContext(context) {
|
|
18
|
+
return 'object' == typeof context && null !== context && 'mapUnsafe' in context;
|
|
19
|
+
}
|
|
20
|
+
const emptyEffectServiceContext = __rspack_external_effect_Context_f1289ca3.empty();
|
|
21
|
+
function callEffectBffRequestHandler(handler, request, context) {
|
|
22
|
+
return void 0 === context ? handler(request) : handler(request, context);
|
|
23
|
+
}
|
|
24
|
+
function createLoadedHandler(webHandler) {
|
|
25
|
+
return {
|
|
26
|
+
handler: (request, context)=>callEffectBffRequestHandler(webHandler.handler, request, context),
|
|
27
|
+
dispose: webHandler.dispose
|
|
24
28
|
};
|
|
29
|
+
}
|
|
30
|
+
function createLoadedHttpApiHandler(webHandler) {
|
|
31
|
+
return {
|
|
32
|
+
handler: (request, context)=>{
|
|
33
|
+
const effectContext = isEffectServiceContext(context) ? context : emptyEffectServiceContext;
|
|
34
|
+
return webHandler.handler(request, effectContext);
|
|
35
|
+
},
|
|
36
|
+
dispose: webHandler.dispose
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
function resolveNormalizedEffectBffModuleHandler(normalizedModule, options = {}) {
|
|
25
40
|
if (isRequestHandler(normalizedModule.handler)) return {
|
|
26
41
|
handler: normalizedModule.handler
|
|
27
42
|
};
|
|
@@ -29,13 +44,6 @@ async function resolveEffectBffModuleHandler(mod, options = {}) {
|
|
|
29
44
|
if (isRequestHandler(entry)) return {
|
|
30
45
|
handler: entry
|
|
31
46
|
};
|
|
32
|
-
if ('function' == typeof entry && 0 === entry.length) {
|
|
33
|
-
const out = await entry();
|
|
34
|
-
if (isRequestHandler(out)) return {
|
|
35
|
-
handler: out
|
|
36
|
-
};
|
|
37
|
-
mergeRuntimeExports(out);
|
|
38
|
-
}
|
|
39
47
|
if (isRecord(entry)) normalizedModule = {
|
|
40
48
|
...normalizedModule,
|
|
41
49
|
...entry
|
|
@@ -55,12 +63,7 @@ async function resolveEffectBffModuleHandler(mod, options = {}) {
|
|
|
55
63
|
openapi: options.openapi,
|
|
56
64
|
dataPlatform: options.dataPlatform
|
|
57
65
|
});
|
|
58
|
-
return
|
|
59
|
-
handler: async (request, context)=>webHandler.handler(request, context),
|
|
60
|
-
dispose: async ()=>{
|
|
61
|
-
await webHandler.dispose();
|
|
62
|
-
}
|
|
63
|
-
};
|
|
66
|
+
return createLoadedHandler(webHandler);
|
|
64
67
|
}
|
|
65
68
|
if (isEffectApiDefinition(normalizedModule)) {
|
|
66
69
|
options.onWarning?.('[BFF][Effect] Detected { api, layer } export without createHandler. Prefer `defineEffectBff(...)` from @modern-js/plugin-bff/server to avoid module instance mismatch.');
|
|
@@ -70,13 +73,33 @@ async function resolveEffectBffModuleHandler(mod, options = {}) {
|
|
|
70
73
|
openapi: options.openapi,
|
|
71
74
|
dataPlatform: options.dataPlatform
|
|
72
75
|
});
|
|
73
|
-
return
|
|
74
|
-
handler: async (request, context)=>webHandler.handler(request, context),
|
|
75
|
-
dispose: async ()=>{
|
|
76
|
-
await webHandler.dispose();
|
|
77
|
-
}
|
|
78
|
-
};
|
|
76
|
+
return createLoadedHttpApiHandler(webHandler);
|
|
79
77
|
}
|
|
80
78
|
return null;
|
|
81
79
|
}
|
|
80
|
+
function resolveEffectBffModuleHandler(mod, options = {}) {
|
|
81
|
+
let normalizedModule = mod;
|
|
82
|
+
const mergeRuntimeExports = (value)=>{
|
|
83
|
+
if (!isRecord(value) || !includesRuntimeExports(value)) return;
|
|
84
|
+
normalizedModule = {
|
|
85
|
+
...normalizedModule,
|
|
86
|
+
...value
|
|
87
|
+
};
|
|
88
|
+
};
|
|
89
|
+
if (isRequestHandler(normalizedModule.handler)) return Promise.resolve({
|
|
90
|
+
handler: normalizedModule.handler
|
|
91
|
+
});
|
|
92
|
+
const entry = normalizedModule.default;
|
|
93
|
+
if (isRequestHandler(entry)) return Promise.resolve({
|
|
94
|
+
handler: entry
|
|
95
|
+
});
|
|
96
|
+
if ('function' == typeof entry && 0 === entry.length) return Promise.resolve(entry()).then((out)=>{
|
|
97
|
+
if (isRequestHandler(out)) return {
|
|
98
|
+
handler: out
|
|
99
|
+
};
|
|
100
|
+
mergeRuntimeExports(out);
|
|
101
|
+
return resolveNormalizedEffectBffModuleHandler(normalizedModule, options);
|
|
102
|
+
});
|
|
103
|
+
return Promise.resolve(resolveNormalizedEffectBffModuleHandler(normalizedModule, options));
|
|
104
|
+
}
|
|
82
105
|
export { resolveEffectBffModuleHandler };
|
|
@@ -56,7 +56,7 @@ function makeEffectHttpApiClient(api, options) {
|
|
|
56
56
|
for (const [header, value] of Object.entries(requestContextHeaders))if (void 0 === nextRequest.headers[header.toLowerCase()]) nextRequest = HttpClientRequest.setHeader(nextRequest, header, value);
|
|
57
57
|
return nextRequest;
|
|
58
58
|
}));
|
|
59
|
-
return options?.transformClient ? options.transformClient(contextClient) : contextClient;
|
|
59
|
+
return 'function' == typeof options?.transformClient ? options.transformClient(contextClient) : contextClient;
|
|
60
60
|
};
|
|
61
61
|
return HttpApiClient.make(api, {
|
|
62
62
|
baseUrl: options?.baseUrl,
|
|
@@ -2,4 +2,4 @@ import type { EffectContext } from './operation-context';
|
|
|
2
2
|
export { type CreateEffectOperationContextOptions, createEffectOperationContext, type EffectContext, } from './operation-context';
|
|
3
3
|
export declare const runWithEffectContext: <T>(context: EffectContext, cb: () => T) => T;
|
|
4
4
|
export declare const useEffectContext: () => EffectContext;
|
|
5
|
-
export declare const useOperationContext: () => OperationContext;
|
|
5
|
+
export declare const useOperationContext: () => import("@modern-js/create-request").OperationContext;
|
|
@@ -1,8 +1,10 @@
|
|
|
1
|
+
import type { FileSystem, Path } from 'effect';
|
|
2
|
+
import * as Context from 'effect/Context';
|
|
1
3
|
import type * as EffectType from 'effect/Effect';
|
|
2
4
|
import * as Layer from 'effect/Layer';
|
|
5
|
+
import { Etag, HttpPlatform, HttpRouter } from 'effect/unstable/http';
|
|
3
6
|
import { type HttpApi, type HttpApiClient, type HttpApiGroup } from 'effect/unstable/httpapi';
|
|
4
7
|
import { type Rpc, type RpcGroup } from 'effect/unstable/rpc';
|
|
5
|
-
export * as OpenTelemetry from '@effect/opentelemetry';
|
|
6
8
|
export * as Config from 'effect/Config';
|
|
7
9
|
export * as Effect from 'effect/Effect';
|
|
8
10
|
export * as Layer from 'effect/Layer';
|
|
@@ -13,7 +15,8 @@ export { HttpTraceContext } from 'effect/unstable/http';
|
|
|
13
15
|
export * from 'effect/unstable/httpapi';
|
|
14
16
|
export { HttpApiBuilder } from 'effect/unstable/httpapi';
|
|
15
17
|
export * from 'effect/unstable/rpc';
|
|
16
|
-
export type
|
|
18
|
+
export type EffectRuntimeRequirements = Etag.Generator | FileSystem.FileSystem | HttpPlatform.HttpPlatform | HttpRouter.HttpRouter | HttpRouter.Request<'Error', any> | HttpRouter.Request<'GlobalError', any> | HttpRouter.Request<'GlobalRequires', any> | HttpRouter.Request<'Requires', any> | Path.Path;
|
|
19
|
+
export type EffectRuntimeLayer = Layer.Layer<never, never, EffectRuntimeRequirements>;
|
|
17
20
|
export type EffectRpcSerialization = 'json' | 'ndjson' | 'jsonRpc' | 'ndJsonRpc' | 'msgPack';
|
|
18
21
|
export type EffectRpcRuntimeLayer<TRpcs extends Rpc.Any = Rpc.Any> = Layer.Layer<Rpc.ToHandler<TRpcs> | Rpc.Middleware<TRpcs> | Rpc.ServicesServer<TRpcs>, unknown, never>;
|
|
19
22
|
export type EffectRpcBffDefinition<TRpcs extends Rpc.Any = Rpc.Any, TRpcLayer extends EffectRpcRuntimeLayer<TRpcs> = EffectRpcRuntimeLayer<TRpcs>> = {
|
|
@@ -141,7 +144,7 @@ export type EffectBffOpenApiConfig = boolean | {
|
|
|
141
144
|
};
|
|
142
145
|
export type EffectRpcBffHandlerFactory<TRpcs extends Rpc.Any = Rpc.Any> = (options?: Partial<EffectRpcBffHandlerOptions>) => ReturnType<typeof createRpcApiHandler<TRpcs>>;
|
|
143
146
|
declare function createRpcApiHandler<TRpcs extends Rpc.Any = Rpc.Any>(options: EffectRpcBffDefinition<TRpcs>): {
|
|
144
|
-
readonly handler: (request: globalThis.Request, context?:
|
|
147
|
+
readonly handler: (request: globalThis.Request, context?: Context.Context<never> | undefined) => Promise<Response>;
|
|
145
148
|
readonly dispose: () => Promise<void>;
|
|
146
149
|
};
|
|
147
150
|
export declare function defineEffectBff<TApi extends HttpApi.AnyWithProps, TLayer extends EffectRuntimeLayer, TRpcs extends Rpc.Any = Rpc.Any>(definition: {
|
|
@@ -165,6 +168,6 @@ export declare function createHttpApiHandler<TApi extends HttpApi.AnyWithProps =
|
|
|
165
168
|
rpc?: EffectRpcBffDefinition<TRpcs>;
|
|
166
169
|
dataPlatform?: EffectDataPlatformValidationOptions;
|
|
167
170
|
}): {
|
|
168
|
-
handler: (request: Request, context?: Parameters<(request: globalThis.Request, context:
|
|
171
|
+
handler: (request: Request, context?: Parameters<(request: globalThis.Request, context: Context.Context<any>) => Promise<Response>>[1]) => Promise<Response>;
|
|
169
172
|
dispose: () => Promise<void>;
|
|
170
173
|
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type * as EffectServiceContext from 'effect/Context';
|
|
2
2
|
import { type EffectBffOpenApiConfig, type EffectDataPlatformValidationOptions } from './handler';
|
|
3
3
|
import type { EffectContext } from './operation-context';
|
|
4
|
-
export type EffectBffRequestHandler = (request: Request, context?: EffectServiceContext.Context<
|
|
4
|
+
export type EffectBffRequestHandler = (request: Request, context?: EffectServiceContext.Context<any> | EffectContext) => Promise<Response> | Response;
|
|
5
5
|
export type EffectBffHandlerFactory = (options?: {
|
|
6
6
|
openapi?: EffectBffOpenApiConfig;
|
|
7
7
|
dataPlatform?: EffectDataPlatformValidationOptions;
|
|
@@ -3,8 +3,8 @@ import type { Context } from '@modern-js/server-core';
|
|
|
3
3
|
type Handler = APIHandlerInfo['handler'];
|
|
4
4
|
declare const createHonoRoutes: (handlerInfos?: APIHandlerInfo[]) => {
|
|
5
5
|
method: any;
|
|
6
|
-
path:
|
|
7
|
-
handler: any[] | ((c: Context) => Promise<
|
|
6
|
+
path: string;
|
|
7
|
+
handler: any[] | ((c: Context) => Promise<void | Response>);
|
|
8
8
|
}[];
|
|
9
|
-
export declare const createHonoHandler: (handler: Handler) => (c: Context) => Promise<
|
|
9
|
+
export declare const createHonoHandler: (handler: Handler) => (c: Context) => Promise<void | Response>;
|
|
10
10
|
export default createHonoRoutes;
|
package/package.json
CHANGED
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
"modern",
|
|
18
18
|
"modern.js"
|
|
19
19
|
],
|
|
20
|
-
"version": "3.2.0-ultramodern.
|
|
20
|
+
"version": "3.2.0-ultramodern.104",
|
|
21
21
|
"types": "./dist/types/cli.d.ts",
|
|
22
22
|
"main": "./dist/cjs/cli.js",
|
|
23
23
|
"exports": {
|
|
@@ -145,15 +145,15 @@
|
|
|
145
145
|
"effect": "4.0.0-beta.66",
|
|
146
146
|
"qs": "^6.15.2",
|
|
147
147
|
"type-is": "^2.1.0",
|
|
148
|
-
"@modern-js/
|
|
149
|
-
"@modern-js/
|
|
150
|
-
"@modern-js/
|
|
151
|
-
"@modern-js/
|
|
152
|
-
"@modern-js/server-utils": "npm:@bleedingdev/modern-js-server-utils@3.2.0-ultramodern.
|
|
153
|
-
"@modern-js/utils": "npm:@bleedingdev/modern-js-utils@3.2.0-ultramodern.
|
|
148
|
+
"@modern-js/builder": "npm:@bleedingdev/modern-js-builder@3.2.0-ultramodern.104",
|
|
149
|
+
"@modern-js/create-request": "npm:@bleedingdev/modern-js-create-request@3.2.0-ultramodern.104",
|
|
150
|
+
"@modern-js/bff-core": "npm:@bleedingdev/modern-js-bff-core@3.2.0-ultramodern.104",
|
|
151
|
+
"@modern-js/server-core": "npm:@bleedingdev/modern-js-server-core@3.2.0-ultramodern.104",
|
|
152
|
+
"@modern-js/server-utils": "npm:@bleedingdev/modern-js-server-utils@3.2.0-ultramodern.104",
|
|
153
|
+
"@modern-js/utils": "npm:@bleedingdev/modern-js-utils@3.2.0-ultramodern.104"
|
|
154
154
|
},
|
|
155
155
|
"devDependencies": {
|
|
156
|
-
"@rsbuild/core": "2.0.
|
|
156
|
+
"@rsbuild/core": "2.0.10",
|
|
157
157
|
"@rslib/core": "0.21.5",
|
|
158
158
|
"@types/node": "^25.9.1",
|
|
159
159
|
"@types/qs": "^6.15.1",
|
|
@@ -161,12 +161,12 @@
|
|
|
161
161
|
"@typescript/native-preview": "7.0.0-dev.20260527.2",
|
|
162
162
|
"memfs": "^4.57.2",
|
|
163
163
|
"zod": "^4.4.3",
|
|
164
|
-
"@modern-js/
|
|
165
|
-
"@modern-js/
|
|
166
|
-
"@modern-js/plugin": "npm:@bleedingdev/modern-js-plugin@3.2.0-ultramodern.
|
|
164
|
+
"@modern-js/bff-runtime": "npm:@bleedingdev/modern-js-bff-runtime@3.2.0-ultramodern.104",
|
|
165
|
+
"@modern-js/app-tools": "npm:@bleedingdev/modern-js-app-tools@3.2.0-ultramodern.104",
|
|
166
|
+
"@modern-js/plugin": "npm:@bleedingdev/modern-js-plugin@3.2.0-ultramodern.104",
|
|
167
|
+
"@modern-js/types": "npm:@bleedingdev/modern-js-types@3.2.0-ultramodern.104",
|
|
167
168
|
"@scripts/rstest-config": "2.66.0",
|
|
168
|
-
"@modern-js/
|
|
169
|
-
"@modern-js/runtime": "npm:@bleedingdev/modern-js-runtime@3.2.0-ultramodern.102"
|
|
169
|
+
"@modern-js/runtime": "npm:@bleedingdev/modern-js-runtime@3.2.0-ultramodern.104"
|
|
170
170
|
},
|
|
171
171
|
"sideEffects": false,
|
|
172
172
|
"publishConfig": {
|