@witchcraft/expressit 0.1.3 → 0.2.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 +7 -5
- package/dist/Lexer.js +21 -42
- package/dist/Parser.d.ts +14 -29
- package/dist/Parser.d.ts.map +1 -1
- package/dist/Parser.js +151 -197
- package/dist/ast/builders/array.d.ts +1 -3
- package/dist/ast/builders/array.d.ts.map +1 -1
- package/dist/ast/builders/array.js +3 -5
- package/dist/ast/builders/condition.d.ts +5 -11
- package/dist/ast/builders/condition.d.ts.map +1 -1
- package/dist/ast/builders/condition.js +4 -7
- package/dist/ast/builders/delim.d.ts +1 -1
- package/dist/ast/builders/delim.js +2 -4
- package/dist/ast/builders/error.d.ts +3 -4
- package/dist/ast/builders/error.d.ts.map +1 -1
- package/dist/ast/builders/error.js +6 -2
- package/dist/ast/builders/expression.d.ts +3 -7
- package/dist/ast/builders/expression.d.ts.map +1 -1
- package/dist/ast/builders/expression.js +4 -7
- package/dist/ast/builders/group.d.ts +3 -8
- package/dist/ast/builders/group.d.ts.map +1 -1
- package/dist/ast/builders/group.js +3 -3
- package/dist/ast/builders/pos.d.ts +1 -2
- package/dist/ast/builders/pos.d.ts.map +1 -1
- package/dist/ast/builders/pos.js +3 -6
- package/dist/ast/builders/token.d.ts +3 -5
- package/dist/ast/builders/token.d.ts.map +1 -1
- package/dist/ast/builders/token.js +3 -4
- package/dist/ast/builders/type.d.ts +1 -1
- package/dist/ast/builders/variable.d.ts +3 -5
- package/dist/ast/builders/variable.d.ts.map +1 -1
- package/dist/ast/builders/variable.js +4 -7
- package/dist/ast/createArrayNode.d.ts +3 -0
- package/dist/ast/createArrayNode.d.ts.map +1 -0
- package/dist/ast/createArrayNode.js +12 -0
- package/dist/ast/createConditionNode.d.ts +11 -0
- package/dist/ast/createConditionNode.d.ts.map +1 -0
- package/dist/ast/createConditionNode.js +18 -0
- package/dist/ast/createExpressionNode.d.ts +3 -0
- package/dist/ast/createExpressionNode.d.ts.map +1 -0
- package/dist/ast/createExpressionNode.js +14 -0
- package/dist/ast/createGroupNode.d.ts +5 -0
- package/dist/ast/createGroupNode.d.ts.map +1 -0
- package/dist/ast/createGroupNode.js +14 -0
- package/dist/ast/createNormalizedCondition.d.ts +3 -0
- package/dist/ast/createNormalizedCondition.d.ts.map +1 -0
- package/dist/ast/createNormalizedCondition.js +10 -0
- package/dist/ast/createNormalizedExpression.d.ts +3 -0
- package/dist/ast/createNormalizedExpression.d.ts.map +1 -0
- package/dist/ast/createNormalizedExpression.js +10 -0
- package/dist/ast/createToken.d.ts +6 -0
- package/dist/ast/createToken.d.ts.map +1 -0
- package/dist/ast/createToken.js +15 -0
- package/dist/ast/createVariableNode.d.ts +3 -0
- package/dist/ast/createVariableNode.d.ts.map +1 -0
- package/dist/ast/createVariableNode.js +12 -0
- package/dist/ast/error.d.ts +3 -0
- package/dist/ast/error.d.ts.map +1 -0
- package/dist/ast/error.js +8 -0
- package/dist/ast/handlers.d.ts +5 -12
- package/dist/ast/handlers.d.ts.map +1 -1
- package/dist/ast/handlers.js +25 -37
- package/dist/ast/index.d.ts +9 -1
- package/dist/ast/index.d.ts.map +1 -1
- package/dist/ast/index.js +18 -2
- package/dist/defaults/defaultConditionNormalizer.d.ts +3 -0
- package/dist/defaults/defaultConditionNormalizer.d.ts.map +1 -0
- package/dist/defaults/defaultKeyParser.d.ts +3 -0
- package/dist/defaults/defaultKeyParser.d.ts.map +1 -0
- package/dist/{helpers/general → defaults}/defaultKeyParser.js +1 -2
- package/dist/defaults/defaultPrefixApplier.d.ts +3 -0
- package/dist/defaults/defaultPrefixApplier.d.ts.map +1 -0
- package/dist/defaults/defaultValueComparer.d.ts +3 -0
- package/dist/defaults/defaultValueComparer.d.ts.map +1 -0
- package/dist/{helpers/general → defaults}/index.d.ts +0 -2
- package/dist/defaults/index.d.ts.map +1 -0
- package/dist/{helpers/general → defaults}/index.js +0 -4
- package/dist/examples/shortcutContextParser.js +4 -10
- package/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -1
- package/dist/{helpers/errors.d.ts → internal/ExpressitError.d.ts} +3 -2
- package/dist/internal/ExpressitError.d.ts.map +1 -0
- package/dist/{helpers/errors.js → internal/ExpressitError.js} +3 -6
- package/dist/internal/applyBoolean.d.ts.map +1 -0
- package/dist/{helpers/general → internal}/applyPrefix.d.ts +1 -1
- package/dist/internal/applyPrefix.d.ts.map +1 -0
- package/dist/{helpers/parser → internal}/checkParserOpts.d.ts +2 -1
- package/dist/internal/checkParserOpts.d.ts.map +1 -0
- package/dist/{helpers/parser → internal}/checkParserOpts.js +22 -30
- package/dist/internal/escapeVariableOrPrefix.d.ts +2 -0
- package/dist/internal/escapeVariableOrPrefix.d.ts.map +1 -0
- package/dist/internal/escapeVariableOrPrefix.js +34 -0
- package/dist/internal/extractPosition.d.ts +5 -0
- package/dist/internal/extractPosition.d.ts.map +1 -0
- package/dist/internal/getUnclosedRightParenCount.d.ts +4 -0
- package/dist/internal/getUnclosedRightParenCount.d.ts.map +1 -0
- package/dist/{helpers/parser → internal}/getUnclosedRightParenCount.js +1 -1
- package/dist/{helpers/parser → internal}/parseParserOptions.d.ts +1 -1
- package/dist/internal/parseParserOptions.d.ts.map +1 -0
- package/dist/{helpers/parser → internal}/parseParserOptions.js +4 -4
- package/dist/internal/unescape.d.ts.map +1 -0
- package/dist/package.json.js +7 -7
- package/dist/types/ast.d.ts +195 -6
- package/dist/types/ast.d.ts.map +1 -1
- package/dist/types/ast.js +2 -0
- package/dist/types/autocomplete.d.ts +5 -6
- package/dist/types/autocomplete.d.ts.map +1 -1
- package/dist/types/parser.d.ts +17 -22
- package/dist/types/parser.d.ts.map +1 -1
- package/dist/utils/extractTokens.d.ts +2 -4
- package/dist/utils/extractTokens.d.ts.map +1 -1
- package/dist/utils/extractTokens.js +14 -18
- package/dist/utils/generateParentsMap.d.ts +10 -0
- package/dist/utils/generateParentsMap.d.ts.map +1 -0
- package/dist/utils/generateParentsMap.js +53 -0
- package/dist/utils/getCursorInfo.d.ts +1 -1
- package/dist/utils/getCursorInfo.d.ts.map +1 -1
- package/dist/utils/getCursorInfo.js +11 -21
- package/dist/utils/getOppositeDelimiter.d.ts +2 -1
- package/dist/utils/getOppositeDelimiter.d.ts.map +1 -1
- package/dist/utils/getOppositeDelimiter.js +9 -11
- package/dist/utils/getParent.d.ts +5 -0
- package/dist/utils/getParent.d.ts.map +1 -0
- package/dist/utils/getParent.js +6 -0
- package/dist/utils/getSurroundingErrors.d.ts +3 -4
- package/dist/utils/getSurroundingErrors.d.ts.map +1 -1
- package/dist/utils/getSurroundingErrors.js +3 -3
- package/dist/utils/index.d.ts +4 -0
- package/dist/utils/index.d.ts.map +1 -1
- package/dist/utils/index.js +8 -0
- package/dist/utils/isNode.d.ts +10 -0
- package/dist/utils/isNode.d.ts.map +1 -0
- package/dist/utils/isNode.js +6 -0
- package/dist/utils/isToken.d.ts +8 -0
- package/dist/utils/isToken.d.ts.map +1 -0
- package/dist/utils/isToken.js +6 -0
- package/dist/utils/prettyAst.d.ts +1 -2
- package/dist/utils/prettyAst.d.ts.map +1 -1
- package/dist/utils/prettyAst.js +20 -28
- package/package.json +7 -7
- package/src/Lexer.ts +2 -2
- package/src/Parser.ts +158 -165
- package/src/ast/builders/array.ts +4 -9
- package/src/ast/builders/condition.ts +10 -15
- package/src/ast/builders/delim.ts +1 -1
- package/src/ast/builders/error.ts +10 -6
- package/src/ast/builders/expression.ts +17 -23
- package/src/ast/builders/group.ts +7 -11
- package/src/ast/builders/pos.ts +2 -3
- package/src/ast/builders/token.ts +6 -7
- package/src/ast/builders/type.ts +1 -1
- package/src/ast/builders/variable.ts +6 -8
- package/src/ast/createArrayNode.ts +17 -0
- package/src/ast/createConditionNode.ts +58 -0
- package/src/ast/createExpressionNode.ts +21 -0
- package/src/ast/createGroupNode.ts +46 -0
- package/src/ast/createNormalizedCondition.ts +12 -0
- package/src/ast/createNormalizedExpression.ts +9 -0
- package/src/ast/createToken.ts +26 -0
- package/src/ast/createVariableNode.ts +18 -0
- package/src/ast/error.ts +9 -0
- package/src/ast/handlers.ts +26 -37
- package/src/ast/index.ts +9 -1
- package/src/{helpers/general → defaults}/defaultConditionNormalizer.ts +1 -1
- package/src/{helpers/general → defaults}/defaultKeyParser.ts +1 -1
- package/src/{helpers/general → defaults}/defaultPrefixApplier.ts +1 -1
- package/src/{helpers/general → defaults}/defaultValueComparer.ts +1 -1
- package/src/{helpers/general → defaults}/index.ts +0 -2
- package/src/index.ts +2 -1
- package/src/{helpers/errors.ts → internal/ExpressitError.ts} +2 -2
- package/src/{helpers/general → internal}/applyPrefix.ts +1 -1
- package/src/{helpers/parser → internal}/checkParserOpts.ts +16 -15
- package/src/internal/escapeVariableOrPrefix.ts +36 -0
- package/src/{helpers/parser → internal}/extractPosition.ts +2 -2
- package/src/{helpers/parser → internal}/getUnclosedRightParenCount.ts +1 -2
- package/src/{helpers/parser → internal}/parseParserOptions.ts +5 -5
- package/src/types/ast.ts +292 -7
- package/src/types/autocomplete.ts +5 -7
- package/src/types/parser.ts +17 -22
- package/src/utils/extractTokens.ts +16 -20
- package/src/utils/generateParentsMap.ts +60 -0
- package/src/utils/getCursorInfo.ts +4 -6
- package/src/utils/getOppositeDelimiter.ts +11 -10
- package/src/utils/getParent.ts +16 -0
- package/src/utils/getSurroundingErrors.ts +10 -9
- package/src/utils/index.ts +4 -0
- package/src/utils/isNode.ts +12 -0
- package/src/utils/isToken.ts +10 -0
- package/src/utils/prettyAst.ts +20 -17
- package/dist/ast/classes/ArrayNode.d.ts +0 -18
- package/dist/ast/classes/ArrayNode.d.ts.map +0 -1
- package/dist/ast/classes/ArrayNode.js +0 -55
- package/dist/ast/classes/Condition.d.ts +0 -13
- package/dist/ast/classes/Condition.d.ts.map +0 -1
- package/dist/ast/classes/Condition.js +0 -21
- package/dist/ast/classes/ConditionNode.d.ts +0 -73
- package/dist/ast/classes/ConditionNode.d.ts.map +0 -1
- package/dist/ast/classes/ConditionNode.js +0 -101
- package/dist/ast/classes/ErrorToken.d.ts +0 -27
- package/dist/ast/classes/ErrorToken.d.ts.map +0 -1
- package/dist/ast/classes/ErrorToken.js +0 -47
- package/dist/ast/classes/Expression.d.ts +0 -13
- package/dist/ast/classes/Expression.d.ts.map +0 -1
- package/dist/ast/classes/Expression.js +0 -19
- package/dist/ast/classes/ExpressionNode.d.ts +0 -21
- package/dist/ast/classes/ExpressionNode.d.ts.map +0 -1
- package/dist/ast/classes/ExpressionNode.js +0 -57
- package/dist/ast/classes/GroupNode.d.ts +0 -64
- package/dist/ast/classes/GroupNode.d.ts.map +0 -1
- package/dist/ast/classes/GroupNode.js +0 -69
- package/dist/ast/classes/Node.d.ts +0 -22
- package/dist/ast/classes/Node.d.ts.map +0 -1
- package/dist/ast/classes/Node.js +0 -28
- package/dist/ast/classes/Token.d.ts +0 -27
- package/dist/ast/classes/Token.d.ts.map +0 -1
- package/dist/ast/classes/Token.js +0 -28
- package/dist/ast/classes/ValidToken.d.ts +0 -26
- package/dist/ast/classes/ValidToken.d.ts.map +0 -1
- package/dist/ast/classes/ValidToken.js +0 -49
- package/dist/ast/classes/VariableNode.d.ts +0 -33
- package/dist/ast/classes/VariableNode.d.ts.map +0 -1
- package/dist/ast/classes/VariableNode.js +0 -58
- package/dist/ast/classes/index.d.ts +0 -12
- package/dist/ast/classes/index.d.ts.map +0 -1
- package/dist/ast/classes/index.js +0 -24
- package/dist/helpers/errors.d.ts.map +0 -1
- package/dist/helpers/general/applyBoolean.d.ts.map +0 -1
- package/dist/helpers/general/applyPrefix.d.ts.map +0 -1
- package/dist/helpers/general/defaultConditionNormalizer.d.ts +0 -3
- package/dist/helpers/general/defaultConditionNormalizer.d.ts.map +0 -1
- package/dist/helpers/general/defaultKeyParser.d.ts +0 -3
- package/dist/helpers/general/defaultKeyParser.d.ts.map +0 -1
- package/dist/helpers/general/defaultPrefixApplier.d.ts +0 -3
- package/dist/helpers/general/defaultPrefixApplier.d.ts.map +0 -1
- package/dist/helpers/general/defaultValueComparer.d.ts +0 -3
- package/dist/helpers/general/defaultValueComparer.d.ts.map +0 -1
- package/dist/helpers/general/index.d.ts.map +0 -1
- package/dist/helpers/index.d.ts +0 -4
- package/dist/helpers/index.d.ts.map +0 -1
- package/dist/helpers/index.js +0 -8
- package/dist/helpers/parser/assignParents.d.ts +0 -4
- package/dist/helpers/parser/assignParents.d.ts.map +0 -1
- package/dist/helpers/parser/assignParents.js +0 -71
- package/dist/helpers/parser/checkParserOpts.d.ts.map +0 -1
- package/dist/helpers/parser/extractPosition.d.ts +0 -5
- package/dist/helpers/parser/extractPosition.d.ts.map +0 -1
- package/dist/helpers/parser/getUnclosedRightParenCount.d.ts +0 -4
- package/dist/helpers/parser/getUnclosedRightParenCount.d.ts.map +0 -1
- package/dist/helpers/parser/index.d.ts +0 -9
- package/dist/helpers/parser/index.d.ts.map +0 -1
- package/dist/helpers/parser/index.js +0 -18
- package/dist/helpers/parser/parseParserOptions.d.ts.map +0 -1
- package/dist/helpers/parser/seal.d.ts +0 -8
- package/dist/helpers/parser/seal.d.ts.map +0 -1
- package/dist/helpers/parser/seal.js +0 -10
- package/dist/helpers/parser/setParent.d.ts +0 -6
- package/dist/helpers/parser/setParent.d.ts.map +0 -1
- package/dist/helpers/parser/setParent.js +0 -4
- package/dist/helpers/parser/unescape.d.ts.map +0 -1
- package/src/ast/classes/ArrayNode.ts +0 -46
- package/src/ast/classes/Condition.ts +0 -22
- package/src/ast/classes/ConditionNode.ts +0 -141
- package/src/ast/classes/ErrorToken.ts +0 -49
- package/src/ast/classes/Expression.ts +0 -26
- package/src/ast/classes/ExpressionNode.ts +0 -62
- package/src/ast/classes/GroupNode.ts +0 -127
- package/src/ast/classes/Node.ts +0 -47
- package/src/ast/classes/Token.ts +0 -59
- package/src/ast/classes/ValidToken.ts +0 -56
- package/src/ast/classes/VariableNode.ts +0 -67
- package/src/ast/classes/index.ts +0 -13
- package/src/helpers/index.ts +0 -6
- package/src/helpers/parser/assignParents.ts +0 -51
- package/src/helpers/parser/index.ts +0 -10
- package/src/helpers/parser/seal.ts +0 -14
- package/src/helpers/parser/setParent.ts +0 -5
- /package/dist/{helpers/general → defaults}/defaultConditionNormalizer.js +0 -0
- /package/dist/{helpers/general → defaults}/defaultPrefixApplier.js +0 -0
- /package/dist/{helpers/general → defaults}/defaultValueComparer.js +0 -0
- /package/dist/{helpers/general → internal}/applyBoolean.d.ts +0 -0
- /package/dist/{helpers/general → internal}/applyBoolean.js +0 -0
- /package/dist/{helpers/general → internal}/applyPrefix.js +0 -0
- /package/dist/{helpers/parser → internal}/extractPosition.js +0 -0
- /package/dist/{helpers/parser → internal}/unescape.d.ts +0 -0
- /package/dist/{helpers/parser → internal}/unescape.js +0 -0
- /package/src/{helpers/general → internal}/applyBoolean.ts +0 -0
- /package/src/{helpers/parser → internal}/unescape.ts +0 -0
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { ExpressitError } from "../internal/ExpressitError.js";
|
|
2
|
+
import { ERROR_CODES } from "../types/errors.js";
|
|
3
|
+
function createToken(raw) {
|
|
4
|
+
if (raw.start === void 0 || raw.end === void 0) {
|
|
5
|
+
throw new ExpressitError(ERROR_CODES.PARSER_POSITION_ERROR, raw);
|
|
6
|
+
}
|
|
7
|
+
return {
|
|
8
|
+
...raw,
|
|
9
|
+
valid: typeof raw.expected === "undefined",
|
|
10
|
+
isToken: true
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
export {
|
|
14
|
+
createToken
|
|
15
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createVariableNode.d.ts","sourceRoot":"","sources":["../../src/ast/createVariableNode.ts"],"names":[],"mappings":"AAAA,OAAO,EAAY,KAAK,OAAO,EAAE,KAAK,YAAY,EAAE,MAAM,iBAAiB,CAAA;AAE3E,wBAAgB,kBAAkB,CAClC,MAAM,SAAS,OAAO,GAAG,OAAO,EAC9B,GAAG,EAAE,OAAO,CAAC,YAAY,CAAC,MAAM,CAAC,CAAC,GAAG,YAAY,CAAC,MAAM,CAAC,CAa1D"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { AST_TYPE } from "../types/ast.js";
|
|
2
|
+
function createVariableNode(raw) {
|
|
3
|
+
return {
|
|
4
|
+
...raw,
|
|
5
|
+
isNode: true,
|
|
6
|
+
valid: raw.value.valid && (raw.quote === void 0 || raw.quote.left.valid && raw.quote.right.valid),
|
|
7
|
+
type: AST_TYPE.VARIABLE
|
|
8
|
+
};
|
|
9
|
+
}
|
|
10
|
+
export {
|
|
11
|
+
createVariableNode
|
|
12
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"error.d.ts","sourceRoot":"","sources":["../../src/ast/error.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,UAAU,EAAC,KAAK,UAAU,EAAE,MAAM,iBAAiB,CAAA;AAEjE,wBAAgB,KAAK,CAAC,CAAC,SAAS,UAAU,EAAE,GAAG,EAAE,MAAM,EAAE,QAAQ,EAAE,CAAC,EAAE,GAAG,UAAU,CAGlF"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { createToken } from "./createToken.js";
|
|
2
|
+
function error(pos, expected) {
|
|
3
|
+
if (pos === void 0) throw new Error("should never happen, passed undefined position for error token");
|
|
4
|
+
return createToken({ expected, start: pos, end: pos });
|
|
5
|
+
}
|
|
6
|
+
export {
|
|
7
|
+
error
|
|
8
|
+
};
|
package/dist/ast/handlers.d.ts
CHANGED
|
@@ -1,16 +1,9 @@
|
|
|
1
|
-
import { ArrayNode } from "
|
|
2
|
-
|
|
3
|
-
import { ErrorToken } from "./classes/ErrorToken.js";
|
|
4
|
-
import { ExpressionNode } from "./classes/ExpressionNode.js";
|
|
5
|
-
import { GroupNode } from "./classes/GroupNode.js";
|
|
6
|
-
import { ValidToken } from "./classes/ValidToken.js";
|
|
7
|
-
import { VariableNode } from "./classes/VariableNode.js";
|
|
8
|
-
import { type AnyToken, type Position, TOKEN_TYPE, type TokenBooleanTypes, type TokenQuoteTypes } from "../types/ast.js";
|
|
9
|
-
declare function error<T extends TOKEN_TYPE>(pos: number, expected: T[]): ErrorToken<T>;
|
|
1
|
+
import { type AnyToken, type ArrayNode, type ConditionNode, type ErrorToken, type ExpressionNode, type GroupNode, type Position, TOKEN_TYPE, type TokenBooleanTypes, type TokenQuoteTypes, type ValidToken, type VariableNode } from "../types/ast.js";
|
|
2
|
+
declare function error<T extends TOKEN_TYPE>(pos: number, expected: T[]): ErrorToken;
|
|
10
3
|
export declare const token: {
|
|
11
|
-
value: <TVal extends string | undefined>(value: TVal, pos: Position) => TVal extends string ? ValidToken<TOKEN_TYPE.VALUE> : ErrorToken
|
|
12
|
-
custom: <TVal_1 extends string | undefined>(value: TVal_1, pos: Position) => TVal_1 extends string ? ValidToken<TOKEN_TYPE.OP_CUSTOM> : ErrorToken
|
|
13
|
-
sep: <TVal_2 extends string | undefined>(value: TVal_2, pos: Position) => TVal_2 extends string ? ValidToken<TOKEN_TYPE.OP_EXPANDED_SEP> : ErrorToken
|
|
4
|
+
value: <TVal extends string | undefined>(value: TVal, pos: Position) => TVal extends string ? ValidToken<TOKEN_TYPE.VALUE> : ErrorToken;
|
|
5
|
+
custom: <TVal_1 extends string | undefined>(value: TVal_1, pos: Position) => TVal_1 extends string ? ValidToken<TOKEN_TYPE.OP_CUSTOM> : ErrorToken;
|
|
6
|
+
sep: <TVal_2 extends string | undefined>(value: TVal_2, pos: Position) => TVal_2 extends string ? ValidToken<TOKEN_TYPE.OP_EXPANDED_SEP> : ErrorToken;
|
|
14
7
|
};
|
|
15
8
|
/** We want to handle all the types outside the grammar file. This makes it easier without trying to check the value. */
|
|
16
9
|
export declare const delimiter: {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"handlers.d.ts","sourceRoot":"","sources":["../../src/ast/handlers.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"handlers.d.ts","sourceRoot":"","sources":["../../src/ast/handlers.ts"],"names":[],"mappings":"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"}
|
package/dist/ast/handlers.js
CHANGED
|
@@ -1,26 +1,24 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import { TOKEN_TYPE } from "../types/ast.js";
|
|
1
|
+
import { createArrayNode } from "./createArrayNode.js";
|
|
2
|
+
import { createConditionNode } from "./createConditionNode.js";
|
|
3
|
+
import { createExpressionNode } from "./createExpressionNode.js";
|
|
4
|
+
import { createGroupNode } from "./createGroupNode.js";
|
|
5
|
+
import { createToken } from "./createToken.js";
|
|
6
|
+
import { createVariableNode } from "./createVariableNode.js";
|
|
7
|
+
import { TOKEN_TYPE, AST_TYPE } from "../types/ast.js";
|
|
9
8
|
function error(pos, expected) {
|
|
10
|
-
if (pos === void 0)
|
|
11
|
-
|
|
12
|
-
return new ErrorToken({ expected, start: pos, end: pos });
|
|
9
|
+
if (pos === void 0) throw new Error("should never happen, passed undefined position for error token");
|
|
10
|
+
return createToken({ expected, start: pos, end: pos });
|
|
13
11
|
}
|
|
14
|
-
const operators = (type) => (value, pos) =>
|
|
12
|
+
const operators = (type) => (value, pos) => createToken({ value, type, ...pos });
|
|
15
13
|
const delimiters = (type) => (value, pos) => (
|
|
16
14
|
// check must be falsy, we want to return undefined when given ""
|
|
17
|
-
value ?
|
|
15
|
+
value ? createToken({ value, type, ...pos }) : void 0
|
|
18
16
|
);
|
|
19
17
|
const maybeToken = (type) => (value, pos) => {
|
|
20
18
|
if (value === void 0) {
|
|
21
19
|
return error(pos.end, [type]);
|
|
22
20
|
} else {
|
|
23
|
-
return
|
|
21
|
+
return createToken({ value, type, ...pos });
|
|
24
22
|
}
|
|
25
23
|
};
|
|
26
24
|
const token = {
|
|
@@ -45,7 +43,7 @@ const operator = {
|
|
|
45
43
|
not: operators(TOKEN_TYPE.NOT)
|
|
46
44
|
};
|
|
47
45
|
function variable(prefix, quoteL, value, quoteR, flags) {
|
|
48
|
-
var _a;
|
|
46
|
+
var _a, _b;
|
|
49
47
|
const node = {
|
|
50
48
|
prefix: prefix ?? void 0,
|
|
51
49
|
value: value ?? error((prefix == null ? void 0 : prefix.end) ?? (quoteL == null ? void 0 : quoteL.end) ?? (quoteR == null ? void 0 : quoteR.start), [TOKEN_TYPE.VALUE]),
|
|
@@ -59,11 +57,10 @@ function variable(prefix, quoteL, value, quoteR, flags) {
|
|
|
59
57
|
};
|
|
60
58
|
if (flags) {
|
|
61
59
|
node.quote.flags = flags;
|
|
62
|
-
node.end = (_a = node.quote) == null ? void 0 : _a.flags.end;
|
|
60
|
+
node.end = ((_b = (_a = node.quote) == null ? void 0 : _a.flags) == null ? void 0 : _b.end) ?? node.end;
|
|
63
61
|
}
|
|
64
62
|
}
|
|
65
|
-
|
|
66
|
-
return instance;
|
|
63
|
+
return createVariableNode(node);
|
|
67
64
|
}
|
|
68
65
|
function condition(not, property, { propertyOperator, sepL, sepR } = {}, value) {
|
|
69
66
|
var _a;
|
|
@@ -77,10 +74,8 @@ function condition(not, property, { propertyOperator, sepL, sepR } = {}, value)
|
|
|
77
74
|
if (not) {
|
|
78
75
|
node.operator = not;
|
|
79
76
|
}
|
|
80
|
-
if (property)
|
|
81
|
-
|
|
82
|
-
if (propertyOperator)
|
|
83
|
-
node.propertyOperator = propertyOperator;
|
|
77
|
+
if (property) node.property = property;
|
|
78
|
+
if (propertyOperator) node.propertyOperator = propertyOperator;
|
|
84
79
|
if (sepL || sepR) {
|
|
85
80
|
node.sep = {};
|
|
86
81
|
if (sepL) {
|
|
@@ -88,29 +83,26 @@ function condition(not, property, { propertyOperator, sepL, sepR } = {}, value)
|
|
|
88
83
|
node.property || (node.property = error(sepL.start, [TOKEN_TYPE.VALUE]));
|
|
89
84
|
node.propertyOperator || (node.propertyOperator = error((sepL == null ? void 0 : sepL.end) ?? (sepR == null ? void 0 : sepR.start), [TOKEN_TYPE.VALUE]));
|
|
90
85
|
}
|
|
91
|
-
if (sepR)
|
|
92
|
-
|
|
93
|
-
else if (!node.value || node.value instanceof VariableNode) {
|
|
86
|
+
if (sepR) node.sep.right = sepR;
|
|
87
|
+
else if (!node.value || node.value.type === AST_TYPE.VARIABLE) {
|
|
94
88
|
node.sep.right = error(((_a = node.value) == null ? void 0 : _a.start) ?? end, [TOKEN_TYPE.OP_EXPANDED_SEP]);
|
|
95
89
|
}
|
|
96
90
|
} else if (propertyOperator) {
|
|
97
91
|
node.property || (node.property = error(propertyOperator.start, [TOKEN_TYPE.VALUE]));
|
|
98
92
|
}
|
|
99
|
-
|
|
100
|
-
return instance;
|
|
93
|
+
return createConditionNode(node);
|
|
101
94
|
}
|
|
102
95
|
function expression(left, operator2, right) {
|
|
103
|
-
|
|
96
|
+
return createExpressionNode({
|
|
104
97
|
left: left ?? error((operator2 == null ? void 0 : operator2.start) ?? (right == null ? void 0 : right.start), [TOKEN_TYPE.VALUE]),
|
|
105
98
|
operator: operator2 ?? error((left == null ? void 0 : left.end) ?? (right == null ? void 0 : right.start), [TOKEN_TYPE.AND, TOKEN_TYPE.OR]),
|
|
106
99
|
right: right ?? error((operator2 == null ? void 0 : operator2.end) ?? (left == null ? void 0 : left.end), [TOKEN_TYPE.VALUE]),
|
|
107
100
|
start: (left == null ? void 0 : left.start) ?? (operator2 == null ? void 0 : operator2.start) ?? (right == null ? void 0 : right.start),
|
|
108
101
|
end: (right == null ? void 0 : right.end) ?? (operator2 == null ? void 0 : operator2.end) ?? (left == null ? void 0 : left.end)
|
|
109
102
|
});
|
|
110
|
-
return instance;
|
|
111
103
|
}
|
|
112
104
|
function group(operator2, prefix, parenL, condition2, parenR) {
|
|
113
|
-
|
|
105
|
+
return createGroupNode({
|
|
114
106
|
prefix: prefix ?? operator2 ?? void 0,
|
|
115
107
|
expression: condition2 ?? error((parenL == null ? void 0 : parenL.end) ?? (parenR == null ? void 0 : parenR.start), [TOKEN_TYPE.VALUE]),
|
|
116
108
|
paren: {
|
|
@@ -119,13 +111,11 @@ function group(operator2, prefix, parenL, condition2, parenR) {
|
|
|
119
111
|
},
|
|
120
112
|
start: (prefix == null ? void 0 : prefix.start) ?? (operator2 == null ? void 0 : operator2.start) ?? (parenL == null ? void 0 : parenL.start) ?? (condition2 == null ? void 0 : condition2.start) ?? (parenR == null ? void 0 : parenR.start),
|
|
121
113
|
end: (parenR == null ? void 0 : parenR.end) ?? (condition2 == null ? void 0 : condition2.end) ?? (parenL == null ? void 0 : parenL.end) ?? (operator2 == null ? void 0 : operator2.end) ?? (prefix == null ? void 0 : prefix.end)
|
|
122
|
-
};
|
|
123
|
-
const instance = new GroupNode(node);
|
|
124
|
-
return instance;
|
|
114
|
+
});
|
|
125
115
|
}
|
|
126
116
|
function array(bracketL, values, bracketR) {
|
|
127
117
|
var _a, _b;
|
|
128
|
-
|
|
118
|
+
return createArrayNode({
|
|
129
119
|
values,
|
|
130
120
|
bracket: {
|
|
131
121
|
left: bracketL,
|
|
@@ -134,9 +124,7 @@ function array(bracketL, values, bracketR) {
|
|
|
134
124
|
},
|
|
135
125
|
start: bracketL.start,
|
|
136
126
|
end: (bracketR == null ? void 0 : bracketR.end) ?? ((_b = values[values.length - 1]) == null ? void 0 : _b.end) ?? bracketL.end
|
|
137
|
-
};
|
|
138
|
-
const instance = new ArrayNode(node);
|
|
139
|
-
return instance;
|
|
127
|
+
});
|
|
140
128
|
}
|
|
141
129
|
export {
|
|
142
130
|
array,
|
package/dist/ast/index.d.ts
CHANGED
|
@@ -1,4 +1,12 @@
|
|
|
1
1
|
export * as builders from "./builders/index.js";
|
|
2
|
-
export
|
|
2
|
+
export { createArrayNode } from "./createArrayNode.js";
|
|
3
|
+
export { createCondition } from "./createNormalizedCondition.js";
|
|
4
|
+
export { createConditionNode } from "./createConditionNode.js";
|
|
5
|
+
export { createExpression } from "./createNormalizedExpression.js";
|
|
6
|
+
export { createExpressionNode } from "./createExpressionNode.js";
|
|
7
|
+
export { createGroupNode } from "./createGroupNode.js";
|
|
8
|
+
export { createToken } from "./createToken.js";
|
|
9
|
+
export { createVariableNode } from "./createVariableNode.js";
|
|
10
|
+
export { error } from "./error.js";
|
|
3
11
|
export { token } from "./handlers.js";
|
|
4
12
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/ast/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/ast/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,QAAQ,MAAM,qBAAqB,CAAA;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/ast/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,QAAQ,MAAM,qBAAqB,CAAA;AAG/C,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAA;AACtD,OAAO,EAAE,eAAe,EAAE,MAAM,gCAAgC,CAAA;AAChE,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAA;AAC9D,OAAO,EAAE,gBAAgB,EAAE,MAAM,iCAAiC,CAAA;AAClE,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAA;AAChE,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAA;AACtD,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAA;AAC9C,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAA;AAC5D,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAA;AAClC,OAAO,EAAE,KAAK,EAAE,MAAM,eAAe,CAAA"}
|
package/dist/ast/index.js
CHANGED
|
@@ -1,8 +1,24 @@
|
|
|
1
1
|
import * as index from "./builders/index.js";
|
|
2
|
-
import
|
|
2
|
+
import { createArrayNode } from "./createArrayNode.js";
|
|
3
|
+
import { createCondition } from "./createNormalizedCondition.js";
|
|
4
|
+
import { createConditionNode } from "./createConditionNode.js";
|
|
5
|
+
import { createExpression } from "./createNormalizedExpression.js";
|
|
6
|
+
import { createExpressionNode } from "./createExpressionNode.js";
|
|
7
|
+
import { createGroupNode } from "./createGroupNode.js";
|
|
8
|
+
import { createToken } from "./createToken.js";
|
|
9
|
+
import { createVariableNode } from "./createVariableNode.js";
|
|
10
|
+
import { error } from "./error.js";
|
|
3
11
|
import { token } from "./handlers.js";
|
|
4
12
|
export {
|
|
5
13
|
index as builders,
|
|
6
|
-
|
|
14
|
+
createArrayNode,
|
|
15
|
+
createCondition,
|
|
16
|
+
createConditionNode,
|
|
17
|
+
createExpression,
|
|
18
|
+
createExpressionNode,
|
|
19
|
+
createGroupNode,
|
|
20
|
+
createToken,
|
|
21
|
+
createVariableNode,
|
|
22
|
+
error,
|
|
7
23
|
token
|
|
8
24
|
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"defaultConditionNormalizer.d.ts","sourceRoot":"","sources":["../../src/defaults/defaultConditionNormalizer.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAc,MAAM,oBAAoB,CAAA;AAGzE,eAAO,MAAM,0BAA0B,EAAE,mBAKxC,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"defaultKeyParser.d.ts","sourceRoot":"","sources":["../../src/defaults/defaultKeyParser.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAA;AAGnD,eAAO,MAAM,gBAAgB,EAAE,SAI7B,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"defaultPrefixApplier.d.ts","sourceRoot":"","sources":["../../src/defaults/defaultPrefixApplier.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAA;AAGvD,eAAO,MAAM,oBAAoB,EAAE,aAGlC,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"defaultValueComparer.d.ts","sourceRoot":"","sources":["../../src/defaults/defaultValueComparer.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAA;AAGvD,eAAO,MAAM,oBAAoB,EAAE,aAGlC,CAAA"}
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
export { applyBoolean } from "./applyBoolean.js";
|
|
2
|
-
export { applyPrefix } from "./applyPrefix.js";
|
|
3
1
|
export { defaultConditionNormalizer } from "./defaultConditionNormalizer.js";
|
|
4
2
|
export { defaultKeyParser } from "./defaultKeyParser.js";
|
|
5
3
|
export { defaultPrefixApplier } from "./defaultPrefixApplier.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/defaults/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,0BAA0B,EAAE,MAAM,iCAAiC,CAAA;AAC5E,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAA;AACxD,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAA;AAChE,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAA"}
|
|
@@ -1,12 +1,8 @@
|
|
|
1
|
-
import { applyBoolean } from "./applyBoolean.js";
|
|
2
|
-
import { applyPrefix } from "./applyPrefix.js";
|
|
3
1
|
import { defaultConditionNormalizer } from "./defaultConditionNormalizer.js";
|
|
4
2
|
import { defaultKeyParser } from "./defaultKeyParser.js";
|
|
5
3
|
import { defaultPrefixApplier } from "./defaultPrefixApplier.js";
|
|
6
4
|
import { defaultValueComparer } from "./defaultValueComparer.js";
|
|
7
5
|
export {
|
|
8
|
-
applyBoolean,
|
|
9
|
-
applyPrefix,
|
|
10
6
|
defaultConditionNormalizer,
|
|
11
7
|
defaultKeyParser,
|
|
12
8
|
defaultPrefixApplier,
|
|
@@ -1,9 +1,6 @@
|
|
|
1
1
|
var __defProp = Object.defineProperty;
|
|
2
2
|
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
3
|
-
var __publicField = (obj, key, value) =>
|
|
4
|
-
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
5
|
-
return value;
|
|
6
|
-
};
|
|
3
|
+
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
7
4
|
import { Parser } from "../Parser.js";
|
|
8
5
|
class ShortcutContextParser extends Parser {
|
|
9
6
|
constructor(dummyContext, validRegexFlags = ["i", "u", "m"]) {
|
|
@@ -67,16 +64,14 @@ class ShortcutContextParser extends Parser {
|
|
|
67
64
|
}
|
|
68
65
|
}
|
|
69
66
|
}
|
|
70
|
-
if (tokens.length > 0)
|
|
71
|
-
return tokens;
|
|
67
|
+
if (tokens.length > 0) return tokens;
|
|
72
68
|
},
|
|
73
69
|
conditionNormalizer({ operator, value, regexFlags, isRegex, isNegated, isQuoted }) {
|
|
74
70
|
let finalValue = value;
|
|
75
71
|
let finalOperator = operator;
|
|
76
72
|
if (typeof value === "string" && !isQuoted) {
|
|
77
73
|
const asNum = parseInt(value, 2);
|
|
78
|
-
if (!isNaN(asNum))
|
|
79
|
-
finalValue = asNum;
|
|
74
|
+
if (!isNaN(asNum)) finalValue = asNum;
|
|
80
75
|
if (["true", "false"].includes(value)) {
|
|
81
76
|
finalValue = value === "true";
|
|
82
77
|
}
|
|
@@ -118,8 +113,7 @@ class ShortcutContextParser extends Parser {
|
|
|
118
113
|
this.regexablekeys.push(prev ? `${prev}.${key}` : key);
|
|
119
114
|
}
|
|
120
115
|
} else {
|
|
121
|
-
if (typeof context[key] !== "object")
|
|
122
|
-
throw new Error("A dummy context value must be a boolean or an object.");
|
|
116
|
+
if (typeof context[key] !== "object") throw new Error("A dummy context value must be a boolean or an object.");
|
|
123
117
|
this._extractKeysFromContext(context[key], prev ? `${prev}.${key}` : key);
|
|
124
118
|
}
|
|
125
119
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
export * as ast from "./ast/
|
|
1
|
+
export * as ast from "./ast/index.js";
|
|
2
2
|
export { Parser } from "./Parser.js";
|
|
3
3
|
export * from "./types/index.js";
|
|
4
4
|
export * as utils from "./utils/index.js";
|
|
5
|
+
export * as defaults from "./defaults/index.js";
|
|
5
6
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,GAAG,MAAM,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,GAAG,MAAM,gBAAgB,CAAA;AACrC,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AACpC,cAAc,kBAAkB,CAAA;AAChC,OAAO,KAAK,KAAK,MAAM,kBAAkB,CAAA;AACzC,OAAO,KAAK,QAAQ,MAAM,qBAAqB,CAAA"}
|
package/dist/index.js
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import * as index from "./ast/
|
|
1
|
+
import * as index from "./ast/index.js";
|
|
2
2
|
import { Parser } from "./Parser.js";
|
|
3
3
|
import { AST_TYPE, TOKEN_TYPE } from "./types/ast.js";
|
|
4
4
|
import { SUGGESTION_TYPE } from "./types/autocomplete.js";
|
|
5
5
|
import { ERROR_CODES } from "./types/errors.js";
|
|
6
6
|
import * as index$1 from "./utils/index.js";
|
|
7
|
+
import * as index$2 from "./defaults/index.js";
|
|
7
8
|
export {
|
|
8
9
|
AST_TYPE,
|
|
9
10
|
ERROR_CODES,
|
|
@@ -11,5 +12,6 @@ export {
|
|
|
11
12
|
SUGGESTION_TYPE,
|
|
12
13
|
TOKEN_TYPE,
|
|
13
14
|
index as ast,
|
|
15
|
+
index$2 as defaults,
|
|
14
16
|
index$1 as utils
|
|
15
17
|
};
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import type { ERROR_CODES, ErrorInfo } from "../types/errors.js";
|
|
2
|
-
|
|
2
|
+
/** @internal */
|
|
3
|
+
export declare class ExpressitError<T extends ERROR_CODES> extends Error {
|
|
3
4
|
version: string;
|
|
4
5
|
repo: string;
|
|
5
6
|
type: T;
|
|
6
7
|
info: ErrorInfo<T>;
|
|
7
8
|
constructor(type: T, info: ErrorInfo<T>, message?: string);
|
|
8
9
|
}
|
|
9
|
-
//# sourceMappingURL=
|
|
10
|
+
//# sourceMappingURL=ExpressitError.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ExpressitError.d.ts","sourceRoot":"","sources":["../../src/internal/ExpressitError.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAA;AAEhE,gBAAgB;AAChB,qBAAa,cAAc,CAAC,CAAC,SAAS,WAAW,CAAE,SAAQ,KAAK;IAC/D,OAAO,EAAE,MAAM,CAAU;IAEzB,IAAI,EAAE,MAAM,CAAa;IAEzB,IAAI,EAAE,CAAC,CAAA;IAEP,IAAI,EAAE,SAAS,CAAC,CAAC,CAAC,CAAA;gBAEN,IAAI,EAAE,CAAC,EAAE,IAAI,EAAE,SAAS,CAAC,CAAC,CAAC,EAAE,OAAO,CAAC,EAAE,MAAM;CAYzD"}
|
|
@@ -1,14 +1,11 @@
|
|
|
1
1
|
var __defProp = Object.defineProperty;
|
|
2
2
|
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
3
|
-
var __publicField = (obj, key, value) =>
|
|
4
|
-
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
5
|
-
return value;
|
|
6
|
-
};
|
|
3
|
+
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
7
4
|
import { crop } from "@alanscodelog/utils/crop.js";
|
|
8
5
|
import { indent } from "@alanscodelog/utils/indent.js";
|
|
9
6
|
import { pretty } from "@alanscodelog/utils/pretty.js";
|
|
10
7
|
import { version, repository } from "../package.js";
|
|
11
|
-
class
|
|
8
|
+
class ExpressitError extends Error {
|
|
12
9
|
constructor(type, info, message) {
|
|
13
10
|
super(
|
|
14
11
|
message ? `${message}
|
|
@@ -39,5 +36,5 @@ function forceStringifyErrors(_key, value) {
|
|
|
39
36
|
return value;
|
|
40
37
|
}
|
|
41
38
|
export {
|
|
42
|
-
|
|
39
|
+
ExpressitError
|
|
43
40
|
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"applyBoolean.d.ts","sourceRoot":"","sources":["../../src/internal/applyBoolean.ts"],"names":[],"mappings":"AAAA,gBAAgB;AAChB,wBAAgB,YAAY,CAAC,IAAI,EAAE,OAAO,GAAG,SAAS,EAAE,KAAK,EAAE,OAAO,GAAG,OAAO,CAO/E"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { PrefixApplier } from "
|
|
1
|
+
import type { PrefixApplier } from "../types/parser.js";
|
|
2
2
|
/** @internal */
|
|
3
3
|
export declare function applyPrefix(left: string | undefined, right: string, prefixApplier: PrefixApplier): string;
|
|
4
4
|
//# sourceMappingURL=applyPrefix.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"applyPrefix.d.ts","sourceRoot":"","sources":["../../src/internal/applyPrefix.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAA;AAEvD,gBAAgB;AAChB,wBAAgB,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,SAAS,EAAE,KAAK,EAAE,MAAM,EAAE,aAAa,EAAE,aAAa,GAAG,MAAM,CAGzG"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
-
import type { FullParserOptions } from "
|
|
1
|
+
import type { FullParserOptions } from "../types/parser.js";
|
|
2
|
+
/** @internal */
|
|
2
3
|
export declare function checkParserOpts<T extends {}>(opts: FullParserOptions<T>, evaluatorChecks?: boolean, validatorChecks?: boolean): void;
|
|
3
4
|
//# sourceMappingURL=checkParserOpts.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"checkParserOpts.d.ts","sourceRoot":"","sources":["../../src/internal/checkParserOpts.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,iBAAiB,EAAiB,MAAM,oBAAoB,CAAA;AAE1E,gBAAgB;AAChB,wBAAgB,eAAe,CAAC,CAAC,SAAS,EAAE,EAAE,IAAI,EAAE,iBAAiB,CAAC,CAAC,CAAC,EAAE,eAAe,GAAE,OAAe,EAAE,eAAe,GAAE,OAAe,GAAG,IAAI,CAoIlJ"}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { isBlank } from "@alanscodelog/utils/isBlank.js";
|
|
2
2
|
import { pushIfNotIn } from "@alanscodelog/utils/pushIfNotIn.js";
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
3
|
+
import { ExpressitError } from "./ExpressitError.js";
|
|
4
|
+
import { defaultConditionNormalizer } from "../defaults/defaultConditionNormalizer.js";
|
|
5
|
+
import { defaultValueComparer } from "../defaults/defaultValueComparer.js";
|
|
6
|
+
import { ERROR_CODES } from "../types/errors.js";
|
|
7
7
|
function checkParserOpts(opts, evaluatorChecks = false, validatorChecks = false) {
|
|
8
8
|
var _a, _b, _c, _d, _e, _f, _g, _h, _i;
|
|
9
9
|
if (!evaluatorChecks) {
|
|
@@ -16,12 +16,10 @@ function checkParserOpts(opts, evaluatorChecks = false, validatorChecks = false)
|
|
|
16
16
|
...opts.regexValues ? ["/"] : []
|
|
17
17
|
];
|
|
18
18
|
const extra = [];
|
|
19
|
-
if (opts.expandedPropertySeparator)
|
|
20
|
-
|
|
21
|
-
if (opts.customPropertyOperators)
|
|
22
|
-
pushIfNotIn(extra, opts.customPropertyOperators);
|
|
19
|
+
if (opts.expandedPropertySeparator) extra.push(opts.expandedPropertySeparator);
|
|
20
|
+
if (opts.customPropertyOperators) pushIfNotIn(extra, opts.customPropertyOperators);
|
|
23
21
|
if (opts.expandedPropertySeparator && isBlank(opts.expandedPropertySeparator)) {
|
|
24
|
-
throw new
|
|
22
|
+
throw new ExpressitError(
|
|
25
23
|
ERROR_CODES.PARSER_CONFLICTING_OPTIONS_ERROR,
|
|
26
24
|
{ prohibited: [""], invalid: opts.expandedPropertySeparator },
|
|
27
25
|
`expandedPropertySeparator cannot be blank`
|
|
@@ -29,7 +27,7 @@ function checkParserOpts(opts, evaluatorChecks = false, validatorChecks = false)
|
|
|
29
27
|
}
|
|
30
28
|
const customInvalid = (_a = opts.customPropertyOperators) == null ? void 0 : _a.find((_) => isBlank(_));
|
|
31
29
|
if (customInvalid !== void 0) {
|
|
32
|
-
throw new
|
|
30
|
+
throw new ExpressitError(
|
|
33
31
|
ERROR_CODES.PARSER_CONFLICTING_OPTIONS_ERROR,
|
|
34
32
|
{ prohibited: [""], invalid: customInvalid },
|
|
35
33
|
`customPropertyOperators cannot contain blank entries`
|
|
@@ -37,7 +35,7 @@ function checkParserOpts(opts, evaluatorChecks = false, validatorChecks = false)
|
|
|
37
35
|
}
|
|
38
36
|
const prefixInvalid = (_b = opts.prefixableStrings) == null ? void 0 : _b.find((_) => isBlank(_));
|
|
39
37
|
if (prefixInvalid !== void 0) {
|
|
40
|
-
throw new
|
|
38
|
+
throw new ExpressitError(
|
|
41
39
|
ERROR_CODES.PARSER_CONFLICTING_OPTIONS_ERROR,
|
|
42
40
|
{ prohibited: [""], invalid: prefixInvalid },
|
|
43
41
|
`prefixableStrings cannot contain blank entries`
|
|
@@ -46,7 +44,7 @@ function checkParserOpts(opts, evaluatorChecks = false, validatorChecks = false)
|
|
|
46
44
|
for (const key of ["and", "or", "not"]) {
|
|
47
45
|
const invalid = (_d = (_c = opts.keywords[key]) == null ? void 0 : _c.find((_) => isBlank(_.value))) == null ? void 0 : _d.value;
|
|
48
46
|
if (invalid !== void 0) {
|
|
49
|
-
throw new
|
|
47
|
+
throw new ExpressitError(
|
|
50
48
|
ERROR_CODES.PARSER_CONFLICTING_OPTIONS_ERROR,
|
|
51
49
|
{ prohibited: [""], invalid },
|
|
52
50
|
`keywords.${key} cannot contain entries with blank values`
|
|
@@ -59,7 +57,7 @@ function checkParserOpts(opts, evaluatorChecks = false, validatorChecks = false)
|
|
|
59
57
|
const messageInvalidBool = "cannot contain boolean operators or special symbols, but found";
|
|
60
58
|
const invalidPrefixableString = (_e = opts.prefixableStrings) == null ? void 0 : _e.find((val) => all.includes(val));
|
|
61
59
|
if (invalidPrefixableString) {
|
|
62
|
-
throw new
|
|
60
|
+
throw new ExpressitError(
|
|
63
61
|
ERROR_CODES.PARSER_CONFLICTING_OPTIONS_ERROR,
|
|
64
62
|
{ prohibited: all, invalid: invalidPrefixableString },
|
|
65
63
|
`prefixableStrings ${messageInvalidAny} "${invalidPrefixableString}"`
|
|
@@ -67,7 +65,7 @@ function checkParserOpts(opts, evaluatorChecks = false, validatorChecks = false)
|
|
|
67
65
|
}
|
|
68
66
|
const invalidExpandedPropertySeparator = allKeywords.find((_) => _ === opts.expandedPropertySeparator);
|
|
69
67
|
if (invalidExpandedPropertySeparator) {
|
|
70
|
-
throw new
|
|
68
|
+
throw new ExpressitError(
|
|
71
69
|
ERROR_CODES.PARSER_CONFLICTING_OPTIONS_ERROR,
|
|
72
70
|
{ prohibited: allKeywords, invalid: invalidExpandedPropertySeparator },
|
|
73
71
|
`expandedPropertySeparator ${messageInvalidBool} "${invalidExpandedPropertySeparator}"`
|
|
@@ -75,7 +73,7 @@ function checkParserOpts(opts, evaluatorChecks = false, validatorChecks = false)
|
|
|
75
73
|
}
|
|
76
74
|
const invalidCustomPropertyOperator = ((_f = opts.customPropertyOperators) == null ? void 0 : _f.find((val) => keywords.includes(val))) ? opts.expandedPropertySeparator : void 0;
|
|
77
75
|
if (invalidCustomPropertyOperator) {
|
|
78
|
-
throw new
|
|
76
|
+
throw new ExpressitError(
|
|
79
77
|
ERROR_CODES.PARSER_CONFLICTING_OPTIONS_ERROR,
|
|
80
78
|
{ prohibited: keywords, invalid: invalidCustomPropertyOperator },
|
|
81
79
|
`customPropertyOperator ${messageInvalidBool} "${invalidCustomPropertyOperator}"`
|
|
@@ -84,28 +82,22 @@ function checkParserOpts(opts, evaluatorChecks = false, validatorChecks = false)
|
|
|
84
82
|
}
|
|
85
83
|
if (evaluatorChecks) {
|
|
86
84
|
const requireCustomNormalizer = [];
|
|
87
|
-
if ((((_g = opts.prefixableStrings) == null ? void 0 : _g.length) ?? 0) > 0)
|
|
88
|
-
|
|
89
|
-
if ((((
|
|
90
|
-
|
|
91
|
-
if ((((_i = opts.expandedPropertySeparator) == null ? void 0 : _i.length) ?? 0) > 0)
|
|
92
|
-
requireCustomNormalizer.push("expandedPropertySeparator");
|
|
93
|
-
if (opts.regexValues)
|
|
94
|
-
requireCustomNormalizer.push("regexValues");
|
|
85
|
+
if ((((_g = opts.prefixableStrings) == null ? void 0 : _g.length) ?? 0) > 0) requireCustomNormalizer.push("prefixableStrings");
|
|
86
|
+
if ((((_h = opts.customPropertyOperators) == null ? void 0 : _h.length) ?? 0) > 0) requireCustomNormalizer.push("customPropertyOperators");
|
|
87
|
+
if ((((_i = opts.expandedPropertySeparator) == null ? void 0 : _i.length) ?? 0) > 0) requireCustomNormalizer.push("expandedPropertySeparator");
|
|
88
|
+
if (opts.regexValues) requireCustomNormalizer.push("regexValues");
|
|
95
89
|
if (requireCustomNormalizer.length > 0 && opts.conditionNormalizer === defaultConditionNormalizer) {
|
|
96
|
-
throw new
|
|
90
|
+
throw new ExpressitError(
|
|
97
91
|
ERROR_CODES.PARSER_OPTION_REQUIRED_ERROR,
|
|
98
92
|
{ options: requireCustomNormalizer, requires: "conditionNormalizer" },
|
|
99
93
|
`A custom conditionNormalizer function must be specified when using the following options: ${requireCustomNormalizer.join(", ")}`
|
|
100
94
|
);
|
|
101
95
|
}
|
|
102
96
|
const requireCustomComparer = [];
|
|
103
|
-
if (opts.regexValues)
|
|
104
|
-
|
|
105
|
-
if (opts.regexValues)
|
|
106
|
-
requireCustomComparer.push("arrayValues");
|
|
97
|
+
if (opts.regexValues) requireCustomComparer.push("regexValues");
|
|
98
|
+
if (opts.regexValues) requireCustomComparer.push("arrayValues");
|
|
107
99
|
if (requireCustomComparer.length > 0 && opts.valueComparer === defaultValueComparer) {
|
|
108
|
-
throw new
|
|
100
|
+
throw new ExpressitError(
|
|
109
101
|
ERROR_CODES.PARSER_OPTION_REQUIRED_ERROR,
|
|
110
102
|
{ options: requireCustomComparer, requires: "valueComparer" },
|
|
111
103
|
`A custom valueComparer function must be specified when using the following options: ${requireCustomComparer.join(", ")}`
|
|
@@ -114,7 +106,7 @@ function checkParserOpts(opts, evaluatorChecks = false, validatorChecks = false)
|
|
|
114
106
|
}
|
|
115
107
|
if (validatorChecks) {
|
|
116
108
|
if (opts.valueValidator === void 0) {
|
|
117
|
-
throw new
|
|
109
|
+
throw new ExpressitError(
|
|
118
110
|
ERROR_CODES.PARSER_OPTION_REQUIRED_ERROR,
|
|
119
111
|
{ requires: "valueValidator" },
|
|
120
112
|
`A custom valueValidator function must be specified when using the validate method.`
|