@chevre/domain 22.11.0-alpha.13 → 22.11.0-alpha.14

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.
@@ -30,7 +30,7 @@ async function main() {
30
30
  ]
31
31
  });
32
32
 
33
- const result = await (await chevre.service.task.createService()).notifyAbortedTasksByEmail({
33
+ const result = await (await chevre.service.notification.createService()).notifyAbortedTasksByEmail({
34
34
  dateAbortedGte: moment()
35
35
  // tslint:disable-next-line:no-magic-numbers
36
36
  .add(-10, 'days')
@@ -13,7 +13,7 @@ interface IExecuteSettings {
13
13
  redisClient?: RedisClientType;
14
14
  }
15
15
  type IOperationExecute<T> = (settings: IExecuteSettings) => Promise<T>;
16
- type INextFunction = (task: Pick<factory.task.ITask<factory.taskName>, 'id' | 'remainingNumberOfTries'>) => IOperationExecute<void>;
16
+ type INextFunction = (task: Pick<factory.task.ITask<factory.taskName>, 'id' | 'remainingNumberOfTries' | 'name' | 'status' | 'data'>) => IOperationExecute<void>;
17
17
  interface IReadyTask {
18
18
  id: string;
19
19
  name?: factory.taskName;
@@ -35,13 +35,14 @@ interface IRunningTask {
35
35
  */
36
36
  interface IExecutedTask {
37
37
  id: string;
38
- status: factory.taskStatus;
38
+ status: factory.taskStatus.Executed | factory.taskStatus.Running;
39
39
  executionResult: factory.task.IExecutionResult;
40
40
  /**
41
41
  * 実行されたタスクの残り試行回数
42
42
  */
43
43
  remainingNumberOfTries: number;
44
- name?: never;
44
+ name: factory.taskName;
45
+ data: factory.task.IData<factory.taskName>;
45
46
  expires?: never;
46
47
  }
47
48
  type IChangedTask = IReadyTask | IRunningTask | IExecutedTask;
@@ -77,8 +77,8 @@ export declare class SellerRepo {
77
77
  }): Promise<void>;
78
78
  getCursor(conditions: FilterQuery<factory.seller.ISeller>, projection: any): import("mongoose").Cursor<import("mongoose").Document<unknown, {}, {
79
79
  url?: string | undefined;
80
- project: Pick<factory.project.IProject, "id" | "typeOf">;
81
80
  name: import("@chevre/factory/lib/multilingualString").IMultilingualString;
81
+ project: Pick<factory.project.IProject, "id" | "typeOf">;
82
82
  typeOf: factory.organizationType.Corporation;
83
83
  location?: factory.organization.ILocation | undefined;
84
84
  additionalProperty?: import("@chevre/factory/lib/propertyValue").IPropertyValue<string>[] | undefined;
@@ -89,8 +89,8 @@ export declare class SellerRepo {
89
89
  paymentAccepted?: factory.seller.IPaymentAccepted[] | undefined;
90
90
  }> & {
91
91
  url?: string | undefined;
92
- project: Pick<factory.project.IProject, "id" | "typeOf">;
93
92
  name: import("@chevre/factory/lib/multilingualString").IMultilingualString;
93
+ project: Pick<factory.project.IProject, "id" | "typeOf">;
94
94
  typeOf: factory.organizationType.Corporation;
95
95
  location?: factory.organization.ILocation | undefined;
96
96
  additionalProperty?: import("@chevre/factory/lib/propertyValue").IPropertyValue<string>[] | undefined;
@@ -103,8 +103,8 @@ export declare class SellerRepo {
103
103
  _id: Types.ObjectId;
104
104
  }, QueryOptions<import("mongoose").Document<unknown, {}, {
105
105
  url?: string | undefined;
106
- project: Pick<factory.project.IProject, "id" | "typeOf">;
107
106
  name: import("@chevre/factory/lib/multilingualString").IMultilingualString;
107
+ project: Pick<factory.project.IProject, "id" | "typeOf">;
108
108
  typeOf: factory.organizationType.Corporation;
109
109
  location?: factory.organization.ILocation | undefined;
110
110
  additionalProperty?: import("@chevre/factory/lib/propertyValue").IPropertyValue<string>[] | undefined;
@@ -115,8 +115,8 @@ export declare class SellerRepo {
115
115
  paymentAccepted?: factory.seller.IPaymentAccepted[] | undefined;
116
116
  }> & {
117
117
  url?: string | undefined;
118
- project: Pick<factory.project.IProject, "id" | "typeOf">;
119
118
  name: import("@chevre/factory/lib/multilingualString").IMultilingualString;
119
+ project: Pick<factory.project.IProject, "id" | "typeOf">;
120
120
  typeOf: factory.organizationType.Corporation;
121
121
  location?: factory.organization.ILocation | undefined;
122
122
  additionalProperty?: import("@chevre/factory/lib/propertyValue").IPropertyValue<string>[] | undefined;
@@ -23,7 +23,9 @@ interface IOptionOnCreate {
23
23
  emitImmediately: boolean;
24
24
  }
25
25
  export type IExecutableTaskKeys = 'data' | 'id' | 'name' | 'status' | 'numberOfTried' | 'project' | 'remainingNumberOfTries' | 'runsAt' | 'expires';
26
- export type IExecutableTask<T extends factory.taskName> = Pick<factory.task.ITask<T>, IExecutableTaskKeys>;
26
+ export type IExecutableTask<T extends factory.taskName> = Pick<factory.task.ITask<T>, IExecutableTaskKeys> & {
27
+ status: factory.taskStatus.Running;
28
+ };
27
29
  type IKeyOfProjection = keyof factory.task.ITask<factory.taskName>;
28
30
  type ICreatingTask = Pick<factory.task.IAttributes<factory.taskName>, 'data' | 'executionResults' | 'name' | 'numberOfTried' | 'project' | 'remainingNumberOfTries' | 'runsAt' | 'status' | 'identifier' | 'description'>;
29
31
  /**
@@ -125,15 +127,6 @@ export declare class TaskRepo {
125
127
  runsAt: factory.sortType;
126
128
  };
127
129
  }, next: INextFunction): Promise<Pick<factory.task.ITask<factory.taskName>, 'id' | 'name'> | null>;
128
- findExecutableOne(params: {
129
- name?: {
130
- $eq?: factory.taskName;
131
- $nin?: factory.taskName[];
132
- };
133
- runsAt: {
134
- $lt: Date;
135
- };
136
- }): Promise<IExecutableTask<factory.taskName> | null>;
137
130
  /**
138
131
  * emit OnTaskStatusChanged on delayed tasks
139
132
  */
@@ -171,12 +164,11 @@ export declare class TaskRepo {
171
164
  * タスクID
172
165
  */
173
166
  id: string;
174
- status: factory.taskStatus;
167
+ status: factory.taskStatus.Executed | factory.taskStatus.Running;
175
168
  remainingNumberOfTries: number;
169
+ name: factory.taskName;
170
+ data: factory.task.IData<factory.taskName>;
176
171
  }, executionResult: factory.task.IExecutionResult, next?: INextFunction): Promise<void>;
177
- /**
178
- * 特定タスク検索
179
- */
180
172
  count(params: factory.task.ISearchConditions): Promise<{
181
173
  count: number;
182
174
  }>;
@@ -218,68 +210,68 @@ export declare class TaskRepo {
218
210
  }>;
219
211
  getCursor(conditions: FilterQuery<factory.task.ITask<factory.taskName>>, projection: ProjectionType<factory.task.ITask<factory.taskName>>): import("mongoose").Cursor<import("mongoose").Document<unknown, {}, {
220
212
  remainingNumberOfTries: number;
213
+ name: factory.taskName;
214
+ status: factory.taskStatus;
215
+ data: import("@chevre/factory/lib/task").IData;
221
216
  alternateName?: string | undefined;
222
217
  identifier?: string | undefined;
223
218
  description?: string | undefined;
224
219
  project: Pick<factory.project.IProject, "id" | "typeOf">;
225
- name: factory.taskName;
226
- status: factory.taskStatus;
227
220
  runsAt: Date;
228
221
  lastTriedAt?: Date | undefined;
229
222
  numberOfTried: number;
230
223
  executionResults: import("@chevre/factory/lib/task").IExecutionResult[];
231
224
  executor?: import("@chevre/factory/lib/task").IExecutor | undefined;
232
- data: import("@chevre/factory/lib/task").IData;
233
225
  dateAborted?: Date | undefined;
234
226
  expires?: Date | undefined;
235
227
  }> & {
236
228
  remainingNumberOfTries: number;
229
+ name: factory.taskName;
230
+ status: factory.taskStatus;
231
+ data: import("@chevre/factory/lib/task").IData;
237
232
  alternateName?: string | undefined;
238
233
  identifier?: string | undefined;
239
234
  description?: string | undefined;
240
235
  project: Pick<factory.project.IProject, "id" | "typeOf">;
241
- name: factory.taskName;
242
- status: factory.taskStatus;
243
236
  runsAt: Date;
244
237
  lastTriedAt?: Date | undefined;
245
238
  numberOfTried: number;
246
239
  executionResults: import("@chevre/factory/lib/task").IExecutionResult[];
247
240
  executor?: import("@chevre/factory/lib/task").IExecutor | undefined;
248
- data: import("@chevre/factory/lib/task").IData;
249
241
  dateAborted?: Date | undefined;
250
242
  expires?: Date | undefined;
251
243
  } & {
252
244
  _id: import("mongoose").Types.ObjectId;
253
245
  }, import("mongoose").QueryOptions<import("mongoose").Document<unknown, {}, {
254
246
  remainingNumberOfTries: number;
247
+ name: factory.taskName;
248
+ status: factory.taskStatus;
249
+ data: import("@chevre/factory/lib/task").IData;
255
250
  alternateName?: string | undefined;
256
251
  identifier?: string | undefined;
257
252
  description?: string | undefined;
258
253
  project: Pick<factory.project.IProject, "id" | "typeOf">;
259
- name: factory.taskName;
260
- status: factory.taskStatus;
261
254
  runsAt: Date;
262
255
  lastTriedAt?: Date | undefined;
263
256
  numberOfTried: number;
264
257
  executionResults: import("@chevre/factory/lib/task").IExecutionResult[];
265
258
  executor?: import("@chevre/factory/lib/task").IExecutor | undefined;
266
- data: import("@chevre/factory/lib/task").IData;
267
259
  dateAborted?: Date | undefined;
268
260
  expires?: Date | undefined;
269
261
  }> & {
270
262
  remainingNumberOfTries: number;
263
+ name: factory.taskName;
264
+ status: factory.taskStatus;
265
+ data: import("@chevre/factory/lib/task").IData;
271
266
  alternateName?: string | undefined;
272
267
  identifier?: string | undefined;
273
268
  description?: string | undefined;
274
269
  project: Pick<factory.project.IProject, "id" | "typeOf">;
275
- name: factory.taskName;
276
- status: factory.taskStatus;
277
270
  runsAt: Date;
278
271
  lastTriedAt?: Date | undefined;
279
272
  numberOfTried: number;
280
273
  executionResults: import("@chevre/factory/lib/task").IExecutionResult[];
281
274
  executor?: import("@chevre/factory/lib/task").IExecutor | undefined;
282
- data: import("@chevre/factory/lib/task").IData;
283
275
  dateAborted?: Date | undefined;
284
276
  expires?: Date | undefined;
285
277
  } & {
@@ -242,48 +242,6 @@ class TaskRepo {
242
242
  return { id, status };
243
243
  });
244
244
  }
245
- // public async createIfNotExistByIdentifier(
246
- // params: factory.task.IAttributes<factory.taskName> & {
247
- // // resolve uniqueness of identifier(2025-03-27~)
248
- // identifier: string;
249
- // },
250
- // options: IOptionOnCreate
251
- // ): Promise<void> {
252
- // if (typeof params.identifier !== 'string' || params.identifier.length === 0) {
253
- // throw new factory.errors.ArgumentNull('identifier');
254
- // }
255
- // try {
256
- // const createdTask = await this.taskModel.findOneAndUpdate(
257
- // {
258
- // 'project.id': { $eq: params.project.id },
259
- // name: { $eq: params.name },
260
- // identifier: { $exists: true, $eq: params.identifier }
261
- // },
262
- // { $setOnInsert: params },
263
- // { new: true, upsert: true }
264
- // )
265
- // .select({ _id: 1 })
266
- // .exec();
267
- // if (options.emitImmediately) {
268
- // taskEventEmitter.emitTaskStatusChanged({
269
- // id: createdTask.id,
270
- // name: params.name,
271
- // status: factory.taskStatus.Ready
272
- // });
273
- // }
274
- // } catch (error) {
275
- // let throwsError = true;
276
- // if (await isMongoError(error)) {
277
- // // すでにidentifierが存在する場合ok
278
- // if (error.code === MongoErrorCode.DuplicateKey) {
279
- // throwsError = false;
280
- // }
281
- // }
282
- // if (throwsError) {
283
- // throw error;
284
- // }
285
- // }
286
- // }
287
245
  /**
288
246
  * タスク識別子から冪等作成する
289
247
  * reimplement createIfNotExistByIdentifier(2025-03-28~)
@@ -341,40 +299,6 @@ class TaskRepo {
341
299
  }
342
300
  });
343
301
  }
344
- // public async createInformTaskIfNotExist(
345
- // // resolve uniqueness of identifier(2025-03-27~)
346
- // params: Pick<
347
- // factory.task.IAttributes<factory.taskName.TriggerWebhook>,
348
- // 'data' | 'executionResults' | 'name' | 'numberOfTried' | 'project' | 'remainingNumberOfTries' | 'runsAt' | 'status'
349
- // > & {
350
- // data: factory.task.triggerWebhook.IInformAnyResourceAction & {
351
- // object: factory.notification.person.IPersonAsNotification;
352
- // };
353
- // },
354
- // options: IOptionOnCreate
355
- // ): Promise<void> {
356
- // const createdTask = await this.taskModel.findOneAndUpdate(
357
- // {
358
- // 'project.id': { $eq: params.project.id },
359
- // name: params.name,
360
- // 'data.object.id': {
361
- // $exists: true,
362
- // $eq: String(params.data.object.id)
363
- // }
364
- // },
365
- // { $setOnInsert: params },
366
- // { new: true, upsert: true }
367
- // )
368
- // .select({ _id: 1 })
369
- // .exec();
370
- // if (options.emitImmediately) {
371
- // taskEventEmitter.emitTaskStatusChanged({
372
- // id: createdTask.id,
373
- // name: params.name,
374
- // status: factory.taskStatus.Ready
375
- // });
376
- // }
377
- // }
378
302
  /**
379
303
  * 取引削除タスク冪等作成
380
304
  */
@@ -599,36 +523,51 @@ class TaskRepo {
599
523
  return doc;
600
524
  });
601
525
  }
602
- findExecutableOne(params) {
603
- return __awaiter(this, void 0, void 0, function* () {
604
- var _a, _b;
605
- if (!(params.runsAt.$lt instanceof Date)) {
606
- throw new factory.errors.Argument('runsAt.$lt', 'must be Date');
607
- }
608
- const nameEq = (_a = params.name) === null || _a === void 0 ? void 0 : _a.$eq;
609
- const nameNin = (_b = params.name) === null || _b === void 0 ? void 0 : _b.$nin;
610
- const query = this.taskModel.findOne(Object.assign({ status: { $eq: factory.taskStatus.Ready }, runsAt: { $lt: params.runsAt.$lt } }, (typeof nameEq === 'string' || Array.isArray(nameNin))
611
- ? {
612
- name: Object.assign(Object.assign({}, (typeof nameEq === 'string') ? { $eq: nameEq } : undefined), (Array.isArray(nameNin)) ? { $nin: nameNin } : undefined)
613
- }
614
- : undefined), executableTaskProjection)
615
- .sort({
616
- runsAt: factory.sortType.Ascending
617
- });
618
- // .hint('executeOneByName');
619
- // const explainResult = await query.explain();
620
- // console.dir(explainResult, { depth: null });
621
- // console.log(explainResult[0].executionStats.allPlansExecution.map((e: any) => e.executionStages.inputStage));
622
- const doc = yield query.setOptions({ maxTimeMS: settings_1.MONGO_MAX_TIME_MS })
623
- .lean()
624
- .exec();
625
- if (doc === null) {
626
- // tslint:disable-next-line:no-null-keyword
627
- return null;
628
- }
629
- return doc;
630
- });
631
- }
526
+ // public async findExecutableOne(params: {
527
+ // name?: {
528
+ // $eq?: factory.taskName;
529
+ // $nin?: factory.taskName[];
530
+ // };
531
+ // runsAt: {
532
+ // $lt: Date;
533
+ // };
534
+ // }): Promise<IExecutableTask<factory.taskName> | null> {
535
+ // if (!(params.runsAt.$lt instanceof Date)) {
536
+ // throw new factory.errors.Argument('runsAt.$lt', 'must be Date');
537
+ // }
538
+ // const nameEq = params.name?.$eq;
539
+ // const nameNin = params.name?.$nin;
540
+ // const query = this.taskModel.findOne(
541
+ // {
542
+ // status: { $eq: factory.taskStatus.Ready },
543
+ // runsAt: { $lt: params.runsAt.$lt },
544
+ // ...(typeof nameEq === 'string' || Array.isArray(nameNin))
545
+ // ? {
546
+ // name: {
547
+ // ...(typeof nameEq === 'string') ? { $eq: nameEq } : undefined,
548
+ // ...(Array.isArray(nameNin)) ? { $nin: nameNin } : undefined
549
+ // }
550
+ // }
551
+ // : undefined
552
+ // },
553
+ // executableTaskProjection
554
+ // )
555
+ // .sort({
556
+ // runsAt: factory.sortType.Ascending
557
+ // });
558
+ // // .hint('executeOneByName');
559
+ // // const explainResult = await query.explain();
560
+ // // console.dir(explainResult, { depth: null });
561
+ // // console.log(explainResult[0].executionStats.allPlansExecution.map((e: any) => e.executionStages.inputStage));
562
+ // const doc = await query.setOptions({ maxTimeMS: MONGO_MAX_TIME_MS })
563
+ // .lean<IExecutableTask<factory.taskName>>()
564
+ // .exec();
565
+ // if (doc === null) {
566
+ // // tslint:disable-next-line:no-null-keyword
567
+ // return null;
568
+ // }
569
+ // return doc;
570
+ // }
632
571
  // discontinue(2025-05-26~)
633
572
  /**
634
573
  * emit OnTaskStatusChanged on delayed tasks
@@ -804,7 +743,7 @@ class TaskRepo {
804
743
  // support customr function(2025-05-25~)
805
744
  next) {
806
745
  return __awaiter(this, void 0, void 0, function* () {
807
- const { id, status, remainingNumberOfTries } = params;
746
+ const { id, status, remainingNumberOfTries, name, data } = params;
808
747
  yield this.taskModel.updateOne({ _id: { $eq: id } }, {
809
748
  $set: { status },
810
749
  $push: { executionResults: executionResult }
@@ -812,35 +751,11 @@ class TaskRepo {
812
751
  .exec();
813
752
  // emit event(2025-05-26~)
814
753
  if (typeof next === 'function') {
815
- const changedTask = { id, status, remainingNumberOfTries, executionResult };
754
+ const changedTask = { id, name, status, data, remainingNumberOfTries, executionResult };
816
755
  task_1.taskEventEmitter.emitTaskStatusChanged(changedTask, next);
817
756
  }
818
757
  });
819
758
  }
820
- /**
821
- * 特定タスク検索
822
- */
823
- // public async findById<T extends factory.taskName>(params: {
824
- // name: T;
825
- // id: string;
826
- // }): Promise<factory.task.ITask<T>> {
827
- // const doc = await this.taskModel.findOne(
828
- // {
829
- // name: { $eq: params.name },
830
- // _id: { $eq: params.id }
831
- // },
832
- // {
833
- // __v: 0,
834
- // createdAt: 0,
835
- // updatedAt: 0
836
- // }
837
- // )
838
- // .exec();
839
- // if (doc === null) {
840
- // throw new factory.errors.NotFound('Task');
841
- // }
842
- // return doc.toObject();
843
- // }
844
759
  count(params) {
845
760
  return __awaiter(this, void 0, void 0, function* () {
846
761
  const { limit } = params;
@@ -1,3 +1,5 @@
1
1
  import * as factory from '../../factory';
2
2
  import type { ICallResult, IExecutableTaskKeys, IOperationExecute } from '../taskHandler';
3
- export declare function call(params: Pick<factory.task.aggregateOnSystem.ITask, IExecutableTaskKeys>): IOperationExecute<ICallResult>;
3
+ export declare function call(params: Pick<factory.task.aggregateOnSystem.ITask, IExecutableTaskKeys> & {
4
+ status: factory.taskStatus.Running;
5
+ }): IOperationExecute<ICallResult>;
@@ -1,3 +1,5 @@
1
1
  import * as factory from '../../factory';
2
2
  import type { ICallResult, IExecutableTaskKeys, IOperationExecute } from '../taskHandler';
3
- export declare function call(params: Pick<factory.task.handleNotification.ITask, IExecutableTaskKeys>): IOperationExecute<ICallResult>;
3
+ export declare function call(params: Pick<factory.task.handleNotification.ITask, IExecutableTaskKeys> & {
4
+ status: factory.taskStatus.Running;
5
+ }): IOperationExecute<ICallResult>;
@@ -73,7 +73,9 @@ function executeTask(task, next) {
73
73
  yield taskRepo.pushExecutionResultById({
74
74
  id: task.id,
75
75
  status: factory.taskStatus.Executed,
76
- remainingNumberOfTries: task.remainingNumberOfTries
76
+ remainingNumberOfTries: task.remainingNumberOfTries,
77
+ name: task.name,
78
+ data: task.data
77
79
  }, result, (typeof next === 'function') ? next : undefined);
78
80
  }
79
81
  catch (error) {
@@ -91,7 +93,9 @@ function executeTask(task, next) {
91
93
  yield taskRepo.pushExecutionResultById({
92
94
  id: task.id,
93
95
  status: task.status,
94
- remainingNumberOfTries: task.remainingNumberOfTries
96
+ remainingNumberOfTries: task.remainingNumberOfTries,
97
+ name: task.name,
98
+ data: task.data
95
99
  }, result, (typeof next === 'function') ? next : undefined);
96
100
  }
97
101
  });
package/package.json CHANGED
@@ -115,5 +115,5 @@
115
115
  "postversion": "git push origin --tags",
116
116
  "prepublishOnly": "npm run clean && npm run build && npm test && npm run doc"
117
117
  },
118
- "version": "22.11.0-alpha.13"
118
+ "version": "22.11.0-alpha.14"
119
119
  }