🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
Book a DemoInstallSign in
Socket

ts-command

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ts-command - npm Package Compare versions

Comparing version

to
0.1.0

8

dist/command.types.d.ts

@@ -10,3 +10,3 @@ import { Class, StrObject } from './types';

export declare type CommandCreateInfo<T> = Array<keyof T | CommandEntry<T>>;
export declare type CommandFn<T extends StrObject, R = any> = (args: T, user: any) => R | Promise<R>;
export declare type CommandFn<T extends StrObject, R = any> = (args: T, user: any, executionInfo: CommandExecutionInfo) => R | Promise<R>;
export declare type CommandClassConstructor<T extends StrObject> = Class<AbstractCommand<T>>;

@@ -23,1 +23,7 @@ export declare type RestrictFunction = (user: any, instance: any) => boolean;

}
export interface CommandExecutionInfo {
commandName: string;
commandInfo: CommandFnInfo;
rawArgs: string;
message: string;
}

@@ -37,2 +37,3 @@ import { Class } from './types';

getCommandByName(name: string): [CommandInstanceInfo, CommandFnInfo] | undefined;
getAllCommands(): CommandFnInfo[];
reload(target: string | Class): void;

@@ -39,0 +40,0 @@ reloadAll(): void;

@@ -145,2 +145,5 @@ "use strict";

}
getAllCommands() {
return this.commands.map(x => x.commands).flat();
}
reload(target) {

@@ -147,0 +150,0 @@ if (typeof target === 'string') {

import { Class } from './types';
import { CommandFnInfo } from './command.types';
export interface ReloadOptions<User = any> {

@@ -19,4 +20,12 @@ enabled: boolean;

reloadAll(): void;
getAllCommands(): CommandFnInfo[];
/**
* @throws {IllegalFormatError|CommandNotEnabledError|CommandTimeoutError|NotFoundError|IllegalArgumentError}
* @param {string} message
* @param {User} user
* @param {() => void} preCommand
* @returns {Promise<T & string>}
*/
onCommand<T = string>(message: string, user: User, preCommand?: () => void): Promise<T & string>;
private onReload;
}

@@ -49,2 +49,12 @@ "use strict";

}
getAllCommands() {
return this.container.getAllCommands();
}
/**
* @throws {IllegalFormatError|CommandNotEnabledError|CommandTimeoutError|NotFoundError|IllegalArgumentError}
* @param {string} message
* @param {User} user
* @param {() => void} preCommand
* @returns {Promise<T & string>}
*/
async onCommand(message, user, preCommand) {

@@ -73,6 +83,12 @@ if (!message)

}
const argsPart = message.substring(commandName.length + 1);
const argsPart = message.substring(commandName.length + 1).trim();
const argsObj = parsing_1.parseCommand(argsPart, parsing_1.tokenizeMessage(argsPart), command.arguments);
preCommand === null || preCommand === void 0 ? void 0 : preCommand();
return await wrapper.instance[command.key](argsObj, user);
// noinspection ES6RedundantAwait
return await wrapper.instance[command.key](argsObj, user, {
commandInfo: command,
commandName,
message,
rawArgs: argsPart,
});
}

@@ -79,0 +95,0 @@ onReload(message, user) {

@@ -88,3 +88,5 @@ "use strict";

}
// todo: /(?:([^ "']+)|"([^"]+)"|'([^']+)')(?: |$)/g
function tokenizeMessage(target) {
target = target.trim();
const results = [];

@@ -91,0 +93,0 @@ for (let i = 0; i < target.length; i++) {

10

package.json
{
"name": "ts-command",
"version": "0.0.1",
"version": "0.1.0",
"main": "dist/index.js",

@@ -22,4 +22,4 @@ "types": "dist/index.d.ts",

"dependencies": {
"reflect-metadata": "^0.1.13",
"lodash": "^4.17.15"
"lodash": "^4.17.15",
"reflect-metadata": "^0.1.13"
},

@@ -38,6 +38,6 @@ "devDependencies": {

"pretty-quick": "^2.0.1",
"rimraf": "^3.0.2",
"ts-node": "^8.9.1",
"typescript": "^3.8.3",
"rimraf": "^3.0.2"
"typescript": "^3.8.3"
}
}

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet