@temporary-name/server 1.9.3-alpha.62445d8d52a6787e7750865cd468fca8cccd3e28 → 1.9.3-alpha.6a70825f6d8c3dc99b87e4e5b778aea0fa007417
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/adapters/aws-lambda/index.d.mts +3 -3
- package/dist/adapters/aws-lambda/index.d.ts +3 -3
- package/dist/adapters/aws-lambda/index.mjs +4 -3
- 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 -3
- 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 -3
- package/dist/adapters/standard/index.d.mts +10 -5
- package/dist/adapters/standard/index.d.ts +10 -5
- package/dist/adapters/standard/index.mjs +4 -3
- package/dist/index.d.mts +51 -83
- package/dist/index.d.ts +51 -83
- package/dist/index.mjs +50 -213
- package/dist/openapi/index.d.mts +1 -1
- package/dist/openapi/index.d.ts +1 -1
- package/dist/openapi/index.mjs +52 -34
- package/dist/plugins/index.d.mts +2 -2
- package/dist/plugins/index.d.ts +2 -2
- package/dist/shared/{server.CT1xhSmE.d.mts → server.BCcLYvdF.d.mts} +1 -1
- package/dist/shared/server.CHV9AQHl.mjs +412 -0
- package/dist/shared/{server.cjcgLdr1.d.ts → server.CdeqmULw.d.ts} +1 -1
- package/dist/shared/{server.B93y_8tj.d.mts → server.DHezmW6C.d.mts} +2 -2
- package/dist/shared/server.DN9mVGfv.mjs +11 -0
- package/dist/shared/{server.CqTex_jI.mjs → server.DWwaAM-a.mjs} +13 -23
- package/dist/shared/{server.D_fags8X.d.ts → server.Da-qLzdU.d.ts} +2 -2
- package/dist/shared/{server.C3RuMHWl.d.mts → server.DecvGKtb.d.mts} +118 -68
- package/dist/shared/{server.C3RuMHWl.d.ts → server.DecvGKtb.d.ts} +118 -68
- 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/index.mjs
CHANGED
|
@@ -1,51 +1,12 @@
|
|
|
1
|
+
import { mergePrefix, mergeTags, ContractProcedure, mergeErrorMap, mergeMeta, mergeRoute, prefixRoute, initialSchemas, isContractProcedure, getContractRouter } from '@temporary-name/contract';
|
|
2
|
+
export { ValidationError, eventIterator, validateORPCError } from '@temporary-name/contract';
|
|
1
3
|
import { onError, resolveMaybeOptionalOptions } from '@temporary-name/shared';
|
|
2
4
|
export { AsyncIteratorClass, EventPublisher, ORPCError, asyncIteratorToStream as eventIteratorToStream, isDefinedError, onError, onFinish, onStart, onSuccess, safe, streamToAsyncIteratorClass as streamToEventIterator } from '@temporary-name/shared';
|
|
3
|
-
import {
|
|
4
|
-
export { ValidationError, eventIterator, validateORPCError } from '@temporary-name/contract';
|
|
5
|
-
import { SchemaClass, gatingContext } from '@temporary-name/zod';
|
|
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, core, object, gatingContext } from '@temporary-name/zod';
|
|
8
6
|
export { getEventMeta, withEventMeta } from '@temporary-name/standard-server';
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
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
|
-
}
|
|
7
|
+
import { g as getDynamicParams } from './shared/server.DN9mVGfv.mjs';
|
|
8
|
+
import { P as Procedure, c as createProcedureClient, e as enhanceRouter, a as addMiddleware, s as setHiddenRouterContract, l as lazyInternal, g as getLazyMeta, u as unlazy, i as isProcedure, b as isLazy, d as getRouter } from './shared/server.CHV9AQHl.mjs';
|
|
9
|
+
export { L as LAZY_SYMBOL, p as createAccessibleLazyRouter, f as createORPCErrorConstructorMap, o as getHiddenRouterContract, k as isStartWithMiddlewares, h as lazy, m as mergeCurrentContext, n as mergeMiddlewares, j as middlewareOutputFn, r as resolveContractProcedures, t as traverseContractProcedures, q as unlazyRouter } from './shared/server.CHV9AQHl.mjs';
|
|
49
10
|
|
|
50
11
|
class DecoratedProcedure extends Procedure {
|
|
51
12
|
/**
|
|
@@ -66,152 +27,6 @@ class DecoratedProcedure extends Procedure {
|
|
|
66
27
|
}
|
|
67
28
|
}
|
|
68
29
|
|
|
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
30
|
class ProcedureBuilder extends ContractProcedure {
|
|
216
31
|
z;
|
|
217
32
|
constructor(def) {
|
|
@@ -242,6 +57,27 @@ class ProcedureBuilder extends ContractProcedure {
|
|
|
242
57
|
meta: mergeMeta(this["~orpc"].meta, meta)
|
|
243
58
|
});
|
|
244
59
|
}
|
|
60
|
+
endpoint(endpoint, schema) {
|
|
61
|
+
const [method, path] = endpoint.split(" ", 2);
|
|
62
|
+
const pathParamNames = getDynamicParams(path)?.map((p) => p.name) ?? [];
|
|
63
|
+
if (schema && !(schema instanceof core.$ZodObject)) {
|
|
64
|
+
throw new Error(`Path schema for endpoint "${endpoint}" must be a ZodObject schema.`);
|
|
65
|
+
}
|
|
66
|
+
const schemaKeys = schema ? Object.keys(schema._zod.def.shape) : [];
|
|
67
|
+
if (pathParamNames.length !== schemaKeys.length || !pathParamNames.every((name) => schemaKeys.includes(name))) {
|
|
68
|
+
throw new Error(`Path schema keys do not match dynamic parameters in endpoint "${endpoint}".`);
|
|
69
|
+
}
|
|
70
|
+
const { prefix } = this["~orpc"];
|
|
71
|
+
const route = { method, path };
|
|
72
|
+
return new ProcedureBuilder({
|
|
73
|
+
...this["~orpc"],
|
|
74
|
+
route: mergeRoute(this["~orpc"].route, prefix ? prefixRoute(route, prefix) : route),
|
|
75
|
+
schemas: {
|
|
76
|
+
...this["~orpc"].schemas,
|
|
77
|
+
pathSchema: schema instanceof core.$ZodType ? schema : object(schema ?? {})
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
}
|
|
245
81
|
/**
|
|
246
82
|
* Sets or updates the route definition for the contract.
|
|
247
83
|
* The provided route is spared-merged with any existing route in the contract.
|
|
@@ -250,22 +86,30 @@ class ProcedureBuilder extends ContractProcedure {
|
|
|
250
86
|
* @see {@link https://orpc.unnoq.com/docs/openapi/routing OpenAPI Routing Docs}
|
|
251
87
|
* @see {@link https://orpc.unnoq.com/docs/openapi/input-output-structure OpenAPI Input/Output Structure Docs}
|
|
252
88
|
*/
|
|
253
|
-
|
|
89
|
+
endpointOpts(route) {
|
|
254
90
|
const { prefix } = this["~orpc"];
|
|
255
91
|
return new ProcedureBuilder({
|
|
256
92
|
...this["~orpc"],
|
|
257
93
|
route: mergeRoute(this["~orpc"].route, prefix ? prefixRoute(route, prefix) : route)
|
|
258
94
|
});
|
|
259
95
|
}
|
|
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) {
|
|
96
|
+
query(schema) {
|
|
266
97
|
return new ProcedureBuilder({
|
|
267
98
|
...this["~orpc"],
|
|
268
|
-
|
|
99
|
+
schemas: {
|
|
100
|
+
...this["~orpc"].schemas,
|
|
101
|
+
querySchema: schema instanceof core.$ZodType ? schema : object(schema)
|
|
102
|
+
},
|
|
103
|
+
inputValidationIndex: this["~orpc"].middlewares.length
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
body(schema) {
|
|
107
|
+
return new ProcedureBuilder({
|
|
108
|
+
...this["~orpc"],
|
|
109
|
+
schemas: {
|
|
110
|
+
...this["~orpc"].schemas,
|
|
111
|
+
bodySchema: schema instanceof core.$ZodType ? schema : object(schema)
|
|
112
|
+
},
|
|
269
113
|
inputValidationIndex: this["~orpc"].middlewares.length
|
|
270
114
|
});
|
|
271
115
|
}
|
|
@@ -277,7 +121,10 @@ class ProcedureBuilder extends ContractProcedure {
|
|
|
277
121
|
output(schema) {
|
|
278
122
|
return new ProcedureBuilder({
|
|
279
123
|
...this["~orpc"],
|
|
280
|
-
|
|
124
|
+
schemas: {
|
|
125
|
+
...this["~orpc"].schemas,
|
|
126
|
+
outputSchema: schema instanceof core.$ZodType ? schema : object(schema)
|
|
127
|
+
},
|
|
281
128
|
outputValidationIndex: this["~orpc"].middlewares.length
|
|
282
129
|
});
|
|
283
130
|
}
|
|
@@ -417,6 +264,7 @@ function createApiBuilder(opts = {}) {
|
|
|
417
264
|
console.dir(error, { depth: null });
|
|
418
265
|
})
|
|
419
266
|
],
|
|
267
|
+
schemas: initialSchemas,
|
|
420
268
|
// NB: this is a relic from orpc -- I'm not convinced there's a need for this (or if there is, that it's
|
|
421
269
|
// the best solution). For now I've removed the interface to configure it externally.
|
|
422
270
|
dedupeLeadingMiddlewares: true
|
|
@@ -458,17 +306,6 @@ function implementerInternal(contract, middlewares) {
|
|
|
458
306
|
});
|
|
459
307
|
return setHiddenRouterContract(adapted, contract);
|
|
460
308
|
};
|
|
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
309
|
}
|
|
473
310
|
const next = getContractRouter(target, [key]);
|
|
474
311
|
if (!next) {
|
|
@@ -510,7 +347,7 @@ function implement(contract) {
|
|
|
510
347
|
}
|
|
511
348
|
|
|
512
349
|
function createAssertedLazyProcedure(lazied) {
|
|
513
|
-
const lazyProcedure =
|
|
350
|
+
const lazyProcedure = lazyInternal(async () => {
|
|
514
351
|
const { default: maybeProcedure } = await unlazy(lazied);
|
|
515
352
|
if (!isProcedure(maybeProcedure)) {
|
|
516
353
|
throw new Error(`
|
|
@@ -561,4 +398,4 @@ function createRouterClient(router, ...rest) {
|
|
|
561
398
|
return recursive;
|
|
562
399
|
}
|
|
563
400
|
|
|
564
|
-
export { Builder, BuilderWithMiddlewares, DecoratedProcedure, Procedure, ProcedureBuilder, addMiddleware, call,
|
|
401
|
+
export { Builder, BuilderWithMiddlewares, DecoratedProcedure, Procedure, ProcedureBuilder, addMiddleware, call, createApiBuilder, createAssertedLazyProcedure, createContractedProcedure, createProcedureClient, createRouterClient, decorateMiddleware, enhanceRouter, getLazyMeta, getRouter, implement, implementerInternal, isLazy, isProcedure, lazyInternal, os, setHiddenRouterContract, unlazy };
|
package/dist/openapi/index.d.mts
CHANGED
|
@@ -55,7 +55,7 @@ interface SchemaConvertOptions {
|
|
|
55
55
|
minStructureDepthForRef?: number;
|
|
56
56
|
}
|
|
57
57
|
interface SchemaConverter {
|
|
58
|
-
convert(
|
|
58
|
+
convert(schemas: AnySchema | undefined, options: SchemaConvertOptions): Promisable<[required: boolean, jsonSchema: JSONSchema]>;
|
|
59
59
|
}
|
|
60
60
|
interface ConditionalSchemaConverter extends SchemaConverter {
|
|
61
61
|
condition(schema: AnySchema | undefined, options: SchemaConvertOptions): Promisable<boolean>;
|
package/dist/openapi/index.d.ts
CHANGED
|
@@ -55,7 +55,7 @@ interface SchemaConvertOptions {
|
|
|
55
55
|
minStructureDepthForRef?: number;
|
|
56
56
|
}
|
|
57
57
|
interface SchemaConverter {
|
|
58
|
-
convert(
|
|
58
|
+
convert(schemas: AnySchema | undefined, options: SchemaConvertOptions): Promisable<[required: boolean, jsonSchema: JSONSchema]>;
|
|
59
59
|
}
|
|
60
60
|
interface ConditionalSchemaConverter extends SchemaConverter {
|
|
61
61
|
condition(schema: AnySchema | undefined, options: SchemaConvertOptions): Promisable<boolean>;
|
package/dist/openapi/index.mjs
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { isProcedure, resolveContractProcedures, ORPCError, createRouterClient } from '@temporary-name/server';
|
|
2
2
|
import { fallbackContractConfig, 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
|
+
import { s as standardizeHTTPPath, g as getDynamicParams } from '../shared/server.DN9mVGfv.mjs';
|
|
6
7
|
import { TypeName } from '@temporary-name/interop/json-schema-typed/draft-2020-12';
|
|
7
8
|
export { ContentEncoding as JSONSchemaContentEncoding, Format as JSONSchemaFormat, TypeName as JSONSchemaTypeName } from '@temporary-name/interop/json-schema-typed/draft-2020-12';
|
|
8
9
|
|
|
@@ -530,60 +531,77 @@ ${errors.join("\n\n")}`
|
|
|
530
531
|
}
|
|
531
532
|
async #request(doc, ref, def, baseSchemaConvertOptions) {
|
|
532
533
|
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
534
|
const dynamicParams = getDynamicParams(def.route.path)?.map((v) => v.name);
|
|
545
|
-
|
|
535
|
+
const [_pathRequired, pathSchema] = await this.converter.convert(def.schemas.pathSchema, {
|
|
546
536
|
...baseSchemaConvertOptions,
|
|
547
537
|
strategy: "input",
|
|
548
|
-
minStructureDepthForRef:
|
|
538
|
+
minStructureDepthForRef: 1
|
|
549
539
|
});
|
|
550
|
-
if (isAnySchema(schema) && !dynamicParams?.length) {
|
|
551
|
-
return;
|
|
552
|
-
}
|
|
553
540
|
if (dynamicParams?.length) {
|
|
554
541
|
const error = new OpenAPIGeneratorError(
|
|
542
|
+
// TODO: fix this error
|
|
555
543
|
'When input structure is "compact", and path has dynamic params, input schema must be an object with all dynamic params as required.'
|
|
556
544
|
);
|
|
557
|
-
if (!isObjectSchema(
|
|
545
|
+
if (!isObjectSchema(pathSchema)) {
|
|
558
546
|
throw error;
|
|
559
547
|
}
|
|
560
|
-
|
|
561
|
-
schema = rest;
|
|
562
|
-
required = rest.required ? rest.required.length !== 0 : false;
|
|
563
|
-
if (!checkParamsSchema(paramsSchema, dynamicParams)) {
|
|
548
|
+
if (!checkParamsSchema(pathSchema, dynamicParams)) {
|
|
564
549
|
throw error;
|
|
565
550
|
}
|
|
566
551
|
ref.parameters ??= [];
|
|
567
|
-
ref.parameters.push(...toOpenAPIParameters(
|
|
552
|
+
ref.parameters.push(...toOpenAPIParameters(pathSchema, "path"));
|
|
553
|
+
} else {
|
|
554
|
+
const error = new OpenAPIGeneratorError("Params set via path do not match those on the route");
|
|
555
|
+
if (!isObjectSchema(pathSchema)) {
|
|
556
|
+
console.log("FOO", pathSchema);
|
|
557
|
+
throw error;
|
|
558
|
+
}
|
|
559
|
+
if (!checkParamsSchema(pathSchema, [])) {
|
|
560
|
+
console.log("BAR", pathSchema);
|
|
561
|
+
throw error;
|
|
562
|
+
}
|
|
568
563
|
}
|
|
569
|
-
|
|
570
|
-
|
|
564
|
+
const [_queryRequired, querySchema] = await this.converter.convert(def.schemas.querySchema, {
|
|
565
|
+
...baseSchemaConvertOptions,
|
|
566
|
+
strategy: "input",
|
|
567
|
+
minStructureDepthForRef: 0
|
|
568
|
+
});
|
|
569
|
+
if (!isAnySchema(querySchema)) {
|
|
570
|
+
const resolvedSchema = resolveOpenAPIJsonSchemaRef(doc, querySchema);
|
|
571
571
|
if (!isObjectSchema(resolvedSchema)) {
|
|
572
|
-
throw new OpenAPIGeneratorError(
|
|
573
|
-
'When method is "GET", input schema must satisfy: object | any | unknown'
|
|
574
|
-
);
|
|
572
|
+
throw new OpenAPIGeneratorError("Query param schema must satisfy: object | any | unknown");
|
|
575
573
|
}
|
|
576
574
|
ref.parameters ??= [];
|
|
577
575
|
ref.parameters.push(...toOpenAPIParameters(resolvedSchema, "query"));
|
|
578
|
-
}
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
576
|
+
}
|
|
577
|
+
if (method !== "GET") {
|
|
578
|
+
const details = getEventIteratorSchemaDetails(def.schemas.bodySchema);
|
|
579
|
+
if (details) {
|
|
580
|
+
ref.requestBody = {
|
|
581
|
+
required: true,
|
|
582
|
+
content: toOpenAPIEventIteratorContent(
|
|
583
|
+
await this.converter.convert(details.yields, { ...baseSchemaConvertOptions, strategy: "input" }),
|
|
584
|
+
await this.converter.convert(details.returns, { ...baseSchemaConvertOptions, strategy: "input" })
|
|
585
|
+
)
|
|
586
|
+
};
|
|
587
|
+
} else {
|
|
588
|
+
const [bodyRequired, bodySchema] = await this.converter.convert(def.schemas.bodySchema, {
|
|
589
|
+
...baseSchemaConvertOptions,
|
|
590
|
+
strategy: "input",
|
|
591
|
+
minStructureDepthForRef: 0
|
|
592
|
+
});
|
|
593
|
+
if (isAnySchema(bodySchema)) {
|
|
594
|
+
return;
|
|
595
|
+
}
|
|
596
|
+
ref.requestBody = {
|
|
597
|
+
required: bodyRequired,
|
|
598
|
+
content: toOpenAPIContent(bodySchema)
|
|
599
|
+
};
|
|
600
|
+
}
|
|
583
601
|
}
|
|
584
602
|
}
|
|
585
603
|
async #successResponse(doc, ref, def, baseSchemaConvertOptions) {
|
|
586
|
-
const outputSchema = def.outputSchema;
|
|
604
|
+
const outputSchema = def.schemas.outputSchema;
|
|
587
605
|
const status = fallbackContractConfig("defaultSuccessStatus", def.route.successStatus);
|
|
588
606
|
const description = fallbackContractConfig("defaultSuccessDescription", def.route?.successDescription);
|
|
589
607
|
const eventIteratorSchemaDetails = getEventIteratorSchemaDetails(outputSchema);
|
package/dist/plugins/index.d.mts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { Value, Promisable, ORPCError } from '@temporary-name/shared';
|
|
2
2
|
import { StandardRequest, StandardHeaders } from '@temporary-name/standard-server';
|
|
3
3
|
import { BatchResponseBodyItem } from '@temporary-name/standard-server/batch';
|
|
4
|
-
import { S as StandardHandlerInterceptorOptions, a as StandardHandlerPlugin, b as StandardHandlerOptions } from '../shared/server.
|
|
5
|
-
import { C as Context,
|
|
4
|
+
import { S as StandardHandlerInterceptorOptions, a as StandardHandlerPlugin, b as StandardHandlerOptions } from '../shared/server.BCcLYvdF.mjs';
|
|
5
|
+
import { C as Context, H as ProcedureClientInterceptorOptions } from '../shared/server.DecvGKtb.mjs';
|
|
6
6
|
import { Meta } from '@temporary-name/contract';
|
|
7
7
|
|
|
8
8
|
interface BatchHandlerOptions<T extends Context> {
|
package/dist/plugins/index.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { Value, Promisable, ORPCError } from '@temporary-name/shared';
|
|
2
2
|
import { StandardRequest, StandardHeaders } from '@temporary-name/standard-server';
|
|
3
3
|
import { BatchResponseBodyItem } from '@temporary-name/standard-server/batch';
|
|
4
|
-
import { S as StandardHandlerInterceptorOptions, a as StandardHandlerPlugin, b as StandardHandlerOptions } from '../shared/server.
|
|
5
|
-
import { C as Context,
|
|
4
|
+
import { S as StandardHandlerInterceptorOptions, a as StandardHandlerPlugin, b as StandardHandlerOptions } from '../shared/server.CdeqmULw.js';
|
|
5
|
+
import { C as Context, H as ProcedureClientInterceptorOptions } from '../shared/server.DecvGKtb.js';
|
|
6
6
|
import { Meta } from '@temporary-name/contract';
|
|
7
7
|
|
|
8
8
|
interface BatchHandlerOptions<T extends Context> {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Meta } from '@temporary-name/contract';
|
|
2
2
|
import { HTTPPath, Interceptor } from '@temporary-name/shared';
|
|
3
3
|
import { StandardLazyRequest, StandardResponse } from '@temporary-name/standard-server';
|
|
4
|
-
import { C as Context, R as Router,
|
|
4
|
+
import { C as Context, R as Router, H as ProcedureClientInterceptorOptions } from './server.DecvGKtb.mjs';
|
|
5
5
|
|
|
6
6
|
interface StandardHandlerPlugin<T extends Context> {
|
|
7
7
|
order?: number;
|