@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.
Files changed (2) hide show
  1. package/README.md +25 -11
  2. 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
- 在插件中使用 `defineSchema` 定义配置(自动注册到 Web 控制台表单渲染):
128
-
129
- ```typescript
130
- import { usePlugin, Schema } from 'zhin.js'
131
-
132
- const { defineSchema } = usePlugin()
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
- const getConfig = defineSchema(Schema.object({
135
- port: Schema.number().default(8080).description('服务端口'),
136
- enabled: Schema.boolean().default(true).description('是否启用'),
137
- }))
140
+ 插件从 generation-owned `ConfigView` 读取已验证配置:
138
141
 
139
- const config = getConfig()
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`、空字符串、空数组、空对象)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zhin.js/schema",
3
- "version": "1.0.73",
3
+ "version": "1.1.1",
4
4
  "description": "Configuration validation and schema system for Zhin.js",
5
5
  "type": "module",
6
6
  "main": "./lib/index.js",