diff --git a/types.ts b/types.ts index ded9656..ff56726 100644 --- a/types.ts +++ b/types.ts @@ -1,36 +1,21 @@ // deno-lint-ignore no-namespace export namespace ExpectedExports { /** Set configuration is called after we have modified and saved the configuration in the embassy ui. Use this to make a file for the docker to read from for configuration. */ - export type setConfig = ( - effects: Effects, - input: Config, - ) => Promise>; + export type setConfig = (effects: Effects, input: Config) => Promise>; /** Get configuration returns a shape that describes the format that the embassy ui will generate, and later send to the set config */ export type getConfig = (effects: Effects) => Promise>; /** These are how we make sure the our dependency configurations are valid and if not how to fix them. */ export type dependencies = Dependencies; /** Properties are used to get values from the docker, like a username + password, what ports we are hosting from */ - export type properties = ( - effects: Effects, - ) => Promise>; + export type properties = (effects: Effects) => Promise>; export type health = { /** Should be the health check id */ - [id: string]: ( - effects: Effects, - dateMs: number, - ) => Promise>; + [id: string]: (effects: Effects, dateMs: number) => Promise>; }; - export type migration = ( - effects: Effects, - version: string, - ...args: unknown[] - ) => Promise>; + export type migration = (effects: Effects, version: string, ...args: unknown[]) => Promise>; export type action = { - [id: string]: ( - effects: Effects, - config?: Config, - ) => Promise>; + [id: string]: (effects: Effects, config?: Config) => Promise>; }; /** @@ -43,9 +28,7 @@ export namespace ExpectedExports { /** Used to reach out from the pure js runtime */ export type Effects = { /** Usable when not sandboxed */ - writeFile( - input: { path: string; volumeId: string; toWrite: string }, - ): Promise; + writeFile(input: { path: string; volumeId: string; toWrite: string }): Promise; readFile(input: { volumeId: string; path: string }): Promise; metadata(input: { volumeId: string; path: string }): Promise; /** Create a directory. Usable when not sandboxed */ @@ -55,35 +38,18 @@ export type Effects = { removeFile(input: { volumeId: string; path: string }): Promise; /** Write a json file into an object. Usable when not sandboxed */ - writeJsonFile( - input: { volumeId: string; path: string; toWrite: Record }, - ): Promise; + writeJsonFile(input: { volumeId: string; path: string; toWrite: Record }): Promise; /** Read a json file into an object */ - readJsonFile( - input: { volumeId: string; path: string }, - ): Promise>; + readJsonFile(input: { volumeId: string; path: string }): Promise>; - runCommand( - input: { - command: string; - args?: string[]; - timeoutMillis?: number; - }, - ): Promise>; - runDaemon( - input: { - command: string; - args?: string[]; - }, - ): { + runCommand(input: { command: string; args?: string[]; timeoutMillis?: number }): Promise>; + runDaemon(input: { command: string; args?: string[] }): { wait(): Promise>; term(): Promise; }; - sleep( - timeMs: number, - ): Promise; + sleep(timeMs: number): Promise; /** Log at the trace level */ trace(whatToPrint: string): void; @@ -101,17 +67,14 @@ export type Effects = { exists(input: { volumeId: string; path: string }): Promise; - fetch(url: string, options?: { - method?: - | "GET" - | "POST" - | "PUT" - | "DELETE" - | "HEAD" - | "PATCH"; - headers?: Record; - body?: string; - }): Promise<{ + fetch( + url: string, + options?: { + method?: "GET" | "POST" | "PUT" | "DELETE" | "HEAD" | "PATCH"; + headers?: Record; + body?: string; + } + ): Promise<{ method: string; ok: boolean; status: number; @@ -196,8 +159,8 @@ export type Target = V & { export type UniqueBy = | { - any: UniqueBy[]; - } + any: UniqueBy[]; + } | string | null; @@ -207,22 +170,20 @@ export type WithNullable = T & { export type DefaultString = | string | { - /** The chars available for the randome generation */ - charset?: string; - /** Length that we generate to */ - len: number; - }; + /** The chars available for the randome generation */ + charset?: string; + /** Length that we generate to */ + len: number; + }; -export type ValueSpecString = - & ( - // deno-lint-ignore ban-types +export type ValueSpecString = // deno-lint-ignore ban-types + ( | {} | { - pattern: string; - "pattern-description": string; - } - ) - & { + pattern: string; + "pattern-description": string; + } + ) & { copyable?: boolean; masked?: boolean; placeholder?: string; @@ -238,71 +199,63 @@ export type ValueSpecNumber = { export type ValueSpecBoolean = Record; export type ValueSpecAny = | Tag<"boolean", WithDescription>> + | Tag<"string", WithDescription, DefaultString>>> + | Tag<"number", WithDescription, number>>> | Tag< - "string", - WithDescription< - WithNullableDefault, DefaultString> - > - > - | Tag< - "number", - WithDescription, number>> - > - | Tag< - "enum", - WithDescription< - WithDefault< - { - values: string[]; - "value-names": { - [key: string]: string; - }; - }, - string + "enum", + WithDescription< + WithDefault< + { + values: readonly string[] | string[]; + "value-names": { + [key: string]: string; + }; + }, + string + > > > - > | Tag<"list", ValueSpecList> | Tag<"object", WithDescription>> | Tag<"union", WithDescription>> | Tag< - "pointer", - WithDescription< - | Subtype< - "package", - | Target< - "tor-key", - { - "package-id": string; - interface: string; - } - > - | Target< - "tor-address", - { - "package-id": string; - interface: string; - } - > - | Target< - "lan-address", - { - "package-id": string; - interface: string; - } - > - | Target< - "config", - { - "package-id": string; - selector: string; - multi: boolean; - } - > + "pointer", + WithDescription< + | Subtype< + "package", + | Target< + "tor-key", + { + "package-id": string; + interface: string; + } + > + | Target< + "tor-address", + { + "package-id": string; + interface: string; + } + > + | Target< + "lan-address", + { + "package-id": string; + interface: string; + } + > + | Target< + "config", + { + "package-id": string; + selector: string; + multi: boolean; + } + > + > + | Subtype<"system", Record> > - | Subtype<"system", Record> - > - >; + >; export type ValueSpecUnion = { /** What tag for the specification, for tag unions */ tag: { @@ -326,39 +279,12 @@ export type ValueSpecObject = { "unique-by"?: UniqueBy; }; export type ValueSpecList = - | Subtype< - "boolean", - WithDescription, boolean[]>> - > - | Subtype< - "string", - WithDescription, string[]>> - > - | Subtype< - "number", - WithDescription, number[]>> - > - | Subtype< - "enum", - WithDescription< - WithDefault< - ListSpec< - ValueSpecEnum - >, - string[] - > - > - > - | Subtype< - "object", - WithDescription< - WithDefault, Record[]> - > - > - | Subtype< - "union", - WithDescription, string[]>> - >; + | Subtype<"boolean", WithDescription, boolean[]>>> + | Subtype<"string", WithDescription, string[]>>> + | Subtype<"number", WithDescription, number[]>>> + | Subtype<"enum", WithDescription, string[]>>> + | Subtype<"object", WithDescription, Record[]>>> + | Subtype<"union", WithDescription, string[]>>>; export type ValueSpecEnum = { values: string[]; "value-names": { [key: string]: string }; @@ -407,9 +333,11 @@ export type DependsOn = { [packageId: string]: string[]; }; -export type KnownError = { error: string } | { - "error-code": [number, string] | readonly [number, string]; -}; +export type KnownError = + | { error: string } + | { + "error-code": [number, string] | readonly [number, string]; + }; export type ResultType = KnownError | { result: T }; export type PackagePropertiesV2 = { diff --git a/utils/propertiesMatcher.test.ts b/utils/propertiesMatcher.test.ts index f7d5c90..7239228 100644 --- a/utils/propertiesMatcher.test.ts +++ b/utils/propertiesMatcher.test.ts @@ -73,7 +73,7 @@ const bitcoinProperties = { "Username and hashed password for JSON-RPC connections. RPC clients connect using the usual http basic authentication.", type: "list", subtype: "string", - default: [], + default: Array(), spec: { pattern: "^[a-zA-Z0-9_-]+:([0-9a-fA-F]{2})+\\$([0-9a-fA-F]{2})+$", "pattern-description": 'Each item must be of the form ":$".', @@ -241,7 +241,7 @@ const bitcoinProperties = { type: "list", subtype: "object", range: "[0,*)", - default: [], + default: Array>(), spec: { spec: { hostname: { @@ -424,7 +424,7 @@ const testUnionValue = anyValue as PM.GuardAll<{ }; }; variants: { - disabled: {}; + disabled: Record; automatic: { size: { type: "number"; @@ -469,7 +469,9 @@ const _testUnionBadUnion: size: number; } = testUnionValue; const _testAll: PM.TypeFromProps = anyValue as { + // deno-lint-ignore no-explicit-any "peer-tor-address": any; + // deno-lint-ignore no-explicit-any "rpc-tor-address": any; rpc: { enable: boolean; @@ -790,5 +792,51 @@ const { test } = Deno; }, }) ).toThrow(); + checker.unsafeCast({ + "peer-tor-address": "", + "rpc-tor-address": null, + rpc: { + enable: true, + username: "asdf", + password: "asdf", + advanced: { + auth: ["test:34$aa"], + serialversion: "non-segwit", + servertimeout: 12, + threads: 12, + workqueue: 12, + }, + }, + "zmq-enabled": false, + txindex: false, + wallet: { + enable: true, + avoidpartialspends: false, + discardfee: 0, + }, + advanced: { + mempool: { + mempoolfullrbf: false, + persistmempool: false, + maxmempool: 3012, + mempoolexpiry: 321, + }, + peers: { + listen: false, + onlyconnect: false, + onlyonion: false, + addnode: [{ hostname: "google.com", port: 231 }], + }, + dbcache: 123, + pruning: { mode: "automatic", size: 1234 }, + blockfilters: { + blockfilterindex: false, + peerblockfilters: false, + }, + bloomfilters: { + peerbloomfilters: false, + }, + }, + }); }); }