@orpc/client 0.17.0 → 0.19.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. package/dist/index.js +8 -13
  2. package/package.json +5 -6
package/dist/index.js CHANGED
@@ -1,34 +1,29 @@
1
1
  // src/procedure-fetch-client.ts
2
- import { ORPC_PROTOCOL_HEADER, ORPC_PROTOCOL_VALUE, trim } from "@orpc/shared";
2
+ import { ORPCPayloadCodec } from "@orpc/server/fetch";
3
+ import { ORPC_HANDLER_HEADER, ORPC_HANDLER_VALUE, trim } from "@orpc/shared";
3
4
  import { ORPCError } from "@orpc/shared/error";
4
- import { ORPCDeserializer, ORPCSerializer } from "@orpc/transformer";
5
- var serializer = new ORPCSerializer();
6
- var deserializer = new ORPCDeserializer();
5
+ var payloadCodec = new ORPCPayloadCodec();
7
6
  function createProcedureFetchClient(options) {
8
7
  const client = async (...[input, callerOptions]) => {
9
8
  const fetchClient = options.fetch ?? fetch;
10
9
  const url = `${trim(options.baseURL, "/")}/${options.path.map(encodeURIComponent).join("/")}`;
11
- const headers = new Headers({
12
- [ORPC_PROTOCOL_HEADER]: ORPC_PROTOCOL_VALUE
13
- });
10
+ const encoded = payloadCodec.encode(input);
11
+ const headers = new Headers(encoded.headers);
12
+ headers.append(ORPC_HANDLER_HEADER, ORPC_HANDLER_VALUE);
14
13
  let customHeaders = await options.headers?.(input);
15
14
  customHeaders = customHeaders instanceof Headers ? customHeaders : new Headers(customHeaders);
16
15
  for (const [key, value] of customHeaders.entries()) {
17
16
  headers.append(key, value);
18
17
  }
19
- const serialized = serializer.serialize(input);
20
- for (const [key, value] of serialized.headers.entries()) {
21
- headers.append(key, value);
22
- }
23
18
  const response = await fetchClient(url, {
24
19
  method: "POST",
25
20
  headers,
26
- body: serialized.body,
21
+ body: encoded.body,
27
22
  signal: callerOptions?.signal
28
23
  });
29
24
  const json = await (async () => {
30
25
  try {
31
- return await deserializer.deserialize(response);
26
+ return await payloadCodec.decode(response);
32
27
  } catch (e) {
33
28
  throw new ORPCError({
34
29
  code: "INTERNAL_SERVER_ERROR",
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@orpc/client",
3
3
  "type": "module",
4
- "version": "0.17.0",
4
+ "version": "0.19.0",
5
5
  "license": "MIT",
6
6
  "homepage": "https://orpc.unnoq.com",
7
7
  "repository": {
@@ -29,16 +29,15 @@
29
29
  "dist"
30
30
  ],
31
31
  "peerDependencies": {
32
- "@orpc/contract": "0.17.0",
33
- "@orpc/server": "0.17.0"
32
+ "@orpc/contract": "0.19.0"
34
33
  },
35
34
  "dependencies": {
36
- "@orpc/shared": "0.17.0",
37
- "@orpc/transformer": "0.17.0"
35
+ "@orpc/server": "0.19.0",
36
+ "@orpc/shared": "0.19.0"
38
37
  },
39
38
  "devDependencies": {
40
39
  "zod": "^3.24.1",
41
- "@orpc/openapi": "0.17.0"
40
+ "@orpc/openapi": "0.19.0"
42
41
  },
43
42
  "scripts": {
44
43
  "build": "tsup --clean --sourcemap --entry.index=src/index.ts --format=esm --onSuccess='tsc -b --noCheck'",