@witchcraft/expressit 0.2.1 → 0.3.0

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 (119) hide show
  1. package/README.md +6 -4
  2. package/dist/Lexer.d.ts +102 -99
  3. package/dist/Lexer.d.ts.map +1 -1
  4. package/dist/Lexer.js +211 -557
  5. package/dist/Parser.d.ts +27 -27
  6. package/dist/Parser.d.ts.map +1 -1
  7. package/dist/Parser.js +5 -2
  8. package/dist/ast/builders/condition.d.ts +1 -1
  9. package/dist/ast/builders/condition.d.ts.map +1 -1
  10. package/dist/ast/builders/condition.js +1 -0
  11. package/dist/ast/builders/delim.d.ts +3 -3
  12. package/dist/ast/builders/delim.d.ts.map +1 -1
  13. package/dist/ast/builders/error.d.ts +2 -2
  14. package/dist/ast/builders/error.d.ts.map +1 -1
  15. package/dist/ast/builders/expression.d.ts +2 -2
  16. package/dist/ast/builders/expression.d.ts.map +1 -1
  17. package/dist/ast/builders/expression.js +2 -6
  18. package/dist/ast/builders/group.d.ts +1 -1
  19. package/dist/ast/builders/group.d.ts.map +1 -1
  20. package/dist/ast/builders/group.js +1 -3
  21. package/dist/ast/builders/pos.d.ts +2 -2
  22. package/dist/ast/builders/pos.d.ts.map +1 -1
  23. package/dist/ast/builders/token.d.ts +2 -2
  24. package/dist/ast/builders/token.d.ts.map +1 -1
  25. package/dist/ast/builders/type.d.ts +2 -2
  26. package/dist/ast/builders/type.d.ts.map +1 -1
  27. package/dist/ast/builders/variable.d.ts +3 -3
  28. package/dist/ast/builders/variable.d.ts.map +1 -1
  29. package/dist/ast/createConditionNode.d.ts +1 -1
  30. package/dist/ast/createConditionNode.d.ts.map +1 -1
  31. package/dist/ast/createGroupNode.d.ts +1 -1
  32. package/dist/ast/createGroupNode.d.ts.map +1 -1
  33. package/dist/ast/createToken.d.ts +2 -2
  34. package/dist/ast/createToken.d.ts.map +1 -1
  35. package/dist/ast/createToken.js +2 -2
  36. package/dist/ast/error.d.ts +2 -2
  37. package/dist/ast/error.d.ts.map +1 -1
  38. package/dist/ast/error.js +1 -0
  39. package/dist/ast/handlers.d.ts +23 -23
  40. package/dist/ast/handlers.d.ts.map +1 -1
  41. package/dist/ast/handlers.js +4 -4
  42. package/dist/examples/ParserWithSqlSupport.d.ts +62 -0
  43. package/dist/examples/ParserWithSqlSupport.d.ts.map +1 -0
  44. package/dist/examples/ParserWithSqlSupport.js +271 -0
  45. package/dist/examples/{shortcutContextParser.d.ts → ShortcutContextParser.d.ts} +5 -5
  46. package/dist/examples/ShortcutContextParser.d.ts.map +1 -0
  47. package/dist/examples/{shortcutContextParser.js → ShortcutContextParser.js} +2 -2
  48. package/dist/examples/index.d.ts +2 -1
  49. package/dist/examples/index.d.ts.map +1 -1
  50. package/dist/examples/index.js +3 -1
  51. package/dist/index.js +2 -2
  52. package/dist/internal/ExpressitError.d.ts +2 -2
  53. package/dist/internal/ExpressitError.d.ts.map +1 -1
  54. package/dist/internal/ExpressitError.js +2 -1
  55. package/dist/internal/checkParserOpts.d.ts +1 -1
  56. package/dist/internal/checkParserOpts.d.ts.map +1 -1
  57. package/dist/internal/checkParserOpts.js +11 -11
  58. package/dist/internal/parseParserOptions.d.ts +1 -1
  59. package/dist/internal/parseParserOptions.d.ts.map +1 -1
  60. package/dist/package.json.js +4 -195
  61. package/dist/types/ast.d.ts +60 -58
  62. package/dist/types/ast.d.ts.map +1 -1
  63. package/dist/types/ast.js +26 -27
  64. package/dist/types/autocomplete.d.ts +23 -21
  65. package/dist/types/autocomplete.d.ts.map +1 -1
  66. package/dist/types/autocomplete.js +24 -21
  67. package/dist/types/errors.d.ts +12 -10
  68. package/dist/types/errors.d.ts.map +1 -1
  69. package/dist/types/errors.js +8 -7
  70. package/dist/types/index.js +2 -2
  71. package/dist/types/parser.d.ts +9 -9
  72. package/dist/types/parser.d.ts.map +1 -1
  73. package/dist/utils/getCursorInfo.js +3 -1
  74. package/dist/utils/getOppositeDelimiter.d.ts +2 -2
  75. package/dist/utils/getOppositeDelimiter.d.ts.map +1 -1
  76. package/dist/utils/isDelimiter.d.ts +2 -2
  77. package/dist/utils/isDelimiter.d.ts.map +1 -1
  78. package/dist/utils/isParen.d.ts +2 -2
  79. package/dist/utils/isParen.d.ts.map +1 -1
  80. package/dist/utils/isQuote.d.ts +2 -2
  81. package/dist/utils/isQuote.d.ts.map +1 -1
  82. package/package.json +29 -27
  83. package/src/Lexer.ts +103 -92
  84. package/src/Parser.ts +70 -64
  85. package/src/ast/builders/condition.ts +3 -3
  86. package/src/ast/builders/delim.ts +5 -5
  87. package/src/ast/builders/error.ts +3 -3
  88. package/src/ast/builders/expression.ts +4 -8
  89. package/src/ast/builders/group.ts +2 -4
  90. package/src/ast/builders/pos.ts +3 -3
  91. package/src/ast/builders/token.ts +2 -2
  92. package/src/ast/builders/type.ts +2 -2
  93. package/src/ast/builders/variable.ts +5 -5
  94. package/src/ast/createConditionNode.ts +2 -2
  95. package/src/ast/createGroupNode.ts +4 -4
  96. package/src/ast/createToken.ts +6 -6
  97. package/src/ast/error.ts +2 -2
  98. package/src/ast/handlers.ts +23 -23
  99. package/src/examples/ParserWithSqlSupport.ts +371 -0
  100. package/src/examples/{shortcutContextParser.ts → ShortcutContextParser.ts} +14 -14
  101. package/src/examples/index.ts +2 -1
  102. package/src/internal/ExpressitError.ts +4 -4
  103. package/src/internal/checkParserOpts.ts +14 -14
  104. package/src/internal/parseParserOptions.ts +2 -2
  105. package/src/types/ast.ts +101 -96
  106. package/src/types/autocomplete.ts +26 -22
  107. package/src/types/errors.ts +18 -13
  108. package/src/types/parser.ts +9 -9
  109. package/src/utils/getCursorInfo.ts +1 -1
  110. package/src/utils/getOppositeDelimiter.ts +2 -2
  111. package/src/utils/getSurroundingErrors.ts +4 -4
  112. package/src/utils/isDelimiter.ts +3 -3
  113. package/src/utils/isParen.ts +2 -2
  114. package/src/utils/isQuote.ts +2 -2
  115. package/dist/examples/shortcutContextParser.d.ts.map +0 -1
  116. package/dist/global.d.js +0 -1
  117. package/dist/package.js +0 -7
  118. package/src/global.d.ts +0 -4
  119. package/src/package.js +0 -11
@@ -67,7 +67,7 @@ function condition(not, property, { propertyOperator, sepL, sepR } = {}, value)
67
67
  const start = (not == null ? void 0 : not.start) ?? (property == null ? void 0 : property.start) ?? (sepL == null ? void 0 : sepL.start) ?? (propertyOperator == null ? void 0 : propertyOperator.start) ?? (sepR == null ? void 0 : sepR.start) ?? (value == null ? void 0 : value.start);
68
68
  const end = (value == null ? void 0 : value.end) ?? (sepR == null ? void 0 : sepR.end) ?? (propertyOperator == null ? void 0 : propertyOperator.end) ?? (sepL == null ? void 0 : sepL.end) ?? (property == null ? void 0 : property.end) ?? (not == null ? void 0 : not.end);
69
69
  const node = {
70
- value: value ? value : error(end, [TOKEN_TYPE.VALUE]),
70
+ value: value ?? error(end, [TOKEN_TYPE.VALUE]),
71
71
  start,
72
72
  end
73
73
  };
@@ -80,15 +80,15 @@ function condition(not, property, { propertyOperator, sepL, sepR } = {}, value)
80
80
  node.sep = {};
81
81
  if (sepL) {
82
82
  node.sep.left = sepL;
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]));
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]));
85
85
  }
86
86
  if (sepR) node.sep.right = sepR;
87
87
  else if (!node.value || node.value.type === AST_TYPE.VARIABLE) {
88
88
  node.sep.right = error(((_a = node.value) == null ? void 0 : _a.start) ?? end, [TOKEN_TYPE.OP_EXPANDED_SEP]);
89
89
  }
90
90
  } else if (propertyOperator) {
91
- node.property || (node.property = error(propertyOperator.start, [TOKEN_TYPE.VALUE]));
91
+ node.property ?? (node.property = error(propertyOperator.start, [TOKEN_TYPE.VALUE]));
92
92
  }
93
93
  return createConditionNode(node);
94
94
  }
@@ -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 SqlParserError = "invalidKey" | "unknownProperty" | "unknownOperator" | "unknownOperatorForType" | "invalidValueType";
30
+ export declare class ParserWithSqlSupport<TErrorToken extends Position & {
31
+ type: SqlParserError;
32
+ message?: string;
33
+ } = Position & {
34
+ type: SqlParserError;
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
+ sqlEscapeValue: TSqlEscapeValue;
38
+ operatorMap: Record<string, string>;
39
+ propertyDefinitions: TPropertyDefinitions;
40
+ operatorDefinitions: TOperatorDefinitions;
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":"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"}
@@ -0,0 +1,271 @@
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
+ __publicField(this, "propertyDefinitions");
155
+ __publicField(this, "operatorDefinitions");
156
+ this.propertyDefinitions = propertyDefinitions;
157
+ this.operatorDefinitions = operatorDefinitions;
158
+ this.operatorMap = operatorMap;
159
+ this.sqlEscapeValue = sqlEscapeValue;
160
+ }
161
+ toSql(ast, wrapStrings) {
162
+ var _a, _b;
163
+ this._checkEvaluationOptions();
164
+ const chunks = [];
165
+ if (ast.type === AST_TYPE.NORMALIZED_CONDITION) {
166
+ const prop = (_a = ast.property) == null ? void 0 : _a[0];
167
+ const definition = this.propertyDefinitions[prop];
168
+ const value = ast.value;
169
+ const col = ((_b = definition.transformToColumn) == null ? void 0 : _b.call(definition, prop, definition.name)) ?? `"${prop}"`;
170
+ const op = ast.operator;
171
+ if (ast.negate) {
172
+ chunks.push((wrapStrings == null ? void 0 : wrapStrings(`NOT(`)) ?? `NOT(`);
173
+ }
174
+ chunks.push((wrapStrings == null ? void 0 : wrapStrings(`${col} `)) ?? `${col} `);
175
+ chunks.push((wrapStrings == null ? void 0 : wrapStrings(`${op} `)) ?? `${op} `);
176
+ const val = this.sqlEscapeValue(value);
177
+ if (definition.transformValue) {
178
+ const transformed = definition.transformValue(val, value);
179
+ if (Array.isArray(transformed)) {
180
+ chunks.push(...transformed);
181
+ } else {
182
+ chunks.push(transformed);
183
+ }
184
+ } else {
185
+ chunks.push(val);
186
+ }
187
+ if (ast.negate) {
188
+ chunks.push((wrapStrings == null ? void 0 : wrapStrings(`)`)) ?? `)`);
189
+ }
190
+ return chunks;
191
+ }
192
+ if (ast.type === AST_TYPE.NORMALIZED_EXPRESSION) {
193
+ const left = this.toSql(ast.left, wrapStrings);
194
+ const right = this.toSql(ast.right, wrapStrings);
195
+ const op = ast.operator === TOKEN_TYPE.AND ? "AND" : "OR";
196
+ chunks.push((wrapStrings == null ? void 0 : wrapStrings(`(`)) ?? `(`);
197
+ chunks.push(...left);
198
+ chunks.push((wrapStrings == null ? void 0 : wrapStrings(` ${op} `)) ?? ` ${op} `);
199
+ chunks.push(...right);
200
+ chunks.push((wrapStrings == null ? void 0 : wrapStrings(`)`)) ?? `)`);
201
+ return chunks;
202
+ }
203
+ return unreachable();
204
+ }
205
+ }
206
+ function createTypeError(prop, type, isArray) {
207
+ if (isArray) {
208
+ return new Error(`Property ${prop} must contain items of type ${type}.`);
209
+ }
210
+ return new Error(`Property ${prop} must be of type ${type}.`);
211
+ }
212
+ function convertAndValidateValue(isQuoted, value, prop, propertyDefinitions, { isArray = false } = {}) {
213
+ var _a;
214
+ let finalValue = value;
215
+ let isFloat = false;
216
+ const propDefinition = propertyDefinitions[prop];
217
+ if (typeof value === "string" && !isQuoted) {
218
+ if (finalValue === "true") {
219
+ finalValue = true;
220
+ } else if (finalValue === "false") {
221
+ finalValue = false;
222
+ } else {
223
+ const asNum = parseInt(value, 10);
224
+ if (!isNaN(asNum)) {
225
+ finalValue = asNum;
226
+ } else {
227
+ const asFloat = parseFloat(value);
228
+ if (!isNaN(asFloat)) {
229
+ finalValue = asFloat;
230
+ isFloat = true;
231
+ }
232
+ }
233
+ }
234
+ }
235
+ const type = propDefinition.type;
236
+ finalValue = ((_a = propDefinition.postParse) == null ? void 0 : _a.call(propDefinition, finalValue)) ?? finalValue;
237
+ switch (type) {
238
+ case "integer":
239
+ case "float": {
240
+ if (typeof finalValue !== "number" || type === "float" && !isFloat || type === "integer" && isFloat) {
241
+ return createTypeError(prop, type, isArray);
242
+ }
243
+ break;
244
+ }
245
+ case "string":
246
+ case "boolean": {
247
+ if (typeof finalValue !== propDefinition.type) {
248
+ return createTypeError(prop, type, isArray);
249
+ }
250
+ break;
251
+ }
252
+ case "date": {
253
+ if (finalValue instanceof Date) {
254
+ break;
255
+ }
256
+ const maybeDate = new Date(finalValue);
257
+ if (isNaN(maybeDate.getTime())) {
258
+ return createTypeError(prop, "date", isArray);
259
+ } else {
260
+ finalValue = maybeDate;
261
+ }
262
+ break;
263
+ }
264
+ }
265
+ return finalValue;
266
+ }
267
+ export {
268
+ ParserWithSqlSupport,
269
+ convertAndValidateValue,
270
+ createTypeError
271
+ };
@@ -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"}
@@ -70,7 +70,7 @@ class ShortcutContextParser extends Parser {
70
70
  let finalValue = value;
71
71
  let finalOperator = operator;
72
72
  if (typeof value === "string" && !isQuoted) {
73
- const asNum = parseInt(value, 2);
73
+ const asNum = parseInt(value, 10);
74
74
  if (!isNaN(asNum)) finalValue = asNum;
75
75
  if (["true", "false"].includes(value)) {
76
76
  finalValue = value === "true";
@@ -109,7 +109,7 @@ class ShortcutContextParser extends Parser {
109
109
  for (const key of Object.keys(context)) {
110
110
  if (typeof context[key] === "boolean") {
111
111
  this.validKeys.push(prev ? `${prev}.${key}` : key);
112
- if (context[key] === true) {
112
+ if (context[key]) {
113
113
  this.regexablekeys.push(prev ? `${prev}.${key}` : key);
114
114
  }
115
115
  } else {
@@ -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
  };
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 { ERROR_CODES } from "./types/errors.js";
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
- ERROR_CODES,
10
+ PARSER_ERROR,
11
11
  Parser,
12
12
  SUGGESTION_TYPE,
13
13
  TOKEN_TYPE,
@@ -1,6 +1,6 @@
1
- import type { ERROR_CODES, ErrorInfo } from "../types/errors.js";
1
+ import type { ErrorInfo, ParserError } from "../types/errors.js";
2
2
  /** @internal */
3
- export declare class ExpressitError<T extends ERROR_CODES> extends Error {
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,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
+ {"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"}
@@ -4,7 +4,8 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
4
4
  import { crop } from "@alanscodelog/utils/crop.js";
5
5
  import { indent } from "@alanscodelog/utils/indent.js";
6
6
  import { pretty } from "@alanscodelog/utils/pretty.js";
7
- import { version, repository } from "../package.js";
7
+ import packageJson from "../package.json.js";
8
+ const { version, repository } = packageJson;
8
9
  class ExpressitError extends Error {
9
10
  constructor(type, info, message) {
10
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"}
@@ -3,7 +3,7 @@ import { pushIfNotIn } from "@alanscodelog/utils/pushIfNotIn.js";
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 { ERROR_CODES } from "../types/errors.js";
6
+ import { PARSER_ERROR } 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) {
@@ -20,7 +20,7 @@ function checkParserOpts(opts, evaluatorChecks = false, validatorChecks = false)
20
20
  if (opts.customPropertyOperators) pushIfNotIn(extra, opts.customPropertyOperators);
21
21
  if (opts.expandedPropertySeparator && isBlank(opts.expandedPropertySeparator)) {
22
22
  throw new ExpressitError(
23
- ERROR_CODES.PARSER_CONFLICTING_OPTIONS_ERROR,
23
+ PARSER_ERROR.CONFLICTING_OPTIONS_ERROR,
24
24
  { prohibited: [""], invalid: opts.expandedPropertySeparator },
25
25
  `expandedPropertySeparator cannot be blank`
26
26
  );
@@ -28,7 +28,7 @@ function checkParserOpts(opts, evaluatorChecks = false, validatorChecks = false)
28
28
  const customInvalid = (_a = opts.customPropertyOperators) == null ? void 0 : _a.find((_) => isBlank(_));
29
29
  if (customInvalid !== void 0) {
30
30
  throw new ExpressitError(
31
- ERROR_CODES.PARSER_CONFLICTING_OPTIONS_ERROR,
31
+ PARSER_ERROR.CONFLICTING_OPTIONS_ERROR,
32
32
  { prohibited: [""], invalid: customInvalid },
33
33
  `customPropertyOperators cannot contain blank entries`
34
34
  );
@@ -36,7 +36,7 @@ function checkParserOpts(opts, evaluatorChecks = false, validatorChecks = false)
36
36
  const prefixInvalid = (_b = opts.prefixableStrings) == null ? void 0 : _b.find((_) => isBlank(_));
37
37
  if (prefixInvalid !== void 0) {
38
38
  throw new ExpressitError(
39
- ERROR_CODES.PARSER_CONFLICTING_OPTIONS_ERROR,
39
+ PARSER_ERROR.CONFLICTING_OPTIONS_ERROR,
40
40
  { prohibited: [""], invalid: prefixInvalid },
41
41
  `prefixableStrings cannot contain blank entries`
42
42
  );
@@ -45,7 +45,7 @@ function checkParserOpts(opts, evaluatorChecks = false, validatorChecks = false)
45
45
  const invalid = (_d = (_c = opts.keywords[key]) == null ? void 0 : _c.find((_) => isBlank(_.value))) == null ? void 0 : _d.value;
46
46
  if (invalid !== void 0) {
47
47
  throw new ExpressitError(
48
- ERROR_CODES.PARSER_CONFLICTING_OPTIONS_ERROR,
48
+ PARSER_ERROR.CONFLICTING_OPTIONS_ERROR,
49
49
  { prohibited: [""], invalid },
50
50
  `keywords.${key} cannot contain entries with blank values`
51
51
  );
@@ -58,7 +58,7 @@ function checkParserOpts(opts, evaluatorChecks = false, validatorChecks = false)
58
58
  const invalidPrefixableString = (_e = opts.prefixableStrings) == null ? void 0 : _e.find((val) => all.includes(val));
59
59
  if (invalidPrefixableString) {
60
60
  throw new ExpressitError(
61
- ERROR_CODES.PARSER_CONFLICTING_OPTIONS_ERROR,
61
+ PARSER_ERROR.CONFLICTING_OPTIONS_ERROR,
62
62
  { prohibited: all, invalid: invalidPrefixableString },
63
63
  `prefixableStrings ${messageInvalidAny} "${invalidPrefixableString}"`
64
64
  );
@@ -66,7 +66,7 @@ function checkParserOpts(opts, evaluatorChecks = false, validatorChecks = false)
66
66
  const invalidExpandedPropertySeparator = allKeywords.find((_) => _ === opts.expandedPropertySeparator);
67
67
  if (invalidExpandedPropertySeparator) {
68
68
  throw new ExpressitError(
69
- ERROR_CODES.PARSER_CONFLICTING_OPTIONS_ERROR,
69
+ PARSER_ERROR.CONFLICTING_OPTIONS_ERROR,
70
70
  { prohibited: allKeywords, invalid: invalidExpandedPropertySeparator },
71
71
  `expandedPropertySeparator ${messageInvalidBool} "${invalidExpandedPropertySeparator}"`
72
72
  );
@@ -74,7 +74,7 @@ function checkParserOpts(opts, evaluatorChecks = false, validatorChecks = false)
74
74
  const invalidCustomPropertyOperator = ((_f = opts.customPropertyOperators) == null ? void 0 : _f.find((val) => keywords.includes(val))) ? opts.expandedPropertySeparator : void 0;
75
75
  if (invalidCustomPropertyOperator) {
76
76
  throw new ExpressitError(
77
- ERROR_CODES.PARSER_CONFLICTING_OPTIONS_ERROR,
77
+ PARSER_ERROR.CONFLICTING_OPTIONS_ERROR,
78
78
  { prohibited: keywords, invalid: invalidCustomPropertyOperator },
79
79
  `customPropertyOperator ${messageInvalidBool} "${invalidCustomPropertyOperator}"`
80
80
  );
@@ -88,7 +88,7 @@ function checkParserOpts(opts, evaluatorChecks = false, validatorChecks = false)
88
88
  if (opts.regexValues) requireCustomNormalizer.push("regexValues");
89
89
  if (requireCustomNormalizer.length > 0 && opts.conditionNormalizer === defaultConditionNormalizer) {
90
90
  throw new ExpressitError(
91
- ERROR_CODES.PARSER_OPTION_REQUIRED_ERROR,
91
+ PARSER_ERROR.OPTION_REQUIRED_ERROR,
92
92
  { options: requireCustomNormalizer, requires: "conditionNormalizer" },
93
93
  `A custom conditionNormalizer function must be specified when using the following options: ${requireCustomNormalizer.join(", ")}`
94
94
  );
@@ -98,7 +98,7 @@ function checkParserOpts(opts, evaluatorChecks = false, validatorChecks = false)
98
98
  if (opts.regexValues) requireCustomComparer.push("arrayValues");
99
99
  if (requireCustomComparer.length > 0 && opts.valueComparer === defaultValueComparer) {
100
100
  throw new ExpressitError(
101
- ERROR_CODES.PARSER_OPTION_REQUIRED_ERROR,
101
+ PARSER_ERROR.OPTION_REQUIRED_ERROR,
102
102
  { options: requireCustomComparer, requires: "valueComparer" },
103
103
  `A custom valueComparer function must be specified when using the following options: ${requireCustomComparer.join(", ")}`
104
104
  );
@@ -107,7 +107,7 @@ function checkParserOpts(opts, evaluatorChecks = false, validatorChecks = false)
107
107
  if (validatorChecks) {
108
108
  if (opts.valueValidator === void 0) {
109
109
  throw new ExpressitError(
110
- ERROR_CODES.PARSER_OPTION_REQUIRED_ERROR,
110
+ PARSER_ERROR.OPTION_REQUIRED_ERROR,
111
111
  { requires: "valueValidator" },
112
112
  `A custom valueValidator function must be specified when using the validate method.`
113
113
  );
@@ -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"}