@temporary-name/server 1.9.3-alpha.76a5d8c6a7525b4b17df3f9565304645f0922ab3 → 1.9.3-alpha.76b43312556f455ccc88aeb67b7c37a426f74d5f
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 +20 -32
- package/dist/adapters/standard/index.d.ts +20 -32
- package/dist/adapters/standard/index.mjs +3 -3
- package/dist/index.d.mts +55 -103
- package/dist/index.d.ts +55 -103
- package/dist/index.mjs +41 -223
- 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 +4 -80
- package/dist/plugins/index.d.ts +4 -80
- package/dist/plugins/index.mjs +2 -168
- package/dist/shared/{server.ChraIVaQ.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.B9VxPdeK.mjs → server.BhH8PqLG.mjs} +57 -95
- package/dist/shared/server.C61o1Zch.mjs +413 -0
- package/dist/shared/{server.B15EEOr0.d.ts → server.D6Qs_UcF.d.mts} +2 -4
- package/dist/shared/{server.8gkXYsTZ.d.ts → server.DFptr1Nz.d.ts} +2 -2
- package/dist/shared/{server.YXplw8TW.d.mts → server.DpoO_ER_.d.ts} +2 -4
- package/dist/shared/{server.BEHw7Eyx.mjs → server.JtIZ8YG7.mjs} +1 -11
- package/package.json +10 -10
- package/dist/shared/server.CZNLCQBm.d.mts +0 -192
- package/dist/shared/server.CZNLCQBm.d.ts +0 -192
- package/dist/shared/server.DcfsPloY.mjs +0 -202
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.DcfsPloY.mjs';
|
|
7
|
-
export { L as LAZY_SYMBOL, a as createORPCErrorConstructorMap, m as mergeCurrentContext, b as middlewareOutputFn } from './shared/server.DcfsPloY.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.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';
|
|
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
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
87
|
+
query(schema) {
|
|
88
|
+
return new ProcedureBuilder({
|
|
89
|
+
...this["~orpc"],
|
|
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) {
|
|
266
98
|
return new ProcedureBuilder({
|
|
267
99
|
...this["~orpc"],
|
|
268
|
-
|
|
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
|
}
|
|
@@ -349,16 +187,6 @@ class BuilderWithMiddlewares extends ProcedureBuilder {
|
|
|
349
187
|
router(router) {
|
|
350
188
|
return enhanceRouter(router, this["~orpc"]);
|
|
351
189
|
}
|
|
352
|
-
/**
|
|
353
|
-
* Create a lazy router
|
|
354
|
-
* And applies all of the previously defined options to the specified router.
|
|
355
|
-
*
|
|
356
|
-
* @see {@link https://orpc.unnoq.com/docs/router#extending-router Extending Router Docs}
|
|
357
|
-
*/
|
|
358
|
-
lazyRoute(loader) {
|
|
359
|
-
const lazied = lazy(loader);
|
|
360
|
-
return enhanceRouter(lazied, this["~orpc"]);
|
|
361
|
-
}
|
|
362
190
|
}
|
|
363
191
|
|
|
364
192
|
function decorateMiddleware(middleware) {
|
|
@@ -427,6 +255,7 @@ function createApiBuilder(opts = {}) {
|
|
|
427
255
|
console.dir(error, { depth: null });
|
|
428
256
|
})
|
|
429
257
|
],
|
|
258
|
+
schemas: initialSchemas,
|
|
430
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
|
|
431
260
|
// the best solution). For now I've removed the interface to configure it externally.
|
|
432
261
|
dedupeLeadingMiddlewares: true
|
|
@@ -468,17 +297,6 @@ function implementerInternal(contract, middlewares) {
|
|
|
468
297
|
});
|
|
469
298
|
return setHiddenRouterContract(adapted, contract);
|
|
470
299
|
};
|
|
471
|
-
} else if (key === "lazyRoute") {
|
|
472
|
-
method = (loader) => {
|
|
473
|
-
const adapted = enhanceRouter(lazy(loader), {
|
|
474
|
-
middlewares,
|
|
475
|
-
errorMap: {},
|
|
476
|
-
prefix: void 0,
|
|
477
|
-
tags: void 0,
|
|
478
|
-
dedupeLeadingMiddlewares: true
|
|
479
|
-
});
|
|
480
|
-
return setHiddenRouterContract(adapted, contract);
|
|
481
|
-
};
|
|
482
300
|
}
|
|
483
301
|
const next = getContractRouter(target, [key]);
|
|
484
302
|
if (!next) {
|
|
@@ -520,7 +338,7 @@ function implement(contract) {
|
|
|
520
338
|
}
|
|
521
339
|
|
|
522
340
|
function createAssertedLazyProcedure(lazied) {
|
|
523
|
-
const lazyProcedure =
|
|
341
|
+
const lazyProcedure = lazyInternal(async () => {
|
|
524
342
|
const { default: maybeProcedure } = await unlazy(lazied);
|
|
525
343
|
if (!isProcedure(maybeProcedure)) {
|
|
526
344
|
throw new Error(`
|
|
@@ -571,4 +389,4 @@ function createRouterClient(router, ...rest) {
|
|
|
571
389
|
return recursive;
|
|
572
390
|
}
|
|
573
391
|
|
|
574
|
-
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);
|
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.YXplw8TW.mjs';
|
|
5
|
-
import { C as Context, E as ProcedureClientInterceptorOptions } from '../shared/server.CZNLCQBm.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 };
|