@temporary-name/server 1.9.3-alpha.4275e976ddda4d8be107c2cfde9899bdea9a337d → 1.9.3-alpha.5537ef74244620c125352bc9356d8c0ae804f10d
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 +12 -6
- package/dist/adapters/aws-lambda/index.d.ts +12 -6
- package/dist/adapters/aws-lambda/index.mjs +12 -4
- package/dist/adapters/fetch/index.d.mts +12 -6
- package/dist/adapters/fetch/index.d.ts +12 -6
- package/dist/adapters/fetch/index.mjs +12 -11
- package/dist/adapters/node/index.d.mts +12 -6
- package/dist/adapters/node/index.d.ts +12 -6
- package/dist/adapters/node/index.mjs +12 -11
- package/dist/adapters/standard/index.d.mts +39 -13
- package/dist/adapters/standard/index.d.ts +39 -13
- package/dist/adapters/standard/index.mjs +8 -100
- package/dist/index.d.mts +41 -324
- package/dist/index.d.ts +41 -324
- package/dist/index.mjs +93 -93
- package/dist/openapi/index.d.mts +220 -0
- package/dist/openapi/index.d.ts +220 -0
- package/dist/openapi/index.mjs +776 -0
- package/dist/plugins/index.d.mts +2 -2
- package/dist/plugins/index.d.ts +2 -2
- package/dist/shared/server.B9VxPdeK.mjs +293 -0
- package/dist/shared/{server.Btxrgkj5.d.ts → server.B9i6p26R.d.ts} +8 -24
- package/dist/shared/server.BEHw7Eyx.mjs +247 -0
- package/dist/shared/{server.C1YnHvvf.d.ts → server.Bzrdopnd.d.mts} +3 -3
- package/dist/shared/{server.C1YnHvvf.d.mts → server.Bzrdopnd.d.ts} +3 -3
- package/dist/shared/{server.Bo94xDTv.d.mts → server.C-j2WKJz.d.mts} +8 -24
- package/dist/shared/server.CYRDznXq.d.ts +23 -0
- package/dist/shared/server.Cp__uvkw.d.mts +23 -0
- package/dist/shared/{server.BEQrAa3A.mjs → server.DcfsPloY.mjs} +16 -21
- package/package.json +19 -13
- package/dist/shared/server.D6K9uoPI.mjs +0 -35
- package/dist/shared/server.DZ5BIITo.mjs +0 -9
- package/dist/shared/server.X0YaZxSJ.mjs +0 -13
package/dist/index.mjs
CHANGED
|
@@ -1,14 +1,35 @@
|
|
|
1
|
-
import { isContractProcedure, mergeErrorMap, mergeMeta, mergeRoute, mergePrefix, enhanceRoute, mergeTags, getContractRouter } from '@temporary-name/contract';
|
|
2
|
-
export { ValidationError, eventIterator, type, validateORPCError } from '@temporary-name/contract';
|
|
3
1
|
import { onError, resolveMaybeOptionalOptions } from '@temporary-name/shared';
|
|
4
2
|
export { AsyncIteratorClass, EventPublisher, ORPCError, asyncIteratorToStream as eventIteratorToStream, isDefinedError, onError, onFinish, onStart, onSuccess, safe, streamToAsyncIteratorClass as streamToEventIterator } from '@temporary-name/shared';
|
|
5
|
-
import {
|
|
6
|
-
|
|
7
|
-
|
|
3
|
+
import { isContractProcedure, mergeErrorMap, mergeMeta, mergeRoute, mergePrefix, enhanceRoute, mergeTags, ContractProcedure, prefixRoute, getContractRouter } from '@temporary-name/contract';
|
|
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.DcfsPloY.mjs';
|
|
7
|
+
export { L as LAZY_SYMBOL, a as createORPCErrorConstructorMap, m as mergeCurrentContext, b as middlewareOutputFn } from './shared/server.DcfsPloY.mjs';
|
|
8
8
|
export { getEventMeta, withEventMeta } from '@temporary-name/standard-server';
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
9
|
+
|
|
10
|
+
function isStartWithMiddlewares(middlewares, compare) {
|
|
11
|
+
if (compare.length > middlewares.length) {
|
|
12
|
+
return false;
|
|
13
|
+
}
|
|
14
|
+
for (let i = 0; i < middlewares.length; i++) {
|
|
15
|
+
if (compare[i] === void 0) {
|
|
16
|
+
return true;
|
|
17
|
+
}
|
|
18
|
+
if (middlewares[i] !== compare[i]) {
|
|
19
|
+
return false;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
return true;
|
|
23
|
+
}
|
|
24
|
+
function mergeMiddlewares(first, second, options) {
|
|
25
|
+
if (options.dedupeLeading && isStartWithMiddlewares(second, first)) {
|
|
26
|
+
return second;
|
|
27
|
+
}
|
|
28
|
+
return [...first, ...second];
|
|
29
|
+
}
|
|
30
|
+
function addMiddleware(middlewares, addition) {
|
|
31
|
+
return [...middlewares, addition];
|
|
32
|
+
}
|
|
12
33
|
|
|
13
34
|
function decorateMiddleware(middleware) {
|
|
14
35
|
const decorated = ((...args) => middleware(...args));
|
|
@@ -46,30 +67,6 @@ function decorateMiddleware(middleware) {
|
|
|
46
67
|
return decorated;
|
|
47
68
|
}
|
|
48
69
|
|
|
49
|
-
function isStartWithMiddlewares(middlewares, compare) {
|
|
50
|
-
if (compare.length > middlewares.length) {
|
|
51
|
-
return false;
|
|
52
|
-
}
|
|
53
|
-
for (let i = 0; i < middlewares.length; i++) {
|
|
54
|
-
if (compare[i] === void 0) {
|
|
55
|
-
return true;
|
|
56
|
-
}
|
|
57
|
-
if (middlewares[i] !== compare[i]) {
|
|
58
|
-
return false;
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
return true;
|
|
62
|
-
}
|
|
63
|
-
function mergeMiddlewares(first, second, options) {
|
|
64
|
-
if (options.dedupeLeading && isStartWithMiddlewares(second, first)) {
|
|
65
|
-
return second;
|
|
66
|
-
}
|
|
67
|
-
return [...first, ...second];
|
|
68
|
-
}
|
|
69
|
-
function addMiddleware(middlewares, addition) {
|
|
70
|
-
return [...middlewares, addition];
|
|
71
|
-
}
|
|
72
|
-
|
|
73
70
|
class Procedure {
|
|
74
71
|
/**
|
|
75
72
|
* This property holds the defined options.
|
|
@@ -296,87 +293,49 @@ async function unlazyRouter(router) {
|
|
|
296
293
|
return unlazied;
|
|
297
294
|
}
|
|
298
295
|
|
|
299
|
-
class
|
|
300
|
-
|
|
301
|
-
* This property holds the defined options.
|
|
302
|
-
*/
|
|
303
|
-
"~orpc";
|
|
296
|
+
class ProcedureBuilder extends ContractProcedure {
|
|
297
|
+
z;
|
|
304
298
|
constructor(def) {
|
|
305
|
-
|
|
299
|
+
super(def);
|
|
300
|
+
this.z = new SchemaClass();
|
|
306
301
|
}
|
|
307
302
|
/**
|
|
308
|
-
*
|
|
309
|
-
*
|
|
310
|
-
* @see {@link https://orpc.unnoq.com/docs/context Context Docs}
|
|
311
|
-
*/
|
|
312
|
-
$context() {
|
|
313
|
-
return this;
|
|
314
|
-
}
|
|
315
|
-
/**
|
|
316
|
-
* Creates a middleware.
|
|
317
|
-
*
|
|
318
|
-
* @see {@link https://orpc.unnoq.com/docs/middleware Middleware Docs}
|
|
319
|
-
*/
|
|
320
|
-
middleware(middleware) {
|
|
321
|
-
return decorateMiddleware(middleware);
|
|
322
|
-
}
|
|
323
|
-
/**
|
|
324
|
-
* Adds type-safe custom errors.
|
|
325
|
-
* The provided errors are spared-merged with any existing errors.
|
|
303
|
+
* Adds type-safe custom errors to the contract.
|
|
304
|
+
* The provided errors are spared-merged with any existing errors in the contract.
|
|
326
305
|
*
|
|
327
306
|
* @see {@link https://orpc.unnoq.com/docs/error-handling#type%E2%80%90safe-error-handling Type-Safe Error Handling Docs}
|
|
328
307
|
*/
|
|
329
308
|
errors(errors) {
|
|
330
|
-
return new
|
|
309
|
+
return new ProcedureBuilder({
|
|
331
310
|
...this["~orpc"],
|
|
332
311
|
errorMap: mergeErrorMap(this["~orpc"].errorMap, errors)
|
|
333
312
|
});
|
|
334
313
|
}
|
|
335
314
|
/**
|
|
336
|
-
*
|
|
337
|
-
*
|
|
338
|
-
* @info Supports both normal middleware and inline middleware implementations.
|
|
339
|
-
* @note The current context must be satisfy middleware dependent-context
|
|
340
|
-
* @see {@link https://orpc.unnoq.com/docs/middleware Middleware Docs}
|
|
341
|
-
*/
|
|
342
|
-
use(middleware) {
|
|
343
|
-
return new Builder({
|
|
344
|
-
...this["~orpc"],
|
|
345
|
-
middlewares: addMiddleware(this["~orpc"].middlewares, middleware)
|
|
346
|
-
});
|
|
347
|
-
}
|
|
348
|
-
useGating(gates, isGateEnabled) {
|
|
349
|
-
return this.use(({ next, context }) => {
|
|
350
|
-
return gatingContext.run(
|
|
351
|
-
(gate) => isGateEnabled(gate, context),
|
|
352
|
-
() => next({ context: { isGateEnabled } })
|
|
353
|
-
);
|
|
354
|
-
});
|
|
355
|
-
}
|
|
356
|
-
/**
|
|
357
|
-
* Sets or updates the metadata.
|
|
358
|
-
* The provided metadata is spared-merged with any existing metadata.
|
|
315
|
+
* Sets or updates the metadata for the contract.
|
|
316
|
+
* The provided metadata is spared-merged with any existing metadata in the contract.
|
|
359
317
|
*
|
|
360
318
|
* @see {@link https://orpc.unnoq.com/docs/metadata Metadata Docs}
|
|
361
319
|
*/
|
|
362
320
|
meta(meta) {
|
|
363
|
-
return new
|
|
321
|
+
return new ProcedureBuilder({
|
|
364
322
|
...this["~orpc"],
|
|
365
323
|
meta: mergeMeta(this["~orpc"].meta, meta)
|
|
366
324
|
});
|
|
367
325
|
}
|
|
368
326
|
/**
|
|
369
|
-
* Sets or updates the route definition.
|
|
370
|
-
* The provided route is spared-merged with any existing route.
|
|
327
|
+
* Sets or updates the route definition for the contract.
|
|
328
|
+
* The provided route is spared-merged with any existing route in the contract.
|
|
371
329
|
* This option is typically relevant when integrating with OpenAPI.
|
|
372
330
|
*
|
|
373
331
|
* @see {@link https://orpc.unnoq.com/docs/openapi/routing OpenAPI Routing Docs}
|
|
374
332
|
* @see {@link https://orpc.unnoq.com/docs/openapi/input-output-structure OpenAPI Input/Output Structure Docs}
|
|
375
333
|
*/
|
|
376
334
|
route(route) {
|
|
377
|
-
|
|
335
|
+
const { prefix } = this["~orpc"];
|
|
336
|
+
return new ProcedureBuilder({
|
|
378
337
|
...this["~orpc"],
|
|
379
|
-
route: mergeRoute(this["~orpc"].route, route)
|
|
338
|
+
route: mergeRoute(this["~orpc"].route, prefix ? prefixRoute(route, prefix) : route)
|
|
380
339
|
});
|
|
381
340
|
}
|
|
382
341
|
/**
|
|
@@ -385,7 +344,7 @@ class Builder {
|
|
|
385
344
|
* @see {@link https://orpc.unnoq.com/docs/procedure#input-output-validation Input Validation Docs}
|
|
386
345
|
*/
|
|
387
346
|
input(schema) {
|
|
388
|
-
return new
|
|
347
|
+
return new ProcedureBuilder({
|
|
389
348
|
...this["~orpc"],
|
|
390
349
|
inputSchema: schema,
|
|
391
350
|
inputValidationIndex: this["~orpc"].middlewares.length
|
|
@@ -397,12 +356,33 @@ class Builder {
|
|
|
397
356
|
* @see {@link https://orpc.unnoq.com/docs/procedure#input-output-validation Output Validation Docs}
|
|
398
357
|
*/
|
|
399
358
|
output(schema) {
|
|
400
|
-
return new
|
|
359
|
+
return new ProcedureBuilder({
|
|
401
360
|
...this["~orpc"],
|
|
402
361
|
outputSchema: schema,
|
|
403
362
|
outputValidationIndex: this["~orpc"].middlewares.length
|
|
404
363
|
});
|
|
405
364
|
}
|
|
365
|
+
/**
|
|
366
|
+
* Uses a middleware to modify the context or improve the pipeline.
|
|
367
|
+
*
|
|
368
|
+
* @info Supports both normal middleware and inline middleware implementations.
|
|
369
|
+
* @note The current context must be satisfy middleware dependent-context
|
|
370
|
+
* @see {@link https://orpc.unnoq.com/docs/middleware Middleware Docs}
|
|
371
|
+
*/
|
|
372
|
+
use(middleware) {
|
|
373
|
+
return new this.constructor({
|
|
374
|
+
...this["~orpc"],
|
|
375
|
+
middlewares: addMiddleware(this["~orpc"].middlewares, middleware)
|
|
376
|
+
});
|
|
377
|
+
}
|
|
378
|
+
useGating(gates, isGateEnabled) {
|
|
379
|
+
return this.use(({ next, context }) => {
|
|
380
|
+
return gatingContext.run(
|
|
381
|
+
(gate) => isGateEnabled(gate, context),
|
|
382
|
+
() => next({ context: { isGateEnabled } })
|
|
383
|
+
);
|
|
384
|
+
});
|
|
385
|
+
}
|
|
406
386
|
/**
|
|
407
387
|
* Defines the handler of the procedure.
|
|
408
388
|
*
|
|
@@ -414,6 +394,8 @@ class Builder {
|
|
|
414
394
|
handler
|
|
415
395
|
});
|
|
416
396
|
}
|
|
397
|
+
}
|
|
398
|
+
class BuilderWithMiddlewares extends ProcedureBuilder {
|
|
417
399
|
/**
|
|
418
400
|
* Prefixes all procedures in the router.
|
|
419
401
|
* The provided prefix is post-appended to any existing router prefix.
|
|
@@ -423,7 +405,7 @@ class Builder {
|
|
|
423
405
|
* @see {@link https://orpc.unnoq.com/docs/openapi/routing#route-prefixes OpenAPI Route Prefixes Docs}
|
|
424
406
|
*/
|
|
425
407
|
prefix(prefix) {
|
|
426
|
-
return new
|
|
408
|
+
return new this.constructor({
|
|
427
409
|
...this["~orpc"],
|
|
428
410
|
prefix: mergePrefix(this["~orpc"].prefix, prefix)
|
|
429
411
|
});
|
|
@@ -435,7 +417,7 @@ class Builder {
|
|
|
435
417
|
* @see {@link https://orpc.unnoq.com/docs/openapi/openapi-specification#operation-metadata OpenAPI Operation Metadata Docs}
|
|
436
418
|
*/
|
|
437
419
|
tag(...tags) {
|
|
438
|
-
return new
|
|
420
|
+
return new this.constructor({
|
|
439
421
|
...this["~orpc"],
|
|
440
422
|
tags: mergeTags(this["~orpc"].tags, tags)
|
|
441
423
|
});
|
|
@@ -458,15 +440,34 @@ class Builder {
|
|
|
458
440
|
return enhanceRouter(lazy(loader), this["~orpc"]);
|
|
459
441
|
}
|
|
460
442
|
}
|
|
443
|
+
|
|
444
|
+
class Builder extends BuilderWithMiddlewares {
|
|
445
|
+
/**
|
|
446
|
+
* Set or override the initial context.
|
|
447
|
+
*
|
|
448
|
+
* @see {@link https://orpc.unnoq.com/docs/context Context Docs}
|
|
449
|
+
*/
|
|
450
|
+
$context() {
|
|
451
|
+
return this;
|
|
452
|
+
}
|
|
453
|
+
/**
|
|
454
|
+
* Creates a middleware.
|
|
455
|
+
*
|
|
456
|
+
* @see {@link https://orpc.unnoq.com/docs/middleware Middleware Docs}
|
|
457
|
+
*/
|
|
458
|
+
middleware(middleware) {
|
|
459
|
+
return decorateMiddleware(middleware);
|
|
460
|
+
}
|
|
461
|
+
}
|
|
461
462
|
function createApiBuilder(opts = {}) {
|
|
462
|
-
|
|
463
|
+
return new Builder({
|
|
463
464
|
route: {},
|
|
464
465
|
meta: opts.meta ?? {},
|
|
465
466
|
errorMap: {},
|
|
466
467
|
inputValidationIndex: 0,
|
|
467
468
|
outputValidationIndex: 0,
|
|
468
469
|
middlewares: [
|
|
469
|
-
onError((error,
|
|
470
|
+
onError((error, _options) => {
|
|
470
471
|
console.dir(error, { depth: null });
|
|
471
472
|
})
|
|
472
473
|
],
|
|
@@ -474,7 +475,6 @@ function createApiBuilder(opts = {}) {
|
|
|
474
475
|
// the best solution). For now I've removed the interface to configure it externally.
|
|
475
476
|
dedupeLeadingMiddlewares: true
|
|
476
477
|
});
|
|
477
|
-
return base;
|
|
478
478
|
}
|
|
479
479
|
const os = createApiBuilder();
|
|
480
480
|
|
|
@@ -615,4 +615,4 @@ function createRouterClient(router, ...rest) {
|
|
|
615
615
|
return recursive;
|
|
616
616
|
}
|
|
617
617
|
|
|
618
|
-
export { Builder, DecoratedProcedure, Procedure, addMiddleware, call, createAccessibleLazyRouter, createApiBuilder, createAssertedLazyProcedure, createContractedProcedure, createProcedureClient, createRouterClient, decorateMiddleware, enhanceRouter, getHiddenRouterContract, getLazyMeta, getRouter, implement, implementerInternal, isLazy, isProcedure, isStartWithMiddlewares, lazy, mergeMiddlewares, os, resolveContractProcedures, setHiddenRouterContract, traverseContractProcedures, unlazy, unlazyRouter };
|
|
618
|
+
export { Builder, BuilderWithMiddlewares, DecoratedProcedure, Procedure, ProcedureBuilder, addMiddleware, call, createAccessibleLazyRouter, createApiBuilder, createAssertedLazyProcedure, createContractedProcedure, createProcedureClient, createRouterClient, decorateMiddleware, enhanceRouter, getHiddenRouterContract, getLazyMeta, getRouter, implement, implementerInternal, isLazy, isProcedure, isStartWithMiddlewares, lazy, mergeMiddlewares, os, resolveContractProcedures, setHiddenRouterContract, traverseContractProcedures, unlazy, unlazyRouter };
|
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
import { OpenAPI, AnyContractProcedure, AnySchema, AnyContractRouter } from '@temporary-name/contract';
|
|
2
|
+
export { OpenAPI } from '@temporary-name/contract';
|
|
3
|
+
import { AnyProcedure, TraverseContractProcedureCallbackOptions, AnyRouter, ORPCError, ClientContext, Lazyable, CreateProcedureClientOptions, InferRouterInitialContext, Schema, ErrorMap, Meta, RouterClient } from '@temporary-name/server';
|
|
4
|
+
import { Promisable, Value, HTTPPath, HTTPMethod, NestedClient, Client, MaybeOptionalOptions } from '@temporary-name/shared';
|
|
5
|
+
import { JSONSchema } from '@temporary-name/interop/json-schema-typed/draft-2020-12';
|
|
6
|
+
export { JSONSchema, ContentEncoding as JSONSchemaContentEncoding, Format as JSONSchemaFormat, TypeName as JSONSchemaTypeName } from '@temporary-name/interop/json-schema-typed/draft-2020-12';
|
|
7
|
+
|
|
8
|
+
type OverrideOperationValue = Partial<OpenAPI.OperationObject> | ((current: OpenAPI.OperationObject, procedure: AnyContractProcedure) => OpenAPI.OperationObject);
|
|
9
|
+
/**
|
|
10
|
+
* Customize The Operation Object by proxy an error map item or a middleware.
|
|
11
|
+
*
|
|
12
|
+
* @see {@link https://orpc.unnoq.com/docs/openapi/openapi-specification#customizing-operation-objects Customizing Operation Objects Docs}
|
|
13
|
+
*/
|
|
14
|
+
declare function customOpenAPIOperation<T extends object>(o: T, extend: OverrideOperationValue): T;
|
|
15
|
+
declare function getCustomOpenAPIOperation(o: object): OverrideOperationValue | undefined;
|
|
16
|
+
declare function applyCustomOpenAPIOperation(operation: OpenAPI.OperationObject, contract: AnyContractProcedure): OpenAPI.OperationObject;
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* @internal
|
|
20
|
+
*/
|
|
21
|
+
type ObjectSchema = JSONSchema & {
|
|
22
|
+
type: 'object';
|
|
23
|
+
} & object;
|
|
24
|
+
/**
|
|
25
|
+
* @internal
|
|
26
|
+
*/
|
|
27
|
+
type FileSchema = JSONSchema & {
|
|
28
|
+
type: 'string';
|
|
29
|
+
contentMediaType: string;
|
|
30
|
+
} & object;
|
|
31
|
+
/**
|
|
32
|
+
* @internal
|
|
33
|
+
*/
|
|
34
|
+
declare const LOGIC_KEYWORDS: string[];
|
|
35
|
+
|
|
36
|
+
interface SchemaConverterComponent {
|
|
37
|
+
allowedStrategies: readonly SchemaConvertOptions['strategy'][];
|
|
38
|
+
schema: AnySchema;
|
|
39
|
+
required: boolean;
|
|
40
|
+
ref: string;
|
|
41
|
+
}
|
|
42
|
+
interface SchemaConvertOptions {
|
|
43
|
+
strategy: 'input' | 'output';
|
|
44
|
+
/**
|
|
45
|
+
* Common components should use `$ref` to represent themselves if matched.
|
|
46
|
+
*/
|
|
47
|
+
components?: readonly SchemaConverterComponent[];
|
|
48
|
+
/**
|
|
49
|
+
* Minimum schema structure depth required before using `$ref` for components.
|
|
50
|
+
*
|
|
51
|
+
* For example, if set to 2, `$ref` will only be used for schemas nested at depth 2 or greater.
|
|
52
|
+
*
|
|
53
|
+
* @default 0 - No depth limit;
|
|
54
|
+
*/
|
|
55
|
+
minStructureDepthForRef?: number;
|
|
56
|
+
}
|
|
57
|
+
interface SchemaConverter {
|
|
58
|
+
convert(schema: AnySchema | undefined, options: SchemaConvertOptions): Promisable<[required: boolean, jsonSchema: JSONSchema]>;
|
|
59
|
+
}
|
|
60
|
+
interface ConditionalSchemaConverter extends SchemaConverter {
|
|
61
|
+
condition(schema: AnySchema | undefined, options: SchemaConvertOptions): Promisable<boolean>;
|
|
62
|
+
}
|
|
63
|
+
declare class CompositeSchemaConverter implements SchemaConverter {
|
|
64
|
+
private readonly converters;
|
|
65
|
+
constructor(converters: readonly ConditionalSchemaConverter[]);
|
|
66
|
+
convert(schema: AnySchema | undefined, options: SchemaConvertOptions): Promise<[required: boolean, jsonSchema: JSONSchema]>;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
interface OpenAPIGeneratorOptions {
|
|
70
|
+
schemaConverters?: ConditionalSchemaConverter[];
|
|
71
|
+
}
|
|
72
|
+
interface OpenAPIGeneratorGenerateOptions extends Partial<Omit<OpenAPI.Document, 'openapi'>> {
|
|
73
|
+
/**
|
|
74
|
+
* Exclude procedures from the OpenAPI specification.
|
|
75
|
+
*
|
|
76
|
+
* @deprecated Use `filter` option instead.
|
|
77
|
+
* @default () => false
|
|
78
|
+
*/
|
|
79
|
+
exclude?: (procedure: AnyProcedure | AnyContractProcedure, path: readonly string[]) => boolean;
|
|
80
|
+
/**
|
|
81
|
+
* Filter procedures. Return `false` to exclude a procedure from the OpenAPI specification.
|
|
82
|
+
*
|
|
83
|
+
* @default true
|
|
84
|
+
*/
|
|
85
|
+
filter?: Value<boolean, [options: TraverseContractProcedureCallbackOptions]>;
|
|
86
|
+
/**
|
|
87
|
+
* Common schemas to be used for $ref resolution.
|
|
88
|
+
*/
|
|
89
|
+
commonSchemas?: Record<string, {
|
|
90
|
+
/**
|
|
91
|
+
* Determines which schema definition to use when input and output schemas differ.
|
|
92
|
+
* This is needed because some schemas transform data differently between input and output,
|
|
93
|
+
* making it impossible to use a single $ref for both cases.
|
|
94
|
+
*
|
|
95
|
+
* @example
|
|
96
|
+
* ```ts
|
|
97
|
+
* // This schema transforms a string input into a number output
|
|
98
|
+
* const Schema = z.string()
|
|
99
|
+
* .transform(v => Number(v))
|
|
100
|
+
* .pipe(z.number())
|
|
101
|
+
*
|
|
102
|
+
* // Input schema: { type: 'string' }
|
|
103
|
+
* // Output schema: { type: 'number' }
|
|
104
|
+
* ```
|
|
105
|
+
*
|
|
106
|
+
* When schemas differ between input and output, you must explicitly choose
|
|
107
|
+
* which version to use for the OpenAPI specification.
|
|
108
|
+
*
|
|
109
|
+
* @default 'input' - Uses the input schema definition by default
|
|
110
|
+
*/
|
|
111
|
+
strategy?: SchemaConvertOptions['strategy'];
|
|
112
|
+
schema: AnySchema;
|
|
113
|
+
} | {
|
|
114
|
+
error: 'UndefinedError';
|
|
115
|
+
schema?: never;
|
|
116
|
+
}>;
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* The generator that converts oRPC routers/contracts to OpenAPI specifications.
|
|
120
|
+
*
|
|
121
|
+
* @see {@link https://orpc.unnoq.com/docs/openapi/openapi-specification OpenAPI Specification Docs}
|
|
122
|
+
*/
|
|
123
|
+
declare class OpenAPIGenerator {
|
|
124
|
+
#private;
|
|
125
|
+
private readonly converter;
|
|
126
|
+
constructor(options?: OpenAPIGeneratorOptions);
|
|
127
|
+
/**
|
|
128
|
+
* Generates OpenAPI specifications from oRPC routers/contracts.
|
|
129
|
+
*
|
|
130
|
+
* @see {@link https://orpc.unnoq.com/docs/openapi/openapi-specification OpenAPI Specification Docs}
|
|
131
|
+
*/
|
|
132
|
+
generate(router: AnyContractRouter | AnyRouter, options?: OpenAPIGeneratorGenerateOptions): Promise<OpenAPI.Document>;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* @internal
|
|
137
|
+
*/
|
|
138
|
+
declare function toOpenAPIPath(path: HTTPPath): string;
|
|
139
|
+
/**
|
|
140
|
+
* @internal
|
|
141
|
+
*/
|
|
142
|
+
declare function toOpenAPIMethod(method: HTTPMethod): Lowercase<HTTPMethod>;
|
|
143
|
+
/**
|
|
144
|
+
* @internal
|
|
145
|
+
*/
|
|
146
|
+
declare function toOpenAPIContent(schema: JSONSchema): Record<string, OpenAPI.MediaTypeObject>;
|
|
147
|
+
/**
|
|
148
|
+
* @internal
|
|
149
|
+
*/
|
|
150
|
+
declare function toOpenAPIEventIteratorContent([yieldsRequired, yieldsSchema]: [boolean, JSONSchema], [returnsRequired, returnsSchema]: [boolean, JSONSchema]): Record<string, OpenAPI.MediaTypeObject>;
|
|
151
|
+
/**
|
|
152
|
+
* @internal
|
|
153
|
+
*/
|
|
154
|
+
declare function toOpenAPIParameters(schema: ObjectSchema, parameterIn: 'path' | 'query' | 'header' | 'cookie'): OpenAPI.ParameterObject[];
|
|
155
|
+
/**
|
|
156
|
+
* @internal
|
|
157
|
+
*/
|
|
158
|
+
declare function checkParamsSchema(schema: ObjectSchema, params: string[]): boolean;
|
|
159
|
+
/**
|
|
160
|
+
* @internal
|
|
161
|
+
*/
|
|
162
|
+
declare function toOpenAPISchema(schema: JSONSchema): OpenAPI.SchemaObject & object;
|
|
163
|
+
declare function resolveOpenAPIJsonSchemaRef(doc: OpenAPI.Document, schema: JSONSchema): JSONSchema;
|
|
164
|
+
|
|
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
|
+
/**
|
|
183
|
+
*@internal
|
|
184
|
+
*/
|
|
185
|
+
declare function isFileSchema(schema: JSONSchema): schema is FileSchema;
|
|
186
|
+
/**
|
|
187
|
+
* @internal
|
|
188
|
+
*/
|
|
189
|
+
declare function isObjectSchema(schema: JSONSchema): schema is ObjectSchema;
|
|
190
|
+
/**
|
|
191
|
+
* @internal
|
|
192
|
+
*/
|
|
193
|
+
declare function isAnySchema(schema: JSONSchema): boolean;
|
|
194
|
+
/**
|
|
195
|
+
* @internal
|
|
196
|
+
*/
|
|
197
|
+
declare function separateObjectSchema(schema: ObjectSchema, separatedProperties: string[]): [matched: ObjectSchema, rest: ObjectSchema];
|
|
198
|
+
/**
|
|
199
|
+
* @internal
|
|
200
|
+
*/
|
|
201
|
+
declare function filterSchemaBranches(schema: JSONSchema, check: (schema: JSONSchema) => boolean, matches?: JSONSchema[]): [matches: JSONSchema[], rest: JSONSchema | undefined];
|
|
202
|
+
declare function applySchemaOptionality(required: boolean, schema: JSONSchema): JSONSchema;
|
|
203
|
+
/**
|
|
204
|
+
* Takes a JSON schema and, if it's primarily a union type (anyOf, oneOf),
|
|
205
|
+
* recursively expands it into an array of its constituent, non-union base schemas.
|
|
206
|
+
* If the schema is not a simple union or is a base type, it's returned as a single-element array.
|
|
207
|
+
*/
|
|
208
|
+
declare function expandUnionSchema(schema: JSONSchema): JSONSchema[];
|
|
209
|
+
declare function expandArrayableSchema(schema: JSONSchema): undefined | [items: JSONSchema, array: JSONSchema & {
|
|
210
|
+
type: 'array';
|
|
211
|
+
items?: JSONSchema;
|
|
212
|
+
}];
|
|
213
|
+
declare function isPrimitiveSchema(schema: JSONSchema): boolean;
|
|
214
|
+
|
|
215
|
+
declare const oo: {
|
|
216
|
+
spec: typeof customOpenAPIOperation;
|
|
217
|
+
};
|
|
218
|
+
|
|
219
|
+
export { CompositeSchemaConverter, LOGIC_KEYWORDS, OpenAPIGenerator, applyCustomOpenAPIOperation, applySchemaOptionality, checkParamsSchema, createJsonifiedRouterClient, customOpenAPIOperation, expandArrayableSchema, expandUnionSchema, filterSchemaBranches, getCustomOpenAPIOperation, isAnySchema, isFileSchema, isObjectSchema, isPrimitiveSchema, oo, resolveOpenAPIJsonSchemaRef, separateObjectSchema, toOpenAPIContent, toOpenAPIEventIteratorContent, toOpenAPIMethod, toOpenAPIParameters, toOpenAPIPath, toOpenAPISchema };
|
|
220
|
+
export type { ConditionalSchemaConverter, FileSchema, JsonifiedArray, JsonifiedClient, JsonifiedValue, ObjectSchema, OpenAPIGeneratorGenerateOptions, OpenAPIGeneratorOptions, OverrideOperationValue, SchemaConvertOptions, SchemaConverter, SchemaConverterComponent };
|