@ramme-io/shared 2.0.0 → 2.0.2

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/src/schema.ts DELETED
@@ -1,209 +0,0 @@
1
- import { z } from 'zod';
2
-
3
- /**
4
- * @file schema.ts
5
- * @description The "Application Constitution".
6
- *
7
- * ARCHITECTURAL ROLE:
8
- * This file uses Zod to define the strict runtime validation rules for the
9
- * App Manifest. While `manifest-types.ts` handles compile-time TypeScript checks,
10
- * this file handles runtime validation, ensuring that any JSON loaded into the
11
- * engine (whether from a file, API, or user input) is structurally sound.
12
- *
13
- * LAYERS DEFINED:
14
- * 1. **SaaS Layer:** Data resources, fields, and tables.
15
- * 2. **Physical Layer:** IoT signals, sensors, and entities.
16
- * 3. **Logic Layer:** Workflows, triggers, and automated actions.
17
- * 4. **Presentation Layer:** Pages, sections, and UI blocks.
18
- */
19
-
20
- // ------------------------------------------------------------------
21
- // 1. DATA RESOURCE DEFINITIONS (SaaS Layer)
22
- // ------------------------------------------------------------------
23
-
24
- export const FieldSchema = z.object({
25
- key: z.string(),
26
- label: z.string(),
27
- type: z.enum(['text', 'number', 'currency', 'date', 'boolean', 'status', 'email', 'image', 'textarea']),
28
- required: z.boolean().optional(),
29
- description: z.string().optional(),
30
- defaultValue: z.any().optional(),
31
- });
32
- export type FieldDefinition = z.infer<typeof FieldSchema>;
33
-
34
- export const ResourceSchema = z.object({
35
- id: z.string(),
36
- name: z.string(),
37
- fields: z.array(FieldSchema),
38
- defaultView: z.enum(['table', 'grid', 'list']).optional(),
39
- features: z.object({
40
- searchable: z.boolean().optional(),
41
- creatable: z.boolean().optional(),
42
- editable: z.boolean().optional(),
43
- deletable: z.boolean().optional(),
44
- exportable: z.boolean().optional(),
45
- }).optional(),
46
- });
47
- export type ResourceDefinition = z.infer<typeof ResourceSchema>;
48
-
49
-
50
- // ------------------------------------------------------------------
51
- // 2. SIGNAL & IOT DEFINITIONS (Physical Layer)
52
- // ------------------------------------------------------------------
53
-
54
- export const SignalSchema = z.object({
55
- id: z.string().min(1, "Signal ID is required"),
56
- label: z.string(),
57
- description: z.string().optional(),
58
- kind: z.enum(['sensor', 'actuator', 'setpoint', 'metric', 'status', 'kpi']),
59
- source: z.enum(['mock', 'mqtt', 'http', 'derived', 'local']),
60
-
61
- // Connectivity
62
- topic: z.string().optional(),
63
- endpoint: z.string().optional(),
64
- jsonPath: z.string().optional(),
65
- refreshRate: z.number().optional().default(1000),
66
-
67
- // Values
68
- defaultValue: z.any().optional(),
69
- unit: z.string().optional(),
70
- min: z.number().optional(),
71
- max: z.number().optional(),
72
- });
73
- export type SignalDefinition = z.infer<typeof SignalSchema>;
74
-
75
- export const EntitySchema = z.object({
76
- id: z.string(),
77
- name: z.string(),
78
- description: z.string().optional(),
79
- type: z.string(),
80
- category: z.string().default('logical'),
81
- signals: z.array(z.string()),
82
- ui: z.object({
83
- icon: z.string().optional(),
84
- color: z.string().optional(),
85
- dashboardComponent: z.string().optional(),
86
- }).optional(),
87
- });
88
- export type EntityDefinition = z.infer<typeof EntitySchema>;
89
-
90
- // ------------------------------------------------------------------
91
- // 3. LOGIC & WORKFLOW DEFINITIONS (Logic Layer)
92
- // ------------------------------------------------------------------
93
-
94
- export const TriggerSchema = z.object({
95
- id: z.string(),
96
- type: z.enum(['signal_change', 'manual_action', 'schedule', 'webhook']),
97
- config: z.record(z.string(), z.any()),
98
- });
99
-
100
- export const ActionSchema = z.object({
101
- id: z.string(),
102
- type: z.enum([
103
- 'update_resource',
104
- 'send_notification',
105
- 'mqtt_publish',
106
- 'api_call',
107
- 'navigate',
108
- 'agent_task'
109
- ]),
110
- config: z.record(z.string(), z.any()),
111
- });
112
-
113
- export const WorkflowSchema = z.object({
114
- id: z.string(),
115
- name: z.string(),
116
- active: z.boolean().default(true),
117
- trigger: TriggerSchema,
118
- actions: z.array(ActionSchema),
119
- });
120
- export type WorkflowDefinition = z.infer<typeof WorkflowSchema>;
121
- export type ActionDefinition = z.infer<typeof ActionSchema>;
122
-
123
-
124
- // ------------------------------------------------------------------
125
- // 4. UI LAYOUT DEFINITIONS (Presentation Layer)
126
- // ------------------------------------------------------------------
127
-
128
- export const BlockSchema = z.object({
129
- id: z.string(),
130
- type: z.string(),
131
- props: z.record(z.string(), z.any()),
132
- layout: z.object({
133
- colSpan: z.number().optional(),
134
- rowSpan: z.number().optional(),
135
- }).optional(),
136
- });
137
- // Explicitly export the Block type
138
- export type Block = z.infer<typeof BlockSchema>;
139
-
140
- export const PageSectionSchema = z.object({
141
- id: z.string(),
142
- title: z.string().optional(),
143
- description: z.string().optional(),
144
- layout: z.object({
145
- columns: z.number().optional(),
146
- variant: z.enum(['grid', 'stack', 'split']).optional()
147
- }).optional(),
148
- blocks: z.array(BlockSchema),
149
- });
150
- // Explicitly export the PageSection type
151
- export type PageSection = z.infer<typeof PageSectionSchema>;
152
-
153
- export const PageSchema = z.object({
154
- id: z.string(),
155
- slug: z.string(),
156
- title: z.string(),
157
- description: z.string().optional(),
158
- icon: z.string().optional(),
159
- sections: z.array(PageSectionSchema),
160
- });
161
- export type PageDefinition = z.infer<typeof PageSchema>;
162
-
163
-
164
- // ------------------------------------------------------------------
165
- // 5. MASTER APP SPECIFICATION (Root)
166
- // ------------------------------------------------------------------
167
-
168
- export const AppSpecificationSchema = z.object({
169
- meta: z.object({
170
- name: z.string(),
171
- version: z.string(),
172
- description: z.string().optional(),
173
- author: z.string().optional(),
174
- createdAt: z.string().optional(),
175
- }),
176
-
177
- config: z.object({
178
- theme: z.enum(['light', 'dark', 'system', 'corporate', 'midnight', 'blueprint']).default('system'),
179
- mockMode: z.boolean().default(true),
180
- brokerUrl: z.string().optional(),
181
- }),
182
-
183
- modules: z.array(z.string()).optional(),
184
- resources: z.array(ResourceSchema).optional(),
185
-
186
- domain: z.object({
187
- signals: z.array(SignalSchema),
188
- entities: z.array(EntitySchema),
189
- workflows: z.array(WorkflowSchema).optional(),
190
- }),
191
-
192
- pages: z.array(PageSchema).optional(),
193
- });
194
-
195
- export type AppSpecification = z.infer<typeof AppSpecificationSchema>;
196
-
197
-
198
- // ------------------------------------------------------------------
199
- // 6. FLORA TELEMETRY (Legacy)
200
- // ------------------------------------------------------------------
201
-
202
- export const FloraTelemetrySchema = z.object({
203
- timestamp: z.number(),
204
- soilMoisture: z.number().min(0).max(100),
205
- ambientLight: z.number().min(0).max(100000),
206
- temperature: z.number().min(-40).max(125),
207
- });
208
-
209
- export type FloraTelemetry = z.infer<typeof FloraTelemetrySchema>;
package/tsconfig.json DELETED
@@ -1,16 +0,0 @@
1
- {
2
- "compilerOptions": {
3
- "target": "ES2020",
4
- "module": "ESNext",
5
- "moduleResolution": "bundler",
6
- "strict": true,
7
- "esModuleInterop": true,
8
- "declaration": true,
9
- "declarationMap": true,
10
- "sourceMap": true,
11
- "outDir": "./dist",
12
- "rootDir": "."
13
- },
14
- "include": ["index.ts", "src/**/*.ts"],
15
- "exclude": ["dist", "node_modules"]
16
- }