@bleedingdev/modern-js-bff-effect 3.9.0-ultramodern.5 → 3.9.0-ultramodern.6
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/README.md +20 -4
- package/dist/cjs/effect/endpoint-contracts.js +1 -2
- package/dist/cjs/effect/entry-shape.js +2 -2
- package/dist/cjs/effect/handler/definition.js +1 -21
- package/dist/cjs/effect/module.js +4 -4
- package/dist/cjs/effect-client/cross-project.js +92 -0
- package/dist/cjs/effect-client/index.js +3 -1
- package/dist/esm/effect/endpoint-contracts.mjs +1 -2
- package/dist/esm/effect/entry-shape.mjs +2 -2
- package/dist/esm/effect/handler/definition.mjs +1 -21
- package/dist/esm/effect/module.mjs +4 -4
- package/dist/esm/effect-client/cross-project.mjs +54 -0
- package/dist/esm/effect-client/index.mjs +3 -1
- package/dist/esm-node/effect/endpoint-contracts.mjs +1 -2
- package/dist/esm-node/effect/entry-shape.mjs +2 -2
- package/dist/esm-node/effect/handler/definition.mjs +1 -21
- package/dist/esm-node/effect/module.mjs +4 -4
- package/dist/esm-node/effect-client/cross-project.mjs +55 -0
- package/dist/esm-node/effect-client/index.mjs +3 -1
- package/dist/types/effect/edge-dispatcher.d.ts +1 -1
- package/dist/types/effect/endpoint-contracts.d.ts +1 -19
- package/dist/types/effect/entry-shape.d.ts +2 -2
- package/dist/types/effect/handler/types.d.ts +0 -15
- package/dist/types/effect/handler.d.ts +1 -1
- package/dist/types/effect-client/cross-project.d.ts +10 -0
- package/dist/types/effect-client/index.d.ts +3 -0
- package/package.json +5 -18
- package/src/effect/edge-dispatcher.ts +0 -1
- package/src/effect/endpoint-contracts.ts +2 -23
- package/src/effect/entry-shape.ts +6 -4
- package/src/effect/handler/definition.ts +0 -44
- package/src/effect/handler/http.ts +2 -2
- package/src/effect/handler/types.ts +0 -27
- package/src/effect/handler.ts +0 -1
- package/src/effect/module.ts +4 -4
- package/src/effect-client/cross-project.ts +109 -0
- package/src/effect-client/index.ts +12 -2
- package/dist/cjs/effect-client/batch.js +0 -73
- package/dist/cjs/effect-client/envelope.js +0 -145
- package/dist/cjs/effect-client/guards.js +0 -44
- package/dist/cjs/effect-client/request-context.js +0 -64
- package/dist/cjs/effect-client/request.js +0 -66
- package/dist/cjs/effect-client/runtime.js +0 -100
- package/dist/cjs/effect-client/types.js +0 -18
- package/dist/esm/effect-client/batch.mjs +0 -35
- package/dist/esm/effect-client/envelope.mjs +0 -104
- package/dist/esm/effect-client/guards.mjs +0 -3
- package/dist/esm/effect-client/request-context.mjs +0 -23
- package/dist/esm/effect-client/request.mjs +0 -28
- package/dist/esm/effect-client/runtime.mjs +0 -62
- package/dist/esm/effect-client/types.mjs +0 -0
- package/dist/esm-node/effect-client/batch.mjs +0 -36
- package/dist/esm-node/effect-client/envelope.mjs +0 -105
- package/dist/esm-node/effect-client/guards.mjs +0 -4
- package/dist/esm-node/effect-client/request-context.mjs +0 -24
- package/dist/esm-node/effect-client/request.mjs +0 -29
- package/dist/esm-node/effect-client/runtime.mjs +0 -63
- package/dist/esm-node/effect-client/types.mjs +0 -1
- package/dist/types/effect-client/batch.d.ts +0 -2
- package/dist/types/effect-client/envelope.d.ts +0 -15
- package/dist/types/effect-client/guards.d.ts +0 -2
- package/dist/types/effect-client/request-context.d.ts +0 -3
- package/dist/types/effect-client/request.d.ts +0 -1
- package/dist/types/effect-client/runtime.d.ts +0 -5
- package/dist/types/effect-client/types.d.ts +0 -68
- package/src/effect-client/batch.ts +0 -50
- package/src/effect-client/envelope.ts +0 -238
- package/src/effect-client/guards.ts +0 -6
- package/src/effect-client/request-context.ts +0 -54
- package/src/effect-client/request.ts +0 -51
- package/src/effect-client/runtime.ts +0 -122
- package/src/effect-client/types.ts +0 -84
|
@@ -1,238 +0,0 @@
|
|
|
1
|
-
// @effect-diagnostics processEnv:off strictBooleanExpressions:off
|
|
2
|
-
import {
|
|
3
|
-
createRequestEnvelope,
|
|
4
|
-
DEFAULT_DATA_BATCH_HEADER,
|
|
5
|
-
DEFAULT_DATA_ENVELOPE_HEADER,
|
|
6
|
-
encodeRequestEnvelopeHeader,
|
|
7
|
-
type RequestEnvelope,
|
|
8
|
-
type SelectionPlan,
|
|
9
|
-
type TraceContext,
|
|
10
|
-
} from '../data-platform';
|
|
11
|
-
import { isRecord, stringOrUndefined } from './guards';
|
|
12
|
-
import { normalizeRequest } from './request';
|
|
13
|
-
import { applyRequestContext } from './request-context';
|
|
14
|
-
import type {
|
|
15
|
-
EffectOperationDescriptor,
|
|
16
|
-
EffectRequestContext,
|
|
17
|
-
EffectRequestContextInput,
|
|
18
|
-
GeneratedEffectClientConfig,
|
|
19
|
-
GeneratedEffectEndpoint,
|
|
20
|
-
} from './types';
|
|
21
|
-
|
|
22
|
-
const DATA_REQUEST_MODES = new Set([
|
|
23
|
-
'cache-first',
|
|
24
|
-
'stale-while-revalidate',
|
|
25
|
-
'network-only',
|
|
26
|
-
]);
|
|
27
|
-
const DATA_MUTATION_MODES = new Set([
|
|
28
|
-
'optimistic',
|
|
29
|
-
'pessimistic',
|
|
30
|
-
'fire-and-forget',
|
|
31
|
-
]);
|
|
32
|
-
|
|
33
|
-
const isDataRequestMode = (value: unknown) =>
|
|
34
|
-
typeof value === 'string' && DATA_REQUEST_MODES.has(value);
|
|
35
|
-
|
|
36
|
-
const isDataMutationMode = (value: unknown) =>
|
|
37
|
-
typeof value === 'string' && DATA_MUTATION_MODES.has(value);
|
|
38
|
-
|
|
39
|
-
const normalizeOrigin = (value: unknown): string | undefined => {
|
|
40
|
-
if (typeof value !== 'string' || value.length === 0) {
|
|
41
|
-
return undefined;
|
|
42
|
-
}
|
|
43
|
-
try {
|
|
44
|
-
return new URL(value).origin;
|
|
45
|
-
} catch {
|
|
46
|
-
return undefined;
|
|
47
|
-
}
|
|
48
|
-
};
|
|
49
|
-
|
|
50
|
-
const resolveRuntimeFetch = (): typeof fetch | undefined =>
|
|
51
|
-
typeof fetch === 'function' ? fetch.bind(globalThis) : undefined;
|
|
52
|
-
|
|
53
|
-
/**
|
|
54
|
-
* Resolves the current page origin with a configurable fallback. Single
|
|
55
|
-
* implementation shared by the configure() bootstrap and the data envelope
|
|
56
|
-
* (the generated template previously duplicated data-platform's
|
|
57
|
-
* `resolveRuntimeOrigin` with a different fallback).
|
|
58
|
-
*/
|
|
59
|
-
|
|
60
|
-
export const resolveOrigin = (defaultOrigin: string): string => {
|
|
61
|
-
if (
|
|
62
|
-
typeof window !== 'undefined' &&
|
|
63
|
-
window.location &&
|
|
64
|
-
typeof window.location.origin === 'string' &&
|
|
65
|
-
window.location.origin
|
|
66
|
-
) {
|
|
67
|
-
return window.location.origin;
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
const globalLocation = (
|
|
71
|
-
globalThis as { location?: { origin?: unknown } } | undefined
|
|
72
|
-
)?.location;
|
|
73
|
-
if (
|
|
74
|
-
globalLocation &&
|
|
75
|
-
typeof globalLocation.origin === 'string' &&
|
|
76
|
-
globalLocation.origin
|
|
77
|
-
) {
|
|
78
|
-
return globalLocation.origin;
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
return defaultOrigin;
|
|
82
|
-
};
|
|
83
|
-
|
|
84
|
-
const resolveTargetOrigin = (
|
|
85
|
-
dataPlatform: Record<string, unknown>,
|
|
86
|
-
defaultOrigin: string,
|
|
87
|
-
): string => {
|
|
88
|
-
const explicitTargetOrigin =
|
|
89
|
-
stringOrUndefined(dataPlatform.targetOrigin) ||
|
|
90
|
-
stringOrUndefined(dataPlatform.endpointOrigin);
|
|
91
|
-
if (explicitTargetOrigin) {
|
|
92
|
-
return explicitTargetOrigin;
|
|
93
|
-
}
|
|
94
|
-
return defaultOrigin;
|
|
95
|
-
};
|
|
96
|
-
|
|
97
|
-
const shouldAttachEnvelopeHeader = (
|
|
98
|
-
dataPlatform: Record<string, unknown>,
|
|
99
|
-
defaultOrigin: string,
|
|
100
|
-
): boolean => {
|
|
101
|
-
if (dataPlatform.allowCrossOriginEnvelope === true) {
|
|
102
|
-
return true;
|
|
103
|
-
}
|
|
104
|
-
const currentOrigin = normalizeOrigin(resolveOrigin(defaultOrigin));
|
|
105
|
-
const targetOrigin = normalizeOrigin(
|
|
106
|
-
resolveTargetOrigin(dataPlatform, defaultOrigin),
|
|
107
|
-
);
|
|
108
|
-
if (!currentOrigin || !targetOrigin) {
|
|
109
|
-
return true;
|
|
110
|
-
}
|
|
111
|
-
return currentOrigin === targetOrigin;
|
|
112
|
-
};
|
|
113
|
-
|
|
114
|
-
const toEnvelopeInput = (
|
|
115
|
-
normalizedRequest: Record<string, unknown>,
|
|
116
|
-
): Record<string, unknown> => {
|
|
117
|
-
const payload: Record<string, unknown> = {};
|
|
118
|
-
if (isRecord(normalizedRequest.params)) {
|
|
119
|
-
payload.path = normalizedRequest.params;
|
|
120
|
-
}
|
|
121
|
-
if (isRecord(normalizedRequest.query)) {
|
|
122
|
-
payload.query = normalizedRequest.query;
|
|
123
|
-
}
|
|
124
|
-
if ('data' in normalizedRequest && normalizedRequest.data !== undefined) {
|
|
125
|
-
payload.data = normalizedRequest.data;
|
|
126
|
-
}
|
|
127
|
-
if ('body' in normalizedRequest && normalizedRequest.body !== undefined) {
|
|
128
|
-
payload.body = normalizedRequest.body;
|
|
129
|
-
}
|
|
130
|
-
if (
|
|
131
|
-
typeof FormData !== 'undefined' &&
|
|
132
|
-
normalizedRequest.formData instanceof FormData
|
|
133
|
-
) {
|
|
134
|
-
payload.formData = Array.from(normalizedRequest.formData.entries()).map(
|
|
135
|
-
([key, value]) => [key, String(value)],
|
|
136
|
-
);
|
|
137
|
-
}
|
|
138
|
-
if (
|
|
139
|
-
typeof URLSearchParams !== 'undefined' &&
|
|
140
|
-
normalizedRequest.formUrlencoded instanceof URLSearchParams
|
|
141
|
-
) {
|
|
142
|
-
payload.formUrlencoded = normalizedRequest.formUrlencoded.toString();
|
|
143
|
-
}
|
|
144
|
-
return payload;
|
|
145
|
-
};
|
|
146
|
-
|
|
147
|
-
export const prepareEffectRequest = (options: {
|
|
148
|
-
endpoint: GeneratedEffectEndpoint;
|
|
149
|
-
operation: EffectOperationDescriptor;
|
|
150
|
-
request: unknown;
|
|
151
|
-
config: GeneratedEffectClientConfig;
|
|
152
|
-
createEffectRequestContext: (
|
|
153
|
-
requestContext: EffectRequestContextInput,
|
|
154
|
-
) => EffectRequestContext;
|
|
155
|
-
}): Record<string, unknown> => {
|
|
156
|
-
const { endpoint, operation, request, config, createEffectRequestContext } =
|
|
157
|
-
options;
|
|
158
|
-
const defaultOrigin = config.defaultOrigin;
|
|
159
|
-
const normalizedRequest = applyRequestContext(
|
|
160
|
-
normalizeRequest(endpoint.method, request),
|
|
161
|
-
request,
|
|
162
|
-
createEffectRequestContext,
|
|
163
|
-
);
|
|
164
|
-
const dataPlatform =
|
|
165
|
-
isRecord(request) && isRecord(request.dataPlatform)
|
|
166
|
-
? request.dataPlatform
|
|
167
|
-
: {};
|
|
168
|
-
const strictEnvelope =
|
|
169
|
-
dataPlatform.requireEnvelope === true || dataPlatform.strict === true;
|
|
170
|
-
|
|
171
|
-
if (
|
|
172
|
-
!strictEnvelope &&
|
|
173
|
-
!shouldAttachEnvelopeHeader(dataPlatform, defaultOrigin)
|
|
174
|
-
) {
|
|
175
|
-
return normalizedRequest;
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
try {
|
|
179
|
-
const namespace =
|
|
180
|
-
stringOrUndefined(dataPlatform.appNamespace) || config.appNamespace;
|
|
181
|
-
const origin =
|
|
182
|
-
stringOrUndefined(dataPlatform.origin) || resolveOrigin(defaultOrigin);
|
|
183
|
-
const envelope: RequestEnvelope = createRequestEnvelope({
|
|
184
|
-
operation: {
|
|
185
|
-
...operation,
|
|
186
|
-
appNamespace: namespace,
|
|
187
|
-
},
|
|
188
|
-
scope: {
|
|
189
|
-
appNamespace: namespace,
|
|
190
|
-
origin,
|
|
191
|
-
tenantId: stringOrUndefined(dataPlatform.tenantId),
|
|
192
|
-
userId: stringOrUndefined(dataPlatform.userId),
|
|
193
|
-
sessionId: stringOrUndefined(dataPlatform.sessionId),
|
|
194
|
-
},
|
|
195
|
-
requestInput: {
|
|
196
|
-
method: endpoint.method,
|
|
197
|
-
routePath: endpoint.routePath,
|
|
198
|
-
payload: toEnvelopeInput(normalizedRequest),
|
|
199
|
-
},
|
|
200
|
-
requestMode: isDataRequestMode(dataPlatform.requestMode)
|
|
201
|
-
? (dataPlatform.requestMode as RequestEnvelope['requestMode'])
|
|
202
|
-
: undefined,
|
|
203
|
-
mutationMode: isDataMutationMode(dataPlatform.mutationMode)
|
|
204
|
-
? (dataPlatform.mutationMode as RequestEnvelope['mutationMode'])
|
|
205
|
-
: undefined,
|
|
206
|
-
selectionPlan: isRecord(dataPlatform.selectionPlan)
|
|
207
|
-
? (dataPlatform.selectionPlan as SelectionPlan)
|
|
208
|
-
: undefined,
|
|
209
|
-
traceContext: isRecord(dataPlatform.traceContext)
|
|
210
|
-
? (dataPlatform.traceContext as unknown as TraceContext)
|
|
211
|
-
: undefined,
|
|
212
|
-
requireTraceContext: dataPlatform.requireTraceContext === true,
|
|
213
|
-
});
|
|
214
|
-
|
|
215
|
-
const headerName =
|
|
216
|
-
stringOrUndefined(dataPlatform.envelopeHeader) ||
|
|
217
|
-
DEFAULT_DATA_ENVELOPE_HEADER;
|
|
218
|
-
const headers = isRecord(normalizedRequest.headers)
|
|
219
|
-
? { ...normalizedRequest.headers }
|
|
220
|
-
: {};
|
|
221
|
-
|
|
222
|
-
if (dataPlatform.batch === false) {
|
|
223
|
-
headers[DEFAULT_DATA_BATCH_HEADER] = 'off';
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
headers[headerName] = encodeRequestEnvelopeHeader(envelope);
|
|
227
|
-
|
|
228
|
-
return {
|
|
229
|
-
...normalizedRequest,
|
|
230
|
-
headers,
|
|
231
|
-
};
|
|
232
|
-
} catch (error) {
|
|
233
|
-
if (strictEnvelope) {
|
|
234
|
-
throw error;
|
|
235
|
-
}
|
|
236
|
-
return normalizedRequest;
|
|
237
|
-
}
|
|
238
|
-
};
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
// @effect-diagnostics processEnv:off strictBooleanExpressions:off
|
|
2
|
-
export const isRecord = (value: unknown): value is Record<string, unknown> =>
|
|
3
|
-
typeof value === 'object' && value !== null;
|
|
4
|
-
|
|
5
|
-
export const stringOrUndefined = (value: unknown): string | undefined =>
|
|
6
|
-
typeof value === 'string' && value.length > 0 ? value : undefined;
|
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
// @effect-diagnostics processEnv:off strictBooleanExpressions:off
|
|
2
|
-
import { isRecord } from './guards';
|
|
3
|
-
import type {
|
|
4
|
-
EffectRequestContext,
|
|
5
|
-
EffectRequestContextInput,
|
|
6
|
-
EffectRequestRuntime,
|
|
7
|
-
} from './types';
|
|
8
|
-
|
|
9
|
-
export const createEffectRequestContext = (
|
|
10
|
-
createRequestContextHeaders: EffectRequestRuntime['createRequestContextHeaders'],
|
|
11
|
-
requestContext: EffectRequestContextInput,
|
|
12
|
-
): EffectRequestContext => {
|
|
13
|
-
if (!isRecord(requestContext)) {
|
|
14
|
-
return {} as EffectRequestContext;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
const headers = createRequestContextHeaders
|
|
18
|
-
? createRequestContextHeaders(requestContext)
|
|
19
|
-
: {};
|
|
20
|
-
|
|
21
|
-
return {
|
|
22
|
-
...requestContext,
|
|
23
|
-
headers,
|
|
24
|
-
};
|
|
25
|
-
};
|
|
26
|
-
|
|
27
|
-
export const applyRequestContext = (
|
|
28
|
-
normalizedRequest: Record<string, unknown>,
|
|
29
|
-
request: unknown,
|
|
30
|
-
createRequestContext: (
|
|
31
|
-
requestContext: EffectRequestContextInput,
|
|
32
|
-
) => EffectRequestContext,
|
|
33
|
-
): Record<string, unknown> => {
|
|
34
|
-
if (!isRecord(request) || !isRecord(request.requestContext)) {
|
|
35
|
-
return normalizedRequest;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
const requestContext = createRequestContext(request.requestContext);
|
|
39
|
-
const requestHeaders = isRecord(requestContext.headers)
|
|
40
|
-
? requestContext.headers
|
|
41
|
-
: {};
|
|
42
|
-
|
|
43
|
-
if (Object.keys(requestHeaders).length === 0) {
|
|
44
|
-
return normalizedRequest;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
return {
|
|
48
|
-
...normalizedRequest,
|
|
49
|
-
headers: {
|
|
50
|
-
...(isRecord(normalizedRequest.headers) ? normalizedRequest.headers : {}),
|
|
51
|
-
...requestHeaders,
|
|
52
|
-
},
|
|
53
|
-
};
|
|
54
|
-
};
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
// @effect-diagnostics processEnv:off strictBooleanExpressions:off
|
|
2
|
-
import { isRecord } from './guards';
|
|
3
|
-
|
|
4
|
-
const METHODS_WITHOUT_BODY = new Set(['GET', 'DELETE', 'HEAD', 'OPTIONS']);
|
|
5
|
-
|
|
6
|
-
export const normalizeRequest = (
|
|
7
|
-
method: string,
|
|
8
|
-
request: unknown,
|
|
9
|
-
): Record<string, unknown> => {
|
|
10
|
-
if (!isRecord(request)) {
|
|
11
|
-
return {};
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
const payload: Record<string, unknown> = { ...request };
|
|
15
|
-
|
|
16
|
-
if (isRecord(request.path) && !isRecord(payload.params)) {
|
|
17
|
-
payload.params = request.path;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
if (isRecord(request.urlParams) && !isRecord(payload.query)) {
|
|
21
|
-
payload.query = request.urlParams;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
if (isRecord(request.headers) && !isRecord(payload.headers)) {
|
|
25
|
-
payload.headers = request.headers;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
if ('payload' in request && request.payload !== undefined) {
|
|
29
|
-
if (
|
|
30
|
-
typeof FormData !== 'undefined' &&
|
|
31
|
-
request.payload instanceof FormData &&
|
|
32
|
-
!('formData' in payload)
|
|
33
|
-
) {
|
|
34
|
-
payload.formData = request.payload;
|
|
35
|
-
} else if (METHODS_WITHOUT_BODY.has(method)) {
|
|
36
|
-
if (isRecord(request.payload)) {
|
|
37
|
-
payload.query = isRecord(payload.query)
|
|
38
|
-
? { ...payload.query, ...request.payload }
|
|
39
|
-
: request.payload;
|
|
40
|
-
} else if (!('body' in payload)) {
|
|
41
|
-
payload.body = request.payload;
|
|
42
|
-
}
|
|
43
|
-
} else if (isRecord(request.payload) && !('data' in payload)) {
|
|
44
|
-
payload.data = request.payload;
|
|
45
|
-
} else if (!('body' in payload)) {
|
|
46
|
-
payload.body = request.payload;
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
return payload;
|
|
51
|
-
};
|
|
@@ -1,122 +0,0 @@
|
|
|
1
|
-
// @effect-diagnostics processEnv:off strictBooleanExpressions:off
|
|
2
|
-
import { configureGeneratedEffectClientRuntime } from './batch';
|
|
3
|
-
import { prepareEffectRequest } from './envelope';
|
|
4
|
-
import { createEffectRequestContext as createEffectRequestContextWithHeaders } from './request-context';
|
|
5
|
-
import type {
|
|
6
|
-
EffectClient,
|
|
7
|
-
EffectClientOperation,
|
|
8
|
-
EffectOperationDescriptor,
|
|
9
|
-
EffectOperationManifest,
|
|
10
|
-
EffectRequestContext,
|
|
11
|
-
EffectRequestContextInput,
|
|
12
|
-
EffectRequestRuntime,
|
|
13
|
-
GeneratedEffectClientConfig,
|
|
14
|
-
GeneratedEffectClientModule,
|
|
15
|
-
GeneratedEffectEndpoint,
|
|
16
|
-
} from './types';
|
|
17
|
-
|
|
18
|
-
export type {
|
|
19
|
-
EffectClient,
|
|
20
|
-
EffectClientGroup,
|
|
21
|
-
EffectClientOperation,
|
|
22
|
-
EffectOperationDescriptor,
|
|
23
|
-
EffectOperationManifest,
|
|
24
|
-
EffectRequestContext,
|
|
25
|
-
EffectRequestContextInput,
|
|
26
|
-
EffectRequestRuntime,
|
|
27
|
-
GeneratedEffectBatchConfig,
|
|
28
|
-
GeneratedEffectClientConfig,
|
|
29
|
-
GeneratedEffectClientModule,
|
|
30
|
-
GeneratedEffectEndpoint,
|
|
31
|
-
} from './types';
|
|
32
|
-
|
|
33
|
-
export const createGeneratedEffectClient = (
|
|
34
|
-
manifest: { endpoints: GeneratedEffectEndpoint[] },
|
|
35
|
-
config: GeneratedEffectClientConfig,
|
|
36
|
-
requestRuntime: EffectRequestRuntime,
|
|
37
|
-
): GeneratedEffectClientModule => {
|
|
38
|
-
const createRequest = requestRuntime.createRequest;
|
|
39
|
-
const configureRequest =
|
|
40
|
-
typeof requestRuntime.configure === 'function'
|
|
41
|
-
? requestRuntime.configure
|
|
42
|
-
: undefined;
|
|
43
|
-
const createRequestContextHeaders =
|
|
44
|
-
typeof requestRuntime.createRequestContextHeaders === 'function'
|
|
45
|
-
? requestRuntime.createRequestContextHeaders
|
|
46
|
-
: undefined;
|
|
47
|
-
|
|
48
|
-
const httpMethodDecider = config.httpMethodDecider || 'functionName';
|
|
49
|
-
const port =
|
|
50
|
-
config.useEnvPort &&
|
|
51
|
-
typeof process !== 'undefined' &&
|
|
52
|
-
process.env &&
|
|
53
|
-
process.env.PORT
|
|
54
|
-
? process.env.PORT
|
|
55
|
-
: config.port;
|
|
56
|
-
|
|
57
|
-
configureGeneratedEffectClientRuntime(config, configureRequest);
|
|
58
|
-
|
|
59
|
-
const createEffectRequestContext = (
|
|
60
|
-
requestContext: EffectRequestContextInput,
|
|
61
|
-
): EffectRequestContext =>
|
|
62
|
-
createEffectRequestContextWithHeaders(
|
|
63
|
-
createRequestContextHeaders,
|
|
64
|
-
requestContext,
|
|
65
|
-
);
|
|
66
|
-
|
|
67
|
-
const client: EffectClient = {};
|
|
68
|
-
const operationManifest: EffectOperationManifest = {};
|
|
69
|
-
|
|
70
|
-
for (const endpoint of manifest.endpoints) {
|
|
71
|
-
const operationId = `${endpoint.method}:${endpoint.routePath}`;
|
|
72
|
-
const operation: EffectOperationDescriptor = {
|
|
73
|
-
appNamespace: config.appNamespace,
|
|
74
|
-
apiId: endpoint.apiId,
|
|
75
|
-
group: endpoint.group,
|
|
76
|
-
endpoint: endpoint.endpoint,
|
|
77
|
-
operationId,
|
|
78
|
-
routePath: endpoint.routePath,
|
|
79
|
-
method: endpoint.method,
|
|
80
|
-
operationVersion: endpoint.operationVersion,
|
|
81
|
-
schemaHash: endpoint.schemaHash,
|
|
82
|
-
version: endpoint.operationVersion,
|
|
83
|
-
};
|
|
84
|
-
|
|
85
|
-
const sender = createRequest({
|
|
86
|
-
path: endpoint.routePath,
|
|
87
|
-
method: endpoint.method,
|
|
88
|
-
port,
|
|
89
|
-
operationContext: {
|
|
90
|
-
operationId,
|
|
91
|
-
routePath: endpoint.routePath,
|
|
92
|
-
method: endpoint.method,
|
|
93
|
-
schemaHash: endpoint.schemaHash,
|
|
94
|
-
operationVersion: endpoint.operationVersion,
|
|
95
|
-
},
|
|
96
|
-
httpMethodDecider,
|
|
97
|
-
...(config.requestId ? { requestId: config.requestId } : {}),
|
|
98
|
-
});
|
|
99
|
-
|
|
100
|
-
const call: EffectClientOperation = (request: unknown = {}) =>
|
|
101
|
-
sender(
|
|
102
|
-
prepareEffectRequest({
|
|
103
|
-
endpoint,
|
|
104
|
-
operation,
|
|
105
|
-
request,
|
|
106
|
-
config,
|
|
107
|
-
createEffectRequestContext,
|
|
108
|
-
}),
|
|
109
|
-
);
|
|
110
|
-
|
|
111
|
-
client[endpoint.group] ??= {};
|
|
112
|
-
client[endpoint.group]![endpoint.endpoint] = call;
|
|
113
|
-
operationManifest[endpoint.group] ??= {};
|
|
114
|
-
operationManifest[endpoint.group]![endpoint.endpoint] = operation;
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
return {
|
|
118
|
-
client,
|
|
119
|
-
operationManifest,
|
|
120
|
-
createEffectRequestContext,
|
|
121
|
-
};
|
|
122
|
-
};
|
|
@@ -1,84 +0,0 @@
|
|
|
1
|
-
// @effect-diagnostics processEnv:off strictBooleanExpressions:off
|
|
2
|
-
export type GeneratedEffectEndpoint = {
|
|
3
|
-
apiId: string;
|
|
4
|
-
group: string;
|
|
5
|
-
endpoint: string;
|
|
6
|
-
method: string;
|
|
7
|
-
routePath: string;
|
|
8
|
-
/** Per-endpoint operation contract hash (bff-core hash). */
|
|
9
|
-
schemaHash: string;
|
|
10
|
-
operationVersion: number;
|
|
11
|
-
};
|
|
12
|
-
|
|
13
|
-
export type GeneratedEffectBatchConfig = {
|
|
14
|
-
enabled: boolean;
|
|
15
|
-
endpoint: string;
|
|
16
|
-
flushIntervalMs: number;
|
|
17
|
-
maxBatchSize: number;
|
|
18
|
-
maxBatchBytes: number;
|
|
19
|
-
requestTimeoutMs: number;
|
|
20
|
-
allowedMethods: string[];
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
export type GeneratedEffectClientConfig = {
|
|
24
|
-
appNamespace: string;
|
|
25
|
-
/** Cross-project producer id; absent for same-project clients. */
|
|
26
|
-
requestId?: string;
|
|
27
|
-
port: number;
|
|
28
|
-
/** Resolve the port from process.env.PORT first (server bundles). */
|
|
29
|
-
useEnvPort?: boolean;
|
|
30
|
-
defaultOrigin: string;
|
|
31
|
-
httpMethodDecider?: string;
|
|
32
|
-
batch: GeneratedEffectBatchConfig;
|
|
33
|
-
};
|
|
34
|
-
|
|
35
|
-
export type EffectOperationDescriptor = {
|
|
36
|
-
appNamespace: string;
|
|
37
|
-
apiId: string;
|
|
38
|
-
group: string;
|
|
39
|
-
endpoint: string;
|
|
40
|
-
operationId: string;
|
|
41
|
-
routePath: string;
|
|
42
|
-
method: string;
|
|
43
|
-
operationVersion: number;
|
|
44
|
-
schemaHash: string;
|
|
45
|
-
version: number;
|
|
46
|
-
};
|
|
47
|
-
|
|
48
|
-
export type EffectClientOperation = (request?: unknown) => Promise<unknown>;
|
|
49
|
-
export type EffectClientGroup = Record<string, EffectClientOperation>;
|
|
50
|
-
export type EffectClient = Record<string, EffectClientGroup>;
|
|
51
|
-
export type EffectOperationManifest = Record<
|
|
52
|
-
string,
|
|
53
|
-
Record<string, EffectOperationDescriptor>
|
|
54
|
-
>;
|
|
55
|
-
|
|
56
|
-
export type EffectRequestContextInput = Record<string, unknown>;
|
|
57
|
-
|
|
58
|
-
export type EffectRequestContext = {
|
|
59
|
-
headers: Record<string, string>;
|
|
60
|
-
} & Record<string, unknown>;
|
|
61
|
-
|
|
62
|
-
/** Structural slice of `@modern-js/runtime-extensions/request-policy` the runtime relies on. */
|
|
63
|
-
export type EffectRequestRuntime = {
|
|
64
|
-
createRequest: (options: {
|
|
65
|
-
path: string;
|
|
66
|
-
method: string;
|
|
67
|
-
port: number | string;
|
|
68
|
-
operationContext: Record<string, unknown>;
|
|
69
|
-
httpMethodDecider: string;
|
|
70
|
-
requestId?: string;
|
|
71
|
-
}) => (...args: unknown[]) => Promise<unknown>;
|
|
72
|
-
configure?: (options: Record<string, unknown>) => void;
|
|
73
|
-
createRequestContextHeaders?: (
|
|
74
|
-
input: EffectRequestContextInput,
|
|
75
|
-
) => Record<string, string>;
|
|
76
|
-
};
|
|
77
|
-
|
|
78
|
-
export type GeneratedEffectClientModule = {
|
|
79
|
-
client: EffectClient;
|
|
80
|
-
operationManifest: EffectOperationManifest;
|
|
81
|
-
createEffectRequestContext: (
|
|
82
|
-
requestContext: EffectRequestContextInput,
|
|
83
|
-
) => EffectRequestContext;
|
|
84
|
-
};
|