@temporary-name/server 1.9.3-alpha.65222302f1b71807a849530b3fe0fa0326d3c1a2 → 1.9.3-alpha.6a70825f6d8c3dc99b87e4e5b778aea0fa007417
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/adapters/aws-lambda/index.d.mts +3 -3
- package/dist/adapters/aws-lambda/index.d.ts +3 -3
- package/dist/adapters/aws-lambda/index.mjs +5 -6
- package/dist/adapters/fetch/index.d.mts +3 -3
- package/dist/adapters/fetch/index.d.ts +3 -3
- package/dist/adapters/fetch/index.mjs +5 -6
- package/dist/adapters/node/index.d.mts +3 -3
- package/dist/adapters/node/index.d.ts +3 -3
- package/dist/adapters/node/index.mjs +5 -6
- package/dist/adapters/standard/index.d.mts +20 -31
- package/dist/adapters/standard/index.d.ts +20 -31
- package/dist/adapters/standard/index.mjs +5 -6
- package/dist/index.d.mts +69 -139
- package/dist/index.d.ts +69 -139
- package/dist/index.mjs +115 -294
- package/dist/openapi/index.d.mts +1 -1
- package/dist/openapi/index.d.ts +1 -1
- package/dist/openapi/index.mjs +60 -76
- package/dist/plugins/index.d.mts +2 -2
- package/dist/plugins/index.d.ts +2 -2
- package/dist/shared/{server.CQyYNJ1H.d.ts → server.BCcLYvdF.d.mts} +1 -2
- package/dist/shared/server.CHV9AQHl.mjs +412 -0
- package/dist/shared/{server.C1fnTLq0.d.mts → server.CdeqmULw.d.ts} +1 -2
- package/dist/shared/{server.BeuTpcmO.d.mts → server.DHezmW6C.d.mts} +2 -2
- package/dist/shared/server.DN9mVGfv.mjs +11 -0
- package/dist/shared/{server.DLsti1Pv.mjs → server.DWwaAM-a.mjs} +56 -94
- package/dist/shared/{server.SLLuK6_v.d.ts → server.Da-qLzdU.d.ts} +2 -2
- package/dist/shared/{server.BKSOrA6h.d.mts → server.DecvGKtb.d.mts} +125 -75
- package/dist/shared/{server.BKSOrA6h.d.ts → server.DecvGKtb.d.ts} +125 -75
- package/dist/shared/{server.BEHw7Eyx.mjs → server.JtIZ8YG7.mjs} +1 -11
- package/package.json +10 -9
- package/dist/shared/server.BKh8I1Ny.mjs +0 -239
package/dist/index.mjs
CHANGED
|
@@ -1,313 +1,115 @@
|
|
|
1
|
+
import { mergePrefix, mergeTags, ContractProcedure, mergeErrorMap, mergeMeta, mergeRoute, prefixRoute, initialSchemas, isContractProcedure, getContractRouter } from '@temporary-name/contract';
|
|
2
|
+
export { ValidationError, eventIterator, validateORPCError } from '@temporary-name/contract';
|
|
1
3
|
import { onError, resolveMaybeOptionalOptions } from '@temporary-name/shared';
|
|
2
4
|
export { AsyncIteratorClass, EventPublisher, ORPCError, asyncIteratorToStream as eventIteratorToStream, isDefinedError, onError, onFinish, onStart, onSuccess, safe, streamToAsyncIteratorClass as streamToEventIterator } from '@temporary-name/shared';
|
|
3
|
-
import {
|
|
4
|
-
export { ValidationError, eventIterator, type, validateORPCError } from '@temporary-name/contract';
|
|
5
|
-
import { c as createProcedureClient, i as isLazy, g as getLazyMeta, l as lazy, u as unlazy, a as gatingContext } from './shared/server.BKh8I1Ny.mjs';
|
|
6
|
-
export { L as LAZY_SYMBOL, b as createORPCErrorConstructorMap, m as mergeCurrentContext, d as middlewareOutputFn } from './shared/server.BKh8I1Ny.mjs';
|
|
5
|
+
import { SchemaClass, core, object, gatingContext } from '@temporary-name/zod';
|
|
7
6
|
export { getEventMeta, withEventMeta } from '@temporary-name/standard-server';
|
|
8
|
-
import '
|
|
9
|
-
import '
|
|
10
|
-
|
|
7
|
+
import { g as getDynamicParams } from './shared/server.DN9mVGfv.mjs';
|
|
8
|
+
import { P as Procedure, c as createProcedureClient, e as enhanceRouter, a as addMiddleware, s as setHiddenRouterContract, l as lazyInternal, g as getLazyMeta, u as unlazy, i as isProcedure, b as isLazy, d as getRouter } from './shared/server.CHV9AQHl.mjs';
|
|
9
|
+
export { L as LAZY_SYMBOL, p as createAccessibleLazyRouter, f as createORPCErrorConstructorMap, o as getHiddenRouterContract, k as isStartWithMiddlewares, h as lazy, m as mergeCurrentContext, n as mergeMiddlewares, j as middlewareOutputFn, r as resolveContractProcedures, t as traverseContractProcedures, q as unlazyRouter } from './shared/server.CHV9AQHl.mjs';
|
|
11
10
|
|
|
12
|
-
|
|
13
|
-
if (compare.length > middlewares.length) {
|
|
14
|
-
return false;
|
|
15
|
-
}
|
|
16
|
-
for (let i = 0; i < middlewares.length; i++) {
|
|
17
|
-
if (compare[i] === void 0) {
|
|
18
|
-
return true;
|
|
19
|
-
}
|
|
20
|
-
if (middlewares[i] !== compare[i]) {
|
|
21
|
-
return false;
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
return true;
|
|
25
|
-
}
|
|
26
|
-
function mergeMiddlewares(first, second, options) {
|
|
27
|
-
if (options.dedupeLeading && isStartWithMiddlewares(second, first)) {
|
|
28
|
-
return second;
|
|
29
|
-
}
|
|
30
|
-
return [...first, ...second];
|
|
31
|
-
}
|
|
32
|
-
function addMiddleware(middlewares, addition) {
|
|
33
|
-
return [...middlewares, addition];
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
function decorateMiddleware(middleware) {
|
|
37
|
-
const decorated = ((...args) => middleware(...args));
|
|
38
|
-
decorated.mapInput = (mapInput) => {
|
|
39
|
-
const mapped = decorateMiddleware(
|
|
40
|
-
(options, input, ...rest) => middleware(options, mapInput(input), ...rest)
|
|
41
|
-
);
|
|
42
|
-
return mapped;
|
|
43
|
-
};
|
|
44
|
-
decorated.concat = (concatMiddleware, mapInput) => {
|
|
45
|
-
const mapped = mapInput ? decorateMiddleware(concatMiddleware).mapInput(mapInput) : concatMiddleware;
|
|
46
|
-
const concatted = decorateMiddleware((options, input, output, ...rest) => {
|
|
47
|
-
const merged = middleware(
|
|
48
|
-
{
|
|
49
|
-
...options,
|
|
50
|
-
next: (...[nextOptions1]) => mapped(
|
|
51
|
-
{
|
|
52
|
-
...options,
|
|
53
|
-
context: { ...options.context, ...nextOptions1?.context },
|
|
54
|
-
next: (...[nextOptions2]) => options.next({ context: { ...nextOptions1?.context, ...nextOptions2?.context } })
|
|
55
|
-
},
|
|
56
|
-
input,
|
|
57
|
-
output,
|
|
58
|
-
...rest
|
|
59
|
-
)
|
|
60
|
-
},
|
|
61
|
-
input,
|
|
62
|
-
output,
|
|
63
|
-
...rest
|
|
64
|
-
);
|
|
65
|
-
return merged;
|
|
66
|
-
});
|
|
67
|
-
return concatted;
|
|
68
|
-
};
|
|
69
|
-
return decorated;
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
class Procedure {
|
|
11
|
+
class DecoratedProcedure extends Procedure {
|
|
73
12
|
/**
|
|
74
|
-
*
|
|
13
|
+
* Make this procedure callable (works like a function while still being a procedure).
|
|
14
|
+
*
|
|
15
|
+
* @see {@link https://orpc.unnoq.com/docs/client/server-side Server-side Client Docs}
|
|
75
16
|
*/
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
17
|
+
callable(...rest) {
|
|
18
|
+
const client = createProcedureClient(this, ...rest);
|
|
19
|
+
return new Proxy(client, {
|
|
20
|
+
get: (target, key) => {
|
|
21
|
+
return Reflect.has(this, key) ? Reflect.get(this, key) : Reflect.get(target, key);
|
|
22
|
+
},
|
|
23
|
+
has: (target, key) => {
|
|
24
|
+
return Reflect.has(this, key) || Reflect.has(target, key);
|
|
25
|
+
}
|
|
26
|
+
});
|
|
84
27
|
}
|
|
85
|
-
return isContractProcedure(item) && "middlewares" in item["~orpc"] && "inputValidationIndex" in item["~orpc"] && "outputValidationIndex" in item["~orpc"] && "handler" in item["~orpc"];
|
|
86
28
|
}
|
|
87
29
|
|
|
88
|
-
class
|
|
30
|
+
class ProcedureBuilder extends ContractProcedure {
|
|
31
|
+
z;
|
|
32
|
+
constructor(def) {
|
|
33
|
+
super(def);
|
|
34
|
+
this.z = new SchemaClass();
|
|
35
|
+
}
|
|
89
36
|
/**
|
|
90
|
-
* Adds type-safe custom errors.
|
|
91
|
-
* The provided errors are spared-merged with any existing errors.
|
|
37
|
+
* Adds type-safe custom errors to the contract.
|
|
38
|
+
* The provided errors are spared-merged with any existing errors in the contract.
|
|
92
39
|
*
|
|
93
40
|
* @see {@link https://orpc.unnoq.com/docs/error-handling#type%E2%80%90safe-error-handling Type-Safe Error Handling Docs}
|
|
94
41
|
*/
|
|
95
42
|
errors(errors) {
|
|
96
|
-
return new
|
|
43
|
+
return new ProcedureBuilder({
|
|
97
44
|
...this["~orpc"],
|
|
98
45
|
errorMap: mergeErrorMap(this["~orpc"].errorMap, errors)
|
|
99
46
|
});
|
|
100
47
|
}
|
|
101
48
|
/**
|
|
102
|
-
* Sets or updates the metadata.
|
|
103
|
-
* The provided metadata is spared-merged with any existing metadata.
|
|
49
|
+
* Sets or updates the metadata for the contract.
|
|
50
|
+
* The provided metadata is spared-merged with any existing metadata in the contract.
|
|
104
51
|
*
|
|
105
52
|
* @see {@link https://orpc.unnoq.com/docs/metadata Metadata Docs}
|
|
106
53
|
*/
|
|
107
54
|
meta(meta) {
|
|
108
|
-
return new
|
|
55
|
+
return new ProcedureBuilder({
|
|
109
56
|
...this["~orpc"],
|
|
110
57
|
meta: mergeMeta(this["~orpc"].meta, meta)
|
|
111
58
|
});
|
|
112
59
|
}
|
|
60
|
+
endpoint(endpoint, schema) {
|
|
61
|
+
const [method, path] = endpoint.split(" ", 2);
|
|
62
|
+
const pathParamNames = getDynamicParams(path)?.map((p) => p.name) ?? [];
|
|
63
|
+
if (schema && !(schema instanceof core.$ZodObject)) {
|
|
64
|
+
throw new Error(`Path schema for endpoint "${endpoint}" must be a ZodObject schema.`);
|
|
65
|
+
}
|
|
66
|
+
const schemaKeys = schema ? Object.keys(schema._zod.def.shape) : [];
|
|
67
|
+
if (pathParamNames.length !== schemaKeys.length || !pathParamNames.every((name) => schemaKeys.includes(name))) {
|
|
68
|
+
throw new Error(`Path schema keys do not match dynamic parameters in endpoint "${endpoint}".`);
|
|
69
|
+
}
|
|
70
|
+
const { prefix } = this["~orpc"];
|
|
71
|
+
const route = { method, path };
|
|
72
|
+
return new ProcedureBuilder({
|
|
73
|
+
...this["~orpc"],
|
|
74
|
+
route: mergeRoute(this["~orpc"].route, prefix ? prefixRoute(route, prefix) : route),
|
|
75
|
+
schemas: {
|
|
76
|
+
...this["~orpc"].schemas,
|
|
77
|
+
pathSchema: schema instanceof core.$ZodType ? schema : object(schema ?? {})
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
}
|
|
113
81
|
/**
|
|
114
|
-
* Sets or updates the route definition.
|
|
115
|
-
* The provided route is spared-merged with any existing route.
|
|
82
|
+
* Sets or updates the route definition for the contract.
|
|
83
|
+
* The provided route is spared-merged with any existing route in the contract.
|
|
116
84
|
* This option is typically relevant when integrating with OpenAPI.
|
|
117
85
|
*
|
|
118
86
|
* @see {@link https://orpc.unnoq.com/docs/openapi/routing OpenAPI Routing Docs}
|
|
119
87
|
* @see {@link https://orpc.unnoq.com/docs/openapi/input-output-structure OpenAPI Input/Output Structure Docs}
|
|
120
88
|
*/
|
|
121
|
-
|
|
122
|
-
|
|
89
|
+
endpointOpts(route) {
|
|
90
|
+
const { prefix } = this["~orpc"];
|
|
91
|
+
return new ProcedureBuilder({
|
|
123
92
|
...this["~orpc"],
|
|
124
|
-
route: mergeRoute(this["~orpc"].route, route)
|
|
93
|
+
route: mergeRoute(this["~orpc"].route, prefix ? prefixRoute(route, prefix) : route)
|
|
125
94
|
});
|
|
126
95
|
}
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
return new DecoratedProcedure({
|
|
96
|
+
query(schema) {
|
|
97
|
+
return new ProcedureBuilder({
|
|
130
98
|
...this["~orpc"],
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
/**
|
|
135
|
-
* Make this procedure callable (works like a function while still being a procedure).
|
|
136
|
-
*
|
|
137
|
-
* @see {@link https://orpc.unnoq.com/docs/client/server-side Server-side Client Docs}
|
|
138
|
-
*/
|
|
139
|
-
callable(...rest) {
|
|
140
|
-
const client = createProcedureClient(this, ...rest);
|
|
141
|
-
return new Proxy(client, {
|
|
142
|
-
get: (target, key) => {
|
|
143
|
-
return Reflect.has(this, key) ? Reflect.get(this, key) : Reflect.get(target, key);
|
|
144
|
-
},
|
|
145
|
-
has: (target, key) => {
|
|
146
|
-
return Reflect.has(this, key) || Reflect.has(target, key);
|
|
147
|
-
}
|
|
148
|
-
});
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
const HIDDEN_ROUTER_CONTRACT_SYMBOL = Symbol("ORPC_HIDDEN_ROUTER_CONTRACT");
|
|
153
|
-
function setHiddenRouterContract(router, contract) {
|
|
154
|
-
return new Proxy(router, {
|
|
155
|
-
get(target, key) {
|
|
156
|
-
if (key === HIDDEN_ROUTER_CONTRACT_SYMBOL) {
|
|
157
|
-
return contract;
|
|
158
|
-
}
|
|
159
|
-
return Reflect.get(target, key);
|
|
160
|
-
}
|
|
161
|
-
});
|
|
162
|
-
}
|
|
163
|
-
function getHiddenRouterContract(router) {
|
|
164
|
-
return router[HIDDEN_ROUTER_CONTRACT_SYMBOL];
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
function getRouter(router, path) {
|
|
168
|
-
let current = router;
|
|
169
|
-
for (let i = 0; i < path.length; i++) {
|
|
170
|
-
const segment = path[i];
|
|
171
|
-
if (!current) {
|
|
172
|
-
return void 0;
|
|
173
|
-
}
|
|
174
|
-
if (isProcedure(current)) {
|
|
175
|
-
return void 0;
|
|
176
|
-
}
|
|
177
|
-
if (!isLazy(current)) {
|
|
178
|
-
current = current[segment];
|
|
179
|
-
continue;
|
|
180
|
-
}
|
|
181
|
-
const lazied = current;
|
|
182
|
-
const rest = path.slice(i);
|
|
183
|
-
return lazy(async () => {
|
|
184
|
-
const unwrapped = await unlazy(lazied);
|
|
185
|
-
const next = getRouter(unwrapped.default, rest);
|
|
186
|
-
return unlazy(next);
|
|
187
|
-
}, getLazyMeta(lazied));
|
|
188
|
-
}
|
|
189
|
-
return current;
|
|
190
|
-
}
|
|
191
|
-
function createAccessibleLazyRouter(lazied) {
|
|
192
|
-
const recursive = new Proxy(lazied, {
|
|
193
|
-
get(target, key) {
|
|
194
|
-
if (typeof key !== "string") {
|
|
195
|
-
return Reflect.get(target, key);
|
|
196
|
-
}
|
|
197
|
-
const next = getRouter(lazied, [key]);
|
|
198
|
-
return createAccessibleLazyRouter(next);
|
|
199
|
-
}
|
|
200
|
-
});
|
|
201
|
-
return recursive;
|
|
202
|
-
}
|
|
203
|
-
function enhanceRouter(router, options) {
|
|
204
|
-
if (isLazy(router)) {
|
|
205
|
-
const laziedMeta = getLazyMeta(router);
|
|
206
|
-
const enhancedPrefix = laziedMeta?.prefix ? mergePrefix(options.prefix, laziedMeta?.prefix) : options.prefix;
|
|
207
|
-
const enhanced2 = lazy(
|
|
208
|
-
async () => {
|
|
209
|
-
const { default: unlaziedRouter } = await unlazy(router);
|
|
210
|
-
const enhanced3 = enhanceRouter(unlaziedRouter, options);
|
|
211
|
-
return unlazy(enhanced3);
|
|
99
|
+
schemas: {
|
|
100
|
+
...this["~orpc"].schemas,
|
|
101
|
+
querySchema: schema instanceof core.$ZodType ? schema : object(schema)
|
|
212
102
|
},
|
|
213
|
-
|
|
214
|
-
...laziedMeta,
|
|
215
|
-
prefix: enhancedPrefix
|
|
216
|
-
}
|
|
217
|
-
);
|
|
218
|
-
const accessible = createAccessibleLazyRouter(enhanced2);
|
|
219
|
-
return accessible;
|
|
220
|
-
}
|
|
221
|
-
if (isProcedure(router)) {
|
|
222
|
-
const newMiddlewares = mergeMiddlewares(options.middlewares, router["~orpc"].middlewares, {
|
|
223
|
-
dedupeLeading: options.dedupeLeadingMiddlewares
|
|
224
|
-
});
|
|
225
|
-
const newMiddlewareAdded = newMiddlewares.length - router["~orpc"].middlewares.length;
|
|
226
|
-
const enhanced2 = new Procedure({
|
|
227
|
-
...router["~orpc"],
|
|
228
|
-
route: enhanceRoute(router["~orpc"].route, options),
|
|
229
|
-
errorMap: mergeErrorMap(options.errorMap, router["~orpc"].errorMap),
|
|
230
|
-
middlewares: newMiddlewares,
|
|
231
|
-
inputValidationIndex: router["~orpc"].inputValidationIndex + newMiddlewareAdded,
|
|
232
|
-
outputValidationIndex: router["~orpc"].outputValidationIndex + newMiddlewareAdded
|
|
233
|
-
});
|
|
234
|
-
return enhanced2;
|
|
235
|
-
}
|
|
236
|
-
const enhanced = {};
|
|
237
|
-
for (const key in router) {
|
|
238
|
-
enhanced[key] = enhanceRouter(router[key], options);
|
|
239
|
-
}
|
|
240
|
-
return enhanced;
|
|
241
|
-
}
|
|
242
|
-
function traverseContractProcedures(options, callback, lazyOptions = []) {
|
|
243
|
-
let currentRouter = options.router;
|
|
244
|
-
const hiddenContract = getHiddenRouterContract(options.router);
|
|
245
|
-
if (hiddenContract !== void 0) {
|
|
246
|
-
currentRouter = hiddenContract;
|
|
247
|
-
}
|
|
248
|
-
if (isLazy(currentRouter)) {
|
|
249
|
-
lazyOptions.push({
|
|
250
|
-
router: currentRouter,
|
|
251
|
-
path: options.path
|
|
252
|
-
});
|
|
253
|
-
} else if (isContractProcedure(currentRouter)) {
|
|
254
|
-
callback({
|
|
255
|
-
contract: currentRouter,
|
|
256
|
-
path: options.path
|
|
103
|
+
inputValidationIndex: this["~orpc"].middlewares.length
|
|
257
104
|
});
|
|
258
|
-
} else {
|
|
259
|
-
for (const key in currentRouter) {
|
|
260
|
-
traverseContractProcedures(
|
|
261
|
-
{
|
|
262
|
-
router: currentRouter[key],
|
|
263
|
-
path: [...options.path, key]
|
|
264
|
-
},
|
|
265
|
-
callback,
|
|
266
|
-
lazyOptions
|
|
267
|
-
);
|
|
268
|
-
}
|
|
269
|
-
}
|
|
270
|
-
return lazyOptions;
|
|
271
|
-
}
|
|
272
|
-
async function resolveContractProcedures(options, callback) {
|
|
273
|
-
const pending = [options];
|
|
274
|
-
for (const options2 of pending) {
|
|
275
|
-
const lazyOptions = traverseContractProcedures(options2, callback);
|
|
276
|
-
for (const options3 of lazyOptions) {
|
|
277
|
-
const { default: router } = await unlazy(options3.router);
|
|
278
|
-
pending.push({
|
|
279
|
-
router,
|
|
280
|
-
path: options3.path
|
|
281
|
-
});
|
|
282
|
-
}
|
|
283
105
|
}
|
|
284
|
-
|
|
285
|
-
async function unlazyRouter(router) {
|
|
286
|
-
if (isProcedure(router)) {
|
|
287
|
-
return router;
|
|
288
|
-
}
|
|
289
|
-
const unlazied = {};
|
|
290
|
-
for (const key in router) {
|
|
291
|
-
const item = router[key];
|
|
292
|
-
const { default: unlaziedRouter } = await unlazy(item);
|
|
293
|
-
unlazied[key] = await unlazyRouter(unlaziedRouter);
|
|
294
|
-
}
|
|
295
|
-
return unlazied;
|
|
296
|
-
}
|
|
297
|
-
|
|
298
|
-
class ProcedureBuilder extends ContractProcedureBuilder {
|
|
299
|
-
constructor(def) {
|
|
300
|
-
super(def);
|
|
301
|
-
}
|
|
302
|
-
/**
|
|
303
|
-
* Defines the input validation schema.
|
|
304
|
-
*
|
|
305
|
-
* @see {@link https://orpc.unnoq.com/docs/procedure#input-output-validation Input Validation Docs}
|
|
306
|
-
*/
|
|
307
|
-
input(schema) {
|
|
106
|
+
body(schema) {
|
|
308
107
|
return new ProcedureBuilder({
|
|
309
108
|
...this["~orpc"],
|
|
310
|
-
|
|
109
|
+
schemas: {
|
|
110
|
+
...this["~orpc"].schemas,
|
|
111
|
+
bodySchema: schema instanceof core.$ZodType ? schema : object(schema)
|
|
112
|
+
},
|
|
311
113
|
inputValidationIndex: this["~orpc"].middlewares.length
|
|
312
114
|
});
|
|
313
115
|
}
|
|
@@ -319,7 +121,10 @@ class ProcedureBuilder extends ContractProcedureBuilder {
|
|
|
319
121
|
output(schema) {
|
|
320
122
|
return new ProcedureBuilder({
|
|
321
123
|
...this["~orpc"],
|
|
322
|
-
|
|
124
|
+
schemas: {
|
|
125
|
+
...this["~orpc"].schemas,
|
|
126
|
+
outputSchema: schema instanceof core.$ZodType ? schema : object(schema)
|
|
127
|
+
},
|
|
323
128
|
outputValidationIndex: this["~orpc"].middlewares.length
|
|
324
129
|
});
|
|
325
130
|
}
|
|
@@ -391,15 +196,42 @@ class BuilderWithMiddlewares extends ProcedureBuilder {
|
|
|
391
196
|
router(router) {
|
|
392
197
|
return enhanceRouter(router, this["~orpc"]);
|
|
393
198
|
}
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
function decorateMiddleware(middleware) {
|
|
202
|
+
const decorated = ((...args) => middleware(...args));
|
|
203
|
+
decorated.mapInput = (mapInput) => {
|
|
204
|
+
const mapped = decorateMiddleware(
|
|
205
|
+
(options, input, ...rest) => middleware(options, mapInput(input), ...rest)
|
|
206
|
+
);
|
|
207
|
+
return mapped;
|
|
208
|
+
};
|
|
209
|
+
decorated.concat = (concatMiddleware, mapInput) => {
|
|
210
|
+
const mapped = mapInput ? decorateMiddleware(concatMiddleware).mapInput(mapInput) : concatMiddleware;
|
|
211
|
+
const concatted = decorateMiddleware((options, input, output, ...rest) => {
|
|
212
|
+
const merged = middleware(
|
|
213
|
+
{
|
|
214
|
+
...options,
|
|
215
|
+
next: (...[nextOptions1]) => mapped(
|
|
216
|
+
{
|
|
217
|
+
...options,
|
|
218
|
+
context: { ...options.context, ...nextOptions1?.context },
|
|
219
|
+
next: (...[nextOptions2]) => options.next({ context: { ...nextOptions1?.context, ...nextOptions2?.context } })
|
|
220
|
+
},
|
|
221
|
+
input,
|
|
222
|
+
output,
|
|
223
|
+
...rest
|
|
224
|
+
)
|
|
225
|
+
},
|
|
226
|
+
input,
|
|
227
|
+
output,
|
|
228
|
+
...rest
|
|
229
|
+
);
|
|
230
|
+
return merged;
|
|
231
|
+
});
|
|
232
|
+
return concatted;
|
|
233
|
+
};
|
|
234
|
+
return decorated;
|
|
403
235
|
}
|
|
404
236
|
|
|
405
237
|
class Builder extends BuilderWithMiddlewares {
|
|
@@ -421,22 +253,22 @@ class Builder extends BuilderWithMiddlewares {
|
|
|
421
253
|
}
|
|
422
254
|
}
|
|
423
255
|
function createApiBuilder(opts = {}) {
|
|
424
|
-
|
|
256
|
+
return new Builder({
|
|
425
257
|
route: {},
|
|
426
258
|
meta: opts.meta ?? {},
|
|
427
259
|
errorMap: {},
|
|
428
260
|
inputValidationIndex: 0,
|
|
429
261
|
outputValidationIndex: 0,
|
|
430
262
|
middlewares: [
|
|
431
|
-
onError((error,
|
|
263
|
+
onError((error, _options) => {
|
|
432
264
|
console.dir(error, { depth: null });
|
|
433
265
|
})
|
|
434
266
|
],
|
|
267
|
+
schemas: initialSchemas,
|
|
435
268
|
// NB: this is a relic from orpc -- I'm not convinced there's a need for this (or if there is, that it's
|
|
436
269
|
// the best solution). For now I've removed the interface to configure it externally.
|
|
437
270
|
dedupeLeadingMiddlewares: true
|
|
438
271
|
});
|
|
439
|
-
return base;
|
|
440
272
|
}
|
|
441
273
|
const os = createApiBuilder();
|
|
442
274
|
|
|
@@ -474,17 +306,6 @@ function implementerInternal(contract, middlewares) {
|
|
|
474
306
|
});
|
|
475
307
|
return setHiddenRouterContract(adapted, contract);
|
|
476
308
|
};
|
|
477
|
-
} else if (key === "lazyRoute") {
|
|
478
|
-
method = (loader) => {
|
|
479
|
-
const adapted = enhanceRouter(lazy(loader), {
|
|
480
|
-
middlewares,
|
|
481
|
-
errorMap: {},
|
|
482
|
-
prefix: void 0,
|
|
483
|
-
tags: void 0,
|
|
484
|
-
dedupeLeadingMiddlewares: true
|
|
485
|
-
});
|
|
486
|
-
return setHiddenRouterContract(adapted, contract);
|
|
487
|
-
};
|
|
488
309
|
}
|
|
489
310
|
const next = getContractRouter(target, [key]);
|
|
490
311
|
if (!next) {
|
|
@@ -526,7 +347,7 @@ function implement(contract) {
|
|
|
526
347
|
}
|
|
527
348
|
|
|
528
349
|
function createAssertedLazyProcedure(lazied) {
|
|
529
|
-
const lazyProcedure =
|
|
350
|
+
const lazyProcedure = lazyInternal(async () => {
|
|
530
351
|
const { default: maybeProcedure } = await unlazy(lazied);
|
|
531
352
|
if (!isProcedure(maybeProcedure)) {
|
|
532
353
|
throw new Error(`
|
|
@@ -577,4 +398,4 @@ function createRouterClient(router, ...rest) {
|
|
|
577
398
|
return recursive;
|
|
578
399
|
}
|
|
579
400
|
|
|
580
|
-
export { Builder, BuilderWithMiddlewares, DecoratedProcedure, Procedure, ProcedureBuilder, addMiddleware, call,
|
|
401
|
+
export { Builder, BuilderWithMiddlewares, DecoratedProcedure, Procedure, ProcedureBuilder, addMiddleware, call, createApiBuilder, createAssertedLazyProcedure, createContractedProcedure, createProcedureClient, createRouterClient, decorateMiddleware, enhanceRouter, getLazyMeta, getRouter, implement, implementerInternal, isLazy, isProcedure, lazyInternal, os, setHiddenRouterContract, unlazy };
|
package/dist/openapi/index.d.mts
CHANGED
|
@@ -55,7 +55,7 @@ interface SchemaConvertOptions {
|
|
|
55
55
|
minStructureDepthForRef?: number;
|
|
56
56
|
}
|
|
57
57
|
interface SchemaConverter {
|
|
58
|
-
convert(
|
|
58
|
+
convert(schemas: AnySchema | undefined, options: SchemaConvertOptions): Promisable<[required: boolean, jsonSchema: JSONSchema]>;
|
|
59
59
|
}
|
|
60
60
|
interface ConditionalSchemaConverter extends SchemaConverter {
|
|
61
61
|
condition(schema: AnySchema | undefined, options: SchemaConvertOptions): Promisable<boolean>;
|
package/dist/openapi/index.d.ts
CHANGED
|
@@ -55,7 +55,7 @@ interface SchemaConvertOptions {
|
|
|
55
55
|
minStructureDepthForRef?: number;
|
|
56
56
|
}
|
|
57
57
|
interface SchemaConverter {
|
|
58
|
-
convert(
|
|
58
|
+
convert(schemas: AnySchema | undefined, options: SchemaConvertOptions): Promisable<[required: boolean, jsonSchema: JSONSchema]>;
|
|
59
59
|
}
|
|
60
60
|
interface ConditionalSchemaConverter extends SchemaConverter {
|
|
61
61
|
condition(schema: AnySchema | undefined, options: SchemaConvertOptions): Promisable<boolean>;
|