@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
package/index.ts
CHANGED
|
@@ -1,18 +1,351 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
1
|
+
import crypto from 'crypto';
|
|
2
|
+
import { exec } from 'child_process';
|
|
3
|
+
// import jetpack from 'fs-jetpack';
|
|
4
|
+
import * as ethers from 'ethers';
|
|
5
|
+
import _ from 'lodash';
|
|
6
|
+
import config from './config';
|
|
7
|
+
import * as time from './time';
|
|
8
|
+
import * as objects from './object';
|
|
9
|
+
import * as db from './db';
|
|
10
|
+
import * as api from './api';
|
|
11
|
+
import * as guid from './guid';
|
|
12
|
+
import * as number from './number';
|
|
13
|
+
import * as string from './string';
|
|
14
|
+
import * as process2 from './process';
|
|
15
|
+
import * as web3 from './web3';
|
|
16
|
+
import * as math from './math';
|
|
17
|
+
import * as json from './json';
|
|
18
|
+
import * as format from './format';
|
|
19
|
+
import * as rpc from './rpc';
|
|
20
|
+
// import * as browser from './browser';
|
|
21
|
+
|
|
22
|
+
export * as decoder from './decoder';
|
|
23
|
+
|
|
24
|
+
const path = require('path');
|
|
25
|
+
const writeLogs = false;
|
|
26
|
+
const logPrefix = process.env.LOG_PREFIX || '[APP]';
|
|
27
|
+
|
|
28
|
+
export const isDebug =
|
|
29
|
+
process.env.HOME === '/Users/dev' ||
|
|
30
|
+
process.env.HOME === '/home/dev' ||
|
|
31
|
+
process.env.HOME === '/root' ||
|
|
32
|
+
process.env.LOG === '1';
|
|
33
|
+
|
|
34
|
+
export function logError(...msgs) {
|
|
35
|
+
console.log(logPrefix, nowReadable(), ...msgs);
|
|
36
|
+
|
|
37
|
+
// const errorLog = jetpack.read(path.resolve('./public/data/errors.json'), 'json') || [];
|
|
38
|
+
|
|
39
|
+
// for (const msg of msgs) {
|
|
40
|
+
// errorLog.push(JSON.stringify(msg));
|
|
41
|
+
// }
|
|
42
|
+
|
|
43
|
+
if (writeLogs) {
|
|
44
|
+
// jetpack.write(path.resolve('./public/data/errors.json'), JSON.stringify(errorLog, null, 2), { atomic: true });
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// console.log(msgs);
|
|
48
|
+
|
|
49
|
+
// throw new Error(msgs.join('; '));
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export function log(...msgs) {
|
|
53
|
+
if (isDebug) {
|
|
54
|
+
console.log(logPrefix, nowReadable(), ...msgs);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
if (writeLogs) {
|
|
58
|
+
// const logData = jetpack.read(path.resolve('../public/data/log.json'), 'json') || [];
|
|
59
|
+
// for (const msg of msgs) {
|
|
60
|
+
// logData.push(JSON.stringify(msg));
|
|
61
|
+
// }
|
|
62
|
+
// jetpack.write(path.resolve('./public/data/log.json'), JSON.stringify(logData, null, 2));
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export function nowReadable() {
|
|
67
|
+
return new Date().toISOString().replace(/T/, ' ').replace(/\..+/, '');
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export function wait(ms) {
|
|
71
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
export function round(num, precision) {
|
|
75
|
+
const _precision = 10 ** precision;
|
|
76
|
+
return Math.ceil(num * _precision) / _precision;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
export function pad(n, width, z = '0') {
|
|
80
|
+
const nn = n + '';
|
|
81
|
+
return nn.length >= width ? nn : new Array(width - nn.length + 1).join(z) + nn;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
export function removeDupes(list) {
|
|
85
|
+
const seen = {};
|
|
86
|
+
return list.filter(function (item) {
|
|
87
|
+
const k1 = item.seller + item.tokenId + item.blockNumber;
|
|
88
|
+
const k2 = item.id;
|
|
89
|
+
const exists = seen.hasOwnProperty(k1) || seen.hasOwnProperty(k2);
|
|
90
|
+
|
|
91
|
+
if (!exists) {
|
|
92
|
+
seen[k1] = true;
|
|
93
|
+
seen[k2] = true;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
return !exists;
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
export const toLong = (x, decimals = 16) =>
|
|
101
|
+
decimals === 16 ? ethers.utils.parseEther(x + '') : ethers.utils.parseUnits(x + '', decimals);
|
|
102
|
+
export const toShort = (x) => round(parseFloat(ethers.utils.formatEther(x)), 4);
|
|
103
|
+
|
|
104
|
+
let updatingGit = false;
|
|
105
|
+
|
|
106
|
+
export async function updateGit() {
|
|
107
|
+
if (updatingGit) return;
|
|
108
|
+
|
|
109
|
+
updatingGit = true;
|
|
110
|
+
try {
|
|
111
|
+
const execPromise = require('util').promisify(exec);
|
|
112
|
+
|
|
113
|
+
try {
|
|
114
|
+
await execPromise('rm ./db/.git/index.lock');
|
|
115
|
+
} catch (e2) {}
|
|
116
|
+
|
|
117
|
+
const { stdout, stderr } = await execPromise(
|
|
118
|
+
'cd db && git add -A && git commit -m "build: Binzy doz it" && git push --set-upstream origin master'
|
|
119
|
+
);
|
|
120
|
+
|
|
121
|
+
console.log(stderr, stdout);
|
|
122
|
+
|
|
123
|
+
await wait(100);
|
|
124
|
+
} catch (e) {
|
|
125
|
+
console.log(e);
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
updatingGit = false;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
export function groupBySub(xs, key, subkey) {
|
|
132
|
+
return (
|
|
133
|
+
xs.reduce(function (rv, x) {
|
|
134
|
+
if (!x[key][subkey]) return rv;
|
|
135
|
+
(rv[x[key][subkey]] = rv[x[key][subkey]] || []).push(x);
|
|
136
|
+
return rv;
|
|
137
|
+
}, {}) || null
|
|
138
|
+
);
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
export function groupBy(xs, key) {
|
|
142
|
+
return (
|
|
143
|
+
xs.reduce(function (rv, x) {
|
|
144
|
+
if (!x[key]) return rv;
|
|
145
|
+
(rv[x[key]] = rv[x[key]] || []).push(x);
|
|
146
|
+
return rv;
|
|
147
|
+
}, {}) || null
|
|
148
|
+
);
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
export function getHighestId(arr) {
|
|
152
|
+
let highest = 0;
|
|
153
|
+
|
|
154
|
+
for (const item of arr) {
|
|
155
|
+
if (item.id > highest) {
|
|
156
|
+
highest = item.id;
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
return highest;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
export function average(arr) {
|
|
164
|
+
return arr.reduce((p, c) => p + c, 0) / arr.length;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
export function ordinalise(n) {
|
|
168
|
+
return (
|
|
169
|
+
n +
|
|
170
|
+
(n % 10 == 1 && n % 100 != 11
|
|
171
|
+
? 'st'
|
|
172
|
+
: n % 10 == 2 && n % 100 != 12
|
|
173
|
+
? 'nd'
|
|
174
|
+
: n % 10 == 3 && n % 100 != 13
|
|
175
|
+
? 'rd'
|
|
176
|
+
: 'th')
|
|
177
|
+
);
|
|
178
|
+
}
|
|
179
|
+
export function commarise(n) {
|
|
180
|
+
return n.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ',');
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
export function getTime() {
|
|
184
|
+
return new Date().getTime();
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
export const capitalizeFirstLetters = (text?: string) => text != null && _.startCase(text?.toLowerCase());
|
|
188
|
+
|
|
189
|
+
export function convertToDecimal(byte) {
|
|
190
|
+
let result = 0;
|
|
191
|
+
|
|
192
|
+
byte = byte.split('');
|
|
193
|
+
|
|
194
|
+
byte.reverse();
|
|
195
|
+
|
|
196
|
+
for (let a = 0; a < byte.length; a++) {
|
|
197
|
+
if (byte[a] === '1') {
|
|
198
|
+
result += 2 ** a;
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
return result;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
export const phoneMask = (phone: string) => {
|
|
206
|
+
//This regular expression provides the pattern for a phone number in format 000-000-0000
|
|
207
|
+
const x = phone.replace(/\D/g, '').match(/(\d{0,3})(\d{0,3})(\d{0,4})/);
|
|
208
|
+
return !x[2] ? x[1] : x[1] + '-' + x[2] + (x[3] ? '-' + x[3] : '');
|
|
209
|
+
};
|
|
210
|
+
|
|
211
|
+
export function binaryAgent(str) {
|
|
212
|
+
let bytes = str.split(' ');
|
|
213
|
+
let output = '';
|
|
214
|
+
|
|
215
|
+
for (let k = 0; k < bytes.length; k++) {
|
|
216
|
+
if (bytes[k]) output += String.fromCharCode(convertToDecimal(bytes[k]));
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
return output;
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
export function decodePayload(msg) {
|
|
223
|
+
try {
|
|
224
|
+
if (typeof msg === 'object') return msg;
|
|
225
|
+
|
|
226
|
+
// @ts-ignore
|
|
227
|
+
let json = binaryAgent(msg); //String.fromCharCode.apply(null, new Uint8Array(msg));
|
|
228
|
+
// else if (Buffer.isBuffer(msg)) json = msg.toString();
|
|
229
|
+
|
|
230
|
+
// explicitly decode the String as UTF-8 for Unicode
|
|
231
|
+
// https://github.com/mathiasbynens/utf8.js
|
|
232
|
+
// json = utf8.decode(json)
|
|
233
|
+
// const buffer = Buffer.from(json, "binary");
|
|
234
|
+
if (typeof json === 'string') return JSON.parse(json);
|
|
235
|
+
|
|
236
|
+
return json;
|
|
237
|
+
} catch (err) {
|
|
238
|
+
// ...
|
|
239
|
+
console.log(err, msg);
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
export function isNumeric(str) {
|
|
244
|
+
if (typeof str != 'string') return false; // we only process strings!
|
|
245
|
+
return (
|
|
246
|
+
// @ts-ignore
|
|
247
|
+
!isNaN(str) && // use type coercion to parse the _entirety_ of the string (`parseFloat` alone does not do this)...
|
|
248
|
+
!isNaN(parseFloat(str))
|
|
249
|
+
); // ...and ensure strings of whitespace fail
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
/**
|
|
253
|
+
* Wrapper around fetch with an optional timeout
|
|
254
|
+
* @param {Url} url
|
|
255
|
+
* @param {Request} request
|
|
256
|
+
* @param {number} timeout
|
|
257
|
+
*/
|
|
258
|
+
async function fetchWithTimeout(url, request, timeout) {
|
|
259
|
+
return Promise.race([
|
|
260
|
+
fetch(url, request),
|
|
261
|
+
new Promise((_, reject) => setTimeout(() => reject(new Error('Timeout')), timeout)),
|
|
262
|
+
]);
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
export function sha256(str) {
|
|
266
|
+
return crypto.createHash('sha256').update(str, 'utf8').digest('base64');
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
// /**
|
|
270
|
+
// * sha256 encodes a given string message
|
|
271
|
+
// * @param {string} message
|
|
272
|
+
// * Borrowed from
|
|
273
|
+
// * https://developers.cloudflare.com/workers/examples/cache-api
|
|
274
|
+
// */
|
|
275
|
+
// async function sha256(message) {
|
|
276
|
+
// // encode as UTF-8
|
|
277
|
+
// const msgBuffer = new TextEncoder().encode(message)
|
|
278
|
+
// // hash the message
|
|
279
|
+
// const hashBuffer = await crypto.subtle.digest("SHA-256", msgBuffer)
|
|
280
|
+
// // convert ArrayBuffer to Array
|
|
281
|
+
// const hashArray = Array.from(new Uint8Array(hashBuffer))
|
|
282
|
+
// // convert bytes to hex string
|
|
283
|
+
// const hashHex = hashArray.map(b => ("00" + b.toString(16)).slice(-2)).join("")
|
|
284
|
+
// return hashHex
|
|
285
|
+
// }
|
|
286
|
+
|
|
287
|
+
export function randomPosition(min, max) {
|
|
288
|
+
return Math.random() * (max - min) + min;
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
export function shuffleArray(array) {
|
|
292
|
+
for (let i = array.length - 1; i > 0; i--) {
|
|
293
|
+
const j = Math.floor(Math.random() * (i + 1));
|
|
294
|
+
[array[i], array[j]] = [array[j], array[i]];
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
return array;
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
export const getAddress = (address) => {
|
|
301
|
+
const mainNetChainId = 56;
|
|
302
|
+
const chainId = window?.location?.hostname === 'testnet.arken.gg' ? 97 : process.env.REACT_APP_CHAIN_ID;
|
|
303
|
+
return address[chainId] ? address[chainId] : address[mainNetChainId];
|
|
304
|
+
};
|
|
305
|
+
|
|
306
|
+
export function random(min, max) {
|
|
307
|
+
return Math.floor(Math.random() * (max - min + 1)) + min;
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
export const isEthereumAddress = (address: string) => {
|
|
311
|
+
// Regular expression to check if the string is a valid Ethereum address
|
|
312
|
+
return /^0x[a-fA-F0-9]{40}$/.test(address);
|
|
313
|
+
};
|
|
314
|
+
|
|
315
|
+
export const ipHashFromSocket = (socket) => {
|
|
316
|
+
const ip = socket.handshake.headers['x-forwarded-for']?.split(',')[0] || socket.conn.remoteAddress?.split(':')[3];
|
|
317
|
+
let hash = ip ? sha256(ip.slice(ip.length / 2)) : '';
|
|
318
|
+
hash = ip ? hash.slice(hash.length - 10, hash.length - 1) : '';
|
|
319
|
+
|
|
320
|
+
return hash;
|
|
321
|
+
};
|
|
322
|
+
|
|
323
|
+
export * as physics from './physics';
|
|
324
|
+
export * as number from './number';
|
|
325
|
+
export * as object from './object';
|
|
326
|
+
export * as api from './api';
|
|
327
|
+
export * as string from './string';
|
|
328
|
+
export * as web3 from './web3';
|
|
329
|
+
export * as math from './math';
|
|
330
|
+
export * as db from './db';
|
|
331
|
+
export * as time from './time';
|
|
332
|
+
export * as config from './config';
|
|
333
|
+
export * as rpc from './rpc';
|
|
334
|
+
|
|
335
|
+
export default {
|
|
336
|
+
objects,
|
|
337
|
+
api,
|
|
338
|
+
guid,
|
|
339
|
+
number,
|
|
340
|
+
string,
|
|
341
|
+
process: process2,
|
|
342
|
+
web3,
|
|
343
|
+
math,
|
|
344
|
+
json,
|
|
345
|
+
db,
|
|
346
|
+
format,
|
|
347
|
+
rpc,
|
|
348
|
+
// browser,
|
|
349
|
+
config,
|
|
350
|
+
time,
|
|
351
|
+
};
|
|
@@ -711,6 +711,7 @@ export function createSchema<T>(
|
|
|
711
711
|
virtuals: true, // Include virtual fields
|
|
712
712
|
versionKey: false, // Remove the __v version field
|
|
713
713
|
transform: (doc, ret) => {
|
|
714
|
+
// @ts-ignore
|
|
714
715
|
ret.id = ret._id.toString(); // Assign _id to id
|
|
715
716
|
delete ret._id; // Remove _id from the output
|
|
716
717
|
return ret;
|
|
@@ -721,6 +722,7 @@ export function createSchema<T>(
|
|
|
721
722
|
virtuals: true, // Include virtual fields
|
|
722
723
|
versionKey: false, // Remove the __v version field
|
|
723
724
|
transform: (doc, ret) => {
|
|
725
|
+
// @ts-ignore
|
|
724
726
|
ret.id = ret._id.toString(); // Assign _id to id
|
|
725
727
|
delete ret._id; // Remove _id from the output
|
|
726
728
|
return ret;
|
package/package.json
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@arken/node",
|
|
3
|
-
"version": "1.5.
|
|
3
|
+
"version": "1.5.2",
|
|
4
4
|
"description": "",
|
|
5
|
-
"main": "index.
|
|
6
|
-
"types": "types.ts",
|
|
5
|
+
"main": "build/index.js",
|
|
6
|
+
"types": "build/types.d.ts",
|
|
7
7
|
"scripts": {
|
|
8
8
|
"build": "npm-run-all dist",
|
|
9
9
|
"clean": "del-cli ./build && make-dir ./build",
|
package/tsconfig.json
CHANGED
|
@@ -44,8 +44,39 @@
|
|
|
44
44
|
"components/**/*",
|
|
45
45
|
"hooks/**/*",
|
|
46
46
|
"generated/**/*",
|
|
47
|
-
"
|
|
48
|
-
"
|
|
47
|
+
"trpc/**/*",
|
|
48
|
+
"types/**/*",
|
|
49
|
+
"web3/**/*",
|
|
50
|
+
"./api.ts",
|
|
51
|
+
"./array.ts",
|
|
52
|
+
"./browser.ts",
|
|
53
|
+
"./codebase.ts",
|
|
54
|
+
"./db.ts",
|
|
55
|
+
"./decoder.ts",
|
|
56
|
+
"./format.ts",
|
|
57
|
+
"./guid.ts",
|
|
58
|
+
"./json.ts",
|
|
59
|
+
"./log.ts",
|
|
60
|
+
"./math.ts",
|
|
61
|
+
"./merkle.ts",
|
|
62
|
+
"./mongo.ts",
|
|
63
|
+
"./number.ts",
|
|
64
|
+
"./object.ts",
|
|
65
|
+
"./otp.ts",
|
|
66
|
+
"./physics.ts",
|
|
67
|
+
"./process.ts",
|
|
68
|
+
"./router.ts",
|
|
69
|
+
"./rpc.ts",
|
|
70
|
+
"./schema.ts",
|
|
71
|
+
"./seer.ts",
|
|
72
|
+
"./string.ts",
|
|
73
|
+
"./text.ts",
|
|
74
|
+
"./types.ts",
|
|
75
|
+
"./util.ts",
|
|
76
|
+
"./web3.ts",
|
|
77
|
+
"./websocket.ts",
|
|
78
|
+
"./zk.ts",
|
|
79
|
+
"./zod.ts",
|
|
49
80
|
"legacy/**/*.json",
|
|
50
81
|
"contracts/**/*.json",
|
|
51
82
|
"generated/**/*.json"
|
package/types.ts
CHANGED
package/util.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '.';
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import * as mongo from '../../util/mongo';
|
|
2
|
-
import type * as Types from './area.types';
|
|
3
|
-
|
|
4
|
-
export const Area = mongo.createModel<Types.AreaDocument>('Area', {
|
|
5
|
-
type: { type: String, default: 'Zone' },
|
|
6
|
-
shortDescription: { type: String },
|
|
7
|
-
// landmarks: [{ type: mongo.Schema.Types.ObjectId, ref: 'AreaLandmark' }],
|
|
8
|
-
});
|
|
9
|
-
|
|
10
|
-
export const AreaLandmark = mongo.createModel<Types.AreaLandmarkDocument>('AreaLandmark', {
|
|
11
|
-
areaId: { type: mongo.Schema.Types.ObjectId, ref: 'Area' },
|
|
12
|
-
});
|
|
13
|
-
|
|
14
|
-
export const AreaType = mongo.createModel<Types.AreaTypeDocument>('AreaType', {});
|
|
15
|
-
export const AreaNameChoice = mongo.createModel<Types.AreaNameChoiceDocument>('AreaNameChoice', {});
|
|
@@ -1,74 +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 { Area, AreaLandmark, AreaType } from './area.schema';
|
|
6
|
-
import { Query, getQueryInput, inferRouterOutputs, inferRouterInputs } from '../../schema';
|
|
7
|
-
|
|
8
|
-
export const z = zod;
|
|
9
|
-
export const t = initTRPC.context<RouterContext>().create();
|
|
10
|
-
export const router = t.router;
|
|
11
|
-
export const procedure = t.procedure;
|
|
12
|
-
|
|
13
|
-
export const createRouter = () =>
|
|
14
|
-
router({
|
|
15
|
-
getArea: procedure
|
|
16
|
-
.use(hasRole('guest', t))
|
|
17
|
-
.use(customErrorFormatter(t))
|
|
18
|
-
.input(getQueryInput(Area))
|
|
19
|
-
.query(({ input, ctx }) => (ctx.app.service.Area.getArea as any)(input, ctx)),
|
|
20
|
-
|
|
21
|
-
getAreas: procedure
|
|
22
|
-
.use(hasRole('guest', t))
|
|
23
|
-
.use(customErrorFormatter(t))
|
|
24
|
-
.input(getQueryInput(Area))
|
|
25
|
-
.query(({ input, ctx }) => (ctx.app.service.Area.getAreas as any)(input, ctx)),
|
|
26
|
-
|
|
27
|
-
saveArea: procedure
|
|
28
|
-
.use(hasRole('admin', t))
|
|
29
|
-
.use(customErrorFormatter(t))
|
|
30
|
-
.input(getQueryInput(Area))
|
|
31
|
-
.output(Area.pick({ id: true }))
|
|
32
|
-
.mutation(({ input, ctx }) => (ctx.app.service.Area.saveArea as any)(input, ctx)),
|
|
33
|
-
|
|
34
|
-
getAreaLandmark: procedure
|
|
35
|
-
.use(hasRole('guest', t))
|
|
36
|
-
.use(customErrorFormatter(t))
|
|
37
|
-
.input(z.object({ query: Query }))
|
|
38
|
-
.query(({ input, ctx }) => (ctx.app.service.Area.getAreaLandmark as any)(input, ctx)),
|
|
39
|
-
|
|
40
|
-
createAreaLandmark: procedure
|
|
41
|
-
.use(hasRole('admin', t))
|
|
42
|
-
.use(customErrorFormatter(t))
|
|
43
|
-
.input(z.object({ data: AreaLandmark.omit({ id: true }) }))
|
|
44
|
-
.mutation(({ input, ctx }) => (ctx.app.service.Area.createAreaLandmark as any)(input, ctx)),
|
|
45
|
-
|
|
46
|
-
updateAreaLandmark: procedure
|
|
47
|
-
.use(hasRole('admin', t))
|
|
48
|
-
.use(customErrorFormatter(t))
|
|
49
|
-
.input(z.object({ query: Query, data: AreaLandmark.partial() }))
|
|
50
|
-
.mutation(({ input, ctx }) => (ctx.app.service.Area.updateAreaLandmark as any)(input, ctx)),
|
|
51
|
-
|
|
52
|
-
getAreaType: procedure
|
|
53
|
-
.use(hasRole('guest', t))
|
|
54
|
-
.use(customErrorFormatter(t))
|
|
55
|
-
.input(z.object({ query: Query }))
|
|
56
|
-
.query(({ input, ctx }) => (ctx.app.service.Area.getAreaType as any)(input, ctx)),
|
|
57
|
-
|
|
58
|
-
createAreaType: procedure
|
|
59
|
-
.use(hasRole('admin', t))
|
|
60
|
-
.use(customErrorFormatter(t))
|
|
61
|
-
.input(z.object({ data: AreaType.omit({ id: true }) }))
|
|
62
|
-
.mutation(({ input, ctx }) => (ctx.app.service.Area.createAreaType as any)(input, ctx)),
|
|
63
|
-
|
|
64
|
-
updateAreaType: procedure
|
|
65
|
-
.use(hasRole('admin', t))
|
|
66
|
-
.use(customErrorFormatter(t))
|
|
67
|
-
.input(z.object({ query: Query, data: AreaType.partial() }))
|
|
68
|
-
.output(AreaType.partial())
|
|
69
|
-
.mutation(({ input, ctx }) => (ctx.app.service.Area.updateAreaType as any)(input, ctx)),
|
|
70
|
-
});
|
|
71
|
-
|
|
72
|
-
export type Router = ReturnType<typeof createRouter>;
|
|
73
|
-
export type RouterInput = inferRouterInputs<Router>;
|
|
74
|
-
export type RouterOutput = inferRouterOutputs<Router>;
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
// arken/packages/node/modules/area/area.schema.ts
|
|
2
|
-
//
|
|
3
|
-
import { z, ObjectId, Entity } from '../../schema';
|
|
4
|
-
|
|
5
|
-
export const Area = Entity.merge(
|
|
6
|
-
z.object({
|
|
7
|
-
type: z.string().default('Zone'),
|
|
8
|
-
landmarks: z.array(ObjectId).optional(),
|
|
9
|
-
shortDescription: z.string(),
|
|
10
|
-
})
|
|
11
|
-
);
|
|
12
|
-
|
|
13
|
-
export const AreaLandmark = Entity.merge(
|
|
14
|
-
z.object({
|
|
15
|
-
areaId: ObjectId.optional(),
|
|
16
|
-
area: ObjectId.optional(),
|
|
17
|
-
})
|
|
18
|
-
);
|
|
19
|
-
|
|
20
|
-
export const AreaType = Entity.merge(z.object({}));
|
|
21
|
-
|
|
22
|
-
export const AreaNameChoice = Entity.merge(z.object({}));
|
|
@@ -1,124 +0,0 @@
|
|
|
1
|
-
import type { Area, AreaLandmark, AreaType, RouterInput, RouterOutput, RouterContext } from './area.types';
|
|
2
|
-
import { getFilter } from '../../util/api';
|
|
3
|
-
import { ARXError } from '../../util/rpc';
|
|
4
|
-
|
|
5
|
-
export class Service {
|
|
6
|
-
async getArea(input: RouterInput['getArea'], ctx: RouterContext): Promise<RouterOutput['getArea']> {
|
|
7
|
-
if (!input) throw new Error('Input should not be void');
|
|
8
|
-
console.log('Area.Service.getArea', input);
|
|
9
|
-
|
|
10
|
-
const filter = getFilter(input);
|
|
11
|
-
// @ts-ignore
|
|
12
|
-
const area = await ctx.app.model.Area.findOne(filter).asJSON();
|
|
13
|
-
if (!area) throw new Error('Area not found');
|
|
14
|
-
|
|
15
|
-
return area as Area;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
async getAreas(input: RouterInput['getAreas'], ctx: RouterContext): Promise<RouterOutput['getAreas']> {
|
|
19
|
-
if (!input) throw new ARXError('NO_INPUT');
|
|
20
|
-
|
|
21
|
-
const filter = getFilter(input);
|
|
22
|
-
|
|
23
|
-
const limit = input.limit ?? 50;
|
|
24
|
-
const skip = input.skip ?? 0;
|
|
25
|
-
|
|
26
|
-
const [items, total] = await Promise.all([
|
|
27
|
-
// @ts-ignore
|
|
28
|
-
ctx.app.model.Area.find(filter).skip(skip).limit(limit).asJSON(),
|
|
29
|
-
ctx.app.model.Area.find(filter).countDocuments().exec(),
|
|
30
|
-
]);
|
|
31
|
-
|
|
32
|
-
return { items, total };
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
async getAreaLandmark(
|
|
36
|
-
input: RouterInput['getAreaLandmark'],
|
|
37
|
-
ctx: RouterContext
|
|
38
|
-
): Promise<RouterOutput['getAreaLandmark']> {
|
|
39
|
-
if (!input) throw new Error('Input should not be void');
|
|
40
|
-
console.log('Area.Service.getAreaLandmark', input.query);
|
|
41
|
-
|
|
42
|
-
const filter = getFilter(input.query);
|
|
43
|
-
const areaLandmark = await ctx.app.model.AreaLandmark.findOne(filter).lean().exec();
|
|
44
|
-
if (!areaLandmark) throw new Error('AreaLandmark not found');
|
|
45
|
-
|
|
46
|
-
return areaLandmark as AreaLandmark;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
async getAreaType(input: RouterInput['getAreaType'], ctx: RouterContext): Promise<RouterOutput['getAreaType']> {
|
|
50
|
-
if (!input) throw new Error('Input should not be void');
|
|
51
|
-
console.log('Area.Service.getAreaType', input.query);
|
|
52
|
-
|
|
53
|
-
const filter = getFilter(input.query);
|
|
54
|
-
const areaType = await ctx.app.model.AreaType.findOne(filter).lean().exec();
|
|
55
|
-
if (!areaType) throw new Error('AreaType not found');
|
|
56
|
-
|
|
57
|
-
return areaType as AreaType;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
async saveArea(input: RouterInput['saveArea'], ctx: RouterContext): Promise<RouterOutput['saveArea']> {
|
|
61
|
-
if (!input) throw new Error('Input should not be void');
|
|
62
|
-
console.log('Area.Service.saveArea', input);
|
|
63
|
-
|
|
64
|
-
const filter = getFilter(input);
|
|
65
|
-
const area = await ctx.app.model.Area.findOneAndUpdate(filter, input.data, { new: true }).lean().exec();
|
|
66
|
-
if (!area) throw new Error('Area update failed');
|
|
67
|
-
|
|
68
|
-
return area as Area;
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
async createAreaLandmark(
|
|
72
|
-
input: RouterInput['createAreaLandmark'],
|
|
73
|
-
ctx: RouterContext
|
|
74
|
-
): Promise<RouterOutput['createAreaLandmark']> {
|
|
75
|
-
if (!input) throw new Error('Input should not be void');
|
|
76
|
-
console.log('Area.Service.createAreaLandmark', input.data);
|
|
77
|
-
|
|
78
|
-
const areaLandmark = await ctx.app.model.AreaLandmark.create(input.data);
|
|
79
|
-
return areaLandmark as AreaLandmark;
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
async createAreaType(
|
|
83
|
-
input: RouterInput['createAreaType'],
|
|
84
|
-
ctx: RouterContext
|
|
85
|
-
): Promise<RouterOutput['createAreaType']> {
|
|
86
|
-
if (!input) throw new Error('Input should not be void');
|
|
87
|
-
console.log('Area.Service.createAreaType', input.data);
|
|
88
|
-
|
|
89
|
-
const areaType = await ctx.app.model.AreaType.create(input.data);
|
|
90
|
-
return areaType as AreaType;
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
async updateAreaLandmark(
|
|
94
|
-
input: RouterInput['updateAreaLandmark'],
|
|
95
|
-
ctx: RouterContext
|
|
96
|
-
): Promise<RouterOutput['updateAreaLandmark']> {
|
|
97
|
-
if (!input) throw new Error('Input should not be void');
|
|
98
|
-
console.log('Area.Service.updateAreaLandmark', input.query, input.data);
|
|
99
|
-
|
|
100
|
-
const filter = getFilter(input.query);
|
|
101
|
-
const updatedAreaLandmark = await ctx.app.model.AreaLandmark.findOneAndUpdate(filter, input.data, { new: true })
|
|
102
|
-
.lean()
|
|
103
|
-
.exec();
|
|
104
|
-
if (!updatedAreaLandmark) throw new Error('AreaLandmark update failed');
|
|
105
|
-
|
|
106
|
-
return updatedAreaLandmark as AreaLandmark;
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
async updateAreaType(
|
|
110
|
-
input: RouterInput['updateAreaType'],
|
|
111
|
-
ctx: RouterContext
|
|
112
|
-
): Promise<RouterOutput['updateAreaType']> {
|
|
113
|
-
if (!input) throw new Error('Input should not be void');
|
|
114
|
-
console.log('Area.Service.updateAreaType', input.query, input.data);
|
|
115
|
-
|
|
116
|
-
const filter = getFilter(input.query);
|
|
117
|
-
const updatedAreaType = await ctx.app.model.AreaType.findOneAndUpdate(filter, input.data, { new: true })
|
|
118
|
-
.lean()
|
|
119
|
-
.exec();
|
|
120
|
-
if (!updatedAreaType) throw new Error('AreaType update failed');
|
|
121
|
-
|
|
122
|
-
return updatedAreaType as AreaType;
|
|
123
|
-
}
|
|
124
|
-
}
|