@rsconcept/domain 1.2.0 → 1.4.0

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 (53) hide show
  1. package/dist/{analyzer-DlSq3Y3r.d.ts → analyzer-BliNe3pV.d.ts} +2 -2
  2. package/dist/{ast-annotations-BiMjkKvz.d.ts → ast-annotations-GOkbNN8F.d.ts} +2 -2
  3. package/dist/{calculator-C9W2jkSx.d.ts → calculator-DFevxZyV.d.ts} +3 -3
  4. package/dist/{error-E1LVq_3w.d.ts → error-deey7EiC.d.ts} +2 -1
  5. package/dist/index.d.ts +6 -6
  6. package/dist/index.js +1 -1
  7. package/dist/library/rsengine.d.ts +2 -3
  8. package/dist/library/rsengine.js +15 -43
  9. package/dist/library/rsengine.js.map +1 -1
  10. package/dist/library/rsform-api.d.ts +1 -1
  11. package/dist/library/rsform.d.ts +1 -1
  12. package/dist/library/rsmodel-api.d.ts +1 -1
  13. package/dist/library/rsmodel-api.js +1 -1
  14. package/dist/library/rsmodel.d.ts +1 -1
  15. package/dist/rslang/ast-annotations.d.ts +1 -1
  16. package/dist/rslang/error.d.ts +1 -1
  17. package/dist/rslang/error.js +1 -0
  18. package/dist/rslang/error.js.map +1 -1
  19. package/dist/rslang/eval/calculator.d.ts +1 -1
  20. package/dist/rslang/eval/calculator.js +1 -1
  21. package/dist/rslang/eval/evaluation-cache.d.ts +1 -1
  22. package/dist/rslang/eval/evaluator.d.ts +2 -2
  23. package/dist/rslang/eval/evaluator.js +17 -11
  24. package/dist/rslang/eval/evaluator.js.map +1 -1
  25. package/dist/rslang/eval/value-api.d.ts +1 -1
  26. package/dist/rslang/eval/value-api.js +1 -1
  27. package/dist/rslang/eval/value.d.ts +2 -2
  28. package/dist/rslang/eval/value.js +2 -2
  29. package/dist/rslang/index.d.ts +6 -6
  30. package/dist/rslang/index.js +1 -1
  31. package/dist/rslang/parser/syntax-errors.d.ts +1 -1
  32. package/dist/rslang/semantic/analyzer.d.ts +1 -1
  33. package/dist/rslang/semantic/type-auditor.d.ts +1 -1
  34. package/dist/rslang/semantic/type-auditor.js +2 -1
  35. package/dist/rslang/semantic/type-auditor.js.map +1 -1
  36. package/dist/rslang/semantic/typification-api.js +1 -1
  37. package/dist/rslang/semantic/typification-api.js.map +1 -1
  38. package/dist/rslang/semantic/value-auditor.d.ts +1 -1
  39. package/dist/{value-CTjX6825.d.ts → value-BduA_ZGp.d.ts} +8 -2
  40. package/dist/{value-api-Bw-SgaYY.d.ts → value-api-B6T6f4Ia.d.ts} +2 -2
  41. package/dist/{value-B8UtCqaK.js → value-ybFBRuz6.js} +14 -3
  42. package/dist/{value-B8UtCqaK.js.map → value-ybFBRuz6.js.map} +1 -1
  43. package/package.json +2 -2
  44. package/src/library/rsengine.ts +14 -59
  45. package/src/rslang/error.ts +1 -0
  46. package/src/rslang/eval/calculator.test.ts +8 -0
  47. package/src/rslang/eval/evaluator.test.ts +5 -1
  48. package/src/rslang/eval/evaluator.ts +22 -13
  49. package/src/rslang/eval/value.ts +14 -1
  50. package/src/rslang/semantic/type-auditor.test.ts +21 -1
  51. package/src/rslang/semantic/type-auditor.ts +2 -1
  52. package/src/rslang/semantic/typification-api.test.ts +11 -2
  53. package/src/rslang/semantic/typification-api.ts +1 -1
@@ -1,6 +1,6 @@
1
1
  import { t as AstNode } from "./ast-C8sIpKdL.js";
2
2
  import { f as ExpressionType, g as TypeClass } from "./typification-Dk-fisgO.js";
3
- import { i as RSErrorDescription } from "./error-E1LVq_3w.js";
3
+ import { i as RSErrorDescription } from "./error-deey7EiC.js";
4
4
  import { t as ValueClass } from "./value-class-CNI-lqXJ.js";
5
5
 
6
6
  //#region src/rslang/semantic/analyzer.d.ts
@@ -36,4 +36,4 @@ declare class RSLangAnalyzer {
36
36
  }
37
37
  //#endregion
38
38
  export { RSLangAnalyzer as a, AnalysisOptions as i, AnalysisFast as n, AnalysisFull as r, AnalysisBase as t };
39
- //# sourceMappingURL=analyzer-DlSq3Y3r.d.ts.map
39
+ //# sourceMappingURL=analyzer-BliNe3pV.d.ts.map
@@ -1,6 +1,6 @@
1
1
  import { t as AstNode } from "./ast-C8sIpKdL.js";
2
2
  import { f as ExpressionType } from "./typification-Dk-fisgO.js";
3
- import { a as RSErrorInfo, r as RSErrorCode } from "./error-E1LVq_3w.js";
3
+ import { a as RSErrorInfo, r as RSErrorCode } from "./error-deey7EiC.js";
4
4
 
5
5
  //#region src/rslang/ast-annotations.d.ts
6
6
  /** Appends {@link ExpressionType} onto the node's `annotation.rsType`. */
@@ -13,4 +13,4 @@ declare function annotateError(node: AstNode, code: RSErrorCode, params?: readon
13
13
  declare function readErrorAnnotation(node: AstNode): RSErrorInfo | null;
14
14
  //#endregion
15
15
  export { readTypeAnnotation as i, annotateType as n, readErrorAnnotation as r, annotateError as t };
16
- //# sourceMappingURL=ast-annotations-BiMjkKvz.d.ts.map
16
+ //# sourceMappingURL=ast-annotations-GOkbNN8F.d.ts.map
@@ -1,7 +1,7 @@
1
1
  import { t as AstNode } from "./ast-C8sIpKdL.js";
2
2
  import { f as ExpressionType } from "./typification-Dk-fisgO.js";
3
- import { i as RSErrorDescription } from "./error-E1LVq_3w.js";
4
- import { c as Value } from "./value-CTjX6825.js";
3
+ import { i as RSErrorDescription } from "./error-deey7EiC.js";
4
+ import { l as Value } from "./value-BduA_ZGp.js";
5
5
 
6
6
  //#region src/rslang/eval/calculator.d.ts
7
7
  /** Result of calculator evaluation. */
@@ -36,4 +36,4 @@ declare class RSCalculator {
36
36
  }
37
37
  //#endregion
38
38
  export { CalculatorResult as n, RSCalculator as r, CalculatorEvaluateOptions as t };
39
- //# sourceMappingURL=calculator-C9W2jkSx.d.ts.map
39
+ //# sourceMappingURL=calculator-DFevxZyV.d.ts.map
@@ -74,6 +74,7 @@ declare const RSErrorCode: {
74
74
  readonly calcInvalidDebool: 33029;
75
75
  readonly iterateInfinity: 33030;
76
76
  readonly calculationNotSupported: 33031;
77
+ readonly calcInvalidData: 33032;
77
78
  readonly cstEmptyDerived: 34913;
78
79
  readonly definitionNotAllowed: 34914;
79
80
  };
@@ -84,4 +85,4 @@ declare function getRSErrorPrefix(code: RSErrorCode): string;
84
85
  declare function isCritical(code: RSErrorCode): boolean;
85
86
  //#endregion
86
87
  export { RSErrorInfo as a, RSErrorDescription as i, RSErrorClass as n, getRSErrorPrefix as o, RSErrorCode as r, isCritical as s, ErrorReporter as t };
87
- //# sourceMappingURL=error-E1LVq_3w.d.ts.map
88
+ //# sourceMappingURL=error-deey7EiC.d.ts.map
package/dist/index.d.ts CHANGED
@@ -9,15 +9,15 @@ import { a as TOKEN_ERROR, c as flattenAst, d as printAst, f as visitAstDFS, i a
9
9
  import { t as Branded } from "./branded-ZlzIcxzu.js";
10
10
  import { n as generateStub, t as applyHash_fnv1a } from "./hash-Y8I4c6Al.js";
11
11
  import { O as makeTypePath, b as Typification, d as EmptySetT, f as ExpressionType, g as TypeClass, m as LogicT, t as AnyTypificationT, v as TypeID, y as TypePath } from "./typification-Dk-fisgO.js";
12
- import { i as RSErrorDescription, r as RSErrorCode } from "./error-E1LVq_3w.js";
13
- import { i as readTypeAnnotation, r as readErrorAnnotation } from "./ast-annotations-BiMjkKvz.js";
14
- import { c as Value, f as makeValuePath, u as ValuePath } from "./value-CTjX6825.js";
15
- import { n as CalculatorResult, r as RSCalculator, t as CalculatorEvaluateOptions } from "./calculator-C9W2jkSx.js";
16
- import { d as printValue } from "./value-api-Bw-SgaYY.js";
12
+ import { i as RSErrorDescription, r as RSErrorCode } from "./error-deey7EiC.js";
13
+ import { i as readTypeAnnotation, r as readErrorAnnotation } from "./ast-annotations-GOkbNN8F.js";
14
+ import { d as ValuePath, l as Value, p as makeValuePath } from "./value-BduA_ZGp.js";
15
+ import { n as CalculatorResult, r as RSCalculator, t as CalculatorEvaluateOptions } from "./calculator-DFevxZyV.js";
16
+ import { d as printValue } from "./value-api-B6T6f4Ia.js";
17
17
  import { t as parser } from "./parser-Bwd8LxJ1.js";
18
18
  import { t as TokenID } from "./token-DeXAmzwr.js";
19
19
  import { t as ValueClass } from "./value-class-CNI-lqXJ.js";
20
- import { a as RSLangAnalyzer, n as AnalysisFast, r as AnalysisFull, t as AnalysisBase } from "./analyzer-DlSq3Y3r.js";
20
+ import { a as RSLangAnalyzer, n as AnalysisFast, r as AnalysisFull, t as AnalysisBase } from "./analyzer-BliNe3pV.js";
21
21
  import { n as ArgumentsType } from "./arguments-extractor-1acwjQNc.js";
22
22
  import { n as applyAsciiTypeSubstitutions, r as parseTypeText } from "./typification-parser-BBVx1RxP.js";
23
23
  import { n as TypificationNodeData, t as TypificationGraph } from "./typification-graph-6HcZ-rKH.js";
package/dist/index.js CHANGED
@@ -10,7 +10,7 @@ import { printTree } from "./parsing/lezer-tree.js";
10
10
  import { TokenID } from "./rslang/parser/token.js";
11
11
  import { applyHash_fnv1a, generateStub } from "./shared/hash.js";
12
12
  import { AnyTypificationT, EmptySetT, LogicT, TypeClass, TypeID, makeTypePath } from "./rslang/semantic/typification.js";
13
- import { S as printValue, l as makeValuePath } from "./value-B8UtCqaK.js";
13
+ import { C as printValue, u as makeValuePath } from "./value-ybFBRuz6.js";
14
14
  import { RSCalculator } from "./rslang/eval/calculator.js";
15
15
  import { parser } from "./rslang/parser/parser.js";
16
16
  import { ValueClass } from "./rslang/semantic/value-class.js";
@@ -1,6 +1,6 @@
1
1
  import { t as AstNode } from "../ast-C8sIpKdL.js";
2
- import { c as Value } from "../value-CTjX6825.js";
3
- import { n as CalculatorResult, r as RSCalculator, t as CalculatorEvaluateOptions } from "../calculator-C9W2jkSx.js";
2
+ import { l as Value } from "../value-BduA_ZGp.js";
3
+ import { n as CalculatorResult, r as RSCalculator, t as CalculatorEvaluateOptions } from "../calculator-DFevxZyV.js";
4
4
  import { CstType, RSForm } from "./rsform.js";
5
5
  import { BasicBinding, BasicsContext, EvalStatus, RSModel } from "./rsmodel.js";
6
6
 
@@ -26,7 +26,6 @@ interface RSEngineServices {
26
26
  interface RSEngineNotifications {
27
27
  onInvalidSetValue: () => void;
28
28
  onCalculationSuccess: (timeSpent: string) => void;
29
- onEvaluationError: (message: string) => void;
30
29
  }
31
30
  /** Calculation engine for {@link RSModel}. */
32
31
  declare class RSEngine {
@@ -1,5 +1,5 @@
1
1
  import { TypeID } from "../rslang/semantic/typification.js";
2
- import { c as compare } from "../value-B8UtCqaK.js";
2
+ import { l as compare } from "../value-ybFBRuz6.js";
3
3
  import { RSCalculator } from "../rslang/eval/calculator.js";
4
4
  import { normalizeType } from "../rslang/labels.js";
5
5
  import "../rslang/index.js";
@@ -224,22 +224,11 @@ var RSEngine = class {
224
224
  }
225
225
  /** Evaluates expression for {@link RSEngine}. */
226
226
  evaluateExpression(expression, cstType) {
227
- return getEvaluationFor(expression, cstType, this.schema, this.calculator, (message) => this.notifications?.onEvaluationError(message));
227
+ return getEvaluationFor(expression, cstType, this.schema, this.calculator);
228
228
  }
229
229
  /** Evaluates AST for {@link RSEngine}. */
230
230
  evaluateAst(ast, options) {
231
- try {
232
- return this.calculator.evaluateFull(ast, options);
233
- } catch (error) {
234
- this.notifications?.onEvaluationError(error.message);
235
- console.error(error);
236
- return {
237
- value: null,
238
- iterations: 0,
239
- cacheHits: 0,
240
- errors: []
241
- };
242
- }
231
+ return this.calculator.evaluateFull(ast, options);
243
232
  }
244
233
  /** Calculates value for {@link Constituenta}. */
245
234
  calculateCst(cstID) {
@@ -254,7 +243,7 @@ var RSEngine = class {
254
243
  const predecessors = this.schema.graph.expandAllInputs([cstID]);
255
244
  this.prepareEvaluation(predecessors);
256
245
  }
257
- const result = getEvaluationFor(cst.definition_formal, cst.cst_type, this.schema, this.calculator, (message) => this.notifications?.onEvaluationError(message));
246
+ const result = getEvaluationFor(cst.definition_formal, cst.cst_type, this.schema, this.calculator);
258
247
  if (result.value === null) this.calculator.resetValue(cst.alias);
259
248
  else this.calculator.setValue(cst.alias, result.value);
260
249
  this.calculatedSet.add(cstID);
@@ -375,7 +364,7 @@ var RSEngine = class {
375
364
  for (const cstID of this.schema.graph.topologicalOrder()) if (dependencies.includes(cstID)) {
376
365
  const cst = this.schema.cstByID.get(cstID);
377
366
  if (isInferrable(cst.cst_type)) {
378
- const value = fastEvaluation(cst.definition_formal, cst.cst_type, this.schema, this.calculator, (message) => this.notifications?.onEvaluationError(message));
367
+ const value = fastEvaluation(cst.definition_formal, cst.cst_type, this.schema, this.calculator);
379
368
  if (value !== null) this.calculator.setValue(cst.alias, value);
380
369
  else this.calculator.resetValue(cst.alias);
381
370
  this.notifyCst(cstID);
@@ -399,7 +388,7 @@ var RSEngine = class {
399
388
  }
400
389
  };
401
390
  /** Evaluates expression for {@link Constituenta}, including error handling. */
402
- function getEvaluationFor(expression, cstType, schema, calculator, onEvaluationError) {
391
+ function getEvaluationFor(expression, cstType, schema, calculator) {
403
392
  const parse = getAnalysisFor(expression, cstType, schema);
404
393
  if (!parse.success || !parse.ast) return {
405
394
  value: null,
@@ -407,36 +396,19 @@ function getEvaluationFor(expression, cstType, schema, calculator, onEvaluationE
407
396
  cacheHits: 0,
408
397
  errors: parse.errors
409
398
  };
410
- else try {
411
- const result = calculator.evaluateFull(parse.ast);
412
- return {
413
- value: result.value,
414
- iterations: result.iterations,
415
- cacheHits: result.cacheHits,
416
- errors: [...parse.errors, ...result.errors]
417
- };
418
- } catch (error) {
419
- onEvaluationError?.(error.message);
420
- console.error(expression, error);
421
- return {
422
- value: null,
423
- iterations: 0,
424
- cacheHits: 0,
425
- errors: []
426
- };
427
- }
399
+ const result = calculator.evaluateFull(parse.ast);
400
+ return {
401
+ value: result.value,
402
+ iterations: result.iterations,
403
+ cacheHits: result.cacheHits,
404
+ errors: [...parse.errors, ...result.errors]
405
+ };
428
406
  }
429
407
  /** Evaluates expression for {@link RSModel}. */
430
- function fastEvaluation(expression, cstType, schema, calculator, onEvaluationError) {
408
+ function fastEvaluation(expression, cstType, schema, calculator) {
431
409
  const parse = getAnalysisFor(expression, cstType, schema);
432
410
  if (!parse.success || !parse.ast) return null;
433
- else try {
434
- return calculator.evaluateFast(parse.ast);
435
- } catch (error) {
436
- onEvaluationError?.(error.message);
437
- console.error(expression, error);
438
- return null;
439
- }
411
+ return calculator.evaluateFast(parse.ast);
440
412
  }
441
413
  //#endregion
442
414
  export { RSEngine };
@@ -1 +1 @@
1
- {"version":3,"file":"rsengine.js","names":[],"sources":["../../src/library/rsengine.ts"],"sourcesContent":["import { type AstNode } from '../parsing';\nimport { type CalculatorEvaluateOptions, type CalculatorResult, RSCalculator, TypeID, type Value } from '../rslang';\nimport { compare } from '../rslang/eval/value';\nimport { normalizeType } from '../rslang/labels';\n\nimport { CstType, type RSForm } from './rsform';\nimport { getAnalysisFor, isBaseSet, isBasicConcept, isFunctional } from './rsform-api';\nimport { type BasicBinding, type BasicsContext, type EvalStatus, type RSModel, TYPE_BASIC } from './rsmodel';\nimport { inferEvalStatus, isInferrable, tryFixValue } from './rsmodel-api';\n\nconst INVALID_TYPE_MARKER = 'INVALID';\n\n/** Services for {@link RSEngine}. */\nexport interface RSEngineServices {\n setCstValue: (args: {\n itemID: number;\n data: { target: number; type: string; data: Value | BasicBinding }[];\n }) => Promise<unknown>;\n clearValues: (args: { itemID: number; data: { items: number[] } }) => Promise<unknown>;\n}\n\n/** Notifications for {@link RSEngine}. */\nexport interface RSEngineNotifications {\n onInvalidSetValue: () => void;\n onCalculationSuccess: (timeSpent: string) => void;\n onEvaluationError: (message: string) => void;\n}\n\n/** Calculation engine for {@link RSModel}. */\nexport class RSEngine {\n public modelID: number;\n public schema: RSForm | null = null;\n public data: RSModel | null = null;\n public calculator = new RSCalculator();\n public basics: BasicsContext = new Map<number, BasicBinding>();\n\n private services: RSEngineServices;\n private notifications: RSEngineNotifications | null;\n private invalidData = new Set<number>();\n private calculatedSet = new Set<number>();\n private valueSubscribers = new Map<number, Set<() => void>>();\n private statusSubscribers = new Map<number, Set<() => void>>();\n private changeSubscribers = new Set<() => void>();\n private changeGeneration = 0;\n private pendingChange = false;\n private coalescedEmitTimeout: ReturnType<typeof setTimeout> | null = null;\n\n constructor(modelID: number, services: RSEngineServices, notifications: RSEngineNotifications | null = null) {\n this.services = services;\n this.notifications = notifications;\n this.modelID = modelID;\n }\n\n /** Updates data for {@link RSEngine}. */\n public loadData(schema: RSForm, model: RSModel): void {\n const oldSchema = this.schema;\n const newSchema = oldSchema !== schema;\n this.schema = schema;\n if (newSchema) {\n const changedCst = this.collectChanged(oldSchema, schema);\n this.prepareAst();\n this.setupEmptySets();\n this.onChangeDefinitions(changedCst);\n }\n if (this.data !== model) {\n this.data = model;\n this.prepareValues();\n }\n this.notifyAll();\n }\n\n /** Updates services for {@link RSEngine}. */\n public updateServices(services: RSEngineServices): void {\n this.services = services;\n }\n\n /** Updates notifications for {@link RSEngine}. */\n public updateNotifications(notifications: RSEngineNotifications | null): void {\n this.notifications = notifications;\n }\n\n /** Gets value of {@link Constituenta}. */\n public getCstValue(cstID: number): Value | null {\n const cst = this.schema?.cstByID.get(cstID);\n if (!cst) {\n return null;\n }\n return this.calculator.getValue(cst.alias);\n }\n\n /** Gets status of {@link Constituenta}. */\n public getCstStatus(cstID: number): EvalStatus {\n const cst = this.schema?.cstByID.get(cstID);\n if (!cst) {\n return inferEvalStatus(null, CstType.NOMINAL, false);\n }\n const value = this.calculator.getValue(cst.alias);\n return inferEvalStatus(value, cst.cst_type, this.calculatedSet.has(cstID), this.invalidData.has(cstID));\n }\n\n /** Subscribe to value change of {@link Constituenta}. */\n public subscribeValue(cstID: number, callbackFn: () => void): () => void {\n let subs = this.valueSubscribers.get(cstID);\n if (!subs) {\n subs = new Set();\n this.valueSubscribers.set(cstID, subs);\n }\n subs.add(callbackFn);\n return () => {\n const current = this.valueSubscribers.get(cstID);\n if (!current) {\n return;\n }\n current.delete(callbackFn);\n if (current.size === 0) {\n this.valueSubscribers.delete(cstID);\n }\n };\n }\n\n /** Subscribe to status change of {@link Constituenta}. */\n public subscribeStatus(cstID: number, callbackFn: () => void): () => void {\n let subs = this.statusSubscribers.get(cstID);\n if (!subs) {\n subs = new Set();\n this.statusSubscribers.set(cstID, subs);\n }\n subs.add(callbackFn);\n return () => {\n const current = this.statusSubscribers.get(cstID);\n if (!current) {\n return;\n }\n current.delete(callbackFn);\n if (current.size === 0) {\n this.statusSubscribers.delete(cstID);\n }\n };\n }\n\n /**\n * Subscribe to any engine change that can affect evaluation (values, status, or loaded data).\n */\n public subscribeChanges(callbackFn: () => void): () => void {\n this.changeSubscribers.add(callbackFn);\n return () => {\n this.changeSubscribers.delete(callbackFn);\n };\n }\n\n /** Monotonic counter bumped whenever the engine emits a change to {@link RSEngine.subscribeChanges} listeners. */\n public getChangeGeneration(): number {\n return this.changeGeneration;\n }\n\n /**\n * Runs pending {@link RSEngine.subscribeChanges} notifications immediately and clears the coalescing queue.\n * Use after a synchronous batch of engine updates when listeners must observe a bumped {@link getChangeGeneration}\n * in the same turn.\n */\n public flushPendingChanges(): void {\n if (this.coalescedEmitTimeout !== null) {\n clearTimeout(this.coalescedEmitTimeout);\n this.coalescedEmitTimeout = null;\n }\n if (!this.pendingChange) {\n return;\n }\n this.pendingChange = false;\n this.emitChange();\n }\n\n /** Sets value for {@link Constituenta} from {@link Value}. */\n public async setStructureValue(cstID: number, data: Value): Promise<void> {\n const cst = this.schema?.cstByID.get(cstID);\n if (!this.schema || !cst || isInferrable(cst.cst_type)) {\n this.notifications?.onInvalidSetValue();\n return;\n }\n\n const typeStr = cst.effectiveType ? normalizeType(cst.effectiveType) : INVALID_TYPE_MARKER;\n const payload = [{ target: cstID, type: typeStr, data }];\n await this.services.setCstValue({ itemID: this.modelID, data: payload });\n\n if (!cst.effectiveType || !this.calculator.validate(data, cst.effectiveType)) {\n this.invalidData.add(cstID);\n } else {\n this.invalidData.delete(cstID);\n }\n this.calculator.setValue(cst.alias, data);\n this.notifyCst(cstID);\n this.cascadeReset([cstID]);\n }\n\n /** Sets value for {@link Constituenta} from {@link BasicBinding}. */\n public async setBasicValue(cstID: number, data: BasicBinding): Promise<void> {\n const cst = this.schema?.cstByID.get(cstID);\n if (!this.schema || !cst || !isBaseSet(cst.cst_type)) {\n this.notifications?.onInvalidSetValue();\n return;\n }\n const oldValue = this.calculator.getValue(cst.alias);\n const newValue = Object.keys(data).map(Number);\n\n const updateList: Parameters<RSEngineServices['setCstValue']>[0]['data'] = [\n { target: cstID, type: TYPE_BASIC, data }\n ];\n const resetList: number[] = [];\n\n if (oldValue !== null && compare(newValue, oldValue) !== 0) {\n const dependencies = this.schema.graph.expandAllOutputs([cstID]);\n for (const childID of dependencies) {\n const child = this.schema.cstByID.get(childID)!;\n if (child.cst_type === CstType.STRUCTURED && !!child.effectiveType) {\n const value = this.calculator.getValue(child.alias);\n if (value !== null) {\n const fix = tryFixValue(value, child.effectiveType, cst.alias, newValue);\n if (fix === null) {\n resetList.push(childID);\n } else if (fix === true) {\n const typeStr = normalizeType(child.effectiveType);\n updateList.push({ target: childID, type: typeStr, data: [...(value as Value[])] });\n }\n }\n }\n }\n }\n\n if (resetList.length > 0) {\n await Promise.all([\n this.services.setCstValue({ itemID: this.modelID, data: updateList }),\n this.services.clearValues({ itemID: this.modelID, data: { items: resetList } })\n ]);\n } else {\n await this.services.setCstValue({ itemID: this.modelID, data: updateList });\n }\n const changed = [...resetList, ...updateList.map(item => item.target)];\n\n this.basics.set(cstID, data);\n this.calculator.setValue(cst.alias, Object.keys(data).map(Number));\n\n for (const item of resetList) {\n this.calculator.resetValue(this.schema.cstByID.get(item)!.alias);\n this.notifyCst(item);\n }\n for (const updateData of updateList) {\n if (updateData.target !== cstID) {\n this.calculator.setValue(\n this.schema.cstByID.get(updateData.target)!.alias,\n updateData.data as unknown as Value\n );\n this.notifyCst(updateData.target);\n }\n }\n for (const item of changed) {\n this.notifyCst(item);\n }\n this.cascadeReset(changed);\n }\n\n /** Resets value for {@link Constituenta}. */\n public async resetValue(cstID: number): Promise<void> {\n const cst = this.schema?.cstByID.get(cstID);\n if (!cst) {\n return;\n }\n await this.services.clearValues({ itemID: this.modelID, data: { items: [cstID] } });\n this.calculator.resetValue(cst.alias);\n this.basics.delete(cstID);\n this.calculatedSet.delete(cstID);\n this.invalidData.delete(cstID);\n this.notifyCst(cstID);\n }\n\n /** Evaluates expression for {@link RSEngine}. */\n public evaluateExpression(expression: string, cstType: CstType): CalculatorResult {\n return getEvaluationFor(expression, cstType, this.schema!, this.calculator, message =>\n this.notifications?.onEvaluationError(message)\n );\n }\n\n /** Evaluates AST for {@link RSEngine}. */\n public evaluateAst(ast: AstNode, options?: CalculatorEvaluateOptions): CalculatorResult {\n try {\n const evaluation = this.calculator.evaluateFull(ast, options);\n return evaluation;\n } catch (error) {\n this.notifications?.onEvaluationError((error as Error).message);\n console.error(error);\n return {\n value: null,\n iterations: 0,\n cacheHits: 0,\n errors: []\n };\n }\n }\n\n /** Calculates value for {@link Constituenta}. */\n public calculateCst(cstID: number): CalculatorResult {\n const cst = this.schema?.cstByID.get(cstID);\n if (!cst || !this.schema) {\n return { value: null, iterations: 0, errors: [], cacheHits: 0 };\n }\n\n if (!this.calculatedSet.has(cstID)) {\n const predecessors = this.schema.graph.expandAllInputs([cstID]);\n this.prepareEvaluation(predecessors);\n }\n const result = getEvaluationFor(cst.definition_formal, cst.cst_type, this.schema, this.calculator, message =>\n this.notifications?.onEvaluationError(message)\n );\n\n if (result.value === null) {\n this.calculator.resetValue(cst.alias);\n } else {\n this.calculator.setValue(cst.alias, result.value);\n }\n\n this.calculatedSet.add(cstID);\n this.notifyCst(cstID);\n\n return result;\n }\n\n /** Recalculate model for all inferrable expressions. */\n recalculateAll(): void {\n const start = performance.now();\n this.calculatedSet.clear();\n this.recalculateInternal();\n const end = performance.now();\n const timeSpent = ((end - start) / 1000).toFixed(2);\n this.notifications?.onCalculationSuccess(timeSpent);\n }\n\n /** Notify subscribers about value and status change of {@link Constituenta}. */\n private notifyCst(cstID: number) {\n this.notifyStatus(cstID);\n this.notifyValue(cstID);\n this.scheduleCoalescedEmitChange();\n }\n\n /** Notify all subscribers about value change. */\n private notifyValue(cstID: number) {\n const subs = this.valueSubscribers.get(cstID);\n if (subs) {\n for (const cb of subs) cb();\n }\n }\n\n /** Notify all subscribers about status change. */\n private notifyStatus(cstID: number) {\n const subs = this.statusSubscribers.get(cstID);\n if (subs) {\n for (const cb of subs) cb();\n }\n }\n\n /** Notify all subscribers about value and status change. */\n private notifyAll(): void {\n for (const subs of this.valueSubscribers.values()) {\n for (const cb of subs) cb();\n }\n for (const subs of this.statusSubscribers.values()) {\n for (const cb of subs) cb();\n }\n this.scheduleCoalescedEmitChange();\n }\n\n private scheduleCoalescedEmitChange(): void {\n this.pendingChange = true;\n if (this.coalescedEmitTimeout !== null) {\n return;\n }\n this.coalescedEmitTimeout = setTimeout(\n function runCoalescedEmitChange(this: RSEngine) {\n this.coalescedEmitTimeout = null;\n if (!this.pendingChange) {\n return;\n }\n this.pendingChange = false;\n this.emitChange();\n }.bind(this),\n 0\n );\n }\n\n private emitChange(): void {\n this.changeGeneration += 1;\n for (const cb of this.changeSubscribers) {\n cb();\n }\n }\n\n private prepareAst(): void {\n this.calculator.clearAllAst();\n const functions = this.schema!.items.filter(cst => isFunctional(cst.cst_type) && cst.analysis?.success);\n for (const cst of functions) {\n const fullAnalysis = getAnalysisFor(cst.definition_formal, cst.cst_type, this.schema!);\n if (fullAnalysis.ast) {\n this.calculator.setAST(cst.alias, fullAnalysis.ast);\n }\n }\n }\n\n private prepareValues(): void {\n this.basics.clear();\n this.invalidData.clear();\n this.calculatedSet.clear();\n\n for (const item of this.data!.items) {\n const cst = this.schema!.cstByID.get(item.id)!;\n if (item.type === TYPE_BASIC) {\n if (cst.cst_type !== CstType.BASE && cst.cst_type !== CstType.CONSTANT) {\n throw new Error(`Invalid data for ${cst.alias}`);\n }\n const data = item.value as BasicBinding;\n this.basics.set(cst.id, data);\n this.calculator.setValue(cst.alias, Object.keys(data).map(Number));\n }\n }\n for (const item of this.data!.items) {\n const cst = this.schema!.cstByID.get(item.id)!;\n if (item.type !== TYPE_BASIC) {\n this.calculator.setValue(cst.alias, item.value as Value);\n if (!cst.effectiveType || !this.calculator.validate(item.value as Value, cst.effectiveType)) {\n this.invalidData.add(item.id);\n }\n }\n }\n this.setupEmptySets();\n }\n\n private setupEmptySets(): void {\n for (const cst of this.schema!.items) {\n if (isBasicConcept(cst.cst_type) && this.schema!.analyzer.getType(cst.alias)?.typeID === TypeID.collection) {\n if (this.calculator.getValue(cst.alias) === null) {\n this.calculator.setValue(cst.alias, []);\n }\n }\n }\n }\n\n private collectChanged(previousSchema: RSForm | null, nextSchema: RSForm): number[] {\n if (!previousSchema) {\n return [];\n }\n const changedIDs: number[] = [];\n for (const cst of nextSchema.items) {\n const prev = previousSchema.cstByID.get(cst.id);\n if (prev && (prev.definition_formal !== cst.definition_formal || prev.alias !== cst.alias)) {\n changedIDs.push(cst.id);\n }\n }\n return changedIDs;\n }\n\n private onChangeDefinitions(cstIDs: number[]): void {\n if (!this.schema || cstIDs.length === 0) {\n return;\n }\n for (const cstID of cstIDs) {\n const cst = this.schema.cstByID.get(cstID);\n if (!cst || !isInferrable(cst.cst_type)) {\n continue;\n }\n this.calculatedSet.delete(cstID);\n this.calculator.resetValue(cst.alias);\n this.notifyCst(cstID);\n }\n this.cascadeReset(cstIDs);\n }\n\n private cascadeReset(cstIDs: number[]): void {\n if (!this.schema) {\n return;\n }\n const dependencies = this.schema.graph.expandAllOutputs(cstIDs);\n for (const cstID of dependencies) {\n const cst = this.schema.cstByID.get(cstID);\n if (!cst || !isInferrable(cst.cst_type)) {\n continue;\n }\n this.calculatedSet.delete(cstID);\n this.calculator.resetValue(this.schema.cstByID.get(cstID)!.alias);\n this.notifyCst(cstID);\n }\n }\n\n private prepareEvaluation(dependencies: number[]): void {\n for (const cstID of this.schema!.graph.topologicalOrder()) {\n if (dependencies.includes(cstID)) {\n const cst = this.schema!.cstByID.get(cstID)!;\n if (isInferrable(cst.cst_type)) {\n const value = fastEvaluation(cst.definition_formal, cst.cst_type, this.schema!, this.calculator, message =>\n this.notifications?.onEvaluationError(message)\n );\n if (value !== null) {\n this.calculator.setValue(cst.alias, value);\n } else {\n this.calculator.resetValue(cst.alias);\n }\n this.notifyCst(cstID);\n }\n this.calculatedSet.add(cstID);\n }\n }\n }\n\n private recalculateInternal(): void {\n const processedIDs = [];\n for (const cst of this.schema!.cstByID.values()) {\n if (isInferrable(cst.cst_type)) {\n this.calculator.resetValue(cst.alias);\n }\n }\n\n for (const cstID of this.schema!.graph.topologicalOrder()) {\n processedIDs.push(cstID);\n const cst = this.schema!.cstByID.get(cstID)!;\n if (isInferrable(cst.cst_type)) {\n const value = fastEvaluation(cst.definition_formal, cst.cst_type, this.schema!, this.calculator);\n this.calculatedSet.add(cstID);\n if (value !== null) {\n this.calculator.setValue(cst.alias, value);\n }\n }\n }\n this.notifyAll();\n }\n}\n\n// ==== Internal functions ==== /\n\n/** Evaluates expression for {@link Constituenta}, including error handling. */\nfunction getEvaluationFor(\n expression: string,\n cstType: CstType,\n schema: RSForm,\n calculator: RSCalculator,\n onEvaluationError?: (message: string) => void\n): CalculatorResult {\n const parse = getAnalysisFor(expression, cstType, schema);\n if (!parse.success || !parse.ast) {\n return {\n value: null,\n iterations: 0,\n cacheHits: 0,\n errors: parse.errors\n };\n } else {\n try {\n const result = calculator.evaluateFull(parse.ast);\n return {\n value: result.value,\n iterations: result.iterations,\n cacheHits: result.cacheHits,\n errors: [...parse.errors, ...result.errors]\n };\n } catch (error) {\n onEvaluationError?.((error as Error).message);\n console.error(expression, error);\n return {\n value: null,\n iterations: 0,\n cacheHits: 0,\n errors: []\n };\n }\n }\n}\n\n/** Evaluates expression for {@link RSModel}. */\nfunction fastEvaluation(\n expression: string,\n cstType: CstType,\n schema: RSForm,\n calculator: RSCalculator,\n onEvaluationError?: (message: string) => void\n): Value | null {\n const parse = getAnalysisFor(expression, cstType, schema);\n if (!parse.success || !parse.ast) {\n return null;\n } else {\n try {\n return calculator.evaluateFast(parse.ast);\n } catch (error) {\n onEvaluationError?.((error as Error).message);\n console.error(expression, error);\n return null;\n }\n }\n}\n"],"mappings":";;;;;;;;;;AAUA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SAAS,OAAO;EACd,oBAAqB,MAAgB,OAAO;EAC5C,QAAQ,MAAM,YAAY,KAAK;EAC/B,OAAO;GACL,OAAO;GACP,YAAY;GACZ,WAAW;GACX,QAAQ,CAAC;EACX;CACF;AAEJ;;AAGA,SAAS,eACP,YACA,SACA,QACA,YACA,mBACc;CACd,MAAM,QAAQ,eAAe,YAAY,SAAS,MAAM;CACxD,IAAI,CAAC,MAAM,WAAW,CAAC,MAAM,KAC3B,OAAO;MAEP,IAAI;EACF,OAAO,WAAW,aAAa,MAAM,GAAG;CAC1C,SAAS,OAAO;EACd,oBAAqB,MAAgB,OAAO;EAC5C,QAAQ,MAAM,YAAY,KAAK;EAC/B,OAAO;CACT;AAEJ"}
1
+ {"version":3,"file":"rsengine.js","names":[],"sources":["../../src/library/rsengine.ts"],"sourcesContent":["import { type AstNode } from '../parsing';\nimport { type CalculatorEvaluateOptions, type CalculatorResult, RSCalculator, TypeID, type Value } from '../rslang';\nimport { compare } from '../rslang/eval/value';\nimport { normalizeType } from '../rslang/labels';\n\nimport { CstType, type RSForm } from './rsform';\nimport { getAnalysisFor, isBaseSet, isBasicConcept, isFunctional } from './rsform-api';\nimport { type BasicBinding, type BasicsContext, type EvalStatus, type RSModel, TYPE_BASIC } from './rsmodel';\nimport { inferEvalStatus, isInferrable, tryFixValue } from './rsmodel-api';\n\nconst INVALID_TYPE_MARKER = 'INVALID';\n\n/** Services for {@link RSEngine}. */\nexport interface RSEngineServices {\n setCstValue: (args: {\n itemID: number;\n data: { target: number; type: string; data: Value | BasicBinding }[];\n }) => Promise<unknown>;\n clearValues: (args: { itemID: number; data: { items: number[] } }) => Promise<unknown>;\n}\n\n/** Notifications for {@link RSEngine}. */\nexport interface RSEngineNotifications {\n onInvalidSetValue: () => void;\n onCalculationSuccess: (timeSpent: string) => void;\n}\n\n/** Calculation engine for {@link RSModel}. */\nexport class RSEngine {\n public modelID: number;\n public schema: RSForm | null = null;\n public data: RSModel | null = null;\n public calculator = new RSCalculator();\n public basics: BasicsContext = new Map<number, BasicBinding>();\n\n private services: RSEngineServices;\n private notifications: RSEngineNotifications | null;\n private invalidData = new Set<number>();\n private calculatedSet = new Set<number>();\n private valueSubscribers = new Map<number, Set<() => void>>();\n private statusSubscribers = new Map<number, Set<() => void>>();\n private changeSubscribers = new Set<() => void>();\n private changeGeneration = 0;\n private pendingChange = false;\n private coalescedEmitTimeout: ReturnType<typeof setTimeout> | null = null;\n\n constructor(modelID: number, services: RSEngineServices, notifications: RSEngineNotifications | null = null) {\n this.services = services;\n this.notifications = notifications;\n this.modelID = modelID;\n }\n\n /** Updates data for {@link RSEngine}. */\n public loadData(schema: RSForm, model: RSModel): void {\n const oldSchema = this.schema;\n const newSchema = oldSchema !== schema;\n this.schema = schema;\n if (newSchema) {\n const changedCst = this.collectChanged(oldSchema, schema);\n this.prepareAst();\n this.setupEmptySets();\n this.onChangeDefinitions(changedCst);\n }\n if (this.data !== model) {\n this.data = model;\n this.prepareValues();\n }\n this.notifyAll();\n }\n\n /** Updates services for {@link RSEngine}. */\n public updateServices(services: RSEngineServices): void {\n this.services = services;\n }\n\n /** Updates notifications for {@link RSEngine}. */\n public updateNotifications(notifications: RSEngineNotifications | null): void {\n this.notifications = notifications;\n }\n\n /** Gets value of {@link Constituenta}. */\n public getCstValue(cstID: number): Value | null {\n const cst = this.schema?.cstByID.get(cstID);\n if (!cst) {\n return null;\n }\n return this.calculator.getValue(cst.alias);\n }\n\n /** Gets status of {@link Constituenta}. */\n public getCstStatus(cstID: number): EvalStatus {\n const cst = this.schema?.cstByID.get(cstID);\n if (!cst) {\n return inferEvalStatus(null, CstType.NOMINAL, false);\n }\n const value = this.calculator.getValue(cst.alias);\n return inferEvalStatus(value, cst.cst_type, this.calculatedSet.has(cstID), this.invalidData.has(cstID));\n }\n\n /** Subscribe to value change of {@link Constituenta}. */\n public subscribeValue(cstID: number, callbackFn: () => void): () => void {\n let subs = this.valueSubscribers.get(cstID);\n if (!subs) {\n subs = new Set();\n this.valueSubscribers.set(cstID, subs);\n }\n subs.add(callbackFn);\n return () => {\n const current = this.valueSubscribers.get(cstID);\n if (!current) {\n return;\n }\n current.delete(callbackFn);\n if (current.size === 0) {\n this.valueSubscribers.delete(cstID);\n }\n };\n }\n\n /** Subscribe to status change of {@link Constituenta}. */\n public subscribeStatus(cstID: number, callbackFn: () => void): () => void {\n let subs = this.statusSubscribers.get(cstID);\n if (!subs) {\n subs = new Set();\n this.statusSubscribers.set(cstID, subs);\n }\n subs.add(callbackFn);\n return () => {\n const current = this.statusSubscribers.get(cstID);\n if (!current) {\n return;\n }\n current.delete(callbackFn);\n if (current.size === 0) {\n this.statusSubscribers.delete(cstID);\n }\n };\n }\n\n /**\n * Subscribe to any engine change that can affect evaluation (values, status, or loaded data).\n */\n public subscribeChanges(callbackFn: () => void): () => void {\n this.changeSubscribers.add(callbackFn);\n return () => {\n this.changeSubscribers.delete(callbackFn);\n };\n }\n\n /** Monotonic counter bumped whenever the engine emits a change to {@link RSEngine.subscribeChanges} listeners. */\n public getChangeGeneration(): number {\n return this.changeGeneration;\n }\n\n /**\n * Runs pending {@link RSEngine.subscribeChanges} notifications immediately and clears the coalescing queue.\n * Use after a synchronous batch of engine updates when listeners must observe a bumped {@link getChangeGeneration}\n * in the same turn.\n */\n public flushPendingChanges(): void {\n if (this.coalescedEmitTimeout !== null) {\n clearTimeout(this.coalescedEmitTimeout);\n this.coalescedEmitTimeout = null;\n }\n if (!this.pendingChange) {\n return;\n }\n this.pendingChange = false;\n this.emitChange();\n }\n\n /** Sets value for {@link Constituenta} from {@link Value}. */\n public async setStructureValue(cstID: number, data: Value): Promise<void> {\n const cst = this.schema?.cstByID.get(cstID);\n if (!this.schema || !cst || isInferrable(cst.cst_type)) {\n this.notifications?.onInvalidSetValue();\n return;\n }\n\n const typeStr = cst.effectiveType ? normalizeType(cst.effectiveType) : INVALID_TYPE_MARKER;\n const payload = [{ target: cstID, type: typeStr, data }];\n await this.services.setCstValue({ itemID: this.modelID, data: payload });\n\n if (!cst.effectiveType || !this.calculator.validate(data, cst.effectiveType)) {\n this.invalidData.add(cstID);\n } else {\n this.invalidData.delete(cstID);\n }\n this.calculator.setValue(cst.alias, data);\n this.notifyCst(cstID);\n this.cascadeReset([cstID]);\n }\n\n /** Sets value for {@link Constituenta} from {@link BasicBinding}. */\n public async setBasicValue(cstID: number, data: BasicBinding): Promise<void> {\n const cst = this.schema?.cstByID.get(cstID);\n if (!this.schema || !cst || !isBaseSet(cst.cst_type)) {\n this.notifications?.onInvalidSetValue();\n return;\n }\n const oldValue = this.calculator.getValue(cst.alias);\n const newValue = Object.keys(data).map(Number);\n\n const updateList: Parameters<RSEngineServices['setCstValue']>[0]['data'] = [\n { target: cstID, type: TYPE_BASIC, data }\n ];\n const resetList: number[] = [];\n\n if (oldValue !== null && compare(newValue, oldValue) !== 0) {\n const dependencies = this.schema.graph.expandAllOutputs([cstID]);\n for (const childID of dependencies) {\n const child = this.schema.cstByID.get(childID)!;\n if (child.cst_type === CstType.STRUCTURED && !!child.effectiveType) {\n const value = this.calculator.getValue(child.alias);\n if (value !== null) {\n const fix = tryFixValue(value, child.effectiveType, cst.alias, newValue);\n if (fix === null) {\n resetList.push(childID);\n } else if (fix === true) {\n const typeStr = normalizeType(child.effectiveType);\n updateList.push({ target: childID, type: typeStr, data: [...(value as Value[])] });\n }\n }\n }\n }\n }\n\n if (resetList.length > 0) {\n await Promise.all([\n this.services.setCstValue({ itemID: this.modelID, data: updateList }),\n this.services.clearValues({ itemID: this.modelID, data: { items: resetList } })\n ]);\n } else {\n await this.services.setCstValue({ itemID: this.modelID, data: updateList });\n }\n const changed = [...resetList, ...updateList.map(item => item.target)];\n\n this.basics.set(cstID, data);\n this.calculator.setValue(cst.alias, Object.keys(data).map(Number));\n\n for (const item of resetList) {\n this.calculator.resetValue(this.schema.cstByID.get(item)!.alias);\n this.notifyCst(item);\n }\n for (const updateData of updateList) {\n if (updateData.target !== cstID) {\n this.calculator.setValue(\n this.schema.cstByID.get(updateData.target)!.alias,\n updateData.data as unknown as Value\n );\n this.notifyCst(updateData.target);\n }\n }\n for (const item of changed) {\n this.notifyCst(item);\n }\n this.cascadeReset(changed);\n }\n\n /** Resets value for {@link Constituenta}. */\n public async resetValue(cstID: number): Promise<void> {\n const cst = this.schema?.cstByID.get(cstID);\n if (!cst) {\n return;\n }\n await this.services.clearValues({ itemID: this.modelID, data: { items: [cstID] } });\n this.calculator.resetValue(cst.alias);\n this.basics.delete(cstID);\n this.calculatedSet.delete(cstID);\n this.invalidData.delete(cstID);\n this.notifyCst(cstID);\n }\n\n /** Evaluates expression for {@link RSEngine}. */\n public evaluateExpression(expression: string, cstType: CstType): CalculatorResult {\n return getEvaluationFor(expression, cstType, this.schema!, this.calculator);\n }\n\n /** Evaluates AST for {@link RSEngine}. */\n public evaluateAst(ast: AstNode, options?: CalculatorEvaluateOptions): CalculatorResult {\n return this.calculator.evaluateFull(ast, options);\n }\n\n /** Calculates value for {@link Constituenta}. */\n public calculateCst(cstID: number): CalculatorResult {\n const cst = this.schema?.cstByID.get(cstID);\n if (!cst || !this.schema) {\n return { value: null, iterations: 0, errors: [], cacheHits: 0 };\n }\n\n if (!this.calculatedSet.has(cstID)) {\n const predecessors = this.schema.graph.expandAllInputs([cstID]);\n this.prepareEvaluation(predecessors);\n }\n const result = getEvaluationFor(cst.definition_formal, cst.cst_type, this.schema, this.calculator);\n\n if (result.value === null) {\n this.calculator.resetValue(cst.alias);\n } else {\n this.calculator.setValue(cst.alias, result.value);\n }\n\n this.calculatedSet.add(cstID);\n this.notifyCst(cstID);\n\n return result;\n }\n\n /** Recalculate model for all inferrable expressions. */\n recalculateAll(): void {\n const start = performance.now();\n this.calculatedSet.clear();\n this.recalculateInternal();\n const end = performance.now();\n const timeSpent = ((end - start) / 1000).toFixed(2);\n this.notifications?.onCalculationSuccess(timeSpent);\n }\n\n /** Notify subscribers about value and status change of {@link Constituenta}. */\n private notifyCst(cstID: number) {\n this.notifyStatus(cstID);\n this.notifyValue(cstID);\n this.scheduleCoalescedEmitChange();\n }\n\n /** Notify all subscribers about value change. */\n private notifyValue(cstID: number) {\n const subs = this.valueSubscribers.get(cstID);\n if (subs) {\n for (const cb of subs) cb();\n }\n }\n\n /** Notify all subscribers about status change. */\n private notifyStatus(cstID: number) {\n const subs = this.statusSubscribers.get(cstID);\n if (subs) {\n for (const cb of subs) cb();\n }\n }\n\n /** Notify all subscribers about value and status change. */\n private notifyAll(): void {\n for (const subs of this.valueSubscribers.values()) {\n for (const cb of subs) cb();\n }\n for (const subs of this.statusSubscribers.values()) {\n for (const cb of subs) cb();\n }\n this.scheduleCoalescedEmitChange();\n }\n\n private scheduleCoalescedEmitChange(): void {\n this.pendingChange = true;\n if (this.coalescedEmitTimeout !== null) {\n return;\n }\n this.coalescedEmitTimeout = setTimeout(\n function runCoalescedEmitChange(this: RSEngine) {\n this.coalescedEmitTimeout = null;\n if (!this.pendingChange) {\n return;\n }\n this.pendingChange = false;\n this.emitChange();\n }.bind(this),\n 0\n );\n }\n\n private emitChange(): void {\n this.changeGeneration += 1;\n for (const cb of this.changeSubscribers) {\n cb();\n }\n }\n\n private prepareAst(): void {\n this.calculator.clearAllAst();\n const functions = this.schema!.items.filter(cst => isFunctional(cst.cst_type) && cst.analysis?.success);\n for (const cst of functions) {\n const fullAnalysis = getAnalysisFor(cst.definition_formal, cst.cst_type, this.schema!);\n if (fullAnalysis.ast) {\n this.calculator.setAST(cst.alias, fullAnalysis.ast);\n }\n }\n }\n\n private prepareValues(): void {\n this.basics.clear();\n this.invalidData.clear();\n this.calculatedSet.clear();\n\n for (const item of this.data!.items) {\n const cst = this.schema!.cstByID.get(item.id)!;\n if (item.type === TYPE_BASIC) {\n if (cst.cst_type !== CstType.BASE && cst.cst_type !== CstType.CONSTANT) {\n throw new Error(`Invalid data for ${cst.alias}`);\n }\n const data = item.value as BasicBinding;\n this.basics.set(cst.id, data);\n this.calculator.setValue(cst.alias, Object.keys(data).map(Number));\n }\n }\n for (const item of this.data!.items) {\n const cst = this.schema!.cstByID.get(item.id)!;\n if (item.type !== TYPE_BASIC) {\n this.calculator.setValue(cst.alias, item.value as Value);\n if (!cst.effectiveType || !this.calculator.validate(item.value as Value, cst.effectiveType)) {\n this.invalidData.add(item.id);\n }\n }\n }\n this.setupEmptySets();\n }\n\n private setupEmptySets(): void {\n for (const cst of this.schema!.items) {\n if (isBasicConcept(cst.cst_type) && this.schema!.analyzer.getType(cst.alias)?.typeID === TypeID.collection) {\n if (this.calculator.getValue(cst.alias) === null) {\n this.calculator.setValue(cst.alias, []);\n }\n }\n }\n }\n\n private collectChanged(previousSchema: RSForm | null, nextSchema: RSForm): number[] {\n if (!previousSchema) {\n return [];\n }\n const changedIDs: number[] = [];\n for (const cst of nextSchema.items) {\n const prev = previousSchema.cstByID.get(cst.id);\n if (prev && (prev.definition_formal !== cst.definition_formal || prev.alias !== cst.alias)) {\n changedIDs.push(cst.id);\n }\n }\n return changedIDs;\n }\n\n private onChangeDefinitions(cstIDs: number[]): void {\n if (!this.schema || cstIDs.length === 0) {\n return;\n }\n for (const cstID of cstIDs) {\n const cst = this.schema.cstByID.get(cstID);\n if (!cst || !isInferrable(cst.cst_type)) {\n continue;\n }\n this.calculatedSet.delete(cstID);\n this.calculator.resetValue(cst.alias);\n this.notifyCst(cstID);\n }\n this.cascadeReset(cstIDs);\n }\n\n private cascadeReset(cstIDs: number[]): void {\n if (!this.schema) {\n return;\n }\n const dependencies = this.schema.graph.expandAllOutputs(cstIDs);\n for (const cstID of dependencies) {\n const cst = this.schema.cstByID.get(cstID);\n if (!cst || !isInferrable(cst.cst_type)) {\n continue;\n }\n this.calculatedSet.delete(cstID);\n this.calculator.resetValue(this.schema.cstByID.get(cstID)!.alias);\n this.notifyCst(cstID);\n }\n }\n\n private prepareEvaluation(dependencies: number[]): void {\n for (const cstID of this.schema!.graph.topologicalOrder()) {\n if (dependencies.includes(cstID)) {\n const cst = this.schema!.cstByID.get(cstID)!;\n if (isInferrable(cst.cst_type)) {\n const value = fastEvaluation(cst.definition_formal, cst.cst_type, this.schema!, this.calculator);\n if (value !== null) {\n this.calculator.setValue(cst.alias, value);\n } else {\n this.calculator.resetValue(cst.alias);\n }\n this.notifyCst(cstID);\n }\n this.calculatedSet.add(cstID);\n }\n }\n }\n\n private recalculateInternal(): void {\n const processedIDs = [];\n for (const cst of this.schema!.cstByID.values()) {\n if (isInferrable(cst.cst_type)) {\n this.calculator.resetValue(cst.alias);\n }\n }\n\n for (const cstID of this.schema!.graph.topologicalOrder()) {\n processedIDs.push(cstID);\n const cst = this.schema!.cstByID.get(cstID)!;\n if (isInferrable(cst.cst_type)) {\n const value = fastEvaluation(cst.definition_formal, cst.cst_type, this.schema!, this.calculator);\n this.calculatedSet.add(cstID);\n if (value !== null) {\n this.calculator.setValue(cst.alias, value);\n }\n }\n }\n this.notifyAll();\n }\n}\n\n// ==== Internal functions ==== /\n\n/** Evaluates expression for {@link Constituenta}, including error handling. */\nfunction getEvaluationFor(\n expression: string,\n cstType: CstType,\n schema: RSForm,\n calculator: RSCalculator\n): CalculatorResult {\n const parse = getAnalysisFor(expression, cstType, schema);\n if (!parse.success || !parse.ast) {\n return {\n value: null,\n iterations: 0,\n cacheHits: 0,\n errors: parse.errors\n };\n }\n const result = calculator.evaluateFull(parse.ast);\n return {\n value: result.value,\n iterations: result.iterations,\n cacheHits: result.cacheHits,\n errors: [...parse.errors, ...result.errors]\n };\n}\n\n/** Evaluates expression for {@link RSModel}. */\nfunction fastEvaluation(expression: string, cstType: CstType, schema: RSForm, calculator: RSCalculator): Value | null {\n const parse = getAnalysisFor(expression, cstType, schema);\n if (!parse.success || !parse.ast) {\n return null;\n }\n return calculator.evaluateFast(parse.ast);\n}\n"],"mappings":";;;;;;;;;;AAUA,MAAM,sBAAsB;;AAkB5B,IAAa,WAAb,MAAsB;CACpB;CACA,SAA+B;CAC/B,OAA8B;CAC9B,aAAoB,IAAI,aAAa;CACrC,yBAA+B,IAAI,IAA0B;CAE7D;CACA;CACA,8BAAsB,IAAI,IAAY;CAC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AI,KAAK;EAIxC,KAAK,MAAM,SAAS,KAAK,OAAQ,MAAM,iBAAiB,GAAG;GACzD,aAAa,KAAK,KAAK;GACvB,MAAM,MAAM,KAAK,OAAQ,QAAQ,IAAI,KAAK;GAC1C,IAAI,aAAa,IAAI,QAAQ,GAAG;IAC9B,MAAM,QAAQ,eAAe,IAAI,mBAAmB,IAAI,UAAU,KAAK,QAAS,KAAK,UAAU;IAC/F,KAAK,cAAc,IAAI,KAAK;IAC5B,IAAI,UAAU,MACZ,KAAK,WAAW,SAAS,IAAI,OAAO,KAAK;GAE7C;EACF;EACA,KAAK,UAAU;CACjB;AACF;;AAKA,SAAS,iBACP,YACA,SACA,QACA,YACkB;CAClB,MAAM,QAAQ,eAAe,YAAY,SAAS,MAAM;CACxD,IAAI,CAAC,MAAM,WAAW,CAAC,MAAM,KAC3B,OAAO;EACL,OAAO;EACP,YAAY;EACZ,WAAW;EACX,QAAQ,MAAM;CAChB;CAEF,MAAM,SAAS,WAAW,aAAa,MAAM,GAAG;CAChD,OAAO;EACL,OAAO,OAAO;EACd,YAAY,OAAO;EACnB,WAAW,OAAO;EAClB,QAAQ,CAAC,GAAG,MAAM,QAAQ,GAAG,OAAO,MAAM;CAC5C;AACF;;AAGA,SAAS,eAAe,YAAoB,SAAkB,QAAgB,YAAwC;CACpH,MAAM,QAAQ,eAAe,YAAY,SAAS,MAAM;CACxD,IAAI,CAAC,MAAM,WAAW,CAAC,MAAM,KAC3B,OAAO;CAET,OAAO,WAAW,aAAa,MAAM,GAAG;AAC1C"}
@@ -1,7 +1,7 @@
1
1
  import { r as LibraryItem } from "../library-CYun28Xz.js";
2
2
  import { g as TypeClass, y as TypePath } from "../typification-Dk-fisgO.js";
3
3
  import { t as ValueClass } from "../value-class-CNI-lqXJ.js";
4
- import { r as AnalysisFull } from "../analyzer-DlSq3Y3r.js";
4
+ import { r as AnalysisFull } from "../analyzer-BliNe3pV.js";
5
5
  import { ArgumentValue, Constituenta, CstClass, CstStatus, CstType, RSForm, RSFormStats } from "./rsform.js";
6
6
 
7
7
  //#region src/library/rsform-api.d.ts
@@ -1,7 +1,7 @@
1
1
  import { t as Graph } from "../graph-DR8rL2o3.js";
2
2
  import { i as LibraryItemReference, n as CurrentVersion, r as LibraryItem, s as VersionInfo } from "../library-CYun28Xz.js";
3
3
  import { f as ExpressionType, y as TypePath } from "../typification-Dk-fisgO.js";
4
- import { a as RSLangAnalyzer, t as AnalysisBase } from "../analyzer-DlSq3Y3r.js";
4
+ import { a as RSLangAnalyzer, t as AnalysisBase } from "../analyzer-BliNe3pV.js";
5
5
  //#region src/library/rsform.d.ts
6
6
  /** Represents {@link Constituenta} type. */
7
7
  declare const CstType: {
@@ -1,5 +1,5 @@
1
1
  import { b as Typification, f as ExpressionType } from "../typification-Dk-fisgO.js";
2
- import { c as Value, u as ValuePath } from "../value-CTjX6825.js";
2
+ import { d as ValuePath, l as Value } from "../value-BduA_ZGp.js";
3
3
  import { Constituenta, CstType, RSForm } from "./rsform.js";
4
4
  import { BasicBinding, EvalStatus, RSModelStats } from "./rsmodel.js";
5
5
  import { RSEngine } from "./rsengine.js";
@@ -1,5 +1,5 @@
1
1
  import { TypeID } from "../rslang/semantic/typification.js";
2
- import { D as setNestedValue, b as makeDefaultValue, c as compare, d as tuple, g as extractValue, y as isTupleValue } from "../value-B8UtCqaK.js";
2
+ import { O as setNestedValue, _ as extractValue, b as isTupleValue, f as tuple, l as compare, x as makeDefaultValue } from "../value-ybFBRuz6.js";
3
3
  import "../rslang/index.js";
4
4
  import { CstType } from "./rsform.js";
5
5
  import { calculateSchemaStats, isBaseSet, isBasicConcept } from "./rsform-api.js";
@@ -1,5 +1,5 @@
1
1
  import { r as LibraryItem } from "../library-CYun28Xz.js";
2
- import { c as Value } from "../value-CTjX6825.js";
2
+ import { l as Value } from "../value-BduA_ZGp.js";
3
3
  import { RSFormStats } from "./rsform.js";
4
4
 
5
5
  //#region src/library/rsmodel.d.ts
@@ -1,2 +1,2 @@
1
- import { i as readTypeAnnotation, n as annotateType, r as readErrorAnnotation, t as annotateError } from "../ast-annotations-BiMjkKvz.js";
1
+ import { i as readTypeAnnotation, n as annotateType, r as readErrorAnnotation, t as annotateError } from "../ast-annotations-GOkbNN8F.js";
2
2
  export { annotateError, annotateType, readErrorAnnotation, readTypeAnnotation };
@@ -1,2 +1,2 @@
1
- import { a as RSErrorInfo, i as RSErrorDescription, n as RSErrorClass, o as getRSErrorPrefix, r as RSErrorCode, s as isCritical, t as ErrorReporter } from "../error-E1LVq_3w.js";
1
+ import { a as RSErrorInfo, i as RSErrorDescription, n as RSErrorClass, o as getRSErrorPrefix, r as RSErrorCode, s as isCritical, t as ErrorReporter } from "../error-deey7EiC.js";
2
2
  export { ErrorReporter, RSErrorClass, RSErrorCode, RSErrorDescription, RSErrorInfo, getRSErrorPrefix, isCritical };
@@ -61,6 +61,7 @@ const RSErrorCode = {
61
61
  calcInvalidDebool: 33029,
62
62
  iterateInfinity: 33030,
63
63
  calculationNotSupported: 33031,
64
+ calcInvalidData: 33032,
64
65
  cstEmptyDerived: 34913,
65
66
  definitionNotAllowed: 34914
66
67
  };
@@ -1 +1 @@
1
- {"version":3,"file":"error.js","names":[],"sources":["../../src/rslang/error.ts"],"sourcesContent":["/** Module: Error types and functions. */\n\n/** Represents error class. */\nexport const RSErrorClass = {\n LEXER: 0,\n PARSER: 1,\n SEMANTIC: 2,\n EVALUATION: 3,\n UNKNOWN: 4\n} as const;\nexport type RSErrorClass = (typeof RSErrorClass)[keyof typeof RSErrorClass];\n\n/** Represents RSLang expression error information. */\nexport interface RSErrorInfo {\n code: RSErrorCode;\n params?: readonly string[];\n}\n\n/** Represents RSLang expression error description. */\nexport interface RSErrorDescription extends RSErrorInfo {\n from: number;\n to: number;\n}\n\n/** Error reporter function type. */\nexport type ErrorReporter = (error: RSErrorDescription) => void;\n\n/** Represents RSLang expression error types. */\nexport const RSErrorCode = {\n unknownSyntax: 0x8400, // 33792\n missingParenthesis: 0x8406, // 33798\n missingCurlyBrace: 0x8407, // 33799\n missingSquareBracket: 0x8408, // 33800\n bracketMismatch: 0x8409, // 33801\n doubleParenthesis: 0x840a, // 33802\n missingOpenBracket: 0x840b, // 33803\n expectedLocal: 0x8415, // 33813\n expectedType: 0x8416, // 33814\n\n localDoubleDeclare: 0x2801, // 10241\n localNotUsed: 0x2802, // 10242\n\n localUndeclared: 0x8801, // 34817\n localShadowing: 0x8802, // 34818\n\n typesNotEqual: 0x8803, // 34819\n globalNotTyped: 0x8804, // 34820\n invalidDecart: 0x8805, // 34821\n invalidBoolean: 0x8806, // 34822\n invalidTypeOperation: 0x8807, // 34823\n invalidCard: 0x8808, // 34824\n invalidDebool: 0x8809, // 34825\n globalFuncWithoutArgs: 0x880b, // 34827\n invalidReduce: 0x8810, // 34832\n invalidProjectionTuple: 0x8811, // 34833\n invalidProjectionSet: 0x8812, // 34834\n invalidEnumeration: 0x8813, // 34835\n invalidCortegeDeclare: 0x8814, // 34836\n localOutOfScope: 0x8815, // 34837\n invalidElementPredicate: 0x8816, // 34838\n invalidEmptySetUsage: 0x8817, // 34839\n invalidArgsArity: 0x8818, // 34840\n invalidArgumentType: 0x8819, // 34841\n globalStructure: 0x881c, // 34844\n radicalUsage: 0x8821, // 34849\n invalidFilterArgumentType: 0x8822, // 34850\n invalidFilterArity: 0x8823, // 34851\n arithmeticNotSupported: 0x8824, // 34852\n typesNotCompatible: 0x8825, // 34853\n orderingNotSupported: 0x8826, // 34854\n expectedLogic: 0x8827, // 34855\n expectedSetexpr: 0x8828, // 34856\n invalidArgumentCortegeDeclare: 0x8829, // 34857\n\n globalNoValue: 0x8840, // 34880\n invalidPropertyUsage: 0x8841, // 34881\n\n // Value evaluation (runtime)\n calcUnknownError: 0x8100, // 35328\n setOverflow: 0x8101, // 35329\n booleanBaseLimit: 0x8102, // 35330\n calcGlobalMissing: 0x8103, // 35331\n iterationsLimit: 0x8104, // 35332\n calcInvalidDebool: 0x8105, // 35333\n iterateInfinity: 0x8106, // 35334\n calculationNotSupported: 0x8107, // 35335\n\n cstEmptyDerived: 0x8861, // 34913\n definitionNotAllowed: 0x8862 // 34914\n} as const;\nexport type RSErrorCode = (typeof RSErrorCode)[keyof typeof RSErrorCode];\n\nconst ERROR_EVALUATION_MASK = 0x0100;\nconst ERROR_LEXER_MASK = 0x0200;\nconst ERROR_PARSER_MASK = 0x0400;\nconst ERROR_SEMANTIC_MASK = 0x0800;\n\n/** Infers error class from error type (code). */\nfunction inferErrorClass(error: RSErrorCode): RSErrorClass {\n if ((error & ERROR_EVALUATION_MASK) !== 0) {\n return RSErrorClass.EVALUATION;\n } else if ((error & ERROR_LEXER_MASK) !== 0) {\n return RSErrorClass.LEXER;\n } else if ((error & ERROR_PARSER_MASK) !== 0) {\n return RSErrorClass.PARSER;\n } else if ((error & ERROR_SEMANTIC_MASK) !== 0) {\n return RSErrorClass.SEMANTIC;\n } else {\n return RSErrorClass.UNKNOWN;\n }\n}\n\n/** Generate ErrorID label. */\nexport function getRSErrorPrefix(code: RSErrorCode): string {\n const id = code.toString(16).toUpperCase();\n // prettier-ignore\n switch (inferErrorClass(code)) {\n case RSErrorClass.LEXER: return 'L' + id;\n case RSErrorClass.PARSER: return 'P' + id;\n case RSErrorClass.SEMANTIC: return 'S' + id;\n case RSErrorClass.EVALUATION: return 'E' + id;\n case RSErrorClass.UNKNOWN: return 'U' + id;\n }\n}\n\n/** Checks if error is critical. */\nexport function isCritical(code: RSErrorCode): boolean {\n return code !== RSErrorCode.localDoubleDeclare && code !== RSErrorCode.localNotUsed;\n}\n"],"mappings":";;;AAGA,MAAa,eAAe;CAC1B,OAAO;CACP,QAAQ;CACR,UAAU;CACV,YAAY;CACZ,SAAS;AACX;;AAmBA,MAAa,cAAc;CACzB,eAAe;CACf,oBAAoB;CACpB,mBAAmB;CACnB,sBAAsB;CACtB,iBAAiB;CACjB,mBAAmB;CACnB,oBAAoB;CACpB,eAAe;CACf,cAAc;CAEd,oBAAoB;CACpB,cAAc;CAEd,iBAAiB;CACjB,gBAAgB;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SAAS,YAAY,sBAAsB,SAAS,YAAY;AACzE"}
1
+ {"version":3,"file":"error.js","names":[],"sources":["../../src/rslang/error.ts"],"sourcesContent":["/** Module: Error types and functions. */\n\n/** Represents error class. */\nexport const RSErrorClass = {\n LEXER: 0,\n PARSER: 1,\n SEMANTIC: 2,\n EVALUATION: 3,\n UNKNOWN: 4\n} as const;\nexport type RSErrorClass = (typeof RSErrorClass)[keyof typeof RSErrorClass];\n\n/** Represents RSLang expression error information. */\nexport interface RSErrorInfo {\n code: RSErrorCode;\n params?: readonly string[];\n}\n\n/** Represents RSLang expression error description. */\nexport interface RSErrorDescription extends RSErrorInfo {\n from: number;\n to: number;\n}\n\n/** Error reporter function type. */\nexport type ErrorReporter = (error: RSErrorDescription) => void;\n\n/** Represents RSLang expression error types. */\nexport const RSErrorCode = {\n unknownSyntax: 0x8400, // 33792\n missingParenthesis: 0x8406, // 33798\n missingCurlyBrace: 0x8407, // 33799\n missingSquareBracket: 0x8408, // 33800\n bracketMismatch: 0x8409, // 33801\n doubleParenthesis: 0x840a, // 33802\n missingOpenBracket: 0x840b, // 33803\n expectedLocal: 0x8415, // 33813\n expectedType: 0x8416, // 33814\n\n localDoubleDeclare: 0x2801, // 10241\n localNotUsed: 0x2802, // 10242\n\n localUndeclared: 0x8801, // 34817\n localShadowing: 0x8802, // 34818\n\n typesNotEqual: 0x8803, // 34819\n globalNotTyped: 0x8804, // 34820\n invalidDecart: 0x8805, // 34821\n invalidBoolean: 0x8806, // 34822\n invalidTypeOperation: 0x8807, // 34823\n invalidCard: 0x8808, // 34824\n invalidDebool: 0x8809, // 34825\n globalFuncWithoutArgs: 0x880b, // 34827\n invalidReduce: 0x8810, // 34832\n invalidProjectionTuple: 0x8811, // 34833\n invalidProjectionSet: 0x8812, // 34834\n invalidEnumeration: 0x8813, // 34835\n invalidCortegeDeclare: 0x8814, // 34836\n localOutOfScope: 0x8815, // 34837\n invalidElementPredicate: 0x8816, // 34838\n invalidEmptySetUsage: 0x8817, // 34839\n invalidArgsArity: 0x8818, // 34840\n invalidArgumentType: 0x8819, // 34841\n globalStructure: 0x881c, // 34844\n radicalUsage: 0x8821, // 34849\n invalidFilterArgumentType: 0x8822, // 34850\n invalidFilterArity: 0x8823, // 34851\n arithmeticNotSupported: 0x8824, // 34852\n typesNotCompatible: 0x8825, // 34853\n orderingNotSupported: 0x8826, // 34854\n expectedLogic: 0x8827, // 34855\n expectedSetexpr: 0x8828, // 34856\n invalidArgumentCortegeDeclare: 0x8829, // 34857\n\n globalNoValue: 0x8840, // 34880\n invalidPropertyUsage: 0x8841, // 34881\n\n // Value evaluation (runtime)\n calcUnknownError: 0x8100, // 35328\n setOverflow: 0x8101, // 35329\n booleanBaseLimit: 0x8102, // 35330\n calcGlobalMissing: 0x8103, // 35331\n iterationsLimit: 0x8104, // 35332\n calcInvalidDebool: 0x8105, // 35333\n iterateInfinity: 0x8106, // 35334\n calculationNotSupported: 0x8107, // 35335\n calcInvalidData: 0x8108, // 35336\n\n cstEmptyDerived: 0x8861, // 34913\n definitionNotAllowed: 0x8862 // 34914\n} as const;\nexport type RSErrorCode = (typeof RSErrorCode)[keyof typeof RSErrorCode];\n\nconst ERROR_EVALUATION_MASK = 0x0100;\nconst ERROR_LEXER_MASK = 0x0200;\nconst ERROR_PARSER_MASK = 0x0400;\nconst ERROR_SEMANTIC_MASK = 0x0800;\n\n/** Infers error class from error type (code). */\nfunction inferErrorClass(error: RSErrorCode): RSErrorClass {\n if ((error & ERROR_EVALUATION_MASK) !== 0) {\n return RSErrorClass.EVALUATION;\n } else if ((error & ERROR_LEXER_MASK) !== 0) {\n return RSErrorClass.LEXER;\n } else if ((error & ERROR_PARSER_MASK) !== 0) {\n return RSErrorClass.PARSER;\n } else if ((error & ERROR_SEMANTIC_MASK) !== 0) {\n return RSErrorClass.SEMANTIC;\n } else {\n return RSErrorClass.UNKNOWN;\n }\n}\n\n/** Generate ErrorID label. */\nexport function getRSErrorPrefix(code: RSErrorCode): string {\n const id = code.toString(16).toUpperCase();\n // prettier-ignore\n switch (inferErrorClass(code)) {\n case RSErrorClass.LEXER: return 'L' + id;\n case RSErrorClass.PARSER: return 'P' + id;\n case RSErrorClass.SEMANTIC: return 'S' + id;\n case RSErrorClass.EVALUATION: return 'E' + id;\n case RSErrorClass.UNKNOWN: return 'U' + id;\n }\n}\n\n/** Checks if error is critical. */\nexport function isCritical(code: RSErrorCode): boolean {\n return code !== RSErrorCode.localDoubleDeclare && code !== RSErrorCode.localNotUsed;\n}\n"],"mappings":";;;AAGA,MAAa,eAAe;CAC1B,OAAO;CACP,QAAQ;CACR,UAAU;CACV,YAAY;CACZ,SAAS;AACX;;AAmBA,MAAa,cAAc;CACzB,eAAe;CACf,oBAAoB;CACpB,mBAAmB;CACnB,sBAAsB;CACtB,iBAAiB;CACjB,mBAAmB;CACnB,oBAAoB;CACpB,eAAe;CACf,cAAc;CAEd,oBAAoB;CACpB,cAAc;CAEd,iBAAiB;CACjB,gBAAgB;CAEhB,eAAe;CACf,gBAAgB;CAChB,eAAe;CACf,gBAAgB;CAChB,sBAAsB;CACtB,aAAa;CACb,eAAe;CACf,uBAAuB;CACvB,eAAe;CACf,wBAAwB;CACxB,sBAAsB;CACtB,oBAAoB;CACpB,uBAAuB;CACvB,iBAAiB;CACjB,yBAAyB;CACzB,sBAAsB;CACtB,kBAAkB;CAClB,qBAAqB;CACrB,iBAAiB;CACjB,cAAc;CACd,2BAA2B;CAC3B,oBAAoB;CACpB,wBAAwB;CACxB,oBAAoB;CACpB,sBAAsB;CACtB,eAAe;CACf,iBAAiB;CACjB,+BAA+B;CAE/B,eAAe;CACf,sBAAsB;CAGtB,kBAAkB;CAClB,aAAa;CACb,kBAAkB;CAClB,mBAAmB;CACnB,iBAAiB;CACjB,mBAAmB;CACnB,iBAAiB;CACjB,yBAAyB;CACzB,iBAAiB;CAEjB,iBAAiB;CACjB,sBAAsB;AACxB;AAGA,MAAM,wBAAwB;AAC9B,MAAM,mBAAmB;AACzB,MAAM,oBAAoB;AAC1B,MAAM,sBAAsB;;AAG5B,SAAS,gBAAgB,OAAkC;CACzD,KAAK,QAAQ,2BAA2B,GACtC,OAAO,aAAa;MACf,KAAK,QAAQ,sBAAsB,GACxC,OAAO,aAAa;MACf,KAAK,QAAQ,uBAAuB,GACzC,OAAO,aAAa;MACf,KAAK,QAAQ,yBAAyB,GAC3C,OAAO,aAAa;MAEpB,OAAO,aAAa;AAExB;;AAGA,SAAgB,iBAAiB,MAA2B;CAC1D,MAAM,KAAK,KAAK,SAAS,EAAE,CAAC,CAAC,YAAY;CAEzC,QAAQ,gBAAgB,IAAI,GAA5B;EACE,KAAK,aAAa,OAAO,OAAO,MAAM;EACtC,KAAK,aAAa,QAAQ,OAAO,MAAM;EACvC,KAAK,aAAa,UAAU,OAAO,MAAM;EACzC,KAAK,aAAa,YAAY,OAAO,MAAM;EAC3C,KAAK,aAAa,SAAS,OAAO,MAAM;CAC1C;AACF;;AAGA,SAAgB,WAAW,MAA4B;CACrD,OAAO,SAAS,YAAY,sBAAsB,SAAS,YAAY;AACzE"}
@@ -1,2 +1,2 @@
1
- import { n as CalculatorResult, r as RSCalculator, t as CalculatorEvaluateOptions } from "../../calculator-C9W2jkSx.js";
1
+ import { n as CalculatorResult, r as RSCalculator, t as CalculatorEvaluateOptions } from "../../calculator-DFevxZyV.js";
2
2
  export { CalculatorEvaluateOptions, CalculatorResult, RSCalculator };
@@ -1,6 +1,6 @@
1
1
  import { annotateError } from "../ast-annotations.js";
2
2
  import { RSErrorCode } from "../error.js";
3
- import { j as validateValue } from "../../value-B8UtCqaK.js";
3
+ import { M as validateValue } from "../../value-ybFBRuz6.js";
4
4
  import { Evaluator } from "./evaluator.js";
5
5
  //#region src/rslang/eval/calculator.ts
6
6
  /** AST calculator - evaluates RS expressions via visitor pattern and provides updates via listeners. */
@@ -1,5 +1,5 @@
1
1
  import { t as AstNode } from "../../ast-C8sIpKdL.js";
2
- import { c as Value } from "../../value-CTjX6825.js";
2
+ import { l as Value } from "../../value-BduA_ZGp.js";
3
3
 
4
4
  //#region src/rslang/eval/evaluation-cache.d.ts
5
5
  /** Static metadata for one AST node. */
@@ -1,6 +1,6 @@
1
1
  import { t as AstNode } from "../../ast-C8sIpKdL.js";
2
- import { t as ErrorReporter } from "../../error-E1LVq_3w.js";
3
- import { c as Value, l as ValueContext } from "../../value-CTjX6825.js";
2
+ import { t as ErrorReporter } from "../../error-deey7EiC.js";
3
+ import { l as Value, u as ValueContext } from "../../value-BduA_ZGp.js";
4
4
 
5
5
  //#region src/rslang/eval/evaluator.d.ts
6
6
  /** AST context. */
@@ -4,7 +4,7 @@ import { getNodeIndices, getNodeText } from "../../parsing/ast.js";
4
4
  import "../../parsing/index.js";
5
5
  import { TokenID } from "../parser/token.js";
6
6
  import { EvaluationCache, EvaluationMetadata } from "./evaluation-cache.js";
7
- import { C as projection, E as setIntersection, O as setSymDiff, T as setDiff, c as compare, d as tuple, f as boolean, i as SET_INFINITY, k as setUnion, m as contains, n as EmptySetV, p as cartesianProduct, u as set, v as isSubsetOrEq, w as reduce } from "../../value-B8UtCqaK.js";
7
+ import { A as setUnion, D as setIntersection, E as setDiff, T as reduce, a as SET_INFINITY, d as set, f as tuple, h as contains, k as setSymDiff, l as compare, m as cartesianProduct, n as CalcInvalidDataError, p as boolean, r as EmptySetV, w as projection, y as isSubsetOrEq } from "../../value-ybFBRuz6.js";
8
8
  //#region src/rslang/eval/evaluator.ts
9
9
  /**
10
10
  * Module: AST evaluation - visitor-pattern evaluator for RS expressions.
@@ -98,9 +98,15 @@ var Evaluator = class {
98
98
  if (cached !== void 0) return cached;
99
99
  }
100
100
  }
101
- const result = this.dispatchVisitImpl(node);
102
- if (!this.disableCache && result !== null && info.cacheable && stamp !== null) this.evalCache.store(info.structuralKey, stamp, result);
103
- return result;
101
+ try {
102
+ const result = this.dispatchVisitImpl(node);
103
+ if (!this.disableCache && result !== null && info.cacheable && stamp !== null) this.evalCache.store(info.structuralKey, stamp, result);
104
+ return result;
105
+ } catch (error) {
106
+ if (error instanceof CalcInvalidDataError) return this.onError(RSErrorCode.calcInvalidData, node, [error.left, error.right]);
107
+ this.onError(RSErrorCode.calcUnknownError, node);
108
+ return null;
109
+ }
104
110
  }
105
111
  dispatchVisitImpl(node) {
106
112
  switch (node.typeID) {
@@ -161,13 +167,15 @@ var Evaluator = class {
161
167
  }
162
168
  visitGlobal(node) {
163
169
  const alias = getNodeText(node);
164
- const value = this.context.get(alias);
165
- if (value === void 0) return this.onError(RSErrorCode.calcGlobalMissing, node, [alias]);
170
+ const value = this.context.get(alias) ?? null;
171
+ if (value === null) return this.onError(RSErrorCode.calcGlobalMissing, node, [alias]);
166
172
  return value;
167
173
  }
168
174
  visitLocal(node) {
169
175
  const alias = getNodeText(node);
170
- return this.locals.getLocal(alias);
176
+ const value = this.locals.findLocal(alias);
177
+ if (value === null) return this.onError(RSErrorCode.localUndeclared, node, [alias]);
178
+ return value;
171
179
  }
172
180
  visitFunctionCall(node) {
173
181
  const funcName = getNodeText(node.children[0]);
@@ -585,10 +593,8 @@ var LocalContext = class {
585
593
  value
586
594
  });
587
595
  }
588
- getLocal(alias) {
589
- const binding = this.data.get(alias);
590
- if (binding === void 0) throw new Error(`Local variable "${alias}" not found`);
591
- return binding.value;
596
+ findLocal(alias) {
597
+ return this.data.get(alias)?.value ?? null;
592
598
  }
593
599
  buildDependencyStamp(reads) {
594
600
  if (reads.size === 0) return "";