add descriptions and some renaming

This commit is contained in:
Matt Hill
2023-05-15 11:33:58 -06:00
parent 2ce6d5df6d
commit a7f9a21057
6 changed files with 76 additions and 65 deletions

View File

@@ -18,9 +18,8 @@ import {
ActionResult,
BackupOptions,
DeepPartial,
Address,
} from "./types"
import * as regexes from "./util/regexes"
import * as patterns from "./util/patterns"
import { Utils } from "./util/utils"
import { DependencyConfig } from "./dependencyConfig/DependencyConfig"
import { BackupSet, Backups } from "./backup/Backups"
@@ -52,8 +51,6 @@ import {
SetInterfaces,
setupInterfaces,
} from "./interfaces/setupInterfaces"
import { AddressReceipt } from "./interfaces/AddressReceipt"
import { Host } from "./interfaces/Host"
// prettier-ignore
type AnyNeverCond<T extends any[], Then, Else> =
@@ -105,7 +102,7 @@ export class StartSdk<Manifest extends SDKManifest, Store, Vault> {
of: healthCheck,
runHealthScript,
},
regexes,
patterns,
setupActions: (...createdActions: CreatedAction<any, any, any>[]) =>
setupActions<Store, Vault>(...createdActions),
setupBackups: (...args: SetupBackupsParams<Manifest>) =>

View File

@@ -1,11 +1,4 @@
import {
Address,
Effects,
EnsureStorePath,
HostName,
NetworkInterface,
hostName,
} from "../types"
import { Address, Effects, HostName, NetworkInterface } from "../types"
import * as regexes from "./regexes"
export type UrlString = string
@@ -72,10 +65,10 @@ export const filledAddress = (
...address,
hostnames,
get onionHostnames() {
return hostnames.filter(regexes.onionHost.test)
return hostnames.filter(regexes.torHostname.test)
},
get localHostnames() {
return hostnames.filter(regexes.localHost.test)
return hostnames.filter(regexes.localHostname.test)
},
get ipHostnames() {
return hostnames.filter(either(regexes.ipv4.test, regexes.ipv6.test))
@@ -96,10 +89,10 @@ export const filledAddress = (
return hostnames.map(toUrl)
},
get onionUrls() {
return hostnames.filter(regexes.onionHost.test).map(toUrl)
return hostnames.filter(regexes.torHostname.test).map(toUrl)
},
get localUrls() {
return hostnames.filter(regexes.localHost.test).map(toUrl)
return hostnames.filter(regexes.localHostname.test).map(toUrl)
},
get ipUrls() {
return hostnames

View File

@@ -1,5 +1,4 @@
import { Address, Effects, EnsureStorePath, HostName, hostName } from "../types"
import * as regexes from "./regexes"
import { Effects, HostName } from "../types"
import {
HostId,
NetworkInterfaceFilled,

59
lib/util/patterns.ts Normal file
View File

@@ -0,0 +1,59 @@
import { Pattern } from "../config/configTypes"
import * as regexes from "./regexes"
export const ipv6: Pattern = {
regex: regexes.ipv6.toString(),
description: "Must be a valid IPv6 address",
}
export const ipv4: Pattern = {
regex: regexes.ipv4.toString(),
description: "Must be a valid IPv4 address",
}
export const hostname = {
regex: regexes.hostname.toString(),
description: "Must be a valid hostname",
}
export const localHostname: Pattern = {
regex: regexes.localHostname.toString(),
description: 'Must be a valid ".local" hostname',
}
export const torHostname: Pattern = {
regex: regexes.torHostname.toString(),
description: 'Must be a valid Tor (".onion") hostname',
}
export const url: Pattern = {
regex: regexes.url.toString(),
description: "Must be a valid URL",
}
export const localUrl: Pattern = {
regex: regexes.localUrl.toString(),
description: 'Must be a valid ".local" URL',
}
export const torUrl: Pattern = {
regex: regexes.torUrl.toString(),
description: 'Must be a valid Tor (".onion") URL',
}
export const ascii: Pattern = {
regex: regexes.ascii.toString(),
description:
"May only contain ASCII characters. See https://www.w3schools.com/charsets/ref_html_ascii.asp",
}
export const email: Pattern = {
regex: regexes.email.toString(),
description: "Must be a valid email address",
}
export const base64: Pattern = {
regex: regexes.base64.toString(),
description:
"May only contain base64 characters. See https://base64.guru/learn/base64-characters",
}

View File

@@ -1,41 +0,0 @@
import { Pattern } from "../config/configTypes"
import * as regexes from "./regexes"
export const ipv6: Pattern = {
regex: regexes.ipv6.toString(),
description: "",
}
export const ipv4: Pattern = { regex: regexes.ipv4.toString(), description: "" }
export const url: Pattern = { regex: regexes.url.toString(), description: "" }
export const local: Pattern = {
regex: regexes.local.toString(),
description: "",
}
export const localHost: Pattern = {
regex: regexes.localHost.toString(),
description: "",
}
export const onion: Pattern = {
regex: regexes.onion.toString(),
description: "",
}
export const onionHost: Pattern = {
regex: regexes.onionHost.toString(),
description: "",
}
export const ascii: Pattern = {
regex: regexes.ascii.toString(),
description: "",
}
export const email: Pattern = {
regex: regexes.email.toString(),
description: "",
}
export const base64: Pattern = {
regex: regexes.base64.toString(),
description: "",
}

View File

@@ -6,19 +6,23 @@ export const ipv6 =
export const ipv4 =
/(\b25[0-5]|\b2[0-4][0-9]|\b[01]?[0-9][0-9]?)(\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}/
export const hostname =
/^(([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-]*[a-zA-Z0-9])\.)*([A-Za-z0-9]|[A-Za-z0-9][A-Za-z0-9\-]*[A-Za-z0-9])$/
export const localHostname = /[-a-zA-Z0-9@:%._\+~#=]{1,256}\.local/
export const torHostname = /[-a-zA-Z0-9@:%._\+~#=]{1,256}\.onion/
// https://ihateregex.io/expr/url/
export const url =
/(https?:\/\/)?(www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()!@:%_\+.~#?&\/\/=]*)/
export const local =
export const localUrl =
/(https?:\/\/)?(www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.local\b([-a-zA-Z0-9()!@:%_\+.~#?&\/\/=]*)/
export const localHost = /[-a-zA-Z0-9@:%._\+~#=]{1,256}\.local/
export const onion =
export const torUrl =
/(https?:\/\/)?(www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.onion\b([-a-zA-Z0-9()!@:%_\+.~#?&\/\/=]*)/
export const onionHost = /[-a-zA-Z0-9@:%._\+~#=]{1,256}\.onion/
// https://ihateregex.io/expr/ascii/
export const ascii = /^[ -~]*$/