-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathobject.zod.ts
More file actions
95 lines (79 loc) · 3.15 KB
/
Copy pathobject.zod.ts
File metadata and controls
95 lines (79 loc) · 3.15 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
import { z } from 'zod';
import { FieldSchema } from './field.zod';
/**
* Capability Flags
* Defines what system features are enabled for this object.
*/
export const ObjectCapabilities = z.object({
/** Enable history tracking (Audit Trail) */
trackHistory: z.boolean().default(false),
/** Enable global search indexing */
searchable: z.boolean().default(true),
/** Enable REST/GraphQL API access */
apiEnabled: z.boolean().default(true),
/**
* API Supported Operations
* Explicitly whitelist allowed operations.
* If not defined, all standard operations are allowed (if apiEnabled=true).
*/
apiMethods: z.array(z.enum([
'get', 'list',
'create', 'update', 'delete',
'upsert',
'bulkCreate', 'bulkUpdate', 'bulkDelete', 'bulkUpsert',
'aggregate', // count, sum, group by
'history', // audit trail access
'search', // full text search
'restore', // undelete from trash
'purge', // hard delete
'import', // data import
'export', // data export
])).optional().describe('Allowed API operations'),
/** Enable attachments/files */
files: z.boolean().default(false),
/** Enable discussions/chatter */
feedEnabled: z.boolean().default(false),
/** Enable Recycle Bin mechanics */
trash: z.boolean().default(true),
});
/**
* Schema for database indexes.
*/
export const IndexSchema = z.object({
name: z.string().optional().describe('Index name'),
fields: z.array(z.string()).describe('Fields included in the index'),
unique: z.boolean().optional().describe('Whether the index is unique'),
});
/**
* Base Object Schema Definition
*/
const ObjectSchemaBase = z.object({
/** Identify */
name: z.string().regex(/^[a-z_][a-z0-9_]*$/).describe('Machine name (snake_case)'),
label: z.string().optional().describe('Singular Label (e.g. "Account")'),
pluralLabel: z.string().optional().describe('Plural Label (e.g. "Accounts")'),
description: z.string().optional().describe('Internal description'),
icon: z.string().optional().describe('Lucide icon name'),
/**
* Storage / Virtualization Config
* Defines where the data actually lives.
*/
datasource: z.string().default('default').describe('Target Datasource ID (e.g. "postgres", "salesforce"). references sys_datasource.'),
tableName: z.string().optional().describe('Physical table/collection name in the target datasource'),
isSystem: z.boolean().default(false).describe('Is system object (protected)'),
/** Fields Definition */
fields: z.record(FieldSchema).describe('Map of field definitions'),
/** Indexes */
indexes: z.array(IndexSchema).optional().describe('Database indexes definition'),
/** Key Fields */
nameField: z.string().optional().describe('Which field represents the record name/title (usually "name")'),
/** Features & Capabilities */
enable: ObjectCapabilities.optional().describe('Enabled system capabilities'),
});
/**
* Enhanced ObjectSchema with Factory
*/
export const ObjectSchema = Object.assign(ObjectSchemaBase, {
create: <T extends z.input<typeof ObjectSchemaBase>>(config: T) => config,
});
export type ServiceObject = z.infer<typeof ObjectSchemaBase>;