-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathstartup-orchestrator.zod.ts
More file actions
207 lines (179 loc) · 6.09 KB
/
startup-orchestrator.zod.ts
File metadata and controls
207 lines (179 loc) · 6.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
// Copyright (c) 2025 ObjectStack. Licensed under the Apache-2.0 license.
import { z } from 'zod';
/**
* Startup Orchestrator Protocol
*
* Zod schemas for plugin startup orchestration data structures.
* These schemas align with the IStartupOrchestrator contract interface.
*
* Following ObjectStack "Zod First" principle - all data structures
* must have Zod schemas for runtime validation and JSON Schema generation.
*/
// ============================================================================
// Startup Configuration Schemas
// ============================================================================
/**
* Startup Options Schema
* Configuration for plugin startup orchestration
*
* @example
* {
* "timeout": 30000,
* "rollbackOnFailure": true,
* "healthCheck": false,
* "parallel": false
* }
*/
export const StartupOptionsSchema = z.object({
/**
* Maximum time (ms) to wait for each plugin to start
* @default 30000 (30 seconds)
*/
timeout: z.number().int().min(0).optional().default(30000)
.describe('Maximum time in milliseconds to wait for each plugin to start'),
/**
* Whether to rollback (destroy) already-started plugins on failure
* @default true
*/
rollbackOnFailure: z.boolean().optional().default(true)
.describe('Whether to rollback already-started plugins if any plugin fails'),
/**
* Whether to run health checks after startup
* @default false
*/
healthCheck: z.boolean().optional().default(false)
.describe('Whether to run health checks after plugin startup'),
/**
* Whether to run plugins in parallel (if dependencies allow)
* @default false (sequential startup)
*/
parallel: z.boolean().optional().default(false)
.describe('Whether to start plugins in parallel when dependencies allow'),
/**
* Custom context to pass to plugin lifecycle methods
*/
context: z.unknown().optional().describe('Custom context object to pass to plugin lifecycle methods'),
});
export type StartupOptions = z.infer<typeof StartupOptionsSchema>;
export type StartupOptionsInput = z.input<typeof StartupOptionsSchema>;
// ============================================================================
// Health Status Schemas
// ============================================================================
/**
* Health Status Schema
* Health status for a plugin
*
* @example
* {
* "healthy": true,
* "timestamp": 1706659200000,
* "details": {
* "databaseConnected": true,
* "memoryUsage": 45.2
* }
* }
*/
export const HealthStatusSchema = z.object({
/**
* Whether the plugin is healthy
*/
healthy: z.boolean().describe('Whether the plugin is healthy'),
/**
* Health check timestamp (Unix milliseconds)
*/
timestamp: z.number().int().describe('Unix timestamp in milliseconds when health check was performed'),
/**
* Optional health details (plugin-specific)
*/
details: z.record(z.string(), z.unknown()).optional().describe('Optional plugin-specific health details'),
/**
* Optional error message if unhealthy
*/
message: z.string().optional().describe('Error message if plugin is unhealthy'),
});
export type HealthStatus = z.infer<typeof HealthStatusSchema>;
// ============================================================================
// Startup Result Schemas
// ============================================================================
/**
* Plugin Startup Result Schema
* Result of a single plugin startup operation
*
* @example
* {
* "plugin": { "name": "crm-plugin", "version": "1.0.0" },
* "success": true,
* "duration": 1250,
* "health": {
* "healthy": true,
* "timestamp": 1706659200000
* }
* }
*/
export const PluginStartupResultSchema = z.object({
/**
* Plugin that was started
*/
plugin: z.object({
name: z.string(),
version: z.string().optional(),
}).passthrough().describe('Plugin metadata'),
/**
* Whether startup was successful
*/
success: z.boolean().describe('Whether the plugin started successfully'),
/**
* Time taken to start (milliseconds)
*/
duration: z.number().min(0).describe('Time taken to start the plugin in milliseconds'),
/**
* Error if startup failed
*/
error: z.object({
name: z.string().describe('Error class name'),
message: z.string().describe('Error message'),
stack: z.string().optional().describe('Stack trace'),
code: z.string().optional().describe('Error code'),
}).optional().describe('Serializable error representation if startup failed'),
/**
* Health status after startup (if healthCheck enabled)
*/
health: HealthStatusSchema.optional().describe('Health status after startup if health check was enabled'),
});
export type PluginStartupResult = z.infer<typeof PluginStartupResultSchema>;
// ============================================================================
// Startup Orchestration Result Schema
// ============================================================================
/**
* Startup Orchestration Result Schema
* Overall result of orchestrating startup for multiple plugins
*
* @example
* {
* "results": [
* { "plugin": { "name": "plugin1" }, "success": true, "duration": 1200 },
* { "plugin": { "name": "plugin2" }, "success": true, "duration": 850 }
* ],
* "totalDuration": 2050,
* "allSuccessful": true
* }
*/
export const StartupOrchestrationResultSchema = z.object({
/**
* Individual plugin startup results
*/
results: z.array(PluginStartupResultSchema).describe('Startup results for each plugin'),
/**
* Total time taken for all plugins (milliseconds)
*/
totalDuration: z.number().min(0).describe('Total time taken for all plugins in milliseconds'),
/**
* Whether all plugins started successfully
*/
allSuccessful: z.boolean().describe('Whether all plugins started successfully'),
/**
* Plugins that were rolled back (if rollbackOnFailure was enabled)
*/
rolledBack: z.array(z.string()).optional().describe('Names of plugins that were rolled back'),
});
export type StartupOrchestrationResult = z.infer<typeof StartupOrchestrationResultSchema>;