@auto-mas/auto-mas-plugin-maa-updates 0.0.0-stage → 0.1.0
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/index.js +1 -0
- package/dist/server/builtin-plugins/maa-updates.js +4 -0
- package/dist/server/execution.js +364 -0
- package/dist/server/game-plugins/maa.js +233 -0
- package/dist/server/game-plugins/native.js +207 -0
- package/dist/server/game-plugins/profile-options.js +38 -0
- package/dist/server/maa-updates.js +75 -0
- package/dist/server/run-lifecycle.js +1 -0
- package/dist/server/schema.js +353 -0
- package/dist/server/storage.js +76 -0
- package/package.json +30 -6
- package/README.md +0 -3
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { mkdirSync } from 'node:fs';
|
|
2
|
+
import { join } from 'node:path';
|
|
3
|
+
import { DatabaseSync } from 'node:sqlite';
|
|
4
|
+
export class Store {
|
|
5
|
+
db;
|
|
6
|
+
lease;
|
|
7
|
+
constructor(directory) {
|
|
8
|
+
mkdirSync(directory, { recursive: true });
|
|
9
|
+
this.lease = new DatabaseSync(join(directory, 'session.db'));
|
|
10
|
+
try {
|
|
11
|
+
this.lease.exec('PRAGMA busy_timeout = 0; BEGIN EXCLUSIVE');
|
|
12
|
+
}
|
|
13
|
+
catch (error) {
|
|
14
|
+
this.lease.close();
|
|
15
|
+
if (error.errcode === 5)
|
|
16
|
+
throw new Error('该数据目录已有 MAS 后端在运行');
|
|
17
|
+
throw error;
|
|
18
|
+
}
|
|
19
|
+
try {
|
|
20
|
+
this.db = new DatabaseSync(join(directory, 'mas.db'));
|
|
21
|
+
this.db.exec(`PRAGMA journal_mode = WAL;
|
|
22
|
+
CREATE TABLE IF NOT EXISTS entries (
|
|
23
|
+
collection TEXT NOT NULL, id TEXT NOT NULL, value TEXT NOT NULL,
|
|
24
|
+
PRIMARY KEY (collection, id)
|
|
25
|
+
);
|
|
26
|
+
CREATE INDEX IF NOT EXISTS run_start ON entries (
|
|
27
|
+
unixepoch(json_extract(value, '$.started'), 'subsec') DESC
|
|
28
|
+
) WHERE collection = 'runs'`);
|
|
29
|
+
}
|
|
30
|
+
catch (error) {
|
|
31
|
+
this.lease.close();
|
|
32
|
+
throw error;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
recentRuns() {
|
|
36
|
+
return this.db.prepare(`SELECT value FROM entries WHERE collection = 'runs'
|
|
37
|
+
ORDER BY unixepoch(json_extract(value, '$.started'), 'subsec') DESC, rowid DESC LIMIT 200`)
|
|
38
|
+
.all().map(row => JSON.parse(String(row.value)));
|
|
39
|
+
}
|
|
40
|
+
list(collection) {
|
|
41
|
+
const rows = this.db.prepare('SELECT value FROM entries WHERE collection = ? ORDER BY rowid').all(collection);
|
|
42
|
+
return rows.map(row => JSON.parse(String(row.value)));
|
|
43
|
+
}
|
|
44
|
+
get(collection, id) {
|
|
45
|
+
const row = this.db.prepare('SELECT value FROM entries WHERE collection = ? AND id = ?').get(collection, id);
|
|
46
|
+
return row && JSON.parse(String(row.value));
|
|
47
|
+
}
|
|
48
|
+
put(collection, entry) {
|
|
49
|
+
this.db.prepare('INSERT INTO entries VALUES (?, ?, ?) ON CONFLICT(collection, id) DO UPDATE SET value = excluded.value')
|
|
50
|
+
.run(collection, entry.id, JSON.stringify(entry));
|
|
51
|
+
return entry;
|
|
52
|
+
}
|
|
53
|
+
remove(collection, id) {
|
|
54
|
+
this.db.prepare('DELETE FROM entries WHERE collection = ? AND id = ?').run(collection, id);
|
|
55
|
+
}
|
|
56
|
+
transaction(callback) {
|
|
57
|
+
this.db.exec('BEGIN IMMEDIATE');
|
|
58
|
+
try {
|
|
59
|
+
const result = callback();
|
|
60
|
+
this.db.exec('COMMIT');
|
|
61
|
+
return result;
|
|
62
|
+
}
|
|
63
|
+
catch (error) {
|
|
64
|
+
this.db.exec('ROLLBACK');
|
|
65
|
+
throw error;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
close() {
|
|
69
|
+
try {
|
|
70
|
+
this.db.close();
|
|
71
|
+
}
|
|
72
|
+
finally {
|
|
73
|
+
this.lease.close();
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,30 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@auto-mas/auto-mas-plugin-maa-updates",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
1
|
+
{
|
|
2
|
+
"name": "@auto-mas/auto-mas-plugin-maa-updates",
|
|
3
|
+
"version": "0.1.0",
|
|
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 maa-updates Cordis component",
|
|
21
|
+
"autoMas": {
|
|
22
|
+
"id": "maa-updates",
|
|
23
|
+
"abi": 1,
|
|
24
|
+
"hostDependencies": {
|
|
25
|
+
"cordis": "4.0.0-rc.13",
|
|
26
|
+
"jsonc-parser": "3.3.1",
|
|
27
|
+
"schemastery": "3.18.0"
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
package/README.md
DELETED