@orpc/client 0.0.0-next.5559bf8 → 0.0.0-next.56271c2

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 (52) hide show
  1. package/README.md +34 -21
  2. package/dist/adapters/fetch/index.d.mts +46 -0
  3. package/dist/adapters/fetch/index.d.ts +46 -0
  4. package/dist/adapters/fetch/index.mjs +45 -0
  5. package/dist/adapters/message-port/index.d.mts +59 -0
  6. package/dist/adapters/message-port/index.d.ts +59 -0
  7. package/dist/adapters/message-port/index.mjs +72 -0
  8. package/dist/adapters/standard/index.d.mts +11 -0
  9. package/dist/adapters/standard/index.d.ts +11 -0
  10. package/dist/adapters/standard/index.mjs +5 -0
  11. package/dist/adapters/websocket/index.d.mts +29 -0
  12. package/dist/adapters/websocket/index.d.ts +29 -0
  13. package/dist/adapters/websocket/index.mjs +46 -0
  14. package/dist/index.d.mts +230 -0
  15. package/dist/index.d.ts +230 -0
  16. package/dist/index.mjs +111 -0
  17. package/dist/plugins/index.d.mts +203 -0
  18. package/dist/plugins/index.d.ts +203 -0
  19. package/dist/plugins/index.mjs +407 -0
  20. package/dist/shared/client.-ulyYbDX.mjs +208 -0
  21. package/dist/shared/client.BH1AYT_p.d.mts +83 -0
  22. package/dist/shared/client.BH1AYT_p.d.ts +83 -0
  23. package/dist/shared/client.BxV-mzeR.d.ts +91 -0
  24. package/dist/shared/client.CIFoKgmJ.mjs +397 -0
  25. package/dist/shared/client.CPgZaUox.d.mts +45 -0
  26. package/dist/shared/client.D8lMmWVC.d.mts +91 -0
  27. package/dist/shared/client.De8SW4Kw.d.ts +45 -0
  28. package/package.json +30 -24
  29. package/dist/chunk-4FUUNP74.js +0 -212
  30. package/dist/chunk-OGAGXWCU.js +0 -281
  31. package/dist/fetch.js +0 -128
  32. package/dist/index.js +0 -81
  33. package/dist/openapi.js +0 -231
  34. package/dist/rpc.js +0 -10
  35. package/dist/src/adapters/fetch/index.d.ts +0 -3
  36. package/dist/src/adapters/fetch/rpc-link.d.ts +0 -98
  37. package/dist/src/adapters/fetch/types.d.ts +0 -5
  38. package/dist/src/client.d.ts +0 -9
  39. package/dist/src/dynamic-link.d.ts +0 -12
  40. package/dist/src/error.d.ts +0 -106
  41. package/dist/src/event-iterator-state.d.ts +0 -9
  42. package/dist/src/event-iterator.d.ts +0 -12
  43. package/dist/src/index.d.ts +0 -9
  44. package/dist/src/openapi/bracket-notation.d.ts +0 -9
  45. package/dist/src/openapi/index.d.ts +0 -4
  46. package/dist/src/openapi/json-serializer.d.ts +0 -7
  47. package/dist/src/openapi/serializer.d.ts +0 -11
  48. package/dist/src/rpc/index.d.ts +0 -3
  49. package/dist/src/rpc/json-serializer.d.ts +0 -12
  50. package/dist/src/rpc/serializer.d.ts +0 -9
  51. package/dist/src/types.d.ts +0 -29
  52. package/dist/src/utils.d.ts +0 -5
@@ -0,0 +1,91 @@
1
+ import { b as ClientContext, c as ClientOptions, f as HTTPMethod } from './client.BH1AYT_p.mjs';
2
+ import { e as StandardLinkCodec, b as StandardLinkOptions, d as StandardLink, f as StandardLinkClient } from './client.CPgZaUox.mjs';
3
+ import { Segment, Value, Promisable } from '@orpc/shared';
4
+ import { StandardHeaders, StandardRequest, StandardLazyResponse } from '@orpc/standard-server';
5
+
6
+ declare const STANDARD_RPC_JSON_SERIALIZER_BUILT_IN_TYPES: {
7
+ readonly BIGINT: 0;
8
+ readonly DATE: 1;
9
+ readonly NAN: 2;
10
+ readonly UNDEFINED: 3;
11
+ readonly URL: 4;
12
+ readonly REGEXP: 5;
13
+ readonly SET: 6;
14
+ readonly MAP: 7;
15
+ };
16
+ type StandardRPCJsonSerializedMetaItem = readonly [type: number, ...path: Segment[]];
17
+ type StandardRPCJsonSerialized = [json: unknown, meta: StandardRPCJsonSerializedMetaItem[], maps: Segment[][], blobs: Blob[]];
18
+ interface StandardRPCCustomJsonSerializer {
19
+ type: number;
20
+ condition(data: unknown): boolean;
21
+ serialize(data: any): unknown;
22
+ deserialize(serialized: any): unknown;
23
+ }
24
+ interface StandardRPCJsonSerializerOptions {
25
+ customJsonSerializers?: readonly StandardRPCCustomJsonSerializer[];
26
+ }
27
+ declare class StandardRPCJsonSerializer {
28
+ private readonly customSerializers;
29
+ constructor(options?: StandardRPCJsonSerializerOptions);
30
+ serialize(data: unknown, segments?: Segment[], meta?: StandardRPCJsonSerializedMetaItem[], maps?: Segment[][], blobs?: Blob[]): StandardRPCJsonSerialized;
31
+ deserialize(json: unknown, meta: readonly StandardRPCJsonSerializedMetaItem[]): unknown;
32
+ deserialize(json: unknown, meta: readonly StandardRPCJsonSerializedMetaItem[], maps: readonly Segment[][], getBlob: (index: number) => Blob): unknown;
33
+ }
34
+
35
+ declare class StandardRPCSerializer {
36
+ #private;
37
+ private readonly jsonSerializer;
38
+ constructor(jsonSerializer: StandardRPCJsonSerializer);
39
+ serialize(data: unknown): object;
40
+ deserialize(data: unknown): unknown;
41
+ }
42
+
43
+ interface StandardRPCLinkCodecOptions<T extends ClientContext> {
44
+ /**
45
+ * Base url for all requests.
46
+ */
47
+ url: Value<Promisable<string | URL>, [options: ClientOptions<T>, path: readonly string[], input: unknown]>;
48
+ /**
49
+ * The maximum length of the URL.
50
+ *
51
+ * @default 2083
52
+ */
53
+ maxUrlLength?: Value<Promisable<number>, [options: ClientOptions<T>, path: readonly string[], input: unknown]>;
54
+ /**
55
+ * The method used to make the request.
56
+ *
57
+ * @default 'POST'
58
+ */
59
+ method?: Value<Promisable<Exclude<HTTPMethod, 'HEAD'>>, [options: ClientOptions<T>, path: readonly string[], input: unknown]>;
60
+ /**
61
+ * The method to use when the payload cannot safely pass to the server with method return from method function.
62
+ * GET is not allowed, it's very dangerous.
63
+ *
64
+ * @default 'POST'
65
+ */
66
+ fallbackMethod?: Exclude<HTTPMethod, 'HEAD' | 'GET'>;
67
+ /**
68
+ * Inject headers to the request.
69
+ */
70
+ headers?: Value<Promisable<StandardHeaders | Headers>, [options: ClientOptions<T>, path: readonly string[], input: unknown]>;
71
+ }
72
+ declare class StandardRPCLinkCodec<T extends ClientContext> implements StandardLinkCodec<T> {
73
+ private readonly serializer;
74
+ private readonly baseUrl;
75
+ private readonly maxUrlLength;
76
+ private readonly fallbackMethod;
77
+ private readonly expectedMethod;
78
+ private readonly headers;
79
+ constructor(serializer: StandardRPCSerializer, options: StandardRPCLinkCodecOptions<T>);
80
+ encode(path: readonly string[], input: unknown, options: ClientOptions<T>): Promise<StandardRequest>;
81
+ decode(response: StandardLazyResponse): Promise<unknown>;
82
+ }
83
+
84
+ interface StandardRPCLinkOptions<T extends ClientContext> extends StandardLinkOptions<T>, StandardRPCLinkCodecOptions<T>, StandardRPCJsonSerializerOptions {
85
+ }
86
+ declare class StandardRPCLink<T extends ClientContext> extends StandardLink<T> {
87
+ constructor(linkClient: StandardLinkClient<T>, options: StandardRPCLinkOptions<T>);
88
+ }
89
+
90
+ export { STANDARD_RPC_JSON_SERIALIZER_BUILT_IN_TYPES as S, StandardRPCJsonSerializer as e, StandardRPCLink as g, StandardRPCLinkCodec as i, StandardRPCSerializer as j };
91
+ export type { StandardRPCJsonSerializedMetaItem as a, StandardRPCJsonSerialized as b, StandardRPCCustomJsonSerializer as c, StandardRPCJsonSerializerOptions as d, StandardRPCLinkOptions as f, StandardRPCLinkCodecOptions as h };
@@ -0,0 +1,45 @@
1
+ import { Interceptor } from '@orpc/shared';
2
+ import { StandardRequest, StandardLazyResponse } from '@orpc/standard-server';
3
+ import { b as ClientContext, c as ClientOptions, C as ClientLink } from './client.BH1AYT_p.js';
4
+
5
+ interface StandardLinkPlugin<T extends ClientContext> {
6
+ order?: number;
7
+ init?(options: StandardLinkOptions<T>): void;
8
+ }
9
+ declare class CompositeStandardLinkPlugin<T extends ClientContext, TPlugin extends StandardLinkPlugin<T>> implements StandardLinkPlugin<T> {
10
+ protected readonly plugins: TPlugin[];
11
+ constructor(plugins?: readonly TPlugin[]);
12
+ init(options: StandardLinkOptions<T>): void;
13
+ }
14
+
15
+ interface StandardLinkCodec<T extends ClientContext> {
16
+ encode(path: readonly string[], input: unknown, options: ClientOptions<T>): Promise<StandardRequest>;
17
+ decode(response: StandardLazyResponse, options: ClientOptions<T>, path: readonly string[], input: unknown): Promise<unknown>;
18
+ }
19
+ interface StandardLinkClient<T extends ClientContext> {
20
+ call(request: StandardRequest, options: ClientOptions<T>, path: readonly string[], input: unknown): Promise<StandardLazyResponse>;
21
+ }
22
+
23
+ interface StandardLinkInterceptorOptions<T extends ClientContext> extends ClientOptions<T> {
24
+ path: readonly string[];
25
+ input: unknown;
26
+ }
27
+ interface StandardLinkClientInterceptorOptions<T extends ClientContext> extends StandardLinkInterceptorOptions<T> {
28
+ request: StandardRequest;
29
+ }
30
+ interface StandardLinkOptions<T extends ClientContext> {
31
+ interceptors?: Interceptor<StandardLinkInterceptorOptions<T>, Promise<unknown>>[];
32
+ clientInterceptors?: Interceptor<StandardLinkClientInterceptorOptions<T>, Promise<StandardLazyResponse>>[];
33
+ plugins?: StandardLinkPlugin<T>[];
34
+ }
35
+ declare class StandardLink<T extends ClientContext> implements ClientLink<T> {
36
+ readonly codec: StandardLinkCodec<T>;
37
+ readonly sender: StandardLinkClient<T>;
38
+ private readonly interceptors;
39
+ private readonly clientInterceptors;
40
+ constructor(codec: StandardLinkCodec<T>, sender: StandardLinkClient<T>, options?: StandardLinkOptions<T>);
41
+ call(path: readonly string[], input: unknown, options: ClientOptions<T>): Promise<unknown>;
42
+ }
43
+
44
+ export { CompositeStandardLinkPlugin as C, StandardLink as d };
45
+ export type { StandardLinkClientInterceptorOptions as S, StandardLinkPlugin as a, StandardLinkOptions as b, StandardLinkInterceptorOptions as c, StandardLinkCodec as e, StandardLinkClient as f };
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.5559bf8",
4
+ "version": "0.0.0-next.56271c2",
5
5
  "license": "MIT",
6
6
  "homepage": "https://orpc.unnoq.com",
7
7
  "repository": {
@@ -15,44 +15,50 @@
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
- "./openapi": {
23
- "types": "./dist/src/openapi/index.d.ts",
24
- "import": "./dist/openapi.js",
25
- "default": "./dist/openapi.js"
22
+ "./plugins": {
23
+ "types": "./dist/plugins/index.d.mts",
24
+ "import": "./dist/plugins/index.mjs",
25
+ "default": "./dist/plugins/index.mjs"
26
26
  },
27
- "./rpc": {
28
- "types": "./dist/src/rpc/index.d.ts",
29
- "import": "./dist/rpc.js",
30
- "default": "./dist/rpc.js"
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
31
  },
32
32
  "./fetch": {
33
- "types": "./dist/src/adapters/fetch/index.d.ts",
34
- "import": "./dist/fetch.js",
35
- "default": "./dist/fetch.js"
33
+ "types": "./dist/adapters/fetch/index.d.mts",
34
+ "import": "./dist/adapters/fetch/index.mjs",
35
+ "default": "./dist/adapters/fetch/index.mjs"
36
36
  },
37
- "./🔒/*": {
38
- "types": "./dist/src/*.d.ts"
37
+ "./websocket": {
38
+ "types": "./dist/adapters/websocket/index.d.mts",
39
+ "import": "./dist/adapters/websocket/index.mjs",
40
+ "default": "./dist/adapters/websocket/index.mjs"
41
+ },
42
+ "./message-port": {
43
+ "types": "./dist/adapters/message-port/index.d.mts",
44
+ "import": "./dist/adapters/message-port/index.mjs",
45
+ "default": "./dist/adapters/message-port/index.mjs"
39
46
  }
40
47
  },
41
48
  "files": [
42
- "!**/*.map",
43
- "!**/*.tsbuildinfo",
44
49
  "dist"
45
50
  ],
46
51
  "dependencies": {
47
- "@orpc/server-standard": "^0.4.0",
48
- "@orpc/server-standard-fetch": "^0.4.0",
49
- "@orpc/shared": "0.0.0-next.5559bf8"
52
+ "@orpc/shared": "0.0.0-next.56271c2",
53
+ "@orpc/standard-server": "0.0.0-next.56271c2",
54
+ "@orpc/standard-server-fetch": "0.0.0-next.56271c2",
55
+ "@orpc/standard-server-peer": "0.0.0-next.56271c2"
50
56
  },
51
57
  "devDependencies": {
52
- "zod": "^3.24.1"
58
+ "zod": "^4.1.12"
53
59
  },
54
60
  "scripts": {
55
- "build": "tsup --onSuccess='tsc -b --noCheck'",
61
+ "build": "unbuild",
56
62
  "build:watch": "pnpm run build --watch",
57
63
  "type:check": "tsc -b"
58
64
  }
@@ -1,212 +0,0 @@
1
- import {
2
- ORPCError,
3
- mapEventIterator,
4
- toORPCError
5
- } from "./chunk-OGAGXWCU.js";
6
-
7
- // src/rpc/json-serializer.ts
8
- import { isObject } from "@orpc/shared";
9
- var RPCJsonSerializer = class {
10
- serialize(data, segments = [], meta = [], maps = [], blobs = []) {
11
- if (data instanceof Blob) {
12
- maps.push(segments);
13
- blobs.push(data);
14
- return [data, meta, maps, blobs];
15
- }
16
- if (typeof data === "bigint") {
17
- meta.push([0, segments]);
18
- return [data.toString(), meta, maps, blobs];
19
- }
20
- if (data instanceof Date) {
21
- meta.push([1, segments]);
22
- if (Number.isNaN(data.getTime())) {
23
- return [null, meta, maps, blobs];
24
- }
25
- return [data.toISOString(), meta, maps, blobs];
26
- }
27
- if (Number.isNaN(data)) {
28
- meta.push([2, segments]);
29
- return [null, meta, maps, blobs];
30
- }
31
- if (data instanceof URL) {
32
- meta.push([4, segments]);
33
- return [data.toString(), meta, maps, blobs];
34
- }
35
- if (data instanceof RegExp) {
36
- meta.push([5, segments]);
37
- return [data.toString(), meta, maps, blobs];
38
- }
39
- if (data instanceof Set) {
40
- const result = this.serialize(Array.from(data), segments, meta, maps, blobs);
41
- meta.push([6, segments]);
42
- return result;
43
- }
44
- if (data instanceof Map) {
45
- const result = this.serialize(Array.from(data.entries()), segments, meta, maps, blobs);
46
- meta.push([7, segments]);
47
- return result;
48
- }
49
- if (Array.isArray(data)) {
50
- const json = data.map((v, i) => {
51
- if (v === void 0) {
52
- meta.push([3, [...segments, i]]);
53
- return v;
54
- }
55
- return this.serialize(v, [...segments, i], meta, maps, blobs)[0];
56
- });
57
- return [json, meta, maps, blobs];
58
- }
59
- if (isObject(data)) {
60
- const json = {};
61
- for (const k in data) {
62
- json[k] = this.serialize(data[k], [...segments, k], meta, maps, blobs)[0];
63
- }
64
- return [json, meta, maps, blobs];
65
- }
66
- return [data, meta, maps, blobs];
67
- }
68
- deserialize(json, meta, maps, getBlob) {
69
- const ref = { data: json };
70
- if (maps && getBlob) {
71
- maps.forEach((segments, i) => {
72
- let currentRef = ref;
73
- let preSegment = "data";
74
- segments.forEach((segment) => {
75
- currentRef = currentRef[preSegment];
76
- preSegment = segment;
77
- });
78
- currentRef[preSegment] = getBlob(i);
79
- });
80
- }
81
- for (const [type, segments] of meta) {
82
- let currentRef = ref;
83
- let preSegment = "data";
84
- segments.forEach((segment) => {
85
- currentRef = currentRef[preSegment];
86
- preSegment = segment;
87
- });
88
- switch (type) {
89
- case 0:
90
- currentRef[preSegment] = BigInt(currentRef[preSegment]);
91
- break;
92
- case 1:
93
- currentRef[preSegment] = new Date(currentRef[preSegment] ?? "Invalid Date");
94
- break;
95
- case 2:
96
- currentRef[preSegment] = Number.NaN;
97
- break;
98
- case 3:
99
- currentRef[preSegment] = void 0;
100
- break;
101
- case 4:
102
- currentRef[preSegment] = new URL(currentRef[preSegment]);
103
- break;
104
- case 5: {
105
- const [, pattern, flags] = currentRef[preSegment].match(/^\/(.*)\/([a-z]*)$/);
106
- currentRef[preSegment] = new RegExp(pattern, flags);
107
- break;
108
- }
109
- case 6:
110
- currentRef[preSegment] = new Set(currentRef[preSegment]);
111
- break;
112
- case 7:
113
- currentRef[preSegment] = new Map(currentRef[preSegment]);
114
- break;
115
- /* v8 ignore next 3 */
116
- default: {
117
- const _expected = type;
118
- }
119
- }
120
- }
121
- return ref.data;
122
- }
123
- };
124
-
125
- // src/rpc/serializer.ts
126
- import { ErrorEvent, isAsyncIteratorObject } from "@orpc/server-standard";
127
- var RPCSerializer = class {
128
- constructor(jsonSerializer = new RPCJsonSerializer()) {
129
- this.jsonSerializer = jsonSerializer;
130
- }
131
- serialize(data) {
132
- if (isAsyncIteratorObject(data)) {
133
- return mapEventIterator(data, {
134
- value: async (value) => this.#serialize(value, false),
135
- error: async (e) => {
136
- if (e instanceof ErrorEvent) {
137
- return new ErrorEvent({
138
- data: this.#serialize(e.data, false),
139
- cause: e
140
- });
141
- }
142
- return new ErrorEvent({
143
- data: this.#serialize(toORPCError(e).toJSON(), false),
144
- cause: e
145
- });
146
- }
147
- });
148
- }
149
- return this.#serialize(data, true);
150
- }
151
- #serialize(data, enableFormData) {
152
- if (data === void 0 || data instanceof Blob) {
153
- return data;
154
- }
155
- const [json, meta_, maps, blobs] = this.jsonSerializer.serialize(data);
156
- const meta = meta_.length === 0 ? void 0 : meta_;
157
- if (!enableFormData || blobs.length === 0) {
158
- return {
159
- json,
160
- meta
161
- };
162
- }
163
- const form = new FormData();
164
- form.set("data", JSON.stringify({ json, meta, maps }));
165
- blobs.forEach((blob, i) => {
166
- form.set(i.toString(), blob);
167
- });
168
- return form;
169
- }
170
- deserialize(data) {
171
- if (isAsyncIteratorObject(data)) {
172
- return mapEventIterator(data, {
173
- value: async (value) => this.#deserialize(value),
174
- error: async (e) => {
175
- if (!(e instanceof ErrorEvent)) {
176
- return e;
177
- }
178
- const deserialized = this.#deserialize(e.data);
179
- if (ORPCError.isValidJSON(deserialized)) {
180
- return ORPCError.fromJSON(deserialized, { cause: e });
181
- }
182
- return new ErrorEvent({
183
- data: deserialized,
184
- cause: e
185
- });
186
- }
187
- });
188
- }
189
- return this.#deserialize(data);
190
- }
191
- #deserialize(data) {
192
- if (data === void 0 || data instanceof Blob) {
193
- return data;
194
- }
195
- if (!(data instanceof FormData)) {
196
- return this.jsonSerializer.deserialize(data.json, data.meta ?? []);
197
- }
198
- const serialized = JSON.parse(data.get("data"));
199
- return this.jsonSerializer.deserialize(
200
- serialized.json,
201
- serialized.meta ?? [],
202
- serialized.maps,
203
- (i) => data.get(i.toString())
204
- );
205
- }
206
- };
207
-
208
- export {
209
- RPCJsonSerializer,
210
- RPCSerializer
211
- };
212
- //# sourceMappingURL=chunk-4FUUNP74.js.map