@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,214 +0,0 @@
1
- // profile.models.ts
2
- //
3
- import * as mongo from '../../util/mongo';
4
- import type * as Types from './profile.types';
5
-
6
- const { addTagVirtuals, addApplicationVirtual } = mongo;
7
-
8
- const RankingStatSchema = new mongo.Schema(
9
- {
10
- total: { type: Number, required: true },
11
- position: { type: Number, required: true },
12
- },
13
- { _id: false }
14
- );
15
-
16
- const RankingSchema = new mongo.Schema(
17
- {
18
- orbs: { type: RankingStatSchema, required: true },
19
- wins: { type: RankingStatSchema, required: true },
20
- kills: { type: RankingStatSchema, required: true },
21
- deaths: { type: RankingStatSchema, required: true },
22
- points: { type: RankingStatSchema, required: true },
23
- rounds: { type: RankingStatSchema, required: true },
24
- evolves: { type: RankingStatSchema, required: true },
25
- rewards: { type: RankingStatSchema, required: true },
26
- powerups: { type: RankingStatSchema, required: true },
27
- revenges: { type: RankingStatSchema, required: true },
28
- winRatio: { type: RankingStatSchema, required: true },
29
- timeSpent: { type: RankingStatSchema, required: true },
30
- averageLatency: { type: RankingStatSchema, required: true },
31
- killDeathRatio: { type: RankingStatSchema, required: true },
32
- roundPointRatio: { type: RankingStatSchema, required: true },
33
- },
34
- { _id: false }
35
- );
36
-
37
- const ServerDataSchema = new mongo.Schema(
38
- {
39
- orbs: { type: Number },
40
- wins: { type: Number },
41
- kills: { type: Number },
42
- deaths: { type: Number },
43
- points: { type: Number },
44
- rounds: { type: Number },
45
- evolves: { type: Number },
46
- ranking: { type: RankingSchema },
47
- rewards: { type: Number },
48
- earnings: { type: Number },
49
- powerups: { type: Number },
50
- revenges: { type: Number },
51
- winRatio: { type: Number },
52
- timeSpent: { type: Number },
53
- winStreak: { type: Number },
54
- averageLatency: { type: Number, default: null },
55
- killDeathRatio: { type: Number },
56
- roundPointRatio: { type: Number },
57
- },
58
- { _id: false }
59
- );
60
-
61
- const EvolutionSchema = new mongo.Schema(
62
- {
63
- hashes: [{ type: String }],
64
- overall: {
65
- orbs: { type: Number },
66
- wins: { type: Number },
67
- kills: { type: Number },
68
- deaths: { type: Number },
69
- points: { type: Number },
70
- rounds: { type: Number },
71
- evolves: { type: Number },
72
- ranking: { type: RankingSchema },
73
- rewards: { type: Number },
74
- earnings: { type: Number },
75
- powerups: { type: Number },
76
- revenges: { type: Number },
77
- winRatio: { type: Number },
78
- timeSpent: { type: Number },
79
- winStreak: { type: Number },
80
- averageLatency: { type: Number },
81
- killDeathRatio: { type: Number },
82
- roundPointRatio: { type: Number },
83
- },
84
- servers: { type: Map, of: ServerDataSchema },
85
- lastUpdated: { type: Number },
86
- },
87
- { _id: false }
88
- );
89
-
90
- // StatsSchema
91
- const StatsSchema = new mongo.Schema(
92
- {
93
- gamesOwned: { type: Number, default: 0 },
94
- playedMinutes: { type: Number, default: 0 },
95
- leveledUpCount: { type: Number, default: 0 },
96
- xpEarnedCount: { type: Number, default: 0 },
97
- craftedItemCount: { type: Number, default: 0 },
98
- equippedItemCount: { type: Number, default: 0 },
99
- transferredInCount: { type: Number, default: 0 },
100
- transferredOutCount: { type: Number, default: 0 },
101
- marketTradeSoldCount: { type: Number, default: 0 },
102
- marketTradeListedCount: { type: Number, default: 0 },
103
- evolution: { type: EvolutionSchema },
104
- },
105
- { _id: false }
106
- );
107
-
108
- const SettingsSchema = new mongo.Schema(
109
- {
110
- warp: { type: mongo.Schema.Types.Mixed, default: {} },
111
- designer: { type: mongo.Schema.Types.Mixed, default: {} },
112
- privacy: {
113
- type: String,
114
- enum: ['public', 'private', 'friends-only'],
115
- default: 'public',
116
- },
117
- notifications: { type: Boolean, default: true },
118
- },
119
- { _id: false }
120
- );
121
-
122
- // const CharacterSubSchema = new mongo.Schema(
123
- // {
124
- // characterId: { type: mongo.Schema.Types.ObjectId, ref: 'Character', required: true, autopopulate: true },
125
- // meta: { type: mongo.Schema.Types.Mixed, default: {} },
126
- // },
127
- // { _id: false }
128
- // );
129
-
130
- // CharacterSubSchema.virtual('character', {
131
- // ref: 'Character', // The model to use
132
- // localField: 'characterId', // Find in `Character` where `_id` matches `characterId`
133
- // foreignField: '_id',
134
- // justOne: true, // Since `characterId` is a single reference
135
- // });
136
-
137
- export const Profile = mongo.createModel<Types.ProfileDocument>(
138
- 'Profile',
139
- {
140
- accountId: { type: mongo.Schema.Types.ObjectId, ref: 'Account', required: true },
141
- points: { type: Number, default: 0 },
142
- // coins: { type: Number, default: 0 },
143
- telegramUserId: { type: Number },
144
- interactions: { type: Number, default: 0 },
145
- activityRating: { type: Number, default: 0 },
146
- address: { type: String, maxlength: 100 },
147
- avatar: { type: String, maxlength: 100 },
148
- roleId: { type: mongo.Schema.Types.ObjectId, ref: 'Role' },
149
- privateKey: { type: String, maxlength: 300 },
150
- signature: { type: String, maxlength: 200 },
151
- chainId: { type: mongo.Schema.Types.ObjectId, ref: 'Chain' },
152
- teamId: { type: mongo.Schema.Types.ObjectId, ref: 'Team' },
153
- characterId: { type: mongo.Schema.Types.ObjectId, ref: 'Character' },
154
- partyId: { type: mongo.Schema.Types.ObjectId, ref: 'Party' },
155
- isBanned: { type: Boolean },
156
- banExpireDate: { type: Date },
157
- banReason: { type: String },
158
- bio: { type: String },
159
- banner: { type: String },
160
- mode: { type: String, default: 'gamer' },
161
- friends: [
162
- {
163
- profileId: { type: mongo.Schema.Types.ObjectId, ref: 'Profile', required: true },
164
- meta: { type: mongo.Schema.Types.Mixed, default: {} },
165
- },
166
- ],
167
- badges: [
168
- {
169
- badgeId: { type: mongo.Schema.Types.ObjectId, ref: 'Badge', required: true },
170
- meta: { type: mongo.Schema.Types.Mixed, default: {} },
171
- },
172
- ],
173
- settings: SettingsSchema,
174
- stats: StatsSchema,
175
- achievements: [
176
- {
177
- achievementId: { type: mongo.Schema.Types.ObjectId, ref: 'Achievement', required: true },
178
- meta: { type: mongo.Schema.Types.Mixed, default: {} },
179
- current: { type: Number, default: 0 },
180
- },
181
- ],
182
- },
183
- {
184
- virtuals: [
185
- ...addTagVirtuals('Profile'),
186
- ...addApplicationVirtual(),
187
- {
188
- name: 'character',
189
- },
190
- {
191
- name: 'characters',
192
- ref: 'Character',
193
- localField: '_id',
194
- foreignField: 'ownerId',
195
- },
196
- {
197
- name: 'chain',
198
- },
199
- {
200
- name: 'role',
201
- },
202
- {
203
- name: 'account',
204
- },
205
- {
206
- name: 'team',
207
- },
208
- ],
209
- indexes: [
210
- { applicationId: 1, telegramUserId: 1, unique: true },
211
- { applicationId: 1, accountId: 1, name: 1, unique: true },
212
- ],
213
- }
214
- );
@@ -1,72 +0,0 @@
1
- import { z as zod } from 'zod';
2
- import { initTRPC, inferRouterInputs } from '@trpc/server';
3
- import { customErrorFormatter, hasRole } from '../../util/rpc';
4
- import type { RouterContext } from '../../types';
5
- import { Profile } from './profile.schema';
6
- import { Query, getQueryInput, getQueryOutput, inferRouterOutputs } from '../../schema';
7
-
8
- export const z = zod;
9
- export const t = initTRPC.context<RouterContext>().create();
10
- export const router = t.router;
11
- export const procedure = t.procedure;
12
-
13
- export const createRouter = () =>
14
- router({
15
- setProfileMode: procedure
16
- .use(hasRole('user', t))
17
- .use(customErrorFormatter(t))
18
- .input(z.string())
19
- .mutation(({ input, ctx }) => (ctx.app.service.Profile.setProfileMode as any)(input, ctx)),
20
-
21
- // Profile endpoints
22
- me: procedure
23
- .use(hasRole('user', t))
24
- .use(customErrorFormatter(t))
25
- // .output(Profile.partial())
26
- .query(({ input, ctx }) => (ctx.app.service.Profile.me as any)(input, ctx)),
27
-
28
- // Profile endpoints
29
- getProfile: procedure
30
- .use(hasRole('guest', t))
31
- .use(customErrorFormatter(t))
32
- .input(getQueryInput(Profile))
33
- // .output(Profile.partial())
34
- .query(({ input, ctx }) => (ctx.app.service.Profile.getProfile as any)(input, ctx)),
35
-
36
- getProfiles: procedure
37
- .use(hasRole('guest', t))
38
- .use(customErrorFormatter(t))
39
- .input(getQueryInput(Profile))
40
- .output(z.array(Profile))
41
- .query(({ input, ctx }) => (ctx.app.service.Profile.getProfiles as any)(input, ctx)),
42
-
43
- createProfile: procedure
44
- .use(hasRole('user', t))
45
- .use(customErrorFormatter(t))
46
- .input(getQueryInput(Profile))
47
- .output(Profile.partial())
48
- .mutation(({ input, ctx }) => (ctx.app.service.Profile.createProfile as any)(input, ctx)),
49
-
50
- updateProfile: procedure
51
- .use(hasRole('user', t))
52
- .use(customErrorFormatter(t))
53
- .input(getQueryInput(Profile))
54
- .output(Profile.partial())
55
- .mutation(({ input, ctx }) => (ctx.app.service.Profile.updateProfile as any)(input, ctx)),
56
-
57
- getProfileStats: procedure
58
- .use(hasRole('guest', t))
59
- .use(customErrorFormatter(t))
60
- .input(z.object({ query: Query }))
61
- .query(({ input, ctx }) => (ctx.app.service.Profile.getProfileStats as any)(input, ctx)),
62
-
63
- updateProfileSettings: procedure
64
- .use(hasRole('user', t))
65
- .use(customErrorFormatter(t))
66
- .input(z.object({ query: Query, settings: Profile.shape.settings }))
67
- .mutation(({ input, ctx }) => (ctx.app.service.Profile.updateProfileSettings as any)(input, ctx)),
68
- });
69
-
70
- export type Router = ReturnType<typeof createRouter>;
71
- export type RouterInput = inferRouterInputs<Router>;
72
- export type RouterOutput = inferRouterOutputs<Router>;
@@ -1,156 +0,0 @@
1
- // profile.schema.ts
2
- //
3
- import { z, ObjectId, Entity } from '../../schema';
4
- import { Character } from '../character/character.schema';
5
- import { Achievement, Badge } from '../core/core.schema';
6
-
7
- const RankingStatSchema = z.object({
8
- total: z.number(),
9
- position: z.number(),
10
- });
11
-
12
- // Define the Ranking schema
13
- const RankingSchema = z.object({
14
- orbs: RankingStatSchema,
15
- wins: RankingStatSchema,
16
- kills: RankingStatSchema,
17
- deaths: RankingStatSchema,
18
- points: RankingStatSchema,
19
- rounds: RankingStatSchema,
20
- evolves: RankingStatSchema,
21
- rewards: RankingStatSchema,
22
- powerups: RankingStatSchema,
23
- revenges: RankingStatSchema,
24
- winRatio: RankingStatSchema,
25
- timeSpent: RankingStatSchema,
26
- averageLatency: RankingStatSchema,
27
- killDeathRatio: RankingStatSchema,
28
- roundPointRatio: RankingStatSchema,
29
- });
30
-
31
- const ServerDataSchema = z.object({
32
- orbs: z.number().optional(),
33
- wins: z.number().optional(),
34
- kills: z.number().optional(),
35
- deaths: z.number().optional(),
36
- points: z.number().optional(),
37
- rounds: z.number().optional(),
38
- evolves: z.number().optional(),
39
- ranking: RankingSchema.optional(),
40
- rewards: z.number().optional(),
41
- earnings: z.number().optional(),
42
- powerups: z.number().optional(),
43
- revenges: z.number().optional(),
44
- winRatio: z.number().optional(),
45
- timeSpent: z.number().optional(),
46
- winStreak: z.number().optional(),
47
- averageLatency: z.number().nullable().optional(),
48
- killDeathRatio: z.number().optional(),
49
- roundPointRatio: z.number().optional(),
50
- });
51
-
52
- // Profile schema for a user on a digital game platform
53
- export const Profile = Entity.merge(
54
- z.object({
55
- accountId: ObjectId.optional(), // TODO; fix?
56
- partyId: ObjectId.optional(),
57
- points: z.number().optional(),
58
- // currency: z.number().optional(),
59
- telegramUserId: z.number().optional(),
60
- interactions: z.number().default(0),
61
- activityRating: z.number().default(0),
62
- address: z.string().max(100).optional(),
63
- avatar: z.string().max(100).optional(),
64
- roleId: ObjectId.optional(),
65
- privateKey: z.string().max(300).optional(),
66
- signature: z.string().max(200).optional(),
67
- chainId: ObjectId.optional(),
68
- teamId: ObjectId.optional(),
69
- characterId: ObjectId.optional(),
70
- isBanned: z.boolean().optional(),
71
- banExpireDate: z.date().optional(),
72
- banReason: z.string().optional(),
73
- mode: z.string().default('gamer').optional(),
74
-
75
- bio: z.string().optional(),
76
- banner: z.string().url().optional(), // URL to the user's banner image
77
- friends: z
78
- .array(
79
- z.object({
80
- friend: z.lazy(() => Profile),
81
- meta: z.any().optional(),
82
- })
83
- )
84
- .optional(),
85
- achievements: z
86
- .array(
87
- z.object({
88
- achievementId: ObjectId,
89
- meta: z.any().optional(),
90
- current: z.number().default(0),
91
- })
92
- )
93
- .optional(),
94
- badges: z
95
- .array(
96
- z.object({
97
- badgeId: ObjectId,
98
- meta: z.any().optional(),
99
- })
100
- )
101
- .optional(),
102
- character: Character.optional(),
103
- characters: z.array(ObjectId.optional()).optional(),
104
- settings: z
105
- .object({
106
- warp: z.any().default({}),
107
- designer: z.any().default({}),
108
- privacy: z.enum(['public', 'private', 'friends-only']).default('public'),
109
- notifications: z.boolean().default(true),
110
- })
111
- .optional(),
112
- stats: z
113
- .object({
114
- gamesOwned: z.number().int().nonnegative().default(0),
115
- playedMinutes: z.number().nonnegative().default(0), // Total playtime in hours
116
- leveledUpCount: z.number().int().nonnegative().default(0),
117
- xpEarnedCount: z.number().int().nonnegative().default(0),
118
- craftedItemCount: z.number().int().nonnegative().default(0),
119
- equippedItemCount: z.number().int().nonnegative().default(0),
120
- transferredInCount: z.number().int().nonnegative().default(0),
121
- transferredOutCount: z.number().int().nonnegative().default(0),
122
- marketTradeSoldCount: z.number().int().nonnegative().default(0),
123
- marketTradeListedCount: z.number().int().nonnegative().default(0),
124
- evolution: z
125
- .object({
126
- hashes: z.array(z.string()).default([]),
127
- overall: z
128
- .object({
129
- orbs: z.number().optional(),
130
- wins: z.number().optional(),
131
- kills: z.number().optional(),
132
- deaths: z.number().optional(),
133
- points: z.number().optional(),
134
- rounds: z.number().optional(),
135
- evolves: z.number().optional(),
136
- ranking: RankingSchema.optional(),
137
- rewards: z.number().optional(),
138
- earnings: z.number().optional(),
139
- powerups: z.number().optional(),
140
- revenges: z.number().optional(),
141
- winRatio: z.number().optional(),
142
- timeSpent: z.number().optional(),
143
- winStreak: z.number().optional(),
144
- averageLatency: z.number().optional().nullable(),
145
- killDeathRatio: z.number().optional(),
146
- roundPointRatio: z.number().optional(),
147
- })
148
- .default({}),
149
- servers: z.record(ServerDataSchema).optional(),
150
- lastUpdated: z.number().optional(),
151
- })
152
- .optional(),
153
- })
154
- .optional(),
155
- })
156
- );
@@ -1,149 +0,0 @@
1
- import type { Profile, RouterContext, RouterInput, RouterOutput } from './profile.types';
2
- import { ARXError } from '../../util/rpc';
3
- import { getFilter } from '../../util/api';
4
- import { deepMerge } from '../../util/object';
5
-
6
- export class Service {
7
- async setProfileMode(
8
- input: RouterInput['setProfileMode'],
9
- ctx: RouterContext
10
- ): Promise<RouterOutput['setProfileMode']> {
11
- if (!input) throw new ARXError('NO_INPUT');
12
- console.log('Profile.Service.setProfileMode', input);
13
-
14
- ctx.client.profile.mode = input;
15
-
16
- // @ts-ignore
17
- await ctx.client.profile.save();
18
- }
19
-
20
- async me(input: RouterInput['me'], ctx: RouterContext): Promise<RouterOutput['me']> {
21
- return {
22
- id: ctx.client.profile.id,
23
- address: ctx.client.profile.address,
24
- name: ctx.client.profile.name,
25
- points: ctx.client.profile.points,
26
- status: ctx.client.profile.status,
27
- isBanned: ctx.client.profile.isBanned,
28
- banExpireDate: ctx.client.profile.banExpireDate,
29
- banReason: ctx.client.profile.banReason,
30
- mode: ctx.client.profile.mode,
31
- settings: ctx.client.profile.settings,
32
- roles: ctx.client.roles,
33
- permissions: ctx.client.permissions,
34
- data: ctx.client.profile.data,
35
- meta: {
36
- rewards: ctx.client.profile.meta.rewards,
37
- evolution: {
38
- settings: {
39
- zoom: ctx.client.profile.meta?.evolution?.settings?.zoom || 0.7,
40
- opacity: ctx.client.profile.meta?.evolution?.settings?.opacity || 1,
41
- },
42
- },
43
- },
44
- };
45
- }
46
-
47
- async getProfile(input: RouterInput['getProfile'], ctx: RouterContext): Promise<RouterOutput['getProfile']> {
48
- if (!input) throw new ARXError('NO_INPUT');
49
- console.log('Profile.Service.getProfile', input);
50
-
51
- const filter = getFilter(input);
52
- const profile = await ctx.app.model.Profile.findOne(filter).lean().exec();
53
- if (!profile) throw new ARXError('NOT_FOUND');
54
-
55
- // @ts-ignore
56
- if (profile?.meta?.market?.trades) delete profile?.meta?.market?.trades;
57
-
58
- return profile as Profile;
59
- }
60
-
61
- async getProfiles(input: RouterInput['getProfiles'], ctx: RouterContext): Promise<RouterOutput['getProfiles']> {
62
- if (!input) throw new ARXError('NO_INPUT');
63
- console.log('Profile.Service.getProfiles', input);
64
-
65
- const filter = getFilter(input);
66
- // const profiles = await ctx.app.model.Profile.find(filter).populate('character', 'characters').exec();
67
-
68
- const profiles = await ctx.app.model.Profile.aggregate([
69
- { $limit: input.limit || 10 },
70
- {
71
- $lookup: {
72
- from: 'Character',
73
- localField: 'characterId',
74
- foreignField: '_id',
75
- as: 'character',
76
- },
77
- },
78
- { $unwind: '$character' },
79
- {
80
- $lookup: {
81
- from: 'Character',
82
- localField: '_id',
83
- foreignField: 'profileId',
84
- as: 'characters',
85
- },
86
- },
87
- { $unwind: '$characters' },
88
- ]);
89
-
90
- return profiles as Profile[];
91
- }
92
-
93
- async createProfile(input: RouterInput['createProfile'], ctx: RouterContext): Promise<RouterOutput['createProfile']> {
94
- if (!input) throw new ARXError('NO_INPUT');
95
- console.log('Profile.Service.createProfile', input.data);
96
-
97
- const profile = await ctx.app.model.Profile.create(input.data);
98
- return profile as Profile;
99
- }
100
-
101
- async updateProfile(input: RouterInput['updateProfile'], ctx: RouterContext): Promise<RouterOutput['updateProfile']> {
102
- if (!input) throw new ARXError('NO_INPUT');
103
- console.log('Profile.Service.updateProfile', input, input.data);
104
-
105
- const filter = getFilter(input);
106
- const updatedProfile = await ctx.app.model.Profile.findOneAndUpdate(filter, input.data, { new: true })
107
- .lean()
108
- .exec();
109
- if (!updatedProfile) throw new ARXError('INTERNAL_SERVER_ERROR');
110
-
111
- // @ts-ignore
112
- return updatedProfile as Profile;
113
- }
114
-
115
- async getProfileStats(
116
- input: RouterInput['getProfileStats'],
117
- ctx: RouterContext
118
- ): Promise<RouterOutput['getProfileStats']> {
119
- if (!input) throw new ARXError('NO_INPUT');
120
- console.log('Profile.Service.getProfileStats', input);
121
-
122
- const filter = getFilter(input);
123
- const profile: Profile = await ctx.app.model.Profile.findOne(filter).lean().exec();
124
- if (!profile) throw new ARXError('NOT_FOUND');
125
-
126
- return profile.stats;
127
- }
128
-
129
- async updateProfileSettings(
130
- input: RouterInput['updateProfileSettings'],
131
- ctx: RouterContext
132
- ): Promise<RouterOutput['updateProfileSettings']> {
133
- if (!input) throw new ARXError('NO_INPUT');
134
- console.log('Profile.Service.updateProfileSettings', input, input.settings);
135
-
136
- const filter = getFilter(input);
137
- // @ts-ignore
138
- const updatedProfile: Profile = await ctx.app.model.Profile.findOneAndUpdate(
139
- filter,
140
- { settings: deepMerge(ctx.client.profile.settings, input.settings) },
141
- { new: true }
142
- )
143
- .lean()
144
- .exec();
145
- if (!updatedProfile) throw new ARXError('INTERNAL_SERVER_ERROR');
146
-
147
- return updatedProfile.settings;
148
- }
149
- }
@@ -1,22 +0,0 @@
1
- // profile.types.ts
2
- //
3
- import { z } from 'zod';
4
- import * as schema from './profile.schema';
5
- import { Document, Model } from '../../util/mongo';
6
- import type { RouterContext } from '../../types';
7
- import type { inferRouterInputs, inferRouterOutputs } from '@trpc/server';
8
- import type { Router } from './profile.router';
9
-
10
- export type * from './profile.router';
11
- export type * from './profile.service';
12
- export type { RouterContext };
13
-
14
- export type Profile = z.infer<typeof schema.Profile>;
15
- export type ProfileDocument = Profile & Document;
16
-
17
- export type Mappings = {
18
- Profile: Model<ProfileDocument>;
19
- };
20
-
21
- export type RouterInput = inferRouterInputs<Router>;
22
- export type RouterOutput = inferRouterOutputs<Router>;
@@ -1,5 +0,0 @@
1
- export * as Types from './raffle.types';
2
- export * as Models from './raffle.models';
3
- export * as Schemas from './raffle.schema';
4
- export * from './raffle.router';
5
- export * from './raffle.service';
@@ -1,44 +0,0 @@
1
- import * as mongo from '../../util/mongo';
2
- import type * as Types from './raffle.types';
3
-
4
- export const Raffle = mongo.createModel<Types.RaffleDocument>(
5
- 'Raffle',
6
- {
7
- content: { type: String, required: true },
8
- rewards: [{ type: mongo.Schema.Types.ObjectId, ref: 'RaffleReward' }],
9
- },
10
- {
11
- virtuals: [
12
- {
13
- name: 'raffleRequirements',
14
- ref: 'RaffleRequirement',
15
- localField: '_id',
16
- foreignField: 'raffleId',
17
- },
18
- {
19
- name: 'raffleEntries',
20
- ref: 'RaffleEntry',
21
- localField: '_id',
22
- foreignField: 'raffleId',
23
- },
24
- ],
25
- }
26
- );
27
-
28
- export const RaffleRequirement = mongo.createModel<Types.RaffleRequirementDocument>('RaffleRequirement', {
29
- amount: { type: Number, required: true },
30
- raffleRewardId: { type: mongo.Schema.Types.ObjectId, ref: 'RaffleReward' },
31
- });
32
-
33
- export const RaffleReward = mongo.createModel<Types.RaffleRewardDocument>('RaffleReward', {
34
- raffleId: { type: mongo.Schema.Types.ObjectId, ref: 'Raffle' },
35
- winnerId: { type: mongo.Schema.Types.ObjectId, ref: 'Profile' },
36
- requirements: [{ type: mongo.Schema.Types.ObjectId, ref: 'RaffleRequirement' }],
37
- entries: [{ type: mongo.Schema.Types.ObjectId, ref: 'RaffleEntry' }],
38
- });
39
-
40
- export const RaffleEntry = mongo.createModel<Types.RaffleEntryDocument>('RaffleEntry', {
41
- amount: { type: Number, required: true },
42
- raffleRewardId: { type: mongo.Schema.Types.ObjectId, ref: 'RaffleReward' },
43
- raffleId: { type: mongo.Schema.Types.ObjectId, ref: 'Raffle' },
44
- });