@backtest-kit/ui 3.4.0 → 3.5.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/build/index.cjs CHANGED
@@ -67,11 +67,13 @@ const mockServices$1 = {
67
67
  notificationMockService: Symbol("notificationMockService"),
68
68
  storageMockService: Symbol("storageMockService"),
69
69
  exchangeMockService: Symbol("exchangeMockService"),
70
+ logMockService: Symbol("logMockService"),
70
71
  };
71
72
  const viewServices$1 = {
72
73
  notificationViewService: Symbol("notificationViewService"),
73
74
  storageViewService: Symbol("storageViewService"),
74
75
  exchangeViewService: Symbol("exchangeViewService"),
76
+ logViewService: Symbol("logViewService"),
75
77
  };
76
78
  const TYPES = {
77
79
  ...baseServices$1,
@@ -174,25 +176,25 @@ class LoggerService {
174
176
  }
175
177
  }
176
178
 
177
- const MOCK_PATH$1 = "./mock/notifications.json";
179
+ const MOCK_PATH$2 = "./mock/notifications.json";
178
180
  const READ_NOTIFICATION_LIST_FN = functoolsKit.singleshot(async () => {
179
- const data = await fs.readFile(MOCK_PATH$1, "utf-8");
181
+ const data = await fs.readFile(MOCK_PATH$2, "utf-8");
180
182
  return JSON.parse(data);
181
183
  });
182
- const DEFAULT_LIMIT$1 = 25;
183
- const DEFAULT_OFFSET$1 = 0;
184
- const CREATE_FILTER_LIST_FN$1 = (filterData) => Object.keys(filterData).map((key) => (row) => new RegExp(filterData[key], "i").test(row[key]));
184
+ const DEFAULT_LIMIT$3 = 25;
185
+ const DEFAULT_OFFSET$3 = 0;
186
+ const CREATE_FILTER_LIST_FN$3 = (filterData) => Object.keys(filterData).map((key) => (row) => new RegExp(filterData[key], "i").test(row[key]));
185
187
  class NotificationMockService {
186
188
  constructor() {
187
189
  this.loggerService = inject(TYPES.loggerService);
188
- this.findByFilter = async (filterData, limit = DEFAULT_LIMIT$1, offset = DEFAULT_OFFSET$1) => {
190
+ this.findByFilter = async (filterData, limit = DEFAULT_LIMIT$3, offset = DEFAULT_OFFSET$3) => {
189
191
  this.loggerService.log("notificationMockService findByFilter", {
190
192
  filterData,
191
193
  limit,
192
194
  offset,
193
195
  });
194
196
  const iter = functoolsKit.pickDocuments(limit, offset);
195
- const filterList = CREATE_FILTER_LIST_FN$1(filterData);
197
+ const filterList = CREATE_FILTER_LIST_FN$3(filterData);
196
198
  for (const notification of await this.getList()) {
197
199
  let isOk = true;
198
200
  for (const filterFn of filterList) {
@@ -236,9 +238,9 @@ class NotificationMockService {
236
238
  }
237
239
  }
238
240
 
239
- const MOCK_PATH = "./mock/db";
241
+ const MOCK_PATH$1 = "./mock/db";
240
242
  const READ_BACKTEST_STORAGE_FN = functoolsKit.singleshot(async () => {
241
- const dbPath = path.join(process.cwd(), MOCK_PATH);
243
+ const dbPath = path.join(process.cwd(), MOCK_PATH$1);
242
244
  const files = await fs.readdir(dbPath);
243
245
  const signals = [];
244
246
  for (const file of files) {
@@ -299,14 +301,64 @@ class ExchangeMockService {
299
301
  }
300
302
  }
301
303
 
302
- const DEFAULT_LIMIT = 25;
303
- const DEFAULT_OFFSET = 0;
304
- const CREATE_FILTER_LIST_FN = (filterData) => Object.keys(filterData).map((key) => (row) => new RegExp(filterData[key], "i").test(row[key]));
304
+ const MOCK_PATH = "./mock/logs.json";
305
+ const READ_LOG_LIST_FN = functoolsKit.singleshot(async () => {
306
+ const data = await fs.readFile(MOCK_PATH, "utf-8");
307
+ return JSON.parse(data);
308
+ });
309
+ const DEFAULT_LIMIT$2 = 25;
310
+ const DEFAULT_OFFSET$2 = 0;
311
+ const CREATE_FILTER_LIST_FN$2 = (filterData) => Object.keys(filterData).map((key) => (row) => new RegExp(filterData[key], "i").test(row[key]));
312
+ class LogMockService {
313
+ constructor() {
314
+ this.loggerService = inject(TYPES.loggerService);
315
+ this.findByFilter = async (filterData, limit = DEFAULT_LIMIT$2, offset = DEFAULT_OFFSET$2) => {
316
+ this.loggerService.log("logMockService findByFilter", {
317
+ filterData,
318
+ limit,
319
+ offset,
320
+ });
321
+ const iter = functoolsKit.pickDocuments(limit, offset);
322
+ const filterList = CREATE_FILTER_LIST_FN$2(filterData);
323
+ for (const entry of await this.getList()) {
324
+ let isOk = true;
325
+ for (const filterFn of filterList) {
326
+ isOk = isOk && filterFn(entry);
327
+ }
328
+ if (!isOk) {
329
+ continue;
330
+ }
331
+ if (iter([entry]).done) {
332
+ break;
333
+ }
334
+ }
335
+ return iter().rows;
336
+ };
337
+ this.getList = async () => {
338
+ this.loggerService.log("logMockService getList");
339
+ const logList = [];
340
+ for (const entry of await READ_LOG_LIST_FN()) {
341
+ logList.push(entry);
342
+ }
343
+ logList.sort((a, b) => b.timestamp - a.timestamp);
344
+ return logList;
345
+ };
346
+ this.getOne = async (id) => {
347
+ this.loggerService.log("logMockService getOne");
348
+ const logList = await this.getList();
349
+ return logList.find((item) => item.id === id) ?? null;
350
+ };
351
+ }
352
+ }
353
+
354
+ const DEFAULT_LIMIT$1 = 25;
355
+ const DEFAULT_OFFSET$1 = 0;
356
+ const CREATE_FILTER_LIST_FN$1 = (filterData) => Object.keys(filterData).map((key) => (row) => new RegExp(filterData[key], "i").test(row[key]));
305
357
  class NotificationViewService {
306
358
  constructor() {
307
359
  this.loggerService = inject(TYPES.loggerService);
308
360
  this.notificationMockService = inject(TYPES.notificationMockService);
309
- this.findByFilter = async (filterData, limit = DEFAULT_LIMIT, offset = DEFAULT_OFFSET) => {
361
+ this.findByFilter = async (filterData, limit = DEFAULT_LIMIT$1, offset = DEFAULT_OFFSET$1) => {
310
362
  this.loggerService.log("notificationViewService findByFilter", {
311
363
  filterData,
312
364
  limit,
@@ -316,7 +368,7 @@ class NotificationViewService {
316
368
  return await this.notificationMockService.findByFilter(filterData, limit, offset);
317
369
  }
318
370
  const iter = functoolsKit.pickDocuments(limit, offset);
319
- const filterList = CREATE_FILTER_LIST_FN(filterData);
371
+ const filterList = CREATE_FILTER_LIST_FN$1(filterData);
320
372
  for (const notification of await this.getList()) {
321
373
  let isOk = true;
322
374
  for (const filterFn of filterList) {
@@ -473,6 +525,61 @@ class ExchangeViewService {
473
525
  }
474
526
  }
475
527
 
528
+ const DEFAULT_LIMIT = 25;
529
+ const DEFAULT_OFFSET = 0;
530
+ const CREATE_FILTER_LIST_FN = (filterData) => Object.keys(filterData).map((key) => (row) => new RegExp(filterData[key], "i").test(row[key]));
531
+ class LogViewService {
532
+ constructor() {
533
+ this.loggerService = inject(TYPES.loggerService);
534
+ this.logMockService = inject(TYPES.logMockService);
535
+ this.findByFilter = async (filterData, limit = DEFAULT_LIMIT, offset = DEFAULT_OFFSET) => {
536
+ this.loggerService.log("logViewService findByFilter", {
537
+ filterData,
538
+ limit,
539
+ offset,
540
+ });
541
+ if (CC_ENABLE_MOCK) {
542
+ return await this.logMockService.findByFilter(filterData, limit, offset);
543
+ }
544
+ const iter = functoolsKit.pickDocuments(limit, offset);
545
+ const filterList = CREATE_FILTER_LIST_FN(filterData);
546
+ for (const entry of await this.getList()) {
547
+ let isOk = true;
548
+ for (const filterFn of filterList) {
549
+ isOk = isOk && filterFn(entry);
550
+ }
551
+ if (!isOk) {
552
+ continue;
553
+ }
554
+ if (iter([entry]).done) {
555
+ break;
556
+ }
557
+ }
558
+ return iter().rows;
559
+ };
560
+ this.getList = async () => {
561
+ this.loggerService.log("logViewService getList");
562
+ if (CC_ENABLE_MOCK) {
563
+ return await this.logMockService.getList();
564
+ }
565
+ const logList = await backtestKit.Log.getList();
566
+ logList.sort((a, b) => b.timestamp - a.timestamp);
567
+ return logList;
568
+ };
569
+ this.getOne = async (id) => {
570
+ this.loggerService.log("logViewService getOne", { id });
571
+ if (CC_ENABLE_MOCK) {
572
+ return await this.logMockService.getOne(id);
573
+ }
574
+ const logList = await this.getList();
575
+ return logList.find((item) => item.id === id) ?? null;
576
+ };
577
+ this.init = functoolsKit.singleshot(async () => {
578
+ this.loggerService.log("logViewService init");
579
+ });
580
+ }
581
+ }
582
+
476
583
  const symbol_list = [
477
584
  {
478
585
  icon: "/icon/btc.png",
@@ -656,11 +763,13 @@ class PriceConnectionService {
656
763
  provide(TYPES.notificationMockService, () => new NotificationMockService());
657
764
  provide(TYPES.storageMockService, () => new StorageMockService());
658
765
  provide(TYPES.exchangeMockService, () => new ExchangeMockService());
766
+ provide(TYPES.logMockService, () => new LogMockService());
659
767
  }
660
768
  {
661
769
  provide(TYPES.notificationViewService, () => new NotificationViewService());
662
770
  provide(TYPES.storageViewService, () => new StorageViewService());
663
771
  provide(TYPES.exchangeViewService, () => new ExchangeViewService());
772
+ provide(TYPES.logViewService, () => new LogViewService());
664
773
  }
665
774
 
666
775
  const baseServices = {
@@ -678,11 +787,13 @@ const mockServices = {
678
787
  notificationMockService: inject(TYPES.notificationMockService),
679
788
  storageMockService: inject(TYPES.storageMockService),
680
789
  exchangeMockService: inject(TYPES.exchangeMockService),
790
+ logMockService: inject(TYPES.logMockService),
681
791
  };
682
792
  const viewServices = {
683
793
  notificationViewService: inject(TYPES.notificationViewService),
684
794
  storageViewService: inject(TYPES.storageViewService),
685
795
  exchangeViewService: inject(TYPES.exchangeViewService),
796
+ logViewService: inject(TYPES.logViewService),
686
797
  };
687
798
  const ioc = {
688
799
  ...baseServices,
@@ -930,6 +1041,92 @@ router$6.post("/api/v1/mock/storage_list/backtest", async (req, res) => {
930
1041
  });
931
1042
  }
932
1043
  });
1044
+ // LogMockService endpoints
1045
+ router$6.post("/api/v1/mock/log_list", async (req, res) => {
1046
+ try {
1047
+ const request = await micro.json(req);
1048
+ const { requestId, serviceName } = request;
1049
+ const data = await ioc.logMockService.getList();
1050
+ const result = {
1051
+ data,
1052
+ status: "ok",
1053
+ error: "",
1054
+ requestId,
1055
+ serviceName,
1056
+ };
1057
+ ioc.loggerService.log("/api/v1/mock/log_list ok", {
1058
+ request,
1059
+ result: omit(result, "data"),
1060
+ });
1061
+ return await micro.send(res, 200, result);
1062
+ }
1063
+ catch (error) {
1064
+ ioc.loggerService.log("/api/v1/mock/log_list error", {
1065
+ error: functoolsKit.errorData(error),
1066
+ });
1067
+ return await micro.send(res, 200, {
1068
+ status: "error",
1069
+ error: functoolsKit.getErrorMessage(error),
1070
+ });
1071
+ }
1072
+ });
1073
+ router$6.post("/api/v1/mock/log_one/:id", async (req, res) => {
1074
+ try {
1075
+ const request = await micro.json(req);
1076
+ const { requestId, serviceName } = request;
1077
+ const id = req.params.id;
1078
+ const data = await ioc.logMockService.getOne(id);
1079
+ const result = {
1080
+ data,
1081
+ status: "ok",
1082
+ error: "",
1083
+ requestId,
1084
+ serviceName,
1085
+ };
1086
+ ioc.loggerService.log("/api/v1/mock/log_one/:id ok", {
1087
+ request,
1088
+ result: omit(result, "data"),
1089
+ });
1090
+ return await micro.send(res, 200, result);
1091
+ }
1092
+ catch (error) {
1093
+ ioc.loggerService.log("/api/v1/mock/log_one/:id error", {
1094
+ error: functoolsKit.errorData(error),
1095
+ });
1096
+ return await micro.send(res, 200, {
1097
+ status: "error",
1098
+ error: functoolsKit.getErrorMessage(error),
1099
+ });
1100
+ }
1101
+ });
1102
+ router$6.post("/api/v1/mock/log_filter", async (req, res) => {
1103
+ try {
1104
+ const request = await micro.json(req);
1105
+ const { requestId, serviceName, filterData, limit, offset } = request;
1106
+ const data = await ioc.logMockService.findByFilter(filterData, limit, offset);
1107
+ const result = {
1108
+ data,
1109
+ status: "ok",
1110
+ error: "",
1111
+ requestId,
1112
+ serviceName,
1113
+ };
1114
+ ioc.loggerService.log("/api/v1/mock/log_filter ok", {
1115
+ request,
1116
+ result: omit(result, "data"),
1117
+ });
1118
+ return await micro.send(res, 200, result);
1119
+ }
1120
+ catch (error) {
1121
+ ioc.loggerService.log("/api/v1/mock/log_filter error", {
1122
+ error: functoolsKit.errorData(error),
1123
+ });
1124
+ return await micro.send(res, 200, {
1125
+ status: "error",
1126
+ error: functoolsKit.getErrorMessage(error),
1127
+ });
1128
+ }
1129
+ });
933
1130
 
934
1131
  const router$5 = Router({
935
1132
  params: true,
@@ -1168,6 +1365,92 @@ router$5.post("/api/v1/view/storage_list/backtest", async (req, res) => {
1168
1365
  });
1169
1366
  }
1170
1367
  });
1368
+ // LogViewService endpoints
1369
+ router$5.post("/api/v1/view/log_list", async (req, res) => {
1370
+ try {
1371
+ const request = await micro.json(req);
1372
+ const { requestId, serviceName } = request;
1373
+ const data = await ioc.logViewService.getList();
1374
+ const result = {
1375
+ data,
1376
+ status: "ok",
1377
+ error: "",
1378
+ requestId,
1379
+ serviceName,
1380
+ };
1381
+ ioc.loggerService.log("/api/v1/view/log_list ok", {
1382
+ request,
1383
+ result: omit(result, "data"),
1384
+ });
1385
+ return await micro.send(res, 200, result);
1386
+ }
1387
+ catch (error) {
1388
+ ioc.loggerService.log("/api/v1/view/log_list error", {
1389
+ error: functoolsKit.errorData(error),
1390
+ });
1391
+ return await micro.send(res, 200, {
1392
+ status: "error",
1393
+ error: functoolsKit.getErrorMessage(error),
1394
+ });
1395
+ }
1396
+ });
1397
+ router$5.post("/api/v1/view/log_one/:id", async (req, res) => {
1398
+ try {
1399
+ const request = await micro.json(req);
1400
+ const { requestId, serviceName } = request;
1401
+ const id = req.params.id;
1402
+ const data = await ioc.logViewService.getOne(id);
1403
+ const result = {
1404
+ data,
1405
+ status: "ok",
1406
+ error: "",
1407
+ requestId,
1408
+ serviceName,
1409
+ };
1410
+ ioc.loggerService.log("/api/v1/view/log_one/:id ok", {
1411
+ request,
1412
+ result: omit(result, "data"),
1413
+ });
1414
+ return await micro.send(res, 200, result);
1415
+ }
1416
+ catch (error) {
1417
+ ioc.loggerService.log("/api/v1/view/log_one/:id error", {
1418
+ error: functoolsKit.errorData(error),
1419
+ });
1420
+ return await micro.send(res, 200, {
1421
+ status: "error",
1422
+ error: functoolsKit.getErrorMessage(error),
1423
+ });
1424
+ }
1425
+ });
1426
+ router$5.post("/api/v1/view/log_filter", async (req, res) => {
1427
+ try {
1428
+ const request = await micro.json(req);
1429
+ const { requestId, serviceName, filterData, limit, offset } = request;
1430
+ const data = await ioc.logViewService.findByFilter(filterData, limit, offset);
1431
+ const result = {
1432
+ data,
1433
+ status: "ok",
1434
+ error: "",
1435
+ requestId,
1436
+ serviceName,
1437
+ };
1438
+ ioc.loggerService.log("/api/v1/view/log_filter ok", {
1439
+ request,
1440
+ result: omit(result, "data"),
1441
+ });
1442
+ return await micro.send(res, 200, result);
1443
+ }
1444
+ catch (error) {
1445
+ ioc.loggerService.log("/api/v1/view/log_filter error", {
1446
+ error: functoolsKit.errorData(error),
1447
+ });
1448
+ return await micro.send(res, 200, {
1449
+ status: "error",
1450
+ error: functoolsKit.getErrorMessage(error),
1451
+ });
1452
+ }
1453
+ });
1171
1454
 
1172
1455
  const require$2 = module$1.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('index.cjs', document.baseURI).href)));
1173
1456
  function getModulesPath() {