@temporary-name/server 1.9.3-alpha.afd18ec2afa743b08cf1b5c2eb6252ded18a1f43 → 1.9.3-alpha.bb3867758271e7fcf8c191f9693365d655697e7f
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 -4
- package/dist/adapters/aws-lambda/index.d.ts +3 -4
- package/dist/adapters/aws-lambda/index.mjs +5 -7
- package/dist/adapters/fetch/index.d.mts +3 -4
- package/dist/adapters/fetch/index.d.ts +3 -4
- package/dist/adapters/fetch/index.mjs +5 -7
- package/dist/adapters/node/index.d.mts +3 -4
- package/dist/adapters/node/index.d.ts +3 -4
- package/dist/adapters/node/index.mjs +5 -7
- package/dist/adapters/standard/index.d.mts +20 -78
- package/dist/adapters/standard/index.d.ts +20 -78
- package/dist/adapters/standard/index.mjs +5 -7
- package/dist/index.d.mts +69 -339
- package/dist/index.d.ts +69 -339
- package/dist/index.mjs +132 -357
- package/dist/openapi/index.d.mts +1 -2
- package/dist/openapi/index.d.ts +1 -2
- package/dist/openapi/index.mjs +63 -88
- package/dist/plugins/index.d.mts +4 -80
- package/dist/plugins/index.d.ts +4 -80
- package/dist/plugins/index.mjs +17 -189
- package/dist/shared/{server.BeuTpcmO.d.mts → server.7aL9gcoU.d.mts} +2 -2
- package/dist/shared/server.BL2R5jcp.d.mts +228 -0
- package/dist/shared/server.BL2R5jcp.d.ts +228 -0
- package/dist/shared/server.C61o1Zch.mjs +413 -0
- package/dist/shared/{server.CQyYNJ1H.d.ts → server.D6Qs_UcF.d.mts} +2 -4
- package/dist/shared/{server.SLLuK6_v.d.ts → server.DFptr1Nz.d.ts} +2 -2
- package/dist/shared/{server.C1fnTLq0.d.mts → server.DpoO_ER_.d.ts} +2 -4
- package/dist/shared/{server._YqJjI50.mjs → server.DwbIdsnK.mjs} +58 -101
- package/dist/shared/server.JtIZ8YG7.mjs +237 -0
- package/package.json +10 -9
- package/dist/shared/server.BKSOrA6h.d.mts +0 -192
- package/dist/shared/server.BKSOrA6h.d.ts +0 -192
- package/dist/shared/server.BKh8I1Ny.mjs +0 -239
- package/dist/shared/server.DhdDYN-Z.mjs +0 -261
package/dist/index.mjs
CHANGED
|
@@ -1,334 +1,122 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export { ValidationError, eventIterator,
|
|
1
|
+
import { mergePrefix, mergeTags, ContractProcedure, mergeErrorMap, mergeMeta, parseEndpointDefinition, mergeRoute, prefixRoute, initialSchemas, isContractProcedure, getContractRouter } from '@temporary-name/contract';
|
|
2
|
+
export { ValidationError, eventIterator, validateORPCError } from '@temporary-name/contract';
|
|
3
3
|
import { onError, resolveMaybeOptionalOptions } from '@temporary-name/shared';
|
|
4
4
|
export { AsyncIteratorClass, EventPublisher, ORPCError, asyncIteratorToStream as eventIteratorToStream, isDefinedError, onError, onFinish, onStart, onSuccess, safe, streamToAsyncIteratorClass as streamToEventIterator } from '@temporary-name/shared';
|
|
5
|
-
import {
|
|
6
|
-
|
|
5
|
+
import { SchemaClass, object, core, gatingContext } from '@temporary-name/zod';
|
|
6
|
+
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.C61o1Zch.mjs';
|
|
7
|
+
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.C61o1Zch.mjs';
|
|
7
8
|
export { getEventMeta, withEventMeta } from '@temporary-name/standard-server';
|
|
8
|
-
import 'node:async_hooks';
|
|
9
|
-
import 'zod';
|
|
10
|
-
import 'zod/v4/core';
|
|
11
9
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
{
|
|
28
|
-
...options,
|
|
29
|
-
context: { ...options.context, ...nextOptions1?.context },
|
|
30
|
-
next: (...[nextOptions2]) => options.next({ context: { ...nextOptions1?.context, ...nextOptions2?.context } })
|
|
31
|
-
},
|
|
32
|
-
input,
|
|
33
|
-
output,
|
|
34
|
-
...rest
|
|
35
|
-
)
|
|
36
|
-
},
|
|
37
|
-
input,
|
|
38
|
-
output,
|
|
39
|
-
...rest
|
|
40
|
-
);
|
|
41
|
-
return merged;
|
|
10
|
+
class DecoratedProcedure extends Procedure {
|
|
11
|
+
/**
|
|
12
|
+
* Make this procedure callable (works like a function while still being a procedure).
|
|
13
|
+
*
|
|
14
|
+
* @see {@link https://orpc.unnoq.com/docs/client/server-side Server-side Client Docs}
|
|
15
|
+
*/
|
|
16
|
+
callable(...rest) {
|
|
17
|
+
const client = createProcedureClient(this, ...rest);
|
|
18
|
+
return new Proxy(client, {
|
|
19
|
+
get: (target, key) => {
|
|
20
|
+
return Reflect.has(this, key) ? Reflect.get(this, key) : Reflect.get(target, key);
|
|
21
|
+
},
|
|
22
|
+
has: (target, key) => {
|
|
23
|
+
return Reflect.has(this, key) || Reflect.has(target, key);
|
|
24
|
+
}
|
|
42
25
|
});
|
|
43
|
-
return concatted;
|
|
44
|
-
};
|
|
45
|
-
return decorated;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
function isStartWithMiddlewares(middlewares, compare) {
|
|
49
|
-
if (compare.length > middlewares.length) {
|
|
50
|
-
return false;
|
|
51
|
-
}
|
|
52
|
-
for (let i = 0; i < middlewares.length; i++) {
|
|
53
|
-
if (compare[i] === void 0) {
|
|
54
|
-
return true;
|
|
55
|
-
}
|
|
56
|
-
if (middlewares[i] !== compare[i]) {
|
|
57
|
-
return false;
|
|
58
|
-
}
|
|
59
26
|
}
|
|
60
|
-
return true;
|
|
61
|
-
}
|
|
62
|
-
function mergeMiddlewares(first, second, options) {
|
|
63
|
-
if (options.dedupeLeading && isStartWithMiddlewares(second, first)) {
|
|
64
|
-
return second;
|
|
65
|
-
}
|
|
66
|
-
return [...first, ...second];
|
|
67
|
-
}
|
|
68
|
-
function addMiddleware(middlewares, addition) {
|
|
69
|
-
return [...middlewares, addition];
|
|
70
27
|
}
|
|
71
28
|
|
|
72
|
-
class
|
|
73
|
-
|
|
74
|
-
* This property holds the defined options.
|
|
75
|
-
*/
|
|
76
|
-
"~orpc";
|
|
29
|
+
class ProcedureBuilder extends ContractProcedure {
|
|
30
|
+
z;
|
|
77
31
|
constructor(def) {
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
}
|
|
81
|
-
function isProcedure(item) {
|
|
82
|
-
if (item instanceof Procedure) {
|
|
83
|
-
return true;
|
|
32
|
+
super(def);
|
|
33
|
+
this.z = new SchemaClass();
|
|
84
34
|
}
|
|
85
|
-
return isContractProcedure(item) && "middlewares" in item["~orpc"] && "inputValidationIndex" in item["~orpc"] && "outputValidationIndex" in item["~orpc"] && "handler" in item["~orpc"];
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
class DecoratedProcedure extends Procedure {
|
|
89
35
|
/**
|
|
90
|
-
* Adds type-safe custom errors.
|
|
91
|
-
* The provided errors are spared-merged with any existing errors.
|
|
36
|
+
* Adds type-safe custom errors to the contract.
|
|
37
|
+
* The provided errors are spared-merged with any existing errors in the contract.
|
|
92
38
|
*
|
|
93
39
|
* @see {@link https://orpc.unnoq.com/docs/error-handling#type%E2%80%90safe-error-handling Type-Safe Error Handling Docs}
|
|
94
40
|
*/
|
|
95
41
|
errors(errors) {
|
|
96
|
-
return new
|
|
42
|
+
return new ProcedureBuilder({
|
|
97
43
|
...this["~orpc"],
|
|
98
44
|
errorMap: mergeErrorMap(this["~orpc"].errorMap, errors)
|
|
99
45
|
});
|
|
100
46
|
}
|
|
101
47
|
/**
|
|
102
|
-
* Sets or updates the metadata.
|
|
103
|
-
* The provided metadata is spared-merged with any existing metadata.
|
|
48
|
+
* Sets or updates the metadata for the contract.
|
|
49
|
+
* The provided metadata is spared-merged with any existing metadata in the contract.
|
|
104
50
|
*
|
|
105
51
|
* @see {@link https://orpc.unnoq.com/docs/metadata Metadata Docs}
|
|
106
52
|
*/
|
|
107
53
|
meta(meta) {
|
|
108
|
-
return new
|
|
54
|
+
return new ProcedureBuilder({
|
|
109
55
|
...this["~orpc"],
|
|
110
56
|
meta: mergeMeta(this["~orpc"].meta, meta)
|
|
111
57
|
});
|
|
112
58
|
}
|
|
59
|
+
endpoint(stringsOrEndpoint, ...values) {
|
|
60
|
+
const { method, path, pathSchema } = parseEndpointDefinition(stringsOrEndpoint, values);
|
|
61
|
+
const { prefix } = this["~orpc"];
|
|
62
|
+
const route = { method, path };
|
|
63
|
+
return new ProcedureBuilder({
|
|
64
|
+
...this["~orpc"],
|
|
65
|
+
route: mergeRoute(this["~orpc"].route, prefix ? prefixRoute(route, prefix) : route),
|
|
66
|
+
schemas: {
|
|
67
|
+
...this["~orpc"].schemas,
|
|
68
|
+
pathSchema
|
|
69
|
+
}
|
|
70
|
+
});
|
|
71
|
+
}
|
|
113
72
|
/**
|
|
114
|
-
* Sets or updates the route definition.
|
|
115
|
-
* The provided route is spared-merged with any existing route.
|
|
73
|
+
* Sets or updates the route definition for the contract.
|
|
74
|
+
* The provided route is spared-merged with any existing route in the contract.
|
|
116
75
|
* This option is typically relevant when integrating with OpenAPI.
|
|
117
76
|
*
|
|
118
77
|
* @see {@link https://orpc.unnoq.com/docs/openapi/routing OpenAPI Routing Docs}
|
|
119
78
|
* @see {@link https://orpc.unnoq.com/docs/openapi/input-output-structure OpenAPI Input/Output Structure Docs}
|
|
120
79
|
*/
|
|
121
|
-
|
|
122
|
-
|
|
80
|
+
endpointOpts(route) {
|
|
81
|
+
const { prefix } = this["~orpc"];
|
|
82
|
+
return new ProcedureBuilder({
|
|
123
83
|
...this["~orpc"],
|
|
124
|
-
route: mergeRoute(this["~orpc"].route, route)
|
|
84
|
+
route: mergeRoute(this["~orpc"].route, prefix ? prefixRoute(route, prefix) : route)
|
|
125
85
|
});
|
|
126
86
|
}
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
return new DecoratedProcedure({
|
|
87
|
+
query(schema) {
|
|
88
|
+
return new ProcedureBuilder({
|
|
130
89
|
...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);
|
|
90
|
+
schemas: {
|
|
91
|
+
...this["~orpc"].schemas,
|
|
92
|
+
querySchema: schema instanceof core.$ZodType ? schema : object(schema)
|
|
144
93
|
},
|
|
145
|
-
|
|
146
|
-
return Reflect.has(this, key) || Reflect.has(target, key);
|
|
147
|
-
}
|
|
94
|
+
inputValidationIndex: this["~orpc"].middlewares.length
|
|
148
95
|
});
|
|
149
96
|
}
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
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);
|
|
97
|
+
body(schema) {
|
|
98
|
+
return new ProcedureBuilder({
|
|
99
|
+
...this["~orpc"],
|
|
100
|
+
schemas: {
|
|
101
|
+
...this["~orpc"].schemas,
|
|
102
|
+
bodySchema: schema instanceof core.$ZodType ? schema : object(schema)
|
|
212
103
|
},
|
|
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
|
|
104
|
+
inputValidationIndex: this["~orpc"].middlewares.length
|
|
257
105
|
});
|
|
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
106
|
}
|
|
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 Builder {
|
|
299
107
|
/**
|
|
300
|
-
*
|
|
301
|
-
*/
|
|
302
|
-
"~orpc";
|
|
303
|
-
constructor(def) {
|
|
304
|
-
this["~orpc"] = def;
|
|
305
|
-
}
|
|
306
|
-
/**
|
|
307
|
-
* Set or override the initial context.
|
|
308
|
-
*
|
|
309
|
-
* @see {@link https://orpc.unnoq.com/docs/context Context Docs}
|
|
310
|
-
*/
|
|
311
|
-
$context() {
|
|
312
|
-
return this;
|
|
313
|
-
}
|
|
314
|
-
/**
|
|
315
|
-
* Creates a middleware.
|
|
316
|
-
*
|
|
317
|
-
* @see {@link https://orpc.unnoq.com/docs/middleware Middleware Docs}
|
|
318
|
-
*/
|
|
319
|
-
middleware(middleware) {
|
|
320
|
-
return decorateMiddleware(middleware);
|
|
321
|
-
}
|
|
322
|
-
/**
|
|
323
|
-
* Adds type-safe custom errors.
|
|
324
|
-
* The provided errors are spared-merged with any existing errors.
|
|
108
|
+
* Defines the output validation schema.
|
|
325
109
|
*
|
|
326
|
-
* @see {@link https://orpc.unnoq.com/docs/
|
|
110
|
+
* @see {@link https://orpc.unnoq.com/docs/procedure#input-output-validation Output Validation Docs}
|
|
327
111
|
*/
|
|
328
|
-
|
|
329
|
-
return new
|
|
112
|
+
output(schema) {
|
|
113
|
+
return new ProcedureBuilder({
|
|
330
114
|
...this["~orpc"],
|
|
331
|
-
|
|
115
|
+
schemas: {
|
|
116
|
+
...this["~orpc"].schemas,
|
|
117
|
+
outputSchema: schema instanceof core.$ZodType ? schema : object(schema)
|
|
118
|
+
},
|
|
119
|
+
outputValidationIndex: this["~orpc"].middlewares.length
|
|
332
120
|
});
|
|
333
121
|
}
|
|
334
122
|
/**
|
|
@@ -339,7 +127,7 @@ class Builder {
|
|
|
339
127
|
* @see {@link https://orpc.unnoq.com/docs/middleware Middleware Docs}
|
|
340
128
|
*/
|
|
341
129
|
use(middleware) {
|
|
342
|
-
return new
|
|
130
|
+
return new this.constructor({
|
|
343
131
|
...this["~orpc"],
|
|
344
132
|
middlewares: addMiddleware(this["~orpc"].middlewares, middleware)
|
|
345
133
|
});
|
|
@@ -352,56 +140,6 @@ class Builder {
|
|
|
352
140
|
);
|
|
353
141
|
});
|
|
354
142
|
}
|
|
355
|
-
/**
|
|
356
|
-
* Sets or updates the metadata.
|
|
357
|
-
* The provided metadata is spared-merged with any existing metadata.
|
|
358
|
-
*
|
|
359
|
-
* @see {@link https://orpc.unnoq.com/docs/metadata Metadata Docs}
|
|
360
|
-
*/
|
|
361
|
-
meta(meta) {
|
|
362
|
-
return new Builder({
|
|
363
|
-
...this["~orpc"],
|
|
364
|
-
meta: mergeMeta(this["~orpc"].meta, meta)
|
|
365
|
-
});
|
|
366
|
-
}
|
|
367
|
-
/**
|
|
368
|
-
* Sets or updates the route definition.
|
|
369
|
-
* The provided route is spared-merged with any existing route.
|
|
370
|
-
* This option is typically relevant when integrating with OpenAPI.
|
|
371
|
-
*
|
|
372
|
-
* @see {@link https://orpc.unnoq.com/docs/openapi/routing OpenAPI Routing Docs}
|
|
373
|
-
* @see {@link https://orpc.unnoq.com/docs/openapi/input-output-structure OpenAPI Input/Output Structure Docs}
|
|
374
|
-
*/
|
|
375
|
-
route(route) {
|
|
376
|
-
return new Builder({
|
|
377
|
-
...this["~orpc"],
|
|
378
|
-
route: mergeRoute(this["~orpc"].route, route)
|
|
379
|
-
});
|
|
380
|
-
}
|
|
381
|
-
/**
|
|
382
|
-
* Defines the input validation schema.
|
|
383
|
-
*
|
|
384
|
-
* @see {@link https://orpc.unnoq.com/docs/procedure#input-output-validation Input Validation Docs}
|
|
385
|
-
*/
|
|
386
|
-
input(schema) {
|
|
387
|
-
return new Builder({
|
|
388
|
-
...this["~orpc"],
|
|
389
|
-
inputSchema: schema,
|
|
390
|
-
inputValidationIndex: this["~orpc"].middlewares.length
|
|
391
|
-
});
|
|
392
|
-
}
|
|
393
|
-
/**
|
|
394
|
-
* Defines the output validation schema.
|
|
395
|
-
*
|
|
396
|
-
* @see {@link https://orpc.unnoq.com/docs/procedure#input-output-validation Output Validation Docs}
|
|
397
|
-
*/
|
|
398
|
-
output(schema) {
|
|
399
|
-
return new Builder({
|
|
400
|
-
...this["~orpc"],
|
|
401
|
-
outputSchema: schema,
|
|
402
|
-
outputValidationIndex: this["~orpc"].middlewares.length
|
|
403
|
-
});
|
|
404
|
-
}
|
|
405
143
|
/**
|
|
406
144
|
* Defines the handler of the procedure.
|
|
407
145
|
*
|
|
@@ -413,6 +151,8 @@ class Builder {
|
|
|
413
151
|
handler
|
|
414
152
|
});
|
|
415
153
|
}
|
|
154
|
+
}
|
|
155
|
+
class BuilderWithMiddlewares extends ProcedureBuilder {
|
|
416
156
|
/**
|
|
417
157
|
* Prefixes all procedures in the router.
|
|
418
158
|
* The provided prefix is post-appended to any existing router prefix.
|
|
@@ -422,7 +162,7 @@ class Builder {
|
|
|
422
162
|
* @see {@link https://orpc.unnoq.com/docs/openapi/routing#route-prefixes OpenAPI Route Prefixes Docs}
|
|
423
163
|
*/
|
|
424
164
|
prefix(prefix) {
|
|
425
|
-
return new
|
|
165
|
+
return new this.constructor({
|
|
426
166
|
...this["~orpc"],
|
|
427
167
|
prefix: mergePrefix(this["~orpc"].prefix, prefix)
|
|
428
168
|
});
|
|
@@ -434,7 +174,7 @@ class Builder {
|
|
|
434
174
|
* @see {@link https://orpc.unnoq.com/docs/openapi/openapi-specification#operation-metadata OpenAPI Operation Metadata Docs}
|
|
435
175
|
*/
|
|
436
176
|
tag(...tags) {
|
|
437
|
-
return new
|
|
177
|
+
return new this.constructor({
|
|
438
178
|
...this["~orpc"],
|
|
439
179
|
tags: mergeTags(this["~orpc"].tags, tags)
|
|
440
180
|
});
|
|
@@ -447,33 +187,79 @@ class Builder {
|
|
|
447
187
|
router(router) {
|
|
448
188
|
return enhanceRouter(router, this["~orpc"]);
|
|
449
189
|
}
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
function decorateMiddleware(middleware) {
|
|
193
|
+
const decorated = ((...args) => middleware(...args));
|
|
194
|
+
decorated.mapInput = (mapInput) => {
|
|
195
|
+
const mapped = decorateMiddleware(
|
|
196
|
+
(options, input, ...rest) => middleware(options, mapInput(input), ...rest)
|
|
197
|
+
);
|
|
198
|
+
return mapped;
|
|
199
|
+
};
|
|
200
|
+
decorated.concat = (concatMiddleware, mapInput) => {
|
|
201
|
+
const mapped = mapInput ? decorateMiddleware(concatMiddleware).mapInput(mapInput) : concatMiddleware;
|
|
202
|
+
const concatted = decorateMiddleware((options, input, output, ...rest) => {
|
|
203
|
+
const merged = middleware(
|
|
204
|
+
{
|
|
205
|
+
...options,
|
|
206
|
+
next: (...[nextOptions1]) => mapped(
|
|
207
|
+
{
|
|
208
|
+
...options,
|
|
209
|
+
context: { ...options.context, ...nextOptions1?.context },
|
|
210
|
+
next: (...[nextOptions2]) => options.next({ context: { ...nextOptions1?.context, ...nextOptions2?.context } })
|
|
211
|
+
},
|
|
212
|
+
input,
|
|
213
|
+
output,
|
|
214
|
+
...rest
|
|
215
|
+
)
|
|
216
|
+
},
|
|
217
|
+
input,
|
|
218
|
+
output,
|
|
219
|
+
...rest
|
|
220
|
+
);
|
|
221
|
+
return merged;
|
|
222
|
+
});
|
|
223
|
+
return concatted;
|
|
224
|
+
};
|
|
225
|
+
return decorated;
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
class Builder extends BuilderWithMiddlewares {
|
|
229
|
+
/**
|
|
230
|
+
* Set or override the initial context.
|
|
231
|
+
*
|
|
232
|
+
* @see {@link https://orpc.unnoq.com/docs/context Context Docs}
|
|
233
|
+
*/
|
|
234
|
+
$context() {
|
|
235
|
+
return this;
|
|
236
|
+
}
|
|
450
237
|
/**
|
|
451
|
-
*
|
|
452
|
-
* And applies all of the previously defined options to the specified router.
|
|
238
|
+
* Creates a middleware.
|
|
453
239
|
*
|
|
454
|
-
* @see {@link https://orpc.unnoq.com/docs/
|
|
240
|
+
* @see {@link https://orpc.unnoq.com/docs/middleware Middleware Docs}
|
|
455
241
|
*/
|
|
456
|
-
|
|
457
|
-
return
|
|
242
|
+
middleware(middleware) {
|
|
243
|
+
return decorateMiddleware(middleware);
|
|
458
244
|
}
|
|
459
245
|
}
|
|
460
246
|
function createApiBuilder(opts = {}) {
|
|
461
|
-
|
|
247
|
+
return new Builder({
|
|
462
248
|
route: {},
|
|
463
249
|
meta: opts.meta ?? {},
|
|
464
250
|
errorMap: {},
|
|
465
251
|
inputValidationIndex: 0,
|
|
466
252
|
outputValidationIndex: 0,
|
|
467
253
|
middlewares: [
|
|
468
|
-
onError((error,
|
|
254
|
+
onError((error, _options) => {
|
|
469
255
|
console.dir(error, { depth: null });
|
|
470
256
|
})
|
|
471
257
|
],
|
|
258
|
+
schemas: initialSchemas,
|
|
472
259
|
// NB: this is a relic from orpc -- I'm not convinced there's a need for this (or if there is, that it's
|
|
473
260
|
// the best solution). For now I've removed the interface to configure it externally.
|
|
474
261
|
dedupeLeadingMiddlewares: true
|
|
475
262
|
});
|
|
476
|
-
return base;
|
|
477
263
|
}
|
|
478
264
|
const os = createApiBuilder();
|
|
479
265
|
|
|
@@ -511,17 +297,6 @@ function implementerInternal(contract, middlewares) {
|
|
|
511
297
|
});
|
|
512
298
|
return setHiddenRouterContract(adapted, contract);
|
|
513
299
|
};
|
|
514
|
-
} else if (key === "lazyRoute") {
|
|
515
|
-
method = (loader) => {
|
|
516
|
-
const adapted = enhanceRouter(lazy(loader), {
|
|
517
|
-
middlewares,
|
|
518
|
-
errorMap: {},
|
|
519
|
-
prefix: void 0,
|
|
520
|
-
tags: void 0,
|
|
521
|
-
dedupeLeadingMiddlewares: true
|
|
522
|
-
});
|
|
523
|
-
return setHiddenRouterContract(adapted, contract);
|
|
524
|
-
};
|
|
525
300
|
}
|
|
526
301
|
const next = getContractRouter(target, [key]);
|
|
527
302
|
if (!next) {
|
|
@@ -563,7 +338,7 @@ function implement(contract) {
|
|
|
563
338
|
}
|
|
564
339
|
|
|
565
340
|
function createAssertedLazyProcedure(lazied) {
|
|
566
|
-
const lazyProcedure =
|
|
341
|
+
const lazyProcedure = lazyInternal(async () => {
|
|
567
342
|
const { default: maybeProcedure } = await unlazy(lazied);
|
|
568
343
|
if (!isProcedure(maybeProcedure)) {
|
|
569
344
|
throw new Error(`
|
|
@@ -614,4 +389,4 @@ function createRouterClient(router, ...rest) {
|
|
|
614
389
|
return recursive;
|
|
615
390
|
}
|
|
616
391
|
|
|
617
|
-
export { Builder, DecoratedProcedure, Procedure, addMiddleware, call,
|
|
392
|
+
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>;
|
|
@@ -122,7 +122,6 @@ interface OpenAPIGeneratorGenerateOptions extends Partial<Omit<OpenAPI.Document,
|
|
|
122
122
|
*/
|
|
123
123
|
declare class OpenAPIGenerator {
|
|
124
124
|
#private;
|
|
125
|
-
private readonly serializer;
|
|
126
125
|
private readonly converter;
|
|
127
126
|
constructor(options?: OpenAPIGeneratorOptions);
|
|
128
127
|
/**
|
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>;
|
|
@@ -122,7 +122,6 @@ interface OpenAPIGeneratorGenerateOptions extends Partial<Omit<OpenAPI.Document,
|
|
|
122
122
|
*/
|
|
123
123
|
declare class OpenAPIGenerator {
|
|
124
124
|
#private;
|
|
125
|
-
private readonly serializer;
|
|
126
125
|
private readonly converter;
|
|
127
126
|
constructor(options?: OpenAPIGeneratorOptions);
|
|
128
127
|
/**
|