@arken/node 1.5.0 → 1.5.2

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 (160) hide show
  1. package/build/modules/character/character.service.js.map +1 -1
  2. package/build/modules/chat/chat.service.js.map +1 -1
  3. package/build/modules/core/core.models.js.map +1 -1
  4. package/build/modules/core/core.service.js.map +1 -1
  5. package/build/modules/profile/profile.service.js.map +1 -1
  6. package/build/package.json +2 -2
  7. package/build/tsconfig.tsbuildinfo +1 -1
  8. package/build/types.d.ts +1 -0
  9. package/build/types.js +1 -0
  10. package/build/types.js.map +1 -1
  11. package/build/util/mongo.js.map +1 -1
  12. package/db.ts +76 -1
  13. package/index.ts +351 -18
  14. package/{util/mongo.ts → mongo.ts} +2 -0
  15. package/package.json +3 -3
  16. package/tsconfig.json +33 -2
  17. package/types.ts +2 -0
  18. package/util.ts +1 -0
  19. package/modules/area/area.models.ts +0 -15
  20. package/modules/area/area.router.ts +0 -74
  21. package/modules/area/area.schema.ts +0 -22
  22. package/modules/area/area.service.ts +0 -124
  23. package/modules/area/area.types.ts +0 -26
  24. package/modules/area/index.ts +0 -5
  25. package/modules/asset/asset.models.ts +0 -59
  26. package/modules/asset/asset.router.ts +0 -55
  27. package/modules/asset/asset.schema.ts +0 -27
  28. package/modules/asset/asset.service.ts +0 -85
  29. package/modules/asset/asset.types.ts +0 -22
  30. package/modules/asset/index.ts +0 -5
  31. package/modules/chain/chain.models.ts +0 -50
  32. package/modules/chain/chain.router.ts +0 -104
  33. package/modules/chain/chain.schema.ts +0 -52
  34. package/modules/chain/chain.service.ts +0 -167
  35. package/modules/chain/chain.types.ts +0 -24
  36. package/modules/chain/index.ts +0 -5
  37. package/modules/character/character.models.ts +0 -174
  38. package/modules/character/character.router.ts +0 -314
  39. package/modules/character/character.schema.ts +0 -147
  40. package/modules/character/character.service.ts +0 -875
  41. package/modules/character/character.types.ts +0 -64
  42. package/modules/character/index.ts +0 -5
  43. package/modules/chat/chat.models.ts +0 -43
  44. package/modules/chat/chat.router.ts +0 -67
  45. package/modules/chat/chat.schema.ts +0 -36
  46. package/modules/chat/chat.service.ts +0 -120
  47. package/modules/chat/chat.types.ts +0 -20
  48. package/modules/chat/index.ts +0 -5
  49. package/modules/collection/collection.models.ts +0 -76
  50. package/modules/collection/collection.router.ts +0 -91
  51. package/modules/collection/collection.schema.ts +0 -90
  52. package/modules/collection/collection.service.ts +0 -192
  53. package/modules/collection/collection.types.ts +0 -36
  54. package/modules/collection/index.ts +0 -5
  55. package/modules/core/core.models.ts +0 -1379
  56. package/modules/core/core.router.ts +0 -1781
  57. package/modules/core/core.schema.ts +0 -847
  58. package/modules/core/core.service.ts +0 -2822
  59. package/modules/core/core.types.ts +0 -340
  60. package/modules/core/index.ts +0 -5
  61. package/modules/core/mail/applyPatchesOrMail.ts +0 -568
  62. package/modules/core/mail/mailClaimablePatchesBatch.ts +0 -381
  63. package/modules/game/game.models.ts +0 -53
  64. package/modules/game/game.router.ts +0 -110
  65. package/modules/game/game.schema.ts +0 -23
  66. package/modules/game/game.service.ts +0 -143
  67. package/modules/game/game.types.ts +0 -28
  68. package/modules/game/index.ts +0 -5
  69. package/modules/interface/index.ts +0 -5
  70. package/modules/interface/interface.canonicalize.ts +0 -279
  71. package/modules/interface/interface.models.ts +0 -40
  72. package/modules/interface/interface.router.ts +0 -175
  73. package/modules/interface/interface.schema.ts +0 -59
  74. package/modules/interface/interface.service.ts +0 -356
  75. package/modules/interface/interface.types.ts +0 -25
  76. package/modules/item/index.ts +0 -5
  77. package/modules/item/item.models.ts +0 -124
  78. package/modules/item/item.router.ts +0 -103
  79. package/modules/item/item.schema.ts +0 -120
  80. package/modules/item/item.service.ts +0 -167
  81. package/modules/item/item.types.ts +0 -74
  82. package/modules/job/index.ts +0 -5
  83. package/modules/job/job.models.ts +0 -14
  84. package/modules/job/job.router.ts +0 -44
  85. package/modules/job/job.schema.ts +0 -9
  86. package/modules/job/job.service.ts +0 -243
  87. package/modules/job/job.types.ts +0 -23
  88. package/modules/market/index.ts +0 -5
  89. package/modules/market/market.models.ts +0 -113
  90. package/modules/market/market.router.ts +0 -73
  91. package/modules/market/market.schema.ts +0 -140
  92. package/modules/market/market.service.ts +0 -122
  93. package/modules/market/market.types.ts +0 -56
  94. package/modules/product/index.ts +0 -5
  95. package/modules/product/product.models.ts +0 -166
  96. package/modules/product/product.router.ts +0 -93
  97. package/modules/product/product.schema.ts +0 -149
  98. package/modules/product/product.service.ts +0 -160
  99. package/modules/product/product.types.ts +0 -33
  100. package/modules/profile/index.ts +0 -5
  101. package/modules/profile/profile.models.ts +0 -214
  102. package/modules/profile/profile.router.ts +0 -72
  103. package/modules/profile/profile.schema.ts +0 -156
  104. package/modules/profile/profile.service.ts +0 -147
  105. package/modules/profile/profile.types.ts +0 -22
  106. package/modules/raffle/index.ts +0 -5
  107. package/modules/raffle/raffle.models.ts +0 -44
  108. package/modules/raffle/raffle.router.ts +0 -90
  109. package/modules/raffle/raffle.schema.ts +0 -32
  110. package/modules/raffle/raffle.service.ts +0 -167
  111. package/modules/raffle/raffle.types.ts +0 -30
  112. package/modules/skill/index.ts +0 -5
  113. package/modules/skill/skill.models.ts +0 -16
  114. package/modules/skill/skill.router.ts +0 -201
  115. package/modules/skill/skill.schema.ts +0 -40
  116. package/modules/skill/skill.service.ts +0 -390
  117. package/modules/skill/skill.types.ts +0 -33
  118. package/modules/video/index.ts +0 -5
  119. package/modules/video/video.models.ts +0 -25
  120. package/modules/video/video.router.ts +0 -143
  121. package/modules/video/video.schema.ts +0 -46
  122. package/modules/video/video.service.ts +0 -274
  123. package/modules/video/video.types.ts +0 -33
  124. package/util/db/index.ts +0 -7
  125. package/util/db/isPostgresError.ts +0 -9
  126. package/util/db/isUniqueConstraintViolation.ts +0 -3
  127. package/util/db.ts +0 -62
  128. package/util/index.ts +0 -351
  129. /package/{util/api.ts → api.ts} +0 -0
  130. /package/{util/array.ts → array.ts} +0 -0
  131. /package/{util/browser.ts → browser.ts} +0 -0
  132. /package/{util/codebase.ts → codebase.ts} +0 -0
  133. /package/{util/config.ts → config.ts} +0 -0
  134. /package/{util/decoder.test.ts → decoder.test.ts} +0 -0
  135. /package/{util/decoder.ts → decoder.ts} +0 -0
  136. /package/{util/format.ts → format.ts} +0 -0
  137. /package/{util/guid.ts → guid.ts} +0 -0
  138. /package/{util/json.ts → json.ts} +0 -0
  139. /package/{util/log.ts → log.ts} +0 -0
  140. /package/{util/math.ts → math.ts} +0 -0
  141. /package/{util/merkle.ts → merkle.ts} +0 -0
  142. /package/{util/number.ts → number.ts} +0 -0
  143. /package/{util/object.ts → object.ts} +0 -0
  144. /package/{util/otp.ts → otp.ts} +0 -0
  145. /package/{util/physics.ts → physics.ts} +0 -0
  146. /package/{util/process.ts → process.ts} +0 -0
  147. /package/{util/rpc.ts → rpc.ts} +0 -0
  148. /package/{util/seer.ts → seer.ts} +0 -0
  149. /package/{util/string.ts → string.ts} +0 -0
  150. /package/{util/text.ts → text.ts} +0 -0
  151. /package/{util/time → time}/date.ts +0 -0
  152. /package/{util/time → time}/fancyTimeFormat.ts +0 -0
  153. /package/{util/time → time}/index.ts +0 -0
  154. /package/{util/time → time}/now.ts +0 -0
  155. /package/{util/types → types}/mongo.d.ts +0 -0
  156. /package/{util/web3 → web3}/httpProvider.ts +0 -0
  157. /package/{util/web3.ts → web3.ts} +0 -0
  158. /package/{util/websocket.ts → websocket.ts} +0 -0
  159. /package/{util/zk.ts → zk.ts} +0 -0
  160. /package/{util/zod.ts → zod.ts} +0 -0
@@ -1,1379 +0,0 @@
1
- // node/modules/core/core.models.ts
2
-
3
- import * as mongo from '../../util/mongo';
4
- import type * as Types from './core.types';
5
-
6
- const { createModel, addTagVirtuals, addApplicationVirtual } = mongo;
7
-
8
- // MerkleTree Model
9
- export const MerkleTree = createModel<Types.MerkleTreeDocument>(
10
- 'MerkleTree',
11
- {
12
- root: { type: String, required: true, default: '0x' + '0'.repeat(64) },
13
- depth: { type: Number, required: true, default: 16 }, // log2(#leaves)
14
- },
15
- {
16
- // extend: 'CommonFields',
17
- virtuals: [...addTagVirtuals('MerkleTree'), ...addApplicationVirtual()],
18
- }
19
- );
20
-
21
- // MerkleNode Model
22
- export const MerkleNode = createModel<Types.MerkleNodeDocument>(
23
- 'MerkleNode',
24
- {
25
- treeId: { type: mongo.Schema.Types.ObjectId, ref: 'MerkleTree', required: true },
26
- level: { type: Number, required: true }, // 0 = leaves
27
- index: { type: Number, required: true }, // position in level
28
- hash: { type: String, required: true },
29
- },
30
- {
31
- // extend: 'CommonFields',
32
- indexes: [{ treeId: 1, level: 1, index: 1 }],
33
- virtuals: [...addTagVirtuals('MerkleNode'), ...addApplicationVirtual()],
34
- }
35
- );
36
-
37
- // Omniverse Model
38
- export const Omniverse = createModel<Types.OmniverseDocument>(
39
- 'Omniverse',
40
- {
41
- ratingId: { type: mongo.Schema.Types.ObjectId, ref: 'Rating' },
42
- },
43
- {
44
- extend: 'CommonFields',
45
- virtuals: [...addTagVirtuals('Omniverse'), ...addApplicationVirtual()],
46
- }
47
- );
48
-
49
- // Metaverse Model
50
- export const Metaverse = createModel<Types.MetaverseDocument>(
51
- 'Metaverse',
52
- {
53
- omniverseId: { type: mongo.Schema.Types.ObjectId, ref: 'Omniverse', required: true },
54
- ratingId: { type: mongo.Schema.Types.ObjectId, ref: 'Rating' },
55
- },
56
- {
57
- extend: 'CommonFields',
58
- virtuals: [...addTagVirtuals('Metaverse'), ...addApplicationVirtual()],
59
- }
60
- );
61
-
62
- // Application Model
63
- export const Application = createModel<Types.ApplicationDocument>(
64
- 'Application',
65
- {
66
- ownerId: { type: mongo.Schema.Types.ObjectId, ref: 'Account' },
67
- metaverseId: { type: mongo.Schema.Types.ObjectId, ref: 'Metaverse' },
68
- name: { type: String, required: true },
69
- description: { type: String },
70
- },
71
- {
72
- extend: 'CommonFields',
73
- indexes: [{ metaverseId: 1, name: 1, unique: true }],
74
- virtuals: [
75
- ...addTagVirtuals('Application'),
76
- { name: 'agents', ref: 'Agent', localField: '_id', foreignField: 'applicationId' },
77
- { name: 'chain' },
78
- { name: 'account' },
79
- { name: 'assets' },
80
- { name: 'badges' },
81
- { name: 'battlePasses' },
82
- { name: 'collections' },
83
- { name: 'communities' },
84
- { name: 'discussions' },
85
- { name: 'events' },
86
- { name: 'exchanges' },
87
- { name: 'files' },
88
- { name: 'ideas' },
89
- { name: 'leaderboards' },
90
- { name: 'assetLicenses' },
91
- { name: 'logs' },
92
- { name: 'marketPairs' },
93
- { name: 'markets' },
94
- { name: 'messages' },
95
- { name: 'offers' },
96
- { name: 'orders' },
97
- { name: 'products' },
98
- { name: 'projects' },
99
- { name: 'ratings' },
100
- { name: 'realms' },
101
- { name: 'reviews' },
102
- { name: 'roles' },
103
- { name: 'realmShards' },
104
- { name: 'suggestions' },
105
- { name: 'tags' },
106
- { name: 'tokens' },
107
- { name: 'tradeIdeas' },
108
- { name: 'trades' },
109
- { name: 'buyerTrades' },
110
- { name: 'transactions' },
111
- { name: 'votes' },
112
- { name: 'payments' },
113
- { name: 'permissions' },
114
- { name: 'stats' },
115
- { name: 'revisions' },
116
- { name: 'comments' },
117
- { name: 'interfaces' },
118
- { name: 'characters' },
119
- { name: 'metaverses' },
120
- { name: 'omniverses' },
121
- { name: 'referrals' },
122
- { name: 'recipientReferrals' },
123
- { name: 'senderReferrals' },
124
- { name: 'chains' },
125
- { name: 'characterAbilities' },
126
- { name: 'tournaments' },
127
- { name: 'teams' },
128
- { name: 'items' },
129
- { name: 'skills' },
130
- { name: 'itemRecipes' },
131
- { name: 'itemSkins' },
132
- { name: 'stashes' },
133
- { name: 'biomes' },
134
- { name: 'planets' },
135
- { name: 'solarSystems' },
136
- { name: 'universes' },
137
- { name: 'stars' },
138
- { name: 'areas' },
139
- { name: 'acts' },
140
- { name: 'characterClasses' },
141
- { name: 'characterFactions' },
142
- { name: 'eras' },
143
- { name: 'seasons' },
144
- { name: 'itemAttributes' },
145
- { name: 'itemMaterials' },
146
- { name: 'itemSets' },
147
- { name: 'itemSlots' },
148
- { name: 'itemRarities' },
149
- { name: 'itemTypes' },
150
- { name: 'itemSubTypes' },
151
- { name: 'itemSpecificTypes' },
152
- { name: 'characterGenders' },
153
- { name: 'characterRaces' },
154
- { name: 'characterPersonalities' },
155
- { name: 'characterTitles' },
156
- { name: 'lores' },
157
- { name: 'energies' },
158
- { name: 'guides' },
159
- { name: 'achievements' },
160
- { name: 'games' },
161
- { name: 'npcs' },
162
- { name: 'characterAttributes' },
163
- { name: 'characterTypes' },
164
- { name: 'areaTypes' },
165
- { name: 'areaLandmarks' },
166
- { name: 'biomeFeatures' },
167
- { name: 'skillMods' },
168
- { name: 'skillClassifications' },
169
- { name: 'skillConditions' },
170
- { name: 'skillStatusEffects' },
171
- { name: 'skillTrees' },
172
- { name: 'skillTreeNodes' },
173
- { name: 'areaNameChoices' },
174
- { name: 'characterNameChoices' },
175
- { name: 'validators' },
176
- { name: 'productUpdates' },
177
- { name: 'polls' },
178
- { name: 'galaxies' },
179
- { name: 'quests' },
180
- { name: 'raffles' },
181
- { name: 'raffleEntries' },
182
- { name: 'raffleRequirements' },
183
- { name: 'raffleRewards' },
184
- { name: 'proposals' },
185
- { name: 'companies' },
186
- { name: 'people' },
187
- ],
188
- }
189
- );
190
-
191
- // Account Model
192
- export const Account = createModel<Types.AccountDocument>(
193
- 'Account',
194
- {
195
- username: { type: String },
196
- email: { type: String },
197
- address: { type: String },
198
- addressIndex: { type: Number },
199
- telegramUserId: { type: Number },
200
- activeProfileId: { type: mongo.Schema.Types.ObjectId, ref: 'Profile' },
201
- sessionUserId: { type: String },
202
- },
203
- {
204
- indexes: [
205
- // { applicationId: 1, username: 1, unique: true },
206
- {
207
- fields: { applicationId: 1, telegramUserId: 1 },
208
- options: {
209
- unique: true,
210
- partialFilterExpression: { telegramUserId: { $exists: true } },
211
- },
212
- },
213
- ],
214
- virtuals: [
215
- {
216
- name: 'profiles',
217
- ref: 'Profile',
218
- localField: '_id',
219
- foreignField: 'accountId',
220
- justOne: false,
221
- },
222
- ...addTagVirtuals('Account'),
223
- ...addApplicationVirtual(),
224
- ],
225
- }
226
- );
227
-
228
- // Achievement Model
229
- export const Achievement = createModel<Types.AchievementDocument>(
230
- 'Achievement',
231
- {},
232
- {
233
- virtuals: [...addTagVirtuals('Achievement'), ...addApplicationVirtual()],
234
- }
235
- );
236
-
237
- // Act Model
238
- export const Act = createModel<Types.ActDocument>(
239
- 'Act',
240
- {},
241
- {
242
- virtuals: [...addTagVirtuals('Act'), ...addApplicationVirtual()],
243
- }
244
- );
245
-
246
- // Agent Model
247
- export const Agent = createModel<Types.AgentDocument>(
248
- 'Agent',
249
- {},
250
- {
251
- virtuals: [...addTagVirtuals('Agent'), ...addApplicationVirtual()],
252
- }
253
- );
254
-
255
- // Badge Model
256
- export const Badge = createModel<Types.BadgeDocument>(
257
- 'Badge',
258
- {},
259
- {
260
- virtuals: [...addTagVirtuals('Badge'), ...addApplicationVirtual()],
261
- }
262
- );
263
-
264
- // BattlePass Model
265
- export const BattlePass = createModel<Types.BattlePassDocument>(
266
- 'BattlePass',
267
- {},
268
- {
269
- virtuals: [...addTagVirtuals('BattlePass'), ...addApplicationVirtual()],
270
- }
271
- );
272
-
273
- // Biome Model
274
- export const Biome = createModel<Types.BiomeDocument>(
275
- 'Biome',
276
- {},
277
- {
278
- virtuals: [...addTagVirtuals('Biome'), ...addApplicationVirtual()],
279
- }
280
- );
281
-
282
- // BiomeFeature Model
283
- export const BiomeFeature = createModel<Types.BiomeFeatureDocument>(
284
- 'BiomeFeature',
285
- {},
286
- {
287
- virtuals: [...addTagVirtuals('BiomeFeature'), ...addApplicationVirtual()],
288
- }
289
- );
290
-
291
- // Bounty Model
292
- export const Bounty = createModel<Types.BountyDocument>(
293
- 'Bounty',
294
- {},
295
- {
296
- virtuals: [...addTagVirtuals('Bounty'), ...addApplicationVirtual()],
297
- }
298
- );
299
-
300
- export const Counter = createModel<Types.CounterDocument>(
301
- 'Counter',
302
- { _id: { type: String, required: true }, seq: { type: Number, default: 0 } },
303
- { versionKey: false, virtuals: [...addTagVirtuals('Counter'), ...addApplicationVirtual()] }
304
- );
305
-
306
- // Collection Model
307
- export const Collection = createModel<Types.CollectionDocument>(
308
- 'Collection',
309
- {},
310
- {
311
- virtuals: [...addTagVirtuals('Collection'), ...addApplicationVirtual()],
312
- }
313
- );
314
-
315
- // Comment Model
316
- export const Comment = createModel<Types.CommentDocument>(
317
- 'Comment',
318
- {
319
- body: { type: String, required: true },
320
- entity: { type: mongo.Schema.Types.ObjectId },
321
- entityModel: { type: String },
322
- text: { type: String },
323
- ratingId: { type: mongo.Schema.Types.ObjectId, ref: 'Rating' },
324
- },
325
- {
326
- virtuals: [...addTagVirtuals('Comment'), ...addApplicationVirtual()],
327
- }
328
- );
329
-
330
- // Community Model
331
- export const Community = createModel<Types.CommunityDocument>(
332
- 'Community',
333
- {
334
- ideas: [{ type: mongo.Schema.Types.ObjectId, ref: 'Idea' }],
335
- products: [{ type: mongo.Schema.Types.ObjectId, ref: 'Product' }],
336
- projects: [{ type: mongo.Schema.Types.ObjectId, ref: 'Project' }],
337
- },
338
- {
339
- virtuals: [...addTagVirtuals('Community'), ...addApplicationVirtual()],
340
- }
341
- );
342
-
343
- // Company Model
344
- export const Company = createModel<Types.CompanyDocument>(
345
- 'Company',
346
- {
347
- content: { type: String },
348
- people: [{ type: mongo.Schema.Types.ObjectId, ref: 'Person' }],
349
- },
350
- {
351
- virtuals: [...addTagVirtuals('Company'), ...addApplicationVirtual()],
352
- }
353
- );
354
-
355
- // =========================
356
- // Conversation (Thread)
357
- // =========================
358
- //
359
- // Key points:
360
- // - "mailboxKey" gives you a stable unique identity for system inbox threads.
361
- // - Participants field-level index removed; indexes centralized below.
362
- // - lastMessageDate naming normalized.
363
- // - Back-compat messages[] kept, but consider disabling pushes or capping.
364
- //
365
- export const Conversation = createModel<Types.ConversationDocument>(
366
- 'Conversation',
367
- {
368
- // Back-compat: old "owner" thread (mailbox-style threads should set this)
369
- profileId: { type: mongo.Schema.Types.ObjectId, ref: 'Profile', index: true },
370
-
371
- // Mail/chat type
372
- kind: {
373
- type: String,
374
- enum: ['mail', 'dm', 'group', 'support', 'system'],
375
- default: 'mail',
376
- index: true,
377
- },
378
-
379
- // Participants so the same model can do mail+discord-like threads
380
- participants: [
381
- {
382
- profileId: { type: mongo.Schema.Types.ObjectId, ref: 'Profile', required: true },
383
-
384
- role: { type: String, enum: ['user', 'system', 'gm', 'npc'], default: 'user' },
385
-
386
- lastReadAt: { type: Date, default: new Date(0) },
387
- unreadCount: { type: Number, default: 0 },
388
-
389
- isMuted: { type: Boolean, default: false },
390
- isPinned: { type: Boolean, default: false },
391
- isArchived: { type: Boolean, default: false },
392
- isDeleted: { type: Boolean, default: false },
393
- },
394
- ],
395
-
396
- isLocked: { type: Boolean, default: true },
397
- allowUserSend: { type: Boolean, default: false },
398
-
399
- category: { type: String, default: 'system' },
400
- importance: { type: Number, default: 0 },
401
-
402
- // ✅ keep consistent with your service code (use lastMessageDate everywhere)
403
- lastMessageDate: { type: Date, default: null, index: true },
404
- lastMessagePreview: { type: String, default: '' },
405
- messageCount: { type: Number, default: 0 },
406
-
407
- // Back-compat only. Don’t rely on this for reads at scale.
408
- messages: [{ type: mongo.Schema.Types.ObjectId, ref: 'ConversationMessage' }],
409
- },
410
- {
411
- indexes: [
412
- // Inbox list (participant mailbox / DMs / etc.)
413
- { fields: { 'participants.profileId': 1, lastMessageDate: -1 } },
414
-
415
- // Filtered by kind (mail tab, dm tab, etc.)
416
- { fields: { kind: 1, 'participants.profileId': 1, lastMessageDate: -1 } },
417
-
418
- // Back-compat owner mailbox queries
419
- { fields: { profileId: 1, kind: 1, lastMessageDate: -1 } },
420
- {
421
- fields: { key: 1, profileId: 1 },
422
- options: {
423
- unique: true,
424
- partialFilterExpression: { profileId: { $type: 'objectId' } },
425
- },
426
- },
427
- {
428
- fields: { kind: 1, profileId: 1 },
429
- options: {
430
- unique: true,
431
- partialFilterExpression: { profileId: { $type: 'objectId' } },
432
- },
433
- },
434
-
435
- {
436
- fields: { applicationId: 1, kind: 1, profileId: 1, key: 1 },
437
- options: {
438
- unique: true,
439
- partialFilterExpression: { key: { $type: 'string' } },
440
- },
441
- },
442
- ],
443
- virtuals: [...addTagVirtuals('Conversation'), ...addApplicationVirtual()],
444
- }
445
- );
446
-
447
- // =========================
448
- // ConversationMessage (Message)
449
- // =========================
450
- //
451
- // Key points:
452
- // - Primary paging index is (conversationId, _id:-1).
453
- // - Claim fields use claimedDate consistently.
454
- // - Dedupe is per-conversation (compound) and unique when present.
455
- // - Claimable listing inside a conversation has a supporting index.
456
- //
457
- export const ConversationMessage = createModel<Types.ConversationMessageDocument>(
458
- 'ConversationMessage',
459
- {
460
- conversationId: { type: mongo.Schema.Types.ObjectId, ref: 'Conversation', required: true, index: true },
461
-
462
- role: { type: String, enum: ['user', 'assistant', 'system'], required: true },
463
-
464
- type: {
465
- type: String,
466
- enum: ['text', 'notice', 'reward', 'action', 'system'],
467
- default: 'text',
468
- index: true,
469
- },
470
-
471
- isStarred: { type: Boolean, default: false, index: true },
472
-
473
- content: { type: String, default: '' },
474
-
475
- payload: { type: mongo.Schema.Types.Mixed },
476
-
477
- replyToId: { type: mongo.Schema.Types.ObjectId, ref: 'ConversationMessage' },
478
-
479
- claim: {
480
- isClaimable: { type: Boolean, default: false, index: true },
481
-
482
- // ✅ normalized field names (match your latest applyPatchesOrMail.ts)
483
- claimedDate: { type: Date, default: null },
484
- claimedByProfileId: { type: mongo.Schema.Types.ObjectId, ref: 'Profile', default: null },
485
-
486
- dedupeKey: { type: String, default: null },
487
-
488
- attachments: { type: [mongo.Schema.Types.Mixed], default: [] },
489
-
490
- revokedDate: { type: Date, default: null },
491
- revokeReason: { type: String, default: null },
492
- },
493
- },
494
- {
495
- indexes: [
496
- // ✅ Primary paging for “latest messages”
497
- { fields: { conversationId: 1, _id: -1 } },
498
-
499
- // Optional (only if you actually sort by createdDate elsewhere)
500
- { fields: { conversationId: 1, createdDate: -1 } },
501
-
502
- // Claim listing scans (admin / analytics)
503
- { fields: { 'claim.isClaimable': 1, 'claim.claimedDate': 1 } },
504
-
505
- // Claim listing inside a conversation (UI list “claimable first”)
506
- { fields: { conversationId: 1, 'claim.isClaimable': 1, 'claim.claimedDate': 1, _id: -1 } },
507
-
508
- // Fast dedupe lookup per conversation
509
- { fields: { conversationId: 1, 'claim.dedupeKey': 1 } },
510
-
511
- // ✅ Enforce dedupeKey uniqueness per conversation when present
512
- {
513
- fields: { conversationId: 1, 'claim.dedupeKey': 1 },
514
- options: {
515
- unique: true,
516
- partialFilterExpression: { 'claim.dedupeKey': { $type: 'string' } },
517
- },
518
- },
519
-
520
- { fields: { isStarred: 1, conversationId: 1, _id: -1 } },
521
- ],
522
- virtuals: [...addTagVirtuals('ConversationMessage'), ...addApplicationVirtual()],
523
- }
524
- );
525
-
526
- // Data Model
527
- export const Data = createModel<Types.DataDocument>(
528
- 'Data',
529
- {
530
- mod: { type: String, required: true },
531
- },
532
- {
533
- virtuals: [...addTagVirtuals('Data'), ...addApplicationVirtual()],
534
- }
535
- );
536
-
537
- export const Meta = createModel<Types.DataDocument>(
538
- 'Meta',
539
- {},
540
- {
541
- virtuals: [...addTagVirtuals('Meta'), ...addApplicationVirtual()],
542
- }
543
- );
544
-
545
- // Discussion Model
546
- export const Discussion = createModel<Types.DiscussionDocument>(
547
- 'Discussion',
548
- {
549
- content: { type: String },
550
- parentId: { type: mongo.Schema.Types.ObjectId, ref: 'Discussion' },
551
- rootMessageId: { type: mongo.Schema.Types.ObjectId, ref: 'Message' },
552
- type: { type: String, default: 'Discussion' },
553
- },
554
- {
555
- virtuals: [...addTagVirtuals('Discussion'), ...addApplicationVirtual()],
556
- }
557
- );
558
-
559
- // Energy Model
560
- export const Energy = createModel<Types.EnergyDocument>(
561
- 'Energy',
562
- {},
563
- {
564
- virtuals: [...addTagVirtuals('Energy'), ...addApplicationVirtual()],
565
- }
566
- );
567
-
568
- // Event Model
569
- export const Event = createModel<Types.EventDocument>(
570
- 'Event',
571
- {},
572
- {
573
- virtuals: [...addTagVirtuals('Event'), ...addApplicationVirtual()],
574
- }
575
- );
576
-
577
- // File Model
578
- export const File = createModel<Types.FileDocument>(
579
- 'File',
580
- {
581
- content: { type: String },
582
- storageType: { type: String, max: 100 },
583
- accessType: { type: String, max: 100 },
584
- },
585
- {
586
- virtuals: [...addTagVirtuals('File'), ...addApplicationVirtual()],
587
- }
588
- );
589
-
590
- // Galaxy Model
591
- export const Galaxy = createModel<Types.GalaxyDocument>(
592
- 'Galaxy',
593
- {
594
- universeId: { type: mongo.Schema.Types.ObjectId, ref: 'Universe' },
595
- },
596
- {
597
- virtuals: [...addTagVirtuals('Galaxy'), ...addApplicationVirtual()],
598
- }
599
- );
600
-
601
- // Guide Model
602
- export const Guide = createModel<Types.GuideDocument>(
603
- 'Guide',
604
- {
605
- content: { type: String },
606
- gameId: { type: mongo.Schema.Types.ObjectId, ref: 'Game' },
607
- attachments: [mongo.Schema.Types.Mixed],
608
- },
609
- {
610
- virtuals: [...addTagVirtuals('Guide'), ...addApplicationVirtual()],
611
- }
612
- );
613
-
614
- // Idea Model
615
- export const Idea = createModel<Types.IdeaDocument>(
616
- 'Idea',
617
- {
618
- type: { type: String, max: 100 },
619
- communityId: { type: mongo.Schema.Types.ObjectId, ref: 'Community' },
620
- },
621
- {
622
- virtuals: [...addTagVirtuals('Idea'), ...addApplicationVirtual()],
623
- }
624
- );
625
-
626
- // Leaderboard Model
627
- export const Leaderboard = createModel<Types.LeaderboardDocument>(
628
- 'Leaderboard',
629
- {
630
- productId: { type: mongo.Schema.Types.ObjectId, ref: 'Product' },
631
- },
632
- {
633
- virtuals: [...addTagVirtuals('Leaderboard'), ...addApplicationVirtual()],
634
- }
635
- );
636
-
637
- // Log Model
638
- export const Log = createModel<Types.LogDocument>(
639
- 'Log',
640
- {
641
- mod: { type: String, required: true },
642
- messages: [mongo.Schema.Types.Mixed],
643
- // tags: [mongo.Schema.Types.Mixed],
644
- },
645
- {
646
- virtuals: [...addTagVirtuals('Log'), ...addApplicationVirtual()],
647
- }
648
- );
649
-
650
- // Lore Model
651
- export const Lore = createModel<Types.LoreDocument>(
652
- 'Lore',
653
- {
654
- gameId: { type: mongo.Schema.Types.ObjectId, ref: 'Game' },
655
- },
656
- {
657
- virtuals: [...addTagVirtuals('Lore'), ...addApplicationVirtual()],
658
- }
659
- );
660
-
661
- // Market Model
662
- export const Market = createModel<Types.MarketDocument>(
663
- 'Market',
664
- {},
665
- {
666
- virtuals: [...addTagVirtuals('Market'), ...addApplicationVirtual()],
667
- }
668
- );
669
-
670
- // Memory Model
671
- export const Memory = createModel<Types.MemoryDocument>(
672
- 'Memory',
673
- {},
674
- {
675
- virtuals: [...addTagVirtuals('Memory'), ...addApplicationVirtual()],
676
- }
677
- );
678
-
679
- // Message Model
680
- export const Message = createModel<Types.MessageDocument>(
681
- 'Message',
682
- {
683
- content: { type: String },
684
- type: { type: String, max: 100 },
685
- replyToId: { type: mongo.Schema.Types.ObjectId, ref: 'Message' },
686
- parentId: { type: mongo.Schema.Types.ObjectId, ref: 'Message' },
687
- conversationId: { type: mongo.Schema.Types.ObjectId, ref: 'Conversation' },
688
- // messages: [{ type: mongo.Schema.Types.ObjectId, ref: 'Message' }],
689
- },
690
- {
691
- virtuals: [...addTagVirtuals('Message'), ...addApplicationVirtual()],
692
- }
693
- );
694
-
695
- // NewsArticle Model
696
- export const NewsArticle = createModel<Types.NewsArticleDocument>(
697
- 'NewsArticle',
698
- {
699
- href: { type: String, required: true },
700
- source: { type: String, required: true },
701
- },
702
- {
703
- virtuals: [...addTagVirtuals('NewsArticle'), ...addApplicationVirtual()],
704
- }
705
- );
706
-
707
- // Npc Model
708
- export const Npc = createModel<Types.NpcDocument>(
709
- 'Npc',
710
- {
711
- characterId: { type: mongo.Schema.Types.ObjectId, ref: 'Character' },
712
- },
713
- {
714
- virtuals: [...addTagVirtuals('Npc'), ...addApplicationVirtual()],
715
- }
716
- );
717
-
718
- // Offer Model
719
- export const Offer = createModel<Types.OfferDocument>(
720
- 'Offer',
721
- {},
722
- {
723
- virtuals: [...addTagVirtuals('Offer'), ...addApplicationVirtual()],
724
- }
725
- );
726
-
727
- // Order Model
728
- export const Order = createModel<Types.OrderDocument>(
729
- 'Order',
730
- {},
731
- {
732
- virtuals: [...addTagVirtuals('Order'), ...addApplicationVirtual()],
733
- }
734
- );
735
-
736
- // Payment Model
737
- export const Payment = createModel<Types.PaymentDocument>(
738
- 'Payment',
739
- {
740
- status: {
741
- type: String,
742
- default: 'Submitted',
743
- enum: [
744
- 'Archived',
745
- 'Processing',
746
- 'Failed',
747
- 'Submitted',
748
- 'Denied',
749
- 'Processed',
750
- 'Voided',
751
- 'Completed',
752
- 'Refunding',
753
- 'Refunded',
754
- 'Expired',
755
- ],
756
- },
757
- },
758
- {
759
- virtuals: [{ name: 'owner' }, ...addTagVirtuals('Payment'), ...addApplicationVirtual()],
760
- }
761
- );
762
-
763
- // Permission Model
764
- export const Permission = createModel<Types.PermissionDocument>(
765
- 'Permission',
766
- {
767
- roles: [{ type: mongo.Schema.Types.ObjectId, ref: 'Role' }],
768
- },
769
- {
770
- virtuals: [...addTagVirtuals('Permission'), ...addApplicationVirtual()],
771
- }
772
- );
773
-
774
- // Person Model
775
- export const Person = createModel<Types.PersonDocument>(
776
- 'Person',
777
- {
778
- content: { type: String },
779
- companyId: { type: mongo.Schema.Types.ObjectId, ref: 'Company' },
780
- },
781
- {
782
- virtuals: [...addTagVirtuals('Person'), ...addApplicationVirtual()],
783
- }
784
- );
785
-
786
- // Planet Model
787
- export const Planet = createModel<Types.PlanetDocument>(
788
- 'Planet',
789
- {
790
- solarSystemId: { type: mongo.Schema.Types.ObjectId, ref: 'SolarSystem' },
791
- },
792
- {
793
- virtuals: [...addTagVirtuals('Planet'), ...addApplicationVirtual()],
794
- }
795
- );
796
-
797
- // Poll Model
798
- export const Poll = createModel<Types.PollDocument>(
799
- 'Poll',
800
- {},
801
- {
802
- virtuals: [...addTagVirtuals('Poll'), ...addApplicationVirtual()],
803
- }
804
- );
805
-
806
- // Project Model
807
- export const Project = createModel<Types.ProjectDocument>(
808
- 'Project',
809
- {
810
- content: { type: String },
811
- contractStatus: { type: String, default: 'Pending' },
812
- parentId: { type: mongo.Schema.Types.ObjectId, ref: 'Project' },
813
- realmId: { type: mongo.Schema.Types.ObjectId, ref: 'Realm' },
814
- communityId: { type: mongo.Schema.Types.ObjectId, ref: 'Community' },
815
- productId: { type: mongo.Schema.Types.ObjectId, ref: 'Product' },
816
- ratingId: { type: mongo.Schema.Types.ObjectId, ref: 'Rating' },
817
- },
818
- {
819
- virtuals: [...addTagVirtuals('Project'), ...addApplicationVirtual()],
820
- }
821
- );
822
-
823
- // Proposal Model
824
- export const Proposal = createModel<Types.ProposalDocument>(
825
- 'Proposal',
826
- {
827
- content: { type: String },
828
- },
829
- {
830
- virtuals: [...addTagVirtuals('Proposal'), ...addApplicationVirtual()],
831
- }
832
- );
833
-
834
- // Quest Model
835
- export const Quest = createModel<Types.QuestDocument>(
836
- 'Quest',
837
- {
838
- type: { type: String, default: 'zone' },
839
- },
840
- {
841
- virtuals: [...addTagVirtuals('Quest'), ...addApplicationVirtual()],
842
- }
843
- );
844
-
845
- // Question Model
846
- export const Question = createModel<Types.QuestionDocument>(
847
- 'Question',
848
- {
849
- topics: [mongo.Schema.Types.Mixed],
850
- text: { type: String, required: true },
851
- answer: { type: String, required: true },
852
- popularity: { type: Number },
853
- },
854
- {
855
- virtuals: [...addTagVirtuals('Question'), ...addApplicationVirtual()],
856
- }
857
- );
858
-
859
- // Rating Model
860
- export const Rating = createModel<Types.RatingDocument>(
861
- 'Rating',
862
- {
863
- votes: [{ type: mongo.Schema.Types.ObjectId, ref: 'Vote' }],
864
- },
865
- {
866
- virtuals: [...addTagVirtuals('Rating'), ...addApplicationVirtual()],
867
- }
868
- );
869
-
870
- // Realm Model
871
- export const Realm = createModel<Types.RealmDocument>(
872
- 'Realm',
873
- {
874
- endpoint: { type: String },
875
- status: { type: String },
876
- clientCount: { type: Number },
877
- regionCode: { type: String },
878
- gameId: { type: mongo.Schema.Types.ObjectId, ref: 'Game', required: true },
879
- },
880
- {
881
- virtuals: [
882
- ...addTagVirtuals('Realm'),
883
- ...addApplicationVirtual(),
884
- { name: 'realmShards' },
885
- { name: 'realmTraits' },
886
- { name: 'realmEvents' },
887
- ],
888
- }
889
- );
890
-
891
- // RealmEvent Model
892
- export const RealmEvent = createModel<Types.RealmEventDocument>(
893
- 'RealmEvent',
894
- {
895
- description: { type: String, required: true },
896
- startDate: { type: Date, required: false },
897
- endDate: { type: Date, required: false },
898
- },
899
- {
900
- virtuals: [...addTagVirtuals('RealmEvent'), ...addApplicationVirtual()],
901
- }
902
- );
903
-
904
- // RealmTrait Model
905
- export const RealmTrait = createModel<Types.RealmTraitDocument>(
906
- 'RealmTrait',
907
- {
908
- description: { type: String, required: true },
909
- },
910
- {
911
- virtuals: [...addTagVirtuals('RealmTrait'), ...addApplicationVirtual()],
912
- }
913
- );
914
-
915
- // Referral Model
916
- export const Referral = createModel<Types.ReferralDocument>(
917
- 'Referral',
918
- {
919
- recipientId: { type: mongo.Schema.Types.ObjectId, ref: 'Profile', required: true },
920
- senderId: { type: mongo.Schema.Types.ObjectId, ref: 'Profile', required: true },
921
- },
922
- {
923
- virtuals: [...addTagVirtuals('Referral'), ...addApplicationVirtual()],
924
- }
925
- );
926
-
927
- // Review Model
928
- export const Review = createModel<Types.ReviewDocument>(
929
- 'Review',
930
- {
931
- value: { type: String },
932
- },
933
- {
934
- virtuals: [...addTagVirtuals('Review'), ...addApplicationVirtual()],
935
- }
936
- );
937
-
938
- // Role Model
939
- export const Role = createModel<Types.RoleDocument>(
940
- 'Role',
941
- {
942
- value: { type: String },
943
- profiles: [{ type: mongo.Schema.Types.ObjectId, ref: 'Profile' }],
944
- permissions: [{ type: mongo.Schema.Types.ObjectId, ref: 'Permission' }],
945
- },
946
- {
947
- virtuals: [...addTagVirtuals('Role'), ...addApplicationVirtual()],
948
- }
949
- );
950
-
951
- // Season Model
952
- export const Season = createModel<Types.SeasonDocument>(
953
- 'Season',
954
- {},
955
- {
956
- virtuals: [...addTagVirtuals('Season'), ...addApplicationVirtual()],
957
- }
958
- );
959
-
960
- // RealmShard Model
961
- export const RealmShard = createModel<Types.RealmShardDocument>(
962
- 'RealmShard',
963
- {
964
- realmId: { type: mongo.Schema.Types.ObjectId, ref: 'Realm' },
965
- endpoint: { type: String },
966
- status: { type: String },
967
- clientCount: { type: Number },
968
- },
969
- {
970
- virtuals: [...addTagVirtuals('RealmShard'), ...addApplicationVirtual()],
971
- }
972
- );
973
-
974
- // Session Model
975
- export const Session = createModel<Types.SessionDocument>(
976
- 'Session',
977
- {
978
- expired: { type: Date, required: true },
979
- },
980
- {
981
- virtuals: [...addTagVirtuals('Session'), ...addApplicationVirtual()],
982
- }
983
- );
984
-
985
- // SolarSystem Model
986
- export const SolarSystem = createModel<Types.SolarSystemDocument>(
987
- 'SolarSystem',
988
- {
989
- galaxyId: { type: mongo.Schema.Types.ObjectId, ref: 'Galaxy' },
990
- },
991
- {
992
- virtuals: [...addTagVirtuals('SolarSystem'), ...addApplicationVirtual()],
993
- }
994
- );
995
-
996
- // Star Model
997
- export const Star = createModel<Types.StarDocument>(
998
- 'Star',
999
- {},
1000
- {
1001
- virtuals: [...addTagVirtuals('Star'), ...addApplicationVirtual()],
1002
- }
1003
- );
1004
-
1005
- // Stat Model
1006
- export const Stat = createModel<Types.StatDocument>(
1007
- 'Stat',
1008
- {
1009
- number: { type: Number, default: 0 },
1010
- },
1011
- {
1012
- virtuals: [...addTagVirtuals('Stat'), ...addApplicationVirtual()],
1013
- }
1014
- );
1015
-
1016
- // Stash Model
1017
- export const Stash = createModel<Types.StashDocument>(
1018
- 'Stash',
1019
- {},
1020
- {
1021
- virtuals: [...addTagVirtuals('Stash'), ...addApplicationVirtual()],
1022
- }
1023
- );
1024
-
1025
- // Stock Model
1026
- export const Stock = createModel<Types.StockDocument>(
1027
- 'Stock',
1028
- {
1029
- rank: { type: Number, min: 0 },
1030
- price: { type: Number, min: 0 },
1031
- hourChange: { type: Number },
1032
- dayChange: { type: Number },
1033
- weekChange: { type: Number },
1034
- marketCap: { type: Number, min: 0 },
1035
- volume: { type: Number, min: 0 },
1036
- ticker: { type: String },
1037
- unusualActivity: { type: Number, min: 0 },
1038
- },
1039
- {
1040
- virtuals: [...addTagVirtuals('Stock'), ...addApplicationVirtual()],
1041
- }
1042
- );
1043
-
1044
- // Suggestion Model
1045
- export const Suggestion = createModel<Types.SuggestionDocument>(
1046
- 'Suggestion',
1047
- {
1048
- content: { type: String },
1049
- },
1050
- {
1051
- virtuals: [...addTagVirtuals('Suggestion'), ...addApplicationVirtual()],
1052
- }
1053
- );
1054
-
1055
- // Tag Model
1056
- export const Tag = createModel<Types.TagDocument>(
1057
- 'Tag',
1058
- {
1059
- value: { type: String },
1060
- },
1061
- {
1062
- virtuals: [...addApplicationVirtual()],
1063
- }
1064
- );
1065
-
1066
- // Team Model
1067
- export const Team = createModel<Types.TeamDocument>(
1068
- 'Team',
1069
- {
1070
- ratingId: { type: mongo.Schema.Types.ObjectId, ref: 'Rating' },
1071
- points: { type: Number, default: 0 },
1072
- memberCount: { type: Number, default: 0 },
1073
- },
1074
- {
1075
- virtuals: [
1076
- ...addTagVirtuals('Team'),
1077
- ...addApplicationVirtual(),
1078
- {
1079
- name: 'profiles',
1080
- ref: 'Profile',
1081
- localField: '_id',
1082
- foreignField: 'teamId',
1083
- },
1084
- ],
1085
- }
1086
- );
1087
-
1088
- // Tournament Model
1089
- export const Tournament = createModel<Types.TournamentDocument>(
1090
- 'Tournament',
1091
- {},
1092
- {
1093
- virtuals: [...addTagVirtuals('Tournament'), ...addApplicationVirtual()],
1094
- }
1095
- );
1096
-
1097
- // Trade Model
1098
- export const Trade = createModel<Types.TradeDocument>(
1099
- 'Trade',
1100
- {
1101
- status: {
1102
- type: String,
1103
- default: 'Active',
1104
- enum: ['Paused', 'Pending', 'Active', 'Delisted', 'Sold'],
1105
- },
1106
- chainId: { type: mongo.Schema.Types.ObjectId, ref: 'Chain' },
1107
- buyerId: { type: mongo.Schema.Types.ObjectId, ref: 'Profile' },
1108
- parentId: { type: mongo.Schema.Types.ObjectId, ref: 'Trade' },
1109
- productId: { type: mongo.Schema.Types.ObjectId, ref: 'Product' },
1110
- sellerId: { type: mongo.Schema.Types.ObjectId, ref: 'Profile' },
1111
- tokenId: { type: mongo.Schema.Types.ObjectId, ref: 'ChainToken' },
1112
- },
1113
- {
1114
- virtuals: [...addTagVirtuals('Trade'), ...addApplicationVirtual()],
1115
- }
1116
- );
1117
-
1118
- // Universe Model
1119
- export const Universe = createModel<Types.UniverseDocument>(
1120
- 'Universe',
1121
- {},
1122
- {
1123
- virtuals: [...addTagVirtuals('Universe'), ...addApplicationVirtual()],
1124
- }
1125
- );
1126
-
1127
- // Validator Model
1128
- export const Validator = createModel<Types.ValidatorDocument>(
1129
- 'Validator',
1130
- {},
1131
- {
1132
- virtuals: [...addTagVirtuals('Validator'), ...addApplicationVirtual()],
1133
- }
1134
- );
1135
-
1136
- // Vote Model
1137
- export const Vote = createModel<Types.VoteDocument>(
1138
- 'Vote',
1139
- {
1140
- ratingId: { type: mongo.Schema.Types.ObjectId, ref: 'Rating' },
1141
- },
1142
- {
1143
- virtuals: [
1144
- {
1145
- name: 'parent',
1146
- ref: 'Node',
1147
- localField: '_id',
1148
- foreignField: 'from',
1149
- justOne: true,
1150
- match: { fromModel: 'Vote' },
1151
- },
1152
- {
1153
- name: 'owner',
1154
- ref: 'Profile',
1155
- localField: '_id',
1156
- foreignField: '_id',
1157
- justOne: true,
1158
- },
1159
- ...addTagVirtuals('Vote'),
1160
- ...addApplicationVirtual(),
1161
- ],
1162
- }
1163
- );
1164
-
1165
- // WorldEvent Model
1166
- export const WorldEvent = createModel<Types.WorldEventDocument>(
1167
- 'WorldEvent',
1168
- {
1169
- text: { type: String, required: true },
1170
- importance: { type: Number },
1171
- // tags: [mongo.Schema.Types.Mixed],
1172
- },
1173
- {
1174
- virtuals: [...addTagVirtuals('WorldEvent'), ...addApplicationVirtual()],
1175
- }
1176
- );
1177
-
1178
- // WorldRecord Model
1179
- export const WorldRecord = createModel<Types.WorldRecordDocument>(
1180
- 'WorldRecord',
1181
- {
1182
- holderId: { type: mongo.Schema.Types.ObjectId, ref: 'Profile' },
1183
- score: { type: Number },
1184
- // tags: [mongo.Schema.Types.Mixed],
1185
- },
1186
- {
1187
- virtuals: [
1188
- {
1189
- name: 'holder',
1190
- ref: 'Profile',
1191
- localField: '_id',
1192
- foreignField: '_id',
1193
- justOne: true,
1194
- },
1195
- ...addTagVirtuals('WorldRecord'),
1196
- ...addApplicationVirtual(),
1197
- ],
1198
- }
1199
- );
1200
-
1201
- // Node Model (for polymorphic relationships)
1202
- export const Node = createModel<Types.NodeDocument>(
1203
- 'Node',
1204
- {
1205
- relationKey: { type: String, required: true },
1206
- fromModel: { type: String, required: true },
1207
- from: { type: mongo.Schema.Types.ObjectId, required: true },
1208
- toModel: { type: String, required: true },
1209
- to: { type: mongo.Schema.Types.ObjectId, required: true },
1210
- },
1211
- {
1212
- indexes: [
1213
- { fromModel: 1, from: 1 },
1214
- { toModel: 1, to: 1 },
1215
- ],
1216
- }
1217
- );
1218
-
1219
- export const Prefab = createModel<Types.PrefabDocument>(
1220
- 'Prefab',
1221
- {
1222
- name: { type: String, required: true },
1223
- fbxPath: { type: String, required: true },
1224
- customizationOptions: { type: mongo.Schema.Types.Mixed }, // e.g., color, scale range, etc.
1225
- childPrefabs: [
1226
- {
1227
- prefabId: { type: mongo.Schema.Types.ObjectId, ref: 'Prefab' },
1228
- position: { type: mongo.Schema.Types.Mixed }, // Relative position within parent prefab
1229
- rotation: { type: mongo.Schema.Types.Mixed },
1230
- scale: { type: Number, default: 1.0 },
1231
- },
1232
- ],
1233
- },
1234
- {
1235
- extend: 'EntityFields',
1236
- virtuals: [...addTagVirtuals('Prefab'), ...addApplicationVirtual()],
1237
- }
1238
- );
1239
-
1240
- export const Object = createModel<Types.ObjectDocument>(
1241
- 'Object',
1242
- {
1243
- prefabId: { type: mongo.Schema.Types.ObjectId, ref: 'Prefab', required: true },
1244
- // profileId: { type: mongo.Schema.Types.ObjectId, ref: 'Profile', required: true },
1245
- // worldCoordinates: {
1246
- // x: { type: Number, required: true },
1247
- // y: { type: Number, required: true },
1248
- // z: { type: Number, required: true },
1249
- // },
1250
- rotation: { type: mongo.Schema.Types.Mixed },
1251
- scale: { type: Number, default: 1.0 },
1252
- customizations: { type: mongo.Schema.Types.Mixed },
1253
- childInstances: [
1254
- {
1255
- prefabId: { type: mongo.Schema.Types.ObjectId, ref: 'Prefab' },
1256
- worldCoordinates: { type: mongo.Schema.Types.Mixed },
1257
- rotation: { type: mongo.Schema.Types.Mixed },
1258
- scale: { type: Number, default: 1.0 },
1259
- },
1260
- ],
1261
- },
1262
- {
1263
- extend: 'EntityFields',
1264
- virtuals: [...addTagVirtuals('Object'), ...addApplicationVirtual()],
1265
- }
1266
- );
1267
-
1268
- export const ObjectInteraction = createModel<Types.ObjectInteractionDocument>(
1269
- 'ObjectInteraction',
1270
- {
1271
- profileId: { type: mongo.Schema.Types.ObjectId, ref: 'Profile', required: true },
1272
- objectId: { type: mongo.Schema.Types.ObjectId, ref: 'Object', required: true },
1273
- interactionType: { type: String, enum: ['use', 'fight', 'open', 'talk'], required: true },
1274
- outcome: { type: mongo.Schema.Types.Mixed },
1275
- // timestamp: { type: Date, default: Date.now },
1276
- },
1277
- {
1278
- extend: 'EntityFields',
1279
- virtuals: [...addTagVirtuals('Interaction'), ...addApplicationVirtual()],
1280
- }
1281
- );
1282
-
1283
- // Party Model
1284
- export const Party = createModel<Types.PartyDocument>(
1285
- 'Party',
1286
- {
1287
- targetAreaId: { type: mongo.Schema.Types.ObjectId, ref: 'Area', required: false }, // Adjust 'Area' to actual collection if known
1288
- limit: { type: Number, default: 6 },
1289
- isPublic: { type: Boolean, default: true },
1290
- isVisibleToEnemies: { type: Boolean, default: true },
1291
- isApprovalRequired: { type: Boolean, default: false },
1292
- isNonLeaderInviteAllowed: { type: Boolean, default: false },
1293
- isCombatEnabled: { type: Boolean, default: true },
1294
- isFriendlyFireEnabled: { type: Boolean, default: true },
1295
- isLocalQuestShared: { type: Boolean, default: true },
1296
- isGlobalQuestShared: { type: Boolean, default: true },
1297
- isMergeEnabled: { type: Boolean, default: false },
1298
- isRejoinEnabled: { type: Boolean, default: false },
1299
- itemDistribution: {
1300
- type: String,
1301
- enum: ['Random', 'Personal'],
1302
- required: true,
1303
- },
1304
- leaderId: { type: mongo.Schema.Types.ObjectId, ref: 'Profile', required: false }, // Adjust 'Profile' to actual collection if known
1305
- powerRequired: { type: Number, required: true, default: 1 },
1306
- levelRequired: { type: Number, required: true, default: 1 },
1307
- approvalMethod: {
1308
- type: String,
1309
- enum: ['Auto Accept', 'Approval Required'],
1310
- required: true,
1311
- },
1312
- memberIds: [{ type: mongo.Schema.Types.ObjectId, ref: 'Profile' }], // Adjust 'Profile' if necessary
1313
- assistantIds: [{ type: mongo.Schema.Types.ObjectId, ref: 'Profile' }],
1314
- pendingMemberIds: [{ type: mongo.Schema.Types.ObjectId, ref: 'Profile' }],
1315
- blockedMemberIds: [{ type: mongo.Schema.Types.ObjectId, ref: 'Profile' }],
1316
- },
1317
- {
1318
- virtuals: [
1319
- { name: 'owner' },
1320
- {
1321
- name: 'members',
1322
- ref: 'Profile',
1323
- localField: '_id',
1324
- foreignField: 'partyId',
1325
- },
1326
- ...addTagVirtuals('Party'),
1327
- ...addApplicationVirtual(),
1328
- ],
1329
- }
1330
- );
1331
-
1332
- export const SeerEvent = mongo.createModel<Types.SeerEventDocument>(
1333
- 'SeerEvent',
1334
- {
1335
- kind: { type: String, required: true }, // model name: 'Character', 'Item', etc.
1336
- operation: {
1337
- type: String,
1338
- enum: ['create', 'update', 'delete'],
1339
- required: true,
1340
- },
1341
- recordId: { type: String, required: true },
1342
- applicationId: { type: mongo.Schema.Types.ObjectId, ref: 'Application' },
1343
-
1344
- // ✅ this is the important fix: schema *object* with `type: Mixed`
1345
- payload: { type: mongo.Schema.Types.Mixed, required: true },
1346
-
1347
- seq: { type: Number, required: true, index: true },
1348
- timestamp: { type: Date, default: Date.now, index: true },
1349
- },
1350
- {
1351
- // extend: 'CommonFields', // or 'EntityFields' if you want applicationId/ownerId, but you already have applicationId above
1352
- indexes: [{ seq: 1 }, { timestamp: 1 }],
1353
- }
1354
- );
1355
-
1356
- export const SeerPayload = mongo.createModel<Types.SeerPayloadDocument>(
1357
- 'SeerPayload',
1358
- {
1359
- fromSeer: { type: String, required: true },
1360
- applicationId: { type: mongo.Schema.Types.ObjectId, ref: 'Application' },
1361
-
1362
- // list of raw events we snapshot
1363
- // TS doesn't love `[Mixed]`, so we cast this field only
1364
- events: {
1365
- type: [mongo.Schema.Types.Mixed],
1366
- default: [],
1367
- } as any,
1368
-
1369
- eventsHash: { type: String, required: true },
1370
- merkleRoot: { type: String, required: true },
1371
-
1372
- proof: { type: mongo.Schema.Types.Mixed, required: true },
1373
- publicSignals: { type: [String], default: [] },
1374
- },
1375
- {
1376
- // extend: 'CommonFields',
1377
- indexes: [{ createdDate: 1 }],
1378
- }
1379
- );