Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@clerc/core

Package Overview
Dependencies
Maintainers
1
Versions
61
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@clerc/core - npm Package Compare versions

Comparing version 0.21.0 to 0.22.0

40

dist/index.d.ts

@@ -72,3 +72,3 @@ import * as _clerc_utils from '@clerc/utils';

type CommandType = SingleCommandType | string;
type CommandType = RootType | string;
type FlagOptions = FlagSchema & {

@@ -82,3 +82,3 @@ description?: string;

}
interface CommandOptions<P extends string[] = string[], A extends MaybeArray<string | SingleCommandType> = MaybeArray<string | SingleCommandType>, F extends Dict<FlagOptions> = Dict<FlagOptions>> extends CommandCustomProperties {
interface CommandOptions<P extends string[] = string[], A extends MaybeArray<string | RootType> = MaybeArray<string | RootType>, F extends Dict<FlagOptions> = Dict<FlagOptions>> extends CommandCustomProperties {
alias?: A;

@@ -90,10 +90,10 @@ parameters?: P;

}
type Command<N extends string | SingleCommandType = string, O extends CommandOptions = CommandOptions> = O & {
type Command<N extends string | RootType = string, O extends CommandOptions = CommandOptions> = O & {
name: N;
description: string;
};
type CommandAlias<N extends string | SingleCommandType = string, O extends CommandOptions = CommandOptions> = Command<N, O> & {
type CommandAlias<N extends string | RootType = string, O extends CommandOptions = CommandOptions> = Command<N, O> & {
__isAlias?: true;
};
type CommandWithHandler<N extends string | SingleCommandType = string, O extends CommandOptions = CommandOptions> = Command<N, O> & {
type CommandWithHandler<N extends string | RootType = string, O extends CommandOptions = CommandOptions> = Command<N, O> & {
handler?: HandlerInCommand<Record<N, Command<N, O>> & Record<never, never>, N>;

@@ -104,3 +104,3 @@ };

type CommandRecord = Dict<Command> & {
[SingleCommand]?: Command;
[Root]?: Command;
};

@@ -127,6 +127,6 @@ type MakeEventMap<T extends CommandRecord> = {

name: N extends keyof C ? N : N | undefined;
called?: string | SingleCommandType;
called?: string | RootType;
resolved: N extends keyof C ? true : boolean;
hasSingleCommandOrAlias: boolean;
hasSingleCommand: boolean;
hasRootOrAlias: boolean;
hasRoot: boolean;
raw: Raw<C, N>;

@@ -156,4 +156,4 @@ parameters: TransformParameters<C, N>;

declare const SingleCommand: unique symbol;
type SingleCommandType = typeof SingleCommand;
declare const Root: unique symbol;
type RootType = typeof Root;
declare class Clerc<C extends CommandRecord = {}> {

@@ -229,3 +229,3 @@ #private;

* Clerc.create()
* .command("", "single command", {
* .command("", "root", {
* flags: {

@@ -240,4 +240,4 @@ * foo: {

*/
command<N extends string | SingleCommandType, O extends CommandOptions<[...P], A, F>, P extends string[] = string[], A extends MaybeArray<string | SingleCommandType> = MaybeArray<string | SingleCommandType>, F extends Dict<FlagOptions> = Dict<FlagOptions>>(c: CommandWithHandler<N, O & CommandOptions<[...P], A, F>>): this & Clerc<C & Record<N, Command<N, O>>>;
command<N extends string | SingleCommandType, O extends CommandOptions<[...P], A, F>, P extends string[] = string[], A extends MaybeArray<string | SingleCommandType> = MaybeArray<string | SingleCommandType>, F extends Dict<FlagOptions> = Dict<FlagOptions>>(name: N, description: string, options?: O & CommandOptions<[...P], A, F>): this & Clerc<C & Record<N, Command<N, O>>>;
command<N extends string | RootType, O extends CommandOptions<[...P], A, F>, P extends string[] = string[], A extends MaybeArray<string | RootType> = MaybeArray<string | RootType>, F extends Dict<FlagOptions> = Dict<FlagOptions>>(c: CommandWithHandler<N, O & CommandOptions<[...P], A, F>>): this & Clerc<C & Record<N, Command<N, O>>>;
command<N extends string | RootType, O extends CommandOptions<[...P], A, F>, P extends string[] = string[], A extends MaybeArray<string | RootType> = MaybeArray<string | RootType>, F extends Dict<FlagOptions> = Dict<FlagOptions>>(name: N, description: string, options?: O & CommandOptions<[...P], A, F>): this & Clerc<C & Record<N, Command<N, O>>>;
/**

@@ -299,3 +299,3 @@ * Register a handler

declare const defineInspector: <C extends Clerc<{}>>(_cli: C, inspector: Inspector<C["_commands"]>) => Inspector<C["_commands"]>;
declare const defineCommand: <N extends string | typeof SingleCommand, O extends CommandOptions<[...P], A, F>, P extends string[] = string[], A extends MaybeArray<string> = MaybeArray<string>, F extends Dict<FlagOptions> = Dict<FlagOptions>>(command: CommandWithHandler<N, O & CommandOptions<[...P], A, F>>) => CommandWithHandler<N, O & CommandOptions<[...P], A, F>>;
declare const defineCommand: <N extends string | typeof Root, O extends CommandOptions<[...P], A, F>, P extends string[] = string[], A extends MaybeArray<string> = MaybeArray<string>, F extends Dict<FlagOptions> = Dict<FlagOptions>>(command: CommandWithHandler<N, O & CommandOptions<[...P], A, F>>) => CommandWithHandler<N, O & CommandOptions<[...P], A, F>>;

@@ -332,6 +332,6 @@ declare class CommandExistsError extends Error {

declare function resolveFlattenCommands(commands: CommandRecord): Map<string[] | typeof SingleCommand, CommandAlias<string, CommandOptions<string[], _clerc_utils.MaybeArray<string | typeof SingleCommand>, _clerc_utils.Dict<FlagOptions>>>>;
declare function resolveCommand(commands: CommandRecord, name: string | string[] | SingleCommandType): Command<string | SingleCommandType> | undefined;
declare function resolveSubcommandsByParent(commands: CommandRecord, parent: string | string[], depth?: number): Command<string, CommandOptions<string[], _clerc_utils.MaybeArray<string | typeof SingleCommand>, _clerc_utils.Dict<FlagOptions>>>[];
declare const resolveRootCommands: (commands: CommandRecord) => Command<string, CommandOptions<string[], _clerc_utils.MaybeArray<string | typeof SingleCommand>, _clerc_utils.Dict<FlagOptions>>>[];
declare function resolveFlattenCommands(commands: CommandRecord): Map<string[] | typeof Root, CommandAlias<string, CommandOptions<string[], _clerc_utils.MaybeArray<string | typeof Root>, _clerc_utils.Dict<FlagOptions>>>>;
declare function resolveCommand(commands: CommandRecord, name: string | string[] | RootType): Command<string | RootType> | undefined;
declare function resolveSubcommandsByParent(commands: CommandRecord, parent: string | string[], depth?: number): Command<string, CommandOptions<string[], _clerc_utils.MaybeArray<string | typeof Root>, _clerc_utils.Dict<FlagOptions>>>[];
declare const resolveRootCommands: (commands: CommandRecord) => Command<string, CommandOptions<string[], _clerc_utils.MaybeArray<string | typeof Root>, _clerc_utils.Dict<FlagOptions>>>[];
declare function resolveParametersBeforeFlag(argv: string[]): string[];

@@ -350,2 +350,2 @@ declare const resolveArgv: () => string[];

export { Clerc, Command, CommandAlias, CommandCustomProperties, CommandExistsError, CommandNameConflictError, CommandOptions, CommandRecord, CommandType, CommandWithHandler, DescriptionNotSetError, FallbackType, Flag, FlagOptions, Handler, HandlerContext, HandlerInCommand, Inspector, InspectorContext, InspectorFn, InspectorObject, InvalidCommandNameError, MakeEventMap, NameNotSetError, NoCommandGivenError, NoSuchCommandError, Plugin, PossibleInputKind, SingleCommand, SingleCommandType, VersionNotSetError, compose, defineCommand, defineHandler, defineInspector, definePlugin, isInvalidName, mapParametersToArguments, parseParameters, resolveArgv, resolveCommand, resolveFlattenCommands, resolveParametersBeforeFlag, resolveRootCommands, resolveSubcommandsByParent };
export { Clerc, Command, CommandAlias, CommandCustomProperties, CommandExistsError, CommandNameConflictError, CommandOptions, CommandRecord, CommandType, CommandWithHandler, DescriptionNotSetError, FallbackType, Flag, FlagOptions, Handler, HandlerContext, HandlerInCommand, Inspector, InspectorContext, InspectorFn, InspectorObject, InvalidCommandNameError, MakeEventMap, NameNotSetError, NoCommandGivenError, NoSuchCommandError, Plugin, PossibleInputKind, Root, RootType, VersionNotSetError, compose, defineCommand, defineHandler, defineInspector, definePlugin, isInvalidName, mapParametersToArguments, parseParameters, resolveArgv, resolveCommand, resolveFlattenCommands, resolveParametersBeforeFlag, resolveRootCommands, resolveSubcommandsByParent };

@@ -65,5 +65,5 @@ import { LiteEmit } from 'lite-emit';

const commandsMap = /* @__PURE__ */ new Map();
if (commands[SingleCommand]) {
commandsMap.set(SingleCommand, commands[SingleCommand]);
setCommand(commandsMap, commands, commands[SingleCommand]);
if (commands[Root]) {
commandsMap.set(Root, commands[Root]);
setCommand(commandsMap, commands, commands[Root]);
}

@@ -77,4 +77,4 @@ for (const command of Object.values(commands)) {

function resolveCommand(commands, name) {
if (name === SingleCommand) {
return commands[SingleCommand];
if (name === Root) {
return commands[Root];
}

@@ -86,8 +86,8 @@ const nameArr = toArray(name);

commandsMap.forEach((v, k) => {
if (k === SingleCommand) {
current = commandsMap.get(SingleCommand);
currentName = SingleCommand;
if (k === Root) {
current = commandsMap.get(Root);
currentName = Root;
return;
}
if (arrayStartsWith(nameArr, k) && (!currentName || currentName === SingleCommand || k.length > currentName.length)) {
if (arrayStartsWith(nameArr, k) && (!currentName || currentName === Root || k.length > currentName.length)) {
current = v;

@@ -217,8 +217,8 @@ currentName = k;

};
var _name, _description, _version, _inspectors, _commands, _commandEmitter, _usedNames, _hasSingleCommandOrAlias, hasSingleCommandOrAlias_get, _hasSingleCommand, hasSingleCommand_get;
const SingleCommand = Symbol("SingleCommand");
var _name, _description, _version, _inspectors, _commands, _commandEmitter, _usedNames, _hasRootOrAlias, hasRootOrAlias_get, _hasRoot, hasRoot_get;
const Root = Symbol("Root");
const _Clerc = class {
constructor(name, description, version) {
__privateAdd(this, _hasSingleCommandOrAlias);
__privateAdd(this, _hasSingleCommand);
__privateAdd(this, _hasRootOrAlias);
__privateAdd(this, _hasRoot);
__privateAdd(this, _name, "");

@@ -266,3 +266,3 @@ __privateAdd(this, _description, "");

command(nameOrCommand, description, options = {}) {
const checkIsCommandObject = (nameOrCommand2) => !(typeof nameOrCommand2 === "string" || nameOrCommand2 === SingleCommand);
const checkIsCommandObject = (nameOrCommand2) => !(typeof nameOrCommand2 === "string" || nameOrCommand2 === Root);
const isCommandObject = checkIsCommandObject(nameOrCommand);

@@ -320,3 +320,3 @@ const name = !isCommandObject ? nameOrCommand : nameOrCommand.name;

const { _: args, flags, unknownFlags } = parsed;
let parameters = !isCommandResolved || command.name === SingleCommand ? args : args.slice(command.name.split(" ").length);
let parameters = !isCommandResolved || command.name === Root ? args : args.slice(command.name.split(" ").length);
let commandParameters = (command == null ? void 0 : command.parameters) || [];

@@ -350,6 +350,6 @@ const hasEof = commandParameters.indexOf("--");

name: command == null ? void 0 : command.name,
called: name.length === 0 ? SingleCommand : stringName,
called: name.length === 0 ? Root : stringName,
resolved: isCommandResolved,
hasSingleCommandOrAlias: __privateGet(this, _hasSingleCommandOrAlias, hasSingleCommandOrAlias_get),
hasSingleCommand: __privateGet(this, _hasSingleCommand, hasSingleCommand_get),
hasRootOrAlias: __privateGet(this, _hasRootOrAlias, hasRootOrAlias_get),
hasRoot: __privateGet(this, _hasRoot, hasRoot_get),
raw: { ...parsed, parameters, mergedFlags },

@@ -396,9 +396,9 @@ parameters: mapping,

_usedNames = new WeakMap();
_hasSingleCommandOrAlias = new WeakSet();
hasSingleCommandOrAlias_get = function() {
return __privateGet(this, _usedNames).includes(SingleCommand);
_hasRootOrAlias = new WeakSet();
hasRootOrAlias_get = function() {
return __privateGet(this, _usedNames).includes(Root);
};
_hasSingleCommand = new WeakSet();
hasSingleCommand_get = function() {
return !!__privateGet(this, _commands)[SingleCommand];
_hasRoot = new WeakSet();
hasRoot_get = function() {
return !!__privateGet(this, _commands)[Root];
};

@@ -411,2 +411,2 @@

export { Clerc, CommandExistsError, CommandNameConflictError, DescriptionNotSetError, InvalidCommandNameError, NameNotSetError, NoCommandGivenError, NoSuchCommandError, SingleCommand, VersionNotSetError, compose, defineCommand, defineHandler, defineInspector, definePlugin, isInvalidName, mapParametersToArguments, parseParameters, resolveArgv, resolveCommand, resolveFlattenCommands, resolveParametersBeforeFlag, resolveRootCommands, resolveSubcommandsByParent };
export { Clerc, CommandExistsError, CommandNameConflictError, DescriptionNotSetError, InvalidCommandNameError, NameNotSetError, NoCommandGivenError, NoSuchCommandError, Root, VersionNotSetError, compose, defineCommand, defineHandler, defineInspector, definePlugin, isInvalidName, mapParametersToArguments, parseParameters, resolveArgv, resolveCommand, resolveFlattenCommands, resolveParametersBeforeFlag, resolveRootCommands, resolveSubcommandsByParent };
{
"name": "@clerc/core",
"version": "0.21.0",
"version": "0.22.0",
"author": "Ray <nn_201312@163.com> (https://github.com/so1ve)",

@@ -53,3 +53,3 @@ "description": "Clerc core",

"type-flag": "^3.0.0",
"@clerc/utils": "0.21.0"
"@clerc/utils": "0.22.0"
},

@@ -56,0 +56,0 @@ "scripts": {

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc