@temporary-name/server 1.9.3-alpha.65222302f1b71807a849530b3fe0fa0326d3c1a2 → 1.9.3-alpha.6dce39d156e86570d7f905d2e09463c8e1c80db2
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 +4 -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 +4 -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 +4 -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 +4 -6
- package/dist/index.d.mts +72 -139
- package/dist/index.d.ts +72 -139
- package/dist/index.mjs +106 -294
- package/dist/openapi/index.d.mts +1 -1
- package/dist/openapi/index.d.ts +1 -1
- package/dist/openapi/index.mjs +60 -77
- package/dist/plugins/index.d.mts +2 -2
- package/dist/plugins/index.d.ts +2 -2
- package/dist/shared/{server.CQyYNJ1H.d.ts → server.BSJugGGA.d.mts} +1 -2
- package/dist/shared/{server.SLLuK6_v.d.ts → server.Bs8EZATl.d.ts} +2 -2
- package/dist/shared/server.CHV9AQHl.mjs +412 -0
- package/dist/shared/server.CWWP8ypC.d.mts +239 -0
- package/dist/shared/server.CWWP8ypC.d.ts +239 -0
- package/dist/shared/{server.DLsti1Pv.mjs → server.Cn7WsRHl.mjs} +56 -95
- package/dist/shared/{server.BeuTpcmO.d.mts → server.DrMgIiBr.d.mts} +2 -2
- package/dist/shared/{server.C1fnTLq0.d.mts → server.EKwDe0d2.d.ts} +1 -2
- package/dist/shared/{server.BEHw7Eyx.mjs → server.JtIZ8YG7.mjs} +1 -11
- 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/index.mjs
CHANGED
|
@@ -1,313 +1,106 @@
|
|
|
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';
|
|
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
|
-
|
|
5
|
-
|
|
6
|
-
export { L as LAZY_SYMBOL, b as createORPCErrorConstructorMap, m as mergeCurrentContext, d as middlewareOutputFn } from './shared/server.BKh8I1Ny.mjs';
|
|
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.CHV9AQHl.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.CHV9AQHl.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
|
-
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 {
|
|
10
|
+
class DecoratedProcedure extends Procedure {
|
|
73
11
|
/**
|
|
74
|
-
*
|
|
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}
|
|
75
15
|
*/
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
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
|
+
}
|
|
25
|
+
});
|
|
84
26
|
}
|
|
85
|
-
return isContractProcedure(item) && "middlewares" in item["~orpc"] && "inputValidationIndex" in item["~orpc"] && "outputValidationIndex" in item["~orpc"] && "handler" in item["~orpc"];
|
|
86
27
|
}
|
|
87
28
|
|
|
88
|
-
class
|
|
29
|
+
class ProcedureBuilder extends ContractProcedure {
|
|
30
|
+
z;
|
|
31
|
+
constructor(def) {
|
|
32
|
+
super(def);
|
|
33
|
+
this.z = new SchemaClass();
|
|
34
|
+
}
|
|
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);
|
|
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);
|
|
90
|
+
schemas: {
|
|
91
|
+
...this["~orpc"].schemas,
|
|
92
|
+
querySchema: schema instanceof core.$ZodType ? schema : object(schema)
|
|
212
93
|
},
|
|
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
|
|
94
|
+
inputValidationIndex: this["~orpc"].middlewares.length
|
|
257
95
|
});
|
|
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
96
|
}
|
|
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) {
|
|
97
|
+
body(schema) {
|
|
308
98
|
return new ProcedureBuilder({
|
|
309
99
|
...this["~orpc"],
|
|
310
|
-
|
|
100
|
+
schemas: {
|
|
101
|
+
...this["~orpc"].schemas,
|
|
102
|
+
bodySchema: schema instanceof core.$ZodType ? schema : object(schema)
|
|
103
|
+
},
|
|
311
104
|
inputValidationIndex: this["~orpc"].middlewares.length
|
|
312
105
|
});
|
|
313
106
|
}
|
|
@@ -319,7 +112,10 @@ class ProcedureBuilder extends ContractProcedureBuilder {
|
|
|
319
112
|
output(schema) {
|
|
320
113
|
return new ProcedureBuilder({
|
|
321
114
|
...this["~orpc"],
|
|
322
|
-
|
|
115
|
+
schemas: {
|
|
116
|
+
...this["~orpc"].schemas,
|
|
117
|
+
outputSchema: schema instanceof core.$ZodType ? schema : object(schema)
|
|
118
|
+
},
|
|
323
119
|
outputValidationIndex: this["~orpc"].middlewares.length
|
|
324
120
|
});
|
|
325
121
|
}
|
|
@@ -391,15 +187,42 @@ class BuilderWithMiddlewares extends ProcedureBuilder {
|
|
|
391
187
|
router(router) {
|
|
392
188
|
return enhanceRouter(router, this["~orpc"]);
|
|
393
189
|
}
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
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;
|
|
403
226
|
}
|
|
404
227
|
|
|
405
228
|
class Builder extends BuilderWithMiddlewares {
|
|
@@ -421,22 +244,22 @@ class Builder extends BuilderWithMiddlewares {
|
|
|
421
244
|
}
|
|
422
245
|
}
|
|
423
246
|
function createApiBuilder(opts = {}) {
|
|
424
|
-
|
|
247
|
+
return new Builder({
|
|
425
248
|
route: {},
|
|
426
249
|
meta: opts.meta ?? {},
|
|
427
250
|
errorMap: {},
|
|
428
251
|
inputValidationIndex: 0,
|
|
429
252
|
outputValidationIndex: 0,
|
|
430
253
|
middlewares: [
|
|
431
|
-
onError((error,
|
|
254
|
+
onError((error, _options) => {
|
|
432
255
|
console.dir(error, { depth: null });
|
|
433
256
|
})
|
|
434
257
|
],
|
|
258
|
+
schemas: initialSchemas,
|
|
435
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
|
|
436
260
|
// the best solution). For now I've removed the interface to configure it externally.
|
|
437
261
|
dedupeLeadingMiddlewares: true
|
|
438
262
|
});
|
|
439
|
-
return base;
|
|
440
263
|
}
|
|
441
264
|
const os = createApiBuilder();
|
|
442
265
|
|
|
@@ -474,17 +297,6 @@ function implementerInternal(contract, middlewares) {
|
|
|
474
297
|
});
|
|
475
298
|
return setHiddenRouterContract(adapted, contract);
|
|
476
299
|
};
|
|
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
300
|
}
|
|
489
301
|
const next = getContractRouter(target, [key]);
|
|
490
302
|
if (!next) {
|
|
@@ -526,7 +338,7 @@ function implement(contract) {
|
|
|
526
338
|
}
|
|
527
339
|
|
|
528
340
|
function createAssertedLazyProcedure(lazied) {
|
|
529
|
-
const lazyProcedure =
|
|
341
|
+
const lazyProcedure = lazyInternal(async () => {
|
|
530
342
|
const { default: maybeProcedure } = await unlazy(lazied);
|
|
531
343
|
if (!isProcedure(maybeProcedure)) {
|
|
532
344
|
throw new Error(`
|
|
@@ -577,4 +389,4 @@ function createRouterClient(router, ...rest) {
|
|
|
577
389
|
return recursive;
|
|
578
390
|
}
|
|
579
391
|
|
|
580
|
-
export { Builder, BuilderWithMiddlewares, DecoratedProcedure, Procedure, ProcedureBuilder, 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>;
|
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>;
|
package/dist/openapi/index.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { isProcedure, resolveContractProcedures, ORPCError, createRouterClient } from '@temporary-name/server';
|
|
2
|
-
import { fallbackContractConfig, getEventIteratorSchemaDetails } from '@temporary-name/contract';
|
|
2
|
+
import { standardizeHTTPPath, fallbackContractConfig, getDynamicParams, getEventIteratorSchemaDetails } from '@temporary-name/contract';
|
|
3
3
|
import { isObject, stringifyJSON, findDeepMatches, toArray, clone, value, toHttpPath, isORPCErrorStatus, fallbackORPCErrorStatus, fallbackORPCErrorMessage, resolveMaybeOptionalOptions, createORPCErrorFromJson } from '@temporary-name/shared';
|
|
4
|
-
import {
|
|
4
|
+
import { j as jsonSerialize, d as deserialize, s as serialize } from '../shared/server.JtIZ8YG7.mjs';
|
|
5
5
|
import '@temporary-name/standard-server';
|
|
6
6
|
import { TypeName } from '@temporary-name/interop/json-schema-typed/draft-2020-12';
|
|
7
7
|
export { ContentEncoding as JSONSchemaContentEncoding, Format as JSONSchemaFormat, TypeName as JSONSchemaTypeName } from '@temporary-name/interop/json-schema-typed/draft-2020-12';
|
|
@@ -530,94 +530,77 @@ ${errors.join("\n\n")}`
|
|
|
530
530
|
}
|
|
531
531
|
async #request(doc, ref, def, baseSchemaConvertOptions) {
|
|
532
532
|
const method = fallbackContractConfig("defaultMethod", def.route.method);
|
|
533
|
-
const details = getEventIteratorSchemaDetails(def.inputSchema);
|
|
534
|
-
if (details) {
|
|
535
|
-
ref.requestBody = {
|
|
536
|
-
required: true,
|
|
537
|
-
content: toOpenAPIEventIteratorContent(
|
|
538
|
-
await this.converter.convert(details.yields, { ...baseSchemaConvertOptions, strategy: "input" }),
|
|
539
|
-
await this.converter.convert(details.returns, { ...baseSchemaConvertOptions, strategy: "input" })
|
|
540
|
-
)
|
|
541
|
-
};
|
|
542
|
-
return;
|
|
543
|
-
}
|
|
544
533
|
const dynamicParams = getDynamicParams(def.route.path)?.map((v) => v.name);
|
|
545
|
-
const
|
|
546
|
-
let [required, schema] = await this.converter.convert(def.inputSchema, {
|
|
534
|
+
const [_pathRequired, pathSchema] = await this.converter.convert(def.schemas.pathSchema, {
|
|
547
535
|
...baseSchemaConvertOptions,
|
|
548
536
|
strategy: "input",
|
|
549
|
-
minStructureDepthForRef:
|
|
537
|
+
minStructureDepthForRef: 1
|
|
550
538
|
});
|
|
551
|
-
if (
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
);
|
|
559
|
-
if (!isObjectSchema(schema)) {
|
|
560
|
-
throw error2;
|
|
561
|
-
}
|
|
562
|
-
const [paramsSchema, rest] = separateObjectSchema(schema, dynamicParams);
|
|
563
|
-
schema = rest;
|
|
564
|
-
required = rest.required ? rest.required.length !== 0 : false;
|
|
565
|
-
if (!checkParamsSchema(paramsSchema, dynamicParams)) {
|
|
566
|
-
throw error2;
|
|
567
|
-
}
|
|
568
|
-
ref.parameters ??= [];
|
|
569
|
-
ref.parameters.push(...toOpenAPIParameters(paramsSchema, "path"));
|
|
539
|
+
if (dynamicParams?.length) {
|
|
540
|
+
const error = new OpenAPIGeneratorError(
|
|
541
|
+
// TODO: fix this error
|
|
542
|
+
'When input structure is "compact", and path has dynamic params, input schema must be an object with all dynamic params as required.'
|
|
543
|
+
);
|
|
544
|
+
if (!isObjectSchema(pathSchema)) {
|
|
545
|
+
throw error;
|
|
570
546
|
}
|
|
571
|
-
if (
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
547
|
+
if (!checkParamsSchema(pathSchema, dynamicParams)) {
|
|
548
|
+
throw error;
|
|
549
|
+
}
|
|
550
|
+
ref.parameters ??= [];
|
|
551
|
+
ref.parameters.push(...toOpenAPIParameters(pathSchema, "path"));
|
|
552
|
+
} else {
|
|
553
|
+
const error = new OpenAPIGeneratorError("Params set via path do not match those on the route");
|
|
554
|
+
if (!isObjectSchema(pathSchema)) {
|
|
555
|
+
console.log("FOO", pathSchema);
|
|
556
|
+
throw error;
|
|
557
|
+
}
|
|
558
|
+
if (!checkParamsSchema(pathSchema, [])) {
|
|
559
|
+
console.log("BAR", pathSchema);
|
|
560
|
+
throw error;
|
|
585
561
|
}
|
|
586
|
-
return;
|
|
587
|
-
}
|
|
588
|
-
const error = new OpenAPIGeneratorError(
|
|
589
|
-
'When input structure is "detailed", input schema must satisfy: { params?: Record<string, unknown>, query?: Record<string, unknown>, headers?: Record<string, unknown>, body?: unknown }'
|
|
590
|
-
);
|
|
591
|
-
if (!isObjectSchema(schema)) {
|
|
592
|
-
throw error;
|
|
593
562
|
}
|
|
594
|
-
const
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
563
|
+
const [_queryRequired, querySchema] = await this.converter.convert(def.schemas.querySchema, {
|
|
564
|
+
...baseSchemaConvertOptions,
|
|
565
|
+
strategy: "input",
|
|
566
|
+
minStructureDepthForRef: 0
|
|
567
|
+
});
|
|
568
|
+
if (!isAnySchema(querySchema)) {
|
|
569
|
+
const resolvedSchema = resolveOpenAPIJsonSchemaRef(doc, querySchema);
|
|
570
|
+
if (!isObjectSchema(resolvedSchema)) {
|
|
571
|
+
throw new OpenAPIGeneratorError("Query param schema must satisfy: object | any | unknown");
|
|
572
|
+
}
|
|
573
|
+
ref.parameters ??= [];
|
|
574
|
+
ref.parameters.push(...toOpenAPIParameters(resolvedSchema, "query"));
|
|
599
575
|
}
|
|
600
|
-
|
|
601
|
-
const
|
|
602
|
-
if (
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
576
|
+
if (method !== "GET") {
|
|
577
|
+
const details = getEventIteratorSchemaDetails(def.schemas.bodySchema);
|
|
578
|
+
if (details) {
|
|
579
|
+
ref.requestBody = {
|
|
580
|
+
required: true,
|
|
581
|
+
content: toOpenAPIEventIteratorContent(
|
|
582
|
+
await this.converter.convert(details.yields, { ...baseSchemaConvertOptions, strategy: "input" }),
|
|
583
|
+
await this.converter.convert(details.returns, { ...baseSchemaConvertOptions, strategy: "input" })
|
|
584
|
+
)
|
|
585
|
+
};
|
|
586
|
+
} else {
|
|
587
|
+
const [bodyRequired, bodySchema] = await this.converter.convert(def.schemas.bodySchema, {
|
|
588
|
+
...baseSchemaConvertOptions,
|
|
589
|
+
strategy: "input",
|
|
590
|
+
minStructureDepthForRef: 0
|
|
591
|
+
});
|
|
592
|
+
if (isAnySchema(bodySchema)) {
|
|
593
|
+
return;
|
|
606
594
|
}
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
595
|
+
ref.requestBody = {
|
|
596
|
+
required: bodyRequired,
|
|
597
|
+
content: toOpenAPIContent(bodySchema)
|
|
598
|
+
};
|
|
610
599
|
}
|
|
611
600
|
}
|
|
612
|
-
if (schema.properties?.body !== void 0) {
|
|
613
|
-
ref.requestBody = {
|
|
614
|
-
required: schema.required?.includes("body"),
|
|
615
|
-
content: toOpenAPIContent(schema.properties.body)
|
|
616
|
-
};
|
|
617
|
-
}
|
|
618
601
|
}
|
|
619
602
|
async #successResponse(doc, ref, def, baseSchemaConvertOptions) {
|
|
620
|
-
const outputSchema = def.outputSchema;
|
|
603
|
+
const outputSchema = def.schemas.outputSchema;
|
|
621
604
|
const status = fallbackContractConfig("defaultSuccessStatus", def.route.successStatus);
|
|
622
605
|
const description = fallbackContractConfig("defaultSuccessDescription", def.route?.successDescription);
|
|
623
606
|
const eventIteratorSchemaDetails = getEventIteratorSchemaDetails(outputSchema);
|