@zhama/a2ui-core 0.1.0 → 0.3.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,313 +1 @@
1
- 'use strict';
2
-
3
- // src/validators/message-validator.ts
4
- var STANDARD_COMPONENT_TYPES = [
5
- "Text",
6
- "Image",
7
- "Icon",
8
- "Video",
9
- "AudioPlayer",
10
- "Row",
11
- "Column",
12
- "List",
13
- "Card",
14
- "Tabs",
15
- "Divider",
16
- "Modal",
17
- "Button",
18
- "CheckBox",
19
- "TextField",
20
- "DateTimeInput",
21
- "ChoicePicker",
22
- "Slider"
23
- ];
24
- function validateV09Message(message, options = {}) {
25
- const errors = [];
26
- const warnings = [];
27
- if ("createSurface" in message) {
28
- const { createSurface } = message;
29
- if (!createSurface.surfaceId) {
30
- errors.push({
31
- code: "MISSING_SURFACE_ID",
32
- message: "createSurface.surfaceId is required",
33
- path: "createSurface.surfaceId"
34
- });
35
- }
36
- if (!createSurface.catalogId) {
37
- errors.push({
38
- code: "MISSING_CATALOG_ID",
39
- message: "createSurface.catalogId is required",
40
- path: "createSurface.catalogId"
41
- });
42
- }
43
- } else if ("updateComponents" in message) {
44
- const { updateComponents } = message;
45
- if (!updateComponents.surfaceId) {
46
- errors.push({
47
- code: "MISSING_SURFACE_ID",
48
- message: "updateComponents.surfaceId is required",
49
- path: "updateComponents.surfaceId"
50
- });
51
- }
52
- if (!updateComponents.components || !Array.isArray(updateComponents.components)) {
53
- errors.push({
54
- code: "INVALID_COMPONENTS",
55
- message: "updateComponents.components must be an array",
56
- path: "updateComponents.components"
57
- });
58
- } else {
59
- validateComponentsV09(updateComponents.components, errors, warnings, options);
60
- }
61
- } else if ("updateDataModel" in message) {
62
- const { updateDataModel } = message;
63
- if (!updateDataModel.surfaceId) {
64
- errors.push({
65
- code: "MISSING_SURFACE_ID",
66
- message: "updateDataModel.surfaceId is required",
67
- path: "updateDataModel.surfaceId"
68
- });
69
- }
70
- } else if ("deleteSurface" in message) {
71
- const { deleteSurface } = message;
72
- if (!deleteSurface.surfaceId) {
73
- errors.push({
74
- code: "MISSING_SURFACE_ID",
75
- message: "deleteSurface.surfaceId is required",
76
- path: "deleteSurface.surfaceId"
77
- });
78
- }
79
- } else {
80
- errors.push({
81
- code: "INVALID_MESSAGE_TYPE",
82
- message: "Message must contain one of: createSurface, updateComponents, updateDataModel, deleteSurface"
83
- });
84
- }
85
- return {
86
- valid: errors.length === 0,
87
- errors,
88
- warnings
89
- };
90
- }
91
- function validateV08Message(message, options = {}) {
92
- const errors = [];
93
- const warnings = [];
94
- if ("beginRendering" in message) {
95
- const { beginRendering } = message;
96
- if (!beginRendering.surfaceId) {
97
- errors.push({
98
- code: "MISSING_SURFACE_ID",
99
- message: "beginRendering.surfaceId is required",
100
- path: "beginRendering.surfaceId"
101
- });
102
- }
103
- if (!beginRendering.root) {
104
- errors.push({
105
- code: "MISSING_ROOT",
106
- message: "beginRendering.root is required",
107
- path: "beginRendering.root"
108
- });
109
- }
110
- } else if ("surfaceUpdate" in message) {
111
- const { surfaceUpdate } = message;
112
- if (!surfaceUpdate.surfaceId) {
113
- errors.push({
114
- code: "MISSING_SURFACE_ID",
115
- message: "surfaceUpdate.surfaceId is required",
116
- path: "surfaceUpdate.surfaceId"
117
- });
118
- }
119
- if (!surfaceUpdate.components || !Array.isArray(surfaceUpdate.components)) {
120
- errors.push({
121
- code: "INVALID_COMPONENTS",
122
- message: "surfaceUpdate.components must be an array",
123
- path: "surfaceUpdate.components"
124
- });
125
- } else {
126
- validateComponentsV08(surfaceUpdate.components, errors, warnings, options);
127
- }
128
- } else if ("dataModelUpdate" in message) {
129
- const { dataModelUpdate } = message;
130
- if (!dataModelUpdate.surfaceId) {
131
- errors.push({
132
- code: "MISSING_SURFACE_ID",
133
- message: "dataModelUpdate.surfaceId is required",
134
- path: "dataModelUpdate.surfaceId"
135
- });
136
- }
137
- if (!dataModelUpdate.contents || !Array.isArray(dataModelUpdate.contents)) {
138
- errors.push({
139
- code: "INVALID_CONTENTS",
140
- message: "dataModelUpdate.contents must be an array",
141
- path: "dataModelUpdate.contents"
142
- });
143
- }
144
- } else if ("deleteSurface" in message) {
145
- const { deleteSurface } = message;
146
- if (!deleteSurface.surfaceId) {
147
- errors.push({
148
- code: "MISSING_SURFACE_ID",
149
- message: "deleteSurface.surfaceId is required",
150
- path: "deleteSurface.surfaceId"
151
- });
152
- }
153
- } else {
154
- errors.push({
155
- code: "INVALID_MESSAGE_TYPE",
156
- message: "Message must contain one of: beginRendering, surfaceUpdate, dataModelUpdate, deleteSurface"
157
- });
158
- }
159
- return {
160
- valid: errors.length === 0,
161
- errors,
162
- warnings
163
- };
164
- }
165
- function validateMessage(message, options = {}) {
166
- if ("createSurface" in message || "updateComponents" in message || "updateDataModel" in message) {
167
- return validateV09Message(message, options);
168
- }
169
- if ("beginRendering" in message || "surfaceUpdate" in message || "dataModelUpdate" in message) {
170
- return validateV08Message(message, options);
171
- }
172
- if ("deleteSurface" in message) {
173
- if (!message.deleteSurface.surfaceId) {
174
- return {
175
- valid: false,
176
- errors: [{
177
- code: "MISSING_SURFACE_ID",
178
- message: "deleteSurface.surfaceId is required",
179
- path: "deleteSurface.surfaceId"
180
- }],
181
- warnings: []
182
- };
183
- }
184
- return { valid: true, errors: [], warnings: [] };
185
- }
186
- return {
187
- valid: false,
188
- errors: [{
189
- code: "UNKNOWN_MESSAGE_TYPE",
190
- message: "Unknown message type"
191
- }],
192
- warnings: []
193
- };
194
- }
195
- function validateMessages(messages, options = {}) {
196
- const errors = [];
197
- const warnings = [];
198
- for (let i = 0; i < messages.length; i++) {
199
- const result = validateMessage(messages[i], options);
200
- for (const error of result.errors) {
201
- errors.push({
202
- ...error,
203
- path: `messages[${i}].${error.path || ""}`
204
- });
205
- }
206
- for (const warning of result.warnings) {
207
- warnings.push({
208
- ...warning,
209
- path: `messages[${i}].${warning.path || ""}`
210
- });
211
- }
212
- }
213
- return {
214
- valid: errors.length === 0,
215
- errors,
216
- warnings
217
- };
218
- }
219
- function validateComponentsV09(components, errors, warnings, options) {
220
- const componentIds = /* @__PURE__ */ new Set();
221
- let hasRoot = false;
222
- for (let i = 0; i < components.length; i++) {
223
- const comp = components[i];
224
- const path = `updateComponents.components[${i}]`;
225
- if (!comp.id) {
226
- errors.push({
227
- code: "MISSING_COMPONENT_ID",
228
- message: "Component id is required",
229
- path: `${path}.id`
230
- });
231
- } else {
232
- if (componentIds.has(comp.id)) {
233
- errors.push({
234
- code: "DUPLICATE_COMPONENT_ID",
235
- message: `Duplicate component id: ${comp.id}`,
236
- path: `${path}.id`
237
- });
238
- }
239
- componentIds.add(comp.id);
240
- if (comp.id === "root") {
241
- hasRoot = true;
242
- }
243
- }
244
- if (!comp.component) {
245
- errors.push({
246
- code: "MISSING_COMPONENT_TYPE",
247
- message: "Component type is required",
248
- path: `${path}.component`
249
- });
250
- } else if (options.strict && options.allowedComponents) {
251
- if (!options.allowedComponents.includes(comp.component)) {
252
- warnings.push({
253
- code: "UNKNOWN_COMPONENT_TYPE",
254
- message: `Unknown component type: ${comp.component}`,
255
- path: `${path}.component`
256
- });
257
- }
258
- }
259
- }
260
- if (!hasRoot && options.strict) {
261
- warnings.push({
262
- code: "MISSING_ROOT_COMPONENT",
263
- message: 'No component with id "root" found',
264
- path: "updateComponents.components"
265
- });
266
- }
267
- }
268
- function validateComponentsV08(components, errors, warnings, options) {
269
- const componentIds = /* @__PURE__ */ new Set();
270
- for (let i = 0; i < components.length; i++) {
271
- const comp = components[i];
272
- const path = `surfaceUpdate.components[${i}]`;
273
- if (!comp.id) {
274
- errors.push({
275
- code: "MISSING_COMPONENT_ID",
276
- message: "Component id is required",
277
- path: `${path}.id`
278
- });
279
- } else {
280
- if (componentIds.has(comp.id)) {
281
- errors.push({
282
- code: "DUPLICATE_COMPONENT_ID",
283
- message: `Duplicate component id: ${comp.id}`,
284
- path: `${path}.id`
285
- });
286
- }
287
- componentIds.add(comp.id);
288
- }
289
- if (!comp.component || typeof comp.component !== "object") {
290
- errors.push({
291
- code: "MISSING_COMPONENT",
292
- message: "Component definition is required",
293
- path: `${path}.component`
294
- });
295
- } else {
296
- const componentType = Object.keys(comp.component)[0];
297
- if (options.strict && !STANDARD_COMPONENT_TYPES.includes(componentType)) {
298
- warnings.push({
299
- code: "UNKNOWN_COMPONENT_TYPE",
300
- message: `Unknown component type: ${componentType}`,
301
- path: `${path}.component`
302
- });
303
- }
304
- }
305
- }
306
- }
307
-
308
- exports.validateMessage = validateMessage;
309
- exports.validateMessages = validateMessages;
310
- exports.validateV08Message = validateV08Message;
311
- exports.validateV09Message = validateV09Message;
312
- //# sourceMappingURL=index.cjs.map
313
- //# sourceMappingURL=index.cjs.map
1
+ 'use strict';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`});}}}exports.validateMessage=u;exports.validateMessages=f;exports.validateV08Message=p;exports.validateV09Message=c;
@@ -1,4 +1,5 @@
1
1
  import { ServerToClientMessageV09, ServerToClientMessageV08, ServerToClientMessage } from '../types/index.cjs';
2
+ import '../primitives-nmkVz-tB.cjs';
2
3
 
3
4
  /**
4
5
  * Message Validator
@@ -1,4 +1,5 @@
1
1
  import { ServerToClientMessageV09, ServerToClientMessageV08, ServerToClientMessage } from '../types/index.js';
2
+ import '../primitives-nmkVz-tB.js';
2
3
 
3
4
  /**
4
5
  * Message Validator
@@ -1,308 +1 @@
1
- // src/validators/message-validator.ts
2
- var STANDARD_COMPONENT_TYPES = [
3
- "Text",
4
- "Image",
5
- "Icon",
6
- "Video",
7
- "AudioPlayer",
8
- "Row",
9
- "Column",
10
- "List",
11
- "Card",
12
- "Tabs",
13
- "Divider",
14
- "Modal",
15
- "Button",
16
- "CheckBox",
17
- "TextField",
18
- "DateTimeInput",
19
- "ChoicePicker",
20
- "Slider"
21
- ];
22
- function validateV09Message(message, options = {}) {
23
- const errors = [];
24
- const warnings = [];
25
- if ("createSurface" in message) {
26
- const { createSurface } = message;
27
- if (!createSurface.surfaceId) {
28
- errors.push({
29
- code: "MISSING_SURFACE_ID",
30
- message: "createSurface.surfaceId is required",
31
- path: "createSurface.surfaceId"
32
- });
33
- }
34
- if (!createSurface.catalogId) {
35
- errors.push({
36
- code: "MISSING_CATALOG_ID",
37
- message: "createSurface.catalogId is required",
38
- path: "createSurface.catalogId"
39
- });
40
- }
41
- } else if ("updateComponents" in message) {
42
- const { updateComponents } = message;
43
- if (!updateComponents.surfaceId) {
44
- errors.push({
45
- code: "MISSING_SURFACE_ID",
46
- message: "updateComponents.surfaceId is required",
47
- path: "updateComponents.surfaceId"
48
- });
49
- }
50
- if (!updateComponents.components || !Array.isArray(updateComponents.components)) {
51
- errors.push({
52
- code: "INVALID_COMPONENTS",
53
- message: "updateComponents.components must be an array",
54
- path: "updateComponents.components"
55
- });
56
- } else {
57
- validateComponentsV09(updateComponents.components, errors, warnings, options);
58
- }
59
- } else if ("updateDataModel" in message) {
60
- const { updateDataModel } = message;
61
- if (!updateDataModel.surfaceId) {
62
- errors.push({
63
- code: "MISSING_SURFACE_ID",
64
- message: "updateDataModel.surfaceId is required",
65
- path: "updateDataModel.surfaceId"
66
- });
67
- }
68
- } else if ("deleteSurface" in message) {
69
- const { deleteSurface } = message;
70
- if (!deleteSurface.surfaceId) {
71
- errors.push({
72
- code: "MISSING_SURFACE_ID",
73
- message: "deleteSurface.surfaceId is required",
74
- path: "deleteSurface.surfaceId"
75
- });
76
- }
77
- } else {
78
- errors.push({
79
- code: "INVALID_MESSAGE_TYPE",
80
- message: "Message must contain one of: createSurface, updateComponents, updateDataModel, deleteSurface"
81
- });
82
- }
83
- return {
84
- valid: errors.length === 0,
85
- errors,
86
- warnings
87
- };
88
- }
89
- function validateV08Message(message, options = {}) {
90
- const errors = [];
91
- const warnings = [];
92
- if ("beginRendering" in message) {
93
- const { beginRendering } = message;
94
- if (!beginRendering.surfaceId) {
95
- errors.push({
96
- code: "MISSING_SURFACE_ID",
97
- message: "beginRendering.surfaceId is required",
98
- path: "beginRendering.surfaceId"
99
- });
100
- }
101
- if (!beginRendering.root) {
102
- errors.push({
103
- code: "MISSING_ROOT",
104
- message: "beginRendering.root is required",
105
- path: "beginRendering.root"
106
- });
107
- }
108
- } else if ("surfaceUpdate" in message) {
109
- const { surfaceUpdate } = message;
110
- if (!surfaceUpdate.surfaceId) {
111
- errors.push({
112
- code: "MISSING_SURFACE_ID",
113
- message: "surfaceUpdate.surfaceId is required",
114
- path: "surfaceUpdate.surfaceId"
115
- });
116
- }
117
- if (!surfaceUpdate.components || !Array.isArray(surfaceUpdate.components)) {
118
- errors.push({
119
- code: "INVALID_COMPONENTS",
120
- message: "surfaceUpdate.components must be an array",
121
- path: "surfaceUpdate.components"
122
- });
123
- } else {
124
- validateComponentsV08(surfaceUpdate.components, errors, warnings, options);
125
- }
126
- } else if ("dataModelUpdate" in message) {
127
- const { dataModelUpdate } = message;
128
- if (!dataModelUpdate.surfaceId) {
129
- errors.push({
130
- code: "MISSING_SURFACE_ID",
131
- message: "dataModelUpdate.surfaceId is required",
132
- path: "dataModelUpdate.surfaceId"
133
- });
134
- }
135
- if (!dataModelUpdate.contents || !Array.isArray(dataModelUpdate.contents)) {
136
- errors.push({
137
- code: "INVALID_CONTENTS",
138
- message: "dataModelUpdate.contents must be an array",
139
- path: "dataModelUpdate.contents"
140
- });
141
- }
142
- } else if ("deleteSurface" in message) {
143
- const { deleteSurface } = message;
144
- if (!deleteSurface.surfaceId) {
145
- errors.push({
146
- code: "MISSING_SURFACE_ID",
147
- message: "deleteSurface.surfaceId is required",
148
- path: "deleteSurface.surfaceId"
149
- });
150
- }
151
- } else {
152
- errors.push({
153
- code: "INVALID_MESSAGE_TYPE",
154
- message: "Message must contain one of: beginRendering, surfaceUpdate, dataModelUpdate, deleteSurface"
155
- });
156
- }
157
- return {
158
- valid: errors.length === 0,
159
- errors,
160
- warnings
161
- };
162
- }
163
- function validateMessage(message, options = {}) {
164
- if ("createSurface" in message || "updateComponents" in message || "updateDataModel" in message) {
165
- return validateV09Message(message, options);
166
- }
167
- if ("beginRendering" in message || "surfaceUpdate" in message || "dataModelUpdate" in message) {
168
- return validateV08Message(message, options);
169
- }
170
- if ("deleteSurface" in message) {
171
- if (!message.deleteSurface.surfaceId) {
172
- return {
173
- valid: false,
174
- errors: [{
175
- code: "MISSING_SURFACE_ID",
176
- message: "deleteSurface.surfaceId is required",
177
- path: "deleteSurface.surfaceId"
178
- }],
179
- warnings: []
180
- };
181
- }
182
- return { valid: true, errors: [], warnings: [] };
183
- }
184
- return {
185
- valid: false,
186
- errors: [{
187
- code: "UNKNOWN_MESSAGE_TYPE",
188
- message: "Unknown message type"
189
- }],
190
- warnings: []
191
- };
192
- }
193
- function validateMessages(messages, options = {}) {
194
- const errors = [];
195
- const warnings = [];
196
- for (let i = 0; i < messages.length; i++) {
197
- const result = validateMessage(messages[i], options);
198
- for (const error of result.errors) {
199
- errors.push({
200
- ...error,
201
- path: `messages[${i}].${error.path || ""}`
202
- });
203
- }
204
- for (const warning of result.warnings) {
205
- warnings.push({
206
- ...warning,
207
- path: `messages[${i}].${warning.path || ""}`
208
- });
209
- }
210
- }
211
- return {
212
- valid: errors.length === 0,
213
- errors,
214
- warnings
215
- };
216
- }
217
- function validateComponentsV09(components, errors, warnings, options) {
218
- const componentIds = /* @__PURE__ */ new Set();
219
- let hasRoot = false;
220
- for (let i = 0; i < components.length; i++) {
221
- const comp = components[i];
222
- const path = `updateComponents.components[${i}]`;
223
- if (!comp.id) {
224
- errors.push({
225
- code: "MISSING_COMPONENT_ID",
226
- message: "Component id is required",
227
- path: `${path}.id`
228
- });
229
- } else {
230
- if (componentIds.has(comp.id)) {
231
- errors.push({
232
- code: "DUPLICATE_COMPONENT_ID",
233
- message: `Duplicate component id: ${comp.id}`,
234
- path: `${path}.id`
235
- });
236
- }
237
- componentIds.add(comp.id);
238
- if (comp.id === "root") {
239
- hasRoot = true;
240
- }
241
- }
242
- if (!comp.component) {
243
- errors.push({
244
- code: "MISSING_COMPONENT_TYPE",
245
- message: "Component type is required",
246
- path: `${path}.component`
247
- });
248
- } else if (options.strict && options.allowedComponents) {
249
- if (!options.allowedComponents.includes(comp.component)) {
250
- warnings.push({
251
- code: "UNKNOWN_COMPONENT_TYPE",
252
- message: `Unknown component type: ${comp.component}`,
253
- path: `${path}.component`
254
- });
255
- }
256
- }
257
- }
258
- if (!hasRoot && options.strict) {
259
- warnings.push({
260
- code: "MISSING_ROOT_COMPONENT",
261
- message: 'No component with id "root" found',
262
- path: "updateComponents.components"
263
- });
264
- }
265
- }
266
- function validateComponentsV08(components, errors, warnings, options) {
267
- const componentIds = /* @__PURE__ */ new Set();
268
- for (let i = 0; i < components.length; i++) {
269
- const comp = components[i];
270
- const path = `surfaceUpdate.components[${i}]`;
271
- if (!comp.id) {
272
- errors.push({
273
- code: "MISSING_COMPONENT_ID",
274
- message: "Component id is required",
275
- path: `${path}.id`
276
- });
277
- } else {
278
- if (componentIds.has(comp.id)) {
279
- errors.push({
280
- code: "DUPLICATE_COMPONENT_ID",
281
- message: `Duplicate component id: ${comp.id}`,
282
- path: `${path}.id`
283
- });
284
- }
285
- componentIds.add(comp.id);
286
- }
287
- if (!comp.component || typeof comp.component !== "object") {
288
- errors.push({
289
- code: "MISSING_COMPONENT",
290
- message: "Component definition is required",
291
- path: `${path}.component`
292
- });
293
- } else {
294
- const componentType = Object.keys(comp.component)[0];
295
- if (options.strict && !STANDARD_COMPONENT_TYPES.includes(componentType)) {
296
- warnings.push({
297
- code: "UNKNOWN_COMPONENT_TYPE",
298
- message: `Unknown component type: ${componentType}`,
299
- path: `${path}.component`
300
- });
301
- }
302
- }
303
- }
304
- }
305
-
306
- export { validateMessage, validateMessages, validateV08Message, validateV09Message };
307
- //# sourceMappingURL=index.js.map
308
- //# sourceMappingURL=index.js.map
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};