mirror of
https://github.com/Start9Labs/start-sdk.git
synced 2026-03-31 04:33:40 +00:00
chore: Add the getSsl effects
This commit is contained in:
@@ -40,7 +40,7 @@ export class Backups {
|
|||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
private options = DEFAULT_OPTIONS,
|
private options = DEFAULT_OPTIONS,
|
||||||
private backupSet = [] as BackupSet[],
|
private backupSet = [] as BackupSet[]
|
||||||
) {}
|
) {}
|
||||||
static volumes(...volumeNames: string[]) {
|
static volumes(...volumeNames: string[]) {
|
||||||
return new Backups().addSets(
|
return new Backups().addSets(
|
||||||
@@ -49,7 +49,7 @@ export class Backups {
|
|||||||
srcPath: "./",
|
srcPath: "./",
|
||||||
dstPath: `./${srcVolume}/`,
|
dstPath: `./${srcVolume}/`,
|
||||||
dstVolume: Backups.BACKUP,
|
dstVolume: Backups.BACKUP,
|
||||||
})),
|
}))
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
static addSets(...options: BackupSet[]) {
|
static addSets(...options: BackupSet[]) {
|
||||||
@@ -72,12 +72,12 @@ export class Backups {
|
|||||||
srcPath: "./",
|
srcPath: "./",
|
||||||
dstPath: `./${srcVolume}/`,
|
dstPath: `./${srcVolume}/`,
|
||||||
dstVolume: Backups.BACKUP,
|
dstVolume: Backups.BACKUP,
|
||||||
})),
|
}))
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
addSets(...options: BackupSet[]) {
|
addSets(...options: BackupSet[]) {
|
||||||
options.forEach((x) =>
|
options.forEach((x) =>
|
||||||
this.backupSet.push({ ...x, options: { ...this.options, ...x.options } }),
|
this.backupSet.push({ ...x, options: { ...this.options, ...x.options } })
|
||||||
);
|
);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
@@ -98,7 +98,7 @@ export class Backups {
|
|||||||
.map((x) => x.dstPath)
|
.map((x) => x.dstPath)
|
||||||
.map((x) => x.replace(/\.\/([^]*)\//, "$1"));
|
.map((x) => x.replace(/\.\/([^]*)\//, "$1"));
|
||||||
const filteredItems = previousItems.filter(
|
const filteredItems = previousItems.filter(
|
||||||
(x) => backupPaths.indexOf(x) === -1,
|
(x) => backupPaths.indexOf(x) === -1
|
||||||
);
|
);
|
||||||
for (const itemToRemove of filteredItems) {
|
for (const itemToRemove of filteredItems) {
|
||||||
effects.error(`Trying to remove ${itemToRemove}`);
|
effects.error(`Trying to remove ${itemToRemove}`);
|
||||||
@@ -111,7 +111,7 @@ export class Backups {
|
|||||||
effects.removeFile({
|
effects.removeFile({
|
||||||
volumeId: Backups.BACKUP,
|
volumeId: Backups.BACKUP,
|
||||||
path: itemToRemove,
|
path: itemToRemove,
|
||||||
}),
|
})
|
||||||
)
|
)
|
||||||
.catch(() => {
|
.catch(() => {
|
||||||
effects.warn(`Failed to remove ${itemToRemove} from backup volume`);
|
effects.warn(`Failed to remove ${itemToRemove} from backup volume`);
|
||||||
|
|||||||
@@ -489,13 +489,13 @@ export class Config<A extends InputSpec> extends IBuilder<A> {
|
|||||||
}
|
}
|
||||||
static withValue<K extends string, B extends ValueSpec>(
|
static withValue<K extends string, B extends ValueSpec>(
|
||||||
key: K,
|
key: K,
|
||||||
value: Value<B>,
|
value: Value<B>
|
||||||
) {
|
) {
|
||||||
return Config.empty().withValue(key, value);
|
return Config.empty().withValue(key, value);
|
||||||
}
|
}
|
||||||
static addValue<K extends string, B extends ValueSpec>(
|
static addValue<K extends string, B extends ValueSpec>(
|
||||||
key: K,
|
key: K,
|
||||||
value: Value<B>,
|
value: Value<B>
|
||||||
) {
|
) {
|
||||||
return Config.empty().withValue(key, value);
|
return Config.empty().withValue(key, value);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ export class List<A extends ValueSpecList> extends IBuilder<A> {
|
|||||||
Default<string[]> & {
|
Default<string[]> & {
|
||||||
range: string;
|
range: string;
|
||||||
spec: StringSpec;
|
spec: StringSpec;
|
||||||
},
|
}
|
||||||
>(a: A) {
|
>(a: A) {
|
||||||
return new List({
|
return new List({
|
||||||
type: "list" as const,
|
type: "list" as const,
|
||||||
@@ -51,7 +51,7 @@ export class List<A extends ValueSpecList> extends IBuilder<A> {
|
|||||||
Default<number[]> & {
|
Default<number[]> & {
|
||||||
range: string;
|
range: string;
|
||||||
spec: NumberSpec;
|
spec: NumberSpec;
|
||||||
},
|
}
|
||||||
>(a: A) {
|
>(a: A) {
|
||||||
return new List({
|
return new List({
|
||||||
type: "list" as const,
|
type: "list" as const,
|
||||||
@@ -69,7 +69,7 @@ export class List<A extends ValueSpecList> extends IBuilder<A> {
|
|||||||
[key: string]: string;
|
[key: string]: string;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
},
|
}
|
||||||
>(a: A) {
|
>(a: A) {
|
||||||
return new List({
|
return new List({
|
||||||
type: "list" as const,
|
type: "list" as const,
|
||||||
@@ -86,7 +86,7 @@ export class List<A extends ValueSpecList> extends IBuilder<A> {
|
|||||||
"display-as": null | string;
|
"display-as": null | string;
|
||||||
"unique-by": null | UniqueBy;
|
"unique-by": null | UniqueBy;
|
||||||
};
|
};
|
||||||
},
|
}
|
||||||
>(a: A) {
|
>(a: A) {
|
||||||
const { spec: previousSpec, ...rest } = a;
|
const { spec: previousSpec, ...rest } = a;
|
||||||
const { spec: previousSpecSpec, ...restSpec } = previousSpec;
|
const { spec: previousSpecSpec, ...restSpec } = previousSpec;
|
||||||
@@ -127,7 +127,7 @@ export class List<A extends ValueSpecList> extends IBuilder<A> {
|
|||||||
default: string;
|
default: string;
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
B extends string,
|
B extends string
|
||||||
>(a: A) {
|
>(a: A) {
|
||||||
const { spec: previousSpec, ...rest } = a;
|
const { spec: previousSpec, ...rest } = a;
|
||||||
const { variants: previousVariants, ...restSpec } = previousSpec;
|
const { variants: previousVariants, ...restSpec } = previousSpec;
|
||||||
|
|||||||
@@ -80,7 +80,7 @@ export class Value<A extends ValueSpec> extends IBuilder<A> {
|
|||||||
A extends Description &
|
A extends Description &
|
||||||
NullableDefault<DefaultString> &
|
NullableDefault<DefaultString> &
|
||||||
Nullable &
|
Nullable &
|
||||||
StringSpec,
|
StringSpec
|
||||||
>(a: A) {
|
>(a: A) {
|
||||||
return new Value({
|
return new Value({
|
||||||
type: "string" as const,
|
type: "string" as const,
|
||||||
@@ -88,7 +88,7 @@ export class Value<A extends ValueSpec> extends IBuilder<A> {
|
|||||||
} as ValueSpecString);
|
} as ValueSpecString);
|
||||||
}
|
}
|
||||||
static number<
|
static number<
|
||||||
A extends Description & NullableDefault<number> & Nullable & NumberSpec,
|
A extends Description & NullableDefault<number> & Nullable & NumberSpec
|
||||||
>(a: A) {
|
>(a: A) {
|
||||||
return new Value({
|
return new Value({
|
||||||
type: "number" as const,
|
type: "number" as const,
|
||||||
@@ -100,7 +100,7 @@ export class Value<A extends ValueSpec> extends IBuilder<A> {
|
|||||||
Default<string> & {
|
Default<string> & {
|
||||||
values: readonly string[] | string[];
|
values: readonly string[] | string[];
|
||||||
"value-names": Record<string, string>;
|
"value-names": Record<string, string>;
|
||||||
},
|
}
|
||||||
>(a: A) {
|
>(a: A) {
|
||||||
return new Value({
|
return new Value({
|
||||||
type: "enum" as const,
|
type: "enum" as const,
|
||||||
@@ -117,7 +117,7 @@ export class Value<A extends ValueSpec> extends IBuilder<A> {
|
|||||||
"unique-by": null | string;
|
"unique-by": null | string;
|
||||||
spec: Config<InputSpec>;
|
spec: Config<InputSpec>;
|
||||||
"value-names": Record<string, string>;
|
"value-names": Record<string, string>;
|
||||||
},
|
}
|
||||||
>(a: A) {
|
>(a: A) {
|
||||||
const { spec: previousSpec, ...rest } = a;
|
const { spec: previousSpec, ...rest } = a;
|
||||||
const spec = previousSpec.build() as BuilderExtract<A["spec"]>;
|
const spec = previousSpec.build() as BuilderExtract<A["spec"]>;
|
||||||
@@ -143,7 +143,7 @@ export class Value<A extends ValueSpec> extends IBuilder<A> {
|
|||||||
"display-as": string | null;
|
"display-as": string | null;
|
||||||
"unique-by": UniqueBy;
|
"unique-by": UniqueBy;
|
||||||
},
|
},
|
||||||
B extends string,
|
B extends string
|
||||||
>(a: A) {
|
>(a: A) {
|
||||||
const { variants: previousVariants, ...rest } = a;
|
const { variants: previousVariants, ...rest } = a;
|
||||||
const variants = previousVariants.build() as BuilderExtract<A["variants"]>;
|
const variants = previousVariants.build() as BuilderExtract<A["variants"]>;
|
||||||
|
|||||||
@@ -39,12 +39,12 @@ import { Config } from ".";
|
|||||||
```
|
```
|
||||||
*/
|
*/
|
||||||
export class Variants<
|
export class Variants<
|
||||||
A extends { [key: string]: InputSpec },
|
A extends { [key: string]: InputSpec }
|
||||||
> extends IBuilder<A> {
|
> extends IBuilder<A> {
|
||||||
static of<
|
static of<
|
||||||
A extends {
|
A extends {
|
||||||
[key: string]: Config<InputSpec>;
|
[key: string]: Config<InputSpec>;
|
||||||
},
|
}
|
||||||
>(a: A) {
|
>(a: A) {
|
||||||
const variants: { [K in keyof A]: BuilderExtract<A[K]> } = {} as any;
|
const variants: { [K in keyof A]: BuilderExtract<A[K]> } = {} as any;
|
||||||
for (const key in a) {
|
for (const key in a) {
|
||||||
@@ -58,7 +58,7 @@ export class Variants<
|
|||||||
}
|
}
|
||||||
static withVariant<K extends string, B extends InputSpec>(
|
static withVariant<K extends string, B extends InputSpec>(
|
||||||
key: K,
|
key: K,
|
||||||
value: Config<B>,
|
value: Config<B>
|
||||||
) {
|
) {
|
||||||
return Variants.empty().withVariant(key, value);
|
return Variants.empty().withVariant(key, value);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,10 +10,10 @@ import { HealthResult } from "./healthRunner";
|
|||||||
*/
|
*/
|
||||||
export const checkWebUrl: (
|
export const checkWebUrl: (
|
||||||
url: string,
|
url: string,
|
||||||
createSuccess?: null | ((response?: string | null) => string),
|
createSuccess?: null | ((response?: string | null) => string)
|
||||||
) => (effects: Effects, duration: number) => Promise<HealthResult> = (
|
) => (effects: Effects, duration: number) => Promise<HealthResult> = (
|
||||||
url,
|
url,
|
||||||
createSuccess = null,
|
createSuccess = null
|
||||||
) => {
|
) => {
|
||||||
return async (effects, duration) => {
|
return async (effects, duration) => {
|
||||||
const errorValue = guardDurationAboveMinimum({
|
const errorValue = guardDurationAboveMinimum({
|
||||||
|
|||||||
@@ -4,16 +4,16 @@ import * as fs from "fs";
|
|||||||
export async function writeConvertedFile(
|
export async function writeConvertedFile(
|
||||||
file: string,
|
file: string,
|
||||||
inputData: Promise<any> | any,
|
inputData: Promise<any> | any,
|
||||||
options: Parameters<typeof makeFileContent>[1],
|
options: Parameters<typeof makeFileContent>[1]
|
||||||
) {
|
) {
|
||||||
await fs.writeFile(file, await makeFileContent(inputData, options), (err) =>
|
await fs.writeFile(file, await makeFileContent(inputData, options), (err) =>
|
||||||
console.error(err),
|
console.error(err)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export default async function makeFileContent(
|
export default async function makeFileContent(
|
||||||
inputData: Promise<any> | any,
|
inputData: Promise<any> | any,
|
||||||
{ startSdk = "start-sdk" } = {},
|
{ startSdk = "start-sdk" } = {}
|
||||||
) {
|
) {
|
||||||
const outputLines: string[] = [];
|
const outputLines: string[] = [];
|
||||||
outputLines.push(`
|
outputLines.push(`
|
||||||
@@ -25,10 +25,10 @@ export default async function makeFileContent(
|
|||||||
const configName = newConst("InputSpec", convertInputSpec(data));
|
const configName = newConst("InputSpec", convertInputSpec(data));
|
||||||
const configMatcherName = newConst(
|
const configMatcherName = newConst(
|
||||||
"matchInputSpec",
|
"matchInputSpec",
|
||||||
`${configName}.validator()`,
|
`${configName}.validator()`
|
||||||
);
|
);
|
||||||
outputLines.push(
|
outputLines.push(
|
||||||
`export type InputSpec = typeof ${configMatcherName}._TYPE;`,
|
`export type InputSpec = typeof ${configMatcherName}._TYPE;`
|
||||||
);
|
);
|
||||||
|
|
||||||
return outputLines.join("\n");
|
return outputLines.join("\n");
|
||||||
@@ -64,7 +64,7 @@ export default async function makeFileContent(
|
|||||||
textarea: value.textarea || null,
|
textarea: value.textarea || null,
|
||||||
},
|
},
|
||||||
null,
|
null,
|
||||||
2,
|
2
|
||||||
)})`;
|
)})`;
|
||||||
}
|
}
|
||||||
case "number": {
|
case "number": {
|
||||||
@@ -81,7 +81,7 @@ export default async function makeFileContent(
|
|||||||
placeholder: value.placeholder || null,
|
placeholder: value.placeholder || null,
|
||||||
},
|
},
|
||||||
null,
|
null,
|
||||||
2,
|
2
|
||||||
)})`;
|
)})`;
|
||||||
}
|
}
|
||||||
case "boolean": {
|
case "boolean": {
|
||||||
@@ -93,7 +93,7 @@ export default async function makeFileContent(
|
|||||||
warning: value.warning || null,
|
warning: value.warning || null,
|
||||||
},
|
},
|
||||||
null,
|
null,
|
||||||
2,
|
2
|
||||||
)})`;
|
)})`;
|
||||||
}
|
}
|
||||||
case "enum": {
|
case "enum": {
|
||||||
@@ -107,13 +107,13 @@ export default async function makeFileContent(
|
|||||||
"value-names": value["value-names"] || null,
|
"value-names": value["value-names"] || null,
|
||||||
},
|
},
|
||||||
null,
|
null,
|
||||||
2,
|
2
|
||||||
)})`;
|
)})`;
|
||||||
}
|
}
|
||||||
case "object": {
|
case "object": {
|
||||||
const specName = newConst(
|
const specName = newConst(
|
||||||
value.name + "_spec",
|
value.name + "_spec",
|
||||||
convertInputSpec(value.spec),
|
convertInputSpec(value.spec)
|
||||||
);
|
);
|
||||||
return `Value.object({
|
return `Value.object({
|
||||||
name: ${JSON.stringify(value.name || null)},
|
name: ${JSON.stringify(value.name || null)},
|
||||||
@@ -129,7 +129,7 @@ export default async function makeFileContent(
|
|||||||
case "union": {
|
case "union": {
|
||||||
const variants = newConst(
|
const variants = newConst(
|
||||||
value.name + "_variants",
|
value.name + "_variants",
|
||||||
convertVariants(value.variants),
|
convertVariants(value.variants)
|
||||||
);
|
);
|
||||||
return `Value.union({
|
return `Value.union({
|
||||||
name: ${JSON.stringify(value.name || null)},
|
name: ${JSON.stringify(value.name || null)},
|
||||||
@@ -147,7 +147,7 @@ export default async function makeFileContent(
|
|||||||
"display-as": ${JSON.stringify(value["display-as"] || null)},
|
"display-as": ${JSON.stringify(value["display-as"] || null)},
|
||||||
"unique-by": ${JSON.stringify(value["unique-by"] || null)},
|
"unique-by": ${JSON.stringify(value["unique-by"] || null)},
|
||||||
"variant-names": ${JSON.stringify(
|
"variant-names": ${JSON.stringify(
|
||||||
(value["variant-names"] as any) || null,
|
(value["variant-names"] as any) || null
|
||||||
)},
|
)},
|
||||||
})`;
|
})`;
|
||||||
}
|
}
|
||||||
@@ -182,7 +182,7 @@ export default async function makeFileContent(
|
|||||||
warning: value.warning || null,
|
warning: value.warning || null,
|
||||||
},
|
},
|
||||||
null,
|
null,
|
||||||
2,
|
2
|
||||||
)})`;
|
)})`;
|
||||||
}
|
}
|
||||||
case "number": {
|
case "number": {
|
||||||
@@ -201,7 +201,7 @@ export default async function makeFileContent(
|
|||||||
warning: value.warning || null,
|
warning: value.warning || null,
|
||||||
},
|
},
|
||||||
null,
|
null,
|
||||||
2,
|
2
|
||||||
)})`;
|
)})`;
|
||||||
}
|
}
|
||||||
case "enum": {
|
case "enum": {
|
||||||
@@ -218,13 +218,13 @@ export default async function makeFileContent(
|
|||||||
warning: value.warning || null,
|
warning: value.warning || null,
|
||||||
},
|
},
|
||||||
null,
|
null,
|
||||||
2,
|
2
|
||||||
)})`;
|
)})`;
|
||||||
}
|
}
|
||||||
case "object": {
|
case "object": {
|
||||||
const specName = newConst(
|
const specName = newConst(
|
||||||
value.name + "_spec",
|
value.name + "_spec",
|
||||||
convertInputSpec(value.spec.spec),
|
convertInputSpec(value.spec.spec)
|
||||||
);
|
);
|
||||||
return `List.obj({
|
return `List.obj({
|
||||||
name: ${JSON.stringify(value.name || null)},
|
name: ${JSON.stringify(value.name || null)},
|
||||||
@@ -232,7 +232,7 @@ export default async function makeFileContent(
|
|||||||
spec: {
|
spec: {
|
||||||
spec: ${specName},
|
spec: ${specName},
|
||||||
"display-as": ${JSON.stringify(
|
"display-as": ${JSON.stringify(
|
||||||
value?.spec?.["display-as"] || null,
|
value?.spec?.["display-as"] || null
|
||||||
)},
|
)},
|
||||||
"unique-by": ${JSON.stringify(value?.spec?.["unique-by"] || null)},
|
"unique-by": ${JSON.stringify(value?.spec?.["unique-by"] || null)},
|
||||||
},
|
},
|
||||||
@@ -244,7 +244,7 @@ export default async function makeFileContent(
|
|||||||
case "union": {
|
case "union": {
|
||||||
const variants = newConst(
|
const variants = newConst(
|
||||||
value.name + "_variants",
|
value.name + "_variants",
|
||||||
convertInputSpec(value.spec.variants),
|
convertInputSpec(value.spec.variants)
|
||||||
);
|
);
|
||||||
return `List.union(
|
return `List.union(
|
||||||
{
|
{
|
||||||
@@ -254,24 +254,24 @@ export default async function makeFileContent(
|
|||||||
tag: {
|
tag: {
|
||||||
"id":${JSON.stringify(value?.spec?.tag?.["id"] || null)},
|
"id":${JSON.stringify(value?.spec?.tag?.["id"] || null)},
|
||||||
"name": ${JSON.stringify(
|
"name": ${JSON.stringify(
|
||||||
value?.spec?.tag?.["name"] || null,
|
value?.spec?.tag?.["name"] || null
|
||||||
)},
|
)},
|
||||||
"description": ${JSON.stringify(
|
"description": ${JSON.stringify(
|
||||||
value?.spec?.tag?.["description"] || null,
|
value?.spec?.tag?.["description"] || null
|
||||||
)},
|
)},
|
||||||
"warning": ${JSON.stringify(
|
"warning": ${JSON.stringify(
|
||||||
value?.spec?.tag?.["warning"] || null,
|
value?.spec?.tag?.["warning"] || null
|
||||||
)},
|
)},
|
||||||
"variant-names": ${JSON.stringify(
|
"variant-names": ${JSON.stringify(
|
||||||
value?.spec?.tag?.["variant-names"] || {},
|
value?.spec?.tag?.["variant-names"] || {}
|
||||||
)},
|
)},
|
||||||
},
|
},
|
||||||
variants: ${variants},
|
variants: ${variants},
|
||||||
"display-as": ${JSON.stringify(
|
"display-as": ${JSON.stringify(
|
||||||
value?.spec?.["display-as"] || null,
|
value?.spec?.["display-as"] || null
|
||||||
)},
|
)},
|
||||||
"unique-by": ${JSON.stringify(
|
"unique-by": ${JSON.stringify(
|
||||||
value?.spec?.["unique-by"] || null,
|
value?.spec?.["unique-by"] || null
|
||||||
)},
|
)},
|
||||||
default: ${JSON.stringify(value?.spec?.["default"] || null)},
|
default: ${JSON.stringify(value?.spec?.["default"] || null)},
|
||||||
},
|
},
|
||||||
|
|||||||
13
lib/types.ts
13
lib/types.ts
@@ -269,6 +269,19 @@ export type Effects = {
|
|||||||
* @param configured
|
* @param configured
|
||||||
*/
|
*/
|
||||||
setConfigured(configured: boolean): Promise<void>;
|
setConfigured(configured: boolean): Promise<void>;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @returns PEM encoded fullchain (ecdsa)
|
||||||
|
*/
|
||||||
|
getSslCertificate: (
|
||||||
|
packageId: string,
|
||||||
|
algorithm?: "ecdsa" | "ed25519",
|
||||||
|
) => [string, string, string];
|
||||||
|
/**
|
||||||
|
* @returns PEM encoded ssl key (ecdsa)
|
||||||
|
*/
|
||||||
|
getSslKey: (packageId: string, algorithm?: "ecdsa" | "ed25519") => string;
|
||||||
};
|
};
|
||||||
|
|
||||||
/* rsync options: https://linux.die.net/man/1/rsync
|
/* rsync options: https://linux.die.net/man/1/rsync
|
||||||
|
|||||||
@@ -111,7 +111,7 @@ export interface ValueSpecListOf<T extends ListValueSpecType>
|
|||||||
// sometimes the type checker needs just a little bit of help
|
// sometimes the type checker needs just a little bit of help
|
||||||
export function isValueSpecListOf<S extends ListValueSpecType>(
|
export function isValueSpecListOf<S extends ListValueSpecType>(
|
||||||
t: ValueSpecList,
|
t: ValueSpecList,
|
||||||
s: S,
|
s: S
|
||||||
): t is ValueSpecListOf<S> {
|
): t is ValueSpecListOf<S> {
|
||||||
return t.subtype === s;
|
return t.subtype === s;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -56,7 +56,7 @@ export class FileHelper<A> {
|
|||||||
readonly path: string,
|
readonly path: string,
|
||||||
readonly volume: string,
|
readonly volume: string,
|
||||||
readonly writeData: (dataIn: A) => string,
|
readonly writeData: (dataIn: A) => string,
|
||||||
readonly readData: (stringValue: string) => A,
|
readonly readData: (stringValue: string) => A
|
||||||
) {}
|
) {}
|
||||||
async write(data: A, effects: T.Effects) {
|
async write(data: A, effects: T.Effects) {
|
||||||
let matched;
|
let matched;
|
||||||
@@ -86,21 +86,21 @@ export class FileHelper<A> {
|
|||||||
await effects.readFile({
|
await effects.readFile({
|
||||||
path: this.path,
|
path: this.path,
|
||||||
volumeId: this.volume,
|
volumeId: this.volume,
|
||||||
}),
|
})
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
static raw<A>(
|
static raw<A>(
|
||||||
path: string,
|
path: string,
|
||||||
volume: string,
|
volume: string,
|
||||||
toFile: (dataIn: A) => string,
|
toFile: (dataIn: A) => string,
|
||||||
fromFile: (rawData: string) => A,
|
fromFile: (rawData: string) => A
|
||||||
) {
|
) {
|
||||||
return new FileHelper<A>(path, volume, toFile, fromFile);
|
return new FileHelper<A>(path, volume, toFile, fromFile);
|
||||||
}
|
}
|
||||||
static json<A>(
|
static json<A>(
|
||||||
path: string,
|
path: string,
|
||||||
volume: string,
|
volume: string,
|
||||||
shape: matches.Validator<unknown, A>,
|
shape: matches.Validator<unknown, A>
|
||||||
) {
|
) {
|
||||||
return new FileHelper<A>(
|
return new FileHelper<A>(
|
||||||
path,
|
path,
|
||||||
@@ -110,13 +110,13 @@ export class FileHelper<A> {
|
|||||||
},
|
},
|
||||||
(inString) => {
|
(inString) => {
|
||||||
return shape.unsafeCast(JSON.parse(inString));
|
return shape.unsafeCast(JSON.parse(inString));
|
||||||
},
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
static toml<A extends Record<string, unknown>>(
|
static toml<A extends Record<string, unknown>>(
|
||||||
path: string,
|
path: string,
|
||||||
volume: string,
|
volume: string,
|
||||||
shape: matches.Validator<unknown, A>,
|
shape: matches.Validator<unknown, A>
|
||||||
) {
|
) {
|
||||||
return new FileHelper<A>(
|
return new FileHelper<A>(
|
||||||
path,
|
path,
|
||||||
@@ -126,13 +126,13 @@ export class FileHelper<A> {
|
|||||||
},
|
},
|
||||||
(inString) => {
|
(inString) => {
|
||||||
return shape.unsafeCast(TOML.parse(inString));
|
return shape.unsafeCast(TOML.parse(inString));
|
||||||
},
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
static yaml<A extends Record<string, unknown>>(
|
static yaml<A extends Record<string, unknown>>(
|
||||||
path: string,
|
path: string,
|
||||||
volume: string,
|
volume: string,
|
||||||
shape: matches.Validator<unknown, A>,
|
shape: matches.Validator<unknown, A>
|
||||||
) {
|
) {
|
||||||
return new FileHelper<A>(
|
return new FileHelper<A>(
|
||||||
path,
|
path,
|
||||||
@@ -142,7 +142,7 @@ export class FileHelper<A> {
|
|||||||
},
|
},
|
||||||
(inString) => {
|
(inString) => {
|
||||||
return shape.unsafeCast(YAML.parse(inString));
|
return shape.unsafeCast(YAML.parse(inString));
|
||||||
},
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,11 +7,11 @@ export { FileHelper } from "./fileHelper";
|
|||||||
/** Used to check if the file exists before hand */
|
/** Used to check if the file exists before hand */
|
||||||
export const exists = (
|
export const exists = (
|
||||||
effects: T.Effects,
|
effects: T.Effects,
|
||||||
props: { path: string; volumeId: string },
|
props: { path: string; volumeId: string }
|
||||||
) =>
|
) =>
|
||||||
effects.metadata(props).then(
|
effects.metadata(props).then(
|
||||||
(_) => true,
|
(_) => true,
|
||||||
(_) => false,
|
(_) => false
|
||||||
);
|
);
|
||||||
|
|
||||||
export const isKnownError = (e: unknown): e is T.KnownError =>
|
export const isKnownError = (e: unknown): e is T.KnownError =>
|
||||||
|
|||||||
@@ -107,7 +107,7 @@ function charRange(value = "") {
|
|||||||
*/
|
*/
|
||||||
export function generateDefault(
|
export function generateDefault(
|
||||||
generate: { charset: string; len: number },
|
generate: { charset: string; len: number },
|
||||||
{ random = () => Math.random() } = {},
|
{ random = () => Math.random() } = {}
|
||||||
) {
|
) {
|
||||||
const validCharSets: number[][] = generate.charset
|
const validCharSets: number[][] = generate.charset
|
||||||
.split(",")
|
.split(",")
|
||||||
@@ -118,7 +118,7 @@ export function generateDefault(
|
|||||||
}
|
}
|
||||||
const max = validCharSets.reduce(
|
const max = validCharSets.reduce(
|
||||||
(acc, x) => x.reduce((x, y) => Math.max(x, y), acc),
|
(acc, x) => x.reduce((x, y) => Math.max(x, y), acc),
|
||||||
0,
|
0
|
||||||
);
|
);
|
||||||
let i = 0;
|
let i = 0;
|
||||||
const answer: string[] = Array(generate.len);
|
const answer: string[] = Array(generate.len);
|
||||||
@@ -127,7 +127,7 @@ export function generateDefault(
|
|||||||
const inRange = validCharSets.reduce(
|
const inRange = validCharSets.reduce(
|
||||||
(acc, [lower, upper]) =>
|
(acc, [lower, upper]) =>
|
||||||
acc || (nextValue >= lower && nextValue <= upper),
|
acc || (nextValue >= lower && nextValue <= upper),
|
||||||
false,
|
false
|
||||||
);
|
);
|
||||||
if (!inRange) continue;
|
if (!inRange) continue;
|
||||||
answer[i] = String.fromCharCode(nextValue);
|
answer[i] = String.fromCharCode(nextValue);
|
||||||
@@ -155,7 +155,7 @@ export function matchNumberWithRange(range: string) {
|
|||||||
? "any"
|
? "any"
|
||||||
: left === "["
|
: left === "["
|
||||||
? `greaterThanOrEqualTo${leftValue}`
|
? `greaterThanOrEqualTo${leftValue}`
|
||||||
: `greaterThan${leftValue}`,
|
: `greaterThan${leftValue}`
|
||||||
)
|
)
|
||||||
.validate(
|
.validate(
|
||||||
// prettier-ignore
|
// prettier-ignore
|
||||||
@@ -165,7 +165,7 @@ export function matchNumberWithRange(range: string) {
|
|||||||
// prettier-ignore
|
// prettier-ignore
|
||||||
rightValue === "*" ? "any" :
|
rightValue === "*" ? "any" :
|
||||||
right === "]" ? `lessThanOrEqualTo${rightValue}` :
|
right === "]" ? `lessThanOrEqualTo${rightValue}` :
|
||||||
`lessThan${rightValue}`,
|
`lessThan${rightValue}`
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
function withIntegral(parser: matches.Parser<unknown, number>, value: unknown) {
|
function withIntegral(parser: matches.Parser<unknown, number>, value: unknown) {
|
||||||
@@ -186,12 +186,12 @@ const isGenerator = matches.shape({
|
|||||||
}).test;
|
}).test;
|
||||||
function defaultNullable<A>(
|
function defaultNullable<A>(
|
||||||
parser: matches.Parser<unknown, A>,
|
parser: matches.Parser<unknown, A>,
|
||||||
value: unknown,
|
value: unknown
|
||||||
) {
|
) {
|
||||||
if (matchDefault.test(value)) {
|
if (matchDefault.test(value)) {
|
||||||
if (isGenerator(value.default)) {
|
if (isGenerator(value.default)) {
|
||||||
return parser.defaultTo(
|
return parser.defaultTo(
|
||||||
parser.unsafeCast(generateDefault(value.default)),
|
parser.unsafeCast(generateDefault(value.default))
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
return parser.defaultTo(value.default);
|
return parser.defaultTo(value.default);
|
||||||
@@ -209,7 +209,7 @@ function defaultNullable<A>(
|
|||||||
* @returns
|
* @returns
|
||||||
*/
|
*/
|
||||||
export function guardAll<A extends ValueSpecAny>(
|
export function guardAll<A extends ValueSpecAny>(
|
||||||
value: A,
|
value: A
|
||||||
): matches.Parser<unknown, GuardAll<A>> {
|
): matches.Parser<unknown, GuardAll<A>> {
|
||||||
if (!isType.test(value)) {
|
if (!isType.test(value)) {
|
||||||
return matches.unknown as any;
|
return matches.unknown as any;
|
||||||
@@ -224,7 +224,7 @@ export function guardAll<A extends ValueSpecAny>(
|
|||||||
case "number":
|
case "number":
|
||||||
return defaultNullable(
|
return defaultNullable(
|
||||||
withIntegral(withRange(value), value),
|
withIntegral(withRange(value), value),
|
||||||
value,
|
value
|
||||||
) as any;
|
) as any;
|
||||||
|
|
||||||
case "object":
|
case "object":
|
||||||
@@ -244,14 +244,14 @@ export function guardAll<A extends ValueSpecAny>(
|
|||||||
matches
|
matches
|
||||||
.arrayOf(guardAll({ type: subtype, ...spec } as any))
|
.arrayOf(guardAll({ type: subtype, ...spec } as any))
|
||||||
.validate((x) => rangeValidate(x.length), "valid length"),
|
.validate((x) => rangeValidate(x.length), "valid length"),
|
||||||
value,
|
value
|
||||||
) as any;
|
) as any;
|
||||||
}
|
}
|
||||||
case "enum":
|
case "enum":
|
||||||
if (matchValues.test(value)) {
|
if (matchValues.test(value)) {
|
||||||
return defaultNullable(
|
return defaultNullable(
|
||||||
matches.literals(value.values[0], ...value.values),
|
matches.literals(value.values[0], ...value.values),
|
||||||
value,
|
value
|
||||||
) as any;
|
) as any;
|
||||||
}
|
}
|
||||||
return matches.unknown as any;
|
return matches.unknown as any;
|
||||||
@@ -261,8 +261,8 @@ export function guardAll<A extends ValueSpecAny>(
|
|||||||
...Object.entries(value.variants).map(([variant, spec]) =>
|
...Object.entries(value.variants).map(([variant, spec]) =>
|
||||||
matches
|
matches
|
||||||
.shape({ [value.tag.id]: matches.literal(variant) })
|
.shape({ [value.tag.id]: matches.literal(variant) })
|
||||||
.concat(typeFromProps(spec)),
|
.concat(typeFromProps(spec))
|
||||||
),
|
)
|
||||||
) as any;
|
) as any;
|
||||||
}
|
}
|
||||||
return matches.unknown as any;
|
return matches.unknown as any;
|
||||||
@@ -279,7 +279,7 @@ export function guardAll<A extends ValueSpecAny>(
|
|||||||
* @returns
|
* @returns
|
||||||
*/
|
*/
|
||||||
export function typeFromProps<A extends InputSpec>(
|
export function typeFromProps<A extends InputSpec>(
|
||||||
valueDictionary: A,
|
valueDictionary: A
|
||||||
): matches.Parser<unknown, TypeFromProps<A>> {
|
): matches.Parser<unknown, TypeFromProps<A>> {
|
||||||
if (!recordString.test(valueDictionary)) return matches.unknown as any;
|
if (!recordString.test(valueDictionary)) return matches.unknown as any;
|
||||||
return matches.shape(
|
return matches.shape(
|
||||||
@@ -287,7 +287,7 @@ export function typeFromProps<A extends InputSpec>(
|
|||||||
Object.entries(valueDictionary).map(([key, value]) => [
|
Object.entries(valueDictionary).map(([key, value]) => [
|
||||||
key,
|
key,
|
||||||
guardAll(value),
|
guardAll(value),
|
||||||
]),
|
])
|
||||||
),
|
)
|
||||||
) as any;
|
) as any;
|
||||||
}
|
}
|
||||||
|
|||||||
4
package-lock.json
generated
4
package-lock.json
generated
@@ -1,12 +1,12 @@
|
|||||||
{
|
{
|
||||||
"name": "start-sdk",
|
"name": "start-sdk",
|
||||||
"version": "0.4.0-lib0.alpha5",
|
"version": "0.4.0-lib0.alpha6",
|
||||||
"lockfileVersion": 2,
|
"lockfileVersion": 2,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"packages": {
|
"packages": {
|
||||||
"": {
|
"": {
|
||||||
"name": "start-sdk",
|
"name": "start-sdk",
|
||||||
"version": "0.4.0-lib0.alpha5",
|
"version": "0.4.0-lib0.alpha6",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@iarna/toml": "^2.2.5",
|
"@iarna/toml": "^2.2.5",
|
||||||
|
|||||||
Reference in New Issue
Block a user