@chevre/domain 22.11.0-alpha.2 → 22.11.0-alpha.22
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/example/src/chevre/assetTransaction/processReserve.ts +0 -1
- package/example/src/chevre/notifyAbortedTasksByEmail.ts +1 -1
- package/example/src/chevre/orders/searchWithUnwoundAcceptedOffers.ts +73 -0
- package/example/src/chevre/reIndex.ts +1 -1
- package/example/src/chevre/roles/addAdminPermissionIfNotExists.ts +132 -0
- package/example/src/chevre/roles/addDefaultPermissionIfNotExists.ts +37 -0
- package/example/src/chevre/roles/addEventOfferPermissionIfNotExists.ts +27 -0
- package/example/src/chevre/roles/addPermissionIfNotExists.ts +39 -6
- package/example/src/chevre/roles/addProjectCreatorRole.ts +48 -0
- package/example/src/chevre/roles/assignGlobalRoles.ts +72 -0
- package/example/src/chevre/roles/findPermissions.ts +84 -0
- package/example/src/chevre/roles/findRoleNames.ts +117 -0
- package/example/src/chevre/roles/removeConsolePermissionIfExists.ts +38 -0
- package/example/src/chevre/roles/removePermissionFromAPIRoles.ts +46 -0
- package/example/src/chevre/roles/removePermissionIfExists.ts +39 -0
- package/example/src/chevre/settings/addSettings.ts +23 -17
- package/example/src/chevre/stockHolder/checkRedisKeyCount.ts +11 -20
- package/example/src/chevre/unsetUnnecessaryFields.ts +8 -5
- package/example/src/idaas/auth0/adminApplications.ts +183 -0
- package/example/src/idaas/auth0/getToken.ts +55 -0
- package/example/src/idaas/auth0/getTokenByPrivateKeyJWT.ts +84 -0
- package/example/src/regex.ts +31 -0
- package/lib/chevre/eventEmitter/task.d.ts +13 -4
- package/lib/chevre/index.d.ts +0 -2
- package/lib/chevre/index.js +0 -10
- package/lib/chevre/repo/acceptedOffer.d.ts +3 -1
- package/lib/chevre/repo/acceptedOffer.js +11 -3
- package/lib/chevre/repo/confirmationNumber.d.ts +0 -11
- package/lib/chevre/repo/confirmationNumber.js +15 -54
- package/lib/chevre/repo/identity.d.ts +11 -33
- package/lib/chevre/repo/identity.js +10 -15
- package/lib/chevre/repo/member.d.ts +22 -4
- package/lib/chevre/repo/member.js +81 -27
- package/lib/chevre/repo/mongoose/schemas/identity.d.ts +1 -1
- package/lib/chevre/repo/mongoose/schemas/member/global.d.ts +14 -0
- package/lib/chevre/repo/mongoose/schemas/member/global.js +82 -0
- package/lib/chevre/repo/mongoose/schemas/setting.d.ts +11 -0
- package/lib/chevre/repo/mongoose/schemas/setting.js +1 -0
- package/lib/chevre/repo/mongoose/schemas/task.js +9 -0
- package/lib/chevre/repo/orderNumber.d.ts +0 -11
- package/lib/chevre/repo/orderNumber.js +13 -51
- package/lib/chevre/repo/role.d.ts +16 -4
- package/lib/chevre/repo/role.js +71 -32
- package/lib/chevre/repo/serviceOutputIdentifier.d.ts +0 -4
- package/lib/chevre/repo/serviceOutputIdentifier.js +13 -38
- package/lib/chevre/repo/setting.d.ts +5 -10
- package/lib/chevre/repo/setting.js +4 -7
- package/lib/chevre/repo/stockHolder.js +0 -11
- package/lib/chevre/repo/task.d.ts +38 -25
- package/lib/chevre/repo/task.js +114 -211
- package/lib/chevre/repo/transactionNumber.d.ts +0 -11
- package/lib/chevre/repo/transactionNumber.js +13 -51
- package/lib/chevre/repo/transactionNumberCounter.d.ts +0 -10
- package/lib/chevre/repo/transactionNumberCounter.js +34 -29
- package/lib/chevre/service/assetTransaction/cancelReservation/start.d.ts +1 -1
- package/lib/chevre/service/code.d.ts +5 -28
- package/lib/chevre/service/code.js +3 -79
- package/lib/chevre/service/iam.d.ts +17 -7
- package/lib/chevre/service/iam.js +26 -6
- package/lib/chevre/service/notification/notifyAbortedTasksByEmail.d.ts +15 -0
- package/lib/chevre/service/notification/notifyAbortedTasksByEmail.js +38 -0
- package/lib/chevre/service/notification.d.ts +2 -1
- package/lib/chevre/service/notification.js +3 -1
- package/lib/chevre/service/task/acceptCOAOffer.d.ts +1 -1
- package/lib/chevre/service/task/acceptCOAOffer.js +6 -5
- package/lib/chevre/service/task/aggregateOffers.d.ts +1 -1
- package/lib/chevre/service/task/aggregateOnSystem.d.ts +4 -2
- package/lib/chevre/service/task/aggregateScreeningEvent.d.ts +1 -1
- package/lib/chevre/service/task/authorizePayment.d.ts +1 -1
- package/lib/chevre/service/task/authorizePayment.js +7 -6
- package/lib/chevre/service/task/cancelMoneyTransfer.d.ts +1 -1
- package/lib/chevre/service/task/cancelPendingReservation.d.ts +1 -1
- package/lib/chevre/service/task/cancelReservation.d.ts +1 -1
- package/lib/chevre/service/task/checkMovieTicket.d.ts +1 -1
- package/lib/chevre/service/task/checkMovieTicket.js +4 -3
- package/lib/chevre/service/task/checkResource.d.ts +1 -1
- package/lib/chevre/service/task/confirmMoneyTransfer.d.ts +1 -1
- package/lib/chevre/service/task/confirmPayTransaction.d.ts +1 -1
- package/lib/chevre/service/task/confirmRegisterService.d.ts +1 -1
- package/lib/chevre/service/task/confirmRegisterServiceTransaction.d.ts +1 -1
- package/lib/chevre/service/task/confirmReserveTransaction.d.ts +1 -1
- package/lib/chevre/service/task/createAccountingReport.d.ts +1 -1
- package/lib/chevre/service/task/createEvent.d.ts +1 -1
- package/lib/chevre/service/task/deletePerson.d.ts +1 -1
- package/lib/chevre/service/task/deleteTransaction.d.ts +1 -1
- package/lib/chevre/service/task/givePointAward.d.ts +1 -1
- package/lib/chevre/service/task/givePointAward.js +1 -1
- package/lib/chevre/service/task/handleNotification.d.ts +4 -2
- package/lib/chevre/service/task/importEventCapacitiesFromCOA.d.ts +1 -1
- package/lib/chevre/service/task/importEventsFromCOA.d.ts +1 -1
- package/lib/chevre/service/task/importOffersFromCOA.d.ts +1 -1
- package/lib/chevre/service/task/invalidatePaymentUrl.d.ts +1 -1
- package/lib/chevre/service/task/moneyTransfer.d.ts +1 -1
- package/lib/chevre/service/task/moneyTransfer.js +1 -1
- package/lib/chevre/service/task/onAssetTransactionStatusChanged.d.ts +1 -1
- package/lib/chevre/service/task/onAuthorizationCreated.d.ts +1 -1
- package/lib/chevre/service/task/onEventChanged.d.ts +1 -1
- package/lib/chevre/service/task/onOrderPaymentCompleted.d.ts +1 -1
- package/lib/chevre/service/task/onResourceUpdated.d.ts +1 -1
- package/lib/chevre/service/task/pay.d.ts +1 -1
- package/lib/chevre/service/task/placeOrder.d.ts +1 -1
- package/lib/chevre/service/task/publishPaymentUrl.d.ts +1 -1
- package/lib/chevre/service/task/publishPaymentUrl.js +6 -7
- package/lib/chevre/service/task/refund.d.ts +1 -1
- package/lib/chevre/service/task/refund.js +1 -1
- package/lib/chevre/service/task/registerService.d.ts +1 -1
- package/lib/chevre/service/task/reserve.d.ts +1 -1
- package/lib/chevre/service/task/returnMoneyTransfer.d.ts +1 -1
- package/lib/chevre/service/task/returnMoneyTransfer.js +1 -1
- package/lib/chevre/service/task/returnOrder.d.ts +1 -1
- package/lib/chevre/service/task/returnPayTransaction.d.ts +1 -1
- package/lib/chevre/service/task/returnPayTransaction.js +1 -1
- package/lib/chevre/service/task/returnPointAward.d.ts +1 -1
- package/lib/chevre/service/task/returnPointAward.js +1 -1
- package/lib/chevre/service/task/returnReserveTransaction.d.ts +1 -1
- package/lib/chevre/service/task/returnReserveTransaction.js +1 -1
- package/lib/chevre/service/task/sendEmailMessage.d.ts +1 -1
- package/lib/chevre/service/task/sendOrder.d.ts +1 -1
- package/lib/chevre/service/task/triggerWebhook.d.ts +1 -1
- package/lib/chevre/service/task/useReservation.d.ts +1 -1
- package/lib/chevre/service/task/voidMoneyTransferTransaction.d.ts +1 -1
- package/lib/chevre/service/task/voidPayTransaction.d.ts +1 -1
- package/lib/chevre/service/task/voidPayment.d.ts +1 -1
- package/lib/chevre/service/task/voidRegisterServiceTransaction.d.ts +1 -1
- package/lib/chevre/service/task/voidReserveTransaction.d.ts +1 -1
- package/lib/chevre/service/task/voidReserveTransaction.js +4 -3
- package/lib/chevre/service/task.d.ts +1 -23
- package/lib/chevre/service/task.js +3 -110
- package/lib/chevre/service/taskHandler.d.ts +26 -0
- package/lib/chevre/service/taskHandler.js +139 -0
- package/lib/chevre/service/validation/validateOrder.js +55 -37
- package/lib/chevre/service.d.ts +0 -4
- package/lib/chevre/service.js +10 -14
- package/lib/chevre/settings/aggregation.d.ts +6 -1
- package/lib/chevre/settings/aggregation.js +2 -1
- package/package.json +5 -3
- package/example/src/chevre/adminAuth/adminIdentity.ts +0 -38
- package/example/src/chevre/findExecutableTask.ts +0 -50
- package/example/src/chevre/findSetting.ts +0 -79
- package/example/src/chevre/roles/addRoleMembers.ts +0 -75
- package/example/src/chevre/searchPermissions.ts +0 -46
- package/example/src/chevre/transactionNumber/publishConfimationNumber.ts +0 -37
- package/example/src/chevre/transactionNumber/publishOrderNumber.ts +0 -40
- package/example/src/chevre/transactionNumber/setUseMongo4confirmationNumberFrom.ts +0 -45
- package/example/src/chevre/transactionNumber/setUseMongo4orderNumberFrom.ts +0 -41
- package/example/src/chevre/transactionNumber/setUseMongo4transactionNumberFrom.ts +0 -41
- package/lib/chevre/adminAuth.d.ts +0 -2
- package/lib/chevre/adminAuth.js +0 -6
package/lib/chevre/repo/task.js
CHANGED
|
@@ -242,48 +242,6 @@ class TaskRepo {
|
|
|
242
242
|
return { id, status };
|
|
243
243
|
});
|
|
244
244
|
}
|
|
245
|
-
// public async createIfNotExistByIdentifier(
|
|
246
|
-
// params: factory.task.IAttributes<factory.taskName> & {
|
|
247
|
-
// // resolve uniqueness of identifier(2025-03-27~)
|
|
248
|
-
// identifier: string;
|
|
249
|
-
// },
|
|
250
|
-
// options: IOptionOnCreate
|
|
251
|
-
// ): Promise<void> {
|
|
252
|
-
// if (typeof params.identifier !== 'string' || params.identifier.length === 0) {
|
|
253
|
-
// throw new factory.errors.ArgumentNull('identifier');
|
|
254
|
-
// }
|
|
255
|
-
// try {
|
|
256
|
-
// const createdTask = await this.taskModel.findOneAndUpdate(
|
|
257
|
-
// {
|
|
258
|
-
// 'project.id': { $eq: params.project.id },
|
|
259
|
-
// name: { $eq: params.name },
|
|
260
|
-
// identifier: { $exists: true, $eq: params.identifier }
|
|
261
|
-
// },
|
|
262
|
-
// { $setOnInsert: params },
|
|
263
|
-
// { new: true, upsert: true }
|
|
264
|
-
// )
|
|
265
|
-
// .select({ _id: 1 })
|
|
266
|
-
// .exec();
|
|
267
|
-
// if (options.emitImmediately) {
|
|
268
|
-
// taskEventEmitter.emitTaskStatusChanged({
|
|
269
|
-
// id: createdTask.id,
|
|
270
|
-
// name: params.name,
|
|
271
|
-
// status: factory.taskStatus.Ready
|
|
272
|
-
// });
|
|
273
|
-
// }
|
|
274
|
-
// } catch (error) {
|
|
275
|
-
// let throwsError = true;
|
|
276
|
-
// if (await isMongoError(error)) {
|
|
277
|
-
// // すでにidentifierが存在する場合ok
|
|
278
|
-
// if (error.code === MongoErrorCode.DuplicateKey) {
|
|
279
|
-
// throwsError = false;
|
|
280
|
-
// }
|
|
281
|
-
// }
|
|
282
|
-
// if (throwsError) {
|
|
283
|
-
// throw error;
|
|
284
|
-
// }
|
|
285
|
-
// }
|
|
286
|
-
// }
|
|
287
245
|
/**
|
|
288
246
|
* タスク識別子から冪等作成する
|
|
289
247
|
* reimplement createIfNotExistByIdentifier(2025-03-28~)
|
|
@@ -341,40 +299,6 @@ class TaskRepo {
|
|
|
341
299
|
}
|
|
342
300
|
});
|
|
343
301
|
}
|
|
344
|
-
// public async createInformTaskIfNotExist(
|
|
345
|
-
// // resolve uniqueness of identifier(2025-03-27~)
|
|
346
|
-
// params: Pick<
|
|
347
|
-
// factory.task.IAttributes<factory.taskName.TriggerWebhook>,
|
|
348
|
-
// 'data' | 'executionResults' | 'name' | 'numberOfTried' | 'project' | 'remainingNumberOfTries' | 'runsAt' | 'status'
|
|
349
|
-
// > & {
|
|
350
|
-
// data: factory.task.triggerWebhook.IInformAnyResourceAction & {
|
|
351
|
-
// object: factory.notification.person.IPersonAsNotification;
|
|
352
|
-
// };
|
|
353
|
-
// },
|
|
354
|
-
// options: IOptionOnCreate
|
|
355
|
-
// ): Promise<void> {
|
|
356
|
-
// const createdTask = await this.taskModel.findOneAndUpdate(
|
|
357
|
-
// {
|
|
358
|
-
// 'project.id': { $eq: params.project.id },
|
|
359
|
-
// name: params.name,
|
|
360
|
-
// 'data.object.id': {
|
|
361
|
-
// $exists: true,
|
|
362
|
-
// $eq: String(params.data.object.id)
|
|
363
|
-
// }
|
|
364
|
-
// },
|
|
365
|
-
// { $setOnInsert: params },
|
|
366
|
-
// { new: true, upsert: true }
|
|
367
|
-
// )
|
|
368
|
-
// .select({ _id: 1 })
|
|
369
|
-
// .exec();
|
|
370
|
-
// if (options.emitImmediately) {
|
|
371
|
-
// taskEventEmitter.emitTaskStatusChanged({
|
|
372
|
-
// id: createdTask.id,
|
|
373
|
-
// name: params.name,
|
|
374
|
-
// status: factory.taskStatus.Ready
|
|
375
|
-
// });
|
|
376
|
-
// }
|
|
377
|
-
// }
|
|
378
302
|
/**
|
|
379
303
|
* 取引削除タスク冪等作成
|
|
380
304
|
*/
|
|
@@ -401,36 +325,6 @@ class TaskRepo {
|
|
|
401
325
|
}
|
|
402
326
|
});
|
|
403
327
|
}
|
|
404
|
-
// public async createConfirmReserveTransactionTaskIfNotExist(
|
|
405
|
-
// params: factory.task.IAttributes<factory.taskName.ConfirmReserveTransaction>,
|
|
406
|
-
// options: IOptionOnCreate
|
|
407
|
-
// ): Promise<void> {
|
|
408
|
-
// const createdTask = await this.taskModel.findOneAndUpdate(
|
|
409
|
-
// {
|
|
410
|
-
// 'project.id': { $eq: params.project.id },
|
|
411
|
-
// name: { $eq: params.name },
|
|
412
|
-
// 'data.object.transactionNumber': {
|
|
413
|
-
// $exists: true,
|
|
414
|
-
// $eq: String(params.data.object.transactionNumber)
|
|
415
|
-
// },
|
|
416
|
-
// 'data.purpose.orderNumber': {
|
|
417
|
-
// $exists: true,
|
|
418
|
-
// $eq: String(params.data.purpose.orderNumber)
|
|
419
|
-
// }
|
|
420
|
-
// },
|
|
421
|
-
// { $setOnInsert: params },
|
|
422
|
-
// { new: true, upsert: true }
|
|
423
|
-
// )
|
|
424
|
-
// .select({ _id: 1 })
|
|
425
|
-
// .exec();
|
|
426
|
-
// if (options.emitImmediately) {
|
|
427
|
-
// taskEventEmitter.emitTaskStatusChanged({
|
|
428
|
-
// id: createdTask.id,
|
|
429
|
-
// name: params.name,
|
|
430
|
-
// status: factory.taskStatus.Ready
|
|
431
|
-
// });
|
|
432
|
-
// }
|
|
433
|
-
// }
|
|
434
328
|
createOnAssetTransactionStatusChangedTaskIfNotExist(
|
|
435
329
|
// resolve uniqueness of identifier(2025-03-27~)
|
|
436
330
|
params, options) {
|
|
@@ -458,6 +352,10 @@ class TaskRepo {
|
|
|
458
352
|
}
|
|
459
353
|
});
|
|
460
354
|
}
|
|
355
|
+
/**
|
|
356
|
+
* Ready -> remainingNumberOfTriesが1減る
|
|
357
|
+
* Running -> findOneするだけ
|
|
358
|
+
*/
|
|
461
359
|
executeOneById(params) {
|
|
462
360
|
return __awaiter(this, void 0, void 0, function* () {
|
|
463
361
|
const now = new Date();
|
|
@@ -492,7 +390,7 @@ class TaskRepo {
|
|
|
492
390
|
});
|
|
493
391
|
}
|
|
494
392
|
/**
|
|
495
|
-
*
|
|
393
|
+
* Readyのタスクをname指定でひとつRunningに変更する
|
|
496
394
|
*/
|
|
497
395
|
executeOneIfExists(params) {
|
|
498
396
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -552,7 +450,11 @@ class TaskRepo {
|
|
|
552
450
|
return { count };
|
|
553
451
|
});
|
|
554
452
|
}
|
|
555
|
-
|
|
453
|
+
/**
|
|
454
|
+
* 実行日時を一定期間過ぎたReadyタスクについて、Runningスタータスに変更した上で、Runningイベントを発生させる
|
|
455
|
+
*/
|
|
456
|
+
emitRunningIfExists(params, next // support next function(2025-08-02~)
|
|
457
|
+
) {
|
|
556
458
|
return __awaiter(this, void 0, void 0, function* () {
|
|
557
459
|
var _a, _b;
|
|
558
460
|
if (!(params.runsAt.$lt instanceof Date)) {
|
|
@@ -591,40 +493,55 @@ class TaskRepo {
|
|
|
591
493
|
task_1.taskEventEmitter.emitTaskStatusChanged({
|
|
592
494
|
id: doc.id,
|
|
593
495
|
status: factory.taskStatus.Running
|
|
594
|
-
});
|
|
595
|
-
return doc;
|
|
596
|
-
});
|
|
597
|
-
}
|
|
598
|
-
findExecutableOne(params) {
|
|
599
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
600
|
-
var _a, _b;
|
|
601
|
-
if (!(params.runsAt.$lt instanceof Date)) {
|
|
602
|
-
throw new factory.errors.Argument('runsAt.$lt', 'must be Date');
|
|
603
|
-
}
|
|
604
|
-
const nameEq = (_a = params.name) === null || _a === void 0 ? void 0 : _a.$eq;
|
|
605
|
-
const nameNin = (_b = params.name) === null || _b === void 0 ? void 0 : _b.$nin;
|
|
606
|
-
const query = this.taskModel.findOne(Object.assign({ status: { $eq: factory.taskStatus.Ready }, runsAt: { $lt: params.runsAt.$lt } }, (typeof nameEq === 'string' || Array.isArray(nameNin))
|
|
607
|
-
? {
|
|
608
|
-
name: Object.assign(Object.assign({}, (typeof nameEq === 'string') ? { $eq: nameEq } : undefined), (Array.isArray(nameNin)) ? { $nin: nameNin } : undefined)
|
|
609
|
-
}
|
|
610
|
-
: undefined), executableTaskProjection)
|
|
611
|
-
.sort({
|
|
612
|
-
runsAt: factory.sortType.Ascending
|
|
613
|
-
});
|
|
614
|
-
// .hint('executeOneByName');
|
|
615
|
-
// const explainResult = await query.explain();
|
|
616
|
-
// console.dir(explainResult, { depth: null });
|
|
617
|
-
// console.log(explainResult[0].executionStats.allPlansExecution.map((e: any) => e.executionStages.inputStage));
|
|
618
|
-
const doc = yield query.setOptions({ maxTimeMS: settings_1.MONGO_MAX_TIME_MS })
|
|
619
|
-
.lean()
|
|
620
|
-
.exec();
|
|
621
|
-
if (doc === null) {
|
|
622
|
-
// tslint:disable-next-line:no-null-keyword
|
|
623
|
-
return null;
|
|
624
|
-
}
|
|
496
|
+
}, (typeof next === 'function') ? next : undefined);
|
|
625
497
|
return doc;
|
|
626
498
|
});
|
|
627
499
|
}
|
|
500
|
+
// public async findExecutableOne(params: {
|
|
501
|
+
// name?: {
|
|
502
|
+
// $eq?: factory.taskName;
|
|
503
|
+
// $nin?: factory.taskName[];
|
|
504
|
+
// };
|
|
505
|
+
// runsAt: {
|
|
506
|
+
// $lt: Date;
|
|
507
|
+
// };
|
|
508
|
+
// }): Promise<IExecutableTask<factory.taskName> | null> {
|
|
509
|
+
// if (!(params.runsAt.$lt instanceof Date)) {
|
|
510
|
+
// throw new factory.errors.Argument('runsAt.$lt', 'must be Date');
|
|
511
|
+
// }
|
|
512
|
+
// const nameEq = params.name?.$eq;
|
|
513
|
+
// const nameNin = params.name?.$nin;
|
|
514
|
+
// const query = this.taskModel.findOne(
|
|
515
|
+
// {
|
|
516
|
+
// status: { $eq: factory.taskStatus.Ready },
|
|
517
|
+
// runsAt: { $lt: params.runsAt.$lt },
|
|
518
|
+
// ...(typeof nameEq === 'string' || Array.isArray(nameNin))
|
|
519
|
+
// ? {
|
|
520
|
+
// name: {
|
|
521
|
+
// ...(typeof nameEq === 'string') ? { $eq: nameEq } : undefined,
|
|
522
|
+
// ...(Array.isArray(nameNin)) ? { $nin: nameNin } : undefined
|
|
523
|
+
// }
|
|
524
|
+
// }
|
|
525
|
+
// : undefined
|
|
526
|
+
// },
|
|
527
|
+
// executableTaskProjection
|
|
528
|
+
// )
|
|
529
|
+
// .sort({
|
|
530
|
+
// runsAt: factory.sortType.Ascending
|
|
531
|
+
// });
|
|
532
|
+
// // .hint('executeOneByName');
|
|
533
|
+
// // const explainResult = await query.explain();
|
|
534
|
+
// // console.dir(explainResult, { depth: null });
|
|
535
|
+
// // console.log(explainResult[0].executionStats.allPlansExecution.map((e: any) => e.executionStages.inputStage));
|
|
536
|
+
// const doc = await query.setOptions({ maxTimeMS: MONGO_MAX_TIME_MS })
|
|
537
|
+
// .lean<IExecutableTask<factory.taskName>>()
|
|
538
|
+
// .exec();
|
|
539
|
+
// if (doc === null) {
|
|
540
|
+
// // tslint:disable-next-line:no-null-keyword
|
|
541
|
+
// return null;
|
|
542
|
+
// }
|
|
543
|
+
// return doc;
|
|
544
|
+
// }
|
|
628
545
|
// discontinue(2025-05-26~)
|
|
629
546
|
/**
|
|
630
547
|
* emit OnTaskStatusChanged on delayed tasks
|
|
@@ -682,7 +599,7 @@ class TaskRepo {
|
|
|
682
599
|
// return delayedTasks;
|
|
683
600
|
// }
|
|
684
601
|
/**
|
|
685
|
-
*
|
|
602
|
+
* Readyのままで期限切れのタスクをExpiredに変更する
|
|
686
603
|
*/
|
|
687
604
|
makeExpiredMany(params) {
|
|
688
605
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -702,21 +619,23 @@ class TaskRepo {
|
|
|
702
619
|
});
|
|
703
620
|
}
|
|
704
621
|
/**
|
|
705
|
-
*
|
|
622
|
+
* Runningのまま一定期間超過し、かつ、remainingNumberOfTries>0のタスクをReadyに変更する
|
|
706
623
|
*/
|
|
707
|
-
|
|
624
|
+
retryMany(params) {
|
|
708
625
|
return __awaiter(this, void 0, void 0, function* () {
|
|
709
626
|
const lastTriedAtShoudBeLessThan = moment()
|
|
710
627
|
.add(-params.intervalInMinutes, 'minutes')
|
|
711
628
|
.toDate();
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
629
|
+
const remainingNumberOfTriesGte = params.remainingNumberOfTries.$gte;
|
|
630
|
+
const remainingNumberOfTriesLte = params.remainingNumberOfTries.$lte;
|
|
631
|
+
return this.taskModel.updateMany(Object.assign(Object.assign(Object.assign({ status: { $eq: factory.taskStatus.Running }, lastTriedAt: {
|
|
715
632
|
$type: 'date',
|
|
716
633
|
$lt: lastTriedAtShoudBeLessThan
|
|
717
|
-
},
|
|
718
|
-
remainingNumberOfTries: { $
|
|
719
|
-
|
|
634
|
+
} }, (typeof remainingNumberOfTriesGte === 'number')
|
|
635
|
+
? { remainingNumberOfTries: { $gte: remainingNumberOfTriesGte } }
|
|
636
|
+
: undefined), (typeof remainingNumberOfTriesLte === 'number')
|
|
637
|
+
? { remainingNumberOfTries: { $lte: remainingNumberOfTriesLte } }
|
|
638
|
+
: undefined), (Array.isArray(params.name.$in)) ? { name: { $in: params.name.$in } } : undefined), {
|
|
720
639
|
$set: {
|
|
721
640
|
status: factory.taskStatus.Ready // 実行前に変更
|
|
722
641
|
}
|
|
@@ -744,47 +663,51 @@ class TaskRepo {
|
|
|
744
663
|
.exec();
|
|
745
664
|
});
|
|
746
665
|
}
|
|
747
|
-
abortOne(params
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
666
|
+
// public async abortOne(params: {
|
|
667
|
+
// intervalInMinutes: number;
|
|
668
|
+
// }): Promise<factory.task.ITask<factory.taskName> | null> {
|
|
669
|
+
// const lastTriedAtShoudBeLessThan = moment()
|
|
670
|
+
// .add(-params.intervalInMinutes, 'minutes')
|
|
671
|
+
// .toDate();
|
|
672
|
+
// const projection: ProjectionType<factory.task.ITask<factory.taskName>> = {
|
|
673
|
+
// _id: 0,
|
|
674
|
+
// id: { $toString: '$_id' },
|
|
675
|
+
// ...Object.fromEntries<1>(AVAILABLE_PROJECT_FIELDS.map((key) => ([key, 1])))
|
|
676
|
+
// };
|
|
677
|
+
// const doc = await this.taskModel.findOneAndUpdate(
|
|
678
|
+
// {
|
|
679
|
+
// status: { $eq: factory.taskStatus.Running },
|
|
680
|
+
// lastTriedAt: {
|
|
681
|
+
// $type: 'date',
|
|
682
|
+
// $lt: lastTriedAtShoudBeLessThan
|
|
683
|
+
// },
|
|
684
|
+
// remainingNumberOfTries: { $eq: 0 }
|
|
685
|
+
// },
|
|
686
|
+
// {
|
|
687
|
+
// $set: {
|
|
688
|
+
// status: factory.taskStatus.Aborted,
|
|
689
|
+
// dateAborted: new Date()
|
|
690
|
+
// }
|
|
691
|
+
// },
|
|
692
|
+
// { new: true, projection }
|
|
693
|
+
// )
|
|
694
|
+
// .lean<factory.task.ITask<factory.taskName>>() // lean(2024-09-26~)
|
|
695
|
+
// .exec();
|
|
696
|
+
// if (doc === null) {
|
|
697
|
+
// // tslint:disable-next-line:no-null-keyword
|
|
698
|
+
// return null;
|
|
699
|
+
// }
|
|
700
|
+
// return doc;
|
|
701
|
+
// }
|
|
775
702
|
abortMany(params) {
|
|
776
703
|
return __awaiter(this, void 0, void 0, function* () {
|
|
777
704
|
const lastTriedAtShoudBeLessThan = moment()
|
|
778
705
|
.add(-params.intervalInMinutes, 'minutes')
|
|
779
706
|
.toDate();
|
|
780
|
-
return this.taskModel.updateMany({
|
|
781
|
-
status: { $eq: factory.taskStatus.Running },
|
|
782
|
-
lastTriedAt: {
|
|
707
|
+
return this.taskModel.updateMany(Object.assign({ status: { $eq: factory.taskStatus.Running }, lastTriedAt: {
|
|
783
708
|
$type: 'date',
|
|
784
709
|
$lt: lastTriedAtShoudBeLessThan
|
|
785
|
-
},
|
|
786
|
-
remainingNumberOfTries: { $eq: 0 }
|
|
787
|
-
}, {
|
|
710
|
+
}, remainingNumberOfTries: { $eq: 0 } }, (Array.isArray(params.name.$in)) ? { name: { $in: params.name.$in } } : undefined), {
|
|
788
711
|
$set: {
|
|
789
712
|
status: factory.taskStatus.Aborted,
|
|
790
713
|
dateAborted: new Date()
|
|
@@ -794,48 +717,28 @@ class TaskRepo {
|
|
|
794
717
|
});
|
|
795
718
|
}
|
|
796
719
|
/**
|
|
797
|
-
*
|
|
720
|
+
* タスクIDから実行結果とステータスを保管する
|
|
721
|
+
* Abortedの場合、dateAbortedもセットする
|
|
798
722
|
*/
|
|
799
|
-
|
|
723
|
+
setExecutionResultAndStatus(params, update,
|
|
800
724
|
// support customr function(2025-05-25~)
|
|
801
725
|
next) {
|
|
802
726
|
return __awaiter(this, void 0, void 0, function* () {
|
|
803
|
-
const { id,
|
|
727
|
+
const { id, remainingNumberOfTries, name } = params;
|
|
728
|
+
const { status, executionResult } = update;
|
|
804
729
|
yield this.taskModel.updateOne({ _id: { $eq: id } }, {
|
|
805
|
-
$set: { status },
|
|
730
|
+
$set: Object.assign({ status }, (status === factory.taskStatus.Aborted) ? { dateAborted: executionResult.endDate } : undefined // 2025-08-04~
|
|
731
|
+
),
|
|
806
732
|
$push: { executionResults: executionResult }
|
|
807
733
|
})
|
|
808
734
|
.exec();
|
|
809
735
|
// emit event(2025-05-26~)
|
|
810
736
|
if (typeof next === 'function') {
|
|
811
|
-
|
|
737
|
+
const changedTask = { id, name, status, remainingNumberOfTries, executionResult };
|
|
738
|
+
task_1.taskEventEmitter.emitTaskStatusChanged(changedTask, next);
|
|
812
739
|
}
|
|
813
740
|
});
|
|
814
741
|
}
|
|
815
|
-
/**
|
|
816
|
-
* 特定タスク検索
|
|
817
|
-
*/
|
|
818
|
-
// public async findById<T extends factory.taskName>(params: {
|
|
819
|
-
// name: T;
|
|
820
|
-
// id: string;
|
|
821
|
-
// }): Promise<factory.task.ITask<T>> {
|
|
822
|
-
// const doc = await this.taskModel.findOne(
|
|
823
|
-
// {
|
|
824
|
-
// name: { $eq: params.name },
|
|
825
|
-
// _id: { $eq: params.id }
|
|
826
|
-
// },
|
|
827
|
-
// {
|
|
828
|
-
// __v: 0,
|
|
829
|
-
// createdAt: 0,
|
|
830
|
-
// updatedAt: 0
|
|
831
|
-
// }
|
|
832
|
-
// )
|
|
833
|
-
// .exec();
|
|
834
|
-
// if (doc === null) {
|
|
835
|
-
// throw new factory.errors.NotFound('Task');
|
|
836
|
-
// }
|
|
837
|
-
// return doc.toObject();
|
|
838
|
-
// }
|
|
839
742
|
count(params) {
|
|
840
743
|
return __awaiter(this, void 0, void 0, function* () {
|
|
841
744
|
const { limit } = params;
|
|
@@ -1,6 +1,4 @@
|
|
|
1
1
|
import type { Connection } from 'mongoose';
|
|
2
|
-
import { RedisClientType } from 'redis';
|
|
3
|
-
import { ISetting } from './mongoose/schemas/setting';
|
|
4
2
|
interface IPublishResult {
|
|
5
3
|
transactionNumber: string;
|
|
6
4
|
}
|
|
@@ -8,10 +6,8 @@ interface IPublishResult {
|
|
|
8
6
|
* 取引番号リポジトリ
|
|
9
7
|
*/
|
|
10
8
|
export declare class TransactionNumberRepo {
|
|
11
|
-
private readonly settingModel;
|
|
12
9
|
private readonly counterRepo;
|
|
13
10
|
constructor(params: {
|
|
14
|
-
redisClient: RedisClientType;
|
|
15
11
|
connection: Connection;
|
|
16
12
|
});
|
|
17
13
|
/**
|
|
@@ -20,12 +16,5 @@ export declare class TransactionNumberRepo {
|
|
|
20
16
|
publishByTimestamp(params: {
|
|
21
17
|
startDate: Date;
|
|
22
18
|
}): Promise<IPublishResult>;
|
|
23
|
-
/**
|
|
24
|
-
* DB移行時のみに使用目的の設定更新
|
|
25
|
-
*/
|
|
26
|
-
setUseMongo4transactionNumberFrom(params: {
|
|
27
|
-
useMongo4transactionNumberFrom: Date;
|
|
28
|
-
}): Promise<Pick<ISetting, "useMongo4transactionNumberFrom"> | null>;
|
|
29
|
-
private useMongoBySettings;
|
|
30
19
|
}
|
|
31
20
|
export {};
|
|
@@ -12,9 +12,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
12
12
|
exports.TransactionNumberRepo = void 0;
|
|
13
13
|
const cdigit = require("cdigit");
|
|
14
14
|
const moment = require("moment-timezone");
|
|
15
|
+
// import { RedisClientType } from 'redis';
|
|
15
16
|
// tslint:disable-next-line:no-require-imports no-var-requires
|
|
16
17
|
const fpe = require('node-fpe');
|
|
17
|
-
|
|
18
|
+
// import { createSchema as createSettingSchema, modelName as settingModelName } from './mongoose/schemas/setting';
|
|
18
19
|
const transactionNumber_1 = require("./mongoose/schemas/transactionNumber");
|
|
19
20
|
const transactionNumberCounter_1 = require("./transactionNumberCounter");
|
|
20
21
|
/**
|
|
@@ -22,8 +23,8 @@ const transactionNumberCounter_1 = require("./transactionNumberCounter");
|
|
|
22
23
|
*/
|
|
23
24
|
class TransactionNumberRepo {
|
|
24
25
|
constructor(params) {
|
|
25
|
-
const { connection } = params;
|
|
26
|
-
this.settingModel = connection.model(
|
|
26
|
+
// const { connection } = params;
|
|
27
|
+
// this.settingModel = connection.model(settingModelName, createSettingSchema());
|
|
27
28
|
this.counterRepo = new transactionNumberCounter_1.TransactionNumberCounterRepo(params);
|
|
28
29
|
}
|
|
29
30
|
// private static createKey(params: {
|
|
@@ -47,27 +48,15 @@ class TransactionNumberRepo {
|
|
|
47
48
|
let dataFeedExpires;
|
|
48
49
|
const dataFeedIdentifier = timestamp;
|
|
49
50
|
let incrReply;
|
|
50
|
-
const useMongoBySettings =
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
});
|
|
60
|
-
}
|
|
61
|
-
else {
|
|
62
|
-
dataFeedExpires = moment(params.startDate)
|
|
63
|
-
.add(1, 'minute') // ミリ秒でカウントしていくので、予約日時後1分で十分
|
|
64
|
-
.toDate();
|
|
65
|
-
incrReply = yield this.counterRepo.incrementByRedis({
|
|
66
|
-
identifier: dataFeedIdentifier,
|
|
67
|
-
includedInDataCatalog: { identifier: transactionNumber_1.DataCatalogIdentifier.transactionNumber },
|
|
68
|
-
expires: dataFeedExpires
|
|
69
|
-
});
|
|
70
|
-
}
|
|
51
|
+
// const useMongoBySettings = await this.useMongoBySettings(params);
|
|
52
|
+
dataFeedExpires = moment(params.startDate)
|
|
53
|
+
.add(1, 'minute') // ミリ秒でカウントしていくので、予約日時後1分で十分
|
|
54
|
+
.toDate();
|
|
55
|
+
incrReply = yield this.counterRepo.incrementByMongo({
|
|
56
|
+
identifier: dataFeedIdentifier,
|
|
57
|
+
includedInDataCatalog: { identifier: transactionNumber_1.DataCatalogIdentifier.transactionNumber },
|
|
58
|
+
expires: dataFeedExpires
|
|
59
|
+
});
|
|
71
60
|
let transactionNumber = `${timestamp}${incrReply}`;
|
|
72
61
|
// checkdigit
|
|
73
62
|
const cd = cdigit.luhn.compute(transactionNumber);
|
|
@@ -77,32 +66,5 @@ class TransactionNumberRepo {
|
|
|
77
66
|
return { transactionNumber };
|
|
78
67
|
});
|
|
79
68
|
}
|
|
80
|
-
/**
|
|
81
|
-
* DB移行時のみに使用目的の設定更新
|
|
82
|
-
*/
|
|
83
|
-
setUseMongo4transactionNumberFrom(params) {
|
|
84
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
85
|
-
const { useMongo4transactionNumberFrom } = params;
|
|
86
|
-
return this.settingModel.findOneAndUpdate({ 'project.id': { $eq: '*' } }, {
|
|
87
|
-
$set: { useMongo4transactionNumberFrom }
|
|
88
|
-
}, { projection: { _id: 0, useMongo4transactionNumberFrom: 1 } })
|
|
89
|
-
.lean()
|
|
90
|
-
.exec();
|
|
91
|
-
});
|
|
92
|
-
}
|
|
93
|
-
useMongoBySettings(params) {
|
|
94
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
95
|
-
const setting = yield this.settingModel.findOne({ 'project.id': { $eq: '*' } }, {
|
|
96
|
-
_id: 0,
|
|
97
|
-
useMongo4transactionNumberFrom: 1
|
|
98
|
-
})
|
|
99
|
-
.lean()
|
|
100
|
-
.exec();
|
|
101
|
-
const useMongo4transactionNumberFrom = setting === null || setting === void 0 ? void 0 : setting.useMongo4transactionNumberFrom;
|
|
102
|
-
return useMongo4transactionNumberFrom instanceof Date
|
|
103
|
-
&& moment(params.startDate)
|
|
104
|
-
.isSameOrAfter(moment(useMongo4transactionNumberFrom));
|
|
105
|
-
});
|
|
106
|
-
}
|
|
107
69
|
}
|
|
108
70
|
exports.TransactionNumberRepo = TransactionNumberRepo;
|
|
@@ -1,23 +1,13 @@
|
|
|
1
1
|
import type { Connection } from 'mongoose';
|
|
2
|
-
import { RedisClientType } from 'redis';
|
|
3
2
|
import { DataCatalogIdentifier } from './mongoose/schemas/transactionNumber';
|
|
4
3
|
/**
|
|
5
4
|
* 取引番号カウンターリポジトリ
|
|
6
5
|
*/
|
|
7
6
|
export declare class TransactionNumberCounterRepo {
|
|
8
|
-
private readonly redisClient;
|
|
9
7
|
private readonly transactionNumberModel;
|
|
10
8
|
constructor(params: {
|
|
11
|
-
redisClient: RedisClientType;
|
|
12
9
|
connection: Connection;
|
|
13
10
|
});
|
|
14
|
-
incrementByRedis(params: {
|
|
15
|
-
identifier: string;
|
|
16
|
-
includedInDataCatalog: {
|
|
17
|
-
identifier: DataCatalogIdentifier;
|
|
18
|
-
};
|
|
19
|
-
expires: Date;
|
|
20
|
-
}): Promise<number>;
|
|
21
11
|
incrementByMongo(params: {
|
|
22
12
|
identifier: string;
|
|
23
13
|
includedInDataCatalog: {
|
|
@@ -10,6 +10,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.TransactionNumberCounterRepo = void 0;
|
|
13
|
+
// import { RedisClientType } from 'redis';
|
|
13
14
|
const errorHandler_1 = require("../errorHandler");
|
|
14
15
|
const factory = require("../factory");
|
|
15
16
|
const transactionNumber_1 = require("./mongoose/schemas/transactionNumber");
|
|
@@ -19,37 +20,41 @@ const MAX_RETRY_INCREMENT = 1;
|
|
|
19
20
|
*/
|
|
20
21
|
class TransactionNumberCounterRepo {
|
|
21
22
|
constructor(params) {
|
|
22
|
-
const {
|
|
23
|
-
this.redisClient = redisClient;
|
|
23
|
+
const { connection } = params;
|
|
24
|
+
// this.redisClient = redisClient;
|
|
24
25
|
this.transactionNumberModel = connection.model(transactionNumber_1.modelName, (0, transactionNumber_1.createSchema)());
|
|
25
26
|
}
|
|
26
|
-
incrementByRedis(params
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
27
|
+
// public async incrementByRedis(params: {
|
|
28
|
+
// identifier: string;
|
|
29
|
+
// includedInDataCatalog: {
|
|
30
|
+
// identifier: DataCatalogIdentifier;
|
|
31
|
+
// };
|
|
32
|
+
// expires: Date;
|
|
33
|
+
// }): Promise<number> {
|
|
34
|
+
// // const now = moment();
|
|
35
|
+
// const { expires } = params;
|
|
36
|
+
// const key = `${params.includedInDataCatalog.identifier}:${params.identifier}`;
|
|
37
|
+
// // const TTL = moment(expires)
|
|
38
|
+
// // .diff(now, 'seconds');
|
|
39
|
+
// const [incrReply, expireAtReply] = await this.redisClient.multi()
|
|
40
|
+
// .incr(key)
|
|
41
|
+
// // .expire(key, TTL)
|
|
42
|
+
// .expireAt(key, expires)
|
|
43
|
+
// .exec();
|
|
44
|
+
// // tslint:disable-next-line:no-single-line-block-comment
|
|
45
|
+
// /* istanbul ignore else: please write tests */
|
|
46
|
+
// if (typeof incrReply !== 'number') {
|
|
47
|
+
// // 基本的にありえないフロー
|
|
48
|
+
// throw new factory.errors.Internal('transaction number not incremented unexpectedly');
|
|
49
|
+
// }
|
|
50
|
+
// // expireAtReplyの検証も追加する(2023-04-19~)
|
|
51
|
+
// const expiredSet = expireAtReply === 1 || <any>expireAtReply === true;
|
|
52
|
+
// if (!expiredSet) {
|
|
53
|
+
// // 基本的にありえないフロー
|
|
54
|
+
// throw new factory.errors.Internal('transaction number expiration not set unexpectedly');
|
|
55
|
+
// }
|
|
56
|
+
// return incrReply;
|
|
57
|
+
// }
|
|
53
58
|
incrementByMongo(params) {
|
|
54
59
|
return __awaiter(this, void 0, void 0, function* () {
|
|
55
60
|
var _a;
|