@nocobase/plugin-flow-engine 2.1.0-alpha.6 → 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,39 +1,39 @@
|
|
|
1
1
|
# ctx.libs
|
|
2
2
|
|
|
3
|
-
`ctx.libs` is the unified namespace for
|
|
3
|
+
`ctx.libs` is the unified namespace for built-in libraries in RunJS, containing commonly used libraries such as React, Ant Design, dayjs, and lodash. **No `import` or asynchronous loading is required**; they can be used directly via `ctx.libs.xxx`.
|
|
4
4
|
|
|
5
5
|
## Use Cases
|
|
6
6
|
|
|
7
7
|
| Scenario | Description |
|
|
8
|
-
|
|
9
|
-
| **JSBlock / JSField / JSItem / JSColumn** | React + Ant Design
|
|
10
|
-
| **
|
|
11
|
-
| **
|
|
8
|
+
|------|------|
|
|
9
|
+
| **JSBlock / JSField / JSItem / JSColumn** | Use React + Ant Design to render UI, dayjs for date handling, and lodash for data processing. |
|
|
10
|
+
| **Formula / Calculation** | Use formula or math for Excel-like formulas and mathematical expression operations. |
|
|
11
|
+
| **Workflow / Linkage Rules** | Call utility libraries like lodash, dayjs, and formula in pure logic scenarios. |
|
|
12
12
|
|
|
13
|
-
## Built-in
|
|
13
|
+
## Built-in Libraries Overview
|
|
14
14
|
|
|
15
|
-
| Property | Description |
|
|
16
|
-
|
|
17
|
-
| `ctx.libs.React` | React core for JSX and Hooks | [React](https://react.dev/) |
|
|
18
|
-
| `ctx.libs.ReactDOM` | ReactDOM (
|
|
19
|
-
| `ctx.libs.antd` | Ant Design (Button, Card, Table, Form, Input, Modal, etc.) | [Ant Design](https://ant.design/components/overview/) |
|
|
20
|
-
| `ctx.libs.antdIcons` | Ant Design
|
|
21
|
-
| `ctx.libs.dayjs` | Date
|
|
22
|
-
| `ctx.libs.lodash` |
|
|
23
|
-
| `ctx.libs.formula` | Excel-like
|
|
24
|
-
| `ctx.libs.math` |
|
|
15
|
+
| Property | Description | Documentation |
|
|
16
|
+
|------|------|------|
|
|
17
|
+
| `ctx.libs.React` | React core, used for JSX and Hooks | [React](https://react.dev/) |
|
|
18
|
+
| `ctx.libs.ReactDOM` | ReactDOM client API (including `createRoot`), used with React for rendering | [React DOM](https://react.dev/reference/react-dom) |
|
|
19
|
+
| `ctx.libs.antd` | Ant Design component library (Button, Card, Table, Form, Input, Modal, etc.) | [Ant Design](https://ant.design/components/overview/) |
|
|
20
|
+
| `ctx.libs.antdIcons` | Ant Design icon library (e.g., PlusOutlined, UserOutlined) | [@ant-design/icons](https://ant.design/components/icon/) |
|
|
21
|
+
| `ctx.libs.dayjs` | Date and time utility library | [dayjs](https://day.js.org/) |
|
|
22
|
+
| `ctx.libs.lodash` | Utility library (get, set, debounce, etc.) | [Lodash](https://lodash.com/docs/) |
|
|
23
|
+
| `ctx.libs.formula` | Excel-like formula function library (SUM, AVERAGE, IF, etc.) | [Formula.js](https://formulajs.info/functions/) |
|
|
24
|
+
| `ctx.libs.math` | Mathematical expression and calculation library | [Math.js](https://mathjs.org/docs/) |
|
|
25
25
|
|
|
26
|
-
## Top-level
|
|
26
|
+
## Top-level Aliases
|
|
27
27
|
|
|
28
|
-
For
|
|
28
|
+
For compatibility with legacy code, some libraries are also exposed at the top level: `ctx.React`, `ctx.ReactDOM`, `ctx.antd`, and `ctx.dayjs`. **It is recommended to consistently use `ctx.libs.xxx`** for easier maintenance and documentation searching.
|
|
29
29
|
|
|
30
|
-
## Lazy
|
|
30
|
+
## Lazy Loading
|
|
31
31
|
|
|
32
|
-
`lodash`, `formula`, `math`
|
|
32
|
+
`lodash`, `formula`, and `math` use **lazy loading**: a dynamic import is triggered only when `ctx.libs.lodash` is accessed for the first time, and the cache is reused thereafter. `React`, `antd`, `dayjs`, and `antdIcons` are pre-configured by the context and are available immediately.
|
|
33
33
|
|
|
34
34
|
## Examples
|
|
35
35
|
|
|
36
|
-
### React and Ant Design
|
|
36
|
+
### Rendering with React and Ant Design
|
|
37
37
|
|
|
38
38
|
```tsx
|
|
39
39
|
const { Button, Card } = ctx.libs.antd;
|
|
@@ -45,7 +45,7 @@ ctx.render(
|
|
|
45
45
|
);
|
|
46
46
|
```
|
|
47
47
|
|
|
48
|
-
### Hooks
|
|
48
|
+
### Using Hooks
|
|
49
49
|
|
|
50
50
|
```tsx
|
|
51
51
|
const { React } = ctx.libs;
|
|
@@ -59,7 +59,7 @@ const App = () => {
|
|
|
59
59
|
ctx.render(<App />);
|
|
60
60
|
```
|
|
61
61
|
|
|
62
|
-
### Icons
|
|
62
|
+
### Using Icons
|
|
63
63
|
|
|
64
64
|
```tsx
|
|
65
65
|
const { Button } = ctx.libs.antd;
|
|
@@ -68,7 +68,7 @@ const { UserOutlined, HeartOutlined } = ctx.libs.antdIcons;
|
|
|
68
68
|
ctx.render(<Button icon={<UserOutlined />}>User</Button>);
|
|
69
69
|
```
|
|
70
70
|
|
|
71
|
-
### dayjs
|
|
71
|
+
### Date Processing with dayjs
|
|
72
72
|
|
|
73
73
|
```ts
|
|
74
74
|
const now = ctx.libs.dayjs();
|
|
@@ -76,14 +76,14 @@ const formatted = now.format('YYYY-MM-DD HH:mm:ss');
|
|
|
76
76
|
ctx.message.info(formatted);
|
|
77
77
|
```
|
|
78
78
|
|
|
79
|
-
### lodash
|
|
79
|
+
### Utility Functions with lodash
|
|
80
80
|
|
|
81
81
|
```ts
|
|
82
82
|
const user = { profile: { name: 'Alice' } };
|
|
83
83
|
const name = ctx.libs.lodash.get(user, 'profile.name', 'Unknown');
|
|
84
84
|
```
|
|
85
85
|
|
|
86
|
-
###
|
|
86
|
+
### Formula Calculations
|
|
87
87
|
|
|
88
88
|
```ts
|
|
89
89
|
const values = [1, 2, 3, 4];
|
|
@@ -91,7 +91,7 @@ const sum = ctx.libs.formula.SUM(values);
|
|
|
91
91
|
const avg = ctx.libs.formula.AVERAGE(values);
|
|
92
92
|
```
|
|
93
93
|
|
|
94
|
-
### math
|
|
94
|
+
### Mathematical Expressions with math.js
|
|
95
95
|
|
|
96
96
|
```ts
|
|
97
97
|
const result = ctx.libs.math.evaluate('2 + 3 * 4');
|
|
@@ -100,10 +100,10 @@ const result = ctx.libs.math.evaluate('2 + 3 * 4');
|
|
|
100
100
|
|
|
101
101
|
## Notes
|
|
102
102
|
|
|
103
|
-
- **Mixing with ctx.importAsync**: If
|
|
104
|
-
- **Multiple React
|
|
103
|
+
- **Mixing with ctx.importAsync**: If an external React is loaded via `ctx.importAsync('react@19')`, JSX will use that instance. In this case, **do not** mix it with `ctx.libs.antd`. Ant Design must be loaded to match that React version (e.g., `ctx.importAsync('antd@5.x')`, `ctx.importAsync('@ant-design/icons@5.x')`).
|
|
104
|
+
- **Multiple React Instances**: If "Invalid hook call" occurs or the hook dispatcher is null, it is usually caused by multiple React instances. Before reading `ctx.libs.React` or calling Hooks, execute `await ctx.importAsync('react@version')` first to ensure the same React instance is shared with the page.
|
|
105
105
|
|
|
106
106
|
## Related
|
|
107
107
|
|
|
108
|
-
- [ctx.importAsync()](./import-async.md)
|
|
109
|
-
- [ctx.render()](./render.md)
|
|
108
|
+
- [ctx.importAsync()](./import-async.md) - Load external ESM modules on demand (e.g., specific versions of React, Vue)
|
|
109
|
+
- [ctx.render()](./render.md) - Render content to a container
|
|
@@ -1,85 +1,88 @@
|
|
|
1
1
|
# ctx.location
|
|
2
2
|
|
|
3
|
-
Current route location, equivalent to React Router
|
|
3
|
+
Current route location information, equivalent to the React Router `location` object. It is typically used in conjunction with `ctx.router` and `ctx.route` to read the current path, query string, hash, and state passed through the route.
|
|
4
4
|
|
|
5
5
|
## Use Cases
|
|
6
6
|
|
|
7
7
|
| Scenario | Description |
|
|
8
|
-
|
|
9
|
-
| **JSBlock / JSField** |
|
|
10
|
-
| **Linkage /
|
|
11
|
-
| **
|
|
8
|
+
|------|------|
|
|
9
|
+
| **JSBlock / JSField** | Perform conditional rendering or logic branching based on the current path, query parameters, or hash. |
|
|
10
|
+
| **Linkage Rules / FlowEngine** | Read URL query parameters for linkage filtering, or determine the source based on `location.state`. |
|
|
11
|
+
| **Post-navigation processing** | Receive data passed from the previous page via `ctx.router.navigate` using `ctx.location.state` on the target page. |
|
|
12
12
|
|
|
13
|
-
> Note: `ctx.location` is only available in RunJS
|
|
13
|
+
> Note: `ctx.location` is only available in RunJS environments with a routing context (e.g., JSBlock within a page, FlowEngine, etc.); it may be null in pure backend or non-routing contexts (e.g., Workflows).
|
|
14
14
|
|
|
15
|
-
## Type
|
|
15
|
+
## Type Definition
|
|
16
16
|
|
|
17
17
|
```ts
|
|
18
18
|
location: Location;
|
|
19
19
|
```
|
|
20
20
|
|
|
21
|
-
`Location`
|
|
21
|
+
`Location` comes from `react-router-dom`, consistent with the return value of React Router's `useLocation()`.
|
|
22
22
|
|
|
23
23
|
## Common Fields
|
|
24
24
|
|
|
25
25
|
| Field | Type | Description |
|
|
26
|
-
|
|
27
|
-
| `pathname` | `string` |
|
|
28
|
-
| `search` | `string` |
|
|
29
|
-
| `hash` | `string` |
|
|
30
|
-
| `state` | `any` |
|
|
31
|
-
| `key` | `string` |
|
|
26
|
+
|------|------|------|
|
|
27
|
+
| `pathname` | `string` | The current path, starting with `/` (e.g., `/admin/users`). |
|
|
28
|
+
| `search` | `string` | The query string, starting with `?` (e.g., `?page=1&status=active`). |
|
|
29
|
+
| `hash` | `string` | The hash fragment, starting with `#` (e.g., `#section-1`). |
|
|
30
|
+
| `state` | `any` | Arbitrary data passed via `ctx.router.navigate(path, { state })`, not reflected in the URL. |
|
|
31
|
+
| `key` | `string` | A unique identifier for this location; the initial page is `"default"`. |
|
|
32
32
|
|
|
33
|
-
##
|
|
33
|
+
## Relationship with ctx.router and ctx.urlSearchParams
|
|
34
34
|
|
|
35
|
-
|
|
|
36
|
-
|
|
37
|
-
| **
|
|
38
|
-
| **
|
|
39
|
-
| **Parse search** | `new URLSearchParams(ctx.location.search)` or `ctx.urlSearchParams` |
|
|
35
|
+
| Purpose | Recommended Usage |
|
|
36
|
+
|------|----------|
|
|
37
|
+
| **Read path, hash, state** | `ctx.location.pathname` / `ctx.location.hash` / `ctx.location.state` |
|
|
38
|
+
| **Read query parameters (as object)** | `ctx.urlSearchParams`, which provides the parsed object directly. |
|
|
39
|
+
| **Parse search string** | `new URLSearchParams(ctx.location.search)` or use `ctx.urlSearchParams` directly. |
|
|
40
40
|
|
|
41
|
-
`ctx.urlSearchParams` is
|
|
41
|
+
`ctx.urlSearchParams` is parsed from `ctx.location.search`. If you only need query parameters, using `ctx.urlSearchParams` is more convenient.
|
|
42
42
|
|
|
43
43
|
## Examples
|
|
44
44
|
|
|
45
|
-
###
|
|
45
|
+
### Branching Based on Path
|
|
46
46
|
|
|
47
47
|
```ts
|
|
48
48
|
if (ctx.location.pathname.startsWith('/admin/users')) {
|
|
49
|
-
ctx.message.info('
|
|
49
|
+
ctx.message.info('Currently on the user management page');
|
|
50
50
|
}
|
|
51
51
|
```
|
|
52
52
|
|
|
53
|
-
###
|
|
53
|
+
### Parsing Query Parameters
|
|
54
54
|
|
|
55
55
|
```ts
|
|
56
|
+
// Method 1: Using ctx.urlSearchParams (Recommended)
|
|
56
57
|
const page = ctx.urlSearchParams.page || 1;
|
|
57
58
|
const status = ctx.urlSearchParams.status;
|
|
58
59
|
|
|
60
|
+
// Method 2: Using URLSearchParams to parse search
|
|
59
61
|
const params = new URLSearchParams(ctx.location.search);
|
|
60
62
|
const page = params.get('page') || '1';
|
|
61
63
|
const status = params.get('status');
|
|
62
64
|
```
|
|
63
65
|
|
|
64
|
-
###
|
|
66
|
+
### Receiving State Passed via Route Navigation
|
|
65
67
|
|
|
66
68
|
```ts
|
|
69
|
+
// When navigating from the previous page: ctx.router.navigate('/users/123', { state: { from: 'dashboard' } })
|
|
67
70
|
const prevState = ctx.location.state;
|
|
68
71
|
if (prevState?.from === 'dashboard') {
|
|
69
|
-
ctx.message.info('Navigated from dashboard');
|
|
72
|
+
ctx.message.info('Navigated from the dashboard');
|
|
70
73
|
}
|
|
71
74
|
```
|
|
72
75
|
|
|
73
|
-
###
|
|
76
|
+
### Locating Anchors via Hash
|
|
74
77
|
|
|
75
78
|
```ts
|
|
76
|
-
const hash = ctx.location.hash;
|
|
79
|
+
const hash = ctx.location.hash; // e.g., "#edit"
|
|
77
80
|
if (hash === '#edit') {
|
|
78
|
-
// Scroll to edit or
|
|
81
|
+
// Scroll to the edit area or execute corresponding logic
|
|
79
82
|
}
|
|
80
83
|
```
|
|
81
84
|
|
|
82
85
|
## Related
|
|
83
86
|
|
|
84
|
-
- [ctx.router](./router.md): navigation; `state` from `ctx.router.navigate`
|
|
85
|
-
- [ctx.route](./route.md):
|
|
87
|
+
- [ctx.router](./router.md): Route navigation; the `state` from `ctx.router.navigate` can be retrieved via `ctx.location.state` on the target page.
|
|
88
|
+
- [ctx.route](./route.md): Current route match information (parameters, configuration, etc.), often used in conjunction with `ctx.location`.
|
|
@@ -1,84 +1,85 @@
|
|
|
1
1
|
# ctx.logger
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
A logging wrapper based on [pino](https://github.com/pinojs/pino), providing high-performance structured JSON logs. It is recommended to use `ctx.logger` instead of `console` for easier log collection and analysis.
|
|
4
4
|
|
|
5
|
-
##
|
|
5
|
+
## Scenarios
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
`ctx.logger` can be used in all RunJS scenarios for debugging, error tracking, performance analysis, etc.
|
|
8
8
|
|
|
9
|
-
## Type
|
|
9
|
+
## Type Definition
|
|
10
10
|
|
|
11
11
|
```ts
|
|
12
12
|
logger: pino.Logger;
|
|
13
13
|
```
|
|
14
14
|
|
|
15
|
-
`ctx.logger` is `engine.logger.child({ module: 'flow-engine' })`,
|
|
15
|
+
`ctx.logger` is an instance of `engine.logger.child({ module: 'flow-engine' })`, which is a pino child logger with a `module` context.
|
|
16
16
|
|
|
17
|
-
## Log
|
|
17
|
+
## Log Levels
|
|
18
18
|
|
|
19
|
-
|
|
19
|
+
pino supports the following levels (from highest to lowest):
|
|
20
20
|
|
|
21
21
|
| Level | Method | Description |
|
|
22
|
-
|
|
23
|
-
| `fatal` | `ctx.logger.fatal()` | Fatal
|
|
24
|
-
| `error` | `ctx.logger.error()` | Error
|
|
25
|
-
| `warn` | `ctx.logger.warn()` | Warning
|
|
26
|
-
| `info` | `ctx.logger.info()` | General runtime
|
|
27
|
-
| `debug` | `ctx.logger.debug()` |
|
|
28
|
-
| `trace` | `ctx.logger.trace()` |
|
|
22
|
+
|------|------|------|
|
|
23
|
+
| `fatal` | `ctx.logger.fatal()` | Fatal error, usually leading to process exit |
|
|
24
|
+
| `error` | `ctx.logger.error()` | Error, indicating a failed request or operation |
|
|
25
|
+
| `warn` | `ctx.logger.warn()` | Warning, indicating potential risks or abnormal situations |
|
|
26
|
+
| `info` | `ctx.logger.info()` | General runtime information |
|
|
27
|
+
| `debug` | `ctx.logger.debug()` | Debugging information, used during development |
|
|
28
|
+
| `trace` | `ctx.logger.trace()` | Detailed trace, used for deep diagnostics |
|
|
29
29
|
|
|
30
|
-
## Recommended
|
|
30
|
+
## Recommended Usage
|
|
31
31
|
|
|
32
|
-
|
|
32
|
+
The recommended format is `level(msg, meta)`: the message comes first, followed by an optional metadata object.
|
|
33
33
|
|
|
34
34
|
```ts
|
|
35
|
-
ctx.logger.info('Block
|
|
36
|
-
ctx.logger.info('
|
|
37
|
-
ctx.logger.warn('
|
|
38
|
-
ctx.logger.error('
|
|
35
|
+
ctx.logger.info('Block loading complete');
|
|
36
|
+
ctx.logger.info('Operation successful', { recordId: 456 });
|
|
37
|
+
ctx.logger.warn('Performance warning', { duration: 5000 });
|
|
38
|
+
ctx.logger.error('Operation failed', { userId: 123, action: 'create' });
|
|
39
39
|
ctx.logger.error('Request failed', { err });
|
|
40
40
|
```
|
|
41
41
|
|
|
42
|
-
pino also supports `level(meta, msg)` or `level({ msg, ...meta })`
|
|
42
|
+
pino also supports `level(meta, msg)` (object first) or `level({ msg, ...meta })` (single object), which can be used as needed.
|
|
43
43
|
|
|
44
44
|
## Examples
|
|
45
45
|
|
|
46
|
-
### Basic
|
|
46
|
+
### Basic Usage
|
|
47
47
|
|
|
48
48
|
```ts
|
|
49
|
-
ctx.logger.info('Block
|
|
49
|
+
ctx.logger.info('Block loading complete');
|
|
50
50
|
ctx.logger.warn('Request failed, using cache', { err });
|
|
51
|
-
ctx.logger.debug('Saving', { recordId: ctx.record?.id });
|
|
51
|
+
ctx.logger.debug('Saving...', { recordId: ctx.record?.id });
|
|
52
52
|
```
|
|
53
53
|
|
|
54
|
-
### Child
|
|
54
|
+
### Creating a Child Logger with child()
|
|
55
55
|
|
|
56
56
|
```ts
|
|
57
|
+
// Create a child logger with context for the current logic
|
|
57
58
|
const log = ctx.logger.child({ scope: 'myBlock' });
|
|
58
|
-
log.info('
|
|
59
|
-
log.debug('
|
|
59
|
+
log.info('Executing step 1');
|
|
60
|
+
log.debug('Executing step 2', { step: 2 });
|
|
60
61
|
```
|
|
61
62
|
|
|
62
|
-
###
|
|
63
|
+
### Relationship with console
|
|
63
64
|
|
|
64
|
-
|
|
65
|
+
It is recommended to use `ctx.logger` directly to obtain structured JSON logs. If you are accustomed to using `console`, the mappings are: `console.log` → `ctx.logger.info`, `console.error` → `ctx.logger.error`, `console.warn` → `ctx.logger.warn`.
|
|
65
66
|
|
|
66
|
-
##
|
|
67
|
+
## Log Format
|
|
67
68
|
|
|
68
|
-
pino outputs JSON
|
|
69
|
+
pino outputs structured JSON, where each log entry contains:
|
|
69
70
|
|
|
70
|
-
- `level`:
|
|
71
|
-
- `time`:
|
|
72
|
-
- `msg`: message
|
|
73
|
-
- `module`: `flow-engine`
|
|
74
|
-
-
|
|
71
|
+
- `level`: Log level (numeric)
|
|
72
|
+
- `time`: Timestamp (milliseconds)
|
|
73
|
+
- `msg`: Log message
|
|
74
|
+
- `module`: Fixed as `flow-engine`
|
|
75
|
+
- Other custom fields (passed via objects)
|
|
75
76
|
|
|
76
77
|
## Notes
|
|
77
78
|
|
|
78
|
-
- Logs are JSON
|
|
79
|
-
- Child loggers
|
|
80
|
-
- Some environments (
|
|
79
|
+
- Logs are structured JSON, making them easy to collect, search, and analyze.
|
|
80
|
+
- Child loggers created via `child()` also follow the `level(msg, meta)` recommendation.
|
|
81
|
+
- Some runtime environments (such as Workflows) may use different log output methods.
|
|
81
82
|
|
|
82
83
|
## Related
|
|
83
84
|
|
|
84
|
-
- [pino](https://github.com/pinojs/pino)
|
|
85
|
+
- [pino](https://github.com/pinojs/pino) — The underlying logging library
|
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
# ctx.makeResource()
|
|
2
2
|
|
|
3
|
-
**Creates** a new resource instance
|
|
3
|
+
**Creates** and returns a new resource instance **without** writing to or modifying `ctx.resource`. It is suitable for scenarios requiring multiple independent resources or temporary usage.
|
|
4
4
|
|
|
5
5
|
## Use Cases
|
|
6
6
|
|
|
7
7
|
| Scenario | Description |
|
|
8
|
-
|
|
9
|
-
| **Multiple resources** | Load
|
|
10
|
-
| **
|
|
11
|
-
| **Auxiliary data** |
|
|
8
|
+
|------|------|
|
|
9
|
+
| **Multiple resources** | Load multiple data sources simultaneously (e.g., user list + order list), each using an independent resource. |
|
|
10
|
+
| **Temporary queries** | One-time queries that are discarded after use, without needing to bind to `ctx.resource`. |
|
|
11
|
+
| **Auxiliary data** | Use `ctx.resource` for primary data and `makeResource` to create instances for additional data. |
|
|
12
12
|
|
|
13
|
-
If you only need
|
|
13
|
+
If you only need a single resource and want to bind it to `ctx.resource`, using [ctx.initResource()](./init-resource.md) is more appropriate.
|
|
14
14
|
|
|
15
|
-
## Type
|
|
15
|
+
## Type Definition
|
|
16
16
|
|
|
17
17
|
```ts
|
|
18
18
|
makeResource<T = FlowResource>(
|
|
@@ -21,17 +21,17 @@ makeResource<T = FlowResource>(
|
|
|
21
21
|
```
|
|
22
22
|
|
|
23
23
|
| Parameter | Type | Description |
|
|
24
|
-
|
|
25
|
-
| `resourceType` | `string` | `'APIResource'`, `'SingleRecordResource'`, `'MultiRecordResource'`, `'SQLResource'` |
|
|
24
|
+
|------|------|------|
|
|
25
|
+
| `resourceType` | `string` | Resource type: `'APIResource'`, `'SingleRecordResource'`, `'MultiRecordResource'`, `'SQLResource'` |
|
|
26
26
|
|
|
27
|
-
**Returns**: The
|
|
27
|
+
**Returns**: The newly created resource instance.
|
|
28
28
|
|
|
29
|
-
##
|
|
29
|
+
## Difference from ctx.initResource()
|
|
30
30
|
|
|
31
31
|
| Method | Behavior |
|
|
32
|
-
|
|
33
|
-
| `ctx.makeResource(type)` |
|
|
34
|
-
| `ctx.initResource(type)` | Creates and binds if
|
|
32
|
+
|------|------|
|
|
33
|
+
| `ctx.makeResource(type)` | Only creates and returns a new instance, **not** writing to `ctx.resource`. Can be called multiple times to obtain multiple independent resources. |
|
|
34
|
+
| `ctx.initResource(type)` | Creates and binds if `ctx.resource` does not exist; returns it directly if it already exists. Ensures `ctx.resource` is available. |
|
|
35
35
|
|
|
36
36
|
## Examples
|
|
37
37
|
|
|
@@ -42,7 +42,7 @@ const listRes = ctx.makeResource('MultiRecordResource');
|
|
|
42
42
|
listRes.setResourceName('users');
|
|
43
43
|
await listRes.refresh();
|
|
44
44
|
const users = listRes.getData();
|
|
45
|
-
// ctx.resource
|
|
45
|
+
// ctx.resource remains its original value (if any)
|
|
46
46
|
```
|
|
47
47
|
|
|
48
48
|
### Multiple resources
|
|
@@ -58,15 +58,16 @@ await ordersRes.refresh();
|
|
|
58
58
|
|
|
59
59
|
ctx.render(
|
|
60
60
|
<div>
|
|
61
|
-
<p>
|
|
62
|
-
<p>
|
|
61
|
+
<p>User count: {usersRes.getData().length}</p>
|
|
62
|
+
<p>Order count: {ordersRes.getData().length}</p>
|
|
63
63
|
</div>
|
|
64
64
|
);
|
|
65
65
|
```
|
|
66
66
|
|
|
67
|
-
###
|
|
67
|
+
### Temporary query
|
|
68
68
|
|
|
69
69
|
```ts
|
|
70
|
+
// One-time query, does not pollute ctx.resource
|
|
70
71
|
const tempRes = ctx.makeResource('SingleRecordResource');
|
|
71
72
|
tempRes.setResourceName('users');
|
|
72
73
|
tempRes.setFilterByTk(1);
|
|
@@ -76,14 +77,14 @@ const record = tempRes.getData();
|
|
|
76
77
|
|
|
77
78
|
## Notes
|
|
78
79
|
|
|
79
|
-
-
|
|
80
|
-
- Each instance is independent;
|
|
80
|
+
- The newly created resource needs to call `setResourceName(name)` to specify the collection, and then load data via `refresh()`.
|
|
81
|
+
- Each resource instance is independent and does not affect others; suitable for loading multiple data sources in parallel.
|
|
81
82
|
|
|
82
83
|
## Related
|
|
83
84
|
|
|
84
|
-
- [ctx.initResource()](./init-resource.md):
|
|
85
|
-
- [ctx.resource](./resource.md): current context
|
|
86
|
-
- [MultiRecordResource](../resource/multi-record-resource
|
|
87
|
-
- [SingleRecordResource](../resource/single-record-resource
|
|
88
|
-
- [APIResource](../resource/api-resource
|
|
89
|
-
- [SQLResource](../resource/sql-resource
|
|
85
|
+
- [ctx.initResource()](./init-resource.md): Initialize and bind to `ctx.resource`
|
|
86
|
+
- [ctx.resource](./resource.md): The resource instance in the current context
|
|
87
|
+
- [MultiRecordResource](../resource/multi-record-resource) — Multiple records/List
|
|
88
|
+
- [SingleRecordResource](../resource/single-record-resource) — Single record
|
|
89
|
+
- [APIResource](../resource/api-resource) — General API resource
|
|
90
|
+
- [SQLResource](../resource/sql-resource) — SQL query resource
|
|
@@ -1,63 +1,63 @@
|
|
|
1
1
|
# ctx.message
|
|
2
2
|
|
|
3
|
-
Ant Design global message API
|
|
3
|
+
Ant Design global message API, used to display temporary light prompts at the top center of the page. Messages close automatically after a certain period or can be closed manually by the user.
|
|
4
4
|
|
|
5
5
|
## Use Cases
|
|
6
6
|
|
|
7
7
|
| Scenario | Description |
|
|
8
|
-
|
|
9
|
-
| **JSBlock / JSField / JSItem / JSColumn** |
|
|
10
|
-
| **Form
|
|
11
|
-
| **JSAction** |
|
|
8
|
+
|------|------|
|
|
9
|
+
| **JSBlock / JSField / JSItem / JSColumn** | Operation feedback, validation prompts, copy success, and other light prompts |
|
|
10
|
+
| **Form Operations / Workflow** | Feedback for submission success, save failure, validation failure, etc. |
|
|
11
|
+
| **Action Events (JSAction)** | Immediate feedback for clicks, batch operation completion, etc. |
|
|
12
12
|
|
|
13
|
-
## Type
|
|
13
|
+
## Type Definition
|
|
14
14
|
|
|
15
15
|
```ts
|
|
16
16
|
message: MessageInstance;
|
|
17
17
|
```
|
|
18
18
|
|
|
19
|
-
`MessageInstance` is the Ant Design message
|
|
19
|
+
`MessageInstance` is the Ant Design message interface, providing the following methods.
|
|
20
20
|
|
|
21
21
|
## Common Methods
|
|
22
22
|
|
|
23
23
|
| Method | Description |
|
|
24
|
-
|
|
25
|
-
| `success(content, duration?)` |
|
|
26
|
-
| `error(content, duration?)` |
|
|
27
|
-
| `warning(content, duration?)` |
|
|
28
|
-
| `info(content, duration?)` |
|
|
29
|
-
| `loading(content, duration?)` |
|
|
30
|
-
| `open(config)` | Open
|
|
31
|
-
| `destroy()` | Close all messages |
|
|
24
|
+
|------|------|
|
|
25
|
+
| `success(content, duration?)` | Display a success prompt |
|
|
26
|
+
| `error(content, duration?)` | Display an error prompt |
|
|
27
|
+
| `warning(content, duration?)` | Display a warning prompt |
|
|
28
|
+
| `info(content, duration?)` | Display an information prompt |
|
|
29
|
+
| `loading(content, duration?)` | Display a loading prompt (must be closed manually) |
|
|
30
|
+
| `open(config)` | Open a message using custom configuration |
|
|
31
|
+
| `destroy()` | Close all currently displayed messages |
|
|
32
32
|
|
|
33
33
|
**Parameters:**
|
|
34
34
|
|
|
35
|
-
- `content
|
|
36
|
-
- `duration
|
|
35
|
+
- `content` (`string` | `ConfigOptions`): Message content or configuration object
|
|
36
|
+
- `duration` (`number`, optional): Auto-close delay (seconds), default is 3 seconds; set to 0 to disable auto-close
|
|
37
37
|
|
|
38
|
-
**ConfigOptions** (when content is an object):
|
|
38
|
+
**ConfigOptions** (when `content` is an object):
|
|
39
39
|
|
|
40
40
|
```ts
|
|
41
41
|
interface ConfigOptions {
|
|
42
|
-
content: React.ReactNode;
|
|
43
|
-
duration?: number;
|
|
44
|
-
onClose?: () => void;
|
|
45
|
-
icon?: React.ReactNode;
|
|
42
|
+
content: React.ReactNode; // Message content
|
|
43
|
+
duration?: number; // Auto-close delay (seconds)
|
|
44
|
+
onClose?: () => void; // Callback when closed
|
|
45
|
+
icon?: React.ReactNode; // Custom icon
|
|
46
46
|
}
|
|
47
47
|
```
|
|
48
48
|
|
|
49
49
|
## Examples
|
|
50
50
|
|
|
51
|
-
### Basic
|
|
51
|
+
### Basic Usage
|
|
52
52
|
|
|
53
53
|
```ts
|
|
54
|
-
ctx.message.success('
|
|
55
|
-
ctx.message.error('
|
|
54
|
+
ctx.message.success('Operation successful');
|
|
55
|
+
ctx.message.error('Operation failed');
|
|
56
56
|
ctx.message.warning('Please select data first');
|
|
57
57
|
ctx.message.info('Processing...');
|
|
58
58
|
```
|
|
59
59
|
|
|
60
|
-
###
|
|
60
|
+
### Internationalization with ctx.t
|
|
61
61
|
|
|
62
62
|
```ts
|
|
63
63
|
ctx.message.success(ctx.t('Copied'));
|
|
@@ -65,42 +65,43 @@ ctx.message.warning(ctx.t('Please select at least one row'));
|
|
|
65
65
|
ctx.message.success(ctx.t('Exported {{count}} records', { count: rows.length }));
|
|
66
66
|
```
|
|
67
67
|
|
|
68
|
-
### Loading and
|
|
68
|
+
### Loading and Manual Close
|
|
69
69
|
|
|
70
70
|
```ts
|
|
71
71
|
const hide = ctx.message.loading(ctx.t('Saving...'));
|
|
72
|
+
// Execute asynchronous operation
|
|
72
73
|
await saveData();
|
|
73
|
-
hide();
|
|
74
|
+
hide(); // Manually close loading
|
|
74
75
|
ctx.message.success(ctx.t('Saved'));
|
|
75
76
|
```
|
|
76
77
|
|
|
77
|
-
###
|
|
78
|
+
### Custom Configuration with open
|
|
78
79
|
|
|
79
80
|
```ts
|
|
80
81
|
ctx.message.open({
|
|
81
82
|
type: 'success',
|
|
82
|
-
content: 'Custom success',
|
|
83
|
+
content: 'Custom success prompt',
|
|
83
84
|
duration: 5,
|
|
84
|
-
onClose: () => console.log('closed'),
|
|
85
|
+
onClose: () => console.log('message closed'),
|
|
85
86
|
});
|
|
86
87
|
```
|
|
87
88
|
|
|
88
|
-
### Close
|
|
89
|
+
### Close All Messages
|
|
89
90
|
|
|
90
91
|
```ts
|
|
91
92
|
ctx.message.destroy();
|
|
92
93
|
```
|
|
93
94
|
|
|
94
|
-
## ctx.message
|
|
95
|
+
## Difference Between ctx.message and ctx.notification
|
|
95
96
|
|
|
96
|
-
| | ctx.message | ctx.notification |
|
|
97
|
-
|
|
98
|
-
| **Position** | Top center | Top right |
|
|
99
|
-
| **
|
|
100
|
-
| **Typical** |
|
|
97
|
+
| Feature | ctx.message | ctx.notification |
|
|
98
|
+
|------|--------------|------------------|
|
|
99
|
+
| **Position** | Top center of the page | Top right corner |
|
|
100
|
+
| **Purpose** | Temporary light prompt, disappears automatically | Notification panel, can include title and description, suitable for longer display |
|
|
101
|
+
| **Typical Scenarios** | Operation feedback, validation prompts, copy success | Task completion notifications, system messages, longer content requiring user attention |
|
|
101
102
|
|
|
102
103
|
## Related
|
|
103
104
|
|
|
104
|
-
- [ctx.notification](./notification.md)
|
|
105
|
-
- [ctx.modal](./modal.md)
|
|
106
|
-
- [ctx.t()](./t.md)
|
|
105
|
+
- [ctx.notification](./notification.md) - Top-right notifications, suitable for longer display durations
|
|
106
|
+
- [ctx.modal](./modal.md) - Modal confirmation, blocking interaction
|
|
107
|
+
- [ctx.t()](./t.md) - Internationalization, commonly used with message
|