-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmanifest.zod.ts
More file actions
383 lines (352 loc) · 14.2 KB
/
manifest.zod.ts
File metadata and controls
383 lines (352 loc) · 14.2 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
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
// Copyright (c) 2025 ObjectStack. Licensed under the Apache-2.0 license.
import { z } from 'zod';
import { PluginCapabilityManifestSchema } from './plugin-capability.zod';
import { PluginLoadingConfigSchema } from './plugin-loading.zod';
import { CORE_PLUGIN_TYPES } from './plugin.zod';
import { DatasetSchema } from '../data/dataset.zod';
/**
* Schema for the ObjectStack Manifest.
* This defines the structure of a package configuration in the ObjectStack ecosystem.
* All packages (apps, plugins, drivers, modules) must conform to this schema.
*
* @example App Package
* ```yaml
* id: com.acme.crm
* version: 1.0.0
* type: app
* name: Acme CRM
* description: Customer Relationship Management system
* permissions:
* - system.user.read
* - system.object.create
* objects:
* - "./src/objects/*.object.yml"
* ```
*/
export const ManifestSchema = z.object({
/**
* Unique package identifier using reverse domain notation.
* Must be unique across the entire ecosystem.
*
* @example "com.steedos.crm"
* @example "org.apache.superset"
*/
id: z.string().describe('Unique package identifier (reverse domain style)'),
/**
* Short namespace identifier for metadata scoping.
* Used as a prefix for objects and other metadata to prevent naming collisions
* across packages from different vendors.
*
* Rules:
* - 2-20 characters, lowercase letters, digits, and underscores only.
* - Must be unique within a running instance.
* - Platform-reserved namespaces (no prefix applied): "base", "system".
* - FQN (Fully Qualified Name) = `{namespace}__{short_name}` (double underscore separator).
*
* @example "crm" → objects become crm__account, crm__deal
* @example "todo" → objects become todo__task
* @example "base" → objects keep short name (platform reserved)
*/
namespace: z.string()
.regex(/^[a-z][a-z0-9_]{1,19}$/, 'Namespace must be 2-20 chars, lowercase alphanumeric + underscore')
.optional()
.describe('Short namespace identifier for metadata scoping (e.g. "crm", "todo")'),
/**
* Default datasource for all objects in this package.
*
* When set, all objects defined in this package will use this datasource
* by default unless they explicitly override it with their own `datasource` field.
*
* This provides package-level datasource configuration without needing to
* specify it on every individual object.
*
* @example "memory" // Use in-memory driver for all package objects
* @example "turso" // Use Turso/LibSQL for all package objects
*/
defaultDatasource: z.string().optional().default('default')
.describe('Default datasource for all objects in this package'),
/**
* Package version following semantic versioning (major.minor.patch).
*
* @example "1.0.0"
* @example "2.1.0-beta.1"
*/
version: z.string().regex(/^\d+\.\d+\.\d+$/).describe('Package version (semantic versioning)'),
/**
* Type of the package in the ObjectStack ecosystem.
* - plugin: General-purpose functionality extension (Runtime: standard)
* - app: Business application package
* - driver: Connectivity adapter
* - server: Protocol gateway (Hono, GraphQL)
* - ui: Frontend package (Static/SPA)
* - theme: UI Theme
* - agent: AI Agent
* - module: Reusable code library/shared module
* - objectql: Core engine
* - adapter: Host adapter (Express, Fastify)
*/
type: z.enum([
'plugin',
...CORE_PLUGIN_TYPES,
'module',
'gateway', // Deprecated: use 'server'
'adapter'
]).describe('Type of package'),
/**
* Human-readable name of the package.
* Displayed in the UI for users.
*
* @example "Project Management"
*/
name: z.string().describe('Human-readable package name'),
/**
* Brief description of the package functionality.
* Displayed in the marketplace and plugin manager.
*/
description: z.string().optional().describe('Package description'),
/**
* Array of permission strings that the package requires.
* These form the "Scope" requested by the package at installation.
*
* @example ["system.user.read", "system.data.write"]
*/
permissions: z.array(z.string()).optional().describe('Array of required permission strings'),
/**
* Glob patterns specifying ObjectQL schemas files.
* Matches `*.object.yml` or `*.object.ts` files to load business objects.
*
* @example ["./src/objects/*.object.yml"]
*/
objects: z.array(z.string()).optional().describe('Glob patterns for ObjectQL schemas files'),
/**
* Defines system level DataSources.
* Matches `*.datasource.yml` files.
*
* @example ["./src/datasources/*.datasource.mongo.yml"]
*/
datasources: z.array(z.string()).optional().describe('Glob patterns for Datasource definitions'),
/**
* Package Dependencies.
* Map of package IDs to version requirements.
*
* @example { "@steedos/plugin-auth": "^2.0.0" }
*/
dependencies: z.record(z.string(), z.string()).optional().describe('Package dependencies'),
/**
* Plugin Configuration Schema.
* Defines the settings this plugin exposes to the user via UI/ENV.
* Uses a simplified JSON Schema format.
*
* @example
* {
* "title": "Stripe Config",
* "properties": {
* "apiKey": { "type": "string", "secret": true },
* "currency": { "type": "string", "default": "USD" }
* }
* }
*/
configuration: z.object({
title: z.string().optional(),
properties: z.record(z.string(), z.object({
type: z.enum(['string', 'number', 'boolean', 'array', 'object']).describe('Data type of the setting'),
default: z.unknown().optional().describe('Default value'),
description: z.string().optional().describe('Tooltip description'),
required: z.boolean().optional().describe('Is this setting required?'),
secret: z.boolean().optional().describe('If true, value is encrypted/masked (e.g. API Keys)'),
enum: z.array(z.string()).optional().describe('Allowed values for select inputs'),
})).describe('Map of configuration keys to their definitions')
}).optional().describe('Plugin configuration settings'),
/**
* Contribution Points (VS Code Style).
* formalized way to extend the platform capabilities.
*/
contributes: z.object({
/**
* Register new Metadata Kinds (CRDs).
* Enables the system to parse and validate new file types.
* Example: Registering a BI plugin to handle *.report.ts
*/
kinds: z.array(z.object({
id: z.string().describe('The generic identifier of the kind (e.g., "sys.bi.report")'),
globs: z.array(z.string()).describe('File patterns to watch (e.g., ["**/*.report.ts"])'),
description: z.string().optional().describe('Description of what this kind represents'),
})).optional().describe('New Metadata Types to recognize'),
/**
* Register System Hooks.
* Declares that this plugin listens to specific system events.
*/
events: z.array(z.string()).optional().describe('Events this plugin listens to'),
/**
* Register UI Menus.
*/
menus: z.record(z.string(), z.array(z.object({
id: z.string(),
label: z.string(),
command: z.string().optional(),
}))).optional().describe('UI Menu contributions'),
/**
* Register Custom Themes.
*/
themes: z.array(z.object({
id: z.string(),
label: z.string(),
path: z.string(),
})).optional().describe('Theme contributions'),
/**
* Register Translations.
* Path to translation files (e.g. "locales/en.json").
*/
translations: z.array(z.object({
locale: z.string(),
path: z.string(),
})).optional().describe('Translation resources'),
/**
* Register Server Actions.
* Invocable functions exposed to Flows or API.
*/
actions: z.array(z.object({
name: z.string().describe('Unique action name'),
label: z.string().optional(),
description: z.string().optional(),
input: z.unknown().optional().describe('Input validation schema'),
output: z.unknown().optional().describe('Output schema'),
})).optional().describe('Exposed server actions'),
/**
* Register Storage Drivers.
* Enables connecting to new types of datasources.
*/
drivers: z.array(z.object({
id: z.string().describe('Driver unique identifier (e.g. "postgres", "mongo")'),
label: z.string().describe('Human readable name'),
description: z.string().optional(),
})).optional().describe('Driver contributions'),
/**
* Register Custom Field Types.
* Extends the data model with new widget types.
*/
fieldTypes: z.array(z.object({
name: z.string().describe('Unique field type name (e.g. "vector")'),
label: z.string().describe('Display label'),
description: z.string().optional(),
})).optional().describe('Field Type contributions'),
/**
* Register Custom Query Operators/Functions.
* Extends ObjectQL with new functions (e.g. distance()).
*/
functions: z.array(z.object({
name: z.string().describe('Function name (e.g. "distance")'),
description: z.string().optional(),
args: z.array(z.string()).optional().describe('Argument types'),
returnType: z.string().optional(),
})).optional().describe('Query Function contributions'),
/**
* Register API Route Namespaces.
* Declares the API endpoints this plugin provides to the HttpDispatcher.
* The kernel routes matching prefixes to this plugin's handler.
*
* @example
* routes: [
* { prefix: '/api/v1/ai', service: 'ai', methods: ['aiNlq', 'aiChat'] }
* ]
*/
routes: z.array(z.object({
/** URL path prefix (e.g. "/api/v1/ai") */
prefix: z.string().regex(/^\//).describe('API path prefix'),
/** Service name this plugin provides */
service: z.string().describe('Service name this plugin provides'),
/** Protocol method names implemented */
methods: z.array(z.string()).optional()
.describe('Protocol method names implemented (e.g. ["aiNlq", "aiChat"])'),
})).optional().describe('API route contributions to HttpDispatcher'),
/**
* Register CLI Commands.
* Allows plugins to extend the ObjectStack CLI with custom commands.
* Each command entry declares metadata; the actual Commander.js command
* is resolved at runtime by importing the plugin's module.
*
* The plugin package must export a `commands` array of Commander.js `Command` instances
* from its main entry point or from the path specified in `module`.
*
* @example
* ```yaml
* commands:
* - name: marketplace
* description: "Manage marketplace apps"
* module: "./cli" # optional, defaults to package main
* - name: deploy
* description: "Deploy to cloud"
* ```
*/
commands: z.array(z.object({
/** CLI command name (e.g., "marketplace", "deploy"). Must be a valid CLI identifier. */
name: z.string()
.regex(/^[a-z][a-z0-9-]*$/, 'Command name must be lowercase alphanumeric with hyphens')
.describe('CLI command name'),
/** Brief description shown in `os --help` */
description: z.string().optional().describe('Command description for help text'),
/**
* Optional module path (relative to package root) that exports the Commander.js commands.
* If omitted, the CLI will import from the package's main entry point.
* The module must export a `commands` array of Commander.js `Command` instances,
* or a single `Command` instance as default export.
*/
module: z.string().optional().describe('Module path exporting Commander.js commands'),
})).optional().describe('CLI command contributions'),
}).optional().describe('Platform contributions'),
/**
* Initial data seeding configuration.
* Defines default records to be inserted when the package is installed.
*
* Uses the standard DatasetSchema which supports idempotent upsert via
* `externalId`, environment scoping via `env`, and multiple conflict
* resolution modes.
*
* @deprecated Prefer using the top-level `data` field on the Stack Definition
* (defineStack({ data: [...] })) for better visibility and metadata registration.
* This field is retained for backward compatibility with manifest-only packages.
*/
data: z.array(DatasetSchema).optional().describe('Initial seed data (prefer top-level data field)'),
/**
* Plugin Capability Manifest.
* Declares protocols implemented, interfaces provided, dependencies, and extension points.
* This enables plugin interoperability and automatic discovery.
*/
capabilities: PluginCapabilityManifestSchema.optional()
.describe('Plugin capability declarations for interoperability'),
/**
* Extension points contributed by this package.
* Allows packages to extend UI components, add functionality, etc.
*/
extensions: z.record(z.string(), z.unknown()).optional().describe('Extension points and contributions'),
/**
* Plugin Loading Configuration.
* Configures how the plugin is loaded, initialized, and managed at runtime.
* Includes strategies for lazy loading, code splitting, caching, and hot reload.
*/
loading: PluginLoadingConfigSchema.optional()
.describe('Plugin loading and runtime behavior configuration'),
/**
* Platform Compatibility Requirements.
* Specifies the minimum ObjectStack platform version required to run this package.
* Used at install time to prevent incompatible packages from being installed.
*
* @example
* ```yaml
* engine:
* objectstack: ">=3.0.0"
* ```
*/
engine: z.object({
/** ObjectStack platform version requirement (SemVer range) */
objectstack: z.string()
.regex(/^[><=~^]*\d+\.\d+\.\d+/)
.describe('ObjectStack platform version requirement (SemVer range, e.g. ">=3.0.0")'),
}).optional().describe('Platform compatibility requirements'),
});
/**
* TypeScript type inferred from the ManifestSchema.
* Use this type for type-safe manifest handling in TypeScript code.
*/
export type ObjectStackManifest = z.infer<typeof ManifestSchema>;
export type ObjectStackManifestInput = z.input<typeof ManifestSchema>;