@orpc/openapi 2.0.0-beta.49 → 2.0.0-beta.50

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 (65) hide show
  1. package/dist/adapters/aws-lambda/index.d.ts +3 -15
  2. package/dist/adapters/aws-lambda/index.js +1 -1
  3. package/dist/adapters/aws-lambda/openapi-handler.d.ts +8 -9
  4. package/dist/adapters/aws-lambda/openapi-handler.js +19 -17
  5. package/dist/adapters/fastify/index.d.ts +2 -1
  6. package/dist/adapters/fastify/index.js +1 -1
  7. package/dist/adapters/fastify/openapi-handler.d.ts +8 -9
  8. package/dist/adapters/fastify/openapi-handler.js +16 -14
  9. package/dist/adapters/fetch/index.d.ts +3 -2
  10. package/dist/adapters/fetch/index.js +2 -2
  11. package/dist/adapters/fetch/openapi-handler.d.ts +8 -9
  12. package/dist/adapters/fetch/openapi-handler.js +16 -14
  13. package/dist/adapters/fetch/openapi-link.d.ts +9 -10
  14. package/dist/adapters/fetch/openapi-link.js +21 -19
  15. package/dist/adapters/node/index.d.ts +2 -1
  16. package/dist/adapters/node/index.js +1 -1
  17. package/dist/adapters/node/openapi-handler.d.ts +8 -9
  18. package/dist/adapters/node/openapi-handler.js +16 -14
  19. package/dist/adapters/standard/index.d.ts +4 -3
  20. package/dist/adapters/standard/index.js +3 -3
  21. package/dist/adapters/standard/openapi-handler-codec.d.ts +56 -57
  22. package/dist/adapters/standard/openapi-handler-codec.js +143 -205
  23. package/dist/adapters/standard/openapi-link-codec.d.ts +55 -59
  24. package/dist/adapters/standard/openapi-link-codec.js +262 -377
  25. package/dist/adapters/standard/openapi-matcher.d.ts +26 -26
  26. package/dist/adapters/standard/openapi-matcher.js +78 -108
  27. package/dist/adapters/standard/utils.js +28 -44
  28. package/dist/bracket-notation.d.ts +22 -22
  29. package/dist/bracket-notation.js +123 -173
  30. package/dist/client-factory.d.ts +12 -12
  31. package/dist/client-factory.js +13 -11
  32. package/dist/constants.d.ts +1 -4
  33. package/dist/constants.js +5 -4
  34. package/dist/extensions/route.d.ts +36 -36
  35. package/dist/extensions/route.js +7 -6
  36. package/dist/helpers/form-data.d.ts +1 -1
  37. package/dist/helpers/form-data.js +74 -86
  38. package/dist/helpers/index.d.ts +2 -1
  39. package/dist/helpers/index.js +1 -1
  40. package/dist/index.d.ts +15 -13
  41. package/dist/index.js +11 -11
  42. package/dist/meta.d.ts +298 -298
  43. package/dist/meta.js +54 -72
  44. package/dist/openapi-generator-components.d.ts +2 -31
  45. package/dist/openapi-generator-components.js +200 -248
  46. package/dist/openapi-generator-operation.d.ts +12 -33
  47. package/dist/openapi-generator-operation.js +369 -437
  48. package/dist/openapi-generator.d.ts +75 -80
  49. package/dist/openapi-generator.js +114 -142
  50. package/dist/openapi-json-serializer.d.ts +65 -65
  51. package/dist/openapi-json-serializer.js +218 -257
  52. package/dist/openapi-serializer.d.ts +31 -32
  53. package/dist/openapi-serializer.js +68 -92
  54. package/dist/plugins/index.d.ts +2 -1
  55. package/dist/plugins/index.js +1 -1
  56. package/dist/plugins/openapi-reference.d.ts +99 -102
  57. package/dist/plugins/openapi-reference.js +109 -132
  58. package/dist/router-utils.d.ts +7 -10
  59. package/dist/router-utils.js +30 -34
  60. package/dist/types.d.ts +8 -12
  61. package/dist/utils.d.ts +5 -10
  62. package/dist/utils.js +39 -42
  63. package/package.json +12 -12
  64. package/dist/adapters/standard/utils.d.ts +0 -4
  65. package/dist/types.js +0 -1
@@ -1,29 +1,29 @@
1
- import type { AnyProcedureContract } from '@orpc/contract';
2
- import type { AnyProcedure, AnyRouter } from '@orpc/server';
3
- import type { Value } from '@orpc/shared';
1
+ import { Value } from "@orpc/shared";
2
+ import { AnyProcedureContract } from "@orpc/contract";
3
+ import { AnyProcedure, AnyRouter } from "@orpc/server";
4
4
  export interface OpenAPIMatcherOptions {
5
- /**
6
- * Filter which procedures are exposed for matching. Return `false` to exclude.
7
- *
8
- * @default true
9
- */
10
- filter?: Value<boolean, [contract: AnyProcedureContract | AnyProcedure, path: string[]]> | undefined;
5
+ /**
6
+ * Filter which procedures are exposed for matching. Return `false` to exclude.
7
+ *
8
+ * @default true
9
+ */
10
+ filter?: Value<boolean, [contract: AnyProcedureContract | AnyProcedure, path: string[]]> | undefined;
11
11
  }
12
12
  export declare class OpenAPIMatcher {
13
- private readonly filter;
14
- private readonly rootRouter;
15
- private readonly tree;
16
- private readonly pendingLazyRouters;
17
- constructor(router: AnyRouter, options?: OpenAPIMatcherOptions);
18
- private index;
19
- match(method: string, pathname: `/${string}`, prefix: `/${string}` | undefined): Promise<{
20
- path: string[];
21
- procedure: AnyProcedure;
22
- params?: Record<string, string> | undefined;
23
- } | undefined>;
24
- private resolvePendingLazyRouters;
25
- private loadPendingLazyRouters;
26
- private loadPendingLazyRouter;
27
- private indexPendingLazyRouter;
28
- private resolveProcedure;
29
- }
13
+ private readonly filter;
14
+ private readonly rootRouter;
15
+ private readonly tree;
16
+ private readonly pendingLazyRouters;
17
+ constructor(router: AnyRouter, options?: OpenAPIMatcherOptions);
18
+ private index;
19
+ match(method: string, pathname: `/${string}`, prefix: `/${string}` | undefined): Promise<{
20
+ path: string[];
21
+ procedure: AnyProcedure;
22
+ params?: Record<string, string> | undefined;
23
+ } | undefined>;
24
+ private resolvePendingLazyRouters;
25
+ private loadPendingLazyRouters;
26
+ private loadPendingLazyRouter;
27
+ private indexPendingLazyRouter;
28
+ private resolveProcedure;
29
+ }
@@ -1,108 +1,78 @@
1
- import { createPrefixMatcher, Router } from '@openapi-spec/router';
2
- import { Procedure, resolveContractProcedure, unlazy, walkProcedureContractsSync, } from '@orpc/server';
3
- import { mergeHttpPath, pathToHttpPath, value } from '@orpc/shared';
4
- import { DEFAULT_OPENAPI_METHOD } from '../../constants.js';
5
- import { getOpenAPIMeta } from '../../meta.js';
6
- export class OpenAPIMatcher {
7
- filter;
8
- rootRouter;
9
- tree = new Router();
10
- pendingLazyRouters = new Set();
11
- constructor(router, options = {}) {
12
- this.filter = options.filter ?? true;
13
- this.rootRouter = router;
14
- this.index(router);
15
- }
16
- index(router, path = []) {
17
- const lazyResults = walkProcedureContractsSync(router, (contract, path) => {
18
- if (!value(this.filter, contract, path)) {
19
- return;
20
- }
21
- const meta = getOpenAPIMeta(contract);
22
- const method = meta?.method ?? DEFAULT_OPENAPI_METHOD;
23
- const postHttpPath = meta?.path ?? pathToHttpPath(path);
24
- const httpPath = meta?.prefix ? mergeHttpPath(meta.prefix, postHttpPath) : postHttpPath;
25
- this.tree.add(method, httpPath, {
26
- path,
27
- contract,
28
- procedure: contract instanceof Procedure ? contract : undefined,
29
- });
30
- }, path);
31
- for (const result of lazyResults) {
32
- const prefix = getOpenAPIMeta(result.router)?.prefix;
33
- this.pendingLazyRouters.add({
34
- ...result,
35
- matcher: prefix ? createPrefixMatcher(prefix) : undefined,
36
- });
37
- }
38
- }
39
- async match(method, pathname, prefix) {
40
- if (prefix) {
41
- if (!pathname.startsWith(prefix)) {
42
- return undefined;
43
- }
44
- const charAfterPrefix = pathname[prefix.length];
45
- if (charAfterPrefix === '/') {
46
- pathname = pathname.slice(prefix.length);
47
- }
48
- else if (charAfterPrefix === undefined) {
49
- pathname = '/';
50
- }
51
- else if (prefix[prefix.length - 1] === '/') {
52
- pathname = pathname.slice(prefix.length - 1);
53
- }
54
- else {
55
- return undefined;
56
- }
57
- }
58
- // most requests `await undefined` so conditionally await it to save a microtask turn
59
- const loading = this.resolvePendingLazyRouters(pathname);
60
- if (loading !== undefined) {
61
- await loading;
62
- }
63
- const match = this.tree.match(method, pathname);
64
- if (match === undefined) {
65
- return undefined;
66
- }
67
- const entry = match.data;
68
- return {
69
- path: entry.path,
70
- procedure: entry.procedure ?? (await this.resolveProcedure(entry)),
71
- params: match.params,
72
- };
73
- }
74
- resolvePendingLazyRouters(pathname) {
75
- for (const pending of this.pendingLazyRouters) {
76
- if (pending.matcher === undefined || pending.matcher(pathname)) {
77
- return this.loadPendingLazyRouters(pathname);
78
- }
79
- }
80
- }
81
- async loadPendingLazyRouters(pathname) {
82
- for (const pending of this.pendingLazyRouters) {
83
- if (pending.matcher === undefined || pending.matcher(pathname)) {
84
- await this.loadPendingLazyRouter(pending);
85
- }
86
- }
87
- }
88
- loadPendingLazyRouter(pending) {
89
- if (pending.loading === undefined) {
90
- pending.loading = this.indexPendingLazyRouter(pending).catch((error) => {
91
- pending.loading = undefined;
92
- throw error;
93
- });
94
- }
95
- return pending.loading;
96
- }
97
- async indexPendingLazyRouter(pending) {
98
- const { default: router } = await unlazy(pending.router);
99
- this.index(router, pending.path);
100
- // removed only once indexed, so a concurrent match never observes this router as
101
- // neither pending nor indexed
102
- this.pendingLazyRouters.delete(pending);
103
- }
104
- async resolveProcedure(entry) {
105
- entry.procedure = await resolveContractProcedure(this.rootRouter, entry.contract, entry.path);
106
- return entry.procedure;
107
- }
108
- }
1
+ import "../../constants.js";
2
+ import { getOpenAPIMeta } from "../../meta.js";
3
+ import { mergeHttpPath, pathToHttpPath, stripHttpPathPrefix, value } from "@orpc/shared";
4
+ import { Procedure, resolveContractProcedure, unlazy, walkProcedureContractsSync } from "@orpc/server";
5
+ import { Router as Router$1, createPrefixMatcher } from "@openapi-spec/router";
6
+ // src/adapters/standard/openapi-matcher.ts
7
+ var OpenAPIMatcher = class {
8
+ filter;
9
+ rootRouter;
10
+ tree = new Router$1();
11
+ pendingLazyRouters = /* @__PURE__ */ new Set();
12
+ constructor(router, options = {}) {
13
+ this.filter = options.filter ?? true;
14
+ this.rootRouter = router;
15
+ this.index(router);
16
+ }
17
+ index(router, path = []) {
18
+ const lazyResults = walkProcedureContractsSync(router, (contract, path) => {
19
+ if (!value(this.filter, contract, path)) return;
20
+ const meta = getOpenAPIMeta(contract);
21
+ const method = meta?.method ?? "POST";
22
+ const postHttpPath = meta?.path ?? pathToHttpPath(path);
23
+ const httpPath = meta?.prefix ? mergeHttpPath(meta.prefix, postHttpPath) : postHttpPath;
24
+ this.tree.add(method, httpPath, {
25
+ path,
26
+ contract,
27
+ procedure: contract instanceof Procedure ? contract : void 0
28
+ });
29
+ }, path);
30
+ for (const result of lazyResults) {
31
+ const prefix = getOpenAPIMeta(result.router)?.prefix;
32
+ this.pendingLazyRouters.add({
33
+ ...result,
34
+ matcher: prefix ? createPrefixMatcher(prefix) : void 0
35
+ });
36
+ }
37
+ }
38
+ async match(method, pathname, prefix) {
39
+ if (prefix) {
40
+ const stripped = stripHttpPathPrefix(pathname, prefix);
41
+ if (stripped === void 0) return;
42
+ pathname = stripped;
43
+ }
44
+ const loading = this.resolvePendingLazyRouters(pathname);
45
+ if (loading !== void 0) await loading;
46
+ const match = this.tree.match(method, pathname);
47
+ if (match === void 0) return;
48
+ const entry = match.data;
49
+ return {
50
+ path: entry.path,
51
+ procedure: entry.procedure ?? await this.resolveProcedure(entry),
52
+ params: match.params
53
+ };
54
+ }
55
+ resolvePendingLazyRouters(pathname) {
56
+ for (const pending of this.pendingLazyRouters) if (pending.matcher === void 0 || pending.matcher(pathname)) return this.loadPendingLazyRouters(pathname);
57
+ }
58
+ async loadPendingLazyRouters(pathname) {
59
+ for (const pending of this.pendingLazyRouters) if (pending.matcher === void 0 || pending.matcher(pathname)) await this.loadPendingLazyRouter(pending);
60
+ }
61
+ loadPendingLazyRouter(pending) {
62
+ if (pending.loading === void 0) pending.loading = this.indexPendingLazyRouter(pending).catch((error) => {
63
+ pending.loading = void 0;
64
+ throw error;
65
+ });
66
+ return pending.loading;
67
+ }
68
+ async indexPendingLazyRouter(pending) {
69
+ const { default: router } = await unlazy(pending.router);
70
+ this.index(router, pending.path);
71
+ this.pendingLazyRouters.delete(pending);
72
+ }
73
+ async resolveProcedure(entry) {
74
+ entry.procedure = await resolveContractProcedure(this.rootRouter, entry.contract, entry.path);
75
+ return entry.procedure;
76
+ }
77
+ };
78
+ export { OpenAPIMatcher };
@@ -1,47 +1,31 @@
1
- import { isNonPrimitive, NullProtoObj } from '@orpc/shared';
2
- export function serializeHeaders(headers, serializer) {
3
- const result = new NullProtoObj();
4
- for (const [key, value] of Object.entries(headers)) {
5
- /**
6
- * Only an actual array value represents a multi-value header (sent as multiple lines).
7
- * Serialization can turn non-array values into arrays (e.g. Set, Map, custom handlers),
8
- * and those must stay a single line, so the structure is checked before serializing.
9
- */
10
- if (Array.isArray(value)) {
11
- const lines = [];
12
- for (const item of value) {
13
- const line = serializeHeaderValue(item, serializer);
14
- if (line !== undefined) {
15
- lines.push(line);
16
- }
17
- }
18
- result[key] = lines;
19
- continue;
20
- }
21
- const line = serializeHeaderValue(value, serializer);
22
- if (line !== undefined) {
23
- result[key] = line;
24
- }
25
- }
26
- return result;
1
+ import { NullProtoObj, isNonPrimitive } from "@orpc/shared";
2
+ // src/adapters/standard/utils.ts
3
+ function serializeHeaders(headers, serializer) {
4
+ const result = new NullProtoObj();
5
+ for (const [key, value] of Object.entries(headers)) {
6
+ /**
7
+ * Only an actual array value represents a multi-value header (sent as multiple lines).
8
+ * Serialization can turn non-array values into arrays (e.g. Set, Map, custom handlers),
9
+ * and those must stay a single line, so the structure is checked before serializing.
10
+ */
11
+ if (Array.isArray(value)) {
12
+ const lines = [];
13
+ for (const item of value) {
14
+ const line = serializeHeaderValue(item, serializer);
15
+ if (line !== void 0) lines.push(line);
16
+ }
17
+ result[key] = lines;
18
+ continue;
19
+ }
20
+ const line = serializeHeaderValue(value, serializer);
21
+ if (line !== void 0) result[key] = line;
22
+ }
23
+ return result;
27
24
  }
28
25
  function serializeHeaderValue(value, serializer) {
29
- const serialized = serializer.serializeJson(value).json;
30
- if (Array.isArray(serialized)) {
31
- return serialized
32
- .filter((item) => item !== undefined && item !== null)
33
- .map(String)
34
- .join(',');
35
- }
36
- if (isNonPrimitive(serialized)) {
37
- return Object.entries(serialized)
38
- .filter(([, val]) => val !== undefined && val !== null)
39
- .map(([key, val]) => `${key},${String(val)}`)
40
- .join(',');
41
- }
42
- if (serialized !== undefined && serialized !== null) {
43
- // oxlint-disable-next-line typescript/no-base-to-string
44
- return String(serialized);
45
- }
46
- return undefined;
26
+ const serialized = serializer.serializeJson(value).json;
27
+ if (Array.isArray(serialized)) return serialized.filter((item) => item !== void 0 && item !== null).map(String).join(",");
28
+ if (isNonPrimitive(serialized)) return Object.entries(serialized).filter(([, val]) => val !== void 0 && val !== null).map(([key, val]) => `${key},${String(val)}`).join(",");
29
+ if (serialized !== void 0 && serialized !== null) return String(serialized);
47
30
  }
31
+ export { serializeHeaders };
@@ -1,26 +1,26 @@
1
- import type { Segment } from '@orpc/shared';
1
+ import { Segment } from "@orpc/shared";
2
2
  export type BracketNotationSerializeResult = [string, unknown][];
3
3
  export interface BracketNotationSerializerOptions {
4
- /**
5
- * Maximum number of empty slots that explicit array indexes may leave in total during deserialization
6
- * (e.g., `a[0]=x&a[3]=y` leaves 2). An index that would exceed it turns its array into an object
7
- * instead (e.g., `?arr[5000]=x` becomes `{ arr: { 5000: 'x' } }`).
8
- *
9
- * Empty slots take memory (a lone `?arr[999]=x` takes ~12KB in V8), and code iterating an array walks
10
- * every one of them, so this keeps both in line with the input.
11
- *
12
- * NOTE: Append-style notation (e.g., `arr[]`) never leaves empty slots.
13
- *
14
- * @default 1_000
15
- */
16
- maxDeserializingEmptySlots?: number | undefined;
4
+ /**
5
+ * Maximum number of empty slots that explicit array indexes may leave in total during deserialization
6
+ * (e.g., `a[0]=x&a[3]=y` leaves 2). An index that would exceed it turns its array into an object
7
+ * instead (e.g., `?arr[5000]=x` becomes `{ arr: { 5000: 'x' } }`).
8
+ *
9
+ * Empty slots take memory (a lone `?arr[999]=x` takes ~12KB in V8), and code iterating an array walks
10
+ * every one of them, so this keeps both in line with the input.
11
+ *
12
+ * NOTE: Append-style notation (e.g., `arr[]`) never leaves empty slots.
13
+ *
14
+ * @default 1_000
15
+ */
16
+ maxDeserializingEmptySlots?: number | undefined;
17
17
  }
18
18
  export declare class BracketNotationSerializer {
19
- private readonly maxDeserializingEmptySlots;
20
- constructor(options?: BracketNotationSerializerOptions);
21
- serialize(data: unknown): BracketNotationSerializeResult;
22
- private internalSerialize;
23
- deserialize(serialized: BracketNotationSerializeResult): Record<string, unknown>;
24
- stringifyPath(segments: readonly Segment[]): string;
25
- parsePath(path: string): string[];
26
- }
19
+ private readonly maxDeserializingEmptySlots;
20
+ constructor(options?: BracketNotationSerializerOptions);
21
+ serialize(data: unknown): BracketNotationSerializeResult;
22
+ private internalSerialize;
23
+ deserialize(serialized: BracketNotationSerializeResult): Record<string, unknown>;
24
+ stringifyPath(segments: readonly Segment[]): string;
25
+ parsePath(path: string): string[];
26
+ }