@orpc/client 0.0.0-next.84e58e0 → 0.0.0-next.85df466

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 CHANGED
@@ -1,5 +1,5 @@
1
1
  <div align="center">
2
- <image align="center" src="https://orpc.unnoq.com/logo.webp" width=280 />
2
+ <image align="center" src="https://orpc.unnoq.com/logo.webp" width=280 alt="oRPC logo" />
3
3
  </div>
4
4
 
5
5
  <h1></h1>
@@ -1,7 +1,7 @@
1
1
  import { Value } from '@orpc/shared';
2
2
  import { ToFetchBodyOptions } from '@orpc/standard-server-fetch';
3
3
  import { C as ClientContext, a as ClientOptionsOut, E as EventIteratorReconnectOptions, b as ClientLink } from '../../shared/client.D_CzLDyB.mjs';
4
- import { RPCSerializer } from '../../rpc/index.mjs';
4
+ import { RPCSerializer } from '../standard/index.mjs';
5
5
 
6
6
  interface FetchWithContext<TClientContext extends ClientContext> {
7
7
  (url: URL, init: RequestInit, options: ClientOptionsOut<TClientContext>, path: readonly string[], input: unknown): Promise<Response>;
@@ -1,7 +1,7 @@
1
1
  import { Value } from '@orpc/shared';
2
2
  import { ToFetchBodyOptions } from '@orpc/standard-server-fetch';
3
3
  import { C as ClientContext, a as ClientOptionsOut, E as EventIteratorReconnectOptions, b as ClientLink } from '../../shared/client.D_CzLDyB.js';
4
- import { RPCSerializer } from '../../rpc/index.js';
4
+ import { RPCSerializer } from '../standard/index.js';
5
5
 
6
6
  interface FetchWithContext<TClientContext extends ClientContext> {
7
7
  (url: URL, init: RequestInit, options: ClientOptionsOut<TClientContext>, path: readonly string[], input: unknown): Promise<Response>;
@@ -0,0 +1,4 @@
1
+ export { R as RPCJsonSerializer, a as RPCSerializer } from '../../shared/client.DHJ8vRIG.mjs';
2
+ import '@orpc/shared';
3
+ import '@orpc/standard-server';
4
+ import '../../shared/client.Ly4zGQrc.mjs';
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.84e58e0",
4
+ "version": "0.0.0-next.85df466",
5
5
  "license": "MIT",
6
6
  "homepage": "https://orpc.unnoq.com",
7
7
  "repository": {
@@ -19,15 +19,10 @@
19
19
  "import": "./dist/index.mjs",
20
20
  "default": "./dist/index.mjs"
21
21
  },
22
- "./openapi": {
23
- "types": "./dist/openapi/index.d.mts",
24
- "import": "./dist/openapi/index.mjs",
25
- "default": "./dist/openapi/index.mjs"
26
- },
27
- "./rpc": {
28
- "types": "./dist/rpc/index.d.mts",
29
- "import": "./dist/rpc/index.mjs",
30
- "default": "./dist/rpc/index.mjs"
22
+ "./standard": {
23
+ "types": "./dist/adapters/standard/index.d.mts",
24
+ "import": "./dist/adapters/standard/index.mjs",
25
+ "default": "./dist/adapters/standard/index.mjs"
31
26
  },
32
27
  "./fetch": {
33
28
  "types": "./dist/adapters/fetch/index.d.mts",
@@ -39,9 +34,9 @@
39
34
  "dist"
40
35
  ],
41
36
  "dependencies": {
42
- "@orpc/shared": "0.0.0-next.84e58e0",
43
- "@orpc/standard-server": "0.0.0-next.84e58e0",
44
- "@orpc/standard-server-fetch": "0.0.0-next.84e58e0"
37
+ "@orpc/shared": "0.0.0-next.85df466",
38
+ "@orpc/standard-server": "0.0.0-next.85df466",
39
+ "@orpc/standard-server-fetch": "0.0.0-next.85df466"
45
40
  },
46
41
  "devDependencies": {
47
42
  "zod": "^3.24.1"
@@ -1,27 +0,0 @@
1
- import { Segment } from '@orpc/shared';
2
-
3
- type BracketNotationSerialized = [string, unknown][];
4
- declare class BracketNotationSerializer {
5
- serialize(data: unknown, segments?: Segment[], result?: BracketNotationSerialized): BracketNotationSerialized;
6
- deserialize(serialized: BracketNotationSerialized): unknown;
7
- stringifyPath(segments: readonly Segment[]): string;
8
- parsePath(path: string): string[];
9
- }
10
-
11
- type OpenAPIJsonSerialized = [json: unknown, hasBlob: boolean];
12
- declare class OpenAPIJsonSerializer {
13
- serialize(data: unknown, hasBlobRef?: {
14
- value: boolean;
15
- }): OpenAPIJsonSerialized;
16
- }
17
-
18
- declare class OpenAPISerializer {
19
- #private;
20
- private readonly jsonSerializer;
21
- private readonly bracketNotation;
22
- constructor(jsonSerializer?: OpenAPIJsonSerializer, bracketNotation?: BracketNotationSerializer);
23
- serialize(data: unknown): unknown;
24
- deserialize(data: unknown): unknown;
25
- }
26
-
27
- export { type BracketNotationSerialized, BracketNotationSerializer, type OpenAPIJsonSerialized, OpenAPIJsonSerializer, OpenAPISerializer };
@@ -1,27 +0,0 @@
1
- import { Segment } from '@orpc/shared';
2
-
3
- type BracketNotationSerialized = [string, unknown][];
4
- declare class BracketNotationSerializer {
5
- serialize(data: unknown, segments?: Segment[], result?: BracketNotationSerialized): BracketNotationSerialized;
6
- deserialize(serialized: BracketNotationSerialized): unknown;
7
- stringifyPath(segments: readonly Segment[]): string;
8
- parsePath(path: string): string[];
9
- }
10
-
11
- type OpenAPIJsonSerialized = [json: unknown, hasBlob: boolean];
12
- declare class OpenAPIJsonSerializer {
13
- serialize(data: unknown, hasBlobRef?: {
14
- value: boolean;
15
- }): OpenAPIJsonSerialized;
16
- }
17
-
18
- declare class OpenAPISerializer {
19
- #private;
20
- private readonly jsonSerializer;
21
- private readonly bracketNotation;
22
- constructor(jsonSerializer?: OpenAPIJsonSerializer, bracketNotation?: BracketNotationSerializer);
23
- serialize(data: unknown): unknown;
24
- deserialize(data: unknown): unknown;
25
- }
26
-
27
- export { type BracketNotationSerialized, BracketNotationSerializer, type OpenAPIJsonSerialized, OpenAPIJsonSerializer, OpenAPISerializer };
@@ -1,213 +0,0 @@
1
- import { isObject, isAsyncIteratorObject } from '@orpc/shared';
2
- import { ErrorEvent } from '@orpc/standard-server';
3
- import { m as mapEventIterator, t as toORPCError, O as ORPCError } from '../shared/client.Ly4zGQrc.mjs';
4
-
5
- class BracketNotationSerializer {
6
- serialize(data, segments = [], result = []) {
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
- const arrayPushStyles = /* @__PURE__ */ new WeakSet();
22
- const ref = { value: [] };
23
- for (const [path, value] of serialized) {
24
- const segments = this.parsePath(path);
25
- let currentRef = ref;
26
- let nextSegment = "value";
27
- segments.forEach((segment, i) => {
28
- if (!Array.isArray(currentRef[nextSegment]) && !isObject(currentRef[nextSegment])) {
29
- currentRef[nextSegment] = [];
30
- }
31
- if (i !== segments.length - 1) {
32
- if (Array.isArray(currentRef[nextSegment]) && !isValidArrayIndex(segment)) {
33
- currentRef[nextSegment] = { ...currentRef[nextSegment] };
34
- }
35
- } else {
36
- if (Array.isArray(currentRef[nextSegment])) {
37
- if (segment === "") {
38
- if (currentRef[nextSegment].length && !arrayPushStyles.has(currentRef[nextSegment])) {
39
- currentRef[nextSegment] = { ...currentRef[nextSegment] };
40
- }
41
- } else {
42
- if (arrayPushStyles.has(currentRef[nextSegment])) {
43
- currentRef[nextSegment] = { "": currentRef[nextSegment].at(-1) };
44
- } else if (!isValidArrayIndex(segment)) {
45
- currentRef[nextSegment] = { ...currentRef[nextSegment] };
46
- }
47
- }
48
- }
49
- }
50
- currentRef = currentRef[nextSegment];
51
- nextSegment = segment;
52
- });
53
- if (Array.isArray(currentRef)) {
54
- if (nextSegment === "") {
55
- arrayPushStyles.add(currentRef);
56
- currentRef.push(value);
57
- } else {
58
- currentRef[Number(nextSegment)] = value;
59
- }
60
- } else {
61
- currentRef[nextSegment] = value;
62
- }
63
- }
64
- return ref.value;
65
- }
66
- stringifyPath(segments) {
67
- return segments.map((segment) => {
68
- return segment.toString().replace(/[\\[\]]/g, (match) => {
69
- switch (match) {
70
- case "\\":
71
- return "\\\\";
72
- case "[":
73
- return "\\[";
74
- case "]":
75
- return "\\]";
76
- /* v8 ignore next 2 */
77
- default:
78
- return match;
79
- }
80
- });
81
- }).reduce((result, segment, i) => {
82
- if (i === 0) {
83
- return segment;
84
- }
85
- return `${result}[${segment}]`;
86
- }, "");
87
- }
88
- parsePath(path) {
89
- const segments = [];
90
- let inBrackets = false;
91
- let currentSegment = "";
92
- let backslashCount = 0;
93
- for (let i = 0; i < path.length; i++) {
94
- const char = path[i];
95
- const nextChar = path[i + 1];
96
- if (inBrackets && char === "]" && (nextChar === void 0 || nextChar === "[") && backslashCount % 2 === 0) {
97
- if (nextChar === void 0) {
98
- inBrackets = false;
99
- }
100
- segments.push(currentSegment);
101
- currentSegment = "";
102
- i++;
103
- } else if (segments.length === 0 && char === "[" && backslashCount % 2 === 0) {
104
- inBrackets = true;
105
- segments.push(currentSegment);
106
- currentSegment = "";
107
- } else if (char === "\\") {
108
- backslashCount++;
109
- } else {
110
- currentSegment += "\\".repeat(backslashCount / 2) + char;
111
- backslashCount = 0;
112
- }
113
- }
114
- return inBrackets || segments.length === 0 ? [path] : segments;
115
- }
116
- }
117
- function isValidArrayIndex(value) {
118
- return /^0$|^[1-9]\d*$/.test(value);
119
- }
120
-
121
- class OpenAPIJsonSerializer {
122
- serialize(data, hasBlobRef = { value: false }) {
123
- if (data instanceof Blob) {
124
- hasBlobRef.value = true;
125
- return [data, hasBlobRef.value];
126
- }
127
- if (data instanceof Set) {
128
- return this.serialize(Array.from(data), hasBlobRef);
129
- }
130
- if (data instanceof Map) {
131
- return this.serialize(Array.from(data.entries()), hasBlobRef);
132
- }
133
- if (Array.isArray(data)) {
134
- const json = data.map((v) => v === void 0 ? null : this.serialize(v, hasBlobRef)[0]);
135
- return [json, hasBlobRef.value];
136
- }
137
- if (isObject(data)) {
138
- const json = {};
139
- for (const k in data) {
140
- json[k] = this.serialize(data[k], hasBlobRef)[0];
141
- }
142
- return [json, hasBlobRef.value];
143
- }
144
- if (typeof data === "bigint" || data instanceof RegExp || data instanceof URL) {
145
- return [data.toString(), hasBlobRef.value];
146
- }
147
- if (data instanceof Date) {
148
- return [Number.isNaN(data.getTime()) ? null : data.toISOString(), hasBlobRef.value];
149
- }
150
- if (Number.isNaN(data)) {
151
- return [null, hasBlobRef.value];
152
- }
153
- return [data, hasBlobRef.value];
154
- }
155
- }
156
-
157
- class OpenAPISerializer {
158
- constructor(jsonSerializer = new OpenAPIJsonSerializer(), bracketNotation = new BracketNotationSerializer()) {
159
- this.jsonSerializer = jsonSerializer;
160
- this.bracketNotation = bracketNotation;
161
- }
162
- serialize(data) {
163
- if (isAsyncIteratorObject(data)) {
164
- return mapEventIterator(data, {
165
- value: async (value) => this.#serialize(value, false),
166
- error: async (e) => {
167
- return new ErrorEvent({
168
- data: this.#serialize(toORPCError(e).toJSON(), false),
169
- cause: e
170
- });
171
- }
172
- });
173
- }
174
- return this.#serialize(data, true);
175
- }
176
- #serialize(data, enableFormData) {
177
- if (data instanceof Blob || data === void 0) {
178
- return data;
179
- }
180
- const [json, hasBlob] = this.jsonSerializer.serialize(data);
181
- if (!enableFormData || !hasBlob) {
182
- return json;
183
- }
184
- const form = new FormData();
185
- for (const [path, value] of this.bracketNotation.serialize(json)) {
186
- if (typeof value === "string" || typeof value === "number" || typeof value === "boolean") {
187
- form.append(path, value.toString());
188
- } else if (value instanceof Blob) {
189
- form.append(path, value);
190
- }
191
- }
192
- return form;
193
- }
194
- deserialize(data) {
195
- if (data instanceof URLSearchParams || data instanceof FormData) {
196
- return this.bracketNotation.deserialize(Array.from(data.entries()));
197
- }
198
- if (isAsyncIteratorObject(data)) {
199
- return mapEventIterator(data, {
200
- value: async (value) => value,
201
- error: async (e) => {
202
- if (e instanceof ErrorEvent && ORPCError.isValidJSON(e.data)) {
203
- return ORPCError.fromJSON(e.data, { cause: e });
204
- }
205
- return e;
206
- }
207
- });
208
- }
209
- return data;
210
- }
211
- }
212
-
213
- export { BracketNotationSerializer, OpenAPIJsonSerializer, OpenAPISerializer };
@@ -1,4 +0,0 @@
1
- export { R as RPCJsonSerializer, a as RPCSerializer } from '../shared/client.DHJ8vRIG.mjs';
2
- import '@orpc/shared';
3
- import '@orpc/standard-server';
4
- import '../shared/client.Ly4zGQrc.mjs';
File without changes
File without changes