@gorules/zen-engine 2.0.2 → 2.1.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.
- package/index.d.ts +108 -154
- package/index.js +1 -2
- package/package.json +10 -10
package/index.d.ts
CHANGED
|
@@ -21,7 +21,7 @@ export type PolicyRenameTarget =
|
|
|
21
21
|
export type PolicyCursorTarget =
|
|
22
22
|
| { kind: 'expression'; id: string }
|
|
23
23
|
| { kind: 'assertionOutput' }
|
|
24
|
-
| { kind: 'expressionKey' }
|
|
24
|
+
| { kind: 'expressionKey'; id?: string }
|
|
25
25
|
| { kind: 'matchTarget' }
|
|
26
26
|
| { kind: 'matchValue'; id: string }
|
|
27
27
|
| { kind: 'decisionTableHead'; col: string }
|
|
@@ -69,7 +69,6 @@ export type PolicyDiagnosticCode =
|
|
|
69
69
|
| 'UNRESOLVED_FUNCTION_TYPE'
|
|
70
70
|
| 'IMPLICIT_ANY'
|
|
71
71
|
| 'UNCHECKED_NODE'
|
|
72
|
-
| 'NULLABILITY_DIVERGENCE'
|
|
73
72
|
| 'REDUNDANT_NULLISH'
|
|
74
73
|
| 'REPEATED_DERIVATION'
|
|
75
74
|
| 'PREFER_MATCH'
|
|
@@ -92,153 +91,100 @@ export type PolicyVariableType =
|
|
|
92
91
|
| { type: 'object'; fields: Record<string, PolicyVariableType> }
|
|
93
92
|
| { type: 'nullable'; inner: PolicyVariableType };
|
|
94
93
|
|
|
95
|
-
/** Language-agnostic symbol key for an infix operator. The client maps the key to a localized phrase. */
|
|
96
|
-
export type NlOpSym =
|
|
97
|
-
| 'gt' | 'gte' | 'lt' | 'lte' | 'eq' | 'ne' | 'in' | 'notIn'
|
|
98
|
-
| 'contains' | 'notContains'
|
|
99
|
-
| 'containsAny' | 'containsAll' | 'containsNone' | 'containsOnly'
|
|
100
|
-
| 'add' | 'sub' | 'mul' | 'div' | 'mod' | 'pow'
|
|
101
|
-
| 'and' | 'or' | 'not' | 'coalesce';
|
|
102
|
-
|
|
103
|
-
/**
|
|
104
|
-
* Structural separator word inside a multi-operand construct (conditional, closure, interval).
|
|
105
|
-
* `has` replaces `where` when an alias-elided closure body leads with a member on the binding
|
|
106
|
-
* ("any drivers has age less than 5"); clients should shorten the op label that follows it.
|
|
107
|
-
*/
|
|
108
|
-
export type NlWordSym = 'if' | 'then' | 'otherwise' | 'in' | 'where' | 'has' | 'rangeAnd';
|
|
109
|
-
|
|
110
|
-
/**
|
|
111
|
-
* Resolved type of a value/field token. `enum` / `array<enum>` carry an `index`
|
|
112
|
-
* into the per-result `enums` table; dedupe the domain once, reference by index.
|
|
113
|
-
*/
|
|
114
|
-
export type NlTypeTag =
|
|
115
|
-
| { t: 'number' }
|
|
116
|
-
| { t: 'string' }
|
|
117
|
-
| { t: 'bool' }
|
|
118
|
-
| { t: 'date' }
|
|
119
|
-
| { t: 'interval' }
|
|
120
|
-
| { t: 'object' }
|
|
121
|
-
| { t: 'null' }
|
|
122
|
-
| { t: 'unknown' }
|
|
123
|
-
| { t: 'enum'; index: number }
|
|
124
|
-
| { t: 'array'; items: NlTypeTag };
|
|
125
|
-
|
|
126
|
-
/** One operator the user may switch to: the symbol for labelling plus its ZEN source form for splicing. */
|
|
127
|
-
export interface NlOpChoice {
|
|
128
|
-
sym: NlOpSym;
|
|
129
|
-
source: string;
|
|
130
|
-
}
|
|
131
|
-
|
|
132
94
|
/**
|
|
133
|
-
*
|
|
134
|
-
* `
|
|
95
|
+
* Slot-aware autocomplete. `PolicyExpressionCursor.pos` passed to `slot()`, every `span` and
|
|
96
|
+
* `replaceSpan` below are UTF-16 code units (JavaScript string offsets), not bytes.
|
|
135
97
|
*/
|
|
136
|
-
export
|
|
98
|
+
export type PolicySlotState =
|
|
99
|
+
| 'start'
|
|
100
|
+
| 'unaryStart'
|
|
101
|
+
| 'value'
|
|
102
|
+
| 'listElement'
|
|
103
|
+
| 'range'
|
|
104
|
+
| 'operator'
|
|
105
|
+
| 'logical'
|
|
106
|
+
| 'argument'
|
|
107
|
+
| 'member'
|
|
108
|
+
| 'closure'
|
|
109
|
+
| 'inString'
|
|
110
|
+
| 'path';
|
|
111
|
+
export type PolicySlotRole = 'unary' | 'condition' | 'value' | 'path';
|
|
112
|
+
/** One enum value: `label` for display, `source` the ready-to-splice ZEN literal (null when unquotable). */
|
|
113
|
+
export interface PolicyValueOption {
|
|
114
|
+
value: string;
|
|
137
115
|
label: string;
|
|
138
|
-
source
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
| {
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
| {
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
| { t: 'intervalClose'; inclusive: boolean }
|
|
193
|
-
| { t: 'code'; source: string };
|
|
194
|
-
|
|
195
|
-
/** A projected token plus its source span (`[start, end)` bytes) and optional widget hint. */
|
|
196
|
-
export interface NlToken {
|
|
197
|
-
token: NlTokenKind;
|
|
198
|
-
span: PolicySpan;
|
|
199
|
-
hint?: NlEditHint;
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
export type NlDiagnosticSource = 'lexer' | 'parser' | 'typeCheck' | 'compiler';
|
|
203
|
-
|
|
204
|
-
export interface NlDiagnostic {
|
|
205
|
-
span: PolicySpan;
|
|
206
|
-
message: string;
|
|
207
|
-
severity: PolicySeverity;
|
|
208
|
-
source: NlDiagnosticSource;
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
/** Result of projecting one expression; `enums` is the dedup table referenced by `NlTypeTag` / `NlEditHint` indices. */
|
|
212
|
-
export interface NlResult {
|
|
213
|
-
id: string;
|
|
214
|
-
tokens: NlToken[];
|
|
215
|
-
enums: NlEnumOption[][];
|
|
216
|
-
diagnostics: NlDiagnostic[];
|
|
217
|
-
/** Resolved `$` type for unary requests (decision-table input cells); present even for empty text. */
|
|
218
|
-
subjectType?: PolicyVariableType;
|
|
219
|
-
/** Labeled options when the unary subject is an enum (dictionary labels applied); present even for empty text. */
|
|
220
|
-
subjectOptions?: NlEnumOption[];
|
|
116
|
+
source: string | null;
|
|
117
|
+
}
|
|
118
|
+
export interface PolicyEnumTable {
|
|
119
|
+
name: string | null;
|
|
120
|
+
options: PolicyValueOption[];
|
|
121
|
+
}
|
|
122
|
+
export interface PolicySlot {
|
|
123
|
+
state: PolicySlotState;
|
|
124
|
+
expected: PolicyVariableType | null;
|
|
125
|
+
operand: PolicyVariableType | null;
|
|
126
|
+
options: PolicyValueOption[];
|
|
127
|
+
operators: string[];
|
|
128
|
+
function: string | null;
|
|
129
|
+
argument: number | null;
|
|
130
|
+
/** `[start, end)` UTF-16 range the accepted suggestion replaces. */
|
|
131
|
+
replaceSpan: PolicySpan;
|
|
132
|
+
inString: string | null;
|
|
133
|
+
listed: string[];
|
|
134
|
+
autoOpen: boolean;
|
|
135
|
+
/** Names bound by enclosing closures at the caret, innermost first (`x` for `as x`, `#` otherwise). */
|
|
136
|
+
locals: Array<{ name: string; type: PolicyVariableType }>;
|
|
137
|
+
}
|
|
138
|
+
export type PolicyLiteralFact =
|
|
139
|
+
| {
|
|
140
|
+
kind: 'enum';
|
|
141
|
+
span: PolicySpan;
|
|
142
|
+
value: string;
|
|
143
|
+
name: string | null;
|
|
144
|
+
label: string;
|
|
145
|
+
valid: boolean;
|
|
146
|
+
enumIndex: number;
|
|
147
|
+
}
|
|
148
|
+
| {
|
|
149
|
+
kind: 'date';
|
|
150
|
+
span: PolicySpan;
|
|
151
|
+
arg:
|
|
152
|
+
| { kind: 'now' }
|
|
153
|
+
| { kind: 'today' }
|
|
154
|
+
| { kind: 'literal'; value: string; valid: boolean; tz?: string }
|
|
155
|
+
| { kind: 'field'; path: string };
|
|
156
|
+
}
|
|
157
|
+
| { kind: 'bool'; span: PolicySpan; value: boolean };
|
|
158
|
+
/** Result of `slot(cursor, text)` and of each `slotBatch` request. */
|
|
159
|
+
export interface PolicySlotResponse {
|
|
160
|
+
/** Whether the source is a complete, syntactically valid expression. */
|
|
161
|
+
complete?: boolean;
|
|
162
|
+
kind: 'standard' | 'unary';
|
|
163
|
+
role: PolicySlotRole;
|
|
164
|
+
/** `$` type for unary cells, otherwise the expected value type. */
|
|
165
|
+
subjectType: PolicyVariableType | null;
|
|
166
|
+
expectedType: PolicyVariableType | null;
|
|
167
|
+
slot: PolicySlot;
|
|
168
|
+
literals: PolicyLiteralFact[];
|
|
169
|
+
enums: PolicyEnumTable[];
|
|
221
170
|
}
|
|
222
|
-
|
|
223
171
|
/**
|
|
224
|
-
* One
|
|
225
|
-
*
|
|
226
|
-
*
|
|
227
|
-
* came from (assertion condition, match arm, decision-table cell `{row, col}`, …).
|
|
172
|
+
* One expression location of a policy or graph, returned by `facts(policyPath)`. `source` is the
|
|
173
|
+
* stored text the facts were computed from; `subjectOptions` lists labeled enum values for an
|
|
174
|
+
* empty unary or value cell.
|
|
228
175
|
*/
|
|
229
|
-
export interface
|
|
176
|
+
export interface PolicyExpressionFacts {
|
|
177
|
+
complete?: boolean;
|
|
230
178
|
blockId: string;
|
|
231
179
|
target: PolicyCursorTarget;
|
|
232
|
-
kind: 'standard' | 'unary';
|
|
233
|
-
/** Expression text this projection was computed from — compare against the editor value to detect staleness. */
|
|
234
180
|
source: string;
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
subjectOptions
|
|
181
|
+
kind: 'standard' | 'unary';
|
|
182
|
+
role: PolicySlotRole;
|
|
183
|
+
subjectType: PolicyVariableType | null;
|
|
184
|
+
expectedType: PolicyVariableType | null;
|
|
185
|
+
literals: PolicyLiteralFact[];
|
|
186
|
+
enums: PolicyEnumTable[];
|
|
187
|
+
subjectOptions: PolicyValueOption[];
|
|
242
188
|
}
|
|
243
189
|
|
|
244
190
|
/**
|
|
@@ -457,12 +403,10 @@ export declare class Workspace {
|
|
|
457
403
|
outputs(req: PolicyScopeRequest): Array<PolicyOutputProperty>
|
|
458
404
|
conditionalSchema(req: PolicyScopeRequest): PolicyConditionalSchema
|
|
459
405
|
inspect(cursor: PolicyExpressionCursor): PolicyInspectResult | null
|
|
460
|
-
nl(policyPath: string): PolicyNlExpression[]
|
|
461
|
-
nlTokenize(cursor: PolicyExpressionCursor, text: string): NlResult | null
|
|
462
406
|
completions(cursor: PolicyExpressionCursor): Array<PolicyCompletion>
|
|
463
407
|
prepareRename(cursor: PolicyExpressionCursor): PolicyPrepareRenameResult | null
|
|
464
408
|
rename(req: PolicyRenameRequest): PolicyEngineEdit[]
|
|
465
|
-
references(target: any): PolicyReferenceSite[]
|
|
409
|
+
references(target: any, origin?: string | undefined | null): PolicyReferenceSite[]
|
|
466
410
|
search(query: string, limit?: number | undefined | null): PolicySearchHit[]
|
|
467
411
|
inputSkeleton(req: PolicyScopeRequest): unknown
|
|
468
412
|
dependencies(target: string, document?: string | undefined | null): PolicyDependencyNode
|
|
@@ -471,6 +415,8 @@ export declare class Workspace {
|
|
|
471
415
|
enhanceGraphTrace(path: string, trace: any): PolicyTrace
|
|
472
416
|
componentMembers(policy: string): Array<string>
|
|
473
417
|
crossComponentWriteConflicts(): Array<PolicyWriteConflict>
|
|
418
|
+
slot(cursor: PolicyExpressionCursor, text: string): PolicySlotResponse | null
|
|
419
|
+
facts(policyPath: string): PolicyExpressionFacts[]
|
|
474
420
|
}
|
|
475
421
|
|
|
476
422
|
export declare class ZenDecision {
|
|
@@ -526,17 +472,6 @@ export declare function evaluateUnaryExpression(expression: string, context: any
|
|
|
526
472
|
|
|
527
473
|
export declare function evaluateUnaryExpressionSync(expression: string, context: any): boolean
|
|
528
474
|
|
|
529
|
-
export declare function nlEncodeString(value: string): string | null
|
|
530
|
-
|
|
531
|
-
export declare function nlTokenizeBatch(requests: NlTokenizeRequest[], rootType: PolicyVariableType, strict?: boolean): NlResult[]
|
|
532
|
-
|
|
533
|
-
export interface NlTokenizeRequest {
|
|
534
|
-
id: string
|
|
535
|
-
expression: string
|
|
536
|
-
unary: boolean
|
|
537
|
-
subjectType?: PolicyVariableType
|
|
538
|
-
}
|
|
539
|
-
|
|
540
475
|
export declare function overrideConfig(config: ZenConfig): void
|
|
541
476
|
|
|
542
477
|
export interface PolicyCompletion {
|
|
@@ -544,6 +479,7 @@ export interface PolicyCompletion {
|
|
|
544
479
|
kind: string
|
|
545
480
|
detail: string
|
|
546
481
|
info: string
|
|
482
|
+
follow?: string
|
|
547
483
|
}
|
|
548
484
|
|
|
549
485
|
export interface PolicyConditionalSchema {
|
|
@@ -562,6 +498,8 @@ export interface PolicyDiagnostic {
|
|
|
562
498
|
span?: PolicySpan
|
|
563
499
|
expressionId?: string
|
|
564
500
|
target?: PolicyCursorTarget
|
|
501
|
+
exprCode?: string
|
|
502
|
+
args?: Record<string, string>
|
|
565
503
|
}
|
|
566
504
|
|
|
567
505
|
export interface PolicyDictionaryEntryInfo {
|
|
@@ -644,6 +582,8 @@ export interface PolicyInspectResult {
|
|
|
644
582
|
span: PolicySpan
|
|
645
583
|
kind: PolicyVariableType
|
|
646
584
|
label: string
|
|
585
|
+
detail?: string
|
|
586
|
+
info?: string
|
|
647
587
|
}
|
|
648
588
|
|
|
649
589
|
export interface PolicyInstanceOf {
|
|
@@ -677,6 +617,7 @@ export interface PolicyRemoveBlockRequest {
|
|
|
677
617
|
export interface PolicyRenameRequest {
|
|
678
618
|
target: PolicyRenameTarget
|
|
679
619
|
newName: string
|
|
620
|
+
origin?: string
|
|
680
621
|
}
|
|
681
622
|
|
|
682
623
|
export interface PolicySchemaGroup {
|
|
@@ -703,6 +644,19 @@ export declare function renderTemplate(template: string, context: any): Promise<
|
|
|
703
644
|
|
|
704
645
|
export declare function renderTemplateSync(template: string, context: any): any
|
|
705
646
|
|
|
647
|
+
export declare function slotBatch(requests: Array<SlotRequest>, strict?: boolean | undefined | null): Array<{ id: string; result: PolicySlotResponse }>
|
|
648
|
+
|
|
649
|
+
export interface SlotRequest {
|
|
650
|
+
id: string
|
|
651
|
+
text: string
|
|
652
|
+
pos: number
|
|
653
|
+
unary: boolean
|
|
654
|
+
role: PolicySlotRole
|
|
655
|
+
scope: PolicyVariableType
|
|
656
|
+
expected?: PolicyVariableType | null
|
|
657
|
+
labels?: Record<string, Record<string, string>> | null
|
|
658
|
+
}
|
|
659
|
+
|
|
706
660
|
export interface ZenConfig {
|
|
707
661
|
nodesInContext?: boolean
|
|
708
662
|
functionTimeoutMillis?: number
|
package/index.js
CHANGED
|
@@ -581,8 +581,7 @@ module.exports.evaluateExpression = nativeBinding.evaluateExpression
|
|
|
581
581
|
module.exports.evaluateExpressionSync = nativeBinding.evaluateExpressionSync
|
|
582
582
|
module.exports.evaluateUnaryExpression = nativeBinding.evaluateUnaryExpression
|
|
583
583
|
module.exports.evaluateUnaryExpressionSync = nativeBinding.evaluateUnaryExpressionSync
|
|
584
|
-
module.exports.nlEncodeString = nativeBinding.nlEncodeString
|
|
585
|
-
module.exports.nlTokenizeBatch = nativeBinding.nlTokenizeBatch
|
|
586
584
|
module.exports.overrideConfig = nativeBinding.overrideConfig
|
|
587
585
|
module.exports.renderTemplate = nativeBinding.renderTemplate
|
|
588
586
|
module.exports.renderTemplateSync = nativeBinding.renderTemplateSync
|
|
587
|
+
module.exports.slotBatch = nativeBinding.slotBatch
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gorules/zen-engine",
|
|
3
3
|
"description": "Open-source Business Rules Engine for Node.js, powered by Rust",
|
|
4
|
-
"version": "2.
|
|
4
|
+
"version": "2.1.1",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"browser": "browser.js",
|
|
7
7
|
"types": "./index.d.ts",
|
|
@@ -102,15 +102,15 @@
|
|
|
102
102
|
"resolutions": {
|
|
103
103
|
"form-data@^4.0.0": "4.0.4"
|
|
104
104
|
},
|
|
105
|
-
"gitHead": "
|
|
105
|
+
"gitHead": "2e88387e7a7a70e6bfc77e20c8024d140f0dcee3",
|
|
106
106
|
"optionalDependencies": {
|
|
107
|
-
"@gorules/zen-engine-darwin-x64": "2.
|
|
108
|
-
"@gorules/zen-engine-linux-x64-gnu": "2.
|
|
109
|
-
"@gorules/zen-engine-linux-x64-musl": "2.
|
|
110
|
-
"@gorules/zen-engine-win32-x64-msvc": "2.
|
|
111
|
-
"@gorules/zen-engine-linux-arm64-gnu": "2.
|
|
112
|
-
"@gorules/zen-engine-linux-arm64-musl": "2.
|
|
113
|
-
"@gorules/zen-engine-darwin-arm64": "2.
|
|
114
|
-
"@gorules/zen-engine-wasm32-wasi": "2.
|
|
107
|
+
"@gorules/zen-engine-darwin-x64": "2.1.1",
|
|
108
|
+
"@gorules/zen-engine-linux-x64-gnu": "2.1.1",
|
|
109
|
+
"@gorules/zen-engine-linux-x64-musl": "2.1.1",
|
|
110
|
+
"@gorules/zen-engine-win32-x64-msvc": "2.1.1",
|
|
111
|
+
"@gorules/zen-engine-linux-arm64-gnu": "2.1.1",
|
|
112
|
+
"@gorules/zen-engine-linux-arm64-musl": "2.1.1",
|
|
113
|
+
"@gorules/zen-engine-darwin-arm64": "2.1.1",
|
|
114
|
+
"@gorules/zen-engine-wasm32-wasi": "2.1.1"
|
|
115
115
|
}
|
|
116
116
|
}
|