diff --git a/packages/sessions/src/trackers/remote/sessions.gen.ts b/packages/sessions/src/trackers/remote/sessions.gen.ts index a85c8ce9d..f393d0717 100644 --- a/packages/sessions/src/trackers/remote/sessions.gen.ts +++ b/packages/sessions/src/trackers/remote/sessions.gen.ts @@ -5,72 +5,71 @@ // // webrpc-gen -schema=sessions.ridl -target=typescript -client -out=./clients/sessions.gen.ts -export const WebrpcHeader = "Webrpc" +export const WebrpcHeader = 'Webrpc' -export const WebrpcHeaderValue = "webrpc@v0.21.3;gen-typescript@v0.16.0;sessions@v0.0.1" +export const WebrpcHeaderValue = 'webrpc@v0.21.3;gen-typescript@v0.16.0;sessions@v0.0.1' // WebRPC description and code-gen version -export const WebRPCVersion = "v1" +export const WebRPCVersion = 'v1' // Schema version of your RIDL schema -export const WebRPCSchemaVersion = "v0.0.1" +export const WebRPCSchemaVersion = 'v0.0.1' // Schema hash generated from your RIDL schema -export const WebRPCSchemaHash = "e8a95eea9b72a50abe2c3b10d8a51c5c3fd8c631" +export const WebRPCSchemaHash = 'e8a95eea9b72a50abe2c3b10d8a51c5c3fd8c631' type WebrpcGenVersions = { - webrpcGenVersion: string; - codeGenName: string; - codeGenVersion: string; - schemaName: string; - schemaVersion: string; -}; + webrpcGenVersion: string + codeGenName: string + codeGenVersion: string + schemaName: string + schemaVersion: string +} export function VersionFromHeader(headers: Headers): WebrpcGenVersions { - const headerValue = headers.get(WebrpcHeader); + const headerValue = headers.get(WebrpcHeader) if (!headerValue) { return { - webrpcGenVersion: "", - codeGenName: "", - codeGenVersion: "", - schemaName: "", - schemaVersion: "", - }; + webrpcGenVersion: '', + codeGenName: '', + codeGenVersion: '', + schemaName: '', + schemaVersion: '' + } } - return parseWebrpcGenVersions(headerValue); + return parseWebrpcGenVersions(headerValue) } function parseWebrpcGenVersions(header: string): WebrpcGenVersions { - const versions = header.split(";"); + const versions = header.split(';') if (versions.length < 3) { return { - webrpcGenVersion: "", - codeGenName: "", - codeGenVersion: "", - schemaName: "", - schemaVersion: "", - }; + webrpcGenVersion: '', + codeGenName: '', + codeGenVersion: '', + schemaName: '', + schemaVersion: '' + } } - const [_, webrpcGenVersion] = versions[0].split("@"); - const [codeGenName, codeGenVersion] = versions[1].split("@"); - const [schemaName, schemaVersion] = versions[2].split("@"); + const [_, webrpcGenVersion] = versions[0].split('@') + const [codeGenName, codeGenVersion] = versions[1].split('@') + const [schemaName, schemaVersion] = versions[2].split('@') return { webrpcGenVersion, codeGenName, codeGenVersion, schemaName, - schemaVersion, - }; + schemaVersion + } } // // Types // - export enum SignatureType { EIP712 = 'EIP712', EthSign = 'EthSign', @@ -103,10 +102,10 @@ export interface ArweaveStatus { } export interface Info { - wallets: {[key: string]: number} - configs: {[key: string]: number} + wallets: { [key: string]: number } + configs: { [key: string]: number } configTrees: number - migrations: {[key: string]: number} + migrations: { [key: string]: number } signatures: number digests: number recorder: RecorderInfo @@ -118,7 +117,7 @@ export interface RecorderInfo { buffer: number lastFlush?: string lastFlushSeconds?: number - endpoints: {[key: string]: number} + endpoints: { [key: string]: number } } export interface ArweaveInfo { @@ -216,23 +215,29 @@ export interface Sessions { saveConfig(args: SaveConfigArgs, headers?: object, signal?: AbortSignal): Promise saveWallet(args: SaveWalletArgs, headers?: object, signal?: AbortSignal): Promise saveSignature(args: SaveSignatureArgs, headers?: object, signal?: AbortSignal): Promise - saveSignerSignatures(args: SaveSignerSignaturesArgs, headers?: object, signal?: AbortSignal): Promise - saveSignerSignatures2(args: SaveSignerSignatures2Args, headers?: object, signal?: AbortSignal): Promise + saveSignerSignatures( + args: SaveSignerSignaturesArgs, + headers?: object, + signal?: AbortSignal + ): Promise + saveSignerSignatures2( + args: SaveSignerSignatures2Args, + headers?: object, + signal?: AbortSignal + ): Promise saveMigration(args: SaveMigrationArgs, headers?: object, signal?: AbortSignal): Promise } -export interface PingArgs { -} +export interface PingArgs {} -export interface PingReturn { -} +export interface PingReturn {} export interface ConfigArgs { imageHash: string } export interface ConfigReturn { version: number - config: any + config: any } export interface WalletsArgs { signer: string @@ -241,8 +246,8 @@ export interface WalletsArgs { } export interface WalletsReturn { - wallets: {[key: string]: Signature} - cursor: number + wallets: { [key: string]: Signature } + cursor: number } export interface DeployHashArgs { wallet: string @@ -250,7 +255,7 @@ export interface DeployHashArgs { export interface DeployHashReturn { deployHash: string - context: Context + context: Context } export interface ConfigUpdatesArgs { wallet: string @@ -259,7 +264,7 @@ export interface ConfigUpdatesArgs { } export interface ConfigUpdatesReturn { - updates: Array + updates: Array } export interface MigrationsArgs { wallet: string @@ -269,22 +274,20 @@ export interface MigrationsArgs { } export interface MigrationsReturn { - migrations: {[key: string]: {[key: number]: {[key: string]: TransactionBundle}}} + migrations: { [key: string]: { [key: number]: { [key: string]: TransactionBundle } } } } export interface SaveConfigArgs { version: number config: any } -export interface SaveConfigReturn { -} +export interface SaveConfigReturn {} export interface SaveWalletArgs { version: number deployConfig: any } -export interface SaveWalletReturn { -} +export interface SaveWalletReturn {} export interface SaveSignatureArgs { wallet: string digest: string @@ -293,8 +296,7 @@ export interface SaveSignatureArgs { toConfig?: any } -export interface SaveSignatureReturn { -} +export interface SaveSignatureReturn {} export interface SaveSignerSignaturesArgs { wallet: string digest: string @@ -303,8 +305,7 @@ export interface SaveSignerSignaturesArgs { toConfig?: any } -export interface SaveSignerSignaturesReturn { -} +export interface SaveSignerSignaturesReturn {} export interface SaveSignerSignatures2Args { wallet: string digest: string @@ -313,8 +314,7 @@ export interface SaveSignerSignatures2Args { toConfig?: any } -export interface SaveSignerSignatures2Return { -} +export interface SaveSignerSignatures2Return {} export interface SaveMigrationArgs { wallet: string fromVersion: number @@ -327,11 +327,8 @@ export interface SaveMigrationArgs { chainID?: string } -export interface SaveMigrationReturn { -} - +export interface SaveMigrationReturn {} - // // Client // @@ -348,169 +345,187 @@ export class Sessions implements Sessions { private url(name: string): string { return this.hostname + this.path + name } - + ping = (headers?: object, signal?: AbortSignal): Promise => { - return this.fetch( - this.url('Ping'), - createHTTPRequest({}, headers, signal) - ).then((res) => { - return buildResponse(res).then(_data => { - return {} - }) - }, (error) => { - throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error.message || ''}` }) - }) + return this.fetch(this.url('Ping'), createHTTPRequest({}, headers, signal)).then( + res => { + return buildResponse(res).then(_data => { + return {} + }) + }, + error => { + throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error.message || ''}` }) + } + ) } - + config = (args: ConfigArgs, headers?: object, signal?: AbortSignal): Promise => { - return this.fetch( - this.url('Config'), - createHTTPRequest(args, headers, signal)).then((res) => { - return buildResponse(res).then(_data => { - return { - version: (_data.version), - config: (_data.config), - } - }) - }, (error) => { - throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error.message || ''}` }) - }) + return this.fetch(this.url('Config'), createHTTPRequest(args, headers, signal)).then( + res => { + return buildResponse(res).then(_data => { + return { + version: _data.version, + config: _data.config + } + }) + }, + error => { + throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error.message || ''}` }) + } + ) } - + wallets = (args: WalletsArgs, headers?: object, signal?: AbortSignal): Promise => { - return this.fetch( - this.url('Wallets'), - createHTTPRequest(args, headers, signal)).then((res) => { - return buildResponse(res).then(_data => { - return { - wallets: <{[key: string]: Signature}>(_data.wallets), - cursor: (_data.cursor), - } - }) - }, (error) => { - throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error.message || ''}` }) - }) + return this.fetch(this.url('Wallets'), createHTTPRequest(args, headers, signal)).then( + res => { + return buildResponse(res).then(_data => { + return { + wallets: <{ [key: string]: Signature }>_data.wallets, + cursor: _data.cursor + } + }) + }, + error => { + throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error.message || ''}` }) + } + ) } - + deployHash = (args: DeployHashArgs, headers?: object, signal?: AbortSignal): Promise => { - return this.fetch( - this.url('DeployHash'), - createHTTPRequest(args, headers, signal)).then((res) => { - return buildResponse(res).then(_data => { - return { - deployHash: (_data.deployHash), - context: (_data.context), - } - }) - }, (error) => { - throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error.message || ''}` }) - }) + return this.fetch(this.url('DeployHash'), createHTTPRequest(args, headers, signal)).then( + res => { + return buildResponse(res).then(_data => { + return { + deployHash: _data.deployHash, + context: _data.context + } + }) + }, + error => { + throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error.message || ''}` }) + } + ) } - + configUpdates = (args: ConfigUpdatesArgs, headers?: object, signal?: AbortSignal): Promise => { - return this.fetch( - this.url('ConfigUpdates'), - createHTTPRequest(args, headers, signal)).then((res) => { - return buildResponse(res).then(_data => { - return { - updates: >(_data.updates), - } - }) - }, (error) => { - throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error.message || ''}` }) - }) + return this.fetch(this.url('ConfigUpdates'), createHTTPRequest(args, headers, signal)).then( + res => { + return buildResponse(res).then(_data => { + return { + updates: >_data.updates + } + }) + }, + error => { + throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error.message || ''}` }) + } + ) } - + migrations = (args: MigrationsArgs, headers?: object, signal?: AbortSignal): Promise => { - return this.fetch( - this.url('Migrations'), - createHTTPRequest(args, headers, signal)).then((res) => { - return buildResponse(res).then(_data => { - return { - migrations: <{[key: string]: {[key: number]: {[key: string]: TransactionBundle}}}>(_data.migrations), - } - }) - }, (error) => { - throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error.message || ''}` }) - }) + return this.fetch(this.url('Migrations'), createHTTPRequest(args, headers, signal)).then( + res => { + return buildResponse(res).then(_data => { + return { + migrations: <{ [key: string]: { [key: number]: { [key: string]: TransactionBundle } } }>_data.migrations + } + }) + }, + error => { + throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error.message || ''}` }) + } + ) } - + saveConfig = (args: SaveConfigArgs, headers?: object, signal?: AbortSignal): Promise => { - return this.fetch( - this.url('SaveConfig'), - createHTTPRequest(args, headers, signal)).then((res) => { - return buildResponse(res).then(_data => { - return {} - }) - }, (error) => { - throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error.message || ''}` }) - }) + return this.fetch(this.url('SaveConfig'), createHTTPRequest(args, headers, signal)).then( + res => { + return buildResponse(res).then(_data => { + return {} + }) + }, + error => { + throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error.message || ''}` }) + } + ) } - + saveWallet = (args: SaveWalletArgs, headers?: object, signal?: AbortSignal): Promise => { - return this.fetch( - this.url('SaveWallet'), - createHTTPRequest(args, headers, signal)).then((res) => { - return buildResponse(res).then(_data => { - return {} - }) - }, (error) => { - throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error.message || ''}` }) - }) + return this.fetch(this.url('SaveWallet'), createHTTPRequest(args, headers, signal)).then( + res => { + return buildResponse(res).then(_data => { + return {} + }) + }, + error => { + throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error.message || ''}` }) + } + ) } - + saveSignature = (args: SaveSignatureArgs, headers?: object, signal?: AbortSignal): Promise => { - return this.fetch( - this.url('SaveSignature'), - createHTTPRequest(args, headers, signal)).then((res) => { - return buildResponse(res).then(_data => { - return {} - }) - }, (error) => { - throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error.message || ''}` }) - }) - } - - saveSignerSignatures = (args: SaveSignerSignaturesArgs, headers?: object, signal?: AbortSignal): Promise => { - return this.fetch( - this.url('SaveSignerSignatures'), - createHTTPRequest(args, headers, signal)).then((res) => { - return buildResponse(res).then(_data => { - return {} - }) - }, (error) => { - throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error.message || ''}` }) - }) - } - - saveSignerSignatures2 = (args: SaveSignerSignatures2Args, headers?: object, signal?: AbortSignal): Promise => { - return this.fetch( - this.url('SaveSignerSignatures2'), - createHTTPRequest(args, headers, signal)).then((res) => { - return buildResponse(res).then(_data => { - return {} - }) - }, (error) => { - throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error.message || ''}` }) - }) + return this.fetch(this.url('SaveSignature'), createHTTPRequest(args, headers, signal)).then( + res => { + return buildResponse(res).then(_data => { + return {} + }) + }, + error => { + throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error.message || ''}` }) + } + ) + } + + saveSignerSignatures = ( + args: SaveSignerSignaturesArgs, + headers?: object, + signal?: AbortSignal + ): Promise => { + return this.fetch(this.url('SaveSignerSignatures'), createHTTPRequest(args, headers, signal)).then( + res => { + return buildResponse(res).then(_data => { + return {} + }) + }, + error => { + throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error.message || ''}` }) + } + ) + } + + saveSignerSignatures2 = ( + args: SaveSignerSignatures2Args, + headers?: object, + signal?: AbortSignal + ): Promise => { + return this.fetch(this.url('SaveSignerSignatures2'), createHTTPRequest(args, headers, signal)).then( + res => { + return buildResponse(res).then(_data => { + return {} + }) + }, + error => { + throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error.message || ''}` }) + } + ) } - + saveMigration = (args: SaveMigrationArgs, headers?: object, signal?: AbortSignal): Promise => { - return this.fetch( - this.url('SaveMigration'), - createHTTPRequest(args, headers, signal)).then((res) => { - return buildResponse(res).then(_data => { - return {} - }) - }, (error) => { - throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error.message || ''}` }) - }) + return this.fetch(this.url('SaveMigration'), createHTTPRequest(args, headers, signal)).then( + res => { + return buildResponse(res).then(_data => { + return {} + }) + }, + error => { + throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error.message || ''}` }) + } + ) } - } - const createHTTPRequest = (body: object = {}, headers: object = {}, signal: AbortSignal | null = null): object => { - const reqHeaders: {[key: string]: string} = { ...headers, 'Content-Type': 'application/json' } +const createHTTPRequest = (body: object = {}, headers: object = {}, signal: AbortSignal | null = null): object => { + const reqHeaders: { [key: string]: string } = { ...headers, 'Content-Type': 'application/json' } reqHeaders[WebrpcHeader] = WebrpcHeaderValue return { @@ -526,18 +541,18 @@ const buildResponse = (res: Response): Promise => { let data try { data = JSON.parse(text) - } catch(error) { + } catch (error) { let message = '' - if (error instanceof Error) { + if (error instanceof Error) { message = error.message } throw WebrpcBadResponseError.new({ status: res.status, - cause: `JSON.parse(): ${message}: response text: ${text}`}, - ) + cause: `JSON.parse(): ${message}: response text: ${text}` + }) } if (!res.ok) { - const code: number = (typeof data.code === 'number') ? data.code : 0 + const code: number = typeof data.code === 'number' ? data.code : 0 throw (webrpcErrorByCode[code] || WebrpcError).new(data) } return data @@ -719,7 +734,6 @@ export class WebrpcStreamFinishedError extends WebrpcError { } } - // Schema errors export class InvalidArgumentError extends WebrpcError { @@ -736,19 +750,12 @@ export class InvalidArgumentError extends WebrpcError { } export class NotFoundError extends WebrpcError { - constructor( - name: string = 'NotFound', - code: number = 2, - message: string = 'not found', - status: number = 0, - cause?: string - ) { + constructor(name: string = 'NotFound', code: number = 2, message: string = 'not found', status: number = 0, cause?: string) { super(name, code, message, status, cause) Object.setPrototypeOf(this, NotFoundError.prototype) } } - export enum errors { WebrpcEndpoint = 'WebrpcEndpoint', WebrpcRequestFailed = 'WebrpcRequestFailed', @@ -762,7 +769,7 @@ export enum errors { WebrpcStreamLost = 'WebrpcStreamLost', WebrpcStreamFinished = 'WebrpcStreamFinished', InvalidArgument = 'InvalidArgument', - NotFound = 'NotFound', + NotFound = 'NotFound' } const webrpcErrorByCode: { [code: number]: any } = { @@ -778,8 +785,7 @@ const webrpcErrorByCode: { [code: number]: any } = { [-9]: WebrpcStreamLostError, [-10]: WebrpcStreamFinishedError, [1]: InvalidArgumentError, - [2]: NotFoundError, + [2]: NotFoundError } export type Fetch = (input: RequestInfo, init?: RequestInit) => Promise -