@witchcraft/expressit 0.4.1 → 0.4.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/dist/Parser.js CHANGED
@@ -978,7 +978,7 @@ class Parser {
978
978
  const propOpTarget = isPropertyOperatorPrev ? token2.valid.prev : !noArrayValuesTarget && !isVarPrev && !isPropertyPrev && isPropertyOperatorNext ? token2.valid.next : isPropertyOperatorAt ? token2.at : void 0;
979
979
  if (target) {
980
980
  const parent = getParent(target, parentMap);
981
- if (parent && parent.type === AST_TYPE.VARIABLE) {
981
+ if (parent?.type === AST_TYPE.VARIABLE) {
982
982
  const range = pos(parent);
983
983
  const parentParent = getParent(parent, parentMap);
984
984
  const condition2 = parentParent;
@@ -97,7 +97,7 @@ class ParserWithSqlSupport extends Parser {
97
97
  const value = val.value.value;
98
98
  const res = convertAndValidateValue(query.isQuoted, value, prop, propertyDefinitions);
99
99
  if (res instanceof Error) {
100
- if (!query.value || query.value.type !== "VARIABLE") unreachable();
100
+ if (query.value?.type !== "VARIABLE") unreachable();
101
101
  const token = query.value.value;
102
102
  tokens.push({
103
103
  start: token.start,
@@ -16,7 +16,7 @@ export declare class ShortcutContextParser<TErrorTokens extends Position & {
16
16
  }> extends Parser<TErrorTokens> {
17
17
  validKeys: string[];
18
18
  regexablekeys: string[];
19
- constructor(dummyContext: Record<string, any>, validRegexFlags?: string[]);
19
+ constructor(dummyContext: Record<string, any> | (() => Record<string, any>), validRegexFlags?: string[]);
20
20
  setContext(context: Record<string, any>): void;
21
21
  private _extractKeysFromContext;
22
22
  }
@@ -1 +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,q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M,EAAE,GAAG,CAAC,CAAC,EAC/D,eAAe,GAAE,MAAM,EAAoB;IAmG5C,UAAU,CAAC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,IAAI;IAK9C,OAAO,CAAC,uBAAuB;CAa/B"}
@@ -96,7 +96,7 @@ class ShortcutContextParser extends Parser {
96
96
  return { value: finalValue, operator: finalOperator, negate: isNegated };
97
97
  }
98
98
  });
99
- this._extractKeysFromContext(dummyContext);
99
+ this._extractKeysFromContext(typeof dummyContext === "function" ? dummyContext() : dummyContext);
100
100
  }
101
101
  setContext(context) {
102
102
  this.validKeys = [];
package/dist/index.js CHANGED
@@ -3,8 +3,8 @@ 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
5
  import { PARSER_ERROR } from "./types/errors.js";
6
- import * as index$1 from "./utils/index.js";
7
- import * as index$2 from "./defaults/index.js";
6
+ import * as index$2 from "./utils/index.js";
7
+ import * as index$1 from "./defaults/index.js";
8
8
  export {
9
9
  AST_TYPE,
10
10
  PARSER_ERROR,
@@ -12,6 +12,6 @@ export {
12
12
  SUGGESTION_TYPE,
13
13
  TOKEN_TYPE,
14
14
  index as ast,
15
- index$2 as defaults,
16
- index$1 as utils
15
+ index$1 as defaults,
16
+ index$2 as utils
17
17
  };
@@ -1,4 +1,4 @@
1
- const version = "0.4.1";
1
+ const version = "0.4.2";
2
2
  const repository = "https://github.com/witchcraftjs/expressit";
3
3
  const packageJson = {
4
4
  version,
package/package.json CHANGED
@@ -1,147 +1,148 @@
1
1
  {
2
- "name": "@witchcraft/expressit",
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.4.1",
5
- "types": "./dist/index.d.ts",
6
- "type": "module",
7
- "main": "./dist/index.js",
8
- "sideEffects": false,
9
- "exports": {
10
- ".": {
11
- "types": "./dist/index.d.ts",
12
- "import": "./dist/index.js"
13
- },
14
- "./ast": {
15
- "types": "./dist/ast/index.d.ts",
16
- "import": "./dist/ast/index.js"
17
- },
18
- "./ast/*": {
19
- "types": "./dist/ast/*.d.ts",
20
- "import": "./dist/ast/*.js"
21
- },
22
- "./internal/*": {
23
- "types": "./dist/internal/*.d.ts",
24
- "import": "./dist/internal/*.js"
25
- },
26
- "./utils": {
27
- "types": "./dist/utils/index.d.ts",
28
- "import": "./dist/utils/index.js"
29
- },
30
- "./utils/*": {
31
- "types": "./dist/utils/*.d.ts",
32
- "import": "./dist/utils/*.js"
33
- },
34
- "./examples": {
35
- "types": "./dist/examples/index.d.ts",
36
- "import": "./dist/examples/index.js"
37
- },
38
- "./examples/*": {
39
- "types": "./dist/examples/*.d.ts",
40
- "import": "./dist/examples/*.js"
41
- },
42
- "./*": {
43
- "types": "./dist/types/*.d.ts",
44
- "import": "./dist/types/*.js"
45
- }
46
- },
47
- "scripts": {
48
- "debug": "ts-node -r tsconfig-paths/register -T --esm",
49
- "build": "vite build",
50
- "build:dev": "vite build --mode development",
51
- "build:watch": "vite build --watch --mode production",
52
- "build:types": "tsc --emitDeclarationOnly -p tsconfig.types.json",
53
- "lint:eslint": "eslint \"{src,tests,bin}/**/*.{cjs,js,ts}\" \"*.{cjs,js,ts}\" --max-warnings=1 --report-unused-disable-directives",
54
- "lint:types": "tsc --noEmit --pretty",
55
- "lint:commits": "commitlint --from-last-tag --to HEAD --verbose",
56
- "lint:imports": "madge --circular --extensions ts ./src",
57
- "lint": "npm run lint:types && npm run lint:eslint",
58
- "coverage": "vitest --exclude '.direnv/**/*' --coverage",
59
- "coverage:dev": "vitest --exclude '.direnv/**/*' --watch --coverage",
60
- "test:db": "rm -rf ./tests/db/migrations && pnpm drizzle-kit generate --config ./tests/db/drizzle.config.ts",
61
- "test": "pnpm test:db && npm run lint:types && vitest run --exclude '.direnv/**/*'",
62
- "test:watch": "pnpm test:db && vitest --watch --exclude '.direnv/**/*'",
63
- "test:inspect-errors": "cross-env INSPECT_ERRORS=true npm run test",
64
- "doc": "typedoc --options typedoc.config.js",
65
- "doc:watch": "onchange -i \"src/**/*.ts\" \"typedoc.config.cjs\" -- npm run doc",
66
- "doc:serve": "http-server docs --port=5001",
67
- "doc:dev": "concurrently \"npm run doc:watch\" \"npm run doc:serve\"",
68
- "doc:check-invalid": "typedoc --options typedoc.config.cjs --listInvalidSymbolLinks",
69
- "demo:dev": "cd demo && concurrently \"vite\" \"npm run build:watch\"",
70
- "demo:build": "cd demo && npm run build",
71
- "actions:debug": "act -r -v -j release",
72
- "gen:exports": "indexit update -o '${path}.js' -i **/*.d.ts",
73
- "prepare": "husky && npm run build"
74
- },
75
- "dependencies": {
76
- "@alanscodelog/utils": "^6.0.1"
77
- },
78
- "devDependencies": {
79
- "@alanscodelog/commitlint-config": "^3.1.2",
80
- "@alanscodelog/eslint-config": "^6.3.0",
81
- "@alanscodelog/semantic-release-config": "^5.0.4",
82
- "@alanscodelog/tsconfigs": "^6.2.0",
83
- "@commitlint/cli": "^19.8.1",
84
- "@electric-sql/pglite": "^0.3.7",
85
- "@types/node": "^24.3.1",
86
- "@vitest/coverage-v8": "^3.2.4",
87
- "concurrently": "^9.2.1",
88
- "cross-env": "^7.0.3",
89
- "drizzle-kit": "^0.31.4",
90
- "drizzle-orm": "^0.44.5",
91
- "eslint": "^9.35.0",
92
- "fast-glob": "^3.3.3",
93
- "http-server": "^14.1.1",
94
- "husky": "^9.1.7",
95
- "indexit": "2.1.0-beta.3",
96
- "madge": "^8.0.0",
97
- "onchange": "^7.1.0",
98
- "semantic-release": "^24.2.7",
99
- "ts-node": "^10.9.2",
100
- "typedoc": "0.28.7",
101
- "typescript": "^5.9.2",
102
- "vite": "^7.1.4",
103
- "vite-plugin-externalize-deps": "^0.9.0",
104
- "vite-tsconfig-paths": "^5.1.4",
105
- "vitest": "^3.2.4"
106
- },
107
- "author": "Alan <alanscodelog@gmail.com>",
108
- "repository": "https://github.com/witchcraftjs/expressit",
109
- "keywords": [
110
- "boolean",
111
- "parser",
112
- "query",
113
- "evaluator",
114
- "expression",
115
- "condition",
116
- "search"
117
- ],
118
- "license": "MIT",
119
- "files": [
120
- "src",
121
- "dist"
122
- ],
123
- "release": {
124
- "extends": [
125
- "@alanscodelog/semantic-release-config"
126
- ]
127
- },
128
- "commitlint": {
129
- "extends": [
130
- "@alanscodelog"
131
- ]
132
- },
133
- "browserslist": "defaults and supports es6-module,maintained node versions",
134
- "engines": {
135
- "node": ">=20.0.0"
136
- },
137
- "@comments": {
138
- "scripts": {
139
- "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.",
140
- "prepare": "Needed so that if we pull the package from git it will get built and installed properly.",
141
- "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"
142
- }
143
- },
144
- "publishConfig": {
145
- "access": "public"
146
- }
147
- }
2
+ "name": "@witchcraft/expressit",
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.4.2",
5
+ "types": "./dist/index.d.ts",
6
+ "type": "module",
7
+ "main": "./dist/index.js",
8
+ "sideEffects": false,
9
+ "exports": {
10
+ ".": {
11
+ "types": "./dist/index.d.ts",
12
+ "import": "./dist/index.js"
13
+ },
14
+ "./ast": {
15
+ "types": "./dist/ast/index.d.ts",
16
+ "import": "./dist/ast/index.js"
17
+ },
18
+ "./ast/*": {
19
+ "types": "./dist/ast/*.d.ts",
20
+ "import": "./dist/ast/*.js"
21
+ },
22
+ "./internal/*": {
23
+ "types": "./dist/internal/*.d.ts",
24
+ "import": "./dist/internal/*.js"
25
+ },
26
+ "./utils": {
27
+ "types": "./dist/utils/index.d.ts",
28
+ "import": "./dist/utils/index.js"
29
+ },
30
+ "./utils/*": {
31
+ "types": "./dist/utils/*.d.ts",
32
+ "import": "./dist/utils/*.js"
33
+ },
34
+ "./examples": {
35
+ "types": "./dist/examples/index.d.ts",
36
+ "import": "./dist/examples/index.js"
37
+ },
38
+ "./examples/*": {
39
+ "types": "./dist/examples/*.d.ts",
40
+ "import": "./dist/examples/*.js"
41
+ },
42
+ "./*": {
43
+ "types": "./dist/types/*.d.ts",
44
+ "import": "./dist/types/*.js"
45
+ }
46
+ },
47
+ "dependencies": {
48
+ "@alanscodelog/utils": "^6.0.1"
49
+ },
50
+ "devDependencies": {
51
+ "@alanscodelog/commitlint-config": "^3.1.2",
52
+ "@alanscodelog/eslint-config": "^6.3.0",
53
+ "@alanscodelog/semantic-release-config": "^6.0.1",
54
+ "@alanscodelog/tsconfigs": "^6.2.0",
55
+ "@alanscodelog/vite-config": "^0.0.7",
56
+ "@commitlint/cli": "^20.4.1",
57
+ "@electric-sql/pglite": "^0.3.7",
58
+ "@types/node": "^25.2.1",
59
+ "@vitest/coverage-v8": "^4.0.18",
60
+ "concurrently": "^9.2.1",
61
+ "cross-env": "^10.1.0",
62
+ "drizzle-kit": "^0.31.4",
63
+ "drizzle-orm": "^0.45.1",
64
+ "eslint": "^9.35.0",
65
+ "fast-glob": "^3.3.3",
66
+ "http-server": "^14.1.1",
67
+ "husky": "^9.1.7",
68
+ "indexit": "2.1.0-beta.3",
69
+ "madge": "^8.0.0",
70
+ "onchange": "^7.1.0",
71
+ "semantic-release": "^25.0.3",
72
+ "ts-node": "^10.9.2",
73
+ "typedoc": "0.28.16",
74
+ "typescript": "^5.9.2",
75
+ "vite": "^7.1.4",
76
+ "vite-plugin-externalize-deps": "^0.10.0",
77
+ "vite-tsconfig-paths": "^6.0.5",
78
+ "vitest": "^4.0.18"
79
+ },
80
+ "author": "Alan <alanscodelog@gmail.com>",
81
+ "repository": "https://github.com/witchcraftjs/expressit",
82
+ "keywords": [
83
+ "boolean",
84
+ "parser",
85
+ "query",
86
+ "evaluator",
87
+ "expression",
88
+ "condition",
89
+ "search"
90
+ ],
91
+ "license": "MIT",
92
+ "files": [
93
+ "src",
94
+ "dist"
95
+ ],
96
+ "release": {
97
+ "extends": [
98
+ "@alanscodelog/semantic-release-config"
99
+ ]
100
+ },
101
+ "commitlint": {
102
+ "extends": [
103
+ "@alanscodelog"
104
+ ]
105
+ },
106
+ "browserslist": "defaults and supports es6-module,maintained node versions",
107
+ "engines": {
108
+ "node": ">=20.0.0"
109
+ },
110
+ "@comments": {
111
+ "scripts": {
112
+ "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.",
113
+ "prepare": "Needed so that if we pull the package from git it will get built and installed properly.",
114
+ "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"
115
+ }
116
+ },
117
+ "publishConfig": {
118
+ "access": "public",
119
+ "provenance": true
120
+ },
121
+ "scripts": {
122
+ "debug": "ts-node -r tsconfig-paths/register -T --esm",
123
+ "build": "vite build",
124
+ "build:dev": "vite build --mode development",
125
+ "build:watch": "vite build --watch --mode production",
126
+ "build:types": "tsc --emitDeclarationOnly -p tsconfig.types.json",
127
+ "lint:eslint": "eslint \"{src,tests,bin}/**/*.{cjs,js,ts}\" \"*.{cjs,js,ts}\" --max-warnings=1 --report-unused-disable-directives",
128
+ "lint:types": "tsc --noEmit --pretty",
129
+ "lint:commits": "commitlint --from-last-tag --to HEAD --verbose",
130
+ "lint:imports": "madge --circular --extensions ts ./src",
131
+ "lint": "npm run lint:types && npm run lint:eslint",
132
+ "coverage": "vitest --exclude '.direnv/**/*' --coverage",
133
+ "coverage:dev": "vitest --exclude '.direnv/**/*' --watch --coverage",
134
+ "test:db": "rm -rf ./tests/db/migrations && pnpm drizzle-kit generate --config ./tests/db/drizzle.config.ts",
135
+ "test": "pnpm test:db && npm run lint:types && vitest run --exclude '.direnv/**/*'",
136
+ "test:watch": "pnpm test:db && vitest --watch --exclude '.direnv/**/*'",
137
+ "test:inspect-errors": "cross-env INSPECT_ERRORS=true npm run test",
138
+ "doc": "typedoc",
139
+ "doc:watch": "onchange -i \"src/**/*.ts\" \"typedoc.config.js\" -- npm run doc",
140
+ "doc:serve": "http-server docs --port=5001",
141
+ "doc:dev": "concurrently \"npm run doc:watch\" \"npm run doc:serve\"",
142
+ "doc:check-invalid": "typedoc --listInvalidSymbolLinks",
143
+ "demo:dev": "cd demo && concurrently \"vite\" \"npm run build:watch\"",
144
+ "demo:build": "cd demo && npm run build",
145
+ "actions:debug": "act -r -v -j release",
146
+ "gen:exports": "indexit update -o '${path}.js' -i **/*.d.ts"
147
+ }
148
+ }
package/src/Parser.ts CHANGED
@@ -1423,7 +1423,7 @@ export class Parser<T = any> {
1423
1423
 
1424
1424
  if (target) {
1425
1425
  const parent = getParent(target, parentMap)
1426
- if (parent && parent.type === AST_TYPE.VARIABLE) {
1426
+ if (parent?.type === AST_TYPE.VARIABLE) {
1427
1427
  const range = pos(parent)
1428
1428
  const parentParent = getParent(parent, parentMap)
1429
1429
  const condition = parentParent as ConditionNode
@@ -175,7 +175,7 @@ export class ParserWithSqlSupport<TErrorToken extends
175
175
  const value = val.value.value
176
176
  const res = convertAndValidateValue(query.isQuoted, value, prop, propertyDefinitions)
177
177
  if (res instanceof Error) {
178
- if (!query.value || query.value.type !== "VARIABLE") unreachable()
178
+ if (query.value?.type !== "VARIABLE") unreachable()
179
179
  const token = query.value.value
180
180
  tokens.push({
181
181
  start: token.start,
@@ -23,7 +23,7 @@ export class ShortcutContextParser<TErrorTokens extends
23
23
  regexablekeys: string[] = []
24
24
 
25
25
  constructor(
26
- dummyContext: Record<string, any>,
26
+ dummyContext: Record<string, any> | (() => Record<string, any>),
27
27
  validRegexFlags: string[] = ["i", "u", "m"],
28
28
  ) {
29
29
  super({
@@ -120,7 +120,7 @@ export class ShortcutContextParser<TErrorTokens extends
120
120
  return { value: finalValue, operator: finalOperator, negate: isNegated }
121
121
  },
122
122
  })
123
- this._extractKeysFromContext(dummyContext)
123
+ this._extractKeysFromContext(typeof dummyContext === "function" ? dummyContext() : dummyContext)
124
124
  }
125
125
 
126
126
  setContext(context: Record<string, any>): void {