Skip to content

Commit

Permalink
Merge pull request #16 from initia-labs/feat/ibc-type
Browse files Browse the repository at this point in the history
add ibc app version
  • Loading branch information
ALPAC-4 authored Mar 19, 2024
2 parents 46c3200 + b160be4 commit 88c14a6
Show file tree
Hide file tree
Showing 4 changed files with 128 additions and 44 deletions.
2 changes: 1 addition & 1 deletion _package/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@initia/initia-registry-types",
"version": "0.0.3",
"version": "0.0.5",
"description": "The package provides TypeScript type definitions and Zod integration for initia-registry.",
"types": "./dist/types/index.d.ts",
"exports": {
Expand Down
23 changes: 16 additions & 7 deletions _package/src/types/Chain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -226,13 +226,22 @@ export interface Chain {
/**
* [Optional] The list of IBC channels that are supported by the chain.
*/
ibc_channels?: {
channel?: {
chain_id: string;
transfer?: string;
"nft-transfer"?: string;
}[];
};
ibc_channels?:
| {
channel?: {
chain_id: string;
port_id: string;
channel_id: string;
version: string;
}[];
}
| {
channel?: {
chain_id: string;
transfer?: string;
"nft-transfer"?: string;
}[];
};
};
}
export interface FeeToken {
Expand Down
64 changes: 51 additions & 13 deletions _package/src/zods/Chain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -496,20 +496,58 @@ export const ChainSchema = z
)
.optional(),
ibc_channels: z
.object({
channel: z
.array(
z
.object({
chain_id: z.string(),
transfer: z.string().optional(),
"nft-transfer": z.string().optional(),
})
.strict()
)
.optional(),
.any()
.superRefine((x, ctx) => {
const schemas = [
z
.object({
channel: z
.array(
z
.object({
chain_id: z.string(),
port_id: z.string(),
channel_id: z.string(),
version: z.string(),
})
.strict()
)
.optional(),
})
.strict(),
z
.object({
channel: z
.array(
z
.object({
chain_id: z.string(),
transfer: z.string().optional(),
"nft-transfer": z.string().optional(),
})
.strict()
)
.optional(),
})
.strict(),
];
const errors = schemas.reduce(
(errors: z.ZodError[], schema) =>
((result) =>
"error" in result ? [...errors, result.error] : errors)(
schema.safeParse(x)
),
[]
);
if (schemas.length - errors.length !== 1) {
ctx.addIssue({
path: ctx.path,
code: "invalid_union",
unionErrors: errors,
message: "Invalid input: Should pass single schema",
});
}
})
.strict()
.describe(
"[Optional] The list of IBC channels that are supported by the chain."
)
Expand Down
83 changes: 60 additions & 23 deletions chain.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -639,31 +639,68 @@
"description": "[Optional] A list specifying coin amounts by denomination that exempt users from transaction fees when their balance meets or exceeds these amounts."
},
"ibc_channels": {
"type": "object",
"properties": {
"channel": {
"type": "array",
"items": {
"type": "object",
"required": [
"chain_id"
],
"properties": {
"chain_id": {
"type": "string"
},
"transfer": {
"type": "string"
},
"nft-transfer": {
"type": "string"
"oneOf": [
{
"type": "object",
"properties": {
"channel": {
"type": "array",
"items": {
"type": "object",
"required": [
"chain_id",
"port_id",
"channel_id",
"version"
],
"properties": {
"chain_id": {
"type": "string"
},
"port_id": {
"type": "string"
},
"channel_id": {
"type": "string"
},
"version": {
"type": "string"
}
},
"additionalProperties": false
}
},
"additionalProperties": false
}
}
},
"additionalProperties": false
},
{
"type": "object",
"properties": {
"channel": {
"type": "array",
"items": {
"type": "object",
"required": [
"chain_id"
],
"properties": {
"chain_id": {
"type": "string"
},
"transfer": {
"type": "string"
},
"nft-transfer": {
"type": "string"
}
},
"additionalProperties": false
}
}
},
"additionalProperties": false
}
},
"additionalProperties": false,
],
"description": "[Optional] The list of IBC channels that are supported by the chain."
}
},
Expand Down

0 comments on commit 88c14a6

Please sign in to comment.