@chevre/domain 25.2.0-alpha.54 → 25.2.0-alpha.55

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.
@@ -0,0 +1,37 @@
1
+ import type { AnyKeys, Connection, FilterQuery, ProjectionType } from 'mongoose';
2
+ import { factory } from '../factory';
3
+ import { IModel, IDocType } from './mongoose/schemas/task';
4
+ type IKeyOfProjection = keyof factory.task.ITask<factory.taskName> | 'expires';
5
+ /**
6
+ * タスク管理リポジトリ
7
+ */
8
+ export declare class AdminTaskRepo {
9
+ readonly taskModel: IModel;
10
+ constructor(connection: Connection);
11
+ static CREATE_MONGO_CONDITIONS(params: factory.task.ISearchConditions): 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>[];
12
+ countTasks(params: factory.task.ISearchConditions): Promise<{
13
+ count: number;
14
+ }>;
15
+ /**
16
+ * 検索する
17
+ */
18
+ findTasks(params: factory.task.ISearchConditions, inclusion: IKeyOfProjection[]): Promise<factory.task.ITask<factory.taskName>[]>;
19
+ getCursor(conditions: FilterQuery<factory.task.ITask<factory.taskName>>, projection: ProjectionType<factory.task.ITask<factory.taskName>>): import("mongoose").Cursor<import("mongoose").Document<unknown, Record<string, never>, IDocType, import("./mongoose/virtuals").IVirtuals, {}> & Omit<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, "id"> & {
20
+ expires?: Date;
21
+ } & {
22
+ _id: import("mongoose").Types.ObjectId;
23
+ } & {
24
+ __v: number;
25
+ }, import("mongoose").QueryOptions<IDocType>, (import("mongoose").Document<unknown, Record<string, never>, IDocType, import("./mongoose/virtuals").IVirtuals, {}> & Omit<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, "id"> & {
26
+ expires?: Date;
27
+ } & {
28
+ _id: import("mongoose").Types.ObjectId;
29
+ } & {
30
+ __v: number;
31
+ }) | null>;
32
+ unsetUnnecessaryFields(params: {
33
+ filter: FilterQuery<factory.task.ITask<factory.taskName>>;
34
+ $unset: AnyKeys<factory.task.ITask<factory.taskName>>;
35
+ }): Promise<import("mongoose").UpdateWriteOpResult>;
36
+ }
37
+ export {};
@@ -0,0 +1,163 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.AdminTaskRepo = void 0;
4
+ const factory_1 = require("../factory");
5
+ const settings_1 = require("../settings");
6
+ const task_1 = require("./mongoose/schemas/task");
7
+ const AVAILABLE_PROJECT_FIELDS = [
8
+ 'alternateName',
9
+ 'identifier',
10
+ 'description',
11
+ 'project',
12
+ 'name',
13
+ 'status',
14
+ 'runsAt',
15
+ 'remainingNumberOfTries',
16
+ 'lastTriedAt',
17
+ 'numberOfTried',
18
+ 'executionResults',
19
+ 'executor',
20
+ 'data',
21
+ 'dateAborted',
22
+ 'expires'
23
+ ];
24
+ /**
25
+ * タスク管理リポジトリ
26
+ */
27
+ class AdminTaskRepo {
28
+ taskModel;
29
+ constructor(connection) {
30
+ this.taskModel = connection.model(task_1.modelName, (0, task_1.createSchema)());
31
+ }
32
+ static CREATE_MONGO_CONDITIONS(params) {
33
+ const andConditions = [];
34
+ const idEq = params.id?.$eq;
35
+ if (typeof idEq === 'string') {
36
+ andConditions.push({ _id: { $eq: idEq } });
37
+ }
38
+ const projectIdEq = params.project?.id?.$eq;
39
+ if (typeof projectIdEq === 'string') {
40
+ andConditions.push({ 'project.id': { $eq: projectIdEq } });
41
+ }
42
+ if (typeof params.name === 'string') {
43
+ andConditions.push({ name: { $eq: params.name } });
44
+ }
45
+ else {
46
+ const nameIn = params.name?.$in;
47
+ if (Array.isArray(nameIn)) {
48
+ andConditions.push({ name: { $in: nameIn } });
49
+ }
50
+ const nameNin = params.name?.$nin;
51
+ if (Array.isArray(nameNin)) {
52
+ andConditions.push({ name: { $nin: nameNin } });
53
+ }
54
+ }
55
+ const statusEq = params.status?.$eq;
56
+ if (typeof statusEq === 'string') {
57
+ andConditions.push({ status: { $eq: statusEq } });
58
+ }
59
+ if (Array.isArray(params.statuses)) {
60
+ andConditions.push({ status: { $in: params.statuses } });
61
+ }
62
+ if (params.runsFrom instanceof Date) {
63
+ andConditions.push({ runsAt: { $gte: params.runsFrom } });
64
+ }
65
+ if (params.runsThrough instanceof Date) {
66
+ andConditions.push({ runsAt: { $lte: params.runsThrough } });
67
+ }
68
+ if (params.lastTriedFrom instanceof Date) {
69
+ andConditions.push({ lastTriedAt: { $type: 'date', $gte: params.lastTriedFrom } });
70
+ }
71
+ if (params.lastTriedThrough instanceof Date) {
72
+ andConditions.push({ lastTriedAt: { $type: 'date', $lte: params.lastTriedThrough } });
73
+ }
74
+ const dateAbortedGte = params.dateAborted?.$gte;
75
+ if (dateAbortedGte instanceof Date) {
76
+ andConditions.push({ dateAborted: { $type: 'date', $gte: dateAbortedGte } });
77
+ }
78
+ const dateAbortedLte = params.dateAborted?.$lte;
79
+ if (dateAbortedLte instanceof Date) {
80
+ andConditions.push({ dateAborted: { $type: 'date', $lte: dateAbortedLte } });
81
+ }
82
+ const objectIdEq = params.data?.object?.id?.$eq;
83
+ if (typeof objectIdEq === 'string') {
84
+ andConditions.push({ 'data.object.id': { $exists: true, $eq: objectIdEq } });
85
+ }
86
+ const objectOrderNumberEq = params.data?.object?.orderNumber?.$eq;
87
+ if (typeof objectOrderNumberEq === 'string') {
88
+ andConditions.push({ 'data.object.orderNumber': { $exists: true, $eq: objectOrderNumberEq } });
89
+ }
90
+ const objectTransactionNumberEq = params.data?.object?.transactionNumber?.$eq;
91
+ if (typeof objectTransactionNumberEq === 'string') {
92
+ andConditions.push({ 'data.object.transactionNumber': { $exists: true, $eq: objectTransactionNumberEq } });
93
+ }
94
+ const objectPurposeIdEq = params.data?.purpose?.id?.$eq;
95
+ if (typeof objectPurposeIdEq === 'string') {
96
+ andConditions.push({ 'data.purpose.id': { $exists: true, $eq: objectPurposeIdEq } });
97
+ }
98
+ const objectPurposeOrderNumberEq = params.data?.purpose?.orderNumber?.$eq;
99
+ if (typeof objectPurposeOrderNumberEq === 'string') {
100
+ andConditions.push({ 'data.purpose.orderNumber': { $exists: true, $eq: objectPurposeOrderNumberEq } });
101
+ }
102
+ const alternateNameRegex = params.alternateName?.$regex;
103
+ if (typeof alternateNameRegex === 'string' && alternateNameRegex.length > 0) {
104
+ andConditions.push({ alternateName: { $exists: true, $regex: new RegExp(alternateNameRegex) } });
105
+ }
106
+ const identifierRegex = params.identifier?.$regex;
107
+ if (typeof identifierRegex === 'string' && identifierRegex.length > 0) {
108
+ andConditions.push({ identifier: { $exists: true, $regex: new RegExp(identifierRegex) } });
109
+ }
110
+ return andConditions;
111
+ }
112
+ async countTasks(params) {
113
+ const { limit } = params;
114
+ const conditions = AdminTaskRepo.CREATE_MONGO_CONDITIONS(params);
115
+ const query = this.taskModel.countDocuments((conditions.length > 0) ? { $and: conditions } : {});
116
+ if (typeof limit === 'number' && limit >= 0) {
117
+ query.limit(limit);
118
+ }
119
+ const count = await query.setOptions({ maxTimeMS: settings_1.MONGO_MAX_TIME_MS })
120
+ .exec();
121
+ return { count };
122
+ }
123
+ /**
124
+ * 検索する
125
+ */
126
+ async findTasks(params, inclusion) {
127
+ const conditions = AdminTaskRepo.CREATE_MONGO_CONDITIONS(params);
128
+ let positiveProjectionFields = AVAILABLE_PROJECT_FIELDS;
129
+ if (Array.isArray(inclusion) && inclusion.length > 0) {
130
+ positiveProjectionFields = inclusion.filter((key) => AVAILABLE_PROJECT_FIELDS.includes(key));
131
+ }
132
+ else {
133
+ // no op
134
+ }
135
+ const projection = {
136
+ _id: 0,
137
+ id: { $toString: '$_id' },
138
+ ...Object.fromEntries(positiveProjectionFields.map((key) => ([key, 1])))
139
+ };
140
+ const query = this.taskModel.find((conditions.length > 0) ? { $and: conditions } : {}, projection);
141
+ if (typeof params.limit === 'number' && params.limit > 0) {
142
+ const page = (typeof params.page === 'number' && params.page > 0) ? params.page : 1;
143
+ query.limit(params.limit)
144
+ .skip(params.limit * (page - 1));
145
+ }
146
+ if (params.sort?.runsAt !== undefined) {
147
+ query.sort({ runsAt: params.sort.runsAt });
148
+ }
149
+ return query.setOptions({ maxTimeMS: settings_1.MONGO_MAX_TIME_MS })
150
+ .lean() // lean(2024-09-26~)
151
+ .exec();
152
+ }
153
+ getCursor(conditions, projection) {
154
+ return this.taskModel.find(conditions, projection)
155
+ .sort({ runsAt: factory_1.factory.sortType.Ascending })
156
+ .cursor();
157
+ }
158
+ async unsetUnnecessaryFields(params) {
159
+ return this.taskModel.updateMany(params.filter, { $unset: params.$unset }, { timestamps: false })
160
+ .exec();
161
+ }
162
+ }
163
+ exports.AdminTaskRepo = AdminTaskRepo;
@@ -0,0 +1,38 @@
1
+ import type { Connection } from 'mongoose';
2
+ import { factory } from '../factory';
3
+ import { IModel } from './mongoose/schemas/task';
4
+ interface IAggregationByStatus {
5
+ taskCount: number;
6
+ avgLatency: number;
7
+ maxLatency: number;
8
+ minLatency: number;
9
+ percentilesLatency: {
10
+ name: string;
11
+ value: number;
12
+ }[];
13
+ }
14
+ interface IStatus {
15
+ status: factory.taskStatus;
16
+ aggregation: IAggregationByStatus;
17
+ }
18
+ interface IAggregateTask {
19
+ statuses: IStatus[];
20
+ }
21
+ /**
22
+ * タスク集計リポジトリ
23
+ */
24
+ export declare class AggregateTaskRepo {
25
+ readonly taskModel: IModel;
26
+ constructor(connection: Connection);
27
+ aggregateTask(params: {
28
+ project?: {
29
+ id?: {
30
+ $ne?: string;
31
+ };
32
+ };
33
+ runsFrom: Date;
34
+ runsThrough: Date;
35
+ }): Promise<IAggregateTask>;
36
+ private agggregateByStatus;
37
+ }
38
+ export {};
@@ -0,0 +1,136 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.AggregateTaskRepo = void 0;
4
+ const factory_1 = require("../factory");
5
+ const task_1 = require("./mongoose/schemas/task");
6
+ /**
7
+ * タスク集計リポジトリ
8
+ */
9
+ class AggregateTaskRepo {
10
+ taskModel;
11
+ constructor(connection) {
12
+ this.taskModel = connection.model(task_1.modelName, (0, task_1.createSchema)());
13
+ }
14
+ async aggregateTask(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
+ runsAt: {
21
+ $gte: params.runsFrom,
22
+ $lte: params.runsThrough
23
+ },
24
+ status: { $eq: taskStatus },
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.taskModel.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.taskModel.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.AggregateTaskRepo = AggregateTaskRepo;
@@ -1,25 +1,8 @@
1
- import type { AnyKeys, Connection, FilterQuery, ProjectionType, UpdateWriteOpResult } from 'mongoose';
1
+ import type { Connection, UpdateWriteOpResult } from 'mongoose';
2
2
  import { INextFunction } from '../eventEmitter/task';
3
3
  import { factory } from '../factory';
4
4
  import { IModel, IDocType } from './mongoose/schemas/task';
5
5
  import type { IExecutableTask } from '../taskSettings';
6
- interface IAggregationByStatus {
7
- taskCount: number;
8
- avgLatency: number;
9
- maxLatency: number;
10
- minLatency: number;
11
- percentilesLatency: {
12
- name: string;
13
- value: number;
14
- }[];
15
- }
16
- interface IStatus {
17
- status: factory.taskStatus;
18
- aggregation: IAggregationByStatus;
19
- }
20
- export interface IAggregateTask {
21
- statuses: IStatus[];
22
- }
23
6
  interface IOptionOnCreate {
24
7
  emitImmediately: boolean;
25
8
  }
@@ -36,7 +19,6 @@ type ICreatingTask = Pick<factory.task.IAttributes<factory.taskName>, 'data' | '
36
19
  export declare class TaskRepo {
37
20
  readonly taskModel: IModel;
38
21
  constructor(connection: Connection);
39
- static CREATE_MONGO_CONDITIONS(params: factory.task.ISearchConditions): 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>[];
40
22
  runImmediately(params: Pick<factory.task.IAttributes<factory.taskName>, 'data' | 'name' | 'project' | 'remainingNumberOfTries' | 'runsAt'> & {
41
23
  alternateName?: never;
42
24
  identifier?: never;
@@ -140,7 +122,7 @@ export declare class TaskRepo {
140
122
  name: string;
141
123
  };
142
124
  nameFilterBeforeRunsAt: boolean;
143
- }, next?: INextFunction): Promise<Pick<factory.task.ITask<factory.taskName>, 'id' | 'name'> | null>;
125
+ }): Promise<Pick<factory.task.ITask<factory.taskName>, 'id' | 'name'> | null>;
144
126
  /**
145
127
  * Readyのままで期限切れのタスクをExpiredに変更する
146
128
  */
@@ -193,13 +175,6 @@ export declare class TaskRepo {
193
175
  status: factory.taskStatus.Executed | factory.taskStatus.Running | factory.taskStatus.Aborted;
194
176
  executionResult: factory.task.IExecutionResult;
195
177
  }, next?: INextFunction): Promise<void>;
196
- count(params: factory.task.ISearchConditions): Promise<{
197
- count: number;
198
- }>;
199
- /**
200
- * 検索する
201
- */
202
- projectFields(params: factory.task.ISearchConditions, inclusion: IKeyOfProjection[]): Promise<factory.task.ITask<factory.taskName>[]>;
203
178
  /**
204
179
  * タスクの状態を参照する
205
180
  * 非同期アクション移行が完了したら廃止する(2026-07-29~)
@@ -222,16 +197,6 @@ export declare class TaskRepo {
222
197
  id: string;
223
198
  };
224
199
  }): Promise<void>;
225
- deleteByName(params: {
226
- name: factory.taskName;
227
- status?: {
228
- $eq?: factory.taskStatus;
229
- };
230
- runsAt?: {
231
- $gte: Date;
232
- $lte: Date;
233
- };
234
- }): Promise<import("mongodb").DeleteResult>;
235
200
  /**
236
201
  * 不要なタスクを削除する
237
202
  */
@@ -249,32 +214,5 @@ export declare class TaskRepo {
249
214
  }): Promise<{
250
215
  count: number;
251
216
  }>;
252
- getCursor(conditions: FilterQuery<factory.task.ITask<factory.taskName>>, projection: ProjectionType<factory.task.ITask<factory.taskName>>): import("mongoose").Cursor<import("mongoose").Document<unknown, Record<string, never>, IDocType, import("./mongoose/virtuals").IVirtuals, {}> & Omit<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, "id"> & {
253
- expires?: Date;
254
- } & {
255
- _id: import("mongoose").Types.ObjectId;
256
- } & {
257
- __v: number;
258
- }, import("mongoose").QueryOptions<IDocType>, (import("mongoose").Document<unknown, Record<string, never>, IDocType, import("./mongoose/virtuals").IVirtuals, {}> & Omit<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, "id"> & {
259
- expires?: Date;
260
- } & {
261
- _id: import("mongoose").Types.ObjectId;
262
- } & {
263
- __v: number;
264
- }) | null>;
265
- unsetUnnecessaryFields(params: {
266
- filter: FilterQuery<factory.task.ITask<factory.taskName>>;
267
- $unset: AnyKeys<factory.task.ITask<factory.taskName>>;
268
- }): Promise<UpdateWriteOpResult>;
269
- aggregateTask(params: {
270
- project?: {
271
- id?: {
272
- $ne?: string;
273
- };
274
- };
275
- runsFrom: Date;
276
- runsThrough: Date;
277
- }): Promise<IAggregateTask>;
278
- private agggregateByStatus;
279
217
  }
280
218
  export {};
@@ -10,13 +10,6 @@ const task_1 = require("../eventEmitter/task");
10
10
  const factory_1 = require("../factory");
11
11
  const settings_1 = require("../settings");
12
12
  const task_2 = require("./mongoose/schemas/task");
13
- /**
14
- * タスク実行時のソート条件
15
- */
16
- // const sortOrder4executionOfTasks: { [key in keyof factory.task.IAttributes<factory.taskName>]?: factory.sortType } = {
17
- // numberOfTried: factory.sortType.Ascending, // トライ回数の少なさ優先
18
- // runsAt: factory.sortType.Ascending // 実行予定日時の早さ優先
19
- // };
20
13
  const executableTaskProjection = {
21
14
  _id: 0,
22
15
  id: { $toString: '$_id' },
@@ -55,86 +48,6 @@ class TaskRepo {
55
48
  constructor(connection) {
56
49
  this.taskModel = connection.model(task_2.modelName, (0, task_2.createSchema)());
57
50
  }
58
- static CREATE_MONGO_CONDITIONS(params) {
59
- const andConditions = [];
60
- const idEq = params.id?.$eq;
61
- if (typeof idEq === 'string') {
62
- andConditions.push({ _id: { $eq: idEq } });
63
- }
64
- const projectIdEq = params.project?.id?.$eq;
65
- if (typeof projectIdEq === 'string') {
66
- andConditions.push({ 'project.id': { $eq: projectIdEq } });
67
- }
68
- if (typeof params.name === 'string') {
69
- andConditions.push({ name: { $eq: params.name } });
70
- }
71
- else {
72
- const nameIn = params.name?.$in;
73
- if (Array.isArray(nameIn)) {
74
- andConditions.push({ name: { $in: nameIn } });
75
- }
76
- const nameNin = params.name?.$nin;
77
- if (Array.isArray(nameNin)) {
78
- andConditions.push({ name: { $nin: nameNin } });
79
- }
80
- }
81
- const statusEq = params.status?.$eq;
82
- if (typeof statusEq === 'string') {
83
- andConditions.push({ status: { $eq: statusEq } });
84
- }
85
- if (Array.isArray(params.statuses)) {
86
- andConditions.push({ status: { $in: params.statuses } });
87
- }
88
- if (params.runsFrom instanceof Date) {
89
- andConditions.push({ runsAt: { $gte: params.runsFrom } });
90
- }
91
- if (params.runsThrough instanceof Date) {
92
- andConditions.push({ runsAt: { $lte: params.runsThrough } });
93
- }
94
- if (params.lastTriedFrom instanceof Date) {
95
- andConditions.push({ lastTriedAt: { $type: 'date', $gte: params.lastTriedFrom } });
96
- }
97
- if (params.lastTriedThrough instanceof Date) {
98
- andConditions.push({ lastTriedAt: { $type: 'date', $lte: params.lastTriedThrough } });
99
- }
100
- const dateAbortedGte = params.dateAborted?.$gte;
101
- if (dateAbortedGte instanceof Date) {
102
- andConditions.push({ dateAborted: { $type: 'date', $gte: dateAbortedGte } });
103
- }
104
- const dateAbortedLte = params.dateAborted?.$lte;
105
- if (dateAbortedLte instanceof Date) {
106
- andConditions.push({ dateAborted: { $type: 'date', $lte: dateAbortedLte } });
107
- }
108
- const objectIdEq = params.data?.object?.id?.$eq;
109
- if (typeof objectIdEq === 'string') {
110
- andConditions.push({ 'data.object.id': { $exists: true, $eq: objectIdEq } });
111
- }
112
- const objectOrderNumberEq = params.data?.object?.orderNumber?.$eq;
113
- if (typeof objectOrderNumberEq === 'string') {
114
- andConditions.push({ 'data.object.orderNumber': { $exists: true, $eq: objectOrderNumberEq } });
115
- }
116
- const objectTransactionNumberEq = params.data?.object?.transactionNumber?.$eq;
117
- if (typeof objectTransactionNumberEq === 'string') {
118
- andConditions.push({ 'data.object.transactionNumber': { $exists: true, $eq: objectTransactionNumberEq } });
119
- }
120
- const objectPurposeIdEq = params.data?.purpose?.id?.$eq;
121
- if (typeof objectPurposeIdEq === 'string') {
122
- andConditions.push({ 'data.purpose.id': { $exists: true, $eq: objectPurposeIdEq } });
123
- }
124
- const objectPurposeOrderNumberEq = params.data?.purpose?.orderNumber?.$eq;
125
- if (typeof objectPurposeOrderNumberEq === 'string') {
126
- andConditions.push({ 'data.purpose.orderNumber': { $exists: true, $eq: objectPurposeOrderNumberEq } });
127
- }
128
- const alternateNameRegex = params.alternateName?.$regex;
129
- if (typeof alternateNameRegex === 'string' && alternateNameRegex.length > 0) {
130
- andConditions.push({ alternateName: { $exists: true, $regex: new RegExp(alternateNameRegex) } });
131
- }
132
- const identifierRegex = params.identifier?.$regex;
133
- if (typeof identifierRegex === 'string' && identifierRegex.length > 0) {
134
- andConditions.push({ identifier: { $exists: true, $regex: new RegExp(identifierRegex) } });
135
- }
136
- return andConditions;
137
- }
138
51
  async runImmediately(
139
52
  // resolve uniqueness of identifier(2025-03-27~)
140
53
  params,
@@ -452,8 +365,7 @@ class TaskRepo {
452
365
  /**
453
366
  * 実行日時を一定期間過ぎたReadyタスクについて、Runningスタータスに変更した上で、Runningイベントを発生させる
454
367
  */
455
- async emitRunningIfExists(params, next // support next function(2025-08-02~)
456
- ) {
368
+ async emitRunningIfExists(params) {
457
369
  if (!(params.runsAt.$lt instanceof Date)) {
458
370
  throw new factory_1.factory.errors.Argument('runsAt.$lt', 'must be Date');
459
371
  }
@@ -471,15 +383,6 @@ class TaskRepo {
471
383
  ...(nameFilterBeforeRunsAt) ? { name: params.name } : undefined,
472
384
  runsAt: { $lt: params.runsAt.$lt },
473
385
  ...(!nameFilterBeforeRunsAt) ? { name: params.name } : undefined
474
- // ...(typeof nameEq === 'string' || Array.isArray(nameIn))
475
- // ? {
476
- // name: {
477
- // ...(typeof nameEq === 'string') ? { $eq: nameEq } : undefined,
478
- // // ...(Array.isArray(nameNin)) ? { $nin: nameNin } : undefined
479
- // ...(Array.isArray(nameIn)) ? { $in: nameIn } : undefined
480
- // }
481
- // }
482
- // : undefined
483
386
  };
484
387
  const doc = await this.taskModel.findOneAndUpdate(filter, {
485
388
  $set: {
@@ -518,7 +421,7 @@ class TaskRepo {
518
421
  status: factory_1.factory.taskStatus.Running
519
422
  };
520
423
  }
521
- task_1.taskEventEmitter.emitTaskStatusChanged(changedTask, (typeof next === 'function') ? next : undefined);
424
+ task_1.taskEventEmitter.emitTaskStatusChanged(changedTask);
522
425
  return doc;
523
426
  }
524
427
  /**
@@ -589,42 +492,6 @@ class TaskRepo {
589
492
  })
590
493
  .exec();
591
494
  }
592
- // public async abortOne(params: {
593
- // intervalInMinutes: number;
594
- // }): Promise<factory.task.ITask<factory.taskName> | null> {
595
- // const lastTriedAtShoudBeLessThan = moment()
596
- // .add(-params.intervalInMinutes, 'minutes')
597
- // .toDate();
598
- // const projection: ProjectionType<factory.task.ITask<factory.taskName>> = {
599
- // _id: 0,
600
- // id: { $toString: '$_id' },
601
- // ...Object.fromEntries<1>(AVAILABLE_PROJECT_FIELDS.map((key) => ([key, 1])))
602
- // };
603
- // const doc = await this.taskModel.findOneAndUpdate(
604
- // {
605
- // status: { $eq: factory.taskStatus.Running },
606
- // lastTriedAt: {
607
- // $type: 'date',
608
- // $lt: lastTriedAtShoudBeLessThan
609
- // },
610
- // remainingNumberOfTries: { $eq: 0 }
611
- // },
612
- // {
613
- // $set: {
614
- // status: factory.taskStatus.Aborted,
615
- // dateAborted: new Date()
616
- // }
617
- // },
618
- // { new: true, projection }
619
- // )
620
- // .lean<factory.task.ITask<factory.taskName>>() // lean(2024-09-26~)
621
- // .exec();
622
- // if (doc === null) {
623
- // // tslint:disable-next-line:no-null-keyword
624
- // return null;
625
- // }
626
- // return doc;
627
- // }
628
495
  async abortMany(params) {
629
496
  const lastTriedAtShoudBeLessThan = (0, moment_1.default)()
630
497
  .add(-params.intervalInMinutes, 'minutes')
@@ -668,47 +535,6 @@ class TaskRepo {
668
535
  task_1.taskEventEmitter.emitTaskStatusChanged(changedTask, next);
669
536
  }
670
537
  }
671
- async count(params) {
672
- const { limit } = params;
673
- const conditions = TaskRepo.CREATE_MONGO_CONDITIONS(params);
674
- const query = this.taskModel.countDocuments((conditions.length > 0) ? { $and: conditions } : {});
675
- if (typeof limit === 'number' && limit >= 0) {
676
- query.limit(limit);
677
- }
678
- const count = await query.setOptions({ maxTimeMS: settings_1.MONGO_MAX_TIME_MS })
679
- .exec();
680
- return { count };
681
- }
682
- /**
683
- * 検索する
684
- */
685
- async projectFields(params, inclusion) {
686
- const conditions = TaskRepo.CREATE_MONGO_CONDITIONS(params);
687
- let positiveProjectionFields = AVAILABLE_PROJECT_FIELDS;
688
- if (Array.isArray(inclusion) && inclusion.length > 0) {
689
- positiveProjectionFields = inclusion.filter((key) => AVAILABLE_PROJECT_FIELDS.includes(key));
690
- }
691
- else {
692
- // no op
693
- }
694
- const projection = {
695
- _id: 0,
696
- id: { $toString: '$_id' },
697
- ...Object.fromEntries(positiveProjectionFields.map((key) => ([key, 1])))
698
- };
699
- const query = this.taskModel.find((conditions.length > 0) ? { $and: conditions } : {}, projection);
700
- if (typeof params.limit === 'number' && params.limit > 0) {
701
- const page = (typeof params.page === 'number' && params.page > 0) ? params.page : 1;
702
- query.limit(params.limit)
703
- .skip(params.limit * (page - 1));
704
- }
705
- if (params.sort?.runsAt !== undefined) {
706
- query.sort({ runsAt: params.sort.runsAt });
707
- }
708
- return query.setOptions({ maxTimeMS: settings_1.MONGO_MAX_TIME_MS })
709
- .lean() // lean(2024-09-26~)
710
- .exec();
711
- }
712
538
  /**
713
539
  * タスクの状態を参照する
714
540
  * 非同期アクション移行が完了したら廃止する(2026-07-29~)
@@ -745,18 +571,6 @@ class TaskRepo {
745
571
  })
746
572
  .exec();
747
573
  }
748
- async deleteByName(params) {
749
- return this.taskModel.deleteMany({
750
- name: { $eq: params.name },
751
- ...(typeof params.status?.$eq === 'string') ? { status: { $eq: params.status.$eq } } : undefined,
752
- ...(params.runsAt?.$gte instanceof Date)
753
- ? {
754
- runsAt: { $gte: params.runsAt.$gte, $lte: params.runsAt.$lte }
755
- }
756
- : undefined
757
- })
758
- .exec();
759
- }
760
574
  /**
761
575
  * 不要なタスクを削除する
762
576
  */
@@ -790,135 +604,5 @@ class TaskRepo {
790
604
  .exec();
791
605
  return { count };
792
606
  }
793
- getCursor(conditions, projection) {
794
- return this.taskModel.find(conditions, projection)
795
- .sort({ runsAt: factory_1.factory.sortType.Ascending })
796
- .cursor();
797
- }
798
- async unsetUnnecessaryFields(params) {
799
- return this.taskModel.updateMany(params.filter, { $unset: params.$unset }, { timestamps: false })
800
- .exec();
801
- }
802
- async aggregateTask(params) {
803
- const statuses = await Promise.all([
804
- factory_1.factory.taskStatus.Executed,
805
- factory_1.factory.taskStatus.Aborted
806
- ].map(async (taskStatus) => {
807
- const matchConditions = {
808
- runsAt: {
809
- $gte: params.runsFrom,
810
- $lte: params.runsThrough
811
- },
812
- status: { $eq: taskStatus },
813
- ...(typeof params.project?.id?.$ne === 'string')
814
- ? { 'project.id': { $ne: params.project.id.$ne } }
815
- : undefined
816
- };
817
- return this.agggregateByStatus({ matchConditions, status: taskStatus });
818
- }));
819
- return { statuses };
820
- }
821
- async agggregateByStatus(params) {
822
- const matchConditions = params.matchConditions;
823
- const taskStatus = params.status;
824
- const aggregate1 = this.taskModel.aggregate([
825
- {
826
- $match: matchConditions
827
- },
828
- {
829
- $project: {
830
- latency: { $subtract: ['$lastTriedAt', '$runsAt'] },
831
- status: '$status',
832
- runsAt: '$runsAt',
833
- lastTriedAt: '$lastTriedAt'
834
- }
835
- },
836
- {
837
- $group: {
838
- _id: '$status',
839
- taskCount: { $sum: 1 },
840
- maxLatency: { $max: '$latency' },
841
- minLatency: { $min: '$latency' },
842
- avgLatency: { $avg: '$latency' }
843
- }
844
- },
845
- {
846
- $project: {
847
- _id: 0,
848
- taskCount: '$taskCount',
849
- avgLatency: '$avgLatency',
850
- maxLatency: '$maxLatency',
851
- minLatency: '$minLatency'
852
- }
853
- }
854
- ]);
855
- // const explainResult = await aggregate1.explain();
856
- // console.dir(explainResult, { depth: null });
857
- // return;
858
- const aggregations = await aggregate1.exec();
859
- const percents = [50, 95, 99];
860
- if (aggregations.length === 0) {
861
- return {
862
- status: taskStatus,
863
- aggregation: {
864
- taskCount: 0,
865
- avgLatency: 0,
866
- maxLatency: 0,
867
- minLatency: 0,
868
- percentilesLatency: percents.map((percent) => {
869
- return {
870
- name: String(percent),
871
- value: 0
872
- };
873
- })
874
- }
875
- };
876
- }
877
- const ranks4percentile = percents.map((percentile) => {
878
- return {
879
- percentile,
880
- rank: Math.floor(aggregations[0].taskCount * percentile / 100)
881
- };
882
- });
883
- const aggregate2 = this.taskModel.aggregate([
884
- {
885
- $match: matchConditions
886
- },
887
- {
888
- $project: {
889
- latency: { $subtract: ['$lastTriedAt', '$runsAt'] },
890
- status: '$status',
891
- runsAt: '$runsAt',
892
- lastTriedAt: '$lastTriedAt'
893
- }
894
- },
895
- { $sort: { latency: 1 } },
896
- {
897
- $group: {
898
- _id: '$status',
899
- latencies: { $push: '$latency' }
900
- }
901
- },
902
- {
903
- $project: {
904
- _id: 0,
905
- percentilesLatency: ranks4percentile.map((rank) => {
906
- return {
907
- name: String(rank.percentile),
908
- value: { $arrayElemAt: ['$latencies', rank.rank] }
909
- };
910
- })
911
- }
912
- }
913
- ]);
914
- const aggregations2 = await aggregate2.exec();
915
- return {
916
- status: taskStatus,
917
- aggregation: {
918
- ...aggregations[0],
919
- ...aggregations2[0]
920
- }
921
- };
922
- }
923
607
  }
924
608
  exports.TaskRepo = TaskRepo;
@@ -17,10 +17,12 @@ import type { PayActionRepo } from './repo/action/pay';
17
17
  import type { RefundActionRepo } from './repo/action/refund';
18
18
  import type { AsyncActionRepo } from './repo/asyncAction';
19
19
  import type { AdditionalPropertyRepo } from './repo/additionalProperty';
20
+ import type { AdminTaskRepo } from './repo/adminTask';
20
21
  import type { AggregateActionRepo } from './repo/aggregateAction';
21
22
  import type { AggregateOfferRepo } from './repo/aggregateOffer';
22
23
  import type { AggregateOrderRepo } from './repo/aggregateOrder';
23
24
  import type { AggregateReservationRepo } from './repo/aggregateReservation';
25
+ import type { AggregateTaskRepo } from './repo/aggregateTask';
24
26
  import type { AggregationRepo } from './repo/aggregation';
25
27
  import type { AssetTransactionRepo } from './repo/assetTransaction';
26
28
  import type { ReserveTransactionRepo } from './repo/assetTransaction/reserve';
@@ -159,10 +161,18 @@ export type AdditionalProperty = AdditionalPropertyRepo;
159
161
  export declare namespace AdditionalProperty {
160
162
  function createInstance(...params: ConstructorParameters<typeof AdditionalPropertyRepo>): Promise<AdditionalPropertyRepo>;
161
163
  }
164
+ export type AdminTask = AdminTaskRepo;
165
+ export declare namespace AdminTask {
166
+ function createInstance(...params: ConstructorParameters<typeof AdminTaskRepo>): Promise<AdminTaskRepo>;
167
+ }
162
168
  export type AggregateAction = AggregateActionRepo;
163
169
  export declare namespace AggregateAction {
164
170
  function createInstance(...params: ConstructorParameters<typeof AggregateActionRepo>): Promise<AggregateActionRepo>;
165
171
  }
172
+ export type AggregateTask = AggregateTaskRepo;
173
+ export declare namespace AggregateTask {
174
+ function createInstance(...params: ConstructorParameters<typeof AggregateTaskRepo>): Promise<AggregateTaskRepo>;
175
+ }
166
176
  export type AggregateOffer = AggregateOfferRepo;
167
177
  export declare namespace AggregateOffer {
168
178
  function createInstance(...params: ConstructorParameters<typeof AggregateOfferRepo>): Promise<AggregateOfferRepo>;
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.place = exports.Person = exports.PendingReservation = exports.PaymentServiceProvider = exports.PaymentServiceChannel = exports.PaymentService = exports.Passport = exports.OwnershipInfo = exports.OrderNumber = exports.OrderInTransaction = exports.Order = exports.Offer = exports.OfferItemCondition = exports.OfferCatalogItem = exports.OfferCatalog = exports.NoteAboutOrder = exports.Note = exports.MovieTicketType = exports.Message = exports.MerchantReturnPolicy = exports.MemberProgram = exports.Member = exports.Issuer = exports.IdentityProvider = exports.Identity = exports.EventSeries = exports.EventSellerMakesOffer = exports.EventOffer = exports.Event = exports.EmailMessage = exports.CustomerType = exports.Customer = exports.Credentials = exports.CreativeWork = exports.ConfirmationNumber = exports.Authorization = exports.CategoryCode = exports.assetTransaction = exports.AssetTransaction = exports.Aggregation = exports.AggregateReservation = exports.AggregateOrder = exports.AggregateOffer = exports.AggregateAction = exports.AdditionalProperty = exports.action = exports.Action = exports.AccountTitle = exports.AccountingReport = exports.AcceptedOffer = void 0;
4
- exports.WebSite = exports.rateLimit = exports.TransactionProcess = exports.TransactionNumber = exports.transaction = exports.Transaction = exports.Ticket = exports.AsyncAction = exports.Task = exports.StockHolder = exports.setting = exports.Setting = exports.ServiceAvailableHour = exports.SellerReturnPolicy = exports.SellerPaymentAccepted = exports.SellerMakesOffer = exports.Seller = exports.Schedule = exports.Role = exports.ReserveInterface = exports.Reservation = exports.ProjectMakesOffer = exports.Project = exports.ProductHasOfferCatalog = exports.Product = exports.PriceSpecification = exports.PotentialAction = void 0;
3
+ exports.PendingReservation = exports.PaymentServiceProvider = exports.PaymentServiceChannel = exports.PaymentService = exports.Passport = exports.OwnershipInfo = exports.OrderNumber = exports.OrderInTransaction = exports.Order = exports.Offer = exports.OfferItemCondition = exports.OfferCatalogItem = exports.OfferCatalog = exports.NoteAboutOrder = exports.Note = exports.MovieTicketType = exports.Message = exports.MerchantReturnPolicy = exports.MemberProgram = exports.Member = exports.Issuer = exports.IdentityProvider = exports.Identity = exports.EventSeries = exports.EventSellerMakesOffer = exports.EventOffer = exports.Event = exports.EmailMessage = exports.CustomerType = exports.Customer = exports.Credentials = exports.CreativeWork = exports.ConfirmationNumber = exports.Authorization = exports.CategoryCode = exports.assetTransaction = exports.AssetTransaction = exports.Aggregation = exports.AggregateReservation = exports.AggregateOrder = exports.AggregateOffer = exports.AggregateTask = exports.AggregateAction = exports.AdminTask = exports.AdditionalProperty = exports.action = exports.Action = exports.AccountTitle = exports.AccountingReport = exports.AcceptedOffer = void 0;
4
+ exports.WebSite = exports.rateLimit = exports.TransactionProcess = exports.TransactionNumber = exports.transaction = exports.Transaction = exports.Ticket = exports.AsyncAction = exports.Task = exports.StockHolder = exports.setting = exports.Setting = exports.ServiceAvailableHour = exports.SellerReturnPolicy = exports.SellerPaymentAccepted = exports.SellerMakesOffer = exports.Seller = exports.Schedule = exports.Role = exports.ReserveInterface = exports.Reservation = exports.ProjectMakesOffer = exports.Project = exports.ProductHasOfferCatalog = exports.Product = exports.PriceSpecification = exports.PotentialAction = exports.place = exports.Person = void 0;
5
5
  var AcceptedOffer;
6
6
  (function (AcceptedOffer) {
7
7
  let repo;
@@ -170,6 +170,17 @@ var AdditionalProperty;
170
170
  }
171
171
  AdditionalProperty.createInstance = createInstance;
172
172
  })(AdditionalProperty || (exports.AdditionalProperty = AdditionalProperty = {}));
173
+ var AdminTask;
174
+ (function (AdminTask) {
175
+ let repo;
176
+ async function createInstance(...params) {
177
+ if (repo === undefined) {
178
+ repo = (await import('./repo/adminTask.js')).AdminTaskRepo;
179
+ }
180
+ return new repo(...params);
181
+ }
182
+ AdminTask.createInstance = createInstance;
183
+ })(AdminTask || (exports.AdminTask = AdminTask = {}));
173
184
  var AggregateAction;
174
185
  (function (AggregateAction) {
175
186
  let repo;
@@ -181,6 +192,17 @@ var AggregateAction;
181
192
  }
182
193
  AggregateAction.createInstance = createInstance;
183
194
  })(AggregateAction || (exports.AggregateAction = AggregateAction = {}));
195
+ var AggregateTask;
196
+ (function (AggregateTask) {
197
+ let repo;
198
+ async function createInstance(...params) {
199
+ if (repo === undefined) {
200
+ repo = (await import('./repo/aggregateTask.js')).AggregateTaskRepo;
201
+ }
202
+ return new repo(...params);
203
+ }
204
+ AggregateTask.createInstance = createInstance;
205
+ })(AggregateTask || (exports.AggregateTask = AggregateTask = {}));
184
206
  var AggregateOffer;
185
207
  (function (AggregateOffer) {
186
208
  let repo;
@@ -1,9 +1,9 @@
1
1
  import type { AggregateActionRepo } from '../../repo/aggregateAction';
2
+ import type { AggregateTaskRepo } from '../../repo/aggregateTask';
2
3
  import { AggregationRepo } from '../../repo/aggregation';
3
4
  import type { AssetTransactionRepo } from '../../repo/assetTransaction';
4
5
  import type { EventRepo } from '../../repo/event';
5
6
  import { OrderRepo } from '../../repo/order';
6
- import type { TaskRepo } from '../../repo/task';
7
7
  import type { TransactionRepo } from '../../repo/transaction';
8
8
  type AggregateDurationUnit = 'days' | 'hours';
9
9
  interface IAggregateParams {
@@ -141,7 +141,7 @@ declare function aggregateReserveTransaction(params: IAggregateParams): (repos:
141
141
  }>;
142
142
  declare function aggregateTask(params: IAggregateParams): (repos: {
143
143
  agregation: AggregationRepo;
144
- task: TaskRepo;
144
+ aggregateTask: AggregateTaskRepo;
145
145
  }) => Promise<{
146
146
  aggregationCount: number;
147
147
  aggregateDuration: string;
@@ -673,7 +673,7 @@ function aggregateTask(params) {
673
673
  .add(-i, params.aggregateDurationUnit)
674
674
  .endOf(params.aggregateDurationUnit)
675
675
  .toDate();
676
- const aggregateResult = await repos.task.aggregateTask({
676
+ const aggregateResult = await repos.aggregateTask.aggregateTask({
677
677
  project: { id: { $ne: params.excludedProjectId } },
678
678
  runsFrom,
679
679
  runsThrough
@@ -1,7 +1,7 @@
1
- import type { TaskRepo } from '../../repo/task';
1
+ import type { AdminTaskRepo } from '../../repo/adminTask';
2
2
  import type { IntegrationSettingRepo } from '../../repo/setting/integration';
3
3
  interface INotifyAbortedTasksRepos {
4
- task: TaskRepo;
4
+ adminTask: AdminTaskRepo;
5
5
  integrationSetting: IntegrationSettingRepo;
6
6
  }
7
7
  /**
@@ -16,7 +16,7 @@ const debug = (0, debug_1.default)('chevre-domain:service:notification');
16
16
  function notifyAbortedTasksByEmail(params) {
17
17
  return async (repos) => {
18
18
  const abortedTasksWithoutReport = await repos.integrationSetting.getByKey('abortedTasksWithoutReport');
19
- const abortedTasks = await repos.task.projectFields({
19
+ const abortedTasks = await repos.adminTask.findTasks({
20
20
  limit: params.limit,
21
21
  page: 1,
22
22
  status: { $eq: factory_1.factory.taskStatus.Aborted },
@@ -1,6 +1,3 @@
1
- /**
2
- * 注文決済時処理
3
- */
4
1
  import type { TaskRepo } from '../../../repo/task';
5
2
  import { factory } from '../../../factory';
6
3
  declare function onOrderPaymentDue(params: {
@@ -1,6 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.onOrderPaymentDue = onOrderPaymentDue;
4
+ /**
5
+ * 注文決済時処理
6
+ */
7
+ const util_1 = require("util");
4
8
  const factory_1 = require("../../../factory");
5
9
  function onOrderPaymentDue(params) {
6
10
  return async (repos) => {
@@ -13,8 +17,9 @@ function onOrderPaymentDue(params) {
13
17
  switch (params.order.orderStatus) {
14
18
  // OrderPaymentDueを追加(2023-08-23~)
15
19
  case factory_1.factory.orderStatus.OrderPaymentDue:
20
+ await createConfirmPayTransactionTasks(params.order, simpleOrder)(repos);
16
21
  tasks = [
17
- ...await createConfirmPayTransactionTasks(params.order, simpleOrder)(repos),
22
+ // ...await createConfirmPayTransactionTasks(params.order, simpleOrder)(repos),
18
23
  ...createCreateAccountingReportTask(params.order) // 経理レポート作成タスク(2024-02-02~)
19
24
  ];
20
25
  break;
@@ -27,55 +32,79 @@ function onOrderPaymentDue(params) {
27
32
  function createConfirmPayTransactionTasks(order, simpleOrder) {
28
33
  return async (repos) => {
29
34
  const taskRunsAt = new Date();
30
- const tasks = [];
35
+ // const tasks: factory.task.IAttributes<factory.taskName.ConfirmPayTransaction>[] = [];
31
36
  await Promise.all(order.paymentMethods.map(async (invoice) => {
32
37
  // PaymentAutomaticallyAppliedであれば、自動決済処理を実行(2023-08-24~)
33
38
  if (invoice.paymentStatus !== factory_1.factory.paymentStatusType.PaymentAutomaticallyApplied) {
34
39
  return;
35
40
  }
36
- // 冗長なタスク作成を回避
37
- const existingTasks = await repos.task.projectFields({
38
- limit: 1,
39
- page: 1,
40
- project: { id: { $eq: order.project.id } },
41
+ // 識別子指定でタスク作成(2026-07-30~)
42
+ const data = {
43
+ project: order.project,
44
+ typeOf: factory_1.factory.actionType.ConfirmAction,
45
+ object: [{ typeOf: factory_1.factory.assetTransactionType.Pay, transactionNumber: invoice.paymentMethodId }],
46
+ agent: order.project,
47
+ purpose: {
48
+ ...simpleOrder,
49
+ confirmationNumber: order.confirmationNumber
50
+ },
51
+ processOrder: order.orderStatus === factory_1.factory.orderStatus.OrderPaymentDue, // OrderPaymentDueの場合、processOrderを実行する
52
+ useOnOrderStatusChanged: true
53
+ };
54
+ const taskIdentifier = (0, util_1.format)('%s:%s:%s:%s:%s:%s', order.project.id, factory_1.factory.taskName.ConfirmPayTransaction, data.purpose.typeOf, data.purpose.orderNumber, factory_1.factory.assetTransactionType.Pay, invoice.paymentMethodId);
55
+ const confirmPayTransactionTask = {
56
+ alternateName: taskIdentifier,
57
+ identifier: taskIdentifier,
58
+ project: order.project,
41
59
  name: factory_1.factory.taskName.ConfirmPayTransaction,
42
- data: {
43
- object: { transactionNumber: { $eq: invoice.paymentMethodId } },
44
- purpose: { orderNumber: { $eq: order.orderNumber } }
45
- }
46
- }, ['id']);
47
- if (existingTasks.length === 0) {
48
- const data = {
49
- project: order.project,
50
- typeOf: factory_1.factory.actionType.ConfirmAction,
51
- object: [{ typeOf: factory_1.factory.assetTransactionType.Pay, transactionNumber: invoice.paymentMethodId }],
52
- agent: order.project,
53
- purpose: {
54
- ...simpleOrder,
55
- confirmationNumber: order.confirmationNumber
56
- },
57
- // 廃止(2024-03-12~)
58
- // instrument: {
59
- // typeOf: factory.assetTransactionType.Pay, // 産取引化(2024-03-11~)
60
- // identifier: factory.action.authorize.paymentMethod.any.ServiceIdentifier.Chevre,
61
- // transactionNumber: invoice.paymentMethodId
62
- // },
63
- processOrder: order.orderStatus === factory_1.factory.orderStatus.OrderPaymentDue, // OrderPaymentDueの場合、processOrderを実行する
64
- useOnOrderStatusChanged: true
65
- };
66
- tasks.push({
67
- project: order.project,
68
- name: factory_1.factory.taskName.ConfirmPayTransaction,
69
- status: factory_1.factory.taskStatus.Ready,
70
- runsAt: taskRunsAt,
71
- remainingNumberOfTries: 10,
72
- numberOfTried: 0,
73
- executionResults: [],
74
- data
75
- });
76
- }
60
+ status: factory_1.factory.taskStatus.Ready,
61
+ runsAt: taskRunsAt,
62
+ remainingNumberOfTries: 10,
63
+ numberOfTried: 0,
64
+ executionResults: [],
65
+ data
66
+ };
67
+ await repos.task.createIfNotExistByAlternateName(confirmPayTransactionTask, { emitImmediately: true });
68
+ // 冗長なタスク作成を回避
69
+ // const existingTasks = await repos.task.projectFields(
70
+ // {
71
+ // limit: 1,
72
+ // page: 1,
73
+ // project: { id: { $eq: order.project.id } },
74
+ // name: factory.taskName.ConfirmPayTransaction,
75
+ // data: {
76
+ // object: { transactionNumber: { $eq: invoice.paymentMethodId } },
77
+ // purpose: { orderNumber: { $eq: order.orderNumber } }
78
+ // }
79
+ // },
80
+ // ['id']
81
+ // ) as { id: string }[];
82
+ // if (existingTasks.length === 0) {
83
+ // const data: factory.task.IData<factory.taskName.ConfirmPayTransaction> = {
84
+ // project: order.project,
85
+ // typeOf: factory.actionType.ConfirmAction,
86
+ // object: [{ typeOf: factory.assetTransactionType.Pay, transactionNumber: invoice.paymentMethodId }],
87
+ // agent: order.project,
88
+ // purpose: {
89
+ // ...simpleOrder,
90
+ // confirmationNumber: order.confirmationNumber
91
+ // },
92
+ // processOrder: order.orderStatus === factory.orderStatus.OrderPaymentDue, // OrderPaymentDueの場合、processOrderを実行する
93
+ // useOnOrderStatusChanged: true
94
+ // };
95
+ // tasks.push({
96
+ // project: order.project,
97
+ // name: factory.taskName.ConfirmPayTransaction,
98
+ // status: factory.taskStatus.Ready,
99
+ // runsAt: taskRunsAt,
100
+ // remainingNumberOfTries: 10,
101
+ // numberOfTried: 0,
102
+ // executionResults: [],
103
+ // data
104
+ // });
105
+ // }
77
106
  }));
78
- return tasks;
107
+ // return tasks;
79
108
  };
80
109
  }
81
110
  function createCreateAccountingReportTask(order) {
package/package.json CHANGED
@@ -88,5 +88,5 @@
88
88
  "postversion": "git push origin --tags",
89
89
  "prepublishOnly": "npm run clean && npm run build"
90
90
  },
91
- "version": "25.2.0-alpha.54"
91
+ "version": "25.2.0-alpha.55"
92
92
  }