@bleedingdev/modern-js-bff-effect 3.9.0-ultramodern.11 → 3.9.0-ultramodern.13
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/data-platform/batch/options.js +48 -0
- package/dist/cjs/data-platform/batch/queue.js +48 -83
- package/dist/cjs/effect/entry-shape.js +4 -1
- package/dist/cjs/effect/handler/batch-handler.js +2 -3
- package/dist/cjs/effect/handler/batch.js +0 -9
- package/dist/cjs/effect/module.js +4 -0
- package/dist/cjs/effect/operation-context.js +1 -1
- package/dist/cjs/effect/rpcSerialization.js +0 -2
- package/dist/cjs/effect-client/cross-project.js +5 -8
- package/dist/cjs/microvertical-api.js +1 -1
- package/dist/esm/data-platform/batch/options.mjs +10 -0
- package/dist/esm/data-platform/batch/queue.mjs +48 -83
- package/dist/esm/effect/entry-shape-registry.mjs +2 -2
- package/dist/esm/effect/handler/batch-handler.mjs +3 -4
- package/dist/esm/effect/handler/batch.mjs +1 -7
- package/dist/esm/effect/module.mjs +4 -0
- package/dist/esm/effect/operation-context.mjs +1 -1
- package/dist/esm/effect/rpcSerialization.mjs +0 -2
- package/dist/esm/effect-client/cross-project.mjs +6 -9
- package/dist/esm/microvertical-api.mjs +1 -1
- package/dist/esm-node/data-platform/batch/options.mjs +11 -0
- package/dist/esm-node/data-platform/batch/queue.mjs +48 -83
- package/dist/esm-node/effect/entry-shape.mjs +4 -1
- package/dist/esm-node/effect/handler/batch-handler.mjs +3 -4
- package/dist/esm-node/effect/handler/batch.mjs +1 -7
- package/dist/esm-node/effect/module.mjs +4 -0
- package/dist/esm-node/effect/operation-context.mjs +1 -1
- package/dist/esm-node/effect/rpcSerialization.mjs +0 -2
- package/dist/esm-node/effect-client/cross-project.mjs +6 -9
- package/dist/esm-node/microvertical-api.mjs +1 -1
- package/dist/types/data-platform/batch/options.d.ts +7 -0
- package/dist/types/data-platform/batch/queue.d.ts +0 -1
- package/dist/types/effect/entry-shape.d.ts +2 -0
- package/dist/types/effect/handler/batch.d.ts +0 -1
- package/dist/types/effect/handler/types.d.ts +1 -1
- package/dist/types/effect/module.d.ts +2 -1
- package/dist/types/effect-client/index.d.ts +3 -3
- package/dist/types/microvertical-api.d.ts +4 -4
- package/package.json +12 -12
- package/src/data-platform/batch/options.ts +20 -0
- package/src/data-platform/batch/queue.ts +61 -89
- package/src/effect/entry-shape.ts +12 -0
- package/src/effect/handler/batch-handler.ts +6 -12
- package/src/effect/handler/batch.ts +0 -10
- package/src/effect/handler/types.ts +1 -2
- package/src/effect/module.ts +7 -0
- package/src/effect/operation-context.ts +1 -1
- package/src/effect/rpcSerialization.ts +0 -2
- package/src/effect-client/cross-project.ts +9 -14
- package/src/effect-client/index.ts +4 -4
- package/src/microvertical-api.ts +1 -1
|
@@ -8,6 +8,7 @@ import {
|
|
|
8
8
|
isPlainObject,
|
|
9
9
|
normalizeMethod as normalizeItemMethod,
|
|
10
10
|
} from '../../data-platform';
|
|
11
|
+
import { normalizeBatchLimits } from '../../data-platform/batch/options';
|
|
11
12
|
import {
|
|
12
13
|
decodeBatchBody,
|
|
13
14
|
isBatchBody,
|
|
@@ -18,7 +19,6 @@ import {
|
|
|
18
19
|
createBatchValidationResponse,
|
|
19
20
|
isBatchRequestPayload,
|
|
20
21
|
mapWithConcurrency,
|
|
21
|
-
normalizeBatchAllowedMethods,
|
|
22
22
|
normalizeBatchPath,
|
|
23
23
|
promiseWithTimeout,
|
|
24
24
|
toBatchItemError,
|
|
@@ -129,14 +129,11 @@ export function createDataPlatformBatchRequestHandler<TContext>(options: {
|
|
|
129
129
|
const dataPlatformBatchOptions = options.dataPlatform?.batch;
|
|
130
130
|
const batchEnabled = dataPlatformBatchOptions?.enabled !== false;
|
|
131
131
|
const batchPath = normalizeBatchPath(dataPlatformBatchOptions?.endpoint);
|
|
132
|
-
const
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
1024,
|
|
138
|
-
dataPlatformBatchOptions?.maxBatchBytes ?? 64 * 1024,
|
|
139
|
-
);
|
|
132
|
+
const {
|
|
133
|
+
maxBatchSize: batchMaxSize,
|
|
134
|
+
maxBatchBytes: batchMaxBytes,
|
|
135
|
+
allowedMethods: batchAllowedMethods,
|
|
136
|
+
} = normalizeBatchLimits(dataPlatformBatchOptions);
|
|
140
137
|
const batchConcurrency = Math.max(
|
|
141
138
|
1,
|
|
142
139
|
dataPlatformBatchOptions?.maxConcurrency ?? 4,
|
|
@@ -145,9 +142,6 @@ export function createDataPlatformBatchRequestHandler<TContext>(options: {
|
|
|
145
142
|
0,
|
|
146
143
|
dataPlatformBatchOptions?.requestTimeoutMs ?? 10_000,
|
|
147
144
|
);
|
|
148
|
-
const batchAllowedMethods = normalizeBatchAllowedMethods(
|
|
149
|
-
dataPlatformBatchOptions?.allowedMethods,
|
|
150
|
-
);
|
|
151
145
|
const envelopeHeader =
|
|
152
146
|
options.dataPlatform?.envelopeHeader || DEFAULT_DATA_ENVELOPE_HEADER;
|
|
153
147
|
const normalizedEnvelopeHeader = envelopeHeader.toLowerCase();
|
|
@@ -24,16 +24,6 @@ export function normalizeBatchPath(pathname: string | undefined) {
|
|
|
24
24
|
return pathname as `/${string}`;
|
|
25
25
|
}
|
|
26
26
|
|
|
27
|
-
export function normalizeBatchAllowedMethods(
|
|
28
|
-
allowedMethods: string[] | undefined,
|
|
29
|
-
) {
|
|
30
|
-
const source =
|
|
31
|
-
Array.isArray(allowedMethods) && allowedMethods.length > 0
|
|
32
|
-
? allowedMethods
|
|
33
|
-
: ['GET'];
|
|
34
|
-
return new Set(source.map(method => method.toUpperCase()));
|
|
35
|
-
}
|
|
36
|
-
|
|
37
27
|
type ParsedBatchRequestPayload = Omit<DataBatchRequestPayload, 'items'> & {
|
|
38
28
|
items: unknown[];
|
|
39
29
|
};
|
package/src/effect/module.ts
CHANGED
|
@@ -12,6 +12,7 @@ import {
|
|
|
12
12
|
type EffectBffOpenApiConfig,
|
|
13
13
|
type EffectDataPlatformValidationOptions,
|
|
14
14
|
type EffectRequestValidator,
|
|
15
|
+
type EffectRpcBffDefinition,
|
|
15
16
|
type EffectRuntimeLayer,
|
|
16
17
|
} from './handler';
|
|
17
18
|
import type { EffectContext } from './operation-context';
|
|
@@ -33,6 +34,7 @@ export type EffectBffHandlerFactory = (options?: {
|
|
|
33
34
|
export type EffectApiModule = {
|
|
34
35
|
api?: unknown;
|
|
35
36
|
layer?: unknown;
|
|
37
|
+
rpc?: EffectRpcBffDefinition;
|
|
36
38
|
handler?: EffectBffRequestHandler;
|
|
37
39
|
createHandler?: EffectBffHandlerFactory;
|
|
38
40
|
default?: unknown;
|
|
@@ -125,6 +127,11 @@ function resolveClassifiedEffectBffModuleHandler(
|
|
|
125
127
|
}
|
|
126
128
|
}
|
|
127
129
|
|
|
130
|
+
if (facts.module.rpc !== undefined && !facts.createHandlerValidatorAware) {
|
|
131
|
+
rejectUnsupportedEffectModuleShape(options, 'unbranded RPC runtime');
|
|
132
|
+
return null;
|
|
133
|
+
}
|
|
134
|
+
|
|
128
135
|
if (typeof facts.createHandler === 'function') {
|
|
129
136
|
if (facts.createHandlerValidatorAware) {
|
|
130
137
|
const factory = facts.createHandler as EffectBffHandlerFactory;
|
|
@@ -128,7 +128,7 @@ export const createEffectOperationContext = ({
|
|
|
128
128
|
: {}),
|
|
129
129
|
routePath: servicePath,
|
|
130
130
|
method: (method || request.method || 'GET').toUpperCase(),
|
|
131
|
-
source: 'effect-
|
|
131
|
+
source: 'effect-server',
|
|
132
132
|
...(path && path !== servicePath
|
|
133
133
|
? { attributes: { mountedPath: path } }
|
|
134
134
|
: {}),
|
|
@@ -12,8 +12,6 @@ export function getRpcSerializationLayer(
|
|
|
12
12
|
return RpcSerialization.layerJsonRpc();
|
|
13
13
|
case 'ndJsonRpc':
|
|
14
14
|
return RpcSerialization.layerNdJsonRpc();
|
|
15
|
-
case 'msgPack':
|
|
16
|
-
return RpcSerialization.layerMsgPack;
|
|
17
15
|
default:
|
|
18
16
|
return RpcSerialization.layerJsonRpc();
|
|
19
17
|
}
|
|
@@ -2,6 +2,7 @@ import {
|
|
|
2
2
|
BFF_ENVELOPE_HEADER,
|
|
3
3
|
BFF_OPERATION_CONTEXT_DETAIL_HEADER,
|
|
4
4
|
BFF_OPERATION_CONTEXT_HEADER,
|
|
5
|
+
digestOperationContract,
|
|
5
6
|
resolveCrossProjectRequestObservation,
|
|
6
7
|
} from '@modern-js/server-runtime-extensions/bff-policy';
|
|
7
8
|
import * as Effect from 'effect/Effect';
|
|
@@ -66,22 +67,16 @@ export function withCrossProjectPolicy<
|
|
|
66
67
|
);
|
|
67
68
|
}
|
|
68
69
|
return Effect.gen(function* () {
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
globalThis.crypto.subtle.digest(
|
|
78
|
-
'SHA-256',
|
|
79
|
-
new TextEncoder().encode(input),
|
|
70
|
+
const schemaHash = yield* Effect.promise(() =>
|
|
71
|
+
digestOperationContract(
|
|
72
|
+
{
|
|
73
|
+
httpMethod: contract.method,
|
|
74
|
+
name: contract.name,
|
|
75
|
+
routePath: contract.routePath,
|
|
76
|
+
},
|
|
77
|
+
options.requestId,
|
|
80
78
|
),
|
|
81
79
|
);
|
|
82
|
-
const schemaHash = Array.from(new Uint8Array(digest), value =>
|
|
83
|
-
value.toString(16).padStart(2, '0'),
|
|
84
|
-
).join('');
|
|
85
80
|
return request.pipe(
|
|
86
81
|
HttpClientRequest.setHeader(
|
|
87
82
|
BFF_ENVELOPE_HEADER,
|
|
@@ -24,6 +24,7 @@ import {
|
|
|
24
24
|
import {
|
|
25
25
|
Rpc,
|
|
26
26
|
RpcClient,
|
|
27
|
+
RpcClientError,
|
|
27
28
|
RpcGroup,
|
|
28
29
|
RpcSchema,
|
|
29
30
|
RpcSerialization,
|
|
@@ -106,8 +107,7 @@ export type EffectRpcSerialization =
|
|
|
106
107
|
| 'json'
|
|
107
108
|
| 'ndjson'
|
|
108
109
|
| 'jsonRpc'
|
|
109
|
-
| 'ndJsonRpc'
|
|
110
|
-
| 'msgPack';
|
|
110
|
+
| 'ndJsonRpc';
|
|
111
111
|
|
|
112
112
|
export class EffectRpcClientError extends Data.TaggedError(
|
|
113
113
|
'EffectRpcClientError',
|
|
@@ -138,8 +138,8 @@ export type EffectRpcClientHandle<
|
|
|
138
138
|
Rpcs extends Rpc.Any,
|
|
139
139
|
Flatten extends boolean = false,
|
|
140
140
|
> = (Flatten extends true
|
|
141
|
-
? RpcClient.RpcClient.Flat<Rpcs,
|
|
142
|
-
: RpcClient.RpcClient<Rpcs,
|
|
141
|
+
? RpcClient.RpcClient.Flat<Rpcs, RpcClientError.RpcClientError>
|
|
142
|
+
: RpcClient.RpcClient<Rpcs, RpcClientError.RpcClientError>) & {
|
|
143
143
|
dispose: () => Promise<void>;
|
|
144
144
|
};
|
|
145
145
|
|