@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,97 +1,94 @@
|
|
|
1
1
|
# ctx.getVar()
|
|
2
2
|
|
|
3
|
-
Asynchronously reads variable
|
|
3
|
+
**Asynchronously** reads a variable from the current runtime context. Variable sources are the same as for SQL and template `{{ctx.xxx}}`: current user, current record, view params, popup context, etc.
|
|
4
4
|
|
|
5
5
|
## Use Cases
|
|
6
6
|
|
|
7
7
|
| Scenario | Description |
|
|
8
|
-
|
|
9
|
-
| **JSBlock / JSField** | Get
|
|
10
|
-
| **Linkage
|
|
11
|
-
| **Formulas /
|
|
8
|
+
|----------|-------------|
|
|
9
|
+
| **JSBlock / JSField** | Get current record, user, resource, etc. for rendering or logic |
|
|
10
|
+
| **Linkage / event flow** | Read `ctx.record`, `ctx.formValues`, etc. for conditions |
|
|
11
|
+
| **Formulas / templates** | Same variable resolution as `{{ctx.xxx}}` |
|
|
12
12
|
|
|
13
|
-
## Type
|
|
13
|
+
## Type
|
|
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 and array index |
|
|
22
22
|
|
|
23
|
-
**
|
|
23
|
+
**Returns**: `Promise<any>`; use `await` to get the resolved value. Returns `undefined` if the variable does not exist.
|
|
24
24
|
|
|
25
|
-
> If
|
|
25
|
+
> If the path does not start with `ctx.`, an error is thrown: `ctx.getVar(path) expects an expression starting with "ctx.", got: "..."`.
|
|
26
26
|
|
|
27
|
-
## Common
|
|
27
|
+
## Common paths
|
|
28
28
|
|
|
29
29
|
| Path | Description |
|
|
30
|
-
|
|
31
|
-
| `ctx.record` | Current record (
|
|
30
|
+
|------|-------------|
|
|
31
|
+
| `ctx.record` | Current record (when form/detail is bound to a record) |
|
|
32
32
|
| `ctx.record.id` | Current record primary key |
|
|
33
|
-
| `ctx.formValues` | Current form values (
|
|
34
|
-
| `ctx.user` | Current
|
|
35
|
-
| `ctx.user.id` | Current user
|
|
33
|
+
| `ctx.formValues` | Current form values (common in linkage/event flow; in form context prefer `ctx.form.getFieldsValue()` for live values) |
|
|
34
|
+
| `ctx.user` | Current 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 in popup |
|
|
39
|
+
| `ctx.popup.record.id` | Popup record primary key |
|
|
40
|
+
| `ctx.urlSearchParams` | URL query params (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
|
+
Returns **structure info** (type, title, child properties, etc.) for variables that can be resolved in the current context. Useful to discover available paths. Values are static meta, not runtime values.
|
|
47
47
|
|
|
48
|
-
### Type
|
|
48
|
+
### Type
|
|
49
49
|
|
|
50
50
|
```ts
|
|
51
51
|
getVarInfos(options?: { path?: string | string[]; maxDepth?: number }): Promise<Record<string, any>>;
|
|
52
52
|
```
|
|
53
53
|
|
|
54
|
-
|
|
54
|
+
Each key in the result is a variable path; each value is that path’s structure (e.g. `type`, `title`, `properties`).
|
|
55
55
|
|
|
56
|
-
###
|
|
56
|
+
### Options
|
|
57
57
|
|
|
58
|
-
|
|
|
59
|
-
|
|
60
|
-
| `path` | `string \| string[]` |
|
|
61
|
-
| `maxDepth` | `number` |
|
|
58
|
+
| Option | Type | Description |
|
|
59
|
+
|--------|------|-------------|
|
|
60
|
+
| `path` | `string \| string[]` | Limit to paths under this; e.g. `'record'`, `'record.id'`, `'ctx.record'`, `'{{ ctx.record }}'`; array = multiple paths merged |
|
|
61
|
+
| `maxDepth` | `number` | Max depth to expand; default `3`. Without path, top-level depth=1; with path, that node depth=1 |
|
|
62
62
|
|
|
63
63
|
### Example
|
|
64
64
|
|
|
65
65
|
```ts
|
|
66
|
-
// Get the variable structure under record (expanded up to 3 levels)
|
|
67
66
|
const vars = await ctx.getVarInfos({ path: 'record', maxDepth: 3 });
|
|
68
67
|
|
|
69
|
-
// Get the structure of popup.record
|
|
70
68
|
const vars = await ctx.getVarInfos({ path: 'popup.record', maxDepth: 3 });
|
|
71
69
|
|
|
72
|
-
// Get the complete top-level variable structure (default maxDepth=3)
|
|
73
70
|
const vars = await ctx.getVarInfos();
|
|
74
71
|
```
|
|
75
72
|
|
|
76
|
-
##
|
|
73
|
+
## Relation to ctx.getValue
|
|
77
74
|
|
|
78
|
-
| Method |
|
|
79
|
-
|
|
80
|
-
| `ctx.getValue()` |
|
|
81
|
-
| `ctx.getVar(path)` | Any RunJS
|
|
75
|
+
| Method | Context | Description |
|
|
76
|
+
|--------|---------|-------------|
|
|
77
|
+
| `ctx.getValue()` | JSField, JSItem, etc. | Sync; **current field** value; requires form binding |
|
|
78
|
+
| `ctx.getVar(path)` | Any RunJS | Async; **any ctx variable**; path must start with `ctx.` |
|
|
82
79
|
|
|
83
|
-
In
|
|
80
|
+
In JSField, use getValue/setValue for the field; use getVar for other context (record, user, formValues).
|
|
84
81
|
|
|
85
82
|
## Notes
|
|
86
83
|
|
|
87
|
-
- **Path must start with `ctx.`**: e.g
|
|
88
|
-
- **
|
|
89
|
-
- **
|
|
90
|
-
- **Form values**:
|
|
84
|
+
- **Path must start with `ctx.`**: e.g. `ctx.record.id`; otherwise an error is thrown.
|
|
85
|
+
- **Async**: Use `await`, e.g. `const id = await ctx.getVar('ctx.record.id')`.
|
|
86
|
+
- **Missing variable**: Returns `undefined`; use `??` for default: `(await ctx.getVar('ctx.user.nickname')) ?? 'Guest'`.
|
|
87
|
+
- **Form values**: Get via `await ctx.getVar('ctx.formValues')`; not exposed as `ctx.formValues`. In form context prefer `ctx.form.getFieldsValue()` for latest values.
|
|
91
88
|
|
|
92
89
|
## Examples
|
|
93
90
|
|
|
94
|
-
###
|
|
91
|
+
### Current record id
|
|
95
92
|
|
|
96
93
|
```ts
|
|
97
94
|
const recordId = await ctx.getVar('ctx.record.id');
|
|
@@ -100,58 +97,55 @@ if (recordId) {
|
|
|
100
97
|
}
|
|
101
98
|
```
|
|
102
99
|
|
|
103
|
-
###
|
|
100
|
+
### Popup record
|
|
104
101
|
|
|
105
102
|
```ts
|
|
106
103
|
const recordId = await ctx.getVar('ctx.popup.record.id');
|
|
107
104
|
if (recordId) {
|
|
108
|
-
ctx.message.info(`
|
|
105
|
+
ctx.message.info(`Popup record: ${recordId}`);
|
|
109
106
|
}
|
|
110
107
|
```
|
|
111
108
|
|
|
112
|
-
###
|
|
109
|
+
### Array field items
|
|
113
110
|
|
|
114
111
|
```ts
|
|
115
112
|
const roleNames = await ctx.getVar('ctx.user.roles.name');
|
|
116
|
-
//
|
|
113
|
+
// e.g. ['admin', 'member']
|
|
117
114
|
```
|
|
118
115
|
|
|
119
|
-
###
|
|
116
|
+
### Default value
|
|
120
117
|
|
|
121
118
|
```ts
|
|
122
|
-
// getVar does not have a defaultValue parameter; use ?? after the result
|
|
123
119
|
const userName = (await ctx.getVar('ctx.user.nickname')) ?? 'Guest';
|
|
124
120
|
```
|
|
125
121
|
|
|
126
|
-
###
|
|
122
|
+
### Form field value
|
|
127
123
|
|
|
128
124
|
```ts
|
|
129
|
-
// Both ctx.formValues and ctx.form are for form scenarios; use getVar to read nested fields
|
|
130
125
|
const status = await ctx.getVar('ctx.formValues.status');
|
|
131
126
|
if (status === 'draft') {
|
|
132
127
|
// ...
|
|
133
128
|
}
|
|
134
129
|
```
|
|
135
130
|
|
|
136
|
-
###
|
|
131
|
+
### URL query params
|
|
137
132
|
|
|
138
133
|
```ts
|
|
139
|
-
const id = await ctx.getVar('ctx.urlSearchParams.id'); //
|
|
134
|
+
const id = await ctx.getVar('ctx.urlSearchParams.id'); // ?id=xxx
|
|
140
135
|
```
|
|
141
136
|
|
|
142
|
-
### Explore
|
|
137
|
+
### Explore variables
|
|
143
138
|
|
|
144
139
|
```ts
|
|
145
|
-
// Get the variable structure under record (expanded up to 3 levels)
|
|
146
140
|
const vars = await ctx.getVarInfos({ path: 'record', maxDepth: 3 });
|
|
147
|
-
//
|
|
141
|
+
// e.g. { 'record.id': { type: 'string', title: 'id' }, ... }
|
|
148
142
|
```
|
|
149
143
|
|
|
150
144
|
## Related
|
|
151
145
|
|
|
152
|
-
- [ctx.getValue()](./get-value.md)
|
|
153
|
-
- [ctx.form](./form.md)
|
|
154
|
-
- [ctx.model](./model.md)
|
|
155
|
-
- [ctx.blockModel](./block-model.md)
|
|
156
|
-
- [ctx.resource](./resource.md)
|
|
157
|
-
- `{{ctx.xxx}}
|
|
146
|
+
- [ctx.getValue()](./get-value.md): sync current field value (JSField/JSItem only)
|
|
147
|
+
- [ctx.form](./form.md): form instance; `ctx.form.getFieldsValue()` for live form values
|
|
148
|
+
- [ctx.model](./model.md): current model
|
|
149
|
+
- [ctx.blockModel](./block-model.md): parent block
|
|
150
|
+
- [ctx.resource](./resource.md): resource in current context
|
|
151
|
+
- SQL / template `{{ctx.xxx}}`: same resolution as `ctx.getVar('ctx.xxx')`
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
# ctx.i18n
|
|
2
2
|
|
|
3
|
-
The i18n instance
|
|
3
|
+
The i18n instance for the current context; used to read or change the language. **Use [ctx.t()](./t.md) for all translated text**; do not use `ctx.i18n.t`.
|
|
4
4
|
|
|
5
|
-
##
|
|
5
|
+
## Use Cases
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
Available in all RunJS environments (JSBlock, JSField, JSItem, JSColumn, event flow, linkage, etc.).
|
|
8
8
|
|
|
9
|
-
## Type
|
|
9
|
+
## Type
|
|
10
10
|
|
|
11
11
|
```typescript
|
|
12
12
|
interface i18n: {
|
|
@@ -18,28 +18,27 @@ interface i18n: {
|
|
|
18
18
|
## Common Properties
|
|
19
19
|
|
|
20
20
|
| Property | Type | Description |
|
|
21
|
-
|
|
22
|
-
| `language` | `string` |
|
|
21
|
+
|----------|------|-------------|
|
|
22
|
+
| `language` | `string` | Current language code (e.g. `zh-CN`, `en-US`) |
|
|
23
23
|
|
|
24
24
|
## Common Methods
|
|
25
25
|
|
|
26
26
|
### changeLanguage(lng)
|
|
27
27
|
|
|
28
|
-
|
|
28
|
+
Change 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 when the language has been changed.
|
|
35
35
|
|
|
36
36
|
## Examples
|
|
37
37
|
|
|
38
|
-
###
|
|
38
|
+
### Read current language
|
|
39
39
|
|
|
40
40
|
```ts
|
|
41
41
|
const lang = ctx.i18n.language;
|
|
42
|
-
// 'en-US' | 'zh-CN' | ...
|
|
43
42
|
if (lang.startsWith('zh')) {
|
|
44
43
|
ctx.render(ctx.t('Chinese UI'));
|
|
45
44
|
} else {
|
|
@@ -47,13 +46,11 @@ if (lang.startsWith('zh')) {
|
|
|
47
46
|
}
|
|
48
47
|
```
|
|
49
48
|
|
|
50
|
-
###
|
|
49
|
+
### Change language
|
|
51
50
|
|
|
52
51
|
```ts
|
|
53
|
-
// Switch to English
|
|
54
52
|
await ctx.i18n.changeLanguage('en-US');
|
|
55
53
|
|
|
56
|
-
// Switch to Chinese
|
|
57
54
|
await ctx.i18n.changeLanguage('zh-CN');
|
|
58
55
|
```
|
|
59
56
|
|
|
@@ -73,8 +70,8 @@ ctx.render(
|
|
|
73
70
|
|
|
74
71
|
## Notes
|
|
75
72
|
|
|
76
|
-
- **
|
|
73
|
+
- **Translated text**: Use `ctx.t()` only; do not use `ctx.i18n.t`.
|
|
77
74
|
|
|
78
75
|
## Related
|
|
79
76
|
|
|
80
|
-
- [ctx.t()](./t.md):
|
|
77
|
+
- [ctx.t()](./t.md): translation; use this for all copy
|