@temporary-name/server 1.9.3-alpha.e2d8d164da72fb570c2b14a4fa956c80f9e33cdc → 1.9.3-alpha.f9f5ce625d5edee78250b87b3a64f1d9760c2244
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 +3 -3
- package/dist/adapters/fetch/index.d.mts +3 -4
- package/dist/adapters/fetch/index.d.ts +3 -4
- package/dist/adapters/fetch/index.mjs +3 -3
- package/dist/adapters/node/index.d.mts +3 -4
- package/dist/adapters/node/index.d.ts +3 -4
- package/dist/adapters/node/index.mjs +3 -3
- package/dist/adapters/standard/index.d.mts +10 -6
- package/dist/adapters/standard/index.d.ts +10 -6
- package/dist/adapters/standard/index.mjs +3 -3
- package/dist/index.d.mts +54 -83
- package/dist/index.d.ts +54 -83
- package/dist/index.mjs +41 -213
- package/dist/openapi/index.d.mts +1 -1
- package/dist/openapi/index.d.ts +1 -1
- package/dist/openapi/index.mjs +52 -35
- package/dist/plugins/index.d.mts +4 -80
- package/dist/plugins/index.d.ts +4 -80
- package/dist/plugins/index.mjs +2 -168
- package/dist/shared/{server.B93y_8tj.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.CqTex_jI.mjs → server.CVBLzkro.mjs} +14 -24
- package/dist/shared/server.ClhVCxfg.mjs +413 -0
- package/dist/shared/{server.cjcgLdr1.d.ts → server.D6Qs_UcF.d.mts} +2 -3
- package/dist/shared/{server.D_fags8X.d.ts → server.DFptr1Nz.d.ts} +2 -2
- package/dist/shared/{server.CT1xhSmE.d.mts → server.DpoO_ER_.d.ts} +2 -3
- package/dist/shared/{server.Kxw442A9.mjs → server.JtIZ8YG7.mjs} +1 -11
- package/package.json +10 -10
- package/dist/shared/server.BYYf0Wn6.mjs +0 -202
- package/dist/shared/server.C3RuMHWl.d.mts +0 -192
- package/dist/shared/server.C3RuMHWl.d.ts +0 -192
package/dist/index.mjs
CHANGED
|
@@ -1,52 +1,12 @@
|
|
|
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
|
-
import { c as createProcedureClient, i as isLazy, g as getLazyMeta, l as lazy, u as unlazy } from './shared/server.BYYf0Wn6.mjs';
|
|
7
|
-
export { L as LAZY_SYMBOL, a as createORPCErrorConstructorMap, m as mergeCurrentContext, b as middlewareOutputFn } from './shared/server.BYYf0Wn6.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.ClhVCxfg.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.ClhVCxfg.mjs';
|
|
8
8
|
export { getEventMeta, withEventMeta } from '@temporary-name/standard-server';
|
|
9
9
|
|
|
10
|
-
function isStartWithMiddlewares(middlewares, compare) {
|
|
11
|
-
if (compare.length > middlewares.length) {
|
|
12
|
-
return false;
|
|
13
|
-
}
|
|
14
|
-
for (let i = 0; i < middlewares.length; i++) {
|
|
15
|
-
if (compare[i] === void 0) {
|
|
16
|
-
return true;
|
|
17
|
-
}
|
|
18
|
-
if (middlewares[i] !== compare[i]) {
|
|
19
|
-
return false;
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
return true;
|
|
23
|
-
}
|
|
24
|
-
function mergeMiddlewares(first, second, options) {
|
|
25
|
-
if (options.dedupeLeading && isStartWithMiddlewares(second, first)) {
|
|
26
|
-
return second;
|
|
27
|
-
}
|
|
28
|
-
return [...first, ...second];
|
|
29
|
-
}
|
|
30
|
-
function addMiddleware(middlewares, addition) {
|
|
31
|
-
return [...middlewares, addition];
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
class Procedure {
|
|
35
|
-
/**
|
|
36
|
-
* This property holds the defined options.
|
|
37
|
-
*/
|
|
38
|
-
"~orpc";
|
|
39
|
-
constructor(def) {
|
|
40
|
-
this["~orpc"] = def;
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
function isProcedure(item) {
|
|
44
|
-
if (item instanceof Procedure) {
|
|
45
|
-
return true;
|
|
46
|
-
}
|
|
47
|
-
return isContractProcedure(item) && "middlewares" in item["~orpc"] && "handler" in item["~orpc"];
|
|
48
|
-
}
|
|
49
|
-
|
|
50
10
|
class DecoratedProcedure extends Procedure {
|
|
51
11
|
/**
|
|
52
12
|
* Make this procedure callable (works like a function while still being a procedure).
|
|
@@ -66,152 +26,6 @@ class DecoratedProcedure extends Procedure {
|
|
|
66
26
|
}
|
|
67
27
|
}
|
|
68
28
|
|
|
69
|
-
const HIDDEN_ROUTER_CONTRACT_SYMBOL = Symbol("ORPC_HIDDEN_ROUTER_CONTRACT");
|
|
70
|
-
function setHiddenRouterContract(router, contract) {
|
|
71
|
-
return new Proxy(router, {
|
|
72
|
-
get(target, key) {
|
|
73
|
-
if (key === HIDDEN_ROUTER_CONTRACT_SYMBOL) {
|
|
74
|
-
return contract;
|
|
75
|
-
}
|
|
76
|
-
return Reflect.get(target, key);
|
|
77
|
-
}
|
|
78
|
-
});
|
|
79
|
-
}
|
|
80
|
-
function getHiddenRouterContract(router) {
|
|
81
|
-
return router[HIDDEN_ROUTER_CONTRACT_SYMBOL];
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
function getRouter(router, path) {
|
|
85
|
-
let current = router;
|
|
86
|
-
for (let i = 0; i < path.length; i++) {
|
|
87
|
-
const segment = path[i];
|
|
88
|
-
if (!current) {
|
|
89
|
-
return void 0;
|
|
90
|
-
}
|
|
91
|
-
if (isProcedure(current)) {
|
|
92
|
-
return void 0;
|
|
93
|
-
}
|
|
94
|
-
if (!isLazy(current)) {
|
|
95
|
-
current = current[segment];
|
|
96
|
-
continue;
|
|
97
|
-
}
|
|
98
|
-
const lazied = current;
|
|
99
|
-
const rest = path.slice(i);
|
|
100
|
-
return lazy(async () => {
|
|
101
|
-
const unwrapped = await unlazy(lazied);
|
|
102
|
-
const next = getRouter(unwrapped.default, rest);
|
|
103
|
-
return unlazy(next);
|
|
104
|
-
}, getLazyMeta(lazied));
|
|
105
|
-
}
|
|
106
|
-
return current;
|
|
107
|
-
}
|
|
108
|
-
function createAccessibleLazyRouter(lazied) {
|
|
109
|
-
const recursive = new Proxy(lazied, {
|
|
110
|
-
get(target, key) {
|
|
111
|
-
if (typeof key !== "string") {
|
|
112
|
-
return Reflect.get(target, key);
|
|
113
|
-
}
|
|
114
|
-
const next = getRouter(lazied, [key]);
|
|
115
|
-
return createAccessibleLazyRouter(next);
|
|
116
|
-
}
|
|
117
|
-
});
|
|
118
|
-
return recursive;
|
|
119
|
-
}
|
|
120
|
-
function enhanceRouter(router, options) {
|
|
121
|
-
if (isLazy(router)) {
|
|
122
|
-
const laziedMeta = getLazyMeta(router);
|
|
123
|
-
const enhancedPrefix = laziedMeta?.prefix ? mergePrefix(options.prefix, laziedMeta?.prefix) : options.prefix;
|
|
124
|
-
const enhanced2 = lazy(
|
|
125
|
-
async () => {
|
|
126
|
-
const { default: unlaziedRouter } = await unlazy(router);
|
|
127
|
-
const enhanced3 = enhanceRouter(unlaziedRouter, options);
|
|
128
|
-
return unlazy(enhanced3);
|
|
129
|
-
},
|
|
130
|
-
{
|
|
131
|
-
...laziedMeta,
|
|
132
|
-
prefix: enhancedPrefix
|
|
133
|
-
}
|
|
134
|
-
);
|
|
135
|
-
const accessible = createAccessibleLazyRouter(enhanced2);
|
|
136
|
-
return accessible;
|
|
137
|
-
}
|
|
138
|
-
if (isProcedure(router)) {
|
|
139
|
-
const newMiddlewares = mergeMiddlewares(options.middlewares, router["~orpc"].middlewares, {
|
|
140
|
-
dedupeLeading: options.dedupeLeadingMiddlewares
|
|
141
|
-
});
|
|
142
|
-
const newMiddlewareAdded = newMiddlewares.length - router["~orpc"].middlewares.length;
|
|
143
|
-
const enhanced2 = new Procedure({
|
|
144
|
-
...router["~orpc"],
|
|
145
|
-
route: enhanceRoute(router["~orpc"].route, options),
|
|
146
|
-
errorMap: mergeErrorMap(options.errorMap, router["~orpc"].errorMap),
|
|
147
|
-
middlewares: newMiddlewares,
|
|
148
|
-
inputValidationIndex: router["~orpc"].inputValidationIndex + newMiddlewareAdded,
|
|
149
|
-
outputValidationIndex: router["~orpc"].outputValidationIndex + newMiddlewareAdded
|
|
150
|
-
});
|
|
151
|
-
return enhanced2;
|
|
152
|
-
}
|
|
153
|
-
const enhanced = {};
|
|
154
|
-
for (const key in router) {
|
|
155
|
-
enhanced[key] = enhanceRouter(router[key], options);
|
|
156
|
-
}
|
|
157
|
-
return enhanced;
|
|
158
|
-
}
|
|
159
|
-
function traverseContractProcedures(options, callback, lazyOptions = []) {
|
|
160
|
-
let currentRouter = options.router;
|
|
161
|
-
const hiddenContract = getHiddenRouterContract(options.router);
|
|
162
|
-
if (hiddenContract !== void 0) {
|
|
163
|
-
currentRouter = hiddenContract;
|
|
164
|
-
}
|
|
165
|
-
if (isLazy(currentRouter)) {
|
|
166
|
-
lazyOptions.push({
|
|
167
|
-
router: currentRouter,
|
|
168
|
-
path: options.path
|
|
169
|
-
});
|
|
170
|
-
} else if (isContractProcedure(currentRouter)) {
|
|
171
|
-
callback({
|
|
172
|
-
contract: currentRouter,
|
|
173
|
-
path: options.path
|
|
174
|
-
});
|
|
175
|
-
} else {
|
|
176
|
-
for (const key in currentRouter) {
|
|
177
|
-
traverseContractProcedures(
|
|
178
|
-
{
|
|
179
|
-
router: currentRouter[key],
|
|
180
|
-
path: [...options.path, key]
|
|
181
|
-
},
|
|
182
|
-
callback,
|
|
183
|
-
lazyOptions
|
|
184
|
-
);
|
|
185
|
-
}
|
|
186
|
-
}
|
|
187
|
-
return lazyOptions;
|
|
188
|
-
}
|
|
189
|
-
async function resolveContractProcedures(options, callback) {
|
|
190
|
-
const pending = [options];
|
|
191
|
-
for (const options2 of pending) {
|
|
192
|
-
const lazyOptions = traverseContractProcedures(options2, callback);
|
|
193
|
-
for (const options3 of lazyOptions) {
|
|
194
|
-
const { default: router } = await unlazy(options3.router);
|
|
195
|
-
pending.push({
|
|
196
|
-
router,
|
|
197
|
-
path: options3.path
|
|
198
|
-
});
|
|
199
|
-
}
|
|
200
|
-
}
|
|
201
|
-
}
|
|
202
|
-
async function unlazyRouter(router) {
|
|
203
|
-
if (isProcedure(router)) {
|
|
204
|
-
return router;
|
|
205
|
-
}
|
|
206
|
-
const unlazied = {};
|
|
207
|
-
for (const key in router) {
|
|
208
|
-
const item = router[key];
|
|
209
|
-
const { default: unlaziedRouter } = await unlazy(item);
|
|
210
|
-
unlazied[key] = await unlazyRouter(unlaziedRouter);
|
|
211
|
-
}
|
|
212
|
-
return unlazied;
|
|
213
|
-
}
|
|
214
|
-
|
|
215
29
|
class ProcedureBuilder extends ContractProcedure {
|
|
216
30
|
z;
|
|
217
31
|
constructor(def) {
|
|
@@ -242,6 +56,19 @@ class ProcedureBuilder extends ContractProcedure {
|
|
|
242
56
|
meta: mergeMeta(this["~orpc"].meta, meta)
|
|
243
57
|
});
|
|
244
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
|
+
}
|
|
245
72
|
/**
|
|
246
73
|
* Sets or updates the route definition for the contract.
|
|
247
74
|
* The provided route is spared-merged with any existing route in the contract.
|
|
@@ -250,22 +77,30 @@ class ProcedureBuilder extends ContractProcedure {
|
|
|
250
77
|
* @see {@link https://orpc.unnoq.com/docs/openapi/routing OpenAPI Routing Docs}
|
|
251
78
|
* @see {@link https://orpc.unnoq.com/docs/openapi/input-output-structure OpenAPI Input/Output Structure Docs}
|
|
252
79
|
*/
|
|
253
|
-
|
|
80
|
+
endpointOpts(route) {
|
|
254
81
|
const { prefix } = this["~orpc"];
|
|
255
82
|
return new ProcedureBuilder({
|
|
256
83
|
...this["~orpc"],
|
|
257
84
|
route: mergeRoute(this["~orpc"].route, prefix ? prefixRoute(route, prefix) : route)
|
|
258
85
|
});
|
|
259
86
|
}
|
|
260
|
-
|
|
261
|
-
* Defines the input validation schema.
|
|
262
|
-
*
|
|
263
|
-
* @see {@link https://orpc.unnoq.com/docs/procedure#input-output-validation Input Validation Docs}
|
|
264
|
-
*/
|
|
265
|
-
input(schema) {
|
|
87
|
+
query(schema) {
|
|
266
88
|
return new ProcedureBuilder({
|
|
267
89
|
...this["~orpc"],
|
|
268
|
-
|
|
90
|
+
schemas: {
|
|
91
|
+
...this["~orpc"].schemas,
|
|
92
|
+
querySchema: schema instanceof core.$ZodType ? schema : object(schema)
|
|
93
|
+
},
|
|
94
|
+
inputValidationIndex: this["~orpc"].middlewares.length
|
|
95
|
+
});
|
|
96
|
+
}
|
|
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)
|
|
103
|
+
},
|
|
269
104
|
inputValidationIndex: this["~orpc"].middlewares.length
|
|
270
105
|
});
|
|
271
106
|
}
|
|
@@ -277,7 +112,10 @@ class ProcedureBuilder extends ContractProcedure {
|
|
|
277
112
|
output(schema) {
|
|
278
113
|
return new ProcedureBuilder({
|
|
279
114
|
...this["~orpc"],
|
|
280
|
-
|
|
115
|
+
schemas: {
|
|
116
|
+
...this["~orpc"].schemas,
|
|
117
|
+
outputSchema: schema instanceof core.$ZodType ? schema : object(schema)
|
|
118
|
+
},
|
|
281
119
|
outputValidationIndex: this["~orpc"].middlewares.length
|
|
282
120
|
});
|
|
283
121
|
}
|
|
@@ -417,6 +255,7 @@ function createApiBuilder(opts = {}) {
|
|
|
417
255
|
console.dir(error, { depth: null });
|
|
418
256
|
})
|
|
419
257
|
],
|
|
258
|
+
schemas: initialSchemas,
|
|
420
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
|
|
421
260
|
// the best solution). For now I've removed the interface to configure it externally.
|
|
422
261
|
dedupeLeadingMiddlewares: true
|
|
@@ -458,17 +297,6 @@ function implementerInternal(contract, middlewares) {
|
|
|
458
297
|
});
|
|
459
298
|
return setHiddenRouterContract(adapted, contract);
|
|
460
299
|
};
|
|
461
|
-
} else if (key === "lazyRoute") {
|
|
462
|
-
method = (loader) => {
|
|
463
|
-
const adapted = enhanceRouter(lazy(loader), {
|
|
464
|
-
middlewares,
|
|
465
|
-
errorMap: {},
|
|
466
|
-
prefix: void 0,
|
|
467
|
-
tags: void 0,
|
|
468
|
-
dedupeLeadingMiddlewares: true
|
|
469
|
-
});
|
|
470
|
-
return setHiddenRouterContract(adapted, contract);
|
|
471
|
-
};
|
|
472
300
|
}
|
|
473
301
|
const next = getContractRouter(target, [key]);
|
|
474
302
|
if (!next) {
|
|
@@ -510,7 +338,7 @@ function implement(contract) {
|
|
|
510
338
|
}
|
|
511
339
|
|
|
512
340
|
function createAssertedLazyProcedure(lazied) {
|
|
513
|
-
const lazyProcedure =
|
|
341
|
+
const lazyProcedure = lazyInternal(async () => {
|
|
514
342
|
const { default: maybeProcedure } = await unlazy(lazied);
|
|
515
343
|
if (!isProcedure(maybeProcedure)) {
|
|
516
344
|
throw new Error(`
|
|
@@ -561,4 +389,4 @@ function createRouterClient(router, ...rest) {
|
|
|
561
389
|
return recursive;
|
|
562
390
|
}
|
|
563
391
|
|
|
564
|
-
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,60 +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
|
-
|
|
534
|
+
const [_pathRequired, pathSchema] = await this.converter.convert(def.schemas.pathSchema, {
|
|
546
535
|
...baseSchemaConvertOptions,
|
|
547
536
|
strategy: "input",
|
|
548
|
-
minStructureDepthForRef:
|
|
537
|
+
minStructureDepthForRef: 1
|
|
549
538
|
});
|
|
550
|
-
if (isAnySchema(schema) && !dynamicParams?.length) {
|
|
551
|
-
return;
|
|
552
|
-
}
|
|
553
539
|
if (dynamicParams?.length) {
|
|
554
540
|
const error = new OpenAPIGeneratorError(
|
|
541
|
+
// TODO: fix this error
|
|
555
542
|
'When input structure is "compact", and path has dynamic params, input schema must be an object with all dynamic params as required.'
|
|
556
543
|
);
|
|
557
|
-
if (!isObjectSchema(
|
|
544
|
+
if (!isObjectSchema(pathSchema)) {
|
|
558
545
|
throw error;
|
|
559
546
|
}
|
|
560
|
-
|
|
561
|
-
schema = rest;
|
|
562
|
-
required = rest.required ? rest.required.length !== 0 : false;
|
|
563
|
-
if (!checkParamsSchema(paramsSchema, dynamicParams)) {
|
|
547
|
+
if (!checkParamsSchema(pathSchema, dynamicParams)) {
|
|
564
548
|
throw error;
|
|
565
549
|
}
|
|
566
550
|
ref.parameters ??= [];
|
|
567
|
-
ref.parameters.push(...toOpenAPIParameters(
|
|
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;
|
|
561
|
+
}
|
|
568
562
|
}
|
|
569
|
-
|
|
570
|
-
|
|
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);
|
|
571
570
|
if (!isObjectSchema(resolvedSchema)) {
|
|
572
|
-
throw new OpenAPIGeneratorError(
|
|
573
|
-
'When method is "GET", input schema must satisfy: object | any | unknown'
|
|
574
|
-
);
|
|
571
|
+
throw new OpenAPIGeneratorError("Query param schema must satisfy: object | any | unknown");
|
|
575
572
|
}
|
|
576
573
|
ref.parameters ??= [];
|
|
577
574
|
ref.parameters.push(...toOpenAPIParameters(resolvedSchema, "query"));
|
|
578
|
-
}
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
575
|
+
}
|
|
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;
|
|
594
|
+
}
|
|
595
|
+
ref.requestBody = {
|
|
596
|
+
required: bodyRequired,
|
|
597
|
+
content: toOpenAPIContent(bodySchema)
|
|
598
|
+
};
|
|
599
|
+
}
|
|
583
600
|
}
|
|
584
601
|
}
|
|
585
602
|
async #successResponse(doc, ref, def, baseSchemaConvertOptions) {
|
|
586
|
-
const outputSchema = def.outputSchema;
|
|
603
|
+
const outputSchema = def.schemas.outputSchema;
|
|
587
604
|
const status = fallbackContractConfig("defaultSuccessStatus", def.route.successStatus);
|
|
588
605
|
const description = fallbackContractConfig("defaultSuccessDescription", def.route?.successDescription);
|
|
589
606
|
const eventIteratorSchemaDetails = getEventIteratorSchemaDetails(outputSchema);
|
package/dist/plugins/index.d.mts
CHANGED
|
@@ -1,58 +1,8 @@
|
|
|
1
1
|
import { Value, Promisable, ORPCError } from '@temporary-name/shared';
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import { S as StandardHandlerInterceptorOptions, a as StandardHandlerPlugin, b as StandardHandlerOptions } from '../shared/server.CT1xhSmE.mjs';
|
|
5
|
-
import { C as Context, E as ProcedureClientInterceptorOptions } from '../shared/server.C3RuMHWl.mjs';
|
|
2
|
+
import { S as StandardHandlerInterceptorOptions, a as StandardHandlerPlugin, b as StandardHandlerOptions } from '../shared/server.D6Qs_UcF.mjs';
|
|
3
|
+
import { C as Context, G as ProcedureClientInterceptorOptions } from '../shared/server.BL2R5jcp.mjs';
|
|
6
4
|
import { Meta } from '@temporary-name/contract';
|
|
7
5
|
|
|
8
|
-
interface BatchHandlerOptions<T extends Context> {
|
|
9
|
-
/**
|
|
10
|
-
* The max size of the batch allowed.
|
|
11
|
-
*
|
|
12
|
-
* @default 10
|
|
13
|
-
*/
|
|
14
|
-
maxSize?: Value<Promisable<number>, [StandardHandlerInterceptorOptions<T>]>;
|
|
15
|
-
/**
|
|
16
|
-
* Map the request before processing it.
|
|
17
|
-
*
|
|
18
|
-
* @default merged back batch request headers into the request
|
|
19
|
-
*/
|
|
20
|
-
mapRequestItem?(request: StandardRequest, batchOptions: StandardHandlerInterceptorOptions<T>): StandardRequest;
|
|
21
|
-
/**
|
|
22
|
-
* Success batch response status code.
|
|
23
|
-
*
|
|
24
|
-
* @default 207
|
|
25
|
-
*/
|
|
26
|
-
successStatus?: Value<Promisable<number>, [
|
|
27
|
-
responses: Promise<BatchResponseBodyItem>[],
|
|
28
|
-
batchOptions: StandardHandlerInterceptorOptions<T>
|
|
29
|
-
]>;
|
|
30
|
-
/**
|
|
31
|
-
* success batch response headers.
|
|
32
|
-
*
|
|
33
|
-
* @default {}
|
|
34
|
-
*/
|
|
35
|
-
headers?: Value<Promisable<StandardHeaders>, [
|
|
36
|
-
responses: Promise<BatchResponseBodyItem>[],
|
|
37
|
-
batchOptions: StandardHandlerInterceptorOptions<T>
|
|
38
|
-
]>;
|
|
39
|
-
}
|
|
40
|
-
/**
|
|
41
|
-
* The Batch Requests Plugin allows you to combine multiple requests and responses into a single batch,
|
|
42
|
-
* reducing the overhead of sending each one separately.
|
|
43
|
-
*
|
|
44
|
-
* @see {@link https://orpc.unnoq.com/docs/plugins/batch-requests Batch Requests Plugin Docs}
|
|
45
|
-
*/
|
|
46
|
-
declare class BatchHandlerPlugin<T extends Context> implements StandardHandlerPlugin<T> {
|
|
47
|
-
private readonly maxSize;
|
|
48
|
-
private readonly mapRequestItem;
|
|
49
|
-
private readonly successStatus;
|
|
50
|
-
private readonly headers;
|
|
51
|
-
order: number;
|
|
52
|
-
constructor(options?: BatchHandlerOptions<T>);
|
|
53
|
-
init(options: StandardHandlerOptions<T>): void;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
6
|
interface CORSOptions<T extends Context> {
|
|
57
7
|
origin?: Value<Promisable<string | readonly string[] | null | undefined>, [
|
|
58
8
|
origin: string,
|
|
@@ -80,32 +30,6 @@ declare class CORSPlugin<T extends Context> implements StandardHandlerPlugin<T>
|
|
|
80
30
|
init(options: StandardHandlerOptions<T>): void;
|
|
81
31
|
}
|
|
82
32
|
|
|
83
|
-
interface RequestHeadersPluginContext {
|
|
84
|
-
reqHeaders?: Headers;
|
|
85
|
-
}
|
|
86
|
-
/**
|
|
87
|
-
* The Request Headers Plugin injects a `reqHeaders` instance into the context,
|
|
88
|
-
* allowing access to request headers in oRPC.
|
|
89
|
-
*
|
|
90
|
-
* @see {@link https://orpc.unnoq.com/docs/plugins/request-headers Request Headers Plugin Docs}
|
|
91
|
-
*/
|
|
92
|
-
declare class RequestHeadersPlugin<T extends RequestHeadersPluginContext> implements StandardHandlerPlugin<T> {
|
|
93
|
-
init(options: StandardHandlerOptions<T>): void;
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
interface ResponseHeadersPluginContext {
|
|
97
|
-
resHeaders?: Headers;
|
|
98
|
-
}
|
|
99
|
-
/**
|
|
100
|
-
* The Response Headers Plugin allows you to set response headers in oRPC.
|
|
101
|
-
* It injects a resHeaders instance into the context, enabling you to modify response headers easily.
|
|
102
|
-
*
|
|
103
|
-
* @see {@link https://orpc.unnoq.com/docs/plugins/response-headers Response Headers Plugin Docs}
|
|
104
|
-
*/
|
|
105
|
-
declare class ResponseHeadersPlugin<T extends ResponseHeadersPluginContext> implements StandardHandlerPlugin<T> {
|
|
106
|
-
init(options: StandardHandlerOptions<T>): void;
|
|
107
|
-
}
|
|
108
|
-
|
|
109
33
|
interface SimpleCsrfProtectionHandlerPluginOptions<T extends Context> {
|
|
110
34
|
/**
|
|
111
35
|
* The name of the header to check.
|
|
@@ -156,5 +80,5 @@ declare class SimpleCsrfProtectionHandlerPlugin<T extends Context> implements St
|
|
|
156
80
|
init(options: StandardHandlerOptions<T>): void;
|
|
157
81
|
}
|
|
158
82
|
|
|
159
|
-
export {
|
|
160
|
-
export type {
|
|
83
|
+
export { CORSPlugin, SimpleCsrfProtectionHandlerPlugin };
|
|
84
|
+
export type { CORSOptions, SimpleCsrfProtectionHandlerPluginOptions };
|
package/dist/plugins/index.d.ts
CHANGED
|
@@ -1,58 +1,8 @@
|
|
|
1
1
|
import { Value, Promisable, ORPCError } from '@temporary-name/shared';
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import { S as StandardHandlerInterceptorOptions, a as StandardHandlerPlugin, b as StandardHandlerOptions } from '../shared/server.cjcgLdr1.js';
|
|
5
|
-
import { C as Context, E as ProcedureClientInterceptorOptions } from '../shared/server.C3RuMHWl.js';
|
|
2
|
+
import { S as StandardHandlerInterceptorOptions, a as StandardHandlerPlugin, b as StandardHandlerOptions } from '../shared/server.DpoO_ER_.js';
|
|
3
|
+
import { C as Context, G as ProcedureClientInterceptorOptions } from '../shared/server.BL2R5jcp.js';
|
|
6
4
|
import { Meta } from '@temporary-name/contract';
|
|
7
5
|
|
|
8
|
-
interface BatchHandlerOptions<T extends Context> {
|
|
9
|
-
/**
|
|
10
|
-
* The max size of the batch allowed.
|
|
11
|
-
*
|
|
12
|
-
* @default 10
|
|
13
|
-
*/
|
|
14
|
-
maxSize?: Value<Promisable<number>, [StandardHandlerInterceptorOptions<T>]>;
|
|
15
|
-
/**
|
|
16
|
-
* Map the request before processing it.
|
|
17
|
-
*
|
|
18
|
-
* @default merged back batch request headers into the request
|
|
19
|
-
*/
|
|
20
|
-
mapRequestItem?(request: StandardRequest, batchOptions: StandardHandlerInterceptorOptions<T>): StandardRequest;
|
|
21
|
-
/**
|
|
22
|
-
* Success batch response status code.
|
|
23
|
-
*
|
|
24
|
-
* @default 207
|
|
25
|
-
*/
|
|
26
|
-
successStatus?: Value<Promisable<number>, [
|
|
27
|
-
responses: Promise<BatchResponseBodyItem>[],
|
|
28
|
-
batchOptions: StandardHandlerInterceptorOptions<T>
|
|
29
|
-
]>;
|
|
30
|
-
/**
|
|
31
|
-
* success batch response headers.
|
|
32
|
-
*
|
|
33
|
-
* @default {}
|
|
34
|
-
*/
|
|
35
|
-
headers?: Value<Promisable<StandardHeaders>, [
|
|
36
|
-
responses: Promise<BatchResponseBodyItem>[],
|
|
37
|
-
batchOptions: StandardHandlerInterceptorOptions<T>
|
|
38
|
-
]>;
|
|
39
|
-
}
|
|
40
|
-
/**
|
|
41
|
-
* The Batch Requests Plugin allows you to combine multiple requests and responses into a single batch,
|
|
42
|
-
* reducing the overhead of sending each one separately.
|
|
43
|
-
*
|
|
44
|
-
* @see {@link https://orpc.unnoq.com/docs/plugins/batch-requests Batch Requests Plugin Docs}
|
|
45
|
-
*/
|
|
46
|
-
declare class BatchHandlerPlugin<T extends Context> implements StandardHandlerPlugin<T> {
|
|
47
|
-
private readonly maxSize;
|
|
48
|
-
private readonly mapRequestItem;
|
|
49
|
-
private readonly successStatus;
|
|
50
|
-
private readonly headers;
|
|
51
|
-
order: number;
|
|
52
|
-
constructor(options?: BatchHandlerOptions<T>);
|
|
53
|
-
init(options: StandardHandlerOptions<T>): void;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
6
|
interface CORSOptions<T extends Context> {
|
|
57
7
|
origin?: Value<Promisable<string | readonly string[] | null | undefined>, [
|
|
58
8
|
origin: string,
|
|
@@ -80,32 +30,6 @@ declare class CORSPlugin<T extends Context> implements StandardHandlerPlugin<T>
|
|
|
80
30
|
init(options: StandardHandlerOptions<T>): void;
|
|
81
31
|
}
|
|
82
32
|
|
|
83
|
-
interface RequestHeadersPluginContext {
|
|
84
|
-
reqHeaders?: Headers;
|
|
85
|
-
}
|
|
86
|
-
/**
|
|
87
|
-
* The Request Headers Plugin injects a `reqHeaders` instance into the context,
|
|
88
|
-
* allowing access to request headers in oRPC.
|
|
89
|
-
*
|
|
90
|
-
* @see {@link https://orpc.unnoq.com/docs/plugins/request-headers Request Headers Plugin Docs}
|
|
91
|
-
*/
|
|
92
|
-
declare class RequestHeadersPlugin<T extends RequestHeadersPluginContext> implements StandardHandlerPlugin<T> {
|
|
93
|
-
init(options: StandardHandlerOptions<T>): void;
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
interface ResponseHeadersPluginContext {
|
|
97
|
-
resHeaders?: Headers;
|
|
98
|
-
}
|
|
99
|
-
/**
|
|
100
|
-
* The Response Headers Plugin allows you to set response headers in oRPC.
|
|
101
|
-
* It injects a resHeaders instance into the context, enabling you to modify response headers easily.
|
|
102
|
-
*
|
|
103
|
-
* @see {@link https://orpc.unnoq.com/docs/plugins/response-headers Response Headers Plugin Docs}
|
|
104
|
-
*/
|
|
105
|
-
declare class ResponseHeadersPlugin<T extends ResponseHeadersPluginContext> implements StandardHandlerPlugin<T> {
|
|
106
|
-
init(options: StandardHandlerOptions<T>): void;
|
|
107
|
-
}
|
|
108
|
-
|
|
109
33
|
interface SimpleCsrfProtectionHandlerPluginOptions<T extends Context> {
|
|
110
34
|
/**
|
|
111
35
|
* The name of the header to check.
|
|
@@ -156,5 +80,5 @@ declare class SimpleCsrfProtectionHandlerPlugin<T extends Context> implements St
|
|
|
156
80
|
init(options: StandardHandlerOptions<T>): void;
|
|
157
81
|
}
|
|
158
82
|
|
|
159
|
-
export {
|
|
160
|
-
export type {
|
|
83
|
+
export { CORSPlugin, SimpleCsrfProtectionHandlerPlugin };
|
|
84
|
+
export type { CORSOptions, SimpleCsrfProtectionHandlerPluginOptions };
|