@orpc/openapi 0.0.0-next.8f9385e → 0.0.0-next.93e7a4c

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.
@@ -0,0 +1,84 @@
1
+ /**
2
+ * Serialize an object or array into a list of [key, value] pairs.
3
+ * The key will express by using bracket-notation.
4
+ *
5
+ * Notice: This way cannot express the empty object or array.
6
+ *
7
+ * @example
8
+ * ```ts
9
+ * const payload = {
10
+ * name: 'John Doe',
11
+ * pets: ['dog', 'cat'],
12
+ * }
13
+ *
14
+ * const entities = serialize(payload)
15
+ *
16
+ * expect(entities).toEqual([
17
+ * ['name', 'John Doe'],
18
+ * ['name[pets][0]', 'dog'],
19
+ * ['name[pets][1]', 'cat'],
20
+ * ])
21
+ * ```
22
+ */
23
+ export declare function serialize(payload: unknown, parentKey?: string): [string, unknown][];
24
+ /**
25
+ * Deserialize a list of [key, value] pairs into an object or array.
26
+ * The key is expressed by using bracket-notation.
27
+ *
28
+ * @example
29
+ * ```ts
30
+ * const entities = [
31
+ * ['name', 'John Doe'],
32
+ * ['name[pets][0]', 'dog'],
33
+ * ['name[pets][1]', 'cat'],
34
+ * ['name[dogs][]', 'hello'],
35
+ * ['name[dogs][]', 'kitty'],
36
+ * ]
37
+ *
38
+ * const payload = deserialize(entities)
39
+ *
40
+ * expect(payload).toEqual({
41
+ * name: 'John Doe',
42
+ * pets: { 0: 'dog', 1: 'cat' },
43
+ * dogs: ['hello', 'kitty'],
44
+ * })
45
+ * ```
46
+ */
47
+ export declare function deserialize(entities: readonly (readonly [string, unknown])[]): Record<string, unknown> | unknown[] | undefined;
48
+ /**
49
+ * Escape the `[`, `]`, and `\` chars in a path segment.
50
+ *
51
+ * @example
52
+ * ```ts
53
+ * expect(escapeSegment('name[pets')).toEqual('name\\[pets')
54
+ * ```
55
+ */
56
+ export declare function escapeSegment(segment: string): string;
57
+ /**
58
+ * Convert an array of path segments into a path string using bracket-notation.
59
+ *
60
+ * For the special char `[`, `]`, and `\` will be escaped by adding `\` at start.
61
+ *
62
+ * @example
63
+ * ```ts
64
+ * expect(stringifyPath(['name', 'pets', '0'])).toEqual('name[pets][0]')
65
+ * ```
66
+ */
67
+ export declare function stringifyPath(path: readonly [string, ...string[]]): string;
68
+ /**
69
+ * Convert a path string using bracket-notation into an array of path segments.
70
+ *
71
+ * For the special char `[`, `]`, and `\` you should escape by adding `\` at start.
72
+ * It only treats a pair `[${string}]` as a path segment.
73
+ * If missing or escape it will bypass and treat as normal string.
74
+ *
75
+ * @example
76
+ * ```ts
77
+ * expect(parsePath('name[pets][0]')).toEqual(['name', 'pets', '0'])
78
+ * expect(parsePath('name[pets][0')).toEqual(['name', 'pets', '[0'])
79
+ * expect(parsePath('name[pets[0]')).toEqual(['name', 'pets[0')
80
+ * expect(parsePath('name\\[pets][0]')).toEqual(['name[pets]', '0'])
81
+ * ```
82
+ */
83
+ export declare function parsePath(path: string): [string, ...string[]];
84
+ //# sourceMappingURL=bracket-notation.d.ts.map
@@ -1,4 +1,10 @@
1
- export * from './base-handler';
2
- export * from './server-handler';
3
- export * from './serverless-handler';
1
+ export * from './bracket-notation';
2
+ export * from './input-builder-full';
3
+ export * from './input-builder-simple';
4
+ export * from './openapi-handler';
5
+ export * from './openapi-handler-server';
6
+ export * from './openapi-handler-serverless';
7
+ export * from './openapi-payload-codec';
8
+ export * from './openapi-procedure-matcher';
9
+ export * from './schema-coercer';
4
10
  //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,11 @@
1
+ import type { Params } from 'hono/router';
2
+ export declare class InputBuilderFull {
3
+ build(params: Params, query: unknown, headers: unknown, body: unknown): {
4
+ params: Params;
5
+ query: unknown;
6
+ headers: unknown;
7
+ body: unknown;
8
+ };
9
+ }
10
+ export type PublicInputBuilderFull = Pick<InputBuilderFull, keyof InputBuilderFull>;
11
+ //# sourceMappingURL=input-builder-full.d.ts.map
@@ -0,0 +1,6 @@
1
+ import type { Params } from 'hono/router';
2
+ export declare class InputBuilderSimple {
3
+ build(params: Params, payload: unknown): unknown;
4
+ }
5
+ export type PublicInputBuilderSimple = Pick<InputBuilderSimple, keyof InputBuilderSimple>;
6
+ //# sourceMappingURL=input-builder-simple.d.ts.map
@@ -0,0 +1,7 @@
1
+ import type { Context, Router } from '@orpc/server';
2
+ import type { OpenAPIHandlerOptions } from './openapi-handler';
3
+ import { OpenAPIHandler } from './openapi-handler';
4
+ export declare class OpenAPIServerHandler<T extends Context> extends OpenAPIHandler<T> {
5
+ constructor(router: Router<T, any>, options?: NoInfer<OpenAPIHandlerOptions<T>>);
6
+ }
7
+ //# sourceMappingURL=openapi-handler-server.d.ts.map
@@ -0,0 +1,7 @@
1
+ import type { Context, Router } from '@orpc/server';
2
+ import type { OpenAPIHandlerOptions } from './openapi-handler';
3
+ import { OpenAPIHandler } from './openapi-handler';
4
+ export declare class OpenAPIServerlessHandler<T extends Context> extends OpenAPIHandler<T> {
5
+ constructor(router: Router<T, any>, options?: NoInfer<OpenAPIHandlerOptions<T>>);
6
+ }
7
+ //# sourceMappingURL=openapi-handler-serverless.d.ts.map
@@ -0,0 +1,28 @@
1
+ import type { ConditionalFetchHandler, FetchOptions } from '@orpc/server/fetch';
2
+ import type { PublicInputBuilderSimple } from './input-builder-simple';
3
+ import { type Context, type Router, type WithSignal } from '@orpc/server';
4
+ import { type Hooks } from '@orpc/shared';
5
+ import { type PublicInputBuilderFull } from './input-builder-full';
6
+ import { type PublicOpenAPIPayloadCodec } from './openapi-payload-codec';
7
+ import { type Hono, type PublicOpenAPIProcedureMatcher } from './openapi-procedure-matcher';
8
+ import { type SchemaCoercer } from './schema-coercer';
9
+ export type OpenAPIHandlerOptions<T extends Context> = Hooks<Request, Response, T, WithSignal> & {
10
+ procedureMatcher?: PublicOpenAPIProcedureMatcher;
11
+ payloadCodec?: PublicOpenAPIPayloadCodec;
12
+ inputBuilderSimple?: PublicInputBuilderSimple;
13
+ inputBuilderFull?: PublicInputBuilderFull;
14
+ schemaCoercers?: SchemaCoercer[];
15
+ };
16
+ export declare class OpenAPIHandler<T extends Context> implements ConditionalFetchHandler<T> {
17
+ private readonly options?;
18
+ private readonly procedureMatcher;
19
+ private readonly payloadCodec;
20
+ private readonly inputBuilderSimple;
21
+ private readonly inputBuilderFull;
22
+ private readonly compositeSchemaCoercer;
23
+ constructor(hono: Hono, router: Router<T, any>, options?: NoInfer<OpenAPIHandlerOptions<T>> | undefined);
24
+ condition(request: Request): boolean;
25
+ fetch(request: Request, ...[options]: [options: FetchOptions<T>] | (undefined extends T ? [] : never)): Promise<Response>;
26
+ private convertToORPCError;
27
+ }
28
+ //# sourceMappingURL=openapi-handler.d.ts.map
@@ -0,0 +1,13 @@
1
+ export declare class OpenAPIPayloadCodec {
2
+ encode(payload: unknown, accept?: string): {
3
+ body: FormData | Blob | string | undefined;
4
+ headers?: Headers;
5
+ };
6
+ private encodeAsJSON;
7
+ private encodeAsFormData;
8
+ private encodeAsURLSearchParams;
9
+ serialize(payload: unknown): unknown;
10
+ decode(re: Request | Response | Headers | URLSearchParams | FormData): Promise<unknown>;
11
+ }
12
+ export type PublicOpenAPIPayloadCodec = Pick<OpenAPIPayloadCodec, keyof OpenAPIPayloadCodec>;
13
+ //# sourceMappingURL=openapi-payload-codec.d.ts.map
@@ -0,0 +1,19 @@
1
+ import type { Router as BaseHono, Params } from 'hono/router';
2
+ import { type ANY_PROCEDURE, type ANY_ROUTER } from '@orpc/server';
3
+ export type Hono = BaseHono<[string, string[]]>;
4
+ export declare class OpenAPIProcedureMatcher {
5
+ private readonly hono;
6
+ private readonly router;
7
+ private pendingRouters;
8
+ constructor(hono: Hono, router: ANY_ROUTER);
9
+ match(method: string, pathname: string): Promise<{
10
+ path: string[];
11
+ procedure: ANY_PROCEDURE;
12
+ params: Params;
13
+ } | undefined>;
14
+ private add;
15
+ private handlePendingRouters;
16
+ private convertOpenAPIPathToRouterPath;
17
+ }
18
+ export type PublicOpenAPIProcedureMatcher = Pick<OpenAPIProcedureMatcher, keyof OpenAPIProcedureMatcher>;
19
+ //# sourceMappingURL=openapi-procedure-matcher.d.ts.map
@@ -0,0 +1,10 @@
1
+ import type { Schema } from '@orpc/contract';
2
+ export interface SchemaCoercer {
3
+ coerce: (schema: Schema, value: unknown) => unknown;
4
+ }
5
+ export declare class CompositeSchemaCoercer implements SchemaCoercer {
6
+ private readonly coercers;
7
+ constructor(coercers: SchemaCoercer[]);
8
+ coerce(schema: Schema, value: unknown): unknown;
9
+ }
10
+ //# sourceMappingURL=schema-coercer.d.ts.map
@@ -1,5 +1,6 @@
1
+ import type { PublicOpenAPIPayloadCodec } from './fetch';
1
2
  import { type ContractRouter } from '@orpc/contract';
2
- import { type Router } from '@orpc/server';
3
+ import { type ANY_ROUTER } from '@orpc/server';
3
4
  import { type OpenAPIObject } from 'openapi3-ts/oas31';
4
5
  export interface GenerateOpenAPIOptions {
5
6
  /**
@@ -17,8 +18,9 @@ export interface GenerateOpenAPIOptions {
17
18
  * @default false
18
19
  */
19
20
  ignoreUndefinedPathProcedures?: boolean;
21
+ payloadCodec?: PublicOpenAPIPayloadCodec;
20
22
  }
21
23
  export declare function generateOpenAPI(opts: {
22
- router: ContractRouter | Router<any>;
23
- } & Omit<OpenAPIObject, 'openapi'>, options?: GenerateOpenAPIOptions): OpenAPIObject;
24
+ router: ContractRouter | ANY_ROUTER;
25
+ } & Omit<OpenAPIObject, 'openapi'>, options?: GenerateOpenAPIOptions): Promise<OpenAPIObject>;
24
26
  //# sourceMappingURL=generator.d.ts.map
@@ -0,0 +1,17 @@
1
+ import type { ContractRouter, HTTPPath, WELL_CONTRACT_PROCEDURE } from '@orpc/contract';
2
+ import type { ANY_PROCEDURE, ANY_ROUTER, Lazy } from '@orpc/server';
3
+ export interface EachLeafOptions {
4
+ router: ContractRouter | ANY_ROUTER;
5
+ path: string[];
6
+ }
7
+ export interface EachLeafCallbackOptions {
8
+ contract: WELL_CONTRACT_PROCEDURE;
9
+ path: string[];
10
+ }
11
+ export interface EachContractLeafResultItem {
12
+ router: Lazy<ANY_PROCEDURE> | Lazy<Record<string, ANY_ROUTER> | ANY_PROCEDURE>;
13
+ path: string[];
14
+ }
15
+ export declare function forEachContractProcedure(options: EachLeafOptions, callback: (options: EachLeafCallbackOptions) => void, result?: EachContractLeafResultItem[], isCurrentRouterContract?: boolean): EachContractLeafResultItem[];
16
+ export declare function standardizeHTTPPath(path: HTTPPath): HTTPPath;
17
+ //# sourceMappingURL=utils.d.ts.map
@@ -1,5 +1,5 @@
1
+ import type { StandardSchemaV1 } from '@standard-schema/spec';
1
2
  import { type JSONSchema } from 'json-schema-typed/draft-2020-12';
2
- import { type ZodTypeAny } from 'zod';
3
3
  export declare const NON_LOGIC_KEYWORDS: ("$anchor" | "$comment" | "$defs" | "$dynamicAnchor" | "$dynamicRef" | "$id" | "$schema" | "$vocabulary" | "contentEncoding" | "contentMediaType" | "default" | "definitions" | "deprecated" | "description" | "examples" | "format" | "readOnly" | "title" | "writeOnly")[];
4
4
  export declare const UNSUPPORTED_JSON_SCHEMA: {
5
5
  not: {};
@@ -35,7 +35,7 @@ export interface ZodToJsonSchemaOptions {
35
35
  */
36
36
  isHandledCustomJSONSchema?: boolean;
37
37
  }
38
- export declare function zodToJsonSchema(schema: ZodTypeAny, options?: ZodToJsonSchemaOptions): Exclude<JSONSchema, boolean>;
38
+ export declare function zodToJsonSchema(schema: StandardSchemaV1, options?: ZodToJsonSchemaOptions): Exclude<JSONSchema, boolean>;
39
39
  export declare function extractJSONSchema(schema: JSONSchema, check: (schema: JSONSchema) => boolean, matches?: JSONSchema[]): {
40
40
  schema: JSONSchema | undefined;
41
41
  matches: JSONSchema[];
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@orpc/openapi",
3
3
  "type": "module",
4
- "version": "0.0.0-next.8f9385e",
4
+ "version": "0.0.0-next.93e7a4c",
5
5
  "license": "MIT",
6
6
  "homepage": "https://orpc.unnoq.com",
7
7
  "repository": {
@@ -34,19 +34,22 @@
34
34
  "dist"
35
35
  ],
36
36
  "dependencies": {
37
+ "@standard-schema/spec": "1.0.0-beta.4",
38
+ "@types/content-disposition": "^0.5.8",
39
+ "content-disposition": "^0.5.4",
37
40
  "escape-string-regexp": "^5.0.0",
41
+ "fast-content-type-parse": "^2.0.0",
42
+ "hono": "^4.6.12",
38
43
  "json-schema-typed": "^8.0.1",
39
44
  "openapi3-ts": "^4.4.0",
40
- "@orpc/contract": "0.0.0-next.8f9385e",
41
- "@orpc/shared": "0.0.0-next.8f9385e",
42
- "@orpc/transformer": "0.0.0-next.8f9385e",
43
- "@orpc/server": "0.0.0-next.8f9385e",
44
- "@orpc/zod": "0.0.0-next.8f9385e"
45
+ "wildcard-match": "^5.1.3",
46
+ "@orpc/contract": "0.0.0-next.93e7a4c",
47
+ "@orpc/shared": "0.0.0-next.93e7a4c",
48
+ "@orpc/server": "0.0.0-next.93e7a4c"
45
49
  },
46
50
  "devDependencies": {
47
51
  "@readme/openapi-parser": "^2.6.0",
48
- "hono": "^4.6.12",
49
- "zod": "^3.23.8"
52
+ "zod": "^3.24.1"
50
53
  },
51
54
  "scripts": {
52
55
  "build": "tsup --clean --sourcemap --entry.index=src/index.ts --entry.fetch=src/fetch/index.ts --format=esm --onSuccess='tsc -b --noCheck'",
@@ -1,15 +0,0 @@
1
- import type { HTTPPath } from '@orpc/contract';
2
- import type { FetchHandler } from '@orpc/server/fetch';
3
- import type { Router as HonoRouter } from 'hono/router';
4
- import { type Procedure, type Router } from '@orpc/server';
5
- export type ResolveRouter = (router: Router<any>, method: string, pathname: string) => {
6
- path: string[];
7
- procedure: Procedure<any, any, any, any, any>;
8
- params: Record<string, string>;
9
- } | undefined;
10
- type Routing = HonoRouter<[string[], Procedure<any, any, any, any, any>]>;
11
- export declare function createOpenAPIHandler(createHonoRouter: () => Routing): FetchHandler;
12
- export declare function createResolveRouter(createHonoRouter: () => Routing): ResolveRouter;
13
- export declare function openAPIPathToRouterPath(path: HTTPPath): string;
14
- export {};
15
- //# sourceMappingURL=base-handler.d.ts.map
@@ -1,3 +0,0 @@
1
- import type { FetchHandler } from '@orpc/server/fetch';
2
- export declare function createOpenAPIServerHandler(): FetchHandler;
3
- //# sourceMappingURL=server-handler.d.ts.map
@@ -1,3 +0,0 @@
1
- import type { FetchHandler } from '@orpc/server/fetch';
2
- export declare function createOpenAPIServerlessHandler(): FetchHandler;
3
- //# sourceMappingURL=serverless-handler.d.ts.map