@arken/node 1.5.0 → 1.5.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/modules/character/character.service.js.map +1 -1
- package/build/modules/chat/chat.service.js.map +1 -1
- package/build/modules/core/core.models.js.map +1 -1
- package/build/modules/core/core.service.js.map +1 -1
- package/build/modules/profile/profile.service.js.map +1 -1
- package/build/package.json +2 -2
- package/build/tsconfig.tsbuildinfo +1 -1
- package/build/types.d.ts +1 -0
- package/build/types.js +1 -0
- package/build/types.js.map +1 -1
- package/build/util/mongo.js.map +1 -1
- package/db.ts +76 -1
- package/index.ts +351 -18
- package/{util/mongo.ts → mongo.ts} +2 -0
- package/package.json +3 -3
- package/tsconfig.json +33 -2
- package/types.ts +2 -0
- package/util.ts +1 -0
- package/modules/area/area.models.ts +0 -15
- package/modules/area/area.router.ts +0 -74
- package/modules/area/area.schema.ts +0 -22
- package/modules/area/area.service.ts +0 -124
- package/modules/area/area.types.ts +0 -26
- package/modules/area/index.ts +0 -5
- package/modules/asset/asset.models.ts +0 -59
- package/modules/asset/asset.router.ts +0 -55
- package/modules/asset/asset.schema.ts +0 -27
- package/modules/asset/asset.service.ts +0 -85
- package/modules/asset/asset.types.ts +0 -22
- package/modules/asset/index.ts +0 -5
- package/modules/chain/chain.models.ts +0 -50
- package/modules/chain/chain.router.ts +0 -104
- package/modules/chain/chain.schema.ts +0 -52
- package/modules/chain/chain.service.ts +0 -167
- package/modules/chain/chain.types.ts +0 -24
- package/modules/chain/index.ts +0 -5
- package/modules/character/character.models.ts +0 -174
- package/modules/character/character.router.ts +0 -314
- package/modules/character/character.schema.ts +0 -147
- package/modules/character/character.service.ts +0 -875
- package/modules/character/character.types.ts +0 -64
- package/modules/character/index.ts +0 -5
- package/modules/chat/chat.models.ts +0 -43
- package/modules/chat/chat.router.ts +0 -67
- package/modules/chat/chat.schema.ts +0 -36
- package/modules/chat/chat.service.ts +0 -120
- package/modules/chat/chat.types.ts +0 -20
- package/modules/chat/index.ts +0 -5
- package/modules/collection/collection.models.ts +0 -76
- package/modules/collection/collection.router.ts +0 -91
- package/modules/collection/collection.schema.ts +0 -90
- package/modules/collection/collection.service.ts +0 -192
- package/modules/collection/collection.types.ts +0 -36
- package/modules/collection/index.ts +0 -5
- package/modules/core/core.models.ts +0 -1379
- package/modules/core/core.router.ts +0 -1781
- package/modules/core/core.schema.ts +0 -847
- package/modules/core/core.service.ts +0 -2822
- package/modules/core/core.types.ts +0 -340
- package/modules/core/index.ts +0 -5
- package/modules/core/mail/applyPatchesOrMail.ts +0 -568
- package/modules/core/mail/mailClaimablePatchesBatch.ts +0 -381
- package/modules/game/game.models.ts +0 -53
- package/modules/game/game.router.ts +0 -110
- package/modules/game/game.schema.ts +0 -23
- package/modules/game/game.service.ts +0 -143
- package/modules/game/game.types.ts +0 -28
- package/modules/game/index.ts +0 -5
- package/modules/interface/index.ts +0 -5
- package/modules/interface/interface.canonicalize.ts +0 -279
- package/modules/interface/interface.models.ts +0 -40
- package/modules/interface/interface.router.ts +0 -175
- package/modules/interface/interface.schema.ts +0 -59
- package/modules/interface/interface.service.ts +0 -356
- package/modules/interface/interface.types.ts +0 -25
- package/modules/item/index.ts +0 -5
- package/modules/item/item.models.ts +0 -124
- package/modules/item/item.router.ts +0 -103
- package/modules/item/item.schema.ts +0 -120
- package/modules/item/item.service.ts +0 -167
- package/modules/item/item.types.ts +0 -74
- package/modules/job/index.ts +0 -5
- package/modules/job/job.models.ts +0 -14
- package/modules/job/job.router.ts +0 -44
- package/modules/job/job.schema.ts +0 -9
- package/modules/job/job.service.ts +0 -243
- package/modules/job/job.types.ts +0 -23
- package/modules/market/index.ts +0 -5
- package/modules/market/market.models.ts +0 -113
- package/modules/market/market.router.ts +0 -73
- package/modules/market/market.schema.ts +0 -140
- package/modules/market/market.service.ts +0 -122
- package/modules/market/market.types.ts +0 -56
- package/modules/product/index.ts +0 -5
- package/modules/product/product.models.ts +0 -166
- package/modules/product/product.router.ts +0 -93
- package/modules/product/product.schema.ts +0 -149
- package/modules/product/product.service.ts +0 -160
- package/modules/product/product.types.ts +0 -33
- package/modules/profile/index.ts +0 -5
- package/modules/profile/profile.models.ts +0 -214
- package/modules/profile/profile.router.ts +0 -72
- package/modules/profile/profile.schema.ts +0 -156
- package/modules/profile/profile.service.ts +0 -147
- package/modules/profile/profile.types.ts +0 -22
- package/modules/raffle/index.ts +0 -5
- package/modules/raffle/raffle.models.ts +0 -44
- package/modules/raffle/raffle.router.ts +0 -90
- package/modules/raffle/raffle.schema.ts +0 -32
- package/modules/raffle/raffle.service.ts +0 -167
- package/modules/raffle/raffle.types.ts +0 -30
- package/modules/skill/index.ts +0 -5
- package/modules/skill/skill.models.ts +0 -16
- package/modules/skill/skill.router.ts +0 -201
- package/modules/skill/skill.schema.ts +0 -40
- package/modules/skill/skill.service.ts +0 -390
- package/modules/skill/skill.types.ts +0 -33
- package/modules/video/index.ts +0 -5
- package/modules/video/video.models.ts +0 -25
- package/modules/video/video.router.ts +0 -143
- package/modules/video/video.schema.ts +0 -46
- package/modules/video/video.service.ts +0 -274
- package/modules/video/video.types.ts +0 -33
- package/util/db/index.ts +0 -7
- package/util/db/isPostgresError.ts +0 -9
- package/util/db/isUniqueConstraintViolation.ts +0 -3
- package/util/db.ts +0 -62
- package/util/index.ts +0 -351
- /package/{util/api.ts → api.ts} +0 -0
- /package/{util/array.ts → array.ts} +0 -0
- /package/{util/browser.ts → browser.ts} +0 -0
- /package/{util/codebase.ts → codebase.ts} +0 -0
- /package/{util/config.ts → config.ts} +0 -0
- /package/{util/decoder.test.ts → decoder.test.ts} +0 -0
- /package/{util/decoder.ts → decoder.ts} +0 -0
- /package/{util/format.ts → format.ts} +0 -0
- /package/{util/guid.ts → guid.ts} +0 -0
- /package/{util/json.ts → json.ts} +0 -0
- /package/{util/log.ts → log.ts} +0 -0
- /package/{util/math.ts → math.ts} +0 -0
- /package/{util/merkle.ts → merkle.ts} +0 -0
- /package/{util/number.ts → number.ts} +0 -0
- /package/{util/object.ts → object.ts} +0 -0
- /package/{util/otp.ts → otp.ts} +0 -0
- /package/{util/physics.ts → physics.ts} +0 -0
- /package/{util/process.ts → process.ts} +0 -0
- /package/{util/rpc.ts → rpc.ts} +0 -0
- /package/{util/seer.ts → seer.ts} +0 -0
- /package/{util/string.ts → string.ts} +0 -0
- /package/{util/text.ts → text.ts} +0 -0
- /package/{util/time → time}/date.ts +0 -0
- /package/{util/time → time}/fancyTimeFormat.ts +0 -0
- /package/{util/time → time}/index.ts +0 -0
- /package/{util/time → time}/now.ts +0 -0
- /package/{util/types → types}/mongo.d.ts +0 -0
- /package/{util/web3 → web3}/httpProvider.ts +0 -0
- /package/{util/web3.ts → web3.ts} +0 -0
- /package/{util/websocket.ts → websocket.ts} +0 -0
- /package/{util/zk.ts → zk.ts} +0 -0
- /package/{util/zod.ts → zod.ts} +0 -0
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
// arken/packages/node/modules/interface/interface.schema.ts
|
|
2
|
-
//
|
|
3
|
-
import { z, ObjectId, Entity } from '../../schema';
|
|
4
|
-
|
|
5
|
-
// Patch ops for interface composition
|
|
6
|
-
const InterfacePatch = z.object({
|
|
7
|
-
op: z.enum(['merge', 'replace', 'remove', 'push', 'unshift', 'splice']).default('merge'),
|
|
8
|
-
key: z.string().min(1), // target node key (or special key like "root")
|
|
9
|
-
path: z.string().optional(), // optional deep path inside that node, ex: "props.omit"
|
|
10
|
-
value: z.unknown().optional(), // payload for merge/replace/push/etc
|
|
11
|
-
});
|
|
12
|
-
|
|
13
|
-
export const Interface = Entity.merge(
|
|
14
|
-
z.object({
|
|
15
|
-
ratingId: ObjectId.optional(),
|
|
16
|
-
groupId: ObjectId.optional(),
|
|
17
|
-
submissions: z.array(ObjectId).optional(),
|
|
18
|
-
|
|
19
|
-
// ✅ NEW: composition / inheritance
|
|
20
|
-
inherits: z.array(z.string()).default([]),
|
|
21
|
-
|
|
22
|
-
// ✅ NEW: variables available to formula scope + patch engine
|
|
23
|
-
variables: z.record(z.unknown()).default({}),
|
|
24
|
-
|
|
25
|
-
// ✅ NEW: patch list applied on top of inherited/base nodes
|
|
26
|
-
patches: z.array(InterfacePatch).default([]),
|
|
27
|
-
|
|
28
|
-
// existing
|
|
29
|
-
nodes: z.any(), // you can later tighten this to z.array(AnyNodeSchema)
|
|
30
|
-
version: z.number().optional(),
|
|
31
|
-
status: z.enum(['Paused', 'Pending', 'Active', 'Archived', 'Published', 'Draft']).default('Active'),
|
|
32
|
-
})
|
|
33
|
-
);
|
|
34
|
-
|
|
35
|
-
export const InterfaceGroup = Entity.merge(
|
|
36
|
-
z.object({
|
|
37
|
-
roles: z.array(ObjectId).optional(),
|
|
38
|
-
})
|
|
39
|
-
);
|
|
40
|
-
|
|
41
|
-
export const InterfaceComponent = Entity.merge(
|
|
42
|
-
z.object({
|
|
43
|
-
value: z.unknown().optional(),
|
|
44
|
-
data: z.record(z.unknown()).optional(),
|
|
45
|
-
type: z.string().optional(),
|
|
46
|
-
hasAttachment: z.boolean().optional(),
|
|
47
|
-
hasValidation: z.boolean().optional(),
|
|
48
|
-
isDisabled: z.boolean().optional(),
|
|
49
|
-
isEditable: z.boolean().optional(),
|
|
50
|
-
isRequired: z.boolean().optional(),
|
|
51
|
-
})
|
|
52
|
-
);
|
|
53
|
-
|
|
54
|
-
export const InterfaceSubmission = Entity.merge(
|
|
55
|
-
z.object({
|
|
56
|
-
interfaceId: ObjectId,
|
|
57
|
-
interface: ObjectId.optional(),
|
|
58
|
-
})
|
|
59
|
-
);
|
|
@@ -1,356 +0,0 @@
|
|
|
1
|
-
import _ from 'lodash';
|
|
2
|
-
import { getFilter } from '../../util/api';
|
|
3
|
-
import type {
|
|
4
|
-
RouterContext,
|
|
5
|
-
RouterInput,
|
|
6
|
-
RouterOutput,
|
|
7
|
-
Interface,
|
|
8
|
-
InterfaceDocument,
|
|
9
|
-
InterfaceGroupDocument,
|
|
10
|
-
InterfaceComponentDocument,
|
|
11
|
-
} from './interface.types';
|
|
12
|
-
import { log, logError } from '../../util';
|
|
13
|
-
import { ARXError } from '../../util/rpc';
|
|
14
|
-
|
|
15
|
-
export class Service {
|
|
16
|
-
constructor() {}
|
|
17
|
-
|
|
18
|
-
// Interface Methods
|
|
19
|
-
async getInterfaces(input: RouterInput['getInterfaces'], ctx: RouterContext): Promise<RouterOutput['getInterfaces']> {
|
|
20
|
-
if (!input) throw new ARXError('NO_INPUT');
|
|
21
|
-
log('Core.Service.getInterfaces', input);
|
|
22
|
-
const filter = getFilter(input);
|
|
23
|
-
const limit = input.limit ?? 50;
|
|
24
|
-
const skip = input.skip ?? 0;
|
|
25
|
-
|
|
26
|
-
const [items, total] = await Promise.all([
|
|
27
|
-
// If your Interface model has findJSON like Conversation:
|
|
28
|
-
ctx.app.model.Interface.findJSON(filter, null, { skip, limit }),
|
|
29
|
-
ctx.app.model.Interface.find(filter).countDocuments().exec(),
|
|
30
|
-
]);
|
|
31
|
-
|
|
32
|
-
return { items, total };
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
async getInterface(input: RouterInput['getInterface'], ctx: RouterContext): Promise<RouterOutput['getInterface']> {
|
|
36
|
-
if (!input) throw new ARXError('NO_INPUT');
|
|
37
|
-
log('Core.Service.getInterface', input);
|
|
38
|
-
// If you have findOneJSON on Interface:
|
|
39
|
-
const iface = await ctx.app.model.Interface.findOneJSON(getFilter(input));
|
|
40
|
-
if (!iface) throw new Error('Interface not found');
|
|
41
|
-
return iface as Interface;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
async createInterface(
|
|
45
|
-
input: RouterInput['createInterface'],
|
|
46
|
-
ctx: RouterContext
|
|
47
|
-
): Promise<RouterOutput['createInterface']> {
|
|
48
|
-
if (!input) throw new ARXError('NO_INPUT');
|
|
49
|
-
log('Core.Service.createInterface', input);
|
|
50
|
-
|
|
51
|
-
// Same pattern as createConversation: expect { data: {...} }
|
|
52
|
-
const iface = await ctx.app.model.Interface.create(input.data);
|
|
53
|
-
return iface as Interface;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
async updateInterface(
|
|
57
|
-
input: RouterInput['updateInterface'],
|
|
58
|
-
ctx: RouterContext
|
|
59
|
-
): Promise<RouterOutput['updateInterface']> {
|
|
60
|
-
if (!input) throw new ARXError('NO_INPUT');
|
|
61
|
-
|
|
62
|
-
const filters = getFilter(input);
|
|
63
|
-
if (!filters._id) throw new ARXError('BAD_REQUEST');
|
|
64
|
-
|
|
65
|
-
log('Core.Service.updateInterface', input);
|
|
66
|
-
const updatedInterface = await ctx.app.model.Interface.findByIdAndUpdate(filters._id, input.data, {
|
|
67
|
-
new: true,
|
|
68
|
-
})
|
|
69
|
-
.lean()
|
|
70
|
-
.exec();
|
|
71
|
-
|
|
72
|
-
if (!updatedInterface) throw new Error('Interface update failed');
|
|
73
|
-
return updatedInterface as Interface;
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
async deleteInterface(
|
|
77
|
-
input: RouterInput['deleteInterface'],
|
|
78
|
-
ctx: RouterContext
|
|
79
|
-
): Promise<RouterOutput['deleteInterface']> {
|
|
80
|
-
if (!input) throw new ARXError('NO_INPUT');
|
|
81
|
-
log('Core.Service.deleteInterface', input);
|
|
82
|
-
const deleted = await ctx.app.model.Interface.findByIdAndDelete(input.where.id.equals).exec();
|
|
83
|
-
if (!deleted) throw new Error('Interface not found');
|
|
84
|
-
return { id: input.where.id.equals };
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
// // Interface Methods
|
|
88
|
-
// async getInterface(input: RouterInput['getInterface'], ctx: RouterContext): Promise<RouterOutput['getInterface']> {
|
|
89
|
-
// if (!input) throw new Error('Input should not be void');
|
|
90
|
-
// console.log('Interface.Service.getInterface', input);
|
|
91
|
-
|
|
92
|
-
// const filter = getFilter(input);
|
|
93
|
-
// const interfac = await ctx.app.model.Interface.findOne(filter).select('-meta').exec();
|
|
94
|
-
// if (!interfac) throw new Error('Interface not found');
|
|
95
|
-
|
|
96
|
-
// if (!interfac.version) interfac.version = 1;
|
|
97
|
-
// if (!interfac.meta) interfac.meta = {};
|
|
98
|
-
|
|
99
|
-
// return interfac as InterfaceDocument;
|
|
100
|
-
// }
|
|
101
|
-
|
|
102
|
-
// async getInterfaces(input: RouterInput['getInterfaces'], ctx: RouterContext): Promise<RouterOutput['getInterfaces']> {
|
|
103
|
-
// if (!input) throw new Error('Input should not be void');
|
|
104
|
-
|
|
105
|
-
// const filter = getFilter(input);
|
|
106
|
-
// console.log('Interface.Service.getInterfaces', input, filter);
|
|
107
|
-
// const interfaces = await ctx.app.model.Interface.find(filter).select('-meta').exec();
|
|
108
|
-
// const rolesOnUsers = ['Super User']; // await this.fetchRolesFromContext(ctx);
|
|
109
|
-
|
|
110
|
-
// for (const interfac of interfaces) {
|
|
111
|
-
// if (!interfac.version) interfac.version = 1;
|
|
112
|
-
// if (!interfac.meta) interfac.meta = {};
|
|
113
|
-
// }
|
|
114
|
-
|
|
115
|
-
// return interfaces.filter((interfac) => {
|
|
116
|
-
// const roles = [];
|
|
117
|
-
// return this.hasPermission(roles, rolesOnUsers);
|
|
118
|
-
// }) as InterfaceDocument[];
|
|
119
|
-
// }
|
|
120
|
-
|
|
121
|
-
// async createInterface(
|
|
122
|
-
// input: RouterInput['createInterface'],
|
|
123
|
-
// ctx: RouterContext
|
|
124
|
-
// ): Promise<RouterOutput['createInterface']> {
|
|
125
|
-
// if (!input) throw new Error('Input should not be void');
|
|
126
|
-
|
|
127
|
-
// const existingInterface = await ctx.app.model.Interface.findOne({ key: input.data.key }).exec();
|
|
128
|
-
// const version = existingInterface ? existingInterface.version + 1 : 1;
|
|
129
|
-
|
|
130
|
-
// const newInterface = await ctx.app.model.Interface.create({
|
|
131
|
-
// ...input.data,
|
|
132
|
-
// status: input.data.status || 'Draft',
|
|
133
|
-
// version,
|
|
134
|
-
// createdDate: new Date(),
|
|
135
|
-
// });
|
|
136
|
-
|
|
137
|
-
// await ctx.app.service.Job.updateMetrics({}, ctx);
|
|
138
|
-
|
|
139
|
-
// return newInterface as InterfaceDocument;
|
|
140
|
-
// }
|
|
141
|
-
|
|
142
|
-
async createInterfaceDraft(
|
|
143
|
-
input: RouterInput['createInterfaceDraft'],
|
|
144
|
-
ctx: RouterContext
|
|
145
|
-
): Promise<RouterOutput['createInterfaceDraft']> {
|
|
146
|
-
if (!input) throw new Error('Input should not be void');
|
|
147
|
-
console.log('Interface.Service.createInterfaceDraft', input);
|
|
148
|
-
|
|
149
|
-
const existingInterface = await ctx.app.model.Interface.findOne({ key: input.data.key }).exec();
|
|
150
|
-
const version = existingInterface ? existingInterface.version + 1 : 1;
|
|
151
|
-
|
|
152
|
-
const newInterface = await ctx.app.model.Interface.create({
|
|
153
|
-
...input.data,
|
|
154
|
-
status: input.data.status || 'Draft',
|
|
155
|
-
version,
|
|
156
|
-
createdDate: new Date(),
|
|
157
|
-
});
|
|
158
|
-
|
|
159
|
-
await ctx.app.service.Job.updateMetrics({}, ctx);
|
|
160
|
-
|
|
161
|
-
return newInterface as InterfaceDocument;
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
// async updateInterface(
|
|
165
|
-
// input: RouterInput['updateInterface'],
|
|
166
|
-
// ctx: RouterContext
|
|
167
|
-
// ): Promise<RouterOutput['updateInterface']> {
|
|
168
|
-
// if (!input) throw new Error('Input should not be void');
|
|
169
|
-
// console.log('Interface.Service.updateInterface', input);
|
|
170
|
-
|
|
171
|
-
// const filter = getFilter(input);
|
|
172
|
-
// let interfac: any = await ctx.app.model.Interface.findOne(filter).exec();
|
|
173
|
-
// if (!interfac) throw new Error('Interface does not exist');
|
|
174
|
-
|
|
175
|
-
// if (interfac.status === 'Published' || input.data.groupId) {
|
|
176
|
-
// await ctx.app.model.Interface.updateMany({ key: interfac.key, status: 'Draft' }, { status: 'Archived' }).exec();
|
|
177
|
-
// const version =
|
|
178
|
-
// (await ctx.app.model.Interface.find({ key: interfac.key }).sort({ version: -1 }).exec())[0].version + 1;
|
|
179
|
-
|
|
180
|
-
// interfac = (await ctx.app.model.Interface.create({
|
|
181
|
-
// ...interfac,
|
|
182
|
-
// ...input.data,
|
|
183
|
-
// status: 'Draft',
|
|
184
|
-
// version,
|
|
185
|
-
// createdDate: new Date(),
|
|
186
|
-
// })) as InterfaceDocument;
|
|
187
|
-
// } else {
|
|
188
|
-
// await ctx.app.model.Interface.updateOne(filter, input.data).exec();
|
|
189
|
-
// interfac = await ctx.app.model.Interface.findOne(filter).exec();
|
|
190
|
-
// }
|
|
191
|
-
|
|
192
|
-
// await ctx.app.service.Job.updateMetrics({}, ctx);
|
|
193
|
-
|
|
194
|
-
// return interfac as InterfaceDocument;
|
|
195
|
-
// }
|
|
196
|
-
|
|
197
|
-
// async deleteInterface(
|
|
198
|
-
// input: RouterInput['deleteInterface'],
|
|
199
|
-
// ctx: RouterContext
|
|
200
|
-
// ): Promise<RouterOutput['deleteInterface']> {
|
|
201
|
-
// if (!input) throw new Error('Input should not be void');
|
|
202
|
-
// console.log('Interface.Service.deleteInterface', input);
|
|
203
|
-
|
|
204
|
-
// const filter = getFilter(input);
|
|
205
|
-
// const interfac = await ctx.app.model.Interface.findOne(filter).exec();
|
|
206
|
-
// if (!interfac) throw new Error('Interface does not exist');
|
|
207
|
-
|
|
208
|
-
// interfac.status = 'Archived';
|
|
209
|
-
// interfac.updatedDate = new Date();
|
|
210
|
-
// await ctx.app.model.Interface.updateOne(filter, interfac).exec();
|
|
211
|
-
|
|
212
|
-
// await ctx.app.service.Job.updateMetrics({}, ctx);
|
|
213
|
-
|
|
214
|
-
// return interfac as InterfaceDocument;
|
|
215
|
-
// }
|
|
216
|
-
|
|
217
|
-
async getInterfaceGroup(
|
|
218
|
-
input: RouterInput['getInterfaceGroup'],
|
|
219
|
-
ctx: RouterContext
|
|
220
|
-
): Promise<RouterOutput['getInterfaceGroup']> {
|
|
221
|
-
if (!input) throw new Error('Input should not be void');
|
|
222
|
-
console.log('Interface.Service.getInterfaceGroup', input);
|
|
223
|
-
|
|
224
|
-
const filter = getFilter(input);
|
|
225
|
-
const group = await ctx.app.model.InterfaceGroup.findOne(filter).exec();
|
|
226
|
-
if (!group) throw new Error('InterfaceGroup not found');
|
|
227
|
-
|
|
228
|
-
if (!group.roles) group.roles = [];
|
|
229
|
-
|
|
230
|
-
// for (const role of group.roles) {
|
|
231
|
-
// role.role = await ctx.app.service.Profile.findRole({
|
|
232
|
-
// where: { id: { equals: role.role.id } },
|
|
233
|
-
// });
|
|
234
|
-
// }
|
|
235
|
-
|
|
236
|
-
return group as InterfaceGroupDocument;
|
|
237
|
-
}
|
|
238
|
-
|
|
239
|
-
async getInterfaceGroups(
|
|
240
|
-
input: RouterInput['getInterfaceGroups'],
|
|
241
|
-
ctx: RouterContext
|
|
242
|
-
): Promise<RouterOutput['getInterfaceGroups']> {
|
|
243
|
-
console.log('Interface.Service.getInterfaceGroups', input);
|
|
244
|
-
|
|
245
|
-
const filter = getFilter(input);
|
|
246
|
-
const groups = await ctx.app.model.InterfaceGroup.find(filter).exec();
|
|
247
|
-
|
|
248
|
-
return groups as InterfaceGroupDocument[];
|
|
249
|
-
}
|
|
250
|
-
|
|
251
|
-
async createInterfaceGroup(
|
|
252
|
-
input: RouterInput['createInterfaceGroup'],
|
|
253
|
-
ctx: RouterContext
|
|
254
|
-
): Promise<RouterOutput['createInterfaceGroup']> {
|
|
255
|
-
if (!input) throw new Error('Input should not be void');
|
|
256
|
-
console.log('Interface.Service.createInterfaceGroup', input);
|
|
257
|
-
|
|
258
|
-
const newGroup = await ctx.app.model.InterfaceGroup.create(input.data);
|
|
259
|
-
|
|
260
|
-
return newGroup as InterfaceGroupDocument;
|
|
261
|
-
}
|
|
262
|
-
|
|
263
|
-
async updateInterfaceGroup(
|
|
264
|
-
input: RouterInput['updateInterfaceGroup'],
|
|
265
|
-
ctx: RouterContext
|
|
266
|
-
): Promise<RouterOutput['updateInterfaceGroup']> {
|
|
267
|
-
if (!input) throw new Error('Input should not be void');
|
|
268
|
-
console.log('Interface.Service.updateInterfaceGroup', input);
|
|
269
|
-
|
|
270
|
-
const filter = getFilter(input);
|
|
271
|
-
await ctx.app.model.InterfaceGroup.updateOne(filter, input.data, {
|
|
272
|
-
runValidators: true,
|
|
273
|
-
}).exec();
|
|
274
|
-
|
|
275
|
-
const updatedGroup = await ctx.app.model.InterfaceGroup.findOne(filter).exec();
|
|
276
|
-
if (!updatedGroup) throw new Error('InterfaceGroup update failed');
|
|
277
|
-
|
|
278
|
-
return updatedGroup as InterfaceGroupDocument;
|
|
279
|
-
}
|
|
280
|
-
|
|
281
|
-
async getInterfaceComponent(
|
|
282
|
-
input: RouterInput['getInterfaceComponent'],
|
|
283
|
-
ctx: RouterContext
|
|
284
|
-
): Promise<RouterOutput['getInterfaceComponent']> {
|
|
285
|
-
if (!input) throw new Error('Input should not be void');
|
|
286
|
-
console.log('Interface.Service.getInterfaceComponent', input);
|
|
287
|
-
|
|
288
|
-
const filter = getFilter(input);
|
|
289
|
-
const component = await ctx.app.model.InterfaceComponent.findOne(filter).exec();
|
|
290
|
-
if (!component) throw new Error('InterfaceComponent not found');
|
|
291
|
-
|
|
292
|
-
return component as InterfaceComponentDocument;
|
|
293
|
-
}
|
|
294
|
-
|
|
295
|
-
async createInterfaceComponent(
|
|
296
|
-
input: RouterInput['createInterfaceComponent'],
|
|
297
|
-
ctx: RouterContext
|
|
298
|
-
): Promise<RouterOutput['createInterfaceComponent']> {
|
|
299
|
-
if (!input) throw new Error('Input should not be void');
|
|
300
|
-
console.log('Interface.Service.createInterfaceComponent', input);
|
|
301
|
-
|
|
302
|
-
if (
|
|
303
|
-
await ctx.app.model.InterfaceComponent.findOne({
|
|
304
|
-
$or: [{ name: input.data.name }, { key: input.data.key }],
|
|
305
|
-
}).exec()
|
|
306
|
-
) {
|
|
307
|
-
throw new Error('Component template already exists');
|
|
308
|
-
}
|
|
309
|
-
|
|
310
|
-
const component = await ctx.app.model.InterfaceComponent.create({
|
|
311
|
-
name: input.data.name,
|
|
312
|
-
key: input.data.key,
|
|
313
|
-
status: input.data.status,
|
|
314
|
-
meta: input.data.meta,
|
|
315
|
-
});
|
|
316
|
-
|
|
317
|
-
await ctx.app.service.Job.updateMetrics({}, ctx);
|
|
318
|
-
|
|
319
|
-
return component as InterfaceComponentDocument;
|
|
320
|
-
}
|
|
321
|
-
|
|
322
|
-
async updateInterfaceComponent(
|
|
323
|
-
input: RouterInput['updateInterfaceComponent'],
|
|
324
|
-
ctx: RouterContext
|
|
325
|
-
): Promise<RouterOutput['updateInterfaceComponent']> {
|
|
326
|
-
if (!input) throw new Error('Input should not be void');
|
|
327
|
-
console.log('Interface.Service.updateInterfaceComponent', input);
|
|
328
|
-
|
|
329
|
-
const filter = getFilter(input);
|
|
330
|
-
const data = Object.entries(input.data).reduce((acc, [key, value]: any) => {
|
|
331
|
-
if (value?.set) acc[key] = value.set;
|
|
332
|
-
return acc;
|
|
333
|
-
}, {} as any);
|
|
334
|
-
|
|
335
|
-
await ctx.app.model.InterfaceComponent.updateOne(filter, data, {
|
|
336
|
-
runValidators: true,
|
|
337
|
-
}).exec();
|
|
338
|
-
|
|
339
|
-
const updatedComponent = await ctx.app.model.InterfaceComponent.findOne(filter).exec();
|
|
340
|
-
if (!updatedComponent) throw new Error('InterfaceComponent update failed');
|
|
341
|
-
|
|
342
|
-
await ctx.app.service.Job.updateMetrics({}, ctx);
|
|
343
|
-
|
|
344
|
-
return updatedComponent as InterfaceComponentDocument;
|
|
345
|
-
}
|
|
346
|
-
|
|
347
|
-
// Helper Methods
|
|
348
|
-
private async fetchRolesFromContext(ctx: RouterContext): Promise<string[]> {
|
|
349
|
-
// @ts-ignore
|
|
350
|
-
return ctx.profile?.roles.filter((r) => r.status === 'Active').map((r) => r.role.name) || [];
|
|
351
|
-
}
|
|
352
|
-
|
|
353
|
-
private hasPermission(roles: string[], rolesOnUsers: string[]): boolean {
|
|
354
|
-
return rolesOnUsers.includes('Super User') || _.intersection(roles, rolesOnUsers).length > 0;
|
|
355
|
-
}
|
|
356
|
-
}
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import { z, Model, Document } from '../../util/mongo';
|
|
2
|
-
import * as schema from './interface.schema';
|
|
3
|
-
|
|
4
|
-
export type * from './interface.router';
|
|
5
|
-
export type * from './interface.service';
|
|
6
|
-
export type { RouterContext } from '../../types';
|
|
7
|
-
|
|
8
|
-
export type Interface = z.infer<typeof schema.Interface>;
|
|
9
|
-
export type InterfaceDocument = Interface & Document;
|
|
10
|
-
|
|
11
|
-
export type InterfaceGroup = z.infer<typeof schema.InterfaceGroup>;
|
|
12
|
-
export type InterfaceGroupDocument = InterfaceGroup & Document;
|
|
13
|
-
|
|
14
|
-
export type InterfaceComponent = z.infer<typeof schema.InterfaceComponent>;
|
|
15
|
-
export type InterfaceComponentDocument = InterfaceComponent & Document;
|
|
16
|
-
|
|
17
|
-
export type InterfaceSubmission = z.infer<typeof schema.InterfaceSubmission>;
|
|
18
|
-
export type InterfaceSubmissionDocument = InterfaceSubmission & Document;
|
|
19
|
-
|
|
20
|
-
export type Mappings = {
|
|
21
|
-
Interface: Model<InterfaceDocument>;
|
|
22
|
-
InterfaceGroup: Model<InterfaceGroupDocument>;
|
|
23
|
-
InterfaceComponent: Model<InterfaceComponentDocument>;
|
|
24
|
-
InterfaceSubmission: Model<InterfaceSubmissionDocument>;
|
|
25
|
-
};
|
package/modules/item/index.ts
DELETED
|
@@ -1,124 +0,0 @@
|
|
|
1
|
-
import * as mongo from '../../util/mongo';
|
|
2
|
-
import type * as Types from './item.types';
|
|
3
|
-
|
|
4
|
-
const { addTagVirtuals, addApplicationVirtual } = mongo;
|
|
5
|
-
|
|
6
|
-
export const Item = mongo.createModel<Types.ItemDocument>(
|
|
7
|
-
'Item',
|
|
8
|
-
{
|
|
9
|
-
token: { type: String, maxlength: 500, minlength: 1, required: true },
|
|
10
|
-
characterId: { type: mongo.Schema.Types.ObjectId, ref: 'Character', required: true },
|
|
11
|
-
assetId: { type: mongo.Schema.Types.ObjectId, ref: 'Asset', required: true },
|
|
12
|
-
chainId: { type: mongo.Schema.Types.ObjectId, ref: 'Chain', required: false },
|
|
13
|
-
materialId: { type: mongo.Schema.Types.ObjectId, ref: 'ItemMaterial', required: false },
|
|
14
|
-
skinId: { type: mongo.Schema.Types.ObjectId, ref: 'ItemSkin', required: false },
|
|
15
|
-
recipeId: { type: mongo.Schema.Types.ObjectId, ref: 'ItemRecipe', required: false },
|
|
16
|
-
typeId: { type: mongo.Schema.Types.ObjectId, ref: 'ItemType', required: false },
|
|
17
|
-
subTypeId: { type: mongo.Schema.Types.ObjectId, ref: 'ItemSubType', required: false },
|
|
18
|
-
specificTypeId: { type: mongo.Schema.Types.ObjectId, ref: 'ItemSpecificType', required: false },
|
|
19
|
-
rarityId: { type: mongo.Schema.Types.ObjectId, ref: 'ItemRarity', required: false },
|
|
20
|
-
rankId: { type: mongo.Schema.Types.ObjectId, ref: 'ItemRank', required: false },
|
|
21
|
-
rankValue: { type: Number, integer: true, min: 0, max: 100, required: false },
|
|
22
|
-
slotIds: [{ type: mongo.Schema.Types.ObjectId, ref: 'ItemSlot', required: false }],
|
|
23
|
-
setId: { type: mongo.Schema.Types.ObjectId, ref: 'ItemSet', required: false },
|
|
24
|
-
attributes: [{ type: mongo.Schema.Types.ObjectId, ref: 'ItemAttribute', required: false }],
|
|
25
|
-
quantity: { type: Number, integer: true, min: 0, default: 1 },
|
|
26
|
-
distribution: { type: String, default: 'Unknown' },
|
|
27
|
-
x: { type: Number, integer: true, min: 0, required: false },
|
|
28
|
-
y: { type: Number, integer: true, min: 0, required: false },
|
|
29
|
-
items: [{ type: mongo.Schema.Types.ObjectId, ref: 'Item', default: [] }],
|
|
30
|
-
capacity: { type: Number, integer: true, min: 0, default: 60 },
|
|
31
|
-
points: { type: Number, integer: true, min: 0, default: 0 },
|
|
32
|
-
},
|
|
33
|
-
{
|
|
34
|
-
extend: 'EntityFields',
|
|
35
|
-
indexes: [{ quantity: 1 }, { points: 1 }, { capacity: 1 }],
|
|
36
|
-
virtuals: [
|
|
37
|
-
...addTagVirtuals('Item'),
|
|
38
|
-
...addApplicationVirtual(),
|
|
39
|
-
{
|
|
40
|
-
name: 'character',
|
|
41
|
-
},
|
|
42
|
-
{
|
|
43
|
-
name: 'asset',
|
|
44
|
-
},
|
|
45
|
-
{
|
|
46
|
-
name: 'chain',
|
|
47
|
-
},
|
|
48
|
-
{
|
|
49
|
-
name: 'material',
|
|
50
|
-
},
|
|
51
|
-
{
|
|
52
|
-
name: 'skin',
|
|
53
|
-
},
|
|
54
|
-
{
|
|
55
|
-
name: 'recipe',
|
|
56
|
-
},
|
|
57
|
-
{
|
|
58
|
-
name: 'type',
|
|
59
|
-
},
|
|
60
|
-
{
|
|
61
|
-
name: 'subType',
|
|
62
|
-
},
|
|
63
|
-
{
|
|
64
|
-
name: 'specificType',
|
|
65
|
-
},
|
|
66
|
-
{
|
|
67
|
-
name: 'rarity',
|
|
68
|
-
},
|
|
69
|
-
],
|
|
70
|
-
}
|
|
71
|
-
);
|
|
72
|
-
|
|
73
|
-
export const ItemAttribute = mongo.createModel<Types.ItemAttributeDocument>('ItemAttribute', {});
|
|
74
|
-
|
|
75
|
-
export const ItemMaterial = mongo.createModel<Types.ItemMaterialDocument>('ItemMaterial', {});
|
|
76
|
-
|
|
77
|
-
export const ItemSet = mongo.createModel<Types.ItemSetDocument>('ItemSet', {});
|
|
78
|
-
|
|
79
|
-
export const ItemSlot = mongo.createModel<Types.ItemSlotDocument>('ItemSlot', {});
|
|
80
|
-
|
|
81
|
-
export const ItemRarity = mongo.createModel<Types.ItemRarityDocument>('ItemRarity', {});
|
|
82
|
-
|
|
83
|
-
export const ItemRank = mongo.createModel<Types.ItemRankDocument>('ItemRank', {
|
|
84
|
-
value: { type: Number },
|
|
85
|
-
});
|
|
86
|
-
|
|
87
|
-
export const ItemType = mongo.createModel<Types.ItemTypeDocument>('ItemType', {});
|
|
88
|
-
|
|
89
|
-
export const ItemSubType = mongo.createModel<Types.ItemSubTypeDocument>('ItemSubType', {});
|
|
90
|
-
|
|
91
|
-
export const ItemSpecificType = mongo.createModel<Types.ItemSpecificTypeDocument>('ItemSpecificType', {});
|
|
92
|
-
|
|
93
|
-
export const ItemAffix = mongo.createModel<Types.ItemAffixDocument>('ItemAffix', {
|
|
94
|
-
isPrefix: { type: Boolean, default: false },
|
|
95
|
-
isSuffix: { type: Boolean, default: false },
|
|
96
|
-
isTitle: { type: Boolean, default: false },
|
|
97
|
-
weight: { type: Number, min: 0, default: 1 },
|
|
98
|
-
typeIds: [{ type: mongo.Schema.Types.ObjectId, ref: 'ItemType', required: false }],
|
|
99
|
-
rarityIds: [{ type: mongo.Schema.Types.ObjectId, ref: 'ItemRarity', required: false }],
|
|
100
|
-
});
|
|
101
|
-
|
|
102
|
-
export const ItemRecipe = mongo.createModel<Types.ItemRecipeDocument>('ItemRecipe', {});
|
|
103
|
-
|
|
104
|
-
export const ItemSkin = mongo.createModel<Types.ItemSkinDocument>('ItemSkin', {});
|
|
105
|
-
|
|
106
|
-
export const ItemTransmute = mongo.createModel<Types.ItemTransmuteDocument>(
|
|
107
|
-
'ItemTransmute',
|
|
108
|
-
{
|
|
109
|
-
token: { type: String, maxlength: 500, required: true },
|
|
110
|
-
assetId: { type: mongo.Schema.Types.ObjectId, ref: 'Asset', required: true },
|
|
111
|
-
itemId: { type: mongo.Schema.Types.ObjectId, ref: 'Item', required: true },
|
|
112
|
-
chainId: { type: mongo.Schema.Types.ObjectId, ref: 'Chain' },
|
|
113
|
-
},
|
|
114
|
-
{
|
|
115
|
-
virtuals: [
|
|
116
|
-
{
|
|
117
|
-
name: 'item',
|
|
118
|
-
},
|
|
119
|
-
{
|
|
120
|
-
name: 'asset',
|
|
121
|
-
},
|
|
122
|
-
],
|
|
123
|
-
}
|
|
124
|
-
);
|
|
@@ -1,103 +0,0 @@
|
|
|
1
|
-
import { z as zod } from 'zod';
|
|
2
|
-
import { initTRPC } from '@trpc/server';
|
|
3
|
-
import { customErrorFormatter, hasRole } from '../../util/rpc';
|
|
4
|
-
import type { RouterContext } from '../../types';
|
|
5
|
-
import { Query, getQueryInput, inferRouterOutputs, inferRouterInputs } from '../../schema';
|
|
6
|
-
import {
|
|
7
|
-
Item,
|
|
8
|
-
ItemAttribute,
|
|
9
|
-
ItemMaterial,
|
|
10
|
-
ItemSet,
|
|
11
|
-
ItemSlot,
|
|
12
|
-
ItemRarity,
|
|
13
|
-
ItemType,
|
|
14
|
-
ItemSubType,
|
|
15
|
-
ItemSpecificType,
|
|
16
|
-
ItemAffix,
|
|
17
|
-
ItemRecipe,
|
|
18
|
-
ItemSkin,
|
|
19
|
-
ItemTransmute,
|
|
20
|
-
} from './item.schema';
|
|
21
|
-
|
|
22
|
-
export const z = zod;
|
|
23
|
-
export const t = initTRPC.context<RouterContext>().create();
|
|
24
|
-
export const router = t.router;
|
|
25
|
-
export const procedure = t.procedure;
|
|
26
|
-
|
|
27
|
-
export const createRouter = () =>
|
|
28
|
-
router({
|
|
29
|
-
getItem: procedure
|
|
30
|
-
.use(hasRole('guest', t))
|
|
31
|
-
.input(getQueryInput(Item))
|
|
32
|
-
.output(Item)
|
|
33
|
-
.query(({ input, ctx }) => (ctx.app.service.Item.getItem as any)(input, ctx)),
|
|
34
|
-
|
|
35
|
-
getItems: procedure
|
|
36
|
-
.use(hasRole('guest', t))
|
|
37
|
-
.use(customErrorFormatter(t))
|
|
38
|
-
.input(getQueryInput(Item))
|
|
39
|
-
// .output(z.array(Item))
|
|
40
|
-
.query(({ input, ctx }) => (ctx.app.service.Item.getItems as any)(input, ctx)),
|
|
41
|
-
|
|
42
|
-
createItem: procedure
|
|
43
|
-
.use(hasRole('admin', t))
|
|
44
|
-
.use(customErrorFormatter(t))
|
|
45
|
-
.input(getQueryInput(Item))
|
|
46
|
-
.output(Item.pick({ id: true }))
|
|
47
|
-
.mutation(({ input, ctx }) => (ctx.app.service.Item.createItem as any)(input, ctx)),
|
|
48
|
-
|
|
49
|
-
updateItem: procedure
|
|
50
|
-
.use(hasRole('admin', t))
|
|
51
|
-
.use(customErrorFormatter(t))
|
|
52
|
-
.input(getQueryInput(Item))
|
|
53
|
-
.output(Item.pick({ id: true }))
|
|
54
|
-
.mutation(({ input, ctx }) => (ctx.app.service.Item.updateItem as any)(input, ctx)),
|
|
55
|
-
|
|
56
|
-
getItemAttribute: procedure
|
|
57
|
-
.use(hasRole('guest', t))
|
|
58
|
-
.use(customErrorFormatter(t))
|
|
59
|
-
.input(getQueryInput(ItemAttribute))
|
|
60
|
-
.output(ItemAttribute)
|
|
61
|
-
.query(({ input, ctx }) => (ctx.app.service.Item.getItemAttribute as any)(input, ctx)),
|
|
62
|
-
|
|
63
|
-
createItemAttribute: procedure
|
|
64
|
-
.use(hasRole('admin', t))
|
|
65
|
-
.use(customErrorFormatter(t))
|
|
66
|
-
.input(getQueryInput(ItemAttribute))
|
|
67
|
-
.output(ItemAttribute.pick({ id: true }))
|
|
68
|
-
.mutation(({ input, ctx }) => (ctx.app.service.Item.createItemAttribute as any)(input, ctx)),
|
|
69
|
-
|
|
70
|
-
updateItemAttribute: procedure
|
|
71
|
-
.use(hasRole('admin', t))
|
|
72
|
-
.use(customErrorFormatter(t))
|
|
73
|
-
.input(getQueryInput(ItemAttribute))
|
|
74
|
-
.output(ItemAttribute.pick({ id: true }))
|
|
75
|
-
.mutation(({ input, ctx }) => (ctx.app.service.Item.updateItemAttribute as any)(input, ctx)),
|
|
76
|
-
|
|
77
|
-
// Add more procedures for other entities like ItemMaterial, ItemSet, ItemSlot, ItemRarity, etc.
|
|
78
|
-
|
|
79
|
-
getItemTransmute: procedure
|
|
80
|
-
.use(hasRole('guest', t))
|
|
81
|
-
.use(customErrorFormatter(t))
|
|
82
|
-
.input(getQueryInput(ItemTransmute))
|
|
83
|
-
.output(ItemTransmute)
|
|
84
|
-
.query(({ input, ctx }) => (ctx.app.service.Item.getItemTransmute as any)(input, ctx)),
|
|
85
|
-
|
|
86
|
-
createItemTransmute: procedure
|
|
87
|
-
.use(hasRole('admin', t))
|
|
88
|
-
.use(customErrorFormatter(t))
|
|
89
|
-
.input(getQueryInput(ItemTransmute))
|
|
90
|
-
.output(ItemTransmute.pick({ id: true }))
|
|
91
|
-
.mutation(({ input, ctx }) => (ctx.app.service.Item.createItemTransmute as any)(input, ctx)),
|
|
92
|
-
|
|
93
|
-
updateItemTransmute: procedure
|
|
94
|
-
.use(hasRole('admin', t))
|
|
95
|
-
.use(customErrorFormatter(t))
|
|
96
|
-
.input(getQueryInput(ItemTransmute))
|
|
97
|
-
.output(ItemTransmute.pick({ id: true }))
|
|
98
|
-
.mutation(({ input, ctx }) => (ctx.app.service.Item.updateItemTransmute as any)(input, ctx)),
|
|
99
|
-
});
|
|
100
|
-
|
|
101
|
-
export type Router = ReturnType<typeof createRouter>;
|
|
102
|
-
export type RouterInput = inferRouterInputs<Router>;
|
|
103
|
-
export type RouterOutput = inferRouterOutputs<Router>;
|