@auto-mas/auto-mas-plugin-community 0.0.0-stage → 0.2.1
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/dist/LICENSE +661 -0
- package/dist/client/THIRD-PARTY-LICENSES.md +440 -0
- package/dist/client/index.js +45677 -0
- package/dist/client/style.css +2 -0
- package/dist/index.js +1 -0
- package/dist/server/builtin-plugins/community.js +4 -0
- package/dist/server/community/arknights-gacha.js +195 -0
- package/dist/server/community/cloud-genshin.js +80 -0
- package/dist/server/community/des.js +158 -0
- package/dist/server/community/display-names.js +7 -0
- package/dist/server/community/index.js +788 -0
- package/dist/server/community/kuro.js +121 -0
- package/dist/server/community/miyoushe-device.js +108 -0
- package/dist/server/community/miyoushe-qr.js +484 -0
- package/dist/server/community/miyoushe.js +633 -0
- package/dist/server/community/pages.js +630 -0
- package/dist/server/community/provider.js +63 -0
- package/dist/server/community/qrcode.js +365 -0
- package/dist/server/community/skland-qr.js +267 -0
- package/dist/server/community/skland.js +422 -0
- package/dist/server/community/taygedo.js +189 -0
- package/dist/server/community/vault.js +65 -0
- package/dist/server/features.js +31 -0
- package/dist/server/schema.js +353 -0
- package/package.json +43 -6
- package/README.md +0 -3
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { createCipheriv, createDecipheriv, randomBytes } from 'node:crypto';
|
|
2
|
+
import { lstat, readFile, writeFile } from 'node:fs/promises';
|
|
3
|
+
import { join } from 'node:path';
|
|
4
|
+
export class CredentialVault {
|
|
5
|
+
path;
|
|
6
|
+
namespace;
|
|
7
|
+
pending;
|
|
8
|
+
constructor(dataDir, scope = 'community') {
|
|
9
|
+
this.path = join(dataDir, scope === 'community' ? '.community-key' : '.plugin-config-key');
|
|
10
|
+
this.namespace = scope === 'community' ? 'Cordis MAS community sign-in v1:cloud-genshin' : 'AUTO-MASC plugin configuration v1';
|
|
11
|
+
}
|
|
12
|
+
async load(create) {
|
|
13
|
+
try {
|
|
14
|
+
const info = await lstat(this.path);
|
|
15
|
+
if (!info.isFile() || info.size !== 32 || (process.platform !== 'win32' && (info.mode & 0o077) !== 0)) {
|
|
16
|
+
throw new Error('本机加密密钥文件无效或权限过宽');
|
|
17
|
+
}
|
|
18
|
+
return await readFile(this.path);
|
|
19
|
+
}
|
|
20
|
+
catch (error) {
|
|
21
|
+
if (error.code !== 'ENOENT')
|
|
22
|
+
throw error;
|
|
23
|
+
if (!create)
|
|
24
|
+
throw new Error('找不到本机加密密钥,请重新配置');
|
|
25
|
+
const key = randomBytes(32);
|
|
26
|
+
try {
|
|
27
|
+
await writeFile(this.path, key, { flag: 'wx', mode: 0o600 });
|
|
28
|
+
}
|
|
29
|
+
catch (writeError) {
|
|
30
|
+
if (writeError.code !== 'EEXIST')
|
|
31
|
+
throw writeError;
|
|
32
|
+
return this.load(false);
|
|
33
|
+
}
|
|
34
|
+
return key;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
key(create) {
|
|
38
|
+
this.pending ??= this.load(create).catch(error => { this.pending = undefined; throw error; });
|
|
39
|
+
return this.pending;
|
|
40
|
+
}
|
|
41
|
+
context(id) {
|
|
42
|
+
return Buffer.from(`${this.namespace}:${id}`);
|
|
43
|
+
}
|
|
44
|
+
async seal(id, secret) {
|
|
45
|
+
const nonce = randomBytes(12);
|
|
46
|
+
const cipher = createCipheriv('aes-256-gcm', await this.key(true), nonce);
|
|
47
|
+
cipher.setAAD(this.context(id));
|
|
48
|
+
const data = Buffer.concat([cipher.update(secret, 'utf8'), cipher.final()]);
|
|
49
|
+
return { version: 1, nonce: nonce.toString('base64'), cipher: data.toString('base64'), tag: cipher.getAuthTag().toString('base64') };
|
|
50
|
+
}
|
|
51
|
+
async reveal(id, secret) {
|
|
52
|
+
const key = await this.key(false);
|
|
53
|
+
try {
|
|
54
|
+
if (secret.version !== 1)
|
|
55
|
+
throw new Error('Unrecognized credential');
|
|
56
|
+
const decipher = createDecipheriv('aes-256-gcm', key, Buffer.from(secret.nonce, 'base64'), { authTagLength: 16 });
|
|
57
|
+
decipher.setAAD(this.context(id));
|
|
58
|
+
decipher.setAuthTag(Buffer.from(secret.tag, 'base64'));
|
|
59
|
+
return Buffer.concat([decipher.update(Buffer.from(secret.cipher, 'base64')), decipher.final()]).toString('utf8');
|
|
60
|
+
}
|
|
61
|
+
catch {
|
|
62
|
+
throw new Error('无法解密本机配置,请重新配置');
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
export const ui = (ctx) => ctx.get('mas.ui');
|
|
2
|
+
export const store = (ctx) => ctx.get('mas.store');
|
|
3
|
+
export const runner = (ctx) => ctx.get('mas.runner');
|
|
4
|
+
export function text(input, key, label, required = true) {
|
|
5
|
+
const value = input[key];
|
|
6
|
+
if (typeof value === 'string' && value.trim())
|
|
7
|
+
return value.trim();
|
|
8
|
+
if (required)
|
|
9
|
+
throw new Error(`请输入${label}`);
|
|
10
|
+
return '';
|
|
11
|
+
}
|
|
12
|
+
export function strings(value) {
|
|
13
|
+
if (!value)
|
|
14
|
+
return [];
|
|
15
|
+
if (Array.isArray(value) && value.every(item => typeof item === 'string'))
|
|
16
|
+
return value;
|
|
17
|
+
if (typeof value === 'string') {
|
|
18
|
+
if (value.trim().startsWith('[')) {
|
|
19
|
+
const parsed = JSON.parse(value);
|
|
20
|
+
if (Array.isArray(parsed) && parsed.every(item => typeof item === 'string'))
|
|
21
|
+
return parsed;
|
|
22
|
+
throw new Error('JSON 必须是字符串数组');
|
|
23
|
+
}
|
|
24
|
+
return value.split(/[\n,]+/).map(item => item.trim()).filter(Boolean);
|
|
25
|
+
}
|
|
26
|
+
throw new Error('请输入字符串列表');
|
|
27
|
+
}
|
|
28
|
+
export const field = (key, label, extra = {}) => ({ key, label, ...extra });
|
|
29
|
+
export const columns = (...pairs) => pairs.map(([key, label]) => ({ key, label }));
|
|
30
|
+
export const action = (id, label) => ({ id, label });
|
|
31
|
+
export const runColumns = columns(['name', '托管'], ['status', '状态'], ['started', '开始时间'], ['finished', '结束时间'], ['error', '结果详情']);
|
|
@@ -0,0 +1,353 @@
|
|
|
1
|
+
import { isDeepStrictEqual } from 'node:util';
|
|
2
|
+
import Schemastery from 'schemastery';
|
|
3
|
+
export const Schema = Object.assign(Schemastery, {
|
|
4
|
+
path(options = {}) {
|
|
5
|
+
return Schemastery.string().role('path', options);
|
|
6
|
+
},
|
|
7
|
+
});
|
|
8
|
+
function plain(value) {
|
|
9
|
+
if (!value || typeof value !== 'object' || Array.isArray(value))
|
|
10
|
+
return false;
|
|
11
|
+
const prototype = Object.getPrototypeOf(value);
|
|
12
|
+
return prototype === Object.prototype || prototype === null;
|
|
13
|
+
}
|
|
14
|
+
function entries(value) {
|
|
15
|
+
return Object.entries(value).filter(([key]) => key !== '__proto__');
|
|
16
|
+
}
|
|
17
|
+
function own(value, key) {
|
|
18
|
+
return Object.hasOwn(value, key) ? value[key] : undefined;
|
|
19
|
+
}
|
|
20
|
+
export function isSchema(value) {
|
|
21
|
+
if (typeof value !== 'function')
|
|
22
|
+
return false;
|
|
23
|
+
const schema = value;
|
|
24
|
+
return schema[Symbol.for('schemastery')] === true && typeof schema.type === 'string' && plain(schema.meta);
|
|
25
|
+
}
|
|
26
|
+
function encode(value, parents = new Set()) {
|
|
27
|
+
if (value === null || typeof value === 'string' || typeof value === 'boolean')
|
|
28
|
+
return value;
|
|
29
|
+
if (typeof value === 'number')
|
|
30
|
+
return Number.isFinite(value) ? value : null;
|
|
31
|
+
if (value instanceof Date)
|
|
32
|
+
return value.toJSON();
|
|
33
|
+
if (value instanceof RegExp)
|
|
34
|
+
return { source: value.source, flags: value.flags };
|
|
35
|
+
if (!(Array.isArray(value) || plain(value)) || parents.has(value))
|
|
36
|
+
return undefined;
|
|
37
|
+
parents.add(value);
|
|
38
|
+
const result = Array.isArray(value)
|
|
39
|
+
? value.map(item => encode(item, parents) ?? null)
|
|
40
|
+
: Object.fromEntries(entries(value).flatMap(([key, item]) => {
|
|
41
|
+
const encoded = encode(item, parents);
|
|
42
|
+
return encoded === undefined ? [] : [[key, encoded]];
|
|
43
|
+
}));
|
|
44
|
+
parents.delete(value);
|
|
45
|
+
return result;
|
|
46
|
+
}
|
|
47
|
+
function copyInput(value, copies = new WeakMap()) {
|
|
48
|
+
if (!(Array.isArray(value) || plain(value)))
|
|
49
|
+
return value;
|
|
50
|
+
if (copies.has(value))
|
|
51
|
+
return copies.get(value);
|
|
52
|
+
if (Array.isArray(value)) {
|
|
53
|
+
const result = [];
|
|
54
|
+
copies.set(value, result);
|
|
55
|
+
for (const item of value)
|
|
56
|
+
result.push(copyInput(item, copies));
|
|
57
|
+
return result;
|
|
58
|
+
}
|
|
59
|
+
const result = {};
|
|
60
|
+
copies.set(value, result);
|
|
61
|
+
for (const [key, item] of entries(value))
|
|
62
|
+
result[key] = copyInput(item, copies);
|
|
63
|
+
return result;
|
|
64
|
+
}
|
|
65
|
+
function secret(meta) {
|
|
66
|
+
return meta?.role === 'secret' || meta?.role === 'password' || meta?.password === true || meta?.writeOnly === true;
|
|
67
|
+
}
|
|
68
|
+
function privateValue(meta) {
|
|
69
|
+
return meta?.hidden === true || secret(meta);
|
|
70
|
+
}
|
|
71
|
+
function lazyTarget(schema) {
|
|
72
|
+
if (isSchema(schema.inner))
|
|
73
|
+
return schema.inner;
|
|
74
|
+
const target = schema.builder?.();
|
|
75
|
+
if (!isSchema(target))
|
|
76
|
+
throw new TypeError('Schemastery lazy builder must return a schema');
|
|
77
|
+
return new Schema({ ...target, meta: { ...schema.meta, ...target.meta } });
|
|
78
|
+
}
|
|
79
|
+
export function describeSchema(schema) {
|
|
80
|
+
const visible = new WeakMap();
|
|
81
|
+
const protectedNodes = new WeakMap();
|
|
82
|
+
const defaults = [];
|
|
83
|
+
let nextId = 0;
|
|
84
|
+
function describe(source, inherited = false) {
|
|
85
|
+
const isPrivate = inherited || privateValue(source.meta);
|
|
86
|
+
const seen = isPrivate ? protectedNodes : visible;
|
|
87
|
+
const previous = seen.get(source);
|
|
88
|
+
if (previous !== undefined)
|
|
89
|
+
return { type: 'ref', ref: previous };
|
|
90
|
+
const id = nextId++;
|
|
91
|
+
seen.set(source, id);
|
|
92
|
+
const effective = source.type === 'lazy' ? lazyTarget(source) : source;
|
|
93
|
+
const meta = encode(effective.meta);
|
|
94
|
+
const protectsChildren = isPrivate || privateValue(meta);
|
|
95
|
+
const node = { type: effective.type, id };
|
|
96
|
+
if (protectsChildren) {
|
|
97
|
+
delete meta.default;
|
|
98
|
+
delete meta.extra;
|
|
99
|
+
}
|
|
100
|
+
if (isPrivate && !privateValue(meta))
|
|
101
|
+
meta.hidden = true;
|
|
102
|
+
if (Object.keys(meta).length)
|
|
103
|
+
node.meta = meta;
|
|
104
|
+
if (Object.hasOwn(meta, 'default'))
|
|
105
|
+
defaults.push(node);
|
|
106
|
+
if (effective.inner && isSchema(effective.inner))
|
|
107
|
+
node.inner = describe(effective.inner, protectsChildren);
|
|
108
|
+
if (effective.sKey)
|
|
109
|
+
node.key = describe(effective.sKey, protectsChildren);
|
|
110
|
+
if (effective.list)
|
|
111
|
+
node.list = effective.list.map(item => describe(item, protectsChildren));
|
|
112
|
+
if (effective.dict)
|
|
113
|
+
node.dict = Object.fromEntries(Object.entries(effective.dict)
|
|
114
|
+
.filter(([key]) => key !== '__proto__').map(([key, item]) => [key, describe(item, protectsChildren)]));
|
|
115
|
+
if (effective.bits)
|
|
116
|
+
node.bits = Object.fromEntries(Object.entries(effective.bits).filter(([key]) => key !== '__proto__'));
|
|
117
|
+
if (effective.type === 'is' && effective.constructor)
|
|
118
|
+
node.className = typeof effective.constructor === 'string' ? effective.constructor : effective.constructor.name;
|
|
119
|
+
if (effective.type === 'transform' && effective.preserve !== undefined)
|
|
120
|
+
node.preserve = effective.preserve;
|
|
121
|
+
const value = protectsChildren ? undefined : encode(effective.value);
|
|
122
|
+
if (value !== undefined)
|
|
123
|
+
node.value = value;
|
|
124
|
+
return node;
|
|
125
|
+
}
|
|
126
|
+
const root = describe(schema);
|
|
127
|
+
const refs = indexNodes(root);
|
|
128
|
+
for (const node of defaults) {
|
|
129
|
+
const value = expose([node], node.meta.default, refs);
|
|
130
|
+
if (value === undefined)
|
|
131
|
+
delete node.meta.default;
|
|
132
|
+
else
|
|
133
|
+
node.meta.default = value;
|
|
134
|
+
}
|
|
135
|
+
return root;
|
|
136
|
+
}
|
|
137
|
+
function indexNodes(root) {
|
|
138
|
+
const refs = new Map();
|
|
139
|
+
const walk = (node) => {
|
|
140
|
+
if (!node || node.type === 'ref')
|
|
141
|
+
return;
|
|
142
|
+
if (node.id !== undefined)
|
|
143
|
+
refs.set(node.id, node);
|
|
144
|
+
walk(node.inner);
|
|
145
|
+
walk(node.key);
|
|
146
|
+
node.list?.forEach(walk);
|
|
147
|
+
Object.values(node.dict ?? {}).forEach(walk);
|
|
148
|
+
};
|
|
149
|
+
walk(root);
|
|
150
|
+
return refs;
|
|
151
|
+
}
|
|
152
|
+
function fits(node, value, refs, visited = new Set()) {
|
|
153
|
+
if (value == null || visited.has(node))
|
|
154
|
+
return true;
|
|
155
|
+
visited.add(node);
|
|
156
|
+
if (node.type === 'ref' && node.ref !== undefined) {
|
|
157
|
+
const target = refs.get(node.ref);
|
|
158
|
+
return !target || fits(target, value, refs, visited);
|
|
159
|
+
}
|
|
160
|
+
if (node.type === 'const')
|
|
161
|
+
return !Object.hasOwn(node, 'value') || isDeepStrictEqual(node.value, value);
|
|
162
|
+
if (node.type === 'string' || node.type === 'number' || node.type === 'boolean')
|
|
163
|
+
return typeof value === node.type;
|
|
164
|
+
if (node.type === 'array' || node.type === 'tuple')
|
|
165
|
+
return Array.isArray(value);
|
|
166
|
+
if (node.type === 'object' || node.type === 'dict') {
|
|
167
|
+
if (!plain(value))
|
|
168
|
+
return false;
|
|
169
|
+
return Object.entries(node.dict ?? {}).every(([key, child]) => {
|
|
170
|
+
const field = child.type === 'ref' && child.ref !== undefined ? refs.get(child.ref) : child;
|
|
171
|
+
return field?.type !== 'const' || fits(field, own(value, key), refs, new Set(visited));
|
|
172
|
+
});
|
|
173
|
+
}
|
|
174
|
+
if (node.type === 'transform' && node.inner)
|
|
175
|
+
return fits(node.inner, value, refs, visited);
|
|
176
|
+
if (node.type === 'intersect')
|
|
177
|
+
return node.list?.every(item => fits(item, value, refs, new Set(visited))) ?? true;
|
|
178
|
+
if (node.type === 'union')
|
|
179
|
+
return node.list?.some(item => fits(item, value, refs, new Set(visited))) ?? true;
|
|
180
|
+
return true;
|
|
181
|
+
}
|
|
182
|
+
function expand(input, value, refs) {
|
|
183
|
+
const seen = new Set();
|
|
184
|
+
function visit(node) {
|
|
185
|
+
if (!node || seen.has(node))
|
|
186
|
+
return;
|
|
187
|
+
seen.add(node);
|
|
188
|
+
if (node.type === 'ref')
|
|
189
|
+
visit(node.ref === undefined ? undefined : refs.get(node.ref));
|
|
190
|
+
if (node.type === 'transform')
|
|
191
|
+
visit(node.inner);
|
|
192
|
+
if (node.type === 'intersect')
|
|
193
|
+
node.list?.forEach(visit);
|
|
194
|
+
if (node.type === 'union' && node.list) {
|
|
195
|
+
const matching = node.list.filter(branch => fits(branch, value, refs));
|
|
196
|
+
const branches = matching.length ? matching : node.list;
|
|
197
|
+
branches.forEach(visit);
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
input.forEach(visit);
|
|
201
|
+
return [...seen];
|
|
202
|
+
}
|
|
203
|
+
function at(nodes, key) {
|
|
204
|
+
return nodes.flatMap(node => {
|
|
205
|
+
let child;
|
|
206
|
+
if (typeof key === 'number')
|
|
207
|
+
child = node.type === 'array' ? node.inner : node.type === 'tuple' ? node.list?.[key] : undefined;
|
|
208
|
+
else if (node.type === 'dict')
|
|
209
|
+
child = node.inner;
|
|
210
|
+
else if (node.type === 'object' && Object.hasOwn(node.dict ?? {}, key))
|
|
211
|
+
child = node.dict?.[key];
|
|
212
|
+
return child ? [child] : [];
|
|
213
|
+
});
|
|
214
|
+
}
|
|
215
|
+
function hidesKeys(node, refs) {
|
|
216
|
+
return node.type === 'dict' && node.key && expand([node.key], undefined, refs).some(key => privateValue(key.meta));
|
|
217
|
+
}
|
|
218
|
+
function locked(node, refs) {
|
|
219
|
+
return node.meta?.hidden === true || node.meta?.disabled === true || node.meta?.readonly === true || hidesKeys(node, refs);
|
|
220
|
+
}
|
|
221
|
+
function expose(input, value, refs) {
|
|
222
|
+
const nodes = expand(input, value, refs);
|
|
223
|
+
if (nodes.some(node => privateValue(node.meta) || hidesKeys(node, refs)))
|
|
224
|
+
return undefined;
|
|
225
|
+
if (Array.isArray(value))
|
|
226
|
+
return value.map((item, key) => expose(at(nodes, key), item, refs) ?? null);
|
|
227
|
+
if (!plain(value))
|
|
228
|
+
return encode(value);
|
|
229
|
+
const typed = nodes.some(node => node.type === 'object');
|
|
230
|
+
return Object.fromEntries(entries(value).flatMap(([key, item]) => {
|
|
231
|
+
const rules = at(nodes, key);
|
|
232
|
+
if (typed && !rules.length)
|
|
233
|
+
return [];
|
|
234
|
+
const visible = expose(rules, item, refs);
|
|
235
|
+
return visible === undefined ? [] : [[key, visible]];
|
|
236
|
+
}));
|
|
237
|
+
}
|
|
238
|
+
export function publicConfig(node, value) {
|
|
239
|
+
return expose([node], value, indexNodes(node));
|
|
240
|
+
}
|
|
241
|
+
function rowSources(before, after, prior, draft, refs) {
|
|
242
|
+
const oldRows = prior.map((value, index) => {
|
|
243
|
+
const rules = at(before, index);
|
|
244
|
+
return { value, visible: expose(rules, value, refs) };
|
|
245
|
+
});
|
|
246
|
+
if (oldRows.every(row => isDeepStrictEqual(row.visible, row.value)))
|
|
247
|
+
return prior;
|
|
248
|
+
const visibleDraft = draft.map((item, index) => expose(at(after, index), item, refs));
|
|
249
|
+
if (oldRows.length === draft.length && oldRows.every((row, index) => isDeepStrictEqual(row.visible, visibleDraft[index])))
|
|
250
|
+
return prior;
|
|
251
|
+
const signature = (value) => JSON.stringify(value, (_, item) => {
|
|
252
|
+
if (!plain(item))
|
|
253
|
+
return item;
|
|
254
|
+
return Object.fromEntries(Object.keys(item).sort().map(key => [key, item[key]]));
|
|
255
|
+
});
|
|
256
|
+
const positions = new Map();
|
|
257
|
+
oldRows.forEach((row, index) => {
|
|
258
|
+
const key = signature(row.visible);
|
|
259
|
+
positions.set(key, positions.has(key) ? null : index);
|
|
260
|
+
});
|
|
261
|
+
const matched = new Set();
|
|
262
|
+
const sources = visibleDraft.map(value => {
|
|
263
|
+
const index = positions.get(signature(value));
|
|
264
|
+
if (typeof index === 'number' && !matched.has(index)) {
|
|
265
|
+
matched.add(index);
|
|
266
|
+
return oldRows[index].value;
|
|
267
|
+
}
|
|
268
|
+
return undefined;
|
|
269
|
+
});
|
|
270
|
+
if (sources.includes(undefined) && oldRows.some((row, index) => !matched.has(index) && !isDeepStrictEqual(row.visible, row.value))) {
|
|
271
|
+
throw new TypeError('无法对应包含密钥或隐藏值的配置行。请分开保存删除和新增操作。');
|
|
272
|
+
}
|
|
273
|
+
return sources;
|
|
274
|
+
}
|
|
275
|
+
function merge(previousSchemas, draftSchemas, prior, draft, refs) {
|
|
276
|
+
const before = expand(previousSchemas, prior, refs);
|
|
277
|
+
let sample = draft ?? prior;
|
|
278
|
+
if (plain(draft)) {
|
|
279
|
+
const previous = plain(prior) ? prior : {};
|
|
280
|
+
const candidate = { ...previous, ...draft };
|
|
281
|
+
for (const [key] of entries(draft)) {
|
|
282
|
+
const value = own(previous, key);
|
|
283
|
+
if (expand(at(before, key), value, refs).some(node => locked(node, refs))) {
|
|
284
|
+
if (value === undefined)
|
|
285
|
+
delete candidate[key];
|
|
286
|
+
else
|
|
287
|
+
candidate[key] = value;
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
sample = candidate;
|
|
291
|
+
}
|
|
292
|
+
const after = expand(draftSchemas, sample, refs);
|
|
293
|
+
if (after.some(node => locked(node, refs)))
|
|
294
|
+
return copyInput(prior);
|
|
295
|
+
if (after.some(node => secret(node.meta))) {
|
|
296
|
+
return draft == null || typeof draft === 'string' && !draft.trim() ? copyInput(prior) : copyInput(draft);
|
|
297
|
+
}
|
|
298
|
+
if (draft === undefined && before.some(node => privateValue(node.meta)))
|
|
299
|
+
return undefined;
|
|
300
|
+
if (Array.isArray(draft)) {
|
|
301
|
+
const previous = Array.isArray(prior) ? prior : [];
|
|
302
|
+
const sources = before.some(node => node.type === 'array') ? rowSources(before, after, previous, draft, refs) : previous;
|
|
303
|
+
return draft.map((item, key) => merge(at(before, key), at(after, key), sources[key], item, refs));
|
|
304
|
+
}
|
|
305
|
+
const previous = plain(prior) ? prior : {};
|
|
306
|
+
if (plain(draft) || draft === undefined && plain(prior)) {
|
|
307
|
+
const next = plain(draft) ? draft : {};
|
|
308
|
+
const keys = new Set(entries(next).map(([key]) => key));
|
|
309
|
+
for (const [key] of entries(previous)) {
|
|
310
|
+
if (draft === undefined || after.some(node => node.type === 'object' && Object.hasOwn(node.dict ?? {}, key)))
|
|
311
|
+
keys.add(key);
|
|
312
|
+
}
|
|
313
|
+
const result = Object.fromEntries([...keys].flatMap(key => {
|
|
314
|
+
const value = merge(at(before, key), at(after, key), own(previous, key), own(next, key), refs);
|
|
315
|
+
return value === undefined ? [] : [[key, value]];
|
|
316
|
+
}));
|
|
317
|
+
return draft === undefined && !Object.keys(result).length ? undefined : result;
|
|
318
|
+
}
|
|
319
|
+
return copyInput(draft);
|
|
320
|
+
}
|
|
321
|
+
export function mergeConfig(node, prior, draft) {
|
|
322
|
+
return merge([node], [node], prior, draft, indexNodes(node));
|
|
323
|
+
}
|
|
324
|
+
export function parseConfig(schema, value) {
|
|
325
|
+
if (!isSchema(schema))
|
|
326
|
+
throw new TypeError('Configuration schema must be a Schemastery schema');
|
|
327
|
+
const validate = schema['~standard'].validate;
|
|
328
|
+
let result;
|
|
329
|
+
try {
|
|
330
|
+
result = validate(copyInput(value));
|
|
331
|
+
}
|
|
332
|
+
catch (error) {
|
|
333
|
+
if ([...indexNodes(describeSchema(schema)).values()].some(node => privateValue(node.meta)))
|
|
334
|
+
throw new TypeError('Invalid configuration value');
|
|
335
|
+
throw error;
|
|
336
|
+
}
|
|
337
|
+
if (result instanceof Promise)
|
|
338
|
+
throw new TypeError('Schemastery configuration validation must be synchronous');
|
|
339
|
+
if (!result.issues)
|
|
340
|
+
return result.value;
|
|
341
|
+
// Upstream messages can quote the input or the contents of an entire union.
|
|
342
|
+
const graph = indexNodes(describeSchema(schema));
|
|
343
|
+
const nodes = [...graph.values()];
|
|
344
|
+
const protectedSchema = nodes.some(node => privateValue(node.meta));
|
|
345
|
+
const privateKeys = nodes.some(node => hidesKeys(node, graph));
|
|
346
|
+
const messages = result.issues.map(issue => {
|
|
347
|
+
if (!protectedSchema)
|
|
348
|
+
return issue.message;
|
|
349
|
+
const path = !privateKeys && issue.path?.map(segment => typeof segment === 'object' ? segment.key : segment).join('.');
|
|
350
|
+
return path ? `${path}: invalid configuration value` : 'Invalid configuration value';
|
|
351
|
+
});
|
|
352
|
+
throw new TypeError(messages.join('\n'));
|
|
353
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,43 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@auto-mas/auto-mas-plugin-community",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
1
|
+
{
|
|
2
|
+
"name": "@auto-mas/auto-mas-plugin-community",
|
|
3
|
+
"version": "0.2.1",
|
|
4
|
+
"license": "AGPL-3.0-only",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/index.js",
|
|
7
|
+
"exports": "./dist/index.js",
|
|
8
|
+
"files": [
|
|
9
|
+
"dist"
|
|
10
|
+
],
|
|
11
|
+
"engines": {
|
|
12
|
+
"node": ">=24"
|
|
13
|
+
},
|
|
14
|
+
"keywords": [
|
|
15
|
+
"auto-mas-plugin"
|
|
16
|
+
],
|
|
17
|
+
"publishConfig": {
|
|
18
|
+
"access": "public"
|
|
19
|
+
},
|
|
20
|
+
"description": "AUTO-MAS community Cordis component",
|
|
21
|
+
"mas": {
|
|
22
|
+
"hidden": false,
|
|
23
|
+
"category": "information",
|
|
24
|
+
"description": {
|
|
25
|
+
"zh": "集中管理游戏社区账号、角色信息和签到",
|
|
26
|
+
"en": "Manage game community accounts, character information, and check-ins"
|
|
27
|
+
}
|
|
28
|
+
},
|
|
29
|
+
"autoMas": {
|
|
30
|
+
"id": "community",
|
|
31
|
+
"abi": 1,
|
|
32
|
+
"views": [
|
|
33
|
+
"community",
|
|
34
|
+
"community-qr",
|
|
35
|
+
"community-gacha"
|
|
36
|
+
],
|
|
37
|
+
"hostDependencies": {
|
|
38
|
+
"cordis": "4.0.0-rc.13",
|
|
39
|
+
"jsonc-parser": "3.3.1",
|
|
40
|
+
"schemastery": "3.18.0"
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
package/README.md
DELETED