mirror of
https://github.com/Start9Labs/start-sdk.git
synced 2026-03-30 12:21:57 +00:00
Merge pull request #22 from Start9Labs/fix/default-not-valid
chore: Update default that are not valids
This commit is contained in:
@@ -596,6 +596,32 @@ const { test } = Deno;
|
|||||||
console.log("Checker = ", matches.Parser.parserAsString(checker.parser));
|
console.log("Checker = ", matches.Parser.parserAsString(checker.parser));
|
||||||
checker.unsafeCast({ mode: "automatic", size: 1234 });
|
checker.unsafeCast({ mode: "automatic", size: 1234 });
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test("A default that is invalid according to the tests", () => {
|
||||||
|
const checker = PM.typeFromProps({
|
||||||
|
pubkey_whitelist: {
|
||||||
|
name: "Pubkey Whitelist (hex)",
|
||||||
|
description:
|
||||||
|
"A list of pubkeys that are permitted to publish through your relay. A minimum, you need to enter your own Nostr hex (not npub) pubkey. Go to https://damus.io/key/ to convert from npub to hex.",
|
||||||
|
type: "list",
|
||||||
|
nullable: true,
|
||||||
|
range: "[1,*)",
|
||||||
|
subtype: "string",
|
||||||
|
spec: {
|
||||||
|
placeholder: "hex (not npub) pubkey",
|
||||||
|
pattern: "[0-9a-fA-F]{3}",
|
||||||
|
"pattern-description":
|
||||||
|
"Must be a valid 64-digit hexadecimal value (ie a Nostr hex pubkey, not an npub). Go to https://damus.io/key/ to convert npub to hex.",
|
||||||
|
},
|
||||||
|
default: [] as string[], // [] as string []
|
||||||
|
},
|
||||||
|
} as const);
|
||||||
|
|
||||||
|
checker.unsafeCast({
|
||||||
|
pubkey_whitelist: ["aaa"],
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
test("Full spec", () => {
|
test("Full spec", () => {
|
||||||
const checker = PM.typeFromProps(bitcoinProperties);
|
const checker = PM.typeFromProps(bitcoinProperties);
|
||||||
|
|
||||||
|
|||||||
@@ -168,7 +168,7 @@ const isGenerator = matches.shape({ charset: matches.string, len: matches.number
|
|||||||
function defaultNullable<A>(parser: matches.Parser<unknown, A>, value: unknown) {
|
function defaultNullable<A>(parser: matches.Parser<unknown, A>, value: unknown) {
|
||||||
if (matchDefault.test(value)) {
|
if (matchDefault.test(value)) {
|
||||||
if (isGenerator(value.default)) return parser.defaultTo(parser.unsafeCast(generateDefault(value.default)));
|
if (isGenerator(value.default)) return parser.defaultTo(parser.unsafeCast(generateDefault(value.default)));
|
||||||
return parser.defaultTo(parser.unsafeCast(value.default));
|
return parser.defaultTo(value.default);
|
||||||
}
|
}
|
||||||
if (matchNullable.test(value)) return parser.optional();
|
if (matchNullable.test(value)) return parser.optional();
|
||||||
return parser;
|
return parser;
|
||||||
@@ -215,11 +215,13 @@ export function guardAll<A extends ValueSpecAny>(value: A): matches.Parser<unkno
|
|||||||
const spec = (matchSpec.test(value) && value.spec) || {};
|
const spec = (matchSpec.test(value) && value.spec) || {};
|
||||||
const rangeValidate = (matchRange.test(value) && matchNumberWithRange(value.range).test) || (() => true);
|
const rangeValidate = (matchRange.test(value) && matchNumberWithRange(value.range).test) || (() => true);
|
||||||
|
|
||||||
|
const { default: _, ...arrayOfSpec } = spec;
|
||||||
|
|
||||||
const subtype = matchSubType.unsafeCast(value).subtype;
|
const subtype = matchSubType.unsafeCast(value).subtype;
|
||||||
return defaultNullable(
|
return defaultNullable(
|
||||||
matches
|
matches
|
||||||
// deno-lint-ignore no-explicit-any
|
// deno-lint-ignore no-explicit-any
|
||||||
.arrayOf(guardAll({ type: subtype, ...spec } as any))
|
.arrayOf(guardAll({ type: subtype, ...arrayOfSpec } as any))
|
||||||
.validate((x) => rangeValidate(x.length), "valid length"),
|
.validate((x) => rangeValidate(x.length), "valid length"),
|
||||||
value
|
value
|
||||||
// deno-lint-ignore no-explicit-any
|
// deno-lint-ignore no-explicit-any
|
||||||
|
|||||||
Reference in New Issue
Block a user