@orpc/openapi 1.14.5 → 2.0.0-beta.1

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.
Files changed (48) hide show
  1. package/README.md +75 -109
  2. package/dist/adapters/fetch/index.d.mts +20 -16
  3. package/dist/adapters/fetch/index.d.ts +20 -16
  4. package/dist/adapters/fetch/index.mjs +24 -8
  5. package/dist/adapters/node/index.d.mts +8 -13
  6. package/dist/adapters/node/index.d.ts +8 -13
  7. package/dist/adapters/node/index.mjs +10 -7
  8. package/dist/adapters/standard/index.d.mts +46 -16
  9. package/dist/adapters/standard/index.d.ts +46 -16
  10. package/dist/adapters/standard/index.mjs +9 -6
  11. package/dist/extensions/route.d.mts +43 -0
  12. package/dist/extensions/route.d.ts +43 -0
  13. package/dist/extensions/route.mjs +14 -0
  14. package/dist/helpers/index.d.mts +51 -0
  15. package/dist/helpers/index.d.ts +51 -0
  16. package/dist/helpers/index.mjs +39 -0
  17. package/dist/index.d.mts +92 -111
  18. package/dist/index.d.ts +92 -111
  19. package/dist/index.mjs +894 -34
  20. package/dist/plugins/index.d.mts +55 -51
  21. package/dist/plugins/index.d.ts +55 -51
  22. package/dist/plugins/index.mjs +147 -142
  23. package/dist/shared/openapi.B2SK0ZAr.mjs +359 -0
  24. package/dist/shared/openapi.B9PQzqBn.mjs +49 -0
  25. package/dist/shared/openapi.BQzzr4-4.d.ts +299 -0
  26. package/dist/shared/openapi.BcEtAxQj.d.mts +299 -0
  27. package/dist/shared/openapi.Bt87OzTt.mjs +131 -0
  28. package/dist/shared/openapi.C7m7NAmH.d.mts +142 -0
  29. package/dist/shared/openapi.C7m7NAmH.d.ts +142 -0
  30. package/dist/shared/openapi.C9Olbxd5.d.ts +75 -0
  31. package/dist/shared/openapi.CYgMBSUF.d.mts +18 -0
  32. package/dist/shared/openapi.CYgMBSUF.d.ts +18 -0
  33. package/dist/shared/openapi.CcyUEuTs.mjs +313 -0
  34. package/dist/shared/openapi.DmAa7YPO.mjs +275 -0
  35. package/dist/shared/openapi.Drd1OtzG.d.mts +75 -0
  36. package/package.json +29 -23
  37. package/dist/adapters/aws-lambda/index.d.mts +0 -20
  38. package/dist/adapters/aws-lambda/index.d.ts +0 -20
  39. package/dist/adapters/aws-lambda/index.mjs +0 -18
  40. package/dist/adapters/fastify/index.d.mts +0 -23
  41. package/dist/adapters/fastify/index.d.ts +0 -23
  42. package/dist/adapters/fastify/index.mjs +0 -18
  43. package/dist/shared/openapi.BB-W-NKv.mjs +0 -204
  44. package/dist/shared/openapi.BGy4N6eR.d.mts +0 -120
  45. package/dist/shared/openapi.BGy4N6eR.d.ts +0 -120
  46. package/dist/shared/openapi.BwdtJjDu.mjs +0 -878
  47. package/dist/shared/openapi.DwaweYRb.d.mts +0 -54
  48. package/dist/shared/openapi.DwaweYRb.d.ts +0 -54
package/dist/index.d.ts CHANGED
@@ -1,117 +1,98 @@
1
- import { OpenAPI, AnyContractProcedure } from '@orpc/contract';
2
- export { OpenAPI } from '@orpc/contract';
3
- export { e as CompositeSchemaConverter, C as ConditionalSchemaConverter, b as OpenAPIGenerator, a as OpenAPIGeneratorGenerateOptions, O as OpenAPIGeneratorOptions, c as SchemaConvertOptions, d as SchemaConverter, S as SchemaConverterComponent } from './shared/openapi.BGy4N6eR.js';
4
- import { HTTPPath, HTTPMethod } from '@orpc/client';
5
- import { JSONSchema } from 'json-schema-typed/draft-2020-12';
6
- export { JSONSchema, ContentEncoding as JSONSchemaContentEncoding, Format as JSONSchemaFormat, TypeName as JSONSchemaTypeName } from 'json-schema-typed/draft-2020-12';
7
- import { JsonifiedClient } from '@orpc/openapi-client';
8
- import { AnyRouter, ClientContext, Lazyable, CreateProcedureClientOptions, InferRouterInitialContext, Schema, ErrorMap, Meta, RouterClient } from '@orpc/server';
9
- import { MaybeOptionalOptions } from '@orpc/shared';
10
- import '@orpc/openapi-client/standard';
1
+ import { O as OpenAPISerializer } from './shared/openapi.C7m7NAmH.js';
2
+ export { B as BracketNotationSerializeResult, a as BracketNotationSerializer, b as BracketNotationSerializerOptions, c as OpenAPIJsonSerialization, d as OpenAPIJsonSerializer, e as OpenAPIJsonSerializerHandler, f as OpenAPIJsonSerializerOptions, g as OpenAPISerializerOptions, h as OpenAPISerializerSerializeOptions } from './shared/openapi.C7m7NAmH.js';
3
+ import { ClientContext, ClientRest, ThrowableError, ORPCClientOptions, ClientLink } from '@orpc/client';
4
+ export { COMMON_ERROR_STATUS_MAP } from '@orpc/client';
5
+ import { AnySchema, ErrorMap, ProcedureContract, InferSchemaInput, InferSchemaOutput, ORPCErrorFromErrorMap, RouterContractClient, RouterContract, AnyProcedureContract } from '@orpc/contract';
6
+ import { PromiseWithError, Value } from '@orpc/shared';
7
+ import { J as JsonifiedValue, b as JsonifiedClientError, c as JsonifiedClient, a as OpenAPIDocument } from './shared/openapi.CYgMBSUF.js';
8
+ export { d as JsonifiedArray, O as OpenAPIOperationObject } from './shared/openapi.CYgMBSUF.js';
9
+ export { a as OpenAPIFunction, O as OpenAPIMeta, b as OpenAPIMetaPlugin, c as OpenAPIMethodMetaPlugin, d as OpenAPIPathMetaPlugin, e as OpenAPIPrefixMetaPlugin, f as OpenAPISpecMetaPlugin, g as getOpenAPIMeta, o as openapi } from './shared/openapi.BQzzr4-4.js';
10
+ import { JsonSchemaConverter, JsonSchema } from '@orpc/json-schema';
11
+ import { AnyRouter, AnyProcedure } from '@orpc/server';
12
+ import '@standardserver/core';
13
+ import '@hey-api/spec-types';
11
14
 
12
- type OverrideOperationValue = Partial<OpenAPI.OperationObject> | ((current: OpenAPI.OperationObject, procedure: AnyContractProcedure) => OpenAPI.OperationObject);
13
- /**
14
- * Customize The Operation Object by proxy an error map item or a middleware.
15
- *
16
- * @see {@link https://orpc.dev/docs/openapi/openapi-specification#customizing-operation-objects Customizing Operation Objects Docs}
17
- */
18
- declare function customOpenAPIOperation<T extends object>(o: T, extend: OverrideOperationValue): T;
19
- declare function getCustomOpenAPIOperation(o: object): OverrideOperationValue | undefined;
20
- declare function applyCustomOpenAPIOperation(operation: OpenAPI.OperationObject, contract: AnyContractProcedure): OpenAPI.OperationObject;
15
+ interface ContractJsonifiedCaller<TClientContext extends ClientContext> {
16
+ <TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap>(procedure: ProcedureContract<TInputSchema, TOutputSchema, TErrorMap>, ...rest: ClientRest<TClientContext, InferSchemaInput<TInputSchema>>): PromiseWithError<JsonifiedValue<InferSchemaOutput<TOutputSchema>>, JsonifiedClientError<ORPCErrorFromErrorMap<TErrorMap> | ThrowableError>>;
17
+ }
18
+ interface ContractJsonifiedCallerOptions<TClientContext extends ClientContext> extends Pick<ORPCClientOptions<JsonifiedClient<RouterContractClient<RouterContract, TClientContext>>>, 'interceptors' | 'scoped'> {
19
+ /**
20
+ * An optional reference to the root router-contract.
21
+ * When provided, the caller will automatically register the called procedure-contract
22
+ * into the router at the path defined by `meta.path`.
23
+ */
24
+ contractRef?: undefined | RouterContract;
25
+ }
26
+ declare function createContractJsonifiedCaller<TClientContext extends ClientContext>(link: ClientLink<TClientContext>, options?: ContractJsonifiedCallerOptions<TClientContext>): ContractJsonifiedCaller<TClientContext>;
21
27
 
22
- /**
23
- * @internal
24
- */
25
- type ObjectSchema = JSONSchema & {
26
- type: 'object';
27
- } & object;
28
- /**
29
- * @internal
30
- */
31
- type FileSchema = JSONSchema & {
32
- type: 'string';
33
- contentMediaType: string;
34
- } & object;
35
- /**
36
- * @internal
37
- */
38
- declare const LOGIC_KEYWORDS: string[];
28
+ declare class OpenAPIGeneratorError extends TypeError {
29
+ }
30
+ interface OpenAPIGeneratorOptions {
31
+ converters?: JsonSchemaConverter[] | undefined;
32
+ /**
33
+ * The serializer used to serialize the generated OpenAPI documentation
34
+ */
35
+ serializer?: Pick<OpenAPISerializer, keyof OpenAPISerializer> | undefined;
36
+ }
37
+ interface OpenAPIGeneratorGenerateOptions {
38
+ base?: Partial<OpenAPIDocument> | undefined;
39
+ /**
40
+ * Controls whether a generated json schema `$defs` at root-level should be moved into `components.schemas`.
41
+ *
42
+ * @default true
43
+ */
44
+ shouldHoistDef?: Value<boolean, [defName: string, defSchema: JsonSchema]>;
45
+ /**
46
+ * Filter procedures. Return `false` to exclude a procedure from the OpenAPI specification.
47
+ *
48
+ * @default true
49
+ */
50
+ filter?: Value<boolean, [contract: AnyProcedureContract | AnyProcedure, path: string[]]>;
51
+ /**
52
+ * Define a custom JSON schema for the error response body when using
53
+ * type-safe errors. Helps align ORPC error formatting with existing API
54
+ * response standards or conventions.
55
+ *
56
+ * @remarks
57
+ * - Return `null | undefined` to use the default error response body shaper.
58
+ */
59
+ customErrorResponseBodySchema?: Value<JsonSchema | undefined | null, [
60
+ definedErrors: {
61
+ code: string;
62
+ defaultMessage: string | undefined;
63
+ dataOptional: boolean;
64
+ dataJsonSchema: JsonSchema;
65
+ }[],
66
+ status: number
67
+ ]>;
68
+ /**
69
+ * Mapping ORPCError Code -> HTTP Status Code
70
+ *
71
+ * @default COMMON_ERROR_STATUS_MAP, DEFAULT_ERROR_STATUS
72
+ */
73
+ errorStatusMap?: Record<string, number> | undefined;
74
+ }
75
+ declare class OpenAPIGenerator {
76
+ private readonly serializer;
77
+ private readonly converter;
78
+ constructor(options?: OpenAPIGeneratorOptions);
79
+ generate(router: RouterContract | AnyRouter, options?: OpenAPIGeneratorGenerateOptions): Promise<OpenAPIDocument>;
80
+ private convertSchema;
81
+ private convertSchemas;
82
+ private request;
83
+ private successResponse;
84
+ private errorResponse;
85
+ }
39
86
 
40
87
  /**
41
- * @internal
42
- */
43
- declare function toOpenAPIPath(path: HTTPPath): string;
44
- /**
45
- * @internal
88
+ * Dynamic parameters are always returned in path order.
46
89
  */
47
- declare function toOpenAPIMethod(method: HTTPMethod): Lowercase<HTTPMethod>;
48
- /**
49
- * @internal
50
- */
51
- declare function toOpenAPIContent(schema: JSONSchema): Record<string, OpenAPI.MediaTypeObject>;
52
- /**
53
- * @internal
54
- */
55
- declare function toOpenAPIEventIteratorContent([yieldsRequired, yieldsSchema]: [boolean, JSONSchema], [returnsRequired, returnsSchema]: [boolean, JSONSchema]): Record<string, OpenAPI.MediaTypeObject>;
56
- /**
57
- * @internal
58
- */
59
- declare function toOpenAPIParameters(schema: ObjectSchema, parameterIn: 'path' | 'query' | 'header' | 'cookie'): OpenAPI.ParameterObject[];
60
- /**
61
- * @internal
62
- */
63
- declare function checkParamsSchema(schema: ObjectSchema, params: string[]): boolean;
64
- /**
65
- * @internal
66
- */
67
- declare function toOpenAPISchema(schema: JSONSchema): OpenAPI.SchemaObject & object;
68
- declare function resolveOpenAPIJsonSchemaRef(doc: OpenAPI.Document, schema: JSONSchema): JSONSchema;
69
- /**
70
- * Simplifies composed object JSON Schemas (using anyOf, oneOf, allOf) by flattening nested compositions
71
- *
72
- * @warning The result is looser than the original schema and may not fully validate the same data.
73
- */
74
- declare function simplifyComposedObjectJsonSchemasAndRefs(schema: JSONSchema, doc?: OpenAPI.Document): JSONSchema;
75
-
76
- 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>>;
77
-
78
- /**
79
- *@internal
80
- */
81
- declare function isFileSchema(schema: JSONSchema): schema is FileSchema;
82
- /**
83
- * @internal
84
- */
85
- declare function isObjectSchema(schema: JSONSchema): schema is ObjectSchema;
86
- /**
87
- * @internal
88
- */
89
- declare function isAnySchema(schema: JSONSchema): boolean;
90
- declare function isNeverSchema(schema: JSONSchema): boolean;
91
- /**
92
- * @internal
93
- */
94
- declare function separateObjectSchema(schema: ObjectSchema, separatedProperties: string[]): [matched: ObjectSchema, rest: ObjectSchema];
95
- /**
96
- * @internal
97
- */
98
- declare function filterSchemaBranches(schema: JSONSchema, check: (schema: JSONSchema) => boolean, matches?: JSONSchema[]): [matches: JSONSchema[], rest: JSONSchema | undefined];
99
- declare function applySchemaOptionality(required: boolean, schema: JSONSchema): JSONSchema;
100
- /**
101
- * Takes a JSON schema and, if it's primarily a union type (anyOf, oneOf),
102
- * recursively expands it into an array of its constituent, non-union base schemas.
103
- * If the schema is not a simple union or is a base type, it's returned as a single-element array.
104
- */
105
- declare function expandUnionSchema(schema: JSONSchema): JSONSchema[];
106
- declare function expandArrayableSchema(schema: JSONSchema): undefined | [items: JSONSchema, array: JSONSchema & {
107
- type: 'array';
108
- items?: JSONSchema;
109
- }];
110
- declare function isPrimitiveSchema(schema: JSONSchema): boolean;
111
-
112
- declare const oo: {
113
- spec: typeof customOpenAPIOperation;
114
- };
90
+ declare function getDynamicPathParams(path: `/${string}`): {
91
+ segment: string;
92
+ startIndex: number;
93
+ parameterName: string;
94
+ allowsSlash: boolean;
95
+ }[] | undefined;
115
96
 
116
- export { LOGIC_KEYWORDS, applyCustomOpenAPIOperation, applySchemaOptionality, checkParamsSchema, createJsonifiedRouterClient, customOpenAPIOperation, expandArrayableSchema, expandUnionSchema, filterSchemaBranches, getCustomOpenAPIOperation, isAnySchema, isFileSchema, isNeverSchema, isObjectSchema, isPrimitiveSchema, oo, resolveOpenAPIJsonSchemaRef, separateObjectSchema, simplifyComposedObjectJsonSchemasAndRefs, toOpenAPIContent, toOpenAPIEventIteratorContent, toOpenAPIMethod, toOpenAPIParameters, toOpenAPIPath, toOpenAPISchema };
117
- export type { FileSchema, ObjectSchema, OverrideOperationValue };
97
+ export { JsonifiedClient, JsonifiedClientError, JsonifiedValue, OpenAPIDocument, OpenAPIGenerator, OpenAPIGeneratorError, OpenAPISerializer, createContractJsonifiedCaller, getDynamicPathParams };
98
+ export type { ContractJsonifiedCaller, ContractJsonifiedCallerOptions, OpenAPIGeneratorGenerateOptions, OpenAPIGeneratorOptions };