@zwa73/utils 1.0.88 → 1.0.90
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/UtilFileTools.d.ts +1 -16
- package/dist/UtilFileTools.js +0 -82
- package/dist/UtilFunctions.d.ts +1 -1
- package/dist/UtilFunctions.js +3 -5
- package/package.json +1 -2
- package/src/UtilClass.ts +0 -1
- package/src/UtilFileTools.ts +0 -83
- package/src/UtilFunctions.ts +3 -6
package/dist/UtilFileTools.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { JToken } from "./UtilInterfaces";
|
|
2
2
|
/**文件工具 */
|
|
3
3
|
export declare namespace UtilFT {
|
|
4
4
|
/**验证路径 文件或文件夹 是否存在 异步
|
|
@@ -88,19 +88,4 @@ export declare namespace UtilFT {
|
|
|
88
88
|
* @param filePath - 需要验证的文件路径
|
|
89
89
|
*/
|
|
90
90
|
function isValidFilePath(filePath: string): boolean;
|
|
91
|
-
/**构造Schema
|
|
92
|
-
* @async
|
|
93
|
-
* @param configPath - tsconfig路径
|
|
94
|
-
* @param outDir - schema文件夹路径 如 ./schema/
|
|
95
|
-
* @param coverDefine - 将会覆盖 definitions 对应内容的表
|
|
96
|
-
*/
|
|
97
|
-
function builAllSchema(configPath: string, outDir: string, coverDefine?: JObject): Promise<void>;
|
|
98
|
-
/**生成匹配的文件的所有type的schema
|
|
99
|
-
* @async
|
|
100
|
-
* @param globPattern - glob匹配符
|
|
101
|
-
* @param outDir - schema输出路径目录 如 ./schema/
|
|
102
|
-
* @param ignore - glob忽略匹配符
|
|
103
|
-
* @param coverDefine - 将会覆盖 definitions 对应内容的表
|
|
104
|
-
*/
|
|
105
|
-
function buildMatchSchema(globPattern: string | string[], outDir: string, ignore?: string | string[], coverDefine?: JObject): Promise<void>;
|
|
106
91
|
}
|
package/dist/UtilFileTools.js
CHANGED
|
@@ -7,7 +7,6 @@ const UtilLogger_1 = require("./UtilLogger");
|
|
|
7
7
|
const JSON5 = require("json5");
|
|
8
8
|
const glob_1 = require("glob");
|
|
9
9
|
const UtilFunctions_1 = require("./UtilFunctions");
|
|
10
|
-
const TJS = require("typescript-json-schema");
|
|
11
10
|
/**文件工具 */
|
|
12
11
|
var UtilFT;
|
|
13
12
|
(function (UtilFT) {
|
|
@@ -219,85 +218,4 @@ var UtilFT;
|
|
|
219
218
|
return true;
|
|
220
219
|
}
|
|
221
220
|
UtilFT.isValidFilePath = isValidFilePath;
|
|
222
|
-
//#region schema
|
|
223
|
-
/**构造Schema
|
|
224
|
-
* @async
|
|
225
|
-
* @param configPath - tsconfig路径
|
|
226
|
-
* @param outDir - schema文件夹路径 如 ./schema/
|
|
227
|
-
* @param coverDefine - 将会覆盖 definitions 对应内容的表
|
|
228
|
-
*/
|
|
229
|
-
async function builAllSchema(configPath, outDir, coverDefine = {}) {
|
|
230
|
-
outDir = path.join(outDir, "schemas.json");
|
|
231
|
-
const log = await UtilFunctions_1.UtilFunc.exec(`typescript-json-schema ${configPath} * --out ${outDir} --required --strictNullChecks --aliasRefs`);
|
|
232
|
-
console.log(log);
|
|
233
|
-
const schema = (await UtilFT.loadJSONFileSync(outDir));
|
|
234
|
-
//进行预处理并展开
|
|
235
|
-
await expandSchema(outDir, schema, coverDefine);
|
|
236
|
-
}
|
|
237
|
-
UtilFT.builAllSchema = builAllSchema;
|
|
238
|
-
/**生成匹配的文件的所有type的schema
|
|
239
|
-
* @async
|
|
240
|
-
* @param globPattern - glob匹配符
|
|
241
|
-
* @param outDir - schema输出路径目录 如 ./schema/
|
|
242
|
-
* @param ignore - glob忽略匹配符
|
|
243
|
-
* @param coverDefine - 将会覆盖 definitions 对应内容的表
|
|
244
|
-
*/
|
|
245
|
-
async function buildMatchSchema(globPattern, outDir, ignore, coverDefine = {}) {
|
|
246
|
-
//生成
|
|
247
|
-
const settings = {
|
|
248
|
-
required: true,
|
|
249
|
-
aliasRef: true,
|
|
250
|
-
};
|
|
251
|
-
const compilerOptions = {
|
|
252
|
-
strictNullChecks: true,
|
|
253
|
-
};
|
|
254
|
-
const files = UtilFT.fileSearchGlob(globPattern, ignore);
|
|
255
|
-
const program = TJS.getProgramFromFiles(files, compilerOptions);
|
|
256
|
-
const schema = TJS.generateSchema(program, "*", settings);
|
|
257
|
-
outDir = outDir ?? path.join(process.cwd(), 'schema');
|
|
258
|
-
const schemasPath = path.join(outDir, 'schemas.json');
|
|
259
|
-
//进行预处理并展开
|
|
260
|
-
await expandSchema(schemasPath, schema, coverDefine);
|
|
261
|
-
}
|
|
262
|
-
UtilFT.buildMatchSchema = buildMatchSchema;
|
|
263
|
-
/**展开schema以供使用 */
|
|
264
|
-
async function expandSchema(schemasPath, schema, coverDefine) {
|
|
265
|
-
//覆盖
|
|
266
|
-
coverObj(schema["definitions"], coverDefine);
|
|
267
|
-
//替换SchemaString标识符
|
|
268
|
-
schema = JSON.parse(JSON.stringify(schema).replace(/\^\.\*SchemaString\$/g, '^.*$'));
|
|
269
|
-
const plist = [];
|
|
270
|
-
plist.push(UtilFT.writeJSONFile(schemasPath, schema));
|
|
271
|
-
const definitions = schema["definitions"];
|
|
272
|
-
//展开定义
|
|
273
|
-
for (const typeName in definitions) {
|
|
274
|
-
const schema = definitions[typeName];
|
|
275
|
-
//展开所有object与忽略检测的类型
|
|
276
|
-
if (!(schema.type == "object" || schema.type == "array" || schema.type == undefined))
|
|
277
|
-
continue;
|
|
278
|
-
if ((/^.+_[0-9]/).test(typeName) || (/^{./).test(typeName))
|
|
279
|
-
continue;
|
|
280
|
-
const basename = path.basename(schemasPath);
|
|
281
|
-
const tpath = path.join(path.dirname(schemasPath), `${typeName}.schema.json`);
|
|
282
|
-
if (!isValidFilePath(tpath))
|
|
283
|
-
continue;
|
|
284
|
-
plist.push(UtilFT.writeJSONFile(tpath, {
|
|
285
|
-
"$schema": "http://json-schema.org/draft-07/schema#",
|
|
286
|
-
"$ref": `${basename}#/definitions/${typeName}`
|
|
287
|
-
}));
|
|
288
|
-
}
|
|
289
|
-
await Promise.all(plist);
|
|
290
|
-
}
|
|
291
|
-
/**覆盖object */
|
|
292
|
-
function coverObj(base, cover) {
|
|
293
|
-
for (const k in cover) {
|
|
294
|
-
const v = cover[k];
|
|
295
|
-
if (typeof v === "object" && !Array.isArray(v) &&
|
|
296
|
-
typeof base[k] === "object" && !Array.isArray(base[k]))
|
|
297
|
-
coverObj(base[k], v);
|
|
298
|
-
else
|
|
299
|
-
base[k] = v;
|
|
300
|
-
}
|
|
301
|
-
}
|
|
302
|
-
//#endregion
|
|
303
221
|
})(UtilFT || (exports.UtilFT = UtilFT = {}));
|
package/dist/UtilFunctions.d.ts
CHANGED
|
@@ -103,7 +103,7 @@ export declare class UtilFunc {
|
|
|
103
103
|
* @param task - 任务逻辑
|
|
104
104
|
* @returns 处理结果
|
|
105
105
|
*/
|
|
106
|
-
static queueProc<T>(flag: Keyable, task: (() => Promise<T>)
|
|
106
|
+
static queueProc<T>(flag: Keyable, task: (() => Promise<T>)): Promise<T>;
|
|
107
107
|
/**队列获取目标的代办事件数
|
|
108
108
|
* @param flag - 队列标签
|
|
109
109
|
*/
|
package/dist/UtilFunctions.js
CHANGED
|
@@ -301,7 +301,7 @@ class UtilFunc {
|
|
|
301
301
|
this.pendingMap[flag] = this.pendingMap[flag] ?? [];
|
|
302
302
|
const pending = this.pendingMap[flag];
|
|
303
303
|
//尝试解除下个任务的等待
|
|
304
|
-
const tryRes =
|
|
304
|
+
const tryRes = () => {
|
|
305
305
|
const thispd = pending;
|
|
306
306
|
const resolve = thispd.shift();
|
|
307
307
|
if (resolve)
|
|
@@ -313,10 +313,8 @@ class UtilFunc {
|
|
|
313
313
|
else
|
|
314
314
|
await new Promise((resolve) => pending.push(resolve));
|
|
315
315
|
try {
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
: await task;
|
|
319
|
-
return result;
|
|
316
|
+
return await task();
|
|
317
|
+
;
|
|
320
318
|
}
|
|
321
319
|
catch (e) {
|
|
322
320
|
UtilLogger_1.SLogger.fatal(`queuePromise 出现错误`, e);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zwa73/utils",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.90",
|
|
4
4
|
"description": "my utils",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -26,7 +26,6 @@
|
|
|
26
26
|
"https-proxy-agent": "^5.0.1",
|
|
27
27
|
"json5": "^2.2.3",
|
|
28
28
|
"tiktoken": "^1.0.7",
|
|
29
|
-
"typescript-json-schema": "^0.63.0",
|
|
30
29
|
"winston": "^3.10.0",
|
|
31
30
|
"winston-daily-rotate-file": "^4.7.1"
|
|
32
31
|
},
|
package/src/UtilClass.ts
CHANGED
package/src/UtilFileTools.ts
CHANGED
|
@@ -5,7 +5,6 @@ import { SLogger } from "@src/UtilLogger";
|
|
|
5
5
|
import * as JSON5 from 'json5';
|
|
6
6
|
import { globSync } from "glob";
|
|
7
7
|
import { UtilFunc } from "./UtilFunctions";
|
|
8
|
-
import * as TJS from "typescript-json-schema";
|
|
9
8
|
|
|
10
9
|
/**文件工具 */
|
|
11
10
|
export namespace UtilFT{
|
|
@@ -243,86 +242,4 @@ export function isValidFilePath(filePath:string){
|
|
|
243
242
|
}
|
|
244
243
|
return true;
|
|
245
244
|
}
|
|
246
|
-
|
|
247
|
-
//#region schema
|
|
248
|
-
/**构造Schema
|
|
249
|
-
* @async
|
|
250
|
-
* @param configPath - tsconfig路径
|
|
251
|
-
* @param outDir - schema文件夹路径 如 ./schema/
|
|
252
|
-
* @param coverDefine - 将会覆盖 definitions 对应内容的表
|
|
253
|
-
*/
|
|
254
|
-
export async function builAllSchema(configPath:string,outDir:string,coverDefine:JObject={}){
|
|
255
|
-
outDir = path.join(outDir,"schemas.json");
|
|
256
|
-
const log = await UtilFunc.exec(`typescript-json-schema ${configPath} * --out ${outDir} --required --strictNullChecks --aliasRefs`);
|
|
257
|
-
console.log(log);
|
|
258
|
-
const schema = (await UtilFT.loadJSONFileSync(outDir)) as any;
|
|
259
|
-
//进行预处理并展开
|
|
260
|
-
await expandSchema(outDir,schema,coverDefine);
|
|
261
|
-
}
|
|
262
|
-
/**生成匹配的文件的所有type的schema
|
|
263
|
-
* @async
|
|
264
|
-
* @param globPattern - glob匹配符
|
|
265
|
-
* @param outDir - schema输出路径目录 如 ./schema/
|
|
266
|
-
* @param ignore - glob忽略匹配符
|
|
267
|
-
* @param coverDefine - 将会覆盖 definitions 对应内容的表
|
|
268
|
-
*/
|
|
269
|
-
export async function buildMatchSchema(globPattern:string|string[],outDir:string,ignore?:string|string[],coverDefine:JObject={}){
|
|
270
|
-
//生成
|
|
271
|
-
const settings: TJS.PartialArgs = {
|
|
272
|
-
required: true,
|
|
273
|
-
aliasRef:true,
|
|
274
|
-
};
|
|
275
|
-
const compilerOptions: TJS.CompilerOptions = {
|
|
276
|
-
strictNullChecks: true,
|
|
277
|
-
};
|
|
278
|
-
const files = UtilFT.fileSearchGlob(globPattern,ignore);
|
|
279
|
-
const program = TJS.getProgramFromFiles(
|
|
280
|
-
files,
|
|
281
|
-
compilerOptions,
|
|
282
|
-
);
|
|
283
|
-
const schema = TJS.generateSchema(program, "*", settings) as any;
|
|
284
|
-
outDir = outDir??path.join(process.cwd(),'schema');
|
|
285
|
-
const schemasPath = path.join(outDir,'schemas.json');
|
|
286
|
-
//进行预处理并展开
|
|
287
|
-
await expandSchema(schemasPath,schema,coverDefine);
|
|
288
|
-
}
|
|
289
|
-
/**展开schema以供使用 */
|
|
290
|
-
async function expandSchema(schemasPath:string,schema:any,coverDefine:JObject){
|
|
291
|
-
//覆盖
|
|
292
|
-
coverObj(schema["definitions"],coverDefine);
|
|
293
|
-
//替换SchemaString标识符
|
|
294
|
-
schema = JSON.parse(JSON.stringify(schema).replace(/\^\.\*SchemaString\$/g,'^.*$'));
|
|
295
|
-
const plist:Promise<void>[] = [];
|
|
296
|
-
plist.push(UtilFT.writeJSONFile(schemasPath,schema));
|
|
297
|
-
|
|
298
|
-
const definitions = schema["definitions"] as Record<string,JObject>;
|
|
299
|
-
//展开定义
|
|
300
|
-
for(const typeName in definitions){
|
|
301
|
-
const schema = definitions[typeName];
|
|
302
|
-
//展开所有object与忽略检测的类型
|
|
303
|
-
if(!(schema.type == "object" || schema.type == "array" || schema.type == undefined)) continue;
|
|
304
|
-
if((/^.+_[0-9]/).test(typeName) || (/^{./).test(typeName)) continue;
|
|
305
|
-
|
|
306
|
-
const basename = path.basename(schemasPath);
|
|
307
|
-
const tpath = path.join(path.dirname(schemasPath),`${typeName}.schema.json`);
|
|
308
|
-
if(!isValidFilePath(tpath)) continue;
|
|
309
|
-
plist.push(UtilFT.writeJSONFile(tpath,{
|
|
310
|
-
"$schema": "http://json-schema.org/draft-07/schema#",
|
|
311
|
-
"$ref": `${basename}#/definitions/${typeName}`
|
|
312
|
-
}));
|
|
313
|
-
}
|
|
314
|
-
await Promise.all(plist);
|
|
315
|
-
}
|
|
316
|
-
/**覆盖object */
|
|
317
|
-
function coverObj(base:JObject,cover:JObject){
|
|
318
|
-
for(const k in cover){
|
|
319
|
-
const v = cover[k];
|
|
320
|
-
if( typeof v === "object" && !Array.isArray(v) &&
|
|
321
|
-
typeof base[k] === "object" && !Array.isArray(base[k]) )
|
|
322
|
-
coverObj(base[k] as JObject,v as JObject);
|
|
323
|
-
else
|
|
324
|
-
base[k] = v;
|
|
325
|
-
}
|
|
326
|
-
}
|
|
327
|
-
//#endregion
|
|
328
245
|
}
|
package/src/UtilFunctions.ts
CHANGED
|
@@ -356,12 +356,12 @@ static pendingMap:Record<Keyable,AnyFunc[]> = {};
|
|
|
356
356
|
* @param task - 任务逻辑
|
|
357
357
|
* @returns 处理结果
|
|
358
358
|
*/
|
|
359
|
-
static async queueProc<T>(flag:Keyable,task:(()=>Promise<T>)
|
|
359
|
+
static async queueProc<T>(flag:Keyable,task:(()=>Promise<T>)):Promise<T> {
|
|
360
360
|
this.pendingMap[flag] = this.pendingMap[flag]??[];
|
|
361
361
|
const pending = this.pendingMap[flag];
|
|
362
362
|
|
|
363
363
|
//尝试解除下个任务的等待
|
|
364
|
-
const tryRes =
|
|
364
|
+
const tryRes = () => {
|
|
365
365
|
const thispd = pending;
|
|
366
366
|
const resolve = thispd.shift();
|
|
367
367
|
if(resolve) resolve();
|
|
@@ -373,10 +373,7 @@ static async queueProc<T>(flag:Keyable,task:(()=>Promise<T>)|Promise<T>):Promise
|
|
|
373
373
|
else await new Promise((resolve) => pending.push(resolve));
|
|
374
374
|
|
|
375
375
|
try {
|
|
376
|
-
|
|
377
|
-
? await task()
|
|
378
|
-
: await task;
|
|
379
|
-
return result;
|
|
376
|
+
return await task();;
|
|
380
377
|
} catch(e){
|
|
381
378
|
SLogger.fatal(`queuePromise 出现错误`,e);
|
|
382
379
|
throw e;
|