diff --git a/.eslintrc.cjs b/.eslintrc.cjs index ed20b05fc4..941ff892a7 100644 --- a/.eslintrc.cjs +++ b/.eslintrc.cjs @@ -1,11 +1,14 @@ module.exports = { extends: ["eslint:recommended", "plugin:@typescript-eslint/recommended"], parser: "@typescript-eslint/parser", - plugins: ["@typescript-eslint"], + plugins: ["@typescript-eslint", 'eslint-plugin-tsdoc'], root: true, env: { browser: true, node: true, jest: true, }, + rules: { + 'tsdoc/syntax': 'warn' + } }; diff --git a/.github/workflows/lint-ts.yml b/.github/workflows/lint-ts.yml index 4844462055..3e5688f363 100644 --- a/.github/workflows/lint-ts.yml +++ b/.github/workflows/lint-ts.yml @@ -20,6 +20,6 @@ jobs: - uses: actions/checkout@v3 - name: lint ts run: | - npm install @typescript-eslint/parser @typescript-eslint/eslint-plugin eslint typescript + npm install @typescript-eslint/parser @typescript-eslint/eslint-plugin -plugin-tsdoc eslint eslint typescript npm i npx eslint . diff --git a/node/package.json b/node/package.json index 1d51cc5e29..85bb48d918 100644 --- a/node/package.json +++ b/node/package.json @@ -20,7 +20,8 @@ "build-protobuf": "npm run compile-protobuf-files && npm run fix-protobuf-file", "compile-protobuf-files": "cd src && pbjs -t static-module -o ProtobufMessage.js ../../babushka-core/src/protobuf/*.proto && pbts -o ProtobufMessage.d.ts ProtobufMessage.js", "fix-protobuf-file": "replace 'this\\.encode\\(message, writer\\)\\.ldelim' 'this.encode(message, writer && writer.len ? writer.fork() : writer).ldelim' src/ProtobufMessage.js", - "test": "jest --verbose --runInBand" + "test": "jest --verbose --runInBand", + "lint": "eslint -f unix \"src/**/*.{ts,tsx}\"" }, "devDependencies": { "@babel/preset-env": "^7.20.2", diff --git a/node/src/RedisClient.ts b/node/src/RedisClient.ts index 5491fb8192..2e183a7f60 100644 --- a/node/src/RedisClient.ts +++ b/node/src/RedisClient.ts @@ -258,14 +258,27 @@ export class RedisClient { this.writeBufferedRequestsToSocket(); } - /// Get the value associated with the given key, or null if no such value exists. - /// See https://redis.io/commands/get/ for details. + + /** Get the value associated with the given key, or null if no such value exists. + * See https://redis.io/commands/get/ for details. + * + * @param key - The key to retrieve from the database. + * @returns If the key exists, returns the value of the key as a string. Otherwise, return null. + */ public get(key: string): Promise { return this.createWritePromise(createGet(key)); } - /// Set the given key with the given value. Return value is dependent on the passed options. - /// See https://redis.io/commands/set/ for details. + /** Set the given key with the given value. Return value is dependent on the passed options. + * See https://redis.io/commands/set/ for details. + * + * @param key - The key to store. + * @param value - The value to store with the given key. + * @param options - The set options. + * @returns - If the value is successfully set, return OK. + * If value isn't set because of only_if_exists or only_if_does_not_exist conditions, return null. + * If return_old_value is set, return the old value as a string. + */ public set( key: string, value: string, @@ -274,16 +287,24 @@ export class RedisClient { return this.createWritePromise(createSet(key, value, options)); } - /// Returns information and statistics about the server according to the given arguments. - /// When no parameter is provided, the default option is assumed. - /// See https://redis.io/commands/info/ for details. + /** Get information and statistics about the Redis server. + * See https://redis.io/commands/info/ for details. + * + * @param options - A list of InfoSection values specifying which sections of information to retrieve. + * When no parameter is provided, the default option is assumed. + * @returns a string containing the information for the sections requested. + */ public info(options?: InfoOptions[]): Promise { return this.createWritePromise(createInfo(options)); } - /// Removes the specified keys. A key is ignored if it does not exist. - /// Returns the number of keys that were removed. - /// See https://redis.io/commands/del/ for details. + /** Get information and statistics about the Redis server. + * See https://redis.io/commands/info/ for details. + * + * @param options - A list of InfoSection values specifying which sections of information to retrieve. + * When no parameter is provided, the default option is assumed. + * @returns a string containing the information for the sections requested. + */ public del(keys: string[]): Promise { return this.createWritePromise(createDel(keys)); } @@ -291,7 +312,7 @@ export class RedisClient { /** Change the currently selected Redis database. * See https://redis.io/commands/select/ for details. * - * @param index : The index of the database to select. + * @param index - The index of the database to select. * @returns A simple OK response. */ public select(index: number): Promise<"OK"> { diff --git a/node/src/RedisClusterClient.ts b/node/src/RedisClusterClient.ts index 91709098fc..bfe3c3a11a 100644 --- a/node/src/RedisClusterClient.ts +++ b/node/src/RedisClusterClient.ts @@ -124,8 +124,16 @@ export class RedisClusterClient extends RedisClient { return super.createWritePromise(command, toProtobufRoute(route)); } - /// Returns information and statistics about the server according to the given arguments. - /// See https://redis.io/commands/info/ for details. + + /** Get information and statistics about the Redis server. + * See https://redis.io/commands/info/ for details. + * + * @param options - A list of InfoSection values specifying which sections of information to retrieve. + * When no parameter is provided, the default option is assumed. + * @param route - The command will be routed automatically, unless `route` is provided, in which + * case the client will initially try to route the command to the nodes defined by `route`. + * @returns a string containing the information for the sections requested. + */ public info(options?: InfoOptions[], route?: Routes): Promise { return this.createWritePromise(createInfo(options), toProtobufRoute(route)); } @@ -133,7 +141,7 @@ export class RedisClusterClient extends RedisClient { /** Resets the statistics reported by Redis using the INFO and LATENCY HISTOGRAM commands. * See https://redis.io/commands/config-resetstat/ for details. * - * @param route The command will be routed automatically, unless `route` is provided, in which + * @param route - The command will be routed automatically, unless `route` is provided, in which * case the client will initially try to route the command to the nodes defined by `route`. * * @returns always "OK" diff --git a/node/src/Transaction.ts b/node/src/Transaction.ts index 3a9be88df3..2a0ce3b818 100644 --- a/node/src/Transaction.ts +++ b/node/src/Transaction.ts @@ -15,27 +15,47 @@ import { redis_request } from "./ProtobufMessage"; export class BaseTransaction { readonly commands: redis_request.Command[] = []; - /// Get the value associated with the given key, or null if no such value exists. - /// See https://redis.io/commands/get/ for details. + /** Get the value associated with the given key, or null if no such value exists. + * See https://redis.io/commands/get/ for details. + * + * @param key - The key to retrieve from the database. + * @returns If the key exists, returns the value of the key as a string. Otherwise, return null. + */ public get(key: string) { this.commands.push(createGet(key)); } - /// Set the given key with the given value. Return value is dependent on the passed options. - /// See https://redis.io/commands/set/ for details. + /** Set the given key with the given value. Return value is dependent on the passed options. + * See https://redis.io/commands/set/ for details. + * + * @param key - The key to store. + * @param value - The value to store with the given key. + * @param options - The set options. + * @returns If the value is successfully set, return OK. + * If value isn't set because of only_if_exists or only_if_does_not_exist conditions, return null. + * If return_old_value is set, return the old value as a string. + */ public set(key: string, value: string, options?: SetOptions) { this.commands.push(createSet(key, value, options)); } - /// Returns information and statistics about the server according to the given arguments. - /// See https://redis.io/commands/info/ for details. + /** Get information and statistics about the Redis server. + * See https://redis.io/commands/info/ for details. + * + * @param options - A list of InfoSection values specifying which sections of information to retrieve. + * When no parameter is provided, the default option is assumed. + * @returns a string containing the information for the sections requested. + */ public info(options?: InfoOptions[]) { this.commands.push(createInfo(options)); } - /// Removes the specified keys. A key is ignored if it does not exist. - /// Returns the number of keys that were removed. - /// See https://redis.io/commands/del/ for details. + /** Remove the specified keys. A key is ignored if it does not exist. + * See https://redis.io/commands/del/ for details. + * + * @param keys - A list of keys to be deleted from the database. + * @returns the number of keys that were removed. + */ public del(keys: string[]) { this.commands.push(createDel(keys)); } @@ -70,8 +90,8 @@ export class Transaction extends BaseTransaction{ /** Change the currently selected Redis database. * See https://redis.io/commands/select/ for details. * - * @param index : The index of the database to select. - * @CommandResponse : A simple OK response. + * @param index - The index of the database to select. + * Returns A simple OK response. */ public select(index: number) { this.commands.push(createSelect(index));