Last active
October 30, 2019 21:24
-
-
Save wrumsby/8a382bb21c5c02251490907d38845dc6 to your computer and use it in GitHub Desktop.
Exporting BasePlugin from @cloudant/cloudant
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Add this import after requiring ('./lib/client.js') | |
const BasePlugin = require('./plugins/base.js'); | |
// This adds BasePlugin to the existing export | |
Cloudant.BasePlugin = BasePlugin; | |
... | |
// change nano.basePlugin = require('./plugins/base.js'); to | |
nano.basePlugin = BasePlugin; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Add the following to the cloudant namespace | |
interface PluginConfig {} | |
interface PluginState { | |
maxAttempt: number; | |
} | |
type PluginCallbackFunction = (state: PluginState) => void; | |
type PluginLifecycleFunction = (state: PluginState, event: any, callback: PluginCallbackFunction) => void; | |
export class BasePlugin { | |
public static pluginVersion: number; | |
public disabled: boolean; | |
public _cfg: PluginConfig; | |
public constructor(client: nano.DocumentScope<{}>, config?: PluginConfig) | |
public get id(): string | |
// Having a more specific type for `request` would be nice too | |
public onRequest(state: PluginState, request: any, callback: PluginLifecycleFunction) | |
// Having a more specific type for `response` would be nice too | |
public onResponse(state: PluginState, response: any, callback: PluginLifecycleFunction) | |
// Having a more specific type for `error` would be nice too (could this be `error: Error`?) | |
public onError(state: PluginState, error: any, callback: PluginLifecycleFunction) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment