@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.
Files changed (160) hide show
  1. package/build/modules/character/character.service.js.map +1 -1
  2. package/build/modules/chat/chat.service.js.map +1 -1
  3. package/build/modules/core/core.models.js.map +1 -1
  4. package/build/modules/core/core.service.js.map +1 -1
  5. package/build/modules/profile/profile.service.js.map +1 -1
  6. package/build/package.json +2 -2
  7. package/build/tsconfig.tsbuildinfo +1 -1
  8. package/build/types.d.ts +1 -0
  9. package/build/types.js +1 -0
  10. package/build/types.js.map +1 -1
  11. package/build/util/mongo.js.map +1 -1
  12. package/db.ts +76 -1
  13. package/index.ts +351 -18
  14. package/{util/mongo.ts → mongo.ts} +2 -0
  15. package/package.json +3 -3
  16. package/tsconfig.json +33 -2
  17. package/types.ts +2 -0
  18. package/util.ts +1 -0
  19. package/modules/area/area.models.ts +0 -15
  20. package/modules/area/area.router.ts +0 -74
  21. package/modules/area/area.schema.ts +0 -22
  22. package/modules/area/area.service.ts +0 -124
  23. package/modules/area/area.types.ts +0 -26
  24. package/modules/area/index.ts +0 -5
  25. package/modules/asset/asset.models.ts +0 -59
  26. package/modules/asset/asset.router.ts +0 -55
  27. package/modules/asset/asset.schema.ts +0 -27
  28. package/modules/asset/asset.service.ts +0 -85
  29. package/modules/asset/asset.types.ts +0 -22
  30. package/modules/asset/index.ts +0 -5
  31. package/modules/chain/chain.models.ts +0 -50
  32. package/modules/chain/chain.router.ts +0 -104
  33. package/modules/chain/chain.schema.ts +0 -52
  34. package/modules/chain/chain.service.ts +0 -167
  35. package/modules/chain/chain.types.ts +0 -24
  36. package/modules/chain/index.ts +0 -5
  37. package/modules/character/character.models.ts +0 -174
  38. package/modules/character/character.router.ts +0 -314
  39. package/modules/character/character.schema.ts +0 -147
  40. package/modules/character/character.service.ts +0 -875
  41. package/modules/character/character.types.ts +0 -64
  42. package/modules/character/index.ts +0 -5
  43. package/modules/chat/chat.models.ts +0 -43
  44. package/modules/chat/chat.router.ts +0 -67
  45. package/modules/chat/chat.schema.ts +0 -36
  46. package/modules/chat/chat.service.ts +0 -120
  47. package/modules/chat/chat.types.ts +0 -20
  48. package/modules/chat/index.ts +0 -5
  49. package/modules/collection/collection.models.ts +0 -76
  50. package/modules/collection/collection.router.ts +0 -91
  51. package/modules/collection/collection.schema.ts +0 -90
  52. package/modules/collection/collection.service.ts +0 -192
  53. package/modules/collection/collection.types.ts +0 -36
  54. package/modules/collection/index.ts +0 -5
  55. package/modules/core/core.models.ts +0 -1379
  56. package/modules/core/core.router.ts +0 -1781
  57. package/modules/core/core.schema.ts +0 -847
  58. package/modules/core/core.service.ts +0 -2822
  59. package/modules/core/core.types.ts +0 -340
  60. package/modules/core/index.ts +0 -5
  61. package/modules/core/mail/applyPatchesOrMail.ts +0 -568
  62. package/modules/core/mail/mailClaimablePatchesBatch.ts +0 -381
  63. package/modules/game/game.models.ts +0 -53
  64. package/modules/game/game.router.ts +0 -110
  65. package/modules/game/game.schema.ts +0 -23
  66. package/modules/game/game.service.ts +0 -143
  67. package/modules/game/game.types.ts +0 -28
  68. package/modules/game/index.ts +0 -5
  69. package/modules/interface/index.ts +0 -5
  70. package/modules/interface/interface.canonicalize.ts +0 -279
  71. package/modules/interface/interface.models.ts +0 -40
  72. package/modules/interface/interface.router.ts +0 -175
  73. package/modules/interface/interface.schema.ts +0 -59
  74. package/modules/interface/interface.service.ts +0 -356
  75. package/modules/interface/interface.types.ts +0 -25
  76. package/modules/item/index.ts +0 -5
  77. package/modules/item/item.models.ts +0 -124
  78. package/modules/item/item.router.ts +0 -103
  79. package/modules/item/item.schema.ts +0 -120
  80. package/modules/item/item.service.ts +0 -167
  81. package/modules/item/item.types.ts +0 -74
  82. package/modules/job/index.ts +0 -5
  83. package/modules/job/job.models.ts +0 -14
  84. package/modules/job/job.router.ts +0 -44
  85. package/modules/job/job.schema.ts +0 -9
  86. package/modules/job/job.service.ts +0 -243
  87. package/modules/job/job.types.ts +0 -23
  88. package/modules/market/index.ts +0 -5
  89. package/modules/market/market.models.ts +0 -113
  90. package/modules/market/market.router.ts +0 -73
  91. package/modules/market/market.schema.ts +0 -140
  92. package/modules/market/market.service.ts +0 -122
  93. package/modules/market/market.types.ts +0 -56
  94. package/modules/product/index.ts +0 -5
  95. package/modules/product/product.models.ts +0 -166
  96. package/modules/product/product.router.ts +0 -93
  97. package/modules/product/product.schema.ts +0 -149
  98. package/modules/product/product.service.ts +0 -160
  99. package/modules/product/product.types.ts +0 -33
  100. package/modules/profile/index.ts +0 -5
  101. package/modules/profile/profile.models.ts +0 -214
  102. package/modules/profile/profile.router.ts +0 -72
  103. package/modules/profile/profile.schema.ts +0 -156
  104. package/modules/profile/profile.service.ts +0 -147
  105. package/modules/profile/profile.types.ts +0 -22
  106. package/modules/raffle/index.ts +0 -5
  107. package/modules/raffle/raffle.models.ts +0 -44
  108. package/modules/raffle/raffle.router.ts +0 -90
  109. package/modules/raffle/raffle.schema.ts +0 -32
  110. package/modules/raffle/raffle.service.ts +0 -167
  111. package/modules/raffle/raffle.types.ts +0 -30
  112. package/modules/skill/index.ts +0 -5
  113. package/modules/skill/skill.models.ts +0 -16
  114. package/modules/skill/skill.router.ts +0 -201
  115. package/modules/skill/skill.schema.ts +0 -40
  116. package/modules/skill/skill.service.ts +0 -390
  117. package/modules/skill/skill.types.ts +0 -33
  118. package/modules/video/index.ts +0 -5
  119. package/modules/video/video.models.ts +0 -25
  120. package/modules/video/video.router.ts +0 -143
  121. package/modules/video/video.schema.ts +0 -46
  122. package/modules/video/video.service.ts +0 -274
  123. package/modules/video/video.types.ts +0 -33
  124. package/util/db/index.ts +0 -7
  125. package/util/db/isPostgresError.ts +0 -9
  126. package/util/db/isUniqueConstraintViolation.ts +0 -3
  127. package/util/db.ts +0 -62
  128. package/util/index.ts +0 -351
  129. /package/{util/api.ts → api.ts} +0 -0
  130. /package/{util/array.ts → array.ts} +0 -0
  131. /package/{util/browser.ts → browser.ts} +0 -0
  132. /package/{util/codebase.ts → codebase.ts} +0 -0
  133. /package/{util/config.ts → config.ts} +0 -0
  134. /package/{util/decoder.test.ts → decoder.test.ts} +0 -0
  135. /package/{util/decoder.ts → decoder.ts} +0 -0
  136. /package/{util/format.ts → format.ts} +0 -0
  137. /package/{util/guid.ts → guid.ts} +0 -0
  138. /package/{util/json.ts → json.ts} +0 -0
  139. /package/{util/log.ts → log.ts} +0 -0
  140. /package/{util/math.ts → math.ts} +0 -0
  141. /package/{util/merkle.ts → merkle.ts} +0 -0
  142. /package/{util/number.ts → number.ts} +0 -0
  143. /package/{util/object.ts → object.ts} +0 -0
  144. /package/{util/otp.ts → otp.ts} +0 -0
  145. /package/{util/physics.ts → physics.ts} +0 -0
  146. /package/{util/process.ts → process.ts} +0 -0
  147. /package/{util/rpc.ts → rpc.ts} +0 -0
  148. /package/{util/seer.ts → seer.ts} +0 -0
  149. /package/{util/string.ts → string.ts} +0 -0
  150. /package/{util/text.ts → text.ts} +0 -0
  151. /package/{util/time → time}/date.ts +0 -0
  152. /package/{util/time → time}/fancyTimeFormat.ts +0 -0
  153. /package/{util/time → time}/index.ts +0 -0
  154. /package/{util/time → time}/now.ts +0 -0
  155. /package/{util/types → types}/mongo.d.ts +0 -0
  156. /package/{util/web3 → web3}/httpProvider.ts +0 -0
  157. /package/{util/web3.ts → web3.ts} +0 -0
  158. /package/{util/websocket.ts → websocket.ts} +0 -0
  159. /package/{util/zk.ts → zk.ts} +0 -0
  160. /package/{util/zod.ts → zod.ts} +0 -0
@@ -1,26 +0,0 @@
1
- import { z } from 'zod';
2
- import * as schema from './area.schema';
3
- import { Document, Model } from '../../util/mongo';
4
-
5
- export type * from './area.router';
6
- export type * from './area.service';
7
- export type { RouterContext } from '../../types';
8
-
9
- export type Area = z.infer<typeof schema.Area>;
10
- export type AreaDocument = Area & Document;
11
-
12
- export type AreaLandmark = z.infer<typeof schema.AreaLandmark>;
13
- export type AreaLandmarkDocument = AreaLandmark & Document;
14
-
15
- export type AreaType = z.infer<typeof schema.AreaType>;
16
- export type AreaTypeDocument = AreaType & Document;
17
-
18
- export type AreaNameChoice = z.infer<typeof schema.AreaNameChoice>;
19
- export type AreaNameChoiceDocument = AreaNameChoice & Document;
20
-
21
- export type Mappings = {
22
- Area: Model<AreaDocument>;
23
- AreaLandmark: Model<AreaLandmarkDocument>;
24
- AreaType: Model<AreaTypeDocument>;
25
- AreaNameChoice: Model<AreaNameChoiceDocument>;
26
- };
@@ -1,5 +0,0 @@
1
- export * as Types from './area.types';
2
- export * as Models from './area.models';
3
- export * as Schemas from './area.schema';
4
- export * from './area.router';
5
- export * from './area.service';
@@ -1,59 +0,0 @@
1
- import * as mongo from '../../util/mongo';
2
- import type * as Types from './asset.types';
3
-
4
- export const AssetStandard = mongo.createModel<Types.AssetStandardDocument>(
5
- 'AssetStandard',
6
- {
7
- version: { type: String, required: false },
8
- parentId: { type: mongo.Schema.Types.ObjectId, ref: 'AssetStandard', required: false },
9
- },
10
- {
11
- virtuals: [
12
- {
13
- name: 'children',
14
- ref: 'AssetStandard',
15
- localField: '_id',
16
- foreignField: 'parent',
17
- justOne: false,
18
- },
19
- ],
20
- }
21
- );
22
-
23
- export const Asset = mongo.createModel<Types.AssetDocument>(
24
- 'Asset',
25
- {
26
- uri: { type: String, required: true },
27
- type: { type: String, maxlength: 100, required: true },
28
- standards: [{ type: mongo.Schema.Types.ObjectId, ref: 'AssetStandard', required: true }],
29
- licenseId: { type: mongo.Schema.Types.ObjectId, ref: 'AssetLicense' },
30
- chainId: { type: mongo.Schema.Types.ObjectId, ref: 'Chain' },
31
- ownerId: { type: mongo.Schema.Types.ObjectId, ref: 'Profile' }, // Added ownerId
32
- // skin: { type: String },
33
- // transmuteCount: { type: Number },
34
- // score: { type: Number },
35
- },
36
- {
37
- virtuals: [
38
- {
39
- name: 'items',
40
- ref: 'Item',
41
- localField: '_id',
42
- foreignField: 'assetId',
43
- },
44
- {
45
- name: 'offers',
46
- ref: 'Node',
47
- localField: '_id',
48
- foreignField: 'fromOfferId',
49
- justOne: false,
50
- match: { relationKey: 'offers' },
51
- },
52
- ],
53
- }
54
- );
55
-
56
- export const AssetLicense = mongo.createModel<Types.AssetLicenseDocument>('AssetLicense', {
57
- value: { type: String, required: true },
58
- // assets: [{ type: mongo.Schema.Types.ObjectId, ref: 'Asset' }],
59
- });
@@ -1,55 +0,0 @@
1
- // module/asset.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 { Asset, AssetLicense } from './asset.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
- getAsset: procedure
17
- .use(hasRole('guest', t))
18
- .use(customErrorFormatter(t))
19
- .input(z.object({ assetId: z.string() }))
20
- .query(({ input, ctx }) => (ctx.app.service.Asset.getAsset as any)(input, ctx)),
21
-
22
- createAsset: procedure
23
- .use(hasRole('admin', t))
24
- .use(customErrorFormatter(t))
25
- .input(Asset)
26
- .mutation(({ input, ctx }) => (ctx.app.service.Asset.createAsset as any)(input, ctx)),
27
-
28
- updateAsset: procedure
29
- .use(hasRole('admin', t))
30
- .use(customErrorFormatter(t))
31
- .input(z.object({ assetId: z.string(), data: Asset.partial() }))
32
- .mutation(({ input, ctx }) => (ctx.app.service.Asset.updateAsset as any)(input, ctx)),
33
-
34
- getAssetLicense: procedure
35
- .use(hasRole('guest', t))
36
- .use(customErrorFormatter(t))
37
- .input(z.object({ assetLicenseId: z.string() }))
38
- .query(({ input, ctx }) => (ctx.app.service.Asset.getAssetLicense as any)(input, ctx)),
39
-
40
- createAssetLicense: procedure
41
- .use(hasRole('admin', t))
42
- .use(customErrorFormatter(t))
43
- .input(AssetLicense)
44
- .mutation(({ input, ctx }) => (ctx.app.service.Asset.createAssetLicense as any)(input, ctx)),
45
-
46
- updateAssetLicense: procedure
47
- .use(hasRole('admin', t))
48
- .use(customErrorFormatter(t))
49
- .input(z.object({ assetLicenseId: z.string(), data: AssetLicense.partial() }))
50
- .mutation(({ input, ctx }) => (ctx.app.service.Asset.updateAssetLicense as any)(input, ctx)),
51
- });
52
-
53
- export type Router = ReturnType<typeof createRouter>;
54
- export type RouterInput = inferRouterInputs<Router>;
55
- export type RouterOutput = inferRouterOutputs<Router>;
@@ -1,27 +0,0 @@
1
- import { z, ObjectId, Entity } from '../../schema';
2
-
3
- export const AssetStandard = Entity.merge(
4
- z.object({
5
- version: z.string().optional(),
6
- parentId: ObjectId.optional(),
7
- })
8
- );
9
-
10
- export const Asset = Entity.merge(
11
- z.object({
12
- uri: z.string().min(1),
13
- type: z.string().max(100).min(1),
14
- standards: z.array(ObjectId),
15
- licenseId: ObjectId.optional(),
16
- license: ObjectId.optional(),
17
- chainId: ObjectId.optional(),
18
- items: z.array(ObjectId).optional(),
19
- })
20
- );
21
-
22
- export const AssetLicense = Entity.merge(
23
- z.object({
24
- value: z.string().min(1),
25
- assets: z.array(ObjectId).optional(),
26
- })
27
- );
@@ -1,85 +0,0 @@
1
- import type { Asset, AssetLicense, Router, RouterInput, RouterOutput, RouterContext } from './asset.types';
2
-
3
- export class Service {
4
- async getAsset(input: RouterInput['getAsset'], ctx: RouterContext): Promise<RouterOutput['getAsset']> {
5
- if (!input) throw new Error('Input should not be void');
6
- console.log('Asset.Service.getAsset', input.assetId);
7
-
8
- const asset = await ctx.app.model.Asset.findById(input.assetId).lean().exec();
9
- if (!asset) throw new Error('Asset not found');
10
-
11
- return asset as Asset;
12
- }
13
-
14
- async getAssetLicense(
15
- input: RouterInput['getAssetLicense'],
16
- ctx: RouterContext
17
- ): Promise<RouterOutput['getAssetLicense']> {
18
- if (!input) throw new Error('Input should not be void');
19
- console.log('Asset.Service.getAssetLicense', input.assetLicenseId);
20
-
21
- const assetLicense = await ctx.app.model.AssetLicense.findById(input.assetLicenseId).lean().exec();
22
- if (!assetLicense) throw new Error('AssetLicense not found');
23
-
24
- return assetLicense as AssetLicense;
25
- }
26
-
27
- async createAsset(input: RouterInput['createAsset'], ctx: RouterContext): Promise<RouterOutput['createAsset']> {
28
- if (!input) throw new Error('Input should not be void');
29
- console.log('Asset.Service.createAsset', input.uri, input.type);
30
-
31
- const asset = await ctx.app.model.Asset.create({
32
- uri: input.uri,
33
- type: input.type,
34
- standards: input.standards,
35
- licenseId: input.licenseId,
36
- chainId: input.chainId,
37
- });
38
-
39
- return asset as Asset;
40
- }
41
-
42
- async createAssetLicense(
43
- input: RouterInput['createAssetLicense'],
44
- ctx: RouterContext
45
- ): Promise<RouterOutput['createAssetLicense']> {
46
- if (!input) throw new Error('Input should not be void');
47
- console.log('Asset.Service.createAssetLicense', input.value);
48
-
49
- const assetLicense = await ctx.app.model.AssetLicense.create({
50
- value: input.value,
51
- assets: input.assets,
52
- });
53
-
54
- return assetLicense as AssetLicense;
55
- }
56
-
57
- async updateAsset(input: RouterInput['updateAsset'], ctx: RouterContext): Promise<RouterOutput['updateAsset']> {
58
- if (!input) throw new Error('Input should not be void');
59
- console.log('Asset.Service.updateAsset', input.assetId, input.data);
60
-
61
- const updatedAsset = await ctx.app.model.Asset.findByIdAndUpdate(input.assetId, input.data, { new: true })
62
- .lean()
63
- .exec();
64
- if (!updatedAsset) throw new Error('Asset update failed');
65
-
66
- return updatedAsset as Asset;
67
- }
68
-
69
- async updateAssetLicense(
70
- input: RouterInput['updateAssetLicense'],
71
- ctx: RouterContext
72
- ): Promise<RouterOutput['updateAssetLicense']> {
73
- if (!input) throw new Error('Input should not be void');
74
- console.log('Asset.Service.updateAssetLicense', input.assetLicenseId, input.data);
75
-
76
- const updatedAssetLicense = await ctx.app.model.AssetLicense.findByIdAndUpdate(input.assetLicenseId, input.data, {
77
- new: true,
78
- })
79
- .lean()
80
- .exec();
81
- if (!updatedAssetLicense) throw new Error('AssetLicense update failed');
82
-
83
- return updatedAssetLicense as AssetLicense;
84
- }
85
- }
@@ -1,22 +0,0 @@
1
- import { z } from 'zod';
2
- import * as schema from './asset.schema';
3
- import { Document, Model } from '../../util/mongo';
4
-
5
- export type * from './asset.router';
6
- export type * from './asset.service';
7
- export type { RouterContext } from '../../types';
8
-
9
- export type Asset = z.infer<typeof schema.Asset>;
10
- export type AssetDocument = Asset & Document;
11
-
12
- export type AssetStandard = z.infer<typeof schema.AssetStandard>;
13
- export type AssetStandardDocument = AssetStandard & Document;
14
-
15
- export type AssetLicense = z.infer<typeof schema.AssetLicense>;
16
- export type AssetLicenseDocument = AssetLicense & Document;
17
-
18
- export type Mappings = {
19
- Asset: Model<AssetDocument>;
20
- AssetStandard: Model<AssetStandardDocument>;
21
- AssetLicense: Model<AssetLicenseDocument>;
22
- };
@@ -1,5 +0,0 @@
1
- export * as Types from './asset.types';
2
- export * as Models from './asset.models';
3
- export * as Schemas from './asset.schema';
4
- export * from './asset.router';
5
- export * from './asset.service';
@@ -1,50 +0,0 @@
1
- import * as mongo from '../../util/mongo';
2
- import type * as Types from './chain.types';
3
-
4
- export const Chain = mongo.createModel<Types.ChainDocument>('Chain', {
5
- content: { type: String, required: true },
6
- type: { type: String, maxlength: 100, required: true },
7
- });
8
-
9
- export const ChainContract = mongo.createModel<Types.ChainContractDocument>('ChainContract', {
10
- chainId: { type: mongo.Schema.Types.ObjectId, ref: 'Chain', required: true },
11
- content: { type: String },
12
- address: { type: String },
13
- type: { type: String, maxlength: 100, required: true },
14
- standards: [{ type: mongo.Schema.Types.ObjectId, ref: 'AssetStandard', required: true }],
15
- });
16
-
17
- export const ChainToken = mongo.createModel<Types.ChainTokenDocument>(
18
- 'ChainToken',
19
- {
20
- chainId: { type: mongo.Schema.Types.ObjectId, ref: 'Chain', required: true },
21
- chainContractId: { type: mongo.Schema.Types.ObjectId, ref: 'ChainContract', required: true },
22
- rank: { type: Number, min: 0, default: 0 },
23
- description: { type: String, trim: true },
24
- address: { type: String },
25
- content: { type: String },
26
- decimals: { type: Number, default: 0 },
27
- price: { type: Number, min: 0, default: 0 },
28
- hourChange: { type: Number, default: 0 },
29
- dayChange: { type: Number, default: 0 },
30
- weekChange: { type: Number, default: 0 },
31
- marketCap: { type: Number, min: 0, default: 0 },
32
- volume: { type: Number, min: 0, default: 0 },
33
- symbol: { type: String, required: true, trim: true },
34
- circulatingSupply: { type: Number, min: 0, default: 0 },
35
- cmcLink: { type: String, trim: true },
36
- movementDown: { type: Number, min: 0, default: 0 },
37
- movementUp: { type: Number, min: 0, default: 0 },
38
- enteredTop100: { type: Number, min: 0, default: 0 },
39
- exitedTop100: { type: Number, min: 0, default: 0 },
40
- largeMoveDown: { type: Number, min: 0, default: 0 },
41
- },
42
- {
43
- indexes: [{ applicationId: 1, symbol: 1, unique: true }],
44
- }
45
- );
46
-
47
- export const ChainTransaction = mongo.createModel<Types.ChainTransactionDocument>('ChainTransaction', {
48
- value: { type: String, required: true },
49
- chainId: { type: mongo.Schema.Types.ObjectId, ref: 'Chain', required: true },
50
- });
@@ -1,104 +0,0 @@
1
- // module/chain.router.ts
2
-
3
- import { z as zod } from 'zod';
4
- import { initTRPC, inferRouterInputs } from '@trpc/server';
5
- import { customErrorFormatter, hasRole } from '../../util/rpc';
6
- import type { RouterContext } from '../../types';
7
- import { Chain, ChainContract, ChainToken, ChainTransaction } from './chain.schema';
8
- import { Query, getQueryInput, getQueryOutput, inferRouterOutputs } from '../../schema';
9
-
10
- export const z = zod;
11
- export const t = initTRPC.context<RouterContext>().create();
12
- export const router = t.router;
13
- export const procedure = t.procedure;
14
-
15
- export const createRouter = () =>
16
- router({
17
- getChain: procedure
18
- .use(hasRole('guest', t))
19
- .use(customErrorFormatter(t))
20
- .input(getQueryInput(Chain))
21
- .output(Chain)
22
- .query(({ input, ctx }) => (ctx.app.service.Chain.getChain as any)(input, ctx)),
23
-
24
- createChain: procedure
25
- .use(hasRole('admin', t))
26
- .use(customErrorFormatter(t))
27
- .input(getQueryInput(Chain))
28
- .output(Chain.pick({ id: true }))
29
- .mutation(({ input, ctx }) => (ctx.app.service.Chain.createChain as any)(input, ctx)),
30
-
31
- updateChain: procedure
32
- .use(hasRole('admin', t))
33
- .use(customErrorFormatter(t))
34
- .input(getQueryInput(Chain))
35
- .output(Chain.pick({ id: true }))
36
- .mutation(({ input, ctx }) => (ctx.app.service.Chain.updateChain as any)(input, ctx)),
37
-
38
- getChainContract: procedure
39
- .use(hasRole('guest', t))
40
- .use(customErrorFormatter(t))
41
- .input(getQueryInput(ChainContract))
42
- .output(ChainContract)
43
- .query(({ input, ctx }) => (ctx.app.service.Chain.getChainContract as any)(input, ctx)),
44
-
45
- createChainContract: procedure
46
- .use(hasRole('admin', t))
47
- .use(customErrorFormatter(t))
48
- .input(getQueryInput(ChainContract))
49
- .output(ChainContract.pick({ id: true }))
50
- .mutation(({ input, ctx }) => (ctx.app.service.Chain.createChainContract as any)(input, ctx)),
51
-
52
- updateChainContract: procedure
53
- .use(hasRole('admin', t))
54
- .use(customErrorFormatter(t))
55
- .input(getQueryInput(ChainContract))
56
- .output(ChainContract.pick({ id: true }))
57
- .mutation(({ input, ctx }) => (ctx.app.service.Chain.updateChainContract as any)(input, ctx)),
58
-
59
- getChainToken: procedure
60
- .use(hasRole('guest', t))
61
- .use(customErrorFormatter(t))
62
- .input(getQueryInput(ChainToken))
63
- .output(ChainToken)
64
- .query(({ input, ctx }) => (ctx.app.service.Chain.getChainToken as any)(input, ctx)),
65
-
66
- createChainToken: procedure
67
- .use(hasRole('admin', t))
68
- .use(customErrorFormatter(t))
69
- .input(getQueryInput(ChainToken))
70
- .output(ChainToken.pick({ id: true }))
71
- .mutation(({ input, ctx }) => (ctx.app.service.Chain.createChainToken as any)(input, ctx)),
72
-
73
- updateChainToken: procedure
74
- .use(hasRole('admin', t))
75
- .use(customErrorFormatter(t))
76
- .input(getQueryInput(ChainToken))
77
- .output(ChainToken.pick({ id: true }))
78
- .mutation(({ input, ctx }) => (ctx.app.service.Chain.updateChainToken as any)(input, ctx)),
79
-
80
- getChainTransaction: procedure
81
- .use(hasRole('guest', t))
82
- .use(customErrorFormatter(t))
83
- .input(getQueryInput(ChainTransaction))
84
- .output(ChainTransaction)
85
- .query(({ input, ctx }) => (ctx.app.service.Chain.getChainTransaction as any)(input, ctx)),
86
-
87
- createChainTransaction: procedure
88
- .use(hasRole('admin', t))
89
- .use(customErrorFormatter(t))
90
- .input(getQueryInput(ChainTransaction))
91
- .output(ChainTransaction.pick({ id: true }))
92
- .mutation(({ input, ctx }) => (ctx.app.service.Chain.createChainTransaction as any)(input, ctx)),
93
-
94
- updateChainTransaction: procedure
95
- .use(hasRole('admin', t))
96
- .use(customErrorFormatter(t))
97
- .input(getQueryInput(ChainTransaction))
98
- .output(ChainTransaction.pick({ id: true }))
99
- .mutation(({ input, ctx }) => (ctx.app.service.Chain.updateChainTransaction as any)(input, ctx)),
100
- });
101
-
102
- export type Router = ReturnType<typeof createRouter>;
103
- export type RouterInput = inferRouterInputs<Router>;
104
- export type RouterOutput = inferRouterOutputs<Router>;
@@ -1,52 +0,0 @@
1
- import { z, ObjectId, Entity } from '../../schema';
2
-
3
- export const Chain = Entity.merge(
4
- z.object({
5
- content: z.string().min(1),
6
- type: z.string().max(100).min(1),
7
- standard: z.string().max(100).min(1),
8
- })
9
- );
10
-
11
- export const ChainContract = Entity.merge(
12
- z.object({
13
- chainId: ObjectId,
14
- content: z.string().min(1).optional(),
15
- address: z.string().max(100),
16
- type: z.string().max(100).min(1),
17
- standards: z.array(ObjectId),
18
- })
19
- );
20
-
21
- export const ChainToken = Entity.merge(
22
- z.object({
23
- chainId: ObjectId,
24
- chainContractId: ObjectId,
25
- address: z.string().max(100), // TODO: validate address?
26
- decimals: z.number().optional(),
27
- rank: z.number().optional(),
28
- description: z.string().optional(),
29
- content: z.string().min(1).optional(),
30
- price: z.number().optional(),
31
- hourChange: z.number().optional(),
32
- dayChange: z.number().optional(),
33
- weekChange: z.number().optional(),
34
- marketCap: z.number().optional(),
35
- volume: z.number().optional(),
36
- symbol: z.string().min(1),
37
- circulatingSupply: z.number().optional(),
38
- cmcLink: z.string().optional(),
39
- movementDown: z.number().optional(),
40
- movementUp: z.number().optional(),
41
- enteredTop100: z.number().optional(),
42
- exitedTop100: z.number().optional(),
43
- largeMoveDown: z.number().optional(),
44
- })
45
- );
46
-
47
- export const ChainTransaction = Entity.merge(
48
- z.object({
49
- value: z.string().min(1),
50
- chainId: ObjectId,
51
- })
52
- );
@@ -1,167 +0,0 @@
1
- import type {
2
- Chain,
3
- ChainContract,
4
- ChainToken,
5
- ChainTransaction,
6
- Router,
7
- RouterInput,
8
- RouterOutput,
9
- RouterContext,
10
- } from './chain.types';
11
- import { ARXError } from '../../util/rpc';
12
- import { getFilter } from '../../util/api';
13
-
14
- export class Service {
15
- async getChain(input: RouterInput['getChain'], ctx: RouterContext): Promise<RouterOutput['getChain']> {
16
- if (!input) throw new ARXError('NO_INPUT');
17
- console.log('Chain.Service.getChain', input);
18
-
19
- const chain = await ctx.app.model.Chain.findOne(getFilter(input)).lean().exec();
20
- if (!chain) throw new Error('Chain not found');
21
-
22
- return chain as Chain;
23
- }
24
-
25
- async getChainContract(
26
- input: RouterInput['getChainContract'],
27
- ctx: RouterContext
28
- ): Promise<RouterOutput['getChainContract']> {
29
- if (!input) throw new ARXError('NO_INPUT');
30
- console.log('Chain.Service.getChainContract', input);
31
-
32
- const chainContract = await ctx.app.model.ChainContract.findOne(getFilter(input)).lean().exec();
33
- if (!chainContract) throw new Error('ChainContract not found');
34
-
35
- return chainContract as ChainContract;
36
- }
37
-
38
- async getChainToken(input: RouterInput['getChainToken'], ctx: RouterContext): Promise<RouterOutput['getChainToken']> {
39
- if (!input) throw new ARXError('NO_INPUT');
40
- console.log('Chain.Service.getChainToken', input);
41
-
42
- const chainToken = await ctx.app.model.ChainToken.findOne(getFilter(input)).lean().exec();
43
- if (!chainToken) throw new Error('ChainToken not found');
44
-
45
- return chainToken as ChainToken;
46
- }
47
-
48
- async getChainTransaction(
49
- input: RouterInput['getChainTransaction'],
50
- ctx: RouterContext
51
- ): Promise<RouterOutput['getChainTransaction']> {
52
- if (!input) throw new ARXError('NO_INPUT');
53
- console.log('Chain.Service.getChainTransaction', input);
54
-
55
- const chainTransaction = await ctx.app.model.ChainTransaction.findOne(getFilter(input)).lean().exec();
56
- if (!chainTransaction) throw new Error('ChainTransaction not found');
57
-
58
- return chainTransaction as ChainTransaction;
59
- }
60
-
61
- async createChain(input: RouterInput['createChain'], ctx: RouterContext): Promise<RouterOutput['createChain']> {
62
- if (!input) throw new ARXError('NO_INPUT');
63
- console.log('Chain.Service.createChain', input);
64
-
65
- const chain = await ctx.app.model.Chain.create(input);
66
-
67
- return chain as Chain;
68
- }
69
-
70
- async createChainContract(
71
- input: RouterInput['createChainContract'],
72
- ctx: RouterContext
73
- ): Promise<RouterOutput['createChainContract']> {
74
- if (!input) throw new ARXError('NO_INPUT');
75
- console.log('Chain.Service.createChainContract', input);
76
-
77
- const chainContract = await ctx.app.model.ChainContract.create(input);
78
-
79
- return chainContract as ChainContract;
80
- }
81
-
82
- async createChainToken(
83
- input: RouterInput['createChainToken'],
84
- ctx: RouterContext
85
- ): Promise<RouterOutput['createChainToken']> {
86
- if (!input) throw new ARXError('NO_INPUT');
87
- console.log('Chain.Service.createChainToken', input);
88
-
89
- const chainToken = await ctx.app.model.ChainToken.create(input);
90
-
91
- return chainToken as ChainToken;
92
- }
93
-
94
- async createChainTransaction(
95
- input: RouterInput['createChainTransaction'],
96
- ctx: RouterContext
97
- ): Promise<RouterOutput['createChainTransaction']> {
98
- if (!input) throw new ARXError('NO_INPUT');
99
- console.log('Chain.Service.createChainTransaction', input);
100
-
101
- const chainTransaction = await ctx.app.model.ChainToken.create(input);
102
-
103
- return chainTransaction as ChainTransaction;
104
- }
105
-
106
- async updateChain(input: RouterInput['updateChain'], ctx: RouterContext): Promise<RouterOutput['updateChain']> {
107
- if (!input) throw new ARXError('NO_INPUT');
108
- console.log('Chain.Service.updateChain', input);
109
-
110
- const updatedChain = await ctx.app.model.Game.findByIdAndUpdate(input.where.id.equals, { new: true }).lean().exec();
111
- if (!updatedChain) throw new Error('Chain update failed');
112
-
113
- return updatedChain as Chain;
114
- }
115
-
116
- async updateChainContract(
117
- input: RouterInput['updateChainContract'],
118
- ctx: RouterContext
119
- ): Promise<RouterOutput['updateChainContract']> {
120
- if (!input) throw new ARXError('NO_INPUT');
121
- console.log('Chain.Service.updateChainContract', input);
122
-
123
- const updatedChainContract = await ctx.app.model.ChainContract.findByIdAndUpdate(input.where.id.equals, {
124
- new: true,
125
- })
126
- .lean()
127
- .exec();
128
-
129
- if (!updatedChainContract) throw new Error('ChainContract update failed');
130
-
131
- return updatedChainContract as ChainContract;
132
- }
133
-
134
- async updateChainToken(
135
- input: RouterInput['updateChainToken'],
136
- ctx: RouterContext
137
- ): Promise<RouterOutput['updateChainToken']> {
138
- if (!input) throw new ARXError('NO_INPUT');
139
- console.log('Chain.Service.updateChainToken', input);
140
-
141
- const updatedChainToken = await ctx.app.model.ChainToken.findByIdAndUpdate(input.where.id.equals, { new: true })
142
- .lean()
143
- .exec();
144
-
145
- if (!updatedChainToken) throw new Error('ChainToken update failed');
146
-
147
- return updatedChainToken as ChainToken;
148
- }
149
-
150
- async updateChainTransaction(
151
- input: RouterInput['updateChainTransaction'],
152
- ctx: RouterContext
153
- ): Promise<RouterOutput['updateChainTransaction']> {
154
- if (!input) throw new ARXError('NO_INPUT');
155
- console.log('Chain.Service.updateChainTransaction', input);
156
-
157
- const updatedChainTransaction = await ctx.app.model.ChainTransaction.findByIdAndUpdate(input.where.id.equals, {
158
- new: true,
159
- })
160
- .lean()
161
- .exec();
162
-
163
- if (!updatedChainTransaction) throw new Error('ChainTransaction update failed');
164
-
165
- return updatedChainTransaction as ChainTransaction;
166
- }
167
- }