@nocobase/flow-engine 2.0.0-alpha.47 → 2.0.0-alpha.48

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.
@@ -83,6 +83,33 @@ export declare class CollectionManager {
83
83
  clearCollections(): void;
84
84
  getAssociation(associationName: string): CollectionField | undefined;
85
85
  getChildrenCollections(name: any): any[];
86
+ getCollectionFieldsOptions(collectionName: string, type?: string | string[], interfaces?: string | string[], opts?: {
87
+ dataSource?: string;
88
+ cached?: Record<string, any>;
89
+ collectionNames?: string[];
90
+ /**
91
+ * 为 true 时允许查询所有关联字段
92
+ * 为 Array<string> 时仅允许查询指定的关联字段
93
+ */
94
+ association?: boolean | string[];
95
+ /**
96
+ * Max depth of recursion
97
+ */
98
+ maxDepth?: number;
99
+ allowAllTypes?: boolean;
100
+ /**
101
+ * 排除这些接口的字段
102
+ */
103
+ exceptInterfaces?: string[];
104
+ /**
105
+ * field value 的前缀,用 . 连接,比如 a.b.c
106
+ */
107
+ prefixFieldValue?: string;
108
+ /**
109
+ * 是否使用 prefixFieldValue 作为 field value
110
+ */
111
+ usePrefix?: boolean;
112
+ }): any;
86
113
  }
87
114
  export declare class Collection {
88
115
  fields: Map<string, CollectionField>;
@@ -317,6 +317,57 @@ const _CollectionManager = class _CollectionManager {
317
317
  }, "getChildrens");
318
318
  return getChildrens(name);
319
319
  }
320
+ getCollectionFieldsOptions(collectionName, type, interfaces, opts) {
321
+ var _a;
322
+ const {
323
+ association = false,
324
+ cached = {},
325
+ collectionNames = [collectionName],
326
+ maxDepth = 1,
327
+ allowAllTypes = false,
328
+ exceptInterfaces = [],
329
+ prefixFieldValue = "",
330
+ usePrefix = false,
331
+ dataSource: customDataSourceNameValue
332
+ } = opts || {};
333
+ if (collectionNames.length - 1 > maxDepth) {
334
+ return;
335
+ }
336
+ if (cached[collectionName]) {
337
+ return import_lodash.default.cloneDeep(cached[collectionName]);
338
+ }
339
+ const collection = this.getCollection(collectionName);
340
+ if (!collection) {
341
+ throw new Error(`Collection ${collectionName} not found`);
342
+ }
343
+ const fields = collection.getFields();
344
+ const options = (_a = fields == null ? void 0 : fields.filter(
345
+ (field) => field.interface && !exceptInterfaces.includes(field.interface) && (allowAllTypes || type && type.includes(field.type) || interfaces && interfaces.includes(field.interface) || (association && field.target && field.target !== collectionName && Array.isArray(association) ? association.includes(field.interface) : false))
346
+ )) == null ? void 0 : _a.map((field) => {
347
+ var _a2, _b;
348
+ const result = {
349
+ value: usePrefix && prefixFieldValue ? `${prefixFieldValue}.${field.name}` : field.name,
350
+ label: ((_a2 = field == null ? void 0 : field.uiSchema) == null ? void 0 : _a2.title) || field.name,
351
+ ...field
352
+ };
353
+ if (association && field.target) {
354
+ result.children = collectionNames.includes(field.target) ? [] : this.getCollectionFieldsOptions(field.target, type, interfaces, {
355
+ ...opts,
356
+ cached,
357
+ dataSource: customDataSourceNameValue,
358
+ collectionNames: [...collectionNames, field.target],
359
+ prefixFieldValue: usePrefix ? prefixFieldValue ? `${prefixFieldValue}.${field.name}` : field.name : "",
360
+ usePrefix
361
+ });
362
+ if (!((_b = result.children) == null ? void 0 : _b.length)) {
363
+ return null;
364
+ }
365
+ }
366
+ return result;
367
+ }).filter(Boolean);
368
+ cached[collectionName] = options;
369
+ return options;
370
+ }
320
371
  };
321
372
  __name(_CollectionManager, "CollectionManager");
322
373
  let CollectionManager = _CollectionManager;
@@ -220,6 +220,9 @@ const _BaseRecordResource = class _BaseRecordResource extends import_apiResource
220
220
  return this;
221
221
  }
222
222
  setFilterByTk(filterByTk) {
223
+ if (filterByTk !== null && typeof filterByTk === "object") {
224
+ filterByTk = JSON.stringify(filterByTk);
225
+ }
223
226
  return this.addRequestParameter("filterByTk", filterByTk);
224
227
  }
225
228
  getFilterByTk() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nocobase/flow-engine",
3
- "version": "2.0.0-alpha.47",
3
+ "version": "2.0.0-alpha.48",
4
4
  "private": false,
5
5
  "description": "A standalone flow engine for NocoBase, managing workflows, models, and actions.",
6
6
  "main": "lib/index.js",
@@ -8,8 +8,8 @@
8
8
  "dependencies": {
9
9
  "@formily/antd-v5": "1.x",
10
10
  "@formily/reactive": "2.x",
11
- "@nocobase/sdk": "2.0.0-alpha.47",
12
- "@nocobase/shared": "2.0.0-alpha.47",
11
+ "@nocobase/sdk": "2.0.0-alpha.48",
12
+ "@nocobase/shared": "2.0.0-alpha.48",
13
13
  "ahooks": "^3.7.2",
14
14
  "dayjs": "^1.11.9",
15
15
  "dompurify": "^3.0.2",
@@ -36,5 +36,5 @@
36
36
  ],
37
37
  "author": "NocoBase Team",
38
38
  "license": "AGPL-3.0",
39
- "gitHead": "50e5bfd0c5b6879535d20abcbbabc5541d749e12"
39
+ "gitHead": "456be3a6e92f984fe283590c80d3ea9423695ba6"
40
40
  }
@@ -9,6 +9,7 @@
9
9
 
10
10
  import { observable } from '@formily/reactive';
11
11
  import _ from 'lodash';
12
+ import { CascaderProps } from 'antd';
12
13
  import { FlowEngine } from '../flowEngine';
13
14
  import { jioToJoiSchema } from './jioToJoiSchema';
14
15
  import { sortCollectionsByInherits } from './sortCollectionsByInherits';
@@ -338,6 +339,118 @@ export class CollectionManager {
338
339
  };
339
340
  return getChildrens(name);
340
341
  }
342
+
343
+ getCollectionFieldsOptions(
344
+ collectionName: string,
345
+ type?: string | string[],
346
+ interfaces?: string | string[],
347
+ opts?: {
348
+ dataSource?: string;
349
+ cached?: Record<string, any>;
350
+ collectionNames?: string[];
351
+ /**
352
+ * 为 true 时允许查询所有关联字段
353
+ * 为 Array<string> 时仅允许查询指定的关联字段
354
+ */
355
+ association?: boolean | string[];
356
+ /**
357
+ * Max depth of recursion
358
+ */
359
+ maxDepth?: number;
360
+ allowAllTypes?: boolean;
361
+ /**
362
+ * 排除这些接口的字段
363
+ */
364
+ exceptInterfaces?: string[];
365
+ /**
366
+ * field value 的前缀,用 . 连接,比如 a.b.c
367
+ */
368
+ prefixFieldValue?: string;
369
+ /**
370
+ * 是否使用 prefixFieldValue 作为 field value
371
+ */
372
+ usePrefix?: boolean;
373
+ },
374
+ ) {
375
+ const {
376
+ association = false,
377
+ cached = {},
378
+ collectionNames = [collectionName],
379
+ maxDepth = 1,
380
+ allowAllTypes = false,
381
+ exceptInterfaces = [],
382
+ prefixFieldValue = '',
383
+ usePrefix = false,
384
+ dataSource: customDataSourceNameValue,
385
+ } = opts || {};
386
+
387
+ if (collectionNames.length - 1 > maxDepth) {
388
+ return;
389
+ }
390
+
391
+ if (cached[collectionName]) {
392
+ // avoid infinite recursion
393
+ return _.cloneDeep(cached[collectionName]);
394
+ }
395
+
396
+ // Fetch the collection
397
+ const collection = this.getCollection(collectionName);
398
+ if (!collection) {
399
+ throw new Error(`Collection ${collectionName} not found`);
400
+ }
401
+
402
+ // Get the fields of the collection
403
+ const fields = collection.getFields(); // Assuming `getFields` returns an array of fields for the collection.
404
+
405
+ const options = fields
406
+ ?.filter(
407
+ (field) =>
408
+ field.interface &&
409
+ !exceptInterfaces.includes(field.interface) &&
410
+ (allowAllTypes ||
411
+ (type && type.includes(field.type)) ||
412
+ (interfaces && interfaces.includes(field.interface)) ||
413
+ (association && field.target && field.target !== collectionName && Array.isArray(association)
414
+ ? association.includes(field.interface)
415
+ : false)),
416
+ )
417
+ ?.map((field) => {
418
+ const result: CascaderProps<any>['options'][0] = {
419
+ value: usePrefix && prefixFieldValue ? `${prefixFieldValue}.${field.name}` : field.name,
420
+ label: field?.uiSchema?.title || field.name,
421
+ ...field,
422
+ };
423
+
424
+ if (association && field.target) {
425
+ result.children = collectionNames.includes(field.target)
426
+ ? []
427
+ : this.getCollectionFieldsOptions(field.target, type, interfaces, {
428
+ ...opts,
429
+ cached,
430
+ dataSource: customDataSourceNameValue,
431
+ collectionNames: [...collectionNames, field.target],
432
+ prefixFieldValue: usePrefix
433
+ ? prefixFieldValue
434
+ ? `${prefixFieldValue}.${field.name}`
435
+ : field.name
436
+ : '',
437
+ usePrefix,
438
+ });
439
+
440
+ // If no children are found, don't return the field
441
+ if (!result.children?.length) {
442
+ return null;
443
+ }
444
+ }
445
+ return result;
446
+ })
447
+ // Filter out null values (i.e., fields with no valid options)
448
+ .filter(Boolean);
449
+
450
+ // Cache the result to avoid infinite recursion
451
+ cached[collectionName] = options;
452
+ return options;
453
+ }
341
454
  }
342
455
 
343
456
  // Collection 负责管理自己的 Field
@@ -228,6 +228,9 @@ export abstract class BaseRecordResource<TData = any> extends APIResource<TData>
228
228
  }
229
229
 
230
230
  setFilterByTk(filterByTk: any) {
231
+ if (filterByTk !== null && typeof filterByTk === 'object') {
232
+ filterByTk = JSON.stringify(filterByTk);
233
+ }
231
234
  return this.addRequestParameter('filterByTk', filterByTk);
232
235
  }
233
236