@witchcraft/expressit 0.2.0 → 0.2.2

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.
Files changed (60) hide show
  1. package/README.md +5 -2
  2. package/dist/Lexer.d.ts +3 -5
  3. package/dist/Lexer.d.ts.map +1 -1
  4. package/dist/Lexer.js +21 -40
  5. package/dist/Parser.d.ts +1 -1
  6. package/dist/Parser.d.ts.map +1 -1
  7. package/dist/Parser.js +35 -64
  8. package/dist/ast/builders/condition.js +2 -4
  9. package/dist/ast/builders/delim.d.ts +1 -1
  10. package/dist/ast/builders/delim.d.ts.map +1 -1
  11. package/dist/ast/builders/delim.js +2 -4
  12. package/dist/ast/builders/expression.js +1 -2
  13. package/dist/ast/builders/pos.js +3 -6
  14. package/dist/ast/builders/variable.js +2 -4
  15. package/dist/ast/error.js +1 -2
  16. package/dist/ast/handlers.d.ts +2 -2
  17. package/dist/ast/handlers.d.ts.map +1 -1
  18. package/dist/ast/handlers.js +7 -11
  19. package/dist/defaults/defaultKeyParser.js +1 -2
  20. package/dist/examples/ParserWithSqlSupport.d.ts +62 -0
  21. package/dist/examples/ParserWithSqlSupport.d.ts.map +1 -0
  22. package/dist/examples/ParserWithSqlSupport.js +269 -0
  23. package/dist/examples/{shortcutContextParser.d.ts → ShortcutContextParser.d.ts} +5 -5
  24. package/dist/examples/ShortcutContextParser.d.ts.map +1 -0
  25. package/dist/examples/{shortcutContextParser.js → ShortcutContextParser.js} +6 -12
  26. package/dist/examples/index.d.ts +2 -1
  27. package/dist/examples/index.d.ts.map +1 -1
  28. package/dist/examples/index.js +3 -1
  29. package/dist/internal/ExpressitError.js +3 -5
  30. package/dist/internal/checkParserOpts.d.ts +1 -1
  31. package/dist/internal/checkParserOpts.d.ts.map +1 -1
  32. package/dist/internal/checkParserOpts.js +8 -16
  33. package/dist/internal/escapeVariableOrPrefix.js +4 -8
  34. package/dist/internal/parseParserOptions.d.ts +1 -1
  35. package/dist/internal/parseParserOptions.d.ts.map +1 -1
  36. package/dist/package.json.js +14 -147
  37. package/dist/types/parser.d.ts +6 -6
  38. package/dist/types/parser.d.ts.map +1 -1
  39. package/dist/utils/generateParentsMap.js +20 -40
  40. package/dist/utils/getCursorInfo.js +9 -17
  41. package/dist/utils/getOppositeDelimiter.js +3 -6
  42. package/dist/utils/prettyAst.js +1 -2
  43. package/package.json +25 -23
  44. package/src/Lexer.ts +5 -4
  45. package/src/Parser.ts +9 -3
  46. package/src/ast/builders/delim.ts +1 -1
  47. package/src/ast/handlers.ts +3 -3
  48. package/src/examples/ParserWithSqlSupport.ts +365 -0
  49. package/src/examples/{shortcutContextParser.ts → ShortcutContextParser.ts} +14 -14
  50. package/src/examples/index.ts +2 -1
  51. package/src/internal/ExpressitError.ts +2 -2
  52. package/src/internal/checkParserOpts.ts +3 -3
  53. package/src/internal/parseParserOptions.ts +2 -2
  54. package/src/types/parser.ts +6 -6
  55. package/src/utils/getCursorInfo.ts +1 -1
  56. package/dist/examples/shortcutContextParser.d.ts.map +0 -1
  57. package/dist/global.d.js +0 -1
  58. package/dist/package.js +0 -7
  59. package/src/global.d.ts +0 -4
  60. package/src/package.js +0 -11
@@ -2,8 +2,8 @@ import { type AnyToken, type ArrayNode, type ConditionNode, type ErrorToken, typ
2
2
  declare function error<T extends TOKEN_TYPE>(pos: number, expected: T[]): ErrorToken;
3
3
  export declare const token: {
4
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;
5
+ custom: <TVal extends string | undefined>(value: TVal, pos: Position) => TVal extends string ? ValidToken<TOKEN_TYPE.OP_CUSTOM> : ErrorToken;
6
+ sep: <TVal extends string | undefined>(value: TVal, pos: Position) => TVal extends string ? ValidToken<TOKEN_TYPE.OP_EXPANDED_SEP> : ErrorToken;
7
7
  };
8
8
  /** We want to handle all the types outside the grammar file. This makes it easier without trying to check the value. */
9
9
  export declare const delimiter: {
@@ -1 +1 @@
1
- {"version":3,"file":"handlers.d.ts","sourceRoot":"","sources":["../../src/ast/handlers.ts"],"names":[],"mappings":"AASA,OAAO,EAAE,KAAK,QAAQ,EAAE,KAAK,SAAS,EAAU,KAAK,aAAa,EAAE,KAAK,UAAU,EAAE,KAAK,cAAc,EAAiB,KAAK,SAAS,EAAE,KAAK,QAAQ,EAAE,UAAU,EAAE,KAAK,iBAAiB,EAAqD,KAAK,eAAe,EAAE,KAAK,UAAU,EAAE,KAAK,YAAY,EAAE,MAAM,iBAAiB,CAAA;AAIhU,iBAAS,KAAK,CAAC,CAAC,SAAS,UAAU,EAAE,GAAG,EAAE,MAAM,EAAE,QAAQ,EAAE,CAAC,EAAE,GAAG,UAAU,CAG3E;AAsBD,eAAO,MAAM,KAAK;+DAR0F,QAAQ;oEAAR,QAAQ;iEAAR,QAAQ;CAYnH,CAAA;AAED,wHAAwH;AACxH,eAAO,MAAM,SAAS;oBAnBb,MAAM,GAAG,SAAS,OAAO,QAAQ;oBAAjC,MAAM,GAAG,SAAS,OAAO,QAAQ;sBAAjC,MAAM,GAAG,SAAS,OAAO,QAAQ;sBAAjC,MAAM,GAAG,SAAS,OAAO,QAAQ;oBAAjC,MAAM,GAAG,SAAS,OAAO,QAAQ;oBAAjC,MAAM,GAAG,SAAS,OAAO,QAAQ;mBAAjC,MAAM,GAAG,SAAS,OAAO,QAAQ;kBAAjC,MAAM,GAAG,SAAS,OAAO,QAAQ;;CA6BzC,CAAA;AACD,eAAO,MAAM,QAAQ;iBAlCZ,MAAM,OAAO,QAAQ;gBAArB,MAAM,OAAO,QAAQ;iBAArB,MAAM,OAAO,QAAQ;CAsC7B,CAAA;AAID,wBAAg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AE,YAAY,GAAG,SAAS,GAAG,SAAS,GAAG,IAAI,GACjD,aAAa,CA0Bf;AAED,wBAAgB,UAAU,CACzB,IAAI,EAAE,aAAa,GAAG,SAAS,GAAG,IAAI,GAAG,SAAS,EAClD,QAAQ,EAAE,UAAU,CAAC,iBAAiB,CAAC,GAAG,IAAI,GAAG,SAAS,EAC1D,KAAK,EAAE,aAAa,GAAG,SAAS,GAAG,IAAI,GAAG,SAAS,GACjD,cAAc,CAQhB;AAED,wBAAgB,KAAK,CACpB,QAAQ,EAAE,UAAU,CAAC,UAAU,CAAC,GAAG,CAAC,GAAG,IAAI,GAAG,SAAS,EACvD,MAAM,EAAE,aAAa,GAAG,IAAI,GAAG,SAAS,EACxC,MAAM,EAAE,UAAU,CAAC,UAAU,CAAC,MAAM,CAAC,GAAG,IAAI,GAAG,SAAS,EACxD,SAAS,EAAE,SAAS,CAAC,YAAY,CAAC,EAClC,MAAM,EAAE,UAAU,CAAC,UAAU,CAAC,MAAM,CAAC,GAAG,IAAI,GAAG,SAAS,GACtD,SAAS,CAWX;AAED,wBAAgB,KAAK,CACpB,QAAQ,EAAE,UAAU,CAAC,UAAU,CAAC,QAAQ,CAAC,EACzC,MAAM,EAAE,YAAY,EAAE,EACtB,QAAQ,EAAE,UAAU,CAAC,UAAU,CAAC,QAAQ,CAAC,GAAG,IAAI,GAAG,SAAS,GAC1D,SAAS,CAUX"}
@@ -6,8 +6,7 @@ import { createToken } from "./createToken.js";
6
6
  import { createVariableNode } from "./createVariableNode.js";
7
7
  import { TOKEN_TYPE, AST_TYPE } from "../types/ast.js";
8
8
  function error(pos, expected) {
9
- if (pos === void 0)
10
- throw new Error("should never happen, passed undefined position for error token");
9
+ if (pos === void 0) throw new Error("should never happen, passed undefined position for error token");
11
10
  return createToken({ expected, start: pos, end: pos });
12
11
  }
13
12
  const operators = (type) => (value, pos) => createToken({ value, type, ...pos });
@@ -75,24 +74,21 @@ function condition(not, property, { propertyOperator, sepL, sepR } = {}, value)
75
74
  if (not) {
76
75
  node.operator = not;
77
76
  }
78
- if (property)
79
- node.property = property;
80
- if (propertyOperator)
81
- node.propertyOperator = propertyOperator;
77
+ if (property) node.property = property;
78
+ if (propertyOperator) node.propertyOperator = propertyOperator;
82
79
  if (sepL || sepR) {
83
80
  node.sep = {};
84
81
  if (sepL) {
85
82
  node.sep.left = sepL;
86
- node.property || (node.property = error(sepL.start, [TOKEN_TYPE.VALUE]));
87
- node.propertyOperator || (node.propertyOperator = error((sepL == null ? void 0 : sepL.end) ?? (sepR == null ? void 0 : sepR.start), [TOKEN_TYPE.VALUE]));
83
+ node.property ?? (node.property = error(sepL.start, [TOKEN_TYPE.VALUE]));
84
+ node.propertyOperator ?? (node.propertyOperator = error((sepL == null ? void 0 : sepL.end) ?? (sepR == null ? void 0 : sepR.start), [TOKEN_TYPE.VALUE]));
88
85
  }
89
- if (sepR)
90
- node.sep.right = sepR;
86
+ if (sepR) node.sep.right = sepR;
91
87
  else if (!node.value || node.value.type === AST_TYPE.VARIABLE) {
92
88
  node.sep.right = error(((_a = node.value) == null ? void 0 : _a.start) ?? end, [TOKEN_TYPE.OP_EXPANDED_SEP]);
93
89
  }
94
90
  } else if (propertyOperator) {
95
- node.property || (node.property = error(propertyOperator.start, [TOKEN_TYPE.VALUE]));
91
+ node.property ?? (node.property = error(propertyOperator.start, [TOKEN_TYPE.VALUE]));
96
92
  }
97
93
  return createConditionNode(node);
98
94
  }
@@ -1,6 +1,5 @@
1
1
  const defaultKeyParser = function defaultKeyParser2(value) {
2
- if (value === void 0)
3
- return [];
2
+ if (value === void 0) return [];
4
3
  return [value];
5
4
  };
6
5
  export {
@@ -0,0 +1,62 @@
1
+ import { Parser } from "../Parser.js";
2
+ import { type NormalizedCondition, type NormalizedExpression, type Position } from "../types/ast.js";
3
+ export interface BasePropertyDefinition {
4
+ name: string;
5
+ /** Supported types are: string, boolean, int, float, date. */
6
+ type: string;
7
+ /** Return how to access the column in the WHERE condition of the SQL query, useful for json properties. It is up to you to properly quote the value if needed. */
8
+ transformToColumn?: (key: string, name: string) => string;
9
+ /**
10
+ * A function that can be used to transform the value before it is inserted into the SQL query. Useful for types like arrays. It is up to you to properly escape values if you use the second parameter which contains the unescaped value.
11
+ */
12
+ transformValue?: (value: any, unescapedValue: any) => any | any[];
13
+ isArray?: boolean;
14
+ /** If undefined, it's assumed all operators are supported. This should only include the final operator (see {@link BaseOperatorDefinition.operator}), it doesn't need to include it's aliases. */
15
+ supportedOperators?: string[];
16
+ /** Further transform the value after the basic parsing has been done. Useful to, for example, parse other strings (e.g. now, today, tomorrow) as dates. */
17
+ postParse?: (value: any) => any;
18
+ }
19
+ export interface BaseOperatorDefinition {
20
+ /** The final operator to use in the SQL query and while evaluating. */
21
+ operator: string;
22
+ /** All aliases the user can use to specify the operator. They need not include the real final operator. */
23
+ operators: string[];
24
+ /** All negated aliases to the operator. If an operator is listed here, it will be used to "invert" a condition when normalizing. e.g. < can list >= as a negated operator. This greatly simplifies queries. */
25
+ negatedOperators?: string[];
26
+ /** How to compare the value when evualuating a condition. This is only used if using `evaluate`. */
27
+ valueComparer: (condition: any, contextValue: any) => boolean;
28
+ }
29
+ export type BaseErrorTokenTypes = "invalidKey" | "unknownProperty" | "unknownOperator" | "unknownOperatorForType" | "invalidValueType";
30
+ export declare class ParserWithSqlSupport<TErrorToken extends Position & {
31
+ type: BaseErrorTokenTypes;
32
+ message?: string;
33
+ } = Position & {
34
+ type: BaseErrorTokenTypes;
35
+ message?: string;
36
+ }, TPropertyDefinition extends BasePropertyDefinition = BasePropertyDefinition, TPropertyDefinitions extends Record<string, TPropertyDefinition> = Record<string, TPropertyDefinition>, TOperatorDefinition extends BaseOperatorDefinition = BaseOperatorDefinition, TOperatorDefinitions extends Record<string, TOperatorDefinition> = Record<string, TOperatorDefinition>, TSqlEscapeValue extends (value: string) => any | ReturnType<TSqlEscapeValue> = (value: string) => any> extends Parser<TErrorToken> {
37
+ propertyDefinitions: TPropertyDefinitions;
38
+ operatorDefinitions: TOperatorDefinitions;
39
+ sqlEscapeValue: TSqlEscapeValue;
40
+ operatorMap: Record<string, string>;
41
+ constructor(propertyDefinitions: TPropertyDefinitions, operatorDefinitions: TOperatorDefinitions, { sqlEscapeValue }: {
42
+ sqlEscapeValue: TSqlEscapeValue;
43
+ });
44
+ toSql<T>(ast: NormalizedExpression<any, any> | NormalizedCondition<any, any>,
45
+ /**
46
+ * Optionally convert the raw strings to something else. If uding drizzle, you can pass sql.raw here. So later you can just sql.join the return of the function:
47
+ *
48
+ * ```ts
49
+ * sql.join([
50
+ * sql.raw(db.select().from(someTable).toSQL().sql),
51
+ * sql.raw(`where`),
52
+ * ...parser.toSql(ast, sql.raw)
53
+ * ], sql` `)
54
+ * ```
55
+ */
56
+ wrapStrings?: (value: string) => T): (ReturnType<TSqlEscapeValue> | typeof wrapStrings extends undefined ? string : T)[];
57
+ }
58
+ export declare function createTypeError(prop: string, type: string, isArray: boolean): Error;
59
+ export declare function convertAndValidateValue(isQuoted: boolean, value: any, prop: string, propertyDefinitions: Record<string, BasePropertyDefinition>, { isArray }?: {
60
+ isArray?: boolean;
61
+ }): any;
62
+ //# sourceMappingURL=ParserWithSqlSupport.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ParserWithSqlSupport.d.ts","sourceRoot":"","sources":["../../src/examples/ParserWithSqlSupport.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAA;AACrC,OAAO,EAAY,KAAK,mBAAmB,EAAE,KAAK,oBAAoB,EAAE,KAAK,QAAQ,EAAa,MAAM,iBAAiB,CAAA;AAEzH,MAAM,WAAW,sBAAsB;IACtC,IAAI,EAAE,MAAM,CAAA;IACZ,8DAA8D;IAC9D,IAAI,EAAE,MAAM,CAAA;IACZ,kKAAkK;IAClK,iBAAiB,CAAC,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,KAAK,MAAM,CAAA;IACzD;;OAEG;IACH,cAAc,CAAC,EAAE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,GAAG,UAAU,CAAC,eAAe,CAAC,GAAG,CAAC,KAAK,EAAE,MAAM,KAAK,GAAG,CACpG,SAAQ,MAAM,CAAC,WAAW,CAAC;IAMpB,mBAAmB,EAAE,oBAAoB;IACzC,mBAAmB,EAAE,oBAAoB;IANjD,cAAc,EAAE,eAAe,CAAA;IAE/B,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;gBAG3B,mBAAmB,EAAE,oBAAoB,EACzC,mBAAmB,EAAE,oBAAoB,EAChD,EAAE,cAAc,EAAE,EAAE;QAAE,cAAc,EAAE,eAAe,CAAA;KAAE;IAgKxD,KAAK,CAAC,CAAC,EACN,GAAG,EAAE,oBAAoB,CAAC,GAAG,EAAE,GAAG,CAAC,GAAG,mBAAmB,CAAC,GAAG,EAAE,GAAG,CAAC;IACnE;;;;;;;;;;OAUG;IACH,WAAW,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,CAAC,GAChC,CAAC,UAAU,CAAC,eAAe,CAAC,GAAG,OAAO,WAAW,SAAS,SAAS,GAAG,MAAM,GAAG,CAAC,CAAC,EAAE;CA6CtF;AACD,wBAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,GAAG,KAAK,CAKnF;AAED,wBAAgB,uBAAuB,CACtC,QAAQ,EAAE,OAAO,EACjB,KAAK,EAAE,GAAG,EACV,IAAI,EAAE,MAAM,EACZ,mBAAmB,EAAE,MAAM,CAAC,MAAM,EAAE,sBAAsB,CAAC,EAC3D,EAAE,OAAe,EAAE,GAAE;IAAE,OAAO,CAAC,EAAE,OAAO,CAAA;CAAO,GAC7C,GAAG,CAwDL"}
@@ -0,0 +1,269 @@
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
+ import { unreachable } from "@alanscodelog/utils/unreachable.js";
5
+ import { Parser } from "../Parser.js";
6
+ import { AST_TYPE, TOKEN_TYPE } from "../types/ast.js";
7
+ class ParserWithSqlSupport extends Parser {
8
+ constructor(propertyDefinitions, operatorDefinitions, { sqlEscapeValue }) {
9
+ const operators = [];
10
+ const operatorMap = {};
11
+ for (const value of Object.values(operatorDefinitions)) {
12
+ for (const operator of value.operators) {
13
+ operatorMap[operator] = value.operator;
14
+ operators.push(operator);
15
+ }
16
+ if (value.negatedOperators) {
17
+ for (const operator of value.negatedOperators) {
18
+ operatorMap[operator] = value.operator;
19
+ operators.push(operator);
20
+ }
21
+ }
22
+ }
23
+ super({
24
+ arrayValues: true,
25
+ regexValues: false,
26
+ keywords: {
27
+ and: [{ isSymbol: true, value: "&&" }],
28
+ or: [{ isSymbol: true, value: "||" }],
29
+ not: [{ isSymbol: true, value: "!" }]
30
+ },
31
+ customPropertyOperators: operators,
32
+ prefixableGroups: false,
33
+ valueComparer: (condition, contextValue, _context) => {
34
+ var _a;
35
+ if (typeof condition.value !== typeof contextValue) {
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
+ }
38
+ const prop = condition.property[0];
39
+ if (!prop) unreachable("Did you validate the ast before evaluating it?");
40
+ const propDefinition = propertyDefinitions[prop];
41
+ const operatorDefinition = condition.operator && operatorDefinitions[condition.operator];
42
+ if (!operatorDefinition) unreachable("Did you validate the ast before evaluating it?");
43
+ const isSupported = !((_a = propDefinition.supportedOperators) == null ? void 0 : _a.includes(condition.operator));
44
+ if (!isSupported) unreachable("Did you validate the ast before evaluating it?");
45
+ const res = operatorDefinition.valueComparer(condition, contextValue);
46
+ return res;
47
+ },
48
+ valueValidator: (_contextValue, query) => {
49
+ var _a, _b, _c;
50
+ const prop = query.propertyKeys[0];
51
+ let tokens = [];
52
+ const propDefinition = propertyDefinitions[prop];
53
+ if (!propDefinition) {
54
+ tokens = tokens.concat(query.property.map((token) => ({
55
+ start: token.start,
56
+ end: token.end,
57
+ type: "unknownProperty"
58
+ })));
59
+ return tokens;
60
+ }
61
+ const op = query.operator;
62
+ const opKey = op && operatorMap[op.value];
63
+ if (!op || !opKey) {
64
+ tokens.push({
65
+ start: (_a = op ?? query.condition) == null ? void 0 : _a.start,
66
+ end: (_b = op ?? query.condition) == null ? void 0 : _b.end,
67
+ type: "unknownOperator"
68
+ });
69
+ } else {
70
+ if (propDefinition.supportedOperators && !((_c = propDefinition.supportedOperators) == null ? void 0 : _c.includes(opKey))) {
71
+ tokens.push({
72
+ start: query.condition.start,
73
+ end: query.condition.end,
74
+ type: "unknownOperatorForType"
75
+ });
76
+ }
77
+ }
78
+ const val = query.value;
79
+ if (Array.isArray(val)) {
80
+ for (const v of val) {
81
+ if (v.type !== "VARIABLE") unreachable();
82
+ const res2 = convertAndValidateValue(query.isQuoted, v.value.value, prop, propertyDefinitions, { isArray: true });
83
+ if (res2 instanceof Error) {
84
+ if (v.type !== "VARIABLE") unreachable();
85
+ const token = v;
86
+ tokens.push({
87
+ start: token.start,
88
+ end: token.end,
89
+ type: "invalidValueType",
90
+ message: res2.message
91
+ });
92
+ }
93
+ }
94
+ if (tokens.length > 0) return tokens;
95
+ return;
96
+ }
97
+ if ((val == null ? void 0 : val.type) !== "VARIABLE") unreachable();
98
+ const value = val.value.value;
99
+ const res = convertAndValidateValue(query.isQuoted, value, prop, propertyDefinitions);
100
+ if (res instanceof Error) {
101
+ if (!query.value || query.value.type !== "VARIABLE") unreachable();
102
+ const token = query.value.value;
103
+ tokens.push({
104
+ start: token.start,
105
+ end: token.end,
106
+ type: "invalidValueType",
107
+ message: res.message
108
+ });
109
+ }
110
+ if (tokens.length > 0) return tokens;
111
+ },
112
+ conditionNormalizer(query) {
113
+ var _a, _b;
114
+ const prop = (_a = query.property) == null ? void 0 : _a[0];
115
+ if (!prop) unreachable("Did you validate the ast before normalizing it?");
116
+ const propDefinition = propertyDefinitions[prop];
117
+ let finalValue;
118
+ if (Array.isArray(query.value)) {
119
+ const values = [];
120
+ if (query.condition.value.type !== AST_TYPE.ARRAY) unreachable();
121
+ const raw = query.condition.value.values;
122
+ for (let i = 0; i < query.value.length; i += 1) {
123
+ const token = raw[i];
124
+ const val = query.value[i];
125
+ const isQuoted = !!token.quote;
126
+ const res = convertAndValidateValue(isQuoted, val, prop, propertyDefinitions, { isArray: true });
127
+ if (res instanceof Error) throw res;
128
+ values.push(res);
129
+ }
130
+ finalValue = values;
131
+ } else {
132
+ finalValue = convertAndValidateValue(query.isQuoted, query.value, prop, propertyDefinitions);
133
+ if (propDefinition.isArray) {
134
+ finalValue = [finalValue];
135
+ }
136
+ }
137
+ let finalOperator = query.operator;
138
+ if (finalValue instanceof Error) throw finalValue;
139
+ const opKey = query.operator && operatorMap[query.operator];
140
+ if (!opKey) unreachable("Did you validate the ast before normalizing it?");
141
+ const operatorDefinition = opKey && operatorDefinitions[opKey];
142
+ if (!operatorDefinition) unreachable("Did you validate the ast before normalizing it?");
143
+ const isNegatableOperator = (_b = operatorDefinition.negatedOperators) == null ? void 0 : _b.includes(query.operator);
144
+ finalOperator = operatorDefinition.operator;
145
+ let isNegated = query.isNegated;
146
+ if (isNegatableOperator) {
147
+ isNegated = !isNegated;
148
+ }
149
+ return { value: finalValue, operator: finalOperator, negate: isNegated };
150
+ }
151
+ });
152
+ __publicField(this, "sqlEscapeValue");
153
+ __publicField(this, "operatorMap");
154
+ this.propertyDefinitions = propertyDefinitions;
155
+ this.operatorDefinitions = operatorDefinitions;
156
+ this.operatorMap = operatorMap;
157
+ this.sqlEscapeValue = sqlEscapeValue;
158
+ }
159
+ toSql(ast, wrapStrings) {
160
+ var _a, _b;
161
+ this._checkEvaluationOptions();
162
+ const chunks = [];
163
+ if (ast.type === AST_TYPE.NORMALIZED_CONDITION) {
164
+ const prop = (_a = ast.property) == null ? void 0 : _a[0];
165
+ const definition = this.propertyDefinitions[prop];
166
+ const value = ast.value;
167
+ const col = ((_b = definition.transformToColumn) == null ? void 0 : _b.call(definition, prop, definition.name)) ?? `"${prop}"`;
168
+ const op = ast.operator;
169
+ if (ast.negate) {
170
+ chunks.push((wrapStrings == null ? void 0 : wrapStrings(`NOT(`)) ?? `NOT(`);
171
+ }
172
+ chunks.push((wrapStrings == null ? void 0 : wrapStrings(`${col} `)) ?? `${col} `);
173
+ chunks.push((wrapStrings == null ? void 0 : wrapStrings(`${op} `)) ?? `${op} `);
174
+ const val = this.sqlEscapeValue(value);
175
+ if (definition.transformValue) {
176
+ const transformed = definition.transformValue(val, value);
177
+ if (Array.isArray(transformed)) {
178
+ chunks.push(...transformed);
179
+ } else {
180
+ chunks.push(transformed);
181
+ }
182
+ } else {
183
+ chunks.push(val);
184
+ }
185
+ if (ast.negate) {
186
+ chunks.push((wrapStrings == null ? void 0 : wrapStrings(`)`)) ?? `)`);
187
+ }
188
+ return chunks;
189
+ }
190
+ if (ast.type === AST_TYPE.NORMALIZED_EXPRESSION) {
191
+ const left = this.toSql(ast.left, wrapStrings);
192
+ const right = this.toSql(ast.right, wrapStrings);
193
+ const op = ast.operator === TOKEN_TYPE.AND ? "AND" : "OR";
194
+ chunks.push((wrapStrings == null ? void 0 : wrapStrings(`(`)) ?? `(`);
195
+ chunks.push(...left);
196
+ chunks.push((wrapStrings == null ? void 0 : wrapStrings(` ${op} `)) ?? ` ${op} `);
197
+ chunks.push(...right);
198
+ chunks.push((wrapStrings == null ? void 0 : wrapStrings(`)`)) ?? `)`);
199
+ return chunks;
200
+ }
201
+ return unreachable();
202
+ }
203
+ }
204
+ function createTypeError(prop, type, isArray) {
205
+ if (isArray) {
206
+ return new Error(`Property ${prop} must contain items of type ${type}.`);
207
+ }
208
+ return new Error(`Property ${prop} must be of type ${type}.`);
209
+ }
210
+ function convertAndValidateValue(isQuoted, value, prop, propertyDefinitions, { isArray = false } = {}) {
211
+ var _a;
212
+ let finalValue = value;
213
+ let isFloat = false;
214
+ const propDefinition = propertyDefinitions[prop];
215
+ if (typeof value === "string" && !isQuoted) {
216
+ if (finalValue === "true") {
217
+ finalValue = true;
218
+ } else if (finalValue === "false") {
219
+ finalValue = false;
220
+ } else {
221
+ const asNum = parseInt(value, 10);
222
+ if (!isNaN(asNum)) {
223
+ finalValue = asNum;
224
+ } else {
225
+ const asFloat = parseFloat(value);
226
+ if (!isNaN(asFloat)) {
227
+ finalValue = asFloat;
228
+ isFloat = true;
229
+ }
230
+ }
231
+ }
232
+ }
233
+ const type = propDefinition.type;
234
+ finalValue = ((_a = propDefinition.postParse) == null ? void 0 : _a.call(propDefinition, finalValue)) ?? finalValue;
235
+ switch (type) {
236
+ case "integer":
237
+ case "float": {
238
+ if (typeof finalValue !== "number" || type === "float" && !isFloat || type === "integer" && isFloat) {
239
+ return createTypeError(prop, type, isArray);
240
+ }
241
+ break;
242
+ }
243
+ case "string":
244
+ case "boolean": {
245
+ if (typeof finalValue !== propDefinition.type) {
246
+ return createTypeError(prop, type, isArray);
247
+ }
248
+ break;
249
+ }
250
+ case "date": {
251
+ if (finalValue instanceof Date) {
252
+ break;
253
+ }
254
+ const maybeDate = new Date(finalValue);
255
+ if (isNaN(maybeDate.getTime())) {
256
+ return createTypeError(prop, "date", isArray);
257
+ } else {
258
+ finalValue = maybeDate;
259
+ }
260
+ break;
261
+ }
262
+ }
263
+ return finalValue;
264
+ }
265
+ export {
266
+ ParserWithSqlSupport,
267
+ convertAndValidateValue,
268
+ createTypeError
269
+ };
@@ -1,3 +1,5 @@
1
+ import { Parser } from "../Parser.js";
2
+ import type { Position } from "../types/ast.js";
1
3
  /**
2
4
  * A pre-configured parser for parsing shortcut contexts (similar to VSCode's [when clause contexts](https://code.visualstudio.com/docs/getstarted/keybindings#_when-clause-contexts)).
3
5
  *
@@ -7,17 +9,15 @@
7
9
  *
8
10
  * The validate function will return a list of positions with a list of errors which includes handling invalid or duplicate regex flags.
9
11
  */
10
- import { Parser } from "../Parser.js";
11
- import type { Position } from "../types/ast.js";
12
- export declare class ShortcutContextParser<T extends Position & {
12
+ export declare class ShortcutContextParser<TErrorTokens extends Position & {
13
13
  type: ("invalidKey" | "unregexableKey" | "invalidRegexFlag" | "duplicateRegexFlag");
14
14
  } = Position & {
15
15
  type: ("invalidKey" | "unregexableKey" | "invalidRegexFlag" | "duplicateRegexFlag");
16
- }> extends Parser<T> {
16
+ }> extends Parser<TErrorTokens> {
17
17
  validKeys: string[];
18
18
  regexablekeys: string[];
19
19
  constructor(dummyContext: Record<string, any>, validRegexFlags?: string[]);
20
20
  setContext(context: Record<string, any>): void;
21
21
  private _extractKeysFromContext;
22
22
  }
23
- //# sourceMappingURL=shortcutContextParser.d.ts.map
23
+ //# sourceMappingURL=ShortcutContextParser.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ShortcutContextParser.d.ts","sourceRoot":"","sources":["../../src/examples/ShortcutContextParser.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAA;AACrC,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAA;AAI/C;;;;;;;;GAQG;AAGH,qBAAa,qBAAqB,CAAC,YAAY,SAC9C,QAAQ,GAAG;IAAE,IAAI,EAAE,CAAC,YAAY,GAAG,gBAAgB,GAAG,kBAAkB,GAAG,oBAAoB,CAAC,CAAA;CAAE,GAClG,QAAQ,GAAG;IAAE,IAAI,EAAE,CAAC,YAAY,GAAG,gBAAgB,GAAG,kBAAkB,GAAG,oBAAoB,CAAC,CAAA;CAAE,CACjG,SAAQ,MAAM,CAAC,YAAY,CAAC;IAC7B,SAAS,EAAE,MAAM,EAAE,CAAK;IAExB,aAAa,EAAE,MAAM,EAAE,CAAK;gBAG3B,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EACjC,eAAe,GAAE,MAAM,EAAoB;IAmG5C,UAAU,CAAC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,IAAI;IAK9C,OAAO,CAAC,uBAAuB;CAa/B"}
@@ -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
- const asNum = parseInt(value, 2);
78
- if (!isNaN(asNum))
79
- finalValue = asNum;
73
+ const asNum = parseInt(value, 10);
74
+ if (!isNaN(asNum)) finalValue = asNum;
80
75
  if (["true", "false"].includes(value)) {
81
76
  finalValue = value === "true";
82
77
  }
@@ -114,12 +109,11 @@ class ShortcutContextParser extends Parser {
114
109
  for (const key of Object.keys(context)) {
115
110
  if (typeof context[key] === "boolean") {
116
111
  this.validKeys.push(prev ? `${prev}.${key}` : key);
117
- if (context[key] === true) {
112
+ if (context[key]) {
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
  }
@@ -1,2 +1,3 @@
1
- export { ShortcutContextParser } from "./shortcutContextParser.js";
1
+ export { ShortcutContextParser } from "./ShortcutContextParser.js";
2
+ export { ParserWithSqlSupport } from "./ParserWithSqlSupport.js";
2
3
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/examples/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/examples/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAA;AAClE,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAA"}
@@ -1,4 +1,6 @@
1
- import { ShortcutContextParser } from "./shortcutContextParser.js";
1
+ import { ShortcutContextParser } from "./ShortcutContextParser.js";
2
+ import { ParserWithSqlSupport } from "./ParserWithSqlSupport.js";
2
3
  export {
4
+ ParserWithSqlSupport,
3
5
  ShortcutContextParser
4
6
  };
@@ -1,13 +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
- import { version, repository } from "../package.js";
7
+ import packageJson from "../package.json.js";
8
+ const { version, repository } = packageJson;
11
9
  class ExpressitError extends Error {
12
10
  constructor(type, info, message) {
13
11
  super(
@@ -1,4 +1,4 @@
1
1
  import type { FullParserOptions } from "../types/parser.js";
2
2
  /** @internal */
3
- export declare function checkParserOpts<T extends {}>(opts: FullParserOptions<T>, evaluatorChecks?: boolean, validatorChecks?: boolean): void;
3
+ export declare function checkParserOpts<T>(opts: FullParserOptions<T>, evaluatorChecks?: boolean, validatorChecks?: boolean): void;
4
4
  //# sourceMappingURL=checkParserOpts.d.ts.map
@@ -1 +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
+ {"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,EAAE,IAAI,EAAE,iBAAiB,CAAC,CAAC,CAAC,EAAE,eAAe,GAAE,OAAe,EAAE,eAAe,GAAE,OAAe,GAAG,IAAI,CAoIvI"}
@@ -16,10 +16,8 @@ function checkParserOpts(opts, evaluatorChecks = false, validatorChecks = false)
16
16
  ...opts.regexValues ? ["/"] : []
17
17
  ];
18
18
  const extra = [];
19
- if (opts.expandedPropertySeparator)
20
- extra.push(opts.expandedPropertySeparator);
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
22
  throw new ExpressitError(
25
23
  ERROR_CODES.PARSER_CONFLICTING_OPTIONS_ERROR,
@@ -84,14 +82,10 @@ 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
- requireCustomNormalizer.push("prefixableStrings");
89
- if ((((_h = opts.customPropertyOperators) == null ? void 0 : _h.length) ?? 0) > 0)
90
- requireCustomNormalizer.push("customPropertyOperators");
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
90
  throw new ExpressitError(
97
91
  ERROR_CODES.PARSER_OPTION_REQUIRED_ERROR,
@@ -100,10 +94,8 @@ function checkParserOpts(opts, evaluatorChecks = false, validatorChecks = false)
100
94
  );
101
95
  }
102
96
  const requireCustomComparer = [];
103
- if (opts.regexValues)
104
- requireCustomComparer.push("regexValues");
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
100
  throw new ExpressitError(
109
101
  ERROR_CODES.PARSER_OPTION_REQUIRED_ERROR,
@@ -2,16 +2,14 @@ import { multisplice } from "@alanscodelog/utils/multisplice.js";
2
2
  function escapeVariableOrPrefix(variable, preferredQuote) {
3
3
  let doQuote = false;
4
4
  for (const quoteType of ['"', "'", "`"]) {
5
- if (!variable.includes(quoteType) && !variable.includes(" "))
6
- continue;
5
+ if (!variable.includes(quoteType) && !variable.includes(" ")) continue;
7
6
  if (variable.startsWith(quoteType) && variable.endsWith(quoteType)) {
8
7
  break;
9
8
  }
10
9
  const indexes = [];
11
10
  for (let i = 0; i < variable.length; i++) {
12
11
  const char = variable[i];
13
- if (char === void 0)
14
- break;
12
+ if (char === void 0) break;
15
13
  if (char === "\\") {
16
14
  i += 2;
17
15
  continue;
@@ -19,11 +17,9 @@ function escapeVariableOrPrefix(variable, preferredQuote) {
19
17
  if (char === " ") {
20
18
  doQuote = true;
21
19
  }
22
- if (char === quoteType)
23
- indexes.push(i);
20
+ if (char === quoteType) indexes.push(i);
24
21
  }
25
- if (indexes.length === 0)
26
- break;
22
+ if (indexes.length === 0) break;
27
23
  const newVal = multisplice(variable.split(""), indexes, 0, "\\").array.join("");
28
24
  variable = newVal;
29
25
  break;
@@ -1,4 +1,4 @@
1
1
  import type { FullParserOptions, ParserOptions } from "../types/parser.js";
2
2
  /** @internal */
3
- export declare function parseParserOptions<T extends {} = {}>(options: ParserOptions<T>): FullParserOptions<T>;
3
+ export declare function parseParserOptions<T>(options: ParserOptions<T>): FullParserOptions<T>;
4
4
  //# sourceMappingURL=parseParserOptions.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"parseParserOptions.d.ts","sourceRoot":"","sources":["../../src/internal/parseParserOptions.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,iBAAiB,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAA;AAE1E,gBAAgB;AAChB,wBAAgB,kBAAkB,CAAC,CAAC,SAAS,EAAE,GAAG,EAAE,EACnD,OAAO,EAAE,aAAa,CAAC,CAAC,CAAC,GACvB,iBAAiB,CAAC,CAAC,CAAC,CA4CtB"}
1
+ {"version":3,"file":"parseParserOptions.d.ts","sourceRoot":"","sources":["../../src/internal/parseParserOptions.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,iBAAiB,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAA;AAE1E,gBAAgB;AAChB,wBAAgB,kBAAkB,CAAC,CAAC,EACnC,OAAO,EAAE,aAAa,CAAC,CAAC,CAAC,GACvB,iBAAiB,CAAC,CAAC,CAAC,CA4CtB"}