@zhin.js/schema 1.0.9 → 1.0.11

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/CHANGELOG.md CHANGED
@@ -1,5 +1,20 @@
1
1
  # @zhin.js/schema
2
2
 
3
+ ## 1.0.11
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies [b27e633]
8
+ - zhin.js@1.0.27
9
+
10
+ ## 1.0.10
11
+
12
+ ### Patch Changes
13
+
14
+ - 106d357: fix: ai
15
+ - Updated dependencies [106d357]
16
+ - zhin.js@1.0.26
17
+
3
18
  ## 1.0.9
4
19
 
5
20
  ### Patch Changes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zhin.js/schema",
3
- "version": "1.0.9",
3
+ "version": "1.0.11",
4
4
  "description": "Configuration validation and schema system for Zhin.js",
5
5
  "type": "module",
6
6
  "main": "./lib/index.js",
@@ -14,7 +14,7 @@
14
14
  "devDependencies": {
15
15
  "typescript": "^5.3.0",
16
16
  "@types/node": "^24.3.0",
17
- "zhin.js": "1.0.25"
17
+ "zhin.js": "1.0.27"
18
18
  },
19
19
  "repository": {
20
20
  "type": "git",
@@ -26,7 +26,7 @@
26
26
  "registry": "https://registry.npmjs.org"
27
27
  },
28
28
  "peerDependencies": {
29
- "zhin.js": "1.0.25"
29
+ "zhin.js": "1.0.27"
30
30
  },
31
31
  "keywords": [
32
32
  "zhin",
@@ -38,6 +38,6 @@
38
38
  ],
39
39
  "scripts": {
40
40
  "build": "tsc",
41
- "clean": "rm -rf lib"
41
+ "clean": "rimraf lib"
42
42
  }
43
43
  }
@@ -1,4 +1,4 @@
1
- import { describe, it, expect } from 'vitest'
1
+ import { describe, it, expect, beforeAll } from 'vitest'
2
2
  import { Schema } from '../src/index'
3
3
 
4
4
  describe('Schema', () => {
@@ -163,3 +163,81 @@ describe('Schema', () => {
163
163
  })
164
164
  })
165
165
  })
166
+
167
+ // ============================================================================
168
+ // Schema 工具函数补全
169
+ // ============================================================================
170
+ describe('Schema utils', () => {
171
+ let isEmpty: (v: any) => boolean;
172
+ let deepMerge: <T>(target: T, source: Partial<T>) => T;
173
+
174
+ beforeAll(async () => {
175
+ const utils = await import('../src/utils.js');
176
+ isEmpty = utils.isEmpty;
177
+ deepMerge = utils.deepMerge;
178
+ });
179
+
180
+ describe('isEmpty', () => {
181
+ it('null 应为空', () => {
182
+ expect(isEmpty(null)).toBe(true)
183
+ })
184
+
185
+ it('undefined 应为空', () => {
186
+ expect(isEmpty(undefined)).toBe(true)
187
+ })
188
+
189
+ it('空字符串应为空', () => {
190
+ expect(isEmpty('')).toBe(true)
191
+ })
192
+
193
+ it('0 不应为空', () => {
194
+ expect(isEmpty(0)).toBe(false)
195
+ })
196
+
197
+ it('false 不应为空', () => {
198
+ expect(isEmpty(false)).toBe(false)
199
+ })
200
+
201
+ it('非空字符串不应为空', () => {
202
+ expect(isEmpty('hello')).toBe(false)
203
+ })
204
+
205
+ it('空数组不应为空', () => {
206
+ expect(isEmpty([])).toBe(false)
207
+ })
208
+ })
209
+
210
+ describe('deepMerge', () => {
211
+ it('应合并简单对象', () => {
212
+ const target = { a: 1, b: 2 }
213
+ const source = { b: 3, c: 4 }
214
+ const result = deepMerge(target, source)
215
+ expect(result).toEqual({ a: 1, b: 3, c: 4 })
216
+ })
217
+
218
+ it('应深度合并嵌套对象', () => {
219
+ const target = { a: { x: 1, y: 2 }, b: 3 }
220
+ const source = { a: { y: 5, z: 6 } }
221
+ const result = deepMerge(target, source)
222
+ expect(result).toEqual({ a: { x: 1, y: 5, z: 6 }, b: 3 })
223
+ })
224
+
225
+ it('数组应直接覆盖而非合并', () => {
226
+ const target = { a: [1, 2] }
227
+ const source = { a: [3, 4, 5] }
228
+ const result = deepMerge(target, source)
229
+ expect(result).toEqual({ a: [3, 4, 5] })
230
+ })
231
+
232
+ it('undefined 值不应覆盖', () => {
233
+ const target = { a: 1, b: 2 }
234
+ const source = { a: undefined, b: 3 }
235
+ const result = deepMerge(target, source)
236
+ expect(result).toEqual({ a: 1, b: 3 })
237
+ })
238
+
239
+ it('null target 应返回 target', () => {
240
+ expect(deepMerge(null, { a: 1 })).toBeNull()
241
+ })
242
+ })
243
+ })