karin-plugin-mys-core 1.0.11 → 1.0.13

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 (156) hide show
  1. package/README.md +1 -1
  2. package/lib/apps/MiHoYoLogin.js +7 -38
  3. package/lib/apps/MysDevice.js +6 -37
  4. package/lib/apps/UIDManage.js +7 -38
  5. package/lib/{chunk-4BTKE3LO.js → chunk-567NAKP4.js} +300 -189
  6. package/lib/{chunk-BBJ4U2IY.js → chunk-A5FZEOIN.js} +75 -4
  7. package/lib/{chunk-AFLOM3CG.js → chunk-G564WWA7.js} +6 -10
  8. package/lib/chunk-HKSHKXRI.js +21 -0
  9. package/lib/chunk-IASM5MM5.js +639 -0
  10. package/lib/{chunk-5DXIT7UB.js → chunk-RX4VMVAI.js} +0 -5
  11. package/lib/chunk-UIPRZFST.js +184 -0
  12. package/lib/core/index.d.ts +20 -0
  13. package/lib/core/index.js +10 -0
  14. package/lib/exports/config/index.d.ts +56 -1
  15. package/lib/exports/config/index.js +3 -9
  16. package/lib/exports/database/index.d.ts +78 -12
  17. package/lib/exports/database/index.js +12 -40
  18. package/lib/exports/mys/index.d.ts +379 -14
  19. package/lib/exports/mys/index.js +10 -43
  20. package/lib/exports/render/index.d.ts +36 -3
  21. package/lib/exports/render/index.js +3 -8
  22. package/lib/exports/utils/index.d.ts +45 -2
  23. package/lib/exports/utils/index.js +1 -4
  24. package/lib/{exports/database/types/dbs/base.d.ts → mysUserInfo-BsyEENbc.d.ts} +60 -1
  25. package/package.json +6 -1
  26. package/resources/image/frame-logo.webp +0 -0
  27. package/resources/image/launcher-icon//345/216/237/347/245/236.webp +0 -0
  28. package/resources/image/launcher-icon//345/264/251/345/235/2173.webp +0 -0
  29. package/resources/image/launcher-icon//345/264/251/345/235/217/345/255/246/345/233/2552.webp +0 -0
  30. package/resources/image/launcher-icon//345/264/251/345/235/217/357/274/232/345/233/240/347/274/230/347/262/276/347/201/265.webp +0 -0
  31. package/resources/image/launcher-icon//345/264/251/345/235/217/357/274/232/346/230/237/347/251/271/351/223/201/351/201/223.webp +0 -0
  32. package/resources/image/launcher-icon//346/230/237/345/270/203/350/260/267/345/234/260.webp +0 -0
  33. package/resources/image/launcher-icon//346/234/252/345/256/232/344/272/213/344/273/266/347/260/277.webp +0 -0
  34. package/resources/image/launcher-icon//347/273/235/345/214/272/351/233/266.webp +0 -0
  35. package/resources/image/mys-core-logo.webp +0 -0
  36. package/resources/image/mys-logo.webp +0 -0
  37. package/lib/chunk-2BVJS5VE.js +0 -49
  38. package/lib/chunk-3ERB3ILC.js +0 -0
  39. package/lib/chunk-3JN5WYUN.js +0 -135
  40. package/lib/chunk-7KEG6SDX.js +0 -0
  41. package/lib/chunk-7VAWV6ZE.js +0 -0
  42. package/lib/chunk-ARLTXJFJ.js +0 -0
  43. package/lib/chunk-CFS2WFOO.js +0 -0
  44. package/lib/chunk-DMJ5OQR6.js +0 -73
  45. package/lib/chunk-EDNBKOMS.js +0 -30
  46. package/lib/chunk-FBWSEBAW.js +0 -0
  47. package/lib/chunk-FOAQZIZ2.js +0 -0
  48. package/lib/chunk-G5W5WAY5.js +0 -64
  49. package/lib/chunk-G7TMVDGP.js +0 -68
  50. package/lib/chunk-HJ6HX5HB.js +0 -29
  51. package/lib/chunk-I7XZONDN.js +0 -13
  52. package/lib/chunk-JRH4JC43.js +0 -0
  53. package/lib/chunk-JVJQKRJ4.js +0 -89
  54. package/lib/chunk-K5U2O3HH.js +0 -0
  55. package/lib/chunk-KQVWWGRH.js +0 -31
  56. package/lib/chunk-LBLGKL3W.js +0 -77
  57. package/lib/chunk-LJSDSOY6.js +0 -0
  58. package/lib/chunk-LYTNREAI.js +0 -0
  59. package/lib/chunk-MPZP23EX.js +0 -219
  60. package/lib/chunk-MWYDWDR4.js +0 -0
  61. package/lib/chunk-PMFOX5HA.js +0 -80
  62. package/lib/chunk-PYTECG57.js +0 -0
  63. package/lib/chunk-SEWEEPJN.js +0 -0
  64. package/lib/chunk-SHW6FHIB.js +0 -10
  65. package/lib/chunk-T7W4DXRM.js +0 -0
  66. package/lib/chunk-TTN7NFCA.js +0 -109
  67. package/lib/chunk-W4DBT7AD.js +0 -0
  68. package/lib/chunk-WCX7WZAQ.js +0 -0
  69. package/lib/chunk-Z5I6A73Y.js +0 -0
  70. package/lib/chunk-ZTOR2DXG.js +0 -38
  71. package/lib/common-BlI5Gsw_.d.ts +0 -35
  72. package/lib/define-B9r20dK6.d.ts +0 -130
  73. package/lib/exports/config/array.d.ts +0 -1
  74. package/lib/exports/config/array.js +0 -7
  75. package/lib/exports/config/config.d.ts +0 -56
  76. package/lib/exports/config/config.js +0 -12
  77. package/lib/exports/database/database.d.ts +0 -30
  78. package/lib/exports/database/database.js +0 -22
  79. package/lib/exports/database/dbs/base.d.ts +0 -25
  80. package/lib/exports/database/dbs/base.js +0 -19
  81. package/lib/exports/database/dbs/index.d.ts +0 -4
  82. package/lib/exports/database/dbs/index.js +0 -29
  83. package/lib/exports/database/dbs/sqlite3.d.ts +0 -27
  84. package/lib/exports/database/dbs/sqlite3.js +0 -23
  85. package/lib/exports/database/dbs/table.d.ts +0 -20
  86. package/lib/exports/database/dbs/table.js +0 -25
  87. package/lib/exports/database/tables/index.d.ts +0 -9
  88. package/lib/exports/database/tables/index.js +0 -40
  89. package/lib/exports/database/tables/mysAccountInfo.d.ts +0 -9
  90. package/lib/exports/database/tables/mysAccountInfo.js +0 -27
  91. package/lib/exports/database/tables/mysDeviceInfo.d.ts +0 -9
  92. package/lib/exports/database/tables/mysDeviceInfo.js +0 -27
  93. package/lib/exports/database/tables/mysUserInfo.d.ts +0 -9
  94. package/lib/exports/database/tables/mysUserInfo.js +0 -27
  95. package/lib/exports/database/types/database.d.ts +0 -6
  96. package/lib/exports/database/types/database.js +0 -1
  97. package/lib/exports/database/types/dbs/base.js +0 -11
  98. package/lib/exports/database/types/dbs/index.d.ts +0 -2
  99. package/lib/exports/database/types/dbs/index.js +0 -12
  100. package/lib/exports/database/types/index.d.ts +0 -6
  101. package/lib/exports/database/types/index.js +0 -24
  102. package/lib/exports/database/types/tables/index.d.ts +0 -5
  103. package/lib/exports/database/types/tables/index.js +0 -13
  104. package/lib/exports/database/types/tables/mysAccountInfo.d.ts +0 -14
  105. package/lib/exports/database/types/tables/mysAccountInfo.js +0 -7
  106. package/lib/exports/database/types/tables/mysDeviceInfo.d.ts +0 -19
  107. package/lib/exports/database/types/tables/mysDeviceInfo.js +0 -1
  108. package/lib/exports/database/types/tables/mysUserInfo.d.ts +0 -32
  109. package/lib/exports/database/types/tables/mysUserInfo.js +0 -7
  110. package/lib/exports/mys/api/apis.d.ts +0 -82
  111. package/lib/exports/mys/api/apis.js +0 -56
  112. package/lib/exports/mys/api/app.d.ts +0 -60
  113. package/lib/exports/mys/api/app.js +0 -32
  114. package/lib/exports/mys/api/define.d.ts +0 -6
  115. package/lib/exports/mys/api/define.js +0 -42
  116. package/lib/exports/mys/api/index.d.ts +0 -11
  117. package/lib/exports/mys/api/index.js +0 -63
  118. package/lib/exports/mys/types/api/define.d.ts +0 -6
  119. package/lib/exports/mys/types/api/define.js +0 -1
  120. package/lib/exports/mys/types/api/index.d.ts +0 -6
  121. package/lib/exports/mys/types/api/index.js +0 -2
  122. package/lib/exports/mys/types/index.d.ts +0 -12
  123. package/lib/exports/mys/types/index.js +0 -6
  124. package/lib/exports/mys/types/user/game.d.ts +0 -23
  125. package/lib/exports/mys/types/user/game.js +0 -1
  126. package/lib/exports/mys/types/user/index.d.ts +0 -12
  127. package/lib/exports/mys/types/user/index.js +0 -3
  128. package/lib/exports/mys/types/user/userInfo.d.ts +0 -43
  129. package/lib/exports/mys/types/user/userInfo.js +0 -1
  130. package/lib/exports/mys/user/deviceInfo.d.ts +0 -11
  131. package/lib/exports/mys/user/deviceInfo.js +0 -30
  132. package/lib/exports/mys/user/game.d.ts +0 -40
  133. package/lib/exports/mys/user/game.js +0 -9
  134. package/lib/exports/mys/user/index.d.ts +0 -14
  135. package/lib/exports/mys/user/index.js +0 -52
  136. package/lib/exports/mys/user/userInfo.d.ts +0 -53
  137. package/lib/exports/mys/user/userInfo.js +0 -44
  138. package/lib/exports/render/render.d.ts +0 -38
  139. package/lib/exports/render/render.js +0 -12
  140. package/lib/exports/utils/common.d.ts +0 -1
  141. package/lib/exports/utils/common.js +0 -15
  142. package/lib/exports/utils/types/common.d.ts +0 -11
  143. package/lib/exports/utils/types/common.js +0 -1
  144. package/lib/exports/utils/types/index.d.ts +0 -1
  145. package/lib/exports/utils/types/index.js +0 -2
  146. package/resources/image/frame-logo.png +0 -0
  147. package/resources/image/launcher-icon//345/216/237/347/245/236.png +0 -0
  148. package/resources/image/launcher-icon//345/264/251/345/235/2173.png +0 -0
  149. package/resources/image/launcher-icon//345/264/251/345/235/217/345/255/246/345/233/2552.png +0 -0
  150. package/resources/image/launcher-icon//345/264/251/345/235/217/357/274/232/345/233/240/347/274/230/347/262/276/347/201/265.png +0 -0
  151. package/resources/image/launcher-icon//345/264/251/345/235/217/357/274/232/346/230/237/347/251/271/351/223/201/351/201/223.png +0 -0
  152. package/resources/image/launcher-icon//346/230/237/345/270/203/350/260/267/345/234/260.png +0 -0
  153. package/resources/image/launcher-icon//346/234/252/345/256/232/344/272/213/344/273/266/347/260/277.png +0 -0
  154. package/resources/image/launcher-icon//347/273/235/345/214/272/351/233/266.png +0 -0
  155. package/resources/image/mys-core-logo.png +0 -0
  156. package/resources/image/mys-logo.png +0 -0
@@ -0,0 +1,21 @@
1
+ import {
2
+ dir
3
+ } from "./chunk-SHLPPEAY.js";
4
+ import {
5
+ Config
6
+ } from "./chunk-UIPRZFST.js";
7
+
8
+ // src/core/config/device.ts
9
+ var DefaultDevice = {
10
+ version: 12,
11
+ name: "aurora",
12
+ board: "24031PN0DC",
13
+ model: "24031PN0DC",
14
+ product: "aurora",
15
+ fingerprint: "Xiaomi/aurora/aurora:12/V417IR/813:user/release-keys"
16
+ };
17
+ var DeviceCfg = new Config(`${dir.name}:device`, dir.ConfigDir, DefaultDevice, {}).watch();
18
+
19
+ export {
20
+ DeviceCfg
21
+ };
@@ -0,0 +1,639 @@
1
+ import {
2
+ dir
3
+ } from "./chunk-SHLPPEAY.js";
4
+ import {
5
+ common_exports
6
+ } from "./chunk-RX4VMVAI.js";
7
+
8
+ // src/exports/database/database.ts
9
+ import { logger as logger4 } from "node-karin";
10
+ import { DataTypes as DataTypes2 } from "sequelize";
11
+
12
+ // src/exports/database/dbs/sqlite3.ts
13
+ import { existsSync, json as json2, logger as logger3, mkdirSync, rmSync as rmSync2 } from "node-karin";
14
+ import fs2 from "fs";
15
+ import path2 from "path";
16
+ import { DataTypes, Op, Sequelize } from "sequelize";
17
+
18
+ // src/exports/database/types/dbs/base.ts
19
+ import { logger } from "node-karin";
20
+ import lodash from "node-karin/lodash";
21
+ var Dialect = /* @__PURE__ */ ((Dialect2) => {
22
+ Dialect2["Sqlite"] = "sqlite";
23
+ Dialect2["MySQL"] = "mysql";
24
+ Dialect2["MariaDB"] = "mariadb";
25
+ Dialect2["PostgreSQL"] = "postgres";
26
+ Dialect2["MSSQL"] = "mssql";
27
+ Dialect2["Oracle"] = "oracle";
28
+ Dialect2["DB2"] = "db2";
29
+ Dialect2["Snowflake"] = "snowflake";
30
+ return Dialect2;
31
+ })(Dialect || {});
32
+ var DatabaseType = /* @__PURE__ */ ((DatabaseType3) => {
33
+ DatabaseType3["File"] = "file";
34
+ DatabaseType3["Dir"] = "dir";
35
+ DatabaseType3["Db"] = "db";
36
+ return DatabaseType3;
37
+ })(DatabaseType || {});
38
+ var DatabaseArray = class _DatabaseArray extends Array {
39
+ constructor(items) {
40
+ super();
41
+ Object.setPrototypeOf(this, _DatabaseArray.prototype);
42
+ if (Array.isArray(items)) {
43
+ this.push(...items);
44
+ }
45
+ }
46
+ /**
47
+ * @param element - string | number
48
+ * @returns
49
+ */
50
+ has(element) {
51
+ return new Set(this).has(element);
52
+ }
53
+ /**
54
+ * @param isEqual 是否不添加重复元素
55
+ */
56
+ add(element, isEqual) {
57
+ if (isEqual) {
58
+ const existingSet = new Set(this.map((item) => JSON.stringify(item)));
59
+ if (existingSet.has(JSON.stringify(element))) return this;
60
+ }
61
+ this.push(element);
62
+ return this;
63
+ }
64
+ /**
65
+ * @param isEqual 是否不添加重复元素
66
+ */
67
+ addSome(elements, isEqual) {
68
+ if (isEqual) {
69
+ const existingSet = new Set(this.map((item) => JSON.stringify(item)));
70
+ elements = elements.filter((element) => !existingSet.has(JSON.stringify(element)));
71
+ if (elements.length === 0) return this;
72
+ }
73
+ this.push(...elements);
74
+ return this;
75
+ }
76
+ /**
77
+ * @param isIndex predicate是否为索引
78
+ */
79
+ remove(predicate, isIndex = false) {
80
+ let newArr = [];
81
+ if (isIndex && lodash.isNumber(predicate)) {
82
+ if (predicate < 0 || predicate >= this.length) {
83
+ logger.error(`DatabaseArray\u7D22\u5F15 ${predicate} \u8D85\u51FA\u8303\u56F4`);
84
+ return this;
85
+ }
86
+ newArr = [...this.slice(0, predicate), ...this.slice(predicate + 1)];
87
+ } else if (lodash.isFunction(predicate)) {
88
+ newArr = this.filter((item) => !predicate(item));
89
+ } else {
90
+ newArr = lodash.without(this, predicate);
91
+ }
92
+ this.length = 0;
93
+ this.push(...newArr);
94
+ return this;
95
+ }
96
+ clear() {
97
+ this.length = 0;
98
+ return this;
99
+ }
100
+ };
101
+
102
+ // src/exports/database/types/tables/mysAccountInfo.ts
103
+ var MysAccountType = /* @__PURE__ */ ((MysAccountType2) => {
104
+ MysAccountType2["cn"] = "mihoyo";
105
+ MysAccountType2["os"] = "hoyolab";
106
+ return MysAccountType2;
107
+ })(MysAccountType || {});
108
+
109
+ // src/exports/database/types/tables/mysUserInfo.ts
110
+ var UidPermission = /* @__PURE__ */ ((UidPermission2) => {
111
+ UidPermission2[UidPermission2["BIND"] = 0] = "BIND";
112
+ UidPermission2[UidPermission2["CK"] = 1] = "CK";
113
+ UidPermission2[UidPermission2["ST"] = 2] = "ST";
114
+ UidPermission2[UidPermission2["CS"] = 3] = "CS";
115
+ UidPermission2[UidPermission2["DEL"] = 4] = "DEL";
116
+ return UidPermission2;
117
+ })(UidPermission || {});
118
+
119
+ // src/exports/database/dbs/base.ts
120
+ import { existToMkdirSync, json, logger as logger2, rmSync } from "node-karin";
121
+ import lodash2 from "node-karin/lodash";
122
+ import fs from "fs";
123
+ import path from "path";
124
+ var DbBase = class {
125
+ primaryKey;
126
+ initBase(DataDir, modelName, modelSchema, modelSchemaDefine, type, primaryKey) {
127
+ this.primaryKey = primaryKey;
128
+ this.databaseType = type;
129
+ this.databasePath = path.join(DataDir, modelName);
130
+ if (type !== "db" /* Db */) {
131
+ existToMkdirSync(this.databasePath);
132
+ }
133
+ this.modelName = modelName;
134
+ this.modelSchema = modelSchema;
135
+ this.modelSchemaDefine = modelSchemaDefine;
136
+ }
137
+ schemaToJSON(pk) {
138
+ const primaryKey = this.model?.primaryKeyAttribute || this.primaryKey;
139
+ const result = {
140
+ [primaryKey]: pk
141
+ };
142
+ lodash2.forEach(this.modelSchema, (value, key) => {
143
+ if (key !== primaryKey) {
144
+ const Value = typeof value.defaultValue === "function" ? value.defaultValue() : value.defaultValue;
145
+ result[key] = value.JsonColumn ? JSON.parse(Value) : value.ArrayColumn ? Value.split(",") : Value;
146
+ }
147
+ });
148
+ return result;
149
+ }
150
+ userPath(pk) {
151
+ if (this.databaseType === "dir" /* Dir */) {
152
+ return path.join(this.databasePath, pk);
153
+ }
154
+ return path.join(this.databasePath, `${pk}.json`);
155
+ }
156
+ readSync(path3, pk) {
157
+ const result = json.readSync(path3);
158
+ result.save = this.saveFile(pk);
159
+ result.destroy = () => this.destroyPath(pk);
160
+ return result;
161
+ }
162
+ readDirSync(pk) {
163
+ const path3 = this.userPath(pk);
164
+ const files = fs.readdirSync(path3);
165
+ const result = {
166
+ save: this.saveDir(pk),
167
+ destroy: () => this.destroyPath(pk),
168
+ [this.primaryKey]: pk
169
+ };
170
+ const filePromises = files.map(async (file) => {
171
+ const data = await json.read(`${path3}/${file}`);
172
+ result[data.key] = data.data;
173
+ });
174
+ Promise.all(filePromises).then().catch((err) => {
175
+ logger2.error(err);
176
+ });
177
+ return result;
178
+ }
179
+ writeDirSync(pk, data) {
180
+ const path3 = this.userPath(pk);
181
+ lodash2.forEach(this.modelSchema, (value, key) => {
182
+ if (key !== this.primaryKey) {
183
+ const mergeData = common_exports.filterData(data[key], value.defaultValue, this.modelSchemaDefine[key]);
184
+ json.writeSync(`${path3}/${key}.json`, {
185
+ key,
186
+ [this.primaryKey]: pk,
187
+ data: mergeData
188
+ });
189
+ }
190
+ });
191
+ return true;
192
+ }
193
+ saveFile(pk) {
194
+ return async (data) => {
195
+ const userPath = this.userPath(pk);
196
+ const mergeData = common_exports.filterData(data, this.schemaToJSON(pk), this.modelSchemaDefine);
197
+ delete data[this.primaryKey];
198
+ json.writeSync(userPath, mergeData);
199
+ return this.readSync(userPath, pk);
200
+ };
201
+ }
202
+ saveDir(pk) {
203
+ return async (data) => {
204
+ delete data[this.primaryKey];
205
+ this.writeDirSync(pk, data);
206
+ return this.readDirSync(pk);
207
+ };
208
+ }
209
+ destroyPath(pk) {
210
+ return new Promise((resolve) => {
211
+ const userPath = this.userPath(pk);
212
+ try {
213
+ rmSync(userPath, { recursive: true });
214
+ resolve(true);
215
+ } catch (err) {
216
+ logger2.error(err);
217
+ resolve(false);
218
+ }
219
+ });
220
+ }
221
+ saveSql(model, pk) {
222
+ return async (data) => {
223
+ delete data[this.model.primaryKeyAttribute];
224
+ const defData = this.schemaToJSON(pk);
225
+ const mergeData = {};
226
+ lodash2.forEach(data, (value, key) => {
227
+ if (value !== void 0 && value !== null) {
228
+ mergeData[key] = common_exports.filterData(value, defData[key], this.modelSchemaDefine[key]);
229
+ }
230
+ });
231
+ const result = await model.update(mergeData);
232
+ return {
233
+ ...result.toJSON(),
234
+ save: this.saveSql(result, pk),
235
+ destroy: () => this.destroySql(pk)
236
+ };
237
+ };
238
+ }
239
+ destroySql(pk) {
240
+ return new Promise((resolve) => {
241
+ const result = this.model.destroy({ where: { [this.model.primaryKeyAttribute]: pk } }).then((count) => count > 0).catch(() => false);
242
+ resolve(result);
243
+ });
244
+ }
245
+ };
246
+
247
+ // src/exports/database/dbs/sqlite3.ts
248
+ var dialect = "sqlite" /* Sqlite */;
249
+ var sequelize = new Sequelize({
250
+ storage: path2.join(dir.DataDir, "database", "sqlite3.db"),
251
+ dialect,
252
+ logging: false
253
+ });
254
+ var Sqlite3 = class extends DbBase {
255
+ dialect = dialect;
256
+ async check() {
257
+ try {
258
+ await sequelize.authenticate();
259
+ return true;
260
+ } catch (error) {
261
+ logger3.error(error);
262
+ return false;
263
+ }
264
+ }
265
+ async init(DataDir, modelName, modelSchema, modelSchemaDefine, type, primaryKey) {
266
+ this.initBase(DataDir, modelName, modelSchema, modelSchemaDefine, type, primaryKey);
267
+ if (this.databaseType === "db" /* Db */) {
268
+ this.model = sequelize.define(this.modelName, this.modelSchema, {
269
+ timestamps: false,
270
+ freezeTableName: true
271
+ });
272
+ await this.model.sync();
273
+ const queryInterface = sequelize.getQueryInterface();
274
+ const tableDescription = await queryInterface.describeTable(this.modelName);
275
+ for (const key in this.modelSchema) {
276
+ if (!tableDescription[key]) {
277
+ await queryInterface.addColumn(this.modelName, key, this.modelSchema[key]);
278
+ if (typeof this.modelSchema[key] === "string") continue;
279
+ const defaultValue = this.modelSchema[key].defaultValue;
280
+ if (defaultValue !== void 0) {
281
+ await this.model.update({ [key]: defaultValue }, { where: {} });
282
+ }
283
+ }
284
+ }
285
+ }
286
+ return this;
287
+ }
288
+ async findByPk(pk, create = false) {
289
+ if (this.databaseType !== "db" /* Db */) {
290
+ const path3 = this.userPath(pk);
291
+ if (!existsSync(path3)) {
292
+ if (create) {
293
+ const data = this.schemaToJSON(pk);
294
+ if (this.databaseType === "dir" /* Dir */) {
295
+ mkdirSync(path3);
296
+ this.writeDirSync(pk, data);
297
+ return {
298
+ ...data,
299
+ save: this.saveDir(pk),
300
+ destroy: () => this.destroyPath(pk)
301
+ };
302
+ } else {
303
+ json2.writeSync(path3, data);
304
+ return {
305
+ ...data,
306
+ save: this.saveFile(pk),
307
+ destroy: () => this.destroyPath(pk)
308
+ };
309
+ }
310
+ }
311
+ return void 0;
312
+ }
313
+ if (this.databaseType === "dir" /* Dir */) {
314
+ return this.readDirSync(pk);
315
+ } else {
316
+ return this.readSync(path3, pk);
317
+ }
318
+ } else {
319
+ let result = await this.model.findByPk(pk);
320
+ if (!result && create) {
321
+ result = await this.model.create(this.schemaToJSON(pk));
322
+ }
323
+ if (!result) return void 0;
324
+ return {
325
+ ...result.toJSON(),
326
+ save: this.saveSql(result, pk),
327
+ destroy: () => this.destroySql(pk)
328
+ };
329
+ }
330
+ }
331
+ async findAllByPks(pks) {
332
+ if (this.databaseType !== "db" /* Db */) {
333
+ const result = [];
334
+ pks.forEach((pk) => {
335
+ const path3 = this.userPath(pk);
336
+ if (existsSync(path3)) {
337
+ if (this.databaseType === "dir" /* Dir */) {
338
+ result.push(this.readDirSync(pk));
339
+ } else {
340
+ result.push(this.readSync(path3, pk));
341
+ }
342
+ }
343
+ });
344
+ return result;
345
+ } else {
346
+ const result = await this.model.findAll({
347
+ where: {
348
+ [this.model.primaryKeyAttribute]: pks
349
+ }
350
+ });
351
+ return result.map((item) => ({
352
+ ...item.toJSON(),
353
+ save: this.saveSql(item, item[this.model.primaryKeyAttribute]),
354
+ destroy: () => this.destroySql(item[this.model.primaryKeyAttribute])
355
+ }));
356
+ }
357
+ }
358
+ async findAll(excludePks) {
359
+ const excludeSet = new Set(excludePks || []);
360
+ if (this.databaseType !== "db" /* Db */) {
361
+ const result = [];
362
+ const files = fs2.readdirSync(this.databasePath);
363
+ if (this.databaseType === "dir" /* Dir */) {
364
+ files.forEach((file) => {
365
+ if (excludeSet.has(file)) return;
366
+ const stat = fs2.statSync(path2.join(this.databasePath, file));
367
+ if (stat.isDirectory()) {
368
+ result.push(this.readDirSync(file));
369
+ }
370
+ });
371
+ } else {
372
+ files.forEach((file) => {
373
+ if (!file.endsWith(".json")) return;
374
+ const pk = file.replace(".json", "");
375
+ if (excludeSet.has(pk)) return;
376
+ result.push(this.readSync(this.userPath(pk), pk));
377
+ });
378
+ }
379
+ return result;
380
+ } else {
381
+ const whereClause = excludePks && excludePks.length > 0 ? { [this.model.primaryKeyAttribute]: { [Op.notIn]: excludePks } } : {};
382
+ const result = await this.model.findAll({ where: whereClause });
383
+ return result.map((item) => ({
384
+ ...item.toJSON(),
385
+ save: this.saveSql(item, item[this.model.primaryKeyAttribute]),
386
+ destroy: () => this.destroySql(item[this.model.primaryKeyAttribute])
387
+ }));
388
+ }
389
+ }
390
+ async destroy(pk) {
391
+ if (this.databaseType !== "db" /* Db */) {
392
+ rmSync2(this.userPath(pk), { recursive: true });
393
+ return true;
394
+ } else {
395
+ const destroyed = await this.model.destroy({
396
+ where: { [this.model.primaryKeyAttribute]: pk }
397
+ });
398
+ return destroyed > 0;
399
+ }
400
+ }
401
+ };
402
+ var Sqlite3Static = new class Sqlite3Static2 {
403
+ dialect = dialect;
404
+ description = "\u63D2\u4EF6\u9ED8\u8BA4\u6570\u636E\u5E93";
405
+ Column(type, def, option) {
406
+ return {
407
+ type: DataTypes[type],
408
+ defaultValue: def,
409
+ ...option
410
+ };
411
+ }
412
+ ArrayColumn(key, fn) {
413
+ return {
414
+ ArrayColumn: true,
415
+ type: DataTypes.STRING,
416
+ defaultValue: [].join(","),
417
+ get() {
418
+ const data = this.getDataValue(key).split(",").filter(Boolean);
419
+ return new DatabaseArray(data);
420
+ },
421
+ set(data) {
422
+ const setData = (fn ? fn(data) : data) || [];
423
+ this.setDataValue(key, setData.join(","));
424
+ }
425
+ };
426
+ }
427
+ JsonColumn(key, def) {
428
+ return {
429
+ JsonColumn: true,
430
+ type: DataTypes.STRING,
431
+ defaultValue: JSON.stringify(def),
432
+ get() {
433
+ let data = this.getDataValue(key);
434
+ try {
435
+ data = JSON.parse(data) || def;
436
+ } catch (e) {
437
+ data = def;
438
+ }
439
+ return data;
440
+ },
441
+ set(data) {
442
+ this.setDataValue(key, JSON.stringify(data));
443
+ }
444
+ };
445
+ }
446
+ }();
447
+
448
+ // src/exports/database/database.ts
449
+ var Database = new class DatabaseClass {
450
+ #defaultDialect = "sqlite" /* Sqlite */;
451
+ #DatabaseMap = /* @__PURE__ */ new Map();
452
+ default(dialect2) {
453
+ const db = this.#DatabaseMap.get(dialect2);
454
+ if (!db) {
455
+ logger4.error(`\u672A\u627E\u5230\u6570\u636E\u5E93: ${dialect2}\uFF01\u4F7F\u7528\u9ED8\u8BA4\u6570\u636E\u5E93\u3002`);
456
+ return;
457
+ }
458
+ this.#defaultDialect = dialect2;
459
+ }
460
+ /** @description 添加数据库 */
461
+ async Add(Db, Static) {
462
+ const db = Db();
463
+ if (await db.check()) {
464
+ this.#DatabaseMap.set(Static.dialect, { Database: Db, Static });
465
+ } else {
466
+ logger4.error(`${Static.dialect} check failed!`);
467
+ }
468
+ }
469
+ get Db() {
470
+ const dialect2 = this.#defaultDialect;
471
+ const db = this.#DatabaseMap.get(dialect2);
472
+ if (!db) {
473
+ logger4.error(`\u672A\u627E\u5230\u6570\u636E\u5E93: ${dialect2}\uFF01\u4F7F\u7528\u9ED8\u8BA4\u6570\u636E\u5E93\u3002`);
474
+ return this.#DatabaseMap.get("sqlite" /* Sqlite */);
475
+ }
476
+ return db;
477
+ }
478
+ get details() {
479
+ return Array.from(this.#DatabaseMap.entries()).map(([dialect2, { Static }]) => ({
480
+ dialect: dialect2,
481
+ desc: Static.description
482
+ }));
483
+ }
484
+ /** @description 获取当前使用的数据库 */
485
+ get() {
486
+ return this.Db.Database();
487
+ }
488
+ get PkColumn() {
489
+ return (type, option) => ({
490
+ type: DataTypes2[type],
491
+ primaryKey: true,
492
+ allowNull: false,
493
+ ...option
494
+ });
495
+ }
496
+ get Column() {
497
+ return this.Db.Static.Column;
498
+ }
499
+ get ArrayColumn() {
500
+ return this.Db.Static.ArrayColumn;
501
+ }
502
+ get JsonColumn() {
503
+ return this.Db.Static.JsonColumn;
504
+ }
505
+ }();
506
+ await Database.Add(
507
+ () => new Sqlite3(),
508
+ Sqlite3Static
509
+ );
510
+
511
+ // src/exports/database/dbs/table.ts
512
+ var Table = class {
513
+ #dialect;
514
+ #Database;
515
+ #DataDir;
516
+ #tableName;
517
+ #type;
518
+ #primaryKey;
519
+ /**
520
+ * @param type Db: 直接保存在sqlite数据中、 File: 保存在单个json文件中、 Dir: 保存在多个json文件的目录中、Schema中除pk外每一个键值对应一个文件 e.g tableName/user/key.json
521
+ */
522
+ constructor(DataDir, tableName, type, primaryKey) {
523
+ this.#primaryKey = primaryKey;
524
+ this.#Database = Database.get();
525
+ this.#dialect = this.#Database.dialect;
526
+ this.#DataDir = DataDir;
527
+ this.#tableName = tableName;
528
+ this.#type = type;
529
+ }
530
+ #cache() {
531
+ return async () => {
532
+ const Db = Database.get();
533
+ if (Db.dialect !== this.#dialect) {
534
+ this.#dialect = Db.dialect;
535
+ this.#Database = Db;
536
+ await this.init(this.modelSchema);
537
+ }
538
+ return this.initCache;
539
+ };
540
+ }
541
+ async init(Schema, SchemaDefine = {}) {
542
+ this.modelSchema = Schema;
543
+ this.modelSchemaDefine = SchemaDefine;
544
+ this.initCache = await this.#Database.init(
545
+ this.#DataDir,
546
+ this.#tableName,
547
+ this.modelSchema,
548
+ this.modelSchemaDefine,
549
+ this.#type,
550
+ this.#primaryKey
551
+ );
552
+ return this.#cache();
553
+ }
554
+ async addSchem(newSchema, SchemaDefine = {}) {
555
+ this.modelSchema = Object.assign(this.modelSchema, newSchema);
556
+ this.modelSchemaDefine = Object.assign(this.modelSchemaDefine, SchemaDefine);
557
+ this.initCache = await this.#Database.init(
558
+ this.#DataDir,
559
+ this.#tableName,
560
+ this.modelSchema,
561
+ this.modelSchemaDefine,
562
+ this.#type
563
+ );
564
+ return this.#cache();
565
+ }
566
+ };
567
+ function createTable(DataDir, tableName, type, primaryKey) {
568
+ return new Table(DataDir, tableName, type, primaryKey);
569
+ }
570
+
571
+ // src/exports/database/tables/mysAccountInfo.ts
572
+ var MysAccountInfoTable = createTable(
573
+ dir.DataDir,
574
+ "mys_account_info_data",
575
+ "db" /* Db */
576
+ );
577
+ var MysAccountInfoDB = await MysAccountInfoTable.init(
578
+ {
579
+ ltuid: Database.PkColumn("STRING"),
580
+ type: Database.Column("STRING", "mihoyo" /* cn */),
581
+ cookie: Database.Column("TEXT", ""),
582
+ stoken: Database.Column("STRING", ""),
583
+ deviceMd5: Database.Column("STRING", "")
584
+ }
585
+ );
586
+
587
+ // src/exports/database/tables/mysDeviceInfo.ts
588
+ var MysDeviceInfoTable = createTable(
589
+ dir.DataDir,
590
+ "mys_device_info_data",
591
+ "db" /* Db */
592
+ );
593
+ var MysDeviceInfoDB = await MysDeviceInfoTable.init(
594
+ {
595
+ md5: Database.PkColumn("STRING"),
596
+ deviceId: Database.Column("STRING", common_exports.getDeviceGuid),
597
+ deviceFp: Database.Column("STRING", ""),
598
+ name: Database.Column("STRING", ""),
599
+ board: Database.Column("STRING", ""),
600
+ model: Database.Column("STRING", ""),
601
+ oaid: Database.Column("STRING", ""),
602
+ version: Database.Column("INTEGER", 12),
603
+ fingerprint: Database.Column("STRING", ""),
604
+ product: Database.Column("STRING", "")
605
+ }
606
+ );
607
+
608
+ // src/exports/database/tables/mysUserInfo.ts
609
+ var MysUserInfoTable = createTable(
610
+ dir.DataDir,
611
+ "mys_user_info_data",
612
+ "db" /* Db */
613
+ );
614
+ var MysUserInfoDB = await MysUserInfoTable.init(
615
+ {
616
+ userId: Database.PkColumn("STRING"),
617
+ ltuids: Database.ArrayColumn("ltuids"),
618
+ stuids: Database.ArrayColumn("stuids"),
619
+ deviceList: Database.ArrayColumn("deviceList")
620
+ }
621
+ );
622
+
623
+ export {
624
+ Dialect,
625
+ DatabaseType,
626
+ DatabaseArray,
627
+ MysAccountType,
628
+ UidPermission,
629
+ DbBase,
630
+ Database,
631
+ Table,
632
+ createTable,
633
+ MysAccountInfoTable,
634
+ MysAccountInfoDB,
635
+ MysDeviceInfoTable,
636
+ MysDeviceInfoDB,
637
+ MysUserInfoTable,
638
+ MysUserInfoDB
639
+ };
@@ -79,10 +79,5 @@ function filterData(user, defaults, Define) {
79
79
  }
80
80
 
81
81
  export {
82
- randomString,
83
- getDeviceGuid,
84
- StrToObj,
85
- ObjToStr,
86
- filterData,
87
82
  common_exports
88
83
  };