@rsconcept/domain 2.3.0 → 3.0.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 (104) hide show
  1. package/dist/{analyzer-fNhkwO-6.d.ts → analyzer-CzFaWR7w.d.ts} +4 -4
  2. package/dist/{api-Bf0f_uiI.d.ts → api-DgecYHjR.d.ts} +5 -3
  3. package/dist/{arguments-extractor-ngatANBI.d.ts → arguments-extractor-CXWRT5Ou.d.ts} +4 -4
  4. package/dist/{ast-C8sIpKdL.d.ts → ast-D-D6Rq3T.d.ts} +2 -3
  5. package/dist/{ast-annotations-CiIx8qBM.d.ts → ast-annotations-x4PJ_Lhc.d.ts} +4 -4
  6. package/dist/{calculator-DE89LtIM.d.ts → calculator-uPaTV3hc.d.ts} +5 -5
  7. package/dist/cctext/language-api.d.ts +0 -1
  8. package/dist/{diagnostics-CljEzVBV.js → diagnostics-D1Cp21nP.js} +36 -13
  9. package/dist/diagnostics-D1Cp21nP.js.map +1 -0
  10. package/dist/{diagnostics-Dac5sJhO.d.ts → diagnostics-DKyMf6q-.d.ts} +24 -8
  11. package/dist/{expression-generator-CoucLIkE.d.ts → expression-generator-CADzBw-C.d.ts} +3 -2
  12. package/dist/graph/index.d.ts +1 -0
  13. package/dist/index-CnuO4w8e.d.ts +13 -0
  14. package/dist/index-D5RahF1K.d.ts +2 -0
  15. package/dist/index-DCO4mxiO.d.ts +378 -0
  16. package/dist/index-DntDUXW1.d.ts +1 -0
  17. package/dist/index-x0_Y5uPV.d.ts +2 -0
  18. package/dist/index.d.ts +13 -13
  19. package/dist/index.js +1 -1
  20. package/dist/{lezer-tree-iS7LpLBJ.d.ts → lezer-tree-BQZqBT5A.d.ts} +1 -2
  21. package/dist/library/diagnostics.d.ts +1 -1
  22. package/dist/library/diagnostics.js +1 -1
  23. package/dist/library/index.d.ts +5 -5
  24. package/dist/library/index.js +1 -1
  25. package/dist/library/index.js.map +1 -1
  26. package/dist/library/oss-api.d.ts +11 -3
  27. package/dist/library/oss-api.js +45 -4
  28. package/dist/library/oss-api.js.map +1 -1
  29. package/dist/library/oss-layout-api.d.ts +0 -1
  30. package/dist/library/oss.d.ts +21 -16
  31. package/dist/library/oss.js +19 -13
  32. package/dist/library/oss.js.map +1 -1
  33. package/dist/library/rsengine.d.ts +6 -5
  34. package/dist/library/rsengine.js +1 -1
  35. package/dist/library/rsform-api/index.d.ts +2 -299
  36. package/dist/library/rsform-api/index.js +1 -1
  37. package/dist/library/rsform.d.ts +1 -1
  38. package/dist/library/rsmodel-api.d.ts +12 -7
  39. package/dist/library/rsmodel-api.js +6 -2
  40. package/dist/library/rsmodel-api.js.map +1 -1
  41. package/dist/library/rsmodel.d.ts +1 -1
  42. package/dist/library/structure-planner.d.ts +3 -3
  43. package/dist/library/structure-planner.js +1 -1
  44. package/dist/library/structure-planner.js.map +1 -1
  45. package/dist/{parser-Bwd8LxJ1.d.ts → parser-DkejtiOR.d.ts} +1 -2
  46. package/dist/parsing/ast.d.ts +1 -1
  47. package/dist/parsing/index.d.ts +3 -2
  48. package/dist/parsing/lezer-tree.d.ts +1 -1
  49. package/dist/rslang/api.d.ts +2 -2
  50. package/dist/rslang/ast-annotations.d.ts +1 -1
  51. package/dist/rslang/eval/calculator.d.ts +1 -1
  52. package/dist/rslang/eval/evaluation-cache.d.ts +3 -3
  53. package/dist/rslang/eval/evaluator.d.ts +3 -3
  54. package/dist/rslang/eval/value-api.d.ts +1 -1
  55. package/dist/rslang/eval/value.d.ts +1 -1
  56. package/dist/rslang/index.d.ts +11 -10
  57. package/dist/rslang/labels.d.ts +3 -3
  58. package/dist/rslang/parser/expression-generator.d.ts +1 -1
  59. package/dist/rslang/parser/normalize.d.ts +2 -1
  60. package/dist/rslang/parser/parser.d.ts +1 -1
  61. package/dist/rslang/parser/parser.terms.d.ts +1 -40
  62. package/dist/rslang/parser/syntax-errors/index.d.ts +3 -3
  63. package/dist/rslang/semantic/analyzer.d.ts +1 -1
  64. package/dist/rslang/semantic/arguments-extractor.d.ts +1 -1
  65. package/dist/rslang/semantic/type-auditor.d.ts +3 -3
  66. package/dist/rslang/semantic/typification-api.d.ts +1 -2
  67. package/dist/rslang/semantic/typification-parser.d.ts +1 -1
  68. package/dist/rslang/semantic/typification.d.ts +1 -1
  69. package/dist/rslang/semantic/value-auditor.d.ts +2 -2
  70. package/dist/rslang/typification-graph.d.ts +1 -1
  71. package/dist/shared/index.d.ts +1 -0
  72. package/dist/{typification-graph-BY_oGT82.d.ts → typification-graph-CSxDt18X.d.ts} +2 -3
  73. package/dist/{typification-9lNu9R4k.d.ts → typification-hWUoWCba.d.ts} +2 -1
  74. package/dist/{typification-parser-Dytsv9CI.d.ts → typification-parser-DFxj4JiQ.d.ts} +2 -3
  75. package/dist/{value-BduA_ZGp.d.ts → value-XpJOVzMP.d.ts} +2 -1
  76. package/dist/{value-api-CXLl_zg0.d.ts → value-api-Dw8UkwCD.d.ts} +3 -4
  77. package/package.json +8 -8
  78. package/src/library/diagnostics.ts +36 -11
  79. package/src/library/oss-api.test.ts +100 -5
  80. package/src/library/oss-api.ts +76 -6
  81. package/src/library/oss.ts +22 -16
  82. package/src/library/rsform-api/alias.ts +8 -8
  83. package/src/library/rsform-api/cst-type.ts +7 -5
  84. package/src/library/rsform-api/expression.ts +3 -3
  85. package/src/library/rsform-api/formal-graph.test.ts +2 -2
  86. package/src/library/rsform-api/formal-graph.ts +6 -10
  87. package/src/library/rsform-api/index.ts +18 -3
  88. package/src/library/rsform-api/semantic-relations.ts +4 -7
  89. package/src/library/rsform-api/stats.ts +6 -5
  90. package/src/library/rsform-api/structure.ts +12 -6
  91. package/src/library/rsform-api/substitution.ts +2 -2
  92. package/src/library/rsform-api/synthesis.test.ts +33 -2
  93. package/src/library/rsform-api/synthesis.ts +16 -12
  94. package/src/library/rsform-api/text-resolution.test.ts +2 -4
  95. package/src/library/rsform-api/text-resolution.ts +8 -8
  96. package/src/library/rsform-api/types.ts +89 -8
  97. package/src/library/rsmodel-api.ts +10 -5
  98. package/src/library/structure-planner.ts +6 -2
  99. package/src/library/template-instantiation.ts +11 -9
  100. package/dist/diagnostics-CljEzVBV.js.map +0 -1
  101. package/dist/index-BKZ67WMa.d.ts +0 -1
  102. package/dist/index-BVVgDSdq.d.ts +0 -1
  103. package/dist/index-DmtQKWjk.d.ts +0 -1
  104. package/dist/index-_6s0AX1B.d.ts +0 -1
@@ -1,299 +1,2 @@
1
- import { t as Graph } from "../../graph-CL73WdW1.js";
2
- import { t as AstNode } from "../../ast-C8sIpKdL.js";
3
- import { g as TypeClass, y as TypePath } from "../../typification-9lNu9R4k.js";
4
- import { t as ValueClass } from "../../value-class-CNI-lqXJ.js";
5
- import { r as AnalysisFull } from "../../analyzer-fNhkwO-6.js";
6
- import { r as LibraryItem } from "../../library-CYun28Xz.js";
7
- 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-Dac5sJhO.js";
8
- import { t as AliasMapping } from "../../api-Bf0f_uiI.js";
9
-
10
- //#region src/library/rsform-api/types.d.ts
11
- /** Minimal constituent fields required to restore order. */
12
- interface OrderableConstituenta {
13
- id: number;
14
- alias: string;
15
- cst_type: CstType;
16
- definition_formal: string;
17
- }
18
- /** Semantic parent/children derived from formal definitions (backend SemanticInfo). */
19
- interface SemanticRelations {
20
- /** Parent id for each constituenta (self when none). */
21
- parentOf: Map<number, number>;
22
- /** Semantic children ids for each constituenta. */
23
- childrenOf: Map<number, number[]>;
24
- }
25
- /** Constituent fields needed to resolve term/definition entity references. */
26
- interface ResolvableConstituenta {
27
- id: number;
28
- alias: string;
29
- term_raw: string;
30
- term_resolved: string;
31
- term_forms: TermForm[];
32
- definition_raw: string;
33
- definition_resolved: string;
34
- }
35
- /** Constituent fields needed to allocate or reset aliases by type. */
36
- interface AliasTypedConstituenta {
37
- alias: string;
38
- cst_type: CstType;
39
- }
40
- //#endregion
41
- //#region src/library/rsform-api/alias.d.ts
42
- /** Fields of {@link Constituenta} updated in place by alias mapping. */
43
- interface ConstituentaMappableFields {
44
- alias: string;
45
- definition_formal: string;
46
- typification_manual: string;
47
- term_raw: string;
48
- definition_raw: string;
49
- }
50
- /** Build alias mapping from template argument bindings. */
51
- declare function argumentValuesToMapping(args: ArgumentValue[]): AliasMapping;
52
- /** Validate alias format for a given {@link CstType} (prefix + digits, min length 2). */
53
- declare function validateAliasFormat(alias: string, type: CstType): boolean;
54
- /** Validate new alias against {@link CstType} and {@link RSForm}. */
55
- declare function validateNewAlias(alias: string, type: CstType, schema: RSForm): boolean;
56
- /** Generate alias for new {@link Constituenta} of a given {@link CstType} for current {@link RSForm}. */
57
- declare function generateAlias(type: CstType, schema: RSForm, takenAliases?: string[]): string;
58
- /**
59
- * Remap formal expressions and terminological entity references in constituent fields.
60
- * Mutates each element of `items` in place; pass owned or cloned data only.
61
- */
62
- declare function applyMappingToConstituents<T extends ConstituentaMappableFields>(items: T[], mapping: AliasMapping, changeAliases: boolean): void;
63
- /** Highest numeric alias suffix for {@link type} among {@link items} (0 when none). */
64
- declare function maxAliasIndex(items: readonly AliasTypedConstituenta[], type: CstType): number;
65
- /**
66
- * Build alias → new-alias mapping that renumbers each type sequentially in list order.
67
- * Matches backend {@code RSFormCached.reset_aliases}.
68
- */
69
- declare function buildSequentialAliasMapping(items: readonly AliasTypedConstituenta[]): AliasMapping;
70
- /**
71
- * Allocate fresh aliases for {@link source} constituents being imported into a non-empty receiver.
72
- * Returns an empty mapping when the receiver has no items (aliases kept as-is).
73
- */
74
- declare function allocateImportAliases(receiver: readonly AliasTypedConstituenta[], source: readonly AliasTypedConstituenta[]): AliasMapping;
75
- /** Remove alias from expression. */
76
- declare function removeAliasReference(expression: string, alias: string): string;
77
- /** Add alias to expression. */
78
- declare function addAliasReference(expression: string, alias: string): string;
79
- //#endregion
80
- //#region src/library/rsform-api/analysis.d.ts
81
- declare function getAnalysisFor(expression: string, cstType: CstType, schema: RSForm, alias?: string): AnalysisFull;
82
- /**
83
- * When an untyped / bare F·P reference names a constituent on a definition cycle with the
84
- * current expression, replace that error with {@link RSDiagnosticCode.schemaDependencyCycle}.
85
- *
86
- * Covers both semantic `globalNotTyped` (e.g. `F3[σ]`) and parser `globalFuncWithoutArgs`
87
- * (bare `P1` / `F1` treated as a call without arguments).
88
- *
89
- * Uses a draft dependency graph: incoming edges of the edited constituent are taken from
90
- * `expression`, so Check works before Save.
91
- */
92
- declare function refineAnalysisForDependencyCycles(analysis: AnalysisFull, expression: string, schema: RSForm, alias?: string): AnalysisFull;
93
- //#endregion
94
- //#region src/library/rsform-api/attribution.d.ts
95
- /**
96
- * Remap attributions when constituents are substituted (original → replacement).
97
- * Drops self-loops and duplicates. Matches sandbox / backend substitute attribution rewrite.
98
- */
99
- declare function remapAttributionsUnderSubstitution(attributions: readonly Attribution[], origToSub: ReadonlyMap<number, number>): Attribution[];
100
- /**
101
- * Copy attributions whose both endpoints are in {@link sourceIdSet}, remapping ids via {@link idMap}.
102
- * Appends onto a clone of {@link existing} with dedupe. Used by schema embedding / insert.
103
- */
104
- declare function importAttributions(sourceAttributions: readonly Attribution[], sourceIdSet: ReadonlySet<number>, idMap: Readonly<Record<number, number>>, existing?: readonly Attribution[]): Attribution[];
105
- /** Drop attributions that reference any id in {@link deletedIds}. */
106
- declare function filterAttributions(attributions: readonly Attribution[], deletedIds: ReadonlySet<number>): Attribution[];
107
- //#endregion
108
- //#region src/library/rsform-api/cst-type.d.ts
109
- /** Prefix for alias indicating {@link CstType}. */
110
- declare function getCstTypePrefix(type: CstType): string;
111
- /** Guess {@link CstType} from user input hint. */
112
- declare function guessCstType(hint: string): CstType | null;
113
- /** Infers the {@link CstClass} based on the provided {@link CstType} and template status. */
114
- declare function inferClass(type: CstType, isTemplate?: boolean): CstClass;
115
- /** Check if {@link Constituenta} is a template or a category. */
116
- declare function isTemplateCst(cst: Constituenta): boolean;
117
- /** Evaluate if {@link CstType} is basic concept. */
118
- declare function isBasicConcept(type: CstType): boolean;
119
- /** Evaluate if {@link CstType} is base set or constant set. */
120
- declare function isBaseSet(type: CstType): boolean;
121
- /** Evaluate if {@link CstType} is a function. */
122
- declare function isFunctional(type: CstType): boolean;
123
- /** Evaluate if {@link CstType} is logical. */
124
- declare function isLogical(type: CstType): boolean;
125
- /** Evaluate if {@link CstType} can have manual typification. */
126
- declare function canHaveManualTypification(type: CstType): boolean;
127
- /** Checks whether a constituenta type supports formal definitions. */
128
- declare function canHaveFormalDefinition(cstType: CstType): boolean;
129
- /** Returns expected {@link TypeClass} of formal definition for {@link CstType}. */
130
- declare function typeClassForCstType(cstType: CstType): TypeClass;
131
- /** Evaluate if {@link Constituenta} can be used produce structure. */
132
- declare function canProduceStructure(cst: Constituenta): boolean;
133
- //#endregion
134
- //#region src/library/rsform-api/expression.d.ts
135
- /** Infers the status of an expression based on parsing and value information. */
136
- declare function inferStatus(parse: boolean, value?: ValueClass | null): CstStatus;
137
- /** Infers type of constituent for a given template and arguments. */
138
- declare function inferTemplatedType(templateType: CstType, args: ArgumentValue[]): CstType;
139
- /**
140
- * Normalize a RSLang expression for duplicate comparison.
141
- *
142
- * Returns `null` for basic concepts without formal definitions. Pass a pre-parsed `ast`
143
- * when the expression was already analyzed to avoid re-parsing.
144
- */
145
- declare function normalizeExpression(expression: string, cst_type: CstType, ast?: AstNode | null): string | null;
146
- /** Checks if given expression is a template. */
147
- declare function inferTemplate(expression: string): boolean;
148
- /** Apply filter based on start {@link Constituenta} type. */
149
- declare function applyFilterCategory(start: Constituenta, items: Constituenta[]): Constituenta[];
150
- //#endregion
151
- //#region src/library/rsform-api/formal-graph.d.ts
152
- /**
153
- * Build the formal dependency graph: supplier → dependent.
154
- * Matches backend {@code RSForm.graph_formal}.
155
- */
156
- declare function buildFormalDependencyGraph(items: readonly OrderableConstituenta[]): Graph<number>;
157
- /**
158
- * Reorder constituents: formal topology hard, semantic children sticky when ready,
159
- * otherwise stable against type/kernel preferred ranks.
160
- *
161
- * One Kahn pass over the formal dependency graph.
162
- */
163
- declare function restoreConstituentOrder<T extends OrderableConstituenta>(items: readonly T[], graph?: Graph<number>, relations?: SemanticRelations): T[];
164
- //#endregion
165
- //#region src/library/rsform-api/stats.d.ts
166
- /** Checks if {@link Constituenta} is a schema issue. */
167
- declare function isSchemaIssue(cst: Constituenta): boolean;
168
- /** Calculate statistics for {@link RSForm}. */
169
- declare function calculateSchemaStats(target: RSForm): RSFormStats;
170
- //#endregion
171
- //#region src/library/rsform-api/structure.d.ts
172
- /**
173
- * Id to pass as `insert_after` when creating a new {@link Constituenta} spawned by `targetId`:
174
- * after the last existing child of that spawner, or after the spawner itself if none.
175
- */
176
- declare function inferNewSpawnPosition(schema: RSForm, targetId: number): number;
177
- /** Finds {@link Constituenta} by structure path. */
178
- declare function findCstByStructure(schema: RSForm, target: Constituenta, path: TypePath): Constituenta | null;
179
- /** Retrieves name for piece of target {@link Constituenta} structure. */
180
- declare function getStructureName(schema: RSForm, target: Constituenta, path: TypePath): string;
181
- //#endregion
182
- //#region src/library/rsform-api/substitution.d.ts
183
- /** Result of applying substitutions to a schema fragment. */
184
- interface SubstitutionResult<T> {
185
- items: T[];
186
- attributions: Attribution[];
187
- deletedIds: Set<number>;
188
- /** Replacement constituent ids (survivors referenced by substitutions). */
189
- replacementIds: number[];
190
- }
191
- /**
192
- * Apply constituenta substitutions: remap attributions, drop originals, rewrite aliases in survivors.
193
- * Does not resolve texts — call {@link resolveAllConstituentTexts} afterwards.
194
- */
195
- declare function applyConstituentSubstitutions<T extends ConstituentaMappableFields & {
196
- id: number;
197
- alias: string;
198
- }>(items: readonly T[], attributions: readonly Attribution[], substitutions: readonly Substitution[]): SubstitutionResult<T>;
199
- /**
200
- * Remap substitution endpoints after source constituents were inserted under new ids.
201
- * If {@link original} was imported, map it; otherwise map {@link substitution}.
202
- */
203
- declare function remapSubstitutionsAfterImport(substitutions: readonly Substitution[], sourceIdSet: ReadonlySet<number>, idMap: Readonly<Record<number, number>>): Substitution[];
204
- //#endregion
205
- //#region src/library/rsform-api/synthesis.d.ts
206
- /** Constituent shape required for embedding / synthesis transforms. */
207
- type SynthesizableConstituenta = ConstituentaMappableFields & ResolvableConstituenta & AliasTypedConstituenta & {
208
- id: number;
209
- alias: string;
210
- cst_type: CstType;
211
- };
212
- /** Input for {@link inlineSynthesis}. */
213
- interface InlineSynthesisInput<T extends SynthesizableConstituenta> {
214
- /** Receiver schema constituents (order preserved; imports append). */
215
- receiverItems: readonly T[];
216
- /** Receiver attributions (default empty). */
217
- receiverAttributions?: readonly Attribution[];
218
- /**
219
- * Source constituents to insert (already filtered to the desired subset).
220
- * Cloned; originals are not mutated.
221
- */
222
- sourceItems: readonly T[];
223
- /** Source attributions whose both endpoints are among {@link sourceItems}. */
224
- sourceAttributions?: readonly Attribution[];
225
- /**
226
- * Identification table using pre-import ids:
227
- * one endpoint is a source id, the other a receiver id
228
- * (same rules as backend embedding / InlineSynthesis).
229
- */
230
- substitutions?: readonly Substitution[];
231
- /** Next free numeric id for inserted constituents. */
232
- nextId: number;
233
- }
234
- /** Result of {@link inlineSynthesis}. */
235
- interface InlineSynthesisResult<T extends SynthesizableConstituenta> {
236
- items: T[];
237
- attributions: Attribution[];
238
- /** Updated next-id after inserts. */
239
- nextId: number;
240
- /** Source id → inserted id. */
241
- idMap: Record<number, number>;
242
- /** Alias remapping applied to imported constituents (empty when receiver was empty). */
243
- aliasMapping: AliasMapping;
244
- /** Ids removed by substitutions. */
245
- deletedIds: Set<number>;
246
- /** Ids of newly inserted constituents (before any were deleted by substitutions). */
247
- insertedIds: number[];
248
- /** Survivor ids referenced by applied substitutions. */
249
- replacementIds: number[];
250
- }
251
- /**
252
- * Embed {@link InlineSynthesisInput.sourceItems} into the receiver and apply substitutions.
253
- * Resolves term/definition entity references on the result.
254
- * Does not mutate inputs.
255
- */
256
- declare function inlineSynthesis<T extends SynthesizableConstituenta>(input: InlineSynthesisInput<T>): InlineSynthesisResult<T>;
257
- /** Sorts library items relevant for schema embedding with specified {@link RSForm}. */
258
- declare function sortItemsForInlineSynthesis(receiver: RSForm, items: readonly LibraryItem[]): LibraryItem[];
259
- //#endregion
260
- //#region src/library/rsform-api/text-resolution.d.ts
261
- /** Options controlling which texts to re-resolve after an edit. */
262
- interface TextChangeOptions {
263
- termChanged: boolean;
264
- termRawChanged: boolean;
265
- definitionRawChanged: boolean;
266
- clearTargetForms: boolean;
267
- }
268
- /** Build term-reference graph: referenced constituent → dependent (backend {@code graph_term}). */
269
- declare function buildTermReferenceGraph(items: readonly ResolvableConstituenta[]): Graph<number>;
270
- /** Build definition-reference graph: referenced constituent → dependent (backend {@code graph_text}). */
271
- declare function buildDefinitionReferenceGraph(items: readonly ResolvableConstituenta[]): Graph<number>;
272
- /** Resolve all term and definition texts in topological order. Mutates items in place. */
273
- declare function resolveAllConstituentTexts(items: ResolvableConstituenta[]): void;
274
- /**
275
- * Resolve texts after a single constituent change, cascading dependents when the term changed.
276
- * Mutates items in place.
277
- */
278
- declare function resolveConstituentTextChange(items: ResolvableConstituenta[], targetID: number, options: TextChangeOptions): void;
279
- //#endregion
280
- //#region src/library/rsform-api/transforms.d.ts
281
- /**
282
- * Pure constituenta list transforms: reorder, move, insert position.
283
- */
284
- /** Rebuild an item list following {@link orderedIds}. Throws if an id is missing. */
285
- declare function reorderItemsByIds<T extends {
286
- id: number;
287
- }>(items: readonly T[], orderedIds: readonly number[]): T[];
288
- /**
289
- * Move a subset of ids within an ordered id list.
290
- * {@link moveTo} is clamped to `[0, rest.length]` (index among non-moving items).
291
- */
292
- declare function moveIdsInOrder(ids: readonly number[], moving: readonly number[], moveTo: number): number[];
293
- /** Insert {@link item} after {@link insertAfter}, or append when null/undefined/missing. Mutates {@link items}. */
294
- declare function insertItemAfter<T extends {
295
- id: number;
296
- }>(items: T[], item: T, insertAfter: number | null | undefined): void;
297
- //#endregion
298
- export { type AliasTypedConstituenta, type ConstituentaMappableFields, type InlineSynthesisInput, type InlineSynthesisResult, type OrderableConstituenta, type ResolvableConstituenta, type SemanticRelations, type SubstitutionResult, type SynthesizableConstituenta, type TextChangeOptions, 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 };
299
- //# sourceMappingURL=index.d.ts.map
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";
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-CljEzVBV.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-D1Cp21nP.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-Dac5sJhO.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-DKyMf6q-.js";
2
2
  export { ArgumentValue, Attribution, Constituenta, CstClass, CstStatus, CstType, RSForm, RSFormStats, Substitution, TermForm, TypeInfo };
@@ -1,8 +1,9 @@
1
- import { b as Typification, f as ExpressionType } from "../typification-9lNu9R4k.js";
2
- import { d as ValuePath, l as Value } from "../value-BduA_ZGp.js";
3
- import { S as RSForm, f as EvalStatus, l as BasicBinding, m as RSModelStats, v as Constituenta, x as CstType } from "../diagnostics-Dac5sJhO.js";
1
+ import { b as Typification, f as ExpressionType } from "../typification-hWUoWCba.js";
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";
4
5
  import { RSEngine } from "./rsengine.js";
5
-
6
+ import { st as ModelEvalFields } from "../index-DCO4mxiO.js";
6
7
  //#region src/library/rsmodel-api.d.ts
7
8
  /** Evaluate if parsed data is a basic binding data. */
8
9
  declare function validateBasicBindingData(data: unknown): data is Record<string, string>;
@@ -10,11 +11,15 @@ declare function validateBasicBindingData(data: unknown): data is Record<string,
10
11
  declare function toBasicBinding(data: Record<string | number, string>): BasicBinding;
11
12
  /** Evaluate if parsed data is a {@link Value} data. */
12
13
  declare function validateValueData(data: unknown): data is Value;
13
- declare function generateRandomValue(type: Typification, basics: Map<number, BasicBinding>, cstByAlias: Map<string, Constituenta>, setElementsCount?: number): Value | null;
14
+ declare function generateRandomValue(type: Typification, basics: Map<number, BasicBinding>, cstByAlias: Map<string, {
15
+ id: number;
16
+ }>, setElementsCount?: number): Value | null;
14
17
  /** Calculate statistics for {@link RSModel}. */
15
18
  declare function calculateModelStats(schema: RSForm, engine: RSEngine, _engineGeneration?: number): RSModelStats;
16
19
  /** Checks whether evaluation status contributes to model status issues. */
17
- declare function isModelIssue(engine: RSEngine, cst: Constituenta): boolean;
20
+ declare function isModelIssue(engine: RSEngine, cst: ModelEvalFields): boolean;
21
+ /** Filters items whose evaluation status contributes to model issues. */
22
+ declare function getEvalIssueItems(items: readonly ModelEvalFields[], engine: RSEngine): ModelEvalFields[];
18
23
  /** Evaluate if {@link CstType} is interpretable. */
19
24
  declare function isInterpretable(type: CstType): boolean;
20
25
  /** Evaluate if {@link CstType} is inferrable. */
@@ -31,5 +36,5 @@ declare function updateValueElement(value: Value | null, path: ValuePath, newVal
31
36
  declare function deleteValueElement(value: Value | null, path: ValuePath, type: Typification, target: number): Value | null;
32
37
  declare function addValueElement(value: Value | null, path: ValuePath, type: Typification, currentType: Typification): Value | null;
33
38
  //#endregion
34
- export { addValueElement, calculateModelStats, deleteValueElement, generateRandomValue, inferEvalStatus, isInferrable, isInterpretable, isModelIssue, toBasicBinding, tryFixValue, updateValueElement, validateBasicBindingData, validateValueData };
39
+ export { addValueElement, calculateModelStats, deleteValueElement, generateRandomValue, getEvalIssueItems, inferEvalStatus, isInferrable, isInterpretable, isModelIssue, toBasicBinding, tryFixValue, updateValueElement, validateBasicBindingData, validateValueData };
35
40
  //# sourceMappingURL=rsmodel-api.d.ts.map
@@ -2,7 +2,7 @@ import { TypeID } from "../rslang/semantic/typification.js";
2
2
  import { CstType } from "./rsform.js";
3
3
  import { O as setNestedValue, _ as extractValue, b as isTupleValue, f as tuple, l as compare, x as makeDefaultValue } from "../value-COprb2Je.js";
4
4
  import "../rslang/index.js";
5
- import { Q as isBasicConcept, S as calculateSchemaStats, Z as isBaseSet, s as modelStatusCstDiagnostic } from "../diagnostics-CljEzVBV.js";
5
+ import { Q as isBasicConcept, S as calculateSchemaStats, Z as isBaseSet, s as modelStatusCstDiagnostic } from "../diagnostics-D1Cp21nP.js";
6
6
  import { EvalStatus } from "./rsmodel.js";
7
7
  //#region src/library/rsmodel-api.ts
8
8
  const RANDOM_INTEGER_MIN = -100;
@@ -75,6 +75,10 @@ function calculateModelStats(schema, engine, _engineGeneration) {
75
75
  function isModelIssue(engine, cst) {
76
76
  return modelStatusCstDiagnostic(engine.getCstStatus(cst.id), cst.cst_type) !== null;
77
77
  }
78
+ /** Filters items whose evaluation status contributes to model issues. */
79
+ function getEvalIssueItems(items, engine) {
80
+ return items.filter((cst) => isModelIssue(engine, cst));
81
+ }
78
82
  /** Evaluate if {@link CstType} is interpretable. */
79
83
  function isInterpretable(type) {
80
84
  switch (type) {
@@ -190,6 +194,6 @@ function countBaseElements(cst, engine) {
190
194
  return value.length;
191
195
  }
192
196
  //#endregion
193
- export { addValueElement, calculateModelStats, deleteValueElement, generateRandomValue, inferEvalStatus, isInferrable, isInterpretable, isModelIssue, toBasicBinding, tryFixValue, updateValueElement, validateBasicBindingData, validateValueData };
197
+ export { addValueElement, calculateModelStats, deleteValueElement, generateRandomValue, getEvalIssueItems, inferEvalStatus, isInferrable, isInterpretable, isModelIssue, toBasicBinding, tryFixValue, updateValueElement, validateBasicBindingData, validateValueData };
194
198
 
195
199
  //# sourceMappingURL=rsmodel-api.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"rsmodel-api.js","names":[],"sources":["../../src/library/rsmodel-api.ts"],"sourcesContent":["import { type ExpressionType, TypeID, type Typification, type Value } from '../rslang';\nimport { compare, tuple, TUPLE_ID, VALUE_TRUE, type ValuePath } from '../rslang/eval/value';\nimport { extractValue, isTupleValue, makeDefaultValue, setNestedValue } from '../rslang/eval/value-api';\nimport { type EchelonCollection } from '../rslang/semantic/typification';\n\nimport { modelStatusCstDiagnostic } from './diagnostics';\nimport { type RSEngine } from './rsengine';\nimport { type Constituenta, CstType, type RSForm } from './rsform';\nimport { calculateSchemaStats, isBaseSet, isBasicConcept } from './rsform-api';\nimport { type BasicBinding, EvalStatus, type RSModelStats } from './rsmodel';\n\nconst RANDOM_INTEGER_MIN = -100;\nconst RANDOM_INTEGER_MAX = 100;\nconst DEFAULT_RANDOM_SET_ELEMENTS_COUNT = 5;\n\n/** Evaluate if parsed data is a basic binding data. */\nexport function validateBasicBindingData(data: unknown): data is Record<string, string> {\n if (!data || typeof data !== 'object' || Array.isArray(data)) {\n return false;\n }\n return Object.entries(data).every(([key, value]) => typeof value === 'string' && Number.isInteger(Number(key)));\n}\n\n/** Convert parsed data to a basic binding. */\nexport function toBasicBinding(data: Record<string | number, string>): BasicBinding {\n const result: BasicBinding = {};\n for (const [k, v] of Object.entries(data)) {\n result[Number(k)] = v;\n }\n return result;\n}\n\n/** Evaluate if parsed data is a {@link Value} data. */\nexport function validateValueData(data: unknown): data is Value {\n if (typeof data === 'number') {\n return Number.isFinite(data);\n }\n if (!Array.isArray(data)) {\n return false;\n }\n return data.every(item => validateValueData(item));\n}\n\nexport function generateRandomValue(\n type: Typification,\n basics: Map<number, BasicBinding>,\n cstByAlias: Map<string, Constituenta>,\n setElementsCount: number = DEFAULT_RANDOM_SET_ELEMENTS_COUNT\n): Value | null {\n switch (type.typeID) {\n case TypeID.integer:\n return Math.floor(Math.random() * (RANDOM_INTEGER_MAX - RANDOM_INTEGER_MIN + 1)) + RANDOM_INTEGER_MIN;\n case TypeID.basic: {\n const cst = cstByAlias.get(type.baseID);\n const binding = cst ? basics.get(cst.id) : undefined;\n const ids = Object.keys(binding ?? {}).map(Number);\n if (ids.length === 0) {\n return null;\n }\n return ids[Math.floor(Math.random() * ids.length)];\n }\n case TypeID.tuple: {\n const factors: Value[] = [];\n for (const factor of type.factors) {\n const sample = generateRandomValue(factor, basics, cstByAlias, setElementsCount);\n if (sample === null) {\n return null;\n }\n factors.push(sample);\n }\n return tuple(factors);\n }\n case TypeID.collection: {\n const result: Value[] = [];\n const randomElementsCount = Math.floor(Math.random() * (setElementsCount + 1));\n for (let i = 0; i < randomElementsCount; i++) {\n const sample = generateRandomValue(type.base, basics, cstByAlias, setElementsCount);\n if (sample === null) {\n return null;\n }\n result.push(sample);\n }\n return result;\n }\n case TypeID.anyTypification:\n return null;\n }\n}\n\n/** Calculate statistics for {@link RSModel}. */\nexport function calculateModelStats(schema: RSForm, engine: RSEngine, _engineGeneration?: number): RSModelStats {\n const items = schema.items;\n const statusByID = new Map<number, EvalStatus>();\n for (const cst of items) {\n statusByID.set(cst.id, engine.getCstStatus(cst.id));\n }\n return {\n ...calculateSchemaStats(schema),\n base_elements: items.reduce((sum, cst) => sum + countBaseElements(cst, engine), 0),\n count_missing_base: items.reduce(\n (sum, cst) => sum + (statusByID.get(cst.id) === EvalStatus.EMPTY && isBasicConcept(cst.cst_type) ? 1 : 0),\n 0\n ),\n count_false_axioms: items.reduce(\n (sum, cst) => sum + (statusByID.get(cst.id) === EvalStatus.AXIOM_FALSE ? 1 : 0),\n 0\n ),\n count_invalid_data: items.reduce(\n (sum, cst) => sum + (statusByID.get(cst.id) === EvalStatus.INVALID_DATA ? 1 : 0),\n 0\n ),\n count_invalid_calculations: items.reduce(\n (sum, cst) =>\n sum +\n (statusByID.get(cst.id) === EvalStatus.EVAL_FAIL || statusByID.get(cst.id) === EvalStatus.NOT_PROCESSED\n ? 1\n : 0),\n 0\n ),\n count_empty_terms: items.reduce(\n (sum, cst) => sum + (statusByID.get(cst.id) === EvalStatus.EMPTY && cst.cst_type === CstType.TERM ? 1 : 0),\n 0\n )\n };\n}\n\n/** Checks whether evaluation status contributes to model status issues. */\nexport function isModelIssue(engine: RSEngine, cst: Constituenta): boolean {\n return modelStatusCstDiagnostic(engine.getCstStatus(cst.id), cst.cst_type) !== null;\n}\n\n/** Evaluate if {@link CstType} is interpretable. */\nexport function isInterpretable(type: CstType): boolean {\n switch (type) {\n case CstType.BASE:\n case CstType.CONSTANT:\n case CstType.STRUCTURED:\n case CstType.AXIOM:\n case CstType.TERM:\n case CstType.STATEMENT:\n return true;\n\n case CstType.NOMINAL:\n case CstType.FUNCTION:\n case CstType.PREDICATE:\n return false;\n }\n}\n\n/** Evaluate if {@link CstType} is inferrable. */\nexport function isInferrable(type: CstType): boolean {\n switch (type) {\n case CstType.AXIOM:\n case CstType.STATEMENT:\n case CstType.TERM:\n return true;\n\n case CstType.NOMINAL:\n case CstType.BASE:\n case CstType.CONSTANT:\n case CstType.STRUCTURED:\n case CstType.FUNCTION:\n case CstType.PREDICATE:\n return false;\n }\n}\n\n/** Infers status of a given {@link Value} and {@link CstType}. */\nexport function inferEvalStatus(\n value: Value | null,\n cstType: CstType,\n wasCalculated: boolean = true,\n isInvalid: boolean = false\n): EvalStatus {\n if (isBaseSet(cstType) || cstType === CstType.STRUCTURED) {\n if (isInvalid) {\n return EvalStatus.INVALID_DATA;\n }\n if (value === null || (Array.isArray(value) && value.length === 0)) {\n return EvalStatus.EMPTY;\n }\n return EvalStatus.HAS_DATA;\n }\n if (!isInferrable(cstType)) {\n return EvalStatus.NO_EVAL;\n }\n if (!wasCalculated) {\n return EvalStatus.NOT_PROCESSED;\n }\n if (value === null) {\n return EvalStatus.EVAL_FAIL;\n }\n if (cstType === CstType.AXIOM && value !== VALUE_TRUE) {\n return EvalStatus.AXIOM_FALSE;\n }\n if (Array.isArray(value) && value.length === 0) {\n return EvalStatus.EMPTY;\n }\n return EvalStatus.HAS_DATA;\n}\n\n/** Tries to fix value removing invalid base elements not present in the target value.\n * returns null if no fixing is possible.\n * returns true if fixing was successful.\n * returns false if fixing was not needed.\n */\nexport function tryFixValue(\n value: Value,\n type: ExpressionType,\n targetAlias: string,\n targetValue: Value[]\n): boolean | null {\n switch (type.typeID) {\n case TypeID.integer:\n return false;\n case TypeID.basic:\n if (type.baseID !== targetAlias) {\n return false;\n }\n if (typeof value !== 'number') {\n return null;\n }\n if (!targetValue.includes(value)) {\n return null;\n }\n return false;\n case TypeID.tuple: {\n if (!isTupleValue(value)) {\n return null;\n }\n let wasChanged = false;\n for (let i = 0; i < type.factors.length; i++) {\n const componentChanged = tryFixValue(value[i + 1], type.factors[i], targetAlias, targetValue);\n if (componentChanged === null) {\n return null;\n }\n if (componentChanged) {\n wasChanged = true;\n }\n }\n return wasChanged;\n }\n case TypeID.collection:\n if (!Array.isArray(value) || (value.length > 1 && value[0] === TUPLE_ID)) {\n return null;\n }\n let wasChanged = false;\n const removeElements: Value[] = [];\n for (const item of value) {\n const elementChanged = tryFixValue(item, type.base, targetAlias, targetValue);\n if (elementChanged === null || elementChanged === true) {\n wasChanged = true;\n if (elementChanged === null) {\n removeElements.push(item);\n }\n }\n }\n for (const item of removeElements) {\n const index = value.indexOf(item);\n if (index !== -1) {\n value.splice(index, 1);\n }\n }\n if (wasChanged) {\n value.sort((a, b) => compare(a, b));\n let i = 1;\n while (i < value.length) {\n if (compare(value[i], value[i - 1]) === 0) {\n value.splice(i, 1);\n } else {\n i++;\n }\n }\n }\n return wasChanged;\n\n case TypeID.logic:\n case TypeID.anyTypification:\n case TypeID.predicate:\n case TypeID.function:\n return null;\n }\n}\n\nexport function updateValueElement(value: Value | null, path: ValuePath, newValue: number): Value | null {\n return setNestedValue(value, path, newValue);\n}\n\nexport function deleteValueElement(\n value: Value | null,\n path: ValuePath,\n type: Typification,\n target: number\n): Value | null {\n if (value === null) {\n return null;\n }\n if (path.length === 0 && type.typeID !== TypeID.collection) {\n return null;\n }\n\n const arrayValue = extractValue(value, path);\n if (!Array.isArray(arrayValue)) {\n return null;\n }\n const updatedArray = [...arrayValue.slice(0, target), ...arrayValue.slice(target + 1)];\n return setNestedValue(value, path, updatedArray);\n}\n\nexport function addValueElement(\n value: Value | null,\n path: ValuePath,\n type: Typification,\n currentType: Typification\n): Value | null {\n if (path.length === 0 && type.typeID !== TypeID.collection) {\n return makeDefaultValue(type);\n }\n\n const newElem = makeDefaultValue((currentType as EchelonCollection).base);\n const arrayValue = (extractValue(value!, path) as Value[] | null) ?? [];\n const updatedArray = [newElem, ...arrayValue];\n return setNestedValue(value, path, updatedArray);\n}\n\n// ========= Internal functions ==========\n\nfunction countBaseElements(cst: Constituenta, engine: RSEngine): number {\n if (!isBasicConcept(cst.cst_type)) {\n return 0;\n }\n const value = engine.getCstValue(cst.id);\n if (value === null) {\n return 0;\n }\n if (!Array.isArray(value) || value[0] === TUPLE_ID) {\n return 1;\n }\n return value.length;\n}\n"],"mappings":";;;;;;;AAWA,MAAM,qBAAqB;AAE3B,MAAM,oCAAoC;;AAG1C,SAAgB,yBAAyB,MAA+C;CACtF,IAAI,CAAC,QAAQ,OAAO,SAAS,YAAY,MAAM,QAAQ,IAAI,GACzD,OAAO;CAET,OAAO,OAAO,QAAQ,IAAI,CAAC,CAAC,OAAO,CAAC,KAAK,WAAW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OAAO;CAET,IAAI,KAAK,WAAW,KAAK,KAAK,WAAW,OAAO,YAC9C,OAAO;CAGT,MAAM,aAAa,aAAa,OAAO,IAAI;CAC3C,IAAI,CAAC,MAAM,QAAQ,UAAU,GAC3B,OAAO;CAGT,OAAO,eAAe,OAAO,MAAM,CADb,GAAG,WAAW,MAAM,GAAG,MAAM,GAAG,GAAG,WAAW,MAAM,SAAS,CAAC,CACjD,CAAY;AACjD;AAEA,SAAgB,gBACd,OACA,MACA,MACA,aACc;CACd,IAAI,KAAK,WAAW,KAAK,KAAK,WAAW,OAAO,YAC9C,OAAO,iBAAiB,IAAI;CAM9B,OAAO,eAAe,OAAO,MAAM,CAHnB,iBAAkB,YAAkC,IAE9C,GAAS,GADX,aAAa,OAAQ,IAAI,KAAwB,CAAC,CAEnC,CAAY;AACjD;AAIA,SAAS,kBAAkB,KAAmB,QAA0B;CACtE,IAAI,CAAC,eAAe,IAAI,QAAQ,GAC9B,OAAO;CAET,MAAM,QAAQ,OAAO,YAAY,IAAI,EAAE;CACvC,IAAI,UAAU,MACZ,OAAO;CAET,IAAI,CAAC,MAAM,QAAQ,KAAK,KAAK,MAAM,OAAA,MACjC,OAAO;CAET,OAAO,MAAM;AACf"}
1
+ {"version":3,"file":"rsmodel-api.js","names":[],"sources":["../../src/library/rsmodel-api.ts"],"sourcesContent":["import { type ExpressionType, TypeID, type Typification, type Value } from '../rslang';\nimport { compare, tuple, TUPLE_ID, VALUE_TRUE, type ValuePath } from '../rslang/eval/value';\nimport { extractValue, isTupleValue, makeDefaultValue, setNestedValue } from '../rslang/eval/value-api';\nimport { type EchelonCollection } from '../rslang/semantic/typification';\n\nimport { modelStatusCstDiagnostic } from './diagnostics';\nimport { type RSEngine } from './rsengine';\nimport { CstType, type RSForm } from './rsform';\nimport { calculateSchemaStats, isBaseSet, isBasicConcept, type ModelEvalFields } from './rsform-api';\nimport { type BasicBinding, EvalStatus, type RSModelStats } from './rsmodel';\n\nconst RANDOM_INTEGER_MIN = -100;\nconst RANDOM_INTEGER_MAX = 100;\nconst DEFAULT_RANDOM_SET_ELEMENTS_COUNT = 5;\n\n/** Evaluate if parsed data is a basic binding data. */\nexport function validateBasicBindingData(data: unknown): data is Record<string, string> {\n if (!data || typeof data !== 'object' || Array.isArray(data)) {\n return false;\n }\n return Object.entries(data).every(([key, value]) => typeof value === 'string' && Number.isInteger(Number(key)));\n}\n\n/** Convert parsed data to a basic binding. */\nexport function toBasicBinding(data: Record<string | number, string>): BasicBinding {\n const result: BasicBinding = {};\n for (const [k, v] of Object.entries(data)) {\n result[Number(k)] = v;\n }\n return result;\n}\n\n/** Evaluate if parsed data is a {@link Value} data. */\nexport function validateValueData(data: unknown): data is Value {\n if (typeof data === 'number') {\n return Number.isFinite(data);\n }\n if (!Array.isArray(data)) {\n return false;\n }\n return data.every(item => validateValueData(item));\n}\n\nexport function generateRandomValue(\n type: Typification,\n basics: Map<number, BasicBinding>,\n cstByAlias: Map<string, { id: number }>,\n setElementsCount: number = DEFAULT_RANDOM_SET_ELEMENTS_COUNT\n): Value | null {\n switch (type.typeID) {\n case TypeID.integer:\n return Math.floor(Math.random() * (RANDOM_INTEGER_MAX - RANDOM_INTEGER_MIN + 1)) + RANDOM_INTEGER_MIN;\n case TypeID.basic: {\n const cst = cstByAlias.get(type.baseID);\n const binding = cst ? basics.get(cst.id) : undefined;\n const ids = Object.keys(binding ?? {}).map(Number);\n if (ids.length === 0) {\n return null;\n }\n return ids[Math.floor(Math.random() * ids.length)];\n }\n case TypeID.tuple: {\n const factors: Value[] = [];\n for (const factor of type.factors) {\n const sample = generateRandomValue(factor, basics, cstByAlias, setElementsCount);\n if (sample === null) {\n return null;\n }\n factors.push(sample);\n }\n return tuple(factors);\n }\n case TypeID.collection: {\n const result: Value[] = [];\n const randomElementsCount = Math.floor(Math.random() * (setElementsCount + 1));\n for (let i = 0; i < randomElementsCount; i++) {\n const sample = generateRandomValue(type.base, basics, cstByAlias, setElementsCount);\n if (sample === null) {\n return null;\n }\n result.push(sample);\n }\n return result;\n }\n case TypeID.anyTypification:\n return null;\n }\n}\n\n/** Calculate statistics for {@link RSModel}. */\nexport function calculateModelStats(schema: RSForm, engine: RSEngine, _engineGeneration?: number): RSModelStats {\n const items = schema.items;\n const statusByID = new Map<number, EvalStatus>();\n for (const cst of items) {\n statusByID.set(cst.id, engine.getCstStatus(cst.id));\n }\n return {\n ...calculateSchemaStats(schema),\n base_elements: items.reduce((sum, cst) => sum + countBaseElements(cst, engine), 0),\n count_missing_base: items.reduce(\n (sum, cst) => sum + (statusByID.get(cst.id) === EvalStatus.EMPTY && isBasicConcept(cst.cst_type) ? 1 : 0),\n 0\n ),\n count_false_axioms: items.reduce(\n (sum, cst) => sum + (statusByID.get(cst.id) === EvalStatus.AXIOM_FALSE ? 1 : 0),\n 0\n ),\n count_invalid_data: items.reduce(\n (sum, cst) => sum + (statusByID.get(cst.id) === EvalStatus.INVALID_DATA ? 1 : 0),\n 0\n ),\n count_invalid_calculations: items.reduce(\n (sum, cst) =>\n sum +\n (statusByID.get(cst.id) === EvalStatus.EVAL_FAIL || statusByID.get(cst.id) === EvalStatus.NOT_PROCESSED\n ? 1\n : 0),\n 0\n ),\n count_empty_terms: items.reduce(\n (sum, cst) => sum + (statusByID.get(cst.id) === EvalStatus.EMPTY && cst.cst_type === CstType.TERM ? 1 : 0),\n 0\n )\n };\n}\n\n/** Checks whether evaluation status contributes to model status issues. */\nexport function isModelIssue(engine: RSEngine, cst: ModelEvalFields): boolean {\n return modelStatusCstDiagnostic(engine.getCstStatus(cst.id), cst.cst_type) !== null;\n}\n\n/** Filters items whose evaluation status contributes to model issues. */\nexport function getEvalIssueItems(items: readonly ModelEvalFields[], engine: RSEngine): ModelEvalFields[] {\n return items.filter(cst => isModelIssue(engine, cst));\n}\n\n/** Evaluate if {@link CstType} is interpretable. */\nexport function isInterpretable(type: CstType): boolean {\n switch (type) {\n case CstType.BASE:\n case CstType.CONSTANT:\n case CstType.STRUCTURED:\n case CstType.AXIOM:\n case CstType.TERM:\n case CstType.STATEMENT:\n return true;\n\n case CstType.NOMINAL:\n case CstType.FUNCTION:\n case CstType.PREDICATE:\n return false;\n }\n}\n\n/** Evaluate if {@link CstType} is inferrable. */\nexport function isInferrable(type: CstType): boolean {\n switch (type) {\n case CstType.AXIOM:\n case CstType.STATEMENT:\n case CstType.TERM:\n return true;\n\n case CstType.NOMINAL:\n case CstType.BASE:\n case CstType.CONSTANT:\n case CstType.STRUCTURED:\n case CstType.FUNCTION:\n case CstType.PREDICATE:\n return false;\n }\n}\n\n/** Infers status of a given {@link Value} and {@link CstType}. */\nexport function inferEvalStatus(\n value: Value | null,\n cstType: CstType,\n wasCalculated: boolean = true,\n isInvalid: boolean = false\n): EvalStatus {\n if (isBaseSet(cstType) || cstType === CstType.STRUCTURED) {\n if (isInvalid) {\n return EvalStatus.INVALID_DATA;\n }\n if (value === null || (Array.isArray(value) && value.length === 0)) {\n return EvalStatus.EMPTY;\n }\n return EvalStatus.HAS_DATA;\n }\n if (!isInferrable(cstType)) {\n return EvalStatus.NO_EVAL;\n }\n if (!wasCalculated) {\n return EvalStatus.NOT_PROCESSED;\n }\n if (value === null) {\n return EvalStatus.EVAL_FAIL;\n }\n if (cstType === CstType.AXIOM && value !== VALUE_TRUE) {\n return EvalStatus.AXIOM_FALSE;\n }\n if (Array.isArray(value) && value.length === 0) {\n return EvalStatus.EMPTY;\n }\n return EvalStatus.HAS_DATA;\n}\n\n/** Tries to fix value removing invalid base elements not present in the target value.\n * returns null if no fixing is possible.\n * returns true if fixing was successful.\n * returns false if fixing was not needed.\n */\nexport function tryFixValue(\n value: Value,\n type: ExpressionType,\n targetAlias: string,\n targetValue: Value[]\n): boolean | null {\n switch (type.typeID) {\n case TypeID.integer:\n return false;\n case TypeID.basic:\n if (type.baseID !== targetAlias) {\n return false;\n }\n if (typeof value !== 'number') {\n return null;\n }\n if (!targetValue.includes(value)) {\n return null;\n }\n return false;\n case TypeID.tuple: {\n if (!isTupleValue(value)) {\n return null;\n }\n let wasChanged = false;\n for (let i = 0; i < type.factors.length; i++) {\n const componentChanged = tryFixValue(value[i + 1], type.factors[i], targetAlias, targetValue);\n if (componentChanged === null) {\n return null;\n }\n if (componentChanged) {\n wasChanged = true;\n }\n }\n return wasChanged;\n }\n case TypeID.collection:\n if (!Array.isArray(value) || (value.length > 1 && value[0] === TUPLE_ID)) {\n return null;\n }\n let wasChanged = false;\n const removeElements: Value[] = [];\n for (const item of value) {\n const elementChanged = tryFixValue(item, type.base, targetAlias, targetValue);\n if (elementChanged === null || elementChanged === true) {\n wasChanged = true;\n if (elementChanged === null) {\n removeElements.push(item);\n }\n }\n }\n for (const item of removeElements) {\n const index = value.indexOf(item);\n if (index !== -1) {\n value.splice(index, 1);\n }\n }\n if (wasChanged) {\n value.sort((a, b) => compare(a, b));\n let i = 1;\n while (i < value.length) {\n if (compare(value[i], value[i - 1]) === 0) {\n value.splice(i, 1);\n } else {\n i++;\n }\n }\n }\n return wasChanged;\n\n case TypeID.logic:\n case TypeID.anyTypification:\n case TypeID.predicate:\n case TypeID.function:\n return null;\n }\n}\n\nexport function updateValueElement(value: Value | null, path: ValuePath, newValue: number): Value | null {\n return setNestedValue(value, path, newValue);\n}\n\nexport function deleteValueElement(\n value: Value | null,\n path: ValuePath,\n type: Typification,\n target: number\n): Value | null {\n if (value === null) {\n return null;\n }\n if (path.length === 0 && type.typeID !== TypeID.collection) {\n return null;\n }\n\n const arrayValue = extractValue(value, path);\n if (!Array.isArray(arrayValue)) {\n return null;\n }\n const updatedArray = [...arrayValue.slice(0, target), ...arrayValue.slice(target + 1)];\n return setNestedValue(value, path, updatedArray);\n}\n\nexport function addValueElement(\n value: Value | null,\n path: ValuePath,\n type: Typification,\n currentType: Typification\n): Value | null {\n if (path.length === 0 && type.typeID !== TypeID.collection) {\n return makeDefaultValue(type);\n }\n\n const newElem = makeDefaultValue((currentType as EchelonCollection).base);\n const arrayValue = (extractValue(value!, path) as Value[] | null) ?? [];\n const updatedArray = [newElem, ...arrayValue];\n return setNestedValue(value, path, updatedArray);\n}\n\n// ========= Internal functions ==========\n\nfunction countBaseElements(cst: ModelEvalFields, engine: RSEngine): number {\n if (!isBasicConcept(cst.cst_type)) {\n return 0;\n }\n const value = engine.getCstValue(cst.id);\n if (value === null) {\n return 0;\n }\n if (!Array.isArray(value) || value[0] === TUPLE_ID) {\n return 1;\n }\n return value.length;\n}\n"],"mappings":";;;;;;;AAWA,MAAM,qBAAqB;AAE3B,MAAM,oCAAoC;;AAG1C,SAAgB,yBAAyB,MAA+C;CACtF,IAAI,CAAC,QAAQ,OAAO,SAAS,YAAY,MAAM,QAAQ,IAAI,GACzD,OAAO;CAET,OAAO,OAAO,QAAQ,IAAI,CAAC,CAAC,OAAO,CAAC,KAAK,WAAW,OAAO,UAAU,YAAY,OAAO,UAAU,OAAO,GAAG,CAAC,CAAC;AAChH;;AAGA,SAAgB,eAAe,MAAqD;CAClF,MAAM,SAAuB,CAAC;CAC9B,KAAK,MAAM,CAAC,GAAG,MAAM,OAAO,QAAQ,IAAI,GACtC,OAAO,OAAO,CAAC,KAAK;CAEtB,OAAO;AACT;;AAGA,SAAgB,kBAAkB,MAA8B;CAC9D,IAAI,OAAO,SAAS,UAClB,OAAO,OAAO,SAAS,IAAI;CAE7B,IAAI,CAAC,MAAM,QAAQ,IAAI,GACrB,OAAO;CAET,OAAO,KAAK,OAAM,SAAQ,kBAAkB,IAAI,CAAC;AACnD;AAEA,SAAgB,oBACd,MACA,QACA,YACA,mBAA2B,mCACb;CACd,QAAQ,KAAK,QAAb;EACE,KAAK,OAAO,SACV,OAAO,KAAK,MAAM,KAAK,OAAO,IAAK,GAA4C,IAAI;EACrF,KAAK,OAAO,OAAO;GACjB,MAAM,MAAM,WAAW,IAAI,KAAK,MAAM;GACtC,MAAM,UAAU,MAAM,OAAO,IAAI,IAAI,EAAE,IAAI;GAC3C,MAAM,MAAM,OAAO,KAAK,WAAW,CAAC,CAAC,CAAC,CAAC,IAAI,MAAM;GACjD,IAAI,IAAI,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;CAET,IAAI,CAAC,MAAM,QAAQ,KAAK,KAAK,MAAM,OAAA,MACjC,OAAO;CAET,OAAO,MAAM;AACf"}
@@ -1,2 +1,2 @@
1
- import { d as DEFAULT_VALUE_TEXT, f as EvalStatus, h as TYPE_BASIC, l as BasicBinding, m as RSModelStats, p as RSModel, u as BasicsContext } from "../diagnostics-Dac5sJhO.js";
1
+ import { d as DEFAULT_VALUE_TEXT, f as EvalStatus, h as TYPE_BASIC, l as BasicBinding, m as RSModelStats, p as RSModel, u as BasicsContext } from "../diagnostics-DKyMf6q-.js";
2
2
  export { BasicBinding, BasicsContext, DEFAULT_VALUE_TEXT, EvalStatus, RSModel, RSModelStats, TYPE_BASIC };
@@ -1,6 +1,6 @@
1
- import { b as Typification, y as TypePath } from "../typification-9lNu9R4k.js";
2
- import { S as RSForm, v as Constituenta } from "../diagnostics-Dac5sJhO.js";
3
-
1
+ import { b as Typification, y as TypePath } from "../typification-hWUoWCba.js";
2
+ import "../index-CnuO4w8e.js";
3
+ import { S as RSForm, v as Constituenta } from "../diagnostics-DKyMf6q-.js";
4
4
  //#region src/library/structure-planner.d.ts
5
5
  /** Represents a node in the structure planner. */
6
6
  interface SPNode {
@@ -3,7 +3,7 @@ import { labelType } from "../rslang/labels.js";
3
3
  import { splitTemplateDefinition } from "../rslang/api.js";
4
4
  import { CstType } from "./rsform.js";
5
5
  import "../rslang/index.js";
6
- import { y as findCstByStructure } from "../diagnostics-CljEzVBV.js";
6
+ import { y as findCstByStructure } from "../diagnostics-D1Cp21nP.js";
7
7
  //#region src/library/structure-planner.ts
8
8
  /** Structure planner for {@link Constituenta}. */
9
9
  var StructurePlanner = class {
@@ -1 +1 @@
1
- {"version":3,"file":"structure-planner.js","names":[],"sources":["../../src/library/structure-planner.ts"],"sourcesContent":["import { makeTypePath, TypeID, type TypePath, type Typification } from '../rslang';\nimport { splitTemplateDefinition } from '../rslang/api';\nimport { labelType } from '../rslang/labels';\nimport { bool, type EchelonFunctional, isTypification } from '../rslang/semantic/typification';\n\nimport { type Constituenta, CstType, type RSForm } from './rsform';\nimport { findCstByStructure } from './rsform-api';\n\n/** Represents a node in the structure planner. */\nexport interface SPNode {\n key: string;\n path: TypePath;\n type: Typification;\n parent: number | null;\n definition: string;\n existing: Constituenta | null;\n}\n\n/** Structure planner for {@link Constituenta}. */\nexport class StructurePlanner {\n private items: SPNode[] = [];\n private schema: RSForm;\n private target: Constituenta;\n private rootType: Typification;\n\n constructor(schema: RSForm, target: Constituenta) {\n const eff = target.effectiveType;\n if (eff == null) {\n throw new Error('Invalid typification for target');\n }\n this.schema = schema;\n this.target = target;\n if (target.cst_type === CstType.FUNCTION && !isTypification(eff)) {\n this.rootType = (eff as EchelonFunctional).result;\n } else if (isTypification(eff)) {\n this.rootType = eff as Typification;\n } else {\n throw new Error('Invalid typification for target');\n }\n }\n\n public build(): SPNode[] {\n this.items.push({\n key: 'root',\n path: makeTypePath([]),\n type: this.rootType,\n parent: null,\n definition: labelType(this.target.effectiveType),\n existing: this.target\n });\n this.visit(this.rootType, this.rootType.typeID === TypeID.collection ? [0] : [], 0);\n return this.items;\n }\n\n private visit(type: Typification, path: number[], parent: number) {\n switch (type.typeID) {\n case TypeID.collection:\n if (type.base.typeID === TypeID.tuple) {\n type.base.factors.forEach((factor, index) => {\n const nextPath = [...path, index + 1];\n const nextType = bool(factor);\n const nextNode = this.pushNode(nextPath, nextType, parent);\n this.visit(nextType, nextPath, nextNode);\n });\n } else if (type.base.typeID === TypeID.collection) {\n const nextPath = [...path, 0];\n const nextNode = this.pushNode(nextPath, type.base, parent);\n this.visit(type.base, nextPath, nextNode);\n }\n return;\n case TypeID.tuple:\n type.factors.forEach((factor, index) => {\n const nextPath = [...path, index + 1];\n const nextNode = this.pushNode(nextPath, factor, parent);\n this.visit(factor, nextPath, nextNode);\n });\n return;\n default:\n return;\n }\n }\n\n private pushNode(path: number[], type: Typification, parent: number) {\n const typePath = makeTypePath(path);\n this.items.push({\n key: formatPathText(typePath),\n path: typePath,\n type: type,\n parent: parent,\n definition: produceDefinition(this.target, this.rootType, typePath),\n existing: findCstByStructure(this.schema, this.target, typePath)\n });\n return this.items.length - 1;\n }\n}\n\n// ======= Internals =======\nfunction produceDefinition(target: Constituenta, rootType: Typification, path: TypePath): string {\n let current = rootType;\n let expression = target.alias;\n let index = rootType.typeID === TypeID.collection ? 1 : 0;\n let prefix = '';\n if (target.cst_type === CstType.FUNCTION) {\n prefix = `[${splitTemplateDefinition(target.definition_formal).head}] `;\n const funcType =\n target.effectiveType && !isTypification(target.effectiveType)\n ? (target.effectiveType as EchelonFunctional)\n : null;\n if (funcType) {\n expression = `${expression}[${funcType.args.map(arg => arg.alias).join(', ')}]`;\n }\n }\n\n while (index < path.length) {\n const step = path[index];\n switch (current.typeID) {\n case TypeID.collection:\n if (current.base.typeID === TypeID.tuple) {\n expression = `Pr${step}(${expression})`;\n current = bool(current.base.factors[step - 1]);\n index += 1;\n } else {\n expression = `red(${expression})`;\n current = current.base;\n index += 1;\n }\n break;\n case TypeID.tuple:\n expression = `pr${step}(${expression})`;\n current = current.factors[step - 1];\n index += 1;\n break;\n default:\n return prefix + expression;\n }\n }\n\n return prefix + expression;\n}\n\nfunction formatPathText(path: TypePath): string {\n return path.map(step => String(step)).join('.');\n}\n"],"mappings":";;;;;;;;AAmBA,IAAa,mBAAb,MAA8B;CAC5B,QAA0B,CAAC;CAC3B;CACA;CACA;CAEA,YAAY,QAAgB,QAAsB;EAChD,MAAM,MAAM,OAAO;EACnB,IAAI,OAAO,MACT,MAAM,IAAI,MAAM,iCAAiC;EAEnD,KAAK,SAAS;EACd,KAAK,SAAS;EACd,IAAI,OAAO,aAAa,QAAQ,YAAY,CAAC,eAAe,GAAG,GAC7D,KAAK,WAAY,IAA0B;OACtC,IAAI,eAAe,GAAG,GAC3B,KAAK,WAAW;OAEhB,MAAM,IAAI,MAAM,iCAAiC;CAErD;CAEA,QAAyB;EACvB,KAAK,MAAM,KAAK;GACd,KAAK;GACL,MAAM,aAAa,CAA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AC;EACD,OAAO,KAAK,MAAM,SAAS;CAC7B;AACF;AAGA,SAAS,kBAAkB,QAAsB,UAAwB,MAAwB;CAC/F,IAAI,UAAU;CACd,IAAI,aAAa,OAAO;CACxB,IAAI,QAAQ,SAAS,WAAW,OAAO,aAAa,IAAI;CACxD,IAAI,SAAS;CACb,IAAI,OAAO,aAAa,QAAQ,UAAU;EACxC,SAAS,IAAI,wBAAwB,OAAO,iBAAiB,CAAC,CAAC,KAAK;EACpE,MAAM,WACJ,OAAO,iBAAiB,CAAC,eAAe,OAAO,aAAa,IACvD,OAAO,gBACR;EACN,IAAI,UACF,aAAa,GAAG,WAAW,GAAG,SAAS,KAAK,KAAI,QAAO,IAAI,KAAK,CAAC,CAAC,KAAK,IAAI,EAAE;CAEjF;CAEA,OAAO,QAAQ,KAAK,QAAQ;EAC1B,MAAM,OAAO,KAAK;EAClB,QAAQ,QAAQ,QAAhB;GACE,KAAK,OAAO;IACV,IAAI,QAAQ,KAAK,WAAW,OAAO,OAAO;KACxC,aAAa,KAAK,KAAK,GAAG,WAAW;KACrC,UAAU,KAAK,QAAQ,KAAK,QAAQ,OAAO,EAAE;KAC7C,SAAS;IACX,OAAO;KACL,aAAa,OAAO,WAAW;KAC/B,UAAU,QAAQ;KAClB,SAAS;IACX;IACA;GACF,KAAK,OAAO;IACV,aAAa,KAAK,KAAK,GAAG,WAAW;IACrC,UAAU,QAAQ,QAAQ,OAAO;IACjC,SAAS;IACT;GACF,SACE,OAAO,SAAS;EACpB;CACF;CAEA,OAAO,SAAS;AAClB;AAEA,SAAS,eAAe,MAAwB;CAC9C,OAAO,KAAK,KAAI,SAAQ,OAAO,IAAI,CAAC,CAAC,CAAC,KAAK,GAAG;AAChD"}
1
+ {"version":3,"file":"structure-planner.js","names":[],"sources":["../../src/library/structure-planner.ts"],"sourcesContent":["import { makeTypePath, TypeID, type TypePath, type Typification } from '../rslang';\nimport { splitTemplateDefinition } from '../rslang/api';\nimport { labelType } from '../rslang/labels';\nimport { bool, type EchelonFunctional, isTypification } from '../rslang/semantic/typification';\n\nimport { type Constituenta, CstType, type RSForm } from './rsform';\nimport { findCstByStructure, type FormalOrderFields, type StructureCapableFields } from './rsform-api';\n\n/** Represents a node in the structure planner. */\nexport interface SPNode {\n key: string;\n path: TypePath;\n type: Typification;\n parent: number | null;\n definition: string;\n existing: Constituenta | null;\n}\n\n/** Structure planner for {@link Constituenta}. */\nexport class StructurePlanner {\n private items: SPNode[] = [];\n private schema: RSForm;\n private target: Constituenta;\n private rootType: Typification;\n\n constructor(schema: RSForm, target: Constituenta) {\n const eff = target.effectiveType;\n if (eff == null) {\n throw new Error('Invalid typification for target');\n }\n this.schema = schema;\n this.target = target;\n if (target.cst_type === CstType.FUNCTION && !isTypification(eff)) {\n this.rootType = (eff as EchelonFunctional).result;\n } else if (isTypification(eff)) {\n this.rootType = eff as Typification;\n } else {\n throw new Error('Invalid typification for target');\n }\n }\n\n public build(): SPNode[] {\n this.items.push({\n key: 'root',\n path: makeTypePath([]),\n type: this.rootType,\n parent: null,\n definition: labelType(this.target.effectiveType),\n existing: this.target\n });\n this.visit(this.rootType, this.rootType.typeID === TypeID.collection ? [0] : [], 0);\n return this.items;\n }\n\n private visit(type: Typification, path: number[], parent: number) {\n switch (type.typeID) {\n case TypeID.collection:\n if (type.base.typeID === TypeID.tuple) {\n type.base.factors.forEach((factor, index) => {\n const nextPath = [...path, index + 1];\n const nextType = bool(factor);\n const nextNode = this.pushNode(nextPath, nextType, parent);\n this.visit(nextType, nextPath, nextNode);\n });\n } else if (type.base.typeID === TypeID.collection) {\n const nextPath = [...path, 0];\n const nextNode = this.pushNode(nextPath, type.base, parent);\n this.visit(type.base, nextPath, nextNode);\n }\n return;\n case TypeID.tuple:\n type.factors.forEach((factor, index) => {\n const nextPath = [...path, index + 1];\n const nextNode = this.pushNode(nextPath, factor, parent);\n this.visit(factor, nextPath, nextNode);\n });\n return;\n default:\n return;\n }\n }\n\n private pushNode(path: number[], type: Typification, parent: number) {\n const typePath = makeTypePath(path);\n this.items.push({\n key: formatPathText(typePath),\n path: typePath,\n type: type,\n parent: parent,\n definition: produceDefinition(this.target, this.rootType, typePath),\n existing: findCstByStructure(this.schema, this.target, typePath)\n });\n return this.items.length - 1;\n }\n}\n\n// ======= Internals =======\nfunction produceDefinition(\n target: FormalOrderFields & StructureCapableFields,\n rootType: Typification,\n path: TypePath\n): string {\n let current = rootType;\n let expression = target.alias;\n let index = rootType.typeID === TypeID.collection ? 1 : 0;\n let prefix = '';\n if (target.cst_type === CstType.FUNCTION) {\n prefix = `[${splitTemplateDefinition(target.definition_formal).head}] `;\n const funcType =\n target.effectiveType && !isTypification(target.effectiveType)\n ? (target.effectiveType as EchelonFunctional)\n : null;\n if (funcType) {\n expression = `${expression}[${funcType.args.map(arg => arg.alias).join(', ')}]`;\n }\n }\n\n while (index < path.length) {\n const step = path[index];\n switch (current.typeID) {\n case TypeID.collection:\n if (current.base.typeID === TypeID.tuple) {\n expression = `Pr${step}(${expression})`;\n current = bool(current.base.factors[step - 1]);\n index += 1;\n } else {\n expression = `red(${expression})`;\n current = current.base;\n index += 1;\n }\n break;\n case TypeID.tuple:\n expression = `pr${step}(${expression})`;\n current = current.factors[step - 1];\n index += 1;\n break;\n default:\n return prefix + expression;\n }\n }\n\n return prefix + expression;\n}\n\nfunction formatPathText(path: TypePath): string {\n return path.map(step => String(step)).join('.');\n}\n"],"mappings":";;;;;;;;AAmBA,IAAa,mBAAb,MAA8B;CAC5B,QAA0B,CAAC;CAC3B;CACA;CACA;CAEA,YAAY,QAAgB,QAAsB;EAChD,MAAM,MAAM,OAAO;EACnB,IAAI,OAAO,MACT,MAAM,IAAI,MAAM,iCAAiC;EAEnD,KAAK,SAAS;EACd,KAAK,SAAS;EACd,IAAI,OAAO,aAAa,QAAQ,YAAY,CAAC,eAAe,GAAG,GAC7D,KAAK,WAAY,IAA0B;OACtC,IAAI,eAAe,GAAG,GAC3B,KAAK,WAAW;OAEhB,MAAM,IAAI,MAAM,iCAAiC;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
4
  //#endregion
6
5
  export { parser as t };
7
- //# sourceMappingURL=parser-Bwd8LxJ1.d.ts.map
6
+ //# sourceMappingURL=parser-DkejtiOR.d.ts.map
@@ -1,2 +1,2 @@
1
- import { a as TOKEN_ERROR, c as flattenAst, d as printAst, f as visitAstDFS, i as FlatAstNode, l as getNodeIndices, n as AstNodeBase, o as buildTree, r as FlatAST, s as findByUid, t as AstNode, u as getNodeText } from "../ast-C8sIpKdL.js";
1
+ import { a as TOKEN_ERROR, c as flattenAst, d as printAst, f as visitAstDFS, i as FlatAstNode, l as getNodeIndices, n as AstNodeBase, o as buildTree, r as FlatAST, s as findByUid, t as AstNode, u as getNodeText } from "../ast-D-D6Rq3T.js";
2
2
  export { AstNode, AstNodeBase, FlatAST, FlatAstNode, TOKEN_ERROR, buildTree, findByUid, flattenAst, getNodeIndices, getNodeText, printAst, visitAstDFS };
@@ -1,3 +1,4 @@
1
- import { r as printTree, t as CMSyntaxNode } from "../lezer-tree-iS7LpLBJ.js";
2
- import { a as TOKEN_ERROR, c as flattenAst, d as printAst, f as visitAstDFS, i as FlatAstNode, l as getNodeIndices, n as AstNodeBase, o as buildTree, r as FlatAST, s as findByUid, t as AstNode, u as getNodeText } from "../ast-C8sIpKdL.js";
1
+ import { r as printTree, t as CMSyntaxNode } from "../lezer-tree-BQZqBT5A.js";
2
+ import { a as TOKEN_ERROR, c as flattenAst, d as printAst, f as visitAstDFS, i as FlatAstNode, l as getNodeIndices, n as AstNodeBase, o as buildTree, r as FlatAST, s as findByUid, t as AstNode, u as getNodeText } from "../ast-D-D6Rq3T.js";
3
+ import "../index-D5RahF1K.js";
3
4
  export { type AstNode, type AstNodeBase, type CMSyntaxNode, type FlatAST, type FlatAstNode, TOKEN_ERROR, buildTree, findByUid, flattenAst, getNodeIndices, getNodeText, printAst, printTree, visitAstDFS };
@@ -1,2 +1,2 @@
1
- import { n as TreeCursor, r as printTree, t as CMSyntaxNode } from "../lezer-tree-iS7LpLBJ.js";
1
+ import { n as TreeCursor, r as printTree, t as CMSyntaxNode } from "../lezer-tree-BQZqBT5A.js";
2
2
  export { CMSyntaxNode, type TreeCursor, printTree };
@@ -1,3 +1,3 @@
1
- import { t as generateExpressionFromAst } from "../expression-generator-CoucLIkE.js";
2
- import { a as extractGlobals, c as isSimpleExpression, d as substituteLocalAliases, f as substituteTemplateArgs, i as extractArguments, l as parseRSLangExpression, n as applyAliasMapping, o as isGlobalAlias, r as applyTypificationMapping, s as isSetTypification, t as AliasMapping, u as splitTemplateDefinition } from "../api-Bf0f_uiI.js";
1
+ import { t as generateExpressionFromAst } from "../expression-generator-CADzBw-C.js";
2
+ import { a as extractGlobals, c as isSimpleExpression, d as substituteLocalAliases, f as substituteTemplateArgs, i as extractArguments, l as parseRSLangExpression, n as applyAliasMapping, o as isGlobalAlias, r as applyTypificationMapping, s as isSetTypification, t as AliasMapping, u as splitTemplateDefinition } from "../api-DgecYHjR.js";
3
3
  export { AliasMapping, applyAliasMapping, applyTypificationMapping, extractArguments, extractGlobals, generateExpressionFromAst, isGlobalAlias, isSetTypification, isSimpleExpression, parseRSLangExpression, splitTemplateDefinition, substituteLocalAliases, substituteTemplateArgs };
@@ -1,2 +1,2 @@
1
- import { i as readTypeAnnotation, n as annotateType, r as readErrorAnnotation, t as annotateError } from "../ast-annotations-CiIx8qBM.js";
1
+ import { i as readTypeAnnotation, n as annotateType, r as readErrorAnnotation, t as annotateError } from "../ast-annotations-x4PJ_Lhc.js";
2
2
  export { annotateError, annotateType, readErrorAnnotation, readTypeAnnotation };
@@ -1,2 +1,2 @@
1
- import { n as CalculatorResult, r as RSCalculator, t as CalculatorEvaluateOptions } from "../../calculator-DE89LtIM.js";
1
+ import { n as CalculatorResult, r as RSCalculator, t as CalculatorEvaluateOptions } from "../../calculator-uPaTV3hc.js";
2
2
  export { CalculatorEvaluateOptions, CalculatorResult, RSCalculator };
@@ -1,6 +1,6 @@
1
- import { t as AstNode } from "../../ast-C8sIpKdL.js";
2
- import { l as Value } from "../../value-BduA_ZGp.js";
3
-
1
+ import { t as AstNode } from "../../ast-D-D6Rq3T.js";
2
+ import "../../index-D5RahF1K.js";
3
+ import { l as Value } from "../../value-XpJOVzMP.js";
4
4
  //#region src/rslang/eval/evaluation-cache.d.ts
5
5
  /** Static metadata for one AST node. */
6
6
  interface EvalNodeInfo {
@@ -1,7 +1,7 @@
1
- import { t as AstNode } from "../../ast-C8sIpKdL.js";
1
+ import { t as AstNode } from "../../ast-D-D6Rq3T.js";
2
+ import "../../index-D5RahF1K.js";
2
3
  import { t as ErrorReporter } from "../../error-B0EkIx4K.js";
3
- import { l as Value, u as ValueContext } from "../../value-BduA_ZGp.js";
4
-
4
+ import { l as Value, u as ValueContext } from "../../value-XpJOVzMP.js";
5
5
  //#region src/rslang/eval/evaluator.d.ts
6
6
  /** AST context. */
7
7
  type ASTContext = Map<string, AstNode>;
@@ -1,2 +1,2 @@
1
- import { _ as setSymDiff, a as extractValue, b as validateValue, c as isTupleValue, d as printValue, f as projection, g as setNestedValue, h as setIntersection, i as convertPathToType, l as makeDefaultValue, m as setDiff, n as cartesianProduct, o as isSetValue, p as reduce, r as contains, s as isSubsetOrEq, t as boolean, u as normalizeValue, v as setUnion, x as valueStub, y as testInvalid } from "../../value-api-CXLl_zg0.js";
1
+ import { _ as setSymDiff, a as extractValue, b as validateValue, c as isTupleValue, d as printValue, f as projection, g as setNestedValue, h as setIntersection, i as convertPathToType, l as makeDefaultValue, m as setDiff, n as cartesianProduct, o as isSetValue, p as reduce, r as contains, s as isSubsetOrEq, t as boolean, u as normalizeValue, v as setUnion, x as valueStub, y as testInvalid } from "../../value-api-Dw8UkwCD.js";
2
2
  export { boolean, cartesianProduct, contains, convertPathToType, extractValue, isSetValue, isSubsetOrEq, isTupleValue, makeDefaultValue, normalizeValue, printValue, projection, reduce, setDiff, setIntersection, setNestedValue, setSymDiff, setUnion, testInvalid, validateValue, valueStub };