@kne/fastify-task 3.0.0-alpha.11 → 3.0.0-alpha.13

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.
@@ -94,6 +94,10 @@ module.exports = fp(async (fastify, options) => {
94
94
  targetId: {
95
95
  type: 'string'
96
96
  },
97
+ targetName: {
98
+ type: 'string',
99
+ description: '目标对象名称,对应任务 input.name'
100
+ },
97
101
  type: {
98
102
  type: 'string'
99
103
  },
@@ -212,7 +212,17 @@ const createContext = (fastify, options) => {
212
212
  const getTaskDeclaration = type => {
213
213
  const declaration = resolveTaskDeclaration(type);
214
214
  if (!declaration) {
215
- throw new Error('未找到合法的任务声明');
215
+ const { taskName } = splitTaskName(type);
216
+ return registerTaskDeclaration({
217
+ namespace: mainNamespace,
218
+ taskName,
219
+ dirs: options.dirs,
220
+ scriptName: options.scriptName,
221
+ config: {},
222
+ override: false,
223
+ syncLegacyTask: false,
224
+ useGlobalDirs: true
225
+ }).declaration;
216
226
  }
217
227
  return declaration;
218
228
  };
@@ -142,7 +142,36 @@ module.exports = fp(async (fastify, options) => {
142
142
  }
143
143
  };
144
144
 
145
- const list = async ({ filter, perPage = 20, currentPage = 1, sort }) => {
145
+ const normalizeListQuery = (query = {}) => {
146
+ const normalized = Object.assign({}, query);
147
+
148
+ Object.entries(query || {}).forEach(([rawKey, value]) => {
149
+ const match = rawKey.match(/^(filter|sort)\[([^\]]+)\](?:\[([^\]]+)\])?$/);
150
+ if (!match) {
151
+ return;
152
+ }
153
+
154
+ const [, root, key, childKey] = match;
155
+ if (!normalized[root] || typeof normalized[root] !== 'object' || Array.isArray(normalized[root])) {
156
+ normalized[root] = {};
157
+ }
158
+
159
+ if (childKey) {
160
+ if (!normalized[root][key] || typeof normalized[root][key] !== 'object' || Array.isArray(normalized[root][key])) {
161
+ normalized[root][key] = {};
162
+ }
163
+ normalized[root][key][childKey] = value;
164
+ } else {
165
+ normalized[root][key] = value;
166
+ }
167
+ delete normalized[rawKey];
168
+ });
169
+
170
+ return normalized;
171
+ };
172
+
173
+ const list = async query => {
174
+ const { filter, perPage = 20, currentPage = 1, sort } = normalizeListQuery(query);
146
175
  const whereQuery = {};
147
176
 
148
177
  ['id', 'targetId', 'type', 'status', 'runnerType'].forEach(key => {
@@ -151,6 +180,10 @@ module.exports = fp(async (fastify, options) => {
151
180
  }
152
181
  });
153
182
 
183
+ if (filter && filter.targetName) {
184
+ whereQuery['input.name'] = filter.targetName;
185
+ }
186
+
154
187
  if (filter && filter.createdAt) {
155
188
  whereQuery.createdAt = getTimeQuery(filter.createdAt);
156
189
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kne/fastify-task",
3
- "version": "3.0.0-alpha.11",
3
+ "version": "3.0.0-alpha.13",
4
4
  "description": "一个 Fastify 插件,用于任务编排、追踪任务执行状态和结果。支持系统自动执行和手动执行两种模式,提供完整的任务生命周期管理",
5
5
  "main": "index.js",
6
6
  "scripts": {