Use bchvmversions, lockingtypes and capabilities from the types package for schema validation
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
/* eslint-disable @stylistic/newline-per-chained-call */
|
||||
import { BchVmVersions, XOTemplateLockingTypes, XOTemplateNftCapabilities, XOTemplatePrimitiveTypes } from '@xo-cash/types';
|
||||
import { z } from 'zod';
|
||||
|
||||
// ============================================================
|
||||
@@ -9,9 +10,8 @@ import { z } from 'zod';
|
||||
* Validation schema for a BCH VM version identifier. Defines the set of known BCH VM versions
|
||||
* that XO templates declare support for.
|
||||
*
|
||||
* Zod's `z.enum` requires the exact values to be defined inline because it needs to know each
|
||||
* specific value at compile time to validate against them. Defining the versions here directly
|
||||
* satisfies that requirement and allows `z.array(bchVmVersionSchema)` to be used elsewhere
|
||||
* Uses `BchVmVersions` from `@xo-cash/types` so template validation stays aligned with the
|
||||
* `BchVmVersion` type.
|
||||
*
|
||||
* ```
|
||||
* {
|
||||
@@ -19,7 +19,7 @@ import { z } from 'zod';
|
||||
* }
|
||||
* ```
|
||||
*/
|
||||
export const bchVmVersionSchema = z.enum([ 'BCH_2020_05', 'BCH_2021_05', 'BCH_2022_05', 'BCH_2023_05', 'BCH_2024_05', 'BCH_2025_05', 'BCH_2026_05' ]);
|
||||
export const bchVmVersionSchema = z.enum(BchVmVersions);
|
||||
|
||||
/**
|
||||
* Validation schema for the capability of a non-fungible token. Defines the three capability
|
||||
@@ -40,7 +40,7 @@ export const bchVmVersionSchema = z.enum([ 'BCH_2020_05', 'BCH_2021_05', 'BCH_20
|
||||
* }
|
||||
* ```
|
||||
*/
|
||||
export const xoTemplateNftCapabilitySchema = z.enum([ 'minting', 'mutable', 'none' ]);
|
||||
export const xoTemplateNftCapabilitySchema = z.enum(XOTemplateNftCapabilities);
|
||||
|
||||
/**
|
||||
* Validation schema for a BCH locking script type. Defines the standard locking script types
|
||||
@@ -56,13 +56,13 @@ export const xoTemplateNftCapabilitySchema = z.enum([ 'minting', 'mutable', 'non
|
||||
* }
|
||||
* ```
|
||||
*/
|
||||
export const xoTemplateLockingTypeSchema = z.enum([ 'p2s', 'p2pkh', 'p2sh' ]);
|
||||
export const xoTemplateLockingTypeSchema = z.enum(XOTemplateLockingTypes);
|
||||
|
||||
/**
|
||||
* Validation schema for a primitive type identifier. Defines the set of primitive types
|
||||
* that can be declared in an XO template. Used by constants, variables, and data fields.
|
||||
*/
|
||||
export const xoTemplatePrimitiveTypeSchema = z.enum([ 'boolean', 'bytes', 'integer', 'bigint', 'string', 'private_key', 'public_key' ]);
|
||||
export const xoTemplatePrimitiveTypeSchema = z.enum(XOTemplatePrimitiveTypes);
|
||||
|
||||
// ============================================================
|
||||
// Primitives
|
||||
|
||||
Reference in New Issue
Block a user