Skip to content

Commit

Permalink
feat: 馃幐 add a list of commands that perform writes
Browse files Browse the repository at this point in the history
  • Loading branch information
streamich committed Dec 13, 2023
1 parent 2a0819b commit e401242
Show file tree
Hide file tree
Showing 4 changed files with 135 additions and 1 deletion.
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
"tslint": "tslint 'src/**/*.{js,jsx,ts,tsx}' -t verbose --project .",
"clean": "rimraf lib es6 es2019 es2020 esm typedocs coverage gh-pages yarn-error.log",
"build": "tsc --project tsconfig.build.json --module commonjs",
"build:commands": "ts-node scripts/build-commands.ts",
"jest": "node -r ts-node/register ./node_modules/.bin/jest",
"test": "jest --maxWorkers 7",
"coverage": "yarn test --collectCoverage",
Expand All @@ -55,7 +56,8 @@
"tslib": "^2.6.2",
"tslint": "^6.1.3",
"tslint-config-common": "^1.6.2",
"typescript": "^5.3.3"
"typescript": "^5.3.3",
"commands": "https://github.com/streamich/commands#4321d5d40473c48fadf49fd99662032eac9b855b"
},
"jest": {
"verbose": true,
Expand Down
24 changes: 24 additions & 0 deletions scripts/build-commands.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import * as fs from 'fs';
const defs = require('commands/lib/commands.json');

let ts = `// This file is generated by "yarn build:commands".
// Set of commands that are writable.
export const write = new Set<string>([
`;

const commands = Object.keys(defs);
for (const command of commands) {
const cmd = command.toUpperCase();
const def = defs[command];
const isWritable = Array.isArray(def.flags) && def.flags.includes('write');
if (isWritable) ts += ` '${cmd}',\n`;
}
ts += `]);
`;

const dir = 'src/generated';
fs.mkdirSync(dir, {recursive: true});
const filename = dir + '/commands.ts';
fs.writeFileSync(filename, ts);
console.log('Wrote', filename);
104 changes: 104 additions & 0 deletions src/generated/commands.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
// This file is generated by "yarn build:commands".

// Set of commands that are writable.
export const write = new Set<string>([
'APPEND',
'BITFIELD',
'BITOP',
'BLMOVE',
'BLMPOP',
'BLPOP',
'BRPOP',
'BRPOPLPUSH',
'BZMPOP',
'BZPOPMAX',
'BZPOPMIN',
'COPY',
'DECR',
'DECRBY',
'DEL',
'EXPIRE',
'EXPIREAT',
'FLUSHALL',
'FLUSHDB',
'GEOADD',
'GEORADIUS',
'GEORADIUSBYMEMBER',
'GEOSEARCHSTORE',
'GETDEL',
'GETEX',
'GETSET',
'HDEL',
'HINCRBY',
'HINCRBYFLOAT',
'HMSET',
'HSET',
'HSETNX',
'INCR',
'INCRBY',
'INCRBYFLOAT',
'LINSERT',
'LMOVE',
'LMPOP',
'LPOP',
'LPUSH',
'LPUSHX',
'LREM',
'LSET',
'LTRIM',
'MIGRATE',
'MOVE',
'MSET',
'MSETNX',
'PERSIST',
'PEXPIRE',
'PEXPIREAT',
'PFADD',
'PFDEBUG',
'PFMERGE',
'PSETEX',
'RENAME',
'RENAMENX',
'RESTORE',
'RESTORE-ASKING',
'RPOP',
'RPOPLPUSH',
'RPUSH',
'RPUSHX',
'SADD',
'SDIFFSTORE',
'SET',
'SETBIT',
'SETEX',
'SETNX',
'SETRANGE',
'SINTERSTORE',
'SMOVE',
'SORT',
'SPOP',
'SREM',
'SUNIONSTORE',
'SWAPDB',
'UNLINK',
'XACK',
'XADD',
'XAUTOCLAIM',
'XCLAIM',
'XDEL',
'XREADGROUP',
'XSETID',
'XTRIM',
'ZADD',
'ZDIFFSTORE',
'ZINCRBY',
'ZINTERSTORE',
'ZMPOP',
'ZPOPMAX',
'ZPOPMIN',
'ZRANGESTORE',
'ZREM',
'ZREMRANGEBYLEX',
'ZREMRANGEBYRANK',
'ZREMRANGEBYSCORE',
'ZUNIONSTORE',
]);
4 changes: 4 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1024,6 +1024,10 @@ commander@^2.12.1:
resolved "https://registry.yarnpkg.com/commander/-/commander-2.20.3.tgz#fd485e84c03eb4881c20722ba48035e8531aeb33"
integrity sha512-GpVkmM8vF2vQUkj2LvZmD35JxeJOLCwJ9cUkugyk2nuhbv3+mJvpLYYt+0+USMxE+oj+ey/lJEnhZw75x/OMcQ==

"commands@https://github.com/streamich/commands#4321d5d40473c48fadf49fd99662032eac9b855b":
version "0.2.0"
resolved "https://github.com/streamich/commands#4321d5d40473c48fadf49fd99662032eac9b855b"

concat-map@0.0.1:
version "0.0.1"
resolved "https://registry.yarnpkg.com/concat-map/-/concat-map-0.0.1.tgz#d8a96bd77fd68df7793a73036a3ba0d5405d477b"
Expand Down

0 comments on commit e401242

Please sign in to comment.