@arken/node 1.5.1 → 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 (148) hide show
  1. package/db.ts +76 -1
  2. package/index.ts +351 -18
  3. package/package.json +3 -3
  4. package/tsconfig.json +33 -2
  5. package/util.ts +1 -0
  6. package/modules/area/area.models.ts +0 -15
  7. package/modules/area/area.router.ts +0 -74
  8. package/modules/area/area.schema.ts +0 -22
  9. package/modules/area/area.service.ts +0 -124
  10. package/modules/area/area.types.ts +0 -26
  11. package/modules/area/index.ts +0 -5
  12. package/modules/asset/asset.models.ts +0 -59
  13. package/modules/asset/asset.router.ts +0 -55
  14. package/modules/asset/asset.schema.ts +0 -27
  15. package/modules/asset/asset.service.ts +0 -85
  16. package/modules/asset/asset.types.ts +0 -22
  17. package/modules/asset/index.ts +0 -5
  18. package/modules/chain/chain.models.ts +0 -50
  19. package/modules/chain/chain.router.ts +0 -104
  20. package/modules/chain/chain.schema.ts +0 -52
  21. package/modules/chain/chain.service.ts +0 -167
  22. package/modules/chain/chain.types.ts +0 -24
  23. package/modules/chain/index.ts +0 -5
  24. package/modules/character/character.models.ts +0 -174
  25. package/modules/character/character.router.ts +0 -314
  26. package/modules/character/character.schema.ts +0 -147
  27. package/modules/character/character.service.ts +0 -876
  28. package/modules/character/character.types.ts +0 -64
  29. package/modules/character/index.ts +0 -5
  30. package/modules/chat/chat.models.ts +0 -43
  31. package/modules/chat/chat.router.ts +0 -67
  32. package/modules/chat/chat.schema.ts +0 -36
  33. package/modules/chat/chat.service.ts +0 -128
  34. package/modules/chat/chat.types.ts +0 -20
  35. package/modules/chat/index.ts +0 -5
  36. package/modules/collection/collection.models.ts +0 -76
  37. package/modules/collection/collection.router.ts +0 -91
  38. package/modules/collection/collection.schema.ts +0 -90
  39. package/modules/collection/collection.service.ts +0 -192
  40. package/modules/collection/collection.types.ts +0 -36
  41. package/modules/collection/index.ts +0 -5
  42. package/modules/core/core.models.ts +0 -1380
  43. package/modules/core/core.router.ts +0 -1781
  44. package/modules/core/core.schema.ts +0 -847
  45. package/modules/core/core.service.ts +0 -2824
  46. package/modules/core/core.types.ts +0 -340
  47. package/modules/core/index.ts +0 -5
  48. package/modules/core/mail/applyPatchesOrMail.ts +0 -568
  49. package/modules/core/mail/mailClaimablePatchesBatch.ts +0 -381
  50. package/modules/game/game.models.ts +0 -53
  51. package/modules/game/game.router.ts +0 -110
  52. package/modules/game/game.schema.ts +0 -23
  53. package/modules/game/game.service.ts +0 -143
  54. package/modules/game/game.types.ts +0 -28
  55. package/modules/game/index.ts +0 -5
  56. package/modules/interface/index.ts +0 -5
  57. package/modules/interface/interface.canonicalize.ts +0 -279
  58. package/modules/interface/interface.models.ts +0 -40
  59. package/modules/interface/interface.router.ts +0 -175
  60. package/modules/interface/interface.schema.ts +0 -59
  61. package/modules/interface/interface.service.ts +0 -356
  62. package/modules/interface/interface.types.ts +0 -25
  63. package/modules/item/index.ts +0 -5
  64. package/modules/item/item.models.ts +0 -124
  65. package/modules/item/item.router.ts +0 -103
  66. package/modules/item/item.schema.ts +0 -120
  67. package/modules/item/item.service.ts +0 -167
  68. package/modules/item/item.types.ts +0 -74
  69. package/modules/job/index.ts +0 -5
  70. package/modules/job/job.models.ts +0 -14
  71. package/modules/job/job.router.ts +0 -44
  72. package/modules/job/job.schema.ts +0 -9
  73. package/modules/job/job.service.ts +0 -243
  74. package/modules/job/job.types.ts +0 -23
  75. package/modules/market/index.ts +0 -5
  76. package/modules/market/market.models.ts +0 -113
  77. package/modules/market/market.router.ts +0 -73
  78. package/modules/market/market.schema.ts +0 -140
  79. package/modules/market/market.service.ts +0 -122
  80. package/modules/market/market.types.ts +0 -56
  81. package/modules/product/index.ts +0 -5
  82. package/modules/product/product.models.ts +0 -166
  83. package/modules/product/product.router.ts +0 -93
  84. package/modules/product/product.schema.ts +0 -149
  85. package/modules/product/product.service.ts +0 -160
  86. package/modules/product/product.types.ts +0 -33
  87. package/modules/profile/index.ts +0 -5
  88. package/modules/profile/profile.models.ts +0 -214
  89. package/modules/profile/profile.router.ts +0 -72
  90. package/modules/profile/profile.schema.ts +0 -156
  91. package/modules/profile/profile.service.ts +0 -149
  92. package/modules/profile/profile.types.ts +0 -22
  93. package/modules/raffle/index.ts +0 -5
  94. package/modules/raffle/raffle.models.ts +0 -44
  95. package/modules/raffle/raffle.router.ts +0 -90
  96. package/modules/raffle/raffle.schema.ts +0 -32
  97. package/modules/raffle/raffle.service.ts +0 -167
  98. package/modules/raffle/raffle.types.ts +0 -30
  99. package/modules/skill/index.ts +0 -5
  100. package/modules/skill/skill.models.ts +0 -16
  101. package/modules/skill/skill.router.ts +0 -201
  102. package/modules/skill/skill.schema.ts +0 -40
  103. package/modules/skill/skill.service.ts +0 -390
  104. package/modules/skill/skill.types.ts +0 -33
  105. package/modules/video/index.ts +0 -5
  106. package/modules/video/video.models.ts +0 -25
  107. package/modules/video/video.router.ts +0 -143
  108. package/modules/video/video.schema.ts +0 -46
  109. package/modules/video/video.service.ts +0 -274
  110. package/modules/video/video.types.ts +0 -33
  111. package/util/db/index.ts +0 -7
  112. package/util/db/isPostgresError.ts +0 -9
  113. package/util/db/isUniqueConstraintViolation.ts +0 -3
  114. package/util/db.ts +0 -62
  115. package/util/index.ts +0 -351
  116. /package/{util/api.ts → api.ts} +0 -0
  117. /package/{util/array.ts → array.ts} +0 -0
  118. /package/{util/browser.ts → browser.ts} +0 -0
  119. /package/{util/codebase.ts → codebase.ts} +0 -0
  120. /package/{util/config.ts → config.ts} +0 -0
  121. /package/{util/decoder.test.ts → decoder.test.ts} +0 -0
  122. /package/{util/decoder.ts → decoder.ts} +0 -0
  123. /package/{util/format.ts → format.ts} +0 -0
  124. /package/{util/guid.ts → guid.ts} +0 -0
  125. /package/{util/json.ts → json.ts} +0 -0
  126. /package/{util/log.ts → log.ts} +0 -0
  127. /package/{util/math.ts → math.ts} +0 -0
  128. /package/{util/merkle.ts → merkle.ts} +0 -0
  129. /package/{util/mongo.ts → mongo.ts} +0 -0
  130. /package/{util/number.ts → number.ts} +0 -0
  131. /package/{util/object.ts → object.ts} +0 -0
  132. /package/{util/otp.ts → otp.ts} +0 -0
  133. /package/{util/physics.ts → physics.ts} +0 -0
  134. /package/{util/process.ts → process.ts} +0 -0
  135. /package/{util/rpc.ts → rpc.ts} +0 -0
  136. /package/{util/seer.ts → seer.ts} +0 -0
  137. /package/{util/string.ts → string.ts} +0 -0
  138. /package/{util/text.ts → text.ts} +0 -0
  139. /package/{util/time → time}/date.ts +0 -0
  140. /package/{util/time → time}/fancyTimeFormat.ts +0 -0
  141. /package/{util/time → time}/index.ts +0 -0
  142. /package/{util/time → time}/now.ts +0 -0
  143. /package/{util/types → types}/mongo.d.ts +0 -0
  144. /package/{util/web3 → web3}/httpProvider.ts +0 -0
  145. /package/{util/web3.ts → web3.ts} +0 -0
  146. /package/{util/websocket.ts → websocket.ts} +0 -0
  147. /package/{util/zk.ts → zk.ts} +0 -0
  148. /package/{util/zod.ts → zod.ts} +0 -0
@@ -1,876 +0,0 @@
1
- // arken/packages/node/modules/character/character.service.ts
2
- //
3
- import mongoose from 'mongoose';
4
- import keccak256 from 'keccak256';
5
- import type {
6
- Character,
7
- CharacterAbility,
8
- CharacterAttribute,
9
- CharacterClass,
10
- CharacterFaction,
11
- CharacterGender,
12
- CharacterNameChoice,
13
- CharacterPersonality,
14
- CharacterRace,
15
- CharacterTitle,
16
- CharacterType,
17
- Router,
18
- RouterInput,
19
- RouterOutput,
20
- RouterContext,
21
- } from './character.types';
22
- import { ARXError } from '../../util/rpc';
23
- import { getNextSeq, hashEvents } from '../../util/mongo';
24
- import { updateLeafWithProof } from '../../util/merkle';
25
- import { getFilter } from '../../util/api';
26
-
27
- const TREE_DEPTH = 16;
28
- const TREE_SIZE = 1 << TREE_DEPTH;
29
- const LOCAL_SEER_ID = process.env.SEER_NODE_WALLET ?? 'seer-node-1';
30
-
31
- // -------------------------------
32
- // Inventory Sync Standard
33
- // -------------------------------
34
- export type InventorySyncOp =
35
- | { op: 'add'; itemKey: string; quantity?: number }
36
- | { op: 'remove'; itemKey: string; quantity?: number };
37
-
38
- export type SyncCharacterInventoryPayload =
39
- | {
40
- characterId: string;
41
- mode: 'patch';
42
- ops: InventorySyncOp[];
43
- reason?: string;
44
- }
45
- | {
46
- characterId: string;
47
- mode: 'refresh';
48
- reason?: string;
49
- };
50
-
51
- // Deterministic mapping from (kind, recordId) -> Merkle leaf index
52
- function computeLeafIndex(kind: string, recordId: string): number {
53
- const h = keccak256(`${kind}:${recordId}`).toString('hex');
54
- const first8 = h.slice(0, 8); // 32 bits
55
- const n = parseInt(first8, 16);
56
- return n % TREE_SIZE;
57
- }
58
-
59
- // -------------------------------
60
- // Helpers
61
- // -------------------------------
62
- async function resolveCharacterForRequest(ctx: RouterContext, input: any) {
63
- // const filter = getFilter(input);
64
- const explicitId = input?.characterId;
65
- // console.log('explicitId', input, filter, explicitId);
66
- // Prefer explicit characterId if provided
67
- // if (explicitId) {
68
- const character = await ctx.app.model.Character.findById(explicitId);
69
- if (!character) throw new Error('Character not found');
70
- return character;
71
- // }
72
-
73
- // // Otherwise, fall back to "active" character = profile.characters[0]
74
- // if (!ctx.client?.profile?.id) throw new Error('No profile');
75
- // // @ts-ignore
76
- // const character = await ctx.app.model.Character.findById(ctx.client.profile.characters?.[0].characterId);
77
- // if (!character) throw new Error('No character');
78
-
79
- // return character;
80
- }
81
-
82
- function ensureInventoryShape(character: any) {
83
- if (!character.inventory) character.inventory = [{ items: [] }];
84
- if (!character.inventory[0]) character.inventory[0] = { items: [] };
85
- if (!Array.isArray(character.inventory[0].items)) character.inventory[0].items = [];
86
-
87
- for (const item of character.inventory[0].items) {
88
- console.log('item', item.itemId, item.itemId.valueOf());
89
- item.itemId = item.itemId.valueOf();
90
- }
91
- }
92
-
93
- // -------------------------------
94
- // Service
95
- // -------------------------------
96
- export class Service {
97
- /**
98
- * Sets the "active" character for the current profile.
99
- *
100
- * Convention used across codebase:
101
- * - profile.characters[0] is treated as active character
102
- *
103
- * Implementation:
104
- * - verify character exists and belongs to the caller
105
- * - reorder profile.characters so the selected id is first
106
- */
107
- /**
108
- * Sets the active character for the current profile.
109
- *
110
- * Stores:
111
- * profile.data.activeCharacterId = <characterId>
112
- *
113
- * Does NOT reorder profile.characters.
114
- */
115
- async setActiveCharacter(input: { characterId: string }, ctx: RouterContext): Promise<{ characterId: string }> {
116
- if (!ctx.client?.profile) throw new ARXError('UNAUTHORIZED');
117
- if (!input?.characterId) throw new ARXError('NO_INPUT');
118
-
119
- const profileId = ctx.client.profile.id;
120
- const characterId = String(input.characterId);
121
-
122
- // Ensure character exists
123
- const character = await ctx.app.model.Character.findById(characterId).lean().exec();
124
- if (!character) throw new Error('Character not found');
125
-
126
- // Ensure ownership (saveCharacters sets ownerId = profile.id)
127
- if (String((character as any).ownerId || '') !== String(profileId)) {
128
- throw new ARXError('FORBIDDEN');
129
- }
130
-
131
- // Load profile and set pointer
132
- const profile = await ctx.app.model.Profile.findById(profileId).exec();
133
- if (!profile) throw new Error('Profile not found');
134
-
135
- // ensure data shape
136
- (profile as any).data =
137
- (profile as any).data && typeof (profile as any).data === 'object' ? (profile as any).data : {};
138
- (profile as any).data.activeCharacterId = characterId;
139
-
140
- profile.markModified('data');
141
- await profile.save();
142
-
143
- ctx.client.profile.data = profile.data;
144
-
145
- await ctx.client.emit.sync.mutate({
146
- kind: 'invalidate',
147
- targets: ['profile.me', 'trek.getState', 'character.inventory'],
148
- reason: 'activeCharacterChanged',
149
- });
150
-
151
- return { characterId };
152
- }
153
-
154
- /**
155
- * Inventory: returns canonical inventory snapshot.
156
- *
157
- * This is the "full refresh" primitive; client can call this any time it needs to converge.
158
- *
159
- * NOTE: Uses the same filter semantics as other character routes:
160
- * - if input includes characterId/id, we use that
161
- * - otherwise we default to the user's first character
162
- */
163
- async getCharacterInventory(
164
- input: any, // intentionally loose so you can add RouterInput/Output wiring later
165
- ctx: RouterContext
166
- ): Promise<{ characterId: string; inventory: any }> {
167
- if (!ctx.client?.profile) throw new ARXError('UNAUTHORIZED');
168
-
169
- const character = await resolveCharacterForRequest(ctx, input);
170
- ensureInventoryShape(character);
171
-
172
- return { characterId: character.id.toString(), inventory: character.inventory };
173
- }
174
-
175
- /**
176
- * Inventory: client convergence endpoint + "standard" payload.
177
- *
178
- * - mode=patch: client is telling us how it applied a local patch (add/remove)
179
- * - mode=refresh: client requests canonical snapshot (recommended fallback)
180
- *
181
- * For now, this route simply returns the canonical snapshot so the client can converge.
182
- * (Server-authoritative changes should still be persisted on the Character document by the
183
- * gameplay systems, and then the UI can call this route or respond to emitted events.)
184
- */
185
- async syncCharacterInventory(
186
- input: SyncCharacterInventoryPayload,
187
- ctx: RouterContext
188
- ): Promise<{ characterId: string; inventory: any }> {
189
- if (!ctx.client?.profile) throw new ARXError('UNAUTHORIZED');
190
- if (!input?.characterId) throw new ARXError('NO_INPUT');
191
-
192
- const character = await ctx.app.model.Character.findById(input.characterId);
193
- if (!character) throw new Error('Character not found');
194
-
195
- ensureInventoryShape(character);
196
-
197
- // Return canonical snapshot (client can always converge from this)
198
- return { characterId: character.id.toString(), inventory: character.inventory };
199
- }
200
-
201
- /**
202
- * Optional server -> client push helper you can call from other services.
203
- *
204
- * Usage:
205
- * await ctx.client.emit.syncCharacterInventory.mutate({ ...payload })
206
- */
207
- async emitInventorySync(ctx: RouterContext, payload: SyncCharacterInventoryPayload) {
208
- // You asked for this exact style: ctx.client.emit.SOMETHING.mutate(DATA_HERE)
209
- try {
210
- await (ctx.client as any)?.emit?.syncCharacterInventory?.mutate?.(payload);
211
- } catch (e) {
212
- // never crash gameplay because a websocket push failed
213
- console.warn('Character.Service.emitInventorySync failed', e);
214
- }
215
- }
216
-
217
- async exchangeCharacterItem(
218
- input: RouterInput['exchangeCharacterItem'],
219
- ctx: RouterContext
220
- ): Promise<RouterOutput['exchangeCharacterItem']> {
221
- if (!input) throw new ARXError('NO_INPUT');
222
- console.log('Character.Service.exchangeCharacterItem', input);
223
-
224
- const filter = getFilter(input);
225
- const character = await ctx.app.model.Character.findById(filter.characterId);
226
- if (!character) throw new Error('Character not found');
227
-
228
- // find the item on character
229
- // see if the current player has the required item
230
- // do the exchange
231
-
232
- return character as Character;
233
- }
234
-
235
- async getCharacterData(
236
- input: RouterInput['getCharacter'],
237
- ctx: RouterContext
238
- ): Promise<RouterOutput['getCharacter']> {
239
- if (!input) throw new ARXError('NO_INPUT');
240
- console.log('Character.Service.getCharacterData', input);
241
-
242
- const filter = getFilter(input);
243
- // @ts-ignore
244
- const character = await ctx.app.model.Character.findOne(filter).asJSON();
245
- if (!character) throw new Error('Character not found');
246
-
247
- return character.data;
248
- }
249
-
250
- async getCharacter(input: RouterInput['getCharacter'], ctx: RouterContext): Promise<RouterOutput['getCharacter']> {
251
- if (!input) throw new ARXError('NO_INPUT');
252
- console.log('Character.Service.getCharacter', input);
253
-
254
- const filter = getFilter(input);
255
- // @ts-ignore
256
- const character = await ctx.app.model.Character.findOne(filter).asJSON();
257
- if (!character) throw new Error('Character not found');
258
- console.log('charactercharactercharacter', character);
259
- return character as Character;
260
- }
261
-
262
- async getCharacters(input: RouterInput['getCharacters'], ctx: RouterContext): Promise<RouterOutput['getCharacters']> {
263
- if (!input) throw new ARXError('NO_INPUT');
264
-
265
- const filter = getFilter(input);
266
-
267
- const limit = input.limit ?? 50;
268
- const skip = input.skip ?? 0;
269
-
270
- const [items, total] = await Promise.all([
271
- // @ts-ignore
272
- ctx.app.model.Character.find(filter).skip(skip).limit(limit).asJSON(),
273
- ctx.app.model.Character.find(filter).countDocuments().exec(),
274
- ]);
275
-
276
- return { items, total };
277
- }
278
-
279
- async getCharacterAbility(
280
- input: RouterInput['getCharacterAbility'],
281
- ctx: RouterContext
282
- ): Promise<RouterOutput['getCharacterAbility']> {
283
- if (!input) throw new ARXError('NO_INPUT');
284
- console.log('Character.Service.getCharacterAbility', input);
285
-
286
- const filter = getFilter(input);
287
- const characterAbility = await ctx.app.model.CharacterAbility.findById(filter.id).lean().exec();
288
- if (!characterAbility) throw new Error('CharacterAbility not found');
289
-
290
- return characterAbility as CharacterAbility;
291
- }
292
-
293
- async saveCharacters(
294
- input: RouterInput['saveCharacters'],
295
- ctx: RouterContext
296
- ): Promise<RouterOutput['saveCharacters']> {
297
- if (!input || !Array.isArray(input) || input.length === 0) {
298
- throw new ARXError('NO_INPUT');
299
- }
300
-
301
- const items: any[] = [];
302
- const events: any[] = [];
303
- const payloads: any[] = [];
304
-
305
- for (const raw of input) {
306
- // Allow id or _id; do not mutate original
307
- const { id, _id, ...rest } = raw.data as any;
308
-
309
- const previousId: string | mongoose.Types.ObjectId | undefined =
310
- typeof id === 'string' || id instanceof mongoose.Types.ObjectId
311
- ? (id as any)
312
- : _id instanceof mongoose.Types.ObjectId || typeof _id === 'string'
313
- ? (_id as any)
314
- : undefined;
315
-
316
- // Scope by applicationId if the Character model uses applicationId filters
317
- if (ctx.app?.model?.Character?.filters?.applicationId && !rest.applicationId) {
318
- rest.applicationId = ctx.app.model.Character.filters.applicationId;
319
- }
320
-
321
- if (!ctx.client.profile.id) {
322
- throw new Error('No profile');
323
- }
324
-
325
- rest.ownerId = ctx.client.profile.id;
326
-
327
- // Derive key from name if missing
328
- if (!rest.key && typeof rest.name === 'string') {
329
- rest.key = String(rest.name)
330
- .trim()
331
- .toLowerCase()
332
- .replace(/[^a-z0-9\s-]/g, '')
333
- .replace(/\s+/g, '-')
334
- .replace(/-+/g, '-');
335
- }
336
-
337
- // IMMUTABLE: always create a new Character document
338
- const doc = await ctx.app.model.Character.create(rest);
339
- const saved = doc?.toObject?.() ?? doc;
340
-
341
- items.push(saved);
342
-
343
- // Logical operation type (even though storage is immutable)
344
- const op: 'create' | 'update' = previousId ? 'update' : 'create';
345
-
346
- const event = {
347
- kind: 'Character',
348
- operation: op,
349
- recordId: saved.id.toString(), // new doc id
350
- applicationId: saved.applicationId,
351
- payload: {
352
- ...saved,
353
- previousId: previousId ? previousId.toString() : null,
354
- },
355
- timestamp: new Date(),
356
- };
357
-
358
- events.push(event);
359
-
360
- // -----------------------------------------------------------------------
361
- // Merkle + zkSNARK for this Character
362
- // -----------------------------------------------------------------------
363
-
364
- try {
365
- const leafIndex = computeLeafIndex('Character', saved.id.toString());
366
-
367
- // Poseidon-based Merkle update + zkSNARK proof using UpdateLeaf(16)
368
- const merkleUpdate = await updateLeafWithProof(leafIndex, {
369
- kind: 'Character',
370
- id: saved.id.toString(),
371
- status: saved.status,
372
- key: saved.key,
373
- applicationId: saved.applicationId,
374
- });
375
-
376
- // Build SeerPayload (one per character for now; you can batch later)
377
- payloads.push({
378
- fromSeer: LOCAL_SEER_ID,
379
- applicationId: saved.applicationId,
380
- events: [event],
381
- eventsHash: hashEvents([event]),
382
- merkleRoot: merkleUpdate.newRoot,
383
- proof: merkleUpdate.proof,
384
- publicSignals: merkleUpdate.publicSignals,
385
- });
386
- } catch (e) {
387
- console.log('Merkle error when creating character');
388
- }
389
- }
390
-
391
- // -------------------------------------------------------------------------
392
- // Persist SeerEvents with monotonic seq
393
- // -------------------------------------------------------------------------
394
-
395
- if (events.length > 0) {
396
- const lastEvent = await ctx.app.model.SeerEvent.findOne().sort({ seq: -1 }).lean().exec();
397
- // @ts-ignore
398
- const baseSeq = (lastEvent?.seq ?? 0) + 1;
399
-
400
- const docsToInsert = events.map((ev, idx) => ({
401
- ...ev,
402
- seq: baseSeq + idx,
403
- }));
404
-
405
- await ctx.app.model.SeerEvent.create(docsToInsert);
406
- }
407
-
408
- // -------------------------------------------------------------------------
409
- // Persist SeerPayloads for cross-seer sync
410
- // -------------------------------------------------------------------------
411
-
412
- if (payloads.length > 0) {
413
- await ctx.app.model.SeerPayload.create(payloads);
414
- }
415
-
416
- const total = await ctx.app.model.Character.find().countDocuments().exec();
417
-
418
- return { items, total };
419
- }
420
-
421
- async createCharacterAbility(
422
- input: RouterInput['createCharacterAbility'],
423
- ctx: RouterContext
424
- ): Promise<RouterOutput['createCharacterAbility']> {
425
- if (!input) throw new ARXError('NO_INPUT');
426
- console.log('Character.Service.createCharacterAbility', input);
427
-
428
- const characterAbility = await ctx.app.model.CharacterAbility.create(input);
429
- return characterAbility as CharacterAbility;
430
- }
431
-
432
- async updateCharacter(
433
- input: RouterInput['updateCharacter'],
434
- ctx: RouterContext
435
- ): Promise<RouterOutput['updateCharacter']> {
436
- if (!input) throw new ARXError('NO_INPUT');
437
- console.log('Character.Service.updateCharacter', input);
438
-
439
- const filter = getFilter(input);
440
- const updatedCharacter = await ctx.app.model.Character.findByIdAndUpdate(filter.id, input.data, {
441
- new: true,
442
- })
443
- .lean()
444
- .exec();
445
- if (!updatedCharacter) throw new Error('Character update failed');
446
-
447
- return updatedCharacter as Character;
448
- }
449
-
450
- async updateCharacterAbility(
451
- input: RouterInput['updateCharacterAbility'],
452
- ctx: RouterContext
453
- ): Promise<RouterOutput['updateCharacterAbility']> {
454
- if (!input) throw new ARXError('NO_INPUT');
455
- console.log('Character.Service.updateCharacterAbility', input);
456
-
457
- const filter = getFilter(input);
458
- const updatedCharacterAbility = await ctx.app.model.CharacterAbility.findByIdAndUpdate(filter.id, input.data, {
459
- new: true,
460
- })
461
- .lean()
462
- .exec();
463
- if (!updatedCharacterAbility) throw new Error('CharacterAbility update failed');
464
-
465
- return updatedCharacterAbility as CharacterAbility;
466
- }
467
-
468
- async getCharacterAttribute(
469
- input: RouterInput['getCharacterAttribute'],
470
- ctx: RouterContext
471
- ): Promise<RouterOutput['getCharacterAttribute']> {
472
- if (!input) throw new ARXError('NO_INPUT');
473
- console.log('Character.Service.getCharacterAttribute', input);
474
-
475
- const filter = getFilter(input);
476
- const characterAttribute = await ctx.app.model.CharacterAttribute.findById(filter.id).lean().exec();
477
- if (!characterAttribute) throw new Error('CharacterAttribute not found');
478
-
479
- return characterAttribute as CharacterAttribute;
480
- }
481
-
482
- async createCharacterAttribute(
483
- input: RouterInput['createCharacterAttribute'],
484
- ctx: RouterContext
485
- ): Promise<RouterOutput['createCharacterAttribute']> {
486
- if (!input) throw new ARXError('NO_INPUT');
487
- console.log('Character.Service.createCharacterAttribute', input);
488
-
489
- const characterAttribute = await ctx.app.model.CharacterAttribute.create(input);
490
- return characterAttribute as CharacterAttribute;
491
- }
492
-
493
- async updateCharacterAttribute(
494
- input: RouterInput['updateCharacterAttribute'],
495
- ctx: RouterContext
496
- ): Promise<RouterOutput['updateCharacterAttribute']> {
497
- if (!input) throw new ARXError('NO_INPUT');
498
- console.log('Character.Service.updateCharacterAttribute', input);
499
-
500
- const filter = getFilter(input);
501
- const updatedCharacterAttribute = await ctx.app.model.CharacterAttribute.findByIdAndUpdate(filter.id, input.data, {
502
- new: true,
503
- })
504
- .lean()
505
- .exec();
506
- if (!updatedCharacterAttribute) throw new Error('CharacterAttribute update failed');
507
-
508
- return updatedCharacterAttribute as CharacterAttribute;
509
- }
510
-
511
- async getCharacterClass(
512
- input: RouterInput['getCharacterClass'],
513
- ctx: RouterContext
514
- ): Promise<RouterOutput['getCharacterClass']> {
515
- if (!input) throw new ARXError('NO_INPUT');
516
- console.log('Character.Service.getCharacterClass', input);
517
-
518
- const characterClass = await ctx.app.model.CharacterClass.findById(getFilter(input).id).lean().exec();
519
- if (!characterClass) throw new Error('CharacterClass not found');
520
-
521
- return characterClass as CharacterClass;
522
- }
523
-
524
- async createCharacterClass(
525
- input: RouterInput['createCharacterClass'],
526
- ctx: RouterContext
527
- ): Promise<RouterOutput['createCharacterClass']> {
528
- if (!input) throw new ARXError('NO_INPUT');
529
- console.log('Character.Service.createCharacterClass', input);
530
-
531
- const characterClass = await ctx.app.model.CharacterClass.create(input);
532
- return characterClass as CharacterClass;
533
- }
534
-
535
- async updateCharacterClass(
536
- input: RouterInput['updateCharacterClass'],
537
- ctx: RouterContext
538
- ): Promise<RouterOutput['updateCharacterClass']> {
539
- if (!input) throw new ARXError('NO_INPUT');
540
- console.log('Character.Service.updateCharacterClass', input);
541
-
542
- const updatedCharacterClass = await ctx.app.model.CharacterClass.findByIdAndUpdate(
543
- getFilter(input).id,
544
- input.data,
545
- {
546
- new: true,
547
- }
548
- )
549
- .lean()
550
- .exec();
551
- if (!updatedCharacterClass) throw new Error('CharacterClass update failed');
552
-
553
- return updatedCharacterClass as CharacterClass;
554
- }
555
-
556
- // Add similar methods for other character-related models...
557
-
558
- async getCharacterFaction(
559
- input: RouterInput['getCharacterFaction'],
560
- ctx: RouterContext
561
- ): Promise<RouterOutput['getCharacterFaction']> {
562
- if (!input) throw new ARXError('NO_INPUT');
563
- console.log('Character.Service.getCharacterFaction', input);
564
-
565
- const characterFaction = await ctx.app.model.CharacterFaction.findOne(getFilter(input)).lean().exec();
566
- if (!characterFaction) throw new Error('CharacterFaction not found');
567
-
568
- return characterFaction as CharacterFaction;
569
- }
570
-
571
- async getCharacterFactions(
572
- input: RouterInput['getCharacterFactions'],
573
- ctx: RouterContext
574
- ): Promise<RouterOutput['getCharacterFactions']> {
575
- if (!input) throw new ARXError('NO_INPUT');
576
- console.log('Character.Service.getCharacterFactions', input);
577
-
578
- const characterFactions = await ctx.app.model.CharacterFaction.find(getFilter(input)).lean().exec();
579
-
580
- return characterFactions as CharacterFaction[];
581
- }
582
-
583
- async createCharacterFaction(
584
- input: RouterInput['createCharacterFaction'],
585
- ctx: RouterContext
586
- ): Promise<RouterOutput['createCharacterFaction']> {
587
- if (!input) throw new ARXError('NO_INPUT');
588
- console.log('Character.Service.createCharacterFaction', input);
589
-
590
- const characterFaction = await ctx.app.model.CharacterFaction.create(input);
591
- return characterFaction as CharacterFaction;
592
- }
593
-
594
- async updateCharacterFaction(
595
- input: RouterInput['updateCharacterFaction'],
596
- ctx: RouterContext
597
- ): Promise<RouterOutput['updateCharacterFaction']> {
598
- if (!input) throw new ARXError('NO_INPUT');
599
- console.log('Character.Service.updateCharacterFaction', input);
600
-
601
- const updatedCharacterFaction = await ctx.app.model.CharacterFaction.findByIdAndUpdate(
602
- getFilter(input).id,
603
- input.data,
604
- {
605
- new: true,
606
- }
607
- )
608
- .lean()
609
- .exec();
610
- if (!updatedCharacterFaction) throw new Error('CharacterFaction update failed');
611
-
612
- return updatedCharacterFaction as CharacterFaction;
613
- }
614
-
615
- async getCharacterGender(
616
- input: RouterInput['getCharacterGender'],
617
- ctx: RouterContext
618
- ): Promise<RouterOutput['getCharacterGender']> {
619
- if (!input) throw new ARXError('NO_INPUT');
620
- console.log('Character.Service.getCharacterGender', input);
621
-
622
- const characterGender = await ctx.app.model.CharacterGender.findById(getFilter(input).id).lean().exec();
623
- if (!characterGender) throw new Error('CharacterGender not found');
624
-
625
- return characterGender as CharacterGender;
626
- }
627
-
628
- async createCharacterGender(
629
- input: RouterInput['createCharacterGender'],
630
- ctx: RouterContext
631
- ): Promise<RouterOutput['createCharacterGender']> {
632
- if (!input) throw new ARXError('NO_INPUT');
633
- console.log('Character.Service.createCharacterGender', input);
634
-
635
- const characterGender = await ctx.app.model.CharacterGender.create(input);
636
- return characterGender as CharacterGender;
637
- }
638
-
639
- async updateCharacterGender(
640
- input: RouterInput['updateCharacterGender'],
641
- ctx: RouterContext
642
- ): Promise<RouterOutput['updateCharacterGender']> {
643
- if (!input) throw new ARXError('NO_INPUT');
644
- console.log('Character.Service.updateCharacterGender', input);
645
-
646
- const updatedCharacterGender = await ctx.app.model.CharacterGender.findByIdAndUpdate(
647
- getFilter(input).id,
648
- input.data,
649
- {
650
- new: true,
651
- }
652
- )
653
- .lean()
654
- .exec();
655
- if (!updatedCharacterGender) throw new Error('CharacterGender update failed');
656
-
657
- return updatedCharacterGender as CharacterGender;
658
- }
659
-
660
- async getCharacterNameChoice(
661
- input: RouterInput['getCharacterNameChoice'],
662
- ctx: RouterContext
663
- ): Promise<RouterOutput['getCharacterNameChoice']> {
664
- if (!input) throw new ARXError('NO_INPUT');
665
- console.log('Character.Service.getCharacterNameChoice', input);
666
-
667
- const characterNameChoice = await ctx.app.model.CharacterNameChoice.findById(getFilter(input).id).lean().exec();
668
- if (!characterNameChoice) throw new Error('CharacterNameChoice not found');
669
-
670
- return characterNameChoice as CharacterNameChoice;
671
- }
672
-
673
- async createCharacterNameChoice(
674
- input: RouterInput['createCharacterNameChoice'],
675
- ctx: RouterContext
676
- ): Promise<RouterOutput['createCharacterNameChoice']> {
677
- if (!input) throw new ARXError('NO_INPUT');
678
- console.log('Character.Service.createCharacterNameChoice', input);
679
-
680
- const characterNameChoice = await ctx.app.model.CharacterNameChoice.create(input);
681
- return characterNameChoice as CharacterNameChoice;
682
- }
683
-
684
- async updateCharacterNameChoice(
685
- input: RouterInput['updateCharacterNameChoice'],
686
- ctx: RouterContext
687
- ): Promise<RouterOutput['updateCharacterNameChoice']> {
688
- if (!input) throw new ARXError('NO_INPUT');
689
- console.log('Character.Service.updateCharacterNameChoice', input);
690
-
691
- const updatedCharacterNameChoice = await ctx.app.model.CharacterNameChoice.findByIdAndUpdate(
692
- getFilter(input).id,
693
- input.data,
694
- {
695
- new: true,
696
- }
697
- )
698
- .lean()
699
- .exec();
700
- if (!updatedCharacterNameChoice) throw new Error('CharacterNameChoice update failed');
701
-
702
- return updatedCharacterNameChoice as CharacterNameChoice;
703
- }
704
-
705
- async getCharacterPersonality(
706
- input: RouterInput['getCharacterPersonality'],
707
- ctx: RouterContext
708
- ): Promise<RouterOutput['getCharacterPersonality']> {
709
- if (!input) throw new ARXError('NO_INPUT');
710
- console.log('Character.Service.getCharacterPersonality', input);
711
-
712
- const characterPersonality = await ctx.app.model.CharacterPersonality.findById(getFilter(input).id).lean().exec();
713
- if (!characterPersonality) throw new Error('CharacterPersonality not found');
714
-
715
- return characterPersonality as CharacterPersonality;
716
- }
717
-
718
- async createCharacterPersonality(
719
- input: RouterInput['createCharacterPersonality'],
720
- ctx: RouterContext
721
- ): Promise<RouterOutput['createCharacterPersonality']> {
722
- if (!input) throw new ARXError('NO_INPUT');
723
- console.log('Character.Service.createCharacterPersonality', input);
724
-
725
- const characterPersonality = await ctx.app.model.CharacterPersonality.create(input);
726
- return characterPersonality as CharacterPersonality;
727
- }
728
-
729
- async updateCharacterPersonality(
730
- input: RouterInput['updateCharacterPersonality'],
731
- ctx: RouterContext
732
- ): Promise<RouterOutput['updateCharacterPersonality']> {
733
- if (!input) throw new ARXError('NO_INPUT');
734
- console.log('Character.Service.updateCharacterPersonality', input);
735
-
736
- const updatedCharacterPersonality = await ctx.app.model.CharacterPersonality.findByIdAndUpdate(
737
- getFilter(input).id,
738
- input.data,
739
- {
740
- new: true,
741
- }
742
- )
743
- .lean()
744
- .exec();
745
- if (!updatedCharacterPersonality) throw new Error('CharacterPersonality update failed');
746
-
747
- return updatedCharacterPersonality as CharacterPersonality;
748
- }
749
-
750
- async getCharacterRace(
751
- input: RouterInput['getCharacterRace'],
752
- ctx: RouterContext
753
- ): Promise<RouterOutput['getCharacterRace']> {
754
- if (!input) throw new ARXError('NO_INPUT');
755
- console.log('Character.Service.getCharacterRace', input);
756
-
757
- const characterRace = await ctx.app.model.CharacterRace.findById(getFilter(input).id).lean().exec();
758
- if (!characterRace) throw new Error('CharacterRace not found');
759
-
760
- return characterRace as CharacterRace;
761
- }
762
-
763
- async createCharacterRace(
764
- input: RouterInput['createCharacterRace'],
765
- ctx: RouterContext
766
- ): Promise<RouterOutput['createCharacterRace']> {
767
- if (!input) throw new ARXError('NO_INPUT');
768
- console.log('Character.Service.createCharacterRace', input);
769
-
770
- const characterRace = await ctx.app.model.CharacterRace.create(input);
771
- return characterRace as CharacterRace;
772
- }
773
-
774
- async updateCharacterRace(
775
- input: RouterInput['updateCharacterRace'],
776
- ctx: RouterContext
777
- ): Promise<RouterOutput['updateCharacterRace']> {
778
- if (!input) throw new ARXError('NO_INPUT');
779
- console.log('Character.Service.updateCharacterRace', input);
780
-
781
- const updatedCharacterRace = await ctx.app.model.CharacterRace.findByIdAndUpdate(getFilter(input).id, input.data, {
782
- new: true,
783
- })
784
- .lean()
785
- .exec();
786
- if (!updatedCharacterRace) throw new Error('CharacterRace update failed');
787
-
788
- return updatedCharacterRace as CharacterRace;
789
- }
790
-
791
- async getCharacterTitle(
792
- input: RouterInput['getCharacterTitle'],
793
- ctx: RouterContext
794
- ): Promise<RouterOutput['getCharacterTitle']> {
795
- if (!input) throw new ARXError('NO_INPUT');
796
- console.log('Character.Service.getCharacterTitle', input);
797
-
798
- const characterTitle = await ctx.app.model.CharacterTitle.findById(getFilter(input).id).lean().exec();
799
- if (!characterTitle) throw new Error('CharacterTitle not found');
800
-
801
- return characterTitle as CharacterTitle;
802
- }
803
-
804
- async createCharacterTitle(
805
- input: RouterInput['createCharacterTitle'],
806
- ctx: RouterContext
807
- ): Promise<RouterOutput['createCharacterTitle']> {
808
- if (!input) throw new ARXError('NO_INPUT');
809
- console.log('Character.Service.createCharacterTitle', input);
810
-
811
- const characterTitle = await ctx.app.model.CharacterTitle.create(input);
812
- return characterTitle as CharacterTitle;
813
- }
814
-
815
- async updateCharacterTitle(
816
- input: RouterInput['updateCharacterTitle'],
817
- ctx: RouterContext
818
- ): Promise<RouterOutput['updateCharacterTitle']> {
819
- if (!input) throw new ARXError('NO_INPUT');
820
- console.log('Character.Service.updateCharacterTitle', input);
821
-
822
- const updatedCharacterTitle = await ctx.app.model.CharacterTitle.findByIdAndUpdate(
823
- getFilter(input).id,
824
- input.data,
825
- {
826
- new: true,
827
- }
828
- )
829
- .lean()
830
- .exec();
831
- if (!updatedCharacterTitle) throw new Error('CharacterTitle update failed');
832
-
833
- return updatedCharacterTitle as CharacterTitle;
834
- }
835
-
836
- async getCharacterType(
837
- input: RouterInput['getCharacterType'],
838
- ctx: RouterContext
839
- ): Promise<RouterOutput['getCharacterType']> {
840
- if (!input) throw new ARXError('NO_INPUT');
841
- console.log('Character.Service.getCharacterType', input);
842
-
843
- const characterType = await ctx.app.model.CharacterType.findById(getFilter(input).id).lean().exec();
844
- if (!characterType) throw new Error('CharacterType not found');
845
-
846
- return characterType as CharacterType;
847
- }
848
-
849
- async createCharacterType(
850
- input: RouterInput['createCharacterType'],
851
- ctx: RouterContext
852
- ): Promise<RouterOutput['createCharacterType']> {
853
- if (!input) throw new ARXError('NO_INPUT');
854
- console.log('Character.Service.createCharacterType', input);
855
-
856
- const characterType = await ctx.app.model.CharacterType.create(input);
857
- return characterType as CharacterType;
858
- }
859
-
860
- async updateCharacterType(
861
- input: RouterInput['updateCharacterType'],
862
- ctx: RouterContext
863
- ): Promise<RouterOutput['updateCharacterType']> {
864
- if (!input) throw new ARXError('NO_INPUT');
865
- console.log('Character.Service.updateCharacterType', input);
866
-
867
- const updatedCharacterType = await ctx.app.model.CharacterType.findByIdAndUpdate(getFilter(input).id, input.data, {
868
- new: true,
869
- })
870
- .lean()
871
- .exec();
872
- if (!updatedCharacterType) throw new Error('CharacterType update failed');
873
-
874
- return updatedCharacterType as CharacterType;
875
- }
876
- }