@nocobase/plugin-flow-engine 2.1.0-alpha.7 → 2.1.0-alpha.8
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 +53 -51
- package/dist/ai/docs/runjs/context/collection.md +39 -39
- package/dist/ai/docs/runjs/context/data-source-manager.md +40 -30
- package/dist/ai/docs/runjs/context/data-source.md +52 -44
- package/dist/ai/docs/runjs/context/element.md +44 -38
- package/dist/ai/docs/runjs/context/exit-all.md +37 -35
- package/dist/ai/docs/runjs/context/exit.md +38 -35
- package/dist/ai/docs/runjs/context/filter-manager.md +36 -30
- package/dist/ai/docs/runjs/context/form.md +57 -57
- package/dist/ai/docs/runjs/context/get-model.md +22 -21
- package/dist/ai/docs/runjs/context/get-value.md +20 -19
- package/dist/ai/docs/runjs/context/get-var.md +61 -55
- package/dist/ai/docs/runjs/context/i18n.md +17 -14
- package/dist/ai/docs/runjs/context/import-async.md +333 -45
- 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 +34 -31
- package/dist/ai/docs/runjs/context/logger.md +41 -40
- package/dist/ai/docs/runjs/context/make-resource.md +27 -26
- package/dist/ai/docs/runjs/context/message.md +42 -41
- package/dist/ai/docs/runjs/context/modal.md +44 -44
- package/dist/ai/docs/runjs/context/model.md +36 -33
- package/dist/ai/docs/runjs/context/notification.md +41 -40
- package/dist/ai/docs/runjs/context/off.md +14 -14
- package/dist/ai/docs/runjs/context/on.md +30 -29
- package/dist/ai/docs/runjs/context/open-view.md +40 -40
- package/dist/ai/docs/runjs/context/render.md +37 -32
- package/dist/ai/docs/runjs/context/request.md +46 -45
- package/dist/ai/docs/runjs/context/require-async.md +28 -25
- package/dist/ai/docs/runjs/context/resource.md +34 -34
- package/dist/ai/docs/runjs/context/route.md +36 -34
- package/dist/ai/docs/runjs/context/router.md +43 -31
- package/dist/ai/docs/runjs/context/set-value.md +18 -17
- package/dist/ai/docs/runjs/context/sql.md +7 -15
- package/dist/ai/docs/runjs/context/t.md +20 -17
- package/dist/ai/docs/runjs/context/view.md +49 -46
- package/dist/ai/docs/runjs/document.md +1 -0
- 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 +1 -3
- 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/dist/server/collections/flowsql.js +1 -0
- package/package.json +2 -2
|
@@ -1,94 +1,97 @@
|
|
|
1
1
|
# ctx.getVar()
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Asynchronously reads variable values from the current runtime context. Variable resolution is consistent with `{{ctx.xxx}}` in SQL and templates, typically originating from the current user, current record, view parameters, popup context, etc.
|
|
4
4
|
|
|
5
5
|
## Use Cases
|
|
6
6
|
|
|
7
7
|
| Scenario | Description |
|
|
8
|
-
|
|
9
|
-
| **JSBlock / JSField** | Get current record, user, resource, etc
|
|
10
|
-
| **Linkage /
|
|
11
|
-
| **Formulas /
|
|
8
|
+
|------|------|
|
|
9
|
+
| **JSBlock / JSField** | Get information about the current record, user, resource, etc., for rendering or logic. |
|
|
10
|
+
| **Linkage Rules / FlowEngine** | Read `ctx.record`, `ctx.formValues`, etc., for conditional logic. |
|
|
11
|
+
| **Formulas / Templates** | Uses the same variable resolution rules as `{{ctx.xxx}}`. |
|
|
12
12
|
|
|
13
|
-
## Type
|
|
13
|
+
## Type Definition
|
|
14
14
|
|
|
15
15
|
```ts
|
|
16
16
|
getVar(path: string): Promise<any>;
|
|
17
17
|
```
|
|
18
18
|
|
|
19
19
|
| Parameter | Type | Description |
|
|
20
|
-
|
|
21
|
-
| `path` | `string` | Variable path; **must start with `ctx
|
|
20
|
+
|------|------|------|
|
|
21
|
+
| `path` | `string` | Variable path; **must start with `ctx.`**. Supports dot notation and array indices. |
|
|
22
22
|
|
|
23
|
-
**
|
|
23
|
+
**Return Value**: `Promise<any>`. Use `await` to get the resolved value; returns `undefined` if the variable does not exist.
|
|
24
24
|
|
|
25
|
-
> If
|
|
25
|
+
> If a path that does not start with `ctx.` is passed, an error will be thrown: `ctx.getVar(path) expects an expression starting with "ctx.", got: "..."`.
|
|
26
26
|
|
|
27
|
-
## Common
|
|
27
|
+
## Common Variable Paths
|
|
28
28
|
|
|
29
29
|
| Path | Description |
|
|
30
|
-
|
|
31
|
-
| `ctx.record` | Current record (when form/
|
|
30
|
+
|------|------|
|
|
31
|
+
| `ctx.record` | Current record (available when a form/details block is bound to a record) |
|
|
32
32
|
| `ctx.record.id` | Current record primary key |
|
|
33
|
-
| `ctx.formValues` | Current form values (
|
|
34
|
-
| `ctx.user` | Current user |
|
|
35
|
-
| `ctx.user.id` | Current user
|
|
33
|
+
| `ctx.formValues` | Current form values (commonly used in linkage rules and FlowEngine; in form scenarios, prefer `ctx.form.getFieldsValue()` for real-time reading) |
|
|
34
|
+
| `ctx.user` | Current logged-in user |
|
|
35
|
+
| `ctx.user.id` | Current user ID |
|
|
36
36
|
| `ctx.user.nickname` | Current user nickname |
|
|
37
37
|
| `ctx.user.roles.name` | Current user role names (array) |
|
|
38
|
-
| `ctx.popup.record` | Record
|
|
39
|
-
| `ctx.popup.record.id` |
|
|
40
|
-
| `ctx.urlSearchParams` | URL query
|
|
41
|
-
| `ctx.token` | Current API
|
|
38
|
+
| `ctx.popup.record` | Record within a popup |
|
|
39
|
+
| `ctx.popup.record.id` | Primary key of the record within a popup |
|
|
40
|
+
| `ctx.urlSearchParams` | URL query parameters (parsed from `?key=value`) |
|
|
41
|
+
| `ctx.token` | Current API Token |
|
|
42
42
|
| `ctx.role` | Current role |
|
|
43
43
|
|
|
44
44
|
## ctx.getVarInfos()
|
|
45
45
|
|
|
46
|
-
|
|
46
|
+
Gets the **structural information** (type, title, sub-properties, etc.) of resolvable variables in the current context, making it easier to explore available paths. The return value is a static description based on `meta` and does not include actual runtime values.
|
|
47
47
|
|
|
48
|
-
### Type
|
|
48
|
+
### Type Definition
|
|
49
49
|
|
|
50
50
|
```ts
|
|
51
51
|
getVarInfos(options?: { path?: string | string[]; maxDepth?: number }): Promise<Record<string, any>>;
|
|
52
52
|
```
|
|
53
53
|
|
|
54
|
-
|
|
54
|
+
In the return value, each key is a variable path, and the value is the structural information for that path (including `type`, `title`, `properties`, etc.).
|
|
55
55
|
|
|
56
|
-
###
|
|
56
|
+
### Parameters
|
|
57
57
|
|
|
58
|
-
|
|
|
59
|
-
|
|
60
|
-
| `path` | `string \| string[]` |
|
|
61
|
-
| `maxDepth` | `number` |
|
|
58
|
+
| Parameter | Type | Description |
|
|
59
|
+
|------|------|------|
|
|
60
|
+
| `path` | `string \| string[]` | Truncation path; only collects the variable structure under this path. Supports `'record'`, `'record.id'`, `'ctx.record'`, `'{{ ctx.record }}'`; an array represents the merging of multiple paths. |
|
|
61
|
+
| `maxDepth` | `number` | Maximum expansion depth, default is `3`. When `path` is not provided, top-level properties have `depth=1`. When `path` is provided, the node corresponding to the path has `depth=1`. |
|
|
62
62
|
|
|
63
63
|
### Example
|
|
64
64
|
|
|
65
65
|
```ts
|
|
66
|
+
// Get the variable structure under record (expanded up to 3 levels)
|
|
66
67
|
const vars = await ctx.getVarInfos({ path: 'record', maxDepth: 3 });
|
|
67
68
|
|
|
69
|
+
// Get the structure of popup.record
|
|
68
70
|
const vars = await ctx.getVarInfos({ path: 'popup.record', maxDepth: 3 });
|
|
69
71
|
|
|
72
|
+
// Get the complete top-level variable structure (default maxDepth=3)
|
|
70
73
|
const vars = await ctx.getVarInfos();
|
|
71
74
|
```
|
|
72
75
|
|
|
73
|
-
##
|
|
76
|
+
## Difference from ctx.getValue
|
|
74
77
|
|
|
75
|
-
| Method |
|
|
76
|
-
|
|
77
|
-
| `ctx.getValue()` | JSField
|
|
78
|
-
| `ctx.getVar(path)` | Any RunJS |
|
|
78
|
+
| Method | Scenario | Description |
|
|
79
|
+
|------|----------|------|
|
|
80
|
+
| `ctx.getValue()` | Editable fields like JSField or JSItem | Synchronously gets the value of the **current field**; requires form binding. |
|
|
81
|
+
| `ctx.getVar(path)` | Any RunJS context | Asynchronously gets **any ctx variable**; path must start with `ctx.`. |
|
|
79
82
|
|
|
80
|
-
In JSField, use getValue
|
|
83
|
+
In a JSField, use `getValue`/`setValue` to read/write the current field; use `getVar` to access other context variables (such as `record`, `user`, `formValues`).
|
|
81
84
|
|
|
82
85
|
## Notes
|
|
83
86
|
|
|
84
|
-
- **Path must start with `ctx.`**: e.g
|
|
85
|
-
- **
|
|
86
|
-
- **
|
|
87
|
-
- **Form values**:
|
|
87
|
+
- **Path must start with `ctx.`**: e.g., `ctx.record.id`, otherwise an error will be thrown.
|
|
88
|
+
- **Asynchronous method**: You must use `await` to get the result, e.g., `const id = await ctx.getVar('ctx.record.id')`.
|
|
89
|
+
- **Variable does not exist**: Returns `undefined`. You can use `??` after the result to set a default value: `(await ctx.getVar('ctx.user.nickname')) ?? 'Guest'`.
|
|
90
|
+
- **Form values**: `ctx.formValues` must be retrieved via `await ctx.getVar('ctx.formValues')`; it is not directly exposed as `ctx.formValues`. In a form context, prefer using `ctx.form.getFieldsValue()` to read the latest values in real-time.
|
|
88
91
|
|
|
89
92
|
## Examples
|
|
90
93
|
|
|
91
|
-
### Current
|
|
94
|
+
### Get Current Record ID
|
|
92
95
|
|
|
93
96
|
```ts
|
|
94
97
|
const recordId = await ctx.getVar('ctx.record.id');
|
|
@@ -97,55 +100,58 @@ if (recordId) {
|
|
|
97
100
|
}
|
|
98
101
|
```
|
|
99
102
|
|
|
100
|
-
### Popup
|
|
103
|
+
### Get Record Within a Popup
|
|
101
104
|
|
|
102
105
|
```ts
|
|
103
106
|
const recordId = await ctx.getVar('ctx.popup.record.id');
|
|
104
107
|
if (recordId) {
|
|
105
|
-
ctx.message.info(`
|
|
108
|
+
ctx.message.info(`Current popup record: ${recordId}`);
|
|
106
109
|
}
|
|
107
110
|
```
|
|
108
111
|
|
|
109
|
-
### Array
|
|
112
|
+
### Read Sub-items of an Array Field
|
|
110
113
|
|
|
111
114
|
```ts
|
|
112
115
|
const roleNames = await ctx.getVar('ctx.user.roles.name');
|
|
113
|
-
// e.g
|
|
116
|
+
// Returns an array of role names, e.g., ['admin', 'member']
|
|
114
117
|
```
|
|
115
118
|
|
|
116
|
-
### Default
|
|
119
|
+
### Set Default Value
|
|
117
120
|
|
|
118
121
|
```ts
|
|
122
|
+
// getVar does not have a defaultValue parameter; use ?? after the result
|
|
119
123
|
const userName = (await ctx.getVar('ctx.user.nickname')) ?? 'Guest';
|
|
120
124
|
```
|
|
121
125
|
|
|
122
|
-
### Form
|
|
126
|
+
### Read Form Field Values
|
|
123
127
|
|
|
124
128
|
```ts
|
|
129
|
+
// Both ctx.formValues and ctx.form are for form scenarios; use getVar to read nested fields
|
|
125
130
|
const status = await ctx.getVar('ctx.formValues.status');
|
|
126
131
|
if (status === 'draft') {
|
|
127
132
|
// ...
|
|
128
133
|
}
|
|
129
134
|
```
|
|
130
135
|
|
|
131
|
-
### URL
|
|
136
|
+
### Read URL Query Parameters
|
|
132
137
|
|
|
133
138
|
```ts
|
|
134
|
-
const id = await ctx.getVar('ctx.urlSearchParams.id'); // ?id=xxx
|
|
139
|
+
const id = await ctx.getVar('ctx.urlSearchParams.id'); // Corresponds to ?id=xxx
|
|
135
140
|
```
|
|
136
141
|
|
|
137
|
-
### Explore
|
|
142
|
+
### Explore Available Variables
|
|
138
143
|
|
|
139
144
|
```ts
|
|
145
|
+
// Get the variable structure under record (expanded up to 3 levels)
|
|
140
146
|
const vars = await ctx.getVarInfos({ path: 'record', maxDepth: 3 });
|
|
141
|
-
//
|
|
147
|
+
// vars looks like { 'record.id': { type: 'string', title: 'id' }, ... }
|
|
142
148
|
```
|
|
143
149
|
|
|
144
150
|
## Related
|
|
145
151
|
|
|
146
|
-
- [ctx.getValue()](./get-value.md)
|
|
147
|
-
- [ctx.form](./form.md)
|
|
148
|
-
- [ctx.model](./model.md)
|
|
149
|
-
- [ctx.blockModel](./block-model.md)
|
|
150
|
-
- [ctx.resource](./resource.md)
|
|
151
|
-
-
|
|
152
|
+
- [ctx.getValue()](./get-value.md) - Synchronously gets the current field value (JSField/JSItem only)
|
|
153
|
+
- [ctx.form](./form.md) - Form instance; `ctx.form.getFieldsValue()` can read form values in real-time
|
|
154
|
+
- [ctx.model](./model.md) - The model where the current execution context resides
|
|
155
|
+
- [ctx.blockModel](./block-model.md) - The parent block where the current JS is located
|
|
156
|
+
- [ctx.resource](./resource.md) - The resource instance in the current context
|
|
157
|
+
- `{{ctx.xxx}}` in SQL / Templates - Uses the same resolution rules as `ctx.getVar('ctx.xxx')`
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
# ctx.i18n
|
|
2
2
|
|
|
3
|
-
The i18n instance
|
|
3
|
+
The i18n instance of the current context, used for reading or switching languages. **Use [ctx.t()](./t.md) for translating text**; do not use `ctx.i18n.t`.
|
|
4
4
|
|
|
5
|
-
##
|
|
5
|
+
## Scenarios
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
All RunJS execution environments can use `ctx.i18n` (e.g., JSBlock, JSField, JSItem, JSColumn, Workflow, Linkage Rules, etc.).
|
|
8
8
|
|
|
9
|
-
## Type
|
|
9
|
+
## Type Definition
|
|
10
10
|
|
|
11
11
|
```typescript
|
|
12
12
|
interface i18n: {
|
|
@@ -18,27 +18,28 @@ interface i18n: {
|
|
|
18
18
|
## Common Properties
|
|
19
19
|
|
|
20
20
|
| Property | Type | Description |
|
|
21
|
-
|
|
22
|
-
| `language` | `string` |
|
|
21
|
+
|------|------|------|
|
|
22
|
+
| `language` | `string` | The currently active language code (e.g., `en-US`, `zh-CN`) |
|
|
23
23
|
|
|
24
24
|
## Common Methods
|
|
25
25
|
|
|
26
26
|
### changeLanguage(lng)
|
|
27
27
|
|
|
28
|
-
|
|
28
|
+
Switches the current language.
|
|
29
29
|
|
|
30
30
|
| Parameter | Type | Description |
|
|
31
|
-
|
|
32
|
-
| `lng` | `string` | Target language code (e.g
|
|
31
|
+
|------|------|------|
|
|
32
|
+
| `lng` | `string` | Target language code (e.g., `'en-US'`, `'zh-CN'`) |
|
|
33
33
|
|
|
34
|
-
**Returns**: `Promise<any>`, resolves
|
|
34
|
+
**Returns**: `Promise<any>`, resolves after the language switch is complete.
|
|
35
35
|
|
|
36
36
|
## Examples
|
|
37
37
|
|
|
38
|
-
###
|
|
38
|
+
### Reading the current language
|
|
39
39
|
|
|
40
40
|
```ts
|
|
41
41
|
const lang = ctx.i18n.language;
|
|
42
|
+
// 'en-US' | 'zh-CN' | ...
|
|
42
43
|
if (lang.startsWith('zh')) {
|
|
43
44
|
ctx.render(ctx.t('Chinese UI'));
|
|
44
45
|
} else {
|
|
@@ -46,11 +47,13 @@ if (lang.startsWith('zh')) {
|
|
|
46
47
|
}
|
|
47
48
|
```
|
|
48
49
|
|
|
49
|
-
###
|
|
50
|
+
### Switching languages
|
|
50
51
|
|
|
51
52
|
```ts
|
|
53
|
+
// Switch to English
|
|
52
54
|
await ctx.i18n.changeLanguage('en-US');
|
|
53
55
|
|
|
56
|
+
// Switch to Chinese
|
|
54
57
|
await ctx.i18n.changeLanguage('zh-CN');
|
|
55
58
|
```
|
|
56
59
|
|
|
@@ -70,8 +73,8 @@ ctx.render(
|
|
|
70
73
|
|
|
71
74
|
## Notes
|
|
72
75
|
|
|
73
|
-
- **
|
|
76
|
+
- **Translation text**: Use `ctx.t()` consistently; do not use `ctx.i18n.t`.
|
|
74
77
|
|
|
75
78
|
## Related
|
|
76
79
|
|
|
77
|
-
- [ctx.t()](./t.md):
|
|
80
|
+
- [ctx.t()](./t.md): Translate text, use this method consistently.
|