@arken/seer-protocol 0.1.0 → 0.1.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/.rush/temp/shrinkwrap-deps.json +537 -56
- package/area/area.models.ts +15 -0
- package/area/area.router.ts +74 -0
- package/area/area.schema.ts +22 -0
- package/area/area.types.ts +26 -0
- package/area/index.ts +5 -0
- package/asset/asset.models.ts +59 -0
- package/asset/asset.router.ts +55 -0
- package/asset/asset.schema.ts +27 -0
- package/asset/asset.types.ts +22 -0
- package/asset/index.ts +5 -0
- package/chain/chain.models.ts +50 -0
- package/chain/chain.router.ts +104 -0
- package/chain/chain.schema.ts +52 -0
- package/chain/chain.types.ts +24 -0
- package/chain/index.ts +5 -0
- package/character/character.models.ts +174 -0
- package/character/character.router.ts +314 -0
- package/character/character.schema.ts +147 -0
- package/character/character.types.ts +64 -0
- package/character/index.ts +5 -0
- package/chat/chat.models.ts +43 -0
- package/chat/chat.router.ts +67 -0
- package/chat/chat.schema.ts +36 -0
- package/chat/chat.types.ts +20 -0
- package/chat/index.ts +5 -0
- package/collection/collection.models.ts +76 -0
- package/collection/collection.router.ts +91 -0
- package/collection/collection.schema.ts +90 -0
- package/collection/collection.types.ts +36 -0
- package/collection/index.ts +5 -0
- package/core/core.models.ts +1380 -0
- package/core/core.router.ts +1781 -0
- package/core/core.schema.ts +847 -0
- package/core/core.types.ts +340 -0
- package/core/index.ts +5 -0
- package/{src/modules/evolution → evolution}/evolution.models.ts +1 -1
- package/{src/modules/evolution → evolution}/evolution.router.ts +5 -5
- package/{src/modules/evolution → evolution}/evolution.types.ts +1 -1
- package/game/game.models.ts +53 -0
- package/game/game.router.ts +110 -0
- package/game/game.schema.ts +23 -0
- package/game/game.types.ts +28 -0
- package/game/index.ts +5 -0
- package/index.ts +59 -0
- package/{src/modules/infinite → infinite}/infinite.models.ts +1 -1
- package/{src/modules/infinite → infinite}/infinite.router.ts +5 -5
- package/{src/modules/infinite → infinite}/infinite.types.ts +1 -1
- package/interface/index.ts +5 -0
- package/interface/interface.canonicalize.ts +279 -0
- package/interface/interface.models.ts +40 -0
- package/interface/interface.router.ts +175 -0
- package/interface/interface.schema.ts +59 -0
- package/interface/interface.types.ts +25 -0
- package/{src/modules/isles → isles}/isles.models.ts +1 -1
- package/{src/modules/isles → isles}/isles.router.ts +5 -5
- package/{src/modules/isles → isles}/isles.types.ts +1 -1
- package/item/index.ts +5 -0
- package/item/item.models.ts +124 -0
- package/item/item.router.ts +103 -0
- package/item/item.schema.ts +120 -0
- package/item/item.types.ts +74 -0
- package/job/index.ts +5 -0
- package/job/job.models.ts +14 -0
- package/job/job.router.ts +44 -0
- package/job/job.schema.ts +9 -0
- package/job/job.types.ts +23 -0
- package/market/index.ts +5 -0
- package/market/market.models.ts +113 -0
- package/market/market.router.ts +73 -0
- package/market/market.schema.ts +140 -0
- package/market/market.types.ts +56 -0
- package/{src/modules/oasis → oasis}/oasis.models.ts +1 -1
- package/{src/modules/oasis → oasis}/oasis.router.ts +1 -1
- package/{src/modules/oasis → oasis}/oasis.types.ts +1 -1
- package/package.json +12 -14
- package/product/index.ts +5 -0
- package/product/product.models.ts +166 -0
- package/product/product.router.ts +93 -0
- package/product/product.schema.ts +149 -0
- package/product/product.types.ts +33 -0
- package/profile/index.ts +5 -0
- package/profile/profile.models.ts +214 -0
- package/profile/profile.router.ts +72 -0
- package/profile/profile.schema.ts +156 -0
- package/profile/profile.types.ts +22 -0
- package/raffle/index.ts +5 -0
- package/raffle/raffle.models.ts +44 -0
- package/raffle/raffle.router.ts +90 -0
- package/raffle/raffle.schema.ts +32 -0
- package/raffle/raffle.types.ts +30 -0
- package/{src/router.ts → router.ts} +22 -28
- package/schema.ts +321 -0
- package/skill/index.ts +5 -0
- package/skill/skill.models.ts +16 -0
- package/skill/skill.router.ts +201 -0
- package/skill/skill.schema.ts +40 -0
- package/skill/skill.types.ts +33 -0
- package/{src/modules/trek → trek}/trek.router.ts +1 -1
- package/types.ts +273 -0
- package/video/index.ts +5 -0
- package/video/video.models.ts +25 -0
- package/video/video.router.ts +143 -0
- package/video/video.schema.ts +46 -0
- package/video/video.types.ts +33 -0
- package/src/index.ts +0 -22
- package/src/modules/evolution/evolution.service.ts +0 -2000
- package/src/modules/infinite/infinite.service.ts +0 -40
- package/src/modules/isles/isles.service.ts +0 -40
- package/src/modules/oasis/oasis.service.ts +0 -38
- package/src/modules/trek/trek.service.ts +0 -1031
- package/src/types.ts +0 -106
- /package/{src/modules/evolution → evolution}/evolution.schema.ts +0 -0
- /package/{src/modules/evolution → evolution}/index.ts +0 -0
- /package/{src/modules/infinite → infinite}/index.ts +0 -0
- /package/{src/modules/infinite → infinite}/infinite.schema.ts +0 -0
- /package/{src/modules/isles → isles}/index.ts +0 -0
- /package/{src/modules/isles → isles}/isles.schema.ts +0 -0
- /package/{src/modules/oasis → oasis}/index.ts +0 -0
- /package/{src/modules/oasis → oasis}/oasis.schema.ts +0 -0
- /package/{src/modules/trek → trek}/index.ts +0 -0
- /package/{src/modules/trek → trek}/trek.models.ts +0 -0
- /package/{src/modules/trek → trek}/trek.schema.ts +0 -0
- /package/{src/modules/trek → trek}/trek.types.ts +0 -0
|
@@ -0,0 +1,44 @@
|
|
|
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
|
+
});
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { z as zod } from 'zod';
|
|
2
|
+
import { initTRPC, inferRouterInputs, inferRouterOutputs } from '@trpc/server';
|
|
3
|
+
import { customErrorFormatter, hasRole } from '../../util/rpc';
|
|
4
|
+
import type { RouterContext } from '../../types';
|
|
5
|
+
import { Raffle, RaffleRequirement, RaffleReward, RaffleEntry } from './raffle.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
|
+
// Raffle endpoints
|
|
15
|
+
getRaffle: procedure
|
|
16
|
+
.use(hasRole('guest', t))
|
|
17
|
+
.use(customErrorFormatter(t))
|
|
18
|
+
.input(z.object({ raffleId: z.string() }))
|
|
19
|
+
.query(({ input, ctx }) => (ctx.app.service.Raffle.getRaffle as any)(input, ctx)),
|
|
20
|
+
|
|
21
|
+
createRaffle: procedure
|
|
22
|
+
.use(hasRole('admin', t))
|
|
23
|
+
.use(customErrorFormatter(t))
|
|
24
|
+
.input(Raffle)
|
|
25
|
+
.mutation(({ input, ctx }) => (ctx.app.service.Raffle.createRaffle as any)(input, ctx)),
|
|
26
|
+
|
|
27
|
+
updateRaffle: procedure
|
|
28
|
+
.use(hasRole('admin', t))
|
|
29
|
+
.use(customErrorFormatter(t))
|
|
30
|
+
.input(z.object({ raffleId: z.string(), data: Raffle.partial() }))
|
|
31
|
+
.mutation(({ input, ctx }) => (ctx.app.service.Raffle.updateRaffle as any)(input, ctx)),
|
|
32
|
+
|
|
33
|
+
getRaffleRequirement: procedure
|
|
34
|
+
.use(hasRole('guest', t))
|
|
35
|
+
.use(customErrorFormatter(t))
|
|
36
|
+
.input(z.object({ raffleRequirementId: z.string() }))
|
|
37
|
+
.query(({ input, ctx }) => (ctx.app.service.Raffle.getRaffleRequirement as any)(input, ctx)),
|
|
38
|
+
|
|
39
|
+
createRaffleRequirement: procedure
|
|
40
|
+
.use(hasRole('admin', t))
|
|
41
|
+
.use(customErrorFormatter(t))
|
|
42
|
+
.input(RaffleRequirement)
|
|
43
|
+
.mutation(({ input, ctx }) => (ctx.app.service.Raffle.createRaffleRequirement as any)(input, ctx)),
|
|
44
|
+
|
|
45
|
+
updateRaffleRequirement: procedure
|
|
46
|
+
.use(hasRole('admin', t))
|
|
47
|
+
.use(customErrorFormatter(t))
|
|
48
|
+
.input(z.object({ raffleRequirementId: z.string(), data: RaffleRequirement.partial() }))
|
|
49
|
+
.mutation(({ input, ctx }) => (ctx.app.service.Raffle.updateRaffleRequirement as any)(input, ctx)),
|
|
50
|
+
|
|
51
|
+
getRaffleReward: procedure
|
|
52
|
+
.use(hasRole('guest', t))
|
|
53
|
+
.use(customErrorFormatter(t))
|
|
54
|
+
.input(z.object({ raffleRewardId: z.string() }))
|
|
55
|
+
.query(({ input, ctx }) => (ctx.app.service.Raffle.getRaffleReward as any)(input, ctx)),
|
|
56
|
+
|
|
57
|
+
createRaffleReward: procedure
|
|
58
|
+
.use(hasRole('admin', t))
|
|
59
|
+
.use(customErrorFormatter(t))
|
|
60
|
+
.input(RaffleReward)
|
|
61
|
+
.mutation(({ input, ctx }) => (ctx.app.service.Raffle.createRaffleReward as any)(input, ctx)),
|
|
62
|
+
|
|
63
|
+
updateRaffleReward: procedure
|
|
64
|
+
.use(hasRole('admin', t))
|
|
65
|
+
.use(customErrorFormatter(t))
|
|
66
|
+
.input(z.object({ raffleRewardId: z.string(), data: RaffleReward.partial() }))
|
|
67
|
+
.mutation(({ input, ctx }) => (ctx.app.service.Raffle.updateRaffleReward as any)(input, ctx)),
|
|
68
|
+
|
|
69
|
+
getRaffleEntry: procedure
|
|
70
|
+
.use(hasRole('guest', t))
|
|
71
|
+
.use(customErrorFormatter(t))
|
|
72
|
+
.input(z.object({ raffleEntryId: z.string() }))
|
|
73
|
+
.query(({ input, ctx }) => (ctx.app.service.Raffle.getRaffleEntry as any)(input, ctx)),
|
|
74
|
+
|
|
75
|
+
createRaffleEntry: procedure
|
|
76
|
+
.use(hasRole('admin', t))
|
|
77
|
+
.use(customErrorFormatter(t))
|
|
78
|
+
.input(RaffleEntry)
|
|
79
|
+
.mutation(({ input, ctx }) => (ctx.app.service.Raffle.createRaffleEntry as any)(input, ctx)),
|
|
80
|
+
|
|
81
|
+
updateRaffleEntry: procedure
|
|
82
|
+
.use(hasRole('admin', t))
|
|
83
|
+
.use(customErrorFormatter(t))
|
|
84
|
+
.input(z.object({ raffleEntryId: z.string(), data: RaffleEntry.partial() }))
|
|
85
|
+
.mutation(({ input, ctx }) => (ctx.app.service.Raffle.updateRaffleEntry as any)(input, ctx)),
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
export type Router = ReturnType<typeof createRouter>;
|
|
89
|
+
export type RouterInput = inferRouterInputs<Router>;
|
|
90
|
+
export type RouterOutput = inferRouterOutputs<Router>;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { z, ObjectId, Entity } from '../../schema';
|
|
2
|
+
|
|
3
|
+
export const Raffle = Entity.merge(
|
|
4
|
+
z.object({
|
|
5
|
+
content: z.string().min(1),
|
|
6
|
+
rewards: z.array(ObjectId).optional(), // List of reward IDs
|
|
7
|
+
})
|
|
8
|
+
);
|
|
9
|
+
|
|
10
|
+
export const RaffleRequirement = Entity.merge(
|
|
11
|
+
z.object({
|
|
12
|
+
amount: z.number().min(1),
|
|
13
|
+
raffleRewardId: ObjectId.optional(), // Reference to the associated RaffleReward
|
|
14
|
+
})
|
|
15
|
+
);
|
|
16
|
+
|
|
17
|
+
export const RaffleReward = Entity.merge(
|
|
18
|
+
z.object({
|
|
19
|
+
raffleId: ObjectId.optional(), // Reference to the associated Raffle
|
|
20
|
+
winnerId: ObjectId.optional(), // Reference to the winning Profile
|
|
21
|
+
requirements: z.array(ObjectId).optional(), // List of associated RaffleRequirement IDs
|
|
22
|
+
entries: z.array(ObjectId).optional(), // List of associated RaffleEntry IDs
|
|
23
|
+
})
|
|
24
|
+
);
|
|
25
|
+
|
|
26
|
+
export const RaffleEntry = Entity.merge(
|
|
27
|
+
z.object({
|
|
28
|
+
amount: z.number().min(1),
|
|
29
|
+
raffleRewardId: ObjectId.optional(), // Reference to the associated RaffleReward
|
|
30
|
+
raffleId: ObjectId.optional(), // Reference to the associated Raffle
|
|
31
|
+
})
|
|
32
|
+
);
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import * as schema from './raffle.schema';
|
|
3
|
+
import { Document, Model } from '../../util/mongo';
|
|
4
|
+
import type { RouterContext } from '../../types';
|
|
5
|
+
import type { inferRouterInputs, inferRouterOutputs } from '@trpc/server';
|
|
6
|
+
import type { Router } from './raffle.router';
|
|
7
|
+
|
|
8
|
+
export type * from './raffle.router';
|
|
9
|
+
export type * from './raffle.service';
|
|
10
|
+
export type { RouterContext };
|
|
11
|
+
|
|
12
|
+
export type Raffle = z.infer<typeof schema.Raffle>;
|
|
13
|
+
export type RaffleRequirement = z.infer<typeof schema.RaffleRequirement>;
|
|
14
|
+
export type RaffleReward = z.infer<typeof schema.RaffleReward>;
|
|
15
|
+
export type RaffleEntry = z.infer<typeof schema.RaffleEntry>;
|
|
16
|
+
|
|
17
|
+
export type RaffleDocument = Raffle & Document;
|
|
18
|
+
export type RaffleRequirementDocument = RaffleRequirement & Document;
|
|
19
|
+
export type RaffleRewardDocument = RaffleReward & Document;
|
|
20
|
+
export type RaffleEntryDocument = RaffleEntry & Document;
|
|
21
|
+
|
|
22
|
+
export type Mappings = {
|
|
23
|
+
Raffle: Model<RaffleDocument>;
|
|
24
|
+
RaffleRequirement: Model<RaffleRequirementDocument>;
|
|
25
|
+
RaffleReward: Model<RaffleRewardDocument>;
|
|
26
|
+
RaffleEntry: Model<RaffleEntryDocument>;
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
export type RouterInput = inferRouterInputs<Router>;
|
|
30
|
+
export type RouterOutput = inferRouterOutputs<Router>;
|
|
@@ -1,34 +1,28 @@
|
|
|
1
|
-
import util from '@arken/node/util';
|
|
2
1
|
import { initTRPC } from '@trpc/server';
|
|
3
|
-
import { observable } from '@trpc/server/observable';
|
|
4
|
-
import { serialize, deserialize } from '@arken/node/util/rpc';
|
|
5
2
|
import { z } from 'zod';
|
|
6
|
-
import { customErrorFormatter, hasRole } from '@arken/node/util/rpc';
|
|
7
|
-
import { Query, getQueryInput, getQueryOutput, inferRouterOutputs } from '@arken/node/schema';
|
|
8
|
-
import * as Arken from '@arken/node/types';
|
|
9
3
|
import * as Schema from '@arken/node/schema';
|
|
10
|
-
import * as Area from '
|
|
11
|
-
import * as Asset from '
|
|
12
|
-
import * as Character from '
|
|
13
|
-
import * as Chain from '
|
|
14
|
-
import * as Chat from '
|
|
15
|
-
import * as Collection from '
|
|
16
|
-
import * as Core from '
|
|
17
|
-
import * as Game from '
|
|
18
|
-
import * as Interface from '
|
|
19
|
-
import * as Item from '
|
|
20
|
-
import * as Job from '
|
|
21
|
-
import * as Market from '
|
|
22
|
-
import * as Product from '
|
|
23
|
-
import * as Profile from '
|
|
24
|
-
import * as Raffle from '
|
|
25
|
-
import * as Skill from '
|
|
26
|
-
import * as Video from '
|
|
27
|
-
import * as Trek from './
|
|
28
|
-
import * as Isles from './
|
|
29
|
-
import * as Evolution from './
|
|
30
|
-
import * as Infinite from './
|
|
31
|
-
import * as Oasis from './
|
|
4
|
+
import * as Area from './area/area.router';
|
|
5
|
+
import * as Asset from './asset/asset.router';
|
|
6
|
+
import * as Character from './character/character.router';
|
|
7
|
+
import * as Chain from './chain/chain.router';
|
|
8
|
+
import * as Chat from './chat/chat.router';
|
|
9
|
+
import * as Collection from './collection/collection.router';
|
|
10
|
+
import * as Core from './core/core.router';
|
|
11
|
+
import * as Game from './game/game.router';
|
|
12
|
+
import * as Interface from './interface/interface.router';
|
|
13
|
+
import * as Item from './item/item.router';
|
|
14
|
+
import * as Job from './job/job.router';
|
|
15
|
+
import * as Market from './market/market.router';
|
|
16
|
+
import * as Product from './product/product.router';
|
|
17
|
+
import * as Profile from './profile/profile.router';
|
|
18
|
+
import * as Raffle from './raffle/raffle.router';
|
|
19
|
+
import * as Skill from './skill/skill.router';
|
|
20
|
+
import * as Video from './video/video.router';
|
|
21
|
+
import * as Trek from './trek/trek.router';
|
|
22
|
+
import * as Isles from './isles/isles.router';
|
|
23
|
+
import * as Evolution from './evolution/evolution.router';
|
|
24
|
+
import * as Infinite from './infinite/infinite.router';
|
|
25
|
+
import * as Oasis from './oasis/oasis.router';
|
|
32
26
|
import type * as Types from './types';
|
|
33
27
|
|
|
34
28
|
export type RouterContext = {
|
package/schema.ts
ADDED
|
@@ -0,0 +1,321 @@
|
|
|
1
|
+
// arken/packages/node/schema.ts
|
|
2
|
+
//
|
|
3
|
+
import Mongoose, { Types } from 'mongoose';
|
|
4
|
+
import { z as zod, ZodTypeAny, ZodLazy, ZodObject, ZodArray } from 'zod';
|
|
5
|
+
import { AnyProcedure, inferProcedureOutput, AnyRouter, AnyTRPCClientTypes, TRPCRouterRecord } from '@trpc/server';
|
|
6
|
+
|
|
7
|
+
export type { inferRouterInputs } from '@trpc/server';
|
|
8
|
+
|
|
9
|
+
export const z = zod;
|
|
10
|
+
|
|
11
|
+
// @ts-ignore
|
|
12
|
+
export const ObjectId = z.union([
|
|
13
|
+
z.string().refine((value) => Mongoose.isValidObjectId(value), {
|
|
14
|
+
// Accept valid ObjectId strings
|
|
15
|
+
message: 'Invalid ObjectId',
|
|
16
|
+
}),
|
|
17
|
+
z.instanceof(Types.ObjectId), // Accept Mongoose ObjectId instances
|
|
18
|
+
]);
|
|
19
|
+
|
|
20
|
+
export const Anything = z.any();
|
|
21
|
+
export const Nothing = z.object({});
|
|
22
|
+
export const Signature = z.object({ hash: z.string(), address: z.string() });
|
|
23
|
+
export const UnsignedData = z.object({ data: z.any() });
|
|
24
|
+
export const SignedData = z.object({
|
|
25
|
+
data: z.any(),
|
|
26
|
+
signature: Signature,
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
export const AnyInput = z.any();
|
|
30
|
+
export const OnlySignatureInput = z.object({ signature: Signature });
|
|
31
|
+
export const NoDataOutput = z.object({ status: z.number() });
|
|
32
|
+
export const AnyDataOutput = z.object({ data: z.any(), status: z.number() });
|
|
33
|
+
|
|
34
|
+
export enum Status {
|
|
35
|
+
Paused = 'Paused',
|
|
36
|
+
Pending = 'Pending',
|
|
37
|
+
Active = 'Active',
|
|
38
|
+
Archived = 'Archived',
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export type Meta = {
|
|
42
|
+
[key: string]: unknown;
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
export const Common = z.object({
|
|
46
|
+
id: ObjectId.optional(),
|
|
47
|
+
meta: z.any(), // Default value set here matches Mongoose
|
|
48
|
+
data: z.any(), // Default value set here matches Mongoose
|
|
49
|
+
status: z.enum(['Paused', 'Pending', 'Active', 'Archived']).default('Active'), // Default set in StatusEnum matches Mongoose
|
|
50
|
+
merkleLeaf: z.string().optional(),
|
|
51
|
+
merkleIndex: z.number().optional(),
|
|
52
|
+
createdById: ObjectId.optional(),
|
|
53
|
+
editedById: ObjectId.optional(),
|
|
54
|
+
deletedById: ObjectId.optional(),
|
|
55
|
+
createdDate: z.date().default(() => new Date()), // Default matches Mongoose
|
|
56
|
+
updatedDate: z.date().optional(),
|
|
57
|
+
deletedDate: z.date().optional(),
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
export type Common = zod.infer<typeof Common>;
|
|
61
|
+
|
|
62
|
+
export const Entity = z
|
|
63
|
+
.object({
|
|
64
|
+
id: z.string().min(24).max(24).trim().optional(),
|
|
65
|
+
key: z.string().min(1).max(200).trim().optional(),
|
|
66
|
+
name: z.string().min(1).max(200).trim().optional(),
|
|
67
|
+
description: z.string().optional(),
|
|
68
|
+
applicationId: ObjectId.optional(),
|
|
69
|
+
ownerId: ObjectId.optional(),
|
|
70
|
+
})
|
|
71
|
+
.merge(Common);
|
|
72
|
+
|
|
73
|
+
export type Entity = zod.infer<typeof Entity>;
|
|
74
|
+
|
|
75
|
+
const QueryFilterOperators = z.object({
|
|
76
|
+
equals: z.any().optional(),
|
|
77
|
+
not: z.any().optional(),
|
|
78
|
+
in: z.array(z.any()).optional(),
|
|
79
|
+
notIn: z.array(z.any()).optional(),
|
|
80
|
+
lt: z.any().optional(),
|
|
81
|
+
lte: z.any().optional(),
|
|
82
|
+
gt: z.any().optional(),
|
|
83
|
+
gte: z.any().optional(),
|
|
84
|
+
contains: z.string().optional(),
|
|
85
|
+
startsWith: z.string().optional(),
|
|
86
|
+
endsWith: z.string().optional(),
|
|
87
|
+
mode: z.enum(['default', 'insensitive']).optional(),
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
const QueryWhereSchema = z.lazy(() =>
|
|
91
|
+
z.object({
|
|
92
|
+
AND: z.array(QueryWhereSchema).optional(),
|
|
93
|
+
OR: z.array(QueryWhereSchema).optional(),
|
|
94
|
+
NOT: z.array(QueryWhereSchema).optional(),
|
|
95
|
+
id: QueryFilterOperators.optional(),
|
|
96
|
+
key: QueryFilterOperators.optional(),
|
|
97
|
+
name: QueryFilterOperators.optional(),
|
|
98
|
+
email: QueryFilterOperators.optional(),
|
|
99
|
+
status: QueryFilterOperators.optional(),
|
|
100
|
+
})
|
|
101
|
+
);
|
|
102
|
+
|
|
103
|
+
export const Query = z.object({
|
|
104
|
+
skip: z.number().default(0).optional(),
|
|
105
|
+
take: z.number().default(10).optional(),
|
|
106
|
+
cursor: z.record(z.any()).optional(),
|
|
107
|
+
where: QueryWhereSchema.optional(),
|
|
108
|
+
orderBy: z.record(z.enum(['asc', 'desc'])).optional(),
|
|
109
|
+
include: z.record(z.boolean()).optional(),
|
|
110
|
+
select: z.record(z.boolean()).optional(),
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
// // Operators for filtering in a Prisma-like way
|
|
114
|
+
// type PrismaFilterOperators<T extends ZodTypeAny> = zod.ZodObject<
|
|
115
|
+
// {
|
|
116
|
+
// equals?: T;
|
|
117
|
+
// not?: T;
|
|
118
|
+
// in?: zod.ZodArray<T>;
|
|
119
|
+
// notIn?: zod.ZodArray<T>;
|
|
120
|
+
// lt?: T;
|
|
121
|
+
// lte?: T;
|
|
122
|
+
// gt?: T;
|
|
123
|
+
// gte?: T;
|
|
124
|
+
// contains?: zod.ZodString; // T extends zod.ZodString ? zod.ZodString : never;
|
|
125
|
+
// startsWith?: zod.ZodString; // T extends zod.ZodString ? zod.ZodString : never;
|
|
126
|
+
// endsWith?: zod.ZodString; // T extends zod.ZodString ? zod.ZodString : never;
|
|
127
|
+
// mode?: zod.ZodString; // T extends zod.ZodString ? zod.ZodEnum<['default', 'insensitive']> : never;
|
|
128
|
+
// },
|
|
129
|
+
// 'strip',
|
|
130
|
+
// ZodTypeAny
|
|
131
|
+
// >;
|
|
132
|
+
|
|
133
|
+
// // Level 0: No AND, OR, NOT
|
|
134
|
+
// type PrismaWhereLevel0<T extends zod.ZodRawShape> = ZodObject<
|
|
135
|
+
// {
|
|
136
|
+
// [K in keyof T]?: PrismaFilterOperators<T[K]>;
|
|
137
|
+
// },
|
|
138
|
+
// 'strip',
|
|
139
|
+
// ZodTypeAny
|
|
140
|
+
// >;
|
|
141
|
+
|
|
142
|
+
// // Level 1: Includes AND, OR, NOT of Level 0
|
|
143
|
+
// type PrismaWhereLevel1<T extends zod.ZodRawShape> = ZodObject<
|
|
144
|
+
// {
|
|
145
|
+
// AND?: ZodArray<ZodLazy<PrismaWhereLevel0<T>>>;
|
|
146
|
+
// OR?: ZodArray<ZodLazy<PrismaWhereLevel0<T>>>;
|
|
147
|
+
// NOT?: ZodArray<ZodLazy<PrismaWhereLevel0<T>>>;
|
|
148
|
+
// } & {
|
|
149
|
+
// [K in keyof T]?: PrismaFilterOperators<T[K]>;
|
|
150
|
+
// },
|
|
151
|
+
// 'strip',
|
|
152
|
+
// ZodTypeAny
|
|
153
|
+
// >;
|
|
154
|
+
|
|
155
|
+
// // Level 2: Includes AND, OR, NOT of Level 1
|
|
156
|
+
// type PrismaWhereLevel2<T extends zod.ZodRawShape> = ZodObject<
|
|
157
|
+
// {
|
|
158
|
+
// AND?: ZodArray<ZodLazy<PrismaWhereLevel1<T>>>;
|
|
159
|
+
// OR?: ZodArray<ZodLazy<PrismaWhereLevel1<T>>>;
|
|
160
|
+
// NOT?: ZodArray<ZodLazy<PrismaWhereLevel1<T>>>;
|
|
161
|
+
// } & {
|
|
162
|
+
// [K in keyof T]?: PrismaFilterOperators<T[K]>;
|
|
163
|
+
// },
|
|
164
|
+
// 'strip',
|
|
165
|
+
// ZodTypeAny
|
|
166
|
+
// >;
|
|
167
|
+
|
|
168
|
+
// // Level 3: Includes AND, OR, NOT of Level 2
|
|
169
|
+
// type PrismaWhereLevel3<T extends zod.ZodRawShape> = ZodObject<
|
|
170
|
+
// {
|
|
171
|
+
// AND?: ZodArray<ZodLazy<PrismaWhereLevel2<T>>>;
|
|
172
|
+
// OR?: ZodArray<ZodLazy<PrismaWhereLevel2<T>>>;
|
|
173
|
+
// NOT?: ZodArray<ZodLazy<PrismaWhereLevel2<T>>>;
|
|
174
|
+
// } & {
|
|
175
|
+
// [K in keyof T]?: PrismaFilterOperators<T[K]>;
|
|
176
|
+
// },
|
|
177
|
+
// 'strip',
|
|
178
|
+
// ZodTypeAny
|
|
179
|
+
// >;
|
|
180
|
+
|
|
181
|
+
// // Level 4: Includes AND, OR, NOT of Level 3
|
|
182
|
+
// type PrismaWhereLevel4<T extends zod.ZodRawShape> = ZodObject<
|
|
183
|
+
// {
|
|
184
|
+
// AND?: ZodArray<ZodLazy<PrismaWhereLevel3<T>>>;
|
|
185
|
+
// OR?: ZodArray<ZodLazy<PrismaWhereLevel3<T>>>;
|
|
186
|
+
// NOT?: ZodArray<ZodLazy<PrismaWhereLevel3<T>>>;
|
|
187
|
+
// } & {
|
|
188
|
+
// [K in keyof T]?: PrismaFilterOperators<T[K]>;
|
|
189
|
+
// },
|
|
190
|
+
// 'strip',
|
|
191
|
+
// ZodTypeAny
|
|
192
|
+
// >;
|
|
193
|
+
|
|
194
|
+
// Function to create a recursive schema up to level 4
|
|
195
|
+
export const createPrismaWhereSchema = <T extends zod.ZodRawShape>(
|
|
196
|
+
modelSchema: zod.ZodObject<T>,
|
|
197
|
+
depth: number = 3
|
|
198
|
+
): zod.ZodObject<any> => {
|
|
199
|
+
const fields = modelSchema.shape;
|
|
200
|
+
|
|
201
|
+
/**
|
|
202
|
+
* For each field, accept either:
|
|
203
|
+
* - a full operator object: { equals, in, lt, ... }
|
|
204
|
+
* - OR a raw value shorthand: 'foo' -> { equals: 'foo' }
|
|
205
|
+
*/
|
|
206
|
+
const makeFieldFilter = (value: zod.ZodTypeAny) => {
|
|
207
|
+
const opsSchema = zod
|
|
208
|
+
.object({
|
|
209
|
+
equals: value.optional(),
|
|
210
|
+
not: value.optional(),
|
|
211
|
+
in: zod.array(value).optional(),
|
|
212
|
+
notIn: zod.array(value).optional(),
|
|
213
|
+
lt: value.optional(),
|
|
214
|
+
lte: value.optional(),
|
|
215
|
+
gt: value.optional(),
|
|
216
|
+
gte: value.optional(),
|
|
217
|
+
contains: zod.string().optional(),
|
|
218
|
+
startsWith: zod.string().optional(),
|
|
219
|
+
endsWith: zod.string().optional(),
|
|
220
|
+
mode: zod.string().optional(),
|
|
221
|
+
})
|
|
222
|
+
.partial();
|
|
223
|
+
|
|
224
|
+
return zod
|
|
225
|
+
.preprocess((input) => {
|
|
226
|
+
// let undefined through
|
|
227
|
+
if (input === undefined) return input;
|
|
228
|
+
|
|
229
|
+
// Already an object (likely { equals, in, ... }) → validate as-is
|
|
230
|
+
if (typeof input === 'object' && input !== null && !Array.isArray(input)) {
|
|
231
|
+
return input;
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
// Prisma-style shorthand: profileId: 'abc' -> { equals: 'abc' }
|
|
235
|
+
return { equals: input };
|
|
236
|
+
}, opsSchema)
|
|
237
|
+
.optional();
|
|
238
|
+
};
|
|
239
|
+
|
|
240
|
+
const fieldFilters = Object.fromEntries(Object.entries(fields).map(([key, value]) => [key, makeFieldFilter(value)]));
|
|
241
|
+
|
|
242
|
+
if (depth <= 0) {
|
|
243
|
+
// Base case: no AND/OR/NOT
|
|
244
|
+
return zod.object({
|
|
245
|
+
...fieldFilters,
|
|
246
|
+
});
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
return zod.object({
|
|
250
|
+
AND: zod.array(zod.lazy(() => createPrismaWhereSchema(modelSchema, depth - 1))).optional(),
|
|
251
|
+
OR: zod.array(zod.lazy(() => createPrismaWhereSchema(modelSchema, depth - 1))).optional(),
|
|
252
|
+
NOT: zod.array(zod.lazy(() => createPrismaWhereSchema(modelSchema, depth - 1))).optional(),
|
|
253
|
+
...fieldFilters,
|
|
254
|
+
});
|
|
255
|
+
};
|
|
256
|
+
|
|
257
|
+
export const getQueryOutput = <T extends zod.ZodTypeAny>(data: T) => {
|
|
258
|
+
return z.object({ status: z.number(), data: data.optional(), error: z.string().optional() });
|
|
259
|
+
};
|
|
260
|
+
|
|
261
|
+
export const getQueryInput = <S extends zod.ZodTypeAny>(schema: S, options: { partialData?: boolean } = {}) => {
|
|
262
|
+
const { partialData = true } = options;
|
|
263
|
+
|
|
264
|
+
// Only object schemas get "where" support.
|
|
265
|
+
const isObjectSchema = schema instanceof zod.ZodObject;
|
|
266
|
+
|
|
267
|
+
const whereSchema = isObjectSchema
|
|
268
|
+
? createPrismaWhereSchema(schema as any) // keep your existing recursive builder
|
|
269
|
+
: zod.never(); // not used; also prevents people from sending "where" for arrays
|
|
270
|
+
|
|
271
|
+
const dataSchema = isObjectSchema
|
|
272
|
+
? partialData
|
|
273
|
+
? (schema as any).partial().optional()
|
|
274
|
+
: (schema as any).optional()
|
|
275
|
+
: schema.optional(); // arrays: allow full array
|
|
276
|
+
|
|
277
|
+
const querySchema = zod
|
|
278
|
+
.object({
|
|
279
|
+
data: dataSchema,
|
|
280
|
+
|
|
281
|
+
// keep your query envelope fields
|
|
282
|
+
skip: zod.number().default(0).optional(),
|
|
283
|
+
limit: zod.number().default(10).optional(),
|
|
284
|
+
cursor: zod.record(zod.any()).optional(),
|
|
285
|
+
|
|
286
|
+
// only valid for object schemas
|
|
287
|
+
where: isObjectSchema ? whereSchema.optional() : zod.undefined().optional(),
|
|
288
|
+
|
|
289
|
+
orderBy: zod.record(zod.enum(['asc', 'desc'])).optional(),
|
|
290
|
+
include: zod.record(zod.boolean()).optional(),
|
|
291
|
+
select: zod.record(zod.boolean()).optional(),
|
|
292
|
+
})
|
|
293
|
+
.partial();
|
|
294
|
+
|
|
295
|
+
return zod.union([querySchema, zod.undefined()]);
|
|
296
|
+
};
|
|
297
|
+
|
|
298
|
+
export type inferQuery<T extends zod.ZodRawShape> = zod.infer<ReturnType<typeof createPrismaWhereSchema<T>>>;
|
|
299
|
+
|
|
300
|
+
export type GetInferenceHelpers<
|
|
301
|
+
TType extends 'input' | 'output',
|
|
302
|
+
TRoot extends AnyTRPCClientTypes,
|
|
303
|
+
TRecord extends TRPCRouterRecord
|
|
304
|
+
> = {
|
|
305
|
+
[TKey in keyof TRecord]: TRecord[TKey] extends infer $Value
|
|
306
|
+
? $Value extends TRPCRouterRecord
|
|
307
|
+
? GetInferenceHelpers<TType, TRoot, $Value>
|
|
308
|
+
: $Value extends AnyProcedure
|
|
309
|
+
? inferProcedureOutput<$Value> // inferTransformedProcedureOutput<TRoot, $Value>
|
|
310
|
+
: never
|
|
311
|
+
: never;
|
|
312
|
+
};
|
|
313
|
+
|
|
314
|
+
export type inferRouterOutputs<TRouter extends AnyRouter> = GetInferenceHelpers<
|
|
315
|
+
'output',
|
|
316
|
+
TRouter['_def']['_config']['$types'],
|
|
317
|
+
TRouter['_def']['record']
|
|
318
|
+
>;
|
|
319
|
+
|
|
320
|
+
// type SpecificOutput = Router['_def']['record']['createInterfaceDraft']['_def']['$types']['output'];
|
|
321
|
+
// type TestOutput = RouterOutput['createInterfaceDraft'];
|
package/skill/index.ts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import * as mongo from '../../util/mongo';
|
|
2
|
+
import type * as Types from './skill.types';
|
|
3
|
+
|
|
4
|
+
export const Skill = mongo.createModel<Types.SkillDocument>('Skill', {});
|
|
5
|
+
|
|
6
|
+
export const SkillMod = mongo.createModel<Types.SkillModDocument>('SkillMod', {});
|
|
7
|
+
|
|
8
|
+
export const SkillClassification = mongo.createModel<Types.SkillClassificationDocument>('SkillClassification', {});
|
|
9
|
+
|
|
10
|
+
export const SkillCondition = mongo.createModel<Types.SkillConditionDocument>('SkillCondition', {});
|
|
11
|
+
|
|
12
|
+
export const SkillStatusEffect = mongo.createModel<Types.SkillStatusEffectDocument>('SkillStatusEffect', {});
|
|
13
|
+
|
|
14
|
+
export const SkillTree = mongo.createModel<Types.SkillTreeDocument>('SkillTree', {});
|
|
15
|
+
|
|
16
|
+
export const SkillTreeNode = mongo.createModel<Types.SkillTreeNodeDocument>('SkillTreeNode', {});
|