@zhama/a2ui-core 0.4.0 → 0.6.0

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.
@@ -1,10 +1,10 @@
1
- import { ServerToClientMessageV09, ServerToClientMessageV08, ServerToClientMessage } from '../types/index.cjs';
2
- import '../primitives-nmkVz-tB.cjs';
1
+ import { ServerToClientMessageV09 } from '../types/index.cjs';
2
+ import '../primitives-DLbBDhLq.cjs';
3
3
 
4
4
  /**
5
- * Message Validator
5
+ * Message Validator - v0.9
6
6
  *
7
- * 提供 A2UI 消息验证功能
7
+ * 提供 A2UI v0.9 消息验证功能
8
8
  */
9
9
 
10
10
  /**
@@ -54,16 +54,12 @@ interface ValidationOptions {
54
54
  */
55
55
  declare function validateV09Message(message: ServerToClientMessageV09, options?: ValidationOptions): ValidationResult;
56
56
  /**
57
- * 验证 v0.8 消息
57
+ * 验证消息(v0.9)
58
58
  */
59
- declare function validateV08Message(message: ServerToClientMessageV08, options?: ValidationOptions): ValidationResult;
60
- /**
61
- * 验证消息(自动检测版本)
62
- */
63
- declare function validateMessage(message: ServerToClientMessage, options?: ValidationOptions): ValidationResult;
59
+ declare function validateMessage(message: ServerToClientMessageV09, options?: ValidationOptions): ValidationResult;
64
60
  /**
65
61
  * 验证消息数组
66
62
  */
67
- declare function validateMessages(messages: ServerToClientMessage[], options?: ValidationOptions): ValidationResult;
63
+ declare function validateMessages(messages: ServerToClientMessageV09[], options?: ValidationOptions): ValidationResult;
68
64
 
69
- export { type ValidationError, type ValidationOptions, type ValidationResult, type ValidationWarning, validateMessage, validateMessages, validateV08Message, validateV09Message };
65
+ export { type ValidationError, type ValidationOptions, type ValidationResult, type ValidationWarning, validateMessage, validateMessages, validateV09Message };
@@ -1,10 +1,10 @@
1
- import { ServerToClientMessageV09, ServerToClientMessageV08, ServerToClientMessage } from '../types/index.js';
2
- import '../primitives-nmkVz-tB.js';
1
+ import { ServerToClientMessageV09 } from '../types/index.js';
2
+ import '../primitives-DLbBDhLq.js';
3
3
 
4
4
  /**
5
- * Message Validator
5
+ * Message Validator - v0.9
6
6
  *
7
- * 提供 A2UI 消息验证功能
7
+ * 提供 A2UI v0.9 消息验证功能
8
8
  */
9
9
 
10
10
  /**
@@ -54,16 +54,12 @@ interface ValidationOptions {
54
54
  */
55
55
  declare function validateV09Message(message: ServerToClientMessageV09, options?: ValidationOptions): ValidationResult;
56
56
  /**
57
- * 验证 v0.8 消息
57
+ * 验证消息(v0.9)
58
58
  */
59
- declare function validateV08Message(message: ServerToClientMessageV08, options?: ValidationOptions): ValidationResult;
60
- /**
61
- * 验证消息(自动检测版本)
62
- */
63
- declare function validateMessage(message: ServerToClientMessage, options?: ValidationOptions): ValidationResult;
59
+ declare function validateMessage(message: ServerToClientMessageV09, options?: ValidationOptions): ValidationResult;
64
60
  /**
65
61
  * 验证消息数组
66
62
  */
67
- declare function validateMessages(messages: ServerToClientMessage[], options?: ValidationOptions): ValidationResult;
63
+ declare function validateMessages(messages: ServerToClientMessageV09[], options?: ValidationOptions): ValidationResult;
68
64
 
69
- export { type ValidationError, type ValidationOptions, type ValidationResult, type ValidationWarning, validateMessage, validateMessages, validateV08Message, validateV09Message };
65
+ export { type ValidationError, type ValidationOptions, type ValidationResult, type ValidationWarning, validateMessage, validateMessages, validateV09Message };
@@ -1 +1 @@
1
- var l=["Text","Image","Icon","Video","AudioPlayer","Row","Column","List","Card","Tabs","Divider","Modal","Button","CheckBox","TextField","DateTimeInput","ChoicePicker","Slider"];function c(e,o={}){let a=[],s=[];if("createSurface"in e){let{createSurface:t}=e;t.surfaceId||a.push({code:"MISSING_SURFACE_ID",message:"createSurface.surfaceId is required",path:"createSurface.surfaceId"}),t.catalogId||a.push({code:"MISSING_CATALOG_ID",message:"createSurface.catalogId is required",path:"createSurface.catalogId"});}else if("updateComponents"in e){let{updateComponents:t}=e;t.surfaceId||a.push({code:"MISSING_SURFACE_ID",message:"updateComponents.surfaceId is required",path:"updateComponents.surfaceId"}),!t.components||!Array.isArray(t.components)?a.push({code:"INVALID_COMPONENTS",message:"updateComponents.components must be an array",path:"updateComponents.components"}):I(t.components,a,s,o);}else if("updateDataModel"in e){let{updateDataModel:t}=e;t.surfaceId||a.push({code:"MISSING_SURFACE_ID",message:"updateDataModel.surfaceId is required",path:"updateDataModel.surfaceId"});}else if("deleteSurface"in e){let{deleteSurface:t}=e;t.surfaceId||a.push({code:"MISSING_SURFACE_ID",message:"deleteSurface.surfaceId is required",path:"deleteSurface.surfaceId"});}else a.push({code:"INVALID_MESSAGE_TYPE",message:"Message must contain one of: createSurface, updateComponents, updateDataModel, deleteSurface"});return {valid:a.length===0,errors:a,warnings:s}}function p(e,o={}){let a=[],s=[];if("beginRendering"in e){let{beginRendering:t}=e;t.surfaceId||a.push({code:"MISSING_SURFACE_ID",message:"beginRendering.surfaceId is required",path:"beginRendering.surfaceId"}),t.root||a.push({code:"MISSING_ROOT",message:"beginRendering.root is required",path:"beginRendering.root"});}else if("surfaceUpdate"in e){let{surfaceUpdate:t}=e;t.surfaceId||a.push({code:"MISSING_SURFACE_ID",message:"surfaceUpdate.surfaceId is required",path:"surfaceUpdate.surfaceId"}),!t.components||!Array.isArray(t.components)?a.push({code:"INVALID_COMPONENTS",message:"surfaceUpdate.components must be an array",path:"surfaceUpdate.components"}):S(t.components,a,s,o);}else if("dataModelUpdate"in e){let{dataModelUpdate:t}=e;t.surfaceId||a.push({code:"MISSING_SURFACE_ID",message:"dataModelUpdate.surfaceId is required",path:"dataModelUpdate.surfaceId"}),(!t.contents||!Array.isArray(t.contents))&&a.push({code:"INVALID_CONTENTS",message:"dataModelUpdate.contents must be an array",path:"dataModelUpdate.contents"});}else if("deleteSurface"in e){let{deleteSurface:t}=e;t.surfaceId||a.push({code:"MISSING_SURFACE_ID",message:"deleteSurface.surfaceId is required",path:"deleteSurface.surfaceId"});}else a.push({code:"INVALID_MESSAGE_TYPE",message:"Message must contain one of: beginRendering, surfaceUpdate, dataModelUpdate, deleteSurface"});return {valid:a.length===0,errors:a,warnings:s}}function u(e,o={}){return "createSurface"in e||"updateComponents"in e||"updateDataModel"in e?c(e,o):"beginRendering"in e||"surfaceUpdate"in e||"dataModelUpdate"in e?p(e,o):"deleteSurface"in e?e.deleteSurface.surfaceId?{valid:true,errors:[],warnings:[]}:{valid:false,errors:[{code:"MISSING_SURFACE_ID",message:"deleteSurface.surfaceId is required",path:"deleteSurface.surfaceId"}],warnings:[]}:{valid:false,errors:[{code:"UNKNOWN_MESSAGE_TYPE",message:"Unknown message type"}],warnings:[]}}function f(e,o={}){let a=[],s=[];for(let t=0;t<e.length;t++){let r=e[t];if(!r)continue;let i=u(r,o);for(let n of i.errors)a.push({...n,path:`messages[${t}].${n.path??""}`});for(let n of i.warnings)s.push({...n,path:`messages[${t}].${n.path??""}`});}return {valid:a.length===0,errors:a,warnings:s}}function I(e,o,a,s){let t=new Set,r=false;for(let i=0;i<e.length;i++){let n=e[i];if(!n)continue;let d=`updateComponents.components[${i}]`;n.id?(t.has(n.id)&&o.push({code:"DUPLICATE_COMPONENT_ID",message:`Duplicate component id: ${n.id}`,path:`${d}.id`}),t.add(n.id),n.id==="root"&&(r=true)):o.push({code:"MISSING_COMPONENT_ID",message:"Component id is required",path:`${d}.id`}),n.component?s.strict&&s.allowedComponents&&(s.allowedComponents.includes(n.component)||a.push({code:"UNKNOWN_COMPONENT_TYPE",message:`Unknown component type: ${n.component}`,path:`${d}.component`})):o.push({code:"MISSING_COMPONENT_TYPE",message:"Component type is required",path:`${d}.component`});}!r&&s.strict&&a.push({code:"MISSING_ROOT_COMPONENT",message:'No component with id "root" found',path:"updateComponents.components"});}function S(e,o,a,s){let t=new Set;for(let r=0;r<e.length;r++){let i=e[r];if(!i)continue;let n=`surfaceUpdate.components[${r}]`;if(i.id?(t.has(i.id)&&o.push({code:"DUPLICATE_COMPONENT_ID",message:`Duplicate component id: ${i.id}`,path:`${n}.id`}),t.add(i.id)):o.push({code:"MISSING_COMPONENT_ID",message:"Component id is required",path:`${n}.id`}),!i.component||typeof i.component!="object")o.push({code:"MISSING_COMPONENT",message:"Component definition is required",path:`${n}.component`});else {let d=Object.keys(i.component)[0];d&&s.strict&&!l.includes(d)&&a.push({code:"UNKNOWN_COMPONENT_TYPE",message:`Unknown component type: ${d}`,path:`${n}.component`});}}}export{u as validateMessage,f as validateMessages,p as validateV08Message,c as validateV09Message};
1
+ var u=["Text","Image","Icon","Video","AudioPlayer","Row","Column","List","Card","Tabs","Divider","Modal","Button","CheckBox","TextField","DateTimeInput","ChoicePicker","Slider"];function p(t,i={}){let a=[],n=[];if("createSurface"in t){let{createSurface:e}=t;e.surfaceId||a.push({code:"MISSING_SURFACE_ID",message:"createSurface.surfaceId is required",path:"createSurface.surfaceId"}),e.catalogId||a.push({code:"MISSING_CATALOG_ID",message:"createSurface.catalogId is required",path:"createSurface.catalogId"});}else if("updateComponents"in t){let{updateComponents:e}=t;e.surfaceId||a.push({code:"MISSING_SURFACE_ID",message:"updateComponents.surfaceId is required",path:"updateComponents.surfaceId"}),!e.components||!Array.isArray(e.components)?a.push({code:"INVALID_COMPONENTS",message:"updateComponents.components must be an array",path:"updateComponents.components"}):f(e.components,a,n,i);}else if("updateDataModel"in t){let{updateDataModel:e}=t;e.surfaceId||a.push({code:"MISSING_SURFACE_ID",message:"updateDataModel.surfaceId is required",path:"updateDataModel.surfaceId"}),e.op&&!["add","replace","remove"].includes(e.op)&&a.push({code:"INVALID_OP",message:"updateDataModel.op must be one of: add, replace, remove",path:"updateDataModel.op"}),e.op==="remove"&&e.value!==void 0&&n.push({code:"UNNECESSARY_VALUE",message:"updateDataModel.value should not be provided for remove operation",path:"updateDataModel.value"}),e.op!=="remove"&&e.value===void 0&&e.op==="add"&&a.push({code:"MISSING_VALUE",message:"updateDataModel.value is required for add operation",path:"updateDataModel.value"});}else if("deleteSurface"in t){let{deleteSurface:e}=t;e.surfaceId||a.push({code:"MISSING_SURFACE_ID",message:"deleteSurface.surfaceId is required",path:"deleteSurface.surfaceId"});}else a.push({code:"INVALID_MESSAGE_TYPE",message:"Message must contain one of: createSurface, updateComponents, updateDataModel, deleteSurface"});return {valid:a.length===0,errors:a,warnings:n}}function c(t,i={}){return p(t,i)}function l(t,i={}){let a=[],n=[];for(let e=0;e<t.length;e++){let r=t[e];if(!r)continue;let s=c(r,i);for(let o of s.errors)a.push({...o,path:`messages[${e}].${o.path??""}`});for(let o of s.warnings)n.push({...o,path:`messages[${e}].${o.path??""}`});}return {valid:a.length===0,errors:a,warnings:n}}function f(t,i,a,n){let e=new Set,r=false;for(let s=0;s<t.length;s++){let o=t[s];if(!o)continue;let d=`updateComponents.components[${s}]`;o.id?(e.has(o.id)&&i.push({code:"DUPLICATE_COMPONENT_ID",message:`Duplicate component id: ${o.id}`,path:`${d}.id`}),e.add(o.id),o.id==="root"&&(r=true)):i.push({code:"MISSING_COMPONENT_ID",message:"Component id is required",path:`${d}.id`}),o.component?n.strict&&!u.includes(o.component)&&n.allowedComponents&&!n.allowedComponents.includes(o.component)&&a.push({code:"UNKNOWN_COMPONENT_TYPE",message:`Unknown component type: ${o.component}`,path:`${d}.component`}):i.push({code:"MISSING_COMPONENT_TYPE",message:"Component type is required",path:`${d}.component`});}!r&&n.strict&&a.push({code:"MISSING_ROOT_COMPONENT",message:'No component with id "root" found',path:"updateComponents.components"});}export{c as validateMessage,l as validateMessages,p as validateV09Message};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zhama/a2ui-core",
3
- "version": "0.4.0",
3
+ "version": "0.6.0",
4
4
  "description": "A2UI Protocol Core Library - Framework-agnostic TypeScript types and builders for A2UI protocol",
5
5
  "type": "module",
6
6
  "main": "dist/index.cjs",