@orpc/openapi-client 0.51.0 → 0.53.0
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/README.md +1 -0
- package/dist/adapters/fetch/index.d.mts +15 -0
- package/dist/adapters/fetch/index.d.ts +15 -0
- package/dist/adapters/fetch/index.mjs +16 -0
- package/dist/adapters/standard/index.d.mts +18 -34
- package/dist/adapters/standard/index.d.ts +18 -34
- package/dist/adapters/standard/index.mjs +6 -229
- package/dist/index.d.mts +10 -1
- package/dist/index.d.ts +10 -1
- package/dist/shared/openapi-client.D89vdV2Y.mjs +413 -0
- package/dist/shared/openapi-client.DArKvaqp.d.mts +78 -0
- package/dist/shared/openapi-client.DArKvaqp.d.ts +78 -0
- package/package.json +13 -4
package/README.md
CHANGED
|
@@ -53,6 +53,7 @@ You can find the full documentation [here](https://orpc.unnoq.com).
|
|
|
53
53
|
- [@orpc/contract](https://www.npmjs.com/package/@orpc/contract): Build your API contract.
|
|
54
54
|
- [@orpc/server](https://www.npmjs.com/package/@orpc/server): Build your API or implement API contract.
|
|
55
55
|
- [@orpc/client](https://www.npmjs.com/package/@orpc/client): Consume your API on the client with type-safety.
|
|
56
|
+
- [@orpc/react](https://www.npmjs.com/package/@orpc/react): Utilities for integrating oRPC with React and React Server Actions.
|
|
56
57
|
- [@orpc/react-query](https://www.npmjs.com/package/@orpc/react-query): Integration with [React Query](https://tanstack.com/query/latest/docs/framework/react/overview).
|
|
57
58
|
- [@orpc/vue-query](https://www.npmjs.com/package/@orpc/vue-query): Integration with [Vue Query](https://tanstack.com/query/latest/docs/framework/vue/overview).
|
|
58
59
|
- [@orpc/solid-query](https://www.npmjs.com/package/@orpc/solid-query): Integration with [Solid Query](https://tanstack.com/query/latest/docs/framework/solid/overview).
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { ClientContext } from '@orpc/client';
|
|
2
|
+
import { AnyContractRouter } from '@orpc/contract';
|
|
3
|
+
import { LinkFetchClientOptions } from '@orpc/client/fetch';
|
|
4
|
+
import { f as StandardOpenAPILinkOptions, g as StandardOpenAPILink } from '../../shared/openapi-client.DArKvaqp.mjs';
|
|
5
|
+
import '@orpc/client/standard';
|
|
6
|
+
import '@orpc/standard-server';
|
|
7
|
+
import '@orpc/shared';
|
|
8
|
+
|
|
9
|
+
interface OpenAPILinkOptions<T extends ClientContext> extends StandardOpenAPILinkOptions<T>, LinkFetchClientOptions<T> {
|
|
10
|
+
}
|
|
11
|
+
declare class OpenAPILink<T extends ClientContext> extends StandardOpenAPILink<T> {
|
|
12
|
+
constructor(contract: AnyContractRouter, options: OpenAPILinkOptions<T>);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export { OpenAPILink, type OpenAPILinkOptions };
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { ClientContext } from '@orpc/client';
|
|
2
|
+
import { AnyContractRouter } from '@orpc/contract';
|
|
3
|
+
import { LinkFetchClientOptions } from '@orpc/client/fetch';
|
|
4
|
+
import { f as StandardOpenAPILinkOptions, g as StandardOpenAPILink } from '../../shared/openapi-client.DArKvaqp.js';
|
|
5
|
+
import '@orpc/client/standard';
|
|
6
|
+
import '@orpc/standard-server';
|
|
7
|
+
import '@orpc/shared';
|
|
8
|
+
|
|
9
|
+
interface OpenAPILinkOptions<T extends ClientContext> extends StandardOpenAPILinkOptions<T>, LinkFetchClientOptions<T> {
|
|
10
|
+
}
|
|
11
|
+
declare class OpenAPILink<T extends ClientContext> extends StandardOpenAPILink<T> {
|
|
12
|
+
constructor(contract: AnyContractRouter, options: OpenAPILinkOptions<T>);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export { OpenAPILink, type OpenAPILinkOptions };
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { LinkFetchClient } from '@orpc/client/fetch';
|
|
2
|
+
import '@orpc/shared';
|
|
3
|
+
import { b as StandardOpenAPILink } from '../../shared/openapi-client.D89vdV2Y.mjs';
|
|
4
|
+
import '@orpc/client';
|
|
5
|
+
import '@orpc/client/standard';
|
|
6
|
+
import '@orpc/contract';
|
|
7
|
+
import '@orpc/standard-server';
|
|
8
|
+
|
|
9
|
+
class OpenAPILink extends StandardOpenAPILink {
|
|
10
|
+
constructor(contract, options) {
|
|
11
|
+
const linkClient = new LinkFetchClient(options);
|
|
12
|
+
super(contract, linkClient, options);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export { OpenAPILink };
|
|
@@ -1,36 +1,20 @@
|
|
|
1
|
-
|
|
1
|
+
export { S as StandardBracketNotationSerialized, a as StandardBracketNotationSerializer, c as StandardOpenAPICustomJsonSerializer, b as StandardOpenAPIJsonSerialized, e as StandardOpenAPIJsonSerializer, d as StandardOpenAPIJsonSerializerOptions, g as StandardOpenAPILink, f as StandardOpenAPILinkOptions, j as StandardOpenAPISerializeOptions, k as StandardOpenAPISerializer, i as StandardOpenapiLinkCodec, h as StandardOpenapiLinkCodecOptions } from '../../shared/openapi-client.DArKvaqp.mjs';
|
|
2
|
+
import { HTTPPath } from '@orpc/client';
|
|
3
|
+
import '@orpc/contract';
|
|
4
|
+
import '@orpc/client/standard';
|
|
5
|
+
import '@orpc/standard-server';
|
|
6
|
+
import '@orpc/shared';
|
|
2
7
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
8
|
+
/**
|
|
9
|
+
* @internal
|
|
10
|
+
*/
|
|
11
|
+
declare function standardizeHTTPPath(path: HTTPPath): HTTPPath;
|
|
12
|
+
/**
|
|
13
|
+
* @internal
|
|
14
|
+
*/
|
|
15
|
+
declare function getDynamicParams(path: HTTPPath | undefined): {
|
|
16
|
+
raw: string;
|
|
17
|
+
name: string;
|
|
18
|
+
}[] | undefined;
|
|
10
19
|
|
|
11
|
-
|
|
12
|
-
interface StandardOpenAPICustomJsonSerializer {
|
|
13
|
-
condition(data: unknown): boolean;
|
|
14
|
-
serialize(data: any): unknown;
|
|
15
|
-
}
|
|
16
|
-
interface StandardOpenAPIJsonSerializerOptions {
|
|
17
|
-
customJsonSerializers?: readonly StandardOpenAPICustomJsonSerializer[];
|
|
18
|
-
}
|
|
19
|
-
declare class StandardOpenAPIJsonSerializer {
|
|
20
|
-
private readonly customSerializers;
|
|
21
|
-
constructor(options?: StandardOpenAPIJsonSerializerOptions);
|
|
22
|
-
serialize(data: unknown, hasBlobRef?: {
|
|
23
|
-
value: boolean;
|
|
24
|
-
}): StandardOpenAPIJsonSerialized;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
declare class StandardOpenAPISerializer {
|
|
28
|
-
#private;
|
|
29
|
-
private readonly jsonSerializer;
|
|
30
|
-
private readonly bracketNotation;
|
|
31
|
-
constructor(jsonSerializer: StandardOpenAPIJsonSerializer, bracketNotation: StandardBracketNotationSerializer);
|
|
32
|
-
serialize(data: unknown): unknown;
|
|
33
|
-
deserialize(data: unknown): unknown;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
export { type StandardBracketNotationSerialized, StandardBracketNotationSerializer, type StandardOpenAPICustomJsonSerializer, type StandardOpenAPIJsonSerialized, StandardOpenAPIJsonSerializer, type StandardOpenAPIJsonSerializerOptions, StandardOpenAPISerializer };
|
|
20
|
+
export { getDynamicParams, standardizeHTTPPath };
|
|
@@ -1,36 +1,20 @@
|
|
|
1
|
-
|
|
1
|
+
export { S as StandardBracketNotationSerialized, a as StandardBracketNotationSerializer, c as StandardOpenAPICustomJsonSerializer, b as StandardOpenAPIJsonSerialized, e as StandardOpenAPIJsonSerializer, d as StandardOpenAPIJsonSerializerOptions, g as StandardOpenAPILink, f as StandardOpenAPILinkOptions, j as StandardOpenAPISerializeOptions, k as StandardOpenAPISerializer, i as StandardOpenapiLinkCodec, h as StandardOpenapiLinkCodecOptions } from '../../shared/openapi-client.DArKvaqp.js';
|
|
2
|
+
import { HTTPPath } from '@orpc/client';
|
|
3
|
+
import '@orpc/contract';
|
|
4
|
+
import '@orpc/client/standard';
|
|
5
|
+
import '@orpc/standard-server';
|
|
6
|
+
import '@orpc/shared';
|
|
2
7
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
8
|
+
/**
|
|
9
|
+
* @internal
|
|
10
|
+
*/
|
|
11
|
+
declare function standardizeHTTPPath(path: HTTPPath): HTTPPath;
|
|
12
|
+
/**
|
|
13
|
+
* @internal
|
|
14
|
+
*/
|
|
15
|
+
declare function getDynamicParams(path: HTTPPath | undefined): {
|
|
16
|
+
raw: string;
|
|
17
|
+
name: string;
|
|
18
|
+
}[] | undefined;
|
|
10
19
|
|
|
11
|
-
|
|
12
|
-
interface StandardOpenAPICustomJsonSerializer {
|
|
13
|
-
condition(data: unknown): boolean;
|
|
14
|
-
serialize(data: any): unknown;
|
|
15
|
-
}
|
|
16
|
-
interface StandardOpenAPIJsonSerializerOptions {
|
|
17
|
-
customJsonSerializers?: readonly StandardOpenAPICustomJsonSerializer[];
|
|
18
|
-
}
|
|
19
|
-
declare class StandardOpenAPIJsonSerializer {
|
|
20
|
-
private readonly customSerializers;
|
|
21
|
-
constructor(options?: StandardOpenAPIJsonSerializerOptions);
|
|
22
|
-
serialize(data: unknown, hasBlobRef?: {
|
|
23
|
-
value: boolean;
|
|
24
|
-
}): StandardOpenAPIJsonSerialized;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
declare class StandardOpenAPISerializer {
|
|
28
|
-
#private;
|
|
29
|
-
private readonly jsonSerializer;
|
|
30
|
-
private readonly bracketNotation;
|
|
31
|
-
constructor(jsonSerializer: StandardOpenAPIJsonSerializer, bracketNotation: StandardBracketNotationSerializer);
|
|
32
|
-
serialize(data: unknown): unknown;
|
|
33
|
-
deserialize(data: unknown): unknown;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
export { type StandardBracketNotationSerialized, StandardBracketNotationSerializer, type StandardOpenAPICustomJsonSerializer, type StandardOpenAPIJsonSerialized, StandardOpenAPIJsonSerializer, type StandardOpenAPIJsonSerializerOptions, StandardOpenAPISerializer };
|
|
20
|
+
export { getDynamicParams, standardizeHTTPPath };
|
|
@@ -1,229 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
if (Array.isArray(data)) {
|
|
8
|
-
data.forEach((item, i) => {
|
|
9
|
-
this.serialize(item, [...segments, i], result);
|
|
10
|
-
});
|
|
11
|
-
} else if (isObject(data)) {
|
|
12
|
-
for (const key in data) {
|
|
13
|
-
this.serialize(data[key], [...segments, key], result);
|
|
14
|
-
}
|
|
15
|
-
} else {
|
|
16
|
-
result.push([this.stringifyPath(segments), data]);
|
|
17
|
-
}
|
|
18
|
-
return result;
|
|
19
|
-
}
|
|
20
|
-
deserialize(serialized) {
|
|
21
|
-
if (serialized.length === 0) {
|
|
22
|
-
return {};
|
|
23
|
-
}
|
|
24
|
-
const arrayPushStyles = /* @__PURE__ */ new WeakSet();
|
|
25
|
-
const ref = { value: [] };
|
|
26
|
-
for (const [path, value] of serialized) {
|
|
27
|
-
const segments = this.parsePath(path);
|
|
28
|
-
let currentRef = ref;
|
|
29
|
-
let nextSegment = "value";
|
|
30
|
-
segments.forEach((segment, i) => {
|
|
31
|
-
if (!Array.isArray(currentRef[nextSegment]) && !isObject(currentRef[nextSegment])) {
|
|
32
|
-
currentRef[nextSegment] = [];
|
|
33
|
-
}
|
|
34
|
-
if (i !== segments.length - 1) {
|
|
35
|
-
if (Array.isArray(currentRef[nextSegment]) && !isValidArrayIndex(segment)) {
|
|
36
|
-
currentRef[nextSegment] = { ...currentRef[nextSegment] };
|
|
37
|
-
}
|
|
38
|
-
} else {
|
|
39
|
-
if (Array.isArray(currentRef[nextSegment])) {
|
|
40
|
-
if (segment === "") {
|
|
41
|
-
if (currentRef[nextSegment].length && !arrayPushStyles.has(currentRef[nextSegment])) {
|
|
42
|
-
currentRef[nextSegment] = { ...currentRef[nextSegment] };
|
|
43
|
-
}
|
|
44
|
-
} else {
|
|
45
|
-
if (arrayPushStyles.has(currentRef[nextSegment])) {
|
|
46
|
-
currentRef[nextSegment] = { "": currentRef[nextSegment].at(-1) };
|
|
47
|
-
} else if (!isValidArrayIndex(segment)) {
|
|
48
|
-
currentRef[nextSegment] = { ...currentRef[nextSegment] };
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
currentRef = currentRef[nextSegment];
|
|
54
|
-
nextSegment = segment;
|
|
55
|
-
});
|
|
56
|
-
if (Array.isArray(currentRef)) {
|
|
57
|
-
if (nextSegment === "") {
|
|
58
|
-
arrayPushStyles.add(currentRef);
|
|
59
|
-
currentRef.push(value);
|
|
60
|
-
} else {
|
|
61
|
-
currentRef[Number(nextSegment)] = value;
|
|
62
|
-
}
|
|
63
|
-
} else {
|
|
64
|
-
currentRef[nextSegment] = value;
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
return ref.value;
|
|
68
|
-
}
|
|
69
|
-
stringifyPath(segments) {
|
|
70
|
-
return segments.map((segment) => {
|
|
71
|
-
return segment.toString().replace(/[\\[\]]/g, (match) => {
|
|
72
|
-
switch (match) {
|
|
73
|
-
case "\\":
|
|
74
|
-
return "\\\\";
|
|
75
|
-
case "[":
|
|
76
|
-
return "\\[";
|
|
77
|
-
case "]":
|
|
78
|
-
return "\\]";
|
|
79
|
-
/* v8 ignore next 2 */
|
|
80
|
-
default:
|
|
81
|
-
return match;
|
|
82
|
-
}
|
|
83
|
-
});
|
|
84
|
-
}).reduce((result, segment, i) => {
|
|
85
|
-
if (i === 0) {
|
|
86
|
-
return segment;
|
|
87
|
-
}
|
|
88
|
-
return `${result}[${segment}]`;
|
|
89
|
-
}, "");
|
|
90
|
-
}
|
|
91
|
-
parsePath(path) {
|
|
92
|
-
const segments = [];
|
|
93
|
-
let inBrackets = false;
|
|
94
|
-
let currentSegment = "";
|
|
95
|
-
let backslashCount = 0;
|
|
96
|
-
for (let i = 0; i < path.length; i++) {
|
|
97
|
-
const char = path[i];
|
|
98
|
-
const nextChar = path[i + 1];
|
|
99
|
-
if (inBrackets && char === "]" && (nextChar === void 0 || nextChar === "[") && backslashCount % 2 === 0) {
|
|
100
|
-
if (nextChar === void 0) {
|
|
101
|
-
inBrackets = false;
|
|
102
|
-
}
|
|
103
|
-
segments.push(currentSegment);
|
|
104
|
-
currentSegment = "";
|
|
105
|
-
i++;
|
|
106
|
-
} else if (segments.length === 0 && char === "[" && backslashCount % 2 === 0) {
|
|
107
|
-
inBrackets = true;
|
|
108
|
-
segments.push(currentSegment);
|
|
109
|
-
currentSegment = "";
|
|
110
|
-
} else if (char === "\\") {
|
|
111
|
-
backslashCount++;
|
|
112
|
-
} else {
|
|
113
|
-
currentSegment += "\\".repeat(backslashCount / 2) + char;
|
|
114
|
-
backslashCount = 0;
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
return inBrackets || segments.length === 0 ? [path] : segments;
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
function isValidArrayIndex(value) {
|
|
121
|
-
return /^0$|^[1-9]\d*$/.test(value);
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
class StandardOpenAPIJsonSerializer {
|
|
125
|
-
customSerializers;
|
|
126
|
-
constructor(options = {}) {
|
|
127
|
-
this.customSerializers = options.customJsonSerializers ?? [];
|
|
128
|
-
}
|
|
129
|
-
serialize(data, hasBlobRef = { value: false }) {
|
|
130
|
-
for (const custom of this.customSerializers) {
|
|
131
|
-
if (custom.condition(data)) {
|
|
132
|
-
const result = this.serialize(custom.serialize(data), hasBlobRef);
|
|
133
|
-
return result;
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
if (data instanceof Blob) {
|
|
137
|
-
hasBlobRef.value = true;
|
|
138
|
-
return [data, hasBlobRef.value];
|
|
139
|
-
}
|
|
140
|
-
if (data instanceof Set) {
|
|
141
|
-
return this.serialize(Array.from(data), hasBlobRef);
|
|
142
|
-
}
|
|
143
|
-
if (data instanceof Map) {
|
|
144
|
-
return this.serialize(Array.from(data.entries()), hasBlobRef);
|
|
145
|
-
}
|
|
146
|
-
if (Array.isArray(data)) {
|
|
147
|
-
const json = data.map((v) => v === void 0 ? null : this.serialize(v, hasBlobRef)[0]);
|
|
148
|
-
return [json, hasBlobRef.value];
|
|
149
|
-
}
|
|
150
|
-
if (isObject(data)) {
|
|
151
|
-
const json = {};
|
|
152
|
-
for (const k in data) {
|
|
153
|
-
if (k === "toJSON" && typeof data[k] === "function") {
|
|
154
|
-
continue;
|
|
155
|
-
}
|
|
156
|
-
json[k] = this.serialize(data[k], hasBlobRef)[0];
|
|
157
|
-
}
|
|
158
|
-
return [json, hasBlobRef.value];
|
|
159
|
-
}
|
|
160
|
-
if (typeof data === "bigint" || data instanceof RegExp || data instanceof URL) {
|
|
161
|
-
return [data.toString(), hasBlobRef.value];
|
|
162
|
-
}
|
|
163
|
-
if (data instanceof Date) {
|
|
164
|
-
return [Number.isNaN(data.getTime()) ? null : data.toISOString(), hasBlobRef.value];
|
|
165
|
-
}
|
|
166
|
-
if (Number.isNaN(data)) {
|
|
167
|
-
return [null, hasBlobRef.value];
|
|
168
|
-
}
|
|
169
|
-
return [data, hasBlobRef.value];
|
|
170
|
-
}
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
class StandardOpenAPISerializer {
|
|
174
|
-
constructor(jsonSerializer, bracketNotation) {
|
|
175
|
-
this.jsonSerializer = jsonSerializer;
|
|
176
|
-
this.bracketNotation = bracketNotation;
|
|
177
|
-
}
|
|
178
|
-
serialize(data) {
|
|
179
|
-
if (isAsyncIteratorObject(data)) {
|
|
180
|
-
return mapEventIterator(data, {
|
|
181
|
-
value: async (value) => this.#serialize(value, false),
|
|
182
|
-
error: async (e) => {
|
|
183
|
-
return new ErrorEvent({
|
|
184
|
-
data: this.#serialize(toORPCError(e).toJSON(), false),
|
|
185
|
-
cause: e
|
|
186
|
-
});
|
|
187
|
-
}
|
|
188
|
-
});
|
|
189
|
-
}
|
|
190
|
-
return this.#serialize(data, true);
|
|
191
|
-
}
|
|
192
|
-
#serialize(data, enableFormData) {
|
|
193
|
-
if (data instanceof Blob || data === void 0) {
|
|
194
|
-
return data;
|
|
195
|
-
}
|
|
196
|
-
const [json, hasBlob] = this.jsonSerializer.serialize(data);
|
|
197
|
-
if (!enableFormData || !hasBlob) {
|
|
198
|
-
return json;
|
|
199
|
-
}
|
|
200
|
-
const form = new FormData();
|
|
201
|
-
for (const [path, value] of this.bracketNotation.serialize(json)) {
|
|
202
|
-
if (typeof value === "string" || typeof value === "number" || typeof value === "boolean") {
|
|
203
|
-
form.append(path, value.toString());
|
|
204
|
-
} else if (value instanceof Blob) {
|
|
205
|
-
form.append(path, value);
|
|
206
|
-
}
|
|
207
|
-
}
|
|
208
|
-
return form;
|
|
209
|
-
}
|
|
210
|
-
deserialize(data) {
|
|
211
|
-
if (data instanceof URLSearchParams || data instanceof FormData) {
|
|
212
|
-
return this.bracketNotation.deserialize(Array.from(data.entries()));
|
|
213
|
-
}
|
|
214
|
-
if (isAsyncIteratorObject(data)) {
|
|
215
|
-
return mapEventIterator(data, {
|
|
216
|
-
value: async (value) => value,
|
|
217
|
-
error: async (e) => {
|
|
218
|
-
if (e instanceof ErrorEvent && ORPCError.isValidJSON(e.data)) {
|
|
219
|
-
return ORPCError.fromJSON(e.data, { cause: e });
|
|
220
|
-
}
|
|
221
|
-
return e;
|
|
222
|
-
}
|
|
223
|
-
});
|
|
224
|
-
}
|
|
225
|
-
return data;
|
|
226
|
-
}
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
export { StandardBracketNotationSerializer, StandardOpenAPIJsonSerializer, StandardOpenAPISerializer };
|
|
1
|
+
export { S as StandardBracketNotationSerializer, a as StandardOpenAPIJsonSerializer, b as StandardOpenAPILink, d as StandardOpenAPISerializer, c as StandardOpenapiLinkCodec, g as getDynamicParams, s as standardizeHTTPPath } from '../../shared/openapi-client.D89vdV2Y.mjs';
|
|
2
|
+
import '@orpc/client/standard';
|
|
3
|
+
import '@orpc/shared';
|
|
4
|
+
import '@orpc/client';
|
|
5
|
+
import '@orpc/contract';
|
|
6
|
+
import '@orpc/standard-server';
|
package/dist/index.d.mts
CHANGED
|
@@ -1,2 +1,11 @@
|
|
|
1
|
+
import { NestedClient, Client, ORPCError } from '@orpc/client';
|
|
1
2
|
|
|
2
|
-
|
|
3
|
+
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> ? {
|
|
4
|
+
[K in keyof T]: JsonifiedValue<T[K]>;
|
|
5
|
+
} : 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;
|
|
6
|
+
type JsonifiedArray<T extends Array<unknown>> = T extends readonly [] ? [] : T extends readonly [infer U, ...infer V] ? [U extends undefined ? null : JsonifiedValue<U>, ...JsonifiedArray<V>] : T extends Array<infer U> ? Array<JsonifiedValue<U>> : unknown;
|
|
7
|
+
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> : {
|
|
8
|
+
[K in keyof T]: T[K] extends NestedClient<any> ? JsonifiedClient<T[K]> : T[K];
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
export type { JsonifiedArray, JsonifiedClient, JsonifiedValue };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,2 +1,11 @@
|
|
|
1
|
+
import { NestedClient, Client, ORPCError } from '@orpc/client';
|
|
1
2
|
|
|
2
|
-
|
|
3
|
+
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> ? {
|
|
4
|
+
[K in keyof T]: JsonifiedValue<T[K]>;
|
|
5
|
+
} : 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;
|
|
6
|
+
type JsonifiedArray<T extends Array<unknown>> = T extends readonly [] ? [] : T extends readonly [infer U, ...infer V] ? [U extends undefined ? null : JsonifiedValue<U>, ...JsonifiedArray<V>] : T extends Array<infer U> ? Array<JsonifiedValue<U>> : unknown;
|
|
7
|
+
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> : {
|
|
8
|
+
[K in keyof T]: T[K] extends NestedClient<any> ? JsonifiedClient<T[K]> : T[K];
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
export type { JsonifiedArray, JsonifiedClient, JsonifiedValue };
|
|
@@ -0,0 +1,413 @@
|
|
|
1
|
+
import { toHttpPath, getMalformedResponseErrorCode, StandardLink } from '@orpc/client/standard';
|
|
2
|
+
import { isObject, value, get, isAsyncIteratorObject } from '@orpc/shared';
|
|
3
|
+
import { isORPCErrorStatus, isORPCErrorJson, createORPCErrorFromJson, mapEventIterator, toORPCError } from '@orpc/client';
|
|
4
|
+
import { isContractProcedure, fallbackContractConfig, ORPCError } from '@orpc/contract';
|
|
5
|
+
import { mergeStandardHeaders, ErrorEvent } from '@orpc/standard-server';
|
|
6
|
+
|
|
7
|
+
class StandardBracketNotationSerializer {
|
|
8
|
+
serialize(data, segments = [], result = []) {
|
|
9
|
+
if (Array.isArray(data)) {
|
|
10
|
+
data.forEach((item, i) => {
|
|
11
|
+
this.serialize(item, [...segments, i], result);
|
|
12
|
+
});
|
|
13
|
+
} else if (isObject(data)) {
|
|
14
|
+
for (const key in data) {
|
|
15
|
+
this.serialize(data[key], [...segments, key], result);
|
|
16
|
+
}
|
|
17
|
+
} else {
|
|
18
|
+
result.push([this.stringifyPath(segments), data]);
|
|
19
|
+
}
|
|
20
|
+
return result;
|
|
21
|
+
}
|
|
22
|
+
deserialize(serialized) {
|
|
23
|
+
if (serialized.length === 0) {
|
|
24
|
+
return {};
|
|
25
|
+
}
|
|
26
|
+
const arrayPushStyles = /* @__PURE__ */ new WeakSet();
|
|
27
|
+
const ref = { value: [] };
|
|
28
|
+
for (const [path, value] of serialized) {
|
|
29
|
+
const segments = this.parsePath(path);
|
|
30
|
+
let currentRef = ref;
|
|
31
|
+
let nextSegment = "value";
|
|
32
|
+
segments.forEach((segment, i) => {
|
|
33
|
+
if (!Array.isArray(currentRef[nextSegment]) && !isObject(currentRef[nextSegment])) {
|
|
34
|
+
currentRef[nextSegment] = [];
|
|
35
|
+
}
|
|
36
|
+
if (i !== segments.length - 1) {
|
|
37
|
+
if (Array.isArray(currentRef[nextSegment]) && !isValidArrayIndex(segment)) {
|
|
38
|
+
currentRef[nextSegment] = { ...currentRef[nextSegment] };
|
|
39
|
+
}
|
|
40
|
+
} else {
|
|
41
|
+
if (Array.isArray(currentRef[nextSegment])) {
|
|
42
|
+
if (segment === "") {
|
|
43
|
+
if (currentRef[nextSegment].length && !arrayPushStyles.has(currentRef[nextSegment])) {
|
|
44
|
+
currentRef[nextSegment] = { ...currentRef[nextSegment] };
|
|
45
|
+
}
|
|
46
|
+
} else {
|
|
47
|
+
if (arrayPushStyles.has(currentRef[nextSegment])) {
|
|
48
|
+
currentRef[nextSegment] = { "": currentRef[nextSegment].at(-1) };
|
|
49
|
+
} else if (!isValidArrayIndex(segment)) {
|
|
50
|
+
currentRef[nextSegment] = { ...currentRef[nextSegment] };
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
currentRef = currentRef[nextSegment];
|
|
56
|
+
nextSegment = segment;
|
|
57
|
+
});
|
|
58
|
+
if (Array.isArray(currentRef)) {
|
|
59
|
+
if (nextSegment === "") {
|
|
60
|
+
arrayPushStyles.add(currentRef);
|
|
61
|
+
currentRef.push(value);
|
|
62
|
+
} else {
|
|
63
|
+
currentRef[Number(nextSegment)] = value;
|
|
64
|
+
}
|
|
65
|
+
} else {
|
|
66
|
+
currentRef[nextSegment] = value;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
return ref.value;
|
|
70
|
+
}
|
|
71
|
+
stringifyPath(segments) {
|
|
72
|
+
return segments.map((segment) => {
|
|
73
|
+
return segment.toString().replace(/[\\[\]]/g, (match) => {
|
|
74
|
+
switch (match) {
|
|
75
|
+
case "\\":
|
|
76
|
+
return "\\\\";
|
|
77
|
+
case "[":
|
|
78
|
+
return "\\[";
|
|
79
|
+
case "]":
|
|
80
|
+
return "\\]";
|
|
81
|
+
/* v8 ignore next 2 */
|
|
82
|
+
default:
|
|
83
|
+
return match;
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
}).reduce((result, segment, i) => {
|
|
87
|
+
if (i === 0) {
|
|
88
|
+
return segment;
|
|
89
|
+
}
|
|
90
|
+
return `${result}[${segment}]`;
|
|
91
|
+
}, "");
|
|
92
|
+
}
|
|
93
|
+
parsePath(path) {
|
|
94
|
+
const segments = [];
|
|
95
|
+
let inBrackets = false;
|
|
96
|
+
let currentSegment = "";
|
|
97
|
+
let backslashCount = 0;
|
|
98
|
+
for (let i = 0; i < path.length; i++) {
|
|
99
|
+
const char = path[i];
|
|
100
|
+
const nextChar = path[i + 1];
|
|
101
|
+
if (inBrackets && char === "]" && (nextChar === void 0 || nextChar === "[") && backslashCount % 2 === 0) {
|
|
102
|
+
if (nextChar === void 0) {
|
|
103
|
+
inBrackets = false;
|
|
104
|
+
}
|
|
105
|
+
segments.push(currentSegment);
|
|
106
|
+
currentSegment = "";
|
|
107
|
+
i++;
|
|
108
|
+
} else if (segments.length === 0 && char === "[" && backslashCount % 2 === 0) {
|
|
109
|
+
inBrackets = true;
|
|
110
|
+
segments.push(currentSegment);
|
|
111
|
+
currentSegment = "";
|
|
112
|
+
} else if (char === "\\") {
|
|
113
|
+
backslashCount++;
|
|
114
|
+
} else {
|
|
115
|
+
currentSegment += "\\".repeat(backslashCount / 2) + char;
|
|
116
|
+
backslashCount = 0;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
return inBrackets || segments.length === 0 ? [path] : segments;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
function isValidArrayIndex(value) {
|
|
123
|
+
return /^0$|^[1-9]\d*$/.test(value);
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
class StandardOpenAPIJsonSerializer {
|
|
127
|
+
customSerializers;
|
|
128
|
+
constructor(options = {}) {
|
|
129
|
+
this.customSerializers = options.customJsonSerializers ?? [];
|
|
130
|
+
}
|
|
131
|
+
serialize(data, hasBlobRef = { value: false }) {
|
|
132
|
+
for (const custom of this.customSerializers) {
|
|
133
|
+
if (custom.condition(data)) {
|
|
134
|
+
const result = this.serialize(custom.serialize(data), hasBlobRef);
|
|
135
|
+
return result;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
if (data instanceof Blob) {
|
|
139
|
+
hasBlobRef.value = true;
|
|
140
|
+
return [data, hasBlobRef.value];
|
|
141
|
+
}
|
|
142
|
+
if (data instanceof Set) {
|
|
143
|
+
return this.serialize(Array.from(data), hasBlobRef);
|
|
144
|
+
}
|
|
145
|
+
if (data instanceof Map) {
|
|
146
|
+
return this.serialize(Array.from(data.entries()), hasBlobRef);
|
|
147
|
+
}
|
|
148
|
+
if (Array.isArray(data)) {
|
|
149
|
+
const json = data.map((v) => v === void 0 ? null : this.serialize(v, hasBlobRef)[0]);
|
|
150
|
+
return [json, hasBlobRef.value];
|
|
151
|
+
}
|
|
152
|
+
if (isObject(data)) {
|
|
153
|
+
const json = {};
|
|
154
|
+
for (const k in data) {
|
|
155
|
+
if (k === "toJSON" && typeof data[k] === "function") {
|
|
156
|
+
continue;
|
|
157
|
+
}
|
|
158
|
+
json[k] = this.serialize(data[k], hasBlobRef)[0];
|
|
159
|
+
}
|
|
160
|
+
return [json, hasBlobRef.value];
|
|
161
|
+
}
|
|
162
|
+
if (typeof data === "bigint" || data instanceof RegExp || data instanceof URL) {
|
|
163
|
+
return [data.toString(), hasBlobRef.value];
|
|
164
|
+
}
|
|
165
|
+
if (data instanceof Date) {
|
|
166
|
+
return [Number.isNaN(data.getTime()) ? null : data.toISOString(), hasBlobRef.value];
|
|
167
|
+
}
|
|
168
|
+
if (Number.isNaN(data)) {
|
|
169
|
+
return [null, hasBlobRef.value];
|
|
170
|
+
}
|
|
171
|
+
return [data, hasBlobRef.value];
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
function standardizeHTTPPath(path) {
|
|
176
|
+
return `/${path.replace(/\/{2,}/g, "/").replace(/^\/|\/$/g, "")}`;
|
|
177
|
+
}
|
|
178
|
+
function getDynamicParams(path) {
|
|
179
|
+
return path ? standardizeHTTPPath(path).match(/\/\{[^}]+\}/g)?.map((v) => ({
|
|
180
|
+
raw: v,
|
|
181
|
+
name: v.match(/\{\+?([^}]+)\}/)[1]
|
|
182
|
+
})) : void 0;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
class StandardOpenapiLinkCodec {
|
|
186
|
+
constructor(contract, serializer, options) {
|
|
187
|
+
this.contract = contract;
|
|
188
|
+
this.serializer = serializer;
|
|
189
|
+
this.baseUrl = options.url;
|
|
190
|
+
this.headers = options.headers ?? {};
|
|
191
|
+
}
|
|
192
|
+
baseUrl;
|
|
193
|
+
headers;
|
|
194
|
+
async encode(path, input, options) {
|
|
195
|
+
const baseUrl = await value(this.baseUrl, options, path, input);
|
|
196
|
+
let headers = await value(this.headers, options, path, input);
|
|
197
|
+
if (options.lastEventId !== void 0) {
|
|
198
|
+
headers = mergeStandardHeaders(headers, { "last-event-id": options.lastEventId });
|
|
199
|
+
}
|
|
200
|
+
const procedure = get(this.contract, path);
|
|
201
|
+
if (!isContractProcedure(procedure)) {
|
|
202
|
+
throw new Error(`[StandardOpenapiLinkCodec] expect a contract procedure at ${path.join(".")}`);
|
|
203
|
+
}
|
|
204
|
+
const inputStructure = fallbackContractConfig("defaultInputStructure", procedure["~orpc"].route.inputStructure);
|
|
205
|
+
return inputStructure === "compact" ? this.#encodeCompact(procedure, path, input, options, baseUrl, headers) : this.#encodeDetailed(procedure, path, input, options, baseUrl, headers);
|
|
206
|
+
}
|
|
207
|
+
#encodeCompact(procedure, path, input, options, baseUrl, headers) {
|
|
208
|
+
let httpPath = standardizeHTTPPath(procedure["~orpc"].route.path ?? toHttpPath(path));
|
|
209
|
+
let httpBody = input;
|
|
210
|
+
const dynamicParams = getDynamicParams(httpPath);
|
|
211
|
+
if (dynamicParams?.length) {
|
|
212
|
+
if (!isObject(input)) {
|
|
213
|
+
throw new TypeError(`[StandardOpenapiLinkCodec] Invalid input shape for "compact" structure when has dynamic params at ${path.join(".")}.`);
|
|
214
|
+
}
|
|
215
|
+
const body = { ...input };
|
|
216
|
+
for (const param of dynamicParams) {
|
|
217
|
+
const value2 = input[param.name];
|
|
218
|
+
httpPath = httpPath.replace(param.raw, `/${encodeURIComponent(`${this.serializer.serialize(value2)}`)}`);
|
|
219
|
+
delete body[param.name];
|
|
220
|
+
}
|
|
221
|
+
httpBody = Object.keys(body).length ? body : void 0;
|
|
222
|
+
}
|
|
223
|
+
const method = fallbackContractConfig("defaultMethod", procedure["~orpc"].route.method);
|
|
224
|
+
const url = new URL(baseUrl);
|
|
225
|
+
url.pathname = `${url.pathname.replace(/\/$/, "")}${httpPath}`;
|
|
226
|
+
if (method === "GET") {
|
|
227
|
+
const serialized = this.serializer.serialize(httpBody, { outputFormat: "URLSearchParams" });
|
|
228
|
+
for (const [key, value2] of serialized) {
|
|
229
|
+
url.searchParams.append(key, value2);
|
|
230
|
+
}
|
|
231
|
+
return {
|
|
232
|
+
url,
|
|
233
|
+
method,
|
|
234
|
+
headers,
|
|
235
|
+
body: void 0,
|
|
236
|
+
signal: options.signal
|
|
237
|
+
};
|
|
238
|
+
}
|
|
239
|
+
return {
|
|
240
|
+
url,
|
|
241
|
+
method,
|
|
242
|
+
headers,
|
|
243
|
+
body: this.serializer.serialize(httpBody),
|
|
244
|
+
signal: options.signal
|
|
245
|
+
};
|
|
246
|
+
}
|
|
247
|
+
#encodeDetailed(procedure, path, input, options, baseUrl, headers) {
|
|
248
|
+
let httpPath = standardizeHTTPPath(procedure["~orpc"].route.path ?? toHttpPath(path));
|
|
249
|
+
const dynamicParams = getDynamicParams(httpPath);
|
|
250
|
+
if (!isObject(input) && input !== void 0) {
|
|
251
|
+
throw new TypeError(`[StandardOpenapiLinkCodec] Invalid input shape for "detailed" structure at ${path.join(".")}.`);
|
|
252
|
+
}
|
|
253
|
+
if (dynamicParams?.length) {
|
|
254
|
+
if (!isObject(input?.params)) {
|
|
255
|
+
throw new TypeError(`[StandardOpenapiLinkCodec] Invalid input.params shape for "detailed" structure when has dynamic params at ${path.join(".")}.`);
|
|
256
|
+
}
|
|
257
|
+
for (const param of dynamicParams) {
|
|
258
|
+
const value2 = input.params[param.name];
|
|
259
|
+
httpPath = httpPath.replace(param.raw, `/${encodeURIComponent(`${this.serializer.serialize(value2)}`)}`);
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
let mergedHeaders = headers;
|
|
263
|
+
if (input?.headers !== void 0) {
|
|
264
|
+
if (!isObject(input.headers)) {
|
|
265
|
+
throw new TypeError(`[StandardOpenapiLinkCodec] Invalid input.headers shape for "detailed" structure at ${path.join(".")}.`);
|
|
266
|
+
}
|
|
267
|
+
mergedHeaders = mergeStandardHeaders(input.headers, headers);
|
|
268
|
+
}
|
|
269
|
+
const method = fallbackContractConfig("defaultMethod", procedure["~orpc"].route.method);
|
|
270
|
+
const url = new URL(baseUrl);
|
|
271
|
+
url.pathname = `${url.pathname.replace(/\/$/, "")}${httpPath}`;
|
|
272
|
+
if (input?.query !== void 0) {
|
|
273
|
+
const query = this.serializer.serialize(input.query, { outputFormat: "URLSearchParams" });
|
|
274
|
+
for (const [key, value2] of query) {
|
|
275
|
+
url.searchParams.append(key, value2);
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
if (method === "GET") {
|
|
279
|
+
return {
|
|
280
|
+
url,
|
|
281
|
+
method,
|
|
282
|
+
headers: mergedHeaders,
|
|
283
|
+
body: void 0,
|
|
284
|
+
signal: options.signal
|
|
285
|
+
};
|
|
286
|
+
}
|
|
287
|
+
return {
|
|
288
|
+
url,
|
|
289
|
+
method,
|
|
290
|
+
headers: mergedHeaders,
|
|
291
|
+
body: this.serializer.serialize(input?.body),
|
|
292
|
+
signal: options.signal
|
|
293
|
+
};
|
|
294
|
+
}
|
|
295
|
+
async decode(response, _options, path) {
|
|
296
|
+
const isOk = !isORPCErrorStatus(response.status);
|
|
297
|
+
const deserialized = await (async () => {
|
|
298
|
+
let isBodyOk = false;
|
|
299
|
+
try {
|
|
300
|
+
const body = await response.body();
|
|
301
|
+
isBodyOk = true;
|
|
302
|
+
return this.serializer.deserialize(body);
|
|
303
|
+
} catch (error) {
|
|
304
|
+
if (!isBodyOk) {
|
|
305
|
+
throw new Error("Cannot parse response body, please check the response body and content-type.", {
|
|
306
|
+
cause: error
|
|
307
|
+
});
|
|
308
|
+
}
|
|
309
|
+
throw new Error("Invalid OpenAPI response format.", {
|
|
310
|
+
cause: error
|
|
311
|
+
});
|
|
312
|
+
}
|
|
313
|
+
})();
|
|
314
|
+
if (!isOk) {
|
|
315
|
+
if (isORPCErrorJson(deserialized)) {
|
|
316
|
+
throw createORPCErrorFromJson(deserialized);
|
|
317
|
+
}
|
|
318
|
+
throw new ORPCError(getMalformedResponseErrorCode(response.status), {
|
|
319
|
+
status: response.status,
|
|
320
|
+
data: { ...response, body: deserialized }
|
|
321
|
+
});
|
|
322
|
+
}
|
|
323
|
+
const procedure = get(this.contract, path);
|
|
324
|
+
if (!isContractProcedure(procedure)) {
|
|
325
|
+
throw new Error(`[StandardOpenapiLinkCodec] expect a contract procedure at ${path.join(".")}`);
|
|
326
|
+
}
|
|
327
|
+
const outputStructure = fallbackContractConfig("defaultOutputStructure", procedure["~orpc"].route.outputStructure);
|
|
328
|
+
if (outputStructure === "compact") {
|
|
329
|
+
return deserialized;
|
|
330
|
+
}
|
|
331
|
+
return {
|
|
332
|
+
headers: response.headers,
|
|
333
|
+
body: deserialized
|
|
334
|
+
};
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
class StandardOpenAPISerializer {
|
|
339
|
+
constructor(jsonSerializer, bracketNotation) {
|
|
340
|
+
this.jsonSerializer = jsonSerializer;
|
|
341
|
+
this.bracketNotation = bracketNotation;
|
|
342
|
+
}
|
|
343
|
+
serialize(data, options = {}) {
|
|
344
|
+
if (isAsyncIteratorObject(data) && !options.outputFormat) {
|
|
345
|
+
return mapEventIterator(data, {
|
|
346
|
+
value: async (value) => this.#serialize(value, { outputFormat: "plain" }),
|
|
347
|
+
error: async (e) => {
|
|
348
|
+
return new ErrorEvent({
|
|
349
|
+
data: this.#serialize(toORPCError(e).toJSON(), { outputFormat: "plain" }),
|
|
350
|
+
cause: e
|
|
351
|
+
});
|
|
352
|
+
}
|
|
353
|
+
});
|
|
354
|
+
}
|
|
355
|
+
return this.#serialize(data, options);
|
|
356
|
+
}
|
|
357
|
+
#serialize(data, options) {
|
|
358
|
+
const [json, hasBlob] = this.jsonSerializer.serialize(data);
|
|
359
|
+
if (options.outputFormat === "plain") {
|
|
360
|
+
return json;
|
|
361
|
+
}
|
|
362
|
+
if (options.outputFormat === "URLSearchParams") {
|
|
363
|
+
const params = new URLSearchParams();
|
|
364
|
+
for (const [path, value] of this.bracketNotation.serialize(json)) {
|
|
365
|
+
if (typeof value === "string" || typeof value === "number" || typeof value === "boolean") {
|
|
366
|
+
params.append(path, value.toString());
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
return params;
|
|
370
|
+
}
|
|
371
|
+
if (json instanceof Blob || json === void 0 || !hasBlob) {
|
|
372
|
+
return json;
|
|
373
|
+
}
|
|
374
|
+
const form = new FormData();
|
|
375
|
+
for (const [path, value] of this.bracketNotation.serialize(json)) {
|
|
376
|
+
if (typeof value === "string" || typeof value === "number" || typeof value === "boolean") {
|
|
377
|
+
form.append(path, value.toString());
|
|
378
|
+
} else if (value instanceof Blob) {
|
|
379
|
+
form.append(path, value);
|
|
380
|
+
}
|
|
381
|
+
}
|
|
382
|
+
return form;
|
|
383
|
+
}
|
|
384
|
+
deserialize(data) {
|
|
385
|
+
if (data instanceof URLSearchParams || data instanceof FormData) {
|
|
386
|
+
return this.bracketNotation.deserialize(Array.from(data.entries()));
|
|
387
|
+
}
|
|
388
|
+
if (isAsyncIteratorObject(data)) {
|
|
389
|
+
return mapEventIterator(data, {
|
|
390
|
+
value: async (value) => value,
|
|
391
|
+
error: async (e) => {
|
|
392
|
+
if (e instanceof ErrorEvent && isORPCErrorJson(e.data)) {
|
|
393
|
+
return createORPCErrorFromJson(e.data, { cause: e });
|
|
394
|
+
}
|
|
395
|
+
return e;
|
|
396
|
+
}
|
|
397
|
+
});
|
|
398
|
+
}
|
|
399
|
+
return data;
|
|
400
|
+
}
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
class StandardOpenAPILink extends StandardLink {
|
|
404
|
+
constructor(contract, linkClient, options) {
|
|
405
|
+
const jsonSerializer = new StandardOpenAPIJsonSerializer(options);
|
|
406
|
+
const bracketNotationSerializer = new StandardBracketNotationSerializer();
|
|
407
|
+
const serializer = new StandardOpenAPISerializer(jsonSerializer, bracketNotationSerializer);
|
|
408
|
+
const linkCodec = new StandardOpenapiLinkCodec(contract, serializer, options);
|
|
409
|
+
super(linkCodec, linkClient, options);
|
|
410
|
+
}
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
export { StandardBracketNotationSerializer as S, StandardOpenAPIJsonSerializer as a, StandardOpenAPILink as b, StandardOpenapiLinkCodec as c, StandardOpenAPISerializer as d, getDynamicParams as g, standardizeHTTPPath as s };
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { ClientContext, ClientOptions } from '@orpc/client';
|
|
2
|
+
import { AnyContractRouter } from '@orpc/contract';
|
|
3
|
+
import { StandardLinkCodec, StandardLinkOptions, StandardLink, StandardLinkClient } from '@orpc/client/standard';
|
|
4
|
+
import { StandardHeaders, StandardRequest, StandardLazyResponse } from '@orpc/standard-server';
|
|
5
|
+
import { Segment, Value } from '@orpc/shared';
|
|
6
|
+
|
|
7
|
+
type StandardBracketNotationSerialized = [string, unknown][];
|
|
8
|
+
declare class StandardBracketNotationSerializer {
|
|
9
|
+
serialize(data: unknown, segments?: Segment[], result?: StandardBracketNotationSerialized): StandardBracketNotationSerialized;
|
|
10
|
+
deserialize(serialized: StandardBracketNotationSerialized): Record<string, unknown> | unknown[];
|
|
11
|
+
stringifyPath(segments: readonly Segment[]): string;
|
|
12
|
+
parsePath(path: string): string[];
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
type StandardOpenAPIJsonSerialized = [json: unknown, hasBlob: boolean];
|
|
16
|
+
interface StandardOpenAPICustomJsonSerializer {
|
|
17
|
+
condition(data: unknown): boolean;
|
|
18
|
+
serialize(data: any): unknown;
|
|
19
|
+
}
|
|
20
|
+
interface StandardOpenAPIJsonSerializerOptions {
|
|
21
|
+
customJsonSerializers?: readonly StandardOpenAPICustomJsonSerializer[];
|
|
22
|
+
}
|
|
23
|
+
declare class StandardOpenAPIJsonSerializer {
|
|
24
|
+
private readonly customSerializers;
|
|
25
|
+
constructor(options?: StandardOpenAPIJsonSerializerOptions);
|
|
26
|
+
serialize(data: unknown, hasBlobRef?: {
|
|
27
|
+
value: boolean;
|
|
28
|
+
}): StandardOpenAPIJsonSerialized;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
interface StandardOpenAPISerializeOptions {
|
|
32
|
+
outputFormat?: 'plain' | 'URLSearchParams';
|
|
33
|
+
}
|
|
34
|
+
declare class StandardOpenAPISerializer {
|
|
35
|
+
#private;
|
|
36
|
+
private readonly jsonSerializer;
|
|
37
|
+
private readonly bracketNotation;
|
|
38
|
+
constructor(jsonSerializer: StandardOpenAPIJsonSerializer, bracketNotation: StandardBracketNotationSerializer);
|
|
39
|
+
serialize(data: unknown, options?: StandardOpenAPISerializeOptions): unknown;
|
|
40
|
+
deserialize(data: unknown): unknown;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
interface StandardOpenapiLinkCodecOptions<T extends ClientContext> {
|
|
44
|
+
/**
|
|
45
|
+
* Base url for all requests.
|
|
46
|
+
*/
|
|
47
|
+
url: Value<string | URL, [
|
|
48
|
+
options: ClientOptions<T>,
|
|
49
|
+
path: readonly string[],
|
|
50
|
+
input: unknown
|
|
51
|
+
]>;
|
|
52
|
+
/**
|
|
53
|
+
* Inject headers to the request.
|
|
54
|
+
*/
|
|
55
|
+
headers?: Value<StandardHeaders, [
|
|
56
|
+
options: ClientOptions<T>,
|
|
57
|
+
path: readonly string[],
|
|
58
|
+
input: unknown
|
|
59
|
+
]>;
|
|
60
|
+
}
|
|
61
|
+
declare class StandardOpenapiLinkCodec<T extends ClientContext> implements StandardLinkCodec<T> {
|
|
62
|
+
#private;
|
|
63
|
+
private readonly contract;
|
|
64
|
+
private readonly serializer;
|
|
65
|
+
private readonly baseUrl;
|
|
66
|
+
private readonly headers;
|
|
67
|
+
constructor(contract: AnyContractRouter, serializer: StandardOpenAPISerializer, options: StandardOpenapiLinkCodecOptions<T>);
|
|
68
|
+
encode(path: readonly string[], input: unknown, options: ClientOptions<T>): Promise<StandardRequest>;
|
|
69
|
+
decode(response: StandardLazyResponse, _options: ClientOptions<T>, path: readonly string[]): Promise<unknown>;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
interface StandardOpenAPILinkOptions<T extends ClientContext> extends StandardLinkOptions<T>, StandardOpenapiLinkCodecOptions<T>, StandardOpenAPIJsonSerializerOptions {
|
|
73
|
+
}
|
|
74
|
+
declare class StandardOpenAPILink<T extends ClientContext> extends StandardLink<T> {
|
|
75
|
+
constructor(contract: AnyContractRouter, linkClient: StandardLinkClient<T>, options: StandardOpenAPILinkOptions<T>);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export { type StandardBracketNotationSerialized as S, StandardBracketNotationSerializer as a, type StandardOpenAPIJsonSerialized as b, type StandardOpenAPICustomJsonSerializer as c, type StandardOpenAPIJsonSerializerOptions as d, StandardOpenAPIJsonSerializer as e, type StandardOpenAPILinkOptions as f, StandardOpenAPILink as g, type StandardOpenapiLinkCodecOptions as h, StandardOpenapiLinkCodec as i, type StandardOpenAPISerializeOptions as j, StandardOpenAPISerializer as k };
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { ClientContext, ClientOptions } from '@orpc/client';
|
|
2
|
+
import { AnyContractRouter } from '@orpc/contract';
|
|
3
|
+
import { StandardLinkCodec, StandardLinkOptions, StandardLink, StandardLinkClient } from '@orpc/client/standard';
|
|
4
|
+
import { StandardHeaders, StandardRequest, StandardLazyResponse } from '@orpc/standard-server';
|
|
5
|
+
import { Segment, Value } from '@orpc/shared';
|
|
6
|
+
|
|
7
|
+
type StandardBracketNotationSerialized = [string, unknown][];
|
|
8
|
+
declare class StandardBracketNotationSerializer {
|
|
9
|
+
serialize(data: unknown, segments?: Segment[], result?: StandardBracketNotationSerialized): StandardBracketNotationSerialized;
|
|
10
|
+
deserialize(serialized: StandardBracketNotationSerialized): Record<string, unknown> | unknown[];
|
|
11
|
+
stringifyPath(segments: readonly Segment[]): string;
|
|
12
|
+
parsePath(path: string): string[];
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
type StandardOpenAPIJsonSerialized = [json: unknown, hasBlob: boolean];
|
|
16
|
+
interface StandardOpenAPICustomJsonSerializer {
|
|
17
|
+
condition(data: unknown): boolean;
|
|
18
|
+
serialize(data: any): unknown;
|
|
19
|
+
}
|
|
20
|
+
interface StandardOpenAPIJsonSerializerOptions {
|
|
21
|
+
customJsonSerializers?: readonly StandardOpenAPICustomJsonSerializer[];
|
|
22
|
+
}
|
|
23
|
+
declare class StandardOpenAPIJsonSerializer {
|
|
24
|
+
private readonly customSerializers;
|
|
25
|
+
constructor(options?: StandardOpenAPIJsonSerializerOptions);
|
|
26
|
+
serialize(data: unknown, hasBlobRef?: {
|
|
27
|
+
value: boolean;
|
|
28
|
+
}): StandardOpenAPIJsonSerialized;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
interface StandardOpenAPISerializeOptions {
|
|
32
|
+
outputFormat?: 'plain' | 'URLSearchParams';
|
|
33
|
+
}
|
|
34
|
+
declare class StandardOpenAPISerializer {
|
|
35
|
+
#private;
|
|
36
|
+
private readonly jsonSerializer;
|
|
37
|
+
private readonly bracketNotation;
|
|
38
|
+
constructor(jsonSerializer: StandardOpenAPIJsonSerializer, bracketNotation: StandardBracketNotationSerializer);
|
|
39
|
+
serialize(data: unknown, options?: StandardOpenAPISerializeOptions): unknown;
|
|
40
|
+
deserialize(data: unknown): unknown;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
interface StandardOpenapiLinkCodecOptions<T extends ClientContext> {
|
|
44
|
+
/**
|
|
45
|
+
* Base url for all requests.
|
|
46
|
+
*/
|
|
47
|
+
url: Value<string | URL, [
|
|
48
|
+
options: ClientOptions<T>,
|
|
49
|
+
path: readonly string[],
|
|
50
|
+
input: unknown
|
|
51
|
+
]>;
|
|
52
|
+
/**
|
|
53
|
+
* Inject headers to the request.
|
|
54
|
+
*/
|
|
55
|
+
headers?: Value<StandardHeaders, [
|
|
56
|
+
options: ClientOptions<T>,
|
|
57
|
+
path: readonly string[],
|
|
58
|
+
input: unknown
|
|
59
|
+
]>;
|
|
60
|
+
}
|
|
61
|
+
declare class StandardOpenapiLinkCodec<T extends ClientContext> implements StandardLinkCodec<T> {
|
|
62
|
+
#private;
|
|
63
|
+
private readonly contract;
|
|
64
|
+
private readonly serializer;
|
|
65
|
+
private readonly baseUrl;
|
|
66
|
+
private readonly headers;
|
|
67
|
+
constructor(contract: AnyContractRouter, serializer: StandardOpenAPISerializer, options: StandardOpenapiLinkCodecOptions<T>);
|
|
68
|
+
encode(path: readonly string[], input: unknown, options: ClientOptions<T>): Promise<StandardRequest>;
|
|
69
|
+
decode(response: StandardLazyResponse, _options: ClientOptions<T>, path: readonly string[]): Promise<unknown>;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
interface StandardOpenAPILinkOptions<T extends ClientContext> extends StandardLinkOptions<T>, StandardOpenapiLinkCodecOptions<T>, StandardOpenAPIJsonSerializerOptions {
|
|
73
|
+
}
|
|
74
|
+
declare class StandardOpenAPILink<T extends ClientContext> extends StandardLink<T> {
|
|
75
|
+
constructor(contract: AnyContractRouter, linkClient: StandardLinkClient<T>, options: StandardOpenAPILinkOptions<T>);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export { type StandardBracketNotationSerialized as S, StandardBracketNotationSerializer as a, type StandardOpenAPIJsonSerialized as b, type StandardOpenAPICustomJsonSerializer as c, type StandardOpenAPIJsonSerializerOptions as d, StandardOpenAPIJsonSerializer as e, type StandardOpenAPILinkOptions as f, StandardOpenAPILink as g, type StandardOpenapiLinkCodecOptions as h, StandardOpenapiLinkCodec as i, type StandardOpenAPISerializeOptions as j, StandardOpenAPISerializer as k };
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@orpc/openapi-client",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.53.0",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"homepage": "https://orpc.unnoq.com",
|
|
7
7
|
"repository": {
|
|
@@ -23,15 +23,24 @@
|
|
|
23
23
|
"types": "./dist/adapters/standard/index.d.mts",
|
|
24
24
|
"import": "./dist/adapters/standard/index.mjs",
|
|
25
25
|
"default": "./dist/adapters/standard/index.mjs"
|
|
26
|
+
},
|
|
27
|
+
"./fetch": {
|
|
28
|
+
"types": "./dist/adapters/fetch/index.d.mts",
|
|
29
|
+
"import": "./dist/adapters/fetch/index.mjs",
|
|
30
|
+
"default": "./dist/adapters/fetch/index.mjs"
|
|
26
31
|
}
|
|
27
32
|
},
|
|
28
33
|
"files": [
|
|
29
34
|
"dist"
|
|
30
35
|
],
|
|
31
36
|
"dependencies": {
|
|
32
|
-
"@orpc/client": "0.
|
|
33
|
-
"@orpc/
|
|
34
|
-
"@orpc/
|
|
37
|
+
"@orpc/client": "0.53.0",
|
|
38
|
+
"@orpc/contract": "0.53.0",
|
|
39
|
+
"@orpc/shared": "0.53.0",
|
|
40
|
+
"@orpc/standard-server": "0.53.0"
|
|
41
|
+
},
|
|
42
|
+
"devDependencies": {
|
|
43
|
+
"@orpc/server": "0.53.0"
|
|
35
44
|
},
|
|
36
45
|
"scripts": {
|
|
37
46
|
"build": "unbuild",
|