diff --git a/README.md b/README.md index b1812c8..03ca43b 100644 --- a/README.md +++ b/README.md @@ -1 +1 @@ -# embassy-sdk-ts \ No newline at end of file +# embassy-sdk-ts diff --git a/types.ts b/types.ts index 226dfd5..89c9a2d 100644 --- a/types.ts +++ b/types.ts @@ -1,315 +1,339 @@ // 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>; - /** 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>; + /** 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>; + /** 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 health = { - /** Should be the health check id */ - [id: string]: ( - effects: Effects, - dateMs: number, - ) => Promise>; - }; - export type migration = ( - effects: Effects, - version: string, - ) => Promise>; - export type action = { - [id: string]: ( - effects: Effects, - config?: Config - ) => Promise> - } + export type health = { + /** Should be the health check id */ + [id: string]: ( + effects: Effects, + dateMs: number, + ) => Promise>; + }; + export type migration = ( + effects: Effects, + version: string, + ) => Promise>; + export type action = { + [id: string]: ( + effects: Effects, + config?: Config, + ) => Promise>; + }; } - /** 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; - readFile(input: { volumeId: string; path: string }): Promise; - metadata(input: { volumeId: string; path: string }): Promise; - /** Create a directory. Usable when not sandboxed */ - createDir(input: { volumeId: string; path: string }): Promise; - /** Remove a directory. Usable when not sandboxed */ - removeDir(input: { volumeId: string; path: string }): Promise; - removeFile(input: { volumeId: string; path: string }): Promise; + /** Usable when not sandboxed */ + 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 */ + createDir(input: { volumeId: string; path: string }): Promise; + /** Remove a directory. Usable when not sandboxed */ + removeDir(input: { volumeId: string; path: string }): Promise; + 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; + /** Write a json file into an object. Usable when not sandboxed */ + writeJsonFile( + input: { volumeId: string; path: string; toWrite: Record }, + ): Promise; - /** Read a json file into an object */ - readJsonFile(input: { volumeId: string; path: string }): Promise>; + /** Read a json file into an object */ + readJsonFile( + input: { volumeId: string; path: string }, + ): Promise>; - /** Log at the trace level */ - trace(whatToPrint: string): void; - /** Log at the warn level */ - warn(whatToPrint: string): void; - /** Log at the error level */ - error(whatToPrint: string): void; - /** Log at the debug level */ - debug(whatToPrint: string): void; - /** Log at the info level */ - info(whatToPrint: string): void; + /** Log at the trace level */ + trace(whatToPrint: string): void; + /** Log at the warn level */ + warn(whatToPrint: string): void; + /** Log at the error level */ + error(whatToPrint: string): void; + /** Log at the debug level */ + debug(whatToPrint: string): void; + /** Log at the info level */ + info(whatToPrint: string): void; - /** Sandbox mode lets us read but not write */ - is_sandboxed(): boolean; + /** Sandbox mode lets us read but not write */ + is_sandboxed(): boolean; - exists(input: { volumeId: string; path: string }): Promise; + exists(input: { volumeId: string; path: string }): Promise; + fetch(url: string, options?: { + method?: + | "GET" + | "POST" + | "PUT" + | "DELETE" + | "HEAD" + | "PATCH"; + headers?: Record; + body?: string; + }): Promise<{ + method: string; + ok: boolean; + status: number; + headers: Record; + body?: string | null; + /// Returns the body as a string + text(): Promise; + /// Returns the body as a json + json(): Promise; + }>; }; export type Metadata = { - fileType: string, - isDir: boolean, - isFile: boolean, - isSymlink: boolean, - len: number, - modified?: Date, - accessed?: Date, - created?: Date, - readonly: boolean, - uid: number, - gid: number, - mode: number -} + fileType: string; + isDir: boolean; + isFile: boolean; + isSymlink: boolean; + len: number; + modified?: Date; + accessed?: Date; + created?: Date; + readonly: boolean; + uid: number; + gid: number; + mode: number; +}; export type MigrationRes = { - configured: boolean; + configured: boolean; }; export type ActionResult = { - version: "0"; - message: string; - value?: string; - copyable: boolean; - qr: boolean; + version: "0"; + message: string; + value?: string; + copyable: boolean; + qr: boolean; }; export type ConfigRes = { - /** This should be the previous config, that way during set config we start with the previous */ - config?: Config; - /** Shape that is describing the form in the ui */ - spec: ConfigSpec; + /** This should be the previous config, that way during set config we start with the previous */ + config?: Config; + /** Shape that is describing the form in the ui */ + spec: ConfigSpec; }; export type Config = { - [propertyName: string]: unknown; + [propertyName: string]: unknown; }; export type ConfigSpec = { - /** Given a config value, define what it should render with the following spec */ - [configValue: string]: ValueSpecAny; + /** Given a config value, define what it should render with the following spec */ + [configValue: string]: ValueSpecAny; }; export type WithDefault = T & { - default?: Default; + default?: Default; }; export type WithDescription = T & { - description?: string; - name: string; - warning?: string; + description?: string; + name: string; + warning?: string; }; export type ListSpec = { - spec: T; - range: string; + spec: T; + range: string; }; export type Tag = V & { - type: T; + type: T; }; export type Subtype = V & { - subtype: T; + subtype: T; }; export type Target = V & { - target: T; + target: T; }; export type UniqueBy = - | { - any: UniqueBy[]; - } - | string - | null; + | { + any: UniqueBy[]; + } + | string + | null; export type WithNullable = T & { - nullable: boolean; + nullable: boolean; }; export type DefaultString = - | string - | { - /** The chars available for the randome generation */ - charset?: string; - /** Length that we generate to */ - len: number; - }; + | string + | { + /** The chars available for the randome generation */ + charset?: string; + /** Length that we generate to */ + len: number; + }; export type ValueSpecString = - & ( - // deno-lint-ignore ban-types - | {} - | { - pattern: string; - "pattern-description": string; - } - ) - & { - copyable?: boolean; - masked?: boolean; - placeholder?: string; - }; + & ( + // deno-lint-ignore ban-types + | {} + | { + pattern: string; + "pattern-description": string; + } + ) + & { + copyable?: boolean; + masked?: boolean; + placeholder?: string; + }; export type ValueSpecNumber = { - /** Something like [3,6] or [0, *) */ - range?: string; - integral?: boolean; - /** Used a description of the units */ - units?: string; - placeholder?: number; + /** Something like [3,6] or [0, *) */ + range?: string; + integral?: boolean; + /** Used a description of the units */ + units?: string; + placeholder?: number; }; export type ValueSpecBoolean = Record; export type ValueSpecAny = - | Tag<"boolean", WithDescription>> - | Tag< - "string", - WithDescription, DefaultString>> - > - | Tag< - "number", - WithDescription, number>> - > - | Tag< - "enum", - WithDescription< - WithDefault< - { - values: 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; - } - > - > - | Subtype<"system", Record> - > - >; -export type ValueSpecUnion = { - /** What tag for the specification, for tag unions */ - tag: { - id: string; - name: string; - description?: string; - "variant-names": { + | Tag<"boolean", WithDescription>> + | Tag< + "string", + WithDescription, DefaultString>> + > + | Tag< + "number", + WithDescription, number>> + > + | Tag< + "enum", + WithDescription< + WithDefault< + { + values: 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; + } + > + > + | Subtype<"system", Record> + > + >; +export type ValueSpecUnion = { + /** What tag for the specification, for tag unions */ + tag: { + id: string; + name: string; + description?: string; + "variant-names": { + [key: string]: string; }; - /** The possible enum values */ - variants: { - [key: string]: ConfigSpec; - }; - "display-as"?: string; - "unique-by"?: UniqueBy; + }; + /** The possible enum values */ + variants: { + [key: string]: ConfigSpec; + }; + "display-as"?: string; + "unique-by"?: UniqueBy; }; export type ValueSpecObject = { - spec: ConfigSpec; - "display-as"?: string; - "unique-by"?: UniqueBy; + spec: ConfigSpec; + "display-as"?: string; + "unique-by"?: UniqueBy; }; export type ValueSpecList = - | Subtype< - "boolean", - WithDescription, boolean[]>> + | Subtype< + "boolean", + WithDescription, boolean[]>> + > + | Subtype< + "string", + WithDescription, string[]>> + > + | Subtype< + "number", + WithDescription, number[]>> + > + | Subtype< + "enum", + WithDescription< + WithDefault< + ListSpec< + ValueSpecEnum + >, + string[] + > > - | Subtype< - "string", - WithDescription, string[]>> + > + | Subtype< + "object", + WithDescription< + WithDefault, Record[]> > - | Subtype< - "number", - WithDescription, number[]>> - > - | Subtype< - "enum", - WithDescription< - WithDefault< - ListSpec< - ValueSpecEnum - >, - string[] - > - > - > - | Subtype< - "object", - WithDescription, Record[]>> - > - | Subtype< - "union", - WithDescription, string[]>> - >; + > + | Subtype< + "union", + WithDescription, string[]>> + >; export type ValueSpecEnum = { - values: string[]; - "value-names": { [key: string]: string }; + values: string[]; + "value-names": { [key: string]: string }; }; export type SetResult = { - /** These are the unix process signals */ - signal: + /** These are the unix process signals */ + signal: | "SIGTERM" | "SIGHUP" | "SIGINT" @@ -343,49 +367,49 @@ export type SetResult = { | "SIGSYS" | "SIGEMT" | "SIGINFO"; - "depends-on": DependsOn + "depends-on": DependsOn; }; export type DependsOn = { - [packageId: string]: string[]; + [packageId: string]: string[]; }; export type KnownError = { error: string } | { - "error-code": [number, string] | readonly [number, string]; + "error-code": [number, string] | readonly [number, string]; }; export type ResultType = KnownError | { result: T }; export type PackagePropertiesV2 = { - [name: string]: PackagePropertyObject | PackagePropertyString; + [name: string]: PackagePropertyObject | PackagePropertyString; }; export type PackagePropertyString = { - type: "string"; - description?: string; - value: string; - /** Let's the ui make this copyable button */ - copyable?: boolean; - /** Let the ui create a qr for this field */ - qr?: boolean; - /** Hiding the value unless toggled off for field */ - masked?: boolean; + type: "string"; + description?: string; + value: string; + /** Let's the ui make this copyable button */ + copyable?: boolean; + /** Let the ui create a qr for this field */ + qr?: boolean; + /** Hiding the value unless toggled off for field */ + masked?: boolean; }; export type PackagePropertyObject = { - value: PackagePropertiesV2; - type: "object"; - description: string; + value: PackagePropertiesV2; + type: "object"; + description: string; }; export type Properties = { - version: 2; - data: PackagePropertiesV2; + version: 2; + data: PackagePropertiesV2; }; export type Dependencies = { - /** Id is the id of the package, should be the same as the manifest */ - [id: string]: { - /** Checks are called to make sure that our dependency is in the correct shape. If a known error is returned we know that the dependency needs modification */ - check(effects: Effects, input: Config): Promise>; - /** This is called after we know that the dependency package needs a new configuration, this would be a transform for defaults */ - autoConfigure(effects: Effects, input: Config): Promise>; - }; -}; \ No newline at end of file + /** Id is the id of the package, should be the same as the manifest */ + [id: string]: { + /** Checks are called to make sure that our dependency is in the correct shape. If a known error is returned we know that the dependency needs modification */ + check(effects: Effects, input: Config): Promise>; + /** This is called after we know that the dependency package needs a new configuration, this would be a transform for defaults */ + autoConfigure(effects: Effects, input: Config): Promise>; + }; +};