@temporary-name/server 1.9.3-alpha.e098b3d1c5bffbad2fadfda89ba01f6452db46b5 → 1.9.3-alpha.ec3bfb9dce56198911349c322c970208b21b50db
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 +4 -5
- package/dist/adapters/aws-lambda/index.d.ts +4 -5
- package/dist/adapters/aws-lambda/index.mjs +4 -4
- package/dist/adapters/fetch/index.d.mts +8 -85
- package/dist/adapters/fetch/index.d.ts +8 -85
- package/dist/adapters/fetch/index.mjs +16 -155
- package/dist/adapters/node/index.d.mts +8 -62
- package/dist/adapters/node/index.d.ts +8 -62
- package/dist/adapters/node/index.mjs +14 -120
- package/dist/adapters/standard/index.d.mts +5 -6
- package/dist/adapters/standard/index.d.ts +5 -6
- package/dist/adapters/standard/index.mjs +4 -4
- package/dist/helpers/index.mjs +3 -29
- package/dist/index.d.mts +110 -199
- package/dist/index.d.ts +110 -199
- package/dist/index.mjs +140 -153
- package/dist/openapi/index.d.mts +11 -27
- package/dist/openapi/index.d.ts +11 -27
- package/dist/openapi/index.mjs +9 -79
- package/dist/shared/server.C1RJffw4.mjs +30 -0
- package/dist/shared/server.CQIFwyhc.mjs +40 -0
- package/dist/shared/server.CVhIyQ4x.d.mts +41 -0
- package/dist/shared/server.CYa9puL2.mjs +403 -0
- package/dist/shared/server.ChOv1yG3.mjs +319 -0
- package/dist/shared/server.Cj3_Lp61.d.mts +373 -0
- package/dist/shared/server.Cj3_Lp61.d.ts +373 -0
- package/dist/shared/server.Cza0RB3u.mjs +160 -0
- package/dist/shared/server.D8RAzJ_p.d.ts +41 -0
- package/dist/shared/server.YUvuxHty.mjs +48 -0
- package/package.json +10 -28
- package/dist/plugins/index.d.mts +0 -110
- package/dist/plugins/index.d.ts +0 -110
- package/dist/plugins/index.mjs +0 -175
- package/dist/shared/server.7aL9gcoU.d.mts +0 -23
- package/dist/shared/server.BL2R5jcp.d.mts +0 -228
- package/dist/shared/server.BL2R5jcp.d.ts +0 -228
- package/dist/shared/server.CVBLzkro.mjs +0 -255
- package/dist/shared/server.ClhVCxfg.mjs +0 -413
- package/dist/shared/server.D6Qs_UcF.d.mts +0 -55
- package/dist/shared/server.DFptr1Nz.d.ts +0 -23
- package/dist/shared/server.DpoO_ER_.d.ts +0 -55
- package/dist/shared/server.JtIZ8YG7.mjs +0 -237
package/dist/index.mjs
CHANGED
|
@@ -1,11 +1,70 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export {
|
|
3
|
-
import
|
|
4
|
-
export { AsyncIteratorClass, EventPublisher, ORPCError, asyncIteratorToStream as eventIteratorToStream, isDefinedError, onError, onFinish, onStart, onSuccess, safe, streamToAsyncIteratorClass as streamToEventIterator } from '@temporary-name/shared';
|
|
1
|
+
import { assertNever, splitFirst, ORPCError, onError, resolveMaybeOptionalOptions, isTypescriptObject, isPropertyKey } from '@temporary-name/shared';
|
|
2
|
+
export { AsyncIteratorClass, EventPublisher, ORPCError, asyncIteratorToStream as eventIteratorToStream, isDefinedError, onError, onFinish, onStart, onSuccess, streamToAsyncIteratorClass as streamToEventIterator } from '@temporary-name/shared';
|
|
3
|
+
import * as z from '@temporary-name/zod';
|
|
5
4
|
import { SchemaClass, object, core, gatingContext } from '@temporary-name/zod';
|
|
6
|
-
import {
|
|
7
|
-
|
|
5
|
+
import { g as getCookie } from './shared/server.C1RJffw4.mjs';
|
|
6
|
+
import { P as Procedure, m as mergePrefix, a as mergeTags, e as enhanceRouter, C as Contract, p as parseEndpointDefinition, b as mergeRoute, c as prefixRoute, d as addMiddleware, l as lazyInternal, f as getLazyMeta, u as unlazy, i as isProcedure, h as isLazy, j as getRouter } from './shared/server.ChOv1yG3.mjs';
|
|
7
|
+
export { L as LAZY_SYMBOL, V as ValidationError, q as createAccessibleLazyRouter, w as endpointRegex, g as getDynamicParams, n as isStartWithMiddlewares, k as lazy, o as mergeMiddlewares, r as resolveContractProcedures, s as standardizeHTTPPath, t as traverseContractProcedures, v as unlazyRouter } from './shared/server.ChOv1yG3.mjs';
|
|
8
|
+
import { c as createProcedureClient } from './shared/server.Cza0RB3u.mjs';
|
|
9
|
+
export { m as mergeCurrentContext, a as middlewareOutputFn } from './shared/server.Cza0RB3u.mjs';
|
|
10
|
+
export { e as eventIterator, g as getEventIteratorSchemaDetails } from './shared/server.YUvuxHty.mjs';
|
|
8
11
|
export { getEventMeta, withEventMeta } from '@temporary-name/standard-server';
|
|
12
|
+
import 'cookie';
|
|
13
|
+
|
|
14
|
+
function validateTokenPrefix(prefix, token) {
|
|
15
|
+
if (prefix && !token.startsWith(prefix)) {
|
|
16
|
+
throw new ORPCError("UNAUTHORIZED", { message: `Invalid auth token. It must start with "${prefix}"` });
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
function validateTokenAuth(config, token, options) {
|
|
20
|
+
const { tokenPrefix, validate } = config;
|
|
21
|
+
validateTokenPrefix(tokenPrefix, token);
|
|
22
|
+
return validate(token, options);
|
|
23
|
+
}
|
|
24
|
+
function authByQuery(config, options) {
|
|
25
|
+
const { name, tokenPrefix, validate } = config;
|
|
26
|
+
const query = options.request.url.searchParams;
|
|
27
|
+
const token = query.get(name);
|
|
28
|
+
if (!token) return void 0;
|
|
29
|
+
validateTokenPrefix(tokenPrefix, token);
|
|
30
|
+
return validate(token, options);
|
|
31
|
+
}
|
|
32
|
+
function authByHeader(config, options) {
|
|
33
|
+
const authHeader = options.request.headers.get(config.name);
|
|
34
|
+
return authHeader ? validateTokenAuth(config, authHeader, options) : void 0;
|
|
35
|
+
}
|
|
36
|
+
function authByCookie(config, options) {
|
|
37
|
+
const cookie = getCookie(options.request.headers, config.name);
|
|
38
|
+
return cookie ? validateTokenAuth(config, cookie, options) : void 0;
|
|
39
|
+
}
|
|
40
|
+
function authByBearer(config, options) {
|
|
41
|
+
const authHeader = options.request.headers.get("Authorization");
|
|
42
|
+
if (!authHeader) return void 0;
|
|
43
|
+
const [authType, bearer] = splitFirst(authHeader, " ");
|
|
44
|
+
return authType === "Bearer" ? validateTokenAuth(config, bearer, options) : void 0;
|
|
45
|
+
}
|
|
46
|
+
function authByBasic(config, options) {
|
|
47
|
+
const authHeader = options.request.headers.get("Authorization");
|
|
48
|
+
if (!authHeader) return void 0;
|
|
49
|
+
const [authType, encoded] = splitFirst(authHeader, " ");
|
|
50
|
+
if (authType !== "Basic") return void 0;
|
|
51
|
+
const decoded = Buffer.from(encoded, "base64").toString("utf-8");
|
|
52
|
+
const [username, password] = splitFirst(decoded, ":");
|
|
53
|
+
validateTokenPrefix(config.tokenPrefix, password);
|
|
54
|
+
return config.validate(username, password, options);
|
|
55
|
+
}
|
|
56
|
+
function authByType(config, options) {
|
|
57
|
+
const { type } = config;
|
|
58
|
+
return type === "header" ? authByHeader(config, options) : type === "query" ? authByQuery(config, options) : type === "cookie" ? authByCookie(config, options) : type === "bearer" ? authByBearer(config, options) : type === "basic" ? authByBasic(config, options) : type === "none" ? false : assertNever(type);
|
|
59
|
+
}
|
|
60
|
+
function authDescription(config) {
|
|
61
|
+
const { type } = config;
|
|
62
|
+
return type === "basic" ? "a Basic Authentication header" : type === "bearer" ? "a Bearer Authentication header" : type === "header" ? `a header named "${config.name}"` : type === "query" ? `a query parameter named "${config.name}"` : type === "cookie" ? `a cookie named "${config.name}"` : type === "none" ? "no authentication" : assertNever(type);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
function mergeMeta(meta1, meta2) {
|
|
66
|
+
return { ...meta1, ...meta2 };
|
|
67
|
+
}
|
|
9
68
|
|
|
10
69
|
class DecoratedProcedure extends Procedure {
|
|
11
70
|
/**
|
|
@@ -26,24 +85,19 @@ class DecoratedProcedure extends Procedure {
|
|
|
26
85
|
}
|
|
27
86
|
}
|
|
28
87
|
|
|
29
|
-
|
|
88
|
+
const initialSchemas = {
|
|
89
|
+
pathSchema: z.strictObject({}),
|
|
90
|
+
querySchema: z.strictObject({}),
|
|
91
|
+
bodySchema: z.strictObject({}),
|
|
92
|
+
outputSchema: z.unknown()
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
class ProcedureBuilder extends Contract {
|
|
30
96
|
z;
|
|
31
97
|
constructor(def) {
|
|
32
98
|
super(def);
|
|
33
99
|
this.z = new SchemaClass();
|
|
34
100
|
}
|
|
35
|
-
/**
|
|
36
|
-
* Adds type-safe custom errors to the contract.
|
|
37
|
-
* The provided errors are spared-merged with any existing errors in the contract.
|
|
38
|
-
*
|
|
39
|
-
* @see {@link https://orpc.unnoq.com/docs/error-handling#type%E2%80%90safe-error-handling Type-Safe Error Handling Docs}
|
|
40
|
-
*/
|
|
41
|
-
errors(errors) {
|
|
42
|
-
return new ProcedureBuilder({
|
|
43
|
-
...this["~orpc"],
|
|
44
|
-
errorMap: mergeErrorMap(this["~orpc"].errorMap, errors)
|
|
45
|
-
});
|
|
46
|
-
}
|
|
47
101
|
/**
|
|
48
102
|
* Sets or updates the metadata for the contract.
|
|
49
103
|
* The provided metadata is spared-merged with any existing metadata in the contract.
|
|
@@ -119,19 +173,42 @@ class ProcedureBuilder extends ContractProcedure {
|
|
|
119
173
|
outputValidationIndex: this["~orpc"].middlewares.length
|
|
120
174
|
});
|
|
121
175
|
}
|
|
122
|
-
/**
|
|
123
|
-
* Uses a middleware to modify the context or improve the pipeline.
|
|
124
|
-
*
|
|
125
|
-
* @info Supports both normal middleware and inline middleware implementations.
|
|
126
|
-
* @note The current context must be satisfy middleware dependent-context
|
|
127
|
-
* @see {@link https://orpc.unnoq.com/docs/middleware Middleware Docs}
|
|
128
|
-
*/
|
|
129
176
|
use(middleware) {
|
|
130
177
|
return new this.constructor({
|
|
131
178
|
...this["~orpc"],
|
|
132
179
|
middlewares: addMiddleware(this["~orpc"].middlewares, middleware)
|
|
133
180
|
});
|
|
134
181
|
}
|
|
182
|
+
// `& {}` is so AuthType will be expanded in parameter info tooltips.
|
|
183
|
+
// The default of false for ValidatedAuthContext is used when you pass in the type 'none'. We use false
|
|
184
|
+
// because we can't use null or undefined (see ValidatedAuthContext) but we still want it to be falsy.
|
|
185
|
+
useAuth(type, ...rest) {
|
|
186
|
+
const config = { type, ...rest[0] };
|
|
187
|
+
const middleware = baseApi.$context().middleware(async (options) => {
|
|
188
|
+
const { next, context } = options;
|
|
189
|
+
if (context.auth) return next();
|
|
190
|
+
const auth = await authByType(config, options);
|
|
191
|
+
if (auth === void 0) {
|
|
192
|
+
const { authConfigs } = options.procedure["~orpc"];
|
|
193
|
+
if (context.auth !== false && config === authConfigs.at(-1)) {
|
|
194
|
+
let authDescriptions = authConfigs.map(authDescription).join(", ");
|
|
195
|
+
if (authConfigs.length > 1) {
|
|
196
|
+
authDescriptions = `one of: ${authDescriptions}`;
|
|
197
|
+
}
|
|
198
|
+
throw new ORPCError("UNAUTHORIZED", {
|
|
199
|
+
message: `Authentication required. You must provide ${authDescriptions}`
|
|
200
|
+
});
|
|
201
|
+
}
|
|
202
|
+
return next();
|
|
203
|
+
}
|
|
204
|
+
return next({ context: { auth } });
|
|
205
|
+
});
|
|
206
|
+
return new this.constructor({
|
|
207
|
+
...this["~orpc"],
|
|
208
|
+
authConfigs: [...this["~orpc"].authConfigs, config],
|
|
209
|
+
middlewares: addMiddleware(this["~orpc"].middlewares, middleware)
|
|
210
|
+
});
|
|
211
|
+
}
|
|
135
212
|
useGating(gates, isGateEnabled) {
|
|
136
213
|
return this.use(({ next, context }) => {
|
|
137
214
|
return gatingContext.run(
|
|
@@ -146,6 +223,9 @@ class ProcedureBuilder extends ContractProcedure {
|
|
|
146
223
|
* @see {@link https://orpc.unnoq.com/docs/procedure Procedure Docs}
|
|
147
224
|
*/
|
|
148
225
|
handler(handler) {
|
|
226
|
+
if (this["~orpc"].schemas.outputSchema === initialSchemas.outputSchema) {
|
|
227
|
+
throw new Error("You must call .output() before calling .handler()");
|
|
228
|
+
}
|
|
149
229
|
return new DecoratedProcedure({
|
|
150
230
|
...this["~orpc"],
|
|
151
231
|
handler
|
|
@@ -197,31 +277,6 @@ function decorateMiddleware(middleware) {
|
|
|
197
277
|
);
|
|
198
278
|
return mapped;
|
|
199
279
|
};
|
|
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
280
|
return decorated;
|
|
226
281
|
}
|
|
227
282
|
|
|
@@ -243,99 +298,22 @@ class Builder extends BuilderWithMiddlewares {
|
|
|
243
298
|
return decorateMiddleware(middleware);
|
|
244
299
|
}
|
|
245
300
|
}
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
});
|
|
263
|
-
}
|
|
264
|
-
const os = createApiBuilder();
|
|
265
|
-
|
|
266
|
-
function implementerInternal(contract, middlewares) {
|
|
267
|
-
if (isContractProcedure(contract)) {
|
|
268
|
-
const impl2 = new Builder({
|
|
269
|
-
...contract["~orpc"],
|
|
270
|
-
middlewares,
|
|
271
|
-
inputValidationIndex: middlewares.length,
|
|
272
|
-
outputValidationIndex: middlewares.length,
|
|
273
|
-
dedupeLeadingMiddlewares: true
|
|
274
|
-
});
|
|
275
|
-
return impl2;
|
|
276
|
-
}
|
|
277
|
-
const impl = new Proxy(contract, {
|
|
278
|
-
get: (target, key) => {
|
|
279
|
-
if (typeof key !== "string") {
|
|
280
|
-
return Reflect.get(target, key);
|
|
281
|
-
}
|
|
282
|
-
let method;
|
|
283
|
-
if (key === "middleware") {
|
|
284
|
-
method = (mid) => decorateMiddleware(mid);
|
|
285
|
-
} else if (key === "use") {
|
|
286
|
-
method = (mid) => {
|
|
287
|
-
return implementerInternal(contract, addMiddleware(middlewares, mid));
|
|
288
|
-
};
|
|
289
|
-
} else if (key === "router") {
|
|
290
|
-
method = (router) => {
|
|
291
|
-
const adapted = enhanceRouter(router, {
|
|
292
|
-
middlewares,
|
|
293
|
-
errorMap: {},
|
|
294
|
-
prefix: void 0,
|
|
295
|
-
tags: void 0,
|
|
296
|
-
dedupeLeadingMiddlewares: true
|
|
297
|
-
});
|
|
298
|
-
return setHiddenRouterContract(adapted, contract);
|
|
299
|
-
};
|
|
300
|
-
}
|
|
301
|
-
const next = getContractRouter(target, [key]);
|
|
302
|
-
if (!next) {
|
|
303
|
-
return method ?? next;
|
|
304
|
-
}
|
|
305
|
-
const nextImpl = implementerInternal(next, middlewares);
|
|
306
|
-
if (method) {
|
|
307
|
-
return new Proxy(method, {
|
|
308
|
-
get(_, key2) {
|
|
309
|
-
return Reflect.get(nextImpl, key2);
|
|
310
|
-
}
|
|
311
|
-
});
|
|
312
|
-
}
|
|
313
|
-
return nextImpl;
|
|
314
|
-
}
|
|
315
|
-
});
|
|
316
|
-
return impl;
|
|
317
|
-
}
|
|
318
|
-
function implement(contract) {
|
|
319
|
-
const implInternal = implementerInternal(contract, []);
|
|
320
|
-
const impl = new Proxy(implInternal, {
|
|
321
|
-
get: (target, key) => {
|
|
322
|
-
let method;
|
|
323
|
-
if (key === "$context") {
|
|
324
|
-
method = () => impl;
|
|
325
|
-
}
|
|
326
|
-
const next = Reflect.get(target, key);
|
|
327
|
-
if (!method || !next || typeof next !== "function" && typeof next !== "object") {
|
|
328
|
-
return method || next;
|
|
329
|
-
}
|
|
330
|
-
return new Proxy(method, {
|
|
331
|
-
get(_, key2) {
|
|
332
|
-
return Reflect.get(next, key2);
|
|
333
|
-
}
|
|
334
|
-
});
|
|
335
|
-
}
|
|
336
|
-
});
|
|
337
|
-
return impl;
|
|
338
|
-
}
|
|
301
|
+
const baseApi = new Builder({
|
|
302
|
+
route: {},
|
|
303
|
+
meta: {},
|
|
304
|
+
inputValidationIndex: 0,
|
|
305
|
+
outputValidationIndex: 0,
|
|
306
|
+
middlewares: [
|
|
307
|
+
onError((error, _options) => {
|
|
308
|
+
console.dir(error, { depth: null });
|
|
309
|
+
})
|
|
310
|
+
],
|
|
311
|
+
schemas: initialSchemas,
|
|
312
|
+
// NB: this is a relic from orpc -- I'm not convinced there's a need for this (or if there is, that it's
|
|
313
|
+
// the best solution). For now I've removed the interface to configure it externally.
|
|
314
|
+
dedupeLeadingMiddlewares: true,
|
|
315
|
+
authConfigs: []
|
|
316
|
+
});
|
|
339
317
|
|
|
340
318
|
function createAssertedLazyProcedure(lazied) {
|
|
341
319
|
const lazyProcedure = lazyInternal(async () => {
|
|
@@ -351,14 +329,6 @@ function createAssertedLazyProcedure(lazied) {
|
|
|
351
329
|
}, getLazyMeta(lazied));
|
|
352
330
|
return lazyProcedure;
|
|
353
331
|
}
|
|
354
|
-
function createContractedProcedure(procedure, contract) {
|
|
355
|
-
return new Procedure({
|
|
356
|
-
...procedure["~orpc"],
|
|
357
|
-
errorMap: contract["~orpc"].errorMap,
|
|
358
|
-
route: contract["~orpc"].route,
|
|
359
|
-
meta: contract["~orpc"].meta
|
|
360
|
-
});
|
|
361
|
-
}
|
|
362
332
|
function call(procedure, input, ...rest) {
|
|
363
333
|
const options = resolveMaybeOptionalOptions(rest);
|
|
364
334
|
return createProcedureClient(procedure, options)(input, options);
|
|
@@ -389,4 +359,21 @@ function createRouterClient(router, ...rest) {
|
|
|
389
359
|
return recursive;
|
|
390
360
|
}
|
|
391
361
|
|
|
392
|
-
|
|
362
|
+
function isSchemaIssue(issue) {
|
|
363
|
+
if (!isTypescriptObject(issue) || typeof issue.message !== "string") {
|
|
364
|
+
return false;
|
|
365
|
+
}
|
|
366
|
+
if (issue.path !== void 0) {
|
|
367
|
+
if (!Array.isArray(issue.path)) {
|
|
368
|
+
return false;
|
|
369
|
+
}
|
|
370
|
+
if (!issue.path.every(
|
|
371
|
+
(segment) => isPropertyKey(segment) || isTypescriptObject(segment) && isPropertyKey(segment.key)
|
|
372
|
+
)) {
|
|
373
|
+
return false;
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
return true;
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
export { Builder, BuilderWithMiddlewares, Contract, DecoratedProcedure, Procedure, ProcedureBuilder, addMiddleware, baseApi, call, createAssertedLazyProcedure, createProcedureClient, createRouterClient, decorateMiddleware, enhanceRouter, getLazyMeta, getRouter, initialSchemas, isLazy, isProcedure, isSchemaIssue, lazyInternal, mergeMeta, parseEndpointDefinition, unlazy };
|
package/dist/openapi/index.d.mts
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
import {
|
|
1
|
+
import { Contract } from '@temporary-name/server';
|
|
2
|
+
import { OpenAPI, Promisable, Value, HTTPPath, HTTPMethod } from '@temporary-name/shared';
|
|
3
|
+
export { OpenAPI } from '@temporary-name/shared';
|
|
4
|
+
import { d as AnySchema, b as Contract$1, ab as TraverseContractProcedureCallbackOptions, a1 as ContractRouter, v as AnyRouter } from '../shared/server.Cj3_Lp61.mjs';
|
|
5
5
|
import { JSONSchema } from '@temporary-name/interop/json-schema-typed/draft-2020-12';
|
|
6
6
|
export { JSONSchema, ContentEncoding as JSONSchemaContentEncoding, Format as JSONSchemaFormat, TypeName as JSONSchemaTypeName } from '@temporary-name/interop/json-schema-typed/draft-2020-12';
|
|
7
|
+
import '@temporary-name/zod';
|
|
7
8
|
|
|
8
|
-
type OverrideOperationValue = Partial<OpenAPI.OperationObject> | ((current: OpenAPI.OperationObject, procedure:
|
|
9
|
+
type OverrideOperationValue = Partial<OpenAPI.OperationObject> | ((current: OpenAPI.OperationObject, procedure: Contract) => OpenAPI.OperationObject);
|
|
9
10
|
/**
|
|
10
11
|
* Customize The Operation Object by proxy an error map item or a middleware.
|
|
11
12
|
*
|
|
@@ -13,7 +14,7 @@ type OverrideOperationValue = Partial<OpenAPI.OperationObject> | ((current: Open
|
|
|
13
14
|
*/
|
|
14
15
|
declare function customOpenAPIOperation<T extends object>(o: T, extend: OverrideOperationValue): T;
|
|
15
16
|
declare function getCustomOpenAPIOperation(o: object): OverrideOperationValue | undefined;
|
|
16
|
-
declare function applyCustomOpenAPIOperation(operation: OpenAPI.OperationObject, contract:
|
|
17
|
+
declare function applyCustomOpenAPIOperation(operation: OpenAPI.OperationObject, contract: Contract): OpenAPI.OperationObject;
|
|
17
18
|
|
|
18
19
|
/**
|
|
19
20
|
* @internal
|
|
@@ -76,7 +77,7 @@ interface OpenAPIGeneratorGenerateOptions extends Partial<Omit<OpenAPI.Document,
|
|
|
76
77
|
* @deprecated Use `filter` option instead.
|
|
77
78
|
* @default () => false
|
|
78
79
|
*/
|
|
79
|
-
exclude?: (procedure:
|
|
80
|
+
exclude?: (procedure: Contract$1, path: readonly string[]) => boolean;
|
|
80
81
|
/**
|
|
81
82
|
* Filter procedures. Return `false` to exclude a procedure from the OpenAPI specification.
|
|
82
83
|
*
|
|
@@ -129,7 +130,7 @@ declare class OpenAPIGenerator {
|
|
|
129
130
|
*
|
|
130
131
|
* @see {@link https://orpc.unnoq.com/docs/openapi/openapi-specification OpenAPI Specification Docs}
|
|
131
132
|
*/
|
|
132
|
-
generate(router:
|
|
133
|
+
generate(router: ContractRouter | AnyRouter, options?: OpenAPIGeneratorGenerateOptions): Promise<OpenAPI.Document>;
|
|
133
134
|
}
|
|
134
135
|
|
|
135
136
|
/**
|
|
@@ -162,23 +163,6 @@ declare function checkParamsSchema(schema: ObjectSchema, params: string[]): bool
|
|
|
162
163
|
declare function toOpenAPISchema(schema: JSONSchema): OpenAPI.SchemaObject & object;
|
|
163
164
|
declare function resolveOpenAPIJsonSchemaRef(doc: OpenAPI.Document, schema: JSONSchema): JSONSchema;
|
|
164
165
|
|
|
165
|
-
type JsonifiedValue<T> = T extends string ? T : T extends number ? T : T extends boolean ? T : T extends null ? T : T extends undefined ? T : T extends Array<unknown> ? JsonifiedArray<T> : T extends Record<string, unknown> ? {
|
|
166
|
-
[K in keyof T]: JsonifiedValue<T[K]>;
|
|
167
|
-
} : T extends Date ? string : T extends bigint ? string : T extends File ? File : T extends Blob ? Blob : T extends RegExp ? string : T extends URL ? string : T extends Map<infer K, infer V> ? JsonifiedArray<[K, V][]> : T extends Set<infer U> ? JsonifiedArray<U[]> : T extends AsyncIteratorObject<infer U, infer V> ? AsyncIteratorObject<JsonifiedValue<U>, JsonifiedValue<V>> : unknown;
|
|
168
|
-
type JsonifiedArray<T extends Array<unknown>> = T extends readonly [] ? [] : T extends readonly [infer U, ...infer V] ? [
|
|
169
|
-
U extends undefined ? null : JsonifiedValue<U>,
|
|
170
|
-
...JsonifiedArray<V>
|
|
171
|
-
] : T extends Array<infer U> ? Array<JsonifiedValue<U>> : unknown;
|
|
172
|
-
/**
|
|
173
|
-
* Convert types that JSON not support to corresponding json types
|
|
174
|
-
*
|
|
175
|
-
* @see {@link https://orpc.unnoq.com/docs/openapi/client/openapi-link OpenAPI Link Docs}
|
|
176
|
-
*/
|
|
177
|
-
type JsonifiedClient<T extends NestedClient<any>> = T extends Client<infer UClientContext, infer UInput, infer UOutput, infer UError> ? Client<UClientContext, UInput, JsonifiedValue<UOutput>, UError extends ORPCError<infer UCode, infer UData> ? ORPCError<UCode, JsonifiedValue<UData>> : UError> : {
|
|
178
|
-
[K in keyof T]: T[K] extends NestedClient<any> ? JsonifiedClient<T[K]> : T[K];
|
|
179
|
-
};
|
|
180
|
-
declare function createJsonifiedRouterClient<T extends AnyRouter, TClientContext extends ClientContext>(router: Lazyable<T | undefined>, ...rest: MaybeOptionalOptions<CreateProcedureClientOptions<InferRouterInitialContext<T>, Schema<unknown, unknown>, ErrorMap, Meta, TClientContext>>): JsonifiedClient<RouterClient<T, TClientContext>>;
|
|
181
|
-
|
|
182
166
|
/**
|
|
183
167
|
*@internal
|
|
184
168
|
*/
|
|
@@ -216,5 +200,5 @@ declare const oo: {
|
|
|
216
200
|
spec: typeof customOpenAPIOperation;
|
|
217
201
|
};
|
|
218
202
|
|
|
219
|
-
export { CompositeSchemaConverter, LOGIC_KEYWORDS, OpenAPIGenerator, applyCustomOpenAPIOperation, applySchemaOptionality, checkParamsSchema,
|
|
220
|
-
export type { ConditionalSchemaConverter, FileSchema,
|
|
203
|
+
export { CompositeSchemaConverter, LOGIC_KEYWORDS, OpenAPIGenerator, applyCustomOpenAPIOperation, applySchemaOptionality, checkParamsSchema, customOpenAPIOperation, expandArrayableSchema, expandUnionSchema, filterSchemaBranches, getCustomOpenAPIOperation, isAnySchema, isFileSchema, isObjectSchema, isPrimitiveSchema, oo, resolveOpenAPIJsonSchemaRef, separateObjectSchema, toOpenAPIContent, toOpenAPIEventIteratorContent, toOpenAPIMethod, toOpenAPIParameters, toOpenAPIPath, toOpenAPISchema };
|
|
204
|
+
export type { ConditionalSchemaConverter, FileSchema, ObjectSchema, OpenAPIGeneratorGenerateOptions, OpenAPIGeneratorOptions, OverrideOperationValue, SchemaConvertOptions, SchemaConverter, SchemaConverterComponent };
|
package/dist/openapi/index.d.ts
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
import {
|
|
1
|
+
import { Contract } from '@temporary-name/server';
|
|
2
|
+
import { OpenAPI, Promisable, Value, HTTPPath, HTTPMethod } from '@temporary-name/shared';
|
|
3
|
+
export { OpenAPI } from '@temporary-name/shared';
|
|
4
|
+
import { d as AnySchema, b as Contract$1, ab as TraverseContractProcedureCallbackOptions, a1 as ContractRouter, v as AnyRouter } from '../shared/server.Cj3_Lp61.js';
|
|
5
5
|
import { JSONSchema } from '@temporary-name/interop/json-schema-typed/draft-2020-12';
|
|
6
6
|
export { JSONSchema, ContentEncoding as JSONSchemaContentEncoding, Format as JSONSchemaFormat, TypeName as JSONSchemaTypeName } from '@temporary-name/interop/json-schema-typed/draft-2020-12';
|
|
7
|
+
import '@temporary-name/zod';
|
|
7
8
|
|
|
8
|
-
type OverrideOperationValue = Partial<OpenAPI.OperationObject> | ((current: OpenAPI.OperationObject, procedure:
|
|
9
|
+
type OverrideOperationValue = Partial<OpenAPI.OperationObject> | ((current: OpenAPI.OperationObject, procedure: Contract) => OpenAPI.OperationObject);
|
|
9
10
|
/**
|
|
10
11
|
* Customize The Operation Object by proxy an error map item or a middleware.
|
|
11
12
|
*
|
|
@@ -13,7 +14,7 @@ type OverrideOperationValue = Partial<OpenAPI.OperationObject> | ((current: Open
|
|
|
13
14
|
*/
|
|
14
15
|
declare function customOpenAPIOperation<T extends object>(o: T, extend: OverrideOperationValue): T;
|
|
15
16
|
declare function getCustomOpenAPIOperation(o: object): OverrideOperationValue | undefined;
|
|
16
|
-
declare function applyCustomOpenAPIOperation(operation: OpenAPI.OperationObject, contract:
|
|
17
|
+
declare function applyCustomOpenAPIOperation(operation: OpenAPI.OperationObject, contract: Contract): OpenAPI.OperationObject;
|
|
17
18
|
|
|
18
19
|
/**
|
|
19
20
|
* @internal
|
|
@@ -76,7 +77,7 @@ interface OpenAPIGeneratorGenerateOptions extends Partial<Omit<OpenAPI.Document,
|
|
|
76
77
|
* @deprecated Use `filter` option instead.
|
|
77
78
|
* @default () => false
|
|
78
79
|
*/
|
|
79
|
-
exclude?: (procedure:
|
|
80
|
+
exclude?: (procedure: Contract$1, path: readonly string[]) => boolean;
|
|
80
81
|
/**
|
|
81
82
|
* Filter procedures. Return `false` to exclude a procedure from the OpenAPI specification.
|
|
82
83
|
*
|
|
@@ -129,7 +130,7 @@ declare class OpenAPIGenerator {
|
|
|
129
130
|
*
|
|
130
131
|
* @see {@link https://orpc.unnoq.com/docs/openapi/openapi-specification OpenAPI Specification Docs}
|
|
131
132
|
*/
|
|
132
|
-
generate(router:
|
|
133
|
+
generate(router: ContractRouter | AnyRouter, options?: OpenAPIGeneratorGenerateOptions): Promise<OpenAPI.Document>;
|
|
133
134
|
}
|
|
134
135
|
|
|
135
136
|
/**
|
|
@@ -162,23 +163,6 @@ declare function checkParamsSchema(schema: ObjectSchema, params: string[]): bool
|
|
|
162
163
|
declare function toOpenAPISchema(schema: JSONSchema): OpenAPI.SchemaObject & object;
|
|
163
164
|
declare function resolveOpenAPIJsonSchemaRef(doc: OpenAPI.Document, schema: JSONSchema): JSONSchema;
|
|
164
165
|
|
|
165
|
-
type JsonifiedValue<T> = T extends string ? T : T extends number ? T : T extends boolean ? T : T extends null ? T : T extends undefined ? T : T extends Array<unknown> ? JsonifiedArray<T> : T extends Record<string, unknown> ? {
|
|
166
|
-
[K in keyof T]: JsonifiedValue<T[K]>;
|
|
167
|
-
} : T extends Date ? string : T extends bigint ? string : T extends File ? File : T extends Blob ? Blob : T extends RegExp ? string : T extends URL ? string : T extends Map<infer K, infer V> ? JsonifiedArray<[K, V][]> : T extends Set<infer U> ? JsonifiedArray<U[]> : T extends AsyncIteratorObject<infer U, infer V> ? AsyncIteratorObject<JsonifiedValue<U>, JsonifiedValue<V>> : unknown;
|
|
168
|
-
type JsonifiedArray<T extends Array<unknown>> = T extends readonly [] ? [] : T extends readonly [infer U, ...infer V] ? [
|
|
169
|
-
U extends undefined ? null : JsonifiedValue<U>,
|
|
170
|
-
...JsonifiedArray<V>
|
|
171
|
-
] : T extends Array<infer U> ? Array<JsonifiedValue<U>> : unknown;
|
|
172
|
-
/**
|
|
173
|
-
* Convert types that JSON not support to corresponding json types
|
|
174
|
-
*
|
|
175
|
-
* @see {@link https://orpc.unnoq.com/docs/openapi/client/openapi-link OpenAPI Link Docs}
|
|
176
|
-
*/
|
|
177
|
-
type JsonifiedClient<T extends NestedClient<any>> = T extends Client<infer UClientContext, infer UInput, infer UOutput, infer UError> ? Client<UClientContext, UInput, JsonifiedValue<UOutput>, UError extends ORPCError<infer UCode, infer UData> ? ORPCError<UCode, JsonifiedValue<UData>> : UError> : {
|
|
178
|
-
[K in keyof T]: T[K] extends NestedClient<any> ? JsonifiedClient<T[K]> : T[K];
|
|
179
|
-
};
|
|
180
|
-
declare function createJsonifiedRouterClient<T extends AnyRouter, TClientContext extends ClientContext>(router: Lazyable<T | undefined>, ...rest: MaybeOptionalOptions<CreateProcedureClientOptions<InferRouterInitialContext<T>, Schema<unknown, unknown>, ErrorMap, Meta, TClientContext>>): JsonifiedClient<RouterClient<T, TClientContext>>;
|
|
181
|
-
|
|
182
166
|
/**
|
|
183
167
|
*@internal
|
|
184
168
|
*/
|
|
@@ -216,5 +200,5 @@ declare const oo: {
|
|
|
216
200
|
spec: typeof customOpenAPIOperation;
|
|
217
201
|
};
|
|
218
202
|
|
|
219
|
-
export { CompositeSchemaConverter, LOGIC_KEYWORDS, OpenAPIGenerator, applyCustomOpenAPIOperation, applySchemaOptionality, checkParamsSchema,
|
|
220
|
-
export type { ConditionalSchemaConverter, FileSchema,
|
|
203
|
+
export { CompositeSchemaConverter, LOGIC_KEYWORDS, OpenAPIGenerator, applyCustomOpenAPIOperation, applySchemaOptionality, checkParamsSchema, customOpenAPIOperation, expandArrayableSchema, expandUnionSchema, filterSchemaBranches, getCustomOpenAPIOperation, isAnySchema, isFileSchema, isObjectSchema, isPrimitiveSchema, oo, resolveOpenAPIJsonSchemaRef, separateObjectSchema, toOpenAPIContent, toOpenAPIEventIteratorContent, toOpenAPIMethod, toOpenAPIParameters, toOpenAPIPath, toOpenAPISchema };
|
|
204
|
+
export type { ConditionalSchemaConverter, FileSchema, ObjectSchema, OpenAPIGeneratorGenerateOptions, OpenAPIGeneratorOptions, OverrideOperationValue, SchemaConvertOptions, SchemaConverter, SchemaConverterComponent };
|
package/dist/openapi/index.mjs
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { isObject, stringifyJSON, findDeepMatches, toArray, clone, value, toHttpPath, isORPCErrorStatus, fallbackORPCErrorStatus, fallbackORPCErrorMessage, resolveMaybeOptionalOptions, createORPCErrorFromJson } from '@temporary-name/shared';
|
|
4
|
-
import { j as jsonSerialize, d as deserialize, s as serialize } from '../shared/server.JtIZ8YG7.mjs';
|
|
1
|
+
import { isObject, stringifyJSON, findDeepMatches, toArray, clone, value, fallbackContractConfig, toHttpPath, isORPCErrorStatus } from '@temporary-name/shared';
|
|
2
|
+
import { j as jsonSerialize } from '../shared/server.CQIFwyhc.mjs';
|
|
5
3
|
import '@temporary-name/standard-server';
|
|
4
|
+
import { g as getEventIteratorSchemaDetails } from '../shared/server.YUvuxHty.mjs';
|
|
5
|
+
import { s as standardizeHTTPPath, r as resolveContractProcedures, g as getDynamicParams } from '../shared/server.ChOv1yG3.mjs';
|
|
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';
|
|
8
|
+
import '@temporary-name/zod';
|
|
8
9
|
|
|
9
10
|
const OPERATION_EXTENDER_SYMBOL = Symbol("ORPC_OPERATION_EXTENDER");
|
|
10
11
|
function customOpenAPIOperation(o, extend) {
|
|
@@ -22,20 +23,12 @@ function getCustomOpenAPIOperation(o) {
|
|
|
22
23
|
}
|
|
23
24
|
function applyCustomOpenAPIOperation(operation, contract) {
|
|
24
25
|
const operationCustoms = [];
|
|
25
|
-
for (const
|
|
26
|
-
const maybeExtender =
|
|
26
|
+
for (const middleware of contract["~orpc"].middlewares) {
|
|
27
|
+
const maybeExtender = getCustomOpenAPIOperation(middleware);
|
|
27
28
|
if (maybeExtender) {
|
|
28
29
|
operationCustoms.push(maybeExtender);
|
|
29
30
|
}
|
|
30
31
|
}
|
|
31
|
-
if (isProcedure(contract)) {
|
|
32
|
-
for (const middleware of contract["~orpc"].middlewares) {
|
|
33
|
-
const maybeExtender = getCustomOpenAPIOperation(middleware);
|
|
34
|
-
if (maybeExtender) {
|
|
35
|
-
operationCustoms.push(maybeExtender);
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
32
|
let currentOperation = operation;
|
|
40
33
|
for (const custom of operationCustoms) {
|
|
41
34
|
if (typeof custom === "function") {
|
|
@@ -401,10 +394,7 @@ class OpenAPIGenerator {
|
|
|
401
394
|
filter: void 0,
|
|
402
395
|
commonSchemas: void 0
|
|
403
396
|
};
|
|
404
|
-
const { baseSchemaConvertOptions
|
|
405
|
-
doc,
|
|
406
|
-
options.commonSchemas
|
|
407
|
-
);
|
|
397
|
+
const { baseSchemaConvertOptions } = await this.#resolveCommonSchemas(doc, options.commonSchemas);
|
|
408
398
|
const contracts = [];
|
|
409
399
|
await resolveContractProcedures({ path: [], router }, (traverseOptions) => {
|
|
410
400
|
if (!value(filter, traverseOptions)) {
|
|
@@ -432,12 +422,6 @@ class OpenAPIGenerator {
|
|
|
432
422
|
};
|
|
433
423
|
await this.#request(doc, operationObjectRef, def, baseSchemaConvertOptions);
|
|
434
424
|
await this.#successResponse(doc, operationObjectRef, def, baseSchemaConvertOptions);
|
|
435
|
-
await this.#errorResponse(
|
|
436
|
-
operationObjectRef,
|
|
437
|
-
def,
|
|
438
|
-
baseSchemaConvertOptions,
|
|
439
|
-
undefinedErrorJsonSchema
|
|
440
|
-
);
|
|
441
425
|
}
|
|
442
426
|
if (typeof def.route.spec === "function") {
|
|
443
427
|
operationObjectRef = def.route.spec(operationObjectRef);
|
|
@@ -696,64 +680,10 @@ ${errors.join("\n\n")}`
|
|
|
696
680
|
}
|
|
697
681
|
}
|
|
698
682
|
}
|
|
699
|
-
async #errorResponse(ref, def, baseSchemaConvertOptions, undefinedErrorSchema) {
|
|
700
|
-
const errorMap = def.errorMap;
|
|
701
|
-
const errors = {};
|
|
702
|
-
for (const code in errorMap) {
|
|
703
|
-
const config = errorMap[code];
|
|
704
|
-
if (!config) {
|
|
705
|
-
continue;
|
|
706
|
-
}
|
|
707
|
-
const status = fallbackORPCErrorStatus(code, config.status);
|
|
708
|
-
const message = fallbackORPCErrorMessage(code, config.message);
|
|
709
|
-
const [dataRequired, dataSchema] = await this.converter.convert(config.data, {
|
|
710
|
-
...baseSchemaConvertOptions,
|
|
711
|
-
strategy: "output"
|
|
712
|
-
});
|
|
713
|
-
errors[status] ??= [];
|
|
714
|
-
errors[status].push({
|
|
715
|
-
type: "object",
|
|
716
|
-
properties: {
|
|
717
|
-
defined: { const: true },
|
|
718
|
-
code: { const: code },
|
|
719
|
-
status: { const: status },
|
|
720
|
-
message: { type: "string", default: message },
|
|
721
|
-
data: dataSchema
|
|
722
|
-
},
|
|
723
|
-
required: dataRequired ? ["defined", "code", "status", "message", "data"] : ["defined", "code", "status", "message"]
|
|
724
|
-
});
|
|
725
|
-
}
|
|
726
|
-
ref.responses ??= {};
|
|
727
|
-
for (const status in errors) {
|
|
728
|
-
const schemas = errors[status];
|
|
729
|
-
ref.responses[status] = {
|
|
730
|
-
description: status,
|
|
731
|
-
content: toOpenAPIContent({
|
|
732
|
-
oneOf: [...schemas, undefinedErrorSchema]
|
|
733
|
-
})
|
|
734
|
-
};
|
|
735
|
-
}
|
|
736
|
-
}
|
|
737
|
-
}
|
|
738
|
-
|
|
739
|
-
function createJsonifiedRouterClient(router, ...rest) {
|
|
740
|
-
const options = resolveMaybeOptionalOptions(rest);
|
|
741
|
-
options.interceptors ??= [];
|
|
742
|
-
options.interceptors.unshift(async (options2) => {
|
|
743
|
-
try {
|
|
744
|
-
return deserialize(serialize(await options2.next()));
|
|
745
|
-
} catch (e) {
|
|
746
|
-
if (e instanceof ORPCError) {
|
|
747
|
-
throw createORPCErrorFromJson(deserialize(serialize(e.toJSON(), { outputFormat: "plain" })));
|
|
748
|
-
}
|
|
749
|
-
throw e;
|
|
750
|
-
}
|
|
751
|
-
});
|
|
752
|
-
return createRouterClient(router, options);
|
|
753
683
|
}
|
|
754
684
|
|
|
755
685
|
const oo = {
|
|
756
686
|
spec: customOpenAPIOperation
|
|
757
687
|
};
|
|
758
688
|
|
|
759
|
-
export { CompositeSchemaConverter, LOGIC_KEYWORDS, OpenAPIGenerator, applyCustomOpenAPIOperation, applySchemaOptionality, checkParamsSchema,
|
|
689
|
+
export { CompositeSchemaConverter, LOGIC_KEYWORDS, OpenAPIGenerator, applyCustomOpenAPIOperation, applySchemaOptionality, checkParamsSchema, customOpenAPIOperation, expandArrayableSchema, expandUnionSchema, filterSchemaBranches, getCustomOpenAPIOperation, isAnySchema, isFileSchema, isObjectSchema, isPrimitiveSchema, oo, resolveOpenAPIJsonSchemaRef, separateObjectSchema, toOpenAPIContent, toOpenAPIEventIteratorContent, toOpenAPIMethod, toOpenAPIParameters, toOpenAPIPath, toOpenAPISchema };
|