|
| 1 | +import { z } from "zod"; |
| 2 | + |
| 3 | +/** |
| 4 | + * Zod schema for ComponentDescriptorParam |
| 5 | + */ |
| 6 | +export const ComponentDescriptorParamSchema = z.object({ |
| 7 | + name: z.string(), |
| 8 | + type: z.string(), |
| 9 | +}); |
| 10 | + |
| 11 | +/** |
| 12 | + * Zod schema for ComponentDescriptorProperty |
| 13 | + */ |
| 14 | +export const ComponentDescriptorPropertySchema = z.object({ |
| 15 | + name: z.string(), |
| 16 | + editorType: z.string(), |
| 17 | + defaultValue: z.string(), |
| 18 | + /** |
| 19 | + * Kodular Creator specific extension - not present in MIT App Inventor. |
| 20 | + * Typically has values like "common", "advanced", etc. |
| 21 | + */ |
| 22 | + propertyType: z.string().optional(), |
| 23 | + editorArgs: z.array(z.any()), |
| 24 | +}); |
| 25 | + |
| 26 | +/** |
| 27 | + * Zod schema for ComponentDescriptorBlockProperty |
| 28 | + */ |
| 29 | +export const ComponentDescriptorBlockPropertySchema = z.object({ |
| 30 | + name: z.string(), |
| 31 | + description: z.string(), |
| 32 | + type: z.string(), |
| 33 | + rw: z.string(), |
| 34 | + deprecated: z.stringbool(), |
| 35 | +}); |
| 36 | + |
| 37 | +/** |
| 38 | + * Zod schema for ComponentDescriptorEvent |
| 39 | + */ |
| 40 | +export const ComponentDescriptorEventSchema = z.object({ |
| 41 | + name: z.string(), |
| 42 | + description: z.string(), |
| 43 | + deprecated: z.stringbool(), |
| 44 | + params: z.array(ComponentDescriptorParamSchema), |
| 45 | +}); |
| 46 | + |
| 47 | +/** |
| 48 | + * Zod schema for ComponentDescriptorMethod |
| 49 | + */ |
| 50 | +export const ComponentDescriptorMethodSchema = z.object({ |
| 51 | + name: z.string(), |
| 52 | + description: z.string(), |
| 53 | + deprecated: z.stringbool(), |
| 54 | + params: z.array(ComponentDescriptorParamSchema), |
| 55 | + returnType: z.string().optional(), |
| 56 | +}); |
| 57 | + |
| 58 | +/** |
| 59 | + * Zod schema for ComponentDescriptor |
| 60 | + */ |
| 61 | +export const ComponentDescriptorSchema = z.object({ |
| 62 | + type: z.string(), |
| 63 | + name: z.string(), |
| 64 | + external: z.stringbool(), |
| 65 | + version: z.string(), |
| 66 | + dateBuilt: z.string(), |
| 67 | + categoryString: z.string(), |
| 68 | + helpString: z.string(), |
| 69 | + helpUrl: z.string(), |
| 70 | + showOnPalette: z.stringbool(), |
| 71 | + nonVisible: z.stringbool(), |
| 72 | + iconName: z.string(), |
| 73 | + androidMinSdk: z.union([z.string(), z.number()]), |
| 74 | + properties: z.array(ComponentDescriptorPropertySchema), |
| 75 | + blockProperties: z.array(ComponentDescriptorBlockPropertySchema), |
| 76 | + events: z.array(ComponentDescriptorEventSchema), |
| 77 | + methods: z.array(ComponentDescriptorMethodSchema), |
| 78 | +}); |
| 79 | + |
| 80 | +export const ComponentDescriptorsSchema = z.array(ComponentDescriptorSchema); |
| 81 | + |
| 82 | +/** |
| 83 | + * Type inferred from the Zod schema for ComponentDescriptor |
| 84 | + */ |
| 85 | +export type ComponentDescriptor = z.infer<typeof ComponentDescriptorSchema>; |
| 86 | + |
| 87 | +/** |
| 88 | + * Type inferred from the Zod schema for ComponentDescriptors |
| 89 | + */ |
| 90 | +export type ComponentDescriptors = z.infer<typeof ComponentDescriptorsSchema>; |
0 commit comments