@vef-framework-react/expression 2.4.0 → 2.4.1

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 (39) hide show
  1. package/LICENSE +201 -0
  2. package/dist/cjs/engine/errors.cjs +1 -1
  3. package/dist/cjs/engine/evaluate.cjs +1 -1
  4. package/dist/cjs/engine/loader.cjs +1 -1
  5. package/dist/cjs/index.cjs +1 -1
  6. package/dist/es/condition/types.js +1 -1
  7. package/dist/es/engine/errors.js +2 -2
  8. package/dist/es/engine/evaluate.js +2 -5
  9. package/dist/es/engine/loader.js +1 -22
  10. package/dist/es/index.js +6 -9
  11. package/dist/types/condition/types.d.ts +10 -0
  12. package/dist/types/{src/engine → engine}/errors.d.ts +1 -2
  13. package/dist/types/{src/engine → engine}/evaluate.d.ts +1 -5
  14. package/dist/types/{src/engine → engine}/loader.d.ts +2 -18
  15. package/dist/types/index.d.ts +4 -0
  16. package/package.json +3 -25
  17. package/dist/cjs/condition/compile.cjs +0 -1
  18. package/dist/cjs/engine/intellisense.cjs +0 -1
  19. package/dist/cjs/engine/messages.cjs +0 -1
  20. package/dist/cjs/react/context.cjs +0 -1
  21. package/dist/cjs/react/index.cjs +0 -1
  22. package/dist/cjs/react/provider.cjs +0 -1
  23. package/dist/cjs/react/use-expression-engine.cjs +0 -1
  24. package/dist/es/condition/compile.js +0 -91
  25. package/dist/es/engine/intellisense.js +0 -64
  26. package/dist/es/engine/messages.js +0 -122
  27. package/dist/es/react/context.js +0 -6
  28. package/dist/es/react/index.js +0 -4
  29. package/dist/es/react/provider.js +0 -20
  30. package/dist/es/react/use-expression-engine.js +0 -11
  31. package/dist/types/src/condition/compile.d.ts +0 -49
  32. package/dist/types/src/condition/types.d.ts +0 -77
  33. package/dist/types/src/engine/intellisense.d.ts +0 -123
  34. package/dist/types/src/engine/messages.d.ts +0 -28
  35. package/dist/types/src/index.d.ts +0 -7
  36. package/dist/types/src/react/context.d.ts +0 -3
  37. package/dist/types/src/react/index.d.ts +0 -2
  38. package/dist/types/src/react/provider.d.ts +0 -23
  39. package/dist/types/src/react/use-expression-engine.d.ts +0 -7
package/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
@@ -1 +1 @@
1
- var e=class extends Error{expression;constructor(e,t,n){super(e,{cause:n}),this.name=`ExpressionError`,this.expression=t}},t=class extends e{constructor(e=`Expression engine is not initialized. Await loadEngine() or render under <ExpressionEngineProvider>.`){super(e),this.name=`ExpressionNotReadyError`}};exports.ExpressionError=e,exports.ExpressionNotReadyError=t;
1
+ var e=class extends Error{expression;constructor(e,t,n){super(e,{cause:n}),this.name=`ExpressionError`,this.expression=t}},t=class extends e{constructor(e=`Expression engine is not initialized. Await loadEngine() before evaluating synchronously.`){super(e),this.name=`ExpressionNotReadyError`}};exports.ExpressionError=e,exports.ExpressionNotReadyError=t;
@@ -1 +1 @@
1
- const e=require("./loader.cjs");async function t(t,n){return(await e.loadEngine()).evaluate(t,n)}async function n(t,n){return(await e.loadEngine()).evaluateUnary(t,n)}function r(t,n){return e.getEngineSync().evaluate(t,n)}function i(t,n){return e.getEngineSync().evaluateUnary(t,n)}async function a(t){return(await e.loadEngine()).validate(t)}async function o(t){return(await e.loadEngine()).validateUnary(t)}async function s(){return(await e.loadEngine()).getCompletions()}exports.evaluate=t,exports.evaluateSync=r,exports.evaluateUnary=n,exports.evaluateUnarySync=i,exports.getCompletions=s,exports.validate=a,exports.validateUnary=o;
1
+ const e=require("./loader.cjs");async function t(t,n){return(await e.loadEngine()).evaluate(t,n)}async function n(t,n){return(await e.loadEngine()).evaluateUnary(t,n)}function r(t,n){return e.getEngineSync().evaluate(t,n)}function i(t,n){return e.getEngineSync().evaluateUnary(t,n)}async function a(t){return(await e.loadEngine()).validate(t)}async function o(t){return(await e.loadEngine()).validateUnary(t)}exports.evaluate=t,exports.evaluateSync=r,exports.evaluateUnary=n,exports.evaluateUnarySync=i,exports.validate=a,exports.validateUnary=o;
@@ -1 +1 @@
1
- const e=require("./errors.cjs");let t=require("@vef-framework-react/shared");var n=null,r=null,i=null,a;function o(t,n){try{return n()}catch(n){throw new e.ExpressionError(`Failed to evaluate expression: ${t}`,t,n)}}function s(){let e=`Failed to load the ZEN expression engine`;return(0,t.isUndefined)(globalThis.window)?`${e}. In a non-browser host (Node / SSR) the wasm cannot be auto-resolved; call configureEngine({ wasmInput }) with the wasm bytes or URL before loading.`:e}function c(t){if(n||r)throw new e.ExpressionError(`configureEngine() must be called before the engine loads.`);a=t.wasmInput}function l(){return n||(i=null,n=(async()=>{let e=await import(`@gorules/zen-engine-wasm`);await e.default((0,t.isUndefined)(a)?void 0:{module_or_path:a});let n=Object.freeze({evaluate:(t,n={})=>o(t,()=>e.evaluateExpression(t,n)),evaluateUnary:(t,n={})=>o(t,()=>e.evaluateUnaryExpression(t,n)),validate:t=>e.validateExpression(t),validateUnary:t=>e.validateUnaryExpression(t),getCompletions:()=>e.getCompletions(),analyze:(t,n,r)=>{let i=e.VariableType.fromJson(t);try{let e=i.toJson(),t=r?i.typeCheckUnary(n):i.typeCheck(n);return{rootKind:e,spans:Array.isArray(t)?t:[]}}finally{i.free()}},satisfies:(t,n)=>{let r=e.VariableType.fromJson(t),i=e.VariableType.fromJson(n);try{return r.satisfies(i)}finally{r.free(),i.free()}},isReady:()=>e.isReady()});return r=n,n})().catch(t=>{throw n=null,i=new e.ExpressionError(s(),void 0,t),i}),n)}function u(){return r?.isReady()??!1}function d(){return i}function f(){if(!r)throw new e.ExpressionNotReadyError;return r}exports.configureEngine=c,exports.getEngineError=d,exports.getEngineSync=f,exports.isEngineReady=u,exports.loadEngine=l;
1
+ const e=require("./errors.cjs");let t=require("@vef-framework-react/shared");var n=null,r=null,i=null,a;function o(t,n){try{return n()}catch(n){throw new e.ExpressionError(`Failed to evaluate expression: ${t}`,t,n)}}function s(){let e=`Failed to load the ZEN expression engine`;return(0,t.isUndefined)(globalThis.window)?`${e}. In a non-browser host (Node / SSR) the wasm cannot be auto-resolved; call configureEngine({ wasmInput }) with the wasm bytes or URL before loading.`:e}function c(t){if(n||r)throw new e.ExpressionError(`configureEngine() must be called before the engine loads.`);a=t.wasmInput}function l(){return n||(i=null,n=(async()=>{let e=await import(`@gorules/zen-engine-wasm`);await e.default((0,t.isUndefined)(a)?void 0:{module_or_path:a});let n=Object.freeze({evaluate:(t,n={})=>o(t,()=>e.evaluateExpression(t,n)),evaluateUnary:(t,n={})=>o(t,()=>e.evaluateUnaryExpression(t,n)),validate:t=>e.validateExpression(t),validateUnary:t=>e.validateUnaryExpression(t),isReady:()=>e.isReady()});return r=n,n})().catch(t=>{throw n=null,i=new e.ExpressionError(s(),void 0,t),i}),n)}function u(){return r?.isReady()??!1}function d(){return i}function f(){if(!r)throw new e.ExpressionNotReadyError;return r}exports.configureEngine=c,exports.getEngineError=d,exports.getEngineSync=f,exports.isEngineReady=u,exports.loadEngine=l;
@@ -1 +1 @@
1
- Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("./engine/errors.cjs"),t=require("./engine/loader.cjs"),n=require("./condition/compile.cjs"),r=require("./condition/types.cjs"),i=require("./engine/evaluate.cjs"),a=require("./engine/messages.cjs"),o=require("./engine/intellisense.cjs");exports.CONDITION_OPERATORS=r.CONDITION_OPERATORS,exports.ExpressionError=e.ExpressionError,exports.ExpressionNotReadyError=e.ExpressionNotReadyError,exports.analyzeTypes=o.analyzeTypes,exports.analyzeTypesSync=o.analyzeTypesSync,exports.compileBranch=n.compileBranch,exports.compileCondition=n.compileCondition,exports.compileGroup=n.compileGroup,exports.configureEngine=t.configureEngine,exports.evaluate=i.evaluate,exports.evaluateSync=i.evaluateSync,exports.evaluateUnary=i.evaluateUnary,exports.evaluateUnarySync=i.evaluateUnarySync,exports.getCompletionItems=o.getCompletionItems,exports.getCompletionItemsSync=o.getCompletionItemsSync,exports.getCompletions=i.getCompletions,exports.getDiagnostics=o.getDiagnostics,exports.getDiagnosticsSync=o.getDiagnosticsSync,exports.getEngineError=t.getEngineError,exports.getEngineSync=t.getEngineSync,exports.getExpressionLocale=a.getExpressionLocale,exports.isEngineReady=t.isEngineReady,exports.loadEngine=t.loadEngine,exports.satisfiesType=o.satisfiesType,exports.satisfiesTypeSync=o.satisfiesTypeSync,exports.selectBranch=n.selectBranch,exports.selectBranchWith=n.selectBranchWith,exports.setExpressionLocale=a.setExpressionLocale,exports.toZenLiteral=n.toZenLiteral,exports.validate=i.validate,exports.validateUnary=i.validateUnary;
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("./condition/types.cjs"),t=require("./engine/errors.cjs"),n=require("./engine/loader.cjs"),r=require("./engine/evaluate.cjs");exports.CONDITION_OPERATORS=e.CONDITION_OPERATORS,exports.ExpressionError=t.ExpressionError,exports.ExpressionNotReadyError=t.ExpressionNotReadyError,exports.configureEngine=n.configureEngine,exports.evaluate=r.evaluate,exports.evaluateSync=r.evaluateSync,exports.evaluateUnary=r.evaluateUnary,exports.evaluateUnarySync=r.evaluateUnarySync,exports.getEngineError=n.getEngineError,exports.getEngineSync=n.getEngineSync,exports.isEngineReady=n.isEngineReady,exports.loadEngine=n.loadEngine,exports.validate=r.validate,exports.validateUnary=r.validateUnary;
@@ -1,4 +1,4 @@
1
- /*! @vef-framework-react/expression v2.4.0 made by Venus | 2026-06-15T15:10:07.346Z */
1
+ /*! @vef-framework-react/expression v2.4.1 made by Venus | 2026-06-17T13:09:30.483Z */
2
2
  //#region src/condition/types.ts
3
3
  var e = [
4
4
  "eq",
@@ -1,4 +1,4 @@
1
- /*! @vef-framework-react/expression v2.4.0 made by Venus | 2026-06-15T15:10:07.346Z */
1
+ /*! @vef-framework-react/expression v2.4.1 made by Venus | 2026-06-17T13:09:30.483Z */
2
2
  //#region src/engine/errors.ts
3
3
  var e = class extends Error {
4
4
  expression;
@@ -6,7 +6,7 @@ var e = class extends Error {
6
6
  super(e, { cause: n }), this.name = "ExpressionError", this.expression = t;
7
7
  }
8
8
  }, t = class extends e {
9
- constructor(e = "Expression engine is not initialized. Await loadEngine() or render under <ExpressionEngineProvider>.") {
9
+ constructor(e = "Expression engine is not initialized. Await loadEngine() before evaluating synchronously.") {
10
10
  super(e), this.name = "ExpressionNotReadyError";
11
11
  }
12
12
  };
@@ -1,4 +1,4 @@
1
- /*! @vef-framework-react/expression v2.4.0 made by Venus | 2026-06-15T15:10:07.346Z */
1
+ /*! @vef-framework-react/expression v2.4.1 made by Venus | 2026-06-17T13:09:30.483Z */
2
2
  import { getEngineSync as e, loadEngine as t } from "./loader.js";
3
3
  //#region src/engine/evaluate.ts
4
4
  async function n(e, n) {
@@ -19,8 +19,5 @@ async function o(e) {
19
19
  async function s(e) {
20
20
  return (await t()).validateUnary(e);
21
21
  }
22
- async function c() {
23
- return (await t()).getCompletions();
24
- }
25
22
  //#endregion
26
- export { n as evaluate, i as evaluateSync, r as evaluateUnary, a as evaluateUnarySync, c as getCompletions, o as validate, s as validateUnary };
23
+ export { n as evaluate, i as evaluateSync, r as evaluateUnary, a as evaluateUnarySync, o as validate, s as validateUnary };
@@ -1,4 +1,4 @@
1
- /*! @vef-framework-react/expression v2.4.0 made by Venus | 2026-06-15T15:10:07.346Z */
1
+ /*! @vef-framework-react/expression v2.4.1 made by Venus | 2026-06-17T13:09:30.483Z */
2
2
  import { ExpressionError as e, ExpressionNotReadyError as t } from "./errors.js";
3
3
  import { isUndefined as n } from "@vef-framework-react/shared";
4
4
  //#region src/engine/loader.ts
@@ -27,27 +27,6 @@ function u() {
27
27
  evaluateUnary: (t, n = {}) => s(t, () => e.evaluateUnaryExpression(t, n)),
28
28
  validate: (t) => e.validateExpression(t),
29
29
  validateUnary: (t) => e.validateUnaryExpression(t),
30
- getCompletions: () => e.getCompletions(),
31
- analyze: (t, n, r) => {
32
- let i = e.VariableType.fromJson(t);
33
- try {
34
- let e = i.toJson(), t = r ? i.typeCheckUnary(n) : i.typeCheck(n);
35
- return {
36
- rootKind: e,
37
- spans: Array.isArray(t) ? t : []
38
- };
39
- } finally {
40
- i.free();
41
- }
42
- },
43
- satisfies: (t, n) => {
44
- let r = e.VariableType.fromJson(t), i = e.VariableType.fromJson(n);
45
- try {
46
- return r.satisfies(i);
47
- } finally {
48
- r.free(), i.free();
49
- }
50
- },
51
30
  isReady: () => e.isReady()
52
31
  });
53
32
  return i = t, t;
package/dist/es/index.js CHANGED
@@ -1,9 +1,6 @@
1
- /*! @vef-framework-react/expression v2.4.0 made by Venus | 2026-06-15T15:10:07.346Z */
2
- import { ExpressionError as e, ExpressionNotReadyError as t } from "./engine/errors.js";
3
- import { configureEngine as n, getEngineError as r, getEngineSync as i, isEngineReady as a, loadEngine as o } from "./engine/loader.js";
4
- import { compileBranch as s, compileCondition as c, compileGroup as l, selectBranch as u, selectBranchWith as d, toZenLiteral as f } from "./condition/compile.js";
5
- import { CONDITION_OPERATORS as p } from "./condition/types.js";
6
- import { evaluate as m, evaluateSync as h, evaluateUnary as g, evaluateUnarySync as _, getCompletions as v, validate as y, validateUnary as b } from "./engine/evaluate.js";
7
- import { getExpressionLocale as x, setExpressionLocale as S } from "./engine/messages.js";
8
- import { analyzeTypes as C, analyzeTypesSync as w, getCompletionItems as T, getCompletionItemsSync as E, getDiagnostics as D, getDiagnosticsSync as O, satisfiesType as k, satisfiesTypeSync as A } from "./engine/intellisense.js";
9
- export { p as CONDITION_OPERATORS, e as ExpressionError, t as ExpressionNotReadyError, C as analyzeTypes, w as analyzeTypesSync, s as compileBranch, c as compileCondition, l as compileGroup, n as configureEngine, m as evaluate, h as evaluateSync, g as evaluateUnary, _ as evaluateUnarySync, T as getCompletionItems, E as getCompletionItemsSync, v as getCompletions, D as getDiagnostics, O as getDiagnosticsSync, r as getEngineError, i as getEngineSync, x as getExpressionLocale, a as isEngineReady, o as loadEngine, k as satisfiesType, A as satisfiesTypeSync, u as selectBranch, d as selectBranchWith, S as setExpressionLocale, f as toZenLiteral, y as validate, b as validateUnary };
1
+ /*! @vef-framework-react/expression v2.4.1 made by Venus | 2026-06-17T13:09:30.483Z */
2
+ import { CONDITION_OPERATORS as e } from "./condition/types.js";
3
+ import { ExpressionError as t, ExpressionNotReadyError as n } from "./engine/errors.js";
4
+ import { configureEngine as r, getEngineError as i, getEngineSync as a, isEngineReady as o, loadEngine as s } from "./engine/loader.js";
5
+ import { evaluate as c, evaluateSync as l, evaluateUnary as u, evaluateUnarySync as d, validate as f, validateUnary as p } from "./engine/evaluate.js";
6
+ export { e as CONDITION_OPERATORS, t as ExpressionError, n as ExpressionNotReadyError, r as configureEngine, c as evaluate, l as evaluateSync, u as evaluateUnary, d as evaluateUnarySync, i as getEngineError, a as getEngineSync, o as isEngineReady, s as loadEngine, f as validate, p as validateUnary };
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Closed condition-operator vocabulary shared with approval-flow editor and
3
+ * backend validation. The {@link ConditionOperator} type derives from this
4
+ * array — one definition site for both the type and the runtime allow-list.
5
+ */
6
+ export declare const CONDITION_OPERATORS: readonly ["eq", "ne", "gt", "gte", "lt", "lte", "contains", "not_contains", "starts_with", "ends_with", "in", "not_in", "is_empty", "is_not_empty"];
7
+ /**
8
+ * Operators understood by the approval condition model.
9
+ */
10
+ export type ConditionOperator = typeof CONDITION_OPERATORS[number];
@@ -9,8 +9,7 @@ export declare class ExpressionError extends Error {
9
9
  }
10
10
  /**
11
11
  * Raised by the synchronous evaluation helpers when the engine has not finished
12
- * initializing yet. Await {@link loadEngine} (or render under
13
- * `<ExpressionEngineProvider>`) before evaluating synchronously.
12
+ * initializing yet. Await {@link loadEngine} before evaluating synchronously.
14
13
  */
15
14
  export declare class ExpressionNotReadyError extends ExpressionError {
16
15
  constructor(message?: string);
@@ -14,7 +14,7 @@ export declare function evaluateUnary(expression: string, context?: ExpressionCo
14
14
  /**
15
15
  * Evaluate a standard ZEN expression synchronously. Throws
16
16
  * {@link ExpressionNotReadyError} when the engine has not loaded yet — use this
17
- * only behind a readiness gate (e.g. under `<ExpressionEngineProvider>`).
17
+ * only behind a readiness gate that has awaited {@link loadEngine}.
18
18
  */
19
19
  export declare function evaluateSync<T = unknown>(expression: string, context?: ExpressionContext): T;
20
20
  /**
@@ -30,7 +30,3 @@ export declare function validate(expression: string): Promise<unknown>;
30
30
  * Validate a unary expression, loading the engine on first use.
31
31
  */
32
32
  export declare function validateUnary(expression: string): Promise<unknown>;
33
- /**
34
- * Return ZEN completion metadata, loading the engine on first use.
35
- */
36
- export declare function getCompletions(): Promise<unknown>;
@@ -1,5 +1,4 @@
1
1
  import { InitInput } from '@gorules/zen-engine-wasm';
2
- import { ExpressionAnalysis, ExpressionType } from './intellisense';
3
2
  import { ExpressionError } from './errors';
4
3
  /**
5
4
  * The data an expression reads from. Property paths in the expression (e.g.
@@ -41,21 +40,6 @@ export interface ExpressionEngine {
41
40
  * Validate a unary expression; returns ZEN's diagnostic payload.
42
41
  */
43
42
  validateUnary: (expression: string) => unknown;
44
- /**
45
- * Return ZEN's completion metadata, for building an expression editor.
46
- */
47
- getCompletions: () => unknown;
48
- /**
49
- * Type-check `source` against a `variables` context, returning the root context
50
- * type and the inferred type of every span (`unary` selects test-expression
51
- * checking). Powers an editor's type-aware completion / hover / diagnostics.
52
- */
53
- analyze: (variables: ExpressionType, source: string, unary: boolean) => ExpressionAnalysis;
54
- /**
55
- * Whether `actual` satisfies (is assignable to) `expected`. Powers
56
- * expected-return-type validation in an editor.
57
- */
58
- satisfies: (actual: ExpressionType, expected: ExpressionType) => boolean;
59
43
  /**
60
44
  * Whether the underlying wasm module reports itself ready.
61
45
  */
@@ -86,8 +70,8 @@ export declare function loadEngine(): Promise<ExpressionEngine>;
86
70
  export declare function isEngineReady(): boolean;
87
71
  /**
88
72
  * The error from the last failed {@link loadEngine} attempt, or `null`. Used by
89
- * the React provider to surface a wasm-load failure to an error boundary rather
90
- * than suspending forever, and by imperative pollers to tell "failed" apart from
73
+ * UI gates to surface a wasm-load failure to an error boundary rather than
74
+ * suspending forever, and by imperative pollers to tell "failed" apart from
91
75
  * "still loading". Cleared when a new load starts or {@link resetEngine}.
92
76
  */
93
77
  export declare function getEngineError(): ExpressionError | null;
@@ -0,0 +1,4 @@
1
+ export { CONDITION_OPERATORS, type ConditionOperator } from './condition/types';
2
+ export { ExpressionError, ExpressionNotReadyError } from './engine/errors';
3
+ export { evaluate, evaluateSync, evaluateUnary, evaluateUnarySync, validate, validateUnary } from './engine/evaluate';
4
+ export { configureEngine, getEngineError, getEngineSync, isEngineReady, loadEngine, type ExpressionContext, type ExpressionEngine, type LoadEngineOptions } from './engine/loader';
package/package.json CHANGED
@@ -1,9 +1,9 @@
1
1
  {
2
2
  "name": "@vef-framework-react/expression",
3
3
  "type": "module",
4
- "version": "2.4.0",
4
+ "version": "2.4.1",
5
5
  "private": false,
6
- "description": "Frontend abstraction over the GoRules ZEN expression engine (WASM) for VEF framework",
6
+ "description": "GoRules ZEN expression runtime and shared condition operators for VEF framework",
7
7
  "author": {
8
8
  "name": "Venus",
9
9
  "email": "iweixiaopeng@163.com",
@@ -33,17 +33,6 @@
33
33
  "default": "./dist/cjs/index.cjs"
34
34
  }
35
35
  },
36
- "./react": {
37
- "vef": "./src/react/index.ts",
38
- "import": {
39
- "types": "./dist/types/react/index.d.ts",
40
- "default": "./dist/es/react/index.js"
41
- },
42
- "require": {
43
- "types": "./dist/types/react/index.d.ts",
44
- "default": "./dist/cjs/react/index.cjs"
45
- }
46
- },
47
36
  "./package.json": "./package.json"
48
37
  },
49
38
  "main": "dist/cjs/index.cjs",
@@ -58,20 +47,9 @@
58
47
  "publishConfig": {
59
48
  "access": "public"
60
49
  },
61
- "peerDependencies": {
62
- "react": ">=19"
63
- },
64
- "peerDependenciesMeta": {
65
- "react": {
66
- "optional": true
67
- }
68
- },
69
50
  "dependencies": {
70
51
  "@gorules/zen-engine-wasm": "0.23.1",
71
- "@vef-framework-react/shared": "2.4.0"
72
- },
73
- "devDependencies": {
74
- "react": "^19.2.7"
52
+ "@vef-framework-react/shared": "2.4.1"
75
53
  },
76
54
  "scripts": {
77
55
  "clean": "rimraf dist",
@@ -1 +0,0 @@
1
- const e=require("../engine/errors.cjs"),t=require("../engine/loader.cjs");let n=require("@vef-framework-react/shared");var r=/^[A-Z_$][\w$]*(?:\.[A-Z_$][\w$]*|\[\d+\])*$/i;function i(t){if((0,n.isNullish)(t))return`null`;if(typeof t==`number`||typeof t==`boolean`||typeof t==`bigint`)return String(t);if((0,n.isString)(t))return a(t);if((0,n.isArray)(t))return`[${t.map(e=>i(e)).join(`, `)}]`;throw new e.ExpressionError(`Value of type "${typeof t}" has no ZEN literal representation`)}function a(t){let n=t.includes(`'`),r=t.includes(`"`);if(n&&r)throw new e.ExpressionError(`String contains both single and double quotes and has no ZEN literal representation`);return n?`"${t}"`:`'${t}'`}function o(e){return(0,n.isArray)(e)?i(e):`[${i(e)}]`}function s(e){return`(${e} == null or (type(${e}) == 'string' and len(trim(${e})) == 0) or (type(${e}) == 'array' and len(${e}) == 0))`}function c(t,n,r){switch(n){case`eq`:return`${t} == ${i(r)}`;case`ne`:return`${t} != ${i(r)}`;case`gt`:return`${t} > ${i(r)}`;case`gte`:return`${t} >= ${i(r)}`;case`lt`:return`${t} < ${i(r)}`;case`lte`:return`${t} <= ${i(r)}`;case`contains`:return`contains(${t}, ${i(r)})`;case`not_contains`:return`not contains(${t}, ${i(r)})`;case`starts_with`:return`startsWith(${t}, ${i(r)})`;case`ends_with`:return`endsWith(${t}, ${i(r)})`;case`in`:return`${t} in ${o(r)}`;case`not_in`:return`not (${t} in ${o(r)})`;case`is_empty`:return s(t);case`is_not_empty`:return`not ${s(t)}`;default:throw new e.ExpressionError(`Unsupported operator: ${String(n)}`)}}function l(e){if(e.kind===`expression`){let t=e.expression.trim();return t===``?null:t}let t=e.subject.trim();if(!r.test(t))return null;try{return c(t,e.operator,e.value)}catch{return null}}function u(e){let t=e.conditions.map(e=>l(e)).filter(e=>e!==null);return t.length===0?null:t.join(` and `)}function d(e){let t=(e.conditionGroups??[]).map(e=>u(e)).filter(e=>e!==null);return t.length===0?null:t.map(e=>`(${e})`).join(` or `)}function f(e,t,n){let r=e.toSorted((e,t)=>e.priority-t.priority);for(let e of r){if(e.isDefault)continue;let r=d(e);if(r!==null&&p(n,r,t))return{branchId:e.id,matched:!0}}return{branchId:r.find(e=>e.isDefault)?.id??null,matched:!1}}function p(e,t,n){try{return e.evaluate(t,n)===!0}catch{return!1}}async function m(e,n){return f(e,n,await t.loadEngine())}exports.compileBranch=d,exports.compileCondition=l,exports.compileGroup=u,exports.selectBranch=m,exports.selectBranchWith=f,exports.toZenLiteral=i;
@@ -1 +0,0 @@
1
- const e=require("./loader.cjs"),t=require("./messages.cjs");function n(e){let t=e.split(` at `),n=t.length<=1?void 0:t.at(-1);if(n===void 0)return null;let[r,i]=n.replace(`(`,``).replace(`)`,``).split(`, `),a=r===void 0?NaN:Number.parseInt(r,10);if(Number.isNaN(a))return null;if(i===void 0)return a;let o=Number.parseInt(i,10);return Number.isNaN(o)?a:[a,o]}function r(e,r){if(e==null)return null;let i=e,a=typeof i.source==`string`?i.source:String(e),o=n(a),[s,c]=o===null?[0,r.length]:typeof o==`number`?[o,o]:o;return{from:s,to:c,message:a,source:t.localizeSourceLabel(i.type)}}function i(e){return Array.isArray(e)?e.flatMap(e=>{let n=e;return typeof n.label!=`string`||n.label===``?[]:[{type:n.type===`method`||n.type===`variable`?n.type:`function`,label:n.label,detail:typeof n.detail==`string`?n.detail.replaceAll("`",``):``,info:t.localizeCompletionInfo(typeof n.info==`string`?n.info:``),boost:typeof n.boost==`number`?n.boost:null,methodFor:typeof n.methodFor==`string`?n.methodFor:null}]}):[]}async function a(t,n){let i=await e.loadEngine();return r(n===`unary`?i.validateUnary(t):i.validate(t),t)}function o(t,n){let i=e.getEngineSync();return r(n===`unary`?i.validateUnary(t):i.validate(t),t)}async function s(){return i((await e.loadEngine()).getCompletions())}function c(){return i(e.getEngineSync().getCompletions())}async function l(t,n,r){return(await e.loadEngine()).analyze(t,n,r===`unary`)}function u(t,n,r){return e.getEngineSync().analyze(t,n,r===`unary`)}async function d(t,n){return(await e.loadEngine()).satisfies(t,n)}function f(t,n){return e.getEngineSync().satisfies(t,n)}exports.analyzeTypes=l,exports.analyzeTypesSync=u,exports.getCompletionItems=s,exports.getCompletionItemsSync=c,exports.getDiagnostics=a,exports.getDiagnosticsSync=o,exports.satisfiesType=d,exports.satisfiesTypeSync=f;
@@ -1 +0,0 @@
1
- var e=`en-US`;function t(t){e=t}function n(){return e}var r={"Returns the length of variable":`返回变量的长度`,"Checks if variable contains a needle":`检查变量是否包含指定元素`,"Flattens an array":`将数组扁平化`,"Merges multiple objects into one.":`将多个对象合并为一个。`,"Deeply merges multiple objects into one.":`将多个对象深度合并为一个。`,"Converts all characters in a string to uppercase":`将字符串中所有字符转换为大写`,"Converts all characters in a string to lowercase":`将字符串中所有字符转换为小写`,"Returns the string with leading and trailing whitespace removed":`返回去除首尾空白后的字符串`,"Returns true if the string starts with the specified prefix":`若字符串以指定前缀开头则返回 true`,"Returns true if the string ends with the specified suffix":`若字符串以指定后缀结尾则返回 true`,"Returns true if the string matches the specified pattern":`若字符串匹配指定模式则返回 true`,"Extracts matching substrings according to a pattern":`按模式提取匹配的子串`,"Performs a fuzzy search of the needle in the haystack, and returns the match score(s).":`在目标中对关键字进行模糊搜索,并返回匹配得分。`,"Splits a string into an array of substrings using the specified delimiter.":`使用指定分隔符将字符串拆分为子串数组。`,"Returns the absolute value of a number":`返回数字的绝对值`,"Returns the sum of all elements in the input array.":`返回输入数组中所有元素之和。`,"Calculates the average of all elements in the input array.":`计算输入数组中所有元素的平均值。`,"Returns the smallest of the elements in the input array.":`返回输入数组中的最小元素。`,"Returns the largest of the elements in the input array.":`返回输入数组中的最大元素。`,"Generates a random number between 0 (inclusive) and max (inclusive).":`生成 0 到 max(均包含)之间的随机数。`,"Calculates the median value of all elements in the input array.":`计算输入数组中所有元素的中位数。`,"Finds the mode(s) of the input array, which are the most frequent element(s).":`求输入数组的众数,即出现最频繁的元素。`,"Rounds a number down to the nearest integer.":`向下取整到最接近的整数。`,"Rounds a number up to the nearest integer.":`向上取整到最接近的整数。`,"Rounds a number to a specified number of decimal places.":`将数字四舍五入到指定的小数位数。`,"Truncates a number to a specified number of decimal places.":`将数字截断到指定的小数位数。`,"Checks if the given value is of a numeric type.":`检查给定值是否为数值类型。`,"Converts the given value to a string.":`将给定值转换为字符串。`,"Converts the given value to a number.":`将给定值转换为数字。`,"Converts the given value to a boolean.":`将给定值转换为布尔值。`,"Returns a string representing the data type of the value.":`返回表示该值数据类型的字符串。`,"Returns an array of a given object's own enumerable property names.":`返回由给定对象自身可枚举属性名组成的数组。`,"Returns an array of a given object's own enumerable property values.":`返回由给定对象自身可枚举属性值组成的数组。`,"Returns a new date time instance.":`返回一个新的日期时间实例。`,"Converts a numeric timestamp to a unix timestamp.":`将数值时间戳转换为 Unix 时间戳。`,"Extracts the time from a numeric timestamp and returns it as a seconds from beginning of day.":`从数值时间戳中提取时间,以当天起始的秒数返回。`,"e.g. 1h30min":`例如 1h30min`,"Extracts the year from a given timestamp.":`从给定时间戳中提取年份。`,"Gets the day of the week from a given timestamp, where Sunday might be 0.":`获取给定时间戳的星期几(周日可能为 0)。`,"Extracts the day of the month from a given timestamp.":`从给定时间戳中提取当月的日期。`,"Gets the day of the year from a given timestamp.":`获取给定时间戳在一年中的第几天。`,"Calculates the week of the year from a given timestamp.":`计算给定时间戳在一年中的第几周。`,"Extracts the month from a given timestamp, typically with January as 1.":`从给定时间戳中提取月份(通常 1 月为 1)。`,"Converts the month from a given timestamp into its string representation (e.g., 'Jan').":`将给定时间戳的月份转换为字符串表示(例如 'Jan')。`,"Converts a timestamp to a human-readable date string.":`将时间戳转换为人类可读的日期字符串。`,"Converts the day of the week from a given timestamp into its string representation (e.g., 'Mon').":`将给定时间戳的星期几转换为字符串表示(例如 'Mon')。`,"Returns the timestamp representing the start of a specified unit (e.g., day, month, year) based on a given timestamp.":`返回给定时间戳在指定单位(如日、月、年)起始处的时间戳。`,"Returns the timestamp representing the end of a specified unit (e.g., day, month, year) based on a given timestamp.":`返回给定时间戳在指定单位(如日、月、年)结束处的时间戳。`,"Checks if all elements in the array satisfy the condition defined in the callback.":`检查数组中所有元素是否都满足回调中定义的条件。`,"Checks if no elements in the array satisfy the condition defined in the callback.":`检查数组中是否没有任何元素满足回调中定义的条件。`,"Checks if at least one element in the array satisfies the condition defined in the callback.":`检查数组中是否至少有一个元素满足回调中定义的条件。`,"Checks if exactly one element in the array satisfies the condition defined in the callback.":`检查数组中是否恰好有一个元素满足回调中定义的条件。`,"Creates a new array with all elements that satisfy the condition defined in the callback.":`创建一个仅包含满足回调中定义条件的元素的新数组。`,"Creates a new array populated with the results of calling the provided function on every element in the calling array.":`创建一个新数组,其元素为对原数组每个元素调用所提供函数的结果。`,"First maps each element using a mapping function, then flattens the result into a new array.":`先用映射函数处理每个元素,再将结果扁平化为新数组。`,"Counts the number of elements in the array that satisfy the condition defined in the callback.":`统计数组中满足回调中定义条件的元素个数。`,"Adds time to a date":`为日期增加时间`,"Subtracts time from a date":`从日期中减去时间`,"Sets a specific unit of time on a date":`设置日期的某个时间单位`,"Formats a date into a string representation":`将日期格式化为字符串`,"Returns the start of a specified time unit for a date":`返回日期在指定时间单位上的起始`,"Returns the end of a specified time unit for a date":`返回日期在指定时间单位上的结束`,"Calculates the difference between two dates":`计算两个日期之间的差值`,"Converts a date to a different timezone":`将日期转换到不同的时区`,"Checks if two dates are the same":`检查两个日期是否相同`,"Checks if a date is before another date":`检查日期是否早于另一个日期`,"Checks if a date is after another date":`检查日期是否晚于另一个日期`,"Checks if a date is the same as or before another date":`检查日期是否等于或早于另一个日期`,"Checks if a date is the same as or after another date":`检查日期是否等于或晚于另一个日期`,"Gets the seconds of a date":`获取日期的秒`,"Gets the minutes of a date":`获取日期的分钟`,"Gets the hours of a date":`获取日期的小时`,"Gets the day of the month for a date":`获取日期在当月的第几天`,"Gets the day of the year for a date":`获取日期在当年的第几天`,"Gets the week of the year for a date":`获取日期在当年的第几周`,"Gets the day of the week for a date":`获取日期的星期几`,"Gets the month for a date":`获取日期的月份`,"Gets the quarter for a date":`获取日期所在的季度`,"Gets the year for a date":`获取日期的年份`,"Gets the Unix timestamp for a date":`获取日期的 Unix 时间戳`,"Gets the timezone offset name for a date":`获取日期的时区偏移名称`,"Checks if a date is valid":`检查日期是否有效`,"Checks if a date is yesterday":`检查日期是否为昨天`,"Checks if a date is today":`检查日期是否为今天`,"Checks if a date is tomorrow":`检查日期是否为明天`,"Checks if the year of a date is a leap year":`检查日期所在年份是否为闰年`};function i(t){return e!==`zh-CN`||t===``?t:r[t]??t}var a={"en-US":{lexerError:`Lexer error`,parserError:`Parser error`,compilerError:`Compiler error`,vmError:`VM error`,fallback:`Error`},"zh-CN":{lexerError:`词法错误`,parserError:`语法错误`,compilerError:`编译错误`,vmError:`运行时错误`,fallback:`错误`}};function o(t){let n=a[e];return(t===void 0?void 0:n[t])??n.fallback}exports.getExpressionLocale=n,exports.localizeCompletionInfo=i,exports.localizeSourceLabel=o,exports.setExpressionLocale=t;
@@ -1 +0,0 @@
1
- var e=(0,require("react").createContext)(null);exports.ExpressionEngineContext=e;
@@ -1 +0,0 @@
1
- Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("./provider.cjs"),t=require("./use-expression-engine.cjs");exports.ExpressionEngineProvider=e.ExpressionEngineProvider,exports.useExpressionEngine=t.useExpressionEngine;
@@ -1 +0,0 @@
1
- const e=require("../engine/loader.cjs"),t=require("../engine/messages.cjs"),n=require("./context.cjs");let r=require("react"),i=require("react/jsx-runtime");function a({children:t}){if(!e.isEngineReady())throw e.getEngineError()||e.loadEngine();let r=e.getEngineSync();return(0,i.jsx)(n.ExpressionEngineContext,{value:r,children:t})}var o=({children:e,fallback:n=null,locale:o})=>(o!==void 0&&t.setExpressionLocale(o),(0,i.jsx)(r.Suspense,{fallback:n,children:(0,i.jsx)(a,{children:e})}));exports.ExpressionEngineProvider=o;
@@ -1 +0,0 @@
1
- const e=require("./context.cjs");let t=require("react");function n(){let n=(0,t.use)(e.ExpressionEngineContext);if(!n)throw Error(`useExpressionEngine must be used within <ExpressionEngineProvider>.`);return n}exports.useExpressionEngine=n;
@@ -1,91 +0,0 @@
1
- /*! @vef-framework-react/expression v2.4.0 made by Venus | 2026-06-15T15:10:07.346Z */
2
- import { ExpressionError as e } from "../engine/errors.js";
3
- import { loadEngine as t } from "../engine/loader.js";
4
- import { isArray as n, isNullish as r, isString as i } from "@vef-framework-react/shared";
5
- //#region src/condition/compile.ts
6
- var a = /^[A-Z_$][\w$]*(?:\.[A-Z_$][\w$]*|\[\d+\])*$/i;
7
- function o(t) {
8
- if (r(t)) return "null";
9
- if (typeof t == "number" || typeof t == "boolean" || typeof t == "bigint") return String(t);
10
- if (i(t)) return s(t);
11
- if (n(t)) return `[${t.map((e) => o(e)).join(", ")}]`;
12
- throw new e(`Value of type "${typeof t}" has no ZEN literal representation`);
13
- }
14
- function s(t) {
15
- let n = t.includes("'"), r = t.includes("\"");
16
- if (n && r) throw new e("String contains both single and double quotes and has no ZEN literal representation");
17
- return n ? `"${t}"` : `'${t}'`;
18
- }
19
- function c(e) {
20
- return n(e) ? o(e) : `[${o(e)}]`;
21
- }
22
- function l(e) {
23
- return `(${e} == null or (type(${e}) == 'string' and len(trim(${e})) == 0) or (type(${e}) == 'array' and len(${e}) == 0))`;
24
- }
25
- function u(t, n, r) {
26
- switch (n) {
27
- case "eq": return `${t} == ${o(r)}`;
28
- case "ne": return `${t} != ${o(r)}`;
29
- case "gt": return `${t} > ${o(r)}`;
30
- case "gte": return `${t} >= ${o(r)}`;
31
- case "lt": return `${t} < ${o(r)}`;
32
- case "lte": return `${t} <= ${o(r)}`;
33
- case "contains": return `contains(${t}, ${o(r)})`;
34
- case "not_contains": return `not contains(${t}, ${o(r)})`;
35
- case "starts_with": return `startsWith(${t}, ${o(r)})`;
36
- case "ends_with": return `endsWith(${t}, ${o(r)})`;
37
- case "in": return `${t} in ${c(r)}`;
38
- case "not_in": return `not (${t} in ${c(r)})`;
39
- case "is_empty": return l(t);
40
- case "is_not_empty": return `not ${l(t)}`;
41
- default: throw new e(`Unsupported operator: ${String(n)}`);
42
- }
43
- }
44
- function d(e) {
45
- if (e.kind === "expression") {
46
- let t = e.expression.trim();
47
- return t === "" ? null : t;
48
- }
49
- let t = e.subject.trim();
50
- if (!a.test(t)) return null;
51
- try {
52
- return u(t, e.operator, e.value);
53
- } catch {
54
- return null;
55
- }
56
- }
57
- function f(e) {
58
- let t = e.conditions.map((e) => d(e)).filter((e) => e !== null);
59
- return t.length === 0 ? null : t.join(" and ");
60
- }
61
- function p(e) {
62
- let t = (e.conditionGroups ?? []).map((e) => f(e)).filter((e) => e !== null);
63
- return t.length === 0 ? null : t.map((e) => `(${e})`).join(" or ");
64
- }
65
- function m(e, t, n) {
66
- let r = e.toSorted((e, t) => e.priority - t.priority);
67
- for (let e of r) {
68
- if (e.isDefault) continue;
69
- let r = p(e);
70
- if (r !== null && h(n, r, t)) return {
71
- branchId: e.id,
72
- matched: !0
73
- };
74
- }
75
- return {
76
- branchId: r.find((e) => e.isDefault)?.id ?? null,
77
- matched: !1
78
- };
79
- }
80
- function h(e, t, n) {
81
- try {
82
- return e.evaluate(t, n) === !0;
83
- } catch {
84
- return !1;
85
- }
86
- }
87
- async function g(e, n) {
88
- return m(e, n, await t());
89
- }
90
- //#endregion
91
- export { p as compileBranch, d as compileCondition, f as compileGroup, g as selectBranch, m as selectBranchWith, o as toZenLiteral };
@@ -1,64 +0,0 @@
1
- /*! @vef-framework-react/expression v2.4.0 made by Venus | 2026-06-15T15:10:07.346Z */
2
- import { getEngineSync as e, loadEngine as t } from "./loader.js";
3
- import { localizeCompletionInfo as n, localizeSourceLabel as r } from "./messages.js";
4
- //#region src/engine/intellisense.ts
5
- function i(e) {
6
- let t = e.split(" at "), n = t.length <= 1 ? void 0 : t.at(-1);
7
- if (n === void 0) return null;
8
- let [r, i] = n.replace("(", "").replace(")", "").split(", "), a = r === void 0 ? NaN : Number.parseInt(r, 10);
9
- if (Number.isNaN(a)) return null;
10
- if (i === void 0) return a;
11
- let o = Number.parseInt(i, 10);
12
- return Number.isNaN(o) ? a : [a, o];
13
- }
14
- function a(e, t) {
15
- if (e == null) return null;
16
- let n = e, a = typeof n.source == "string" ? n.source : String(e), o = i(a), [s, c] = o === null ? [0, t.length] : typeof o == "number" ? [o, o] : o;
17
- return {
18
- from: s,
19
- to: c,
20
- message: a,
21
- source: r(n.type)
22
- };
23
- }
24
- function o(e) {
25
- return Array.isArray(e) ? e.flatMap((e) => {
26
- let t = e;
27
- return typeof t.label != "string" || t.label === "" ? [] : [{
28
- type: t.type === "method" || t.type === "variable" ? t.type : "function",
29
- label: t.label,
30
- detail: typeof t.detail == "string" ? t.detail.replaceAll("`", "") : "",
31
- info: n(typeof t.info == "string" ? t.info : ""),
32
- boost: typeof t.boost == "number" ? t.boost : null,
33
- methodFor: typeof t.methodFor == "string" ? t.methodFor : null
34
- }];
35
- }) : [];
36
- }
37
- async function s(e, n) {
38
- let r = await t();
39
- return a(n === "unary" ? r.validateUnary(e) : r.validate(e), e);
40
- }
41
- function c(t, n) {
42
- let r = e();
43
- return a(n === "unary" ? r.validateUnary(t) : r.validate(t), t);
44
- }
45
- async function l() {
46
- return o((await t()).getCompletions());
47
- }
48
- function u() {
49
- return o(e().getCompletions());
50
- }
51
- async function d(e, n, r) {
52
- return (await t()).analyze(e, n, r === "unary");
53
- }
54
- function f(t, n, r) {
55
- return e().analyze(t, n, r === "unary");
56
- }
57
- async function p(e, n) {
58
- return (await t()).satisfies(e, n);
59
- }
60
- function m(t, n) {
61
- return e().satisfies(t, n);
62
- }
63
- //#endregion
64
- export { d as analyzeTypes, f as analyzeTypesSync, l as getCompletionItems, u as getCompletionItemsSync, s as getDiagnostics, c as getDiagnosticsSync, p as satisfiesType, m as satisfiesTypeSync };
@@ -1,122 +0,0 @@
1
- /*! @vef-framework-react/expression v2.4.0 made by Venus | 2026-06-15T15:10:07.346Z */
2
- //#region src/engine/messages.ts
3
- var e = "en-US";
4
- function t(t) {
5
- e = t;
6
- }
7
- function n() {
8
- return e;
9
- }
10
- var r = {
11
- "Returns the length of variable": "返回变量的长度",
12
- "Checks if variable contains a needle": "检查变量是否包含指定元素",
13
- "Flattens an array": "将数组扁平化",
14
- "Merges multiple objects into one.": "将多个对象合并为一个。",
15
- "Deeply merges multiple objects into one.": "将多个对象深度合并为一个。",
16
- "Converts all characters in a string to uppercase": "将字符串中所有字符转换为大写",
17
- "Converts all characters in a string to lowercase": "将字符串中所有字符转换为小写",
18
- "Returns the string with leading and trailing whitespace removed": "返回去除首尾空白后的字符串",
19
- "Returns true if the string starts with the specified prefix": "若字符串以指定前缀开头则返回 true",
20
- "Returns true if the string ends with the specified suffix": "若字符串以指定后缀结尾则返回 true",
21
- "Returns true if the string matches the specified pattern": "若字符串匹配指定模式则返回 true",
22
- "Extracts matching substrings according to a pattern": "按模式提取匹配的子串",
23
- "Performs a fuzzy search of the needle in the haystack, and returns the match score(s).": "在目标中对关键字进行模糊搜索,并返回匹配得分。",
24
- "Splits a string into an array of substrings using the specified delimiter.": "使用指定分隔符将字符串拆分为子串数组。",
25
- "Returns the absolute value of a number": "返回数字的绝对值",
26
- "Returns the sum of all elements in the input array.": "返回输入数组中所有元素之和。",
27
- "Calculates the average of all elements in the input array.": "计算输入数组中所有元素的平均值。",
28
- "Returns the smallest of the elements in the input array.": "返回输入数组中的最小元素。",
29
- "Returns the largest of the elements in the input array.": "返回输入数组中的最大元素。",
30
- "Generates a random number between 0 (inclusive) and max (inclusive).": "生成 0 到 max(均包含)之间的随机数。",
31
- "Calculates the median value of all elements in the input array.": "计算输入数组中所有元素的中位数。",
32
- "Finds the mode(s) of the input array, which are the most frequent element(s).": "求输入数组的众数,即出现最频繁的元素。",
33
- "Rounds a number down to the nearest integer.": "向下取整到最接近的整数。",
34
- "Rounds a number up to the nearest integer.": "向上取整到最接近的整数。",
35
- "Rounds a number to a specified number of decimal places.": "将数字四舍五入到指定的小数位数。",
36
- "Truncates a number to a specified number of decimal places.": "将数字截断到指定的小数位数。",
37
- "Checks if the given value is of a numeric type.": "检查给定值是否为数值类型。",
38
- "Converts the given value to a string.": "将给定值转换为字符串。",
39
- "Converts the given value to a number.": "将给定值转换为数字。",
40
- "Converts the given value to a boolean.": "将给定值转换为布尔值。",
41
- "Returns a string representing the data type of the value.": "返回表示该值数据类型的字符串。",
42
- "Returns an array of a given object's own enumerable property names.": "返回由给定对象自身可枚举属性名组成的数组。",
43
- "Returns an array of a given object's own enumerable property values.": "返回由给定对象自身可枚举属性值组成的数组。",
44
- "Returns a new date time instance.": "返回一个新的日期时间实例。",
45
- "Converts a numeric timestamp to a unix timestamp.": "将数值时间戳转换为 Unix 时间戳。",
46
- "Extracts the time from a numeric timestamp and returns it as a seconds from beginning of day.": "从数值时间戳中提取时间,以当天起始的秒数返回。",
47
- "e.g. 1h30min": "例如 1h30min",
48
- "Extracts the year from a given timestamp.": "从给定时间戳中提取年份。",
49
- "Gets the day of the week from a given timestamp, where Sunday might be 0.": "获取给定时间戳的星期几(周日可能为 0)。",
50
- "Extracts the day of the month from a given timestamp.": "从给定时间戳中提取当月的日期。",
51
- "Gets the day of the year from a given timestamp.": "获取给定时间戳在一年中的第几天。",
52
- "Calculates the week of the year from a given timestamp.": "计算给定时间戳在一年中的第几周。",
53
- "Extracts the month from a given timestamp, typically with January as 1.": "从给定时间戳中提取月份(通常 1 月为 1)。",
54
- "Converts the month from a given timestamp into its string representation (e.g., 'Jan').": "将给定时间戳的月份转换为字符串表示(例如 'Jan')。",
55
- "Converts a timestamp to a human-readable date string.": "将时间戳转换为人类可读的日期字符串。",
56
- "Converts the day of the week from a given timestamp into its string representation (e.g., 'Mon').": "将给定时间戳的星期几转换为字符串表示(例如 'Mon')。",
57
- "Returns the timestamp representing the start of a specified unit (e.g., day, month, year) based on a given timestamp.": "返回给定时间戳在指定单位(如日、月、年)起始处的时间戳。",
58
- "Returns the timestamp representing the end of a specified unit (e.g., day, month, year) based on a given timestamp.": "返回给定时间戳在指定单位(如日、月、年)结束处的时间戳。",
59
- "Checks if all elements in the array satisfy the condition defined in the callback.": "检查数组中所有元素是否都满足回调中定义的条件。",
60
- "Checks if no elements in the array satisfy the condition defined in the callback.": "检查数组中是否没有任何元素满足回调中定义的条件。",
61
- "Checks if at least one element in the array satisfies the condition defined in the callback.": "检查数组中是否至少有一个元素满足回调中定义的条件。",
62
- "Checks if exactly one element in the array satisfies the condition defined in the callback.": "检查数组中是否恰好有一个元素满足回调中定义的条件。",
63
- "Creates a new array with all elements that satisfy the condition defined in the callback.": "创建一个仅包含满足回调中定义条件的元素的新数组。",
64
- "Creates a new array populated with the results of calling the provided function on every element in the calling array.": "创建一个新数组,其元素为对原数组每个元素调用所提供函数的结果。",
65
- "First maps each element using a mapping function, then flattens the result into a new array.": "先用映射函数处理每个元素,再将结果扁平化为新数组。",
66
- "Counts the number of elements in the array that satisfy the condition defined in the callback.": "统计数组中满足回调中定义条件的元素个数。",
67
- "Adds time to a date": "为日期增加时间",
68
- "Subtracts time from a date": "从日期中减去时间",
69
- "Sets a specific unit of time on a date": "设置日期的某个时间单位",
70
- "Formats a date into a string representation": "将日期格式化为字符串",
71
- "Returns the start of a specified time unit for a date": "返回日期在指定时间单位上的起始",
72
- "Returns the end of a specified time unit for a date": "返回日期在指定时间单位上的结束",
73
- "Calculates the difference between two dates": "计算两个日期之间的差值",
74
- "Converts a date to a different timezone": "将日期转换到不同的时区",
75
- "Checks if two dates are the same": "检查两个日期是否相同",
76
- "Checks if a date is before another date": "检查日期是否早于另一个日期",
77
- "Checks if a date is after another date": "检查日期是否晚于另一个日期",
78
- "Checks if a date is the same as or before another date": "检查日期是否等于或早于另一个日期",
79
- "Checks if a date is the same as or after another date": "检查日期是否等于或晚于另一个日期",
80
- "Gets the seconds of a date": "获取日期的秒",
81
- "Gets the minutes of a date": "获取日期的分钟",
82
- "Gets the hours of a date": "获取日期的小时",
83
- "Gets the day of the month for a date": "获取日期在当月的第几天",
84
- "Gets the day of the year for a date": "获取日期在当年的第几天",
85
- "Gets the week of the year for a date": "获取日期在当年的第几周",
86
- "Gets the day of the week for a date": "获取日期的星期几",
87
- "Gets the month for a date": "获取日期的月份",
88
- "Gets the quarter for a date": "获取日期所在的季度",
89
- "Gets the year for a date": "获取日期的年份",
90
- "Gets the Unix timestamp for a date": "获取日期的 Unix 时间戳",
91
- "Gets the timezone offset name for a date": "获取日期的时区偏移名称",
92
- "Checks if a date is valid": "检查日期是否有效",
93
- "Checks if a date is yesterday": "检查日期是否为昨天",
94
- "Checks if a date is today": "检查日期是否为今天",
95
- "Checks if a date is tomorrow": "检查日期是否为明天",
96
- "Checks if the year of a date is a leap year": "检查日期所在年份是否为闰年"
97
- };
98
- function i(t) {
99
- return e !== "zh-CN" || t === "" ? t : r[t] ?? t;
100
- }
101
- var a = {
102
- "en-US": {
103
- lexerError: "Lexer error",
104
- parserError: "Parser error",
105
- compilerError: "Compiler error",
106
- vmError: "VM error",
107
- fallback: "Error"
108
- },
109
- "zh-CN": {
110
- lexerError: "词法错误",
111
- parserError: "语法错误",
112
- compilerError: "编译错误",
113
- vmError: "运行时错误",
114
- fallback: "错误"
115
- }
116
- };
117
- function o(t) {
118
- let n = a[e];
119
- return (t === void 0 ? void 0 : n[t]) ?? n.fallback;
120
- }
121
- //#endregion
122
- export { n as getExpressionLocale, i as localizeCompletionInfo, o as localizeSourceLabel, t as setExpressionLocale };
@@ -1,6 +0,0 @@
1
- /*! @vef-framework-react/expression v2.4.0 made by Venus | 2026-06-15T15:10:07.346Z */
2
- import { createContext as e } from "react";
3
- //#region src/react/context.ts
4
- var t = e(null);
5
- //#endregion
6
- export { t as ExpressionEngineContext };
@@ -1,4 +0,0 @@
1
- /*! @vef-framework-react/expression v2.4.0 made by Venus | 2026-06-15T15:10:07.346Z */
2
- import { ExpressionEngineProvider as e } from "./provider.js";
3
- import { useExpressionEngine as t } from "./use-expression-engine.js";
4
- export { e as ExpressionEngineProvider, t as useExpressionEngine };
@@ -1,20 +0,0 @@
1
- /*! @vef-framework-react/expression v2.4.0 made by Venus | 2026-06-15T15:10:07.346Z */
2
- import { getEngineError as e, getEngineSync as t, isEngineReady as n, loadEngine as r } from "../engine/loader.js";
3
- import { setExpressionLocale as i } from "../engine/messages.js";
4
- import { ExpressionEngineContext as a } from "./context.js";
5
- import { Suspense as o } from "react";
6
- import { jsx as s } from "react/jsx-runtime";
7
- //#region src/react/provider.tsx
8
- function c({ children: i }) {
9
- if (!n()) throw e() || r();
10
- return /* @__PURE__ */ s(a, {
11
- value: t(),
12
- children: i
13
- });
14
- }
15
- var l = ({ children: e, fallback: t = null, locale: n }) => (n !== void 0 && i(n), /* @__PURE__ */ s(o, {
16
- fallback: t,
17
- children: /* @__PURE__ */ s(c, { children: e })
18
- }));
19
- //#endregion
20
- export { l as ExpressionEngineProvider };
@@ -1,11 +0,0 @@
1
- /*! @vef-framework-react/expression v2.4.0 made by Venus | 2026-06-15T15:10:07.346Z */
2
- import { ExpressionEngineContext as e } from "./context.js";
3
- import { use as t } from "react";
4
- //#region src/react/use-expression-engine.ts
5
- function n() {
6
- let n = t(e);
7
- if (!n) throw Error("useExpressionEngine must be used within <ExpressionEngineProvider>.");
8
- return n;
9
- }
10
- //#endregion
11
- export { n as useExpressionEngine };
@@ -1,49 +0,0 @@
1
- import { ExpressionContext, ExpressionEngine } from '../engine/loader';
2
- import { BranchSelection, ConditionBranchInput, ConditionGroupInput, ConditionInput } from './types';
3
- /**
4
- * Serialize a JavaScript value into a ZEN literal. Nullish becomes `null`;
5
- * numbers / booleans / bigints are emitted verbatim; strings are quoted via
6
- * {@link encodeZenString}; arrays become `[a, b, ...]`.
7
- *
8
- * Throws {@link ExpressionError} for a value with no faithful ZEN
9
- * representation — an object, symbol, or function, or a string containing both
10
- * quote styles. Callers that need a sentinel instead of a throw go through
11
- * {@link compileCondition}, which degrades such a value to a non-compiling
12
- * (null) condition.
13
- */
14
- export declare function toZenLiteral(value: unknown): string;
15
- /**
16
- * Compile a single condition into a ZEN boolean expression. Field conditions map
17
- * their operator to ZEN; expression conditions pass through verbatim. Returns
18
- * `null` when the condition is empty, its subject is not an identifier path, or
19
- * its value has no ZEN representation.
20
- */
21
- export declare function compileCondition(condition: ConditionInput): string | null;
22
- /**
23
- * Compile a condition group (its conditions joined with AND). Returns `null`
24
- * when the group has no compilable conditions.
25
- */
26
- export declare function compileGroup(group: ConditionGroupInput): string | null;
27
- /**
28
- * Compile a branch's condition groups into a single ZEN expression (groups
29
- * joined with OR). Returns `null` when the branch has no compilable groups
30
- * (e.g. a default branch).
31
- */
32
- export declare function compileBranch(branch: ConditionBranchInput): string | null;
33
- /**
34
- * Pick the matching branch for the given context using a pre-loaded engine.
35
- * Non-default branches are tested in ascending `priority` order; the first whose
36
- * compiled expression evaluates to `true` wins. Falls back to the default
37
- * branch, or a `null` id when neither matches.
38
- *
39
- * A branch whose expression throws for the given context (e.g. ZEN's `>`
40
- * throws when the subject is missing or non-numeric) is treated as not matching
41
- * rather than propagating — so a missing field degrades to the default branch
42
- * instead of crashing the caller.
43
- */
44
- export declare function selectBranchWith(branches: ConditionBranchInput[], context: ExpressionContext, engine: Pick<ExpressionEngine, "evaluate" | "validate">): BranchSelection;
45
- /**
46
- * Pick the matching branch for the given context, loading the ZEN engine on
47
- * first use. See {@link selectBranchWith} for the selection semantics.
48
- */
49
- export declare function selectBranch(branches: ConditionBranchInput[], context: ExpressionContext): Promise<BranchSelection>;
@@ -1,77 +0,0 @@
1
- /**
2
- * Structural shapes for the visual condition model compiled to ZEN. They mirror
3
- * the condition types used in the form and flow editors so a host can map those
4
- * definitions to {@link compileCondition} / {@link selectBranch} without this
5
- * package depending on either editor. The editors keep a flat working model for
6
- * form ergonomics (a row can hold both a half-typed field triple and an
7
- * expression while the author toggles between them); this discriminated input is
8
- * the narrowed, compiler-facing shape where each kind carries only what it uses.
9
- */
10
- /**
11
- * The closed operator vocabulary understood by {@link compileCondition}, as a
12
- * runtime constant so validators can build allow-lists from it instead of
13
- * re-declaring the set. The {@link ConditionOperator} type derives from this
14
- * array — one definition site for both the type and the runtime list.
15
- */
16
- export declare const CONDITION_OPERATORS: readonly ["eq", "ne", "gt", "gte", "lt", "lte", "contains", "not_contains", "starts_with", "ends_with", "in", "not_in", "is_empty", "is_not_empty"];
17
- /**
18
- * Operators understood by {@link compileCondition}. The compiler maps each to a
19
- * ZEN expression; this closed set is the single source of truth for the operator
20
- * vocabulary (the flow editor shares it instead of re-declaring its own).
21
- */
22
- export type ConditionOperator = typeof CONDITION_OPERATORS[number];
23
- /**
24
- * A field/operator/value condition.
25
- */
26
- export interface FieldConditionInput {
27
- kind: "field";
28
- /**
29
- * The field path the operator tests. Emitted **verbatim** into the compiled
30
- * ZEN source as a path expression (guarded by an identifier-path pattern),
31
- * unlike `value`, which is serialized to a ZEN literal — so callers must supply
32
- * a valid identifier path, not arbitrary user text.
33
- */
34
- subject: string;
35
- operator: ConditionOperator;
36
- value: unknown;
37
- }
38
- /**
39
- * A raw ZEN expression condition, passed through to the engine verbatim.
40
- */
41
- export interface ExpressionConditionInput {
42
- kind: "expression";
43
- expression: string;
44
- }
45
- /**
46
- * A single condition: either a field/operator/value triple or a raw expression.
47
- */
48
- export type ConditionInput = FieldConditionInput | ExpressionConditionInput;
49
- /**
50
- * A group of conditions, combined with AND.
51
- */
52
- export interface ConditionGroupInput {
53
- conditions: ConditionInput[];
54
- }
55
- /**
56
- * A branch guarded by one or more condition groups (combined with OR).
57
- */
58
- export interface ConditionBranchInput {
59
- id: string;
60
- priority: number;
61
- isDefault?: boolean;
62
- conditionGroups?: ConditionGroupInput[];
63
- }
64
- /**
65
- * The branch chosen by {@link selectBranch}. `matched` is true only when a
66
- * non-default branch's expression evaluated true (then `branchId` is that
67
- * branch's id). On the default-branch fallback `matched` is false while
68
- * `branchId` is the default's id; `branchId` is null only when nothing matched
69
- * and there is no default branch.
70
- */
71
- export type BranchSelection = {
72
- matched: true;
73
- branchId: string;
74
- } | {
75
- matched: false;
76
- branchId: string | null;
77
- };
@@ -1,123 +0,0 @@
1
- import { VariableTypeJson } from '@gorules/zen-engine-wasm';
2
- /**
3
- * Whether an expression is a standard value expression or a unary (test) expression.
4
- */
5
- export type ExpressionMode = "standard" | "unary";
6
- /**
7
- * A ZEN type descriptor — the shape the engine understands for type-aware
8
- * completion and validation. Structurally identical to the wasm
9
- * `VariableTypeJson`: a primitive (`"String"`, `"Number"`, `"Bool"`, ...) or one
10
- * of `{ Object }`, `{ Array }`, `{ Const }`, `{ Enum }`.
11
- */
12
- export type ExpressionType = VariableTypeJson;
13
- /**
14
- * A single syntax / type diagnostic, positioned by character offset.
15
- */
16
- export interface ExpressionDiagnostic {
17
- /**
18
- * Start offset in the source.
19
- */
20
- from: number;
21
- /**
22
- * End offset in the source.
23
- */
24
- to: number;
25
- /**
26
- * Human-readable error message.
27
- */
28
- message: string;
29
- /**
30
- * Diagnostic origin label (e.g. `"Parser error"`).
31
- */
32
- source: string;
33
- }
34
- /**
35
- * An autocomplete suggestion for a ZEN built-in (function / method / variable).
36
- */
37
- export interface ExpressionCompletion {
38
- type: "function" | "method" | "variable";
39
- label: string;
40
- detail: string;
41
- info: string;
42
- boost: number | null;
43
- /**
44
- * For methods, the type-kind they attach to (e.g. `"Date"`); otherwise `null`.
45
- */
46
- methodFor: string | null;
47
- }
48
- /**
49
- * The inferred type of one span of the source, produced by type-checking.
50
- */
51
- export interface ExpressionTypeSpan {
52
- error: string | null;
53
- kind: ExpressionType;
54
- nodeKind: string;
55
- span: [number, number];
56
- }
57
- /**
58
- * The result of type-checking an expression against a variable context.
59
- */
60
- export interface ExpressionAnalysis {
61
- /**
62
- * The root context type (the variables object).
63
- */
64
- rootKind: ExpressionType;
65
- /**
66
- * Per-span inferred types; `spans[0]` is the whole-expression result type.
67
- */
68
- spans: ExpressionTypeSpan[];
69
- }
70
- /**
71
- * Parse a trailing `... at (from, to)` / `... at pos` position out of a ZEN error
72
- * message. Returns a `[from, to]` range, a single offset, or `null` when absent.
73
- */
74
- export declare function extractPosition(message: string): [number, number] | number | null;
75
- /**
76
- * Normalize the wasm validate payload (`null` or `{ type, source }`) into a
77
- * positioned {@link ExpressionDiagnostic}, or `null` when the expression is valid.
78
- */
79
- export declare function normalizeDiagnostic(raw: unknown, source: string): ExpressionDiagnostic | null;
80
- /**
81
- * Normalize the wasm `getCompletions` payload into a typed list, dropping
82
- * malformed entries and stripping the backtick markers ZEN wraps type names in.
83
- */
84
- export declare function normalizeCompletions(raw: unknown): ExpressionCompletion[];
85
- /**
86
- * Validate an expression, loading the engine on first use. Resolves to `null`
87
- * when the expression is valid, or a positioned diagnostic otherwise.
88
- */
89
- export declare function getDiagnostics(expression: string, mode: ExpressionMode): Promise<ExpressionDiagnostic | null>;
90
- /**
91
- * Synchronous {@link getDiagnostics}. Throws `ExpressionNotReadyError` if the
92
- * engine has not loaded yet — use only behind a readiness gate.
93
- */
94
- export declare function getDiagnosticsSync(expression: string, mode: ExpressionMode): ExpressionDiagnostic | null;
95
- /**
96
- * Return the ZEN built-in completion list, loading the engine on first use.
97
- */
98
- export declare function getCompletionItems(): Promise<ExpressionCompletion[]>;
99
- /**
100
- * Synchronous {@link getCompletionItems}. Throws `ExpressionNotReadyError` if the
101
- * engine has not loaded yet.
102
- */
103
- export declare function getCompletionItemsSync(): ExpressionCompletion[];
104
- /**
105
- * Type-check an expression against a `variables` context, loading the engine on
106
- * first use. See {@link ExpressionAnalysis}.
107
- */
108
- export declare function analyzeTypes(variables: ExpressionType, source: string, mode: ExpressionMode): Promise<ExpressionAnalysis>;
109
- /**
110
- * Synchronous {@link analyzeTypes}. Throws `ExpressionNotReadyError` if the
111
- * engine has not loaded yet.
112
- */
113
- export declare function analyzeTypesSync(variables: ExpressionType, source: string, mode: ExpressionMode): ExpressionAnalysis;
114
- /**
115
- * Whether `actual` satisfies (is assignable to) `expected`, loading the engine on
116
- * first use. Used for expected-return-type validation.
117
- */
118
- export declare function satisfiesType(actual: ExpressionType, expected: ExpressionType): Promise<boolean>;
119
- /**
120
- * Synchronous {@link satisfiesType}. Throws `ExpressionNotReadyError` if the
121
- * engine has not loaded yet.
122
- */
123
- export declare function satisfiesTypeSync(actual: ExpressionType, expected: ExpressionType): boolean;
@@ -1,28 +0,0 @@
1
- /**
2
- * The display language for engine-produced text (built-in descriptions and
3
- * diagnostic labels). Defaults to `"en-US"`; a host opts into Chinese with
4
- * {@link setExpressionLocale}. Identifiers, type signatures and the wasm's own
5
- * error message bodies are never translated — only descriptive prose is.
6
- */
7
- export type ExpressionLocale = "en-US" | "zh-CN";
8
- /**
9
- * Set the active locale for engine-produced descriptive text. Module-global (the
10
- * sync editor accessors read it without a React context), mirroring the engine
11
- * singleton itself. Defaults to `"en-US"` so published consumers are unaffected.
12
- */
13
- export declare function setExpressionLocale(locale: ExpressionLocale): void;
14
- /**
15
- * The active locale set by {@link setExpressionLocale}.
16
- */
17
- export declare function getExpressionLocale(): ExpressionLocale;
18
- /**
19
- * Translate a built-in's English `info` description to the active locale, or
20
- * return it unchanged when the locale is English, the description is empty, or no
21
- * translation exists.
22
- */
23
- export declare function localizeCompletionInfo(info: string): string;
24
- /**
25
- * The localized diagnostic origin label for a wasm error `type`
26
- * (`"parserError"` → `"语法错误"`), or the locale's fallback label.
27
- */
28
- export declare function localizeSourceLabel(type?: string): string;
@@ -1,7 +0,0 @@
1
- export { compileBranch, compileCondition, compileGroup, selectBranch, selectBranchWith, toZenLiteral } from './condition/compile';
2
- export { CONDITION_OPERATORS, type BranchSelection, type ConditionBranchInput, type ConditionGroupInput, type ConditionInput, type ConditionOperator, type ExpressionConditionInput, type FieldConditionInput } from './condition/types';
3
- export { ExpressionError, ExpressionNotReadyError } from './engine/errors';
4
- export { evaluate, evaluateSync, evaluateUnary, evaluateUnarySync, getCompletions, validate, validateUnary } from './engine/evaluate';
5
- export { analyzeTypes, analyzeTypesSync, getCompletionItems, getCompletionItemsSync, getDiagnostics, getDiagnosticsSync, satisfiesType, satisfiesTypeSync, type ExpressionAnalysis, type ExpressionCompletion, type ExpressionDiagnostic, type ExpressionMode, type ExpressionType, type ExpressionTypeSpan } from './engine/intellisense';
6
- export { configureEngine, getEngineError, getEngineSync, isEngineReady, loadEngine, type ExpressionContext, type ExpressionEngine, type LoadEngineOptions } from './engine/loader';
7
- export { getExpressionLocale, setExpressionLocale, type ExpressionLocale } from './engine/messages';
@@ -1,3 +0,0 @@
1
- import { ExpressionEngine } from '../engine/loader';
2
- import { Context } from 'react';
3
- export declare const ExpressionEngineContext: Context<ExpressionEngine | null>;
@@ -1,2 +0,0 @@
1
- export { ExpressionEngineProvider, type ExpressionEngineProviderProps } from './provider';
2
- export { useExpressionEngine } from './use-expression-engine';
@@ -1,23 +0,0 @@
1
- import { FC, ReactNode } from 'react';
2
- import { ExpressionLocale } from '../engine/messages';
3
- export interface ExpressionEngineProviderProps {
4
- children: ReactNode;
5
- /**
6
- * Shown while the wasm engine is loading. Children do not render — and thus no
7
- * synchronous evaluation runs — until the engine is ready, so anything inside
8
- * can rely on the engine being initialized.
9
- */
10
- fallback?: ReactNode;
11
- /**
12
- * Language for engine-produced descriptive text (built-in descriptions and
13
- * diagnostic labels). Omitted leaves the module default (`"en-US"`) untouched.
14
- * Equivalent to calling {@link setExpressionLocale} — provided here for hosts
15
- * that already wrap their tree in this provider.
16
- */
17
- locale?: ExpressionLocale;
18
- }
19
- /**
20
- * Loads the ZEN engine and gates its subtree behind `<Suspense>` until the wasm
21
- * is initialized. Descendants read the engine via {@link useExpressionEngine}.
22
- */
23
- export declare const ExpressionEngineProvider: FC<ExpressionEngineProviderProps>;
@@ -1,7 +0,0 @@
1
- import { ExpressionEngine } from '../engine/loader';
2
- /**
3
- * Return the initialized {@link ExpressionEngine}. Must be rendered under
4
- * `<ExpressionEngineProvider>`, which suspends until the wasm engine is ready —
5
- * so the returned engine is always safe to evaluate against synchronously.
6
- */
7
- export declare function useExpressionEngine(): ExpressionEngine;