@zwa73/utils 1.0.146 → 1.0.148
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/ServiceManager.d.ts +0 -0
- package/dist/ServiceManager.js +1 -0
- package/dist/UtilFfmpegTools.js +1 -1
- package/dist/UtilFunctions.d.ts +11 -1
- package/dist/UtilFunctions.js +21 -3
- package/package.json +3 -3
- package/scripts/postinstall.js +5 -5
- package/src/ServiceManager.ts +0 -0
- package/src/UtilFfmpegTools.ts +1 -1
- package/src/UtilFunctions.ts +39 -7
- package/dist/ServiceAdapter.d.ts +0 -47
- package/dist/ServiceAdapter.js +0 -35
- package/src/ServiceAdapter.ts +0 -73
|
File without changes
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";
|
package/dist/UtilFfmpegTools.js
CHANGED
|
@@ -37,7 +37,7 @@ const UtilClass_1 = require("./UtilClass");
|
|
|
37
37
|
class SFfmpegTool {
|
|
38
38
|
/**静态构造函数 */
|
|
39
39
|
static init() {
|
|
40
|
-
const ffmpegPath = process
|
|
40
|
+
const ffmpegPath = process?.env?.FFMPEG_PATH;
|
|
41
41
|
if (ffmpegPath != null) {
|
|
42
42
|
const exepath = pathe_1.default.join(ffmpegPath, "ffmpeg.exe");
|
|
43
43
|
SFfmpegTool.setFfmpegPath(exepath);
|
package/dist/UtilFunctions.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { AnyFunc, ComposedClass, ComposedMixinable, ComposedRefMixinable, ExtractOutcome, IJData, JObject, JToken, Keyable, Literal, Matchable, MatchableFlag, Mixinable, Outcome, ReqVerifyFn, ProperSubsetCheck, RefMixinable, UnionToIntersection, Await, AnyRecord } from "./UtilInterfaces";
|
|
1
|
+
import { PRecord, AnyFunc, ComposedClass, ComposedMixinable, ComposedRefMixinable, ExtractOutcome, IJData, JObject, JToken, Keyable, Literal, Matchable, MatchableFlag, Mixinable, Outcome, ReqVerifyFn, ProperSubsetCheck, RefMixinable, UnionToIntersection, Await, AnyRecord } from "./UtilInterfaces";
|
|
2
2
|
import { LogLevel } from "./UtilLogger";
|
|
3
3
|
import { Failed, FailedLike, None, StatusSymbol, Success, SuccessLike, Timeout } from "./UtilSymbol";
|
|
4
4
|
declare const HashMethodList: readonly ["md5", "sha1", "sha256", "sha512", "sha3", "blake2", "blake3"];
|
|
@@ -165,6 +165,16 @@ export declare class UtilFunc {
|
|
|
165
165
|
}>>(t: T, procObj: P): P extends Record<any, AnyFunc> ? {
|
|
166
166
|
[K in keyof P]: ReturnType<P[K]>;
|
|
167
167
|
}[keyof P] : never;
|
|
168
|
+
/**处理部分联合值
|
|
169
|
+
* @param t - 目标值
|
|
170
|
+
* @param procObj - 所有可能的id组成的处理函数映射 (status, result)=>any
|
|
171
|
+
* @returns 任意处理函数的返回值
|
|
172
|
+
*/
|
|
173
|
+
static matchPartialProc<T extends Matchable<Keyable>, P extends Partial<{
|
|
174
|
+
[K in MatchableFlag<T>]: (k: K, v: ExtractOutcome<T, MatchableFlag<K>>['result']) => unknown;
|
|
175
|
+
}>>(t: T, procObj: P): (P extends PRecord<Keyable, AnyFunc> ? {
|
|
176
|
+
[K in keyof P]: P[K] extends AnyFunc ? ReturnType<P[K]> : undefined;
|
|
177
|
+
}[keyof P] : never) | undefined;
|
|
168
178
|
/**根据典型的成功或失败状态运行函数
|
|
169
179
|
* @param t - 目标值
|
|
170
180
|
* @param sucessFunc - 成功则运行的函数 (result)=>any
|
package/dist/UtilFunctions.js
CHANGED
|
@@ -392,19 +392,20 @@ class UtilFunc {
|
|
|
392
392
|
space = space === null ? undefined : space;
|
|
393
393
|
if (!compress)
|
|
394
394
|
return JSON.stringify(token, null, space);
|
|
395
|
+
const ec = '\uF121\uF122\uF123';
|
|
395
396
|
const compressReplacer = (key, value) => {
|
|
396
397
|
if (Array.isArray(value) && value.every(item => typeof item === 'number' || typeof item === 'string' ||
|
|
397
398
|
typeof item === 'boolean' || item == null))
|
|
398
|
-
return
|
|
399
|
+
return `${ec}${JSON.stringify(value)}${ec}`;
|
|
399
400
|
const str = JSON.stringify(value);
|
|
400
401
|
if (typeof str != 'string')
|
|
401
402
|
return value;
|
|
402
403
|
if (str.length <= 100)
|
|
403
|
-
return
|
|
404
|
+
return `${ec}${str}${ec}`;
|
|
404
405
|
return value;
|
|
405
406
|
};
|
|
406
407
|
return JSON.stringify(token, compressReplacer, space)
|
|
407
|
-
.replace(
|
|
408
|
+
.replace(new RegExp(`"${ec}(.*?)${ec}"`, 'g'), (match, p1) => p1.replace(/\\([\\"])/g, '$1'));
|
|
408
409
|
}
|
|
409
410
|
/**代办表 用于队列处理等待 */
|
|
410
411
|
static pendingMap = {};
|
|
@@ -486,6 +487,23 @@ class UtilFunc {
|
|
|
486
487
|
return procObj[t.status](t.status, t.result);
|
|
487
488
|
UtilFunc.throwError(`matchProc 传入了一个预料之外的值: ${String(t)}`, 'fatal');
|
|
488
489
|
}
|
|
490
|
+
/**处理部分联合值
|
|
491
|
+
* @param t - 目标值
|
|
492
|
+
* @param procObj - 所有可能的id组成的处理函数映射 (status, result)=>any
|
|
493
|
+
* @returns 任意处理函数的返回值
|
|
494
|
+
*/
|
|
495
|
+
static matchPartialProc(t, procObj) {
|
|
496
|
+
if (typeof t === 'string' || typeof t === 'number' || typeof t === 'symbol') {
|
|
497
|
+
if (procObj[t])
|
|
498
|
+
return procObj[t](t);
|
|
499
|
+
else
|
|
500
|
+
return undefined;
|
|
501
|
+
}
|
|
502
|
+
else if (procObj[t.status])
|
|
503
|
+
return procObj[t.status](t.status, t.result);
|
|
504
|
+
UtilLogger_1.SLogger.warn(`matchPartialProc 传入了一个预料之外的值, 已返回undefined: ${String(t)}`);
|
|
505
|
+
return undefined;
|
|
506
|
+
}
|
|
489
507
|
/**根据典型的成功或失败状态运行函数
|
|
490
508
|
* @param t - 目标值
|
|
491
509
|
* @param sucessFunc - 成功则运行的函数 (result)=>any
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zwa73/utils",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.148",
|
|
4
4
|
"description": "my utils",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -17,6 +17,7 @@
|
|
|
17
17
|
"author": "zwa73",
|
|
18
18
|
"license": "ISC",
|
|
19
19
|
"dependencies": {
|
|
20
|
+
"@deepkit/type": "^1.0.1-alpha.153",
|
|
20
21
|
"fluent-ffmpeg": "2.1.2",
|
|
21
22
|
"glob": "^10.4.1",
|
|
22
23
|
"html-entities": "^2.3.3",
|
|
@@ -32,11 +33,10 @@
|
|
|
32
33
|
"devDependencies": {
|
|
33
34
|
"@types/fluent-ffmpeg": "^2.1.21",
|
|
34
35
|
"@types/jest": "^29.5.12",
|
|
35
|
-
"@types/node": "^
|
|
36
|
+
"@types/node": "^20.14.11",
|
|
36
37
|
"@zwa73/dev-utils": "^1.0.58",
|
|
37
38
|
"jest": "^29.7.0",
|
|
38
39
|
"ts-jest": "^29.1.2",
|
|
39
|
-
"ts-morph": "^23.0.0",
|
|
40
40
|
"tsc-alias": "^1.8.8",
|
|
41
41
|
"typescript": "^5.3.3"
|
|
42
42
|
}
|
package/scripts/postinstall.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
const path = require('path');
|
|
2
|
-
const { UtilFT
|
|
2
|
+
const { UtilFT } = require("../index");
|
|
3
3
|
const readline = require('readline');
|
|
4
4
|
|
|
5
5
|
const PACKAGE_PATH = path.join(__dirname,'..','package.json');
|
|
@@ -17,6 +17,7 @@ const INFO_TABLE = {
|
|
|
17
17
|
"1.0.128":"fileSearch 添加Sync版本, 默认改为异步函数",
|
|
18
18
|
"1.0.131":"repeatPromise 与 repeatPost 改为传入可选参数表模式",
|
|
19
19
|
}
|
|
20
|
+
const PKG_NAME = "utils";
|
|
20
21
|
|
|
21
22
|
// 将版本号转换为可以比较的数字
|
|
22
23
|
function versionToNumber(version) {
|
|
@@ -44,19 +45,18 @@ function showUpgradeMessages(prevVersion, currentVersion) {
|
|
|
44
45
|
}
|
|
45
46
|
|
|
46
47
|
|
|
47
|
-
|
|
48
48
|
async function main(){
|
|
49
49
|
const packageTable = await UtilFT.loadJSONFile(PACKAGE_PATH);
|
|
50
50
|
const currentVersion = packageTable.version;
|
|
51
51
|
await UtilFT.ensurePathExists(VERSION_PATH);
|
|
52
|
-
const versionTable = await UtilFT.loadJSONFile(VERSION_PATH,{})
|
|
53
|
-
const prevVersion = versionTable.
|
|
52
|
+
const versionTable = await UtilFT.loadJSONFile(VERSION_PATH,{default:{}});
|
|
53
|
+
const prevVersion = versionTable[PKG_NAME]?.version ?? "0.0.0";
|
|
54
54
|
|
|
55
55
|
console.log(`${currentVersion} 版本已安装`);
|
|
56
56
|
// 使用这个函数来显示升级信息
|
|
57
57
|
const hasOut = showUpgradeMessages(prevVersion, currentVersion);
|
|
58
58
|
|
|
59
|
-
const ntable = Object.assign({},versionTable,{
|
|
59
|
+
const ntable = Object.assign({},versionTable,{[PKG_NAME]:{version:currentVersion}});
|
|
60
60
|
await UtilFT.writeJSONFile(VERSION_PATH, ntable);
|
|
61
61
|
|
|
62
62
|
if(!hasOut) return;
|
|
File without changes
|
package/src/UtilFfmpegTools.ts
CHANGED
|
@@ -15,7 +15,7 @@ export type IOMap = { [key: string]: string };
|
|
|
15
15
|
class SFfmpegTool {
|
|
16
16
|
/**静态构造函数 */
|
|
17
17
|
static init() {
|
|
18
|
-
const ffmpegPath = process
|
|
18
|
+
const ffmpegPath = process?.env?.FFMPEG_PATH;
|
|
19
19
|
if(ffmpegPath!=null){
|
|
20
20
|
const exepath = path.join(ffmpegPath,"ffmpeg.exe");
|
|
21
21
|
SFfmpegTool.setFfmpegPath(exepath);
|
package/src/UtilFunctions.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as crypto from "crypto";
|
|
2
|
-
import { AnyFunc, ComposedClass, ComposedMixinable, ComposedRefMixinable, ExtractOutcome, IJData, JObject, JToken, Keyable, Literal, Matchable, MatchableFlag, Mixinable, Outcome, ReqStat, ReqVerifyFn, ProperSubsetCheck, RefMixinable, UnionToIntersection, Await, AnyRecord } from "@src/UtilInterfaces";
|
|
2
|
+
import { PRecord, AnyFunc, ComposedClass, ComposedMixinable, ComposedRefMixinable, ExtractOutcome, IJData, JObject, JToken, Keyable, Literal, Matchable, MatchableFlag, Mixinable, Outcome, ReqStat, ReqVerifyFn, ProperSubsetCheck, RefMixinable, UnionToIntersection, Await, AnyRecord } from "@src/UtilInterfaces";
|
|
3
3
|
import * as cp from "child_process";
|
|
4
4
|
import { LogLevel, SLogger } from "@src/UtilLogger";
|
|
5
5
|
import { Completed, Failed, FailedLike, None, StatusSymbol, Success, SuccessLike, Terminated, Timeout } from "./UtilSymbol";
|
|
@@ -459,19 +459,21 @@ static stringifyJToken(token:JToken|IJData,opt?:StringifyOpt){
|
|
|
459
459
|
|
|
460
460
|
if(!compress) return JSON.stringify(token,null,space);
|
|
461
461
|
|
|
462
|
+
const ec = '\uF121\uF122\uF123';
|
|
463
|
+
|
|
462
464
|
const compressReplacer = (key: string, value: any)=> {
|
|
463
465
|
if (Array.isArray(value) && value.every(item =>
|
|
464
466
|
typeof item === 'number' || typeof item === 'string' ||
|
|
465
467
|
typeof item === 'boolean' || item == null))
|
|
466
|
-
return
|
|
468
|
+
return `${ec}${JSON.stringify(value)}${ec}`;
|
|
467
469
|
const str = JSON.stringify(value);
|
|
468
470
|
if(typeof str!='string') return value;
|
|
469
|
-
if(str.length<=100) return
|
|
471
|
+
if(str.length<=100) return `${ec}${str}${ec}`;
|
|
470
472
|
return value;
|
|
471
473
|
}
|
|
472
474
|
|
|
473
475
|
return JSON.stringify(token,compressReplacer,space)
|
|
474
|
-
.replace(
|
|
476
|
+
.replace(new RegExp(`"${ec}(.*?)${ec}"`,'g'), (match, p1) =>
|
|
475
477
|
p1.replace(/\\([\\"])/g, '$1'));
|
|
476
478
|
}
|
|
477
479
|
|
|
@@ -553,9 +555,10 @@ static outcome<K extends Keyable,V> (key:K,value:V):Outcome<K,V>{
|
|
|
553
555
|
*/
|
|
554
556
|
static matchProc<
|
|
555
557
|
T extends Matchable<Keyable>,
|
|
556
|
-
P extends UnionToIntersection<
|
|
557
|
-
|
|
558
|
-
(k:K,v:ExtractOutcome<T,MatchableFlag<K>>['result'])=>unknown
|
|
558
|
+
P extends UnionToIntersection<{//旧版本可能会将此映射处理为联合类型 所以需要UnionToIntersection
|
|
559
|
+
[K in MatchableFlag<T>] :
|
|
560
|
+
(k:K,v:ExtractOutcome<T,MatchableFlag<K>>['result'])=>unknown
|
|
561
|
+
}>>
|
|
559
562
|
(t:T, procObj:P):
|
|
560
563
|
P extends Record<any,AnyFunc>
|
|
561
564
|
? {[K in keyof P]: ReturnType<P[K]>}[keyof P]
|
|
@@ -569,6 +572,35 @@ static matchProc<
|
|
|
569
572
|
UtilFunc.throwError(`matchProc 传入了一个预料之外的值: ${String(t)}`,'fatal');
|
|
570
573
|
}
|
|
571
574
|
|
|
575
|
+
/**处理部分联合值
|
|
576
|
+
* @param t - 目标值
|
|
577
|
+
* @param procObj - 所有可能的id组成的处理函数映射 (status, result)=>any
|
|
578
|
+
* @returns 任意处理函数的返回值
|
|
579
|
+
*/
|
|
580
|
+
static matchPartialProc<
|
|
581
|
+
T extends Matchable<Keyable>,
|
|
582
|
+
P extends Partial<{
|
|
583
|
+
[K in MatchableFlag<T>] :
|
|
584
|
+
(k:K,v:ExtractOutcome<T,MatchableFlag<K>>['result'])=>unknown
|
|
585
|
+
}>>
|
|
586
|
+
(t:T, procObj:P):
|
|
587
|
+
(P extends PRecord<Keyable,AnyFunc>
|
|
588
|
+
? {[K in keyof P]: P[K] extends AnyFunc
|
|
589
|
+
? ReturnType<P[K]> : undefined
|
|
590
|
+
}[keyof P] : never ) | undefined {
|
|
591
|
+
if (typeof t === 'string' || typeof t === 'number' || typeof t === 'symbol'){
|
|
592
|
+
if ((procObj as any)[t])
|
|
593
|
+
return (procObj as any)[t](t);
|
|
594
|
+
else return undefined;
|
|
595
|
+
}
|
|
596
|
+
else if ((procObj as any)[t.status])
|
|
597
|
+
return (procObj as any)[t.status](t.status,(t as any).result);
|
|
598
|
+
SLogger.warn(`matchPartialProc 传入了一个预料之外的值, 已返回undefined: ${String(t)}`);
|
|
599
|
+
return undefined;
|
|
600
|
+
}
|
|
601
|
+
|
|
602
|
+
|
|
603
|
+
|
|
572
604
|
/**根据典型的成功或失败状态运行函数
|
|
573
605
|
* @param t - 目标值
|
|
574
606
|
* @param sucessFunc - 成功则运行的函数 (result)=>any
|
package/dist/ServiceAdapter.d.ts
DELETED
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
import { Await, JToken, NeedInit } from "./UtilInterfaces";
|
|
2
|
-
export type ServiceInstance = {
|
|
3
|
-
/**停止实例释放内存
|
|
4
|
-
* @async
|
|
5
|
-
*/
|
|
6
|
-
kill: () => Promise<void> | void;
|
|
7
|
-
};
|
|
8
|
-
export type ServiceConfig = {
|
|
9
|
-
name: string;
|
|
10
|
-
opt: JToken;
|
|
11
|
-
};
|
|
12
|
-
export type CtorTable = {
|
|
13
|
-
[Type in string]: (opt: any) => Promise<ServiceInstance> | ServiceInstance;
|
|
14
|
-
};
|
|
15
|
-
export type CtorTable2FullCfgTable<CT extends CtorTable, Cfg> = {
|
|
16
|
-
[P in keyof CT]: P extends string ? CT[P] extends (opt: infer Opt) => any ? Cfg & {
|
|
17
|
-
type: P;
|
|
18
|
-
opt: Opt;
|
|
19
|
-
} : never : never;
|
|
20
|
-
};
|
|
21
|
-
export declare class ServiceAdapter<CTT extends CtorTable, CFG extends ServiceConfig, FCT extends CtorTable2FullCfgTable<CTT, CFG> = CtorTable2FullCfgTable<CTT, CFG>> implements NeedInit {
|
|
22
|
-
private _cfgPath;
|
|
23
|
-
private _ctorTable;
|
|
24
|
-
inited: Promise<void>;
|
|
25
|
-
protected _cfgTable: Record<string, FCT[keyof FCT]>;
|
|
26
|
-
protected _insPool: Record<string, Await<ReturnType<CTT[keyof CTT]>>>;
|
|
27
|
-
protected constructor(_cfgPath: string, _ctorTable: CTT);
|
|
28
|
-
start<T extends keyof FCT>(type: T, opt: FCT[T]['opt'], name?: string): Promise<void>;
|
|
29
|
-
}
|
|
30
|
-
type ITest1 = {
|
|
31
|
-
test1(): void;
|
|
32
|
-
} & ServiceInstance;
|
|
33
|
-
type ITest2 = {
|
|
34
|
-
test2(): void;
|
|
35
|
-
} & ServiceInstance;
|
|
36
|
-
type TCT = {
|
|
37
|
-
'Test1': (opt: {
|
|
38
|
-
t1: number;
|
|
39
|
-
}) => ITest1;
|
|
40
|
-
'Test2': (opt: {
|
|
41
|
-
t2: string;
|
|
42
|
-
}) => ITest2;
|
|
43
|
-
};
|
|
44
|
-
export type CfgSchema = CtorTable2FullCfgTable<TCT, {
|
|
45
|
-
ssa: string;
|
|
46
|
-
}>;
|
|
47
|
-
export {};
|
package/dist/ServiceAdapter.js
DELETED
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ServiceAdapter = void 0;
|
|
4
|
-
const UtilFileTools_1 = require("./UtilFileTools");
|
|
5
|
-
const UtilFunctions_1 = require("./UtilFunctions");
|
|
6
|
-
class ServiceAdapter {
|
|
7
|
-
_cfgPath;
|
|
8
|
-
_ctorTable;
|
|
9
|
-
inited;
|
|
10
|
-
_cfgTable = {};
|
|
11
|
-
_insPool = {};
|
|
12
|
-
constructor(_cfgPath, _ctorTable) {
|
|
13
|
-
this._cfgPath = _cfgPath;
|
|
14
|
-
this._ctorTable = _ctorTable;
|
|
15
|
-
this.inited = UtilFunctions_1.UtilFunc.ivk(async () => {
|
|
16
|
-
this._cfgTable = await UtilFileTools_1.UtilFT.loadJSONFile(_cfgPath);
|
|
17
|
-
for (const name in this._cfgTable) {
|
|
18
|
-
const cfg = this._cfgTable[name];
|
|
19
|
-
//@ts-ignore
|
|
20
|
-
this._insPool[name] = await this._ctorTable[cfg.type](cfg.opt);
|
|
21
|
-
}
|
|
22
|
-
});
|
|
23
|
-
}
|
|
24
|
-
async start(type, opt, name = 'default') {
|
|
25
|
-
if (this._insPool[name] != undefined)
|
|
26
|
-
await this._insPool[name].kill();
|
|
27
|
-
//@ts-ignore
|
|
28
|
-
this._insPool[name] = await this._ctorTable[type](opt);
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
exports.ServiceAdapter = ServiceAdapter;
|
|
32
|
-
class TessClass extends ServiceAdapter {
|
|
33
|
-
}
|
|
34
|
-
let a = null;
|
|
35
|
-
a.start('Test1', { t1: 100 });
|
package/src/ServiceAdapter.ts
DELETED
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
import { UtilFT } from "./UtilFileTools";
|
|
2
|
-
import { UtilFunc } from "./UtilFunctions";
|
|
3
|
-
import { Await, JToken, NeedInit } from "./UtilInterfaces";
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
export type ServiceInstance = {
|
|
11
|
-
/**停止实例释放内存
|
|
12
|
-
* @async
|
|
13
|
-
*/
|
|
14
|
-
kill:()=>Promise<void>|void;
|
|
15
|
-
}
|
|
16
|
-
export type ServiceConfig = {
|
|
17
|
-
name:string;
|
|
18
|
-
opt :JToken;
|
|
19
|
-
};
|
|
20
|
-
export type CtorTable = {
|
|
21
|
-
[Type in string]:(opt:any)=>Promise<ServiceInstance>|ServiceInstance
|
|
22
|
-
}
|
|
23
|
-
export type CtorTable2FullCfgTable<CT extends CtorTable,Cfg> = {
|
|
24
|
-
[P in keyof CT]: P extends string ?
|
|
25
|
-
CT[P] extends (opt:infer Opt)=>any
|
|
26
|
-
? Cfg&{type:P,opt:Opt}
|
|
27
|
-
: never
|
|
28
|
-
: never
|
|
29
|
-
}
|
|
30
|
-
export class ServiceAdapter
|
|
31
|
-
<CTT extends CtorTable,
|
|
32
|
-
CFG extends ServiceConfig,
|
|
33
|
-
FCT extends CtorTable2FullCfgTable<CTT,CFG> = CtorTable2FullCfgTable<CTT,CFG>>
|
|
34
|
-
implements NeedInit{
|
|
35
|
-
inited:Promise<void>;
|
|
36
|
-
protected _cfgTable :Record<string,FCT[keyof FCT]>={};
|
|
37
|
-
protected _insPool :Record<string,Await<ReturnType<CTT[keyof CTT]>>>={};
|
|
38
|
-
protected constructor(private _cfgPath:string, private _ctorTable:CTT){
|
|
39
|
-
this.inited=UtilFunc.ivk(async ()=>{
|
|
40
|
-
this._cfgTable = await UtilFT.loadJSONFile(_cfgPath) as Record<string,FCT[keyof FCT]>;
|
|
41
|
-
for(const name in this._cfgTable){
|
|
42
|
-
const cfg = this._cfgTable[name];
|
|
43
|
-
//@ts-ignore
|
|
44
|
-
this._insPool[name] = await this._ctorTable[cfg.type](cfg.opt);
|
|
45
|
-
}
|
|
46
|
-
});
|
|
47
|
-
}
|
|
48
|
-
async start<T extends keyof FCT>(type:T,opt:FCT[T]['opt'],name:string='default'){
|
|
49
|
-
if(this._insPool[name]!=undefined)
|
|
50
|
-
await this._insPool[name].kill();
|
|
51
|
-
//@ts-ignore
|
|
52
|
-
this._insPool[name] = await this._ctorTable[type as keyof CTT](opt)
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
type ITest1 = {
|
|
58
|
-
test1():void;
|
|
59
|
-
}&ServiceInstance;
|
|
60
|
-
type ITest2 = {
|
|
61
|
-
test2():void;
|
|
62
|
-
}&ServiceInstance;
|
|
63
|
-
|
|
64
|
-
type TCT = {
|
|
65
|
-
'Test1':(opt:{t1:number})=>ITest1;
|
|
66
|
-
'Test2':(opt:{t2:string})=>ITest2;
|
|
67
|
-
}
|
|
68
|
-
class TessClass extends ServiceAdapter<TCT,{}&ServiceConfig>{
|
|
69
|
-
}
|
|
70
|
-
let a:TessClass = null as any;
|
|
71
|
-
a.start('Test1',{t1:100});
|
|
72
|
-
|
|
73
|
-
export type CfgSchema = CtorTable2FullCfgTable<TCT,{ssa:string}>;
|