@arken/seer-protocol 0.1.1 → 0.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (118) hide show
  1. package/.rush/temp/shrinkwrap-deps.json +778 -53
  2. package/area/area.models.ts +15 -0
  3. package/area/area.router.ts +74 -0
  4. package/area/area.schema.ts +22 -0
  5. package/area/area.types.ts +25 -0
  6. package/area/index.ts +4 -0
  7. package/asset/asset.models.ts +59 -0
  8. package/asset/asset.router.ts +55 -0
  9. package/asset/asset.schema.ts +30 -0
  10. package/asset/asset.types.ts +21 -0
  11. package/asset/index.ts +4 -0
  12. package/chain/chain.models.ts +50 -0
  13. package/chain/chain.router.ts +104 -0
  14. package/chain/chain.schema.ts +67 -0
  15. package/chain/chain.types.ts +23 -0
  16. package/chain/index.ts +4 -0
  17. package/character/character.models.ts +174 -0
  18. package/character/character.router.ts +314 -0
  19. package/character/character.schema.ts +150 -0
  20. package/character/character.types.ts +63 -0
  21. package/character/index.ts +4 -0
  22. package/chat/chat.models.ts +43 -0
  23. package/chat/chat.router.ts +67 -0
  24. package/chat/chat.schema.ts +39 -0
  25. package/chat/chat.types.ts +19 -0
  26. package/chat/index.ts +4 -0
  27. package/collection/collection.models.ts +76 -0
  28. package/collection/collection.router.ts +91 -0
  29. package/collection/collection.schema.ts +90 -0
  30. package/collection/collection.types.ts +35 -0
  31. package/collection/index.ts +4 -0
  32. package/core/core.models.ts +1380 -0
  33. package/core/core.router.ts +1781 -0
  34. package/core/core.schema.ts +940 -0
  35. package/core/core.types.ts +339 -0
  36. package/core/index.ts +4 -0
  37. package/evolution/evolution.models.ts +1 -1
  38. package/evolution/evolution.router.ts +19 -19
  39. package/evolution/evolution.schema.ts +1 -1
  40. package/evolution/evolution.types.ts +2 -3
  41. package/evolution/index.ts +0 -1
  42. package/game/game.models.ts +53 -0
  43. package/game/game.router.ts +110 -0
  44. package/game/game.schema.ts +23 -0
  45. package/game/game.types.ts +27 -0
  46. package/game/index.ts +4 -0
  47. package/index.ts +43 -6
  48. package/infinite/index.ts +0 -1
  49. package/infinite/infinite.models.ts +1 -1
  50. package/infinite/infinite.router.ts +9 -9
  51. package/infinite/infinite.schema.ts +1 -1
  52. package/infinite/infinite.types.ts +2 -3
  53. package/interface/index.ts +4 -0
  54. package/interface/interface.canonicalize.ts +279 -0
  55. package/interface/interface.models.ts +40 -0
  56. package/interface/interface.router.ts +175 -0
  57. package/interface/interface.schema.ts +59 -0
  58. package/interface/interface.types.ts +24 -0
  59. package/isles/index.ts +0 -1
  60. package/isles/isles.models.ts +1 -1
  61. package/isles/isles.router.ts +9 -9
  62. package/isles/isles.schema.ts +1 -1
  63. package/isles/isles.types.ts +2 -3
  64. package/item/index.ts +4 -0
  65. package/item/item.models.ts +124 -0
  66. package/item/item.router.ts +103 -0
  67. package/item/item.schema.ts +150 -0
  68. package/item/item.types.ts +73 -0
  69. package/job/index.ts +4 -0
  70. package/job/job.models.ts +14 -0
  71. package/job/job.router.ts +44 -0
  72. package/job/job.schema.ts +9 -0
  73. package/job/job.types.ts +22 -0
  74. package/market/index.ts +4 -0
  75. package/market/market.models.ts +113 -0
  76. package/market/market.router.ts +73 -0
  77. package/market/market.schema.ts +149 -0
  78. package/market/market.types.ts +55 -0
  79. package/oasis/index.ts +0 -1
  80. package/oasis/oasis.models.ts +1 -1
  81. package/oasis/oasis.router.ts +5 -6
  82. package/oasis/oasis.schema.ts +1 -1
  83. package/oasis/oasis.types.ts +2 -3
  84. package/package.json +17 -4
  85. package/product/index.ts +4 -0
  86. package/product/product.models.ts +166 -0
  87. package/product/product.router.ts +93 -0
  88. package/product/product.schema.ts +186 -0
  89. package/product/product.types.ts +32 -0
  90. package/profile/index.ts +4 -0
  91. package/profile/profile.models.ts +214 -0
  92. package/profile/profile.router.ts +72 -0
  93. package/profile/profile.schema.ts +219 -0
  94. package/profile/profile.types.ts +21 -0
  95. package/raffle/index.ts +4 -0
  96. package/raffle/raffle.models.ts +44 -0
  97. package/raffle/raffle.router.ts +90 -0
  98. package/raffle/raffle.schema.ts +32 -0
  99. package/raffle/raffle.types.ts +29 -0
  100. package/router.ts +23 -29
  101. package/schema.ts +321 -0
  102. package/skill/index.ts +4 -0
  103. package/skill/skill.models.ts +16 -0
  104. package/skill/skill.router.ts +201 -0
  105. package/skill/skill.schema.ts +52 -0
  106. package/skill/skill.types.ts +32 -0
  107. package/trek/index.ts +0 -1
  108. package/trek/trek.models.ts +1 -1
  109. package/trek/trek.router.ts +2 -2
  110. package/trek/trek.schema.ts +1 -1
  111. package/trek/trek.types.ts +1 -1
  112. package/tsconfig.json +25 -17
  113. package/types.ts +174 -26
  114. package/video/index.ts +4 -0
  115. package/video/video.models.ts +25 -0
  116. package/video/video.router.ts +143 -0
  117. package/video/video.schema.ts +46 -0
  118. package/video/video.types.ts +32 -0
@@ -0,0 +1,166 @@
1
+ import * as mongo from '@arken/node/mongo';
2
+ import type * as Types from './product.types';
3
+
4
+ export const Product = mongo.createModel<Types.ProductDocument>(
5
+ 'Product',
6
+ {
7
+ shortDescription: { type: String, maxlength: 300, required: false },
8
+ content: { type: String, required: false },
9
+ communityId: { type: mongo.Schema.Types.ObjectId, ref: 'Community', required: false },
10
+ type: { type: String, default: 'game', maxlength: 100 },
11
+ releaseDate: { type: Date },
12
+
13
+ // New fields from Objection.js model
14
+ parentId: { type: mongo.Schema.Types.ObjectId, ref: 'Product' },
15
+ score: { type: Number },
16
+ ownerId: { type: mongo.Schema.Types.ObjectId, ref: 'Profile' },
17
+ ratingId: { type: mongo.Schema.Types.ObjectId, ref: 'Rating' },
18
+ ideaId: { type: mongo.Schema.Types.ObjectId, ref: 'Idea' },
19
+ meta: {
20
+ name: String,
21
+ members: [{ type: mongo.Schema.Types.ObjectId, ref: 'Profile' }],
22
+ isProposal: Boolean,
23
+ price: Number,
24
+ oldPrice: Number,
25
+ images: Object,
26
+ video: String,
27
+ genre: String,
28
+ releaseDate: String,
29
+ developer: String,
30
+ publisher: String,
31
+ developerTags: [String],
32
+ languageSupport: [Object], // Adjust as needed
33
+ systemRequirements: [Object], // Adjust as needed
34
+ tags: [{ type: mongo.Schema.Types.ObjectId, ref: 'Tag' }],
35
+ type: String,
36
+ downloads: Number,
37
+ plans: [Object], // Adjust as needed
38
+ frequentlyTradedAssets: [{ type: mongo.Schema.Types.ObjectId, ref: 'Asset' }],
39
+ saleBox: Object,
40
+ assets: [{ type: mongo.Schema.Types.ObjectId, ref: 'Asset' }],
41
+ community: Object,
42
+ nameUrl: String,
43
+ steamId: Number,
44
+ author: String,
45
+ },
46
+ },
47
+ {
48
+ virtuals: [
49
+ {
50
+ name: 'projects',
51
+ ref: 'Project',
52
+ localField: '_id',
53
+ foreignField: 'productId',
54
+ },
55
+ {
56
+ name: 'leaderboards',
57
+ ref: 'Leaderboard',
58
+ localField: '_id',
59
+ foreignField: 'productId',
60
+ },
61
+ {
62
+ name: 'games',
63
+ ref: 'Game',
64
+ localField: '_id',
65
+ foreignField: 'productId',
66
+ },
67
+ {
68
+ name: 'productUpdates',
69
+ ref: 'ProductUpdate',
70
+ localField: '_id',
71
+ foreignField: 'productId',
72
+ },
73
+ // Adding missing relations as virtuals
74
+ {
75
+ name: 'owner',
76
+ ref: 'Profile',
77
+ localField: 'ownerId',
78
+ foreignField: '_id',
79
+ justOne: true,
80
+ },
81
+ {
82
+ name: 'rating',
83
+ ref: 'Rating',
84
+ localField: 'ratingId',
85
+ foreignField: '_id',
86
+ justOne: true,
87
+ },
88
+ {
89
+ name: 'community',
90
+ ref: 'Community',
91
+ localField: 'communityId',
92
+ foreignField: '_id',
93
+ justOne: true,
94
+ },
95
+ {
96
+ name: 'idea',
97
+ ref: 'Idea',
98
+ localField: 'ideaId',
99
+ foreignField: '_id',
100
+ justOne: true,
101
+ },
102
+ {
103
+ name: 'subproducts',
104
+ ref: 'Product',
105
+ localField: '_id',
106
+ foreignField: 'parentId',
107
+ },
108
+ {
109
+ name: 'servers',
110
+ ref: 'Server',
111
+ localField: '_id',
112
+ foreignField: 'productId',
113
+ },
114
+ // {
115
+ // name: 'votes',
116
+ // ref: 'Vote',
117
+ // localField: '_id',
118
+ // foreignField: 'productId',
119
+ // through: {
120
+ // from: 'nodes.toProductId',
121
+ // to: 'nodes.fromVoteId',
122
+ // extra: ['relationKey'],
123
+ // },
124
+ // },
125
+ // {
126
+ // name: 'files',
127
+ // ref: 'File',
128
+ // localField: '_id',
129
+ // foreignField: 'productId',
130
+ // through: {
131
+ // from: 'nodes.fromProductId',
132
+ // to: 'nodes.toFileId',
133
+ // extra: ['relationKey'],
134
+ // },
135
+ // },
136
+ // {
137
+ // name: 'tags',
138
+ // ref: 'Tag',
139
+ // localField: '_id',
140
+ // foreignField: 'productId',
141
+ // through: {
142
+ // from: 'nodes.fromProductId',
143
+ // to: 'nodes.toTagId',
144
+ // extra: ['relationKey'],
145
+ // },
146
+ // },
147
+ // {
148
+ // name: 'internalTags',
149
+ // ref: 'Tag',
150
+ // localField: '_id',
151
+ // foreignField: 'productId',
152
+ // through: {
153
+ // from: 'nodes.fromProductId',
154
+ // to: 'nodes.toTagId',
155
+ // extra: ['relationKey'],
156
+ // },
157
+ // },
158
+ ],
159
+ }
160
+ );
161
+
162
+ export const ProductUpdate = mongo.createModel<Types.ProductUpdateDocument>('ProductUpdate', {
163
+ productId: { type: mongo.Schema.Types.ObjectId, ref: 'Product', required: true },
164
+ updateContent: { type: String, required: true },
165
+ updateDate: { type: Date, required: true },
166
+ });
@@ -0,0 +1,93 @@
1
+ import { z as zod } from 'zod';
2
+ import { initTRPC, inferRouterInputs, inferRouterOutputs } from '@trpc/server';
3
+ import { customErrorFormatter, hasRole } from '@arken/node/rpc';
4
+ import type { RouterContext } from '../types';
5
+ import { Product, ProductDLC, ProductBundle, ProductReview } from './product.schema';
6
+
7
+ export const z = zod;
8
+ export const t = initTRPC.context<RouterContext>().create();
9
+ export const router = t.router;
10
+ export const procedure = t.procedure;
11
+
12
+ export const createRouter = () =>
13
+ router({
14
+ // Product endpoints
15
+ getProduct: procedure
16
+ .use(hasRole('guest', t))
17
+ .use(customErrorFormatter(t))
18
+ .input(z.object({ productId: z.string() }))
19
+ .query(({ input, ctx }) => (ctx.app.service.Product.getProduct as any)(input, ctx)),
20
+
21
+ createProduct: procedure
22
+ .use(hasRole('admin', t))
23
+ .use(customErrorFormatter(t))
24
+ .input(Product)
25
+ .mutation(({ input, ctx }) => (ctx.app.service.Product.createProduct as any)(input, ctx)),
26
+
27
+ updateProduct: procedure
28
+ .use(hasRole('admin', t))
29
+ .use(customErrorFormatter(t))
30
+ .input(z.object({ productId: z.string(), data: Product.partial() }))
31
+ .mutation(({ input, ctx }) => (ctx.app.service.Product.updateProduct as any)(input, ctx)),
32
+
33
+ // ProductDLC endpoints
34
+ getProductDLC: procedure
35
+ .use(hasRole('guest', t))
36
+ .use(customErrorFormatter(t))
37
+ .input(z.object({ dlcId: z.string() }))
38
+ .query(({ input, ctx }) => (ctx.app.service.Product.getProductDLC as any)(input, ctx)),
39
+
40
+ createProductDLC: procedure
41
+ .use(hasRole('admin', t))
42
+ .use(customErrorFormatter(t))
43
+ .input(ProductDLC)
44
+ .mutation(({ input, ctx }) => (ctx.app.service.Product.createProductDLC as any)(input, ctx)),
45
+
46
+ updateProductDLC: procedure
47
+ .use(hasRole('admin', t))
48
+ .use(customErrorFormatter(t))
49
+ .input(z.object({ dlcId: z.string(), data: ProductDLC.partial() }))
50
+ .mutation(({ input, ctx }) => (ctx.app.service.Product.updateProductDLC as any)(input, ctx)),
51
+
52
+ // ProductBundle endpoints
53
+ getProductBundle: procedure
54
+ .use(hasRole('guest', t))
55
+ .use(customErrorFormatter(t))
56
+ .input(z.object({ bundleId: z.string() }))
57
+ .query(({ input, ctx }) => (ctx.app.service.Product.getProductBundle as any)(input, ctx)),
58
+
59
+ createProductBundle: procedure
60
+ .use(hasRole('admin', t))
61
+ .use(customErrorFormatter(t))
62
+ .input(ProductBundle)
63
+ .mutation(({ input, ctx }) => (ctx.app.service.Product.createProductBundle as any)(input, ctx)),
64
+
65
+ updateProductBundle: procedure
66
+ .use(hasRole('admin', t))
67
+ .use(customErrorFormatter(t))
68
+ .input(z.object({ bundleId: z.string(), data: ProductBundle.partial() }))
69
+ .mutation(({ input, ctx }) => (ctx.app.service.Product.updateProductBundle as any)(input, ctx)),
70
+
71
+ // ProductReview endpoints
72
+ getProductReview: procedure
73
+ .use(hasRole('guest', t))
74
+ .use(customErrorFormatter(t))
75
+ .input(z.object({ reviewId: z.string() }))
76
+ .query(({ input, ctx }) => (ctx.app.service.Product.getProductReview as any)(input, ctx)),
77
+
78
+ createProductReview: procedure
79
+ .use(hasRole('admin', t))
80
+ .use(customErrorFormatter(t))
81
+ .input(ProductReview)
82
+ .mutation(({ input, ctx }) => (ctx.app.service.Product.createProductReview as any)(input, ctx)),
83
+
84
+ updateProductReview: procedure
85
+ .use(hasRole('admin', t))
86
+ .use(customErrorFormatter(t))
87
+ .input(z.object({ reviewId: z.string(), data: ProductReview.partial() }))
88
+ .mutation(({ input, ctx }) => (ctx.app.service.Product.updateProductReview as any)(input, ctx)),
89
+ });
90
+
91
+ export type Router = ReturnType<typeof createRouter>;
92
+ export type RouterInput = inferRouterInputs<Router>;
93
+ export type RouterOutput = inferRouterOutputs<Router>;
@@ -0,0 +1,186 @@
1
+ import { z, ObjectId, Entity } from '../schema';
2
+
3
+ // Extend the ProductMeta schema
4
+ const ProductMeta = z.object({
5
+ name: z.string(),
6
+ members: z.array(ObjectId), // Array of Profile references
7
+ isProposal: z.boolean(),
8
+ price: z.number().nonnegative(),
9
+ oldPrice: z
10
+ .number()
11
+ .nonnegative()
12
+ .optional(),
13
+ images: z.record(z.string(), z.any()),
14
+ video: z.string().url(),
15
+ genre: z.string(),
16
+ releaseDate: z.string(),
17
+ developer: z.string(),
18
+ publisher: z.string(),
19
+ developerTags: z.array(z.string()),
20
+ languageSupport: z.array(z.any()), // Replace with actual Language schema if available
21
+ systemRequirements: z.array(z.any()), // Replace with actual SystemRequirement schema if available
22
+ tags: z.array(ObjectId), // Array of Tag references
23
+ type: z.string(),
24
+ downloads: z
25
+ .number()
26
+ .int()
27
+ .nonnegative(),
28
+ plans: z.array(z.any()), // Replace with actual ProductPlan schema if available
29
+ frequentlyTradedAssets: z.array(ObjectId), // Array of Asset references
30
+ saleBox: z.record(z.string(), z.any()),
31
+ assets: z.array(ObjectId), // Array of Asset references
32
+ community: z.record(z.string(), z.any()),
33
+ nameUrl: z.string(),
34
+ steamId: z.number().int(),
35
+ author: z.string(),
36
+ });
37
+
38
+ // Updated Product schema
39
+ export const Product = Entity.merge(
40
+ z.object({
41
+ shortDescription: z
42
+ .string()
43
+ .max(300)
44
+ .min(1),
45
+ content: z.string().min(1),
46
+ communityId: ObjectId,
47
+ type: z
48
+ .string()
49
+ .max(100)
50
+ .default('game'),
51
+ releaseDate: z.date().optional(),
52
+ sku: z.string().min(1),
53
+ categoryId: ObjectId.optional(),
54
+ price: z.number().nonnegative(),
55
+ discountPrice: z
56
+ .number()
57
+ .nonnegative()
58
+ .optional(),
59
+ currency: z.string().length(3),
60
+ images: z.array(z.string().url()).optional(),
61
+ videos: z.array(z.string().url()).optional(),
62
+ digitalContent: z
63
+ .array(
64
+ z.object({
65
+ url: z.string().url(),
66
+ size: z.number().nonnegative(),
67
+ drm: z.enum(['None', 'Steam', 'Epic', 'Uplay', 'Origin']).optional(),
68
+ })
69
+ )
70
+ .optional(),
71
+ dlcs: z.array(ObjectId).optional(),
72
+ bundles: z.array(ObjectId).optional(),
73
+ achievements: z
74
+ .array(
75
+ z.object({
76
+ name: z.string(),
77
+ description: z.string().optional(),
78
+ icon: z
79
+ .string()
80
+ .url()
81
+ .optional(),
82
+ })
83
+ )
84
+ .optional(),
85
+ reviews: z
86
+ .array(
87
+ z.object({
88
+ userId: ObjectId,
89
+ rating: z
90
+ .number()
91
+ .min(1)
92
+ .max(5),
93
+ comment: z.string().optional(),
94
+ createdDate: z.date().default(() => new Date()),
95
+ })
96
+ )
97
+ .optional(),
98
+ cloudSave: z.boolean().default(false),
99
+ ugcSupport: z.boolean().default(false),
100
+ wishlistCount: z
101
+ .number()
102
+ .int()
103
+ .nonnegative()
104
+ .default(0),
105
+
106
+ // Additional fields from Objection.js model
107
+ parentId: ObjectId.optional(),
108
+ score: z.number().optional(),
109
+ ownerId: ObjectId.optional(),
110
+ ratingId: ObjectId.optional(),
111
+ ideaId: ObjectId.optional(),
112
+ meta: ProductMeta.optional(),
113
+ })
114
+ );
115
+
116
+ // ProductDLC schema
117
+ export const ProductDLC = Entity.merge(
118
+ z.object({
119
+ name: z.string().min(1),
120
+ description: z.string().optional(),
121
+ gameId: ObjectId,
122
+ price: z.number().nonnegative(),
123
+ discountPrice: z
124
+ .number()
125
+ .nonnegative()
126
+ .optional(),
127
+ currency: z.string().length(3),
128
+ digitalContent: z
129
+ .array(
130
+ z.object({
131
+ url: z.string().url(),
132
+ size: z.number().nonnegative(),
133
+ drm: z.enum(['None', 'Steam', 'Epic', 'Uplay', 'Origin']).optional(),
134
+ })
135
+ )
136
+ .optional(),
137
+ achievements: z
138
+ .array(
139
+ z.object({
140
+ name: z.string(),
141
+ description: z.string().optional(),
142
+ icon: z
143
+ .string()
144
+ .url()
145
+ .optional(),
146
+ })
147
+ )
148
+ .optional(),
149
+ })
150
+ );
151
+
152
+ // ProductBundle schema
153
+ export const ProductBundle = Entity.merge(
154
+ z.object({
155
+ name: z.string().min(1),
156
+ description: z.string().optional(),
157
+ products: z.array(ObjectId),
158
+ price: z.number().nonnegative(),
159
+ discountPrice: z
160
+ .number()
161
+ .nonnegative()
162
+ .optional(),
163
+ currency: z.string().length(3),
164
+ })
165
+ );
166
+
167
+ // ProductReview schema
168
+ export const ProductReview = Entity.merge(
169
+ z.object({
170
+ userId: ObjectId,
171
+ productId: ObjectId,
172
+ rating: z
173
+ .number()
174
+ .min(1)
175
+ .max(5),
176
+ comment: z.string().optional(),
177
+ })
178
+ );
179
+
180
+ export const ProductUpdate = Entity.merge(
181
+ z.object({
182
+ productId: ObjectId,
183
+ updateContent: z.string().min(1),
184
+ updateDate: z.date(),
185
+ })
186
+ );
@@ -0,0 +1,32 @@
1
+ import { z } from 'zod';
2
+ import * as schema from './product.schema';
3
+ import { Document, Model } from '@arken/node/mongo';
4
+ import type { RouterContext } from '../types';
5
+ import type { inferRouterInputs, inferRouterOutputs } from '@trpc/server';
6
+ import type { Router } from './product.router';
7
+
8
+ export type * from './product.router';
9
+ export type { RouterContext };
10
+
11
+ export type Product = z.infer<typeof schema.Product>;
12
+ export type ProductUpdate = z.infer<typeof schema.ProductUpdate>;
13
+ export type ProductDLC = z.infer<typeof schema.ProductDLC>;
14
+ export type ProductBundle = z.infer<typeof schema.ProductBundle>;
15
+ export type ProductReview = z.infer<typeof schema.ProductReview>;
16
+
17
+ export type ProductDocument = Product & Document;
18
+ export type ProductUpdateDocument = ProductUpdate & Document;
19
+ export type ProductDLCDocument = ProductDLC & Document;
20
+ export type ProductBundleDocument = ProductBundle & Document;
21
+ export type ProductReviewDocument = ProductReview & Document;
22
+
23
+ export type Mappings = {
24
+ Product: Model<ProductDocument>;
25
+ ProductUpdate: Model<ProductUpdateDocument>;
26
+ ProductDLC: Model<ProductDLCDocument>;
27
+ ProductBundle: Model<ProductBundleDocument>;
28
+ ProductReview: Model<ProductReviewDocument>;
29
+ };
30
+
31
+ export type RouterInput = inferRouterInputs<Router>;
32
+ export type RouterOutput = inferRouterOutputs<Router>;
@@ -0,0 +1,4 @@
1
+ export * as Types from './profile.types';
2
+ export * as Models from './profile.models';
3
+ export * as Schemas from './profile.schema';
4
+ export * from './profile.router';
@@ -0,0 +1,214 @@
1
+ // profile.models.ts
2
+ //
3
+ import * as mongo from '@arken/node/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
+ );