@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,19 @@
1
+ import type { Connection, FilterQuery } from 'mongoose';
2
+ import { factory } from '../factory';
3
+ import { IDocType } from './mongoose/schemas/asyncAction';
4
+ import type { IExecutableTask } from '../taskSettings';
5
+ export type IExecutableAsyncAction = Pick<IExecutableTask<factory.taskName>, 'data' | 'expires' | 'id' | 'name' | 'project' | 'runsAt' | 'status'>;
6
+ type IKeyOfProjection = keyof factory.task.ITask<factory.taskName> | 'expires';
7
+ type IFindParams = Pick<factory.task.ISearchConditions, 'id' | 'name' | 'project' | 'runsFrom' | 'runsThrough' | 'status' | 'limit' | 'page' | 'sort'>;
8
+ /**
9
+ * 非同期アクション管理リポジトリ
10
+ */
11
+ export declare class AdminAsyncActionRepo {
12
+ private readonly asyncActionModel;
13
+ constructor(connection: Connection);
14
+ static CREATE_MONGO_CONDITIONS(params: Pick<IFindParams, 'id' | 'name' | 'project' | 'runsFrom' | 'runsThrough' | 'status'>): FilterQuery<import("@chevre/factory/lib/chevre/task").ITask | import("@chevre/factory/lib/chevre/task/confirmPayTransaction").ITask | import("@chevre/factory/lib/chevre/task/confirmReserveTransaction").ITask | import("@chevre/factory/lib/chevre/task/createAccountingReport").ITask | import("@chevre/factory/lib/chevre/task/onAssetTransactionStatusChanged").ITask | import("@chevre/factory/lib/chevre/task/onAuthorizationCreated").ITask | import("@chevre/factory/lib/chevre/task/onEventChanged").ITask | import("@chevre/factory/lib/chevre/task/onResourceDeleted").ITask | import("@chevre/factory/lib/chevre/task/onResourceUpdated").ITask | import("@chevre/factory/lib/chevre/task/onOrderPaymentCompleted").ITask | import("@chevre/factory/lib/chevre/task/placeOrder").ITask | import("@chevre/factory/lib/chevre/task/returnOrder").ITask | import("@chevre/factory/lib/chevre/task/returnPayTransaction").ITask | import("@chevre/factory/lib/chevre/task/returnReserveTransaction").ITask | import("@chevre/factory/lib/chevre/task/sendEmailMessage").ITask | import("@chevre/factory/lib/chevre/task/sendOrder").ITask | import("@chevre/factory/lib/chevre/task/triggerWebhook").ITask | import("@chevre/factory/lib/chevre/task/useReservation").ITask | import("@chevre/factory/lib/chevre/task/voidPayTransaction").ITask>[];
15
+ findAsyncActions(params: IFindParams, inclusion: IKeyOfProjection[]): Promise<(IDocType & {
16
+ id: string;
17
+ })[]>;
18
+ }
19
+ export {};
@@ -0,0 +1,86 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.AdminAsyncActionRepo = void 0;
4
+ const settings_1 = require("../settings");
5
+ const asyncAction_1 = require("./mongoose/schemas/asyncAction");
6
+ const AVAILABLE_PROJECT_FIELDS = [
7
+ 'project',
8
+ 'name',
9
+ 'status',
10
+ 'runsAt',
11
+ 'lastTriedAt',
12
+ 'executionResults',
13
+ 'executor',
14
+ 'data',
15
+ 'dateAborted',
16
+ 'expires'
17
+ ];
18
+ /**
19
+ * 非同期アクション管理リポジトリ
20
+ */
21
+ class AdminAsyncActionRepo {
22
+ asyncActionModel;
23
+ constructor(connection) {
24
+ this.asyncActionModel = connection.model(asyncAction_1.modelName, (0, asyncAction_1.createSchema)());
25
+ }
26
+ static CREATE_MONGO_CONDITIONS(params) {
27
+ const andConditions = [];
28
+ const idEq = params.id?.$eq;
29
+ if (typeof idEq === 'string') {
30
+ andConditions.push({ _id: { $eq: idEq } });
31
+ }
32
+ const projectIdEq = params.project?.id?.$eq;
33
+ if (typeof projectIdEq === 'string') {
34
+ andConditions.push({ 'project.id': { $eq: projectIdEq } });
35
+ }
36
+ if (typeof params.name === 'string') {
37
+ andConditions.push({ name: { $eq: params.name } });
38
+ }
39
+ else {
40
+ const nameIn = params.name?.$in;
41
+ if (Array.isArray(nameIn)) {
42
+ andConditions.push({ name: { $in: nameIn } });
43
+ }
44
+ const nameNin = params.name?.$nin;
45
+ if (Array.isArray(nameNin)) {
46
+ andConditions.push({ name: { $nin: nameNin } });
47
+ }
48
+ }
49
+ const statusEq = params.status?.$eq;
50
+ if (typeof statusEq === 'string') {
51
+ andConditions.push({ status: { $eq: statusEq } });
52
+ }
53
+ if (params.runsFrom instanceof Date) {
54
+ andConditions.push({ runsAt: { $gte: params.runsFrom } });
55
+ }
56
+ if (params.runsThrough instanceof Date) {
57
+ andConditions.push({ runsAt: { $lte: params.runsThrough } });
58
+ }
59
+ return andConditions;
60
+ }
61
+ async findAsyncActions(params, inclusion) {
62
+ const conditions = AdminAsyncActionRepo.CREATE_MONGO_CONDITIONS(params);
63
+ let positiveProjectionFields = AVAILABLE_PROJECT_FIELDS;
64
+ if (Array.isArray(inclusion) && inclusion.length > 0) {
65
+ positiveProjectionFields = inclusion.filter((key) => AVAILABLE_PROJECT_FIELDS.includes(key));
66
+ }
67
+ const projection = {
68
+ _id: 0,
69
+ id: { $toString: '$_id' },
70
+ ...Object.fromEntries(positiveProjectionFields.map((key) => ([key, 1])))
71
+ };
72
+ const query = this.asyncActionModel.find((conditions.length > 0) ? { $and: conditions } : {}, projection);
73
+ if (typeof params.limit === 'number' && params.limit > 0) {
74
+ const page = (typeof params.page === 'number' && params.page > 0) ? params.page : 1;
75
+ query.limit(params.limit)
76
+ .skip(params.limit * (page - 1));
77
+ }
78
+ if (params.sort?.runsAt !== undefined) {
79
+ query.sort({ runsAt: params.sort.runsAt });
80
+ }
81
+ return query.setOptions({ maxTimeMS: settings_1.MONGO_MAX_TIME_MS })
82
+ .lean()
83
+ .exec();
84
+ }
85
+ }
86
+ exports.AdminAsyncActionRepo = AdminAsyncActionRepo;
@@ -0,0 +1,20 @@
1
+ import type { Connection, FilterQuery } from 'mongoose';
2
+ import { factory } from '../factory';
3
+ import { IDocType } from './mongoose/schemas/scheduledTasks';
4
+ type IKeyOfProjection = keyof factory.task.ITask<factory.taskName> | 'expires';
5
+ type IFindParams = Pick<factory.task.ISearchConditions, 'id' | 'name' | 'project' | 'runsFrom' | 'runsThrough' | 'status' | 'limit' | 'page' | 'sort'>;
6
+ /**
7
+ * 予定タスク管理リポジトリ
8
+ */
9
+ export declare class AdminScheduledTaskRepo {
10
+ private readonly scheduledTaskModel;
11
+ constructor(connection: Connection);
12
+ static CREATE_MONGO_CONDITIONS(params: Pick<IFindParams, 'id' | 'name' | 'project' | 'runsFrom' | 'runsThrough' | 'status'>): FilterQuery<import("@chevre/factory/lib/chevre/task").ITask | import("@chevre/factory/lib/chevre/task/confirmPayTransaction").ITask | import("@chevre/factory/lib/chevre/task/confirmReserveTransaction").ITask | import("@chevre/factory/lib/chevre/task/createAccountingReport").ITask | import("@chevre/factory/lib/chevre/task/onAssetTransactionStatusChanged").ITask | import("@chevre/factory/lib/chevre/task/onAuthorizationCreated").ITask | import("@chevre/factory/lib/chevre/task/onEventChanged").ITask | import("@chevre/factory/lib/chevre/task/onResourceDeleted").ITask | import("@chevre/factory/lib/chevre/task/onResourceUpdated").ITask | import("@chevre/factory/lib/chevre/task/onOrderPaymentCompleted").ITask | import("@chevre/factory/lib/chevre/task/placeOrder").ITask | import("@chevre/factory/lib/chevre/task/returnOrder").ITask | import("@chevre/factory/lib/chevre/task/returnPayTransaction").ITask | import("@chevre/factory/lib/chevre/task/returnReserveTransaction").ITask | import("@chevre/factory/lib/chevre/task/sendEmailMessage").ITask | import("@chevre/factory/lib/chevre/task/sendOrder").ITask | import("@chevre/factory/lib/chevre/task/triggerWebhook").ITask | import("@chevre/factory/lib/chevre/task/useReservation").ITask | import("@chevre/factory/lib/chevre/task/voidPayTransaction").ITask>[];
13
+ /**
14
+ * 検索する
15
+ */
16
+ findScheduledTasks(params: IFindParams, inclusion: IKeyOfProjection[]): Promise<(IDocType & {
17
+ id: string;
18
+ })[]>;
19
+ }
20
+ export {};
@@ -0,0 +1,95 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.AdminScheduledTaskRepo = void 0;
4
+ const settings_1 = require("../settings");
5
+ const scheduledTasks_1 = require("./mongoose/schemas/scheduledTasks");
6
+ const AVAILABLE_PROJECT_FIELDS = [
7
+ 'description',
8
+ 'project',
9
+ 'name',
10
+ 'status',
11
+ 'runsAt',
12
+ 'remainingNumberOfTries',
13
+ 'lastTriedAt',
14
+ 'numberOfTried',
15
+ 'executionResults',
16
+ 'executor',
17
+ 'data',
18
+ 'dateAborted',
19
+ 'expires'
20
+ ];
21
+ /**
22
+ * 予定タスク管理リポジトリ
23
+ */
24
+ class AdminScheduledTaskRepo {
25
+ scheduledTaskModel;
26
+ constructor(connection) {
27
+ this.scheduledTaskModel = connection.model(scheduledTasks_1.modelName, (0, scheduledTasks_1.createSchema)());
28
+ }
29
+ static CREATE_MONGO_CONDITIONS(params) {
30
+ const andConditions = [];
31
+ const idEq = params.id?.$eq;
32
+ if (typeof idEq === 'string') {
33
+ andConditions.push({ _id: { $eq: idEq } });
34
+ }
35
+ const projectIdEq = params.project?.id?.$eq;
36
+ if (typeof projectIdEq === 'string') {
37
+ andConditions.push({ 'project.id': { $eq: projectIdEq } });
38
+ }
39
+ if (typeof params.name === 'string') {
40
+ andConditions.push({ name: { $eq: params.name } });
41
+ }
42
+ else {
43
+ const nameIn = params.name?.$in;
44
+ if (Array.isArray(nameIn)) {
45
+ andConditions.push({ name: { $in: nameIn } });
46
+ }
47
+ const nameNin = params.name?.$nin;
48
+ if (Array.isArray(nameNin)) {
49
+ andConditions.push({ name: { $nin: nameNin } });
50
+ }
51
+ }
52
+ const statusEq = params.status?.$eq;
53
+ if (typeof statusEq === 'string') {
54
+ andConditions.push({ status: { $eq: statusEq } });
55
+ }
56
+ if (params.runsFrom instanceof Date) {
57
+ andConditions.push({ runsAt: { $gte: params.runsFrom } });
58
+ }
59
+ if (params.runsThrough instanceof Date) {
60
+ andConditions.push({ runsAt: { $lte: params.runsThrough } });
61
+ }
62
+ return andConditions;
63
+ }
64
+ /**
65
+ * 検索する
66
+ */
67
+ async findScheduledTasks(params, inclusion) {
68
+ const conditions = AdminScheduledTaskRepo.CREATE_MONGO_CONDITIONS(params);
69
+ let positiveProjectionFields = AVAILABLE_PROJECT_FIELDS;
70
+ if (Array.isArray(inclusion) && inclusion.length > 0) {
71
+ positiveProjectionFields = inclusion.filter((key) => AVAILABLE_PROJECT_FIELDS.includes(key));
72
+ }
73
+ else {
74
+ // no op
75
+ }
76
+ const projection = {
77
+ _id: 0,
78
+ id: { $toString: '$_id' },
79
+ ...Object.fromEntries(positiveProjectionFields.map((key) => ([key, 1])))
80
+ };
81
+ const query = this.scheduledTaskModel.find((conditions.length > 0) ? { $and: conditions } : {}, projection);
82
+ if (typeof params.limit === 'number' && params.limit > 0) {
83
+ const page = (typeof params.page === 'number' && params.page > 0) ? params.page : 1;
84
+ query.limit(params.limit)
85
+ .skip(params.limit * (page - 1));
86
+ }
87
+ if (params.sort?.runsAt !== undefined) {
88
+ query.sort({ runsAt: params.sort.runsAt });
89
+ }
90
+ return query.setOptions({ maxTimeMS: settings_1.MONGO_MAX_TIME_MS })
91
+ .lean()
92
+ .exec();
93
+ }
94
+ }
95
+ exports.AdminScheduledTaskRepo = AdminScheduledTaskRepo;
@@ -0,0 +1,32 @@
1
+ import type { Connection } from 'mongoose';
2
+ import { factory } from '../factory';
3
+ interface IAggregationByStatus {
4
+ taskCount: number;
5
+ avgLatency: number;
6
+ maxLatency: number;
7
+ minLatency: number;
8
+ percentilesLatency: {
9
+ name: string;
10
+ value: number;
11
+ }[];
12
+ }
13
+ interface IStatus {
14
+ status: factory.taskStatus;
15
+ aggregation: IAggregationByStatus;
16
+ }
17
+ interface IAggregateTask {
18
+ statuses: IStatus[];
19
+ }
20
+ /**
21
+ * 予定タスク集計リポジトリ
22
+ */
23
+ export declare class AggregateScheduledTaskRepo {
24
+ private readonly scheduledTaskModel;
25
+ constructor(connection: Connection);
26
+ aggregateScheduledTask(params: {
27
+ runsFrom: Date;
28
+ runsThrough: Date;
29
+ }): Promise<IAggregateTask>;
30
+ private agggregateByStatus;
31
+ }
32
+ export {};
@@ -0,0 +1,136 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.AggregateScheduledTaskRepo = void 0;
4
+ const factory_1 = require("../factory");
5
+ const scheduledTasks_1 = require("./mongoose/schemas/scheduledTasks");
6
+ /**
7
+ * 予定タスク集計リポジトリ
8
+ */
9
+ class AggregateScheduledTaskRepo {
10
+ scheduledTaskModel;
11
+ constructor(connection) {
12
+ this.scheduledTaskModel = connection.model(scheduledTasks_1.modelName, (0, scheduledTasks_1.createSchema)());
13
+ }
14
+ async aggregateScheduledTask(params) {
15
+ const statuses = await Promise.all([
16
+ factory_1.factory.taskStatus.Executed,
17
+ factory_1.factory.taskStatus.Aborted
18
+ ].map(async (taskStatus) => {
19
+ const matchConditions = {
20
+ status: { $eq: taskStatus },
21
+ runsAt: {
22
+ $gte: params.runsFrom,
23
+ $lte: params.runsThrough
24
+ },
25
+ // ...(typeof params.project?.id?.$ne === 'string')
26
+ // ? { 'project.id': { $ne: params.project.id.$ne } }
27
+ // : undefined
28
+ };
29
+ return this.agggregateByStatus({ matchConditions, status: taskStatus });
30
+ }));
31
+ return { statuses };
32
+ }
33
+ async agggregateByStatus(params) {
34
+ const matchConditions = params.matchConditions;
35
+ const taskStatus = params.status;
36
+ const aggregate1 = this.scheduledTaskModel.aggregate([
37
+ {
38
+ $match: matchConditions
39
+ },
40
+ {
41
+ $project: {
42
+ latency: { $subtract: ['$lastTriedAt', '$runsAt'] },
43
+ status: '$status',
44
+ runsAt: '$runsAt',
45
+ lastTriedAt: '$lastTriedAt'
46
+ }
47
+ },
48
+ {
49
+ $group: {
50
+ _id: '$status',
51
+ taskCount: { $sum: 1 },
52
+ maxLatency: { $max: '$latency' },
53
+ minLatency: { $min: '$latency' },
54
+ avgLatency: { $avg: '$latency' }
55
+ }
56
+ },
57
+ {
58
+ $project: {
59
+ _id: 0,
60
+ taskCount: '$taskCount',
61
+ avgLatency: '$avgLatency',
62
+ maxLatency: '$maxLatency',
63
+ minLatency: '$minLatency'
64
+ }
65
+ }
66
+ ]);
67
+ // const explainResult = await aggregate1.explain();
68
+ // console.dir(explainResult, { depth: null });
69
+ // return;
70
+ const aggregations = await aggregate1.exec();
71
+ const percents = [50, 95, 99];
72
+ if (aggregations.length === 0) {
73
+ return {
74
+ status: taskStatus,
75
+ aggregation: {
76
+ taskCount: 0,
77
+ avgLatency: 0,
78
+ maxLatency: 0,
79
+ minLatency: 0,
80
+ percentilesLatency: percents.map((percent) => {
81
+ return {
82
+ name: String(percent),
83
+ value: 0
84
+ };
85
+ })
86
+ }
87
+ };
88
+ }
89
+ const ranks4percentile = percents.map((percentile) => {
90
+ return {
91
+ percentile,
92
+ rank: Math.floor(aggregations[0].taskCount * percentile / 100)
93
+ };
94
+ });
95
+ const aggregate2 = this.scheduledTaskModel.aggregate([
96
+ {
97
+ $match: matchConditions
98
+ },
99
+ {
100
+ $project: {
101
+ latency: { $subtract: ['$lastTriedAt', '$runsAt'] },
102
+ status: '$status',
103
+ runsAt: '$runsAt',
104
+ lastTriedAt: '$lastTriedAt'
105
+ }
106
+ },
107
+ { $sort: { latency: 1 } },
108
+ {
109
+ $group: {
110
+ _id: '$status',
111
+ latencies: { $push: '$latency' }
112
+ }
113
+ },
114
+ {
115
+ $project: {
116
+ _id: 0,
117
+ percentilesLatency: ranks4percentile.map((rank) => {
118
+ return {
119
+ name: String(rank.percentile),
120
+ value: { $arrayElemAt: ['$latencies', rank.rank] }
121
+ };
122
+ })
123
+ }
124
+ }
125
+ ]);
126
+ const aggregations2 = await aggregate2.exec();
127
+ return {
128
+ status: taskStatus,
129
+ aggregation: {
130
+ ...aggregations[0],
131
+ ...aggregations2[0]
132
+ }
133
+ };
134
+ }
135
+ }
136
+ exports.AggregateScheduledTaskRepo = AggregateScheduledTaskRepo;
@@ -1,23 +1,18 @@
1
- import type { Connection, FilterQuery } from 'mongoose';
1
+ import type { Connection } from 'mongoose';
2
2
  import { factory } from '../factory';
3
- import { IModel, IDocType } from './mongoose/schemas/asyncAction';
3
+ import { IDocType } from './mongoose/schemas/asyncAction';
4
4
  import type { IExecutableTask } from '../taskSettings';
5
5
  type ISavingTask = Pick<factory.task.IAttributes<factory.taskName>, 'data' | 'executionResults' | 'name' | 'project' | 'runsAt' | 'status'> & {
6
6
  expires: Date;
7
7
  };
8
8
  export type IExecutableAsyncAction = Pick<IExecutableTask<factory.taskName>, 'data' | 'expires' | 'id' | 'name' | 'project' | 'runsAt' | 'status'>;
9
9
  type IKeyOfProjection = keyof factory.task.ITask<factory.taskName> | 'expires';
10
- type IFindParams = Pick<factory.task.ISearchConditions, 'id' | 'name' | 'project' | 'runsFrom' | 'runsThrough' | 'status' | 'limit' | 'page' | 'sort'>;
11
10
  /**
12
11
  * 非同期アクションリポジトリ
13
12
  */
14
13
  export declare class AsyncActionRepo {
15
- readonly asyncActionModel: IModel;
14
+ private readonly asyncActionModel;
16
15
  constructor(connection: Connection);
17
- static CREATE_MONGO_CONDITIONS(params: Pick<IFindParams, 'id' | 'name' | 'project' | 'runsFrom' | 'runsThrough' | 'status'>): FilterQuery<import("@chevre/factory/lib/chevre/task").ITask | import("@chevre/factory/lib/chevre/task/confirmPayTransaction").ITask | import("@chevre/factory/lib/chevre/task/confirmReserveTransaction").ITask | import("@chevre/factory/lib/chevre/task/createAccountingReport").ITask | import("@chevre/factory/lib/chevre/task/onAssetTransactionStatusChanged").ITask | import("@chevre/factory/lib/chevre/task/onAuthorizationCreated").ITask | import("@chevre/factory/lib/chevre/task/onEventChanged").ITask | import("@chevre/factory/lib/chevre/task/onResourceDeleted").ITask | import("@chevre/factory/lib/chevre/task/onResourceUpdated").ITask | import("@chevre/factory/lib/chevre/task/onOrderPaymentCompleted").ITask | import("@chevre/factory/lib/chevre/task/placeOrder").ITask | import("@chevre/factory/lib/chevre/task/returnOrder").ITask | import("@chevre/factory/lib/chevre/task/returnPayTransaction").ITask | import("@chevre/factory/lib/chevre/task/returnReserveTransaction").ITask | import("@chevre/factory/lib/chevre/task/sendEmailMessage").ITask | import("@chevre/factory/lib/chevre/task/sendOrder").ITask | import("@chevre/factory/lib/chevre/task/triggerWebhook").ITask | import("@chevre/factory/lib/chevre/task/useReservation").ITask | import("@chevre/factory/lib/chevre/task/voidPayTransaction").ITask>[];
18
- findAsyncActions(params: IFindParams, inclusion: IKeyOfProjection[]): Promise<(IDocType & {
19
- id: string;
20
- })[]>;
21
16
  /**
22
17
  * Readyタスクをひとつ追加する
23
18
  */
@@ -35,65 +35,6 @@ class AsyncActionRepo {
35
35
  constructor(connection) {
36
36
  this.asyncActionModel = connection.model(asyncAction_1.modelName, (0, asyncAction_1.createSchema)());
37
37
  }
38
- static CREATE_MONGO_CONDITIONS(params) {
39
- const andConditions = [];
40
- const idEq = params.id?.$eq;
41
- if (typeof idEq === 'string') {
42
- andConditions.push({ _id: { $eq: idEq } });
43
- }
44
- const projectIdEq = params.project?.id?.$eq;
45
- if (typeof projectIdEq === 'string') {
46
- andConditions.push({ 'project.id': { $eq: projectIdEq } });
47
- }
48
- if (typeof params.name === 'string') {
49
- andConditions.push({ name: { $eq: params.name } });
50
- }
51
- else {
52
- const nameIn = params.name?.$in;
53
- if (Array.isArray(nameIn)) {
54
- andConditions.push({ name: { $in: nameIn } });
55
- }
56
- const nameNin = params.name?.$nin;
57
- if (Array.isArray(nameNin)) {
58
- andConditions.push({ name: { $nin: nameNin } });
59
- }
60
- }
61
- const statusEq = params.status?.$eq;
62
- if (typeof statusEq === 'string') {
63
- andConditions.push({ status: { $eq: statusEq } });
64
- }
65
- if (params.runsFrom instanceof Date) {
66
- andConditions.push({ runsAt: { $gte: params.runsFrom } });
67
- }
68
- if (params.runsThrough instanceof Date) {
69
- andConditions.push({ runsAt: { $lte: params.runsThrough } });
70
- }
71
- return andConditions;
72
- }
73
- async findAsyncActions(params, inclusion) {
74
- const conditions = AsyncActionRepo.CREATE_MONGO_CONDITIONS(params);
75
- let positiveProjectionFields = AVAILABLE_PROJECT_FIELDS;
76
- if (Array.isArray(inclusion) && inclusion.length > 0) {
77
- positiveProjectionFields = inclusion.filter((key) => AVAILABLE_PROJECT_FIELDS.includes(key));
78
- }
79
- const projection = {
80
- _id: 0,
81
- id: { $toString: '$_id' },
82
- ...Object.fromEntries(positiveProjectionFields.map((key) => ([key, 1])))
83
- };
84
- const query = this.asyncActionModel.find((conditions.length > 0) ? { $and: conditions } : {}, projection);
85
- if (typeof params.limit === 'number' && params.limit > 0) {
86
- const page = (typeof params.page === 'number' && params.page > 0) ? params.page : 1;
87
- query.limit(params.limit)
88
- .skip(params.limit * (page - 1));
89
- }
90
- if (params.sort?.runsAt !== undefined) {
91
- query.sort({ runsAt: params.sort.runsAt });
92
- }
93
- return query.setOptions({ maxTimeMS: settings_1.MONGO_MAX_TIME_MS })
94
- .lean()
95
- .exec();
96
- }
97
38
  /**
98
39
  * Readyタスクをひとつ追加する
99
40
  */
@@ -168,55 +109,6 @@ class AsyncActionRepo {
168
109
  }
169
110
  return doc;
170
111
  }
171
- // /**
172
- // * Readyのままで期限切れのタスクをExpiredに変更する
173
- // */
174
- // public async makeExpiredMany(params: {
175
- // expiresLt: Date;
176
- // }): Promise<UpdateWriteOpResult> {
177
- // const { expiresLt } = params;
178
- // if (!(expiresLt instanceof Date)) {
179
- // throw new factory.errors.Argument('expiresLt', 'must be Date');
180
- // }
181
- // return this.asyncActionModel.updateMany(
182
- // {
183
- // status: { $eq: factory.taskStatus.Ready },
184
- // expires: { $lt: expiresLt }
185
- // },
186
- // {
187
- // $set: {
188
- // status: factory.taskStatus.Expired
189
- // }
190
- // }
191
- // )
192
- // .exec();
193
- // }
194
- // /**
195
- // * taskNameに関わらず、Runningのまま放置された非同期アクションをAbortedに変更する
196
- // */
197
- // public async abortMany(params: {
198
- // intervalInMinutes: number;
199
- // }): Promise<UpdateWriteOpResult> {
200
- // const lastTriedAtShoudBeLessThan = moment()
201
- // .add(-params.intervalInMinutes, 'minutes')
202
- // .toDate();
203
- // return this.asyncActionModel.updateMany(
204
- // {
205
- // status: { $eq: factory.taskStatus.Running },
206
- // lastTriedAt: {
207
- // $exists: true,
208
- // $lt: lastTriedAtShoudBeLessThan
209
- // }
210
- // },
211
- // {
212
- // $set: {
213
- // status: factory.taskStatus.Aborted,
214
- // dateAborted: new Date()
215
- // }
216
- // }
217
- // )
218
- // .exec();
219
- // }
220
112
  /**
221
113
  * タスクIDから実行結果とステータスを保管する
222
114
  * Abortedの場合、dateAbortedもセットする
@@ -0,0 +1,23 @@
1
+ import type { Connection, UpdateWriteOpResult } from 'mongoose';
2
+ import { INextFunction } from '../eventEmitter/task';
3
+ import { factory } from '../factory';
4
+ /**
5
+ * 旧非同期アクション(tasksコレクションにて管理)リポジトリ
6
+ */
7
+ export declare class AsyncActionLegacyRepo {
8
+ private readonly taskModel;
9
+ constructor(connection: Connection);
10
+ runImmediately(params: Pick<factory.task.IAttributes<factory.taskName>, 'data' | 'name' | 'project' | 'remainingNumberOfTries' | 'runsAt'> & {
11
+ alternateName?: never;
12
+ identifier?: never;
13
+ expires: Date;
14
+ }, next: INextFunction): Promise<{
15
+ id: string;
16
+ }>;
17
+ /**
18
+ * Readyのままで期限切れのタスクをExpiredに変更する
19
+ */
20
+ makeExpiredMany(params: {
21
+ expiresLt: Date;
22
+ }): Promise<UpdateWriteOpResult>;
23
+ }
@@ -0,0 +1,59 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.AsyncActionLegacyRepo = void 0;
4
+ const task_1 = require("../eventEmitter/task");
5
+ const factory_1 = require("../factory");
6
+ const task_2 = require("./mongoose/schemas/task");
7
+ /**
8
+ * 旧非同期アクション(tasksコレクションにて管理)リポジトリ
9
+ */
10
+ class AsyncActionLegacyRepo {
11
+ taskModel;
12
+ constructor(connection) {
13
+ this.taskModel = connection.model(task_2.modelName, (0, task_2.createSchema)());
14
+ }
15
+ async runImmediately(params,
16
+ // support customr function(2025-05-25~)
17
+ next) {
18
+ const { expires } = params;
19
+ if (!(expires instanceof Date)) {
20
+ throw new factory_1.factory.errors.Argument('expires', 'must be Date');
21
+ }
22
+ const savingTask = {
23
+ ...params,
24
+ status: factory_1.factory.taskStatus.Ready,
25
+ numberOfTried: 0,
26
+ executionResults: []
27
+ };
28
+ const result = await this.taskModel.insertMany(savingTask, { rawResult: true });
29
+ const id = result.insertedIds?.[0]?.toHexString();
30
+ if (typeof id !== 'string') {
31
+ throw new factory_1.factory.errors.Internal('task not saved');
32
+ }
33
+ task_1.taskEventEmitter.emitTaskStatusChanged({
34
+ id,
35
+ status: factory_1.factory.taskStatus.Ready,
36
+ expires // emit expires(2025-03-31~)
37
+ }, next);
38
+ return { id };
39
+ }
40
+ /**
41
+ * Readyのままで期限切れのタスクをExpiredに変更する
42
+ */
43
+ async makeExpiredMany(params) {
44
+ const { expiresLt } = params;
45
+ if (!(expiresLt instanceof Date)) {
46
+ throw new factory_1.factory.errors.Argument('expiresLt', 'must be Date');
47
+ }
48
+ return this.taskModel.updateMany({
49
+ status: { $eq: factory_1.factory.taskStatus.Ready },
50
+ expires: { $exists: true, $lt: expiresLt }
51
+ }, {
52
+ $set: {
53
+ status: factory_1.factory.taskStatus.Expired
54
+ }
55
+ })
56
+ .exec();
57
+ }
58
+ }
59
+ exports.AsyncActionLegacyRepo = AsyncActionLegacyRepo;
@@ -13,10 +13,6 @@ interface IOnReservationStatusChanged {
13
13
  * AggService通知先
14
14
  */
15
15
  informReservation?: factory.project.IInformParams[];
16
- /**
17
- * 確定予約最小化をサポート(2026-07-14~)
18
- */
19
- minimizeReservation?: boolean;
20
16
  }
21
17
  interface IOnTaskStatusChanged {
22
18
  /**
@@ -36,6 +32,8 @@ interface IOnEventChanged {
36
32
  informEvent2agg?: factory.project.IInformParams[];
37
33
  }
38
34
  export interface IStorageSettings {
35
+ useScheduledDeleteTransactionTask?: boolean;
36
+ deleteTransactionTaskExpiresInDays?: number;
39
37
  /**
40
38
  * 取引保管期間(Confirmed)
41
39
  * default:365
@@ -5,7 +5,7 @@ type ICreatingTaskKeys = 'data' | 'executionResults' | 'name' | 'numberOfTried'
5
5
  /**
6
6
  * リトライ可能なタスク作成属性
7
7
  */
8
- type ICreatingTask = (Pick<factory.task.importEventCapacitiesFromCOA.IAttributes, ICreatingTaskKeys> | Pick<factory.task.importEventsFromCOA.IAttributes, ICreatingTaskKeys>) & {
8
+ type ICreatingTask = (Pick<factory.task.importEventCapacitiesFromCOA.IAttributes, ICreatingTaskKeys> | Pick<factory.task.importEventsFromCOA.IAttributes, ICreatingTaskKeys> | Pick<factory.task.deleteTransaction.IAttributes, ICreatingTaskKeys>) & {
9
9
  expires: Date;
10
10
  };
11
11
  /**