@orpc/client 0.0.0-next.e361acd → 0.0.0-next.e563486

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,337 @@
1
+ import { intercept, isObject, value, trim, isAsyncIteratorObject, stringifyJSON } from '@orpc/shared';
2
+ import { C as CompositeClientPlugin } from './client.CvnV7_uV.mjs';
3
+ import { ErrorEvent } from '@orpc/standard-server';
4
+ import { O as ORPCError, m as mapEventIterator, t as toORPCError } from './client.BacCdg3F.mjs';
5
+
6
+ class InvalidEventIteratorRetryResponse extends Error {
7
+ }
8
+ class StandardLink {
9
+ constructor(codec, sender, options = {}) {
10
+ this.codec = codec;
11
+ this.sender = sender;
12
+ const plugin = new CompositeClientPlugin(options.plugins);
13
+ plugin.init(options);
14
+ this.interceptors = options.interceptors ?? [];
15
+ this.clientInterceptors = options.clientInterceptors ?? [];
16
+ }
17
+ interceptors;
18
+ clientInterceptors;
19
+ call(path, input, options) {
20
+ return intercept(this.interceptors, { path, input, options }, async ({ path: path2, input: input2, options: options2 }) => {
21
+ const output = await this.#call(path2, input2, options2);
22
+ return output;
23
+ });
24
+ }
25
+ async #call(path, input, options) {
26
+ const request = await this.codec.encode(path, input, options);
27
+ const response = await intercept(
28
+ this.clientInterceptors,
29
+ { request },
30
+ ({ request: request2 }) => this.sender.call(request2, options, path, input)
31
+ );
32
+ const output = await this.codec.decode(response, options, path, input);
33
+ return output;
34
+ }
35
+ }
36
+
37
+ const STANDARD_RPC_JSON_SERIALIZER_BUILT_IN_TYPES = {
38
+ BIGINT: 0,
39
+ DATE: 1,
40
+ NAN: 2,
41
+ UNDEFINED: 3,
42
+ URL: 4,
43
+ REGEXP: 5,
44
+ SET: 6,
45
+ MAP: 7
46
+ };
47
+ class StandardRPCJsonSerializer {
48
+ customSerializers;
49
+ constructor(options = {}) {
50
+ this.customSerializers = options.customJsonSerializers ?? [];
51
+ if (this.customSerializers.length !== new Set(this.customSerializers.map((custom) => custom.type)).size) {
52
+ throw new Error("Custom serializer type must be unique.");
53
+ }
54
+ }
55
+ serialize(data, segments = [], meta = [], maps = [], blobs = []) {
56
+ for (const custom of this.customSerializers) {
57
+ if (custom.condition(data)) {
58
+ const result = this.serialize(custom.serialize(data), segments, meta, maps, blobs);
59
+ meta.push([custom.type, ...segments]);
60
+ return result;
61
+ }
62
+ }
63
+ if (data instanceof Blob) {
64
+ maps.push(segments);
65
+ blobs.push(data);
66
+ return [data, meta, maps, blobs];
67
+ }
68
+ if (typeof data === "bigint") {
69
+ meta.push([STANDARD_RPC_JSON_SERIALIZER_BUILT_IN_TYPES.BIGINT, ...segments]);
70
+ return [data.toString(), meta, maps, blobs];
71
+ }
72
+ if (data instanceof Date) {
73
+ meta.push([STANDARD_RPC_JSON_SERIALIZER_BUILT_IN_TYPES.DATE, ...segments]);
74
+ if (Number.isNaN(data.getTime())) {
75
+ return [null, meta, maps, blobs];
76
+ }
77
+ return [data.toISOString(), meta, maps, blobs];
78
+ }
79
+ if (Number.isNaN(data)) {
80
+ meta.push([STANDARD_RPC_JSON_SERIALIZER_BUILT_IN_TYPES.NAN, ...segments]);
81
+ return [null, meta, maps, blobs];
82
+ }
83
+ if (data instanceof URL) {
84
+ meta.push([STANDARD_RPC_JSON_SERIALIZER_BUILT_IN_TYPES.URL, ...segments]);
85
+ return [data.toString(), meta, maps, blobs];
86
+ }
87
+ if (data instanceof RegExp) {
88
+ meta.push([STANDARD_RPC_JSON_SERIALIZER_BUILT_IN_TYPES.REGEXP, ...segments]);
89
+ return [data.toString(), meta, maps, blobs];
90
+ }
91
+ if (data instanceof Set) {
92
+ const result = this.serialize(Array.from(data), segments, meta, maps, blobs);
93
+ meta.push([STANDARD_RPC_JSON_SERIALIZER_BUILT_IN_TYPES.SET, ...segments]);
94
+ return result;
95
+ }
96
+ if (data instanceof Map) {
97
+ const result = this.serialize(Array.from(data.entries()), segments, meta, maps, blobs);
98
+ meta.push([STANDARD_RPC_JSON_SERIALIZER_BUILT_IN_TYPES.MAP, ...segments]);
99
+ return result;
100
+ }
101
+ if (Array.isArray(data)) {
102
+ const json = data.map((v, i) => {
103
+ if (v === void 0) {
104
+ meta.push([STANDARD_RPC_JSON_SERIALIZER_BUILT_IN_TYPES.UNDEFINED, ...segments, i]);
105
+ return v;
106
+ }
107
+ return this.serialize(v, [...segments, i], meta, maps, blobs)[0];
108
+ });
109
+ return [json, meta, maps, blobs];
110
+ }
111
+ if (isObject(data)) {
112
+ const json = {};
113
+ for (const k in data) {
114
+ json[k] = this.serialize(data[k], [...segments, k], meta, maps, blobs)[0];
115
+ }
116
+ return [json, meta, maps, blobs];
117
+ }
118
+ return [data, meta, maps, blobs];
119
+ }
120
+ deserialize(json, meta, maps, getBlob) {
121
+ const ref = { data: json };
122
+ if (maps && getBlob) {
123
+ maps.forEach((segments, i) => {
124
+ let currentRef = ref;
125
+ let preSegment = "data";
126
+ segments.forEach((segment) => {
127
+ currentRef = currentRef[preSegment];
128
+ preSegment = segment;
129
+ });
130
+ currentRef[preSegment] = getBlob(i);
131
+ });
132
+ }
133
+ for (const item of meta) {
134
+ const type = item[0];
135
+ let currentRef = ref;
136
+ let preSegment = "data";
137
+ for (let i = 1; i < item.length; i++) {
138
+ currentRef = currentRef[preSegment];
139
+ preSegment = item[i];
140
+ }
141
+ for (const custom of this.customSerializers) {
142
+ if (custom.type === type) {
143
+ currentRef[preSegment] = custom.deserialize(currentRef[preSegment]);
144
+ break;
145
+ }
146
+ }
147
+ switch (type) {
148
+ case STANDARD_RPC_JSON_SERIALIZER_BUILT_IN_TYPES.BIGINT:
149
+ currentRef[preSegment] = BigInt(currentRef[preSegment]);
150
+ break;
151
+ case STANDARD_RPC_JSON_SERIALIZER_BUILT_IN_TYPES.DATE:
152
+ currentRef[preSegment] = new Date(currentRef[preSegment] ?? "Invalid Date");
153
+ break;
154
+ case STANDARD_RPC_JSON_SERIALIZER_BUILT_IN_TYPES.NAN:
155
+ currentRef[preSegment] = Number.NaN;
156
+ break;
157
+ case STANDARD_RPC_JSON_SERIALIZER_BUILT_IN_TYPES.UNDEFINED:
158
+ currentRef[preSegment] = void 0;
159
+ break;
160
+ case STANDARD_RPC_JSON_SERIALIZER_BUILT_IN_TYPES.URL:
161
+ currentRef[preSegment] = new URL(currentRef[preSegment]);
162
+ break;
163
+ case STANDARD_RPC_JSON_SERIALIZER_BUILT_IN_TYPES.REGEXP: {
164
+ const [, pattern, flags] = currentRef[preSegment].match(/^\/(.*)\/([a-z]*)$/);
165
+ currentRef[preSegment] = new RegExp(pattern, flags);
166
+ break;
167
+ }
168
+ case STANDARD_RPC_JSON_SERIALIZER_BUILT_IN_TYPES.SET:
169
+ currentRef[preSegment] = new Set(currentRef[preSegment]);
170
+ break;
171
+ case STANDARD_RPC_JSON_SERIALIZER_BUILT_IN_TYPES.MAP:
172
+ currentRef[preSegment] = new Map(currentRef[preSegment]);
173
+ break;
174
+ }
175
+ }
176
+ return ref.data;
177
+ }
178
+ }
179
+
180
+ class StandardRPCLinkCodec {
181
+ constructor(serializer, options) {
182
+ this.serializer = serializer;
183
+ this.baseUrl = options.url;
184
+ this.maxUrlLength = options.maxUrlLength ?? 2083;
185
+ this.fallbackMethod = options.fallbackMethod ?? "POST";
186
+ this.expectedMethod = options.method ?? this.fallbackMethod;
187
+ this.headers = options.headers ?? {};
188
+ }
189
+ baseUrl;
190
+ maxUrlLength;
191
+ fallbackMethod;
192
+ expectedMethod;
193
+ headers;
194
+ async encode(path, input, options) {
195
+ const expectedMethod = await value(this.expectedMethod, options, path, input);
196
+ const headers = { ...await value(this.headers, options, path, input) };
197
+ const baseUrl = await value(this.baseUrl, options, path, input);
198
+ const url = new URL(`${trim(baseUrl.toString(), "/")}/${path.map(encodeURIComponent).join("/")}`);
199
+ if (options.lastEventId !== void 0) {
200
+ if (Array.isArray(headers["last-event-id"])) {
201
+ headers["last-event-id"] = [...headers["last-event-id"], options.lastEventId];
202
+ } else if (headers["last-event-id"] !== void 0) {
203
+ headers["last-event-id"] = [headers["last-event-id"], options.lastEventId];
204
+ } else {
205
+ headers["last-event-id"] = options.lastEventId;
206
+ }
207
+ }
208
+ const serialized = this.serializer.serialize(input);
209
+ if (expectedMethod === "GET" && !(serialized instanceof FormData) && !(serialized instanceof Blob) && !isAsyncIteratorObject(serialized)) {
210
+ const maxUrlLength = await value(this.maxUrlLength, options, path, input);
211
+ const getUrl = new URL(url);
212
+ getUrl.searchParams.append("data", stringifyJSON(serialized) ?? "");
213
+ if (getUrl.toString().length <= maxUrlLength) {
214
+ return {
215
+ body: void 0,
216
+ method: expectedMethod,
217
+ headers,
218
+ url: getUrl,
219
+ signal: options.signal
220
+ };
221
+ }
222
+ }
223
+ return {
224
+ url,
225
+ method: expectedMethod === "GET" ? this.fallbackMethod : expectedMethod,
226
+ headers,
227
+ body: serialized,
228
+ signal: options.signal
229
+ };
230
+ }
231
+ async decode(response) {
232
+ const isOk = response.status >= 200 && response.status < 300;
233
+ const deserialized = await (async () => {
234
+ let isBodyOk = false;
235
+ try {
236
+ const body = await response.body();
237
+ isBodyOk = true;
238
+ return this.serializer.deserialize(body);
239
+ } catch (error) {
240
+ if (!isBodyOk) {
241
+ throw new Error("Cannot parse response body, please check the response body and content-type.", {
242
+ cause: error
243
+ });
244
+ }
245
+ throw new Error("Invalid RPC response format.", {
246
+ cause: error
247
+ });
248
+ }
249
+ })();
250
+ if (!isOk) {
251
+ if (ORPCError.isValidJSON(deserialized)) {
252
+ throw ORPCError.fromJSON(deserialized);
253
+ }
254
+ throw new Error("Invalid RPC error response format.", {
255
+ cause: deserialized
256
+ });
257
+ }
258
+ return deserialized;
259
+ }
260
+ }
261
+
262
+ class StandardRPCSerializer {
263
+ constructor(jsonSerializer) {
264
+ this.jsonSerializer = jsonSerializer;
265
+ }
266
+ serialize(data) {
267
+ if (isAsyncIteratorObject(data)) {
268
+ return mapEventIterator(data, {
269
+ value: async (value) => this.#serialize(value, false),
270
+ error: async (e) => {
271
+ return new ErrorEvent({
272
+ data: this.#serialize(toORPCError(e).toJSON(), false),
273
+ cause: e
274
+ });
275
+ }
276
+ });
277
+ }
278
+ return this.#serialize(data, true);
279
+ }
280
+ #serialize(data, enableFormData) {
281
+ if (data === void 0 || data instanceof Blob) {
282
+ return data;
283
+ }
284
+ const [json, meta_, maps, blobs] = this.jsonSerializer.serialize(data);
285
+ const meta = meta_.length === 0 ? void 0 : meta_;
286
+ if (!enableFormData || blobs.length === 0) {
287
+ return {
288
+ json,
289
+ meta
290
+ };
291
+ }
292
+ const form = new FormData();
293
+ form.set("data", stringifyJSON({ json, meta, maps }));
294
+ blobs.forEach((blob, i) => {
295
+ form.set(i.toString(), blob);
296
+ });
297
+ return form;
298
+ }
299
+ deserialize(data) {
300
+ if (isAsyncIteratorObject(data)) {
301
+ return mapEventIterator(data, {
302
+ value: async (value) => this.#deserialize(value),
303
+ error: async (e) => {
304
+ if (!(e instanceof ErrorEvent)) {
305
+ return e;
306
+ }
307
+ const deserialized = this.#deserialize(e.data);
308
+ if (ORPCError.isValidJSON(deserialized)) {
309
+ return ORPCError.fromJSON(deserialized, { cause: e });
310
+ }
311
+ return new ErrorEvent({
312
+ data: deserialized,
313
+ cause: e
314
+ });
315
+ }
316
+ });
317
+ }
318
+ return this.#deserialize(data);
319
+ }
320
+ #deserialize(data) {
321
+ if (data === void 0 || data instanceof Blob) {
322
+ return data;
323
+ }
324
+ if (!(data instanceof FormData)) {
325
+ return this.jsonSerializer.deserialize(data.json, data.meta ?? []);
326
+ }
327
+ const serialized = JSON.parse(data.get("data"));
328
+ return this.jsonSerializer.deserialize(
329
+ serialized.json,
330
+ serialized.meta ?? [],
331
+ serialized.maps,
332
+ (i) => data.get(i.toString())
333
+ );
334
+ }
335
+ }
336
+
337
+ export { InvalidEventIteratorRetryResponse as I, StandardLink as S, STANDARD_RPC_JSON_SERIALIZER_BUILT_IN_TYPES as a, StandardRPCJsonSerializer as b, StandardRPCLinkCodec as c, StandardRPCSerializer as d };
@@ -0,0 +1,30 @@
1
+ type ClientContext = Record<string, any>;
2
+ type ClientOptions<TClientContext extends ClientContext> = {
3
+ signal?: AbortSignal;
4
+ lastEventId?: string | undefined;
5
+ } & (Record<never, never> extends TClientContext ? {
6
+ context?: TClientContext;
7
+ } : {
8
+ context: TClientContext;
9
+ });
10
+ type ClientRest<TClientContext extends ClientContext, TInput> = Record<never, never> extends TClientContext ? undefined extends TInput ? [input?: TInput, options?: ClientOptions<TClientContext>] : [input: TInput, options?: ClientOptions<TClientContext>] : [input: TInput, options: ClientOptions<TClientContext>];
11
+ type ClientPromiseResult<TOutput, TError extends Error> = Promise<TOutput> & {
12
+ __error?: {
13
+ type: TError;
14
+ };
15
+ };
16
+ interface Client<TClientContext extends ClientContext, TInput, TOutput, TError extends Error> {
17
+ (...rest: ClientRest<TClientContext, TInput>): ClientPromiseResult<TOutput, TError>;
18
+ }
19
+ type NestedClient<TClientContext extends ClientContext> = Client<TClientContext, any, any, any> | {
20
+ [k: string]: NestedClient<TClientContext>;
21
+ };
22
+ type InferClientContext<T extends NestedClient<any>> = T extends NestedClient<infer U> ? U : never;
23
+ type ClientOptionsOut<TClientContext extends ClientContext> = ClientOptions<TClientContext> & {
24
+ context: TClientContext;
25
+ };
26
+ interface ClientLink<TClientContext extends ClientContext> {
27
+ call: (path: readonly string[], input: unknown, options: ClientOptionsOut<TClientContext>) => Promise<unknown>;
28
+ }
29
+
30
+ export type { ClientOptionsOut as C, InferClientContext as I, NestedClient as N, ClientContext as a, ClientLink as b, ClientPromiseResult as c, ClientOptions as d, ClientRest as e, Client as f };
@@ -0,0 +1,30 @@
1
+ type ClientContext = Record<string, any>;
2
+ type ClientOptions<TClientContext extends ClientContext> = {
3
+ signal?: AbortSignal;
4
+ lastEventId?: string | undefined;
5
+ } & (Record<never, never> extends TClientContext ? {
6
+ context?: TClientContext;
7
+ } : {
8
+ context: TClientContext;
9
+ });
10
+ type ClientRest<TClientContext extends ClientContext, TInput> = Record<never, never> extends TClientContext ? undefined extends TInput ? [input?: TInput, options?: ClientOptions<TClientContext>] : [input: TInput, options?: ClientOptions<TClientContext>] : [input: TInput, options: ClientOptions<TClientContext>];
11
+ type ClientPromiseResult<TOutput, TError extends Error> = Promise<TOutput> & {
12
+ __error?: {
13
+ type: TError;
14
+ };
15
+ };
16
+ interface Client<TClientContext extends ClientContext, TInput, TOutput, TError extends Error> {
17
+ (...rest: ClientRest<TClientContext, TInput>): ClientPromiseResult<TOutput, TError>;
18
+ }
19
+ type NestedClient<TClientContext extends ClientContext> = Client<TClientContext, any, any, any> | {
20
+ [k: string]: NestedClient<TClientContext>;
21
+ };
22
+ type InferClientContext<T extends NestedClient<any>> = T extends NestedClient<infer U> ? U : never;
23
+ type ClientOptionsOut<TClientContext extends ClientContext> = ClientOptions<TClientContext> & {
24
+ context: TClientContext;
25
+ };
26
+ interface ClientLink<TClientContext extends ClientContext> {
27
+ call: (path: readonly string[], input: unknown, options: ClientOptionsOut<TClientContext>) => Promise<unknown>;
28
+ }
29
+
30
+ export type { ClientOptionsOut as C, InferClientContext as I, NestedClient as N, ClientContext as a, ClientLink as b, ClientPromiseResult as c, ClientOptions as d, ClientRest as e, Client as f };
@@ -0,0 +1,12 @@
1
+ class CompositeClientPlugin {
2
+ constructor(plugins = []) {
3
+ this.plugins = plugins;
4
+ }
5
+ init(options) {
6
+ for (const plugin of this.plugins) {
7
+ plugin.init?.(options);
8
+ }
9
+ }
10
+ }
11
+
12
+ export { CompositeClientPlugin as C };
@@ -0,0 +1,45 @@
1
+ import { Interceptor } from '@orpc/shared';
2
+ import { StandardRequest, StandardLazyResponse } from '@orpc/standard-server';
3
+ import { a as ClientContext, C as ClientOptionsOut, b as ClientLink } from './client.CupM8eRP.mjs';
4
+
5
+ interface StandardLinkCodec<T extends ClientContext> {
6
+ encode(path: readonly string[], input: unknown, options: ClientOptionsOut<any>): Promise<StandardRequest>;
7
+ decode(response: StandardLazyResponse, options: ClientOptionsOut<T>, path: readonly string[], input: unknown): Promise<unknown>;
8
+ }
9
+ interface StandardLinkClient<T extends ClientContext> {
10
+ call(request: StandardRequest, options: ClientOptionsOut<T>, path: readonly string[], input: unknown): Promise<StandardLazyResponse>;
11
+ }
12
+
13
+ declare class InvalidEventIteratorRetryResponse extends Error {
14
+ }
15
+ interface StandardLinkOptions<T extends ClientContext> {
16
+ interceptors?: Interceptor<{
17
+ path: readonly string[];
18
+ input: unknown;
19
+ options: ClientOptionsOut<T>;
20
+ }, unknown, unknown>[];
21
+ clientInterceptors?: Interceptor<{
22
+ request: StandardRequest;
23
+ }, StandardLazyResponse, unknown>[];
24
+ plugins?: ClientPlugin<T>[];
25
+ }
26
+ declare class StandardLink<T extends ClientContext> implements ClientLink<T> {
27
+ #private;
28
+ readonly codec: StandardLinkCodec<T>;
29
+ readonly sender: StandardLinkClient<T>;
30
+ private readonly interceptors;
31
+ private readonly clientInterceptors;
32
+ constructor(codec: StandardLinkCodec<T>, sender: StandardLinkClient<T>, options?: StandardLinkOptions<T>);
33
+ call(path: readonly string[], input: unknown, options: ClientOptionsOut<T>): Promise<unknown>;
34
+ }
35
+
36
+ interface ClientPlugin<T extends ClientContext> {
37
+ init?(options: StandardLinkOptions<T>): void;
38
+ }
39
+ declare class CompositeClientPlugin<T extends ClientContext> implements ClientPlugin<T> {
40
+ private readonly plugins;
41
+ constructor(plugins?: ClientPlugin<T>[]);
42
+ init(options: StandardLinkOptions<T>): void;
43
+ }
44
+
45
+ export { type ClientPlugin as C, InvalidEventIteratorRetryResponse as I, type StandardLinkOptions as S, CompositeClientPlugin as a, type StandardLinkClient as b, type StandardLinkCodec as c, StandardLink as d };
@@ -0,0 +1,45 @@
1
+ import { Interceptor } from '@orpc/shared';
2
+ import { StandardRequest, StandardLazyResponse } from '@orpc/standard-server';
3
+ import { a as ClientContext, C as ClientOptionsOut, b as ClientLink } from './client.CupM8eRP.js';
4
+
5
+ interface StandardLinkCodec<T extends ClientContext> {
6
+ encode(path: readonly string[], input: unknown, options: ClientOptionsOut<any>): Promise<StandardRequest>;
7
+ decode(response: StandardLazyResponse, options: ClientOptionsOut<T>, path: readonly string[], input: unknown): Promise<unknown>;
8
+ }
9
+ interface StandardLinkClient<T extends ClientContext> {
10
+ call(request: StandardRequest, options: ClientOptionsOut<T>, path: readonly string[], input: unknown): Promise<StandardLazyResponse>;
11
+ }
12
+
13
+ declare class InvalidEventIteratorRetryResponse extends Error {
14
+ }
15
+ interface StandardLinkOptions<T extends ClientContext> {
16
+ interceptors?: Interceptor<{
17
+ path: readonly string[];
18
+ input: unknown;
19
+ options: ClientOptionsOut<T>;
20
+ }, unknown, unknown>[];
21
+ clientInterceptors?: Interceptor<{
22
+ request: StandardRequest;
23
+ }, StandardLazyResponse, unknown>[];
24
+ plugins?: ClientPlugin<T>[];
25
+ }
26
+ declare class StandardLink<T extends ClientContext> implements ClientLink<T> {
27
+ #private;
28
+ readonly codec: StandardLinkCodec<T>;
29
+ readonly sender: StandardLinkClient<T>;
30
+ private readonly interceptors;
31
+ private readonly clientInterceptors;
32
+ constructor(codec: StandardLinkCodec<T>, sender: StandardLinkClient<T>, options?: StandardLinkOptions<T>);
33
+ call(path: readonly string[], input: unknown, options: ClientOptionsOut<T>): Promise<unknown>;
34
+ }
35
+
36
+ interface ClientPlugin<T extends ClientContext> {
37
+ init?(options: StandardLinkOptions<T>): void;
38
+ }
39
+ declare class CompositeClientPlugin<T extends ClientContext> implements ClientPlugin<T> {
40
+ private readonly plugins;
41
+ constructor(plugins?: ClientPlugin<T>[]);
42
+ init(options: StandardLinkOptions<T>): void;
43
+ }
44
+
45
+ export { type ClientPlugin as C, InvalidEventIteratorRetryResponse as I, type StandardLinkOptions as S, CompositeClientPlugin as a, type StandardLinkClient as b, type StandardLinkCodec as c, StandardLink as d };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@orpc/client",
3
3
  "type": "module",
4
- "version": "0.0.0-next.e361acd",
4
+ "version": "0.0.0-next.e563486",
5
5
  "license": "MIT",
6
6
  "homepage": "https://orpc.unnoq.com",
7
7
  "repository": {
@@ -15,33 +15,39 @@
15
15
  ],
16
16
  "exports": {
17
17
  ".": {
18
- "types": "./dist/src/index.d.ts",
19
- "import": "./dist/index.js",
20
- "default": "./dist/index.js"
18
+ "types": "./dist/index.d.mts",
19
+ "import": "./dist/index.mjs",
20
+ "default": "./dist/index.mjs"
21
21
  },
22
- "./🔒/*": {
23
- "types": "./dist/src/*.d.ts"
22
+ "./plugins": {
23
+ "types": "./dist/plugins/index.d.mts",
24
+ "import": "./dist/plugins/index.mjs",
25
+ "default": "./dist/plugins/index.mjs"
26
+ },
27
+ "./standard": {
28
+ "types": "./dist/adapters/standard/index.d.mts",
29
+ "import": "./dist/adapters/standard/index.mjs",
30
+ "default": "./dist/adapters/standard/index.mjs"
31
+ },
32
+ "./fetch": {
33
+ "types": "./dist/adapters/fetch/index.d.mts",
34
+ "import": "./dist/adapters/fetch/index.mjs",
35
+ "default": "./dist/adapters/fetch/index.mjs"
24
36
  }
25
37
  },
26
38
  "files": [
27
- "!**/*.map",
28
- "!**/*.tsbuildinfo",
29
39
  "dist"
30
40
  ],
31
- "peerDependencies": {
32
- "@orpc/contract": "0.0.0-next.e361acd",
33
- "@orpc/server": "0.0.0-next.e361acd"
34
- },
35
41
  "dependencies": {
36
- "@orpc/transformer": "0.0.0-next.e361acd",
37
- "@orpc/shared": "0.0.0-next.e361acd"
42
+ "@orpc/shared": "0.0.0-next.e563486",
43
+ "@orpc/standard-server": "0.0.0-next.e563486",
44
+ "@orpc/standard-server-fetch": "0.0.0-next.e563486"
38
45
  },
39
46
  "devDependencies": {
40
- "zod": "^3.24.1",
41
- "@orpc/openapi": "0.0.0-next.e361acd"
47
+ "zod": "^3.24.2"
42
48
  },
43
49
  "scripts": {
44
- "build": "tsup --clean --sourcemap --entry.index=src/index.ts --format=esm --onSuccess='tsc -b --noCheck'",
50
+ "build": "unbuild",
45
51
  "build:watch": "pnpm run build --watch",
46
52
  "type:check": "tsc -b"
47
53
  }
package/dist/index.js DELETED
@@ -1,83 +0,0 @@
1
- // src/procedure-fetch-client.ts
2
- import { ORPC_PROTOCOL_HEADER, ORPC_PROTOCOL_VALUE, trim } from "@orpc/shared";
3
- import { ORPCError } from "@orpc/shared/error";
4
- import { ORPCDeserializer, ORPCSerializer } from "@orpc/transformer";
5
- var serializer = new ORPCSerializer();
6
- var deserializer = new ORPCDeserializer();
7
- function createProcedureFetchClient(options) {
8
- const client = async (...[input, callerOptions]) => {
9
- const fetchClient = options.fetch ?? fetch;
10
- const url = `${trim(options.baseURL, "/")}/${options.path.map(encodeURIComponent).join("/")}`;
11
- const headers = new Headers({
12
- [ORPC_PROTOCOL_HEADER]: ORPC_PROTOCOL_VALUE
13
- });
14
- let customHeaders = await options.headers?.(input);
15
- customHeaders = customHeaders instanceof Headers ? customHeaders : new Headers(customHeaders);
16
- for (const [key, value] of customHeaders.entries()) {
17
- headers.append(key, value);
18
- }
19
- const serialized = serializer.serialize(input);
20
- for (const [key, value] of serialized.headers.entries()) {
21
- headers.append(key, value);
22
- }
23
- const response = await fetchClient(url, {
24
- method: "POST",
25
- headers,
26
- body: serialized.body,
27
- signal: callerOptions?.signal
28
- });
29
- const json = await (async () => {
30
- try {
31
- return await deserializer.deserialize(response);
32
- } catch (e) {
33
- throw new ORPCError({
34
- code: "INTERNAL_SERVER_ERROR",
35
- message: "Cannot parse response.",
36
- cause: e
37
- });
38
- }
39
- })();
40
- if (!response.ok) {
41
- throw ORPCError.fromJSON(json) ?? new ORPCError({
42
- status: response.status,
43
- code: "INTERNAL_SERVER_ERROR",
44
- message: "Internal server error"
45
- });
46
- }
47
- return json;
48
- };
49
- return client;
50
- }
51
-
52
- // src/router-fetch-client.ts
53
- function createRouterFetchClient(options) {
54
- const path = options?.path ?? [];
55
- const client = new Proxy(
56
- createProcedureFetchClient({
57
- ...options,
58
- path
59
- }),
60
- {
61
- get(target, key) {
62
- if (typeof key !== "string") {
63
- return Reflect.get(target, key);
64
- }
65
- return createRouterFetchClient({
66
- ...options,
67
- path: [...path, key]
68
- });
69
- }
70
- }
71
- );
72
- return client;
73
- }
74
-
75
- // src/index.ts
76
- export * from "@orpc/shared/error";
77
- var createORPCFetchClient = createRouterFetchClient;
78
- export {
79
- createORPCFetchClient,
80
- createProcedureFetchClient,
81
- createRouterFetchClient
82
- };
83
- //# sourceMappingURL=index.js.map
@@ -1,7 +0,0 @@
1
- /** unnoq */
2
- import { createRouterFetchClient } from './router-fetch-client';
3
- export * from './procedure-fetch-client';
4
- export * from './router-fetch-client';
5
- export * from '@orpc/shared/error';
6
- export declare const createORPCFetchClient: typeof createRouterFetchClient;
7
- //# sourceMappingURL=index.d.ts.map
@@ -1,24 +0,0 @@
1
- import type { ProcedureClient } from '@orpc/server';
2
- import type { Promisable } from '@orpc/shared';
3
- export interface CreateProcedureClientOptions {
4
- /**
5
- * The base url of the server.
6
- */
7
- baseURL: string;
8
- /**
9
- * The fetch function used to make the request.
10
- * @default global fetch
11
- */
12
- fetch?: typeof fetch;
13
- /**
14
- * The headers used to make the request.
15
- * Invoked before the request is made.
16
- */
17
- headers?: (input: unknown) => Promisable<Headers | Record<string, string>>;
18
- /**
19
- * The path of the procedure on server.
20
- */
21
- path: string[];
22
- }
23
- export declare function createProcedureFetchClient<TInput, TOutput>(options: CreateProcedureClientOptions): ProcedureClient<TInput, TOutput>;
24
- //# sourceMappingURL=procedure-fetch-client.d.ts.map