@anov/cic-standard-sdk 0.0.9 → 0.0.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/README.md CHANGED
@@ -33,11 +33,11 @@ const sdk = new CICSDK(config); // 实例化时自动执行 Schema 校验
33
33
  SDK 集成了完整的 JSON Schema (Draft-07),可验证字段类型、必填项、枚举值等。
34
34
 
35
35
  ```typescript
36
- // 静态方法校验
37
- const result = CICSDK.validateConfig(myConfig)
38
- if (!result.valid) {
39
- console.error('配置校验失败:', result.error)
40
- // 输出示例: "/meta/layout/type must be string; /version must have required property 'version'"
36
+ // 静态方法校验(返回中文化错误数组)
37
+ const res = CICSDK.validateCIC(myConfig)
38
+ if (!res.ok) {
39
+ console.error('配置校验失败:', res.errors)
40
+ // 示例: [{ path: '/version', message: '缺少必填字段:version' }]
41
41
  }
42
42
 
43
43
  // 实例化时自动校验,失败抛出异常
@@ -48,6 +48,31 @@ try {
48
48
  }
49
49
  ```
50
50
 
51
+ **2. 导入/导出配置**
52
+
53
+ ```typescript
54
+ // 从 JSON 字符串导入为 CICConfig 对象
55
+ const rImport = CICSDK.importCIC(JSON.stringify(myConfig))
56
+ if (rImport.ok) {
57
+ const cfg = rImport.value
58
+ }
59
+
60
+ // 从路径或 URL 导入(异步,兼容浏览器)
61
+ // - 支持相对路径(同源):'./examples/full-demo.json'、'/examples/full-demo.json'
62
+ // - 支持 http(s) URL:'https://host/examples/full-demo.json'
63
+ // - 不支持 file://(请使用同源路径或 http(s))
64
+ const rImportPath = await CICSDK.importCICAsync('/examples/full-demo.json')
65
+ if (rImportPath.ok) {
66
+ const cfg2 = rImportPath.value
67
+ }
68
+
69
+ // 将 CICConfig 导出为稳定字段顺序的 JSON 字符串
70
+ const rExport = CICSDK.exportCIC(myConfig)
71
+ if (rExport.ok) {
72
+ console.log(rExport.value) // string
73
+ }
74
+ ```
75
+
51
76
  **2. 查找组件**
52
77
 
53
78
  ```typescript
@@ -123,24 +148,6 @@ CICSDK.traverseTree(someComponent, c => {
123
148
 
124
149
  `schema/cic.schema.json` 提供了完整的协议约束。
125
150
 
126
- ### VS Code 智能提示
127
-
128
- 在你的 JSON 配置文件头部添加 `$schema` 字段:
129
-
130
- ```json
131
- {
132
- "$schema": "./schema/cic.schema.json",
133
- "version": "1.0.0",
134
- "meta": { ... }
135
- }
136
- ```
137
-
138
- 这将启用:
139
-
140
- - 字段自动补全
141
- - 枚举值提示(如 `type`: `view` | `container`)
142
- - 结构校验(必填字段检查)
143
-
144
151
  ### 报错与排查
145
152
 
146
153
  - Ajv 错误输出包含 `instancePath`:根据路径定位到具体字段(如 `/pages/0/components/1/role must be equal to constant`)。
@@ -157,5 +164,3 @@ CICSDK.traverseTree(someComponent, c => {
157
164
 
158
165
  - 语义化版本(SemVer)发布
159
166
  - 请在 issue 中反馈使用问题与建议
160
-
161
- (本 README 为发布版自述,专注使用信息;开发演示与内部脚本说明已省略。)