@temporary-name/server 1.9.3-alpha.6a70825f6d8c3dc99b87e4e5b778aea0fa007417 → 1.9.3-alpha.6d3c10e7b535aec2de4b812161c8001a916134b9
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 -6
- package/dist/adapters/aws-lambda/index.d.ts +4 -6
- package/dist/adapters/aws-lambda/index.mjs +4 -5
- package/dist/adapters/fetch/index.d.mts +8 -86
- package/dist/adapters/fetch/index.d.ts +8 -86
- package/dist/adapters/fetch/index.mjs +16 -156
- package/dist/adapters/node/index.d.mts +8 -63
- package/dist/adapters/node/index.d.ts +8 -63
- package/dist/adapters/node/index.mjs +14 -121
- package/dist/adapters/standard/index.d.mts +5 -7
- package/dist/adapters/standard/index.d.ts +5 -7
- package/dist/adapters/standard/index.mjs +4 -5
- package/dist/helpers/index.mjs +3 -29
- package/dist/index.d.mts +106 -181
- package/dist/index.d.ts +106 -181
- package/dist/index.mjs +130 -117
- package/dist/openapi/index.d.mts +11 -27
- package/dist/openapi/index.d.ts +11 -27
- package/dist/openapi/index.mjs +8 -76
- package/dist/shared/server.BYV-qTJt.d.ts +41 -0
- package/dist/shared/server.C1RJffw4.mjs +30 -0
- package/dist/shared/server.CQIFwyhc.mjs +40 -0
- package/dist/shared/server.CWb33y9B.d.mts +41 -0
- package/dist/shared/server.ChOv1yG3.mjs +319 -0
- package/dist/shared/server.DXzEGRE2.mjs +403 -0
- package/dist/shared/server.DgzAlPjF.mjs +160 -0
- package/dist/shared/server.DimTvmOQ.d.mts +373 -0
- package/dist/shared/server.DimTvmOQ.d.ts +373 -0
- package/dist/shared/server.YUvuxHty.mjs +48 -0
- package/package.json +10 -27
- package/dist/plugins/index.d.mts +0 -160
- package/dist/plugins/index.d.ts +0 -160
- package/dist/plugins/index.mjs +0 -288
- package/dist/shared/server.BCcLYvdF.d.mts +0 -56
- package/dist/shared/server.CHV9AQHl.mjs +0 -412
- package/dist/shared/server.CdeqmULw.d.ts +0 -56
- package/dist/shared/server.DHezmW6C.d.mts +0 -23
- package/dist/shared/server.DN9mVGfv.mjs +0 -11
- package/dist/shared/server.DWwaAM-a.mjs +0 -255
- package/dist/shared/server.Da-qLzdU.d.ts +0 -23
- package/dist/shared/server.DecvGKtb.d.mts +0 -242
- package/dist/shared/server.DecvGKtb.d.ts +0 -242
- package/dist/shared/server.JtIZ8YG7.mjs +0 -237
package/dist/index.mjs
CHANGED
|
@@ -1,12 +1,70 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export {
|
|
3
|
-
import
|
|
4
|
-
|
|
5
|
-
import {
|
|
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';
|
|
4
|
+
import { SchemaClass, object, core, gatingContext } from '@temporary-name/zod';
|
|
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.DgzAlPjF.mjs';
|
|
9
|
+
export { m as mergeCurrentContext, a as middlewareOutputFn } from './shared/server.DgzAlPjF.mjs';
|
|
10
|
+
export { e as eventIterator, g as getEventIteratorSchemaDetails } from './shared/server.YUvuxHty.mjs';
|
|
6
11
|
export { getEventMeta, withEventMeta } from '@temporary-name/standard-server';
|
|
7
|
-
import
|
|
8
|
-
|
|
9
|
-
|
|
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
|
+
}
|
|
10
68
|
|
|
11
69
|
class DecoratedProcedure extends Procedure {
|
|
12
70
|
/**
|
|
@@ -27,24 +85,19 @@ class DecoratedProcedure extends Procedure {
|
|
|
27
85
|
}
|
|
28
86
|
}
|
|
29
87
|
|
|
30
|
-
|
|
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 {
|
|
31
96
|
z;
|
|
32
97
|
constructor(def) {
|
|
33
98
|
super(def);
|
|
34
99
|
this.z = new SchemaClass();
|
|
35
100
|
}
|
|
36
|
-
/**
|
|
37
|
-
* Adds type-safe custom errors to the contract.
|
|
38
|
-
* The provided errors are spared-merged with any existing errors in the contract.
|
|
39
|
-
*
|
|
40
|
-
* @see {@link https://orpc.unnoq.com/docs/error-handling#type%E2%80%90safe-error-handling Type-Safe Error Handling Docs}
|
|
41
|
-
*/
|
|
42
|
-
errors(errors) {
|
|
43
|
-
return new ProcedureBuilder({
|
|
44
|
-
...this["~orpc"],
|
|
45
|
-
errorMap: mergeErrorMap(this["~orpc"].errorMap, errors)
|
|
46
|
-
});
|
|
47
|
-
}
|
|
48
101
|
/**
|
|
49
102
|
* Sets or updates the metadata for the contract.
|
|
50
103
|
* The provided metadata is spared-merged with any existing metadata in the contract.
|
|
@@ -57,16 +110,8 @@ class ProcedureBuilder extends ContractProcedure {
|
|
|
57
110
|
meta: mergeMeta(this["~orpc"].meta, meta)
|
|
58
111
|
});
|
|
59
112
|
}
|
|
60
|
-
endpoint(
|
|
61
|
-
const
|
|
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
|
-
}
|
|
113
|
+
endpoint(stringsOrEndpoint, ...values) {
|
|
114
|
+
const { method, path, pathSchema } = parseEndpointDefinition(stringsOrEndpoint, values);
|
|
70
115
|
const { prefix } = this["~orpc"];
|
|
71
116
|
const route = { method, path };
|
|
72
117
|
return new ProcedureBuilder({
|
|
@@ -74,7 +119,7 @@ class ProcedureBuilder extends ContractProcedure {
|
|
|
74
119
|
route: mergeRoute(this["~orpc"].route, prefix ? prefixRoute(route, prefix) : route),
|
|
75
120
|
schemas: {
|
|
76
121
|
...this["~orpc"].schemas,
|
|
77
|
-
pathSchema
|
|
122
|
+
pathSchema
|
|
78
123
|
}
|
|
79
124
|
});
|
|
80
125
|
}
|
|
@@ -141,6 +186,36 @@ class ProcedureBuilder extends ContractProcedure {
|
|
|
141
186
|
middlewares: addMiddleware(this["~orpc"].middlewares, middleware)
|
|
142
187
|
});
|
|
143
188
|
}
|
|
189
|
+
// `& {}` is so AuthType will be expanded in parameter info tooltips.
|
|
190
|
+
// The default of false for ValidatedAuthContext is used when you pass in the type 'none'. We use false
|
|
191
|
+
// because we can't use null or undefined (see ValidatedAuthContext) but we still want it to be falsy.
|
|
192
|
+
useAuth(type, ...rest) {
|
|
193
|
+
const config = { type, ...rest[0] };
|
|
194
|
+
const middleware = os.$context().middleware(async (options) => {
|
|
195
|
+
const { next, context } = options;
|
|
196
|
+
if (context.auth) return next();
|
|
197
|
+
const auth = await authByType(config, options);
|
|
198
|
+
if (auth === void 0) {
|
|
199
|
+
const { authConfigs } = options.procedure["~orpc"];
|
|
200
|
+
if (context.auth !== false && config === authConfigs.at(-1)) {
|
|
201
|
+
let authDescriptions = authConfigs.map(authDescription).join(", ");
|
|
202
|
+
if (authConfigs.length > 1) {
|
|
203
|
+
authDescriptions = `one of: ${authDescriptions}`;
|
|
204
|
+
}
|
|
205
|
+
throw new ORPCError("UNAUTHORIZED", {
|
|
206
|
+
message: `Authentication required. You must provide ${authDescriptions}`
|
|
207
|
+
});
|
|
208
|
+
}
|
|
209
|
+
return next();
|
|
210
|
+
}
|
|
211
|
+
return next({ context: { auth } });
|
|
212
|
+
});
|
|
213
|
+
return new this.constructor({
|
|
214
|
+
...this["~orpc"],
|
|
215
|
+
authConfigs: [...this["~orpc"].authConfigs, config],
|
|
216
|
+
middlewares: addMiddleware(this["~orpc"].middlewares, middleware)
|
|
217
|
+
});
|
|
218
|
+
}
|
|
144
219
|
useGating(gates, isGateEnabled) {
|
|
145
220
|
return this.use(({ next, context }) => {
|
|
146
221
|
return gatingContext.run(
|
|
@@ -155,6 +230,9 @@ class ProcedureBuilder extends ContractProcedure {
|
|
|
155
230
|
* @see {@link https://orpc.unnoq.com/docs/procedure Procedure Docs}
|
|
156
231
|
*/
|
|
157
232
|
handler(handler) {
|
|
233
|
+
if (this["~orpc"].schemas.outputSchema === initialSchemas.outputSchema) {
|
|
234
|
+
throw new Error("You must call .output() before calling .handler()");
|
|
235
|
+
}
|
|
158
236
|
return new DecoratedProcedure({
|
|
159
237
|
...this["~orpc"],
|
|
160
238
|
handler
|
|
@@ -256,7 +334,6 @@ function createApiBuilder(opts = {}) {
|
|
|
256
334
|
return new Builder({
|
|
257
335
|
route: {},
|
|
258
336
|
meta: opts.meta ?? {},
|
|
259
|
-
errorMap: {},
|
|
260
337
|
inputValidationIndex: 0,
|
|
261
338
|
outputValidationIndex: 0,
|
|
262
339
|
middlewares: [
|
|
@@ -267,85 +344,12 @@ function createApiBuilder(opts = {}) {
|
|
|
267
344
|
schemas: initialSchemas,
|
|
268
345
|
// NB: this is a relic from orpc -- I'm not convinced there's a need for this (or if there is, that it's
|
|
269
346
|
// the best solution). For now I've removed the interface to configure it externally.
|
|
270
|
-
dedupeLeadingMiddlewares: true
|
|
347
|
+
dedupeLeadingMiddlewares: true,
|
|
348
|
+
authConfigs: []
|
|
271
349
|
});
|
|
272
350
|
}
|
|
273
351
|
const os = createApiBuilder();
|
|
274
352
|
|
|
275
|
-
function implementerInternal(contract, middlewares) {
|
|
276
|
-
if (isContractProcedure(contract)) {
|
|
277
|
-
const impl2 = new Builder({
|
|
278
|
-
...contract["~orpc"],
|
|
279
|
-
middlewares,
|
|
280
|
-
inputValidationIndex: middlewares.length,
|
|
281
|
-
outputValidationIndex: middlewares.length,
|
|
282
|
-
dedupeLeadingMiddlewares: true
|
|
283
|
-
});
|
|
284
|
-
return impl2;
|
|
285
|
-
}
|
|
286
|
-
const impl = new Proxy(contract, {
|
|
287
|
-
get: (target, key) => {
|
|
288
|
-
if (typeof key !== "string") {
|
|
289
|
-
return Reflect.get(target, key);
|
|
290
|
-
}
|
|
291
|
-
let method;
|
|
292
|
-
if (key === "middleware") {
|
|
293
|
-
method = (mid) => decorateMiddleware(mid);
|
|
294
|
-
} else if (key === "use") {
|
|
295
|
-
method = (mid) => {
|
|
296
|
-
return implementerInternal(contract, addMiddleware(middlewares, mid));
|
|
297
|
-
};
|
|
298
|
-
} else if (key === "router") {
|
|
299
|
-
method = (router) => {
|
|
300
|
-
const adapted = enhanceRouter(router, {
|
|
301
|
-
middlewares,
|
|
302
|
-
errorMap: {},
|
|
303
|
-
prefix: void 0,
|
|
304
|
-
tags: void 0,
|
|
305
|
-
dedupeLeadingMiddlewares: true
|
|
306
|
-
});
|
|
307
|
-
return setHiddenRouterContract(adapted, contract);
|
|
308
|
-
};
|
|
309
|
-
}
|
|
310
|
-
const next = getContractRouter(target, [key]);
|
|
311
|
-
if (!next) {
|
|
312
|
-
return method ?? next;
|
|
313
|
-
}
|
|
314
|
-
const nextImpl = implementerInternal(next, middlewares);
|
|
315
|
-
if (method) {
|
|
316
|
-
return new Proxy(method, {
|
|
317
|
-
get(_, key2) {
|
|
318
|
-
return Reflect.get(nextImpl, key2);
|
|
319
|
-
}
|
|
320
|
-
});
|
|
321
|
-
}
|
|
322
|
-
return nextImpl;
|
|
323
|
-
}
|
|
324
|
-
});
|
|
325
|
-
return impl;
|
|
326
|
-
}
|
|
327
|
-
function implement(contract) {
|
|
328
|
-
const implInternal = implementerInternal(contract, []);
|
|
329
|
-
const impl = new Proxy(implInternal, {
|
|
330
|
-
get: (target, key) => {
|
|
331
|
-
let method;
|
|
332
|
-
if (key === "$context") {
|
|
333
|
-
method = () => impl;
|
|
334
|
-
}
|
|
335
|
-
const next = Reflect.get(target, key);
|
|
336
|
-
if (!method || !next || typeof next !== "function" && typeof next !== "object") {
|
|
337
|
-
return method || next;
|
|
338
|
-
}
|
|
339
|
-
return new Proxy(method, {
|
|
340
|
-
get(_, key2) {
|
|
341
|
-
return Reflect.get(next, key2);
|
|
342
|
-
}
|
|
343
|
-
});
|
|
344
|
-
}
|
|
345
|
-
});
|
|
346
|
-
return impl;
|
|
347
|
-
}
|
|
348
|
-
|
|
349
353
|
function createAssertedLazyProcedure(lazied) {
|
|
350
354
|
const lazyProcedure = lazyInternal(async () => {
|
|
351
355
|
const { default: maybeProcedure } = await unlazy(lazied);
|
|
@@ -360,14 +364,6 @@ function createAssertedLazyProcedure(lazied) {
|
|
|
360
364
|
}, getLazyMeta(lazied));
|
|
361
365
|
return lazyProcedure;
|
|
362
366
|
}
|
|
363
|
-
function createContractedProcedure(procedure, contract) {
|
|
364
|
-
return new Procedure({
|
|
365
|
-
...procedure["~orpc"],
|
|
366
|
-
errorMap: contract["~orpc"].errorMap,
|
|
367
|
-
route: contract["~orpc"].route,
|
|
368
|
-
meta: contract["~orpc"].meta
|
|
369
|
-
});
|
|
370
|
-
}
|
|
371
367
|
function call(procedure, input, ...rest) {
|
|
372
368
|
const options = resolveMaybeOptionalOptions(rest);
|
|
373
369
|
return createProcedureClient(procedure, options)(input, options);
|
|
@@ -398,4 +394,21 @@ function createRouterClient(router, ...rest) {
|
|
|
398
394
|
return recursive;
|
|
399
395
|
}
|
|
400
396
|
|
|
401
|
-
|
|
397
|
+
function isSchemaIssue(issue) {
|
|
398
|
+
if (!isTypescriptObject(issue) || typeof issue.message !== "string") {
|
|
399
|
+
return false;
|
|
400
|
+
}
|
|
401
|
+
if (issue.path !== void 0) {
|
|
402
|
+
if (!Array.isArray(issue.path)) {
|
|
403
|
+
return false;
|
|
404
|
+
}
|
|
405
|
+
if (!issue.path.every(
|
|
406
|
+
(segment) => isPropertyKey(segment) || isTypescriptObject(segment) && isPropertyKey(segment.key)
|
|
407
|
+
)) {
|
|
408
|
+
return false;
|
|
409
|
+
}
|
|
410
|
+
}
|
|
411
|
+
return true;
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
export { Builder, BuilderWithMiddlewares, Contract, DecoratedProcedure, Procedure, ProcedureBuilder, addMiddleware, call, createApiBuilder, createAssertedLazyProcedure, createProcedureClient, createRouterClient, decorateMiddleware, enhanceRouter, getLazyMeta, getRouter, initialSchemas, isLazy, isProcedure, isSchemaIssue, lazyInternal, mergeMeta, os, 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, ac as TraverseContractProcedureCallbackOptions, a2 as ContractRouter, w as AnyRouter } from '../shared/server.DimTvmOQ.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, ac as TraverseContractProcedureCallbackOptions, a2 as ContractRouter, w as AnyRouter } from '../shared/server.DimTvmOQ.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,11 +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';
|
|
6
|
-
import {
|
|
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';
|
|
7
6
|
import { TypeName } from '@temporary-name/interop/json-schema-typed/draft-2020-12';
|
|
8
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';
|
|
9
9
|
|
|
10
10
|
const OPERATION_EXTENDER_SYMBOL = Symbol("ORPC_OPERATION_EXTENDER");
|
|
11
11
|
function customOpenAPIOperation(o, extend) {
|
|
@@ -23,20 +23,12 @@ function getCustomOpenAPIOperation(o) {
|
|
|
23
23
|
}
|
|
24
24
|
function applyCustomOpenAPIOperation(operation, contract) {
|
|
25
25
|
const operationCustoms = [];
|
|
26
|
-
for (const
|
|
27
|
-
const maybeExtender =
|
|
26
|
+
for (const middleware of contract["~orpc"].middlewares) {
|
|
27
|
+
const maybeExtender = getCustomOpenAPIOperation(middleware);
|
|
28
28
|
if (maybeExtender) {
|
|
29
29
|
operationCustoms.push(maybeExtender);
|
|
30
30
|
}
|
|
31
31
|
}
|
|
32
|
-
if (isProcedure(contract)) {
|
|
33
|
-
for (const middleware of contract["~orpc"].middlewares) {
|
|
34
|
-
const maybeExtender = getCustomOpenAPIOperation(middleware);
|
|
35
|
-
if (maybeExtender) {
|
|
36
|
-
operationCustoms.push(maybeExtender);
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
32
|
let currentOperation = operation;
|
|
41
33
|
for (const custom of operationCustoms) {
|
|
42
34
|
if (typeof custom === "function") {
|
|
@@ -433,12 +425,6 @@ class OpenAPIGenerator {
|
|
|
433
425
|
};
|
|
434
426
|
await this.#request(doc, operationObjectRef, def, baseSchemaConvertOptions);
|
|
435
427
|
await this.#successResponse(doc, operationObjectRef, def, baseSchemaConvertOptions);
|
|
436
|
-
await this.#errorResponse(
|
|
437
|
-
operationObjectRef,
|
|
438
|
-
def,
|
|
439
|
-
baseSchemaConvertOptions,
|
|
440
|
-
undefinedErrorJsonSchema
|
|
441
|
-
);
|
|
442
428
|
}
|
|
443
429
|
if (typeof def.route.spec === "function") {
|
|
444
430
|
operationObjectRef = def.route.spec(operationObjectRef);
|
|
@@ -697,64 +683,10 @@ ${errors.join("\n\n")}`
|
|
|
697
683
|
}
|
|
698
684
|
}
|
|
699
685
|
}
|
|
700
|
-
async #errorResponse(ref, def, baseSchemaConvertOptions, undefinedErrorSchema) {
|
|
701
|
-
const errorMap = def.errorMap;
|
|
702
|
-
const errors = {};
|
|
703
|
-
for (const code in errorMap) {
|
|
704
|
-
const config = errorMap[code];
|
|
705
|
-
if (!config) {
|
|
706
|
-
continue;
|
|
707
|
-
}
|
|
708
|
-
const status = fallbackORPCErrorStatus(code, config.status);
|
|
709
|
-
const message = fallbackORPCErrorMessage(code, config.message);
|
|
710
|
-
const [dataRequired, dataSchema] = await this.converter.convert(config.data, {
|
|
711
|
-
...baseSchemaConvertOptions,
|
|
712
|
-
strategy: "output"
|
|
713
|
-
});
|
|
714
|
-
errors[status] ??= [];
|
|
715
|
-
errors[status].push({
|
|
716
|
-
type: "object",
|
|
717
|
-
properties: {
|
|
718
|
-
defined: { const: true },
|
|
719
|
-
code: { const: code },
|
|
720
|
-
status: { const: status },
|
|
721
|
-
message: { type: "string", default: message },
|
|
722
|
-
data: dataSchema
|
|
723
|
-
},
|
|
724
|
-
required: dataRequired ? ["defined", "code", "status", "message", "data"] : ["defined", "code", "status", "message"]
|
|
725
|
-
});
|
|
726
|
-
}
|
|
727
|
-
ref.responses ??= {};
|
|
728
|
-
for (const status in errors) {
|
|
729
|
-
const schemas = errors[status];
|
|
730
|
-
ref.responses[status] = {
|
|
731
|
-
description: status,
|
|
732
|
-
content: toOpenAPIContent({
|
|
733
|
-
oneOf: [...schemas, undefinedErrorSchema]
|
|
734
|
-
})
|
|
735
|
-
};
|
|
736
|
-
}
|
|
737
|
-
}
|
|
738
|
-
}
|
|
739
|
-
|
|
740
|
-
function createJsonifiedRouterClient(router, ...rest) {
|
|
741
|
-
const options = resolveMaybeOptionalOptions(rest);
|
|
742
|
-
options.interceptors ??= [];
|
|
743
|
-
options.interceptors.unshift(async (options2) => {
|
|
744
|
-
try {
|
|
745
|
-
return deserialize(serialize(await options2.next()));
|
|
746
|
-
} catch (e) {
|
|
747
|
-
if (e instanceof ORPCError) {
|
|
748
|
-
throw createORPCErrorFromJson(deserialize(serialize(e.toJSON(), { outputFormat: "plain" })));
|
|
749
|
-
}
|
|
750
|
-
throw e;
|
|
751
|
-
}
|
|
752
|
-
});
|
|
753
|
-
return createRouterClient(router, options);
|
|
754
686
|
}
|
|
755
687
|
|
|
756
688
|
const oo = {
|
|
757
689
|
spec: customOpenAPIOperation
|
|
758
690
|
};
|
|
759
691
|
|
|
760
|
-
export { CompositeSchemaConverter, LOGIC_KEYWORDS, OpenAPIGenerator, applyCustomOpenAPIOperation, applySchemaOptionality, checkParamsSchema,
|
|
692
|
+
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 };
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { HTTPPath, StandardResponse, StandardLazyRequest } from '@temporary-name/shared';
|
|
2
|
+
import { C as Context, m as Router } from './server.DimTvmOQ.js';
|
|
3
|
+
|
|
4
|
+
interface StandardHandleOptions<T extends Context> {
|
|
5
|
+
prefix?: HTTPPath;
|
|
6
|
+
context: T;
|
|
7
|
+
}
|
|
8
|
+
type StandardHandleResult = {
|
|
9
|
+
matched: true;
|
|
10
|
+
response: StandardResponse;
|
|
11
|
+
} | {
|
|
12
|
+
matched: false;
|
|
13
|
+
response: undefined;
|
|
14
|
+
};
|
|
15
|
+
interface StandardHandlerOptions<TContext extends Context> {
|
|
16
|
+
}
|
|
17
|
+
declare class StandardHandler<T extends Context> {
|
|
18
|
+
private readonly matcher;
|
|
19
|
+
constructor(router: Router<T>, _options: NoInfer<StandardHandlerOptions<T>>);
|
|
20
|
+
handle(request: StandardLazyRequest, options: StandardHandleOptions<T>): Promise<StandardHandleResult>;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
type FriendlyStandardHandleOptions<T extends Context> = Omit<StandardHandleOptions<T>, 'context'> & (Record<never, never> extends T ? {
|
|
24
|
+
context?: T;
|
|
25
|
+
} : {
|
|
26
|
+
context: T;
|
|
27
|
+
});
|
|
28
|
+
declare function resolveFriendlyStandardHandleOptions<T extends Context>(options: FriendlyStandardHandleOptions<T>): StandardHandleOptions<T>;
|
|
29
|
+
/**
|
|
30
|
+
* {@link https://github.com/unjs/rou3}
|
|
31
|
+
*
|
|
32
|
+
* @internal
|
|
33
|
+
*/
|
|
34
|
+
declare function toRou3Pattern(path: HTTPPath): string;
|
|
35
|
+
/**
|
|
36
|
+
* @internal
|
|
37
|
+
*/
|
|
38
|
+
declare function decodeParams(params: Record<string, string>): Record<string, string>;
|
|
39
|
+
|
|
40
|
+
export { StandardHandler as c, decodeParams as d, resolveFriendlyStandardHandleOptions as r, toRou3Pattern as t };
|
|
41
|
+
export type { FriendlyStandardHandleOptions as F, StandardHandleOptions as S, StandardHandleResult as a, StandardHandlerOptions as b };
|