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

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 (93) hide show
  1. package/README.md +6 -7
  2. package/dist/adapters/aws-lambda/index.d.ts +10 -22
  3. package/dist/adapters/aws-lambda/index.js +1 -0
  4. package/dist/adapters/aws-lambda/openapi-handler.d.ts +18 -0
  5. package/dist/adapters/aws-lambda/openapi-handler.js +18 -0
  6. package/dist/adapters/fastify/index.d.ts +1 -23
  7. package/dist/adapters/fastify/index.js +1 -0
  8. package/dist/adapters/fastify/openapi-handler.d.ts +15 -0
  9. package/dist/adapters/fastify/openapi-handler.js +15 -0
  10. package/dist/adapters/fetch/index.d.ts +2 -37
  11. package/dist/adapters/fetch/index.js +2 -0
  12. package/dist/adapters/fetch/openapi-handler.d.ts +15 -0
  13. package/dist/adapters/fetch/openapi-handler.js +15 -0
  14. package/dist/adapters/fetch/openapi-link.d.ts +21 -0
  15. package/dist/adapters/fetch/openapi-link.js +20 -0
  16. package/dist/adapters/node/index.d.ts +1 -23
  17. package/dist/adapters/node/index.js +1 -0
  18. package/dist/adapters/node/openapi-handler.d.ts +15 -0
  19. package/dist/adapters/node/openapi-handler.js +15 -0
  20. package/dist/adapters/standard/index.d.ts +3 -56
  21. package/dist/adapters/standard/index.js +3 -0
  22. package/dist/adapters/standard/openapi-handler-codec.d.ts +62 -0
  23. package/dist/adapters/standard/openapi-handler-codec.js +220 -0
  24. package/dist/adapters/standard/{index.d.mts → openapi-link-codec.d.ts} +25 -19
  25. package/dist/adapters/standard/openapi-link-codec.js +405 -0
  26. package/dist/adapters/standard/openapi-matcher.d.ts +29 -0
  27. package/dist/adapters/standard/openapi-matcher.js +108 -0
  28. package/dist/adapters/standard/utils.d.ts +4 -0
  29. package/dist/adapters/standard/utils.js +47 -0
  30. package/dist/bracket-notation.d.ts +26 -0
  31. package/dist/bracket-notation.js +185 -0
  32. package/dist/client-factory.d.ts +24 -0
  33. package/dist/client-factory.js +13 -0
  34. package/dist/constants.d.ts +4 -0
  35. package/dist/constants.js +4 -0
  36. package/dist/extensions/route.d.ts +3 -7
  37. package/dist/extensions/route.js +12 -0
  38. package/dist/helpers/{index.d.mts → form-data.d.ts} +2 -4
  39. package/dist/helpers/form-data.js +90 -0
  40. package/dist/helpers/index.d.ts +1 -59
  41. package/dist/helpers/index.js +1 -0
  42. package/dist/index.d.ts +12 -165
  43. package/dist/index.js +11 -0
  44. package/dist/{shared/openapi.zGZlCOwp.d.mts → meta.d.ts} +14 -18
  45. package/dist/meta.js +84 -0
  46. package/dist/openapi-generator-components.d.ts +31 -0
  47. package/dist/openapi-generator-components.js +275 -0
  48. package/dist/openapi-generator-operation.d.ts +34 -0
  49. package/dist/openapi-generator-operation.js +469 -0
  50. package/dist/openapi-generator.d.ts +92 -0
  51. package/dist/openapi-generator.js +147 -0
  52. package/dist/openapi-json-serializer.d.ts +79 -0
  53. package/dist/openapi-json-serializer.js +260 -0
  54. package/dist/openapi-serializer.d.ts +43 -0
  55. package/dist/openapi-serializer.js +93 -0
  56. package/dist/plugins/index.d.ts +1 -121
  57. package/dist/plugins/index.js +1 -0
  58. package/dist/plugins/{index.d.mts → openapi-reference.d.ts} +15 -21
  59. package/dist/plugins/openapi-reference.js +187 -0
  60. package/dist/router-utils.d.ts +20 -0
  61. package/dist/router-utils.js +36 -0
  62. package/dist/types.d.ts +31 -0
  63. package/dist/types.js +1 -0
  64. package/dist/utils.d.ts +14 -0
  65. package/dist/utils.js +47 -0
  66. package/package.json +69 -71
  67. package/dist/adapters/aws-lambda/index.d.mts +0 -27
  68. package/dist/adapters/aws-lambda/index.mjs +0 -21
  69. package/dist/adapters/fastify/index.d.mts +0 -23
  70. package/dist/adapters/fastify/index.mjs +0 -21
  71. package/dist/adapters/fetch/index.d.mts +0 -37
  72. package/dist/adapters/fetch/index.mjs +0 -34
  73. package/dist/adapters/node/index.d.mts +0 -23
  74. package/dist/adapters/node/index.mjs +0 -21
  75. package/dist/adapters/standard/index.mjs +0 -12
  76. package/dist/extensions/route.d.mts +0 -41
  77. package/dist/extensions/route.mjs +0 -14
  78. package/dist/helpers/index.mjs +0 -39
  79. package/dist/index.d.mts +0 -166
  80. package/dist/index.mjs +0 -780
  81. package/dist/plugins/index.mjs +0 -167
  82. package/dist/shared/openapi.B9PQzqBn.mjs +0 -49
  83. package/dist/shared/openapi.CQkXu1nY.mjs +0 -366
  84. package/dist/shared/openapi.Covi8zVE.d.mts +0 -33
  85. package/dist/shared/openapi.Covi8zVE.d.ts +0 -33
  86. package/dist/shared/openapi.DfmCR1pB.d.mts +0 -94
  87. package/dist/shared/openapi.DtEVcxuW.mjs +0 -149
  88. package/dist/shared/openapi.E3ZBiweM.mjs +0 -353
  89. package/dist/shared/openapi.Y4K_-I5W.d.ts +0 -94
  90. package/dist/shared/openapi.YMRD3b4R.d.mts +0 -157
  91. package/dist/shared/openapi.YMRD3b4R.d.ts +0 -157
  92. package/dist/shared/openapi.g7ucL05o.mjs +0 -410
  93. package/dist/shared/openapi.zGZlCOwp.d.ts +0 -329
@@ -0,0 +1,185 @@
1
+ import { isPlainObject, NullProtoObj, setOwn } from '@orpc/shared';
2
+ export class BracketNotationSerializer {
3
+ maxDeserializingEmptySlots;
4
+ constructor(options = {}) {
5
+ this.maxDeserializingEmptySlots = options.maxDeserializingEmptySlots ?? 1_000;
6
+ }
7
+ serialize(data) {
8
+ const result = [];
9
+ this.internalSerialize(data, '', true, result);
10
+ return result;
11
+ }
12
+ internalSerialize(data, path, isRoot, result) {
13
+ if (Array.isArray(data)) {
14
+ data.forEach((item, i) => {
15
+ this.internalSerialize(item, isRoot ? i.toString() : `${path}[${i}]`, false, result);
16
+ });
17
+ }
18
+ else if (isPlainObject(data)) {
19
+ for (const key of Object.keys(data)) {
20
+ this.internalSerialize(data[key], isRoot ? key : `${path}[${key}]`, false, result);
21
+ }
22
+ }
23
+ else {
24
+ result.push([path, data]);
25
+ }
26
+ }
27
+ deserialize(serialized) {
28
+ // A caller-supplied object value can become a container for deeper paths, and unlike
29
+ // `NullProtoObj` it carries a real prototype, so accesses below stay own-property only.
30
+ let arrayPushStyles;
31
+ const root = new NullProtoObj();
32
+ let emptySlotsLeft = this.maxDeserializingEmptySlots;
33
+ for (const [path, value] of serialized) {
34
+ const segments = this.parsePath(path);
35
+ let currentRef = root;
36
+ // Arrays take keys as numbers, so engines do not parse the same key again on each access
37
+ let nextSegment = segments[0];
38
+ for (let i = 1; i < segments.length; i++) {
39
+ const segment = segments[i];
40
+ const isLast = i === segments.length - 1;
41
+ const hasExisting = Object.hasOwn(currentRef, nextSegment);
42
+ const existing = hasExisting ? currentRef[nextSegment] : undefined;
43
+ let child = existing;
44
+ let key = segment;
45
+ // A missing value is treated like an empty array and a leaf value like a one-item array (as if its key
46
+ // were repeated), which becomes an object if it cannot stay one
47
+ if (Array.isArray(child) || !isPlainObject(child)) {
48
+ if (hasExisting && !Array.isArray(child)) {
49
+ child = [child];
50
+ }
51
+ const isArray = Array.isArray(child);
52
+ const isPushStyle = isArray && !!arrayPushStyles?.has(child);
53
+ const length = isArray ? child.length : 0;
54
+ const index = internalToArrayIndex(segment);
55
+ const emptySlots = index === undefined ? 0 : Math.max(0, index - length);
56
+ const canBeArray = segment === ''
57
+ ? isLast && (isPushStyle || length === 0)
58
+ : index !== undefined && !(isLast && isPushStyle) && emptySlots <= emptySlotsLeft;
59
+ if (canBeArray) {
60
+ emptySlotsLeft -= emptySlots;
61
+ child = isArray ? child : [];
62
+ key = index ?? segment;
63
+ }
64
+ else if (isArray) {
65
+ arrayPushStyles?.delete(child);
66
+ child = isPushStyle
67
+ ? internalPushStyleArrayToObject(child)
68
+ : internalArrayToObject(child);
69
+ }
70
+ else {
71
+ child = new NullProtoObj();
72
+ }
73
+ }
74
+ if (child !== existing) {
75
+ internalSetOwn(currentRef, nextSegment, child);
76
+ }
77
+ currentRef = child;
78
+ nextSegment = key;
79
+ }
80
+ if (Array.isArray(currentRef) && nextSegment === '') {
81
+ arrayPushStyles ??= new WeakSet();
82
+ arrayPushStyles.add(currentRef);
83
+ currentRef.push(value);
84
+ }
85
+ else if (Object.hasOwn(currentRef, nextSegment)) {
86
+ const current = currentRef[nextSegment];
87
+ if (Array.isArray(current)) {
88
+ current.push(value);
89
+ }
90
+ else {
91
+ internalSetOwn(currentRef, nextSegment, [current, value]);
92
+ }
93
+ }
94
+ else {
95
+ internalSetOwn(currentRef, nextSegment, value);
96
+ }
97
+ }
98
+ return root;
99
+ }
100
+ stringifyPath(segments) {
101
+ if (segments.length === 0) {
102
+ return '';
103
+ }
104
+ let result = segments[0].toString();
105
+ for (let i = 1; i < segments.length; i++) {
106
+ result += `[${segments[i]}]`;
107
+ }
108
+ return result;
109
+ }
110
+ parsePath(path) {
111
+ const start = path.indexOf('[');
112
+ // Brackets must open after the first segment and close at the very end, e.g. `a[b][c]`
113
+ if (start === -1 || path[path.length - 1] !== ']') {
114
+ return [path];
115
+ }
116
+ const segments = [path.slice(0, start)];
117
+ let from = start + 1;
118
+ let to = path.indexOf('][', from);
119
+ while (to !== -1) {
120
+ segments.push(path.slice(from, to));
121
+ from = to + 2;
122
+ to = path.indexOf('][', from);
123
+ }
124
+ segments.push(path.slice(from, -1));
125
+ return segments;
126
+ }
127
+ }
128
+ /**
129
+ * The largest array index. Larger integer keys are ordinary properties.
130
+ */
131
+ const MAX_ARRAY_INDEX = 2 ** 32 - 2;
132
+ /**
133
+ * Returns `key` as an array index (no sign, no leading zeros), which is also how engines store the
134
+ * integer keys of objects, or `undefined` if it is not one.
135
+ */
136
+ function internalToArrayIndex(key) {
137
+ // `MAX_ARRAY_INDEX` has 10 digits
138
+ if (key.length === 0 || key.length > 10) {
139
+ return undefined;
140
+ }
141
+ let index = key.charCodeAt(0) - 48; // '0'
142
+ if (index < 0 || index > 9 || (index === 0 && key.length > 1)) {
143
+ return undefined;
144
+ }
145
+ for (let i = 1; i < key.length; i++) {
146
+ const digit = key.charCodeAt(i) - 48;
147
+ if (digit < 0 || digit > 9) {
148
+ return undefined;
149
+ }
150
+ index = index * 10 + digit;
151
+ }
152
+ return index <= MAX_ARRAY_INDEX ? index : undefined;
153
+ }
154
+ function internalArrayToObject(array) {
155
+ const obj = new NullProtoObj(); // Prevent Prototype Pollution with NullProtoObj
156
+ array.forEach((item, i) => {
157
+ obj[i] = item;
158
+ });
159
+ return obj;
160
+ }
161
+ function internalPushStyleArrayToObject(array) {
162
+ const obj = new NullProtoObj();
163
+ obj[''] = array.length === 1 ? array[0] : array;
164
+ return obj;
165
+ }
166
+ /**
167
+ * Like `setOwn`, but first switches an object created during deserialization to sparse storage when an
168
+ * integer key would leave a gap. Engines keep integer keys in a flat backing store sized by the largest one,
169
+ * so a lone `{ 999: x }` takes ~12KB in V8. Holding `MAX_ARRAY_INDEX` switches an object to sparse storage
170
+ * for good (V8 and JSC), so writing and deleting it keeps the object's integer keys cheap without a trace.
171
+ */
172
+ function internalSetOwn(container, key, value) {
173
+ if (typeof key === 'string' && container instanceof NullProtoObj) {
174
+ const index = internalToArrayIndex(key);
175
+ // `0`, or the key right after an existing one, keeps the flat store filled
176
+ if (index !== undefined &&
177
+ index !== 0 &&
178
+ !Object.hasOwn(container, index - 1) &&
179
+ !Object.hasOwn(container, MAX_ARRAY_INDEX)) {
180
+ container[MAX_ARRAY_INDEX] = undefined;
181
+ delete container[MAX_ARRAY_INDEX];
182
+ }
183
+ }
184
+ setOwn(container, key, value);
185
+ }
@@ -0,0 +1,24 @@
1
+ import type { ClientContext, ClientLink, ORPCClientOptions } from '@orpc/client';
2
+ import type { RouterContract, RouterContractClient } from '@orpc/contract';
3
+ import type { JsonifiedClient } from './types.ts';
4
+ export interface ContractJsonifiedClientFactory<TClientContext extends ClientContext> {
5
+ <T extends RouterContract>(contract: T): JsonifiedClient<RouterContractClient<T, TClientContext>>;
6
+ }
7
+ export interface ContractJsonifiedClientFactoryOptions<TClientContext extends ClientContext> extends Pick<ORPCClientOptions<JsonifiedClient<RouterContractClient<RouterContract, TClientContext>>>, 'interceptors' | 'scoped'> {
8
+ /**
9
+ * An optional reference to the root router-contract.
10
+ * When provided, the client factory will automatically register the passed contract
11
+ * into the router at the path defined by `meta.path`.
12
+ */
13
+ contractRef?: RouterContract | undefined;
14
+ }
15
+ /**
16
+ * Like `createContractClientFactory`, but the clients it builds are typed as `JsonifiedClient`,
17
+ * for links that require it, such as OpenAPI Link.
18
+ *
19
+ * @remarks
20
+ * **Warning**: Every procedure contract passed to the factory must define `meta.path` matching its location in the root contract.
21
+ *
22
+ * @see {@link https://orpc.dev/docs/contract/client-factory | Contract Client Factory}
23
+ */
24
+ export declare function createContractJsonifiedClientFactory<TClientContext extends ClientContext>(link: ClientLink<TClientContext>, options?: ContractJsonifiedClientFactoryOptions<TClientContext>): ContractJsonifiedClientFactory<TClientContext>;
@@ -0,0 +1,13 @@
1
+ import { createContractClientFactory } from '@orpc/contract';
2
+ /**
3
+ * Like `createContractClientFactory`, but the clients it builds are typed as `JsonifiedClient`,
4
+ * for links that require it, such as OpenAPI Link.
5
+ *
6
+ * @remarks
7
+ * **Warning**: Every procedure contract passed to the factory must define `meta.path` matching its location in the root contract.
8
+ *
9
+ * @see {@link https://orpc.dev/docs/contract/client-factory | Contract Client Factory}
10
+ */
11
+ export function createContractJsonifiedClientFactory(link, options = {}) {
12
+ return createContractClientFactory(link, options);
13
+ }
@@ -0,0 +1,4 @@
1
+ export declare const DEFAULT_OPENAPI_METHOD = "POST";
2
+ export declare const DEFAULT_OPENAPI_SUCCESS_DESCRIPTION = "OK";
3
+ export declare const DEFAULT_OPENAPI_INPUT_STRUCTURE = "compact";
4
+ export declare const DEFAULT_OPENAPI_OUTPUT_STRUCTURE = "compact";
@@ -0,0 +1,4 @@
1
+ export const DEFAULT_OPENAPI_METHOD = 'POST';
2
+ export const DEFAULT_OPENAPI_SUCCESS_DESCRIPTION = 'OK';
3
+ export const DEFAULT_OPENAPI_INPUT_STRUCTURE = 'compact';
4
+ export const DEFAULT_OPENAPI_OUTPUT_STRUCTURE = 'compact';
@@ -1,10 +1,6 @@
1
- import { ErrorMap, AnySchema } from '@orpc/contract';
2
- import { Context } from '@orpc/server';
3
- import { OpenAPIMeta } from '../index.js';
4
- import '@orpc/shared';
5
- import '@standard-server/core';
6
- import '@openapi-spec/types/v3.2';
7
-
1
+ import type { AnySchema, ErrorMap } from '@orpc/contract';
2
+ import type { Context } from '@orpc/server';
3
+ import type { OpenAPIMeta } from '../meta.ts';
8
4
  declare module '@orpc/contract' {
9
5
  interface ContractBuilder<TErrorMap extends ErrorMap> {
10
6
  route(meta: OpenAPIMeta): ContractBuilder<TErrorMap>;
@@ -0,0 +1,12 @@
1
+ import { ContractBuilder } from '@orpc/contract';
2
+ import { Builder, DecoratedProcedure } from '@orpc/server';
3
+ import { openapi } from '../meta.js';
4
+ ContractBuilder.prototype.route = function route(meta) {
5
+ return this.meta(openapi(meta));
6
+ };
7
+ Builder.prototype.route = function route(meta) {
8
+ return this.meta(openapi(meta));
9
+ };
10
+ DecoratedProcedure.prototype.route = function route(meta) {
11
+ return this.meta(openapi(meta));
12
+ };
@@ -26,7 +26,7 @@
26
26
  *
27
27
  * @see {@link https://orpc.dev/docs/helpers/form-data#parseformdata | Form Data Helpers - parseFormData}
28
28
  */
29
- declare function parseFormData(form: FormData): any;
29
+ export declare function parseFormData(form: FormData): any;
30
30
  /**
31
31
  * Gets the issue message from the error for a given field path.
32
32
  *
@@ -54,6 +54,4 @@ declare function parseFormData(form: FormData): any;
54
54
  *
55
55
  * @see {@link https://orpc.dev/docs/helpers/form-data#getissuemessage | Form Data Helpers - getIssueMessage}
56
56
  */
57
- declare function getIssueMessage(error: unknown, path: string): string | undefined;
58
-
59
- export { getIssueMessage, parseFormData };
57
+ export declare function getIssueMessage(error: unknown, path: string): string | undefined;
@@ -0,0 +1,90 @@
1
+ import { isSchemaIssue } from '@orpc/contract';
2
+ import { isNonPrimitive } from '@orpc/shared';
3
+ import { BracketNotationSerializer } from '../bracket-notation.js';
4
+ /**
5
+ * Parse a form data with [bracket notation](https://orpc.dev/docs/openapi/bracket-notation) syntax
6
+ *
7
+ * @example
8
+ * ```ts
9
+ * const form = new FormData()
10
+ * form.append('a', '1')
11
+ * form.append('user[name]', 'John')
12
+ * form.append('user[age]', '20')
13
+ * form.append('user[friends][]', 'Bob')
14
+ * form.append('user[friends][]', 'Alice')
15
+ * form.append('user[friends][]', 'Charlie')
16
+ * form.append('thumb', new Blob(['hello']), 'thumb.png')
17
+ *
18
+ * parseFormData(form)
19
+ * // {
20
+ * // a: '1',
21
+ * // user: {
22
+ * // name: 'John',
23
+ * // age: '20',
24
+ * // friends: ['Bob', 'Alice', 'Charlie'],
25
+ * // },
26
+ * // thumb: form.get('thumb'),
27
+ * // }
28
+ * ```
29
+ *
30
+ * @see {@link https://orpc.dev/docs/helpers/form-data#parseformdata | Form Data Helpers - parseFormData}
31
+ */
32
+ export function parseFormData(form) {
33
+ const serializer = new BracketNotationSerializer();
34
+ return serializer.deserialize(Array.from(form.entries()));
35
+ }
36
+ /**
37
+ * Gets the issue message from the error for a given field path.
38
+ *
39
+ * @remarks
40
+ * **Note**: Requires validation errors to follow the standard schema issue format, stored under `data.issues` — customized validation errors may not be found.
41
+ *
42
+ * @example
43
+ * ```tsx
44
+ * const { error, data, execute } = useServerAction(someAction)
45
+ *
46
+ * return <form action={(form) => execute(parseFormData(form))}>
47
+ * <input name="user[name]" type="text" />
48
+ * <p>{getIssueMessage(error, 'user[name]')}</p>
49
+ *
50
+ * <input name="user[age]" type="number" />
51
+ * <p>{getIssueMessage(error, 'user[age]')}</p>
52
+ *
53
+ * <input name="images[]" type="file" />
54
+ * <p>{getIssueMessage(error, 'images[]')}</p>
55
+ * </form>
56
+ * ```
57
+ *
58
+ * @param error - The error (can be anything) can contain `data.issues` (standard schema issues)
59
+ * @param path - The path of the field that has the issue follow [bracket notation](https://orpc.dev/docs/openapi/bracket-notation)
60
+ *
61
+ * @see {@link https://orpc.dev/docs/helpers/form-data#getissuemessage | Form Data Helpers - getIssueMessage}
62
+ */
63
+ export function getIssueMessage(error, path) {
64
+ if (!isNonPrimitive(error) || !isNonPrimitive(error.data) || !Array.isArray(error.data.issues)) {
65
+ return undefined;
66
+ }
67
+ const serializer = new BracketNotationSerializer();
68
+ for (const issue of error.data.issues) {
69
+ if (!isSchemaIssue(issue)) {
70
+ continue;
71
+ }
72
+ if (issue.path === undefined) {
73
+ if (path === '') {
74
+ return issue.message;
75
+ }
76
+ continue;
77
+ }
78
+ const issuePath = serializer.stringifyPath(issue.path.map((segment) => typeof segment === 'object' ? segment.key.toString() : segment.toString()));
79
+ if (issuePath === path) {
80
+ return issue.message;
81
+ }
82
+ if (path.endsWith('[]') && issuePath.replace(/\[(?:0|[1-9]\d*)\]$/, '[]') === path) {
83
+ return issue.message;
84
+ }
85
+ if (path === '' && /^(?:0|[1-9]\d*)$/.test(issuePath)) {
86
+ return issue.message;
87
+ }
88
+ }
89
+ return undefined;
90
+ }
@@ -1,59 +1 @@
1
- /**
2
- * Parse a form data with [bracket notation](https://orpc.dev/docs/openapi/bracket-notation) syntax
3
- *
4
- * @example
5
- * ```ts
6
- * const form = new FormData()
7
- * form.append('a', '1')
8
- * form.append('user[name]', 'John')
9
- * form.append('user[age]', '20')
10
- * form.append('user[friends][]', 'Bob')
11
- * form.append('user[friends][]', 'Alice')
12
- * form.append('user[friends][]', 'Charlie')
13
- * form.append('thumb', new Blob(['hello']), 'thumb.png')
14
- *
15
- * parseFormData(form)
16
- * // {
17
- * // a: '1',
18
- * // user: {
19
- * // name: 'John',
20
- * // age: '20',
21
- * // friends: ['Bob', 'Alice', 'Charlie'],
22
- * // },
23
- * // thumb: form.get('thumb'),
24
- * // }
25
- * ```
26
- *
27
- * @see {@link https://orpc.dev/docs/helpers/form-data#parseformdata | Form Data Helpers - parseFormData}
28
- */
29
- declare function parseFormData(form: FormData): any;
30
- /**
31
- * Gets the issue message from the error for a given field path.
32
- *
33
- * @remarks
34
- * **Note**: Requires validation errors to follow the standard schema issue format, stored under `data.issues` — customized validation errors may not be found.
35
- *
36
- * @example
37
- * ```tsx
38
- * const { error, data, execute } = useServerAction(someAction)
39
- *
40
- * return <form action={(form) => execute(parseFormData(form))}>
41
- * <input name="user[name]" type="text" />
42
- * <p>{getIssueMessage(error, 'user[name]')}</p>
43
- *
44
- * <input name="user[age]" type="number" />
45
- * <p>{getIssueMessage(error, 'user[age]')}</p>
46
- *
47
- * <input name="images[]" type="file" />
48
- * <p>{getIssueMessage(error, 'images[]')}</p>
49
- * </form>
50
- * ```
51
- *
52
- * @param error - The error (can be anything) can contain `data.issues` (standard schema issues)
53
- * @param path - The path of the field that has the issue follow [bracket notation](https://orpc.dev/docs/openapi/bracket-notation)
54
- *
55
- * @see {@link https://orpc.dev/docs/helpers/form-data#getissuemessage | Form Data Helpers - getIssueMessage}
56
- */
57
- declare function getIssueMessage(error: unknown, path: string): string | undefined;
58
-
59
- export { getIssueMessage, parseFormData };
1
+ export * from './form-data.ts';
@@ -0,0 +1 @@
1
+ export * from './form-data.js';
package/dist/index.d.ts CHANGED
@@ -1,166 +1,13 @@
1
- import { a as OpenAPIJsonSerializer } from './shared/openapi.YMRD3b4R.js';
2
- export { B as BracketNotationSerializeResult, b as BracketNotationSerializer, c as BracketNotationSerializerOptions, d as OpenAPIJsonSerialization, e as OpenAPIJsonSerializerHandler, f as OpenAPIJsonSerializerOptions, O as OpenAPISerializer, g as OpenAPISerializerOptions, h as OpenAPISerializerSerializeOptions } from './shared/openapi.YMRD3b4R.js';
3
- import { ClientContext, ORPCClientOptions, ClientLink } from '@orpc/client';
1
+ export * from './bracket-notation.ts';
2
+ export * from './client-factory.ts';
3
+ export { DEFAULT_OPENAPI_METHOD } from './constants.ts';
4
+ export * from './meta.ts';
5
+ export * from './openapi-generator.ts';
6
+ export * from './openapi-json-serializer.ts';
7
+ export * from './openapi-serializer.ts';
8
+ export * from './router-utils.ts';
9
+ export * from './types.ts';
10
+ export { getDynamicPathParams } from './utils.ts';
4
11
  export { COMMON_ERROR_STATUS_MAP } from '@orpc/client';
5
- import { RouterContract, RouterContractClient, AnyProcedureContract, ProcedureContract } from '@orpc/contract';
6
- import { J as JsonifiedClient, a as OpenAPIVersion, O as OpenAPIDocument } from './shared/openapi.Covi8zVE.js';
7
- export { b as JsonifiedArray, c as JsonifiedClientError, d as JsonifiedValue } from './shared/openapi.Covi8zVE.js';
8
- 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.zGZlCOwp.js';
9
- import { JsonSchema, JsonSchemaConverter } from '@orpc/json-schema';
10
- export { JsonSchema } from '@orpc/json-schema';
11
- import { AnyRouter, AnyProcedure } from '@orpc/server';
12
- import { Public, Value } from '@orpc/shared';
13
- import * as OpenAPIV3_2 from '@openapi-spec/types/v3.2';
14
- export { OpenAPIV3_2 };
15
- export { StandardBodyHint } from '@standard-server/core';
16
- import * as OpenAPIV3_0 from '@openapi-spec/types/v3.0';
17
- export { OpenAPIV3_0 };
18
- import * as OpenAPIV3_1 from '@openapi-spec/types/v3.1';
19
- export { OpenAPIV3_1 };
20
-
21
- interface ContractJsonifiedClientFactory<TClientContext extends ClientContext> {
22
- <T extends RouterContract>(contract: T): JsonifiedClient<RouterContractClient<T, TClientContext>>;
23
- }
24
- interface ContractJsonifiedClientFactoryOptions<TClientContext extends ClientContext> extends Pick<ORPCClientOptions<JsonifiedClient<RouterContractClient<RouterContract, TClientContext>>>, 'interceptors' | 'scoped'> {
25
- /**
26
- * An optional reference to the root router-contract.
27
- * When provided, the client factory will automatically register the passed contract
28
- * into the router at the path defined by `meta.path`.
29
- */
30
- contractRef?: RouterContract | undefined;
31
- }
32
- /**
33
- * Like `createContractClientFactory`, but the clients it builds are typed as `JsonifiedClient`,
34
- * for links that require it, such as OpenAPI Link.
35
- *
36
- * @remarks
37
- * **Warning**: Every procedure contract passed to the factory must define `meta.path` matching its location in the root contract.
38
- *
39
- * @see {@link https://orpc.dev/docs/contract/client-factory | Contract Client Factory}
40
- */
41
- declare function createContractJsonifiedClientFactory<TClientContext extends ClientContext>(link: ClientLink<TClientContext>, options?: ContractJsonifiedClientFactoryOptions<TClientContext>): ContractJsonifiedClientFactory<TClientContext>;
42
-
43
- declare const DEFAULT_OPENAPI_METHOD = "POST";
44
-
45
- /**
46
- * Dynamic parameters are always returned in path order.
47
- */
48
- declare function getDynamicPathParams(path: `/${string}`): {
49
- segment: string;
50
- startIndex: number;
51
- parameterName: string;
52
- allowsSlash: boolean;
53
- }[] | undefined;
54
-
55
- declare class OpenAPIGeneratorError extends TypeError {
56
- }
57
- interface OpenAPIErrorBodyDefinition {
58
- code: string;
59
- defaultMessage: string | undefined;
60
- dataOptional: boolean;
61
- dataJsonSchema: JsonSchema;
62
- }
63
-
64
- interface OpenAPIGeneratorOptions {
65
- converters?: JsonSchemaConverter[] | undefined;
66
- /**
67
- * The serializer used to serialize the generated OpenAPI documentation
68
- */
69
- serializer?: Public<OpenAPIJsonSerializer> | undefined;
70
- }
71
- interface OpenAPIGeneratorGenerateOptions<TVersion extends OpenAPIVersion> {
72
- /**
73
- * The OpenAPI version of the generated document.
74
- * The document is generated as OpenAPI 3.2 and downgraded when an older version is requested.
75
- * The minor version selects the conversion, the document carries the exact value, such as `3.1.0`.
76
- *
77
- * @default '3.2.0'
78
- */
79
- version?: TVersion | undefined;
80
- /**
81
- * OpenAPI 3.2 document fields to start from, such as `info`, `servers`, or `components`.
82
- * They are downgraded with the rest of the document when an older `version` is requested.
83
- * The `openapi` field is derived from `version`.
84
- */
85
- base?: Partial<Omit<OpenAPIV3_2.OpenAPIObject, 'openapi'>> | undefined;
86
- /**
87
- * Root-level `$defs` are always moved into `components.schemas`.
88
- * Use this to customize the component name of a hoisted def.
89
- *
90
- * @remarks
91
- * - The returned name is a preference, conflicting names are still postfixed (`Planet`, `PlanetInput`, `Planet2`, ...).
92
- * - Return `undefined` to keep the original def name.
93
- *
94
- * @default defName => defName
95
- */
96
- componentName?: ((defName: string, defSchema: JsonSchema) => string | undefined) | undefined;
97
- /**
98
- * Filter procedures. Return `false` to exclude a procedure from the OpenAPI specification.
99
- *
100
- * @default true
101
- */
102
- filter?: Value<boolean, [contract: AnyProcedureContract | AnyProcedure, path: string[]]> | undefined;
103
- /**
104
- * Define a custom JSON schema for the error response body when using
105
- * type-safe errors. Helps align ORPC error formatting with existing API
106
- * response standards or conventions.
107
- *
108
- * @remarks
109
- * - Return `null | undefined` to use the default error response body shaper.
110
- * - The schema is an OpenAPI 3.2 Schema Object, it is downgraded with the rest of the document when an older `version` is requested.
111
- */
112
- errorResponseBodySchema?: Value<JsonSchema | undefined | null, [
113
- definedErrors: OpenAPIErrorBodyDefinition[],
114
- status: number
115
- ]> | undefined;
116
- /**
117
- * Media type of error responses in the generated document, e.g. `application/problem+json`.
118
- * Should match the handler's `errorResponseContentType`.
119
- *
120
- * @default 'application/json'
121
- */
122
- errorResponseContentType?: string | undefined;
123
- /**
124
- * Mapping ORPCError Code -> HTTP Status Code
125
- * Codes missing from the map fall back to `DEFAULT_ERROR_STATUS` (400).
126
- *
127
- * @default COMMON_ERROR_STATUS_MAP
128
- */
129
- errorStatusMap?: Record<string, number> | undefined;
130
- }
131
- /**
132
- * Generates an OpenAPI document from a contract or router.
133
- * Relies on JSON schema converters to translate input, output, and error schemas into JSON Schemas.
134
- *
135
- * @see {@link https://orpc.dev/docs/openapi/specification#openapi-generator | OpenAPI Specification - OpenAPI Generator}
136
- */
137
- declare class OpenAPIGenerator {
138
- private readonly serializer;
139
- private readonly converter;
140
- constructor(options?: OpenAPIGeneratorOptions);
141
- generate<TVersion extends OpenAPIVersion = '3.2.0'>(router: RouterContract | AnyRouter, options?: OpenAPIGeneratorGenerateOptions<TVersion>): Promise<OpenAPIDocument<TVersion>>;
142
- private convertSchema;
143
- private convertSchemas;
144
- }
145
-
146
- type PopulatedContractRouterOpenAPIPaths<T extends RouterContract> = T extends ProcedureContract<infer UInputSchema, infer UOutputSchema, infer UErrors> ? ProcedureContract<UInputSchema, UOutputSchema, UErrors> : {
147
- [K in keyof T]: T[K] extends RouterContract ? PopulatedContractRouterOpenAPIPaths<T[K]> : never;
148
- };
149
- interface PopulateRouterContractOpenAPIPathsOptions {
150
- /**
151
- * Base path segments.
152
- */
153
- path?: string[] | undefined;
154
- }
155
- /**
156
- * Automatically populates missing openapi.path using router structure.
157
- *
158
- * Builds paths by joining router keys with `/`.
159
- * Useful when you want to ensure all contracts define openapi.path, such as for NestJS integration requirements.
160
- *
161
- * @see {@link https://orpc.dev/docs/integrations/nest | Implement oRPC contract with NestJS}
162
- */
163
- declare function populateRouterContractOpenAPIPaths<T extends RouterContract>(router: T, options?: PopulateRouterContractOpenAPIPathsOptions): PopulatedContractRouterOpenAPIPaths<T>;
164
-
165
- export { DEFAULT_OPENAPI_METHOD, JsonifiedClient, OpenAPIDocument, OpenAPIGenerator, OpenAPIGeneratorError, OpenAPIJsonSerializer, OpenAPIVersion, createContractJsonifiedClientFactory, getDynamicPathParams, populateRouterContractOpenAPIPaths };
166
- export type { ContractJsonifiedClientFactory, ContractJsonifiedClientFactoryOptions, OpenAPIErrorBodyDefinition, OpenAPIGeneratorGenerateOptions, OpenAPIGeneratorOptions, PopulateRouterContractOpenAPIPathsOptions, PopulatedContractRouterOpenAPIPaths };
12
+ export type { JsonSchema } from '@orpc/json-schema';
13
+ export type { StandardBodyHint } from '@standard-server/core';
package/dist/index.js ADDED
@@ -0,0 +1,11 @@
1
+ export * from './bracket-notation.js';
2
+ export * from './client-factory.js';
3
+ export { DEFAULT_OPENAPI_METHOD } from './constants.js';
4
+ export * from './meta.js';
5
+ export * from './openapi-generator.js';
6
+ export * from './openapi-json-serializer.js';
7
+ export * from './openapi-serializer.js';
8
+ export * from './router-utils.js';
9
+ export * from './types.js';
10
+ export { getDynamicPathParams } from './utils.js';
11
+ export { COMMON_ERROR_STATUS_MAP } from '@orpc/client';