@orpc/contract 0.0.0-next.f50512c → 0.0.0-next.f5149a8

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,53 @@
1
+ import { fallbackORPCErrorStatus, ORPCError, isORPCErrorStatus } from '@orpc/client';
2
+
3
+ class ValidationError extends Error {
4
+ issues;
5
+ data;
6
+ constructor(options) {
7
+ super(options.message, options);
8
+ this.issues = options.issues;
9
+ this.data = options.data;
10
+ }
11
+ }
12
+ function mergeErrorMap(errorMap1, errorMap2) {
13
+ return { ...errorMap1, ...errorMap2 };
14
+ }
15
+ async function validateORPCError(map, error) {
16
+ const { code, status, message, data, cause, defined } = error;
17
+ const config = map?.[error.code];
18
+ if (!config || fallbackORPCErrorStatus(error.code, config.status) !== error.status) {
19
+ return defined ? new ORPCError(code, { defined: false, status, message, data, cause }) : error;
20
+ }
21
+ if (!config.data) {
22
+ return defined ? error : new ORPCError(code, { defined: true, status, message, data, cause });
23
+ }
24
+ const validated = await config.data["~standard"].validate(error.data);
25
+ if (validated.issues) {
26
+ return defined ? new ORPCError(code, { defined: false, status, message, data, cause }) : error;
27
+ }
28
+ return new ORPCError(code, { defined: true, status, message, data: validated.value, cause });
29
+ }
30
+
31
+ class ContractProcedure {
32
+ /**
33
+ * This property holds the defined options for the contract procedure.
34
+ */
35
+ "~orpc";
36
+ constructor(def) {
37
+ if (def.route?.successStatus && isORPCErrorStatus(def.route.successStatus)) {
38
+ throw new Error("[ContractProcedure] Invalid successStatus.");
39
+ }
40
+ if (Object.values(def.errorMap).some((val) => val && val.status && !isORPCErrorStatus(val.status))) {
41
+ throw new Error("[ContractProcedure] Invalid error status code.");
42
+ }
43
+ this["~orpc"] = def;
44
+ }
45
+ }
46
+ function isContractProcedure(item) {
47
+ if (item instanceof ContractProcedure) {
48
+ return true;
49
+ }
50
+ return (typeof item === "object" || typeof item === "function") && item !== null && "~orpc" in item && typeof item["~orpc"] === "object" && item["~orpc"] !== null && "errorMap" in item["~orpc"] && "route" in item["~orpc"] && "meta" in item["~orpc"];
51
+ }
52
+
53
+ export { ContractProcedure as C, ValidationError as V, isContractProcedure as i, mergeErrorMap as m, validateORPCError as v };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@orpc/contract",
3
3
  "type": "module",
4
- "version": "0.0.0-next.f50512c",
4
+ "version": "0.0.0-next.f5149a8",
5
5
  "license": "MIT",
6
6
  "homepage": "https://orpc.unnoq.com",
7
7
  "repository": {
@@ -18,6 +18,11 @@
18
18
  "types": "./dist/index.d.mts",
19
19
  "import": "./dist/index.mjs",
20
20
  "default": "./dist/index.mjs"
21
+ },
22
+ "./plugins": {
23
+ "types": "./dist/plugins/index.d.mts",
24
+ "import": "./dist/plugins/index.mjs",
25
+ "default": "./dist/plugins/index.mjs"
21
26
  }
22
27
  },
23
28
  "files": [
@@ -26,13 +31,13 @@
26
31
  "dependencies": {
27
32
  "@standard-schema/spec": "^1.0.0",
28
33
  "openapi-types": "^12.1.3",
29
- "@orpc/client": "0.0.0-next.f50512c",
30
- "@orpc/shared": "0.0.0-next.f50512c"
34
+ "@orpc/client": "0.0.0-next.f5149a8",
35
+ "@orpc/shared": "0.0.0-next.f5149a8"
31
36
  },
32
37
  "devDependencies": {
33
- "arktype": "2.1.20",
38
+ "arktype": "2.1.25",
34
39
  "valibot": "^1.1.0",
35
- "zod": "^4.0.5"
40
+ "zod": "^4.1.12"
36
41
  },
37
42
  "scripts": {
38
43
  "build": "unbuild",