diff --git a/packages/memcache-client/src/lib/client.ts b/packages/memcache-client/src/lib/client.ts index c18e91d..462edac 100644 --- a/packages/memcache-client/src/lib/client.ts +++ b/packages/memcache-client/src/lib/client.ts @@ -1,8 +1,7 @@ import assert from "assert"; -import { optionalRequire } from "optional-require"; import { Socket } from "net"; -const Zstd = optionalRequire("zstd.ts"); +import * as Zstd from "zstd.ts"; import nodeify from "./nodeify"; import ValuePacker from "./value-packer"; @@ -226,19 +225,19 @@ export class MemcacheClient extends EventEmitter { options = {}; } - return this._callbackSend(data, key, options, callback) as unknown as Promise; + return this._callbackSend(data, key, options, callback); } // the promise only version of send - xsend( + xsend( data: StoreParams | SocketCallback, key: string, options?: StoreCommandOptions - ): Promise { + ): Promise { return this._servers.doCmd( (c: MemcacheConnection) => this._send(c, data, options || {}), key - ) as Promise; + ) as Promise; } // a convenient method to send a single line as a command to the server @@ -249,7 +248,7 @@ export class MemcacheClient extends EventEmitter { options?: CommonCommandOption, callback?: ErrorFirstCallback ): Promise { - return this.send( + return this.send( (socket) => { let line = data; if (options?.noreply) { @@ -260,7 +259,7 @@ export class MemcacheClient extends EventEmitter { key || "", options, callback - ) as unknown as Promise; + ); } // "set" means "store this data". @@ -346,7 +345,7 @@ export class MemcacheClient extends EventEmitter { key, options as CommonCommandOption, callback - ) as unknown as Promise; + ); } // incr key by value, fire & forget with options.noreply @@ -361,7 +360,7 @@ export class MemcacheClient extends EventEmitter { key, options as StoreCommandOptions, callback - ) as unknown as Promise; + ); } // decrease key by value, fire & forget with options.noreply @@ -376,7 +375,7 @@ export class MemcacheClient extends EventEmitter { key, options as StoreCommandOptions, callback - ) as unknown as Promise; + ); } // touch key with exp time, fire & forget with options.noreply @@ -391,12 +390,12 @@ export class MemcacheClient extends EventEmitter { key, options as CommonCommandOption, callback - ) as unknown as Promise; + ); } // get version of server version(callback?: OperationCallback): Promise { - return this.cmd(`version`, "", {}, callback) as unknown as Promise; + return this.cmd(`version`, "", {}, callback); } async versionAll( @@ -662,6 +661,7 @@ export class MemcacheClient extends EventEmitter { serverKey, keys: serverKeys, }); + return undefined; } }) ); @@ -721,13 +721,13 @@ export class MemcacheClient extends EventEmitter { } // internal send that expects all params passed (even if they are undefined) - _callbackSend( + _callbackSend( data: StoreParams | SocketCallback, key: string, options?: Partial, callback?: ErrorFirstCallback - ): Promise { - return nodeify(this.xsend(data, key, options), callback); + ): Promise { + return nodeify(this.xsend(data, key, options), callback); } _unpackValue(result: PackedData): number | string | Record | Buffer { diff --git a/packages/memcache-client/src/lib/nodeify.ts b/packages/memcache-client/src/lib/nodeify.ts index bf76286..2e265b7 100644 --- a/packages/memcache-client/src/lib/nodeify.ts +++ b/packages/memcache-client/src/lib/nodeify.ts @@ -4,10 +4,10 @@ export type CallbackablePromise = Promise & { nodeify?: (callback: ErrorFirstCallback) => void; }; -export default function nodeify( - promise: CallbackablePromise, +export default function nodeify( + promise: CallbackablePromise, callback?: ErrorFirstCallback -): Promise { +): Promise { if (callback) { if (promise.nodeify !== undefined) { promise.nodeify(callback);