@arken/seer-protocol 0.1.1 → 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.
Files changed (112) hide show
  1. package/.rush/temp/shrinkwrap-deps.json +537 -56
  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 +26 -0
  6. package/area/index.ts +5 -0
  7. package/asset/asset.models.ts +59 -0
  8. package/asset/asset.router.ts +55 -0
  9. package/asset/asset.schema.ts +27 -0
  10. package/asset/asset.types.ts +22 -0
  11. package/asset/index.ts +5 -0
  12. package/chain/chain.models.ts +50 -0
  13. package/chain/chain.router.ts +104 -0
  14. package/chain/chain.schema.ts +52 -0
  15. package/chain/chain.types.ts +24 -0
  16. package/chain/index.ts +5 -0
  17. package/character/character.models.ts +174 -0
  18. package/character/character.router.ts +314 -0
  19. package/character/character.schema.ts +147 -0
  20. package/character/character.types.ts +64 -0
  21. package/character/index.ts +5 -0
  22. package/chat/chat.models.ts +43 -0
  23. package/chat/chat.router.ts +67 -0
  24. package/chat/chat.schema.ts +36 -0
  25. package/chat/chat.types.ts +20 -0
  26. package/chat/index.ts +5 -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 +36 -0
  31. package/collection/index.ts +5 -0
  32. package/core/core.models.ts +1380 -0
  33. package/core/core.router.ts +1781 -0
  34. package/core/core.schema.ts +847 -0
  35. package/core/core.types.ts +340 -0
  36. package/core/index.ts +5 -0
  37. package/evolution/evolution.models.ts +1 -1
  38. package/evolution/evolution.router.ts +8 -8
  39. package/evolution/evolution.schema.ts +1 -1
  40. package/evolution/evolution.types.ts +1 -1
  41. package/game/game.models.ts +53 -0
  42. package/game/game.router.ts +110 -0
  43. package/game/game.schema.ts +23 -0
  44. package/game/game.types.ts +28 -0
  45. package/game/index.ts +5 -0
  46. package/index.ts +39 -2
  47. package/infinite/infinite.models.ts +1 -1
  48. package/infinite/infinite.router.ts +8 -8
  49. package/infinite/infinite.schema.ts +1 -1
  50. package/infinite/infinite.types.ts +1 -1
  51. package/interface/index.ts +5 -0
  52. package/interface/interface.canonicalize.ts +279 -0
  53. package/interface/interface.models.ts +40 -0
  54. package/interface/interface.router.ts +175 -0
  55. package/interface/interface.schema.ts +59 -0
  56. package/interface/interface.types.ts +25 -0
  57. package/isles/isles.models.ts +1 -1
  58. package/isles/isles.router.ts +8 -8
  59. package/isles/isles.schema.ts +1 -1
  60. package/isles/isles.types.ts +1 -1
  61. package/item/index.ts +5 -0
  62. package/item/item.models.ts +124 -0
  63. package/item/item.router.ts +103 -0
  64. package/item/item.schema.ts +120 -0
  65. package/item/item.types.ts +74 -0
  66. package/job/index.ts +5 -0
  67. package/job/job.models.ts +14 -0
  68. package/job/job.router.ts +44 -0
  69. package/job/job.schema.ts +9 -0
  70. package/job/job.types.ts +23 -0
  71. package/market/index.ts +5 -0
  72. package/market/market.models.ts +113 -0
  73. package/market/market.router.ts +73 -0
  74. package/market/market.schema.ts +140 -0
  75. package/market/market.types.ts +56 -0
  76. package/oasis/oasis.models.ts +1 -1
  77. package/oasis/oasis.router.ts +2 -2
  78. package/oasis/oasis.schema.ts +1 -1
  79. package/oasis/oasis.types.ts +1 -1
  80. package/package.json +10 -3
  81. package/product/index.ts +5 -0
  82. package/product/product.models.ts +166 -0
  83. package/product/product.router.ts +93 -0
  84. package/product/product.schema.ts +149 -0
  85. package/product/product.types.ts +33 -0
  86. package/profile/index.ts +5 -0
  87. package/profile/profile.models.ts +214 -0
  88. package/profile/profile.router.ts +72 -0
  89. package/profile/profile.schema.ts +156 -0
  90. package/profile/profile.types.ts +22 -0
  91. package/raffle/index.ts +5 -0
  92. package/raffle/raffle.models.ts +44 -0
  93. package/raffle/raffle.router.ts +90 -0
  94. package/raffle/raffle.schema.ts +32 -0
  95. package/raffle/raffle.types.ts +30 -0
  96. package/router.ts +23 -29
  97. package/schema.ts +321 -0
  98. package/skill/index.ts +5 -0
  99. package/skill/skill.models.ts +16 -0
  100. package/skill/skill.router.ts +201 -0
  101. package/skill/skill.schema.ts +40 -0
  102. package/skill/skill.types.ts +33 -0
  103. package/trek/trek.models.ts +1 -1
  104. package/trek/trek.router.ts +1 -1
  105. package/trek/trek.schema.ts +1 -1
  106. package/trek/trek.types.ts +1 -1
  107. package/types.ts +172 -5
  108. package/video/index.ts +5 -0
  109. package/video/video.models.ts +25 -0
  110. package/video/video.router.ts +143 -0
  111. package/video/video.schema.ts +46 -0
  112. package/video/video.types.ts +33 -0
@@ -0,0 +1,73 @@
1
+ // module/market.router.ts
2
+
3
+ import { z as zod } from 'zod';
4
+ import { initTRPC, inferRouterInputs, inferRouterOutputs } from '@trpc/server';
5
+ import { customErrorFormatter, hasRole } from '../../util/rpc';
6
+ import type { RouterContext } from '../../types';
7
+ import { Market, MarketPair, MarketExchange } from './market.schema';
8
+
9
+ export const z = zod;
10
+ export const t = initTRPC.context<RouterContext>().create();
11
+ export const router = t.router;
12
+ export const procedure = t.procedure;
13
+
14
+ export const createRouter = () =>
15
+ router({
16
+ getMarket: procedure
17
+ .use(hasRole('guest', t))
18
+ .use(customErrorFormatter(t))
19
+ .input(z.object({ marketId: z.string() }))
20
+ .query(({ input, ctx }) => (ctx.app.service.Market.getMarket as any)(input, ctx)),
21
+
22
+ createMarket: procedure
23
+ .use(hasRole('admin', t))
24
+ .use(customErrorFormatter(t))
25
+ .input(Market)
26
+ .mutation(({ input, ctx }) => (ctx.app.service.Market.createMarket as any)(input, ctx)),
27
+
28
+ updateMarket: procedure
29
+ .use(hasRole('admin', t))
30
+ .use(customErrorFormatter(t))
31
+ .input(z.object({ marketId: z.string(), data: Market.partial() }))
32
+ .mutation(({ input, ctx }) => (ctx.app.service.Market.updateMarket as any)(input, ctx)),
33
+
34
+ getMarketPair: procedure
35
+ .use(hasRole('guest', t))
36
+ .use(customErrorFormatter(t))
37
+ .input(z.object({ marketPairId: z.string() }))
38
+ .query(({ input, ctx }) => (ctx.app.service.Market.getMarketPair as any)(input, ctx)),
39
+
40
+ createMarketPair: procedure
41
+ .use(hasRole('admin', t))
42
+ .use(customErrorFormatter(t))
43
+ .input(MarketPair)
44
+ .mutation(({ input, ctx }) => (ctx.app.service.Market.createMarketPair as any)(input, ctx)),
45
+
46
+ updateMarketPair: procedure
47
+ .use(hasRole('admin', t))
48
+ .use(customErrorFormatter(t))
49
+ .input(z.object({ marketPairId: z.string(), data: MarketPair.partial() }))
50
+ .mutation(({ input, ctx }) => (ctx.app.service.Market.updateMarketPair as any)(input, ctx)),
51
+
52
+ getMarketExchange: procedure
53
+ .use(hasRole('guest', t))
54
+ .use(customErrorFormatter(t))
55
+ .input(z.object({ exchangeId: z.string() }))
56
+ .query(({ input, ctx }) => (ctx.app.service.Market.getMarketExchange as any)(input, ctx)),
57
+
58
+ createMarketExchange: procedure
59
+ .use(hasRole('admin', t))
60
+ .use(customErrorFormatter(t))
61
+ .input(MarketExchange)
62
+ .mutation(({ input, ctx }) => (ctx.app.service.Market.createMarketExchange as any)(input, ctx)),
63
+
64
+ updateMarketExchange: procedure
65
+ .use(hasRole('admin', t))
66
+ .use(customErrorFormatter(t))
67
+ .input(z.object({ exchangeId: z.string(), data: MarketExchange.partial() }))
68
+ .mutation(({ input, ctx }) => (ctx.app.service.Market.updateMarketExchange as any)(input, ctx)),
69
+ });
70
+
71
+ export type Router = ReturnType<typeof createRouter>;
72
+ export type RouterInput = inferRouterInputs<Router>;
73
+ export type RouterOutput = inferRouterOutputs<Router>;
@@ -0,0 +1,140 @@
1
+ import { z, Entity, ObjectId } from '../../schema';
2
+
3
+ export const Market = Entity.merge(
4
+ z.object({
5
+ value: z.string(),
6
+ })
7
+ );
8
+
9
+ export const MarketPair = Entity.merge(
10
+ z.object({
11
+ value: z.string(),
12
+ })
13
+ );
14
+
15
+ export const MarketExchange = Entity.merge(
16
+ z.object({
17
+ value: z.string(),
18
+ })
19
+ );
20
+
21
+ export const MarketAnalysis = Entity.merge(
22
+ z.object({
23
+ action: z.enum(['Buy', 'Sell']), // buy or sell action
24
+ asset: z.string().min(1), // the asset being traded (e.g., oil, Bitcoin)
25
+ signalType: z.string().min(1), // type of signal (e.g., news)
26
+ confidence: z.number().min(0).max(100), // confidence level from 0 to 100
27
+ riskLevel: z.enum(['Low', 'Medium', 'High']), // risk level
28
+ timeFrame: z.enum(['Short-Term', 'Long-Term']), // investment time frame
29
+ source: z.string().min(1), // source of information (e.g., FinancialJuice, Ground News)
30
+ summary: z.string().min(1), // summary of the analysis
31
+ labels: z.object({
32
+ sector: z.string().optional(), // sector related to the asset (e.g., energy, aviation)
33
+ topic: z.string().optional(), // topic of the news (e.g., oil demand, job cuts)
34
+ sentiment: z.enum(['Positive', 'Neutral', 'Negative']).optional(), // sentiment of the news
35
+ }),
36
+ })
37
+ );
38
+
39
+ export const MarketInvestor = Entity.merge(
40
+ z.object({
41
+ portfolioIds: z.array(ObjectId), // Array of ObjectId references to InvestmentPortfolio
42
+ totalPnl: z.number().optional(), // Total profit and loss
43
+ })
44
+ );
45
+
46
+ export const MarketInvestmentPortfolio = Entity.merge(
47
+ z.object({
48
+ categoryGoals: z.array(
49
+ z.object({
50
+ category: z.string(), // Category name
51
+ goalPercentage: z.number(), // Goal percentage for this category
52
+ currentPnl: z.number().optional(), // Current P&L for this category
53
+ historicalPnL: z.number().optional(), // Historical P&L for this category
54
+ })
55
+ ), // Array of categories with goal percentages and P&L tracking
56
+ investmentIds: z.array(ObjectId), // Array of ObjectId references to Investment
57
+ totalPnl: z.number().optional(), // Total P&L for this portfolio
58
+ })
59
+ );
60
+
61
+ export const MarketInvestment = Entity.merge(
62
+ z.object({
63
+ type: z.enum(['Stock', 'ChainToken']),
64
+ category: z.enum(['Historically Safe', 'Economy Bull', 'Economy Bear', 'Custom']),
65
+ amount: z.number(), // Initial amount invested
66
+ purchasePrice: z.number(), // Price at which the investment was purchased
67
+ currentValue: z.number().optional(), // Current value of the investment
68
+ pnl: z.number().optional(), // Current P&L of the investment
69
+ transactions: z
70
+ .array(
71
+ z.object({
72
+ date: z.string(), // Date of transaction
73
+ type: z.enum(['Buy', 'Sell']),
74
+ price: z.number(), // Price at transaction
75
+ quantity: z.number(), // Quantity bought or sold
76
+ })
77
+ )
78
+ .optional(), // Optional array for detailed transaction history
79
+ stockId: ObjectId.optional(), // Reference to Stock if type is 'Stock'
80
+ chainTokenId: ObjectId.optional(), // Reference to ChainToken if type is 'ChainToken'
81
+ })
82
+ );
83
+
84
+ export const MarketStock = Entity.merge(
85
+ z.object({
86
+ ticker: z.string(),
87
+ companyId: ObjectId,
88
+ marketCap: z.number().optional(),
89
+ aum: z.number().optional(),
90
+ quoteType: z.string(),
91
+ currentPrice: z.number(),
92
+ dailyChange: z.number().optional(),
93
+ dailyChangePercent: z.number().optional(),
94
+ volume: z.number(),
95
+ currency: z.string(),
96
+ })
97
+ );
98
+
99
+ export const MarketToken = Entity.merge(
100
+ z.object({
101
+ symbol: z.string(),
102
+ currentPrice: z.number(),
103
+ })
104
+ );
105
+
106
+ export const MarketCompany = Entity.merge(
107
+ z.object({
108
+ ticker: z.string(), // Primary ticker, if applicable
109
+ type: z.enum(['Public Company', 'ETF Issuer', 'Both', 'Other']), // Categorize the company type
110
+ country: z.string().optional(), // Country where the company is based
111
+ industry: z.string().optional(), // Industry the company operates in
112
+ sector: z.string().optional(), // Sector the company belongs to
113
+ issuedETFs: z.array(ObjectId).optional(), // References to ETFs issued by this company
114
+ })
115
+ );
116
+
117
+ export const MarketETF = Entity.merge(
118
+ z.object({
119
+ ticker: z.string(),
120
+ issuerId: ObjectId, // Reference to the Company issuing the ETF
121
+ leverage: z.number().optional(), // Leverage factor if applicable (e.g., 3x)
122
+ country: z.string().optional(), // Country where the ETF is based
123
+ currency: z.string().optional(), // Currency the ETF is traded in
124
+ AUM: z.number().optional(), // Assets under management
125
+ industry: z.string().optional(), // Industry the ETF is focused on
126
+ sector: z.string().optional(), // Sector the ETF is focused on
127
+ })
128
+ );
129
+
130
+ export const MarketStockSentiment = Entity.merge(
131
+ z.object({
132
+ ticker: z.string(),
133
+ companyId: ObjectId,
134
+ sentiment: z.object({
135
+ label: z.enum(['Positive', 'Neutral', 'Negative']), // predefined sentiment labels
136
+ score: z.number().min(0).max(1), // sentiment score as a confidence percentage
137
+ }),
138
+ confidence: z.number().min(0).max(1), // overall confidence level for the analysis
139
+ })
140
+ );
@@ -0,0 +1,56 @@
1
+ // module/market.types.ts
2
+
3
+ import { z } from 'zod';
4
+ import * as schema from './market.schema';
5
+ import { Document, Model } from '../../util/mongo';
6
+ import type { RouterContext } from '../../types';
7
+ import type { inferRouterInputs, inferRouterOutputs } from '@trpc/server';
8
+ import type { Router } from './market.router';
9
+
10
+ export type * from './market.router';
11
+ export type * from './market.service';
12
+ export type { RouterContext };
13
+
14
+ export type Market = z.infer<typeof schema.Market>;
15
+ export type MarketPair = z.infer<typeof schema.MarketPair>;
16
+ export type MarketExchange = z.infer<typeof schema.MarketExchange>;
17
+ export type MarketAnalysis = z.infer<typeof schema.MarketAnalysis>;
18
+ export type MarketInvestor = z.infer<typeof schema.MarketInvestor>;
19
+ export type MarketInvestmentPortfolio = z.infer<typeof schema.MarketInvestmentPortfolio>;
20
+ export type MarketInvestment = z.infer<typeof schema.MarketInvestment>;
21
+ export type MarketStock = z.infer<typeof schema.MarketStock>;
22
+ export type MarketToken = z.infer<typeof schema.MarketToken>;
23
+ export type MarketCompany = z.infer<typeof schema.MarketCompany>;
24
+ export type MarketETF = z.infer<typeof schema.MarketETF>;
25
+ export type MarketStockSentiment = z.infer<typeof schema.MarketStockSentiment>;
26
+
27
+ export type MarketDocument = Market & Document;
28
+ export type MarketPairDocument = MarketPair & Document;
29
+ export type MarketExchangeDocument = MarketExchange & Document;
30
+ export type MarketAnalysisDocument = MarketAnalysis & Document;
31
+ export type MarketInvestorDocument = MarketInvestor & Document;
32
+ export type MarketInvestmentPortfolioDocument = MarketInvestmentPortfolio & Document;
33
+ export type MarketInvestmentDocument = MarketInvestment & Document;
34
+ export type MarketStockDocument = MarketStock & Document;
35
+ export type MarketTokenDocument = MarketToken & Document;
36
+ export type MarketCompanyDocument = MarketCompany & Document;
37
+ export type MarketETFDocument = MarketETF & Document;
38
+ export type MarketStockSentimentDocument = MarketStockSentiment & Document;
39
+
40
+ export type Mappings = {
41
+ Market: Model<MarketDocument>;
42
+ MarketPair: Model<MarketPairDocument>;
43
+ MarketExchange: Model<MarketExchangeDocument>;
44
+ MarketAnalysis: Model<MarketAnalysisDocument>;
45
+ MarketInvestor: Model<MarketInvestorDocument>;
46
+ MarketInvestmentPortfolio: Model<MarketInvestmentPortfolioDocument>;
47
+ MarketInvestment: Model<MarketInvestmentDocument>;
48
+ MarketStock: Model<MarketStockDocument>;
49
+ MarketToken: Model<MarketTokenDocument>;
50
+ MarketCompany: Model<MarketCompanyDocument>;
51
+ MarketETF: Model<MarketETFDocument>;
52
+ MarketStockSentiment: Model<MarketStockSentimentDocument>;
53
+ };
54
+
55
+ export type RouterInput = inferRouterInputs<Router>;
56
+ export type RouterOutput = inferRouterOutputs<Router>;
@@ -1,3 +1,3 @@
1
- import * as mongo from '@arken/mongo';
1
+ import * as mongo from '@arken/node/mongo';
2
2
 
3
3
  const { addTagVirtuals, addApplicationVirtual } = mongo;
@@ -1,8 +1,8 @@
1
1
  import { z as zod } from 'zod';
2
2
  import { initTRPC } from '@trpc/server';
3
- import { customErrorFormatter, hasRole } from '@arken/rpc';
3
+ import { customErrorFormatter, hasRole } from '@arken/node/rpc';
4
4
  import * as Arken from '@arken/node';
5
- import { Query, getQueryInput, inferRouterOutputs, inferRouterInputs } from '@arken/schema';
5
+ import { Query, getQueryInput, inferRouterOutputs, inferRouterInputs } from '@arken/node/schema';
6
6
  import { RouterContext } from '../../types';
7
7
 
8
8
  export const z = zod;
@@ -1 +1 @@
1
- import { z, ObjectId, Entity } from '@arken/schema';
1
+ import { z, ObjectId, Entity } from '@arken/node/schema';
@@ -1,5 +1,5 @@
1
1
  import { z } from 'zod';
2
- import { Model, Document } from '@arken/mongo';
2
+ import { Model, Document } from '@arken/node/mongo';
3
3
  import * as schema from './oasis.schema';
4
4
 
5
5
  export type * from './oasis.router';
package/package.json CHANGED
@@ -1,9 +1,16 @@
1
1
  {
2
2
  "name": "@arken/seer-protocol",
3
- "version": "0.1.1",
4
- "main": "src/index.ts",
5
- "scripts": {},
3
+ "version": "0.1.2",
4
+ "main": "index.ts",
5
+ "scripts": {
6
+ "build": "npm-run-all dist",
7
+ "clean": "del-cli ./build && make-dir ./build",
8
+ "dist": "npm-run-all clean tsc:*",
9
+ "publish": "npm publish --access=public",
10
+ "tsc:1": "rm -rf ./build && mkdir ./build && cp package.json ./build && NODE_ENV=production NODE_OPTIONS=--max-old-space-size=8192 tsc"
11
+ },
6
12
  "dependencies": {
13
+ "@arken/node": "^1.5.2",
7
14
  "@arken/forge-protocol": "^0.1.1",
8
15
  "@trpc/client": "11.0.0-rc.660",
9
16
  "@trpc/server": "11.0.0-rc.660",
@@ -0,0 +1,5 @@
1
+ export * as Types from './product.types';
2
+ export * as Models from './product.models';
3
+ export * as Schemas from './product.schema';
4
+ export * from './product.router';
5
+ export * from './product.service';
@@ -0,0 +1,166 @@
1
+ import * as mongo from '../../util/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 '../../util/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>;