@witchcraft/expressit 0.2.2 → 0.3.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 -2
- package/dist/Lexer.d.ts +99 -94
- package/dist/Lexer.d.ts.map +1 -1
- package/dist/Lexer.js +221 -574
- package/dist/Parser.d.ts +26 -26
- package/dist/Parser.d.ts.map +1 -1
- package/dist/Parser.js +106 -116
- package/dist/ast/builders/array.js +7 -8
- package/dist/ast/builders/condition.d.ts +1 -1
- package/dist/ast/builders/condition.d.ts.map +1 -1
- package/dist/ast/builders/condition.js +2 -1
- package/dist/ast/builders/delim.d.ts +2 -2
- package/dist/ast/builders/delim.d.ts.map +1 -1
- package/dist/ast/builders/error.d.ts +2 -2
- package/dist/ast/builders/error.d.ts.map +1 -1
- package/dist/ast/builders/expression.d.ts +2 -2
- package/dist/ast/builders/expression.d.ts.map +1 -1
- package/dist/ast/builders/expression.js +4 -8
- package/dist/ast/builders/group.d.ts +1 -1
- package/dist/ast/builders/group.d.ts.map +1 -1
- package/dist/ast/builders/group.js +8 -11
- package/dist/ast/builders/pos.d.ts +2 -2
- package/dist/ast/builders/pos.d.ts.map +1 -1
- package/dist/ast/builders/token.d.ts +2 -2
- package/dist/ast/builders/token.d.ts.map +1 -1
- package/dist/ast/builders/token.js +1 -1
- package/dist/ast/builders/type.d.ts +2 -2
- package/dist/ast/builders/type.d.ts.map +1 -1
- package/dist/ast/builders/variable.d.ts +3 -3
- package/dist/ast/builders/variable.d.ts.map +1 -1
- package/dist/ast/builders/variable.js +5 -6
- package/dist/ast/createConditionNode.d.ts +1 -1
- package/dist/ast/createConditionNode.d.ts.map +1 -1
- package/dist/ast/createConditionNode.js +1 -2
- package/dist/ast/createGroupNode.d.ts +1 -1
- package/dist/ast/createGroupNode.d.ts.map +1 -1
- package/dist/ast/createToken.d.ts +2 -2
- package/dist/ast/createToken.d.ts.map +1 -1
- package/dist/ast/createToken.js +2 -2
- package/dist/ast/error.d.ts +2 -2
- package/dist/ast/error.d.ts.map +1 -1
- package/dist/ast/error.js +1 -0
- package/dist/ast/handlers.d.ts +23 -23
- package/dist/ast/handlers.d.ts.map +1 -1
- package/dist/ast/handlers.js +23 -26
- package/dist/examples/ParserWithSqlSupport.d.ts +5 -5
- package/dist/examples/ParserWithSqlSupport.d.ts.map +1 -1
- package/dist/examples/ParserWithSqlSupport.js +22 -28
- package/dist/examples/ShortcutContextParser.js +2 -5
- package/dist/index.js +2 -2
- package/dist/internal/ExpressitError.d.ts +2 -2
- package/dist/internal/ExpressitError.d.ts.map +1 -1
- package/dist/internal/ExpressitError.js +7 -10
- package/dist/internal/checkParserOpts.js +21 -22
- package/dist/internal/escapeVariableOrPrefix.js +1 -1
- package/dist/internal/parseParserOptions.js +3 -4
- package/dist/package.json.js +2 -60
- package/dist/types/ast.d.ts +60 -58
- package/dist/types/ast.d.ts.map +1 -1
- package/dist/types/ast.js +26 -27
- package/dist/types/autocomplete.d.ts +23 -21
- package/dist/types/autocomplete.d.ts.map +1 -1
- package/dist/types/autocomplete.js +24 -21
- package/dist/types/errors.d.ts +12 -10
- package/dist/types/errors.d.ts.map +1 -1
- package/dist/types/errors.js +8 -7
- package/dist/types/index.js +2 -2
- package/dist/types/parser.d.ts +3 -3
- package/dist/types/parser.d.ts.map +1 -1
- package/dist/utils/extractTokens.js +4 -5
- package/dist/utils/generateParentsMap.js +7 -8
- package/dist/utils/getCursorInfo.js +5 -3
- package/dist/utils/getOppositeDelimiter.d.ts +2 -2
- package/dist/utils/getOppositeDelimiter.d.ts.map +1 -1
- package/dist/utils/getOppositeDelimiter.js +1 -1
- package/dist/utils/getSurroundingErrors.js +2 -3
- package/dist/utils/isBracket.js +1 -1
- package/dist/utils/isDelimiter.d.ts +2 -2
- package/dist/utils/isDelimiter.d.ts.map +1 -1
- package/dist/utils/isDelimiter.js +1 -1
- package/dist/utils/isNode.js +1 -1
- package/dist/utils/isParen.d.ts +2 -2
- package/dist/utils/isParen.d.ts.map +1 -1
- package/dist/utils/isParen.js +1 -1
- package/dist/utils/isQuote.d.ts +2 -2
- package/dist/utils/isQuote.d.ts.map +1 -1
- package/dist/utils/isQuote.js +1 -1
- package/dist/utils/isToken.js +1 -1
- package/dist/utils/prettyAst.js +10 -11
- package/package.json +19 -20
- package/src/Lexer.ts +100 -90
- package/src/Parser.ts +68 -68
- package/src/ast/builders/condition.ts +3 -3
- package/src/ast/builders/delim.ts +4 -4
- package/src/ast/builders/error.ts +3 -3
- package/src/ast/builders/expression.ts +4 -8
- package/src/ast/builders/group.ts +2 -4
- package/src/ast/builders/pos.ts +3 -3
- package/src/ast/builders/token.ts +3 -3
- package/src/ast/builders/type.ts +2 -2
- package/src/ast/builders/variable.ts +5 -5
- package/src/ast/createConditionNode.ts +2 -2
- package/src/ast/createGroupNode.ts +4 -4
- package/src/ast/createToken.ts +6 -6
- package/src/ast/error.ts +2 -2
- package/src/ast/handlers.ts +20 -20
- package/src/examples/ParserWithSqlSupport.ts +12 -6
- package/src/internal/ExpressitError.ts +6 -6
- package/src/internal/checkParserOpts.ts +13 -13
- package/src/internal/escapeVariableOrPrefix.ts +1 -1
- package/src/types/ast.ts +101 -96
- package/src/types/autocomplete.ts +26 -22
- package/src/types/errors.ts +18 -13
- package/src/types/parser.ts +3 -3
- package/src/utils/extractTokens.ts +1 -1
- package/src/utils/getCursorInfo.ts +2 -2
- package/src/utils/getOppositeDelimiter.ts +3 -3
- package/src/utils/getSurroundingErrors.ts +4 -4
- package/src/utils/isDelimiter.ts +3 -3
- package/src/utils/isParen.ts +2 -2
- package/src/utils/isQuote.ts +2 -2
- package/src/utils/prettyAst.ts +3 -3
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
|
|
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) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
4
|
-
import { unreachable } from "@alanscodelog/utils/unreachable.js";
|
|
1
|
+
import { unreachable } from "@alanscodelog/utils/unreachable";
|
|
5
2
|
import { Parser } from "../Parser.js";
|
|
6
3
|
import { AST_TYPE, TOKEN_TYPE } from "../types/ast.js";
|
|
7
4
|
class ParserWithSqlSupport extends Parser {
|
|
5
|
+
sqlEscapeValue;
|
|
6
|
+
operatorMap;
|
|
7
|
+
propertyDefinitions;
|
|
8
|
+
operatorDefinitions;
|
|
8
9
|
constructor(propertyDefinitions, operatorDefinitions, { sqlEscapeValue }) {
|
|
9
10
|
const operators = [];
|
|
10
11
|
const operatorMap = {};
|
|
@@ -31,7 +32,6 @@ class ParserWithSqlSupport extends Parser {
|
|
|
31
32
|
customPropertyOperators: operators,
|
|
32
33
|
prefixableGroups: false,
|
|
33
34
|
valueComparer: (condition, contextValue, _context) => {
|
|
34
|
-
var _a;
|
|
35
35
|
if (typeof condition.value !== typeof contextValue) {
|
|
36
36
|
throw new Error(`Expected type of property ${condition.property[0]} to be the same type as the context value ${contextValue} (${typeof contextValue}). If the ast has been validated this is likely because the type of the context value is incorrect.`);
|
|
37
37
|
}
|
|
@@ -40,13 +40,12 @@ class ParserWithSqlSupport extends Parser {
|
|
|
40
40
|
const propDefinition = propertyDefinitions[prop];
|
|
41
41
|
const operatorDefinition = condition.operator && operatorDefinitions[condition.operator];
|
|
42
42
|
if (!operatorDefinition) unreachable("Did you validate the ast before evaluating it?");
|
|
43
|
-
const isSupported = !
|
|
43
|
+
const isSupported = !propDefinition.supportedOperators?.includes(condition.operator);
|
|
44
44
|
if (!isSupported) unreachable("Did you validate the ast before evaluating it?");
|
|
45
45
|
const res = operatorDefinition.valueComparer(condition, contextValue);
|
|
46
46
|
return res;
|
|
47
47
|
},
|
|
48
48
|
valueValidator: (_contextValue, query) => {
|
|
49
|
-
var _a, _b, _c;
|
|
50
49
|
const prop = query.propertyKeys[0];
|
|
51
50
|
let tokens = [];
|
|
52
51
|
const propDefinition = propertyDefinitions[prop];
|
|
@@ -62,12 +61,12 @@ class ParserWithSqlSupport extends Parser {
|
|
|
62
61
|
const opKey = op && operatorMap[op.value];
|
|
63
62
|
if (!op || !opKey) {
|
|
64
63
|
tokens.push({
|
|
65
|
-
start: (
|
|
66
|
-
end: (
|
|
64
|
+
start: (op ?? query.condition)?.start,
|
|
65
|
+
end: (op ?? query.condition)?.end,
|
|
67
66
|
type: "unknownOperator"
|
|
68
67
|
});
|
|
69
68
|
} else {
|
|
70
|
-
if (propDefinition.supportedOperators && !
|
|
69
|
+
if (propDefinition.supportedOperators && !propDefinition.supportedOperators?.includes(opKey)) {
|
|
71
70
|
tokens.push({
|
|
72
71
|
start: query.condition.start,
|
|
73
72
|
end: query.condition.end,
|
|
@@ -94,7 +93,7 @@ class ParserWithSqlSupport extends Parser {
|
|
|
94
93
|
if (tokens.length > 0) return tokens;
|
|
95
94
|
return;
|
|
96
95
|
}
|
|
97
|
-
if (
|
|
96
|
+
if (val?.type !== "VARIABLE") unreachable();
|
|
98
97
|
const value = val.value.value;
|
|
99
98
|
const res = convertAndValidateValue(query.isQuoted, value, prop, propertyDefinitions);
|
|
100
99
|
if (res instanceof Error) {
|
|
@@ -110,8 +109,7 @@ class ParserWithSqlSupport extends Parser {
|
|
|
110
109
|
if (tokens.length > 0) return tokens;
|
|
111
110
|
},
|
|
112
111
|
conditionNormalizer(query) {
|
|
113
|
-
|
|
114
|
-
const prop = (_a = query.property) == null ? void 0 : _a[0];
|
|
112
|
+
const prop = query.property?.[0];
|
|
115
113
|
if (!prop) unreachable("Did you validate the ast before normalizing it?");
|
|
116
114
|
const propDefinition = propertyDefinitions[prop];
|
|
117
115
|
let finalValue;
|
|
@@ -140,7 +138,7 @@ class ParserWithSqlSupport extends Parser {
|
|
|
140
138
|
if (!opKey) unreachable("Did you validate the ast before normalizing it?");
|
|
141
139
|
const operatorDefinition = opKey && operatorDefinitions[opKey];
|
|
142
140
|
if (!operatorDefinition) unreachable("Did you validate the ast before normalizing it?");
|
|
143
|
-
const isNegatableOperator =
|
|
141
|
+
const isNegatableOperator = operatorDefinition.negatedOperators?.includes(query.operator);
|
|
144
142
|
finalOperator = operatorDefinition.operator;
|
|
145
143
|
let isNegated = query.isNegated;
|
|
146
144
|
if (isNegatableOperator) {
|
|
@@ -149,28 +147,25 @@ class ParserWithSqlSupport extends Parser {
|
|
|
149
147
|
return { value: finalValue, operator: finalOperator, negate: isNegated };
|
|
150
148
|
}
|
|
151
149
|
});
|
|
152
|
-
__publicField(this, "sqlEscapeValue");
|
|
153
|
-
__publicField(this, "operatorMap");
|
|
154
150
|
this.propertyDefinitions = propertyDefinitions;
|
|
155
151
|
this.operatorDefinitions = operatorDefinitions;
|
|
156
152
|
this.operatorMap = operatorMap;
|
|
157
153
|
this.sqlEscapeValue = sqlEscapeValue;
|
|
158
154
|
}
|
|
159
155
|
toSql(ast, wrapStrings) {
|
|
160
|
-
var _a, _b;
|
|
161
156
|
this._checkEvaluationOptions();
|
|
162
157
|
const chunks = [];
|
|
163
158
|
if (ast.type === AST_TYPE.NORMALIZED_CONDITION) {
|
|
164
|
-
const prop =
|
|
159
|
+
const prop = ast.property?.[0];
|
|
165
160
|
const definition = this.propertyDefinitions[prop];
|
|
166
161
|
const value = ast.value;
|
|
167
|
-
const col =
|
|
162
|
+
const col = definition.transformToColumn?.(prop, definition.name) ?? `"${prop}"`;
|
|
168
163
|
const op = ast.operator;
|
|
169
164
|
if (ast.negate) {
|
|
170
|
-
chunks.push(
|
|
165
|
+
chunks.push(wrapStrings?.(`NOT(`) ?? `NOT(`);
|
|
171
166
|
}
|
|
172
|
-
chunks.push(
|
|
173
|
-
chunks.push(
|
|
167
|
+
chunks.push(wrapStrings?.(`${col} `) ?? `${col} `);
|
|
168
|
+
chunks.push(wrapStrings?.(`${op} `) ?? `${op} `);
|
|
174
169
|
const val = this.sqlEscapeValue(value);
|
|
175
170
|
if (definition.transformValue) {
|
|
176
171
|
const transformed = definition.transformValue(val, value);
|
|
@@ -183,7 +178,7 @@ class ParserWithSqlSupport extends Parser {
|
|
|
183
178
|
chunks.push(val);
|
|
184
179
|
}
|
|
185
180
|
if (ast.negate) {
|
|
186
|
-
chunks.push(
|
|
181
|
+
chunks.push(wrapStrings?.(`)`) ?? `)`);
|
|
187
182
|
}
|
|
188
183
|
return chunks;
|
|
189
184
|
}
|
|
@@ -191,11 +186,11 @@ class ParserWithSqlSupport extends Parser {
|
|
|
191
186
|
const left = this.toSql(ast.left, wrapStrings);
|
|
192
187
|
const right = this.toSql(ast.right, wrapStrings);
|
|
193
188
|
const op = ast.operator === TOKEN_TYPE.AND ? "AND" : "OR";
|
|
194
|
-
chunks.push(
|
|
189
|
+
chunks.push(wrapStrings?.(`(`) ?? `(`);
|
|
195
190
|
chunks.push(...left);
|
|
196
|
-
chunks.push(
|
|
191
|
+
chunks.push(wrapStrings?.(` ${op} `) ?? ` ${op} `);
|
|
197
192
|
chunks.push(...right);
|
|
198
|
-
chunks.push(
|
|
193
|
+
chunks.push(wrapStrings?.(`)`) ?? `)`);
|
|
199
194
|
return chunks;
|
|
200
195
|
}
|
|
201
196
|
return unreachable();
|
|
@@ -208,7 +203,6 @@ function createTypeError(prop, type, isArray) {
|
|
|
208
203
|
return new Error(`Property ${prop} must be of type ${type}.`);
|
|
209
204
|
}
|
|
210
205
|
function convertAndValidateValue(isQuoted, value, prop, propertyDefinitions, { isArray = false } = {}) {
|
|
211
|
-
var _a;
|
|
212
206
|
let finalValue = value;
|
|
213
207
|
let isFloat = false;
|
|
214
208
|
const propDefinition = propertyDefinitions[prop];
|
|
@@ -231,7 +225,7 @@ function convertAndValidateValue(isQuoted, value, prop, propertyDefinitions, { i
|
|
|
231
225
|
}
|
|
232
226
|
}
|
|
233
227
|
const type = propDefinition.type;
|
|
234
|
-
finalValue =
|
|
228
|
+
finalValue = propDefinition.postParse?.(finalValue) ?? finalValue;
|
|
235
229
|
switch (type) {
|
|
236
230
|
case "integer":
|
|
237
231
|
case "float": {
|
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
var __defProp = Object.defineProperty;
|
|
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) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
4
1
|
import { Parser } from "../Parser.js";
|
|
5
2
|
class ShortcutContextParser extends Parser {
|
|
3
|
+
validKeys = [];
|
|
4
|
+
regexablekeys = [];
|
|
6
5
|
constructor(dummyContext, validRegexFlags = ["i", "u", "m"]) {
|
|
7
6
|
super({
|
|
8
7
|
arrayValues: false,
|
|
@@ -97,8 +96,6 @@ class ShortcutContextParser extends Parser {
|
|
|
97
96
|
return { value: finalValue, operator: finalOperator, negate: isNegated };
|
|
98
97
|
}
|
|
99
98
|
});
|
|
100
|
-
__publicField(this, "validKeys", []);
|
|
101
|
-
__publicField(this, "regexablekeys", []);
|
|
102
99
|
this._extractKeysFromContext(dummyContext);
|
|
103
100
|
}
|
|
104
101
|
setContext(context) {
|
package/dist/index.js
CHANGED
|
@@ -2,12 +2,12 @@ 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
|
-
import {
|
|
5
|
+
import { PARSER_ERROR } from "./types/errors.js";
|
|
6
6
|
import * as index$1 from "./utils/index.js";
|
|
7
7
|
import * as index$2 from "./defaults/index.js";
|
|
8
8
|
export {
|
|
9
9
|
AST_TYPE,
|
|
10
|
-
|
|
10
|
+
PARSER_ERROR,
|
|
11
11
|
Parser,
|
|
12
12
|
SUGGESTION_TYPE,
|
|
13
13
|
TOKEN_TYPE,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { ErrorInfo, ParserError } from "../types/errors.js";
|
|
2
2
|
/** @internal */
|
|
3
|
-
export declare class ExpressitError<T extends
|
|
3
|
+
export declare class ExpressitError<T extends ParserError> extends Error {
|
|
4
4
|
version: string;
|
|
5
5
|
repo: string;
|
|
6
6
|
type: T;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ExpressitError.d.ts","sourceRoot":"","sources":["../../src/internal/ExpressitError.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"ExpressitError.d.ts","sourceRoot":"","sources":["../../src/internal/ExpressitError.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,SAAS,EAAE,WAAW,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,12 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
import { crop } from "@alanscodelog/utils/crop.js";
|
|
5
|
-
import { indent } from "@alanscodelog/utils/indent.js";
|
|
6
|
-
import { pretty } from "@alanscodelog/utils/pretty.js";
|
|
1
|
+
import { crop } from "@alanscodelog/utils/crop";
|
|
2
|
+
import { indent } from "@alanscodelog/utils/indent";
|
|
3
|
+
import { pretty } from "@alanscodelog/utils/pretty";
|
|
7
4
|
import packageJson from "../package.json.js";
|
|
8
5
|
const { version, repository } = packageJson;
|
|
9
6
|
class ExpressitError extends Error {
|
|
7
|
+
version = version;
|
|
8
|
+
repo = repository;
|
|
9
|
+
type;
|
|
10
|
+
info;
|
|
10
11
|
constructor(type, info, message) {
|
|
11
12
|
super(
|
|
12
13
|
message ? `${message}
|
|
@@ -17,10 +18,6 @@ ${crop`
|
|
|
17
18
|
info: ${indent(JSON.stringify(info, forceStringifyErrors, " "), 5)}
|
|
18
19
|
`}`
|
|
19
20
|
);
|
|
20
|
-
__publicField(this, "version", version);
|
|
21
|
-
__publicField(this, "repo", repository);
|
|
22
|
-
__publicField(this, "type");
|
|
23
|
-
__publicField(this, "info");
|
|
24
21
|
this.type = type;
|
|
25
22
|
this.info = info;
|
|
26
23
|
}
|
|
@@ -1,11 +1,10 @@
|
|
|
1
|
-
import { isBlank } from "@alanscodelog/utils/isBlank
|
|
2
|
-
import { pushIfNotIn } from "@alanscodelog/utils/pushIfNotIn
|
|
1
|
+
import { isBlank } from "@alanscodelog/utils/isBlank";
|
|
2
|
+
import { pushIfNotIn } from "@alanscodelog/utils/pushIfNotIn";
|
|
3
3
|
import { ExpressitError } from "./ExpressitError.js";
|
|
4
4
|
import { defaultConditionNormalizer } from "../defaults/defaultConditionNormalizer.js";
|
|
5
5
|
import { defaultValueComparer } from "../defaults/defaultValueComparer.js";
|
|
6
|
-
import {
|
|
6
|
+
import { PARSER_ERROR } from "../types/errors.js";
|
|
7
7
|
function checkParserOpts(opts, evaluatorChecks = false, validatorChecks = false) {
|
|
8
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i;
|
|
9
8
|
if (!evaluatorChecks) {
|
|
10
9
|
const keywordsList = [...opts.keywords.and, ...opts.keywords.or, ...opts.keywords.not].map((keyword) => keyword.value);
|
|
11
10
|
const symNots = opts.keywords.not.filter((op) => op.isSymbol).map((op) => op.value);
|
|
@@ -20,32 +19,32 @@ function checkParserOpts(opts, evaluatorChecks = false, validatorChecks = false)
|
|
|
20
19
|
if (opts.customPropertyOperators) pushIfNotIn(extra, opts.customPropertyOperators);
|
|
21
20
|
if (opts.expandedPropertySeparator && isBlank(opts.expandedPropertySeparator)) {
|
|
22
21
|
throw new ExpressitError(
|
|
23
|
-
|
|
22
|
+
PARSER_ERROR.CONFLICTING_OPTIONS_ERROR,
|
|
24
23
|
{ prohibited: [""], invalid: opts.expandedPropertySeparator },
|
|
25
24
|
`expandedPropertySeparator cannot be blank`
|
|
26
25
|
);
|
|
27
26
|
}
|
|
28
|
-
const customInvalid =
|
|
27
|
+
const customInvalid = opts.customPropertyOperators?.find((_) => isBlank(_));
|
|
29
28
|
if (customInvalid !== void 0) {
|
|
30
29
|
throw new ExpressitError(
|
|
31
|
-
|
|
30
|
+
PARSER_ERROR.CONFLICTING_OPTIONS_ERROR,
|
|
32
31
|
{ prohibited: [""], invalid: customInvalid },
|
|
33
32
|
`customPropertyOperators cannot contain blank entries`
|
|
34
33
|
);
|
|
35
34
|
}
|
|
36
|
-
const prefixInvalid =
|
|
35
|
+
const prefixInvalid = opts.prefixableStrings?.find((_) => isBlank(_));
|
|
37
36
|
if (prefixInvalid !== void 0) {
|
|
38
37
|
throw new ExpressitError(
|
|
39
|
-
|
|
38
|
+
PARSER_ERROR.CONFLICTING_OPTIONS_ERROR,
|
|
40
39
|
{ prohibited: [""], invalid: prefixInvalid },
|
|
41
40
|
`prefixableStrings cannot contain blank entries`
|
|
42
41
|
);
|
|
43
42
|
}
|
|
44
43
|
for (const key of ["and", "or", "not"]) {
|
|
45
|
-
const invalid =
|
|
44
|
+
const invalid = opts.keywords[key]?.find((_) => isBlank(_.value))?.value;
|
|
46
45
|
if (invalid !== void 0) {
|
|
47
46
|
throw new ExpressitError(
|
|
48
|
-
|
|
47
|
+
PARSER_ERROR.CONFLICTING_OPTIONS_ERROR,
|
|
49
48
|
{ prohibited: [""], invalid },
|
|
50
49
|
`keywords.${key} cannot contain entries with blank values`
|
|
51
50
|
);
|
|
@@ -55,10 +54,10 @@ function checkParserOpts(opts, evaluatorChecks = false, validatorChecks = false)
|
|
|
55
54
|
const allKeywords = [...keywords, ...symNots];
|
|
56
55
|
const messageInvalidAny = "cannot contain operators or special symbols, but found";
|
|
57
56
|
const messageInvalidBool = "cannot contain boolean operators or special symbols, but found";
|
|
58
|
-
const invalidPrefixableString =
|
|
57
|
+
const invalidPrefixableString = opts.prefixableStrings?.find((val) => all.includes(val));
|
|
59
58
|
if (invalidPrefixableString) {
|
|
60
59
|
throw new ExpressitError(
|
|
61
|
-
|
|
60
|
+
PARSER_ERROR.CONFLICTING_OPTIONS_ERROR,
|
|
62
61
|
{ prohibited: all, invalid: invalidPrefixableString },
|
|
63
62
|
`prefixableStrings ${messageInvalidAny} "${invalidPrefixableString}"`
|
|
64
63
|
);
|
|
@@ -66,15 +65,15 @@ function checkParserOpts(opts, evaluatorChecks = false, validatorChecks = false)
|
|
|
66
65
|
const invalidExpandedPropertySeparator = allKeywords.find((_) => _ === opts.expandedPropertySeparator);
|
|
67
66
|
if (invalidExpandedPropertySeparator) {
|
|
68
67
|
throw new ExpressitError(
|
|
69
|
-
|
|
68
|
+
PARSER_ERROR.CONFLICTING_OPTIONS_ERROR,
|
|
70
69
|
{ prohibited: allKeywords, invalid: invalidExpandedPropertySeparator },
|
|
71
70
|
`expandedPropertySeparator ${messageInvalidBool} "${invalidExpandedPropertySeparator}"`
|
|
72
71
|
);
|
|
73
72
|
}
|
|
74
|
-
const invalidCustomPropertyOperator =
|
|
73
|
+
const invalidCustomPropertyOperator = opts.customPropertyOperators?.find((val) => keywords.includes(val)) ? opts.expandedPropertySeparator : void 0;
|
|
75
74
|
if (invalidCustomPropertyOperator) {
|
|
76
75
|
throw new ExpressitError(
|
|
77
|
-
|
|
76
|
+
PARSER_ERROR.CONFLICTING_OPTIONS_ERROR,
|
|
78
77
|
{ prohibited: keywords, invalid: invalidCustomPropertyOperator },
|
|
79
78
|
`customPropertyOperator ${messageInvalidBool} "${invalidCustomPropertyOperator}"`
|
|
80
79
|
);
|
|
@@ -82,13 +81,13 @@ function checkParserOpts(opts, evaluatorChecks = false, validatorChecks = false)
|
|
|
82
81
|
}
|
|
83
82
|
if (evaluatorChecks) {
|
|
84
83
|
const requireCustomNormalizer = [];
|
|
85
|
-
if ((
|
|
86
|
-
if ((
|
|
87
|
-
if ((
|
|
84
|
+
if ((opts.prefixableStrings?.length ?? 0) > 0) requireCustomNormalizer.push("prefixableStrings");
|
|
85
|
+
if ((opts.customPropertyOperators?.length ?? 0) > 0) requireCustomNormalizer.push("customPropertyOperators");
|
|
86
|
+
if ((opts.expandedPropertySeparator?.length ?? 0) > 0) requireCustomNormalizer.push("expandedPropertySeparator");
|
|
88
87
|
if (opts.regexValues) requireCustomNormalizer.push("regexValues");
|
|
89
88
|
if (requireCustomNormalizer.length > 0 && opts.conditionNormalizer === defaultConditionNormalizer) {
|
|
90
89
|
throw new ExpressitError(
|
|
91
|
-
|
|
90
|
+
PARSER_ERROR.OPTION_REQUIRED_ERROR,
|
|
92
91
|
{ options: requireCustomNormalizer, requires: "conditionNormalizer" },
|
|
93
92
|
`A custom conditionNormalizer function must be specified when using the following options: ${requireCustomNormalizer.join(", ")}`
|
|
94
93
|
);
|
|
@@ -98,7 +97,7 @@ function checkParserOpts(opts, evaluatorChecks = false, validatorChecks = false)
|
|
|
98
97
|
if (opts.regexValues) requireCustomComparer.push("arrayValues");
|
|
99
98
|
if (requireCustomComparer.length > 0 && opts.valueComparer === defaultValueComparer) {
|
|
100
99
|
throw new ExpressitError(
|
|
101
|
-
|
|
100
|
+
PARSER_ERROR.OPTION_REQUIRED_ERROR,
|
|
102
101
|
{ options: requireCustomComparer, requires: "valueComparer" },
|
|
103
102
|
`A custom valueComparer function must be specified when using the following options: ${requireCustomComparer.join(", ")}`
|
|
104
103
|
);
|
|
@@ -107,7 +106,7 @@ function checkParserOpts(opts, evaluatorChecks = false, validatorChecks = false)
|
|
|
107
106
|
if (validatorChecks) {
|
|
108
107
|
if (opts.valueValidator === void 0) {
|
|
109
108
|
throw new ExpressitError(
|
|
110
|
-
|
|
109
|
+
PARSER_ERROR.OPTION_REQUIRED_ERROR,
|
|
111
110
|
{ requires: "valueValidator" },
|
|
112
111
|
`A custom valueValidator function must be specified when using the validate method.`
|
|
113
112
|
);
|
|
@@ -3,7 +3,6 @@ import { defaultKeyParser } from "../defaults/defaultKeyParser.js";
|
|
|
3
3
|
import { defaultPrefixApplier } from "../defaults/defaultPrefixApplier.js";
|
|
4
4
|
import { defaultValueComparer } from "../defaults/defaultValueComparer.js";
|
|
5
5
|
function parseParserOptions(options) {
|
|
6
|
-
var _a, _b, _c;
|
|
7
6
|
const opts = {
|
|
8
7
|
prefixApplier: defaultPrefixApplier,
|
|
9
8
|
keyParser: defaultKeyParser,
|
|
@@ -19,19 +18,19 @@ function parseParserOptions(options) {
|
|
|
19
18
|
...options,
|
|
20
19
|
// todo fix
|
|
21
20
|
keywords: {
|
|
22
|
-
or:
|
|
21
|
+
or: options.keywords?.or ? options.keywords.or : [
|
|
23
22
|
{ value: "||", isSymbol: true },
|
|
24
23
|
{ value: "|", isSymbol: true },
|
|
25
24
|
{ value: "or", isSymbol: false },
|
|
26
25
|
{ value: "OR", isSymbol: false }
|
|
27
26
|
],
|
|
28
|
-
and:
|
|
27
|
+
and: options.keywords?.and ? options.keywords.and : [
|
|
29
28
|
{ value: "&&", isSymbol: true },
|
|
30
29
|
{ value: "&", isSymbol: true },
|
|
31
30
|
{ value: "and", isSymbol: false },
|
|
32
31
|
{ value: "AND", isSymbol: false }
|
|
33
32
|
],
|
|
34
|
-
not:
|
|
33
|
+
not: options.keywords?.not ? options.keywords.not : [
|
|
35
34
|
{ value: "!", isSymbol: true },
|
|
36
35
|
{ value: "not", isSymbol: false },
|
|
37
36
|
{ value: "NOT", isSymbol: false }
|
package/dist/package.json.js
CHANGED
|
@@ -1,69 +1,11 @@
|
|
|
1
|
-
const
|
|
2
|
-
const description = "A blazing fast, customizable, error-tolerant expression parser that creates safe to eval expressions + a few other goodies like autocomplete.";
|
|
3
|
-
const version = "0.2.2";
|
|
4
|
-
const types = "./dist/index.d.ts";
|
|
5
|
-
const type = "module";
|
|
6
|
-
const module = "./dist/index.js";
|
|
7
|
-
const sideEffects = false;
|
|
8
|
-
const exports = { ".": { "types": "./dist/index.d.ts", "import": "./dist/index.js" }, "./ast": { "types": "./dist/ast/index.d.ts", "import": "./dist/ast/index.js" }, "./ast/*": { "types": "./dist/ast/*", "import": "./dist/ast/*" }, "./internal": { "types": "./dist/internal/index.d.ts", "import": "./dist/internal/index.js" }, "./internal/*": { "types": "./dist/internal/*", "import": "./dist/internal/*" }, "./methods": { "types": "./dist/methods/index.d.ts", "import": "./dist/methods/index.js" }, "./methods/*": { "types": "./dist/methods/*", "import": "./dist/methods/*" }, "./utils": { "types": "./dist/utils/index.d.ts", "import": "./dist/utils/index.js" }, "./utils/*": { "types": "./dist/utils/*", "import": "./dist/utils/*" }, "./examples": { "types": "./dist/examples/index.d.ts", "import": "./dist/examples/index.js" }, "./examples/*": { "types": "./dist/examples/*", "import": "./dist/examples/*" }, "./*": { "types": "./dist/types/*", "import": "./dist/types/*" } };
|
|
9
|
-
const scripts = { "debug": "ts-node -r tsconfig-paths/register -T --esm", "build": "vite build", "build:dev": "vite build --mode development", "build:watch": "vite build --watch --mode production", "build:types": "tsc --emitDeclarationOnly -p tsconfig.types.json", "lint:eslint": 'eslint "{src,tests,bin}/**/*.{cjs,js,ts}" "*.{cjs,js,ts}" --max-warnings=1 --report-unused-disable-directives', "lint:types": "tsc --noEmit --pretty", "lint:commits": "commitlint --from $(git rev-list --max-parents=0 HEAD) --to HEAD --verbose", "lint:imports": "madge --circular --extensions ts ./src", "lint": "npm run lint:types && npm run lint:eslint", "coverage": "vitest --exclude '.direnv/**/*' --coverage", "coverage:dev": "vitest --exclude '.direnv/**/*' --watch --coverage", "test:db": "rm -rf ./tests/db/migrations && pnpm drizzle-kit generate --config ./tests/db/drizzle.config.ts", "test": "pnpm test:db && npm run lint:types && vitest run --exclude '.direnv/**/*'", "test:watch": "pnpm test:db && vitest --watch --exclude '.direnv/**/*'", "test:inspect-errors": "cross-env INSPECT_ERRORS=true npm run test", "doc": "typedoc --options typedoc.config.js", "doc:watch": 'onchange -i "src/**/*.ts" "typedoc.config.cjs" -- npm run doc', "doc:serve": "http-server docs --port=5001", "doc:dev": 'concurrently "npm run doc:watch" "npm run doc:serve"', "doc:check-invalid": "typedoc --options typedoc.config.cjs --listInvalidSymbolLinks", "demo:dev": 'cd demo && concurrently "vite" "npm run build:watch"', "demo:build": "cd demo && npm run build", "actions:debug": "act -r -v -j release", "gen:exports": "indexit update -o '${path}.js' -i **/*.d.ts", "prepare": "husky && npm run build" };
|
|
10
|
-
const dependencies = { "@alanscodelog/utils": "^4.0.0" };
|
|
11
|
-
const devDependencies = { "@alanscodelog/commitlint-config": "^3.0.1", "@alanscodelog/eslint-config": "5.0.3", "@alanscodelog/semantic-release-config": "^5.0.3", "@alanscodelog/tsconfigs": "^5.0.1", "@commitlint/cli": "^19.6.1", "@electric-sql/pglite": "^0.2.12", "@types/node": "^22.10.2", "@vitest/coverage-v8": "^2.1.8", "concurrently": "^9.1.0", "cross-env": "^7.0.3", "drizzle-kit": "^0.30.1", "drizzle-orm": "^0.38.2", "fast-glob": "^3.3.1", "http-server": "^14.1.1", "husky": "^9.1.7", "indexit": "2.1.0-beta.3", "madge": "^8.0.0", "onchange": "^7.1.0", "semantic-release": "^24.2.0", "ts-node": "^10.9.1", "typedoc": "0.27.5", "typescript": "~5.7.2", "vite": "^6.0.2", "vite-plugin-externalize-deps": "^0.8.0", "vite-tsconfig-paths": "^5.1.4", "vitest": "^2.1.8" };
|
|
12
|
-
const author = "Alan <alanscodelog@gmail.com>";
|
|
1
|
+
const version = "0.3.1";
|
|
13
2
|
const repository = "https://github.com/witchcraftjs/expressit";
|
|
14
|
-
const keywords = ["boolean", "parser", "query", "evaluator", "expression", "condition", "search"];
|
|
15
|
-
const license = "MIT";
|
|
16
|
-
const files = ["src", "dist"];
|
|
17
|
-
const release = { "extends": ["@alanscodelog/semantic-release-config"] };
|
|
18
|
-
const commitlint = { "extends": ["@alanscodelog"] };
|
|
19
|
-
const browserslist = "defaults and supports es6-module,maintained node versions";
|
|
20
|
-
const engines = { "node": ">=18.0.0" };
|
|
21
|
-
const publishConfig = { "access": "public" };
|
|
22
3
|
const packageJson = {
|
|
23
|
-
name,
|
|
24
|
-
description,
|
|
25
4
|
version,
|
|
26
|
-
|
|
27
|
-
type,
|
|
28
|
-
module,
|
|
29
|
-
sideEffects,
|
|
30
|
-
exports,
|
|
31
|
-
scripts,
|
|
32
|
-
dependencies,
|
|
33
|
-
devDependencies,
|
|
34
|
-
author,
|
|
35
|
-
repository,
|
|
36
|
-
keywords,
|
|
37
|
-
license,
|
|
38
|
-
files,
|
|
39
|
-
release,
|
|
40
|
-
commitlint,
|
|
41
|
-
browserslist,
|
|
42
|
-
engines,
|
|
43
|
-
"@comments": { "scripts": { "test": "Runs `lint:types` before (so that flags can be passed to the test command) so that we can test type assertions. See expect_type function in @alanscodelog/utils.", "lint:commits": "Lints all unpushed commits in the active branch.", "prepare": "Needed so that if we pull the package from git it will get built and installed properly.", "actions:debug": "For debugging github build action locally with nektos/act. Requires act and docker. Note: Cache will never work locally because of https://github.com/nektos/act/issues/285" } },
|
|
44
|
-
publishConfig
|
|
5
|
+
repository
|
|
45
6
|
};
|
|
46
7
|
export {
|
|
47
|
-
author,
|
|
48
|
-
browserslist,
|
|
49
|
-
commitlint,
|
|
50
8
|
packageJson as default,
|
|
51
|
-
dependencies,
|
|
52
|
-
description,
|
|
53
|
-
devDependencies,
|
|
54
|
-
engines,
|
|
55
|
-
exports,
|
|
56
|
-
files,
|
|
57
|
-
keywords,
|
|
58
|
-
license,
|
|
59
|
-
module,
|
|
60
|
-
name,
|
|
61
|
-
publishConfig,
|
|
62
|
-
release,
|
|
63
9
|
repository,
|
|
64
|
-
scripts,
|
|
65
|
-
sideEffects,
|
|
66
|
-
type,
|
|
67
|
-
types,
|
|
68
10
|
version
|
|
69
11
|
};
|