@wq2/brigadier-ts 1.0.0 → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -0
- package/dist/Command.d.ts +2 -2
- package/dist/CommandDispatcher.d.ts +1 -1
- package/dist/CommandDispatcher.js +231 -357
- package/dist/ParseResults.d.ts +1 -1
- package/dist/ParseResults.js +9 -10
- package/dist/StringReader.d.ts +1 -1
- package/dist/StringReader.js +75 -77
- package/dist/arguments/ArgumentType.d.ts +1 -1
- package/dist/arguments/ArgumentType.js +9 -8
- package/dist/arguments/BoolArgumentType.d.ts +5 -1
- package/dist/arguments/BoolArgumentType.js +9 -27
- package/dist/arguments/FloatArgumentType.d.ts +1 -1
- package/dist/arguments/FloatArgumentType.js +11 -30
- package/dist/arguments/IntegerArgumentType.d.ts +1 -1
- package/dist/arguments/IntegerArgumentType.js +11 -30
- package/dist/arguments/LongArgumentType.d.ts +3 -3
- package/dist/arguments/LongArgumentType.js +13 -32
- package/dist/arguments/NumberArgumentType.d.ts +2 -2
- package/dist/arguments/NumberArgumentType.js +15 -33
- package/dist/arguments/StringArgumentType.d.ts +1 -1
- package/dist/arguments/StringArgumentType.js +11 -29
- package/dist/builder/ArgumentBuilder.d.ts +1 -1
- package/dist/builder/ArgumentBuilder.js +31 -71
- package/dist/builder/LiteralArgumentBuilder.js +14 -33
- package/dist/builder/RequiredArgumentBuilder.d.ts +1 -1
- package/dist/builder/RequiredArgumentBuilder.js +18 -37
- package/dist/context/CommandContext.d.ts +1 -1
- package/dist/context/CommandContext.js +31 -32
- package/dist/context/CommandContextBuilder.d.ts +1 -1
- package/dist/context/CommandContextBuilder.js +47 -50
- package/dist/context/ParsedArgument.js +8 -9
- package/dist/context/ParsedCommandNode.d.ts +1 -1
- package/dist/context/ParsedCommandNode.js +7 -8
- package/dist/context/StringRange.js +17 -18
- package/dist/context/SuggestionContext.d.ts +1 -1
- package/dist/context/SuggestionContext.js +3 -4
- package/dist/exceptions/CommandErrorType.d.ts +3 -3
- package/dist/exceptions/CommandErrorType.js +10 -19
- package/dist/exceptions/CommandSyntaxError.js +36 -54
- package/dist/suggestion/Suggestion.d.ts +1 -1
- package/dist/suggestion/Suggestion.js +16 -17
- package/dist/suggestion/Suggestions.d.ts +1 -1
- package/dist/suggestion/Suggestions.js +28 -30
- package/dist/suggestion/SuggestionsBuilder.d.ts +1 -1
- package/dist/suggestion/SuggestionsBuilder.js +22 -23
- package/dist/tree/ArgumentCommandNode.d.ts +1 -1
- package/dist/tree/ArgumentCommandNode.js +22 -40
- package/dist/tree/CommandNode.d.ts +1 -1
- package/dist/tree/CommandNode.js +28 -29
- package/dist/tree/LiteralCommandNode.d.ts +1 -1
- package/dist/tree/LiteralCommandNode.js +28 -41
- package/dist/tree/RootCommandNode.d.ts +1 -1
- package/dist/tree/RootCommandNode.js +17 -69
- package/jest.config.js +5 -5
- package/package.json +32 -32
- package/src/Command.ts +2 -2
- package/src/CommandDispatcher.ts +397 -295
- package/src/ParseResults.ts +26 -22
- package/src/StringReader.ts +212 -193
- package/src/arguments/ArgumentType.ts +13 -8
- package/src/arguments/BoolArgumentType.ts +22 -21
- package/src/arguments/FloatArgumentType.ts +13 -14
- package/src/arguments/IntegerArgumentType.ts +13 -14
- package/src/arguments/LongArgumentType.ts +16 -17
- package/src/arguments/NumberArgumentType.ts +48 -38
- package/src/arguments/StringArgumentType.ts +26 -26
- package/src/builder/ArgumentBuilder.ts +80 -75
- package/src/builder/LiteralArgumentBuilder.ts +31 -21
- package/src/builder/RequiredArgumentBuilder.ts +42 -32
- package/src/context/CommandContext.ts +99 -76
- package/src/context/CommandContextBuilder.ts +169 -143
- package/src/context/ParsedArgument.ts +13 -13
- package/src/context/ParsedCommandNode.ts +14 -14
- package/src/context/StringRange.ts +26 -26
- package/src/context/SuggestionContext.ts +7 -7
- package/src/exceptions/CommandErrorType.ts +20 -13
- package/src/exceptions/CommandSyntaxError.ts +78 -37
- package/src/index.ts +30 -30
- package/src/suggestion/Suggestion.ts +46 -46
- package/src/suggestion/Suggestions.ts +59 -57
- package/src/suggestion/SuggestionsBuilder.ts +59 -57
- package/src/tree/ArgumentCommandNode.ts +51 -40
- package/src/tree/CommandNode.ts +96 -87
- package/src/tree/LiteralCommandNode.ts +78 -57
- package/src/tree/RootCommandNode.ts +33 -23
- package/test/Arguments.test.ts +47 -33
- package/test/CommandDispatcher.test.ts +18 -22
- package/test/StringReader.test.ts +47 -47
- package/tsconfig.json +9 -14
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { CommandNode, StringReader, Command, CommandContext, CommandContextBuilder, Predicate, RedirectModifier, Suggestions, SuggestionsBuilder } from
|
|
1
|
+
import { CommandNode, type StringReader, type Command, type CommandContext, type CommandContextBuilder, type Predicate, type RedirectModifier, Suggestions, type SuggestionsBuilder } from "..";
|
|
2
2
|
export declare class LiteralCommandNode<S> extends CommandNode<S> {
|
|
3
3
|
private literal;
|
|
4
4
|
constructor(literal: string, command: Command<S>, requirement: Predicate<S>, redirect: CommandNode<S>, modifier: RedirectModifier<S>, forks: boolean);
|
|
@@ -1,45 +1,29 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __extends = (this && this.__extends) || (function () {
|
|
3
|
-
var extendStatics = function (d, b) {
|
|
4
|
-
extendStatics = Object.setPrototypeOf ||
|
|
5
|
-
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
6
|
-
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
7
|
-
return extendStatics(d, b);
|
|
8
|
-
};
|
|
9
|
-
return function (d, b) {
|
|
10
|
-
if (typeof b !== "function" && b !== null)
|
|
11
|
-
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
12
|
-
extendStatics(d, b);
|
|
13
|
-
function __() { this.constructor = d; }
|
|
14
|
-
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
15
|
-
};
|
|
16
|
-
})();
|
|
17
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
3
|
exports.LiteralCommandNode = void 0;
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
_this.literal = literal;
|
|
25
|
-
return _this;
|
|
4
|
+
const __1 = require("..");
|
|
5
|
+
class LiteralCommandNode extends __1.CommandNode {
|
|
6
|
+
constructor(literal, command, requirement, redirect, modifier, forks) {
|
|
7
|
+
super(command, requirement, redirect, modifier, forks);
|
|
8
|
+
this.literal = literal;
|
|
26
9
|
}
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
10
|
+
parse(reader, contextBuilder) {
|
|
11
|
+
const start = reader.getCursor();
|
|
12
|
+
const end = this.parseInternal(reader);
|
|
30
13
|
if (end > -1) {
|
|
31
14
|
contextBuilder.withNode(this, new __1.StringRange(start, end));
|
|
32
15
|
return;
|
|
33
16
|
}
|
|
34
17
|
throw __1.CommandSyntaxError.LITERAL_INCORRECT.createWithContext(reader, this.literal);
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
|
|
18
|
+
}
|
|
19
|
+
parseInternal(reader) {
|
|
20
|
+
const start = reader.getCursor();
|
|
38
21
|
if (reader.canRead(this.literal.length)) {
|
|
39
|
-
|
|
40
|
-
if (reader.getString().
|
|
22
|
+
const end = start + this.literal.length;
|
|
23
|
+
if (reader.getString().substring(start, this.literal.length) ===
|
|
24
|
+
this.literal) {
|
|
41
25
|
reader.setCursor(end);
|
|
42
|
-
if (!reader.canRead() || reader.peek()
|
|
26
|
+
if (!reader.canRead() || reader.peek() === " ") {
|
|
43
27
|
return end;
|
|
44
28
|
}
|
|
45
29
|
else {
|
|
@@ -48,21 +32,24 @@ var LiteralCommandNode = /** @class */ (function (_super) {
|
|
|
48
32
|
}
|
|
49
33
|
}
|
|
50
34
|
return -1;
|
|
51
|
-
}
|
|
52
|
-
|
|
35
|
+
}
|
|
36
|
+
getName() {
|
|
53
37
|
return this.literal;
|
|
54
|
-
}
|
|
55
|
-
|
|
38
|
+
}
|
|
39
|
+
getUsageText() {
|
|
56
40
|
return this.literal;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
|
|
41
|
+
}
|
|
42
|
+
listSuggestions(
|
|
43
|
+
// biome-ignore lint/correctness/noUnusedFunctionParameters: yes
|
|
44
|
+
context, builder) {
|
|
45
|
+
if (this.literal
|
|
46
|
+
.toLowerCase()
|
|
47
|
+
.startsWith(builder.getRemaining().toLowerCase())) {
|
|
60
48
|
return builder.suggest(this.literal).buildPromise();
|
|
61
49
|
}
|
|
62
50
|
else {
|
|
63
51
|
return __1.Suggestions.empty();
|
|
64
52
|
}
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
}(__1.CommandNode));
|
|
53
|
+
}
|
|
54
|
+
}
|
|
68
55
|
exports.LiteralCommandNode = LiteralCommandNode;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { CommandNode, StringReader, CommandContextBuilder, CommandContext, Suggestions, SuggestionsBuilder } from
|
|
1
|
+
import { CommandNode, type StringReader, type CommandContextBuilder, type CommandContext, Suggestions, type SuggestionsBuilder } from "..";
|
|
2
2
|
export declare class RootCommandNode<S> extends CommandNode<S> {
|
|
3
3
|
constructor();
|
|
4
4
|
parse(reader: StringReader, contextBuilder: CommandContextBuilder<S>): void;
|
|
@@ -1,77 +1,25 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __extends = (this && this.__extends) || (function () {
|
|
3
|
-
var extendStatics = function (d, b) {
|
|
4
|
-
extendStatics = Object.setPrototypeOf ||
|
|
5
|
-
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
6
|
-
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
7
|
-
return extendStatics(d, b);
|
|
8
|
-
};
|
|
9
|
-
return function (d, b) {
|
|
10
|
-
if (typeof b !== "function" && b !== null)
|
|
11
|
-
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
12
|
-
extendStatics(d, b);
|
|
13
|
-
function __() { this.constructor = d; }
|
|
14
|
-
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
15
|
-
};
|
|
16
|
-
})();
|
|
17
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
18
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
19
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
20
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
21
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
22
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
23
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
24
|
-
});
|
|
25
|
-
};
|
|
26
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
27
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
28
|
-
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
29
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
30
|
-
function step(op) {
|
|
31
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
32
|
-
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
33
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
34
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
35
|
-
switch (op[0]) {
|
|
36
|
-
case 0: case 1: t = op; break;
|
|
37
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
38
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
39
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
40
|
-
default:
|
|
41
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
42
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
43
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
44
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
45
|
-
if (t[2]) _.ops.pop();
|
|
46
|
-
_.trys.pop(); continue;
|
|
47
|
-
}
|
|
48
|
-
op = body.call(thisArg, _);
|
|
49
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
50
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
51
|
-
}
|
|
52
|
-
};
|
|
53
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
54
3
|
exports.RootCommandNode = void 0;
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
var _this = _super.call(this, null, function (c) { return __awaiter(_this, void 0, void 0, function () { return __generator(this, function (_a) {
|
|
60
|
-
return [2 /*return*/, true];
|
|
61
|
-
}); }); }, null, function (c) { return null; }, false) || this;
|
|
62
|
-
return _this;
|
|
4
|
+
const __1 = require("..");
|
|
5
|
+
class RootCommandNode extends __1.CommandNode {
|
|
6
|
+
constructor() {
|
|
7
|
+
super(null, async (_) => true, null, (_) => null, false);
|
|
63
8
|
}
|
|
64
|
-
|
|
65
|
-
}
|
|
66
|
-
|
|
9
|
+
// biome-ignore lint/correctness/noUnusedFunctionParameters: no-op
|
|
10
|
+
parse(reader, contextBuilder) { }
|
|
11
|
+
getName() {
|
|
67
12
|
return "";
|
|
68
|
-
}
|
|
69
|
-
|
|
13
|
+
}
|
|
14
|
+
getUsageText() {
|
|
70
15
|
return "";
|
|
71
|
-
}
|
|
72
|
-
|
|
16
|
+
}
|
|
17
|
+
listSuggestions(
|
|
18
|
+
// biome-ignore lint/correctness/noUnusedFunctionParameters: no-op
|
|
19
|
+
context,
|
|
20
|
+
// biome-ignore lint/correctness/noUnusedFunctionParameters: no-op
|
|
21
|
+
builder) {
|
|
73
22
|
return __1.Suggestions.empty();
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
}(__1.CommandNode));
|
|
23
|
+
}
|
|
24
|
+
}
|
|
77
25
|
exports.RootCommandNode = RootCommandNode;
|
package/jest.config.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
/** @type {import('@jest/types').Config.InitialOptions} */
|
|
2
2
|
module.exports = {
|
|
3
|
-
extensionsToTreatAsEsm: [
|
|
3
|
+
extensionsToTreatAsEsm: [".ts"],
|
|
4
4
|
transform: {
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
"^.+\\.tsx?$": [
|
|
6
|
+
"esbuild-jest",
|
|
7
7
|
{
|
|
8
|
-
format:
|
|
8
|
+
format: "esm",
|
|
9
9
|
},
|
|
10
10
|
],
|
|
11
11
|
},
|
|
12
|
-
}
|
|
12
|
+
};
|
package/package.json
CHANGED
|
@@ -1,34 +1,34 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
2
|
+
"name": "@wq2/brigadier-ts",
|
|
3
|
+
"version": "1.0.1",
|
|
4
|
+
"description": "Fork of brigadier-ts with some extra changes",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
|
+
"scripts": {
|
|
8
|
+
"build": "rimraf dist/ && tsc --build",
|
|
9
|
+
"prepublishOnly": "npm run build",
|
|
10
|
+
"test": "node --experimental-vm-modules --no-warnings node_modules/jest/bin/jest.js"
|
|
11
|
+
},
|
|
12
|
+
"repository": {
|
|
13
|
+
"type": "git",
|
|
14
|
+
"url": "git+https://github.com/MinibloxCheaters2/brigadier-ts.git"
|
|
15
|
+
},
|
|
16
|
+
"publishConfig": {
|
|
17
|
+
"access": "public",
|
|
18
|
+
"provenance": true
|
|
19
|
+
},
|
|
20
|
+
"keywords": [],
|
|
21
|
+
"author": "Misode",
|
|
22
|
+
"license": "MIT",
|
|
23
|
+
"bugs": {
|
|
24
|
+
"url": "https://github.com/MinibloxCheaters2/brigadier-ts/issues"
|
|
25
|
+
},
|
|
26
|
+
"homepage": "https://github.com/MinibloxCheaters2/brigadier-ts#readme",
|
|
27
|
+
"devDependencies": {
|
|
28
|
+
"@types/jest": "^30.0.0",
|
|
29
|
+
"esbuild-jest": "^0.5.0",
|
|
30
|
+
"jest": "^30.2.0",
|
|
31
|
+
"rimraf": "^6.1.2",
|
|
32
|
+
"typescript": "^5.9.3"
|
|
33
|
+
}
|
|
34
34
|
}
|
package/src/Command.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { CommandContext } from "./";
|
|
1
|
+
import type { CommandContext } from "./";
|
|
2
2
|
|
|
3
|
-
export type Command<S> = (c: CommandContext<S>) => Promise<number |
|
|
3
|
+
export type Command<S> = (c: CommandContext<S>) => Promise<number | undefined>;
|