@rsconcept/domain 3.0.2 → 3.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.
Files changed (73) hide show
  1. package/dist/{analyzer-CzFaWR7w.d.ts → analyzer-B35QsI3L.d.ts} +2 -2
  2. package/dist/{ast-annotations-x4PJ_Lhc.d.ts → ast-annotations-DclU1Ser.d.ts} +2 -2
  3. package/dist/{calculator-uPaTV3hc.d.ts → calculator-B-1p712X.d.ts} +2 -2
  4. package/dist/{diagnostics-DKyMf6q-.d.ts → diagnostics-D4_B7rt2.d.ts} +3 -3
  5. package/dist/{diagnostics-D1Cp21nP.js → diagnostics-D_4TpAH4.js} +4 -5
  6. package/dist/{diagnostics-D1Cp21nP.js.map → diagnostics-D_4TpAH4.js.map} +1 -1
  7. package/dist/{error-B0EkIx4K.d.ts → error-S1JghCNN.d.ts} +30 -2
  8. package/dist/{index-CnuO4w8e.d.ts → index-D-w-bgei.d.ts} +4 -4
  9. package/dist/{index-DCO4mxiO.d.ts → index-DzvllU3P.d.ts} +4 -4
  10. package/dist/index.d.ts +6 -6
  11. package/dist/index.js +4 -4
  12. package/dist/library/diagnostics.d.ts +1 -1
  13. package/dist/library/diagnostics.js +1 -1
  14. package/dist/library/index.d.ts +2 -2
  15. package/dist/library/index.js +1 -1
  16. package/dist/library/oss-api.d.ts +1 -1
  17. package/dist/library/oss-api.js +2 -4
  18. package/dist/library/oss-api.js.map +1 -1
  19. package/dist/library/oss.js +1 -1
  20. package/dist/library/rsengine.d.ts +3 -3
  21. package/dist/library/rsengine.js +4 -3
  22. package/dist/library/rsengine.js.map +1 -1
  23. package/dist/library/rsform-api/index.d.ts +1 -1
  24. package/dist/library/rsform-api/index.js +1 -1
  25. package/dist/library/rsform.d.ts +1 -1
  26. package/dist/library/rsmodel-api.d.ts +3 -3
  27. package/dist/library/rsmodel-api.js +20 -4
  28. package/dist/library/rsmodel-api.js.map +1 -1
  29. package/dist/library/rsmodel.d.ts +1 -1
  30. package/dist/library/structure-planner.d.ts +2 -2
  31. package/dist/library/structure-planner.js +1 -1
  32. package/dist/parsing/lezer-tree.js.map +1 -1
  33. package/dist/rslang/api.js +9 -6
  34. package/dist/rslang/api.js.map +1 -1
  35. package/dist/rslang/ast-annotations.d.ts +1 -1
  36. package/dist/rslang/error.d.ts +2 -2
  37. package/dist/rslang/error.js +16 -1
  38. package/dist/rslang/error.js.map +1 -1
  39. package/dist/rslang/eval/calculator.d.ts +1 -1
  40. package/dist/rslang/eval/calculator.js +1 -1
  41. package/dist/rslang/eval/evaluation-cache.js +1 -3
  42. package/dist/rslang/eval/evaluation-cache.js.map +1 -1
  43. package/dist/rslang/eval/evaluator.d.ts +12 -2
  44. package/dist/rslang/eval/evaluator.js +42 -8
  45. package/dist/rslang/eval/evaluator.js.map +1 -1
  46. package/dist/rslang/eval/value-api.js +1 -1
  47. package/dist/rslang/eval/value.js +1 -1
  48. package/dist/rslang/index.d.ts +6 -6
  49. package/dist/rslang/index.js +3 -3
  50. package/dist/rslang/parser/normalize.js.map +1 -1
  51. package/dist/rslang/parser/parser.terms.js.map +1 -1
  52. package/dist/rslang/parser/syntax-errors/index.d.ts +1 -1
  53. package/dist/rslang/semantic/analyzer.d.ts +1 -1
  54. package/dist/rslang/semantic/arguments-extractor.js +6 -4
  55. package/dist/rslang/semantic/arguments-extractor.js.map +1 -1
  56. package/dist/rslang/semantic/type-auditor.d.ts +1 -1
  57. package/dist/rslang/semantic/type-auditor.js +20 -16
  58. package/dist/rslang/semantic/type-auditor.js.map +1 -1
  59. package/dist/rslang/semantic/typification-api.js +10 -9
  60. package/dist/rslang/semantic/typification-api.js.map +1 -1
  61. package/dist/rslang/semantic/typification-parser.js +4 -1
  62. package/dist/rslang/semantic/typification-parser.js.map +1 -1
  63. package/dist/rslang/semantic/value-auditor.d.ts +1 -1
  64. package/dist/{value-COprb2Je.js → value-BDISzQqI.js} +3 -2
  65. package/dist/{value-COprb2Je.js.map → value-BDISzQqI.js.map} +1 -1
  66. package/package.json +23 -22
  67. package/src/index.ts +1 -1
  68. package/src/library/rsmodel-api.ts +27 -0
  69. package/src/rslang/error.test.ts +23 -0
  70. package/src/rslang/error.ts +42 -0
  71. package/src/rslang/eval/evaluator.test.ts +56 -1
  72. package/src/rslang/eval/evaluator.ts +50 -7
  73. package/src/rslang/index.ts +1 -1
@@ -1,13 +1,13 @@
1
1
  import "./typification-hWUoWCba.js";
2
- import "./error-B0EkIx4K.js";
3
- import "./ast-annotations-x4PJ_Lhc.js";
2
+ import "./error-S1JghCNN.js";
3
+ import "./ast-annotations-DclU1Ser.js";
4
4
  import "./value-XpJOVzMP.js";
5
- import "./calculator-uPaTV3hc.js";
5
+ import "./calculator-B-1p712X.js";
6
6
  import "./value-api-Dw8UkwCD.js";
7
7
  import "./parser-DkejtiOR.js";
8
8
  import "./token-DeXAmzwr.js";
9
9
  import "./value-class-CNI-lqXJ.js";
10
- import "./analyzer-CzFaWR7w.js";
10
+ import "./analyzer-B35QsI3L.js";
11
11
  import "./arguments-extractor-CXWRT5Ou.js";
12
12
  import "./typification-parser-DFxj4JiQ.js";
13
13
  import "./typification-graph-CSxDt18X.js";
@@ -4,10 +4,10 @@ import { t as AstNode } from "./ast-D-D6Rq3T.js";
4
4
  import "./index-D5RahF1K.js";
5
5
  import { f as ExpressionType, g as TypeClass, y as TypePath } from "./typification-hWUoWCba.js";
6
6
  import { t as ValueClass } from "./value-class-CNI-lqXJ.js";
7
- import { r as AnalysisFull } from "./analyzer-CzFaWR7w.js";
8
- import "./index-CnuO4w8e.js";
7
+ import { r as AnalysisFull } from "./analyzer-B35QsI3L.js";
8
+ import "./index-D-w-bgei.js";
9
9
  import { r as LibraryItem } from "./library-CYun28Xz.js";
10
- import { C as RSFormStats, S as RSForm, T as TermForm, _ as Attribution, b as CstStatus, g as ArgumentValue, v as Constituenta, w as Substitution, x as CstType, y as CstClass } from "./diagnostics-DKyMf6q-.js";
10
+ import { C as RSFormStats, S as RSForm, T as TermForm, _ as Attribution, b as CstStatus, g as ArgumentValue, v as Constituenta, w as Substitution, x as CstType, y as CstClass } from "./diagnostics-D4_B7rt2.js";
11
11
  import { t as AliasMapping } from "./api-DgecYHjR.js";
12
12
  //#region src/library/rsform-api/types.d.ts
13
13
  /** Fields needed to restore formal dependency order. */
@@ -375,4 +375,4 @@ declare function insertItemAfter<T extends {
375
375
  }>(items: T[], item: T, insertAfter: number | null | undefined): void;
376
376
  //#endregion
377
377
  export { removeAliasReference as $, canProduceStructure as A, filterAttributions as B, restoreConstituentOrder as C, inferTemplatedType as D, inferTemplate as E, isBasicConcept as F, MappableFields as G, remapAttributionsUnderSubstitution as H, isFunctional as I, applyMappingToConstituents as J, addAliasReference as K, isLogical as L, guessCstType as M, inferClass as N, normalizeExpression as O, isBaseSet as P, maxAliasIndex as Q, isTemplateCst as R, buildFormalDependencyGraph as S, inferStatus as T, getAnalysisFor as U, importAttributions as V, refineAnalysisForDependencyCycles as W, buildSequentialAliasMapping as X, argumentValuesToMapping as Y, generateAlias as Z, findCstByStructure as _, buildDefinitionReferenceGraph as a, DiagnosticSourceFields as at, calculateSchemaStats as b, resolveConstituentTextChange as c, SchemaIssueFields as ct, SynthesizableFields as d, SpawnPathFields as dt, validateAliasFormat as et, inlineSynthesis as f, StructureCapableFields as ft, remapSubstitutionsAfterImport as g, applyConstituentSubstitutions as h, TextResolvableFields as ht, TextChangeOptions as i, DescribableFields as it, getCstTypePrefix as j, canHaveManualTypification as k, InlineSynthesisInput as l, SearchableFields as lt, SubstitutionResult as m, TemplateSourceFields as mt, moveIdsInOrder as n, AliasTypedFields as nt, buildTermReferenceGraph as o, FormalOrderFields as ot, sortItemsForInlineSynthesis as p, TemplateParamSourceFields as pt, allocateImportAliases as q, reorderItemsByIds as r, BasicTextCheckFields as rt, resolveAllConstituentTexts as s, ModelEvalFields as st, insertItemAfter as t, validateNewAlias as tt, InlineSynthesisResult as u, SemanticRelations as ut, getStructureName as v, applyFilterCategory as w, isSchemaIssue as x, inferNewSpawnPosition as y, typeClassForCstType as z };
378
- //# sourceMappingURL=index-DCO4mxiO.d.ts.map
378
+ //# sourceMappingURL=index-DzvllU3P.d.ts.map
package/dist/index.d.ts CHANGED
@@ -5,22 +5,22 @@ import { a as TOKEN_ERROR, c as flattenAst, d as printAst, f as visitAstDFS, i a
5
5
  import { t as Branded } from "./branded-ZlzIcxzu.js";
6
6
  import { n as generateStub, t as applyHash_fnv1a } from "./hash-Y8I4c6Al.js";
7
7
  import { A 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-hWUoWCba.js";
8
- import { i as RSErrorDescription, r as RSErrorCode } from "./error-B0EkIx4K.js";
9
- import { i as readTypeAnnotation, r as readErrorAnnotation } from "./ast-annotations-x4PJ_Lhc.js";
8
+ import { a as RSErrorDescription, i as RSErrorCode, n as EvalStackFrame, s as formatEvalCallStack } from "./error-S1JghCNN.js";
9
+ import { i as readTypeAnnotation, r as readErrorAnnotation } from "./ast-annotations-DclU1Ser.js";
10
10
  import { d as ValuePath, l as Value, o as TUPLE_ID, p as makeValuePath } from "./value-XpJOVzMP.js";
11
- import { n as CalculatorResult, r as RSCalculator, t as CalculatorEvaluateOptions } from "./calculator-uPaTV3hc.js";
11
+ import { n as CalculatorResult, r as RSCalculator, t as CalculatorEvaluateOptions } from "./calculator-B-1p712X.js";
12
12
  import { d as printValue } from "./value-api-Dw8UkwCD.js";
13
13
  import { t as parser } from "./parser-DkejtiOR.js";
14
14
  import { t as TokenID } from "./token-DeXAmzwr.js";
15
15
  import { t as ValueClass } from "./value-class-CNI-lqXJ.js";
16
- import { a as RSLangAnalyzer, n as AnalysisFast, r as AnalysisFull, t as AnalysisBase } from "./analyzer-CzFaWR7w.js";
16
+ import { a as RSLangAnalyzer, n as AnalysisFast, r as AnalysisFull, t as AnalysisBase } from "./analyzer-B35QsI3L.js";
17
17
  import { n as ArgumentsType } from "./arguments-extractor-CXWRT5Ou.js";
18
18
  import { n as applyAsciiTypeSubstitutions, r as parseTypeText } from "./typification-parser-DFxj4JiQ.js";
19
19
  import { n as TypificationNodeData, t as TypificationGraph } from "./typification-graph-CSxDt18X.js";
20
20
  import { a as LibraryItemType, i as LibraryItemReference, n as CurrentVersion, o as LocationHead, r as LibraryItem, s as VersionInfo, t as AccessPolicy } from "./library-CYun28Xz.js";
21
- import { C as RSFormStats, E as TypeInfo, S as RSForm, T as TermForm, _ as Attribution, a as detectDependencyCycleDiagnostics, b as CstStatus, c as modelStatusCstDiagnostic, d as DEFAULT_VALUE_TEXT, f as EvalStatus, g as ArgumentValue, i as assignSchemaDiagnostics, l as BasicBinding, m as RSModelStats, n as DiagnosticKind, o as formatDependencyCycle, p as RSModel, r as RSDiagnosticCode, s as hasCstDiagnostic, t as CstDiagnostic, u as BasicsContext, v as Constituenta, w as Substitution, x as CstType, y as CstClass } from "./diagnostics-DKyMf6q-.js";
21
+ import { C as RSFormStats, E as TypeInfo, S as RSForm, T as TermForm, _ as Attribution, a as detectDependencyCycleDiagnostics, b as CstStatus, c as modelStatusCstDiagnostic, d as DEFAULT_VALUE_TEXT, f as EvalStatus, g as ArgumentValue, i as assignSchemaDiagnostics, l as BasicBinding, m as RSModelStats, n as DiagnosticKind, o as formatDependencyCycle, p as RSModel, r as RSDiagnosticCode, s as hasCstDiagnostic, t as CstDiagnostic, u as BasicsContext, v as Constituenta, w as Substitution, x as CstType, y as CstClass } from "./diagnostics-D4_B7rt2.js";
22
22
  import { FolderNode, FolderTree } from "./library/folder-tree.js";
23
23
  import { n as OssLayout, r as Position2D } from "./oss-layout-3glgAqfn.js";
24
24
  import { Block, CstSubstituteInfo, NodeType, Operation, OperationInput, OperationSchema, OperationSchemaStats, OperationSynthesis, OperationType, OssItem, SubstitutionErrorDescription, SubstitutionErrorType } from "./library/oss.js";
25
25
  import { RSEngine } from "./library/rsengine.js";
26
- export { AccessPolicy, type AnalysisBase, type AnalysisFast, type AnalysisFull, AnyTypificationT, type ArgumentValue, type ArgumentsType, type AstNode, type AstNodeBase, type Attribution, type BasicBinding, type BasicsContext, type Block, type Branded, type CMSyntaxNode, type CalculatorEvaluateOptions, type CalculatorResult, type Constituenta, CstClass, type CstDiagnostic, CstStatus, type CstSubstituteInfo, CstType, type CurrentVersion, DEFAULT_VALUE_TEXT, DiagnosticKind, EmptySetT, type EntityReference, EvalStatus, type ExpressionType, type FlatAST, type FlatAstNode, FolderNode, FolderTree, Grammeme, Graph, type LibraryItem, type LibraryItemReference, LibraryItemType, LocationHead, LogicT, NodeType, type Operation, type OperationInput, type OperationSchema, type OperationSchemaStats, type OperationSynthesis, OperationType, type OssItem, type OssLayout, type Position2D, RSCalculator, RSDiagnosticCode, RSEngine, RSErrorCode, type RSErrorDescription, type RSForm, type RSFormStats, RSLangAnalyzer, type RSModel, type RSModelStats, ReferenceType, type Substitution, type SubstitutionErrorDescription, SubstitutionErrorType, type SyntacticReference, TOKEN_ERROR, TUPLE_ID, type TermContext, type TermForm, TokenID, TypeClass, TypeID, type TypeInfo, type TypePath, type Typification, TypificationGraph, type TypificationNodeData, type Value, ValueClass, type ValuePath, type VersionInfo, type WordForm, applyAsciiTypeSubstitutions, applyHash_fnv1a, assignSchemaDiagnostics, buildTree, detectDependencyCycleDiagnostics, findByUid, flattenAst, formatDependencyCycle, generateStub, getNodeIndices, getNodeText, hasCstDiagnostic, makeTypePath, makeValuePath, modelStatusCstDiagnostic, parseTypeText, printAst, printTree, printValue, readErrorAnnotation, readTypeAnnotation, parser as rslangParser, supportedGrammemes, visitAstDFS };
26
+ export { AccessPolicy, type AnalysisBase, type AnalysisFast, type AnalysisFull, AnyTypificationT, type ArgumentValue, type ArgumentsType, type AstNode, type AstNodeBase, type Attribution, type BasicBinding, type BasicsContext, type Block, type Branded, type CMSyntaxNode, type CalculatorEvaluateOptions, type CalculatorResult, type Constituenta, CstClass, type CstDiagnostic, CstStatus, type CstSubstituteInfo, CstType, type CurrentVersion, DEFAULT_VALUE_TEXT, DiagnosticKind, EmptySetT, type EntityReference, type EvalStackFrame, EvalStatus, type ExpressionType, type FlatAST, type FlatAstNode, FolderNode, FolderTree, Grammeme, Graph, type LibraryItem, type LibraryItemReference, LibraryItemType, LocationHead, LogicT, NodeType, type Operation, type OperationInput, type OperationSchema, type OperationSchemaStats, type OperationSynthesis, OperationType, type OssItem, type OssLayout, type Position2D, RSCalculator, RSDiagnosticCode, RSEngine, RSErrorCode, type RSErrorDescription, type RSForm, type RSFormStats, RSLangAnalyzer, type RSModel, type RSModelStats, ReferenceType, type Substitution, type SubstitutionErrorDescription, SubstitutionErrorType, type SyntacticReference, TOKEN_ERROR, TUPLE_ID, type TermContext, type TermForm, TokenID, TypeClass, TypeID, type TypeInfo, type TypePath, type Typification, TypificationGraph, type TypificationNodeData, type Value, ValueClass, type ValuePath, type VersionInfo, type WordForm, applyAsciiTypeSubstitutions, applyHash_fnv1a, assignSchemaDiagnostics, buildTree, detectDependencyCycleDiagnostics, findByUid, flattenAst, formatDependencyCycle, formatEvalCallStack, generateStub, getNodeIndices, getNodeText, hasCstDiagnostic, makeTypePath, makeValuePath, modelStatusCstDiagnostic, parseTypeText, printAst, printTree, printValue, readErrorAnnotation, readTypeAnnotation, parser as rslangParser, supportedGrammemes, visitAstDFS };
package/dist/index.js CHANGED
@@ -7,18 +7,18 @@ import { AnyTypificationT, EmptySetT, LogicT, TypeClass, TypeID, makeTypePath }
7
7
  import { parser } from "./rslang/parser/parser.js";
8
8
  import { readErrorAnnotation, readTypeAnnotation } from "./rslang/ast-annotations.js";
9
9
  import { CstClass, CstStatus, CstType } from "./library/rsform.js";
10
- import { RSErrorCode } from "./rslang/error.js";
10
+ import { RSErrorCode, formatEvalCallStack } from "./rslang/error.js";
11
11
  import { applyHash_fnv1a, generateStub } from "./shared/hash.js";
12
- import { C as printValue, o as TUPLE_ID, u as makeValuePath } from "./value-COprb2Je.js";
12
+ import { C as printValue, o as TUPLE_ID, u as makeValuePath } from "./value-BDISzQqI.js";
13
13
  import { RSCalculator } from "./rslang/eval/calculator.js";
14
14
  import { ValueClass } from "./rslang/semantic/value-class.js";
15
15
  import { RSLangAnalyzer } from "./rslang/semantic/analyzer.js";
16
16
  import { applyAsciiTypeSubstitutions, parseTypeText } from "./rslang/semantic/typification-parser.js";
17
17
  import { TypificationGraph } from "./rslang/typification-graph.js";
18
- import { a as formatDependencyCycle, i as detectDependencyCycleDiagnostics, n as RSDiagnosticCode, o as hasCstDiagnostic, r as assignSchemaDiagnostics, s as modelStatusCstDiagnostic, t as DiagnosticKind } from "./diagnostics-D1Cp21nP.js";
18
+ import { a as formatDependencyCycle, i as detectDependencyCycleDiagnostics, n as RSDiagnosticCode, o as hasCstDiagnostic, r as assignSchemaDiagnostics, s as modelStatusCstDiagnostic, t as DiagnosticKind } from "./diagnostics-D_4TpAH4.js";
19
19
  import { DEFAULT_VALUE_TEXT, EvalStatus } from "./library/rsmodel.js";
20
20
  import { FolderNode, FolderTree } from "./library/folder-tree.js";
21
21
  import { AccessPolicy, LibraryItemType, LocationHead } from "./library/library.js";
22
22
  import { NodeType, OperationType, SubstitutionErrorType } from "./library/oss.js";
23
23
  import { RSEngine } from "./library/rsengine.js";
24
- export { AccessPolicy, AnyTypificationT, CstClass, CstStatus, CstType, DEFAULT_VALUE_TEXT, DiagnosticKind, EmptySetT, EvalStatus, FolderNode, FolderTree, Grammeme, Graph, LibraryItemType, LocationHead, LogicT, NodeType, OperationType, RSCalculator, RSDiagnosticCode, RSEngine, RSErrorCode, RSLangAnalyzer, ReferenceType, SubstitutionErrorType, TOKEN_ERROR, TUPLE_ID, TokenID, TypeClass, TypeID, TypificationGraph, ValueClass, applyAsciiTypeSubstitutions, applyHash_fnv1a, assignSchemaDiagnostics, buildTree, detectDependencyCycleDiagnostics, findByUid, flattenAst, formatDependencyCycle, generateStub, getNodeIndices, getNodeText, hasCstDiagnostic, makeTypePath, makeValuePath, modelStatusCstDiagnostic, parseTypeText, printAst, printTree, printValue, readErrorAnnotation, readTypeAnnotation, parser as rslangParser, supportedGrammemes, visitAstDFS };
24
+ export { AccessPolicy, AnyTypificationT, CstClass, CstStatus, CstType, DEFAULT_VALUE_TEXT, DiagnosticKind, EmptySetT, EvalStatus, FolderNode, FolderTree, Grammeme, Graph, LibraryItemType, LocationHead, LogicT, NodeType, OperationType, RSCalculator, RSDiagnosticCode, RSEngine, RSErrorCode, RSLangAnalyzer, ReferenceType, SubstitutionErrorType, TOKEN_ERROR, TUPLE_ID, TokenID, TypeClass, TypeID, TypificationGraph, ValueClass, applyAsciiTypeSubstitutions, applyHash_fnv1a, assignSchemaDiagnostics, buildTree, detectDependencyCycleDiagnostics, findByUid, flattenAst, formatDependencyCycle, formatEvalCallStack, generateStub, getNodeIndices, getNodeText, hasCstDiagnostic, makeTypePath, makeValuePath, modelStatusCstDiagnostic, parseTypeText, printAst, printTree, printValue, readErrorAnnotation, readTypeAnnotation, parser as rslangParser, supportedGrammemes, visitAstDFS };
@@ -1,2 +1,2 @@
1
- import { a as detectDependencyCycleDiagnostics, c as modelStatusCstDiagnostic, i as assignSchemaDiagnostics, n as DiagnosticKind, o as formatDependencyCycle, r as RSDiagnosticCode, s as hasCstDiagnostic, t as CstDiagnostic } from "../diagnostics-DKyMf6q-.js";
1
+ import { a as detectDependencyCycleDiagnostics, c as modelStatusCstDiagnostic, i as assignSchemaDiagnostics, n as DiagnosticKind, o as formatDependencyCycle, r as RSDiagnosticCode, s as hasCstDiagnostic, t as CstDiagnostic } from "../diagnostics-D4_B7rt2.js";
2
2
  export { CstDiagnostic, DiagnosticKind, RSDiagnosticCode, assignSchemaDiagnostics, detectDependencyCycleDiagnostics, formatDependencyCycle, hasCstDiagnostic, modelStatusCstDiagnostic };
@@ -1,2 +1,2 @@
1
- import { a as formatDependencyCycle, i as detectDependencyCycleDiagnostics, n as RSDiagnosticCode, o as hasCstDiagnostic, r as assignSchemaDiagnostics, s as modelStatusCstDiagnostic, t as DiagnosticKind } from "../diagnostics-D1Cp21nP.js";
1
+ import { a as formatDependencyCycle, i as detectDependencyCycleDiagnostics, n as RSDiagnosticCode, o as hasCstDiagnostic, r as assignSchemaDiagnostics, s as modelStatusCstDiagnostic, t as DiagnosticKind } from "../diagnostics-D_4TpAH4.js";
2
2
  export { DiagnosticKind, RSDiagnosticCode, assignSchemaDiagnostics, detectDependencyCycleDiagnostics, formatDependencyCycle, hasCstDiagnostic, modelStatusCstDiagnostic };
@@ -1,10 +1,10 @@
1
1
  import { a as LibraryItemType, i as LibraryItemReference, n as CurrentVersion, o as LocationHead, r as LibraryItem, s as VersionInfo, t as AccessPolicy } from "../library-CYun28Xz.js";
2
- import { C as RSFormStats, E as TypeInfo, S as RSForm, T as TermForm, _ as Attribution, a as detectDependencyCycleDiagnostics, b as CstStatus, c as modelStatusCstDiagnostic, d as DEFAULT_VALUE_TEXT, f as EvalStatus, g as ArgumentValue, i as assignSchemaDiagnostics, l as BasicBinding, m as RSModelStats, n as DiagnosticKind, o as formatDependencyCycle, p as RSModel, r as RSDiagnosticCode, s as hasCstDiagnostic, t as CstDiagnostic, u as BasicsContext, v as Constituenta, w as Substitution, x as CstType, y as CstClass } from "../diagnostics-DKyMf6q-.js";
2
+ import { C as RSFormStats, E as TypeInfo, S as RSForm, T as TermForm, _ as Attribution, a as detectDependencyCycleDiagnostics, b as CstStatus, c as modelStatusCstDiagnostic, d as DEFAULT_VALUE_TEXT, f as EvalStatus, g as ArgumentValue, i as assignSchemaDiagnostics, l as BasicBinding, m as RSModelStats, n as DiagnosticKind, o as formatDependencyCycle, p as RSModel, r as RSDiagnosticCode, s as hasCstDiagnostic, t as CstDiagnostic, u as BasicsContext, v as Constituenta, w as Substitution, x as CstType, y as CstClass } from "../diagnostics-D4_B7rt2.js";
3
3
  import { FolderNode, FolderTree } from "./folder-tree.js";
4
4
  import { n as OssLayout, r as Position2D } from "../oss-layout-3glgAqfn.js";
5
5
  import { Block, CstSubstituteInfo, NodeType, Operation, OperationInput, OperationSchema, OperationSchemaStats, OperationSynthesis, OperationType, OssItem, SubstitutionErrorDescription, SubstitutionErrorType } from "./oss.js";
6
6
  import { RSEngine } from "./rsengine.js";
7
- import { mt as TemplateSourceFields } from "../index-DCO4mxiO.js";
7
+ import { mt as TemplateSourceFields } from "../index-DzvllU3P.js";
8
8
  //#region src/library/template-instantiation.d.ts
9
9
  /**
10
10
  * Payload for one {@link Constituenta} to create when instantiating an expression-bank template.
@@ -5,7 +5,7 @@ import { TypeID } from "../rslang/semantic/typification.js";
5
5
  import { labelType } from "../rslang/labels.js";
6
6
  import { applyAliasMapping, isGlobalAlias, parseRSLangExpression, splitTemplateDefinition, substituteLocalAliases, substituteTemplateArgs } from "../rslang/api.js";
7
7
  import { CstClass, CstStatus, CstType } from "./rsform.js";
8
- import { $ as isFunctional, A as normalizeExpression, R as applyMappingToConstituents, V as generateAlias, a as formatDependencyCycle, i as detectDependencyCycleDiagnostics, k as inferTemplatedType, n as RSDiagnosticCode, o as hasCstDiagnostic, r as assignSchemaDiagnostics, s as modelStatusCstDiagnostic, t as DiagnosticKind, z as argumentValuesToMapping } from "../diagnostics-D1Cp21nP.js";
8
+ import { $ as isFunctional, A as normalizeExpression, R as applyMappingToConstituents, V as generateAlias, a as formatDependencyCycle, i as detectDependencyCycleDiagnostics, k as inferTemplatedType, n as RSDiagnosticCode, o as hasCstDiagnostic, r as assignSchemaDiagnostics, s as modelStatusCstDiagnostic, t as DiagnosticKind, z as argumentValuesToMapping } from "../diagnostics-D_4TpAH4.js";
9
9
  import { DEFAULT_VALUE_TEXT, EvalStatus } from "./rsmodel.js";
10
10
  import { FolderNode, FolderTree } from "./folder-tree.js";
11
11
  import { AccessPolicy, LibraryItemType, LocationHead } from "./library.js";
@@ -1,5 +1,5 @@
1
1
  import { r as LibraryItem } from "../library-CYun28Xz.js";
2
- import { S as RSForm, v as Constituenta, w as Substitution } from "../diagnostics-DKyMf6q-.js";
2
+ import { S as RSForm, v as Constituenta, w as Substitution } from "../diagnostics-D4_B7rt2.js";
3
3
  import { NodeType, OperationSchema, SubstitutionErrorDescription } from "./oss.js";
4
4
  //#region src/library/oss-api.d.ts
5
5
  declare function constructNodeID(type: NodeType, itemID: number): string;
@@ -3,7 +3,7 @@ import { labelType } from "../rslang/labels.js";
3
3
  import { applyAliasMapping, applyTypificationMapping, isSetTypification } from "../rslang/api.js";
4
4
  import { CstClass, CstType } from "./rsform.js";
5
5
  import { extractBases } from "../rslang/semantic/typification-api.js";
6
- import { a as formatDependencyCycle } from "../diagnostics-D1Cp21nP.js";
6
+ import { a as formatDependencyCycle } from "../diagnostics-D_4TpAH4.js";
7
7
  import "../graph/index.js";
8
8
  import { NodeType, SubstitutionErrorType } from "./oss.js";
9
9
  //#region src/library/oss-api.ts
@@ -126,9 +126,7 @@ var SubstitutionValidator = class {
126
126
  if (original.cst_type !== CstType.PREDICATE) return this.reportError(SubstitutionErrorType.invalidClasses, [substitution.alias, original.alias]);
127
127
  break;
128
128
  case CstType.TERM:
129
- case CstType.STRUCTURED:
130
- if (original.cst_type !== CstType.TERM && original.cst_type !== CstType.STRUCTURED && original.cst_type !== CstType.BASE) return this.reportError(SubstitutionErrorType.invalidClasses, [substitution.alias, original.alias]);
131
- break;
129
+ case CstType.STRUCTURED: if (original.cst_type !== CstType.TERM && original.cst_type !== CstType.STRUCTURED && original.cst_type !== CstType.BASE) return this.reportError(SubstitutionErrorType.invalidClasses, [substitution.alias, original.alias]);
132
130
  }
133
131
  }
134
132
  return true;
@@ -1 +1 @@
1
- {"version":3,"file":"oss-api.js","names":[],"sources":["../../src/library/oss-api.ts"],"sourcesContent":["/**\n * Module: API for OperationSystem.\n */\n\nimport { Graph } from '../graph';\nimport { type AliasMapping, applyAliasMapping, applyTypificationMapping, isSetTypification } from '../rslang/api';\nimport { labelType } from '../rslang/labels';\nimport { extractBases } from '../rslang/semantic/typification-api';\n\nimport { formatDependencyCycle } from './diagnostics';\nimport { type LibraryItem } from './library';\nimport { NodeType, type OperationSchema, type SubstitutionErrorDescription, SubstitutionErrorType } from './oss';\nimport { type Constituenta, CstClass, CstType, type RSForm, type Substitution } from './rsform';\nimport { type FormalOrderFields } from './rsform-api';\n\nconst STARTING_SUB_INDEX = 900; // max semantic index for starting substitution\n\nexport function constructNodeID(type: NodeType, itemID: number): string {\n return type === NodeType.OPERATION ? 'o' + String(itemID) : 'b' + String(itemID);\n}\n\n/** Sorts library items relevant for the specified {@link OperationSchema}. */\nexport function sortItemsForOSS(oss: OperationSchema, items: readonly LibraryItem[]): LibraryItem[] {\n const result = items.filter(item => item.location === oss.location);\n for (const item of items) {\n if (item.visible && item.owner === oss.owner && !result.includes(item)) {\n result.push(item);\n }\n }\n for (const item of items) {\n if (item.visible && !result.includes(item)) {\n result.push(item);\n }\n }\n for (const item of items) {\n if (!result.includes(item)) {\n result.push(item);\n }\n }\n return result;\n}\n\ntype CrossMapping = Map<number, AliasMapping>;\n\n/** Validator for Substitution table. */\nexport class SubstitutionValidator {\n public errors: SubstitutionErrorDescription[] = [];\n public suggestions: Substitution[] = [];\n\n private schemas: RSForm[];\n private substitutions: Substitution[];\n private constituents = new Set<number>();\n private originals = new Set<number>();\n private mapping: CrossMapping = new Map();\n\n private cstByID = new Map<number, Constituenta>();\n private schemaByID = new Map<number, RSForm>();\n private schemaByCst = new Map<number, RSForm>();\n\n constructor(schemas: RSForm[], substitutions: Substitution[]) {\n this.schemas = schemas;\n this.substitutions = substitutions;\n if (schemas.length === 0) {\n return;\n }\n\n for (const schema of schemas) {\n this.schemaByID.set(schema.id, schema);\n this.mapping.set(schema.id, {});\n for (const item of schema.items) {\n this.cstByID.set(item.id, item);\n this.schemaByCst.set(item.id, schema);\n }\n }\n if (substitutions.length === 0) {\n return;\n }\n let index = STARTING_SUB_INDEX;\n for (const item of substitutions) {\n this.constituents.add(item.original);\n this.constituents.add(item.substitution);\n this.originals.add(item.original);\n const original = this.cstByID.get(item.original);\n const substitution = this.cstByID.get(item.substitution);\n if (!original || !substitution) {\n return;\n }\n index++;\n const newAlias = `${substitution.alias[0]}${index}`;\n this.mapping.get(original.schema)![original.alias] = newAlias;\n this.mapping.get(substitution.schema)![substitution.alias] = newAlias;\n }\n }\n\n public validate(): boolean {\n this.errors = [];\n this.suggestions = [];\n this.calculateSuggestions();\n if (this.substitutions.length === 0) {\n return true;\n }\n if (!this.checkTypes()) {\n return false;\n }\n if (!this.checkTypificationCycles()) {\n return false;\n }\n if (!this.checkDefinitionCycles()) {\n return false;\n }\n if (!this.checkSubstitutions()) {\n return false;\n }\n return true;\n }\n\n private calculateSuggestions(): void {\n const candidates = new Map<number, string>();\n const minors = new Set<number>();\n const schemaByCst = new Map<number, RSForm>();\n for (const schema of this.schemas) {\n for (const cst of schema.items) {\n if (this.originals.has(cst.id)) {\n continue;\n }\n if (cst.cst_class === CstClass.BASIC || cst.definition_formal.length === 0) {\n continue;\n }\n const inputs = schema.graph.at(cst.id)!.inputs;\n if (inputs.some(id => !this.constituents.has(id))) {\n continue;\n }\n if (inputs.some(id => this.originals.has(id))) {\n minors.add(cst.id);\n }\n candidates.set(\n cst.id,\n applyAliasMapping(cst.definition_formal, this.mapping.get(schema.id)!).replace(/\\s+/g, '')\n );\n schemaByCst.set(cst.id, schema);\n }\n }\n for (const [key1, value1] of candidates) {\n for (const [key2, value2] of candidates) {\n if (key1 >= key2) {\n continue;\n }\n if (schemaByCst.get(key1) === schemaByCst.get(key2)) {\n continue;\n }\n if (value1 != value2) {\n continue;\n }\n if (minors.has(key2)) {\n this.suggestions.push({\n original: key2,\n substitution: key1\n });\n } else {\n this.suggestions.push({\n original: key1,\n substitution: key2\n });\n }\n }\n }\n }\n\n private checkTypes(): boolean {\n for (const item of this.substitutions) {\n const original = this.cstByID.get(item.original);\n const substitution = this.cstByID.get(item.substitution);\n if (!original || !substitution) {\n return this.reportError(SubstitutionErrorType.invalidIDs, []);\n }\n if (\n substitution.analysis &&\n original.analysis &&\n (!original.analysis.success || !substitution.analysis.success)\n ) {\n return this.reportError(SubstitutionErrorType.incorrectCst, [substitution.alias, original.alias]);\n }\n switch (substitution.cst_type) {\n case CstType.NOMINAL: {\n if (original.cst_type !== CstType.NOMINAL) {\n return this.reportError(SubstitutionErrorType.invalidNominal, [substitution.alias, original.alias]);\n }\n break;\n }\n case CstType.BASE: {\n if (\n original.cst_type !== CstType.BASE &&\n original.cst_type !== CstType.CONSTANT &&\n original.cst_type !== CstType.NOMINAL\n ) {\n return this.reportError(SubstitutionErrorType.invalidBasic, [substitution.alias, original.alias]);\n }\n break;\n }\n\n case CstType.CONSTANT: {\n if (original.cst_type !== CstType.CONSTANT) {\n return this.reportError(SubstitutionErrorType.invalidConstant, [substitution.alias, original.alias]);\n }\n break;\n }\n\n case CstType.AXIOM:\n case CstType.STATEMENT: {\n if (original.cst_type !== CstType.AXIOM && original.cst_type !== CstType.STATEMENT) {\n return this.reportError(SubstitutionErrorType.invalidClasses, [substitution.alias, original.alias]);\n }\n break;\n }\n\n case CstType.FUNCTION: {\n if (original.cst_type !== CstType.FUNCTION) {\n return this.reportError(SubstitutionErrorType.invalidClasses, [substitution.alias, original.alias]);\n }\n break;\n }\n case CstType.PREDICATE: {\n if (original.cst_type !== CstType.PREDICATE) {\n return this.reportError(SubstitutionErrorType.invalidClasses, [substitution.alias, original.alias]);\n }\n break;\n }\n\n case CstType.TERM:\n case CstType.STRUCTURED: {\n if (\n original.cst_type !== CstType.TERM &&\n original.cst_type !== CstType.STRUCTURED &&\n original.cst_type !== CstType.BASE\n ) {\n return this.reportError(SubstitutionErrorType.invalidClasses, [substitution.alias, original.alias]);\n }\n break;\n }\n }\n }\n return true;\n }\n\n /**\n * Detect cycles among base/constant sets implied by typifications of non-base\n * constituents under the substitution table.\n */\n private checkTypificationCycles(): boolean {\n const graph = new Graph();\n for (const schema of this.schemas) {\n for (const cst of schema.items) {\n if (cst.cst_type === CstType.BASE || cst.cst_type === CstType.CONSTANT) {\n graph.addNode(cst.id);\n }\n }\n }\n for (const item of this.substitutions) {\n const original = this.cstByID.get(item.original)!;\n const substitution = this.cstByID.get(item.substitution)!;\n for (const cst of [original, substitution]) {\n if (cst.cst_type === CstType.BASE || cst.cst_type === CstType.CONSTANT) {\n continue;\n }\n graph.addNode(cst.id);\n if (cst.effectiveType === null) {\n continue;\n }\n const parents = extractBases(cst.effectiveType);\n if (parents.size === 0) {\n continue;\n }\n const schema = this.schemaByID.get(cst.schema)!;\n for (const alias of parents) {\n const parent = schema.cstByAlias.get(alias);\n if (parent) {\n graph.addEdge(parent.id, cst.id);\n }\n }\n }\n graph.addEdge(substitution.id, original.id);\n }\n const cycle = graph.findCycle();\n if (cycle !== null) {\n const cycleMsg = cycle\n .map(id => {\n const cst = this.cstByID.get(id)!;\n const schema = this.schemaByID.get(cst.schema)!;\n return `[${schema.alias}]-${cst.alias}`;\n })\n .join(', ');\n return this.reportError(SubstitutionErrorType.typificationCycle, [cycleMsg]);\n }\n return true;\n }\n\n /**\n * Detect logical cycles in formal definitions after applying the substitution table\n * (e.g. D16 := F2[D15] with identification D15 → D16 yields D16 := F2[D16]).\n */\n private checkDefinitionCycles(): boolean {\n const graph = new Graph();\n for (const schema of this.schemas) {\n for (const [id, node] of schema.graph.nodes) {\n graph.addNode(id);\n for (const output of node.outputs) {\n graph.addEdge(id, output);\n }\n }\n }\n\n const deleted = new Map<number, number>();\n for (const item of this.substitutions) {\n deleted.set(item.original, item.substitution);\n }\n const resolve = (id: number): number => deleted.get(id) ?? id;\n\n const result = new Graph();\n for (const id of graph.nodes.keys()) {\n if (!deleted.has(id)) {\n result.addNode(id);\n }\n }\n for (const substitutionId of deleted.values()) {\n result.addNode(substitutionId);\n }\n\n for (const [id, node] of graph.nodes) {\n for (const output of node.outputs) {\n if (deleted.has(output)) {\n continue;\n }\n result.addEdge(resolve(id), output);\n }\n }\n\n const cycle = result.findCycle();\n if (cycle !== null) {\n const aliases = cycle.map(id => {\n const cst = this.cstByID.get(id);\n if (!cst) {\n return String(id);\n }\n if (this.schemas.length > 1) {\n const schema = this.schemaByID.get(cst.schema);\n return schema ? `[${schema.alias}]-${cst.alias}` : cst.alias;\n }\n return cst.alias;\n });\n return this.reportError(SubstitutionErrorType.definitionCycle, [formatDependencyCycle(aliases)]);\n }\n return true;\n }\n\n private checkSubstitutions(): boolean {\n const baseMappings = this.prepareBaseMappings();\n const typeMappings = this.calculateSubstituteMappings(baseMappings);\n if (typeMappings === null) {\n return false;\n }\n for (const item of this.substitutions) {\n const original = this.cstByID.get(item.original)!;\n if (\n original.cst_type === CstType.BASE ||\n original.cst_type === CstType.CONSTANT ||\n original.cst_type === CstType.NOMINAL\n ) {\n continue;\n }\n const substitution = this.cstByID.get(item.substitution)!;\n if (original.cst_type === substitution.cst_type && original.cst_class !== CstClass.BASIC) {\n if (!this.checkEqual(original, substitution)) {\n this.reportError(SubstitutionErrorType.unequalExpressions, [substitution.alias, original.alias]);\n // Note: do not interrupt the validation process. Only warn about the problem.\n }\n }\n\n if (original.analysis.success !== substitution.analysis.success) {\n return this.reportError(SubstitutionErrorType.unequalTypification, [substitution.alias, original.alias]);\n }\n if (!original.analysis.success || !substitution.analysis.success) {\n continue;\n }\n\n const originalType = applyTypificationMapping(\n applyAliasMapping(labelType(original.effectiveType), baseMappings.get(original.schema)!),\n typeMappings\n );\n const substitutionType = applyTypificationMapping(\n applyAliasMapping(labelType(substitution.effectiveType), baseMappings.get(substitution.schema)!),\n typeMappings\n );\n if (originalType !== substitutionType) {\n return this.reportError(SubstitutionErrorType.unequalTypification, [substitution.alias, original.alias]);\n }\n }\n return true;\n }\n\n private prepareBaseMappings(): CrossMapping {\n const result: CrossMapping = new Map();\n let baseCount = 0;\n let constCount = 0;\n for (const schema of this.schemas) {\n const mapping: AliasMapping = {};\n for (const cst of schema.items) {\n if (cst.cst_type === CstType.BASE) {\n baseCount++;\n mapping[cst.alias] = `X${baseCount}`;\n } else if (cst.cst_type === CstType.CONSTANT) {\n constCount++;\n mapping[cst.alias] = `C${constCount}`;\n }\n result.set(schema.id, mapping);\n }\n }\n return result;\n }\n\n private calculateSubstituteMappings(baseMappings: CrossMapping): AliasMapping | null {\n const result: AliasMapping = {};\n const processed = new Set<string>();\n for (const item of this.substitutions) {\n const original = this.cstByID.get(item.original)!;\n if (original.cst_type !== CstType.BASE && original.cst_type !== CstType.CONSTANT) {\n continue;\n }\n const originalAlias = baseMappings.get(original.schema)![original.alias];\n\n const substitution = this.cstByID.get(item.substitution)!;\n let substitutionText = '';\n if (substitution.cst_type === original.cst_type || !substitution.effectiveType) {\n substitutionText = baseMappings.get(substitution.schema)![substitution.alias];\n } else {\n const typeText = labelType(substitution.effectiveType);\n substitutionText = applyAliasMapping(typeText, baseMappings.get(substitution.schema)!);\n substitutionText = applyTypificationMapping(substitutionText, result);\n if (!isSetTypification(substitutionText)) {\n this.reportError(SubstitutionErrorType.baseSubstitutionNotSet, [substitution.alias, typeText]);\n return null;\n }\n if (substitutionText.includes('×') || substitutionText.startsWith('ℬℬ')) {\n substitutionText = substitutionText.slice(1);\n } else {\n substitutionText = substitutionText.slice(2, -1);\n }\n }\n for (const prevAlias of processed) {\n result[prevAlias] = applyTypificationMapping(result[prevAlias], { [originalAlias]: substitutionText });\n }\n result[originalAlias] = substitutionText;\n processed.add(originalAlias);\n }\n return result;\n }\n\n private checkEqual(\n left: FormalOrderFields & { schema: number },\n right: FormalOrderFields & { schema: number }\n ): boolean {\n const schema1 = this.schemaByID.get(left.schema)!;\n const inputs1 = schema1.graph.at(left.id)!.inputs;\n if (inputs1.some(id => !this.constituents.has(id))) {\n return false;\n }\n const schema2 = this.schemaByID.get(right.schema)!;\n const inputs2 = schema2.graph.at(right.id)!.inputs;\n if (inputs2.some(id => !this.constituents.has(id))) {\n return false;\n }\n const expression1 = applyAliasMapping(left.definition_formal, this.mapping.get(schema1.id)!);\n const expression2 = applyAliasMapping(right.definition_formal, this.mapping.get(schema2.id)!);\n return expression1.replace(/\\s+/g, '') === expression2.replace(/\\s+/g, '');\n }\n\n private reportError(code: SubstitutionErrorType, params: string[]): boolean {\n this.errors.push({\n code,\n params\n });\n return false;\n }\n}\n\n/** Filter relocate candidates from gives schema. */\nexport function getRelocateCandidates(\n source: number,\n destination: number,\n schema: RSForm,\n oss: OperationSchema\n): Constituenta[] {\n const destinationSchema = oss.operationByID.get(destination)?.result;\n if (!destinationSchema) {\n return [];\n }\n const node = oss.graph.at(source);\n if (!node) {\n return [];\n }\n\n if (node.outputs.includes(destination)) {\n return schema.items;\n }\n\n const addedCst = schema.items.filter(item => !item.is_inherited).map(cst => cst.id);\n\n const unreachableBases: number[] = [];\n for (const cst of schema.items.filter(item => item.is_inherited)) {\n if (cst.parent_schema == destinationSchema) {\n continue;\n }\n const parent = schema.inheritance.find(item => item.child === cst.id && item.child_source === cst.schema)?.parent;\n if (parent) {\n const original = oss.substitutions.find(sub => sub.substitution === parent)?.original;\n if (original) {\n continue;\n }\n }\n unreachableBases.push(cst.id);\n }\n const unreachable = schema.graph.expandAllOutputs(unreachableBases);\n return schema.items.filter(\n cst => cst.parent_schema === destinationSchema || (addedCst.includes(cst.id) && !unreachable.includes(cst.id))\n );\n}\n"],"mappings":";;;;;;;;;;;;AAeA,MAAM,qBAAqB;AAE3B,SAAgB,gBAAgB,MAAgB,QAAwB;CACtE,OAAO,SAAS,SAAS,YAAY,MAAM,OAAO,MAAM,IAAI,MAAM,OAAO,MAAM;AACjF;;AAGA,SAAgB,gBAAgB,KAAsB,OAA8C;CAClG,MAAM,SAAS,MAAM,QAAO,SAAQ,KAAK,aAAa,IAAI,QAAQ;CAClE,KAAK,MAAM,QAAQ,OACjB,IAAI,KAAK,WAAW,KAAK,UAAU,IAAI,SAAS,CAAC,OAAO,SAAS,IAAI,GACnE,OAAO,KAAK,IAAI;CAGpB,KAAK,MAAM,QAAQ,OACjB,IAAI,KAAK,WAAW,CAAC,OAAO,SAAS,IAAI,GACvC,OAAO,KAAK,IAAI;CAGpB,KAAK,MAAM,QAAQ,OACjB,IAAI,CAAC,OAAO,SAAS,IAAI,GACvB,OAAO,KAAK,IAAI;CAGpB,OAAO;AACT;;AAKA,IAAa,wBAAb,MAAmC;CACjC,SAAgD,CAAC;CACjD,c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,MAAM,QAAO,SAAQ,KAAK,YAAY,GAAG;EAChE,IAAI,IAAI,iBAAiB,mBACvB;EAEF,MAAM,SAAS,OAAO,YAAY,MAAK,SAAQ,KAAK,UAAU,IAAI,MAAM,KAAK,iBAAiB,IAAI,MAAM,CAAC,EAAE;EAC3G,IAAI,QAEF;OADiB,IAAI,cAAc,MAAK,QAAO,IAAI,iBAAiB,MAAM,CAAC,EAAE,UAE3E;EACF;EAEF,iBAAiB,KAAK,IAAI,EAAE;CAC9B;CACA,MAAM,cAAc,OAAO,MAAM,iBAAiB,gBAAgB;CAClE,OAAO,OAAO,MAAM,QAClB,QAAO,IAAI,kBAAkB,qBAAsB,SAAS,SAAS,IAAI,EAAE,KAAK,CAAC,YAAY,SAAS,IAAI,EAAE,CAC9G;AACF"}
1
+ {"version":3,"file":"oss-api.js","names":[],"sources":["../../src/library/oss-api.ts"],"sourcesContent":["/**\n * Module: API for OperationSystem.\n */\n\nimport { Graph } from '../graph';\nimport { type AliasMapping, applyAliasMapping, applyTypificationMapping, isSetTypification } from '../rslang/api';\nimport { labelType } from '../rslang/labels';\nimport { extractBases } from '../rslang/semantic/typification-api';\n\nimport { formatDependencyCycle } from './diagnostics';\nimport { type LibraryItem } from './library';\nimport { NodeType, type OperationSchema, type SubstitutionErrorDescription, SubstitutionErrorType } from './oss';\nimport { type Constituenta, CstClass, CstType, type RSForm, type Substitution } from './rsform';\nimport { type FormalOrderFields } from './rsform-api';\n\nconst STARTING_SUB_INDEX = 900; // max semantic index for starting substitution\n\nexport function constructNodeID(type: NodeType, itemID: number): string {\n return type === NodeType.OPERATION ? 'o' + String(itemID) : 'b' + String(itemID);\n}\n\n/** Sorts library items relevant for the specified {@link OperationSchema}. */\nexport function sortItemsForOSS(oss: OperationSchema, items: readonly LibraryItem[]): LibraryItem[] {\n const result = items.filter(item => item.location === oss.location);\n for (const item of items) {\n if (item.visible && item.owner === oss.owner && !result.includes(item)) {\n result.push(item);\n }\n }\n for (const item of items) {\n if (item.visible && !result.includes(item)) {\n result.push(item);\n }\n }\n for (const item of items) {\n if (!result.includes(item)) {\n result.push(item);\n }\n }\n return result;\n}\n\ntype CrossMapping = Map<number, AliasMapping>;\n\n/** Validator for Substitution table. */\nexport class SubstitutionValidator {\n public errors: SubstitutionErrorDescription[] = [];\n public suggestions: Substitution[] = [];\n\n private schemas: RSForm[];\n private substitutions: Substitution[];\n private constituents = new Set<number>();\n private originals = new Set<number>();\n private mapping: CrossMapping = new Map();\n\n private cstByID = new Map<number, Constituenta>();\n private schemaByID = new Map<number, RSForm>();\n private schemaByCst = new Map<number, RSForm>();\n\n constructor(schemas: RSForm[], substitutions: Substitution[]) {\n this.schemas = schemas;\n this.substitutions = substitutions;\n if (schemas.length === 0) {\n return;\n }\n\n for (const schema of schemas) {\n this.schemaByID.set(schema.id, schema);\n this.mapping.set(schema.id, {});\n for (const item of schema.items) {\n this.cstByID.set(item.id, item);\n this.schemaByCst.set(item.id, schema);\n }\n }\n if (substitutions.length === 0) {\n return;\n }\n let index = STARTING_SUB_INDEX;\n for (const item of substitutions) {\n this.constituents.add(item.original);\n this.constituents.add(item.substitution);\n this.originals.add(item.original);\n const original = this.cstByID.get(item.original);\n const substitution = this.cstByID.get(item.substitution);\n if (!original || !substitution) {\n return;\n }\n index++;\n const newAlias = `${substitution.alias[0]}${index}`;\n this.mapping.get(original.schema)![original.alias] = newAlias;\n this.mapping.get(substitution.schema)![substitution.alias] = newAlias;\n }\n }\n\n public validate(): boolean {\n this.errors = [];\n this.suggestions = [];\n this.calculateSuggestions();\n if (this.substitutions.length === 0) {\n return true;\n }\n if (!this.checkTypes()) {\n return false;\n }\n if (!this.checkTypificationCycles()) {\n return false;\n }\n if (!this.checkDefinitionCycles()) {\n return false;\n }\n if (!this.checkSubstitutions()) {\n return false;\n }\n return true;\n }\n\n private calculateSuggestions(): void {\n const candidates = new Map<number, string>();\n const minors = new Set<number>();\n const schemaByCst = new Map<number, RSForm>();\n for (const schema of this.schemas) {\n for (const cst of schema.items) {\n if (this.originals.has(cst.id)) {\n continue;\n }\n if (cst.cst_class === CstClass.BASIC || cst.definition_formal.length === 0) {\n continue;\n }\n const inputs = schema.graph.at(cst.id)!.inputs;\n if (inputs.some(id => !this.constituents.has(id))) {\n continue;\n }\n if (inputs.some(id => this.originals.has(id))) {\n minors.add(cst.id);\n }\n candidates.set(\n cst.id,\n applyAliasMapping(cst.definition_formal, this.mapping.get(schema.id)!).replace(/\\s+/g, '')\n );\n schemaByCst.set(cst.id, schema);\n }\n }\n for (const [key1, value1] of candidates) {\n for (const [key2, value2] of candidates) {\n if (key1 >= key2) {\n continue;\n }\n if (schemaByCst.get(key1) === schemaByCst.get(key2)) {\n continue;\n }\n if (value1 != value2) {\n continue;\n }\n if (minors.has(key2)) {\n this.suggestions.push({\n original: key2,\n substitution: key1\n });\n } else {\n this.suggestions.push({\n original: key1,\n substitution: key2\n });\n }\n }\n }\n }\n\n private checkTypes(): boolean {\n for (const item of this.substitutions) {\n const original = this.cstByID.get(item.original);\n const substitution = this.cstByID.get(item.substitution);\n if (!original || !substitution) {\n return this.reportError(SubstitutionErrorType.invalidIDs, []);\n }\n if (\n substitution.analysis &&\n original.analysis &&\n (!original.analysis.success || !substitution.analysis.success)\n ) {\n return this.reportError(SubstitutionErrorType.incorrectCst, [substitution.alias, original.alias]);\n }\n switch (substitution.cst_type) {\n case CstType.NOMINAL: {\n if (original.cst_type !== CstType.NOMINAL) {\n return this.reportError(SubstitutionErrorType.invalidNominal, [substitution.alias, original.alias]);\n }\n break;\n }\n case CstType.BASE: {\n if (\n original.cst_type !== CstType.BASE &&\n original.cst_type !== CstType.CONSTANT &&\n original.cst_type !== CstType.NOMINAL\n ) {\n return this.reportError(SubstitutionErrorType.invalidBasic, [substitution.alias, original.alias]);\n }\n break;\n }\n\n case CstType.CONSTANT: {\n if (original.cst_type !== CstType.CONSTANT) {\n return this.reportError(SubstitutionErrorType.invalidConstant, [substitution.alias, original.alias]);\n }\n break;\n }\n\n case CstType.AXIOM:\n case CstType.STATEMENT: {\n if (original.cst_type !== CstType.AXIOM && original.cst_type !== CstType.STATEMENT) {\n return this.reportError(SubstitutionErrorType.invalidClasses, [substitution.alias, original.alias]);\n }\n break;\n }\n\n case CstType.FUNCTION: {\n if (original.cst_type !== CstType.FUNCTION) {\n return this.reportError(SubstitutionErrorType.invalidClasses, [substitution.alias, original.alias]);\n }\n break;\n }\n case CstType.PREDICATE: {\n if (original.cst_type !== CstType.PREDICATE) {\n return this.reportError(SubstitutionErrorType.invalidClasses, [substitution.alias, original.alias]);\n }\n break;\n }\n\n case CstType.TERM:\n case CstType.STRUCTURED: {\n if (\n original.cst_type !== CstType.TERM &&\n original.cst_type !== CstType.STRUCTURED &&\n original.cst_type !== CstType.BASE\n ) {\n return this.reportError(SubstitutionErrorType.invalidClasses, [substitution.alias, original.alias]);\n }\n break;\n }\n }\n }\n return true;\n }\n\n /**\n * Detect cycles among base/constant sets implied by typifications of non-base\n * constituents under the substitution table.\n */\n private checkTypificationCycles(): boolean {\n const graph = new Graph();\n for (const schema of this.schemas) {\n for (const cst of schema.items) {\n if (cst.cst_type === CstType.BASE || cst.cst_type === CstType.CONSTANT) {\n graph.addNode(cst.id);\n }\n }\n }\n for (const item of this.substitutions) {\n const original = this.cstByID.get(item.original)!;\n const substitution = this.cstByID.get(item.substitution)!;\n for (const cst of [original, substitution]) {\n if (cst.cst_type === CstType.BASE || cst.cst_type === CstType.CONSTANT) {\n continue;\n }\n graph.addNode(cst.id);\n if (cst.effectiveType === null) {\n continue;\n }\n const parents = extractBases(cst.effectiveType);\n if (parents.size === 0) {\n continue;\n }\n const schema = this.schemaByID.get(cst.schema)!;\n for (const alias of parents) {\n const parent = schema.cstByAlias.get(alias);\n if (parent) {\n graph.addEdge(parent.id, cst.id);\n }\n }\n }\n graph.addEdge(substitution.id, original.id);\n }\n const cycle = graph.findCycle();\n if (cycle !== null) {\n const cycleMsg = cycle\n .map(id => {\n const cst = this.cstByID.get(id)!;\n const schema = this.schemaByID.get(cst.schema)!;\n return `[${schema.alias}]-${cst.alias}`;\n })\n .join(', ');\n return this.reportError(SubstitutionErrorType.typificationCycle, [cycleMsg]);\n }\n return true;\n }\n\n /**\n * Detect logical cycles in formal definitions after applying the substitution table\n * (e.g. D16 := F2[D15] with identification D15 → D16 yields D16 := F2[D16]).\n */\n private checkDefinitionCycles(): boolean {\n const graph = new Graph();\n for (const schema of this.schemas) {\n for (const [id, node] of schema.graph.nodes) {\n graph.addNode(id);\n for (const output of node.outputs) {\n graph.addEdge(id, output);\n }\n }\n }\n\n const deleted = new Map<number, number>();\n for (const item of this.substitutions) {\n deleted.set(item.original, item.substitution);\n }\n const resolve = (id: number): number => deleted.get(id) ?? id;\n\n const result = new Graph();\n for (const id of graph.nodes.keys()) {\n if (!deleted.has(id)) {\n result.addNode(id);\n }\n }\n for (const substitutionId of deleted.values()) {\n result.addNode(substitutionId);\n }\n\n for (const [id, node] of graph.nodes) {\n for (const output of node.outputs) {\n if (deleted.has(output)) {\n continue;\n }\n result.addEdge(resolve(id), output);\n }\n }\n\n const cycle = result.findCycle();\n if (cycle !== null) {\n const aliases = cycle.map(id => {\n const cst = this.cstByID.get(id);\n if (!cst) {\n return String(id);\n }\n if (this.schemas.length > 1) {\n const schema = this.schemaByID.get(cst.schema);\n return schema ? `[${schema.alias}]-${cst.alias}` : cst.alias;\n }\n return cst.alias;\n });\n return this.reportError(SubstitutionErrorType.definitionCycle, [formatDependencyCycle(aliases)]);\n }\n return true;\n }\n\n private checkSubstitutions(): boolean {\n const baseMappings = this.prepareBaseMappings();\n const typeMappings = this.calculateSubstituteMappings(baseMappings);\n if (typeMappings === null) {\n return false;\n }\n for (const item of this.substitutions) {\n const original = this.cstByID.get(item.original)!;\n if (\n original.cst_type === CstType.BASE ||\n original.cst_type === CstType.CONSTANT ||\n original.cst_type === CstType.NOMINAL\n ) {\n continue;\n }\n const substitution = this.cstByID.get(item.substitution)!;\n if (original.cst_type === substitution.cst_type && original.cst_class !== CstClass.BASIC) {\n if (!this.checkEqual(original, substitution)) {\n this.reportError(SubstitutionErrorType.unequalExpressions, [substitution.alias, original.alias]);\n // Note: do not interrupt the validation process. Only warn about the problem.\n }\n }\n\n if (original.analysis.success !== substitution.analysis.success) {\n return this.reportError(SubstitutionErrorType.unequalTypification, [substitution.alias, original.alias]);\n }\n if (!original.analysis.success || !substitution.analysis.success) {\n continue;\n }\n\n const originalType = applyTypificationMapping(\n applyAliasMapping(labelType(original.effectiveType), baseMappings.get(original.schema)!),\n typeMappings\n );\n const substitutionType = applyTypificationMapping(\n applyAliasMapping(labelType(substitution.effectiveType), baseMappings.get(substitution.schema)!),\n typeMappings\n );\n if (originalType !== substitutionType) {\n return this.reportError(SubstitutionErrorType.unequalTypification, [substitution.alias, original.alias]);\n }\n }\n return true;\n }\n\n private prepareBaseMappings(): CrossMapping {\n const result: CrossMapping = new Map();\n let baseCount = 0;\n let constCount = 0;\n for (const schema of this.schemas) {\n const mapping: AliasMapping = {};\n for (const cst of schema.items) {\n if (cst.cst_type === CstType.BASE) {\n baseCount++;\n mapping[cst.alias] = `X${baseCount}`;\n } else if (cst.cst_type === CstType.CONSTANT) {\n constCount++;\n mapping[cst.alias] = `C${constCount}`;\n }\n result.set(schema.id, mapping);\n }\n }\n return result;\n }\n\n private calculateSubstituteMappings(baseMappings: CrossMapping): AliasMapping | null {\n const result: AliasMapping = {};\n const processed = new Set<string>();\n for (const item of this.substitutions) {\n const original = this.cstByID.get(item.original)!;\n if (original.cst_type !== CstType.BASE && original.cst_type !== CstType.CONSTANT) {\n continue;\n }\n const originalAlias = baseMappings.get(original.schema)![original.alias];\n\n const substitution = this.cstByID.get(item.substitution)!;\n let substitutionText = '';\n if (substitution.cst_type === original.cst_type || !substitution.effectiveType) {\n substitutionText = baseMappings.get(substitution.schema)![substitution.alias];\n } else {\n const typeText = labelType(substitution.effectiveType);\n substitutionText = applyAliasMapping(typeText, baseMappings.get(substitution.schema)!);\n substitutionText = applyTypificationMapping(substitutionText, result);\n if (!isSetTypification(substitutionText)) {\n this.reportError(SubstitutionErrorType.baseSubstitutionNotSet, [substitution.alias, typeText]);\n return null;\n }\n if (substitutionText.includes('×') || substitutionText.startsWith('ℬℬ')) {\n substitutionText = substitutionText.slice(1);\n } else {\n substitutionText = substitutionText.slice(2, -1);\n }\n }\n for (const prevAlias of processed) {\n result[prevAlias] = applyTypificationMapping(result[prevAlias], { [originalAlias]: substitutionText });\n }\n result[originalAlias] = substitutionText;\n processed.add(originalAlias);\n }\n return result;\n }\n\n private checkEqual(\n left: FormalOrderFields & { schema: number },\n right: FormalOrderFields & { schema: number }\n ): boolean {\n const schema1 = this.schemaByID.get(left.schema)!;\n const inputs1 = schema1.graph.at(left.id)!.inputs;\n if (inputs1.some(id => !this.constituents.has(id))) {\n return false;\n }\n const schema2 = this.schemaByID.get(right.schema)!;\n const inputs2 = schema2.graph.at(right.id)!.inputs;\n if (inputs2.some(id => !this.constituents.has(id))) {\n return false;\n }\n const expression1 = applyAliasMapping(left.definition_formal, this.mapping.get(schema1.id)!);\n const expression2 = applyAliasMapping(right.definition_formal, this.mapping.get(schema2.id)!);\n return expression1.replace(/\\s+/g, '') === expression2.replace(/\\s+/g, '');\n }\n\n private reportError(code: SubstitutionErrorType, params: string[]): boolean {\n this.errors.push({\n code,\n params\n });\n return false;\n }\n}\n\n/** Filter relocate candidates from gives schema. */\nexport function getRelocateCandidates(\n source: number,\n destination: number,\n schema: RSForm,\n oss: OperationSchema\n): Constituenta[] {\n const destinationSchema = oss.operationByID.get(destination)?.result;\n if (!destinationSchema) {\n return [];\n }\n const node = oss.graph.at(source);\n if (!node) {\n return [];\n }\n\n if (node.outputs.includes(destination)) {\n return schema.items;\n }\n\n const addedCst = schema.items.filter(item => !item.is_inherited).map(cst => cst.id);\n\n const unreachableBases: number[] = [];\n for (const cst of schema.items.filter(item => item.is_inherited)) {\n if (cst.parent_schema == destinationSchema) {\n continue;\n }\n const parent = schema.inheritance.find(item => item.child === cst.id && item.child_source === cst.schema)?.parent;\n if (parent) {\n const original = oss.substitutions.find(sub => sub.substitution === parent)?.original;\n if (original) {\n continue;\n }\n }\n unreachableBases.push(cst.id);\n }\n const unreachable = schema.graph.expandAllOutputs(unreachableBases);\n return schema.items.filter(\n cst => cst.parent_schema === destinationSchema || (addedCst.includes(cst.id) && !unreachable.includes(cst.id))\n );\n}\n"],"mappings":";;;;;;;;;;;;AAeA,MAAM,qBAAqB;AAE3B,SAAgB,gBAAgB,MAAgB,QAAwB;CACtE,OAAO,SAAS,SAAS,YAAY,MAAM,OAAO,MAAM,IAAI,MAAM,OAAO,MAAM;AACjF;;AAGA,SAAgB,gBAAgB,KAAsB,OAA8C;CAClG,MAAM,SAAS,MAAM,QAAO,SAAQ,KAAK,aAAa,IAAI,QAAQ;CAClE,KAAK,MAAM,QAAQ,OACjB,IAAI,KAAK,WAAW,KAAK,UAAU,IAAI,SAAS,CAAC,OAAO,SAAS,IAAI,GACnE,OAAO,KAAK,IAAI;CAGpB,KAAK,MAAM,QAAQ,OACjB,IAAI,KAAK,WAAW,CAAC,OAAO,SAAS,IAAI,GACvC,OAAO,KAAK,IAAI;CAGpB,KAAK,MAAM,QAAQ,OACjB,IAAI,CAAC,OAAO,SAAS,IAAI,GACvB,OAAO,KAAK,IAAI;CAGpB,OAAO;AACT;;AAKA,IAAa,wBAAb,MAAmC;CACjC,SAAgD,CAAC;CACjD,cAAqC,CAAC;CAEtC;CACA;CACA,+BAAuB,IAAI,IAAY;CACvC,4BAAoB,IAAI,IAAY;CACpC,0BAAgC,IAAI,IAAI;CAExC,0BAAkB,IAAI,IAA0B;CAChD,6BAAqB,IAAI,IAAoB;CAC7C,8BAAsB,IAAI,IAAoB;CAE9C,YAAY,SAAmB,eAA+B;EAC5D,KAAK,UAAU;EACf,KAAK,gBAAgB;EACrB,IAAI,QAAQ,WAAW,GACrB;EAGF,KAAK,MAAM,UAAU,SAAS;GAC5B,KAAK,WAAW,IAAI,OAAO,IAAI,MAAM;GACrC,KAAK,QAAQ,IAAI,OAAO,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AI,kBAAkB,qBAAsB,SAAS,SAAS,IAAI,EAAE,KAAK,CAAC,YAAY,SAAS,IAAI,EAAE,CAC9G;AACF"}
@@ -1,4 +1,4 @@
1
- import { n as RSDiagnosticCode } from "../diagnostics-D1Cp21nP.js";
1
+ import { n as RSDiagnosticCode } from "../diagnostics-D_4TpAH4.js";
2
2
  //#region src/library/oss.ts
3
3
  /** Represents OSS node type. */
4
4
  const NodeType = {
@@ -1,9 +1,9 @@
1
1
  import { t as AstNode } from "../ast-D-D6Rq3T.js";
2
2
  import "../index-D5RahF1K.js";
3
3
  import { l as Value } from "../value-XpJOVzMP.js";
4
- import { n as CalculatorResult, r as RSCalculator, t as CalculatorEvaluateOptions } from "../calculator-uPaTV3hc.js";
5
- import "../index-CnuO4w8e.js";
6
- import { S as RSForm, f as EvalStatus, l as BasicBinding, p as RSModel, u as BasicsContext, x as CstType } from "../diagnostics-DKyMf6q-.js";
4
+ import { n as CalculatorResult, r as RSCalculator, t as CalculatorEvaluateOptions } from "../calculator-B-1p712X.js";
5
+ import "../index-D-w-bgei.js";
6
+ import { S as RSForm, f as EvalStatus, l as BasicBinding, p as RSModel, u as BasicsContext, x as CstType } from "../diagnostics-D4_B7rt2.js";
7
7
  //#region src/library/rsengine.d.ts
8
8
  /** Services for {@link RSEngine}. */
9
9
  interface RSEngineServices {
@@ -1,10 +1,10 @@
1
1
  import { TypeID } from "../rslang/semantic/typification.js";
2
2
  import { normalizeType } from "../rslang/labels.js";
3
3
  import { CstType } from "./rsform.js";
4
- import { l as compare } from "../value-COprb2Je.js";
4
+ import { l as compare } from "../value-BDISzQqI.js";
5
5
  import { RSCalculator } from "../rslang/eval/calculator.js";
6
6
  import "../rslang/index.js";
7
- import { $ as isFunctional, P as getAnalysisFor, Q as isBasicConcept, Z as isBaseSet } from "../diagnostics-D1Cp21nP.js";
7
+ import { $ as isFunctional, P as getAnalysisFor, Q as isBasicConcept, Z as isBaseSet } from "../diagnostics-D_4TpAH4.js";
8
8
  import { TYPE_BASIC } from "./rsmodel.js";
9
9
  import { inferEvalStatus, isInferrable, tryFixValue } from "./rsmodel-api.js";
10
10
  //#region src/library/rsengine.ts
@@ -66,7 +66,8 @@ var RSEngine = class {
66
66
  getCstStatus(cstID) {
67
67
  const cst = this.schema?.cstByID.get(cstID);
68
68
  if (!cst) return inferEvalStatus(null, CstType.NOMINAL, false);
69
- return inferEvalStatus(this.calculator.getValue(cst.alias), cst.cst_type, this.calculatedSet.has(cstID), this.invalidData.has(cstID));
69
+ const value = this.calculator.getValue(cst.alias);
70
+ return inferEvalStatus(value, cst.cst_type, this.calculatedSet.has(cstID), this.invalidData.has(cstID));
70
71
  }
71
72
  /** Subscribe to value change of {@link Constituenta}. */
72
73
  subscribeValue(cstID, callbackFn) {
@@ -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}\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;CA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I,QAAQ,GAC3B,KAAK,WAAW,WAAW,IAAI,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
+ {"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;CACtC,gCAAwB,IAAI,IAAY;CACxC,mCAA2B,IAAI,IAA6B;CAC5D,oCAA4B,IAAI,IAA6B;CAC7D,oCAA4B,IAAI,IAAgB;CAChD,mBAA2B;CAC3B,gBAAwB;CACxB,uBAAqE;CAErE,YAAY,SAAiB,UAA4B,gBAA8C,MAAM;EAC3G,KAAK,WAAW;EAChB,KAAK,gBAAgB;EACrB,KAAK,UAAU;CACjB;;CAGA,SAAgB,QAAgB,OAAsB;EACpD,MAAM,YAAY,KAAK;EACvB,MAAM,YAAY,cAAc;EAChC,KAAK,SAAS;EACd,IAAI,WAAW;GACb,MAAM,aAAa,KAAK,eAAe,WAAW,MAAM;GACxD,KAAK,WAAW;GAChB,KAAK,eAAe;GACpB,KAAK,oBAAoB,UAAU;EACrC;EACA,IAAI,KAAK,SAAS,OAAO;GACvB,KAAK,OAAO;GACZ,KAAK,cAAc;EACrB;EACA,KAAK,UAAU;CACjB;;CAGA,eAAsB,UAAkC;EACtD,KAAK,WAAW;CAClB;;CAGA,oBAA2B,eAAmD;EAC5E,KAAK,gBAAgB;CACvB;;CAGA,YAAmB,OAA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,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,2 +1,2 @@
1
- import { $ as removeAliasReference, A as canProduceStructure, B as filterAttributions, C as restoreConstituentOrder, D as inferTemplatedType, E as inferTemplate, F as isBasicConcept, G as MappableFields, H as remapAttributionsUnderSubstitution, I as isFunctional, J as applyMappingToConstituents, K as addAliasReference, L as isLogical, M as guessCstType, N as inferClass, O as normalizeExpression, P as isBaseSet, Q as maxAliasIndex, R as isTemplateCst, S as buildFormalDependencyGraph, T as inferStatus, U as getAnalysisFor, V as importAttributions, W as refineAnalysisForDependencyCycles, X as buildSequentialAliasMapping, Y as argumentValuesToMapping, Z as generateAlias, _ as findCstByStructure, a as buildDefinitionReferenceGraph, at as DiagnosticSourceFields, b as calculateSchemaStats, c as resolveConstituentTextChange, ct as SchemaIssueFields, d as SynthesizableFields, dt as SpawnPathFields, et as validateAliasFormat, f as inlineSynthesis, ft as StructureCapableFields, g as remapSubstitutionsAfterImport, h as applyConstituentSubstitutions, ht as TextResolvableFields, i as TextChangeOptions, it as DescribableFields, j as getCstTypePrefix, k as canHaveManualTypification, l as InlineSynthesisInput, lt as SearchableFields, m as SubstitutionResult, mt as TemplateSourceFields, n as moveIdsInOrder, nt as AliasTypedFields, o as buildTermReferenceGraph, ot as FormalOrderFields, p as sortItemsForInlineSynthesis, pt as TemplateParamSourceFields, q as allocateImportAliases, r as reorderItemsByIds, rt as BasicTextCheckFields, s as resolveAllConstituentTexts, st as ModelEvalFields, t as insertItemAfter, tt as validateNewAlias, u as InlineSynthesisResult, ut as SemanticRelations, v as getStructureName, w as applyFilterCategory, x as isSchemaIssue, y as inferNewSpawnPosition, z as typeClassForCstType } from "../../index-DCO4mxiO.js";
1
+ import { $ as removeAliasReference, A as canProduceStructure, B as filterAttributions, C as restoreConstituentOrder, D as inferTemplatedType, E as inferTemplate, F as isBasicConcept, G as MappableFields, H as remapAttributionsUnderSubstitution, I as isFunctional, J as applyMappingToConstituents, K as addAliasReference, L as isLogical, M as guessCstType, N as inferClass, O as normalizeExpression, P as isBaseSet, Q as maxAliasIndex, R as isTemplateCst, S as buildFormalDependencyGraph, T as inferStatus, U as getAnalysisFor, V as importAttributions, W as refineAnalysisForDependencyCycles, X as buildSequentialAliasMapping, Y as argumentValuesToMapping, Z as generateAlias, _ as findCstByStructure, a as buildDefinitionReferenceGraph, at as DiagnosticSourceFields, b as calculateSchemaStats, c as resolveConstituentTextChange, ct as SchemaIssueFields, d as SynthesizableFields, dt as SpawnPathFields, et as validateAliasFormat, f as inlineSynthesis, ft as StructureCapableFields, g as remapSubstitutionsAfterImport, h as applyConstituentSubstitutions, ht as TextResolvableFields, i as TextChangeOptions, it as DescribableFields, j as getCstTypePrefix, k as canHaveManualTypification, l as InlineSynthesisInput, lt as SearchableFields, m as SubstitutionResult, mt as TemplateSourceFields, n as moveIdsInOrder, nt as AliasTypedFields, o as buildTermReferenceGraph, ot as FormalOrderFields, p as sortItemsForInlineSynthesis, pt as TemplateParamSourceFields, q as allocateImportAliases, r as reorderItemsByIds, rt as BasicTextCheckFields, s as resolveAllConstituentTexts, st as ModelEvalFields, t as insertItemAfter, tt as validateNewAlias, u as InlineSynthesisResult, ut as SemanticRelations, v as getStructureName, w as applyFilterCategory, x as isSchemaIssue, y as inferNewSpawnPosition, z as typeClassForCstType } from "../../index-DzvllU3P.js";
2
2
  export { type AliasTypedFields, type BasicTextCheckFields, type DescribableFields, type DiagnosticSourceFields, type FormalOrderFields, type InlineSynthesisInput, type InlineSynthesisResult, type MappableFields, type ModelEvalFields, type SchemaIssueFields, type SearchableFields, type SemanticRelations, type SpawnPathFields, type StructureCapableFields, type SubstitutionResult, type SynthesizableFields, type TemplateParamSourceFields, type TemplateSourceFields, type TextChangeOptions, type TextResolvableFields, addAliasReference, allocateImportAliases, applyConstituentSubstitutions, applyFilterCategory, applyMappingToConstituents, argumentValuesToMapping, buildDefinitionReferenceGraph, buildFormalDependencyGraph, buildSequentialAliasMapping, buildTermReferenceGraph, calculateSchemaStats, canHaveManualTypification, canProduceStructure, filterAttributions, findCstByStructure, generateAlias, getAnalysisFor, getCstTypePrefix, getStructureName, guessCstType, importAttributions, inferClass, inferNewSpawnPosition, inferStatus, inferTemplate, inferTemplatedType, inlineSynthesis, insertItemAfter, isBaseSet, isBasicConcept, isFunctional, isLogical, isSchemaIssue, isTemplateCst, maxAliasIndex, moveIdsInOrder, normalizeExpression, refineAnalysisForDependencyCycles, remapAttributionsUnderSubstitution, remapSubstitutionsAfterImport, removeAliasReference, reorderItemsByIds, resolveAllConstituentTexts, resolveConstituentTextChange, restoreConstituentOrder, sortItemsForInlineSynthesis, typeClassForCstType, validateAliasFormat, validateNewAlias };
@@ -1,2 +1,2 @@
1
- import { $ as isFunctional, A as normalizeExpression, B as buildSequentialAliasMapping, C as isSchemaIssue, D as inferStatus, E as applyFilterCategory, F as refineAnalysisForDependencyCycles, G as validateNewAlias, H as maxAliasIndex, I as addAliasReference, J as getCstTypePrefix, K as canHaveManualTypification, L as allocateImportAliases, M as importAttributions, N as remapAttributionsUnderSubstitution, O as inferTemplate, P as getAnalysisFor, Q as isBasicConcept, R as applyMappingToConstituents, S as calculateSchemaStats, T as restoreConstituentOrder, U as removeAliasReference, V as generateAlias, W as validateAliasFormat, X as inferClass, Y as guessCstType, Z as isBaseSet, _ as applyConstituentSubstitutions, b as getStructureName, c as insertItemAfter, d as inlineSynthesis, et as isLogical, f as sortItemsForInlineSynthesis, g as resolveConstituentTextChange, h as resolveAllConstituentTexts, j as filterAttributions, k as inferTemplatedType, l as moveIdsInOrder, m as buildTermReferenceGraph, nt as typeClassForCstType, p as buildDefinitionReferenceGraph, q as canProduceStructure, tt as isTemplateCst, u as reorderItemsByIds, v as remapSubstitutionsAfterImport, w as buildFormalDependencyGraph, x as inferNewSpawnPosition, y as findCstByStructure, z as argumentValuesToMapping } from "../../diagnostics-D1Cp21nP.js";
1
+ import { $ as isFunctional, A as normalizeExpression, B as buildSequentialAliasMapping, C as isSchemaIssue, D as inferStatus, E as applyFilterCategory, F as refineAnalysisForDependencyCycles, G as validateNewAlias, H as maxAliasIndex, I as addAliasReference, J as getCstTypePrefix, K as canHaveManualTypification, L as allocateImportAliases, M as importAttributions, N as remapAttributionsUnderSubstitution, O as inferTemplate, P as getAnalysisFor, Q as isBasicConcept, R as applyMappingToConstituents, S as calculateSchemaStats, T as restoreConstituentOrder, U as removeAliasReference, V as generateAlias, W as validateAliasFormat, X as inferClass, Y as guessCstType, Z as isBaseSet, _ as applyConstituentSubstitutions, b as getStructureName, c as insertItemAfter, d as inlineSynthesis, et as isLogical, f as sortItemsForInlineSynthesis, g as resolveConstituentTextChange, h as resolveAllConstituentTexts, j as filterAttributions, k as inferTemplatedType, l as moveIdsInOrder, m as buildTermReferenceGraph, nt as typeClassForCstType, p as buildDefinitionReferenceGraph, q as canProduceStructure, tt as isTemplateCst, u as reorderItemsByIds, v as remapSubstitutionsAfterImport, w as buildFormalDependencyGraph, x as inferNewSpawnPosition, y as findCstByStructure, z as argumentValuesToMapping } from "../../diagnostics-D_4TpAH4.js";
2
2
  export { addAliasReference, allocateImportAliases, applyConstituentSubstitutions, applyFilterCategory, applyMappingToConstituents, argumentValuesToMapping, buildDefinitionReferenceGraph, buildFormalDependencyGraph, buildSequentialAliasMapping, buildTermReferenceGraph, calculateSchemaStats, canHaveManualTypification, canProduceStructure, filterAttributions, findCstByStructure, generateAlias, getAnalysisFor, getCstTypePrefix, getStructureName, guessCstType, importAttributions, inferClass, inferNewSpawnPosition, inferStatus, inferTemplate, inferTemplatedType, inlineSynthesis, insertItemAfter, isBaseSet, isBasicConcept, isFunctional, isLogical, isSchemaIssue, isTemplateCst, maxAliasIndex, moveIdsInOrder, normalizeExpression, refineAnalysisForDependencyCycles, remapAttributionsUnderSubstitution, remapSubstitutionsAfterImport, removeAliasReference, reorderItemsByIds, resolveAllConstituentTexts, resolveConstituentTextChange, restoreConstituentOrder, sortItemsForInlineSynthesis, typeClassForCstType, validateAliasFormat, validateNewAlias };
@@ -1,2 +1,2 @@
1
- import { C as RSFormStats, E as TypeInfo, S as RSForm, T as TermForm, _ as Attribution, b as CstStatus, g as ArgumentValue, v as Constituenta, w as Substitution, x as CstType, y as CstClass } from "../diagnostics-DKyMf6q-.js";
1
+ import { C as RSFormStats, E as TypeInfo, S as RSForm, T as TermForm, _ as Attribution, b as CstStatus, g as ArgumentValue, v as Constituenta, w as Substitution, x as CstType, y as CstClass } from "../diagnostics-D4_B7rt2.js";
2
2
  export { ArgumentValue, Attribution, Constituenta, CstClass, CstStatus, CstType, RSForm, RSFormStats, Substitution, TermForm, TypeInfo };
@@ -1,9 +1,9 @@
1
1
  import { b as Typification, f as ExpressionType } from "../typification-hWUoWCba.js";
2
2
  import { d as ValuePath, l as Value } from "../value-XpJOVzMP.js";
3
- import "../index-CnuO4w8e.js";
4
- import { S as RSForm, f as EvalStatus, l as BasicBinding, m as RSModelStats, x as CstType } from "../diagnostics-DKyMf6q-.js";
3
+ import "../index-D-w-bgei.js";
4
+ import { S as RSForm, f as EvalStatus, l as BasicBinding, m as RSModelStats, x as CstType } from "../diagnostics-D4_B7rt2.js";
5
5
  import { RSEngine } from "./rsengine.js";
6
- import { st as ModelEvalFields } from "../index-DCO4mxiO.js";
6
+ import { st as ModelEvalFields } from "../index-DzvllU3P.js";
7
7
  //#region src/library/rsmodel-api.d.ts
8
8
  /** Evaluate if parsed data is a basic binding data. */
9
9
  declare function validateBasicBindingData(data: unknown): data is Record<string, string>;
@@ -1,8 +1,8 @@
1
1
  import { TypeID } from "../rslang/semantic/typification.js";
2
2
  import { CstType } from "./rsform.js";
3
- import { O as setNestedValue, _ as extractValue, b as isTupleValue, d as set, f as tuple, l as compare, x as makeDefaultValue } from "../value-COprb2Je.js";
3
+ import { O as setNestedValue, _ as extractValue, b as isTupleValue, d as set, f as tuple, l as compare, x as makeDefaultValue } from "../value-BDISzQqI.js";
4
4
  import "../rslang/index.js";
5
- import { Q as isBasicConcept, S as calculateSchemaStats, Z as isBaseSet, s as modelStatusCstDiagnostic } from "../diagnostics-D1Cp21nP.js";
5
+ import { Q as isBasicConcept, S as calculateSchemaStats, Z as isBaseSet, s as modelStatusCstDiagnostic } from "../diagnostics-D_4TpAH4.js";
6
6
  import { EvalStatus } from "./rsmodel.js";
7
7
  //#region src/library/rsmodel-api.ts
8
8
  const RANDOM_INTEGER_MIN = -100;
@@ -44,6 +44,7 @@ function generateRandomValue(type, basics, cstByAlias, setElementsCount = DEFAUL
44
44
  return tuple(factors);
45
45
  }
46
46
  case TypeID.collection: {
47
+ if (!canGenerateRandomValue(type.base, basics, cstByAlias)) return null;
47
48
  const result = [];
48
49
  const randomElementsCount = Math.floor(Math.random() * (setElementsCount + 1));
49
50
  for (let i = 0; i < randomElementsCount; i++) {
@@ -180,11 +181,26 @@ function deleteValueElement(value, path, type, target) {
180
181
  if (path.length === 0 && type.typeID !== TypeID.collection) return null;
181
182
  const arrayValue = extractValue(value, path);
182
183
  if (!Array.isArray(arrayValue)) return null;
183
- return setNestedValue(value, path, [...arrayValue.slice(0, target), ...arrayValue.slice(target + 1)]);
184
+ const updatedArray = [...arrayValue.slice(0, target), ...arrayValue.slice(target + 1)];
185
+ return setNestedValue(value, path, updatedArray);
184
186
  }
185
187
  function addValueElement(value, path, type, currentType) {
186
188
  if (path.length === 0 && type.typeID !== TypeID.collection) return makeDefaultValue(type);
187
- return setNestedValue(value, path, [makeDefaultValue(currentType.base), ...extractValue(value, path) ?? []]);
189
+ const updatedArray = [makeDefaultValue(currentType.base), ...extractValue(value, path) ?? []];
190
+ return setNestedValue(value, path, updatedArray);
191
+ }
192
+ function canGenerateRandomValue(type, basics, cstByAlias) {
193
+ switch (type.typeID) {
194
+ case TypeID.integer: return true;
195
+ case TypeID.basic: {
196
+ const cst = cstByAlias.get(type.baseID);
197
+ const binding = cst ? basics.get(cst.id) : void 0;
198
+ return Object.keys(binding ?? {}).length > 0;
199
+ }
200
+ case TypeID.tuple: return type.factors.every((factor) => canGenerateRandomValue(factor, basics, cstByAlias));
201
+ case TypeID.collection: return canGenerateRandomValue(type.base, basics, cstByAlias);
202
+ case TypeID.anyTypification: return false;
203
+ }
188
204
  }
189
205
  function countBaseElements(cst, engine) {
190
206
  if (!isBasicConcept(cst.cst_type)) return 0;