@xnetjs/data 0.0.2 → 0.0.3

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 (137) hide show
  1. package/README.md +112 -0
  2. package/dist/account-BZHETMC4.js +12 -0
  3. package/dist/auth/index.d.ts +413 -0
  4. package/dist/auth/index.js +102 -0
  5. package/dist/budget-WR2Q4YH3.js +12 -0
  6. package/dist/canvas-HFMMVQLD.js +10 -0
  7. package/dist/channel-DXDYJ3ZH.js +12 -0
  8. package/dist/chat-message-QUUQGXEW.js +10 -0
  9. package/dist/chunk-2DSDH2ZH.js +52 -0
  10. package/dist/chunk-337E3ZOB.js +54 -0
  11. package/dist/chunk-37267RSF.js +41 -0
  12. package/dist/chunk-3JKW6TDE.js +66 -0
  13. package/dist/chunk-3RB2FMMO.js +148 -0
  14. package/dist/{chunk-BQBPA5HS.js → chunk-4U4KBCDN.js} +16 -2
  15. package/dist/chunk-4UQTURCD.js +722 -0
  16. package/dist/chunk-54Y7QRZN.js +109 -0
  17. package/dist/chunk-5FHJE7RC.js +46 -0
  18. package/dist/chunk-64AM6JPM.js +40 -0
  19. package/dist/chunk-6CN53PON.js +143 -0
  20. package/dist/chunk-6GB7PBCR.js +40 -0
  21. package/dist/chunk-6OPZJ7MG.js +78 -0
  22. package/dist/{chunk-IDMBCRUC.js → chunk-77UDLVQY.js} +1 -1
  23. package/dist/chunk-7GMJOAPF.js +52 -0
  24. package/dist/chunk-7PDRDSFH.js +69 -0
  25. package/dist/chunk-C5IRSEEZ.js +69 -0
  26. package/dist/chunk-CHZUSBSB.js +45 -0
  27. package/dist/chunk-DOZJXPQ6.js +232 -0
  28. package/dist/chunk-DTPSTMUD.js +105 -0
  29. package/dist/chunk-E6S557NC.js +402 -0
  30. package/dist/chunk-EIQX7INF.js +45 -0
  31. package/dist/chunk-ENTHVNOC.js +57 -0
  32. package/dist/chunk-EZA5UT4Y.js +5543 -0
  33. package/dist/chunk-GR3NDMBY.js +76 -0
  34. package/dist/chunk-GWYVY2K4.js +63 -0
  35. package/dist/chunk-IJ675GJR.js +42 -0
  36. package/dist/chunk-IP4BEVVD.js +57 -0
  37. package/dist/chunk-J4IVJA5M.js +102 -0
  38. package/dist/chunk-J6EDPPH4.js +84 -0
  39. package/dist/{chunk-SZC345Z2.js → chunk-JESSJ5CZ.js} +1015 -1110
  40. package/dist/chunk-JO6Y4E5V.js +73 -0
  41. package/dist/chunk-KPVBKKZS.js +47 -0
  42. package/dist/chunk-KTJLFJEQ.js +43 -0
  43. package/dist/chunk-L66WXPTW.js +32 -0
  44. package/dist/chunk-LGD72FVD.js +48 -0
  45. package/dist/chunk-O64EK5FK.js +887 -0
  46. package/dist/chunk-PMUQACPY.js +33 -0
  47. package/dist/chunk-PSUJEKVV.js +1722 -0
  48. package/dist/chunk-QVZXXJSP.js +6122 -0
  49. package/dist/chunk-QWFTRZQT.js +142 -0
  50. package/dist/chunk-RSSZXCLL.js +51 -0
  51. package/dist/chunk-S4B5OPZU.js +415 -0
  52. package/dist/{chunk-VYR5GPJP.js → chunk-SPFKSTPT.js} +9 -3
  53. package/dist/chunk-U6CBYDVZ.js +50 -0
  54. package/dist/chunk-UDUPQKRB.js +49 -0
  55. package/dist/chunk-V6HZ3LF3.js +380 -0
  56. package/dist/chunk-WMSCEBFH.js +64 -0
  57. package/dist/chunk-WUR3WWQM.js +65 -0
  58. package/dist/chunk-XHEA5UER.js +75 -0
  59. package/dist/chunk-XTUGZSYQ.js +75 -0
  60. package/dist/chunk-XWA3CJQ6.js +45 -0
  61. package/dist/chunk-YEQ6LLUY.js +49 -0
  62. package/dist/chunk-YWN27MLD.js +47 -0
  63. package/dist/chunk-YXZGYLKV.js +65 -0
  64. package/dist/chunk-ZICIXDEE.js +54 -0
  65. package/dist/chunk-ZMCO3O2Z.js +70 -0
  66. package/dist/clone-DpbVKLUu.d.ts +2205 -0
  67. package/dist/comment-Y2Y3QYYI.js +10 -0
  68. package/dist/crm-AAJXYIJY.js +68 -0
  69. package/dist/dashboard-3DC6B4BJ.js +10 -0
  70. package/dist/database/index.d.ts +882 -0
  71. package/dist/database/index.js +523 -0
  72. package/dist/database-DRGL5UYS.js +10 -0
  73. package/dist/database-field-F47FY3XX.js +10 -0
  74. package/dist/database-row-77OXW2NF.js +10 -0
  75. package/dist/database-select-option-6S3TTA7A.js +10 -0
  76. package/dist/database-view-YW7DQG5X.js +10 -0
  77. package/dist/experiment-TJOAL3OH.js +10 -0
  78. package/dist/external-item-D654PKLI.js +14 -0
  79. package/dist/external-reference-K5SUJIQN.js +8 -0
  80. package/dist/feed-L23XTNDI.js +12 -0
  81. package/dist/feed-item-GSO242J6.js +12 -0
  82. package/dist/folder-ONKSWHUT.js +21 -0
  83. package/dist/game-BF7DP5JU.js +50 -0
  84. package/dist/grant-NNKMWXPX.js +8 -0
  85. package/dist/grant-expiration-cleaner-DBiNTWbD.d.ts +249 -0
  86. package/dist/import-batch-JMESZ4VI.js +12 -0
  87. package/dist/inbox-state-AN6FPCIY.js +12 -0
  88. package/dist/index.d.ts +224 -4548
  89. package/dist/index.js +2206 -4754
  90. package/dist/map-AUV65YS3.js +10 -0
  91. package/dist/media-asset-4I5YPR4R.js +8 -0
  92. package/dist/memory-NV6EVJBE.js +12 -0
  93. package/dist/metric-X7W55DLC.js +10 -0
  94. package/dist/milestone-JJGOGK4R.js +12 -0
  95. package/dist/moderation-QSUVBCNS.js +30 -0
  96. package/dist/observation-UZSXXGBC.js +10 -0
  97. package/dist/page-NI7XODS6.js +10 -0
  98. package/dist/posting-FZOYVGH2.js +12 -0
  99. package/dist/profile-42A43GES.js +8 -0
  100. package/dist/project-G2CTLDXY.js +10 -0
  101. package/dist/query-ast-CWo6_30h.d.ts +226 -0
  102. package/dist/reaction-VAQBVDUD.js +10 -0
  103. package/dist/registry-CQoN_p8U.d.ts +99 -0
  104. package/dist/saved-view-AOQHGHNM.js +10 -0
  105. package/dist/schema/index.d.ts +6182 -0
  106. package/dist/schema/index.js +631 -0
  107. package/dist/schema-extension-5BUXRDPB.js +18 -0
  108. package/dist/space-PZ737CIS.js +42 -0
  109. package/dist/space-membership-N35NRX6F.js +14 -0
  110. package/dist/store/index.d.ts +391 -0
  111. package/dist/store/index.js +135 -0
  112. package/dist/store-CvgiydME.d.ts +338 -0
  113. package/dist/sync/awareness.d.ts +69 -0
  114. package/dist/sync/awareness.js +20 -0
  115. package/dist/system-Q5I6STDC.js +38 -0
  116. package/dist/tag-C677GKQW.js +16 -0
  117. package/dist/task-WQLMPN5U.js +16 -0
  118. package/dist/task-view-T5S32V4L.js +10 -0
  119. package/dist/transaction-U3ITRGJP.js +12 -0
  120. package/dist/transcription-F3T23LLO.js +12 -0
  121. package/dist/types-Def-5Nka.d.ts +1525 -0
  122. package/dist/updates.d.ts +44 -0
  123. package/dist/updates.js +16 -0
  124. package/dist/user-widget-4SJJFPG5.js +8 -0
  125. package/dist/view-types-DSde-uT_.d.ts +316 -0
  126. package/package.json +32 -9
  127. package/dist/canvas-HSIKIQFK.js +0 -7
  128. package/dist/chunk-2L5ZUGG5.js +0 -53
  129. package/dist/chunk-4MTS5KAQ.js +0 -22
  130. package/dist/chunk-GZHARFKC.js +0 -25
  131. package/dist/chunk-WKIKJTI2.js +0 -45
  132. package/dist/comment-277JD7DV.js +0 -7
  133. package/dist/database-W3KEHLI3.js +0 -7
  134. package/dist/database-row-3O2QSNZN.js +0 -7
  135. package/dist/grant-QVZ454YC.js +0 -7
  136. package/dist/page-O4WTOIEO.js +0 -7
  137. package/dist/task-SEKAYJH7.js +0 -7
@@ -0,0 +1,45 @@
1
+ import {
2
+ spaceCascadeAuthorization
3
+ } from "./chunk-6OPZJ7MG.js";
4
+ import {
5
+ created,
6
+ createdBy,
7
+ defineSchema,
8
+ person,
9
+ relation,
10
+ select,
11
+ text
12
+ } from "./chunk-O64EK5FK.js";
13
+
14
+ // src/schema/schemas/reaction.ts
15
+ var reactionTypes = [
16
+ { id: "like", name: "Like", color: "green" },
17
+ { id: "repost", name: "Repost", color: "blue" },
18
+ { id: "bookmark", name: "Bookmark", color: "purple" },
19
+ { id: "emoji", name: "Emoji", color: "yellow" }
20
+ ];
21
+ var ReactionSchema = defineSchema({
22
+ name: "Reaction",
23
+ namespace: "xnet://xnet.fyi/",
24
+ properties: {
25
+ target: relation({ required: true }),
26
+ targetSchema: text({}),
27
+ reactionType: select({
28
+ options: reactionTypes,
29
+ required: true,
30
+ default: "like"
31
+ }),
32
+ reactor: person({ required: true }),
33
+ emoji: text({ maxLength: 32 }),
34
+ annotation: text({ maxLength: 1e3 }),
35
+ createdAt: created(),
36
+ createdBy: createdBy()
37
+ },
38
+ document: void 0,
39
+ // Inherits access from its home Space (exploration 0181/0192).
40
+ authorization: spaceCascadeAuthorization("target")
41
+ });
42
+
43
+ export {
44
+ ReactionSchema
45
+ };
@@ -0,0 +1,232 @@
1
+ import {
2
+ spaceCascadeAuthorization
3
+ } from "./chunk-6OPZJ7MG.js";
4
+ import {
5
+ date,
6
+ defineSchema,
7
+ file,
8
+ json,
9
+ money,
10
+ number,
11
+ relation,
12
+ select,
13
+ text
14
+ } from "./chunk-O64EK5FK.js";
15
+
16
+ // src/schema/schemas/game.ts
17
+ var GAME_NAMESPACE = "xnet://xnet.fyi/";
18
+ var PLAYER_IDENTITY_SCHEMA_IRI = "xnet://xnet.fyi/PlayerIdentity@1.0.0";
19
+ var INVENTORY_SCHEMA_IRI = "xnet://xnet.fyi/Inventory@1.0.0";
20
+ var GAME_ITEM_SCHEMA_IRI = "xnet://xnet.fyi/GameItem@1.0.0";
21
+ var ACHIEVEMENT_SCHEMA_IRI = "xnet://xnet.fyi/Achievement@1.0.0";
22
+ var MATCH_SESSION_SCHEMA_IRI = "xnet://xnet.fyi/MatchSession@1.0.0";
23
+ var GAME_ECONOMY_ENTRY_SCHEMA_IRI = "xnet://xnet.fyi/GameEconomyEntry@1.0.0";
24
+ var GAME_ASSET_SCHEMA_IRI = "xnet://xnet.fyi/GameAsset@1.0.0";
25
+ var SPACE_TARGET = "xnet://xnet.fyi/Space@1.0.0";
26
+ var GAME_ASSET_MIME_TYPES = [
27
+ "model/gltf-binary",
28
+ // .glb
29
+ "model/gltf+json",
30
+ // .gltf
31
+ "model/vnd.usdz+zip",
32
+ // .usdz
33
+ "model/vnd.usd",
34
+ // .usd
35
+ "model/vnd.usda"
36
+ // .usda
37
+ ];
38
+ var VISIBILITY_OPTIONS = [
39
+ { id: "inherit", name: "Inherit", color: "gray" },
40
+ { id: "private", name: "Private", color: "gray" },
41
+ { id: "unlisted", name: "Unlisted", color: "yellow" },
42
+ { id: "public", name: "Public", color: "green" }
43
+ ];
44
+ var visibility = () => select({ options: VISIBILITY_OPTIONS, default: "inherit" });
45
+ var space = () => relation({ target: SPACE_TARGET });
46
+ var PlayerIdentitySchema = defineSchema({
47
+ name: "PlayerIdentity",
48
+ namespace: GAME_NAMESPACE,
49
+ properties: {
50
+ /** Display / gamer name. */
51
+ displayName: text({ required: true, maxLength: 200 }),
52
+ /** The player's own XNet `did:key` — the portable login across publishers. */
53
+ did: text({ maxLength: 512 }),
54
+ /** Avatar asset (glTF/USD), stored by reference. */
55
+ avatarAsset: file({ accept: [...GAME_ASSET_MIME_TYPES] }),
56
+ /** The title this identity is "homed" in (origin game). */
57
+ homeGame: text({ maxLength: 200 }),
58
+ /** Short bio / status the player chooses to surface in-game. */
59
+ bio: text({ maxLength: 2e3 }),
60
+ space: space(),
61
+ visibility: visibility()
62
+ },
63
+ document: void 0,
64
+ authorization: spaceCascadeAuthorization()
65
+ });
66
+ var ITEM_RARITIES = [
67
+ { id: "common", name: "Common", color: "gray" },
68
+ { id: "uncommon", name: "Uncommon", color: "green" },
69
+ { id: "rare", name: "Rare", color: "blue" },
70
+ { id: "epic", name: "Epic", color: "purple" },
71
+ { id: "legendary", name: "Legendary", color: "orange" }
72
+ ];
73
+ var GameItemSchema = defineSchema({
74
+ name: "GameItem",
75
+ namespace: GAME_NAMESPACE,
76
+ properties: {
77
+ name: text({ required: true, maxLength: 300 }),
78
+ rarity: select({ options: ITEM_RARITIES, default: "common" }),
79
+ /** The title that minted the item (provenance for cross-game portability). */
80
+ sourceGame: text({ maxLength: 200 }),
81
+ /** Visual/3D asset (glTF/USD), by reference. */
82
+ asset: file({ accept: [...GAME_ASSET_MIME_TYPES] }),
83
+ /** Stack count for fungible items. */
84
+ quantity: number({ integer: true, min: 0 }),
85
+ /** Opaque, engine-interpreted attribute bag (stats, sockets, bindings). */
86
+ attributes: json({}),
87
+ space: space(),
88
+ visibility: visibility()
89
+ },
90
+ document: void 0,
91
+ authorization: spaceCascadeAuthorization()
92
+ });
93
+ var InventorySchema = defineSchema({
94
+ name: "Inventory",
95
+ namespace: GAME_NAMESPACE,
96
+ properties: {
97
+ /** Whose inventory this is. */
98
+ owner: relation({ target: PLAYER_IDENTITY_SCHEMA_IRI }),
99
+ label: text({ maxLength: 200 }),
100
+ /** Held items. */
101
+ items: relation({ target: GAME_ITEM_SCHEMA_IRI, multiple: true }),
102
+ space: space(),
103
+ visibility: visibility()
104
+ },
105
+ document: void 0,
106
+ authorization: spaceCascadeAuthorization()
107
+ });
108
+ var AchievementSchema = defineSchema({
109
+ name: "Achievement",
110
+ namespace: GAME_NAMESPACE,
111
+ properties: {
112
+ name: text({ required: true, maxLength: 300 }),
113
+ description: text({ maxLength: 2e3 }),
114
+ player: relation({ target: PLAYER_IDENTITY_SCHEMA_IRI }),
115
+ game: text({ maxLength: 200 }),
116
+ unlockedAt: date({}),
117
+ /** Gamerscore-style point value. */
118
+ points: number({ integer: true, min: 0 }),
119
+ space: space(),
120
+ visibility: visibility()
121
+ },
122
+ document: void 0,
123
+ authorization: spaceCascadeAuthorization()
124
+ });
125
+ var MATCH_RESULTS = [
126
+ { id: "win", name: "Win", color: "green" },
127
+ { id: "loss", name: "Loss", color: "red" },
128
+ { id: "draw", name: "Draw", color: "gray" },
129
+ { id: "incomplete", name: "Incomplete", color: "yellow" }
130
+ ];
131
+ var MatchSessionSchema = defineSchema({
132
+ name: "MatchSession",
133
+ namespace: GAME_NAMESPACE,
134
+ properties: {
135
+ game: text({ required: true, maxLength: 200 }),
136
+ player: relation({ target: PLAYER_IDENTITY_SCHEMA_IRI }),
137
+ result: select({ options: MATCH_RESULTS }),
138
+ score: number({}),
139
+ startedAt: date({}),
140
+ endedAt: date({}),
141
+ /** Opaque per-match stat bag (mode, map, kills, etc.). */
142
+ stats: json({}),
143
+ space: space(),
144
+ visibility: visibility()
145
+ },
146
+ document: void 0,
147
+ authorization: spaceCascadeAuthorization()
148
+ });
149
+ var GameEconomyEntrySchema = defineSchema({
150
+ name: "GameEconomyEntry",
151
+ namespace: GAME_NAMESPACE,
152
+ properties: {
153
+ player: relation({ target: PLAYER_IDENTITY_SCHEMA_IRI }),
154
+ /** Currency code / soft-currency name (e.g. `V-Bucks`, `gold`). */
155
+ currency: text({ required: true, maxLength: 60 }),
156
+ /** Signed amount, integer minor units — reconciles via `@xnetjs/ledger`. */
157
+ amount: money({ required: true }),
158
+ /** What caused the entry (purchase, reward, trade). */
159
+ reason: text({ maxLength: 500 }),
160
+ game: text({ maxLength: 200 }),
161
+ occurredAt: date({}),
162
+ space: space(),
163
+ visibility: visibility()
164
+ },
165
+ document: void 0,
166
+ authorization: spaceCascadeAuthorization()
167
+ });
168
+ var GAME_ASSET_FORMATS = [
169
+ { id: "glb", name: "glTF (binary)" },
170
+ { id: "gltf", name: "glTF (JSON)" },
171
+ { id: "usd", name: "OpenUSD" },
172
+ { id: "usdz", name: "USDZ" },
173
+ { id: "other", name: "Other" }
174
+ ];
175
+ var GameAssetSchema = defineSchema({
176
+ name: "GameAsset",
177
+ namespace: GAME_NAMESPACE,
178
+ properties: {
179
+ title: text({ required: true, maxLength: 300 }),
180
+ /** The asset payload, by reference (CID) — never parsed by XNet. */
181
+ file: file({ required: true, accept: [...GAME_ASSET_MIME_TYPES] }),
182
+ format: select({ options: GAME_ASSET_FORMATS, default: "glb" }),
183
+ sourceGame: text({ maxLength: 200 }),
184
+ description: text({ maxLength: 2e3 }),
185
+ space: space(),
186
+ visibility: visibility()
187
+ },
188
+ document: void 0,
189
+ authorization: spaceCascadeAuthorization()
190
+ });
191
+ var GAME_SCHEMA_IRIS = [
192
+ PLAYER_IDENTITY_SCHEMA_IRI,
193
+ INVENTORY_SCHEMA_IRI,
194
+ GAME_ITEM_SCHEMA_IRI,
195
+ ACHIEVEMENT_SCHEMA_IRI,
196
+ MATCH_SESSION_SCHEMA_IRI,
197
+ GAME_ECONOMY_ENTRY_SCHEMA_IRI,
198
+ GAME_ASSET_SCHEMA_IRI
199
+ ];
200
+ var gameSchemas = [
201
+ PlayerIdentitySchema,
202
+ GameItemSchema,
203
+ InventorySchema,
204
+ AchievementSchema,
205
+ MatchSessionSchema,
206
+ GameEconomyEntrySchema,
207
+ GameAssetSchema
208
+ ];
209
+
210
+ export {
211
+ GAME_NAMESPACE,
212
+ PLAYER_IDENTITY_SCHEMA_IRI,
213
+ INVENTORY_SCHEMA_IRI,
214
+ GAME_ITEM_SCHEMA_IRI,
215
+ ACHIEVEMENT_SCHEMA_IRI,
216
+ MATCH_SESSION_SCHEMA_IRI,
217
+ GAME_ECONOMY_ENTRY_SCHEMA_IRI,
218
+ GAME_ASSET_SCHEMA_IRI,
219
+ GAME_ASSET_MIME_TYPES,
220
+ PlayerIdentitySchema,
221
+ ITEM_RARITIES,
222
+ GameItemSchema,
223
+ InventorySchema,
224
+ AchievementSchema,
225
+ MATCH_RESULTS,
226
+ MatchSessionSchema,
227
+ GameEconomyEntrySchema,
228
+ GAME_ASSET_FORMATS,
229
+ GameAssetSchema,
230
+ GAME_SCHEMA_IRIS,
231
+ gameSchemas
232
+ };
@@ -0,0 +1,105 @@
1
+ import {
2
+ compareSortKeys
3
+ } from "./chunk-QWFTRZQT.js";
4
+ import {
5
+ created,
6
+ createdBy,
7
+ defineSchema,
8
+ relation,
9
+ text
10
+ } from "./chunk-O64EK5FK.js";
11
+ import {
12
+ presets
13
+ } from "./chunk-JESSJ5CZ.js";
14
+
15
+ // src/schema/schemas/folder.ts
16
+ var FOLDER_SCHEMA_IRI = "xnet://xnet.fyi/Folder@1.0.0";
17
+ var FolderSchema = defineSchema({
18
+ name: "Folder",
19
+ namespace: "xnet://xnet.fyi/",
20
+ properties: {
21
+ /** Folder display name */
22
+ name: text({ required: true, maxLength: 120 }),
23
+ /** Emoji or icon URL */
24
+ icon: text({ maxLength: 80 }),
25
+ /** Parent folder; empty = top level */
26
+ parent: relation({ target: "xnet://xnet.fyi/Folder@1.0.0" }),
27
+ /** Order among siblings — fractional index, code-unit compare */
28
+ sortKey: text({ maxLength: 500 }),
29
+ createdAt: created(),
30
+ createdBy: createdBy()
31
+ },
32
+ document: void 0,
33
+ // Standalone/personal content: owner-only by default (exploration 0192).
34
+ authorization: presets.private()
35
+ });
36
+ function compareSiblings(a, b) {
37
+ const bySortKey = compareSortKeys(a.sortKey ?? "", b.sortKey ?? "");
38
+ if (bySortKey !== 0) return bySortKey;
39
+ return a.name === b.name ? 0 : (a.name ?? "") < (b.name ?? "") ? -1 : 1;
40
+ }
41
+ function buildFolderTree(folders) {
42
+ const byId = new Map(folders.map((folder) => [folder.id, folder]));
43
+ const childrenOf = /* @__PURE__ */ new Map();
44
+ const roots = [];
45
+ for (const folder of folders) {
46
+ const parentId = folder.parent ?? null;
47
+ if (!parentId || parentId === folder.id || !byId.has(parentId)) {
48
+ roots.push(folder);
49
+ continue;
50
+ }
51
+ const siblings = childrenOf.get(parentId);
52
+ if (siblings) siblings.push(folder);
53
+ else childrenOf.set(parentId, [folder]);
54
+ }
55
+ const attached = /* @__PURE__ */ new Set();
56
+ const toNode = (folder, depth) => {
57
+ attached.add(folder.id);
58
+ const children = (childrenOf.get(folder.id) ?? []).filter((child) => !attached.has(child.id)).sort(compareSiblings).map((child) => toNode(child, depth + 1));
59
+ return { folder, depth, children };
60
+ };
61
+ const tree = roots.sort(compareSiblings).map((folder) => toNode(folder, 0));
62
+ const stranded = folders.filter((folder) => !attached.has(folder.id)).sort(compareSiblings);
63
+ for (const folder of stranded) {
64
+ if (!attached.has(folder.id)) tree.push(toNode(folder, 0));
65
+ }
66
+ return tree;
67
+ }
68
+ function flattenFolderTree(tree, isExpanded = () => true) {
69
+ const rows = [];
70
+ const visit = (node) => {
71
+ rows.push(node);
72
+ if (isExpanded(node.folder.id)) node.children.forEach(visit);
73
+ };
74
+ tree.forEach(visit);
75
+ return rows;
76
+ }
77
+ function folderAncestorIds(folderId, byId) {
78
+ const ancestors = [];
79
+ const seen = /* @__PURE__ */ new Set([folderId]);
80
+ let current = byId.get(folderId)?.parent ?? null;
81
+ while (current && !seen.has(current)) {
82
+ ancestors.push(current);
83
+ seen.add(current);
84
+ current = byId.get(current)?.parent ?? null;
85
+ }
86
+ return ancestors;
87
+ }
88
+ function wouldCreateFolderCycle(folderId, newParentId, byId) {
89
+ if (!newParentId) return false;
90
+ if (newParentId === folderId) return true;
91
+ return folderAncestorIds(newParentId, byId).includes(folderId);
92
+ }
93
+ function folderPathIds(folderId, byId) {
94
+ return [...folderAncestorIds(folderId, byId).reverse(), folderId];
95
+ }
96
+
97
+ export {
98
+ FOLDER_SCHEMA_IRI,
99
+ FolderSchema,
100
+ buildFolderTree,
101
+ flattenFolderTree,
102
+ folderAncestorIds,
103
+ wouldCreateFolderCycle,
104
+ folderPathIds
105
+ };