@alchemy/wallet-apis 5.0.0-beta.28 → 5.0.0-beta.29
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/esm/actions/prepareCalls.d.ts +8 -3
- package/dist/esm/actions/prepareCalls.js +8 -0
- package/dist/esm/actions/prepareCalls.js.map +1 -1
- package/dist/esm/actions/requestAccount.d.ts +4 -3
- package/dist/esm/actions/requestAccount.js.map +1 -1
- package/dist/esm/actions/sendPreparedCalls.d.ts +3 -1
- package/dist/esm/actions/sendPreparedCalls.js.map +1 -1
- package/dist/esm/actions/signPreparedCalls.js +1 -1
- package/dist/esm/actions/signPreparedCalls.js.map +1 -1
- package/dist/esm/actions/signSignatureRequest.d.ts +4 -4
- package/dist/esm/actions/signSignatureRequest.js +1 -1
- package/dist/esm/actions/signSignatureRequest.js.map +1 -1
- package/dist/esm/actions/signTypedData.d.ts +14 -4
- package/dist/esm/actions/signTypedData.js.map +1 -1
- package/dist/esm/actions/solana/getCallsStatus.d.ts +24 -0
- package/dist/esm/actions/solana/getCallsStatus.js +44 -0
- package/dist/esm/actions/solana/getCallsStatus.js.map +1 -0
- package/dist/esm/actions/solana/prepareCalls.d.ts +46 -0
- package/dist/esm/actions/solana/prepareCalls.js +70 -0
- package/dist/esm/actions/solana/prepareCalls.js.map +1 -0
- package/dist/esm/actions/solana/sendCalls.d.ts +34 -0
- package/dist/esm/actions/solana/sendCalls.js +44 -0
- package/dist/esm/actions/solana/sendCalls.js.map +1 -0
- package/dist/esm/actions/solana/sendPreparedCalls.d.ts +24 -0
- package/dist/esm/actions/solana/sendPreparedCalls.js +32 -0
- package/dist/esm/actions/solana/sendPreparedCalls.js.map +1 -0
- package/dist/esm/actions/solana/signPreparedCalls.d.ts +23 -0
- package/dist/esm/actions/solana/signPreparedCalls.js +24 -0
- package/dist/esm/actions/solana/signPreparedCalls.js.map +1 -0
- package/dist/esm/actions/solana/signSignatureRequest.d.ts +10 -0
- package/dist/esm/actions/solana/signSignatureRequest.js +33 -0
- package/dist/esm/actions/solana/signSignatureRequest.js.map +1 -0
- package/dist/esm/actions/solana/waitForCallsStatus.d.ts +24 -0
- package/dist/esm/actions/solana/waitForCallsStatus.js +46 -0
- package/dist/esm/actions/solana/waitForCallsStatus.js.map +1 -0
- package/dist/esm/adapters/SolanaSignerError.d.ts +4 -0
- package/dist/esm/adapters/SolanaSignerError.js +13 -0
- package/dist/esm/adapters/SolanaSignerError.js.map +1 -0
- package/dist/esm/adapters/fromKeypair.d.ts +21 -0
- package/dist/esm/adapters/fromKeypair.js +46 -0
- package/dist/esm/adapters/fromKeypair.js.map +1 -0
- package/dist/esm/adapters/fromKitSigner.d.ts +21 -0
- package/dist/esm/adapters/fromKitSigner.js +61 -0
- package/dist/esm/adapters/fromKitSigner.js.map +1 -0
- package/dist/esm/adapters/fromWalletAdapter.d.ts +26 -0
- package/dist/esm/adapters/fromWalletAdapter.js +45 -0
- package/dist/esm/adapters/fromWalletAdapter.js.map +1 -0
- package/dist/esm/adapters/fromWalletStandard.d.ts +31 -0
- package/dist/esm/adapters/fromWalletStandard.js +53 -0
- package/dist/esm/adapters/fromWalletStandard.js.map +1 -0
- package/dist/esm/adapters/resolveSignerSlot.d.ts +10 -0
- package/dist/esm/adapters/resolveSignerSlot.js +39 -0
- package/dist/esm/adapters/resolveSignerSlot.js.map +1 -0
- package/dist/esm/client.d.ts +29 -14
- package/dist/esm/client.js +63 -19
- package/dist/esm/client.js.map +1 -1
- package/dist/esm/decorators/smartWalletActions.js +2 -2
- package/dist/esm/decorators/smartWalletActions.js.map +1 -1
- package/dist/esm/decorators/solanaSmartWalletActions.d.ts +16 -0
- package/dist/esm/decorators/solanaSmartWalletActions.js +16 -0
- package/dist/esm/decorators/solanaSmartWalletActions.js.map +1 -0
- package/dist/esm/experimental/actions/requestQuoteV0.d.ts +34 -7
- package/dist/esm/experimental/actions/requestQuoteV0.js.map +1 -1
- package/dist/esm/exports/index.d.ts +3 -3
- package/dist/esm/exports/index.js.map +1 -1
- package/dist/esm/exports/solana.d.ts +24 -0
- package/dist/esm/exports/solana.js +15 -0
- package/dist/esm/exports/solana.js.map +1 -0
- package/dist/esm/types.d.ts +28 -4
- package/dist/esm/types.js.map +1 -1
- package/dist/esm/utils/assertions.d.ts +4 -2
- package/dist/esm/utils/assertions.js +6 -0
- package/dist/esm/utils/assertions.js.map +1 -1
- package/dist/esm/utils/capabilities.d.ts +22 -6
- package/dist/esm/utils/capabilities.js +19 -2
- package/dist/esm/utils/capabilities.js.map +1 -1
- package/dist/esm/utils/format.js +1 -1
- package/dist/esm/utils/format.js.map +1 -1
- package/dist/esm/utils/schema.d.ts +14 -14
- package/dist/esm/utils/schema.js +35 -39
- package/dist/esm/utils/schema.js.map +1 -1
- package/dist/esm/version.d.ts +1 -1
- package/dist/esm/version.js +1 -1
- package/dist/esm/version.js.map +1 -1
- package/dist/types/actions/prepareCalls.d.ts +8 -3
- package/dist/types/actions/prepareCalls.d.ts.map +1 -1
- package/dist/types/actions/requestAccount.d.ts +4 -3
- package/dist/types/actions/requestAccount.d.ts.map +1 -1
- package/dist/types/actions/sendPreparedCalls.d.ts +3 -1
- package/dist/types/actions/sendPreparedCalls.d.ts.map +1 -1
- package/dist/types/actions/signSignatureRequest.d.ts +4 -4
- package/dist/types/actions/signSignatureRequest.d.ts.map +1 -1
- package/dist/types/actions/signTypedData.d.ts +14 -4
- package/dist/types/actions/signTypedData.d.ts.map +1 -1
- package/dist/types/actions/solana/getCallsStatus.d.ts +25 -0
- package/dist/types/actions/solana/getCallsStatus.d.ts.map +1 -0
- package/dist/types/actions/solana/prepareCalls.d.ts +47 -0
- package/dist/types/actions/solana/prepareCalls.d.ts.map +1 -0
- package/dist/types/actions/solana/sendCalls.d.ts +35 -0
- package/dist/types/actions/solana/sendCalls.d.ts.map +1 -0
- package/dist/types/actions/solana/sendPreparedCalls.d.ts +25 -0
- package/dist/types/actions/solana/sendPreparedCalls.d.ts.map +1 -0
- package/dist/types/actions/solana/signPreparedCalls.d.ts +24 -0
- package/dist/types/actions/solana/signPreparedCalls.d.ts.map +1 -0
- package/dist/types/actions/solana/signSignatureRequest.d.ts +11 -0
- package/dist/types/actions/solana/signSignatureRequest.d.ts.map +1 -0
- package/dist/types/actions/solana/waitForCallsStatus.d.ts +25 -0
- package/dist/types/actions/solana/waitForCallsStatus.d.ts.map +1 -0
- package/dist/types/adapters/SolanaSignerError.d.ts +5 -0
- package/dist/types/adapters/SolanaSignerError.d.ts.map +1 -0
- package/dist/types/adapters/fromKeypair.d.ts +22 -0
- package/dist/types/adapters/fromKeypair.d.ts.map +1 -0
- package/dist/types/adapters/fromKitSigner.d.ts +22 -0
- package/dist/types/adapters/fromKitSigner.d.ts.map +1 -0
- package/dist/types/adapters/fromWalletAdapter.d.ts +27 -0
- package/dist/types/adapters/fromWalletAdapter.d.ts.map +1 -0
- package/dist/types/adapters/fromWalletStandard.d.ts +32 -0
- package/dist/types/adapters/fromWalletStandard.d.ts.map +1 -0
- package/dist/types/adapters/resolveSignerSlot.d.ts +11 -0
- package/dist/types/adapters/resolveSignerSlot.d.ts.map +1 -0
- package/dist/types/client.d.ts +29 -14
- package/dist/types/client.d.ts.map +1 -1
- package/dist/types/decorators/solanaSmartWalletActions.d.ts +17 -0
- package/dist/types/decorators/solanaSmartWalletActions.d.ts.map +1 -0
- package/dist/types/experimental/actions/requestQuoteV0.d.ts +34 -7
- package/dist/types/experimental/actions/requestQuoteV0.d.ts.map +1 -1
- package/dist/types/exports/index.d.ts +3 -3
- package/dist/types/exports/index.d.ts.map +1 -1
- package/dist/types/exports/solana.d.ts +25 -0
- package/dist/types/exports/solana.d.ts.map +1 -0
- package/dist/types/types.d.ts +28 -4
- package/dist/types/types.d.ts.map +1 -1
- package/dist/types/utils/assertions.d.ts +4 -2
- package/dist/types/utils/assertions.d.ts.map +1 -1
- package/dist/types/utils/capabilities.d.ts +22 -6
- package/dist/types/utils/capabilities.d.ts.map +1 -1
- package/dist/types/utils/schema.d.ts +14 -14
- package/dist/types/utils/schema.d.ts.map +1 -1
- package/dist/types/version.d.ts +1 -1
- package/package.json +26 -9
- package/src/actions/prepareCalls.ts +21 -3
- package/src/actions/requestAccount.ts +7 -5
- package/src/actions/sendPreparedCalls.ts +4 -1
- package/src/actions/signPreparedCalls.ts +1 -1
- package/src/actions/signSignatureRequest.ts +8 -8
- package/src/actions/signTypedData.ts +15 -12
- package/src/actions/solana/getCallsStatus.ts +79 -0
- package/src/actions/solana/prepareCalls.ts +120 -0
- package/src/actions/solana/sendCalls.ts +66 -0
- package/src/actions/solana/sendPreparedCalls.ts +65 -0
- package/src/actions/solana/signPreparedCalls.ts +50 -0
- package/src/actions/solana/signSignatureRequest.ts +63 -0
- package/src/actions/solana/waitForCallsStatus.ts +84 -0
- package/src/adapters/SolanaSignerError.ts +5 -0
- package/src/adapters/fromKeypair.ts +58 -0
- package/src/adapters/fromKitSigner.ts +82 -0
- package/src/adapters/fromWalletAdapter.ts +58 -0
- package/src/adapters/fromWalletStandard.ts +100 -0
- package/src/adapters/resolveSignerSlot.ts +46 -0
- package/src/client.ts +131 -18
- package/src/decorators/smartWalletActions.ts +2 -2
- package/src/decorators/solanaSmartWalletActions.ts +62 -0
- package/src/experimental/actions/requestQuoteV0.ts +26 -11
- package/src/exports/index.ts +8 -4
- package/src/exports/solana.ts +36 -0
- package/src/types.ts +38 -7
- package/src/utils/assertions.ts +17 -2
- package/src/utils/capabilities.ts +40 -8
- package/src/utils/format.ts +1 -1
- package/src/utils/schema.ts +58 -69
- package/src/version.ts +1 -1
|
@@ -2,17 +2,18 @@ import {
|
|
|
2
2
|
PrepareCallsCapabilities as PrepareCallsCapabilitiesSchema,
|
|
3
3
|
SendPreparedCallsCapabilities as SendPreparedCallsCapabilitiesSchema,
|
|
4
4
|
} from "@alchemy/wallet-api-types/capabilities";
|
|
5
|
-
import type {
|
|
6
|
-
import type {
|
|
5
|
+
import type { z } from "zod";
|
|
6
|
+
import type {
|
|
7
|
+
InnerWalletApiClient,
|
|
8
|
+
InnerSolanaWalletApiClient,
|
|
9
|
+
} from "../types.js";
|
|
7
10
|
|
|
8
11
|
/**
|
|
9
12
|
* Decoded capabilities matching the schema shape (uses `paymasterService` key).
|
|
10
13
|
* `ResolveCapabilities` renames this to `paymaster` for client-facing types.
|
|
11
14
|
*/
|
|
12
|
-
type DecodedPrepareCallsCaps =
|
|
13
|
-
|
|
14
|
-
>;
|
|
15
|
-
type DecodedSendPreparedCallsCaps = StaticDecode<
|
|
15
|
+
type DecodedPrepareCallsCaps = z.output<typeof PrepareCallsCapabilitiesSchema>;
|
|
16
|
+
type DecodedSendPreparedCallsCaps = z.output<
|
|
16
17
|
typeof SendPreparedCallsCapabilitiesSchema
|
|
17
18
|
>;
|
|
18
19
|
|
|
@@ -60,7 +61,7 @@ function hasNoPaymasterServiceField(
|
|
|
60
61
|
|
|
61
62
|
/**
|
|
62
63
|
* Converts capabilities (with `paymaster`) to RPC capabilities (with `paymasterService`)
|
|
63
|
-
* for use with
|
|
64
|
+
* for use with `encode` before sending to the RPC.
|
|
64
65
|
*
|
|
65
66
|
* @param {PrepareCallsCapabilities | SendPreparedCallsCapabilities | undefined} capabilities - Capabilities object containing a `paymaster` field
|
|
66
67
|
* @returns {DecodedPrepareCallsCaps | DecodedSendPreparedCallsCaps | undefined} RPC capabilities with `paymasterService`, or undefined if input is undefined
|
|
@@ -82,7 +83,7 @@ export function toRpcCapabilities(
|
|
|
82
83
|
}
|
|
83
84
|
|
|
84
85
|
/**
|
|
85
|
-
* Converts RPC capabilities (with `paymasterService`) from
|
|
86
|
+
* Converts RPC capabilities (with `paymasterService`) from `decode`
|
|
86
87
|
* to capabilities (with `paymaster`).
|
|
87
88
|
*
|
|
88
89
|
* @param {DecodedPrepareCallsCaps | DecodedSendPreparedCallsCaps | undefined} capabilities - RPC capabilities object containing a `paymasterService` field
|
|
@@ -135,6 +136,37 @@ export const mergeClientCapabilities = <
|
|
|
135
136
|
} as T;
|
|
136
137
|
};
|
|
137
138
|
|
|
139
|
+
export type SolanaPaymasterCapability = {
|
|
140
|
+
policyId: string;
|
|
141
|
+
webhookData?: string;
|
|
142
|
+
};
|
|
143
|
+
|
|
144
|
+
export type SolanaPrepareCallsCapabilities = {
|
|
145
|
+
paymaster?: SolanaPaymasterCapability;
|
|
146
|
+
};
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* Merges Solana client-level capabilities (policyId from factory) with
|
|
150
|
+
* request-level capabilities. Request-level takes priority if provided.
|
|
151
|
+
*
|
|
152
|
+
* @param {InnerSolanaWalletApiClient} client - The Solana wallet API client
|
|
153
|
+
* @param {SolanaPrepareCallsCapabilities | undefined} capabilities - Request capabilities to merge with
|
|
154
|
+
* @returns {SolanaPrepareCallsCapabilities | undefined} The merged capabilities
|
|
155
|
+
*/
|
|
156
|
+
export const mergeSolanaClientCapabilities = (
|
|
157
|
+
client: InnerSolanaWalletApiClient,
|
|
158
|
+
capabilities: SolanaPrepareCallsCapabilities | undefined,
|
|
159
|
+
): SolanaPrepareCallsCapabilities | undefined => {
|
|
160
|
+
if (!client.policyIds?.length || capabilities?.paymaster) {
|
|
161
|
+
return capabilities;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
return {
|
|
165
|
+
...capabilities,
|
|
166
|
+
paymaster: { policyId: client.policyIds[0] },
|
|
167
|
+
};
|
|
168
|
+
};
|
|
169
|
+
|
|
138
170
|
/**
|
|
139
171
|
* Extracts capabilities from prepareCalls that are usable for sendPreparedCalls.
|
|
140
172
|
* Only permissions and paymaster (policyId/policyIds & webhookData) are supported.
|
package/src/utils/format.ts
CHANGED
|
@@ -31,7 +31,7 @@ export const signableMessageToJsonSafe = (
|
|
|
31
31
|
};
|
|
32
32
|
|
|
33
33
|
// Purposefully not using `formatTypedData` from the wallet server types pkg
|
|
34
|
-
// here, since that would require
|
|
34
|
+
// here, since that would require zod at runtime (which breaks RN).
|
|
35
35
|
export const typedDataToJsonSafe = ({
|
|
36
36
|
domain,
|
|
37
37
|
primaryType,
|
package/src/utils/schema.ts
CHANGED
|
@@ -1,109 +1,98 @@
|
|
|
1
|
-
import
|
|
2
|
-
TObject,
|
|
3
|
-
TSchema,
|
|
4
|
-
TTuple,
|
|
5
|
-
StaticDecode,
|
|
6
|
-
StaticEncode,
|
|
7
|
-
} from "typebox";
|
|
8
|
-
import { Value, EncodeError, DecodeError, Pointer } from "typebox/value";
|
|
1
|
+
import { z } from "zod";
|
|
9
2
|
import { BaseError } from "@alchemy/common";
|
|
10
3
|
|
|
11
4
|
/** Constraint for RPC method schemas from `@alchemy/wallet-api-types/rpc`. */
|
|
12
|
-
type RpcMethodSchema =
|
|
13
|
-
Request:
|
|
14
|
-
method:
|
|
15
|
-
params:
|
|
5
|
+
type RpcMethodSchema = z.ZodObject<{
|
|
6
|
+
Request: z.ZodObject<{
|
|
7
|
+
method: z.ZodType;
|
|
8
|
+
params: z.ZodTuple<[z.ZodType, ...z.ZodType[]]>;
|
|
16
9
|
}>;
|
|
17
|
-
ReturnType:
|
|
10
|
+
ReturnType: z.ZodType;
|
|
18
11
|
}>;
|
|
19
12
|
|
|
20
|
-
export function methodSchema<TReq extends
|
|
21
|
-
schema:
|
|
22
|
-
Request:
|
|
13
|
+
export function methodSchema<TReq extends z.ZodType, TRes extends z.ZodType>(
|
|
14
|
+
schema: z.ZodObject<{
|
|
15
|
+
Request: z.ZodObject<{
|
|
16
|
+
method: z.ZodType;
|
|
17
|
+
params: z.ZodTuple<[TReq, ...z.ZodType[]]>;
|
|
18
|
+
}>;
|
|
23
19
|
ReturnType: TRes;
|
|
24
20
|
}>,
|
|
25
21
|
): { request: TReq; response: TRes } {
|
|
26
22
|
return {
|
|
27
|
-
request: schema.
|
|
28
|
-
response: schema.
|
|
23
|
+
request: schema.shape.Request.shape.params.def.items[0],
|
|
24
|
+
response: schema.shape.ReturnType,
|
|
29
25
|
};
|
|
30
26
|
}
|
|
31
27
|
|
|
32
28
|
/** Extracts the decoded params type from a method schema. */
|
|
33
|
-
export type MethodParams<T extends RpcMethodSchema> =
|
|
34
|
-
T["
|
|
29
|
+
export type MethodParams<T extends RpcMethodSchema> = z.output<
|
|
30
|
+
T["shape"]["Request"]["shape"]["params"]["def"]["items"][0]
|
|
35
31
|
>;
|
|
36
32
|
|
|
37
33
|
/** Extracts the decoded response type from a method schema. */
|
|
38
|
-
export type MethodResponse<T extends RpcMethodSchema> =
|
|
39
|
-
T["
|
|
34
|
+
export type MethodResponse<T extends RpcMethodSchema> = z.output<
|
|
35
|
+
T["shape"]["ReturnType"]
|
|
40
36
|
>;
|
|
41
37
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
* @param {TSchema} schema - The TypeBox schema that validation was run against.
|
|
48
|
-
* @param {EncodeError | DecodeError} error - The error thrown by {@link Value.Encode} or {@link Value.Decode}.
|
|
49
|
-
* @returns {string} A formatted error string prefixed with `"Invalid params"`.
|
|
50
|
-
*/
|
|
51
|
-
function formatCodecError(
|
|
52
|
-
schema: TSchema,
|
|
53
|
-
error: EncodeError | DecodeError,
|
|
54
|
-
): string {
|
|
55
|
-
// Use only the first error — it's the most specific. Subsequent errors are
|
|
56
|
-
// typically cascade noise from union/anyOf branches.
|
|
57
|
-
const causeError = error.cause.errors[0];
|
|
58
|
-
// errors is typed as an open array — guard against the (practically
|
|
59
|
-
// impossible) empty case.
|
|
60
|
-
if (!causeError) return "Invalid params";
|
|
38
|
+
function isUnionIssue(
|
|
39
|
+
issue: z.core.$ZodIssue,
|
|
40
|
+
): issue is z.core.$ZodIssueInvalidUnion {
|
|
41
|
+
return issue.code === "invalid_union";
|
|
42
|
+
}
|
|
61
43
|
|
|
62
|
-
|
|
44
|
+
function formatCodecError(error: z.ZodError): string {
|
|
45
|
+
let issue: z.core.$ZodIssue | undefined = error.issues[0];
|
|
46
|
+
if (!issue) return "Invalid params";
|
|
63
47
|
|
|
64
|
-
//
|
|
65
|
-
|
|
66
|
-
const
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
"errorMessage" in schemaNode &&
|
|
73
|
-
typeof (schemaNode as Record<string, unknown>).errorMessage === "string"
|
|
74
|
-
) {
|
|
75
|
-
message = (schemaNode as Record<string, unknown>).errorMessage as string;
|
|
48
|
+
// For union errors, drill into the branch with the fewest issues (closest match).
|
|
49
|
+
// Accumulate paths as we drill — each union level carries a partial path.
|
|
50
|
+
const pathPrefix: PropertyKey[] = [];
|
|
51
|
+
while (isUnionIssue(issue)) {
|
|
52
|
+
pathPrefix.push(...issue.path);
|
|
53
|
+
let best: z.core.$ZodIssue[] | undefined;
|
|
54
|
+
for (const branch of issue.errors) {
|
|
55
|
+
if (!best || branch.length < best.length) best = branch;
|
|
76
56
|
}
|
|
57
|
+
const next = best?.[0];
|
|
58
|
+
if (!next) break;
|
|
59
|
+
issue = next;
|
|
77
60
|
}
|
|
78
61
|
|
|
79
|
-
|
|
62
|
+
const fullPath = [...pathPrefix, ...issue.path];
|
|
63
|
+
const path =
|
|
64
|
+
fullPath.length > 0 ? "/" + fullPath.map(String).join("/") + ": " : "";
|
|
65
|
+
|
|
66
|
+
return `Invalid params: ${path}${issue.message}`;
|
|
80
67
|
}
|
|
81
68
|
|
|
82
|
-
|
|
83
|
-
export function encode<const T extends TSchema>(
|
|
69
|
+
export function encode<const T extends z.ZodType>(
|
|
84
70
|
schema: T,
|
|
85
|
-
value:
|
|
86
|
-
):
|
|
71
|
+
value: z.output<T>,
|
|
72
|
+
): z.input<T> {
|
|
87
73
|
try {
|
|
88
|
-
return
|
|
74
|
+
return schema.encode(value);
|
|
89
75
|
} catch (error) {
|
|
90
|
-
if (error instanceof
|
|
91
|
-
throw new BaseError(formatCodecError(
|
|
76
|
+
if (error instanceof z.ZodError) {
|
|
77
|
+
throw new BaseError(formatCodecError(error), {
|
|
78
|
+
cause: error as Error,
|
|
79
|
+
});
|
|
92
80
|
}
|
|
93
81
|
throw error;
|
|
94
82
|
}
|
|
95
83
|
}
|
|
96
84
|
|
|
97
|
-
|
|
98
|
-
export function decode<const T extends TSchema>(
|
|
85
|
+
export function decode<const T extends z.ZodType>(
|
|
99
86
|
schema: T,
|
|
100
|
-
value:
|
|
101
|
-
):
|
|
87
|
+
value: z.input<T>,
|
|
88
|
+
): z.output<T> {
|
|
102
89
|
try {
|
|
103
|
-
return
|
|
90
|
+
return schema.decode(value);
|
|
104
91
|
} catch (error) {
|
|
105
|
-
if (error instanceof
|
|
106
|
-
throw new BaseError(formatCodecError(
|
|
92
|
+
if (error instanceof z.ZodError) {
|
|
93
|
+
throw new BaseError(formatCodecError(error), {
|
|
94
|
+
cause: error as Error,
|
|
95
|
+
});
|
|
107
96
|
}
|
|
108
97
|
throw error;
|
|
109
98
|
}
|
package/src/version.ts
CHANGED