@chevre/domain 25.2.0-alpha.48 → 25.2.0-alpha.49

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.
@@ -1,11 +1,12 @@
1
1
  import type { Connection, UpdateWriteOpResult } from 'mongoose';
2
2
  import { factory } from '../factory';
3
- import { IModel } from './mongoose/schemas/asyncAction';
3
+ import { IModel, IDocType } from './mongoose/schemas/asyncAction';
4
4
  import type { IExecutableTask } from '../taskSettings';
5
5
  type ISavingTask = Pick<factory.task.IAttributes<factory.taskName>, 'alternateName' | 'data' | 'description' | 'executionResults' | 'expires' | 'identifier' | '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
+ type IKeyOfProjection = keyof factory.task.ITask<factory.taskName>;
9
10
  /**
10
11
  * 非同期アクションリポジトリ
11
12
  */
@@ -30,6 +31,22 @@ export declare class AsyncActionRepo {
30
31
  name: string;
31
32
  };
32
33
  }): Promise<IExecutableAsyncAction | null>;
34
+ /**
35
+ * 非同期アクションの状態を参照する
36
+ */
37
+ findAsyncActionById(params: {
38
+ id: {
39
+ $eq: string;
40
+ };
41
+ project: {
42
+ id: {
43
+ $eq: string;
44
+ };
45
+ };
46
+ name: factory.taskName;
47
+ }, inclusion: IKeyOfProjection[]): Promise<(IDocType & {
48
+ id: string;
49
+ } | undefined)>;
33
50
  /**
34
51
  * Readyのままで期限切れのタスクをExpiredに変更する
35
52
  */
@@ -19,6 +19,21 @@ const executableTaskProjection = {
19
19
  runsAt: 1,
20
20
  expires: 1
21
21
  };
22
+ const AVAILABLE_PROJECT_FIELDS = [
23
+ 'alternateName',
24
+ 'identifier',
25
+ 'description',
26
+ 'project',
27
+ 'name',
28
+ 'status',
29
+ 'runsAt',
30
+ 'lastTriedAt',
31
+ 'executionResults',
32
+ 'executor',
33
+ 'data',
34
+ 'dateAborted',
35
+ 'expires'
36
+ ];
22
37
  /**
23
38
  * 非同期アクションリポジトリ
24
39
  */
@@ -72,6 +87,35 @@ class AsyncActionRepo {
72
87
  }
73
88
  return doc;
74
89
  }
90
+ /**
91
+ * 非同期アクションの状態を参照する
92
+ */
93
+ async findAsyncActionById(params, inclusion) {
94
+ let positiveProjectionFields = AVAILABLE_PROJECT_FIELDS;
95
+ if (Array.isArray(inclusion) && inclusion.length > 0) {
96
+ positiveProjectionFields = inclusion.filter((key) => AVAILABLE_PROJECT_FIELDS.includes(key));
97
+ }
98
+ else {
99
+ // no op
100
+ }
101
+ const projection = {
102
+ _id: 0,
103
+ id: { $toString: '$_id' },
104
+ ...Object.fromEntries(positiveProjectionFields.map((key) => ([key, 1])))
105
+ };
106
+ const query = this.asyncActionModel.findOne({
107
+ _id: { $eq: params.id.$eq },
108
+ 'project.id': { $eq: params.project.id.$eq },
109
+ name: { $eq: params.name }
110
+ }, projection);
111
+ const doc = await query.setOptions({ maxTimeMS: settings_1.MONGO_MAX_TIME_MS })
112
+ .lean()
113
+ .exec();
114
+ if (doc === null) {
115
+ return;
116
+ }
117
+ return doc;
118
+ }
75
119
  /**
76
120
  * Readyのままで期限切れのタスクをExpiredに変更する
77
121
  */
@@ -1,5 +1,6 @@
1
1
  import { factory } from '../../../factory';
2
2
  import type { AcceptCOAOfferActionRepo } from '../../../repo/action/acceptCOAOffer';
3
+ import type { AsyncActionRepo } from '../../../repo/asyncAction';
3
4
  import type { TaskRepo } from '../../../repo/task';
4
5
  interface IFindAcceptActionResult {
5
6
  /**
@@ -34,8 +35,11 @@ declare function findAcceptAction(params: {
34
35
  */
35
36
  id: string;
36
37
  };
38
+ }, options: {
39
+ useAsyncAction: boolean;
37
40
  }): (repos: {
38
41
  action: AcceptCOAOfferActionRepo;
42
+ asyncAction: AsyncActionRepo;
39
43
  task: TaskRepo;
40
44
  }) => Promise<IFindAcceptActionResult>;
41
45
  export { findAcceptAction };
@@ -2,16 +2,29 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.findAcceptAction = findAcceptAction;
4
4
  const factory_1 = require("../../../factory");
5
- function findAcceptAction(params) {
5
+ function findAcceptAction(params, options) {
6
6
  return async (repos) => {
7
- // タスク検索
8
- const task = (await repos.task.projectFields({
9
- limit: 1,
10
- page: 1,
11
- id: { $eq: params.sameAs.id },
12
- project: { id: { $eq: params.project.id } },
13
- name: factory_1.factory.taskName.AcceptCOAOffer
14
- }, ['status', 'executionResults'])).shift();
7
+ // 非同期アクションに対応(2026-07-27~)
8
+ const { useAsyncAction } = options;
9
+ let task;
10
+ if (useAsyncAction) {
11
+ // まず非同期アクションを参照
12
+ task = await repos.asyncAction.findAsyncActionById({
13
+ id: { $eq: params.sameAs.id },
14
+ project: { id: { $eq: params.project.id } },
15
+ name: factory_1.factory.taskName.AcceptCOAOffer
16
+ }, ['status', 'executionResults']);
17
+ }
18
+ // 非同期アクションが存在しなければタスクを参照
19
+ if (task === undefined) {
20
+ task = (await repos.task.projectFields({
21
+ limit: 1,
22
+ page: 1,
23
+ id: { $eq: params.sameAs.id },
24
+ project: { id: { $eq: params.project.id } },
25
+ name: factory_1.factory.taskName.AcceptCOAOffer
26
+ }, ['status', 'executionResults'])).shift();
27
+ }
15
28
  if (task === undefined) {
16
29
  throw new factory_1.factory.errors.NotFound(factory_1.factory.taskName.AcceptCOAOffer);
17
30
  }
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.48"
91
+ "version": "25.2.0-alpha.49"
92
92
  }