@orpc/server 0.0.0-next.5d3da98 → 0.0.0-next.649534d

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/dist/fetch.js CHANGED
@@ -148,9 +148,24 @@ function deserialize({
148
148
 
149
149
  // src/fetch/orpc-payload-codec.ts
150
150
  var ORPCPayloadCodec = class {
151
- encode(payload) {
151
+ /**
152
+ * If method is GET, the payload will be encoded as query string.
153
+ * If method is GET and payload contain file, the method will be fallback to fallbackMethod. (fallbackMethod = GET will force to use GET method)
154
+ */
155
+ encode(payload, method = "POST", fallbackMethod = "POST") {
152
156
  const { data, meta } = serialize(payload);
153
157
  const { maps, values } = findDeepMatches((v) => v instanceof Blob, data);
158
+ if (method === "GET" && (values.length === 0 || fallbackMethod === "GET")) {
159
+ const query = new URLSearchParams({
160
+ data: JSON.stringify(data),
161
+ meta: JSON.stringify(meta)
162
+ });
163
+ return {
164
+ query,
165
+ method: "GET"
166
+ };
167
+ }
168
+ const nonGETMethod = method === "GET" ? fallbackMethod : method;
154
169
  if (values.length > 0) {
155
170
  const form = new FormData();
156
171
  if (data !== void 0) {
@@ -162,17 +177,31 @@ var ORPCPayloadCodec = class {
162
177
  const value = values[i];
163
178
  form.append(i, value);
164
179
  }
165
- return { body: form };
180
+ return {
181
+ body: form,
182
+ method: nonGETMethod
183
+ };
166
184
  }
167
185
  return {
168
186
  body: JSON.stringify({ data, meta }),
169
187
  headers: new Headers({
170
188
  "content-type": "application/json"
171
- })
189
+ }),
190
+ method: nonGETMethod
172
191
  };
173
192
  }
174
193
  async decode(re) {
175
194
  try {
195
+ if ("method" in re && re.method === "GET") {
196
+ const url = new URL(re.url);
197
+ const query = url.searchParams;
198
+ const data = JSON.parse(query.getAll("data").at(-1));
199
+ const meta = JSON.parse(query.getAll("meta").at(-1));
200
+ return deserialize({
201
+ data,
202
+ meta
203
+ });
204
+ }
176
205
  if (re.headers.get("content-type")?.startsWith("multipart/form-data")) {
177
206
  const form = await re.formData();
178
207
  const rawData = form.get("data");
@@ -1,7 +1,14 @@
1
+ import type { HTTPMethod } from '@orpc/contract';
1
2
  export declare class ORPCPayloadCodec {
2
- encode(payload: unknown): {
3
- body: FormData | string;
3
+ /**
4
+ * If method is GET, the payload will be encoded as query string.
5
+ * If method is GET and payload contain file, the method will be fallback to fallbackMethod. (fallbackMethod = GET will force to use GET method)
6
+ */
7
+ encode(payload: unknown, method?: HTTPMethod, fallbackMethod?: HTTPMethod): {
8
+ query?: URLSearchParams;
9
+ body?: FormData | string;
4
10
  headers?: Headers;
11
+ method: HTTPMethod;
5
12
  };
6
13
  decode(re: Request | Response): Promise<unknown>;
7
14
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@orpc/server",
3
3
  "type": "module",
4
- "version": "0.0.0-next.5d3da98",
4
+ "version": "0.0.0-next.649534d",
5
5
  "license": "MIT",
6
6
  "homepage": "https://orpc.unnoq.com",
7
7
  "repository": {
@@ -34,8 +34,8 @@
34
34
  "dist"
35
35
  ],
36
36
  "dependencies": {
37
- "@orpc/contract": "0.0.0-next.5d3da98",
38
- "@orpc/shared": "0.0.0-next.5d3da98"
37
+ "@orpc/contract": "0.0.0-next.649534d",
38
+ "@orpc/shared": "0.0.0-next.649534d"
39
39
  },
40
40
  "devDependencies": {
41
41
  "zod": "^3.24.1"