From dbdb075f18ba9fda8e9a84dc8d9f0c36da7909bd Mon Sep 17 00:00:00 2001 From: ThetaSinner Date: Thu, 21 Dec 2023 16:48:19 +0000 Subject: [PATCH] Please the linter --- ts/src/trycp/conductor/conductor.ts | 164 ++++++++++++++-------------- ts/src/trycp/trycp-client.ts | 11 +- ts/src/trycp/types.ts | 74 ++++++------- 3 files changed, 127 insertions(+), 122 deletions(-) diff --git a/ts/src/trycp/conductor/conductor.ts b/ts/src/trycp/conductor/conductor.ts index 97597b67..4fb56f2a 100644 --- a/ts/src/trycp/conductor/conductor.ts +++ b/ts/src/trycp/conductor/conductor.ts @@ -363,10 +363,10 @@ export class TryCpConductor implements IConductor { request: RegisterDnaRequest & DnaSource ): Promise => { const response = await this.callAdminApi({ - type: { "register_dna": null }, + type: { register_dna: null }, data: request, }); - assert(response.type.hasOwnProperty("dna_registered")); + assert("dna_registered" in response.type); return (response as AdminApiResponseDnaRegistered).data; }; @@ -380,10 +380,10 @@ export class TryCpConductor implements IConductor { dnaHash: GetDnaDefinitionRequest ): Promise => { const response = await this.callAdminApi({ - type: { "get_dna_definition": null }, + type: { get_dna_definition: null }, data: dnaHash, }); - assert(response.type.hasOwnProperty("dna_definition_returned")); + assert("dna_definition_returned" in response.type); return (response as AdminApiResponseDnasDefinitionReturned).data; }; @@ -397,10 +397,10 @@ export class TryCpConductor implements IConductor { request: GrantZomeCallCapabilityRequest ) => { const response = await this.callAdminApi({ - type: { "grant_zome_call_capability": null }, + type: { grant_zome_call_capability: null }, data: request, }); - assert(response.type.hasOwnProperty("zome_call_capability_granted")); + assert("zome_call_capability_granted" in response.type); }; /** @@ -410,9 +410,9 @@ export class TryCpConductor implements IConductor { */ const generateAgentPubKey = async (): Promise => { const response = await this.callAdminApi({ - type: { "generate_agent_pub_key": null }, + type: { generate_agent_pub_key: null }, }); - assert(response.type.hasOwnProperty("agent_pub_key_generated")); + assert("agent_pub_key_generated" in response.type); return (response as AdminApiResponseAgentPubKeyGenerated).data; }; @@ -424,10 +424,10 @@ export class TryCpConductor implements IConductor { */ const installApp = async (data: InstallAppRequest) => { const response = await this.callAdminApi({ - type: { "install_app": null }, + type: { install_app: null }, data, }); - assert(response.type.hasOwnProperty("app_installed")); + assert("app_installed" in response.type); return (response as AdminApiResponseAppInstalled).data; }; @@ -439,10 +439,10 @@ export class TryCpConductor implements IConductor { */ const enableApp = async (request: EnableAppRequest) => { const response = await this.callAdminApi({ - type: { "enable_app": null }, + type: { enable_app: null }, data: request, }); - assert(response.type.hasOwnProperty("app_enabled")); + assert("app_enabled" in response.type); return (response as AdminApiResponseAppEnabled).data; }; @@ -454,10 +454,10 @@ export class TryCpConductor implements IConductor { */ const disableApp = async (request: DisableAppRequest) => { const response = await this.callAdminApi({ - type: { "disable_app": null }, + type: { disable_app: null }, data: request, }); - assert(response.type.hasOwnProperty("app_disabled")); + assert("app_disabled" in response.type); return (response as AdminApiResponseAppDisabled).data; }; @@ -469,10 +469,10 @@ export class TryCpConductor implements IConductor { */ const startApp = async (request: StartAppRequest) => { const response = await this.callAdminApi({ - type: { "start_app": null }, + type: { start_app: null }, data: request, }); - assert(response.type.hasOwnProperty("app_started")); + assert("app_started" in response.type); return (response as AdminApiResponseAppStarted).data; }; @@ -484,10 +484,10 @@ export class TryCpConductor implements IConductor { */ const uninstallApp = async (request: UninstallAppRequest) => { const response = await this.callAdminApi({ - type: { "uninstall_app": null }, + type: { uninstall_app: null }, data: request, }); - assert(response.type.hasOwnProperty("app_uninstalled")); + assert("app_uninstalled" in response.type); return (response as AdminApiResponseAppUninstalled).data; }; @@ -499,10 +499,10 @@ export class TryCpConductor implements IConductor { */ const updateCoordinators = async (request: UpdateCoordinatorsRequest) => { const response = await this.callAdminApi({ - type: { "update_coordinators": null }, + type: { update_coordinators: null }, data: request, }); - assert(response.type.hasOwnProperty("coordinators_updated")); + assert("coordinators_updated" in response.type); return (response as AdminApiResponseCoordinatorsUpdated).data; }; @@ -514,10 +514,10 @@ export class TryCpConductor implements IConductor { */ const listApps = async (request: ListAppsRequest) => { const response = await this.callAdminApi({ - type: { "list_apps": null }, + type: { list_apps: null }, data: request, }); - assert(response.type.hasOwnProperty("apps_listed")); + assert("apps_listed" in response.type); return (response as AdminApiResponseAppsListed).data; }; @@ -527,8 +527,10 @@ export class TryCpConductor implements IConductor { * @returns A list of all installed {@link Cell} ids. */ const listCellIds = async () => { - const response = await this.callAdminApi({ type: { "list_cell_ids": null } }); - assert(response.type.hasOwnProperty("cell_ids_listed")); + const response = await this.callAdminApi({ + type: { list_cell_ids: null }, + }); + assert("cell_ids_listed" in response.type); return (response as AdminApiResponseCellIdsListed).data; }; @@ -538,8 +540,8 @@ export class TryCpConductor implements IConductor { * @returns A list of all installed DNAs' role ids. */ const listDnas = async () => { - const response = await this.callAdminApi({ type: { "list_dnas": null } }); - assert(response.type.hasOwnProperty("dnas_listed")); + const response = await this.callAdminApi({ type: { list_dnas: null } }); + assert("dnas_listed" in response.type); return (response as AdminApiResponseDnasListed).data; }; @@ -554,11 +556,13 @@ export class TryCpConductor implements IConductor { port: await getPort({ port: portNumbers(30000, 40000) }), }; const response = await this.callAdminApi({ - type: { "attach_app_interface": null }, + type: { attach_app_interface: null }, data: request, }); - assert(response.type.hasOwnProperty("app_interface_attached")); - return { port: (response as AdminApiResponseAppInterfaceAttached).data.port }; + assert("app_interface_attached" in response.type); + return { + port: (response as AdminApiResponseAppInterfaceAttached).data.port, + }; }; /** @@ -567,8 +571,10 @@ export class TryCpConductor implements IConductor { * @returns A list of all attached App interfaces. */ const listAppInterfaces = async () => { - const response = await this.callAdminApi({ type: { "list_app_interfaces": null } }); - assert(response.type.hasOwnProperty("app_interfaces_listed")); + const response = await this.callAdminApi({ + type: { list_app_interfaces: null }, + }); + assert("app_interfaces_listed" in response.type); return (response as AdminApiResponseAppInterfacesListed).data; }; @@ -580,12 +586,12 @@ export class TryCpConductor implements IConductor { */ const agentInfo = async (req: AgentInfoRequest) => { const response = await this.callAdminApi({ - type: { "agent_info": null }, + type: { agent_info: null }, data: { cell_id: req.cell_id || null, }, }); - assert(response.type.hasOwnProperty("agent_info")); + assert("agent_info" in response.type); return (response as AdminApiResponseAgentInfo).data; }; @@ -596,10 +602,10 @@ export class TryCpConductor implements IConductor { */ const addAgentInfo = async (request: AddAgentInfoRequest) => { const response = await this.callAdminApi({ - type: { "add_agent_info": null }, + type: { add_agent_info: null }, data: request, }); - assert(response.type.hasOwnProperty("agent_info_added")); + assert("agent_info_added" in response.type); }; /** @@ -609,10 +615,10 @@ export class TryCpConductor implements IConductor { */ const deleteCloneCell = async (request: DeleteCloneCellRequest) => { const response = await this.callAdminApi({ - type: { "delete_clone_cell": null }, + type: { delete_clone_cell: null }, data: request, }); - assert(response.type.hasOwnProperty("clone_cell_deleted")); + assert("clone_cell_deleted" in response.type); }; /** @@ -623,7 +629,7 @@ export class TryCpConductor implements IConductor { */ const dumpState = async (request: DumpStateRequest) => { const response = await this.callAdminApi({ - type: { "dump_state": null }, + type: { dump_state: null }, data: request, }); assert("data" in response); @@ -640,10 +646,10 @@ export class TryCpConductor implements IConductor { */ const dumpFullState = async (request: DumpFullStateRequest) => { const response = await this.callAdminApi({ - type: { "dump_full_state": null }, + type: { dump_full_state: null }, data: request, }); - assert(response.type.hasOwnProperty("full_state_dumped")); + assert("full_state_dumped" in response.type); return (response as AdminApiResponseFullStateDumped).data; }; @@ -655,10 +661,10 @@ export class TryCpConductor implements IConductor { */ const dumpNetworkStats = async (request: DumpNetworkStatsRequest) => { const response = await this.callAdminApi({ - type: { "dump_network_stats": null }, + type: { dump_network_stats: null }, data: request, }); - assert(response.type.hasOwnProperty("network_stats_dumped")); + assert("network_stats_dumped" in response.type); return (response as AdminApiResponseNetworkStatsDumped).data; }; @@ -670,10 +676,10 @@ export class TryCpConductor implements IConductor { */ const storageInfo = async (request: StorageInfoRequest) => { const response = await this.callAdminApi({ - type: { "storage_info": null }, + type: { storage_info: null }, data: request, }); - assert(response.type.hasOwnProperty("storage_info")); + assert("storage_info" in response.type); return (response as AdminApiResponseStorageInfo).data; }; @@ -788,10 +794,10 @@ export class TryCpConductor implements IConductor { */ const appInfo = async (request: AppInfoRequest) => { const response = await this.callAppApi(port, { - type: { "app_info": null }, + type: { app_info: null }, data: request, }); - assert(response.type.hasOwnProperty("app_info")); + assert("app_info" in response.type); return (response as AppApiResponseAppInfo).data; }; @@ -824,7 +830,7 @@ export class TryCpConductor implements IConductor { signedRequest = signedZomeCall; } const response = await this.callAppApi(port, { - type: { "call_zome": null }, + type: { call_zome: null }, data: signedRequest, }); assert("data" in response); @@ -844,10 +850,10 @@ export class TryCpConductor implements IConductor { */ const createCloneCell = async (request: CreateCloneCellRequest) => { const response = await this.callAppApi(port, { - type: { "create_clone_cell": null }, + type: { create_clone_cell: null }, data: request, }); - assert(response.type.hasOwnProperty("clone_cell_created")); + assert("clone_cell_created" in response.type); return (response as AppApiResponseCloneCellCreated).data; }; @@ -860,10 +866,10 @@ export class TryCpConductor implements IConductor { */ const enableCloneCell = async (request: EnableCloneCellRequest) => { const response = await this.callAppApi(port, { - type: { "enable_clone_cell": null }, + type: { enable_clone_cell: null }, data: request, }); - assert(response.type.hasOwnProperty("clone_cell_enabled")); + assert("clone_cell_enabled" in response.type); return (response as AppApiResponseCloneCellEnabled).data; }; @@ -875,10 +881,10 @@ export class TryCpConductor implements IConductor { */ const disableCloneCell = async (request: DisableCloneCellRequest) => { const response = await this.callAppApi(port, { - type: { "disable_clone_cell": null }, + type: { disable_clone_cell: null }, data: request, }); - assert(response.type.hasOwnProperty("clone_cell_disabled")); + assert("clone_cell_disabled" in response.type); return (response as AppApiResponseCloneCellDisabled).data; }; @@ -890,10 +896,10 @@ export class TryCpConductor implements IConductor { */ const networkInfo = async (request: NetworkInfoRequest) => { const response = await this.callAppApi(port, { - type: { "network_info": null }, + type: { network_info: null }, data: request, }); - assert(response.type.hasOwnProperty("network_info")); + assert("network_info" in response.type); return (response as AppApiResponseNetworkInfo).data; }; @@ -1009,19 +1015,19 @@ export class TryCpConductor implements IConductor { const installAppRequest: InstallAppRequest = "bundle" in appBundleSource ? { - bundle: appBundleSource.bundle, - agent_key, - membrane_proofs, - installed_app_id, - network_seed, - } + bundle: appBundleSource.bundle, + agent_key, + membrane_proofs, + installed_app_id, + network_seed, + } : { - path: appBundleSource.path, - agent_key, - membrane_proofs, - installed_app_id, - network_seed, - }; + path: appBundleSource.path, + agent_key, + membrane_proofs, + installed_app_id, + network_seed, + }; return this.adminWs().installApp(installAppRequest); } @@ -1043,19 +1049,19 @@ export class TryCpConductor implements IConductor { const installAppRequest: InstallAppRequest = "bundle" in appForAgent.app ? { - bundle: appForAgent.app.bundle, - agent_key, - membrane_proofs, - installed_app_id, - network_seed, - } + bundle: appForAgent.app.bundle, + agent_key, + membrane_proofs, + installed_app_id, + network_seed, + } : { - path: appForAgent.app.path, - agent_key, - membrane_proofs, - installed_app_id, - network_seed, - }; + path: appForAgent.app.path, + agent_key, + membrane_proofs, + installed_app_id, + network_seed, + }; logger.debug( `installing app with id ${installed_app_id} for agent ${encodeHashToBase64( diff --git a/ts/src/trycp/trycp-client.ts b/ts/src/trycp/trycp-client.ts index 458775c9..61492fa4 100644 --- a/ts/src/trycp/trycp-client.ts +++ b/ts/src/trycp/trycp-client.ts @@ -266,10 +266,11 @@ export class TryCpClient { return response; } - const deserializedApiResponse: TryCpApiResponse = deserializeApiResponse(response); + const deserializedApiResponse: TryCpApiResponse = + deserializeApiResponse(response); // when the request fails, the response's type is "error" - if (deserializedApiResponse.type.hasOwnProperty("error")) { + if ("error" in deserializedApiResponse.type) { const errorMessage = `error response from Admin API\n${JSON.stringify( (deserializedApiResponse as ApiErrorResponse).data, null, @@ -311,7 +312,7 @@ export class TryCpClient { if ( debugLog.type === "call_app_interface" && "data" in debugLog.message && - debugLog.message.type.hasOwnProperty("call_zome") + "call_zome" in debugLog.message.type ) { const messageData = debugLog.message.data as CallZomeRequestSigned; debugLog.message.data = Object.assign(debugLog.message.data, { @@ -319,9 +320,7 @@ export class TryCpClient { Buffer.from(messageData.cell_id[0]).toString("base64"), Buffer.from(messageData.cell_id[1]).toString("base64"), ], - provenance: Buffer.from(messageData.provenance).toString( - "base64" - ), + provenance: Buffer.from(messageData.provenance).toString("base64"), }); } if ("content" in request) { diff --git a/ts/src/trycp/types.ts b/ts/src/trycp/types.ts index b018ea48..8b11e5f2 100644 --- a/ts/src/trycp/types.ts +++ b/ts/src/trycp/types.ts @@ -252,7 +252,7 @@ export type TryCpApiResponse = * @public */ export interface ApiErrorResponse { - type: { "error": null }; + type: { error: null }; data: { type: string; data: string }; } @@ -313,7 +313,7 @@ export type RequestCallAppInterfaceMessage = * @public */ export interface RequestCallZome { - type: { "call_zome": null }; + type: { call_zome: null }; data: CallZomeRequestSigned; } @@ -323,7 +323,7 @@ export interface RequestCallZome { * @public */ export interface RequestAppInfo { - type: { "app_info": null }; + type: { app_info: null }; data: { installed_app_id: string }; } @@ -333,7 +333,7 @@ export interface RequestAppInfo { * @public */ export interface RequestCreateCloneCell { - type: { "create_clone_cell": null }; + type: { create_clone_cell: null }; data: CreateCloneCellRequest; } @@ -343,7 +343,7 @@ export interface RequestCreateCloneCell { * @public */ export interface RequestDisableCloneCell { - type: { "disable_clone_cell": null }; + type: { disable_clone_cell: null }; data: DisableCloneCellRequest; } @@ -353,7 +353,7 @@ export interface RequestDisableCloneCell { * @public */ export interface RequestEnableCloneCell { - type: { "enable_clone_cell": null }; + type: { enable_clone_cell: null }; data: EnableCloneCellRequest; } @@ -363,7 +363,7 @@ export interface RequestEnableCloneCell { * @public */ export interface RequestNetworkInfo { - type: { "network_info": null }; + type: { network_info: null }; data: NetworkInfoRequest; } @@ -394,7 +394,7 @@ export type AppApiResponse = * @public */ export interface AppApiResponseAppInfo { - type: { "app_info": null }; + type: { app_info: null }; data: AppInfoResponse; } @@ -402,7 +402,7 @@ export interface AppApiResponseAppInfo { * @public */ export interface AppApiResponseZomeCall { - type: { "zome_call": null }; + type: { zome_call: null }; data: Uint8Array; } @@ -410,7 +410,7 @@ export interface AppApiResponseZomeCall { * @public */ export interface AppApiResponseCloneCellCreated { - type: { "clone_cell_created": null }; + type: { clone_cell_created: null }; data: CreateCloneCellResponse; } @@ -418,7 +418,7 @@ export interface AppApiResponseCloneCellCreated { * @public */ export interface AppApiResponseCloneCellEnabled { - type: { "clone_cell_enabled": null }; + type: { clone_cell_enabled: null }; data: EnableCloneCellResponse; } @@ -426,7 +426,7 @@ export interface AppApiResponseCloneCellEnabled { * @public */ export interface AppApiResponseCloneCellDisabled { - type: { "clone_cell_disabled": null }; + type: { clone_cell_disabled: null }; data: DisableCloneCellResponse; } @@ -434,7 +434,7 @@ export interface AppApiResponseCloneCellDisabled { * @public */ export interface AppApiResponseNetworkInfo { - type: { "network_info": null }; + type: { network_info: null }; data: NetworkInfoResponse; } @@ -453,7 +453,7 @@ export interface RequestCallAdminInterface { /** * The types of all possible calls to the Admin API. - * + * * @public */ export interface RequestAdminInterfaceMessageType { @@ -543,7 +543,7 @@ export type AdminApiResponse = * @public */ export interface AdminApiResponseAgentInfo { - type: { "agent_info": null }; + type: { agent_info: null }; data: AgentInfoResponse; } @@ -553,7 +553,7 @@ export interface AdminApiResponseAgentInfo { * @public */ export interface RequestDeleteCloneCell { - type: { "delete_clone_cell": null }; + type: { delete_clone_cell: null }; data: DeleteCloneCellRequest; } @@ -561,7 +561,7 @@ export interface RequestDeleteCloneCell { * @public */ export interface AdminApiResponseDnaRegistered { - type: { "dna_registered": null }; + type: { dna_registered: null }; data: HoloHash; } @@ -569,7 +569,7 @@ export interface AdminApiResponseDnaRegistered { * @public */ export interface AdminApiResponseFullStateDumped { - type: { "full_state_dumped": null }; + type: { full_state_dumped: null }; data: FullStateDump; } @@ -577,7 +577,7 @@ export interface AdminApiResponseFullStateDumped { * @public */ export interface AdminApiResponseNetworkStatsDumped { - type: { "network_stats_dumped": null }; + type: { network_stats_dumped: null }; data: DumpNetworkStatsResponse; } @@ -585,7 +585,7 @@ export interface AdminApiResponseNetworkStatsDumped { * @public */ export interface AdminApiResponseStorageInfo { - type: { "storage_info": null }; + type: { storage_info: null }; data: StorageInfoResponse; } @@ -593,7 +593,7 @@ export interface AdminApiResponseStorageInfo { * @public */ export interface AdminApiResponseStateDumped { - type: { "state_dumped": null }; + type: { state_dumped: null }; data: DumpStateResponse; } @@ -601,14 +601,14 @@ export interface AdminApiResponseStateDumped { * @public */ export interface AdminApiResponseZomeCallCapabilityGranted { - type: { "zome_call_capability_granted": null }; + type: { zome_call_capability_granted: null }; } /** * @public */ export interface AdminApiResponseAgentPubKeyGenerated { - type: { "agent_pub_key_generated": null }; + type: { agent_pub_key_generated: null }; data: HoloHash; } @@ -616,7 +616,7 @@ export interface AdminApiResponseAgentPubKeyGenerated { * @public */ export interface AdminApiResponseAppInstalled { - type: { "app_installed": null }; + type: { app_installed: null }; data: AppInfo; } @@ -624,7 +624,7 @@ export interface AdminApiResponseAppInstalled { * @public */ export interface AdminApiResponseAppEnabled { - type: { "app_enabled": null }; + type: { app_enabled: null }; data: EnableAppResponse; } @@ -632,7 +632,7 @@ export interface AdminApiResponseAppEnabled { * @public */ export interface AdminApiResponseAppDisabled { - type: { "app_disabled": null }; + type: { app_disabled: null }; data: DisableAppResponse; } @@ -640,7 +640,7 @@ export interface AdminApiResponseAppDisabled { * @public */ export interface AdminApiResponseAppStarted { - type: { "app_started": null }; + type: { app_started: null }; data: StartAppResponse; } @@ -648,7 +648,7 @@ export interface AdminApiResponseAppStarted { * @public */ export interface AdminApiResponseAppUninstalled { - type: { "app_uninstalled": null }; + type: { app_uninstalled: null }; data: UninstallAppResponse; } @@ -656,7 +656,7 @@ export interface AdminApiResponseAppUninstalled { * @public */ export interface AdminApiResponseCoordinatorsUpdated { - type: { "coordinators_updated": null }; + type: { coordinators_updated: null }; data: UpdateCoordinatorsResponse; } @@ -664,7 +664,7 @@ export interface AdminApiResponseCoordinatorsUpdated { * @public */ export interface AdminApiResponseAppsListed { - type: { "apps_listed": null }; + type: { apps_listed: null }; data: ListAppsResponse; } @@ -672,7 +672,7 @@ export interface AdminApiResponseAppsListed { * @public */ export interface AdminApiResponseAppInterfacesListed { - type: { "app_interfaces_listed": null }; + type: { app_interfaces_listed: null }; data: ListAppInterfacesResponse; } @@ -680,7 +680,7 @@ export interface AdminApiResponseAppInterfacesListed { * @public */ export interface AdminApiResponseCellIdsListed { - type: { "cell_ids_listed": null }; + type: { cell_ids_listed: null }; data: ListCellIdsResponse; } @@ -688,7 +688,7 @@ export interface AdminApiResponseCellIdsListed { * @public */ export interface AdminApiResponseDnasDefinitionReturned { - type: { "dna_definition_returned": null }; + type: { dna_definition_returned: null }; data: DnaDefinition; } @@ -696,7 +696,7 @@ export interface AdminApiResponseDnasDefinitionReturned { * @public */ export interface AdminApiResponseDnasListed { - type: { "dnas_listed": null }; + type: { dnas_listed: null }; data: ListDnasResponse; } @@ -704,7 +704,7 @@ export interface AdminApiResponseDnasListed { * @public */ export interface AdminApiResponseAppInterfaceAttached { - type: { "app_interface_attached": null }; + type: { app_interface_attached: null }; data: AttachAppInterfaceResponse; } @@ -712,12 +712,12 @@ export interface AdminApiResponseAppInterfaceAttached { * @public */ export interface AdminApiResponseAgentInfoAdded { - type: { "agent_info_added": null }; + type: { agent_info_added: null }; } /** * @public */ export interface AdminApiResponseCloneCellDeleted { - type: { "clone_cell_deleted": null }; + type: { clone_cell_deleted: null }; }