mirror of
https://github.com/Start9Labs/start-sdk.git
synced 2026-04-01 21:13:11 +00:00
rename enum and add multiselect
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
import { writeConvertedFile } from "../../scripts/oldSpecToBuilder";
|
||||
import { writeFileSync, readFileSync } from "fs";
|
||||
|
||||
writeConvertedFile(
|
||||
"./lib/util/artifacts/output.ts",
|
||||
@@ -66,7 +65,7 @@ writeConvertedFile(
|
||||
name: "Serialization Version",
|
||||
description:
|
||||
"Return raw transaction or block hex with Segwit or non-SegWit serialization.",
|
||||
type: "enum",
|
||||
type: "select",
|
||||
values: ["non-segwit", "segwit"],
|
||||
"value-names": {},
|
||||
default: "segwit",
|
||||
|
||||
@@ -51,7 +51,7 @@ export const authorizationList = List.string({
|
||||
warning: null,
|
||||
});
|
||||
export const auth = Value.list(authorizationList);
|
||||
export const serialversion = Value.enum({
|
||||
export const serialversion = Value.select({
|
||||
name: "Serialization Version",
|
||||
description:
|
||||
"Return raw transaction or block hex with Segwit or non-SegWit serialization.",
|
||||
|
||||
@@ -6,7 +6,8 @@ type TypeString = "string";
|
||||
type TypeNumber = "number";
|
||||
type TypeObject = "object";
|
||||
type TypeList = "list";
|
||||
type TypeEnum = "enum";
|
||||
type TypeSelect = "select";
|
||||
type TypeMultiselect = "multiselect";
|
||||
type TypePointer = "pointer";
|
||||
type TypeUnion = "union";
|
||||
|
||||
@@ -49,8 +50,12 @@ type GuardPointer<A> =
|
||||
A extends {readonly type:TypePointer} ? (string | null) :
|
||||
unknown
|
||||
// prettier-ignore
|
||||
type GuardEnum<A> =
|
||||
A extends {readonly type:TypeEnum, readonly values: ArrayLike<infer B>} ? GuardDefaultNullable<A, B> :
|
||||
type GuardSelect<A> =
|
||||
A extends {readonly type:TypeSelect, readonly values: ArrayLike<infer B>} ? GuardDefaultNullable<A, B> :
|
||||
unknown
|
||||
// prettier-ignore
|
||||
type GuardMultiselect<A> =
|
||||
A extends {readonly type:TypeMultiselect, readonly values: ArrayLike<infer B>} ? GuardDefaultNullable<A, B> :
|
||||
unknown
|
||||
// prettier-ignore
|
||||
type GuardUnion<A> =
|
||||
@@ -65,7 +70,8 @@ export type GuardAll<A> = GuardNumber<A> &
|
||||
GuardList<A> &
|
||||
GuardPointer<A> &
|
||||
GuardUnion<A> &
|
||||
GuardEnum<A>;
|
||||
GuardSelect<A> &
|
||||
GuardMultiselect<A>;
|
||||
// prettier-ignore
|
||||
export type TypeFromProps<A> =
|
||||
A extends Record<string, unknown> ? {readonly [K in keyof A & string]: _<GuardAll<A[K]>>} :
|
||||
@@ -247,7 +253,7 @@ export function guardAll<A extends ValueSpecAny>(
|
||||
value
|
||||
) as any;
|
||||
}
|
||||
case "enum":
|
||||
case "select":
|
||||
if (matchValues.test(value)) {
|
||||
return defaultNullable(
|
||||
matches.literals(value.values[0], ...value.values),
|
||||
@@ -255,6 +261,20 @@ export function guardAll<A extends ValueSpecAny>(
|
||||
) as any;
|
||||
}
|
||||
return matches.unknown as any;
|
||||
case "multiselect":
|
||||
if (matchValues.test(value)) {
|
||||
const rangeValidate =
|
||||
(matchRange.test(value) && matchNumberWithRange(value.range).test) ||
|
||||
(() => true);
|
||||
|
||||
return defaultNullable(
|
||||
matches
|
||||
.literals(value.values[0], ...value.values)
|
||||
.validate((x) => rangeValidate(x.length), "valid length"),
|
||||
value
|
||||
) as any;
|
||||
}
|
||||
return matches.unknown as any;
|
||||
case "union":
|
||||
if (matchUnion.test(value)) {
|
||||
return matches.some(
|
||||
|
||||
Reference in New Issue
Block a user