@witchcraft/expressit 0.2.1 → 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.
- package/README.md +5 -2
- package/dist/Lexer.d.ts +3 -5
- package/dist/Lexer.d.ts.map +1 -1
- package/dist/Lexer.js +2 -0
- package/dist/Parser.d.ts +1 -1
- package/dist/Parser.d.ts.map +1 -1
- package/dist/Parser.js +3 -1
- package/dist/ast/builders/delim.d.ts +1 -1
- package/dist/ast/builders/delim.d.ts.map +1 -1
- package/dist/ast/handlers.d.ts +2 -2
- package/dist/ast/handlers.d.ts.map +1 -1
- package/dist/ast/handlers.js +3 -3
- package/dist/examples/ParserWithSqlSupport.d.ts +62 -0
- package/dist/examples/ParserWithSqlSupport.d.ts.map +1 -0
- package/dist/examples/ParserWithSqlSupport.js +269 -0
- package/dist/examples/{shortcutContextParser.d.ts → ShortcutContextParser.d.ts} +5 -5
- package/dist/examples/ShortcutContextParser.d.ts.map +1 -0
- package/dist/examples/{shortcutContextParser.js → ShortcutContextParser.js} +2 -2
- package/dist/examples/index.d.ts +2 -1
- package/dist/examples/index.d.ts.map +1 -1
- package/dist/examples/index.js +3 -1
- package/dist/internal/ExpressitError.js +2 -1
- package/dist/internal/checkParserOpts.d.ts +1 -1
- package/dist/internal/checkParserOpts.d.ts.map +1 -1
- package/dist/internal/parseParserOptions.d.ts +1 -1
- package/dist/internal/parseParserOptions.d.ts.map +1 -1
- package/dist/package.json.js +14 -147
- package/dist/types/parser.d.ts +6 -6
- package/dist/types/parser.d.ts.map +1 -1
- package/dist/utils/getCursorInfo.js +1 -1
- package/package.json +25 -23
- package/src/Lexer.ts +5 -4
- package/src/Parser.ts +9 -3
- package/src/ast/builders/delim.ts +1 -1
- package/src/ast/handlers.ts +3 -3
- package/src/examples/ParserWithSqlSupport.ts +365 -0
- package/src/examples/{shortcutContextParser.ts → ShortcutContextParser.ts} +14 -14
- package/src/examples/index.ts +2 -1
- package/src/internal/ExpressitError.ts +2 -2
- package/src/internal/checkParserOpts.ts +3 -3
- package/src/internal/parseParserOptions.ts +2 -2
- package/src/types/parser.ts +6 -6
- package/src/utils/getCursorInfo.ts +1 -1
- package/dist/examples/shortcutContextParser.d.ts.map +0 -1
- package/dist/global.d.js +0 -1
- package/dist/package.js +0 -7
- package/src/global.d.ts +0 -4
- package/src/package.js +0 -11
package/README.md
CHANGED
|
@@ -35,7 +35,10 @@ pnpm install @witchcraft/expressit
|
|
|
35
35
|
- `extractTokens`, `getCursorInfo`, `getOppositeDelimiter`, `getSurroundingErrors` - useful for adding custom syntax highlighting.
|
|
36
36
|
- `prettyAst` - pretty prints a compact version of the ast for debugging
|
|
37
37
|
- other minor utilities - `isDelimiter`, `isQuote`, etc.
|
|
38
|
-
- **Pre-Configured Parsers**
|
|
38
|
+
- **Pre-Configured Example Parsers**
|
|
39
|
+
- Shortcut Context Parser / Boolean Parser - Intended for parsing shortcut contexts in a similar way to VS Code).
|
|
40
|
+
- Experimental parser with **SQL output support** - Create an easy to read query language that can be used to generate safe SQL queries (it's flexible, but built to integrate
|
|
41
|
+
easily with drizzle).
|
|
39
42
|
- **Lots of Docs and Tests**
|
|
40
43
|
|
|
41
44
|
# Usage
|
|
@@ -79,7 +82,7 @@ const parser = new Parser({/* opts */})
|
|
|
79
82
|
// ON ENTER/SUBMIT
|
|
80
83
|
const res = parser.evaluate(ast, context)
|
|
81
84
|
```
|
|
82
|
-
Many more examples can be found in the [tests](https://github.com/witchcraftjs/expressit/blob/master/tests), and there's also some
|
|
85
|
+
Many more examples can be found in the [tests](https://github.com/witchcraftjs/expressit/blob/master/tests), and there's also some example pre-configured parsers in [src/examples](https://github.com/witchcraftjs/expressit/blob/master/src/examples/) whose usage can be seen in [./test/examples.spec.ts](https://github.com/witchcraftjs/expressit/blob/master/test/examples.spec.ts).
|
|
83
86
|
|
|
84
87
|
## [Development](./docs-src/DEVELOPMENT.md)
|
|
85
88
|
|
package/dist/Lexer.d.ts
CHANGED
|
@@ -74,9 +74,7 @@ export interface RealTokenType<T extends $T = $T, TPush extends string | undefin
|
|
|
74
74
|
}
|
|
75
75
|
export interface TokenCategoryType<TC extends $C, TTokens extends RealTokenType<$T, any>[] = RealTokenType<$T, any>[]> extends BaseTokenType<TC> {
|
|
76
76
|
isCategory: true;
|
|
77
|
-
entries: Partial<
|
|
78
|
-
[key in TTokens[number]["type"]]: TTokens[number];
|
|
79
|
-
}>;
|
|
77
|
+
entries: Partial<Record<TTokens[number]["type"], TTokens[number]>>;
|
|
80
78
|
}
|
|
81
79
|
export type TokenType<TC extends $C | $T> = TC extends $T ? RealTokenType<TC, any> : TC extends $C ? TokenCategoryType<TC> : never;
|
|
82
80
|
export interface Token<T extends $T | $C = $T | $C> {
|
|
@@ -95,8 +93,8 @@ export declare class Lexer {
|
|
|
95
93
|
branches: {
|
|
96
94
|
[key in keyof typeof MODE]?: TokenType<$T>[];
|
|
97
95
|
};
|
|
98
|
-
opts: FullParserOptions<
|
|
99
|
-
constructor(opts?: Partial<FullParserOptions<
|
|
96
|
+
opts: FullParserOptions<any>;
|
|
97
|
+
constructor(opts?: Partial<FullParserOptions<any>>);
|
|
100
98
|
calculateSymbolInfo(): SymbolInfo;
|
|
101
99
|
createTokens(): {
|
|
102
100
|
$: {
|
package/dist/Lexer.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Lexer.d.ts","sourceRoot":"","sources":["../src/Lexer.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAA;AAIzD,aAAK,IAAI;IACR,IAAI,SAAS;IACb,iBAAiB,sBAAsB;IACvC,UAAU,eAAe;IACzB,UAAU,eAAe;IACzB,YAAY,iBAAiB;IAC7B,SAAS,cAAc;IACvB,SAAS,cAAc;IACvB,YAAY,iBAAiB;IAC7B,yBAAyB,8BAA8B;IACvD,kBAAkB,uBAAuB;IACzC,kBAAkB,uBAAuB;IACzC,oBAAoB,yBAA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A;CACjB;AAED,qBAAa,KAAK;IACjB,OAAO,EAAE,UAAU,CAAA;IAEnB,CAAC,EAAE;SAAE,GAAG,IAAI,EAAE,GAAG,aAAa,CAAC,GAAG,EAAE,GAAG,CAAC;KAAE,CAAA;IAE1C,WAAW,EAAE,UAAU,CAAC,KAAK,CAAC,cAAc,CAAC,CAAC,CAAC,aAAa,CAAC,CAAA;IAE7D,QAAQ,EAAE;SAAE,GAAG,IAAI,MAAM,OAAO,IAAI,CAAC,CAAC,EAAE,SAAS,CAAC,EAAE,CAAC,EAAE;KAAE,CAAA;IAEzD,IAAI,EAAE,iBAAiB,CAAC,GAAG,CAAC,CAAA;gBAG3B,IAAI,GAAE,OAAO,CAAC,iBAAiB,CAAC,GAAG,CAAC,CAAM;IAW3C,mBAAmB,IAAI,UAAU;IAwDjC,YAAY;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IAiUZ,kBAAkB,IAAI;SAAE,GAAG,IAAI,MAAM,OAAO,IAAI,CAAC,CAAC,EAAE,SAAS,CAAC,EAAE,CAAC,EAAE;KAAE;IAgFrE,QAAQ,CAAC,KAAK,EAAE,MAAM,GAAG,KAAK,CAAC,EAAE,CAAC,EAAE;CAyCpC"}
|
package/dist/Lexer.js
CHANGED
|
@@ -233,6 +233,7 @@ class Lexer {
|
|
|
233
233
|
*/
|
|
234
234
|
(previous == null ? void 0 : previous.type) === "VALUE_NOT_SINGLE" || (previous == null ? void 0 : previous.type) === "VALUE_UNQUOTED"
|
|
235
235
|
) {
|
|
236
|
+
if (mode.startsWith(BRACKET_PREFIX)) return "BRACKET_MAIN";
|
|
236
237
|
return "MAIN";
|
|
237
238
|
}
|
|
238
239
|
switch (mode) {
|
|
@@ -276,6 +277,7 @@ class Lexer {
|
|
|
276
277
|
push: (mode, tokens) => {
|
|
277
278
|
const previous = tokens[tokens.length - 2];
|
|
278
279
|
if ((previous == null ? void 0 : previous.type) === "VALUE_NOT_BACKTICK" || (previous == null ? void 0 : previous.type) === "VALUE_UNQUOTED") {
|
|
280
|
+
if (mode.startsWith(BRACKET_PREFIX)) return "BRACKET_MAIN";
|
|
279
281
|
return "MAIN";
|
|
280
282
|
}
|
|
281
283
|
switch (mode) {
|
package/dist/Parser.d.ts
CHANGED
|
@@ -6,7 +6,7 @@ import type { FullParserOptions, ParserOptions } from "./types/parser.js";
|
|
|
6
6
|
/**
|
|
7
7
|
* Creates the main parser class which handles all functionality (evaluation, validation, etc).
|
|
8
8
|
*/
|
|
9
|
-
export declare class Parser<T
|
|
9
|
+
export declare class Parser<T = any> {
|
|
10
10
|
private evaluationOptionsChecked;
|
|
11
11
|
_checkEvaluationOptions(): void;
|
|
12
12
|
private validationOptionsChecked;
|
package/dist/Parser.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Parser.d.ts","sourceRoot":"","sources":["../src/Parser.ts"],"names":[],"mappings":"AAYA,OAAO,KAAK,MAAM,MAAM,mBAAmB,CAAA;AAS3C,OAAO,EAAE,EAAE,EAAE,EAAE,EAA4B,KAAK,KAAK,EAAE,KAAK,iBAAiB,EAAE,KAAK,SAAS,EAAE,MAAM,YAAY,CAAA;AACjH,OAAO,KAAK,EAAE,SAAS,EAAE,aAAa,EAAE,SAAS,EAAE,mBAAmB,EAAE,oBAAoB,EAAE,aAAa,EAAqB,UAAU,EAAE,YAAY,EAAG,MAAM,gBAAgB,CAAA;AACjL,OAAO,EAAE,KAAK,QAAQ,EAAW,KAAK,UAAU,EAAE,KAAK,QAAQ,EAAE,KAAK,UAAU,EAAkB,UAAU,EAAE,MAAM,kBAAkB,CAAA;AACtI,OAAO,KAAK,EAAE,iBAAiB,EAAgB,aAAa,EAA+B,MAAM,mBAAmB,CAAA;AA6CpH;;GAEG;AACH,qBAAa,MAAM,CAAC,CAAC,
|
|
1
|
+
{"version":3,"file":"Parser.d.ts","sourceRoot":"","sources":["../src/Parser.ts"],"names":[],"mappings":"AAYA,OAAO,KAAK,MAAM,MAAM,mBAAm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IACH,UAAU,CAAC,GAAG,EAAE,mBAAmB,GAAG,oBAAoB,GAAG,GAAG,CAAC,MAAM,CAAC,EAAE;IAuE1E;;OAEG;IACH,SAAS,CAAC,KAAK,SAAS,MAAM,EAAE,MAAM,EAAE,GAAG,EAAE,aAAa,GAAG,mBAAmB,CAAC,KAAK,EAAE,MAAM,CAAC,GAAG,oBAAoB,CAAC,KAAK,EAAE,MAAM,CAAC;IAkHrI;;;;;OAKG;IACH,QAAQ,CAAC,GAAG,EAAE,aAAa,EAAE,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,CAAC,QAAQ,GAAG,CAAC,CAAC,EAAE;CAqH7E"}
|
package/dist/Parser.js
CHANGED
|
@@ -698,6 +698,7 @@ class Parser {
|
|
|
698
698
|
return [{ suggestion, value: ")" }];
|
|
699
699
|
case SUGGESTION_TYPE.BRAKCETR:
|
|
700
700
|
return [{ suggestion, value: "]" }];
|
|
701
|
+
// L not needed
|
|
701
702
|
case SUGGESTION_TYPE.REGEX:
|
|
702
703
|
return [{ suggestion, value: "/" }];
|
|
703
704
|
case SUGGESTION_TYPE.REGEX_FLAGS:
|
|
@@ -1321,8 +1322,9 @@ class Parser {
|
|
|
1321
1322
|
}
|
|
1322
1323
|
if (ast.type === AST_TYPE.GROUP) {
|
|
1323
1324
|
const _prefix = ((_p = ast.prefix) == null ? void 0 : _p.type) === AST_TYPE.CONDITION && ((_q = ast.prefix) == null ? void 0 : _q.value.type) === AST_TYPE.VARIABLE ? unescape(ast.prefix.value.value.value) : void 0;
|
|
1325
|
+
const isNotToken = _prefix === void 0;
|
|
1324
1326
|
const _groupValue = ((_r = ast.prefix) == null ? void 0 : _r.type) === AST_TYPE.CONDITION ? ast.prefix.operator === void 0 : !(((_s = ast.prefix) == null ? void 0 : _s.valid) === true);
|
|
1325
|
-
const applied = applyPrefix(prefix, _prefix
|
|
1327
|
+
const applied = isNotToken ? prefix : applyPrefix(prefix, _prefix, opts.prefixApplier);
|
|
1326
1328
|
return self_.normalize(ast.expression, applied, applyBoolean(groupValue, _groupValue), operator2);
|
|
1327
1329
|
}
|
|
1328
1330
|
if (ast.type === AST_TYPE.EXPRESSION) {
|
|
@@ -5,7 +5,7 @@ import { type ExtractTokenType } from "../../types/ast.js";
|
|
|
5
5
|
export declare function delim<TLeft extends boolean | string, TRight extends boolean | string, TType extends TLeft extends string ? ExtractTokenType<TLeft> : TRight extends string ? ExtractTokenType<TRight> : undefined>(left?: TLeft, right?: TRight): {
|
|
6
6
|
left: TLeft extends string ? true : TLeft;
|
|
7
7
|
right: TRight extends string ? true : TRight;
|
|
8
|
-
} & TType extends undefined ?
|
|
8
|
+
} & TType extends undefined ? Record<string, never> : {
|
|
9
9
|
type: TType;
|
|
10
10
|
};
|
|
11
11
|
//# sourceMappingURL=delim.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"delim.d.ts","sourceRoot":"","sources":["../../../src/ast/builders/delim.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,gBAAgB,EAAc,MAAM,oBAAoB,CAAA;AAEtE;;GAEG;AAEH,wBAAgB,KAAK,CACpB,KAAK,SAAS,OAAO,GAAG,MAAM,EAC9B,MAAM,SAAS,OAAO,GAAG,MAAM,EAC/B,KAAK,SAAS,KAAK,SAAS,MAAM,GAC/B,gBAAgB,CAAC,KAAK,CAAC,GACvB,MAAM,SAAS,MAAM,GACrB,gBAAgB,CAAC,MAAM,CAAC,GACxB,SAAS,EAEZ,IAAI,GAAE,KAAsB,EAC5B,KAAK,GAAE,MAAwB,GAE/B;IACC,IAAI,EAAE,KAAK,SAAS,MAAM,GAAG,IAAI,GAAG,KAAK,CAAA;IACzC,KAAK,EAAE,MAAM,SAAS,MAAM,GAAG,IAAI,GAAG,MAAM,CAAA;CAC5C,GAAG,KAAK,SAAS,SAAS,GAAG,
|
|
1
|
+
{"version":3,"file":"delim.d.ts","sourceRoot":"","sources":["../../../src/ast/builders/delim.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,gBAAgB,EAAc,MAAM,oBAAoB,CAAA;AAEtE;;GAEG;AAEH,wBAAgB,KAAK,CACpB,KAAK,SAAS,OAAO,GAAG,MAAM,EAC9B,MAAM,SAAS,OAAO,GAAG,MAAM,EAC/B,KAAK,SAAS,KAAK,SAAS,MAAM,GAC/B,gBAAgB,CAAC,KAAK,CAAC,GACvB,MAAM,SAAS,MAAM,GACrB,gBAAgB,CAAC,MAAM,CAAC,GACxB,SAAS,EAEZ,IAAI,GAAE,KAAsB,EAC5B,KAAK,GAAE,MAAwB,GAE/B;IACC,IAAI,EAAE,KAAK,SAAS,MAAM,GAAG,IAAI,GAAG,KAAK,CAAA;IACzC,KAAK,EAAE,MAAM,SAAS,MAAM,GAAG,IAAI,GAAG,MAAM,CAAA;CAC5C,GAAG,KAAK,SAAS,SAAS,GAAG,MAAM,CAAC,MAAM,EAAC,KAAK,CAAC,GAAG;IAAE,IAAI,EAAE,KAAK,CAAA;CAAE,CAepE"}
|
package/dist/ast/handlers.d.ts
CHANGED
|
@@ -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: <
|
|
6
|
-
sep: <
|
|
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
|
|
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;YARsC,IAAI,SAAS,MAAM,GAAG,SAAS,oBAAqB,QAAQ;aAA5D,IAAI,SAAS,MAAM,GAAG,SAAS,oBAAqB,QAAQ;UAA5D,IAAI,SAAS,MAAM,GAAG,SAAS,oBAAqB,QAAQ;CAYnH,CAAA;AAED,wHAAwH;AACxH,eAAO,MAAM,SAAS;oBAnBb,MAAM,GAAG,SAAS,OAAO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AG,IAAI,CAAA;CAC/C,EACN,KAAK,CAAC,EAAE,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"}
|
package/dist/ast/handlers.js
CHANGED
|
@@ -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
|
|
84
|
-
node.propertyOperator
|
|
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
|
|
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 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,CAAC,KAAK,EAAE,GAAG,EAAE,cAAc,EAAE,GAAG,KAAK,GAAG,GAAG,GAAG,EAAE,CAAA;IACjE,OAAO,CAAC,EAAE,OAAO,CAAA;IACjB,kMAAkM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AAoB;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
|
-
|
|
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<
|
|
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=
|
|
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,
|
|
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]
|
|
112
|
+
if (context[key]) {
|
|
113
113
|
this.regexablekeys.push(prev ? `${prev}.${key}` : key);
|
|
114
114
|
}
|
|
115
115
|
} else {
|
package/dist/examples/index.d.ts
CHANGED
|
@@ -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"}
|
package/dist/examples/index.js
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
import { ShortcutContextParser } from "./
|
|
1
|
+
import { ShortcutContextParser } from "./ShortcutContextParser.js";
|
|
2
|
+
import { ParserWithSqlSupport } from "./ParserWithSqlSupport.js";
|
|
2
3
|
export {
|
|
4
|
+
ParserWithSqlSupport,
|
|
3
5
|
ShortcutContextParser
|
|
4
6
|
};
|
|
@@ -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
|
|
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
|
|
3
|
+
export declare function checkParserOpts<T>(opts: FullParserOptions<T>, evaluatorChecks?: boolean, validatorChecks?: boolean): void;
|
|
4
4
|
//# sourceMappingURL=checkParserOpts.d.ts.map
|