asaihost-nodejs 0.0.1 → 0.0.3
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 +76 -25
- package/dist/InterventionLog-CRP6YJVM.cjs +30 -0
- package/dist/{InterventionLog-25EHE4QR.cjs.map → InterventionLog-CRP6YJVM.cjs.map} +1 -1
- package/dist/{InterventionLog-R6CCPU2B.es.js → InterventionLog-PZT2CCN3.es.js} +5 -5
- package/dist/LogStore-7MTUQA4G.cjs +54 -0
- package/dist/{LogStore-M2AUBNGO.cjs.map → LogStore-7MTUQA4G.cjs.map} +1 -1
- package/dist/{LogStore-ECXX34WC.es.js → LogStore-Q35YFNAY.es.js} +3 -3
- package/dist/asaihost-nodejs.cjs +1304 -1447
- package/dist/asaihost-nodejs.cjs.map +1 -1
- package/dist/asaihost-nodejs.d.cts +154 -17
- package/dist/asaihost-nodejs.d.ts +154 -17
- package/dist/asaihost-nodejs.es.js +921 -1064
- package/dist/asaihost-nodejs.es.js.map +1 -1
- package/dist/{chunk-HHPGUJ75.cjs → chunk-2BCIIKRG.cjs} +13 -6
- package/dist/chunk-2BCIIKRG.cjs.map +1 -0
- package/dist/{chunk-G4WVDUBH.cjs → chunk-4E7Z5K5U.cjs} +7 -7
- package/dist/{chunk-G4WVDUBH.cjs.map → chunk-4E7Z5K5U.cjs.map} +1 -1
- package/dist/{chunk-DROOHKB3.es.js → chunk-57UQJKSL.es.js} +2 -2
- package/dist/{chunk-EOGZPRML.es.js → chunk-A5CDJGJI.es.js} +224 -39
- package/dist/chunk-A5CDJGJI.es.js.map +1 -0
- package/dist/{chunk-E7V3EBDB.es.js → chunk-A6VJPLDD.es.js} +5 -3
- package/dist/chunk-A6VJPLDD.es.js.map +1 -0
- package/dist/{chunk-X7VHW2TD.cjs → chunk-H3K33HBA.cjs} +249 -64
- package/dist/chunk-H3K33HBA.cjs.map +1 -0
- package/dist/{chunk-KOFCBB3N.cjs → chunk-K2QPSQEV.cjs} +9 -9
- package/dist/{chunk-KOFCBB3N.cjs.map → chunk-K2QPSQEV.cjs.map} +1 -1
- package/dist/{chunk-LOMSUPPU.es.js → chunk-LTEP4XB2.es.js} +6 -6
- package/dist/{chunk-QWVR2HNT.cjs → chunk-LXJMGLKW.cjs} +21 -19
- package/dist/chunk-LXJMGLKW.cjs.map +1 -0
- package/dist/{chunk-4WJDC4M4.es.js → chunk-NLZNIGNF.es.js} +2 -2
- package/dist/chunk-NLZNIGNF.es.js.map +1 -0
- package/dist/{chunk-W7DVKGX5.cjs → chunk-OCEBEEP5.cjs} +2 -2
- package/dist/{chunk-W7DVKGX5.cjs.map → chunk-OCEBEEP5.cjs.map} +1 -1
- package/dist/{chunk-NLBFIRDB.cjs → chunk-RIRKIYET.cjs} +12 -12
- package/dist/{chunk-NLBFIRDB.cjs.map → chunk-RIRKIYET.cjs.map} +1 -1
- package/dist/{chunk-XBIN4C2V.es.js → chunk-SB23ESX2.es.js} +2 -2
- package/dist/{chunk-VLMM735Q.cjs → chunk-TKJAHTPO.cjs} +26 -26
- package/dist/{chunk-VLMM735Q.cjs.map → chunk-TKJAHTPO.cjs.map} +1 -1
- package/dist/{chunk-MCMADJQR.es.js → chunk-VUZO7DCA.es.js} +4 -4
- package/dist/chunk-VUZO7DCA.es.js.map +1 -0
- package/dist/{chunk-KUZQ36IJ.es.js → chunk-ZQBHJRAO.es.js} +10 -3
- package/dist/chunk-ZQBHJRAO.es.js.map +1 -0
- package/dist/intervention-hooks-KF3SNB5Q.cjs +21 -0
- package/dist/{intervention-hooks-LE6X4C6N.cjs.map → intervention-hooks-KF3SNB5Q.cjs.map} +1 -1
- package/dist/{intervention-hooks-FI4EHOL5.es.js → intervention-hooks-TCGIC4IV.es.js} +6 -6
- package/dist/log-formats-TUXGMCCU.cjs +31 -0
- package/dist/{log-formats-FKFMQKNO.cjs.map → log-formats-TUXGMCCU.cjs.map} +1 -1
- package/dist/{log-formats-I5E32H5F.es.js → log-formats-WW3TDUAK.es.js} +2 -2
- package/dist/{password-63OY27RX.es.js → password-4BABWAG4.es.js} +4 -4
- package/dist/password-PJHJRGPE.cjs +20 -0
- package/dist/{password-NZ5EGDWG.cjs.map → password-PJHJRGPE.cjs.map} +1 -1
- package/dist/user-store-6J2PSEIN.cjs +12 -0
- package/dist/{user-store-SX4N6PQ4.cjs.map → user-store-6J2PSEIN.cjs.map} +1 -1
- package/dist/user-store-UC5URX3C.es.js +12 -0
- package/package.json +2 -13
- package/dist/InterventionLog-25EHE4QR.cjs +0 -30
- package/dist/LogStore-M2AUBNGO.cjs +0 -54
- package/dist/chunk-4WJDC4M4.es.js.map +0 -1
- package/dist/chunk-E7V3EBDB.es.js.map +0 -1
- package/dist/chunk-EOGZPRML.es.js.map +0 -1
- package/dist/chunk-HHPGUJ75.cjs.map +0 -1
- package/dist/chunk-KUZQ36IJ.es.js.map +0 -1
- package/dist/chunk-MCMADJQR.es.js.map +0 -1
- package/dist/chunk-QWVR2HNT.cjs.map +0 -1
- package/dist/chunk-X7VHW2TD.cjs.map +0 -1
- package/dist/intervention-hooks-LE6X4C6N.cjs +0 -21
- package/dist/log-formats-FKFMQKNO.cjs +0 -31
- package/dist/password-NZ5EGDWG.cjs +0 -20
- package/dist/user-store-J7LWEXSW.es.js +0 -12
- package/dist/user-store-SX4N6PQ4.cjs +0 -12
- /package/dist/{InterventionLog-R6CCPU2B.es.js.map → InterventionLog-PZT2CCN3.es.js.map} +0 -0
- /package/dist/{LogStore-ECXX34WC.es.js.map → LogStore-Q35YFNAY.es.js.map} +0 -0
- /package/dist/{chunk-DROOHKB3.es.js.map → chunk-57UQJKSL.es.js.map} +0 -0
- /package/dist/{chunk-LOMSUPPU.es.js.map → chunk-LTEP4XB2.es.js.map} +0 -0
- /package/dist/{chunk-XBIN4C2V.es.js.map → chunk-SB23ESX2.es.js.map} +0 -0
- /package/dist/{intervention-hooks-FI4EHOL5.es.js.map → intervention-hooks-TCGIC4IV.es.js.map} +0 -0
- /package/dist/{log-formats-I5E32H5F.es.js.map → log-formats-WW3TDUAK.es.js.map} +0 -0
- /package/dist/{password-63OY27RX.es.js.map → password-4BABWAG4.es.js.map} +0 -0
- /package/dist/{user-store-J7LWEXSW.es.js.map → user-store-UC5URX3C.es.js.map} +0 -0
|
@@ -40,7 +40,135 @@ declare const _default$1: {
|
|
|
40
40
|
};
|
|
41
41
|
};
|
|
42
42
|
|
|
43
|
-
|
|
43
|
+
/** 字段名:数组或逗号分隔字符串 */
|
|
44
|
+
type Istrings = string[] | string;
|
|
45
|
+
/** 插入值:多行二维数组或原始 SQL 片段 */
|
|
46
|
+
type IValues = unknown[][] | string;
|
|
47
|
+
/** 更新赋值:[字段, 值] 或 [字段, 运算符, 值] */
|
|
48
|
+
type ISets = ([string, unknown] | [string, string, unknown] | string)[] | string;
|
|
49
|
+
/** WHERE 条件:逻辑符 or/and 与三元组 [字段, 运算符, 值] 混排 */
|
|
50
|
+
type IWheres = ([string, string, unknown] | string)[] | string;
|
|
51
|
+
/** ORDER BY:[字段, asc|desc] 数组 */
|
|
52
|
+
type IOrders = [string, 'asc' | 'desc' | 'ASC' | 'DESC'][] | string;
|
|
53
|
+
/** 统一 SQL 风格操作数据结构 */
|
|
54
|
+
interface Idb {
|
|
55
|
+
/** 操作类型:select | insert | update | delete | re(file 恢复) */
|
|
56
|
+
type: string;
|
|
57
|
+
/** 表名;file 类型为相对目录名 */
|
|
58
|
+
table: string;
|
|
59
|
+
/** 字段列表,如 ['id', 'name'] */
|
|
60
|
+
field?: Istrings;
|
|
61
|
+
/** 插入行数据,如 [['a', 1], ['b', 2]] */
|
|
62
|
+
value?: IValues;
|
|
63
|
+
/** 更新赋值,如 [['name', 'Tom']] */
|
|
64
|
+
set?: ISets;
|
|
65
|
+
/** 过滤条件,如 ['and', ['age', '>', 18]] */
|
|
66
|
+
where?: IWheres;
|
|
67
|
+
/** 排序,如 [['id', 'desc']] */
|
|
68
|
+
order?: IOrders;
|
|
69
|
+
/** 限制返回行数 */
|
|
70
|
+
limit?: number;
|
|
71
|
+
/** file:列表模式,返回 { open, delete } */
|
|
72
|
+
list?: number;
|
|
73
|
+
/** file:1 表示物理删除(软删除模式下) */
|
|
74
|
+
deltrue?: unknown;
|
|
75
|
+
/** file:子文件名(目录模式) */
|
|
76
|
+
filename?: string;
|
|
77
|
+
/** file:1=解析 JSON 单文件;2=目录 JSON 聚合查询 */
|
|
78
|
+
as?: number;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/** 统一对外接口(各驱动至少实现 sqlDb) */
|
|
82
|
+
interface DbInstance {
|
|
83
|
+
sqlDb(sql: Idb): Promise<unknown>;
|
|
84
|
+
}
|
|
85
|
+
/** 支持回调查询的驱动接口 */
|
|
86
|
+
interface QueryableDb extends DbInstance {
|
|
87
|
+
query(sql: Idb, callback: (err: string | null, result: unknown) => void): void;
|
|
88
|
+
}
|
|
89
|
+
/** 将 query 回调风格封装为 Promise,并统一空结果处理 */
|
|
90
|
+
declare function promisifySqlDb(query: QueryableDb['query'], sql: Idb): Promise<unknown>;
|
|
91
|
+
/** 将 Idb.field 规范为字符串数组 */
|
|
92
|
+
declare function toFieldArray(field: Idb['field']): string[];
|
|
93
|
+
/** 将 Idb.where 规范为 Excel 等值条件 [字段, 值][] */
|
|
94
|
+
declare function toWherePairs(where: Idb['where']): [string, unknown][];
|
|
95
|
+
/** 将 Idb.set 规范为键值对象 */
|
|
96
|
+
declare function toSetObject(set: Idb['set']): Record<string, unknown>;
|
|
97
|
+
/** 将 Idb.value 与 field 组合为插入行对象数组 */
|
|
98
|
+
declare function toInsertRows(sql: Idb): Record<string, unknown>[];
|
|
99
|
+
/**
|
|
100
|
+
* 判断目标路径是否在基准目录内(跨平台:Win/Linux/macOS)
|
|
101
|
+
* 使用 path.resolve + path.relative,兼容正反斜杠与不同盘符
|
|
102
|
+
*/
|
|
103
|
+
declare function isPathInside(baseDir: string, targetPath: string): boolean;
|
|
104
|
+
/**
|
|
105
|
+
* 拼接 table 相对路径(始终使用 /,与 API 路由约定一致)
|
|
106
|
+
* path.resolve 在 Win/Linux/macOS 上均支持正斜杠
|
|
107
|
+
*/
|
|
108
|
+
declare function joinTablePath(table: string, ...segments: string[]): string;
|
|
109
|
+
/** 判断 field 定义中是否已包含 id 列(兼容字符串 includes 语义) */
|
|
110
|
+
declare function fieldHasId(field: Idb['field']): boolean;
|
|
111
|
+
/** 判断错误是否为「表不存在」类错误 */
|
|
112
|
+
declare function isTableMissingError(err: {
|
|
113
|
+
code?: string;
|
|
114
|
+
message?: string;
|
|
115
|
+
} | null | undefined): boolean;
|
|
116
|
+
|
|
117
|
+
type DbCommon_DbInstance = DbInstance;
|
|
118
|
+
type DbCommon_QueryableDb = QueryableDb;
|
|
119
|
+
declare const DbCommon_fieldHasId: typeof fieldHasId;
|
|
120
|
+
declare const DbCommon_isPathInside: typeof isPathInside;
|
|
121
|
+
declare const DbCommon_isTableMissingError: typeof isTableMissingError;
|
|
122
|
+
declare const DbCommon_joinTablePath: typeof joinTablePath;
|
|
123
|
+
declare const DbCommon_promisifySqlDb: typeof promisifySqlDb;
|
|
124
|
+
declare const DbCommon_toFieldArray: typeof toFieldArray;
|
|
125
|
+
declare const DbCommon_toInsertRows: typeof toInsertRows;
|
|
126
|
+
declare const DbCommon_toSetObject: typeof toSetObject;
|
|
127
|
+
declare const DbCommon_toWherePairs: typeof toWherePairs;
|
|
128
|
+
declare namespace DbCommon {
|
|
129
|
+
export { type DbCommon_DbInstance as DbInstance, type DbCommon_QueryableDb as QueryableDb, DbCommon_fieldHasId as fieldHasId, DbCommon_isPathInside as isPathInside, DbCommon_isTableMissingError as isTableMissingError, DbCommon_joinTablePath as joinTablePath, DbCommon_promisifySqlDb as promisifySqlDb, DbCommon_toFieldArray as toFieldArray, DbCommon_toInsertRows as toInsertRows, DbCommon_toSetObject as toSetObject, DbCommon_toWherePairs as toWherePairs };
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
type JoinType = 'where' | 'order' | 'value' | 'set' | 'field';
|
|
133
|
+
declare const _default: {
|
|
134
|
+
/**
|
|
135
|
+
* 将 Idb 中的指定片段转为 SQL 字符串片段
|
|
136
|
+
*/
|
|
137
|
+
joinSql(sql: Idb, type: JoinType): string;
|
|
138
|
+
/**
|
|
139
|
+
* 将完整 Idb 对象转换为可执行 SQL 字符串
|
|
140
|
+
* 注意:值为字符串拼接,调用方需确保输入可信或自行转义
|
|
141
|
+
*/
|
|
142
|
+
makeSql(sql: Idb): string;
|
|
143
|
+
/**
|
|
144
|
+
* 生成建表 SQL(自动补 id 主键与 asdate 时间戳列)
|
|
145
|
+
*/
|
|
146
|
+
createSql(sql: Idb, dialect?: "mysql" | "sqlite" | string): string;
|
|
147
|
+
};
|
|
148
|
+
|
|
149
|
+
/** 传给各 db 驱动插件的共享依赖(sqlite/mysql 插件 factory 入参) */
|
|
150
|
+
interface DbDriverContext {
|
|
151
|
+
IdbType: Idb;
|
|
152
|
+
Sql: typeof _default;
|
|
153
|
+
DbCommon: typeof DbCommon;
|
|
154
|
+
}
|
|
155
|
+
type DbDriverCtor = new (config: any) => DbInstance;
|
|
156
|
+
type DbDriverFactory = (ctx: DbDriverContext) => DbDriverCtor;
|
|
157
|
+
type DbDriversMap = Partial<Record<string, DbDriverFactory>>;
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* 统一数据存储注册表 — file / sqlite / mysql 自由切换,全库数据读写经此入口
|
|
161
|
+
*/
|
|
162
|
+
|
|
163
|
+
type StoreDomain = 'user' | 'log' | (string & {});
|
|
164
|
+
|
|
165
|
+
interface SysserverBootOptions {
|
|
166
|
+
/** 外部 db 驱动插件,键名与 dataStores.type 一致(sqlite / mysql …) */
|
|
167
|
+
db?: DbDriversMap;
|
|
168
|
+
[key: string]: unknown;
|
|
169
|
+
}
|
|
170
|
+
type SysserverFn = ($asai: unknown, opt?: SysserverBootOptions) => void;
|
|
171
|
+
declare function sysserver($asai: any, opt?: SysserverBootOptions): void;
|
|
44
172
|
|
|
45
173
|
/** 启动前归一化 host 配置 */
|
|
46
174
|
declare function normalizeHostConfig(cfg: Record<string, any>): Record<string, any>;
|
|
@@ -300,7 +428,7 @@ interface LoggerConfig {
|
|
|
300
428
|
}
|
|
301
429
|
type WorkHandler = (req: unknown, res: unknown, hostdir: string) => void;
|
|
302
430
|
type WsWorkHandler = (msg: unknown, ws: unknown, hostdir: string, req: unknown) => void;
|
|
303
|
-
interface
|
|
431
|
+
interface AsaiHostNodejsOptions {
|
|
304
432
|
sysWork: WorkHandler;
|
|
305
433
|
apiWork: WorkHandler;
|
|
306
434
|
wsWork: WsWorkHandler;
|
|
@@ -341,20 +469,35 @@ interface AsaiRuntime {
|
|
|
341
469
|
}
|
|
342
470
|
/** npm 包标识(与 package.json name 一致) */
|
|
343
471
|
declare const PLUGIN_NAME: "asaihost-nodejs";
|
|
472
|
+
|
|
344
473
|
/** `fn($asai, opt)` 返回值:启动函数 + ws 模块引用 */
|
|
345
474
|
interface HostBootResult {
|
|
346
|
-
|
|
475
|
+
StartAsaiHostNodejs: () => void;
|
|
347
476
|
asaiWs: typeof ws;
|
|
348
477
|
}
|
|
349
|
-
/**
|
|
350
|
-
interface
|
|
478
|
+
/** wsMock($asai) 返回值 — 供 asaimock 挂载与 WS 开发回包 */
|
|
479
|
+
interface WsMockToolkit {
|
|
480
|
+
getKeyByData: (reqdata: unknown, hostdir?: string) => string;
|
|
481
|
+
wsWorkApi: (workopt: unknown) => void;
|
|
482
|
+
wsWorkMock: (workopt: unknown) => void;
|
|
483
|
+
wsWorkListen: (workopt: unknown, reqkey: unknown) => void;
|
|
484
|
+
getMockDb: (workopt: unknown) => Record<string, unknown>;
|
|
485
|
+
}
|
|
486
|
+
/** AsaiUtils 命名空间(见 src/utils/index.ts) */
|
|
487
|
+
interface AsaiUtilsModule {
|
|
488
|
+
deUserInfoWithAsai: (userinfo: string[] | null | undefined, $asai: AsaiRuntime) => string[] | null;
|
|
489
|
+
wsMock: ($asai: AsaiRuntime) => WsMockToolkit;
|
|
490
|
+
}
|
|
491
|
+
/** 宿主插件核心 API(其余 host-api 方法通过交叉类型扩展) */
|
|
492
|
+
interface AsaiNodejsHostPluginBase {
|
|
351
493
|
readonly name: typeof PLUGIN_NAME;
|
|
352
|
-
fn: (runtime: AsaiRuntime, options:
|
|
353
|
-
sysserver: (runtime: AsaiRuntime) => void;
|
|
494
|
+
fn: (runtime: AsaiRuntime, options: AsaiHostNodejsOptions) => HostBootResult;
|
|
495
|
+
sysserver: (runtime: AsaiRuntime, opt?: SysserverBootOptions) => void;
|
|
354
496
|
AsaiCommon: Record<string, unknown>;
|
|
355
|
-
AsaiUtils:
|
|
356
|
-
[key: string]: unknown;
|
|
497
|
+
AsaiUtils: AsaiUtilsModule;
|
|
357
498
|
}
|
|
499
|
+
/** 宿主插件对外 API 形状(含 normalizeHostConfig 等扩展方法) */
|
|
500
|
+
type AsaiNodejsHostPlugin = AsaiNodejsHostPluginBase & Record<string, unknown>;
|
|
358
501
|
|
|
359
502
|
declare function secureCompare(a: unknown, b: unknown): boolean;
|
|
360
503
|
|
|
@@ -392,15 +535,9 @@ interface AuthCheckResult {
|
|
|
392
535
|
/** 校验 Userinfo 头(us##lv##tk),仅在 requireAuth=1 时由路由层调用 */
|
|
393
536
|
declare function validateHttpAuth(req: any, $asai: any, pathname: string): AuthCheckResult;
|
|
394
537
|
|
|
395
|
-
|
|
396
|
-
* 统一数据存储注册表 — file / sqlite / mysql 自由切换,全库数据读写经此入口
|
|
397
|
-
*/
|
|
398
|
-
|
|
399
|
-
type StoreDomain = 'user' | 'log' | (string & {});
|
|
400
|
-
|
|
401
|
-
declare const initAsaiHost: AsaiNodejsHostPlugin;
|
|
538
|
+
declare const initAsaiHostNodejs: AsaiNodejsHostPlugin;
|
|
402
539
|
|
|
403
540
|
/** 构建时注入的版本号(与 package.json version 同步) */
|
|
404
541
|
declare const PLUGIN_VERSION: string;
|
|
405
542
|
|
|
406
|
-
export { _default$1 as AsaiCommon, type
|
|
543
|
+
export { _default$1 as AsaiCommon, type AsaiHostNodejsOptions, type AsaiNodejsHostPlugin, type AsaiNodejsHostPluginBase, type AsaiRuntime, type AsaiSecrets, index as AsaiUtils, type AuthCheckResult, type HostBootResult, type HostConfig, type HostSiteConfig, type LoggerConfig, PLUGIN_NAME, PLUGIN_VERSION, type ProxySiteConfig, type ReconnectOptions, type RouteFactory, type SecurityAuditEvent, type SecurityConfig, type SecurityEventType, type StoreDomain, type SysserverBootOptions, type SysserverFn, type TransportKind, type WorkHandler, type WsWorkHandler, applySecretsToHostConfig, createTransportDataHandler, initAsaiHostNodejs as default, ensureDefaultConnection, getDefaultConnId, getHostAllowedRoots, getTransportBlock, getTransportDefault, hasTransportDefault, initAsaiHostNodejs, initHostserverApi, initHostserverWs, initTransportBridge, isDevDefaultPassword, loadAsaiSecrets, loadDotEnvFile, logSecurityEvent, normalizeHostConfig, normalizeSecurityConfig, registerApi, registerWs, resolveHttpsCertFromPaths, resolvePathUnderRoots, resolveReconnectOptions, sanitizeString, secureCompare, shouldAutoConnect, stripForbiddenSecretsFromHostConfig, syncApiRouteKeys, syncWsRouteKeys, sysserver, validateAsaiSecrets, validateHostConfig, validateHttpAuth, validateProductionSecurity, wireTransportConnectionLogs };
|