@nocobase/plugin-flow-engine 2.1.0-alpha.9 → 2.1.0-beta.10
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.
- package/dist/ai/docs/runjs/context/block-model.md +35 -35
- package/dist/ai/docs/runjs/context/collection-field.md +51 -53
- package/dist/ai/docs/runjs/context/collection.md +39 -39
- package/dist/ai/docs/runjs/context/data-source-manager.md +30 -40
- package/dist/ai/docs/runjs/context/data-source.md +44 -52
- package/dist/ai/docs/runjs/context/element.md +38 -44
- package/dist/ai/docs/runjs/context/exit-all.md +35 -37
- package/dist/ai/docs/runjs/context/exit.md +35 -38
- package/dist/ai/docs/runjs/context/filter-manager.md +30 -36
- package/dist/ai/docs/runjs/context/form.md +57 -57
- package/dist/ai/docs/runjs/context/get-model.md +21 -22
- package/dist/ai/docs/runjs/context/get-value.md +19 -20
- package/dist/ai/docs/runjs/context/get-var.md +55 -61
- package/dist/ai/docs/runjs/context/i18n.md +14 -17
- package/dist/ai/docs/runjs/context/import-async.md +45 -333
- package/dist/ai/docs/runjs/context/init-resource.md +20 -20
- package/dist/ai/docs/runjs/context/libs.md +31 -31
- package/dist/ai/docs/runjs/context/location.md +31 -34
- package/dist/ai/docs/runjs/context/logger.md +40 -41
- package/dist/ai/docs/runjs/context/make-resource.md +26 -27
- package/dist/ai/docs/runjs/context/message.md +41 -42
- package/dist/ai/docs/runjs/context/modal.md +44 -44
- package/dist/ai/docs/runjs/context/model.md +33 -36
- package/dist/ai/docs/runjs/context/notification.md +40 -41
- package/dist/ai/docs/runjs/context/off.md +14 -14
- package/dist/ai/docs/runjs/context/on.md +29 -30
- package/dist/ai/docs/runjs/context/open-view.md +40 -40
- package/dist/ai/docs/runjs/context/render.md +32 -37
- package/dist/ai/docs/runjs/context/request.md +45 -46
- package/dist/ai/docs/runjs/context/require-async.md +25 -28
- package/dist/ai/docs/runjs/context/resource.md +34 -34
- package/dist/ai/docs/runjs/context/route.md +34 -36
- package/dist/ai/docs/runjs/context/router.md +31 -43
- package/dist/ai/docs/runjs/context/set-value.md +17 -18
- package/dist/ai/docs/runjs/context/t.md +17 -20
- package/dist/ai/docs/runjs/context/view.md +46 -49
- package/dist/ai/docs/runjs/document.md +0 -1
- package/dist/ai/docs/runjs/import-modules.md +32 -32
- package/dist/ai/docs/runjs/index.md +13 -13
- package/dist/ai/docs/runjs/jsx.md +19 -19
- package/dist/ai/docs/runjs/model/form-block-model.md +3 -1
- package/dist/ai/docs/runjs/render.md +15 -15
- package/dist/ai/docs/runjs/resource/api-resource.md +53 -53
- package/dist/ai/docs/runjs/resource/multi-record-resource.md +64 -64
- package/dist/ai/docs/runjs/resource/single-record-resource.md +55 -55
- package/dist/ai/docs/runjs/resource/sql-resource.md +57 -57
- package/dist/ai/docs/runjs/window.md +5 -5
- package/dist/externalVersion.js +10 -10
- package/dist/node_modules/ses/package.json +1 -1
- package/dist/node_modules/zod/package.json +1 -1
- package/package.json +2 -2
|
@@ -1,49 +1,49 @@
|
|
|
1
1
|
# ctx.blockModel
|
|
2
2
|
|
|
3
|
-
The parent block model (BlockModel instance)
|
|
3
|
+
The parent block model (BlockModel instance) that hosts the current JS field / JS block. In JSField, JSItem, JSColumn, etc., `ctx.blockModel` refers to the form block or table block that hosts the current JS logic; in a standalone JSBlock it may be `null` or the same as `ctx.model`.
|
|
4
4
|
|
|
5
|
-
##
|
|
5
|
+
## Use Cases
|
|
6
6
|
|
|
7
7
|
| Scenario | Description |
|
|
8
|
-
|
|
9
|
-
| **JSField** | Access
|
|
10
|
-
| **JSItem** | Access
|
|
11
|
-
| **JSColumn** | Access
|
|
12
|
-
| **Form
|
|
8
|
+
|----------|-------------|
|
|
9
|
+
| **JSField** | Access parent form block's `form`, `collection`, `resource` for linkage or validation |
|
|
10
|
+
| **JSItem** | Access parent table/form block's resource and collection in sub-table items |
|
|
11
|
+
| **JSColumn** | Access parent table block's `resource` (e.g. `getSelectedRows`), `collection` |
|
|
12
|
+
| **Form actions / event flow** | Use `form` for pre-submit validation, `resource` for refresh, etc. |
|
|
13
13
|
|
|
14
|
-
> Note: `ctx.blockModel` is only available in RunJS contexts
|
|
14
|
+
> Note: `ctx.blockModel` is only available in RunJS contexts that have a parent block; in a standalone JSBlock (no parent form/table) it may be `null`—check before use.
|
|
15
15
|
|
|
16
|
-
## Type
|
|
16
|
+
## Type
|
|
17
17
|
|
|
18
18
|
```ts
|
|
19
19
|
blockModel: BlockModel | FormBlockModel | TableBlockModel | CollectionBlockModel | DataBlockModel | null;
|
|
20
20
|
```
|
|
21
21
|
|
|
22
|
-
The
|
|
22
|
+
The exact type depends on the parent block: form blocks are usually `FormBlockModel` / `EditFormModel`, table blocks are usually `TableBlockModel`.
|
|
23
23
|
|
|
24
24
|
## Common Properties
|
|
25
25
|
|
|
26
26
|
| Property | Type | Description |
|
|
27
|
-
|
|
28
|
-
| `uid` | `string` |
|
|
29
|
-
| `collection` | `Collection` |
|
|
30
|
-
| `resource` | `Resource` |
|
|
31
|
-
| `form` | `FormInstance` | Form
|
|
32
|
-
| `emitter` | `EventEmitter` | Event emitter
|
|
27
|
+
|----------|------|-------------|
|
|
28
|
+
| `uid` | `string` | Block model unique id |
|
|
29
|
+
| `collection` | `Collection` | Collection bound to the block |
|
|
30
|
+
| `resource` | `Resource` | Resource instance (`SingleRecordResource` / `MultiRecordResource`, etc.) |
|
|
31
|
+
| `form` | `FormInstance` | Form block: Ant Design Form instance (`getFieldsValue`, `validateFields`, `setFieldsValue`, etc.) |
|
|
32
|
+
| `emitter` | `EventEmitter` | Event emitter; can listen to `formValuesChange`, `onFieldReset`, etc. |
|
|
33
33
|
|
|
34
|
-
##
|
|
34
|
+
## Relation to ctx.model, ctx.form
|
|
35
35
|
|
|
36
|
-
|
|
|
37
|
-
|
|
38
|
-
| **Parent block of
|
|
39
|
-
| **Read/
|
|
40
|
-
| **Model
|
|
36
|
+
| Need | Recommended |
|
|
37
|
+
|------|-------------|
|
|
38
|
+
| **Parent block of current JS** | `ctx.blockModel` |
|
|
39
|
+
| **Read/write form fields** | `ctx.form` (same as `ctx.blockModel?.form`; more convenient in form blocks) |
|
|
40
|
+
| **Model for current execution context** | `ctx.model` (field model in JSField, block model in JSBlock) |
|
|
41
41
|
|
|
42
|
-
In
|
|
42
|
+
In JSField, `ctx.model` is the field model and `ctx.blockModel` is the form/table block that hosts it; `ctx.form` is usually `ctx.blockModel.form`.
|
|
43
43
|
|
|
44
44
|
## Examples
|
|
45
45
|
|
|
46
|
-
### Table:
|
|
46
|
+
### Table: get selected rows and process
|
|
47
47
|
|
|
48
48
|
```ts
|
|
49
49
|
const rows = ctx.blockModel?.resource?.getSelectedRows?.() || [];
|
|
@@ -53,7 +53,7 @@ if (rows.length === 0) {
|
|
|
53
53
|
}
|
|
54
54
|
```
|
|
55
55
|
|
|
56
|
-
### Form
|
|
56
|
+
### Form: validate and refresh
|
|
57
57
|
|
|
58
58
|
```ts
|
|
59
59
|
if (ctx.blockModel?.form) {
|
|
@@ -62,15 +62,15 @@ if (ctx.blockModel?.form) {
|
|
|
62
62
|
}
|
|
63
63
|
```
|
|
64
64
|
|
|
65
|
-
### Listen
|
|
65
|
+
### Listen to form changes
|
|
66
66
|
|
|
67
67
|
```ts
|
|
68
68
|
ctx.blockModel?.emitter?.on?.('formValuesChange', (payload) => {
|
|
69
|
-
//
|
|
69
|
+
// React to latest form values or re-render
|
|
70
70
|
});
|
|
71
71
|
```
|
|
72
72
|
|
|
73
|
-
### Trigger
|
|
73
|
+
### Trigger block re-render
|
|
74
74
|
|
|
75
75
|
```ts
|
|
76
76
|
ctx.blockModel?.rerender?.();
|
|
@@ -78,13 +78,13 @@ ctx.blockModel?.rerender?.();
|
|
|
78
78
|
|
|
79
79
|
## Notes
|
|
80
80
|
|
|
81
|
-
- In a **standalone JSBlock** (
|
|
82
|
-
- In **JSField / JSItem / JSColumn**, `ctx.blockModel`
|
|
83
|
-
- `resource` only
|
|
81
|
+
- In a **standalone JSBlock** (no parent form/table), `ctx.blockModel` may be `null`; use optional chaining: `ctx.blockModel?.resource?.refresh?.()`.
|
|
82
|
+
- In **JSField / JSItem / JSColumn**, `ctx.blockModel` is the form or table block that hosts the field; in **JSBlock**, it may be the block itself or an ancestor, depending on hierarchy.
|
|
83
|
+
- `resource` exists only on data blocks; `form` exists only on form blocks; table blocks usually have no `form`.
|
|
84
84
|
|
|
85
85
|
## Related
|
|
86
86
|
|
|
87
|
-
- [ctx.model](./model.md):
|
|
88
|
-
- [ctx.form](./form.md):
|
|
89
|
-
- [ctx.resource](./resource.md):
|
|
90
|
-
- [ctx.getModel()](./get-model.md):
|
|
87
|
+
- [ctx.model](./model.md): model for current execution context
|
|
88
|
+
- [ctx.form](./form.md): form instance, common in form blocks
|
|
89
|
+
- [ctx.resource](./resource.md): resource instance (same as `ctx.blockModel?.resource` when present)
|
|
90
|
+
- [ctx.getModel()](./get-model.md): get another block model by uid
|
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
# ctx.collectionField
|
|
2
2
|
|
|
3
|
-
The
|
|
3
|
+
The collection field (CollectionField) instance for the current RunJS context; used to access field metadata, type, validation rules, and association info. Only present when the field is bound to a collection definition; custom/virtual fields may have `null`.
|
|
4
4
|
|
|
5
5
|
## Use Cases
|
|
6
6
|
|
|
7
7
|
| Scenario | Description |
|
|
8
|
-
|
|
9
|
-
| **JSField** |
|
|
10
|
-
| **JSItem** | Access metadata of the field
|
|
11
|
-
| **JSColumn** |
|
|
8
|
+
|----------|-------------|
|
|
9
|
+
| **JSField** | Use `interface`, `enum`, `targetCollection`, etc. for linkage or validation |
|
|
10
|
+
| **JSItem** | Access metadata of the column’s field in sub-table items |
|
|
11
|
+
| **JSColumn** | Choose render by `collectionField.interface`, or use `targetCollection` |
|
|
12
12
|
|
|
13
|
-
> Note: `ctx.collectionField` is only available when the field is bound to a
|
|
13
|
+
> Note: `ctx.collectionField` is only available when the field is bound to a collection; in standalone JSBlock or actions with no field binding it is usually `undefined`—check before use.
|
|
14
14
|
|
|
15
|
-
## Type
|
|
15
|
+
## Type
|
|
16
16
|
|
|
17
17
|
```ts
|
|
18
18
|
collectionField: CollectionField | null | undefined;
|
|
@@ -21,47 +21,46 @@ collectionField: CollectionField | null | undefined;
|
|
|
21
21
|
## Common Properties
|
|
22
22
|
|
|
23
23
|
| Property | Type | Description |
|
|
24
|
-
|
|
25
|
-
| `name` | `string` | Field name (e.g
|
|
26
|
-
| `title` | `string` | Field title (
|
|
27
|
-
| `type` | `string` |
|
|
28
|
-
| `interface` | `string` |
|
|
29
|
-
| `collection` | `Collection` |
|
|
30
|
-
| `targetCollection` | `Collection` |
|
|
31
|
-
| `target` | `string` | Target collection name (
|
|
32
|
-
| `enum` | `array` |
|
|
24
|
+
|----------|------|-------------|
|
|
25
|
+
| `name` | `string` | Field name (e.g. `status`, `userId`) |
|
|
26
|
+
| `title` | `string` | Field title (i18n) |
|
|
27
|
+
| `type` | `string` | Data type (`string`, `integer`, `belongsTo`, etc.) |
|
|
28
|
+
| `interface` | `string` | UI type (`input`, `select`, `m2o`, `o2m`, `m2m`, etc.) |
|
|
29
|
+
| `collection` | `Collection` | Field’s collection |
|
|
30
|
+
| `targetCollection` | `Collection` | Target collection for association fields only |
|
|
31
|
+
| `target` | `string` | Target collection name (association) |
|
|
32
|
+
| `enum` | `array` | Enum options (select, radio, etc.) |
|
|
33
33
|
| `defaultValue` | `any` | Default value |
|
|
34
|
-
| `collectionName` | `string` |
|
|
35
|
-
| `foreignKey` | `string` | Foreign key
|
|
36
|
-
| `sourceKey` | `string` |
|
|
37
|
-
| `targetKey` | `string` |
|
|
38
|
-
| `fullpath` | `string` | Full path (e.g
|
|
39
|
-
| `resourceName` | `string` | Resource name (e.g
|
|
40
|
-
| `readonly` | `boolean` |
|
|
41
|
-
| `titleable` | `boolean` |
|
|
42
|
-
| `validation` | `object` | Validation
|
|
43
|
-
| `uiSchema` | `object` | UI
|
|
44
|
-
| `targetCollectionTitleField` | `CollectionField` |
|
|
34
|
+
| `collectionName` | `string` | Collection name |
|
|
35
|
+
| `foreignKey` | `string` | Foreign key (e.g. belongsTo) |
|
|
36
|
+
| `sourceKey` | `string` | Source key (e.g. hasMany) |
|
|
37
|
+
| `targetKey` | `string` | Target key |
|
|
38
|
+
| `fullpath` | `string` | Full path (e.g. `main.users.status`) for API/variables |
|
|
39
|
+
| `resourceName` | `string` | Resource name (e.g. `users.status`) |
|
|
40
|
+
| `readonly` | `boolean` | Read-only |
|
|
41
|
+
| `titleable` | `boolean` | Can be used as title |
|
|
42
|
+
| `validation` | `object` | Validation config |
|
|
43
|
+
| `uiSchema` | `object` | UI config |
|
|
44
|
+
| `targetCollectionTitleField` | `CollectionField` | Title field of target collection (association) |
|
|
45
45
|
|
|
46
46
|
## Common Methods
|
|
47
47
|
|
|
48
48
|
| Method | Description |
|
|
49
|
-
|
|
50
|
-
| `isAssociationField(): boolean` | Whether it is an association
|
|
51
|
-
| `isRelationshipField(): boolean` | Whether it is a relationship
|
|
52
|
-
| `getComponentProps(): object` |
|
|
53
|
-
| `getFields(): CollectionField[]` |
|
|
54
|
-
| `getFilterOperators(): object[]` |
|
|
49
|
+
|--------|-------------|
|
|
50
|
+
| `isAssociationField(): boolean` | Whether it is an association (belongsTo, hasMany, hasOne, belongsToMany, etc.) |
|
|
51
|
+
| `isRelationshipField(): boolean` | Whether it is a relationship (o2o, m2o, o2m, m2m, etc.) |
|
|
52
|
+
| `getComponentProps(): object` | Default props for the field component |
|
|
53
|
+
| `getFields(): CollectionField[]` | Fields of target collection (association only) |
|
|
54
|
+
| `getFilterOperators(): object[]` | Filter operators (e.g. `$eq`, `$ne`) |
|
|
55
55
|
|
|
56
56
|
## Examples
|
|
57
57
|
|
|
58
|
-
### Branch
|
|
58
|
+
### Branch by field type
|
|
59
59
|
|
|
60
60
|
```ts
|
|
61
61
|
if (!ctx.collectionField) return null;
|
|
62
62
|
const { interface: iface } = ctx.collectionField;
|
|
63
63
|
if (['m2o', 'o2m', 'm2m'].includes(iface)) {
|
|
64
|
-
// Association field: display associated records
|
|
65
64
|
const target = ctx.collectionField.targetCollection;
|
|
66
65
|
// ...
|
|
67
66
|
} else if (iface === 'select' || iface === 'radioGroup') {
|
|
@@ -70,24 +69,24 @@ if (['m2o', 'o2m', 'm2m'].includes(iface)) {
|
|
|
70
69
|
}
|
|
71
70
|
```
|
|
72
71
|
|
|
73
|
-
###
|
|
72
|
+
### Check association and use target collection
|
|
74
73
|
|
|
75
74
|
```ts
|
|
76
75
|
if (ctx.collectionField?.isAssociationField()) {
|
|
77
76
|
const targetCol = ctx.collectionField.targetCollection;
|
|
78
77
|
const titleField = targetCol?.titleCollectionField?.name;
|
|
79
|
-
//
|
|
78
|
+
// ...
|
|
80
79
|
}
|
|
81
80
|
```
|
|
82
81
|
|
|
83
|
-
### Get
|
|
82
|
+
### Get enum options
|
|
84
83
|
|
|
85
84
|
```ts
|
|
86
85
|
const options = ctx.collectionField?.enum ?? [];
|
|
87
86
|
const labels = options.map((o) => (typeof o === 'object' ? o.label : o));
|
|
88
87
|
```
|
|
89
88
|
|
|
90
|
-
### Conditional
|
|
89
|
+
### Conditional render by readonly
|
|
91
90
|
|
|
92
91
|
```ts
|
|
93
92
|
const { Input } = ctx.libs.antd;
|
|
@@ -98,35 +97,34 @@ if (ctx.collectionField?.readonly) {
|
|
|
98
97
|
}
|
|
99
98
|
```
|
|
100
99
|
|
|
101
|
-
###
|
|
100
|
+
### Title field of target collection
|
|
102
101
|
|
|
103
102
|
```ts
|
|
104
|
-
// When displaying an association field, use targetCollectionTitleField to get the title field name
|
|
105
103
|
const titleField = ctx.collectionField?.targetCollectionTitleField;
|
|
106
104
|
const titleKey = titleField?.name ?? 'title';
|
|
107
105
|
const assocValue = ctx.getValue?.() ?? ctx.record?.[ctx.collectionField?.name];
|
|
108
106
|
const label = assocValue?.[titleKey];
|
|
109
107
|
```
|
|
110
108
|
|
|
111
|
-
##
|
|
109
|
+
## Relation to ctx.collection
|
|
112
110
|
|
|
113
|
-
|
|
|
114
|
-
|
|
115
|
-
| **
|
|
111
|
+
| Need | Recommended |
|
|
112
|
+
|------|-------------|
|
|
113
|
+
| **Collection of current field** | `ctx.collectionField?.collection` or `ctx.collection` |
|
|
116
114
|
| **Field metadata (name, type, interface, enum, etc.)** | `ctx.collectionField` |
|
|
117
115
|
| **Target collection** | `ctx.collectionField?.targetCollection` |
|
|
118
116
|
|
|
119
|
-
`ctx.collection` usually
|
|
117
|
+
`ctx.collection` is usually the block’s collection; `ctx.collectionField` is the field definition; they can differ in sub-tables and associations.
|
|
120
118
|
|
|
121
119
|
## Notes
|
|
122
120
|
|
|
123
|
-
- In
|
|
124
|
-
-
|
|
125
|
-
- `targetCollection` only
|
|
121
|
+
- In **JSBlock**, **JSAction (no field binding)**, `ctx.collectionField` is usually `undefined`; use optional chaining.
|
|
122
|
+
- Custom JS fields not bound to a collection field may have `ctx.collectionField` as `null`.
|
|
123
|
+
- `targetCollection` exists only for association fields (m2o, o2m, m2m); `enum` only for select, radioGroup, etc.
|
|
126
124
|
|
|
127
125
|
## Related
|
|
128
126
|
|
|
129
|
-
- [ctx.collection](./collection.md):
|
|
130
|
-
- [ctx.model](./model.md):
|
|
131
|
-
- [ctx.blockModel](./block-model.md):
|
|
132
|
-
- [ctx.getValue()](./get-value.md), [ctx.setValue()](./set-value.md):
|
|
127
|
+
- [ctx.collection](./collection.md): collection for current context
|
|
128
|
+
- [ctx.model](./model.md): model for current execution context
|
|
129
|
+
- [ctx.blockModel](./block-model.md): parent block
|
|
130
|
+
- [ctx.getValue()](./get-value.md), [ctx.setValue()](./set-value.md): read/write current field value
|
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
# ctx.collection
|
|
2
2
|
|
|
3
|
-
The
|
|
3
|
+
The collection (data table) instance associated with the current RunJS execution context; used to access collection metadata, field definitions, primary key, etc. Usually from `ctx.blockModel.collection` or `ctx.collectionField?.collection`.
|
|
4
4
|
|
|
5
5
|
## Use Cases
|
|
6
6
|
|
|
7
7
|
| Scenario | Description |
|
|
8
|
-
|
|
9
|
-
| **JSBlock** |
|
|
10
|
-
| **JSField / JSItem / JSColumn** |
|
|
11
|
-
| **Table
|
|
8
|
+
|----------|-------------|
|
|
9
|
+
| **JSBlock** | Block-bound collection; access `name`, `getFields`, `filterTargetKey`, etc. |
|
|
10
|
+
| **JSField / JSItem / JSColumn** | Collection of current field or parent block; get field list, primary key, etc. |
|
|
11
|
+
| **Table column / detail block** | Render by collection structure, pass `filterByTk` when opening popup, etc. |
|
|
12
12
|
|
|
13
|
-
> Note: `ctx.collection` is available
|
|
13
|
+
> Note: `ctx.collection` is available when the context is bound to a data block, form block, or table block; a standalone JSBlock with no bound collection may have `null`—check before use.
|
|
14
14
|
|
|
15
|
-
## Type
|
|
15
|
+
## Type
|
|
16
16
|
|
|
17
17
|
```ts
|
|
18
18
|
collection: Collection | null | undefined;
|
|
@@ -21,39 +21,39 @@ collection: Collection | null | undefined;
|
|
|
21
21
|
## Common Properties
|
|
22
22
|
|
|
23
23
|
| Property | Type | Description |
|
|
24
|
-
|
|
25
|
-
| `name` | `string` | Collection name (e.g
|
|
26
|
-
| `title` | `string` | Collection title (
|
|
27
|
-
| `filterTargetKey` | `string \| string[]` | Primary key field name
|
|
28
|
-
| `dataSourceKey` | `string` | Data source key (e.g
|
|
29
|
-
| `dataSource` | `DataSource` |
|
|
30
|
-
| `template` | `string` | Collection template (e.g
|
|
31
|
-
| `titleableFields` | `CollectionField[]` |
|
|
32
|
-
| `titleCollectionField` | `CollectionField` |
|
|
24
|
+
|----------|------|-------------|
|
|
25
|
+
| `name` | `string` | Collection name (e.g. `users`, `orders`) |
|
|
26
|
+
| `title` | `string` | Collection title (i18n) |
|
|
27
|
+
| `filterTargetKey` | `string \| string[]` | Primary key field name(s); used for `filterByTk`, `getFilterByTK` |
|
|
28
|
+
| `dataSourceKey` | `string` | Data source key (e.g. `main`) |
|
|
29
|
+
| `dataSource` | `DataSource` | Data source instance |
|
|
30
|
+
| `template` | `string` | Collection template (e.g. `general`, `file`, `tree`) |
|
|
31
|
+
| `titleableFields` | `CollectionField[]` | Fields that can be used as title |
|
|
32
|
+
| `titleCollectionField` | `CollectionField` | Title field instance |
|
|
33
33
|
|
|
34
34
|
## Common Methods
|
|
35
35
|
|
|
36
36
|
| Method | Description |
|
|
37
|
-
|
|
38
|
-
| `getFields(): CollectionField[]` |
|
|
39
|
-
| `getField(name: string): CollectionField \| undefined` |
|
|
40
|
-
| `getFieldByPath(path: string): CollectionField \| undefined` |
|
|
41
|
-
| `getAssociationFields(types?): CollectionField[]` |
|
|
42
|
-
| `getFilterByTK(record): any` |
|
|
37
|
+
|--------|-------------|
|
|
38
|
+
| `getFields(): CollectionField[]` | All fields (including inherited) |
|
|
39
|
+
| `getField(name: string): CollectionField \| undefined` | Single field by name |
|
|
40
|
+
| `getFieldByPath(path: string): CollectionField \| undefined` | Field by path (supports association, e.g. `user.name`) |
|
|
41
|
+
| `getAssociationFields(types?): CollectionField[]` | Association fields; `types` e.g. `['one']`, `['many']` |
|
|
42
|
+
| `getFilterByTK(record): any` | Primary key value from record for API `filterByTk` |
|
|
43
43
|
|
|
44
|
-
##
|
|
44
|
+
## Relation to ctx.collectionField, ctx.blockModel
|
|
45
45
|
|
|
46
|
-
|
|
|
47
|
-
|
|
48
|
-
| **Collection
|
|
49
|
-
| **Collection
|
|
50
|
-
| **
|
|
46
|
+
| Need | Recommended |
|
|
47
|
+
|------|-------------|
|
|
48
|
+
| **Collection for current context** | `ctx.collection` (same as `ctx.blockModel?.collection` or `ctx.collectionField?.collection`) |
|
|
49
|
+
| **Collection of current field** | `ctx.collectionField?.collection` |
|
|
50
|
+
| **Target collection of association** | `ctx.collectionField?.targetCollection` |
|
|
51
51
|
|
|
52
|
-
In
|
|
52
|
+
In sub-tables etc., `ctx.collection` may be the association target; in normal form/table it is usually the block’s collection.
|
|
53
53
|
|
|
54
54
|
## Examples
|
|
55
55
|
|
|
56
|
-
### Get
|
|
56
|
+
### Get primary key and open popup
|
|
57
57
|
|
|
58
58
|
```ts
|
|
59
59
|
const primaryKey = ctx.collection?.filterTargetKey ?? 'id';
|
|
@@ -66,7 +66,7 @@ await ctx.openView(popupUid, {
|
|
|
66
66
|
});
|
|
67
67
|
```
|
|
68
68
|
|
|
69
|
-
### Iterate
|
|
69
|
+
### Iterate fields for validation or linkage
|
|
70
70
|
|
|
71
71
|
```ts
|
|
72
72
|
const fields = ctx.collection?.getFields() ?? [];
|
|
@@ -80,21 +80,21 @@ for (const f of requiredFields) {
|
|
|
80
80
|
}
|
|
81
81
|
```
|
|
82
82
|
|
|
83
|
-
### Get
|
|
83
|
+
### Get association fields
|
|
84
84
|
|
|
85
85
|
```ts
|
|
86
86
|
const oneToMany = ctx.collection?.getAssociationFields(['many']) ?? [];
|
|
87
|
-
//
|
|
87
|
+
// For sub-tables, association resources, etc.
|
|
88
88
|
```
|
|
89
89
|
|
|
90
90
|
## Notes
|
|
91
91
|
|
|
92
|
-
- `filterTargetKey` is the primary key field name
|
|
93
|
-
- In
|
|
94
|
-
- `getFields()` merges
|
|
92
|
+
- `filterTargetKey` is the collection’s primary key field name; some collections use `string[]` composite keys; fallback is often `'id'`.
|
|
93
|
+
- In **sub-tables, association fields**, `ctx.collection` may point to the association target, different from `ctx.blockModel.collection`.
|
|
94
|
+
- `getFields()` merges inherited collection fields; local fields override inherited ones with the same name.
|
|
95
95
|
|
|
96
96
|
## Related
|
|
97
97
|
|
|
98
|
-
- [ctx.collectionField](./collection-field.md):
|
|
99
|
-
- [ctx.blockModel](./block-model.md):
|
|
100
|
-
- [ctx.model](./model.md):
|
|
98
|
+
- [ctx.collectionField](./collection-field.md): current field’s collection field definition
|
|
99
|
+
- [ctx.blockModel](./block-model.md): parent block that hosts current JS; has `collection`
|
|
100
|
+
- [ctx.model](./model.md): current model; may have `collection`
|
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
# ctx.dataSourceManager
|
|
2
2
|
|
|
3
|
-
The
|
|
3
|
+
The data source manager (`DataSourceManager` instance) for managing and accessing multiple data sources (e.g. main `main`, logging `logging`). Use when you have multiple data sources or need cross–data-source metadata access.
|
|
4
4
|
|
|
5
5
|
## Use Cases
|
|
6
6
|
|
|
7
7
|
| Scenario | Description |
|
|
8
|
-
|
|
9
|
-
| **
|
|
10
|
-
| **Cross-
|
|
11
|
-
| **
|
|
8
|
+
|----------|-------------|
|
|
9
|
+
| **Multiple data sources** | Enumerate all data sources, get one by key |
|
|
10
|
+
| **Cross–data-source access** | When context doesn’t know the data source, access by “data source key + collection name” |
|
|
11
|
+
| **Field by full path** | Get field definition with path format `dataSourceKey.collectionName.fieldPath` |
|
|
12
12
|
|
|
13
|
-
> Note: If you
|
|
13
|
+
> Note: If you only work with the current data source, use `ctx.dataSource`; use `ctx.dataSourceManager` when you need to enumerate or switch data sources.
|
|
14
14
|
|
|
15
|
-
## Type
|
|
15
|
+
## Type
|
|
16
16
|
|
|
17
17
|
```ts
|
|
18
18
|
dataSourceManager: DataSourceManager;
|
|
@@ -20,74 +20,64 @@ dataSourceManager: DataSourceManager;
|
|
|
20
20
|
class DataSourceManager {
|
|
21
21
|
constructor();
|
|
22
22
|
|
|
23
|
-
// Data source management
|
|
24
23
|
addDataSource(ds: DataSource | DataSourceOptions): void;
|
|
25
24
|
upsertDataSource(ds: DataSource | DataSourceOptions): void;
|
|
26
25
|
removeDataSource(key: string): void;
|
|
27
26
|
clearDataSources(): void;
|
|
28
27
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
getDataSource(key: string): DataSource | undefined; // Get data source by key
|
|
28
|
+
getDataSources(): DataSource[];
|
|
29
|
+
getDataSource(key: string): DataSource | undefined;
|
|
32
30
|
|
|
33
|
-
// Access metadata directly by data source + collection
|
|
34
31
|
getCollection(dataSourceKey: string, collectionName: string): Collection | undefined;
|
|
35
32
|
getCollectionField(fieldPathWithDataSource: string): CollectionField | undefined;
|
|
36
33
|
}
|
|
37
34
|
```
|
|
38
35
|
|
|
39
|
-
##
|
|
36
|
+
## Relation to ctx.dataSource
|
|
40
37
|
|
|
41
|
-
|
|
|
42
|
-
|
|
43
|
-
| **Single data source
|
|
44
|
-
| **Entry
|
|
38
|
+
| Need | Recommended |
|
|
39
|
+
|------|-------------|
|
|
40
|
+
| **Single data source for context** | `ctx.dataSource` |
|
|
41
|
+
| **Entry to all data sources** | `ctx.dataSourceManager` |
|
|
45
42
|
| **List or switch data sources** | `ctx.dataSourceManager.getDataSources()` / `getDataSource(key)` |
|
|
46
|
-
| **
|
|
47
|
-
| **
|
|
48
|
-
| **
|
|
49
|
-
| **
|
|
43
|
+
| **Collection in current data source** | `ctx.dataSource.getCollection(name)` |
|
|
44
|
+
| **Collection in another data source** | `ctx.dataSourceManager.getCollection(dataSourceKey, collectionName)` |
|
|
45
|
+
| **Field in current data source** | `ctx.dataSource.getCollectionField('users.profile.avatar')` |
|
|
46
|
+
| **Field across data sources** | `ctx.dataSourceManager.getCollectionField('main.users.profile.avatar')` |
|
|
50
47
|
|
|
51
48
|
## Examples
|
|
52
49
|
|
|
53
|
-
### Get a
|
|
50
|
+
### Get a data source
|
|
54
51
|
|
|
55
52
|
```ts
|
|
56
|
-
// Get the data source named 'main'
|
|
57
53
|
const mainDS = ctx.dataSourceManager.getDataSource('main');
|
|
58
|
-
|
|
59
|
-
// Get all collections under this data source
|
|
60
54
|
const collections = mainDS?.getCollections();
|
|
61
55
|
```
|
|
62
56
|
|
|
63
|
-
###
|
|
57
|
+
### Cross–data-source collection metadata
|
|
64
58
|
|
|
65
59
|
```ts
|
|
66
|
-
// Get collection by dataSourceKey + collectionName
|
|
67
60
|
const users = ctx.dataSourceManager.getCollection('main', 'users');
|
|
68
61
|
const orders = ctx.dataSourceManager.getCollection('main', 'orders');
|
|
69
62
|
|
|
70
|
-
// Get the primary key of the collection
|
|
71
63
|
const primaryKey = users?.filterTargetKey ?? 'id';
|
|
72
64
|
```
|
|
73
65
|
|
|
74
|
-
###
|
|
66
|
+
### Field by full path
|
|
75
67
|
|
|
76
68
|
```ts
|
|
77
69
|
// Format: dataSourceKey.collectionName.fieldPath
|
|
78
|
-
// Get field definition by "data source key.collection name.field path"
|
|
79
70
|
const field = ctx.dataSourceManager.getCollectionField('main.users.profile.avatar');
|
|
80
71
|
|
|
81
|
-
// Supports association field paths
|
|
82
72
|
const userNameField = ctx.dataSourceManager.getCollectionField('main.orders.createdBy.name');
|
|
83
73
|
```
|
|
84
74
|
|
|
85
|
-
### Iterate
|
|
75
|
+
### Iterate all data sources
|
|
86
76
|
|
|
87
77
|
```ts
|
|
88
78
|
const dataSources = ctx.dataSourceManager.getDataSources();
|
|
89
79
|
for (const ds of dataSources) {
|
|
90
|
-
ctx.logger.info(`Data
|
|
80
|
+
ctx.logger.info(`Data source: ${ds.key}, display: ${ds.displayName}`);
|
|
91
81
|
const collections = ds.getCollections();
|
|
92
82
|
for (const col of collections) {
|
|
93
83
|
ctx.logger.info(` - Collection: ${col.name}`);
|
|
@@ -95,7 +85,7 @@ for (const ds of dataSources) {
|
|
|
95
85
|
}
|
|
96
86
|
```
|
|
97
87
|
|
|
98
|
-
###
|
|
88
|
+
### Dynamic data source from variable
|
|
99
89
|
|
|
100
90
|
```ts
|
|
101
91
|
const dsKey = ctx.getVar('dataSourceKey') ?? 'main';
|
|
@@ -109,12 +99,12 @@ if (col) {
|
|
|
109
99
|
|
|
110
100
|
## Notes
|
|
111
101
|
|
|
112
|
-
-
|
|
113
|
-
- `getDataSource(key)` returns `undefined` if the data source
|
|
114
|
-
- `addDataSource`
|
|
102
|
+
- `getCollectionField` path format is `dataSourceKey.collectionName.fieldPath`; first segment is data source key, then collection name and field path.
|
|
103
|
+
- `getDataSource(key)` returns `undefined` if the data source doesn’t exist—check before use.
|
|
104
|
+
- `addDataSource` throws if key already exists; `upsertDataSource` overwrites or adds.
|
|
115
105
|
|
|
116
106
|
## Related
|
|
117
107
|
|
|
118
|
-
- [ctx.dataSource](./data-source.md):
|
|
119
|
-
- [ctx.collection](./collection.md):
|
|
120
|
-
- [ctx.collectionField](./collection-field.md):
|
|
108
|
+
- [ctx.dataSource](./data-source.md): current data source instance
|
|
109
|
+
- [ctx.collection](./collection.md): collection for current context
|
|
110
|
+
- [ctx.collectionField](./collection-field.md): current field’s collection field definition
|