@zhin.js/schema 1.0.73 → 1.1.1
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/README.md +25 -11
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -124,21 +124,35 @@ const formatter = Schema.resolve('number')
|
|
|
124
124
|
|
|
125
125
|
## 与 Zhin.js 集成
|
|
126
126
|
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
```
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
127
|
+
Plugin Runtime 的配置契约由插件根目录 `schema.json` 声明,Runtime 在候选代装配前统一校验并填充默认值:
|
|
128
|
+
|
|
129
|
+
```json
|
|
130
|
+
{
|
|
131
|
+
"type": "object",
|
|
132
|
+
"properties": {
|
|
133
|
+
"port": { "type": "number", "default": 8080 },
|
|
134
|
+
"enabled": { "type": "boolean", "default": true }
|
|
135
|
+
},
|
|
136
|
+
"additionalProperties": false
|
|
137
|
+
}
|
|
138
|
+
```
|
|
133
139
|
|
|
134
|
-
|
|
135
|
-
port: Schema.number().default(8080).description('服务端口'),
|
|
136
|
-
enabled: Schema.boolean().default(true).description('是否启用'),
|
|
137
|
-
}))
|
|
140
|
+
插件从 generation-owned `ConfigView` 读取已验证配置:
|
|
138
141
|
|
|
139
|
-
|
|
142
|
+
```typescript
|
|
143
|
+
import { definePlugin } from 'zhin.js'
|
|
144
|
+
|
|
145
|
+
export default definePlugin<{ port: number; enabled: boolean }>({
|
|
146
|
+
name: 'example',
|
|
147
|
+
setup({ config }) {
|
|
148
|
+
const current = config.get()
|
|
149
|
+
console.log(current.port, current.enabled)
|
|
150
|
+
},
|
|
151
|
+
})
|
|
140
152
|
```
|
|
141
153
|
|
|
154
|
+
`@zhin.js/schema` 继续用于业务输入的运行时解析;它不承担 Plugin Runtime 配置注册。
|
|
155
|
+
|
|
142
156
|
## 工具函数
|
|
143
157
|
|
|
144
158
|
- `isEmpty(value)` - 检查值是否为空(`undefined`、`null`、空字符串、空数组、空对象)
|