@chevre/domain 26.0.0-alpha.0 → 26.0.0-alpha.10

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.
Files changed (59) hide show
  1. package/lib/chevre/repo/adminAsyncAction.d.ts +19 -0
  2. package/lib/chevre/repo/adminAsyncAction.js +86 -0
  3. package/lib/chevre/repo/adminScheduledTask.d.ts +20 -0
  4. package/lib/chevre/repo/adminScheduledTask.js +95 -0
  5. package/lib/chevre/repo/aggregateScheduledTask.d.ts +32 -0
  6. package/lib/chevre/repo/aggregateScheduledTask.js +136 -0
  7. package/lib/chevre/repo/asyncAction.d.ts +3 -8
  8. package/lib/chevre/repo/asyncAction.js +0 -108
  9. package/lib/chevre/repo/asyncActionLegacy.d.ts +23 -0
  10. package/lib/chevre/repo/asyncActionLegacy.js +59 -0
  11. package/lib/chevre/repo/mongoose/schemas/setting.d.ts +2 -4
  12. package/lib/chevre/repo/scheduledTask.d.ts +1 -1
  13. package/lib/chevre/repo/scheduledTaskLegacy.d.ts +39 -0
  14. package/lib/chevre/repo/scheduledTaskLegacy.js +96 -0
  15. package/lib/chevre/repo/scheduledTaskMigration.d.ts +21 -0
  16. package/lib/chevre/repo/scheduledTaskMigration.js +70 -0
  17. package/lib/chevre/repo/task.d.ts +35 -68
  18. package/lib/chevre/repo/task.js +257 -177
  19. package/lib/chevre/repository.d.ts +25 -0
  20. package/lib/chevre/repository.js +57 -2
  21. package/lib/chevre/service/aggregation/system.d.ts +10 -2
  22. package/lib/chevre/service/aggregation/system.js +42 -0
  23. package/lib/chevre/service/assetTransaction/reserve/start/factory/createStartParams.js +5 -25
  24. package/lib/chevre/service/offer/eventServiceByCOA/authorize/factory.js +1 -1
  25. package/lib/chevre/service/offer/eventServiceByCOA/findAcceptAction.d.ts +0 -4
  26. package/lib/chevre/service/offer/eventServiceByCOA/findAcceptAction.js +19 -19
  27. package/lib/chevre/service/order/onOrderStatusChanged/onOrderInTransit.js +2 -2
  28. package/lib/chevre/service/order/onOrderStatusChanged/onOrderPaymentDue.js +1 -1
  29. package/lib/chevre/service/order/onOrderStatusChanged/onOrderProcessing/createSendEmailMessageTaskIfNotExist.js +1 -1
  30. package/lib/chevre/service/order/onOrderStatusChanged/onOrderProcessing/processOrder.js +1 -1
  31. package/lib/chevre/service/order/onOrderStatusChanged/onOrderProcessing.js +1 -1
  32. package/lib/chevre/service/payment/any/findAcceptAction.d.ts +0 -4
  33. package/lib/chevre/service/payment/any/findAcceptAction.js +19 -19
  34. package/lib/chevre/service/payment/any/findAuthorizeAction.d.ts +0 -4
  35. package/lib/chevre/service/payment/any/findAuthorizeAction.js +19 -19
  36. package/lib/chevre/service/payment/any/findCheckAction.d.ts +0 -4
  37. package/lib/chevre/service/payment/any/findCheckAction.js +19 -19
  38. package/lib/chevre/service/reserve/confirmReservation.js +19 -26
  39. package/lib/chevre/service/reserve/factory.d.ts +0 -3
  40. package/lib/chevre/service/reserve/factory.js +0 -4
  41. package/lib/chevre/service/reserve/potentialActions/onReservationConfirmed.d.ts +4 -13
  42. package/lib/chevre/service/reserve/potentialActions/onReservationConfirmed.js +21 -61
  43. package/lib/chevre/service/task/importEventCapacitiesFromCOA.js +4 -1
  44. package/lib/chevre/service/task/importEventsFromCOA.js +4 -1
  45. package/lib/chevre/service/task/importOffersFromCOA.js +5 -5
  46. package/lib/chevre/service/task.d.ts +1 -20
  47. package/lib/chevre/service/task.js +0 -28
  48. package/lib/chevre/service/taskHandler.js +0 -34
  49. package/lib/chevre/service/transaction/placeOrder/exportTasks/factory.d.ts +8 -4
  50. package/lib/chevre/service/transaction/placeOrder/exportTasks/factory.js +55 -103
  51. package/lib/chevre/service/transaction/placeOrder/exportTasksById.d.ts +2 -0
  52. package/lib/chevre/service/transaction/placeOrder/exportTasksById.js +20 -10
  53. package/lib/chevre/service/transaction/returnOrder/exportTasks/factory.d.ts +13 -3
  54. package/lib/chevre/service/transaction/returnOrder/exportTasks/factory.js +48 -51
  55. package/lib/chevre/service/transaction/returnOrder.d.ts +2 -0
  56. package/lib/chevre/service/transaction/returnOrder.js +21 -13
  57. package/lib/chevre/service/transaction.d.ts +2 -0
  58. package/lib/chevre/service/transaction.js +0 -2
  59. package/package.json +2 -2
@@ -0,0 +1,39 @@
1
+ import type { Connection, UpdateWriteOpResult } from 'mongoose';
2
+ import { factory } from '../factory';
3
+ /**
4
+ * 旧予定タスクリポジトリ
5
+ */
6
+ export declare class ScheduledTaskLegacyRepo {
7
+ private readonly taskModel;
8
+ constructor(connection: Connection);
9
+ /**
10
+ * $eq:0をAbortedにする(特定のタスクのみ)(これらは中止されてもhubへ通知しない)
11
+ */
12
+ abortLegacyTasks(params: {
13
+ intervalInMinutes: number;
14
+ name: {
15
+ $in: factory.taskName[];
16
+ };
17
+ }): Promise<UpdateWriteOpResult>;
18
+ /**
19
+ * 実行日時を一定期間過ぎたReadyタスクについて、Runningステータスに変更した上で、Runningイベントを発生させる
20
+ */
21
+ emitRunningIfExistsLegacy(params: {
22
+ /**
23
+ * 必ずタスク名指定で実行する
24
+ */
25
+ name: {
26
+ $eq: factory.taskName;
27
+ };
28
+ runsAt: {
29
+ $lt: Date;
30
+ };
31
+ sort: {
32
+ numberOfTried?: factory.sortType;
33
+ runsAt?: factory.sortType;
34
+ };
35
+ executor: {
36
+ name: string;
37
+ };
38
+ }): Promise<Pick<factory.task.ITask<factory.taskName>, 'id' | 'name'> | null>;
39
+ }
@@ -0,0 +1,96 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.ScheduledTaskLegacyRepo = void 0;
7
+ const moment_1 = __importDefault(require("moment"));
8
+ const task_1 = require("../eventEmitter/task");
9
+ const factory_1 = require("../factory");
10
+ const settings_1 = require("../settings");
11
+ const task_2 = require("./mongoose/schemas/task");
12
+ /**
13
+ * 旧予定タスクリポジトリ
14
+ */
15
+ class ScheduledTaskLegacyRepo {
16
+ taskModel;
17
+ constructor(connection) {
18
+ this.taskModel = connection.model(task_2.modelName, (0, task_2.createSchema)());
19
+ }
20
+ /**
21
+ * $eq:0をAbortedにする(特定のタスクのみ)(これらは中止されてもhubへ通知しない)
22
+ */
23
+ async abortLegacyTasks(params) {
24
+ const lastTriedAtShoudBeLessThan = (0, moment_1.default)()
25
+ .add(-params.intervalInMinutes, 'minutes')
26
+ .toDate();
27
+ return this.taskModel.updateMany({
28
+ status: { $eq: factory_1.factory.taskStatus.Running },
29
+ lastTriedAt: {
30
+ $type: 'date',
31
+ $lt: lastTriedAtShoudBeLessThan
32
+ },
33
+ remainingNumberOfTries: { $eq: 0 },
34
+ name: { $in: params.name.$in }
35
+ }, {
36
+ $set: {
37
+ status: factory_1.factory.taskStatus.Aborted,
38
+ dateAborted: new Date()
39
+ }
40
+ })
41
+ .exec();
42
+ }
43
+ /**
44
+ * 実行日時を一定期間過ぎたReadyタスクについて、Runningステータスに変更した上で、Runningイベントを発生させる
45
+ */
46
+ async emitRunningIfExistsLegacy(params
47
+ // next?: INextFunction // 現時点でタスク遅延実行ではnext指定なし(2026-07-30)
48
+ ) {
49
+ if (!(params.runsAt.$lt instanceof Date)) {
50
+ throw new factory_1.factory.errors.Argument('runsAt.$lt', 'must be Date');
51
+ }
52
+ const projection = {
53
+ _id: 0,
54
+ id: { $toString: '$_id' },
55
+ name: 1
56
+ };
57
+ const nameEq = params.name?.$eq;
58
+ // インデックス'executeOneByNameIfExists'を想定したfilter
59
+ const filter = {
60
+ status: { $eq: factory_1.factory.taskStatus.Ready },
61
+ runsAt: { $lt: params.runsAt.$lt },
62
+ name: params.name
63
+ };
64
+ const doc = await this.taskModel.findOneAndUpdate(filter, {
65
+ $set: {
66
+ status: factory_1.factory.taskStatus.Running, // 実行中に変更
67
+ lastTriedAt: new Date(),
68
+ executor: params.executor
69
+ },
70
+ $inc: {
71
+ remainingNumberOfTries: -1, // 残りトライ可能回数減らす
72
+ numberOfTried: 1 // トライ回数増やす
73
+ }
74
+ }, {
75
+ new: true,
76
+ projection,
77
+ ...(typeof params.sort.numberOfTried === 'number' || typeof params.sort.runsAt === 'number')
78
+ ? { sort: params.sort }
79
+ : undefined
80
+ })
81
+ .setOptions({ maxTimeMS: settings_1.MONGO_MAX_TIME_MS })
82
+ .lean()
83
+ .exec();
84
+ if (doc === null) {
85
+ return null;
86
+ }
87
+ const changedTask = {
88
+ id: doc.id,
89
+ status: factory_1.factory.taskStatus.Running,
90
+ name: nameEq
91
+ };
92
+ task_1.taskEventEmitter.emitTaskStatusChanged(changedTask);
93
+ return doc;
94
+ }
95
+ }
96
+ exports.ScheduledTaskLegacyRepo = ScheduledTaskLegacyRepo;
@@ -0,0 +1,21 @@
1
+ import type { Connection } from 'mongoose';
2
+ /**
3
+ * 予定タスク移行リポジトリ
4
+ */
5
+ export declare class ScheduledTaskMigrationRepo {
6
+ private readonly scheduledTaskModel;
7
+ private readonly taskModel;
8
+ constructor(connection: Connection);
9
+ /**
10
+ * DeleteTransactionタスク移行処理
11
+ */
12
+ migrateDeleteTransactionTasks(params: {
13
+ limit: number;
14
+ runsAtGte: Date;
15
+ expiresInDays: number;
16
+ }): Promise<(import("mongodb").BulkWriteResult & {
17
+ mongoose?: {
18
+ validationErrors: import("mongoose").Error[];
19
+ } | undefined;
20
+ }) | undefined>;
21
+ }
@@ -0,0 +1,70 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.ScheduledTaskMigrationRepo = void 0;
7
+ const moment_1 = __importDefault(require("moment"));
8
+ const factory_1 = require("../factory");
9
+ const scheduledTasks_1 = require("./mongoose/schemas/scheduledTasks");
10
+ const task_1 = require("./mongoose/schemas/task");
11
+ /**
12
+ * 予定タスク移行リポジトリ
13
+ */
14
+ class ScheduledTaskMigrationRepo {
15
+ scheduledTaskModel;
16
+ taskModel;
17
+ constructor(connection) {
18
+ this.scheduledTaskModel = connection.model(scheduledTasks_1.modelName, (0, scheduledTasks_1.createSchema)());
19
+ this.taskModel = connection.model(task_1.modelName, (0, task_1.createSchema)());
20
+ }
21
+ /**
22
+ * DeleteTransactionタスク移行処理
23
+ */
24
+ async migrateDeleteTransactionTasks(params) {
25
+ const { limit, runsAtGte, expiresInDays } = params;
26
+ // limit件抽出
27
+ const migratingTasks = await this.taskModel.find({
28
+ // _id: { $eq: '6a66e83f9b21f3d4bf5fa232' },
29
+ status: { $eq: factory_1.factory.taskStatus.Ready },
30
+ name: { $eq: factory_1.factory.taskName.DeleteTransaction },
31
+ runsAt: { $gte: runsAtGte }
32
+ })
33
+ .limit(limit)
34
+ .lean()
35
+ .exec();
36
+ if (migratingTasks.length === 0) {
37
+ return;
38
+ }
39
+ ;
40
+ const bulkOps = migratingTasks.map((migratingTask) => {
41
+ return {
42
+ updateOne: {
43
+ filter: {
44
+ _id: { $eq: migratingTask._id }
45
+ },
46
+ update: {
47
+ $setOnInsert: {
48
+ ...migratingTask,
49
+ expires: (0, moment_1.default)(migratingTask.runsAt)
50
+ .add(expiresInDays, 'days')
51
+ .toDate()
52
+ }
53
+ },
54
+ upsert: true
55
+ }
56
+ };
57
+ });
58
+ // 新コレクションへ挿入
59
+ const result = await this.scheduledTaskModel.bulkWrite(bulkOps, { ordered: false });
60
+ // 新コレクションへ書き込めたIDだけを旧DBから削除
61
+ const successfulIds = [];
62
+ migratingTasks.forEach(d => successfulIds.push(d._id));
63
+ if (successfulIds.length > 0) {
64
+ await this.taskModel.deleteMany({ _id: { $in: successfulIds } })
65
+ .exec();
66
+ }
67
+ return result;
68
+ }
69
+ }
70
+ exports.ScheduledTaskMigrationRepo = ScheduledTaskMigrationRepo;
@@ -1,9 +1,8 @@
1
1
  import type { Connection, UpdateWriteOpResult } from 'mongoose';
2
2
  import { INextFunction } from '../eventEmitter/task';
3
3
  import { factory } from '../factory';
4
- import { IModel, IDocType } from './mongoose/schemas/task';
4
+ import { IModel } from './mongoose/schemas/task';
5
5
  import type { IExecutableTask } from '../taskSettings';
6
- type IKeyOfProjection = keyof factory.task.ITask<factory.taskName> | 'expires';
7
6
  /**
8
7
  * リトライ可能なタスク作成属性
9
8
  */
@@ -16,13 +15,6 @@ type ICreatingTask = Pick<factory.task.IAttributes<factory.taskName>, 'data' | '
16
15
  export declare class TaskRepo {
17
16
  readonly taskModel: IModel;
18
17
  constructor(connection: Connection);
19
- runImmediately(params: Pick<factory.task.IAttributes<factory.taskName>, 'data' | 'name' | 'project' | 'remainingNumberOfTries' | 'runsAt'> & {
20
- alternateName?: never;
21
- identifier?: never;
22
- expires: Date;
23
- }, next: INextFunction): Promise<{
24
- id: string;
25
- }>;
26
18
  saveMany(taskAttributes: ICreatingTask[]): Promise<{
27
19
  id: string;
28
20
  }[]>;
@@ -42,8 +34,9 @@ export declare class TaskRepo {
42
34
  /**
43
35
  * タスク識別子から冪等作成する
44
36
  * reimplement createIfNotExistByIdentifier(2025-03-28~)
37
+ * reimplement runTaskByIdentifier(2026-08-03~)
45
38
  */
46
- createIfNotExistByAlternateName(params: ICreatingTask & {
39
+ runTaskByIdentifier(params: ICreatingTask & {
47
40
  alternateName: string;
48
41
  identifier: string;
49
42
  expires?: never;
@@ -62,24 +55,7 @@ export declare class TaskRepo {
62
55
  expires?: Date;
63
56
  }): Promise<IExecutableTask<factory.taskName> | null>;
64
57
  /**
65
- * Readyのタスクをname指定でひとつRunningに変更する
66
- */
67
- executeOneIfExists(params: {
68
- name: {
69
- $eq: factory.taskName;
70
- };
71
- executor: {
72
- name: string;
73
- };
74
- runsAt: {
75
- $lt: Date;
76
- };
77
- sort: {
78
- numberOfTried?: factory.sortType;
79
- runsAt?: factory.sortType;
80
- };
81
- }): Promise<IExecutableTask<factory.taskName> | null>;
82
- /**
58
+ * 潜在的に実行されるべきタスクをカウントする
83
59
  * add(2025-03-16~)
84
60
  */
85
61
  countPotentiallyRunning(params: {
@@ -90,14 +66,18 @@ export declare class TaskRepo {
90
66
  runsAt: {
91
67
  $lt: Date;
92
68
  };
93
- limit?: number;
69
+ limit: number;
94
70
  }): Promise<{
95
71
  count: number;
96
72
  }>;
97
73
  /**
98
- * 実行日時を一定期間過ぎたReadyタスクについて、Runningスタータスに変更した上で、Runningイベントを発生させる
74
+ * 実行日時を一定期間過ぎたReadyタスクについて、Runningステータスに変更する
99
75
  */
100
- emitRunningIfExists(params: {
76
+ private runDelayedTask;
77
+ /**
78
+ * 実行日時を一定期間過ぎたReadyタスクについて、Runningステータスに変更した上で、Runningイベントを発生させる
79
+ */
80
+ emitRunningIfExistsByName(params: {
101
81
  /**
102
82
  * 必ずタスク名指定で実行する
103
83
  */
@@ -118,31 +98,41 @@ export declare class TaskRepo {
118
98
  executor: {
119
99
  name: string;
120
100
  };
121
- nameFilterBeforeRunsAt: boolean;
122
101
  }): Promise<Pick<factory.task.ITask<factory.taskName>, 'id' | 'name'> | null>;
123
102
  /**
124
- * Readyのままで期限切れのタスクをExpiredに変更する
103
+ * 実行日時を一定期間過ぎたReadyタスクについて、Runningステータスに変更した上で、Runningイベントを発生させる
104
+ * taskNameで絞らない
105
+ * 2026-08-04~
125
106
  */
126
- makeExpiredMany(params: {
127
- expiresLt: Date;
128
- }): Promise<UpdateWriteOpResult>;
107
+ emitRunningIfExistsNoName(params: {
108
+ runsAt: {
109
+ $lt: Date;
110
+ };
111
+ executor: {
112
+ name: string;
113
+ };
114
+ }): Promise<Pick<factory.task.ITask<factory.taskName>, 'id' | 'name'> | null>;
129
115
  /**
130
116
  * Runningのまま一定期間超過し、かつ、remainingNumberOfTries>0のタスクをReadyに変更する
131
117
  */
132
- retryMany(params: {
118
+ retryTasks(params: {
119
+ intervalInMinutes: number;
120
+ }): Promise<UpdateWriteOpResult>;
121
+ /**
122
+ * $lte:0をReadyにする(特定のタスクを除いて) -> Readyにすれば自動的にAbortedになる
123
+ */
124
+ retryAbortingTasksByName(params: {
133
125
  intervalInMinutes: number;
134
- /**
135
- * リトライ条件に残り試行回数条件を追加する
136
- * 十分に小さい数値を指定すれば、実質残り試行回数に関係なくRunningがReadyに変更されることになる
137
- */
138
- remainingNumberOfTries: {
139
- $gte?: number;
140
- $lte?: number;
141
- };
142
126
  name: {
143
127
  $in?: factory.taskName[];
144
128
  };
145
129
  }): Promise<UpdateWriteOpResult>;
130
+ /**
131
+ * $lte:0をReadyにする(特定のタスクを除いて) -> Readyにすれば自動的にAbortedになる
132
+ */
133
+ retryAbortingTasks(params: {
134
+ intervalInMinutes: number;
135
+ }): Promise<UpdateWriteOpResult>;
146
136
  /**
147
137
  * 実行中止済タスクを強制的にリトライ
148
138
  * 中止済タスクでなければ何もしない
@@ -151,12 +141,6 @@ export declare class TaskRepo {
151
141
  id: string;
152
142
  remainingNumberOfTries: number;
153
143
  }): Promise<UpdateWriteOpResult>;
154
- abortMany(params: {
155
- intervalInMinutes: number;
156
- name: {
157
- $in?: factory.taskName[];
158
- };
159
- }): Promise<UpdateWriteOpResult>;
160
144
  /**
161
145
  * タスクIDから実行結果とステータスを保管する
162
146
  * Abortedの場合、dateAbortedもセットする
@@ -172,23 +156,6 @@ export declare class TaskRepo {
172
156
  status: factory.taskStatus.Executed | factory.taskStatus.Running | factory.taskStatus.Aborted;
173
157
  executionResult: factory.task.IExecutionResult;
174
158
  }, next?: INextFunction): Promise<void>;
175
- /**
176
- * タスクの状態を参照する
177
- * 非同期アクション移行が完了したら廃止する(2026-07-29~)
178
- */
179
- findTaskById(params: {
180
- id: {
181
- $eq: string;
182
- };
183
- project: {
184
- id: {
185
- $eq: string;
186
- };
187
- };
188
- name: factory.taskName;
189
- }, inclusion: IKeyOfProjection[]): Promise<(IDocType & {
190
- id: string;
191
- } | undefined)>;
192
159
  deleteByProject(params: {
193
160
  project: {
194
161
  id: string;