mindoodb 0.3.3 → 0.3.4

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 (124) hide show
  1. package/dist/browser/index.mjs +6 -0
  2. package/dist/core/BaseMindooTenantDirectory.d.ts +10 -0
  3. package/dist/core/BaseMindooTenantDirectory.d.ts.map +1 -1
  4. package/dist/core/BaseMindooTenantDirectory.js +81 -3
  5. package/dist/core/BaseMindooTenantDirectory.js.map +1 -1
  6. package/dist/core/accesscontrol/directoryProjection.d.ts.map +1 -1
  7. package/dist/core/accesscontrol/directoryProjection.js +1 -0
  8. package/dist/core/accesscontrol/directoryProjection.js.map +1 -1
  9. package/dist/core/accesscontrol/types.d.ts +11 -2
  10. package/dist/core/accesscontrol/types.d.ts.map +1 -1
  11. package/dist/core/accesscontrol/types.js +3 -0
  12. package/dist/core/accesscontrol/types.js.map +1 -1
  13. package/dist/core/appendonlystores/network/AuthenticationService.d.ts +1 -0
  14. package/dist/core/appendonlystores/network/AuthenticationService.d.ts.map +1 -1
  15. package/dist/core/appendonlystores/network/AuthenticationService.js +1 -1
  16. package/dist/core/appendonlystores/network/AuthenticationService.js.map +1 -1
  17. package/dist/core/appendonlystores/network/types.d.ts +2 -0
  18. package/dist/core/appendonlystores/network/types.d.ts.map +1 -1
  19. package/dist/core/appendonlystores/network/types.js.map +1 -1
  20. package/dist/core/appendonlystores/rpc/SqlRpc.d.ts +8 -1
  21. package/dist/core/appendonlystores/rpc/SqlRpc.d.ts.map +1 -1
  22. package/dist/core/appendonlystores/rpc/SqlRpc.js +17 -0
  23. package/dist/core/appendonlystores/rpc/SqlRpc.js.map +1 -1
  24. package/dist/core/appendonlystores/sqlite/SqliteDriver.d.ts +6 -0
  25. package/dist/core/appendonlystores/sqlite/SqliteDriver.d.ts.map +1 -1
  26. package/dist/core/appendonlystores/sqlite/SqliteDriver.js.map +1 -1
  27. package/dist/core/builtinDbInvariants.d.ts +2 -1
  28. package/dist/core/builtinDbInvariants.d.ts.map +1 -1
  29. package/dist/core/builtinDbInvariants.js +2 -1
  30. package/dist/core/builtinDbInvariants.js.map +1 -1
  31. package/dist/core/guestAdmissions.d.ts +31 -2
  32. package/dist/core/guestAdmissions.d.ts.map +1 -1
  33. package/dist/core/guestAdmissions.js +26 -3
  34. package/dist/core/guestAdmissions.js.map +1 -1
  35. package/dist/core/guestTickets.d.ts +13 -0
  36. package/dist/core/guestTickets.d.ts.map +1 -1
  37. package/dist/core/guestTickets.js +16 -1
  38. package/dist/core/guestTickets.js.map +1 -1
  39. package/dist/core/index.d.ts +3 -3
  40. package/dist/core/index.d.ts.map +1 -1
  41. package/dist/core/index.js +9 -3
  42. package/dist/core/index.js.map +1 -1
  43. package/dist/core/indexing/summary/SummaryVirtualViewDataProvider.d.ts +19 -0
  44. package/dist/core/indexing/summary/SummaryVirtualViewDataProvider.d.ts.map +1 -1
  45. package/dist/core/indexing/summary/SummaryVirtualViewDataProvider.js +149 -52
  46. package/dist/core/indexing/summary/SummaryVirtualViewDataProvider.js.map +1 -1
  47. package/dist/core/indexing/virtualviews/IViewEntryAccessCheck.d.ts +8 -7
  48. package/dist/core/indexing/virtualviews/IViewEntryAccessCheck.d.ts.map +1 -1
  49. package/dist/core/indexing/virtualviews/IViewEntryAccessCheck.js +3 -3
  50. package/dist/core/indexing/virtualviews/IViewEntryAccessCheck.js.map +1 -1
  51. package/dist/core/indexing/virtualviews/MindooDBVirtualViewDataProvider.d.ts +9 -0
  52. package/dist/core/indexing/virtualviews/MindooDBVirtualViewDataProvider.d.ts.map +1 -1
  53. package/dist/core/indexing/virtualviews/MindooDBVirtualViewDataProvider.js +20 -3
  54. package/dist/core/indexing/virtualviews/MindooDBVirtualViewDataProvider.js.map +1 -1
  55. package/dist/core/indexing/virtualviews/ViewEntry.d.ts +48 -0
  56. package/dist/core/indexing/virtualviews/ViewEntry.d.ts.map +1 -0
  57. package/dist/core/indexing/virtualviews/ViewEntry.js +3 -0
  58. package/dist/core/indexing/virtualviews/ViewEntry.js.map +1 -0
  59. package/dist/core/indexing/virtualviews/ViewEntrySortKeyComparator.d.ts.map +1 -1
  60. package/dist/core/indexing/virtualviews/ViewEntrySortKeyComparator.js +6 -6
  61. package/dist/core/indexing/virtualviews/ViewEntrySortKeyComparator.js.map +1 -1
  62. package/dist/core/indexing/virtualviews/ViewNavigator.d.ts +58 -0
  63. package/dist/core/indexing/virtualviews/ViewNavigator.d.ts.map +1 -0
  64. package/dist/core/indexing/virtualviews/ViewNavigator.js +3 -0
  65. package/dist/core/indexing/virtualviews/ViewNavigator.js.map +1 -0
  66. package/dist/core/indexing/virtualviews/VirtualView.d.ts +38 -0
  67. package/dist/core/indexing/virtualviews/VirtualView.d.ts.map +1 -1
  68. package/dist/core/indexing/virtualviews/VirtualView.js +150 -0
  69. package/dist/core/indexing/virtualviews/VirtualView.js.map +1 -1
  70. package/dist/core/indexing/virtualviews/VirtualViewDataChange.d.ts +6 -0
  71. package/dist/core/indexing/virtualviews/VirtualViewDataChange.d.ts.map +1 -1
  72. package/dist/core/indexing/virtualviews/VirtualViewDataChange.js +8 -1
  73. package/dist/core/indexing/virtualviews/VirtualViewDataChange.js.map +1 -1
  74. package/dist/core/indexing/virtualviews/VirtualViewEntryData.d.ts +4 -1
  75. package/dist/core/indexing/virtualviews/VirtualViewEntryData.d.ts.map +1 -1
  76. package/dist/core/indexing/virtualviews/VirtualViewEntryData.js +14 -0
  77. package/dist/core/indexing/virtualviews/VirtualViewEntryData.js.map +1 -1
  78. package/dist/core/indexing/virtualviews/VirtualViewFactory.d.ts +9 -1
  79. package/dist/core/indexing/virtualviews/VirtualViewFactory.d.ts.map +1 -1
  80. package/dist/core/indexing/virtualviews/VirtualViewFactory.js +25 -0
  81. package/dist/core/indexing/virtualviews/VirtualViewFactory.js.map +1 -1
  82. package/dist/core/indexing/virtualviews/VirtualViewMergedNavigator.d.ts +19 -17
  83. package/dist/core/indexing/virtualviews/VirtualViewMergedNavigator.d.ts.map +1 -1
  84. package/dist/core/indexing/virtualviews/VirtualViewMergedNavigator.js +20 -17
  85. package/dist/core/indexing/virtualviews/VirtualViewMergedNavigator.js.map +1 -1
  86. package/dist/core/indexing/virtualviews/VirtualViewNavigator.d.ts +77 -301
  87. package/dist/core/indexing/virtualviews/VirtualViewNavigator.d.ts.map +1 -1
  88. package/dist/core/indexing/virtualviews/VirtualViewNavigator.js +158 -895
  89. package/dist/core/indexing/virtualviews/VirtualViewNavigator.js.map +1 -1
  90. package/dist/core/indexing/virtualviews/VirtualViewTreeCursor.d.ts +336 -0
  91. package/dist/core/indexing/virtualviews/VirtualViewTreeCursor.d.ts.map +1 -0
  92. package/dist/core/indexing/virtualviews/VirtualViewTreeCursor.js +1015 -0
  93. package/dist/core/indexing/virtualviews/VirtualViewTreeCursor.js.map +1 -0
  94. package/dist/core/indexing/virtualviews/index.d.ts +6 -0
  95. package/dist/core/indexing/virtualviews/index.d.ts.map +1 -1
  96. package/dist/core/indexing/virtualviews/index.js +10 -1
  97. package/dist/core/indexing/virtualviews/index.js.map +1 -1
  98. package/dist/core/indexing/virtualviews/sql/SqlViewIndex.d.ts +112 -0
  99. package/dist/core/indexing/virtualviews/sql/SqlViewIndex.d.ts.map +1 -0
  100. package/dist/core/indexing/virtualviews/sql/SqlViewIndex.js +364 -0
  101. package/dist/core/indexing/virtualviews/sql/SqlViewIndex.js.map +1 -0
  102. package/dist/core/indexing/virtualviews/sql/SqlViewNavigator.d.ts +250 -0
  103. package/dist/core/indexing/virtualviews/sql/SqlViewNavigator.d.ts.map +1 -0
  104. package/dist/core/indexing/virtualviews/sql/SqlViewNavigator.js +878 -0
  105. package/dist/core/indexing/virtualviews/sql/SqlViewNavigator.js.map +1 -0
  106. package/dist/core/indexing/virtualviews/viewRows.d.ts +59 -0
  107. package/dist/core/indexing/virtualviews/viewRows.d.ts.map +1 -0
  108. package/dist/core/indexing/virtualviews/viewRows.js +105 -0
  109. package/dist/core/indexing/virtualviews/viewRows.js.map +1 -0
  110. package/dist/core/indexing/virtualviews/viewSortKeys.d.ts +44 -0
  111. package/dist/core/indexing/virtualviews/viewSortKeys.d.ts.map +1 -0
  112. package/dist/core/indexing/virtualviews/viewSortKeys.js +85 -0
  113. package/dist/core/indexing/virtualviews/viewSortKeys.js.map +1 -0
  114. package/dist/core/types.d.ts +4 -0
  115. package/dist/core/types.d.ts.map +1 -1
  116. package/dist/guest/guestCall.d.ts +1 -0
  117. package/dist/guest/guestCall.d.ts.map +1 -1
  118. package/dist/guest/guestCall.js +2 -1
  119. package/dist/guest/guestCall.js.map +1 -1
  120. package/dist/server/GuestAdmissionService.d.ts +2 -1
  121. package/dist/server/GuestAdmissionService.d.ts.map +1 -1
  122. package/dist/server/GuestAdmissionService.js +4 -2
  123. package/dist/server/GuestAdmissionService.js.map +1 -1
  124. package/package.json +1 -1
@@ -0,0 +1,1015 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.VirtualViewTreeCursor = void 0;
4
+ const types_1 = require("./types");
5
+ /**
6
+ * Synchronous cursor over the in-memory view tree: the engine of
7
+ * {@link VirtualViewNavigator} for views kept in memory. Handles
8
+ * expanded/collapsed states, selection, and access control.
9
+ *
10
+ * @internal Use VirtualViewNavigator (asynchronous); this cursor only
11
+ * works on the tree in memory.
12
+ */
13
+ class VirtualViewTreeCursor {
14
+ constructor(view, topEntry, withCategories, withDocuments, accessCheck = null, dontShowEmptyCategories = false) {
15
+ /** Stack of traversal states for navigation */
16
+ this.currentEntryStack = [];
17
+ /** Selection state - if selectAll is true, this is a deselection list */
18
+ this.selectedOrDeselectedEntries = new Set();
19
+ this.selectAll = false;
20
+ /** Expansion state - if expandAllByDefault is true, this is a collapse list */
21
+ this.expandedOrCollapsedEntries = new Set();
22
+ this.expandAllByDefault = false;
23
+ this.expandLevel = 0;
24
+ this.view = view;
25
+ this.topEntry = topEntry;
26
+ this.withCategories = withCategories === types_1.WithCategories.YES;
27
+ this.withDocuments = withDocuments === types_1.WithDocuments.YES;
28
+ this.accessCheck = accessCheck;
29
+ this.dontShowEmptyCategories = dontShowEmptyCategories;
30
+ if (!this.withCategories && !this.withDocuments) {
31
+ throw new Error("Navigator must include categories, documents, or both");
32
+ }
33
+ // Initialize traversal at top entry
34
+ this.initializeTraversal();
35
+ }
36
+ initializeTraversal() {
37
+ this.currentEntryStack = [];
38
+ if (this.topEntry) {
39
+ this.currentEntryStack.push(this.createTraversalInfo(this.topEntry));
40
+ }
41
+ }
42
+ createTraversalInfo(parentEntry) {
43
+ // Always get all child entries for traversal purposes
44
+ // Filtering happens when we return entries (getCurrentEntry)
45
+ const childEntries = parentEntry.getChildEntries();
46
+ return {
47
+ parentEntry,
48
+ withCategories: this.withCategories,
49
+ withDocuments: this.withDocuments,
50
+ childEntries,
51
+ currentIndex: -1, // Before first entry
52
+ };
53
+ }
54
+ getView() {
55
+ return this.view;
56
+ }
57
+ isDontShowEmptyCategories() {
58
+ return this.dontShowEmptyCategories;
59
+ }
60
+ /**
61
+ * Set a new root for navigation (restrict to subtree)
62
+ */
63
+ setRoot(newRoot) {
64
+ this.topEntry = newRoot;
65
+ this.initializeTraversal();
66
+ return this;
67
+ }
68
+ // ===== Navigation Methods =====
69
+ /**
70
+ * Get the current entry at the cursor position
71
+ */
72
+ getCurrentEntry() {
73
+ if (this.currentEntryStack.length === 0) {
74
+ return null;
75
+ }
76
+ const info = this.currentEntryStack[this.currentEntryStack.length - 1];
77
+ if (info.currentIndex < 0 || info.currentIndex >= info.childEntries.length) {
78
+ return null;
79
+ }
80
+ const entry = info.childEntries[info.currentIndex];
81
+ // Check visibility
82
+ if (!this.isVisible(entry)) {
83
+ return null;
84
+ }
85
+ // Filter by type
86
+ if (entry.isCategory() && !this.withCategories) {
87
+ return null;
88
+ }
89
+ if (entry.isDocument() && !this.withDocuments) {
90
+ return null;
91
+ }
92
+ return entry;
93
+ }
94
+ /**
95
+ * Move to the first entry
96
+ */
97
+ gotoFirst() {
98
+ // Reset to top level
99
+ while (this.currentEntryStack.length > 1) {
100
+ this.currentEntryStack.pop();
101
+ }
102
+ const info = this.currentEntryStack[0];
103
+ if (!info || info.childEntries.length === 0) {
104
+ return false;
105
+ }
106
+ // Find first visible entry (raw visibility)
107
+ for (let i = 0; i < info.childEntries.length; i++) {
108
+ info.currentIndex = i;
109
+ if (this.isVisibleRaw(info.childEntries[i])) {
110
+ // Check if this matches our type filter
111
+ const entry = this.getCurrentEntry();
112
+ if (entry) {
113
+ return true;
114
+ }
115
+ // Entry doesn't match filter, continue to navigate into it or past it
116
+ return this.gotoNext();
117
+ }
118
+ }
119
+ return false;
120
+ }
121
+ /**
122
+ * Move to the last entry (taking expansion into account)
123
+ */
124
+ gotoLast() {
125
+ // Reset to top level
126
+ while (this.currentEntryStack.length > 1) {
127
+ this.currentEntryStack.pop();
128
+ }
129
+ const info = this.currentEntryStack[0];
130
+ if (!info || info.childEntries.length === 0) {
131
+ return false;
132
+ }
133
+ // Find last visible entry
134
+ for (let i = info.childEntries.length - 1; i >= 0; i--) {
135
+ info.currentIndex = i;
136
+ if (this.isVisible(info.childEntries[i])) {
137
+ // Navigate to deepest expanded descendant
138
+ this.gotoDeepestExpandedDescendant(info.childEntries[i]);
139
+ return true;
140
+ }
141
+ }
142
+ return false;
143
+ }
144
+ /**
145
+ * Move to the next entry (respecting expand states)
146
+ */
147
+ gotoNext() {
148
+ const currEntry = this.getCurrentEntryRaw();
149
+ if (!currEntry) {
150
+ // No current entry - try to find one by moving through the tree
151
+ if (this.gotoNextSibling()) {
152
+ // Check if this entry should be returned
153
+ const entry = this.getCurrentEntry();
154
+ if (entry)
155
+ return true;
156
+ // Keep searching
157
+ return this.gotoNext();
158
+ }
159
+ return false;
160
+ }
161
+ // If expanded and has children, go to first child
162
+ if (this.isExpanded(currEntry) && currEntry.getChildCount() > 0) {
163
+ const childInfo = this.createTraversalInfo(currEntry);
164
+ if (childInfo.childEntries.length > 0) {
165
+ childInfo.currentIndex = 0;
166
+ // Find first visible child (visibility check only, not type filter)
167
+ while (childInfo.currentIndex < childInfo.childEntries.length &&
168
+ !this.isVisibleRaw(childInfo.childEntries[childInfo.currentIndex])) {
169
+ childInfo.currentIndex++;
170
+ }
171
+ if (childInfo.currentIndex < childInfo.childEntries.length) {
172
+ this.currentEntryStack.push(childInfo);
173
+ // Check if this entry matches our filter
174
+ const entry = this.getCurrentEntry();
175
+ if (entry) {
176
+ return true;
177
+ }
178
+ // Entry doesn't match filter (e.g., it's a category but we want documents)
179
+ // Continue navigating
180
+ return this.gotoNext();
181
+ }
182
+ }
183
+ }
184
+ // Try next sibling
185
+ if (this.gotoNextSiblingRaw()) {
186
+ // Check if this entry matches our filter
187
+ const entry = this.getCurrentEntry();
188
+ if (entry) {
189
+ return true;
190
+ }
191
+ // Keep searching
192
+ return this.gotoNext();
193
+ }
194
+ // Go up and try next sibling of parent
195
+ while (this.gotoParent()) {
196
+ if (this.gotoNextSiblingRaw()) {
197
+ // Check if this entry matches our filter
198
+ const entry = this.getCurrentEntry();
199
+ if (entry) {
200
+ return true;
201
+ }
202
+ // Keep searching
203
+ return this.gotoNext();
204
+ }
205
+ }
206
+ return false;
207
+ }
208
+ /**
209
+ * Get the current entry without type filtering (for internal navigation)
210
+ */
211
+ getCurrentEntryRaw() {
212
+ if (this.currentEntryStack.length === 0) {
213
+ return null;
214
+ }
215
+ const info = this.currentEntryStack[this.currentEntryStack.length - 1];
216
+ if (info.currentIndex < 0 || info.currentIndex >= info.childEntries.length) {
217
+ return null;
218
+ }
219
+ return info.childEntries[info.currentIndex];
220
+ }
221
+ /**
222
+ * Check visibility without type filtering
223
+ */
224
+ isVisibleRaw(entry) {
225
+ // Check access control
226
+ if (this.accessCheck && !this.accessCheck.isVisible(entry)) {
227
+ return false;
228
+ }
229
+ return true;
230
+ }
231
+ /**
232
+ * Move to next sibling without checking type filter
233
+ */
234
+ gotoNextSiblingRaw() {
235
+ if (this.currentEntryStack.length === 0) {
236
+ return false;
237
+ }
238
+ const info = this.currentEntryStack[this.currentEntryStack.length - 1];
239
+ // Find next visible entry
240
+ for (let i = info.currentIndex + 1; i < info.childEntries.length; i++) {
241
+ if (this.isVisibleRaw(info.childEntries[i])) {
242
+ info.currentIndex = i;
243
+ return true;
244
+ }
245
+ }
246
+ return false;
247
+ }
248
+ /**
249
+ * Move to the previous entry (respecting expand states)
250
+ */
251
+ gotoPrev() {
252
+ const currEntry = this.getCurrentEntry();
253
+ if (!currEntry) {
254
+ return false;
255
+ }
256
+ // Try previous sibling
257
+ if (this.gotoPrevSibling()) {
258
+ // Navigate to deepest expanded descendant of prev sibling
259
+ const prevEntry = this.getCurrentEntry();
260
+ if (prevEntry) {
261
+ this.gotoDeepestExpandedDescendant(prevEntry);
262
+ }
263
+ return true;
264
+ }
265
+ // Go up to parent
266
+ return this.gotoParent();
267
+ }
268
+ /**
269
+ * Move to the next sibling
270
+ */
271
+ gotoNextSibling() {
272
+ if (this.currentEntryStack.length === 0) {
273
+ return false;
274
+ }
275
+ const info = this.currentEntryStack[this.currentEntryStack.length - 1];
276
+ // Find next visible entry
277
+ for (let i = info.currentIndex + 1; i < info.childEntries.length; i++) {
278
+ if (this.isVisible(info.childEntries[i])) {
279
+ info.currentIndex = i;
280
+ return true;
281
+ }
282
+ }
283
+ return false;
284
+ }
285
+ /**
286
+ * Move to the previous sibling
287
+ */
288
+ gotoPrevSibling() {
289
+ if (this.currentEntryStack.length === 0) {
290
+ return false;
291
+ }
292
+ const info = this.currentEntryStack[this.currentEntryStack.length - 1];
293
+ // Find previous visible entry
294
+ for (let i = info.currentIndex - 1; i >= 0; i--) {
295
+ if (this.isVisible(info.childEntries[i])) {
296
+ info.currentIndex = i;
297
+ return true;
298
+ }
299
+ }
300
+ return false;
301
+ }
302
+ /**
303
+ * Move to the parent entry
304
+ */
305
+ gotoParent() {
306
+ if (this.currentEntryStack.length > 1) {
307
+ this.currentEntryStack.pop();
308
+ return true;
309
+ }
310
+ return false;
311
+ }
312
+ /**
313
+ * Move to the first child of current entry
314
+ */
315
+ gotoFirstChild() {
316
+ const currEntry = this.getCurrentEntry();
317
+ if (!currEntry) {
318
+ return false;
319
+ }
320
+ const childInfo = this.createTraversalInfo(currEntry);
321
+ if (childInfo.childEntries.length === 0) {
322
+ return false;
323
+ }
324
+ // Find first visible child
325
+ for (let i = 0; i < childInfo.childEntries.length; i++) {
326
+ if (this.isVisible(childInfo.childEntries[i])) {
327
+ childInfo.currentIndex = i;
328
+ this.currentEntryStack.push(childInfo);
329
+ return true;
330
+ }
331
+ }
332
+ return false;
333
+ }
334
+ /**
335
+ * Move to the last child of current entry
336
+ */
337
+ gotoLastChild() {
338
+ const currEntry = this.getCurrentEntry();
339
+ if (!currEntry) {
340
+ return false;
341
+ }
342
+ const childInfo = this.createTraversalInfo(currEntry);
343
+ if (childInfo.childEntries.length === 0) {
344
+ return false;
345
+ }
346
+ // Find last visible child
347
+ for (let i = childInfo.childEntries.length - 1; i >= 0; i--) {
348
+ if (this.isVisible(childInfo.childEntries[i])) {
349
+ childInfo.currentIndex = i;
350
+ this.currentEntryStack.push(childInfo);
351
+ return true;
352
+ }
353
+ }
354
+ return false;
355
+ }
356
+ gotoDeepestExpandedDescendant(entry) {
357
+ if (entry.getChildCount() > 0 && this.isExpanded(entry)) {
358
+ const childInfo = this.createTraversalInfo(entry);
359
+ // Find last visible child
360
+ for (let i = childInfo.childEntries.length - 1; i >= 0; i--) {
361
+ if (this.isVisible(childInfo.childEntries[i])) {
362
+ childInfo.currentIndex = i;
363
+ this.currentEntryStack.push(childInfo);
364
+ this.gotoDeepestExpandedDescendant(childInfo.childEntries[i]);
365
+ return;
366
+ }
367
+ }
368
+ }
369
+ }
370
+ /**
371
+ * Move to a specific position (e.g., "1.2.3")
372
+ */
373
+ gotoPos(posStr) {
374
+ const pos = posStr.split(".").map(p => parseInt(p, 10));
375
+ return this.gotoPosArray(pos);
376
+ }
377
+ /**
378
+ * Move to a specific position array (e.g., [1, 2, 3])
379
+ */
380
+ gotoPosArray(pos) {
381
+ // Reset to top level
382
+ this.initializeTraversal();
383
+ let currentInfo = this.currentEntryStack[0];
384
+ if (!currentInfo) {
385
+ return false;
386
+ }
387
+ for (let i = 0; i < pos.length; i++) {
388
+ const targetSiblingIndex = pos[i];
389
+ // Find entry with matching sibling index
390
+ let found = false;
391
+ for (let j = 0; j < currentInfo.childEntries.length; j++) {
392
+ const entry = currentInfo.childEntries[j];
393
+ if (entry.getSiblingIndex() === targetSiblingIndex && this.isVisible(entry)) {
394
+ currentInfo.currentIndex = j;
395
+ found = true;
396
+ // If more levels to go, push new traversal info
397
+ if (i < pos.length - 1) {
398
+ const nextInfo = this.createTraversalInfo(entry);
399
+ this.currentEntryStack.push(nextInfo);
400
+ currentInfo = nextInfo;
401
+ }
402
+ break;
403
+ }
404
+ }
405
+ if (!found) {
406
+ return false;
407
+ }
408
+ }
409
+ return true;
410
+ }
411
+ /**
412
+ * Get the entry at a specific position without moving the cursor
413
+ *
414
+ * @param posStr Position string e.g. "1.2.3"
415
+ * @returns The entry at the position or null if not found
416
+ */
417
+ getPos(posStr) {
418
+ const pos = posStr.split(".").map(p => parseInt(p, 10));
419
+ return this.getPosArray(pos);
420
+ }
421
+ /**
422
+ * Get the entry at a specific position array without moving the cursor
423
+ *
424
+ * @param pos Position array e.g. [1, 2, 3]
425
+ * @returns The entry at the position or null if not found
426
+ */
427
+ getPosArray(pos) {
428
+ // Save current state
429
+ const savedStack = this.currentEntryStack.map(info => ({
430
+ ...info,
431
+ childEntries: info.childEntries,
432
+ }));
433
+ // Navigate to position
434
+ const found = this.gotoPosArray(pos);
435
+ const entry = found ? this.getCurrentEntry() : null;
436
+ // Restore state
437
+ this.currentEntryStack = savedStack;
438
+ return entry;
439
+ }
440
+ // ===== Category Finding Methods =====
441
+ /**
442
+ * Find a category entry by path string (e.g., "Category1\\Category1.1")
443
+ * Navigates through the category tree from the top entry.
444
+ *
445
+ * @param category Category path with backslash separators
446
+ * @returns The category entry or null if not found
447
+ */
448
+ findCategoryEntry(category) {
449
+ const categoryParts = category.split("\\");
450
+ return this.findCategoryEntryByParts(categoryParts);
451
+ }
452
+ /**
453
+ * Find a category entry by array of category parts
454
+ * Navigates through the category tree from the top entry.
455
+ *
456
+ * @param categoryParts Array of category values e.g. ["Category1", "Category1.1"]
457
+ * @returns The category entry or null if not found
458
+ */
459
+ findCategoryEntryByParts(categoryParts) {
460
+ let currentEntry = this.topEntry;
461
+ for (const part of categoryParts) {
462
+ if (!currentEntry) {
463
+ return null;
464
+ }
465
+ // Find matching subcategory
466
+ const matchingCategory = this.childCategoriesByKey(currentEntry, String(part), true, false)
467
+ .find(() => true); // Get first match
468
+ if (!matchingCategory) {
469
+ return null;
470
+ }
471
+ currentEntry = matchingCategory;
472
+ }
473
+ return currentEntry;
474
+ }
475
+ // ===== Iteration Methods =====
476
+ /**
477
+ * Iterate forward through entries
478
+ */
479
+ async *entriesForward(selectedOnly = types_1.SelectedOnly.NO) {
480
+ if (!this.gotoFirst()) {
481
+ return;
482
+ }
483
+ do {
484
+ const entry = this.getCurrentEntry();
485
+ if (entry) {
486
+ if (selectedOnly === types_1.SelectedOnly.NO || this.isSelected(entry.origin, entry.docId)) {
487
+ yield entry;
488
+ }
489
+ }
490
+ } while (selectedOnly === types_1.SelectedOnly.YES ? this.gotoNextSelected() : this.gotoNext());
491
+ }
492
+ /**
493
+ * Iterate forward through entries starting from a specific position
494
+ *
495
+ * @param startPos Starting position string e.g. "1.2.3"
496
+ * @param selectedOnly Whether to only yield selected entries
497
+ */
498
+ async *entriesForwardFromPosition(startPos, selectedOnly = types_1.SelectedOnly.NO) {
499
+ if (!this.gotoPos(startPos)) {
500
+ return;
501
+ }
502
+ do {
503
+ const entry = this.getCurrentEntry();
504
+ if (entry) {
505
+ if (selectedOnly === types_1.SelectedOnly.NO || this.isSelected(entry.origin, entry.docId)) {
506
+ yield entry;
507
+ }
508
+ }
509
+ } while (selectedOnly === types_1.SelectedOnly.YES ? this.gotoNextSelected() : this.gotoNext());
510
+ }
511
+ /**
512
+ * Iterate backward through entries
513
+ */
514
+ async *entriesBackward(selectedOnly = types_1.SelectedOnly.NO) {
515
+ if (!this.gotoLast()) {
516
+ return;
517
+ }
518
+ do {
519
+ const entry = this.getCurrentEntry();
520
+ if (entry) {
521
+ if (selectedOnly === types_1.SelectedOnly.NO || this.isSelected(entry.origin, entry.docId)) {
522
+ yield entry;
523
+ }
524
+ }
525
+ } while (selectedOnly === types_1.SelectedOnly.YES ? this.gotoPrevSelected() : this.gotoPrev());
526
+ }
527
+ /**
528
+ * Move to next selected entry
529
+ */
530
+ gotoNextSelected() {
531
+ while (this.gotoNext()) {
532
+ const entry = this.getCurrentEntry();
533
+ if (entry && this.isSelected(entry.origin, entry.docId)) {
534
+ return true;
535
+ }
536
+ }
537
+ return false;
538
+ }
539
+ /**
540
+ * Move to previous selected entry
541
+ */
542
+ gotoPrevSelected() {
543
+ while (this.gotoPrev()) {
544
+ const entry = this.getCurrentEntry();
545
+ if (entry && this.isSelected(entry.origin, entry.docId)) {
546
+ return true;
547
+ }
548
+ }
549
+ return false;
550
+ }
551
+ // ===== Visibility Check =====
552
+ isVisible(entry) {
553
+ // Check access control
554
+ if (this.accessCheck && !this.accessCheck.isVisible(entry)) {
555
+ return false;
556
+ }
557
+ // Check empty categories
558
+ if (this.dontShowEmptyCategories && entry.isCategory()) {
559
+ if (entry.getDescendantDocumentCount() === 0) {
560
+ return false;
561
+ }
562
+ }
563
+ return true;
564
+ }
565
+ // ===== Selection Methods =====
566
+ /**
567
+ * Select an entry
568
+ */
569
+ select(origin, docId, selectParentCategories = false) {
570
+ const key = (0, types_1.scopedDocIdKey)((0, types_1.createScopedDocId)(origin, docId));
571
+ if (this.selectAll) {
572
+ this.selectedOrDeselectedEntries.delete(key);
573
+ }
574
+ else {
575
+ this.selectedOrDeselectedEntries.add(key);
576
+ }
577
+ if (selectParentCategories) {
578
+ const entries = this.view.getEntries(origin, docId);
579
+ for (const entry of entries) {
580
+ let parent = entry.getParent();
581
+ while (parent && !parent.isRoot()) {
582
+ const parentKey = (0, types_1.scopedDocIdKey)((0, types_1.createScopedDocId)(parent.origin, parent.docId));
583
+ if (this.selectAll) {
584
+ this.selectedOrDeselectedEntries.delete(parentKey);
585
+ }
586
+ else {
587
+ this.selectedOrDeselectedEntries.add(parentKey);
588
+ }
589
+ parent = parent.getParent();
590
+ }
591
+ }
592
+ }
593
+ return this;
594
+ }
595
+ /**
596
+ * Deselect an entry
597
+ */
598
+ deselect(origin, docId) {
599
+ const key = (0, types_1.scopedDocIdKey)((0, types_1.createScopedDocId)(origin, docId));
600
+ if (this.selectAll) {
601
+ this.selectedOrDeselectedEntries.add(key);
602
+ }
603
+ else {
604
+ this.selectedOrDeselectedEntries.delete(key);
605
+ }
606
+ return this;
607
+ }
608
+ /**
609
+ * Select all entries
610
+ */
611
+ selectAllEntries() {
612
+ this.selectedOrDeselectedEntries.clear();
613
+ this.selectAll = true;
614
+ return this;
615
+ }
616
+ /**
617
+ * Deselect all entries
618
+ */
619
+ deselectAllEntries() {
620
+ this.selectedOrDeselectedEntries.clear();
621
+ this.selectAll = false;
622
+ return this;
623
+ }
624
+ /**
625
+ * Check if an entry is selected
626
+ */
627
+ isSelected(origin, docId) {
628
+ const key = (0, types_1.scopedDocIdKey)((0, types_1.createScopedDocId)(origin, docId));
629
+ if (this.selectAll) {
630
+ return !this.selectedOrDeselectedEntries.has(key);
631
+ }
632
+ else {
633
+ return this.selectedOrDeselectedEntries.has(key);
634
+ }
635
+ }
636
+ isSelectAllByDefault() {
637
+ return this.selectAll;
638
+ }
639
+ /**
640
+ * Returns whether all entries are deselected by default
641
+ */
642
+ isDeselectAllByDefault() {
643
+ return !this.selectAll;
644
+ }
645
+ // ===== Expand/Collapse Methods =====
646
+ /**
647
+ * Expand an entry
648
+ */
649
+ expand(origin, docId) {
650
+ const key = (0, types_1.scopedDocIdKey)((0, types_1.createScopedDocId)(origin, docId));
651
+ if (!this.expandAllByDefault) {
652
+ this.expandedOrCollapsedEntries.add(key);
653
+ }
654
+ else {
655
+ this.expandedOrCollapsedEntries.delete(key);
656
+ }
657
+ return this;
658
+ }
659
+ /**
660
+ * Collapse an entry
661
+ */
662
+ collapse(origin, docId) {
663
+ const key = (0, types_1.scopedDocIdKey)((0, types_1.createScopedDocId)(origin, docId));
664
+ if (this.expandAllByDefault) {
665
+ this.expandedOrCollapsedEntries.add(key);
666
+ }
667
+ else {
668
+ this.expandedOrCollapsedEntries.delete(key);
669
+ }
670
+ return this;
671
+ }
672
+ /**
673
+ * Expand by position string
674
+ */
675
+ expandPos(posStr) {
676
+ const entry = this.getEntryAtPos(posStr);
677
+ if (entry) {
678
+ this.expand(entry.origin, entry.docId);
679
+ }
680
+ return this;
681
+ }
682
+ /**
683
+ * Collapse by position string
684
+ */
685
+ collapsePos(posStr) {
686
+ const entry = this.getEntryAtPos(posStr);
687
+ if (entry) {
688
+ this.collapse(entry.origin, entry.docId);
689
+ }
690
+ return this;
691
+ }
692
+ /**
693
+ * Expand by position array
694
+ *
695
+ * @param pos Position array e.g. [1, 2, 3]
696
+ */
697
+ expandPosArray(pos) {
698
+ const entry = this.getPosArray(pos);
699
+ if (entry) {
700
+ this.expand(entry.origin, entry.docId);
701
+ }
702
+ return this;
703
+ }
704
+ /**
705
+ * Collapse by position array
706
+ *
707
+ * @param pos Position array e.g. [1, 2, 3]
708
+ */
709
+ collapsePosArray(pos) {
710
+ const entry = this.getPosArray(pos);
711
+ if (entry) {
712
+ this.collapse(entry.origin, entry.docId);
713
+ }
714
+ return this;
715
+ }
716
+ getEntryAtPos(posStr) {
717
+ // Save current position
718
+ const savedStack = [...this.currentEntryStack];
719
+ const found = this.gotoPos(posStr);
720
+ const entry = found ? this.getCurrentEntry() : null;
721
+ // Restore position
722
+ this.currentEntryStack = savedStack;
723
+ return entry;
724
+ }
725
+ /**
726
+ * Collapse all entries
727
+ */
728
+ collapseAll() {
729
+ this.expandedOrCollapsedEntries.clear();
730
+ this.expandAllByDefault = false;
731
+ return this;
732
+ }
733
+ /**
734
+ * Expand all entries
735
+ */
736
+ expandAll() {
737
+ this.expandedOrCollapsedEntries.clear();
738
+ this.expandAllByDefault = true;
739
+ return this;
740
+ }
741
+ /**
742
+ * Expand entries up to a specific level
743
+ */
744
+ expandToLevel(level) {
745
+ this.expandLevel = level;
746
+ return this;
747
+ }
748
+ /**
749
+ * Check if an entry is expanded
750
+ */
751
+ isExpanded(entry) {
752
+ // Root is always expanded
753
+ if (entry.isRoot()) {
754
+ return true;
755
+ }
756
+ // Check level-based expansion
757
+ if (this.expandLevel > 0 && entry.getLevel() <= this.expandLevel) {
758
+ return true;
759
+ }
760
+ return this.isExpandedByDocId(entry.origin, entry.docId);
761
+ }
762
+ /**
763
+ * Check if an entry is expanded by origin and docId
764
+ * Does not check expandLevel - only checks the expand/collapse state
765
+ *
766
+ * @param origin Origin of the entry
767
+ * @param docId Document ID of the entry
768
+ * @returns true if expanded
769
+ */
770
+ isExpandedByDocId(origin, docId) {
771
+ const key = (0, types_1.scopedDocIdKey)((0, types_1.createScopedDocId)(origin, docId));
772
+ // Check if this is the root
773
+ const root = this.view.getRoot();
774
+ if (root.docId === docId && root.origin === origin) {
775
+ return true;
776
+ }
777
+ if (this.expandAllByDefault) {
778
+ return !this.expandedOrCollapsedEntries.has(key);
779
+ }
780
+ else {
781
+ return this.expandedOrCollapsedEntries.has(key);
782
+ }
783
+ }
784
+ isExpandAllByDefault() {
785
+ return this.expandAllByDefault;
786
+ }
787
+ isCollapseAllByDefault() {
788
+ return !this.expandAllByDefault;
789
+ }
790
+ getExpandLevel() {
791
+ return this.expandLevel;
792
+ }
793
+ // ===== State Getters/Setters =====
794
+ getSelectedOrDeselectedEntries() {
795
+ return new Set(this.selectedOrDeselectedEntries);
796
+ }
797
+ setSelectedOrDeselectedEntries(entries) {
798
+ this.selectedOrDeselectedEntries = new Set(entries);
799
+ return this;
800
+ }
801
+ getExpandedOrCollapsedEntries() {
802
+ return new Set(this.expandedOrCollapsedEntries);
803
+ }
804
+ setExpandedOrCollapsedEntries(entries) {
805
+ this.expandedOrCollapsedEntries = new Set(entries);
806
+ return this;
807
+ }
808
+ // ===== Child Entry Methods =====
809
+ /**
810
+ * Get child documents of an entry
811
+ */
812
+ childDocuments(entry, descending = false) {
813
+ const docs = entry.getChildDocuments();
814
+ const filtered = docs.filter(e => this.isVisible(e));
815
+ return descending ? filtered.reverse() : filtered;
816
+ }
817
+ /**
818
+ * Get child categories of an entry
819
+ */
820
+ childCategories(entry, descending = false) {
821
+ const cats = entry.getChildCategories();
822
+ const filtered = cats.filter(e => this.isVisible(e));
823
+ return descending ? filtered.reverse() : filtered;
824
+ }
825
+ /**
826
+ * Get all child entries of an entry
827
+ */
828
+ childEntries(entry, descending = false) {
829
+ const entries = entry.getChildEntries();
830
+ const filtered = entries.filter(e => this.isVisible(e));
831
+ return descending ? filtered.reverse() : filtered;
832
+ }
833
+ // ===== Range/Key-based Child Queries =====
834
+ /**
835
+ * Get child documents within a key range (inclusive)
836
+ *
837
+ * @param entry Parent entry
838
+ * @param startKey Start key value
839
+ * @param endKey End key value
840
+ * @param descending Whether to return in descending order
841
+ * @returns Filtered child documents within the range
842
+ */
843
+ childDocumentsBetween(entry, startKey, endKey, descending = false) {
844
+ const docs = entry.getChildDocuments();
845
+ const filtered = docs.filter(e => {
846
+ if (!this.isVisible(e))
847
+ return false;
848
+ const sortKey = e.getSortKey();
849
+ const firstValue = sortKey.values.length > 0 ? sortKey.values[0] : null;
850
+ // Check if value is within range
851
+ const afterStart = (0, types_1.compareValues)(firstValue, startKey, false) >= 0;
852
+ const beforeEnd = (0, types_1.compareValues)(firstValue, endKey, false) <= 0;
853
+ return afterStart && beforeEnd;
854
+ });
855
+ return descending ? filtered.reverse() : filtered;
856
+ }
857
+ /**
858
+ * Get child documents by key (exact or prefix match)
859
+ *
860
+ * @param entry Parent entry
861
+ * @param key Key value to search for
862
+ * @param isExact Whether to match exactly or by prefix
863
+ * @param descending Whether to return in descending order
864
+ * @returns Matching child documents
865
+ */
866
+ childDocumentsByKey(entry, key, isExact, descending = false) {
867
+ if (isExact) {
868
+ return this.childDocumentsBetween(entry, key, key, descending);
869
+ }
870
+ // Prefix match - use key to key + max char
871
+ const endKey = key + String.fromCharCode(0xFFFF);
872
+ return this.childDocumentsBetween(entry, key, endKey, descending);
873
+ }
874
+ /**
875
+ * Get child categories within a key range (inclusive)
876
+ *
877
+ * @param entry Parent entry
878
+ * @param startKey Start key value
879
+ * @param endKey End key value
880
+ * @param descending Whether to return in descending order
881
+ * @returns Filtered child categories within the range
882
+ */
883
+ childCategoriesBetween(entry, startKey, endKey, descending = false) {
884
+ const cats = entry.getChildCategories();
885
+ const filtered = cats.filter(e => {
886
+ if (!this.isVisible(e))
887
+ return false;
888
+ const catValue = e.getCategoryValue();
889
+ // Check if value is within range
890
+ const afterStart = (0, types_1.compareValues)(catValue, startKey, false) >= 0;
891
+ const beforeEnd = (0, types_1.compareValues)(catValue, endKey, false) <= 0;
892
+ return afterStart && beforeEnd;
893
+ });
894
+ return descending ? filtered.reverse() : filtered;
895
+ }
896
+ /**
897
+ * Get child categories by key (exact or prefix match)
898
+ *
899
+ * @param entry Parent entry
900
+ * @param key Key value to search for
901
+ * @param isExact Whether to match exactly or by prefix
902
+ * @param descending Whether to return in descending order
903
+ * @returns Matching child categories
904
+ */
905
+ childCategoriesByKey(entry, key, isExact, descending = false) {
906
+ if (isExact) {
907
+ return this.childCategoriesBetween(entry, key, key, descending);
908
+ }
909
+ // Prefix match - use key to key + max char
910
+ const endKey = key + String.fromCharCode(0xFFFF);
911
+ return this.childCategoriesBetween(entry, key, endKey, descending);
912
+ }
913
+ // ===== Sorted Entry Lookup =====
914
+ /**
915
+ * Compare two position arrays for sorting
916
+ */
917
+ static comparePositions(pos1, pos2) {
918
+ const len = Math.min(pos1.length, pos2.length);
919
+ for (let i = 0; i < len; i++) {
920
+ if (pos1[i] !== pos2[i]) {
921
+ return pos1[i] - pos2[i];
922
+ }
923
+ }
924
+ return pos1.length - pos2.length;
925
+ }
926
+ /** Sort entries by tree position, computing each position once. */
927
+ static sortByPosition(entries) {
928
+ return entries
929
+ .map((entry) => ({ entry, position: entry.getPosition() }))
930
+ .sort((a, b) => VirtualViewTreeCursor.comparePositions(a.position, b.position))
931
+ .map(({ entry }) => entry);
932
+ }
933
+ /**
934
+ * Get all occurrences of a document in the view, sorted by position
935
+ *
936
+ * @param origin Origin of the document
937
+ * @param docId Document ID
938
+ * @returns Array of entries sorted by position
939
+ */
940
+ getSortedEntries(origin, docId) {
941
+ const entries = this.view.getEntries(origin, docId);
942
+ return VirtualViewTreeCursor.sortByPosition(entries.filter(e => this.isVisible(e)));
943
+ }
944
+ /**
945
+ * Get all occurrences of multiple documents in the view, sorted by position
946
+ *
947
+ * @param origin Origin of the documents
948
+ * @param docIds Set of document IDs
949
+ * @returns Array of entries sorted by position
950
+ */
951
+ getSortedEntriesMultiple(origin, docIds) {
952
+ const allEntries = [];
953
+ for (const docId of docIds) {
954
+ const entries = this.view.getEntries(origin, docId);
955
+ allEntries.push(...entries);
956
+ }
957
+ return VirtualViewTreeCursor.sortByPosition(allEntries.filter(e => this.isVisible(e)));
958
+ }
959
+ /**
960
+ * Get all occurrences of scoped document IDs in the view, sorted by position
961
+ *
962
+ * @param scopedDocIds Set of scoped document IDs (origin + docId)
963
+ * @returns Array of entries sorted by position
964
+ */
965
+ getSortedEntriesScoped(scopedDocIds) {
966
+ const allEntries = [];
967
+ for (const scopedId of scopedDocIds) {
968
+ const entries = this.view.getEntries(scopedId.origin, scopedId.docId);
969
+ allEntries.push(...entries);
970
+ }
971
+ return VirtualViewTreeCursor.sortByPosition(allEntries.filter(e => this.isVisible(e)));
972
+ }
973
+ /**
974
+ * Get document IDs sorted by their position in the view
975
+ *
976
+ * @param origin Origin of the documents
977
+ * @param docIds Set of document IDs
978
+ * @returns Array of document IDs sorted by their position in the view
979
+ */
980
+ getSortedDocIds(origin, docIds) {
981
+ const sortedEntries = this.getSortedEntriesMultiple(origin, docIds);
982
+ // Use a Set to track seen docIds and maintain order
983
+ const seen = new Set();
984
+ const result = [];
985
+ for (const entry of sortedEntries) {
986
+ if (!seen.has(entry.docId)) {
987
+ seen.add(entry.docId);
988
+ result.push(entry.docId);
989
+ }
990
+ }
991
+ return result;
992
+ }
993
+ /**
994
+ * Get scoped document IDs sorted by their position in the view
995
+ *
996
+ * @param scopedDocIds Set of scoped document IDs
997
+ * @returns Array of scoped document IDs sorted by their position in the view
998
+ */
999
+ getSortedDocIdsScoped(scopedDocIds) {
1000
+ const sortedEntries = this.getSortedEntriesScoped(scopedDocIds);
1001
+ // Use a Set to track seen docIds and maintain order
1002
+ const seen = new Set();
1003
+ const result = [];
1004
+ for (const entry of sortedEntries) {
1005
+ const key = (0, types_1.scopedDocIdKey)({ origin: entry.origin, docId: entry.docId });
1006
+ if (!seen.has(key)) {
1007
+ seen.add(key);
1008
+ result.push({ origin: entry.origin, docId: entry.docId });
1009
+ }
1010
+ }
1011
+ return result;
1012
+ }
1013
+ }
1014
+ exports.VirtualViewTreeCursor = VirtualViewTreeCursor;
1015
+ //# sourceMappingURL=VirtualViewTreeCursor.js.map