Skip to content

Commit fce94af

Browse files
committed
support isolated declarations
1 parent 20cb28d commit fce94af

File tree

10 files changed

+141
-101
lines changed

10 files changed

+141
-101
lines changed

bun.lock

Lines changed: 23 additions & 71 deletions
Large diffs are not rendered by default.

packages/zod-solana/src/index.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@ export { addressSchema } from "./address-schema.js";
22
export { U8_MAX, U16_MAX, U32_MAX, U64_MAX } from "./constants.js";
33
export {
44
type TokenMetadata,
5+
type TokenMetadataAttribute,
6+
type TokenMetadataCollection,
7+
type TokenMetadataCreator,
8+
type TokenMetadataFile,
9+
type TokenMetadataProperties,
510
tokenMetadataSchema,
611
} from "./token-metadata-schema.js";
712
export { u8Schema } from "./u8-schema.js";

packages/zod-solana/src/token-metadata-schema.ts

Lines changed: 104 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import * as z from "zod";
33
/**
44
* Schema for token metadata attributes
55
*/
6-
const tokenAttributeSchema = z.object({
6+
const tokenAttributeSchema: z.ZodType<TokenMetadataAttribute> = z.object({
77
trait_type: z.string(),
88
value: z.union([z.string(), z.number()]),
99
display_type: z.string().optional(),
@@ -12,33 +12,124 @@ const tokenAttributeSchema = z.object({
1212
/**
1313
* Schema for token metadata files
1414
*/
15-
const tokenFileSchema = z.object({
15+
const tokenFileSchema: z.ZodType<TokenMetadataFile> = z.object({
1616
uri: z.string(),
1717
type: z.string(),
1818
cdn: z.boolean().optional(),
1919
});
2020

21+
/**
22+
* Schema for token metadata creators
23+
*/
24+
const tokenCreatorSchema: z.ZodType<TokenMetadataCreator> = z.object({
25+
address: z.string(),
26+
share: z.number().min(0).max(100),
27+
});
28+
2129
/**
2230
* Schema for token metadata properties
2331
*/
24-
const tokenPropertiesSchema = z.object({
32+
const tokenPropertiesSchema: z.ZodType<TokenMetadataProperties> = z.object({
2533
files: z.array(tokenFileSchema).optional(),
2634
category: z.string().optional(),
27-
creators: z
28-
.array(
29-
z.object({
30-
address: z.string(),
31-
share: z.number().min(0).max(100),
32-
}),
33-
)
34-
.optional(),
35+
creators: z.array(tokenCreatorSchema).optional(),
36+
});
37+
38+
/**
39+
* Schema for token metadata collection
40+
*/
41+
const tokenCollectionSchema: z.ZodType<TokenMetadataCollection> = z.object({
42+
name: z.string(),
43+
family: z.string().optional(),
3544
});
3645

46+
/**
47+
* Interface for token metadata attributes/traits
48+
*/
49+
export interface TokenMetadataAttribute {
50+
/** The trait type/category */
51+
trait_type: string;
52+
/** The trait value (string or number) */
53+
value: string | number;
54+
/** Optional display type for UI formatting */
55+
display_type?: string;
56+
}
57+
58+
/**
59+
* Interface for token metadata file references
60+
*/
61+
export interface TokenMetadataFile {
62+
/** File URI */
63+
uri: string;
64+
/** File MIME type */
65+
type: string;
66+
/** Whether the file is CDN cached */
67+
cdn?: boolean;
68+
}
69+
70+
/**
71+
* Interface for token creator information with royalty shares
72+
*/
73+
export interface TokenMetadataCreator {
74+
/** Creator's wallet address */
75+
address: string;
76+
/** Creator's royalty share percentage (0-100) */
77+
share: number;
78+
}
79+
80+
/**
81+
* Interface for token metadata properties
82+
*/
83+
export interface TokenMetadataProperties {
84+
/** Optional array of file references */
85+
files?: TokenMetadataFile[];
86+
/** Optional category classification */
87+
category?: string;
88+
/** Optional array of creators with royalty shares */
89+
creators?: TokenMetadataCreator[];
90+
}
91+
92+
/**
93+
* Interface for token collection information
94+
*/
95+
export interface TokenMetadataCollection {
96+
/** Collection name */
97+
name: string;
98+
/** Optional collection family */
99+
family?: string;
100+
}
101+
102+
/**
103+
* Interface for Solana token metadata following the Metaplex Token Metadata Standard
104+
*/
105+
export interface TokenMetadata {
106+
/** The name of the token */
107+
name: string;
108+
/** The symbol of the token */
109+
symbol: string;
110+
/** Optional description of the token */
111+
description?: string;
112+
/** Optional image URI */
113+
image?: string;
114+
/** Optional animation URL for multimedia content */
115+
animation_url?: string;
116+
/** Optional external URL for additional information */
117+
external_url?: string;
118+
/** Optional array of attributes/traits */
119+
attributes?: TokenMetadataAttribute[];
120+
/** Optional properties object */
121+
properties?: TokenMetadataProperties;
122+
/** Optional seller fee basis points (royalty percentage * 100) */
123+
seller_fee_basis_points?: number;
124+
/** Optional collection information */
125+
collection?: TokenMetadataCollection;
126+
}
127+
37128
/**
38129
* Schema for Solana token metadata JSON
39130
* Based on Metaplex Token Metadata Standard
40131
*/
41-
export const tokenMetadataSchema = z.object({
132+
export const tokenMetadataSchema: z.ZodType<TokenMetadata> = z.object({
42133
name: z.string(),
43134
symbol: z.string(),
44135
description: z.string().optional(),
@@ -49,12 +140,5 @@ export const tokenMetadataSchema = z.object({
49140
properties: tokenPropertiesSchema.optional(),
50141
// Additional fields that may be present
51142
seller_fee_basis_points: z.number().optional(),
52-
collection: z
53-
.object({
54-
name: z.string(),
55-
family: z.string().optional(),
56-
})
57-
.optional(),
143+
collection: tokenCollectionSchema.optional(),
58144
});
59-
60-
export type TokenMetadata = z.infer<typeof tokenMetadataSchema>;

packages/zod-solana/src/u16-schema.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { U16_MAX } from "./constants.js";
55
* A Zod schema for u16 values.
66
* Validates that a number is between 0 and 65535 (inclusive).
77
*/
8-
export const u16Schema = z
8+
export const u16Schema: z.ZodNumber = z
99
.number()
1010
.int("Value must be an integer")
1111
.min(0, "Value must be at least 0")

packages/zod-solana/src/u32-schema.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { U32_MAX } from "./constants.js";
55
* A Zod schema for u32 values.
66
* Validates that a number is between 0 and 4294967295 (inclusive).
77
*/
8-
export const u32Schema = z
8+
export const u32Schema: z.ZodNumber = z
99
.number()
1010
.int("Value must be an integer")
1111
.min(0, "Value must be at least 0")

packages/zod-solana/src/u64-schema.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { U64_MAX } from "./constants.js";
55
* A Zod schema for u64 values.
66
* Validates that a bigint is between 0 and 2^64-1 (inclusive).
77
*/
8-
export const u64Schema = z
8+
export const u64Schema: z.ZodBigInt = z
99
.bigint()
1010
.min(0n, "Value must be at least 0")
1111
.max(U64_MAX, `Value must be at most ${String(U64_MAX)}`);

packages/zod-solana/src/u64-string-schema.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { U64_MAX } from "./constants.js";
66
* Validates that a string represents a valid u64 value (0 to 2^64-1).
77
* Returns the value as a string to preserve precision for large numbers.
88
*/
9-
export const u64StringSchema = z.string().refine(
9+
export const u64StringSchema: z.ZodType<string> = z.string().refine(
1010
(val) => {
1111
// Check for empty string
1212
if (val === "") {

packages/zod-solana/src/u8-schema.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { U8_MAX } from "./constants.js";
55
* A Zod schema for u8 values.
66
* Validates that a number is between 0 and 255 (inclusive).
77
*/
8-
export const u8Schema = z
8+
export const u8Schema: z.ZodNumber = z
99
.number()
1010
.int("Value must be an integer")
1111
.min(0, "Value must be at least 0")

packages/zod-solana/src/uint8array-schema.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@ import { u8Schema } from "./u8-schema.js";
55
* A Zod schema for Uint8Array.
66
* Accepts an array of numbers and transforms it to a Uint8Array.
77
*/
8-
export const uint8ArraySchema = z
8+
export const uint8ArraySchema: z.ZodType<Uint8Array> = z
99
.array(u8Schema)
1010
.transform((arr) => new Uint8Array(arr));
1111

1212
/**
1313
* A Zod schema for JSON-encoded Uint8Array.
1414
* Accepts a JSON string, parses it, and transforms to Uint8Array.
1515
*/
16-
export const jsonUint8ArraySchema = z
16+
export const jsonUint8ArraySchema: z.ZodType<Uint8Array> = z
1717
.string()
1818
.transform((str) => {
1919
try {

packages/zod-solana/tsconfig.json

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
{
2-
"extends": "@macalinao/tsconfig/tsconfig.dom.json",
2+
"extends": "@macalinao/tsconfig/tsconfig.base.json",
33
"compilerOptions": {
4-
"types": ["bun"],
5-
"isolatedDeclarations": false
4+
"types": ["bun"]
65
}
76
}

0 commit comments

Comments
 (0)