@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
|
@@ -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,
|
|
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"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import type { FullParserOptions, ParserOptions } from "../types/parser.js";
|
|
2
2
|
/** @internal */
|
|
3
|
-
export declare function parseParserOptions<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,
|
|
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"}
|
package/dist/package.json.js
CHANGED
|
@@ -1,151 +1,25 @@
|
|
|
1
1
|
const name = "@witchcraft/expressit";
|
|
2
2
|
const description = "A blazing fast, customizable, error-tolerant expression parser that creates safe to eval expressions + a few other goodies like autocomplete.";
|
|
3
|
-
const version = "0.2.
|
|
3
|
+
const version = "0.2.2";
|
|
4
4
|
const types = "./dist/index.d.ts";
|
|
5
5
|
const type = "module";
|
|
6
6
|
const module = "./dist/index.js";
|
|
7
7
|
const sideEffects = false;
|
|
8
|
-
const exports = {
|
|
9
|
-
".": {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
},
|
|
13
|
-
"./ast": {
|
|
14
|
-
types: "./dist/ast/index.d.ts",
|
|
15
|
-
"import": "./dist/ast/index.js"
|
|
16
|
-
},
|
|
17
|
-
"./ast/*": {
|
|
18
|
-
types: "./dist/ast/*",
|
|
19
|
-
"import": "./dist/ast/*"
|
|
20
|
-
},
|
|
21
|
-
"./internal": {
|
|
22
|
-
types: "./dist/internal/index.d.ts",
|
|
23
|
-
"import": "./dist/internal/index.js"
|
|
24
|
-
},
|
|
25
|
-
"./internal/*": {
|
|
26
|
-
types: "./dist/internal/*",
|
|
27
|
-
"import": "./dist/internal/*"
|
|
28
|
-
},
|
|
29
|
-
"./methods": {
|
|
30
|
-
types: "./dist/methods/index.d.ts",
|
|
31
|
-
"import": "./dist/methods/index.js"
|
|
32
|
-
},
|
|
33
|
-
"./methods/*": {
|
|
34
|
-
types: "./dist/methods/*",
|
|
35
|
-
"import": "./dist/methods/*"
|
|
36
|
-
},
|
|
37
|
-
"./utils": {
|
|
38
|
-
types: "./dist/utils/index.d.ts",
|
|
39
|
-
"import": "./dist/utils/index.js"
|
|
40
|
-
},
|
|
41
|
-
"./utils/*": {
|
|
42
|
-
types: "./dist/utils/*",
|
|
43
|
-
"import": "./dist/utils/*"
|
|
44
|
-
},
|
|
45
|
-
"./examples": {
|
|
46
|
-
types: "./dist/examples/index.d.ts",
|
|
47
|
-
"import": "./dist/examples/index.js"
|
|
48
|
-
},
|
|
49
|
-
"./examples/*": {
|
|
50
|
-
types: "./dist/examples/*",
|
|
51
|
-
"import": "./dist/examples/*"
|
|
52
|
-
},
|
|
53
|
-
"./*": {
|
|
54
|
-
types: "./dist/types/*",
|
|
55
|
-
"import": "./dist/types/*"
|
|
56
|
-
}
|
|
57
|
-
};
|
|
58
|
-
const scripts = {
|
|
59
|
-
debug: "ts-node -r tsconfig-paths/register -T --esm",
|
|
60
|
-
build: "vite build",
|
|
61
|
-
"build:dev": "vite build --mode development",
|
|
62
|
-
"build:watch": "vite build --watch --mode production",
|
|
63
|
-
"build:types": "tsc --emitDeclarationOnly -p tsconfig.types.json && npm run build:types:fix",
|
|
64
|
-
"build:types:fix": "tsc-alias -p tsconfig.types.json --debug",
|
|
65
|
-
"lint:eslint": 'eslint "{src,tests,bin}/**/*.{cjs,js,ts}" "*.{cjs,js,ts}" --max-warnings=1 --report-unused-disable-directives',
|
|
66
|
-
"lint:types": "tsc --noEmit --pretty",
|
|
67
|
-
"lint:commits": "commitlint --from $(git rev-list --max-parents=0 HEAD) --to HEAD --verbose",
|
|
68
|
-
"lint:imports": "madge --circular --extensions ts ./src",
|
|
69
|
-
lint: "npm run lint:types && npm run lint:eslint",
|
|
70
|
-
coverage: "vitest --exclude '.direnv/**/*' --coverage",
|
|
71
|
-
"coverage:dev": "vitest --exclude '.direnv/**/*' --watch --coverage",
|
|
72
|
-
test: "npm run lint:types && vitest run --exclude '.direnv/**/*'",
|
|
73
|
-
"test:watch": "vitest --watch --exclude '.direnv/**/*'",
|
|
74
|
-
"test:inspect-errors": "cross-env INSPECT_ERRORS=true npm run test",
|
|
75
|
-
doc: "typedoc --options typedoc.config.cjs",
|
|
76
|
-
"doc:watch": 'onchange -i "src/**/*.ts" "typedoc.config.cjs" -- npm run doc',
|
|
77
|
-
"doc:serve": "http-server docs --port=5001",
|
|
78
|
-
"doc:dev": 'concurrently "npm run doc:watch" "npm run doc:serve"',
|
|
79
|
-
"doc:check-invalid": "typedoc --options typedoc.config.cjs --listInvalidSymbolLinks",
|
|
80
|
-
"demo:dev": 'cd demo && concurrently "vite" "npm run build:watch"',
|
|
81
|
-
"demo:build": "cd demo && npm run build",
|
|
82
|
-
"actions:debug": "act -r -v -j build",
|
|
83
|
-
"gen:exports": "indexit update -o '${path}.js' -i **/*.d.ts",
|
|
84
|
-
prepare: "husky && npm run build"
|
|
85
|
-
};
|
|
86
|
-
const dependencies = {
|
|
87
|
-
"@alanscodelog/utils": "^4.0.0"
|
|
88
|
-
};
|
|
89
|
-
const devDependencies = {
|
|
90
|
-
"@alanscodelog/commitlint-config": "^3.0.1",
|
|
91
|
-
"@alanscodelog/eslint-config": "5.0.0-beta.3",
|
|
92
|
-
"@alanscodelog/semantic-release-config": "^4.1.2",
|
|
93
|
-
"@alanscodelog/tsconfigs": "^4.0.1",
|
|
94
|
-
"@commitlint/cli": "^19.3.0",
|
|
95
|
-
"@types/node": "^20.4.1",
|
|
96
|
-
"@vitest/coverage-v8": "^1.6.0",
|
|
97
|
-
concurrently: "^8.2.0",
|
|
98
|
-
"cross-env": "^7.0.3",
|
|
99
|
-
"fast-glob": "^3.3.1",
|
|
100
|
-
"http-server": "^14.1.1",
|
|
101
|
-
husky: "^9.0.11",
|
|
102
|
-
indexit: "2.1.0-beta.3",
|
|
103
|
-
madge: "^7.0.0",
|
|
104
|
-
onchange: "^7.1.0",
|
|
105
|
-
"semantic-release": "^23.1.1",
|
|
106
|
-
"ts-node": "^10.9.1",
|
|
107
|
-
"tsc-alias": "^1.8.7",
|
|
108
|
-
typedoc: "0.26.0-beta.1",
|
|
109
|
-
typescript: "~5.4.5",
|
|
110
|
-
vite: "^5.2.11",
|
|
111
|
-
"vite-plugin-externalize-deps": "^0.8.0",
|
|
112
|
-
"vite-tsconfig-paths": "^4.2.0",
|
|
113
|
-
vitest: "^1.6.0"
|
|
114
|
-
};
|
|
8
|
+
const exports = { ".": { "types": "./dist/index.d.ts", "import": "./dist/index.js" }, "./ast": { "types": "./dist/ast/index.d.ts", "import": "./dist/ast/index.js" }, "./ast/*": { "types": "./dist/ast/*", "import": "./dist/ast/*" }, "./internal": { "types": "./dist/internal/index.d.ts", "import": "./dist/internal/index.js" }, "./internal/*": { "types": "./dist/internal/*", "import": "./dist/internal/*" }, "./methods": { "types": "./dist/methods/index.d.ts", "import": "./dist/methods/index.js" }, "./methods/*": { "types": "./dist/methods/*", "import": "./dist/methods/*" }, "./utils": { "types": "./dist/utils/index.d.ts", "import": "./dist/utils/index.js" }, "./utils/*": { "types": "./dist/utils/*", "import": "./dist/utils/*" }, "./examples": { "types": "./dist/examples/index.d.ts", "import": "./dist/examples/index.js" }, "./examples/*": { "types": "./dist/examples/*", "import": "./dist/examples/*" }, "./*": { "types": "./dist/types/*", "import": "./dist/types/*" } };
|
|
9
|
+
const scripts = { "debug": "ts-node -r tsconfig-paths/register -T --esm", "build": "vite build", "build:dev": "vite build --mode development", "build:watch": "vite build --watch --mode production", "build:types": "tsc --emitDeclarationOnly -p tsconfig.types.json", "lint:eslint": 'eslint "{src,tests,bin}/**/*.{cjs,js,ts}" "*.{cjs,js,ts}" --max-warnings=1 --report-unused-disable-directives', "lint:types": "tsc --noEmit --pretty", "lint:commits": "commitlint --from $(git rev-list --max-parents=0 HEAD) --to HEAD --verbose", "lint:imports": "madge --circular --extensions ts ./src", "lint": "npm run lint:types && npm run lint:eslint", "coverage": "vitest --exclude '.direnv/**/*' --coverage", "coverage:dev": "vitest --exclude '.direnv/**/*' --watch --coverage", "test:db": "rm -rf ./tests/db/migrations && pnpm drizzle-kit generate --config ./tests/db/drizzle.config.ts", "test": "pnpm test:db && npm run lint:types && vitest run --exclude '.direnv/**/*'", "test:watch": "pnpm test:db && vitest --watch --exclude '.direnv/**/*'", "test:inspect-errors": "cross-env INSPECT_ERRORS=true npm run test", "doc": "typedoc --options typedoc.config.js", "doc:watch": 'onchange -i "src/**/*.ts" "typedoc.config.cjs" -- npm run doc', "doc:serve": "http-server docs --port=5001", "doc:dev": 'concurrently "npm run doc:watch" "npm run doc:serve"', "doc:check-invalid": "typedoc --options typedoc.config.cjs --listInvalidSymbolLinks", "demo:dev": 'cd demo && concurrently "vite" "npm run build:watch"', "demo:build": "cd demo && npm run build", "actions:debug": "act -r -v -j release", "gen:exports": "indexit update -o '${path}.js' -i **/*.d.ts", "prepare": "husky && npm run build" };
|
|
10
|
+
const dependencies = { "@alanscodelog/utils": "^4.0.0" };
|
|
11
|
+
const devDependencies = { "@alanscodelog/commitlint-config": "^3.0.1", "@alanscodelog/eslint-config": "5.0.3", "@alanscodelog/semantic-release-config": "^5.0.3", "@alanscodelog/tsconfigs": "^5.0.1", "@commitlint/cli": "^19.6.1", "@electric-sql/pglite": "^0.2.12", "@types/node": "^22.10.2", "@vitest/coverage-v8": "^2.1.8", "concurrently": "^9.1.0", "cross-env": "^7.0.3", "drizzle-kit": "^0.30.1", "drizzle-orm": "^0.38.2", "fast-glob": "^3.3.1", "http-server": "^14.1.1", "husky": "^9.1.7", "indexit": "2.1.0-beta.3", "madge": "^8.0.0", "onchange": "^7.1.0", "semantic-release": "^24.2.0", "ts-node": "^10.9.1", "typedoc": "0.27.5", "typescript": "~5.7.2", "vite": "^6.0.2", "vite-plugin-externalize-deps": "^0.8.0", "vite-tsconfig-paths": "^5.1.4", "vitest": "^2.1.8" };
|
|
115
12
|
const author = "Alan <alanscodelog@gmail.com>";
|
|
116
13
|
const repository = "https://github.com/witchcraftjs/expressit";
|
|
117
|
-
const keywords = [
|
|
118
|
-
"boolean",
|
|
119
|
-
"parser",
|
|
120
|
-
"query",
|
|
121
|
-
"evaluator",
|
|
122
|
-
"expression",
|
|
123
|
-
"condition",
|
|
124
|
-
"search"
|
|
125
|
-
];
|
|
14
|
+
const keywords = ["boolean", "parser", "query", "evaluator", "expression", "condition", "search"];
|
|
126
15
|
const license = "MIT";
|
|
127
|
-
const files = [
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
];
|
|
131
|
-
const release = {
|
|
132
|
-
"extends": [
|
|
133
|
-
"@alanscodelog/semantic-release-config"
|
|
134
|
-
]
|
|
135
|
-
};
|
|
136
|
-
const commitlint = {
|
|
137
|
-
"extends": [
|
|
138
|
-
"@alanscodelog"
|
|
139
|
-
]
|
|
140
|
-
};
|
|
16
|
+
const files = ["src", "dist"];
|
|
17
|
+
const release = { "extends": ["@alanscodelog/semantic-release-config"] };
|
|
18
|
+
const commitlint = { "extends": ["@alanscodelog"] };
|
|
141
19
|
const browserslist = "defaults and supports es6-module,maintained node versions";
|
|
142
|
-
const engines = {
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
const publishConfig = {
|
|
146
|
-
access: "public"
|
|
147
|
-
};
|
|
148
|
-
const pkg = {
|
|
20
|
+
const engines = { "node": ">=18.0.0" };
|
|
21
|
+
const publishConfig = { "access": "public" };
|
|
22
|
+
const packageJson = {
|
|
149
23
|
name,
|
|
150
24
|
description,
|
|
151
25
|
version,
|
|
@@ -166,21 +40,14 @@ const pkg = {
|
|
|
166
40
|
commitlint,
|
|
167
41
|
browserslist,
|
|
168
42
|
engines,
|
|
169
|
-
"@comments": {
|
|
170
|
-
scripts: {
|
|
171
|
-
test: "Runs `lint:types` before (so that flags can be passed to the test command) so that we can test type assertions. See expect_type function in @alanscodelog/utils.",
|
|
172
|
-
"lint:commits": "Lints all unpushed commits in the active branch.",
|
|
173
|
-
prepare: "Needed so that if we pull the package from git it will get built and installed properly.",
|
|
174
|
-
"actions:debug": "For debugging github build action locally with nektos/act. Requires act and docker. Note: Cache will never work locally because of https://github.com/nektos/act/issues/285"
|
|
175
|
-
}
|
|
176
|
-
},
|
|
43
|
+
"@comments": { "scripts": { "test": "Runs `lint:types` before (so that flags can be passed to the test command) so that we can test type assertions. See expect_type function in @alanscodelog/utils.", "lint:commits": "Lints all unpushed commits in the active branch.", "prepare": "Needed so that if we pull the package from git it will get built and installed properly.", "actions:debug": "For debugging github build action locally with nektos/act. Requires act and docker. Note: Cache will never work locally because of https://github.com/nektos/act/issues/285" } },
|
|
177
44
|
publishConfig
|
|
178
45
|
};
|
|
179
46
|
export {
|
|
180
47
|
author,
|
|
181
48
|
browserslist,
|
|
182
49
|
commitlint,
|
|
183
|
-
|
|
50
|
+
packageJson as default,
|
|
184
51
|
dependencies,
|
|
185
52
|
description,
|
|
186
53
|
devDependencies,
|
package/dist/types/parser.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import type { DeepRequired, MakeRequired } from "@alanscodelog/utils/types";
|
|
2
2
|
import type { ArrayNode, ConditionNode, NormalizedCondition, Position, TOKEN_TYPE, ValidToken, VariableNode } from "./ast.js";
|
|
3
|
-
export type FullParserOptions<T
|
|
3
|
+
export type FullParserOptions<T = any> = MakeRequired<ParserOptions<T>, Exclude<keyof ParserOptions<T>, "prefixableStrings" | "expandedPropertySeparator" | "customPropertyOperators" | "keywords">> & {
|
|
4
4
|
keywords: DeepRequired<KeywordOptions>;
|
|
5
5
|
};
|
|
6
|
-
export type ParserOptions<T
|
|
6
|
+
export type ParserOptions<T = any> = {
|
|
7
7
|
/**
|
|
8
8
|
* Allows any conditions (i.e. a variable or negated variable) to precede groups and append themselves to all variables inside them. Regular use of groups for changing precedence (e.g. `(a || b) && c` ) or negating expressions `!(a || b)` is still supported even if `prefixableGroups` is false.
|
|
9
9
|
*
|
|
@@ -101,7 +101,7 @@ export type ParserOptions<T extends {} = {}> = {
|
|
|
101
101
|
/**
|
|
102
102
|
* Enables regex strings as values. The value is treated as if it was quoted by forward slashes. Any repetition of lowercase characters (even if there are multiple) attached to the end are assumed to be flags and added as a single token to the value's `quotes.mode` property.
|
|
103
103
|
*
|
|
104
|
-
* Can be passed a custom function to determine when to use the regex value or not (it is converted to a regular value). The function is passed the property, the operator, and whether it's an expanded operator. If
|
|
104
|
+
* Can be passed a custom function to determine when to use the regex value or not (it is converted to a regular value). The function is passed the property, the operator, and whether it's an expanded operator. If there is an error token for the property or operator, an empty string is passed.
|
|
105
105
|
*
|
|
106
106
|
* ```ts
|
|
107
107
|
* // allow anything (`prop=/val/`, `prop:op:/val`, `prop=(/val/)`, `prop:op(/val/)`) but the value alone (`/regex/`)
|
|
@@ -257,7 +257,7 @@ export type ParserOptions<T extends {} = {}> = {
|
|
|
257
257
|
* ```ts
|
|
258
258
|
* type Operators = "contains"
|
|
259
259
|
* function valueComparer(condition: Omit<Condition, "negate">, contextValue: any, context: any): boolean {
|
|
260
|
-
* switch (operator as Operators) {
|
|
260
|
+
* switch (condition.operator as Operators) {
|
|
261
261
|
* case "contains": return (contextValue as string[]).includes(condition.value as string)
|
|
262
262
|
* // ...
|
|
263
263
|
* }
|
|
@@ -292,13 +292,13 @@ export type ParserOptions<T extends {} = {}> = {
|
|
|
292
292
|
* if (prefix) {
|
|
293
293
|
* const val = value as string // it's always a string if prefixed
|
|
294
294
|
* switch (prefix as RawPrefixes) {
|
|
295
|
-
* case "num": finalValue = parseInt(val,
|
|
295
|
+
* case "num": finalValue = parseInt(val, 10); break
|
|
296
296
|
* // ...
|
|
297
297
|
* }
|
|
298
298
|
* }
|
|
299
299
|
* // another way to allow special unquoted value types is something like this:
|
|
300
300
|
* if (typeof value === "string" && !isQuoted) {
|
|
301
|
-
* const asNum = parseInt(value,
|
|
301
|
+
* const asNum = parseInt(value, 10)
|
|
302
302
|
* if (!isNaN(asNum)) finalValue = asNum
|
|
303
303
|
* if (["true","false"].includes(value)) {
|
|
304
304
|
* finalValue = value === "true" ? true : false
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parser.d.ts","sourceRoot":"","sources":["../../src/types/parser.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAA;AAE3E,OAAO,KAAK,EAAE,SAAS,EAAE,aAAa,EAAE,mBAAmB,EAAE,QAAQ,EAAE,UAAU,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,UAAU,CAAA;AAI7H,MAAM,MAAM,iBAAiB,CAAC,CAAC,
|
|
1
|
+
{"version":3,"file":"parser.d.ts","sourceRoot":"","sources":["../../src/types/parser.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAA;AAE3E,OAAO,KAAK,EAAE,SAAS,EAAE,aAAa,EAAE,mBAAmB,EAAE,QAAQ,EAAE,UAAU,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,UAAU,CAAA;AAI7H,MAAM,MAAM,iBAAiB,CAAC,CAAC,GAAG,GAAG,IAAI,YAAY,CACpD,aAAa,CAAC,CAAC,CAAC,EAEhB,OAAO,CAAC,MAAM,aAAa,CAAC,CAAC,CAAC,EAC3B,mBAAmB,GACnB,2BAA2B,GAC3B,yBAAyB,GACzB,UAAU,CACZ,CACD,GACC;IAED,QAAQ,EAAE,YAAY,CAAC,cAAc,CAAC,CAAA;CACtC,CAAA;AACD,MAAM,MAAM,aAAa,CAAC,CAAC,GAAG,GAAG,IAAI;IACpC;;;;;;;;;;;;;;;OAeG;IACH,gBAAgB,CAAC,EAAE,OAAO,CAAA;IAC1B;;;;;;OAMG;IACH,iBAAiB,CAAC,EAAE,MAAM,EAAE,CAAA;IAC5B;;;;;;;;;;;;;;;;;;OAkBG;IACH,yBAAyB,CAAC,EAAE,MAAM,CAAA;IAClC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA6BG;IACH,uBAAuB,CAAC,EAAE,MAAM,EAAE,CAAA;IAClC;;;;;;;;;;;;;;;;OAgBG;IACH,wBAAwB,CAAC,E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AAG,CAAC;IAAC,QAAQ,EAAE,GAAG,CAAC;IAAC,MAAM,EAAE,OAAO,CAAA;CAAE,CAAA;AACvG,MAAM,MAAM,cAAc,CAAC,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,IAAI,CAAC,YAAY,EAAE,GAAG,GAAG,SAAS,EAAE,KAAK,EAAE,eAAe,EAAE,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,KAAK,CAAC,QAAQ,GAAG,CAAC,CAAC,EAAE,GAAG,SAAS,GAAG,IAAI,CAAA;AAEnL,MAAM,MAAM,SAAS,GAAG,CAAC,GAAG,EAAE,MAAM,KAAK,MAAM,EAAE,CAAA;AACjD,MAAM,MAAM,aAAa,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,KAAK,MAAM,CAAA;AAExE,MAAM,MAAM,YAAY,GAAG;IAC1B,kDAAkD;IAClD,QAAQ,EAAE,OAAO,CAAA;IACjB,KAAK,EAAE,MAAM,CAAA;CACb,CAAA;AACD,MAAM,MAAM,cAAc,GAAG;IAC5B,EAAE,CAAC,EAAE,YAAY,EAAE,CAAA;IACnB,GAAG,CAAC,EAAE,YAAY,EAAE,CAAA;IACpB,GAAG,CAAC,EAAE,YAAY,EAAE,CAAA;CACpB,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@witchcraft/expressit",
|
|
3
3
|
"description": "A blazing fast, customizable, error-tolerant expression parser that creates safe to eval expressions + a few other goodies like autocomplete.",
|
|
4
|
-
"version": "0.2.
|
|
4
|
+
"version": "0.2.2",
|
|
5
5
|
"types": "./dist/index.d.ts",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"module": "./dist/index.js",
|
|
@@ -61,8 +61,7 @@
|
|
|
61
61
|
"build": "vite build",
|
|
62
62
|
"build:dev": "vite build --mode development",
|
|
63
63
|
"build:watch": "vite build --watch --mode production",
|
|
64
|
-
"build:types": "tsc --emitDeclarationOnly -p tsconfig.types.json
|
|
65
|
-
"build:types:fix": "tsc-alias -p tsconfig.types.json --debug",
|
|
64
|
+
"build:types": "tsc --emitDeclarationOnly -p tsconfig.types.json",
|
|
66
65
|
"lint:eslint": "eslint \"{src,tests,bin}/**/*.{cjs,js,ts}\" \"*.{cjs,js,ts}\" --max-warnings=1 --report-unused-disable-directives",
|
|
67
66
|
"lint:types": "tsc --noEmit --pretty",
|
|
68
67
|
"lint:commits": "commitlint --from $(git rev-list --max-parents=0 HEAD) --to HEAD --verbose",
|
|
@@ -70,17 +69,18 @@
|
|
|
70
69
|
"lint": "npm run lint:types && npm run lint:eslint",
|
|
71
70
|
"coverage": "vitest --exclude '.direnv/**/*' --coverage",
|
|
72
71
|
"coverage:dev": "vitest --exclude '.direnv/**/*' --watch --coverage",
|
|
73
|
-
"test": "
|
|
74
|
-
"test:
|
|
72
|
+
"test:db": "rm -rf ./tests/db/migrations && pnpm drizzle-kit generate --config ./tests/db/drizzle.config.ts",
|
|
73
|
+
"test": "pnpm test:db && npm run lint:types && vitest run --exclude '.direnv/**/*'",
|
|
74
|
+
"test:watch": "pnpm test:db && vitest --watch --exclude '.direnv/**/*'",
|
|
75
75
|
"test:inspect-errors": "cross-env INSPECT_ERRORS=true npm run test",
|
|
76
|
-
"doc": "typedoc --options typedoc.config.
|
|
76
|
+
"doc": "typedoc --options typedoc.config.js",
|
|
77
77
|
"doc:watch": "onchange -i \"src/**/*.ts\" \"typedoc.config.cjs\" -- npm run doc",
|
|
78
78
|
"doc:serve": "http-server docs --port=5001",
|
|
79
79
|
"doc:dev": "concurrently \"npm run doc:watch\" \"npm run doc:serve\"",
|
|
80
80
|
"doc:check-invalid": "typedoc --options typedoc.config.cjs --listInvalidSymbolLinks",
|
|
81
81
|
"demo:dev": "cd demo && concurrently \"vite\" \"npm run build:watch\"",
|
|
82
82
|
"demo:build": "cd demo && npm run build",
|
|
83
|
-
"actions:debug": "act -r -v -j
|
|
83
|
+
"actions:debug": "act -r -v -j release",
|
|
84
84
|
"gen:exports": "indexit update -o '${path}.js' -i **/*.d.ts",
|
|
85
85
|
"prepare": "husky && npm run build"
|
|
86
86
|
},
|
|
@@ -89,29 +89,31 @@
|
|
|
89
89
|
},
|
|
90
90
|
"devDependencies": {
|
|
91
91
|
"@alanscodelog/commitlint-config": "^3.0.1",
|
|
92
|
-
"@alanscodelog/eslint-config": "5.0.
|
|
93
|
-
"@alanscodelog/semantic-release-config": "^
|
|
94
|
-
"@alanscodelog/tsconfigs": "^
|
|
95
|
-
"@commitlint/cli": "^19.
|
|
96
|
-
"@
|
|
97
|
-
"@
|
|
98
|
-
"
|
|
92
|
+
"@alanscodelog/eslint-config": "5.0.3",
|
|
93
|
+
"@alanscodelog/semantic-release-config": "^5.0.3",
|
|
94
|
+
"@alanscodelog/tsconfigs": "^5.0.1",
|
|
95
|
+
"@commitlint/cli": "^19.6.1",
|
|
96
|
+
"@electric-sql/pglite": "^0.2.12",
|
|
97
|
+
"@types/node": "^22.10.2",
|
|
98
|
+
"@vitest/coverage-v8": "^2.1.8",
|
|
99
|
+
"concurrently": "^9.1.0",
|
|
99
100
|
"cross-env": "^7.0.3",
|
|
101
|
+
"drizzle-kit": "^0.30.1",
|
|
102
|
+
"drizzle-orm": "^0.38.2",
|
|
100
103
|
"fast-glob": "^3.3.1",
|
|
101
104
|
"http-server": "^14.1.1",
|
|
102
|
-
"husky": "^9.
|
|
105
|
+
"husky": "^9.1.7",
|
|
103
106
|
"indexit": "2.1.0-beta.3",
|
|
104
|
-
"madge": "^
|
|
107
|
+
"madge": "^8.0.0",
|
|
105
108
|
"onchange": "^7.1.0",
|
|
106
|
-
"semantic-release": "^
|
|
109
|
+
"semantic-release": "^24.2.0",
|
|
107
110
|
"ts-node": "^10.9.1",
|
|
108
|
-
"
|
|
109
|
-
"
|
|
110
|
-
"
|
|
111
|
-
"vite": "^5.2.11",
|
|
111
|
+
"typedoc": "0.27.5",
|
|
112
|
+
"typescript": "~5.7.2",
|
|
113
|
+
"vite": "^6.0.2",
|
|
112
114
|
"vite-plugin-externalize-deps": "^0.8.0",
|
|
113
|
-
"vite-tsconfig-paths": "^
|
|
114
|
-
"vitest": "^1.
|
|
115
|
+
"vite-tsconfig-paths": "^5.1.4",
|
|
116
|
+
"vitest": "^2.1.8"
|
|
115
117
|
},
|
|
116
118
|
"author": "Alan <alanscodelog@gmail.com>",
|
|
117
119
|
"repository": "https://github.com/witchcraftjs/expressit",
|
package/src/Lexer.ts
CHANGED
|
@@ -100,7 +100,7 @@ export interface TokenCategoryType<
|
|
|
100
100
|
TTokens extends RealTokenType<$T, any>[] = RealTokenType<$T, any>[],
|
|
101
101
|
> extends BaseTokenType<TC> {
|
|
102
102
|
isCategory: true
|
|
103
|
-
entries: Partial<
|
|
103
|
+
entries: Partial<Record<TTokens[number]["type"], TTokens[number]>>
|
|
104
104
|
// entries: Partial<Record<TTokens[number]["type"], TTokens[number]>>
|
|
105
105
|
}
|
|
106
106
|
|
|
@@ -181,10 +181,10 @@ export class Lexer {
|
|
|
181
181
|
|
|
182
182
|
branches: {[key in keyof typeof MODE]?: TokenType<$T>[] }
|
|
183
183
|
|
|
184
|
-
opts: FullParserOptions<
|
|
184
|
+
opts: FullParserOptions<any>
|
|
185
185
|
|
|
186
186
|
constructor(
|
|
187
|
-
opts: Partial<FullParserOptions<
|
|
187
|
+
opts: Partial<FullParserOptions<any>> = {},
|
|
188
188
|
) {
|
|
189
189
|
this.opts = parseParserOptions(opts)
|
|
190
190
|
checkParserOpts(this.opts)
|
|
@@ -332,6 +332,7 @@ export class Lexer {
|
|
|
332
332
|
previous?.type === $T.VALUE_NOT_SINGLE
|
|
333
333
|
/* Similarly, if the previous token was an unquoted value, we have a quote error.*/
|
|
334
334
|
|| previous?.type === $T.VALUE_UNQUOTED) {
|
|
335
|
+
if (mode.startsWith(BRACKET_PREFIX)) return MODE.BRACKET_MAIN
|
|
335
336
|
return MODE.MAIN
|
|
336
337
|
}
|
|
337
338
|
switch (mode) {
|
|
@@ -369,6 +370,7 @@ export class Lexer {
|
|
|
369
370
|
push: (mode, tokens) => {
|
|
370
371
|
const previous = tokens[tokens.length - 2]
|
|
371
372
|
if (previous?.type === $T.VALUE_NOT_BACKTICK || previous?.type === $T.VALUE_UNQUOTED) {
|
|
373
|
+
if (mode.startsWith(BRACKET_PREFIX)) return MODE.BRACKET_MAIN
|
|
372
374
|
return MODE.MAIN
|
|
373
375
|
}
|
|
374
376
|
switch (mode) {
|
|
@@ -663,7 +665,6 @@ export class Lexer {
|
|
|
663
665
|
if (match) {
|
|
664
666
|
let matchLength = match === true ? 1 : (match as string).length
|
|
665
667
|
let type = t.type
|
|
666
|
-
|
|
667
668
|
if (t.longerAlt) {
|
|
668
669
|
const longerMatch = this.$[t.longerAlt].matches(c, input, index, mode)
|
|
669
670
|
const longerMatchLength = longerMatch === true ? 1 : (longerMatch as string).length
|
package/src/Parser.ts
CHANGED
|
@@ -70,7 +70,7 @@ const tokenVariable = [TOKEN_TYPE.BACKTICK, TOKEN_TYPE.DOUBLEQUOTE, TOKEN_TYPE.S
|
|
|
70
70
|
/**
|
|
71
71
|
* Creates the main parser class which handles all functionality (evaluation, validation, etc).
|
|
72
72
|
*/
|
|
73
|
-
export class Parser<T
|
|
73
|
+
export class Parser<T = any> {
|
|
74
74
|
// needed for evaluate and validate so they are only checked on demand
|
|
75
75
|
private evaluationOptionsChecked: boolean = false
|
|
76
76
|
|
|
@@ -1803,6 +1803,7 @@ export class Parser<T extends {} = {}> {
|
|
|
1803
1803
|
if (prefix !== undefined && !isNested) {
|
|
1804
1804
|
name = name ? applyPrefix(prefix, name, opts.prefixApplier) : prefix
|
|
1805
1805
|
}
|
|
1806
|
+
|
|
1806
1807
|
let value: any
|
|
1807
1808
|
if (isNested) {
|
|
1808
1809
|
value = name ?? true
|
|
@@ -1855,16 +1856,21 @@ export class Parser<T extends {} = {}> {
|
|
|
1855
1856
|
return self_.normalize(ast.value, name, boolValue, operator) as any
|
|
1856
1857
|
}
|
|
1857
1858
|
}
|
|
1858
|
-
|
|
1859
1859
|
if (ast.type === AST_TYPE.GROUP) {
|
|
1860
1860
|
const _prefix = ast.prefix?.type === AST_TYPE.CONDITION && ast.prefix?.value.type === AST_TYPE.VARIABLE
|
|
1861
1861
|
? unescape(ast.prefix.value.value.value!)
|
|
1862
1862
|
: undefined // we do not want to apply not tokens
|
|
1863
|
+
const isNotToken = _prefix === undefined
|
|
1864
|
+
|
|
1863
1865
|
const _groupValue = ast.prefix?.type === AST_TYPE.CONDITION
|
|
1864
1866
|
? ast.prefix.operator === undefined
|
|
1865
1867
|
: !(ast.prefix?.valid === true)
|
|
1866
1868
|
|
|
1867
|
-
|
|
1869
|
+
// do not attempt to apply prefix if it's undefined (a not token)
|
|
1870
|
+
// otherwise we would get weird calls to applyPrefix
|
|
1871
|
+
const applied = isNotToken
|
|
1872
|
+
? prefix
|
|
1873
|
+
: applyPrefix(prefix, _prefix, opts.prefixApplier)
|
|
1868
1874
|
|
|
1869
1875
|
return self_.normalize(ast.expression as any, applied, applyBoolean(groupValue, _groupValue), operator) as any
|
|
1870
1876
|
}
|
|
@@ -21,7 +21,7 @@ export function delim<
|
|
|
21
21
|
{
|
|
22
22
|
left: TLeft extends string ? true : TLeft
|
|
23
23
|
right: TRight extends string ? true : TRight
|
|
24
|
-
} & TType extends undefined ?
|
|
24
|
+
} & TType extends undefined ? Record<string,never> : { type: TType } {
|
|
25
25
|
let quoteType
|
|
26
26
|
if (typeof left === "string") quoteType = type(left)
|
|
27
27
|
else if (typeof right === "string") quoteType = type(right)
|
package/src/ast/handlers.ts
CHANGED
|
@@ -115,15 +115,15 @@ export function condition(
|
|
|
115
115
|
node.sep = {}
|
|
116
116
|
if (sepL) {
|
|
117
117
|
node.sep.left = sepL
|
|
118
|
-
node.property
|
|
119
|
-
node.propertyOperator
|
|
118
|
+
node.property ??= error(sepL.start, [TOKEN_TYPE.VALUE])
|
|
119
|
+
node.propertyOperator ??= error(sepL?.end ?? sepR?.start, [TOKEN_TYPE.VALUE])
|
|
120
120
|
}
|
|
121
121
|
if (sepR) node.sep.right = sepR
|
|
122
122
|
else if (!node.value || node.value.type === AST_TYPE.VARIABLE) {
|
|
123
123
|
node.sep.right = error(node.value?.start ?? end, [TOKEN_TYPE.OP_EXPANDED_SEP])
|
|
124
124
|
}
|
|
125
125
|
} else if (propertyOperator) {
|
|
126
|
-
node.property
|
|
126
|
+
node.property ??= error(propertyOperator.start, [TOKEN_TYPE.VALUE])
|
|
127
127
|
}
|
|
128
128
|
return createConditionNode(node as ConditionNode)
|
|
129
129
|
}
|