@sfmc-bds/db-server 0.1.0 → 0.2.0-beta.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/README.md +1 -1
- package/dist/db-tables.js +16 -17
- package/dist/db-tables.js.map +7 -1
- package/dist/domain/bridge.js +54 -77
- package/dist/domain/bridge.js.map +7 -1
- package/dist/domain/economy.d.ts +83 -2
- package/dist/domain/economy.d.ts.map +1 -1
- package/dist/domain/economy.js +292 -281
- package/dist/domain/economy.js.map +7 -1
- package/dist/domain/schema.js +480 -426
- package/dist/domain/schema.js.map +7 -1
- package/dist/domain/transaction.js +32 -80
- package/dist/domain/transaction.js.map +7 -1
- package/dist/env.d.ts.map +1 -1
- package/dist/env.js +85 -84
- package/dist/env.js.map +7 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +218 -240
- package/dist/index.js.map +7 -1
- package/dist/lib/http.js +30 -39
- package/dist/lib/http.js.map +7 -1
- package/dist/lib/idempotency-store.js +34 -47
- package/dist/lib/idempotency-store.js.map +7 -1
- package/dist/lib/idempotency.js +8 -13
- package/dist/lib/idempotency.js.map +7 -1
- package/dist/lib/identifiers.js +18 -14
- package/dist/lib/identifiers.js.map +7 -1
- package/dist/lib/log.d.ts +3 -6
- package/dist/lib/log.d.ts.map +1 -1
- package/dist/lib/log.js +13 -14
- package/dist/lib/log.js.map +7 -1
- package/dist/lib/module-state.d.ts.map +1 -1
- package/dist/lib/module-state.js +32 -21
- package/dist/lib/module-state.js.map +7 -1
- package/dist/lib/order-by.d.ts +17 -0
- package/dist/lib/order-by.d.ts.map +1 -0
- package/dist/lib/order-by.js +24 -0
- package/dist/lib/order-by.js.map +7 -0
- package/dist/lib/runtime.js +16 -31
- package/dist/lib/runtime.js.map +7 -1
- package/dist/lib/sql-helpers.js +9 -27
- package/dist/lib/sql-helpers.js.map +7 -1
- package/dist/lib/sqlite.js +40 -52
- package/dist/lib/sqlite.js.map +7 -1
- package/dist/manifest-loader.d.ts.map +1 -1
- package/dist/manifest-loader.js +154 -195
- package/dist/manifest-loader.js.map +7 -1
- package/dist/manifest.d.ts +3 -7
- package/dist/manifest.d.ts.map +1 -1
- package/dist/manifest.js +76 -115
- package/dist/manifest.js.map +7 -1
- package/dist/module-auth.d.ts +17 -6
- package/dist/module-auth.d.ts.map +1 -1
- package/dist/module-auth.js +93 -107
- package/dist/module-auth.js.map +7 -1
- package/dist/module-runtime-sync.d.ts +37 -0
- package/dist/module-runtime-sync.d.ts.map +1 -0
- package/dist/module-runtime-sync.js +54 -0
- package/dist/module-runtime-sync.js.map +7 -0
- package/dist/permission-gate.d.ts.map +1 -1
- package/dist/permission-gate.js +55 -86
- package/dist/permission-gate.js.map +7 -1
- package/dist/routes/_shared.d.ts +7 -2
- package/dist/routes/_shared.d.ts.map +1 -1
- package/dist/routes/_shared.js +16 -25
- package/dist/routes/_shared.js.map +7 -1
- package/dist/routes/config.d.ts +11 -1
- package/dist/routes/config.d.ts.map +1 -1
- package/dist/routes/config.js +167 -213
- package/dist/routes/config.js.map +7 -1
- package/dist/routes/db-routes.d.ts +6 -10
- package/dist/routes/db-routes.d.ts.map +1 -1
- package/dist/routes/db-routes.js +198 -172
- package/dist/routes/db-routes.js.map +7 -1
- package/dist/routes/health.js +15 -20
- package/dist/routes/health.js.map +7 -1
- package/dist/routes/messages.d.ts.map +1 -1
- package/dist/routes/messages.js +56 -63
- package/dist/routes/messages.js.map +7 -1
- package/dist/routes/module-config-routes.d.ts.map +1 -1
- package/dist/routes/module-config-routes.js +92 -111
- package/dist/routes/module-config-routes.js.map +7 -1
- package/dist/routes/modules.d.ts.map +1 -1
- package/dist/routes/modules.js +82 -88
- package/dist/routes/modules.js.map +7 -1
- package/dist/routes/service-routes.d.ts.map +1 -1
- package/dist/routes/service-routes.js +54 -61
- package/dist/routes/service-routes.js.map +7 -1
- package/dist/runtime.test.js +248 -49
- package/dist/runtime.test.js.map +7 -1
- package/dist/schema-registry.d.ts.map +1 -1
- package/dist/schema-registry.js +119 -160
- package/dist/schema-registry.js.map +7 -1
- package/dist/server.js +69 -72
- package/dist/server.js.map +7 -1
- package/dist/service-registry.d.ts.map +1 -1
- package/dist/service-registry.js +60 -67
- package/dist/service-registry.js.map +7 -1
- package/dist/services/builtin-handlers.d.ts +4 -0
- package/dist/services/builtin-handlers.d.ts.map +1 -1
- package/dist/services/builtin-handlers.js +34 -20
- package/dist/services/builtin-handlers.js.map +7 -1
- package/dist/services/economy-handlers.js +143 -132
- package/dist/services/economy-handlers.js.map +7 -1
- package/dist/tx-runner.d.ts +35 -11
- package/dist/tx-runner.d.ts.map +1 -1
- package/dist/tx-runner.js +293 -250
- package/dist/tx-runner.js.map +7 -1
- package/dist/where.js +71 -94
- package/dist/where.js.map +7 -1
- package/package.json +4 -4
package/dist/lib/sqlite.js
CHANGED
|
@@ -1,59 +1,47 @@
|
|
|
1
1
|
import { mkdirSync } from "node:fs";
|
|
2
2
|
import { dirname } from "node:path";
|
|
3
3
|
import { DatabaseSync, StatementSync } from "node:sqlite";
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
s = db.prepare(sql);
|
|
16
|
-
if (stmts.size >= maxStatements) {
|
|
17
|
-
const first = stmts.keys().next().value;
|
|
18
|
-
if (first !== undefined)
|
|
19
|
-
stmts.delete(first);
|
|
20
|
-
}
|
|
21
|
-
stmts.set(sql, s);
|
|
22
|
-
}
|
|
23
|
-
return s;
|
|
4
|
+
function createQuery(db, maxStatements = 200) {
|
|
5
|
+
const stmts = /* @__PURE__ */ new Map();
|
|
6
|
+
function getStmt(sql) {
|
|
7
|
+
let s = stmts.get(sql);
|
|
8
|
+
if (!s) {
|
|
9
|
+
s = db.prepare(sql);
|
|
10
|
+
if (stmts.size >= maxStatements) {
|
|
11
|
+
const first = stmts.keys().next().value;
|
|
12
|
+
if (first !== void 0) stmts.delete(first);
|
|
13
|
+
}
|
|
14
|
+
stmts.set(sql, s);
|
|
24
15
|
}
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
16
|
+
return s;
|
|
17
|
+
}
|
|
18
|
+
function runQuery(sql, values) {
|
|
19
|
+
const s = getStmt(sql);
|
|
20
|
+
const upper = sql.trim().toUpperCase();
|
|
21
|
+
const needsRows = upper.startsWith("SELECT") || upper.startsWith("WITH") || upper.startsWith("PRAGMA") || /\bRETURNING\b/.test(upper);
|
|
22
|
+
const bind = values;
|
|
23
|
+
if (needsRows) return s.all(...bind);
|
|
24
|
+
const r = s.run(...bind);
|
|
25
|
+
return { changes: r.changes };
|
|
26
|
+
}
|
|
27
|
+
return function query(raw, maybeValues) {
|
|
28
|
+
if (typeof raw === "string") {
|
|
29
|
+
return runQuery(raw, maybeValues ?? []);
|
|
37
30
|
}
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
return runQuery(raw, maybeValues ?? []);
|
|
42
|
-
}
|
|
43
|
-
// 格式 2 / 3:{ sql, values } 或 sql-template-strings 对象
|
|
44
|
-
const o = raw;
|
|
45
|
-
return runQuery(o.sql, o.values ?? []);
|
|
46
|
-
};
|
|
31
|
+
const o = raw;
|
|
32
|
+
return runQuery(o.sql, o.values ?? []);
|
|
33
|
+
};
|
|
47
34
|
}
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
db.exec("PRAGMA journal_mode = WAL");
|
|
56
|
-
db.exec("PRAGMA busy_timeout = 5000");
|
|
57
|
-
return db;
|
|
35
|
+
function openDatabase(filePath) {
|
|
36
|
+
mkdirSync(dirname(filePath), { recursive: true });
|
|
37
|
+
const db = new DatabaseSync(filePath);
|
|
38
|
+
db.exec("PRAGMA foreign_keys = ON");
|
|
39
|
+
db.exec("PRAGMA journal_mode = WAL");
|
|
40
|
+
db.exec("PRAGMA busy_timeout = 5000");
|
|
41
|
+
return db;
|
|
58
42
|
}
|
|
59
|
-
|
|
43
|
+
export {
|
|
44
|
+
createQuery,
|
|
45
|
+
openDatabase
|
|
46
|
+
};
|
|
47
|
+
//# sourceMappingURL=sqlite.js.map
|
package/dist/lib/sqlite.js.map
CHANGED
|
@@ -1 +1,7 @@
|
|
|
1
|
-
{
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/lib/sqlite.ts"],
|
|
4
|
+
"sourcesContent": ["import { mkdirSync } from \"node:fs\";\nimport { dirname } from \"node:path\";\nimport { DatabaseSync, StatementSync } from \"node:sqlite\";\nimport type { SQLStatement } from \"sql-template-strings\";\n\nexport type QueryFn = (\n sql: string | SQLStatement | { sql: string; values?: unknown[] },\n values?: unknown[]\n) => unknown[] | { changes: number | bigint };\n\n/**\n * \u7EDF\u4E00 SQL \u67E5\u8BE2\u63A5\u53E3 \u2014 \u652F\u6301\u4E09\u79CD\u8C03\u7528\u683C\u5F0F\uFF1A\n * 1. query(\"SELECT * FROM t WHERE id=?\", [1])\n * 2. query({ sql: \"SELECT * FROM t WHERE id=?\", values: [1] })\n * 3. query(SQL`SELECT * FROM t WHERE id=${1}`) \u2190 sql-template-strings\n */\nexport function createQuery(db: DatabaseSync, maxStatements: number = 200): QueryFn {\n const stmts = new Map<string, StatementSync>();\n\n function getStmt(sql: string): StatementSync {\n let s = stmts.get(sql);\n if (!s) {\n s = db.prepare(sql);\n if (stmts.size >= maxStatements) {\n const first = stmts.keys().next().value;\n if (first !== undefined) stmts.delete(first);\n }\n stmts.set(sql, s);\n }\n return s;\n }\n\n function runQuery(sql: string, values: unknown[]): any[] | { changes: number | bigint } {\n const s = getStmt(sql);\n const upper = sql.trim().toUpperCase();\n const needsRows =\n upper.startsWith(\"SELECT\") ||\n upper.startsWith(\"WITH\") ||\n upper.startsWith(\"PRAGMA\") ||\n /\\bRETURNING\\b/.test(upper);\n const bind = values as any[];\n if (needsRows) return s.all(...bind);\n const r = s.run(...bind);\n return { changes: r.changes };\n }\n\n return function query(raw: string | { sql: string; values?: unknown[] }, maybeValues?: unknown[]): any[] | { changes: number | bigint } {\n // \u683C\u5F0F 1\uFF1Astring + values\n if (typeof raw === \"string\") {\n return runQuery(raw, maybeValues ?? []);\n }\n // \u683C\u5F0F 2 / 3\uFF1A{ sql, values } \u6216 sql-template-strings \u5BF9\u8C61\n const o = raw as { sql: string; values?: unknown[] };\n return runQuery(o.sql, o.values ?? []);\n };\n}\n\n/**\n * \u6253\u5F00 SQLite \u6570\u636E\u5E93\uFF08\u540C\u6B65\u6A21\u5F0F\uFF09\uFF0C\u542F\u7528\u5916\u952E\u3001WAL\u3001busy_timeout\n */\nexport function openDatabase(filePath: string): DatabaseSync {\n mkdirSync(dirname(filePath), { recursive: true });\n const db = new DatabaseSync(filePath);\n db.exec(\"PRAGMA foreign_keys = ON\");\n db.exec(\"PRAGMA journal_mode = WAL\");\n db.exec(\"PRAGMA busy_timeout = 5000\");\n return db;\n}\n"],
|
|
5
|
+
"mappings": "AAAA,SAAS,iBAAiB;AAC1B,SAAS,eAAe;AACxB,SAAS,cAAc,qBAAqB;AAcrC,SAAS,YAAY,IAAkB,gBAAwB,KAAc;AAClF,QAAM,QAAQ,oBAAI,IAA2B;AAE7C,WAAS,QAAQ,KAA4B;AAC3C,QAAI,IAAI,MAAM,IAAI,GAAG;AACrB,QAAI,CAAC,GAAG;AACN,UAAI,GAAG,QAAQ,GAAG;AAClB,UAAI,MAAM,QAAQ,eAAe;AAC/B,cAAM,QAAQ,MAAM,KAAK,EAAE,KAAK,EAAE;AAClC,YAAI,UAAU,OAAW,OAAM,OAAO,KAAK;AAAA,MAC7C;AACA,YAAM,IAAI,KAAK,CAAC;AAAA,IAClB;AACA,WAAO;AAAA,E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aAAa,EAAE,CAAC,CAAC;IACjB,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,GAAG,SAAS,CAAC;IACzB,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,EAAE,MAAM,EAAE,CAAC;IACnB,WAAW,EAAE,MAAM,EAAE,CAAC;IACtB,QAAQ,EAAE;QAAE,QAAQ,EAAE,YAAY,EAAE,CAAC;QAAC,QAAQ,EAAE,YAAY,EAAE,CAAA;KAAE,CAAC;IACjE,KAAK,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;CAC5B;AAKD,0CAA0C;AAC1C,qBAAa,oBAAqB,SAAQ,KAAK;IAC1B,QAAQ,EAAE,MAAM;IAAS,eAAe,EAAE,OAAO;IAApE,YAAmB,QAAQ,EAAE,MAAM,EAAS,eAAe,EAAE,OAAO,EAEnE;CACF;AA8FD,MAAM,WAAW,eAAe;IAC9B,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,gBAAgB,CAAC,CAAC;IAC1C,WAAW,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAClC;AAED;;;GAGG;AACH,wBAAgB,cAAc,CAAC,WAAW,GAAE,MAA6B,GAAG,eAAe,CA8D1F;AAED;;;GAGG;AACH,wBAAgB,aAAa,CAC3B,MAAM,EAAE,eAAe,EACvB,UAAU,EAAE,WAAW,CAAC,MAAM,CAAC,GAC9B,MAAM,CAAC,MAAM,EAAE,gBAAgB,CAAC,CAMlC"}
|
package/dist/manifest-loader.js
CHANGED
|
@@ -1,212 +1,171 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* manifest-loader.ts — 读 v2 manifest,失败 = 启动失败
|
|
3
|
-
*
|
|
4
|
-
* v2 schema:
|
|
5
|
-
* {
|
|
6
|
-
* "schemaVersion": 2,
|
|
7
|
-
* "id": "feature-land",
|
|
8
|
-
* "name": "领地",
|
|
9
|
-
* "type": "feature",
|
|
10
|
-
* "configKey": "land",
|
|
11
|
-
* "requires": ["feature-economy"],
|
|
12
|
-
* "permissions": ["db:read:lands", "service:economy.account"],
|
|
13
|
-
* "services": {
|
|
14
|
-
* "provides": [{ "name": "lands.byOwner", "input": {...}, "output": {...} }],
|
|
15
|
-
* "requires": [{ "name": "economy.account" }]
|
|
16
|
-
* },
|
|
17
|
-
* "notes": "..."
|
|
18
|
-
* }
|
|
19
|
-
*
|
|
20
|
-
* 不要 routes / tables / migrations / seeds / handlers / events。
|
|
21
|
-
*
|
|
22
|
-
* 调用方:db-server/src/index.ts 启动时一次 loadManifestV2,
|
|
23
|
-
* throw 即 crash。
|
|
24
|
-
*/
|
|
25
1
|
import { existsSync, readdirSync, readFileSync } from "node:fs";
|
|
26
2
|
import { resolve } from "node:path";
|
|
27
3
|
import { defaultPackagesDir } from "./manifest.js";
|
|
28
4
|
import { validateManifestPermissions } from "./permission-gate.js";
|
|
29
|
-
const VALID_TYPES = new Set(["core", "feature"]);
|
|
5
|
+
const VALID_TYPES = /* @__PURE__ */ new Set(["core", "feature"]);
|
|
30
6
|
const IDENT = /^[A-Za-z0-9_-]+$/;
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
moduleId;
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
}
|
|
7
|
+
class ModuleV1SkippedError extends Error {
|
|
8
|
+
constructor(moduleId, declaredVersion) {
|
|
9
|
+
super(`moduleId=${moduleId} schemaVersion=${String(declaredVersion)} (\u9700\u8981 2),\u8DF3\u8FC7`);
|
|
10
|
+
this.moduleId = moduleId;
|
|
11
|
+
this.declaredVersion = declaredVersion;
|
|
12
|
+
}
|
|
13
|
+
moduleId;
|
|
14
|
+
declaredVersion;
|
|
40
15
|
}
|
|
41
16
|
function assertModuleObject(modId, obj) {
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
17
|
+
if (typeof obj.schemaVersion !== "number") {
|
|
18
|
+
throw new Error(`[manifest] ${modId}: schemaVersion \u7F3A\u5931`);
|
|
19
|
+
}
|
|
20
|
+
if (obj.schemaVersion !== 2) {
|
|
21
|
+
throw new Error(`[manifest] ${modId}: schemaVersion=${obj.schemaVersion} (\u9700\u8981 2)`);
|
|
22
|
+
}
|
|
23
|
+
if (typeof obj.id !== "string" || !IDENT.test(obj.id)) {
|
|
24
|
+
throw new Error(`[manifest] ${modId}: id \u7F3A\u5931\u6216\u975E\u6CD5 "${String(obj.id)}"`);
|
|
25
|
+
}
|
|
26
|
+
if (typeof obj.name !== "string" || obj.name.length === 0) {
|
|
27
|
+
throw new Error(`[manifest] ${modId}: name \u7F3A\u5931`);
|
|
28
|
+
}
|
|
29
|
+
if (typeof obj.type !== "string" || !VALID_TYPES.has(obj.type)) {
|
|
30
|
+
throw new Error(`[manifest] ${modId}: type \u5FC5\u987B\u662F core|feature ("${String(obj.type)}")`);
|
|
31
|
+
}
|
|
32
|
+
if (typeof obj.configKey !== "string" || obj.configKey.length === 0) {
|
|
33
|
+
throw new Error(`[manifest] ${modId}: configKey \u7F3A\u5931`);
|
|
34
|
+
}
|
|
35
|
+
if (Array.isArray(obj.routes)) {
|
|
36
|
+
throw new Error(`[manifest] ${modId}: \u4E0D\u518D\u652F\u6301 routes \u5B57\u6BB5,\u6539\u7528 db.defineTable + platform routes`);
|
|
37
|
+
}
|
|
38
|
+
if (Array.isArray(obj.migrations)) {
|
|
39
|
+
throw new Error(`[manifest] ${modId}: \u4E0D\u518D\u652F\u6301 migrations \u5B57\u6BB5,\u6539\u7528 db.defineTable \u81EA\u52A8\u5EFA\u8868`);
|
|
40
|
+
}
|
|
41
|
+
if (Array.isArray(obj.tables)) {
|
|
42
|
+
throw new Error(`[manifest] ${modId}: \u4E0D\u518D\u652F\u6301 tables \u5B57\u6BB5,\u6539\u7528 db.defineTable`);
|
|
43
|
+
}
|
|
44
|
+
if (Array.isArray(obj.events)) {
|
|
45
|
+
throw new Error(`[manifest] ${modId}: \u4E0D\u518D\u652F\u6301 events \u5B57\u6BB5,\u6539\u7528 platform event-bus`);
|
|
46
|
+
}
|
|
72
47
|
}
|
|
73
48
|
function parseServices(modId, raw) {
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
return { provides, requires };
|
|
49
|
+
if (raw === void 0) return { provides: [], requires: [] };
|
|
50
|
+
if (typeof raw !== "object" || raw === null) {
|
|
51
|
+
throw new Error(`[manifest] ${modId}: services \u5FC5\u987B\u662F\u5BF9\u8C61`);
|
|
52
|
+
}
|
|
53
|
+
const obj = raw;
|
|
54
|
+
const provides = parseServiceList(modId, "provides", obj.provides);
|
|
55
|
+
const requires = parseServiceList(modId, "requires", obj.requires);
|
|
56
|
+
for (const r of requires) {
|
|
57
|
+
if (provides.find((p) => p.name === r.name)) {
|
|
58
|
+
throw new Error(`[manifest] ${modId}: service "${r.name}" \u65E2 provides \u53C8 requires`);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
return { provides, requires };
|
|
88
62
|
}
|
|
89
63
|
function parseServiceList(modId, dir, raw) {
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
}
|
|
110
|
-
return out;
|
|
64
|
+
if (raw === void 0) return [];
|
|
65
|
+
if (!Array.isArray(raw)) throw new Error(`[manifest] ${modId}: services.${dir} \u5FC5\u987B\u662F\u6570\u7EC4`);
|
|
66
|
+
const out = [];
|
|
67
|
+
for (const item of raw) {
|
|
68
|
+
if (typeof item !== "object" || item === null) {
|
|
69
|
+
throw new Error(`[manifest] ${modId}: services.${dir} \u9879\u5FC5\u987B\u662F\u5BF9\u8C61`);
|
|
70
|
+
}
|
|
71
|
+
const e = item;
|
|
72
|
+
if (typeof e.name !== "string" || e.name.length === 0) {
|
|
73
|
+
throw new Error(`[manifest] ${modId}: services.${dir} \u9879\u7F3A\u5C11 name`);
|
|
74
|
+
}
|
|
75
|
+
const seen = /* @__PURE__ */ new Set();
|
|
76
|
+
if (seen.has(e.name)) {
|
|
77
|
+
throw new Error(`[manifest] ${modId}: services.${dir} name \u91CD\u590D "${e.name}"`);
|
|
78
|
+
}
|
|
79
|
+
seen.add(e.name);
|
|
80
|
+
out.push({ name: e.name, input: e.input, output: e.output });
|
|
81
|
+
}
|
|
82
|
+
return out;
|
|
111
83
|
}
|
|
112
84
|
function parseMod(modId, raw) {
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
85
|
+
if (raw.schemaVersion !== 2) {
|
|
86
|
+
throw new ModuleV1SkippedError(modId, raw.schemaVersion);
|
|
87
|
+
}
|
|
88
|
+
assertModuleObject(modId, raw);
|
|
89
|
+
const requires = Array.isArray(raw.requires) ? raw.requires.filter((x) => typeof x === "string") : [];
|
|
90
|
+
const permissions = Array.isArray(raw.permissions) ? raw.permissions.filter((x) => typeof x === "string") : [];
|
|
91
|
+
validateManifestPermissions(modId, permissions);
|
|
92
|
+
return {
|
|
93
|
+
schemaVersion: 2,
|
|
94
|
+
id: raw.id,
|
|
95
|
+
name: raw.name,
|
|
96
|
+
type: raw.type,
|
|
97
|
+
configKey: raw.configKey,
|
|
98
|
+
requires,
|
|
99
|
+
permissions,
|
|
100
|
+
services: parseServices(modId, raw.services),
|
|
101
|
+
notes: typeof raw.notes === "string" ? raw.notes : void 0
|
|
102
|
+
};
|
|
131
103
|
}
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
const
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
throw new Error(`[manifest] ${id}: ${p} 非合法 JSON: ${e.message}`);
|
|
104
|
+
function loadManifestV2(packagesDir = defaultPackagesDir()) {
|
|
105
|
+
if (!existsSync(packagesDir)) {
|
|
106
|
+
throw new Error(`[manifest] ${packagesDir} \u4E0D\u5B58\u5728;\u65E0\u6CD5\u542F\u52A8 v2 \u534F\u8BAE`);
|
|
107
|
+
}
|
|
108
|
+
const ids = readdirSync(packagesDir, { withFileTypes: true }).filter((e) => e.isDirectory()).map((e) => e.name);
|
|
109
|
+
const modules = {};
|
|
110
|
+
const providesMap = /* @__PURE__ */ new Map();
|
|
111
|
+
for (const id of ids) {
|
|
112
|
+
const p = resolve(packagesDir, id, "sapi", "manifest.json");
|
|
113
|
+
if (!existsSync(p)) continue;
|
|
114
|
+
let raw;
|
|
115
|
+
try {
|
|
116
|
+
raw = readFileSync(p, "utf8");
|
|
117
|
+
} catch (e) {
|
|
118
|
+
throw new Error(`[manifest] ${id}: \u8BFB ${p} \u5931\u8D25: ${e.message}`);
|
|
119
|
+
}
|
|
120
|
+
let parsed;
|
|
121
|
+
try {
|
|
122
|
+
parsed = JSON.parse(raw);
|
|
123
|
+
} catch (e) {
|
|
124
|
+
throw new Error(`[manifest] ${id}: ${p} \u975E\u5408\u6CD5 JSON: ${e.message}`);
|
|
125
|
+
}
|
|
126
|
+
try {
|
|
127
|
+
const m = parseMod(id, parsed);
|
|
128
|
+
modules[m.id] = m;
|
|
129
|
+
for (const s of m.services.provides) {
|
|
130
|
+
const prev = providesMap.get(s.name);
|
|
131
|
+
if (prev) {
|
|
132
|
+
throw new Error(`[manifest] service "${s.name}" \u5DF2\u88AB ${prev} provides,${m.id} \u62A2\u6CE8`);
|
|
162
133
|
}
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
if (!owner) {
|
|
188
|
-
throw new Error(`[manifest] ${m.id}.services.requires.${r.name} 没有模块 provides`);
|
|
189
|
-
}
|
|
190
|
-
}
|
|
191
|
-
// requires 模块依赖也要么 enabled 要么本身 installed (启动期不强求 enabled;运行时再查)
|
|
192
|
-
for (const dep of m.requires) {
|
|
193
|
-
if (!modules[dep]) {
|
|
194
|
-
throw new Error(`[manifest] ${m.id}.requires.${dep} 没找到对应模块`);
|
|
195
|
-
}
|
|
196
|
-
}
|
|
197
|
-
}
|
|
198
|
-
return { modules, providesMap };
|
|
134
|
+
providesMap.set(s.name, m.id);
|
|
135
|
+
}
|
|
136
|
+
} catch (e) {
|
|
137
|
+
if (e instanceof ModuleV1SkippedError) {
|
|
138
|
+
console.warn(`[manifest] ${id}: ${e.message}; v1 \u8DF3\u8FC7`);
|
|
139
|
+
continue;
|
|
140
|
+
}
|
|
141
|
+
throw e;
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
for (const m of Object.values(modules)) {
|
|
145
|
+
for (const r of m.services.requires) {
|
|
146
|
+
const owner = providesMap.get(r.name);
|
|
147
|
+
if (!owner) {
|
|
148
|
+
throw new Error(`[manifest] ${m.id}.services.requires.${r.name} \u6CA1\u6709\u6A21\u5757 provides`);
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
for (const dep of m.requires) {
|
|
152
|
+
if (!modules[dep]) {
|
|
153
|
+
throw new Error(`[manifest] ${m.id}.requires.${dep} \u6CA1\u627E\u5230\u5BF9\u5E94\u6A21\u5757`);
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
return { modules, providesMap };
|
|
199
158
|
}
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
for (const [id, m] of Object.entries(loaded.modules)) {
|
|
207
|
-
if (enabledIds.has(id))
|
|
208
|
-
out[id] = m;
|
|
209
|
-
}
|
|
210
|
-
return out;
|
|
159
|
+
function filterEnabled(loaded, enabledIds) {
|
|
160
|
+
const out = {};
|
|
161
|
+
for (const [id, m] of Object.entries(loaded.modules)) {
|
|
162
|
+
if (enabledIds.has(id)) out[id] = m;
|
|
163
|
+
}
|
|
164
|
+
return out;
|
|
211
165
|
}
|
|
212
|
-
|
|
166
|
+
export {
|
|
167
|
+
ModuleV1SkippedError,
|
|
168
|
+
filterEnabled,
|
|
169
|
+
loadManifestV2
|
|
170
|
+
};
|
|
171
|
+
//# sourceMappingURL=manifest-loader.js.map
|
|
@@ -1 +1,7 @@
|
|
|
1
|
-
{
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/manifest-loader.ts"],
|
|
4
|
+
"sourcesContent": ["/**\n * manifest-loader.ts \u2014 \u8BFB v2 manifest,\u5931\u8D25 = \u542F\u52A8\u5931\u8D25\n *\n * v2 schema:\n * {\n * \"schemaVersion\": 2,\n * \"id\": \"feature-land\",\n * \"name\": \"\u9886\u5730\",\n * \"type\": \"feature\",\n * \"configKey\": \"land\",\n * \"requires\": [\"feature-economy\"],\n * \"permissions\": [\"db:read:lands\", \"service:economy.account\"],\n * \"services\": {\n * \"provides\": [{ \"name\": \"lands.byOwner\", \"input\": {...}, \"output\": {...} }],\n * \"requires\": [{ \"name\": \"economy.account\" }]\n * },\n * \"notes\": \"...\"\n * }\n *\n * \u4E0D\u8981 routes / tables / migrations / seeds / handlers / events\u3002\n *\n * \u8C03\u7528\u65B9:db-server/src/index.ts \u542F\u52A8\u65F6\u4E00\u6B21 loadManifestV2,\n * throw \u5373 crash\u3002\n */\n\nimport { existsSync, readdirSync, readFileSync } from \"node:fs\";\nimport { resolve } from \"node:path\";\nimport { defaultPackagesDir } from \"./manifest.js\";\nimport { validateManifestPermissions } from \"./permission-gate.js\";\n\nexport interface ManifestServiceIO {\n type: \"object\" | \"array\" | \"string\" | \"number\" | \"boolean\" | \"null\";\n properties?: Record<string, unknown>;\n required?: string[];\n}\n\nexport interface ServiceEntry {\n name: string;\n input?: ManifestServiceIO | undefined;\n output?: ManifestServiceIO | undefined;\n}\n\nexport interface ModuleManifestV2 {\n schemaVersion: 2;\n id: string;\n name: string;\n type: \"core\" | \"feature\";\n configKey: string;\n requires: string[];\n permissions: string[];\n services: { provides: ServiceEntry[]; requires: ServiceEntry[] };\n notes?: string | undefined;\n}\n\nconst VALID_TYPES = new Set([\"core\", \"feature\"]);\nconst IDENT = /^[A-Za-z0-9_-]+$/;\n\n/** v1 / \u7F3A schemaVersion:\u8DF3\u8FC7(\u76F4\u5230\u6240\u6709\u6A21\u5757\u8FC1 v2) */\nexport class ModuleV1SkippedError extends Error {\n constructor(public moduleId: string, public declaredVersion: unknown) {\n super(`moduleId=${moduleId} schemaVersion=${String(declaredVersion)} (\u9700\u8981 2),\u8DF3\u8FC7`);\n }\n}\n\nfunction assertModuleObject(modId: string, obj: Record<string, unknown>): void {\n if (typeof obj.schemaVersion !== \"number\") {\n throw new Error(`[manifest] ${modId}: schemaVersion \u7F3A\u5931`);\n }\n if (obj.schemaVersion !== 2) {\n throw new Error(`[manifest] ${modId}: schemaVersion=${obj.schemaVersion} (\u9700\u8981 2)`);\n }\n if (typeof obj.id !== \"string\" || !IDENT.test(obj.id)) {\n throw new Error(`[manifest] ${modId}: id \u7F3A\u5931\u6216\u975E\u6CD5 \"${String(obj.id)}\"`);\n }\n if (typeof obj.name !== \"string\" || obj.name.length === 0) {\n throw new Error(`[manifest] ${modId}: name \u7F3A\u5931`);\n }\n if (typeof obj.type !== \"string\" || !VALID_TYPES.has(obj.type)) {\n throw new Error(`[manifest] ${modId}: type \u5FC5\u987B\u662F core|feature (\"${String(obj.type)}\")`);\n }\n if (typeof obj.configKey !== \"string\" || obj.configKey.length === 0) {\n throw new Error(`[manifest] ${modId}: configKey \u7F3A\u5931`);\n }\n if (Array.isArray(obj.routes)) {\n throw new Error(`[manifest] ${modId}: \u4E0D\u518D\u652F\u6301 routes \u5B57\u6BB5,\u6539\u7528 db.defineTable + platform routes`);\n }\n if (Array.isArray(obj.migrations)) {\n throw new Error(`[manifest] ${modId}: \u4E0D\u518D\u652F\u6301 migrations \u5B57\u6BB5,\u6539\u7528 db.defineTable \u81EA\u52A8\u5EFA\u8868`);\n }\n if (Array.isArray(obj.tables)) {\n throw new Error(`[manifest] ${modId}: \u4E0D\u518D\u652F\u6301 tables \u5B57\u6BB5,\u6539\u7528 db.defineTable`);\n }\n if (Array.isArray(obj.events)) {\n throw new Error(`[manifest] ${modId}: \u4E0D\u518D\u652F\u6301 events \u5B57\u6BB5,\u6539\u7528 platform event-bus`);\n }\n}\n\nfunction parseServices(modId: string, raw: unknown): { provides: ServiceEntry[]; requires: ServiceEntry[] } {\n if (raw === undefined) return { provides: [], requires: [] };\n if (typeof raw !== \"object\" || raw === null) {\n throw new Error(`[manifest] ${modId}: services \u5FC5\u987B\u662F\u5BF9\u8C61`);\n }\n const obj = raw as Record<string, unknown>;\n const provides = parseServiceList(modId, \"provides\", obj.provides);\n const requires = parseServiceList(modId, \"requires\", obj.requires);\n for (const r of requires) {\n if (provides.find((p) => p.name === r.name)) {\n throw new Error(`[manifest] ${modId}: service \"${r.name}\" \u65E2 provides \u53C8 requires`);\n }\n }\n return { provides, requires };\n}\n\nfunction parseServiceList(modId: string, dir: string, raw: unknown): ServiceEntry[] {\n if (raw === undefined) return [];\n if (!Array.isArray(raw)) throw new Error(`[manifest] ${modId}: services.${dir} \u5FC5\u987B\u662F\u6570\u7EC4`);\n const out: ServiceEntry[] = [];\n for (const item of raw) {\n if (typeof item !== \"object\" || item === null) {\n throw new Error(`[manifest] ${modId}: services.${dir} \u9879\u5FC5\u987B\u662F\u5BF9\u8C61`);\n }\n const e = item as Record<string, unknown>;\n if (typeof e.name !== \"string\" || e.name.length === 0) {\n throw new Error(`[manifest] ${modId}: services.${dir} \u9879\u7F3A\u5C11 name`);\n }\n const seen = new Set<string>();\n if (seen.has(e.name)) {\n throw new Error(`[manifest] ${modId}: services.${dir} name \u91CD\u590D \"${e.name}\"`);\n }\n seen.add(e.name);\n out.push({ name: e.name, input: e.input as ManifestServiceIO | undefined, output: e.output as ManifestServiceIO | undefined });\n }\n return out;\n}\n\nfunction parseMod(modId: string, raw: Record<string, unknown>): ModuleManifestV2 {\n if (raw.schemaVersion !== 2) {\n throw new ModuleV1SkippedError(modId, raw.schemaVersion);\n }\n assertModuleObject(modId, raw);\n const requires = Array.isArray(raw.requires) ? (raw.requires as unknown[]).filter((x) => typeof x === \"string\") as string[] : [];\n const permissions = Array.isArray(raw.permissions) ? (raw.permissions as unknown[]).filter((x) => typeof x === \"string\") as string[] : [];\n validateManifestPermissions(modId, permissions);\n return {\n schemaVersion: 2,\n id: raw.id as string,\n name: raw.name as string,\n type: raw.type as \"core\" | \"feature\",\n configKey: raw.configKey as string,\n requires,\n permissions,\n services: parseServices(modId, raw.services),\n notes: typeof raw.notes === \"string\" ? raw.notes : undefined,\n };\n}\n\nexport interface LoadedManifests {\n modules: Record<string, ModuleManifestV2>;\n providesMap: Map<string, string>; // service name \u2192 moduleId\n}\n\n/**\n * \u542F\u52A8\u671F\u8C03\u3002throw = \u542F\u52A8\u5931\u8D25\u3002\n * \u6CE8:\u4E0D\u8BFB v1 manifest\u3002\u53EA\u6709 schemaVersion=2 \u624D\u8D70\u3002\n */\nexport function loadManifestV2(packagesDir: string = defaultPackagesDir()): LoadedManifests {\n if (!existsSync(packagesDir)) {\n throw new Error(`[manifest] ${packagesDir} \u4E0D\u5B58\u5728;\u65E0\u6CD5\u542F\u52A8 v2 \u534F\u8BAE`);\n }\n const ids = readdirSync(packagesDir, { withFileTypes: true })\n .filter((e) => e.isDirectory())\n .map((e) => e.name);\n const modules: Record<string, ModuleManifestV2> = {};\n const providesMap = new Map<string, string>();\n\n for (const id of ids) {\n const p = resolve(packagesDir, id, \"sapi\", \"manifest.json\");\n if (!existsSync(p)) continue;\n let raw: string;\n try {\n raw = readFileSync(p, \"utf8\");\n } catch (e) {\n throw new Error(`[manifest] ${id}: \u8BFB ${p} \u5931\u8D25: ${(e as Error).message}`);\n }\n let parsed: Record<string, unknown>;\n try {\n parsed = JSON.parse(raw) as Record<string, unknown>;\n } catch (e) {\n throw new Error(`[manifest] ${id}: ${p} \u975E\u5408\u6CD5 JSON: ${(e as Error).message}`);\n }\n try {\n const m = parseMod(id, parsed);\n modules[m.id] = m;\n for (const s of m.services.provides) {\n const prev = providesMap.get(s.name);\n if (prev) {\n throw new Error(`[manifest] service \"${s.name}\" \u5DF2\u88AB ${prev} provides,${m.id} \u62A2\u6CE8`);\n }\n providesMap.set(s.name, m.id);\n }\n } catch (e) {\n if (e instanceof ModuleV1SkippedError) {\n // PoC \u517C\u5BB9:\u4E0D\u662F v2 \u7684\u6A21\u5757\u8DF3\u8FC7,\u7B49\u5230\u6240\u6709\u6A21\u5757\u8FC1 v2 \u540E\u6539\u4E3A throw\n console.warn(`[manifest] ${id}: ${e.message}; v1 \u8DF3\u8FC7`);\n continue;\n }\n throw e;\n }\n }\n\n // requires:\u6821\u9A8C\u76EE\u6807 service \u5728\u67D0\u4E2A provides \u91CC\n for (const m of Object.values(modules)) {\n for (const r of m.services.requires) {\n const owner = providesMap.get(r.name);\n if (!owner) {\n throw new Error(`[manifest] ${m.id}.services.requires.${r.name} \u6CA1\u6709\u6A21\u5757 provides`);\n }\n }\n // requires \u6A21\u5757\u4F9D\u8D56\u4E5F\u8981\u4E48 enabled \u8981\u4E48\u672C\u8EAB installed (\u542F\u52A8\u671F\u4E0D\u5F3A\u6C42 enabled;\u8FD0\u884C\u65F6\u518D\u67E5)\n for (const dep of m.requires) {\n if (!modules[dep]) {\n throw new Error(`[manifest] ${m.id}.requires.${dep} \u6CA1\u627E\u5230\u5BF9\u5E94\u6A21\u5757`);\n }\n }\n }\n\n return { modules, providesMap };\n}\n\n/**\n * \u7ED9\u5B9A moduleId \u96C6\u5408,\u8FC7\u6EE4\u51FA enabled (= lock \u6587\u4EF6 enabled \u7684) \u5B50\u96C6\u3002\n * map(moduleId \u2192 manifest) \u2014 \u6CA1\u88C5\u5219\u8DF3\u8FC7\u3002\n */\nexport function filterEnabled(\n loaded: LoadedManifests,\n enabledIds: ReadonlySet<string>\n): Record<string, ModuleManifestV2> {\n const out: Record<string, ModuleManifestV2> = {};\n for (const [id, m] of Object.entries(loaded.modules)) {\n if (enabledIds.has(id)) out[id] = m;\n }\n return out;\n}\n"],
|
|
5
|
+
"mappings": "AAyBA,SAAS,YAAY,aAAa,oBAAoB;AACtD,SAAS,eAAe;AACxB,SAAS,0BAA0B;AACnC,SAAS,mCAAmC;AA0B5C,MAAM,cAAc,oBAAI,IAAI,C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AI,CAAC,QAAQ,GAAG,GAAG;AACjB,cAAM,IAAI,MAAM,cAAc,EAAE,EAAE,aAAa,GAAG,6CAAU;AAAA,MAC9D;AAAA,IACF;AAAA,EACF;AAEA,SAAO,EAAE,SAAS,YAAY;AAChC;AAMO,SAAS,cACd,QACA,YACkC;AAClC,QAAM,MAAwC,CAAC;AAC/C,aAAW,CAAC,IAAI,CAAC,KAAK,OAAO,QAAQ,OAAO,OAAO,GAAG;AACpD,QAAI,WAAW,IAAI,EAAE,EAAG,KAAI,EAAE,IAAI;AAAA,EACpC;AACA,SAAO;AACT;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
package/dist/manifest.d.ts
CHANGED
|
@@ -4,8 +4,7 @@
|
|
|
4
4
|
* At db-server startup, scan `modules/packages/<id>/sapi/manifest.json` for
|
|
5
5
|
* every installed module and aggregate them into a single in-memory manifest.
|
|
6
6
|
* No pre-built `modules/_manifests/module-manifests.json` is required; the
|
|
7
|
-
* per-module files are the single source of truth
|
|
8
|
-
* runtime too).
|
|
7
|
+
* per-module files are the single source of truth.
|
|
9
8
|
*
|
|
10
9
|
* Behavior:
|
|
11
10
|
* - Missing file: skip that module (WARN).
|
|
@@ -44,12 +43,9 @@ export type PackagesDirResolver = () => string;
|
|
|
44
43
|
/** Resolve where db-server should look for `modules/packages/`.
|
|
45
44
|
*
|
|
46
45
|
* 优先级:
|
|
47
|
-
* 1. `process.env.SFMC_PACKAGES_DIR` —— sfmc
|
|
48
|
-
* (
|
|
46
|
+
* 1. `process.env.SFMC_PACKAGES_DIR` —— sfmc spawnService 启动 db 时注入
|
|
47
|
+
* (通常与 SFMC_ROOT 对齐)
|
|
49
48
|
* 2. `__dirname` 上溯两级到仓库根 —— 仅当 db-server 独立启动时兜底(CLI 调试)
|
|
50
|
-
*
|
|
51
|
-
* SEA 模式必须走 env 路径:SEA CJS bundle 里 `__dirname` 是虚拟路径,
|
|
52
|
-
* 不能用 `import.meta.url` 解析;靠 SFMC_PACKAGES_DIR 才是稳定的。
|
|
53
49
|
*/
|
|
54
50
|
export declare function defaultPackagesDir(): string;
|
|
55
51
|
/**
|
package/dist/manifest.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"manifest.d.ts","sourceRoot":"","sources":["../src/manifest.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"manifest.d.ts","sourceRoot":"","sources":["../src/manifest.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAMH,MAAM,WAAW,mBAAmB;IAClC,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,uBAAuB;IACtC,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,mBAAmB;IAClC,IAAI,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAC1B,IAAI,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAC1B,SAAS,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAC/B,QAAQ,CAAC,EAAE,MAAM,EAAE,GAAG,SAAS,CAAC;IAChC,QAAQ,CAAC,EAAE,MAAM,EAAE,GAAG,SAAS,CAAC;IAChC,MAAM,EAAE,mBAAmB,EAAE,CAAC;IAC9B,UAAU,EAAE,uBAAuB,EAAE,CAAC;IACtC,KAAK,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;CAC5B;AAED,MAAM,WAAW,cAAc;IAC7B,aAAa,EAAE,MAAM,CAAC;IACtB,WAAW,EAAE,MAAM,CAAC;IACpB,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,mBAAmB,CAAC,CAAC;CAC9C;AAKD,MAAM,MAAM,mBAAmB,GAAG,MAAM,MAAM,CAAC;AAE/C;;;;;;GAMG;AACH,wBAAgB,kBAAkB,IAAI,MAAM,CAE3C;AAED;;;;;GAKG;AACH,wBAAg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