-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathexplain.ts
More file actions
412 lines (383 loc) · 16.1 KB
/
Copy pathexplain.ts
File metadata and controls
412 lines (383 loc) · 16.1 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
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
// Copyright (c) 2025 ObjectStack. Licensed under the Apache-2.0 license.
import { Args, Command, Flags } from '@oclif/core';
import chalk from 'chalk';
import {
printHeader,
printSuccess,
printError,
printInfo,
printKV,
} from '../utils/format.js';
// ─── Schema Catalog ─────────────────────────────────────────────────
interface SchemaInfo {
name: string;
description: string;
required: Array<{ name: string; type: string; description: string }>;
optional: Array<{ name: string; type: string; description: string }>;
example: string;
related: string[];
docsPath: string;
}
const SCHEMAS: Record<string, SchemaInfo> = {
object: {
name: 'Object',
description: 'Defines a data entity in the ObjectStack data model. Objects contain fields, enable capabilities, and form the foundation of the metadata-driven platform.',
required: [
{ name: 'name', type: 'string (snake_case)', description: 'Machine name identifier' },
{ name: 'fields', type: 'Record<string, Field>', description: 'Map of field definitions' },
],
optional: [
{ name: 'label', type: 'string', description: 'Human-readable display name' },
{ name: 'pluralLabel', type: 'string', description: 'Plural display name' },
{ name: 'description', type: 'string', description: 'Documentation for the object' },
{ name: 'ownership', type: '"own" | "extend"', description: 'Whether this object is owned or extended' },
{ name: 'enable', type: 'ObjectCapabilities', description: 'Feature flags (trackHistory, apiEnabled, etc.)' },
{ name: 'icon', type: 'string', description: 'Icon identifier for UI display' },
],
example: `{
name: 'project_task',
label: 'Project Task',
fields: {
title: { type: 'text', label: 'Title', required: true },
status: { type: 'select', label: 'Status', options: ['open', 'closed'] },
assigned_to: { type: 'lookup', label: 'Assigned To', reference: 'user' },
},
enable: { trackHistory: true, apiEnabled: true },
}`,
related: ['field', 'view', 'flow', 'query'],
docsPath: 'data/object',
},
field: {
name: 'Field',
description: 'Defines a property on an Object. Fields have types that control validation, storage, and UI rendering.',
required: [
{ name: 'type', type: 'FieldType', description: 'Field data type (text, number, boolean, select, lookup, etc.)' },
],
optional: [
{ name: 'label', type: 'string', description: 'Human-readable display name' },
{ name: 'required', type: 'boolean', description: 'Whether the field is mandatory' },
{ name: 'multiple', type: 'boolean', description: 'Whether the field holds an array of values' },
{ name: 'defaultValue', type: 'any', description: 'Default value for new records' },
{ name: 'maxLength', type: 'number', description: 'Maximum character length (text fields)' },
{ name: 'reference', type: 'string', description: 'Target object name (lookup fields)' },
{ name: 'options', type: 'string[]', description: 'Available choices (select fields)' },
],
example: `{
type: 'text',
label: 'Email Address',
required: true,
maxLength: 255,
}`,
related: ['object', 'view', 'query'],
docsPath: 'data/field',
},
view: {
name: 'View',
description: 'Defines how data is displayed and interacted with. Views can be list views (grid, kanban, calendar) or form views (simple, tabbed, wizard).',
required: [
{ name: 'name', type: 'string (snake_case)', description: 'Machine name identifier' },
{ name: 'object', type: 'string', description: 'Target object to display' },
{ name: 'type', type: '"list" | "form"', description: 'View category' },
],
optional: [
{ name: 'label', type: 'string', description: 'Display name' },
{ name: 'layout', type: '"grid" | "kanban" | "calendar" | "gantt" | "simple" | "tabbed" | "wizard"', description: 'Layout style' },
{ name: 'columns', type: 'string[]', description: 'Visible fields for list views' },
{ name: 'filters', type: 'Filter[]', description: 'Default query filters' },
{ name: 'sort', type: 'SortConfig', description: 'Default sort configuration' },
],
example: `{
name: 'task_board',
object: 'project_task',
type: 'list',
label: 'Task Board',
layout: 'kanban',
columns: ['title', 'status', 'assigned_to'],
}`,
related: ['object', 'app', 'action', 'dashboard'],
docsPath: 'ui/view',
},
flow: {
name: 'Flow',
description: 'Visual logic orchestration for business processes. Flows can be auto-launched, screen-based, or scheduled.',
required: [
{ name: 'name', type: 'string (snake_case)', description: 'Machine name identifier' },
{ name: 'type', type: '"autolaunched" | "screen" | "schedule"', description: 'Trigger type' },
],
optional: [
{ name: 'label', type: 'string', description: 'Display name' },
{ name: 'description', type: 'string', description: 'Documentation for the flow' },
{ name: 'trigger', type: 'TriggerConfig', description: 'Event that starts the flow' },
{ name: 'steps', type: 'FlowStep[]', description: 'Sequence of actions' },
{ name: 'variables', type: 'Variable[]', description: 'Flow-scoped variables' },
],
example: `{
name: 'assign_on_create',
type: 'autolaunched',
label: 'Auto-Assign on Create',
trigger: { object: 'project_task', event: 'afterInsert' },
steps: [
{ type: 'assignment', field: 'assigned_to', value: '$currentUser' },
],
}`,
related: ['object', 'trigger', 'agent'],
docsPath: 'automation/flow',
},
agent: {
name: 'Agent',
description: 'Autonomous AI actor that can perform tasks using tools, instructions, and context from the ObjectStack data model.',
required: [
{ name: 'name', type: 'string (snake_case)', description: 'Machine name identifier' },
{ name: 'role', type: 'string', description: 'Agent purpose description' },
],
optional: [
{ name: 'instructions', type: 'string', description: 'System prompt / behavioral instructions' },
{ name: 'tools', type: 'ToolReference[]', description: 'Tools the agent can invoke' },
{ name: 'model', type: 'string', description: 'LLM model to use' },
{ name: 'objects', type: 'string[]', description: 'Objects the agent can access' },
{ name: 'temperature', type: 'number', description: 'Creativity parameter (0-1)' },
],
example: `{
name: 'support_agent',
role: 'Customer Support Assistant',
instructions: 'Help users resolve issues by searching the knowledge base.',
tools: [{ name: 'query', object: 'knowledge_article' }],
model: 'gpt-4o',
}`,
related: ['object', 'flow', 'query'],
docsPath: 'ai/agent',
},
app: {
name: 'App',
description: 'Application shell that groups navigation, branding, and views into a cohesive user experience.',
required: [
{ name: 'name', type: 'string (snake_case)', description: 'Machine name identifier' },
],
optional: [
{ name: 'label', type: 'string', description: 'Display name' },
{ name: 'description', type: 'string', description: 'App description' },
{ name: 'navigation', type: 'NavItem[]', description: 'Menu tree structure' },
{ name: 'logo', type: 'string', description: 'Logo URL or asset path' },
{ name: 'theme', type: 'string', description: 'Theme reference' },
{ name: 'defaultRoute', type: 'string', description: 'Landing page route' },
],
example: `{
name: 'project_manager',
label: 'Project Manager',
navigation: [
{ type: 'object', object: 'project_task', label: 'Tasks' },
{ type: 'dashboard', dashboard: 'project_overview', label: 'Overview' },
],
}`,
related: ['view', 'dashboard', 'action', 'object'],
docsPath: 'ui/app',
},
query: {
name: 'Query',
description: 'Declarative data retrieval definition used for fetching and filtering records from objects.',
required: [
{ name: 'object', type: 'string', description: 'Target object to query' },
],
optional: [
{ name: 'fields', type: 'string[]', description: 'Fields to select' },
{ name: 'filters', type: 'Filter[]', description: 'Where conditions' },
{ name: 'sort', type: 'SortConfig[]', description: 'Order by configuration' },
{ name: 'limit', type: 'number', description: 'Maximum records to return' },
{ name: 'offset', type: 'number', description: 'Pagination offset' },
],
example: `{
object: 'project_task',
fields: ['title', 'status', 'assigned_to'],
filters: [{ field: 'status', operator: 'eq', value: 'open' }],
sort: [{ field: 'created_at', order: 'desc' }],
limit: 50,
}`,
related: ['object', 'field', 'view'],
docsPath: 'data/query',
},
dashboard: {
name: 'Dashboard',
description: 'Grid-layout container for widgets that display aggregated data, charts, and key metrics.',
required: [
{ name: 'name', type: 'string (snake_case)', description: 'Machine name identifier' },
],
optional: [
{ name: 'label', type: 'string', description: 'Display name' },
{ name: 'widgets', type: 'Widget[]', description: 'Dashboard widget definitions' },
{ name: 'layout', type: 'GridLayout', description: 'Widget positioning' },
{ name: 'refreshInterval', type: 'number', description: 'Auto-refresh interval in seconds' },
],
example: `{
name: 'project_overview',
label: 'Project Overview',
widgets: [
{ type: 'chart', object: 'project_task', groupBy: 'status' },
{ type: 'metric', object: 'project_task', aggregate: 'count' },
],
}`,
related: ['app', 'view', 'object'],
docsPath: 'ui/dashboard',
},
action: {
name: 'Action',
description: 'User-triggered operation such as a button click, URL redirect, or screen flow launch.',
required: [
{ name: 'name', type: 'string (snake_case)', description: 'Machine name identifier' },
{ name: 'type', type: '"button" | "url" | "flow" | "api"', description: 'Action type' },
],
optional: [
{ name: 'label', type: 'string', description: 'Display text' },
{ name: 'icon', type: 'string', description: 'Button icon' },
{ name: 'object', type: 'string', description: 'Target object context' },
{ name: 'flow', type: 'string', description: 'Flow to launch (for flow actions)' },
{ name: 'url', type: 'string', description: 'Target URL (for url actions)' },
{ name: 'confirmation', type: 'string', description: 'Confirmation dialog message' },
],
example: `{
name: 'close_task',
type: 'flow',
label: 'Close Task',
object: 'project_task',
flow: 'close_task_flow',
confirmation: 'Are you sure you want to close this task?',
}`,
related: ['flow', 'view', 'app'],
docsPath: 'ui/action',
},
workflow: {
name: 'Workflow',
description: 'State machine and approval process that governs record lifecycle transitions.',
required: [
{ name: 'name', type: 'string (snake_case)', description: 'Machine name identifier' },
{ name: 'object', type: 'string', description: 'Target object' },
],
optional: [
{ name: 'label', type: 'string', description: 'Display name' },
{ name: 'states', type: 'State[]', description: 'Defined workflow states' },
{ name: 'transitions', type: 'Transition[]', description: 'Allowed state transitions' },
{ name: 'approvers', type: 'ApproverConfig', description: 'Approval chain configuration' },
],
example: `{
name: 'task_approval',
object: 'project_task',
label: 'Task Approval',
states: ['draft', 'pending', 'approved', 'rejected'],
transitions: [
{ from: 'draft', to: 'pending', action: 'submit' },
{ from: 'pending', to: 'approved', action: 'approve' },
{ from: 'pending', to: 'rejected', action: 'reject' },
],
}`,
related: ['object', 'flow', 'action'],
docsPath: 'automation/workflow',
},
trigger: {
name: 'Trigger',
description: 'Event-driven automation hook that fires when specific data events occur on an object.',
required: [
{ name: 'name', type: 'string (snake_case)', description: 'Machine name identifier' },
{ name: 'object', type: 'string', description: 'Target object to monitor' },
{ name: 'event', type: '"beforeInsert" | "afterInsert" | "beforeUpdate" | "afterUpdate" | "beforeDelete" | "afterDelete"', description: 'Event type' },
],
optional: [
{ name: 'label', type: 'string', description: 'Display name' },
{ name: 'condition', type: 'FilterExpression', description: 'Conditional guard' },
{ name: 'flow', type: 'string', description: 'Flow to execute' },
{ name: 'async', type: 'boolean', description: 'Whether to execute asynchronously' },
],
example: `{
name: 'task_created_notify',
object: 'project_task',
event: 'afterInsert',
label: 'Notify on Task Creation',
flow: 'send_task_notification',
async: true,
}`,
related: ['object', 'flow', 'workflow'],
docsPath: 'automation/trigger',
},
};
// ─── Command ────────────────────────────────────────────────────────
export default class Explain extends Command {
static override description = 'Display human-readable explanation of an ObjectStack schema';
static override args = {
schema: Args.string({ description: 'Schema name (e.g., object, field, view, flow, agent, app)', required: false }),
};
static override flags = {
json: Flags.boolean({ description: 'Output as JSON' }),
};
async run(): Promise<void> {
const { args, flags } = await this.parse(Explain);
const schemaName = args.schema;
// ── No argument: list all schemas ──
if (!schemaName) {
if (flags.json) {
console.log(JSON.stringify({
schemas: Object.entries(SCHEMAS).map(([key, s]) => ({
name: key,
description: s.description,
})),
}, null, 2));
return;
}
printHeader('Available Schemas');
console.log('');
for (const [key, schema] of Object.entries(SCHEMAS)) {
const desc = schema.description;
console.log(` ${chalk.bold.cyan(key.padEnd(12))} ${chalk.dim(desc.length > 70 ? desc.slice(0, 70) + '...' : desc)}`);
}
console.log('');
printInfo(`Run ${chalk.white('objectstack explain <schema>')} for details.`);
console.log('');
return;
}
// ── Lookup schema ──
const schema = SCHEMAS[schemaName.toLowerCase()];
if (!schema) {
if (flags.json) {
console.log(JSON.stringify({ error: `Unknown schema: ${schemaName}` }));
process.exit(1);
}
printError(`Unknown schema: "${schemaName}"`);
console.log('');
printInfo(`Available schemas: ${Object.keys(SCHEMAS).join(', ')}`);
console.log('');
process.exit(1);
}
// ── JSON output ──
if (flags.json) {
console.log(JSON.stringify(schema, null, 2));
return;
}
// ── Pretty output ──
printHeader(`Schema: ${schema.name}`);
console.log('');
console.log(` ${schema.description}`);
// Required properties
console.log('');
console.log(chalk.bold(' Required Properties:'));
for (const prop of schema.required) {
console.log(` ${chalk.green(prop.name.padEnd(18))} ${chalk.dim(prop.type.padEnd(30))} ${prop.description}`);
}
// Optional properties
if (schema.optional.length > 0) {
console.log('');
console.log(chalk.bold(' Optional Properties:'));
for (const prop of schema.optional) {
console.log(` ${chalk.yellow(prop.name.padEnd(18))} ${chalk.dim(prop.type.padEnd(30))} ${prop.description}`);
}
}
// Example
console.log('');
console.log(chalk.bold(' Example:'));
for (const line of schema.example.split('\n')) {
console.log(chalk.dim(` ${line}`));
}
// Related schemas
console.log('');
printKV(' Related', schema.related.map((r) => chalk.cyan(r)).join(', '));
// Documentation link
printKV(' Docs', `https://objectstack.dev/docs/${schema.docsPath}`);
console.log('');
}
}