@objectstack/spec 0.1.0

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.
@@ -0,0 +1,246 @@
1
+ /**
2
+ * Object Entity Interface
3
+ *
4
+ * Defines the structure of an entity in the ObjectStack metamodel.
5
+ * Entities represent data models/tables with their fields and relationships.
6
+ *
7
+ * @module types/meta/object-entity
8
+ */
9
+ import { ObjectField } from './object-field';
10
+ /**
11
+ * Represents an entity definition in the ObjectStack metamodel
12
+ *
13
+ * @remarks
14
+ * ObjectEntity is the core data model definition. It describes a logical
15
+ * entity (like User, Account, Product) with its fields, constraints,
16
+ * and metadata. This interface is used by:
17
+ *
18
+ * - ObjectQL parser: To validate and process schema definitions
19
+ * - ObjectUI renderer: To generate forms, tables, and views
20
+ * - Database drivers: To create tables and migrations
21
+ * - API generators: To expose REST/GraphQL endpoints
22
+ *
23
+ * @example
24
+ * ```typescript
25
+ * const userEntity: ObjectEntity = {
26
+ * name: 'User',
27
+ * label: 'User',
28
+ * pluralLabel: 'Users',
29
+ * description: 'System user account',
30
+ * fields: [
31
+ * {
32
+ * name: 'id',
33
+ * label: 'ID',
34
+ * type: 'text',
35
+ * required: true,
36
+ * readonly: true
37
+ * },
38
+ * {
39
+ * name: 'email',
40
+ * label: 'Email',
41
+ * type: 'email',
42
+ * required: true,
43
+ * unique: true
44
+ * },
45
+ * {
46
+ * name: 'name',
47
+ * label: 'Full Name',
48
+ * type: 'text',
49
+ * required: true
50
+ * }
51
+ * ],
52
+ * primaryKey: 'id',
53
+ * displayField: 'name'
54
+ * };
55
+ * ```
56
+ */
57
+ export interface ObjectEntity {
58
+ /**
59
+ * Technical name of the entity
60
+ *
61
+ * @remarks
62
+ * Used in code, APIs, and database table names.
63
+ * Should be in PascalCase for entities.
64
+ * Must be unique across the system.
65
+ *
66
+ * @example 'User', 'Account', 'SalesOrder'
67
+ */
68
+ name: string;
69
+ /**
70
+ * Human-readable singular label for the entity
71
+ *
72
+ * @remarks
73
+ * Used in UI headers, forms, and documentation.
74
+ *
75
+ * @example 'User', 'Sales Order', 'Product Category'
76
+ */
77
+ label: string;
78
+ /**
79
+ * Human-readable plural label for the entity
80
+ *
81
+ * @remarks
82
+ * Used in UI when displaying lists or collections.
83
+ *
84
+ * @example 'Users', 'Sales Orders', 'Product Categories'
85
+ */
86
+ pluralLabel: string;
87
+ /**
88
+ * Detailed description of the entity's purpose
89
+ *
90
+ * @remarks
91
+ * Used for documentation and context-sensitive help
92
+ */
93
+ description?: string;
94
+ /**
95
+ * Array of field definitions that make up this entity
96
+ *
97
+ * @remarks
98
+ * Each field represents a column/attribute in the entity.
99
+ * Field names must be unique within the entity.
100
+ *
101
+ * @see ObjectField
102
+ */
103
+ fields: ObjectField[];
104
+ /**
105
+ * Name of the field that serves as the primary key
106
+ *
107
+ * @remarks
108
+ * The primary key uniquely identifies each record.
109
+ * Must be one of the field names in the fields array.
110
+ *
111
+ * @defaultValue 'id'
112
+ *
113
+ * @example 'id', 'uuid', 'userId'
114
+ */
115
+ primaryKey?: string;
116
+ /**
117
+ * Name of the field to use as the display/title field
118
+ *
119
+ * @remarks
120
+ * Used when showing a record reference in lookups, breadcrumbs, etc.
121
+ * Should be a field that uniquely and meaningfully identifies a record.
122
+ *
123
+ * @defaultValue 'name'
124
+ *
125
+ * @example 'name', 'title', 'email', 'code'
126
+ */
127
+ displayField?: string;
128
+ /**
129
+ * Icon identifier for the entity
130
+ *
131
+ * @remarks
132
+ * Used in navigation menus, headers, and lists.
133
+ * Can be an icon library reference (e.g., 'user', 'building', 'package')
134
+ * or a URL to a custom icon.
135
+ *
136
+ * @example 'user', 'briefcase', 'https://example.com/icon.svg'
137
+ */
138
+ icon?: string;
139
+ /**
140
+ * Color theme for the entity
141
+ *
142
+ * @remarks
143
+ * Used for visual distinction in UI elements.
144
+ * Can be a CSS color name, hex code, or theme variable.
145
+ *
146
+ * @example 'blue', '#3B82F6', 'primary'
147
+ */
148
+ color?: string;
149
+ /**
150
+ * Whether this entity should be audited
151
+ *
152
+ * @remarks
153
+ * When enabled, tracks create/update/delete operations with user and timestamp.
154
+ * Typically adds fields like: createdBy, createdAt, updatedBy, updatedAt
155
+ *
156
+ * @defaultValue false
157
+ */
158
+ auditable?: boolean;
159
+ /**
160
+ * Whether this entity supports soft deletion
161
+ *
162
+ * @remarks
163
+ * When enabled, records are marked as deleted rather than physically removed.
164
+ * Typically adds a 'deletedAt' timestamp field.
165
+ *
166
+ * @defaultValue false
167
+ */
168
+ softDelete?: boolean;
169
+ /**
170
+ * Whether this entity can be searched via full-text search
171
+ *
172
+ * @remarks
173
+ * When enabled, the entity is indexed for full-text search operations
174
+ *
175
+ * @defaultValue false
176
+ */
177
+ searchable?: boolean;
178
+ /**
179
+ * Names of fields to include in full-text search
180
+ *
181
+ * @remarks
182
+ * Only relevant when searchable is true.
183
+ * If not specified, all text fields are included.
184
+ *
185
+ * @example ['name', 'description', 'email']
186
+ */
187
+ searchableFields?: string[];
188
+ /**
189
+ * Permission scope identifier
190
+ *
191
+ * @remarks
192
+ * Defines the permission namespace for this entity.
193
+ * Used to generate permission strings like: '{scope}.read', '{scope}.write'
194
+ *
195
+ * @example 'user', 'sales.order', 'product.category'
196
+ */
197
+ permissionScope?: string;
198
+ /**
199
+ * Custom validation rules
200
+ *
201
+ * @remarks
202
+ * Array of validation rule identifiers that apply to the entire entity.
203
+ * Can reference built-in validators or custom validation functions.
204
+ *
205
+ * @example ['uniqueTogether:email,domain', 'requiredIf:field1,field2']
206
+ */
207
+ validationRules?: string[];
208
+ /**
209
+ * Database table name override
210
+ *
211
+ * @remarks
212
+ * By default, table name is derived from entity name.
213
+ * Use this to specify a custom table name.
214
+ *
215
+ * @example 'tbl_users', 'legacy_accounts'
216
+ */
217
+ tableName?: string;
218
+ /**
219
+ * Entity version for schema migration tracking
220
+ *
221
+ * @remarks
222
+ * Incremented when breaking changes are made to the entity structure.
223
+ * Used for migration management and compatibility checking.
224
+ *
225
+ * @defaultValue 1
226
+ */
227
+ version?: number;
228
+ /**
229
+ * Tags for categorization and filtering
230
+ *
231
+ * @remarks
232
+ * Used to organize entities into logical groups.
233
+ *
234
+ * @example ['core', 'sales', 'internal']
235
+ */
236
+ tags?: string[];
237
+ /**
238
+ * Custom metadata for extensions and plugins
239
+ *
240
+ * @remarks
241
+ * Allows third-party code to attach arbitrary metadata to entities
242
+ * without modifying the core interface
243
+ */
244
+ metadata?: Record<string, unknown>;
245
+ }
246
+ //# sourceMappingURL=object-entity.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"object-entity.d.ts","sourceRoot":"","sources":["../../../src/types/meta/object-entity.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAE7C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8CG;AACH,MAAM,WAAW,YAAY;IAC3B;;;;;;;;;OASG;IACH,IAAI,EAAE,MAAM,CAAC;IAEb;;;;;;;OAOG;IACH,KAAK,EAAE,MAAM,CAAC;IAEd;;;;;;;OAOG;IACH,WAAW,EAAE,MAAM,CAAC;IAEpB;;;;;OAKG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;IAErB;;;;;;;;OAQG;IACH,MAAM,EAAE,WAAW,EAAE,CAAC;IAEtB;;;;;;;;;;OAUG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;IAEpB;;;;;;;;;;OAUG;IACH,YAAY,CAAC,EAAE,MAAM,CAAC;IAEtB;;;;;;;;;OASG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC;IAEd;;;;;;;;OAQG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;IAEf;;;;;;;;OAQG;IACH,SAAS,CAAC,EAAE,OAAO,CAAC;IAEpB;;;;;;;;OAQG;IACH,UAAU,CAAC,EAAE,OAAO,CAAC;IAErB;;;;;;;OAOG;IACH,UAAU,CAAC,EAAE,OAAO,CAAC;IAErB;;;;;;;;OAQG;IACH,gBAAgB,CAAC,EAAE,MAAM,EAAE,CAAC;IAE5B;;;;;;;;OAQG;IACH,eAAe,CAAC,EAAE,MAAM,CAAC;IAEzB;;;;;;;;OAQG;IACH,eAAe,CAAC,EAAE,MAAM,EAAE,CAAC;IAE3B;;;;;;;;OAQG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IAEnB;;;;;;;;OAQG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;IAEjB;;;;;;;OAOG;IACH,IAAI,CAAC,EAAE,MAAM,EAAE,CAAC;IAEhB;;;;;;OAMG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACpC"}
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Object Entity Interface
3
+ *
4
+ * Defines the structure of an entity in the ObjectStack metamodel.
5
+ * Entities represent data models/tables with their fields and relationships.
6
+ *
7
+ * @module types/meta/object-entity
8
+ */
9
+ export {};
@@ -0,0 +1,199 @@
1
+ /**
2
+ * Object Field Interface
3
+ *
4
+ * Defines the structure of a field within an ObjectEntity.
5
+ * Fields represent individual data attributes and their metadata.
6
+ *
7
+ * @module types/meta/object-field
8
+ */
9
+ import { FieldType } from './field-type';
10
+ /**
11
+ * Represents a field definition within an ObjectEntity
12
+ *
13
+ * @remarks
14
+ * ObjectField defines the complete metadata for a single field/attribute
15
+ * in an entity. This includes its type, validation rules, UI hints, and
16
+ * relationships to other entities (in the case of lookup fields).
17
+ *
18
+ * @example
19
+ * ```typescript
20
+ * const nameField: ObjectField = {
21
+ * name: 'name',
22
+ * label: 'Full Name',
23
+ * type: 'text',
24
+ * required: true,
25
+ * maxLength: 100
26
+ * };
27
+ *
28
+ * const ownerField: ObjectField = {
29
+ * name: 'owner',
30
+ * label: 'Owner',
31
+ * type: 'lookup',
32
+ * required: true,
33
+ * lookupEntity: 'User',
34
+ * lookupDisplayField: 'name'
35
+ * };
36
+ * ```
37
+ */
38
+ export interface ObjectField {
39
+ /**
40
+ * Technical name of the field (used in code and database)
41
+ *
42
+ * @remarks
43
+ * Should be in camelCase or snake_case format.
44
+ * Must be unique within the entity.
45
+ *
46
+ * @example 'firstName', 'email', 'created_at'
47
+ */
48
+ name: string;
49
+ /**
50
+ * Human-readable label for the field
51
+ *
52
+ * @remarks
53
+ * Used in UI forms, tables, and documentation.
54
+ *
55
+ * @example 'First Name', 'Email Address', 'Created At'
56
+ */
57
+ label: string;
58
+ /**
59
+ * Data type of the field
60
+ *
61
+ * @see FieldType
62
+ */
63
+ type: FieldType;
64
+ /**
65
+ * Detailed description of the field's purpose and usage
66
+ *
67
+ * @remarks
68
+ * Used for tooltips, help text, and documentation.
69
+ */
70
+ description?: string;
71
+ /**
72
+ * Whether the field is required (cannot be null/empty)
73
+ *
74
+ * @defaultValue false
75
+ */
76
+ required?: boolean;
77
+ /**
78
+ * Whether the field value must be unique across all records
79
+ *
80
+ * @defaultValue false
81
+ */
82
+ unique?: boolean;
83
+ /**
84
+ * Default value when creating new records
85
+ *
86
+ * @remarks
87
+ * Can be a static value or a function reference (e.g., 'NOW()' for timestamps)
88
+ */
89
+ defaultValue?: unknown;
90
+ /**
91
+ * Maximum length for text fields
92
+ *
93
+ * @remarks
94
+ * Only applicable to 'text', 'textarea', 'email', 'url' field types
95
+ */
96
+ maxLength?: number;
97
+ /**
98
+ * Minimum length for text fields
99
+ *
100
+ * @remarks
101
+ * Only applicable to 'text', 'textarea', 'email', 'url' field types
102
+ */
103
+ minLength?: number;
104
+ /**
105
+ * Minimum value for numeric fields
106
+ *
107
+ * @remarks
108
+ * Only applicable to 'number', 'currency', 'percentage' field types
109
+ */
110
+ min?: number;
111
+ /**
112
+ * Maximum value for numeric fields
113
+ *
114
+ * @remarks
115
+ * Only applicable to 'number', 'currency', 'percentage' field types
116
+ */
117
+ max?: number;
118
+ /**
119
+ * Regular expression pattern for validation
120
+ *
121
+ * @remarks
122
+ * Applied to text-based field types for custom validation rules
123
+ *
124
+ * @example '^[A-Z]{2}-\\d{4}$' for pattern like 'AB-1234'
125
+ */
126
+ pattern?: string;
127
+ /**
128
+ * Target entity name for lookup fields
129
+ *
130
+ * @remarks
131
+ * Required when type is 'lookup'. Specifies which entity this field references.
132
+ *
133
+ * @example 'User', 'Account', 'Product'
134
+ */
135
+ lookupEntity?: string;
136
+ /**
137
+ * Field name in the lookup entity to display
138
+ *
139
+ * @remarks
140
+ * Used to show human-readable text instead of IDs.
141
+ * Common values: 'name', 'title', 'label'
142
+ *
143
+ * @defaultValue 'name'
144
+ */
145
+ lookupDisplayField?: string;
146
+ /**
147
+ * Available options for select/multiselect fields
148
+ *
149
+ * @remarks
150
+ * Only applicable to 'select' and 'multiselect' field types
151
+ *
152
+ * @example
153
+ * ```typescript
154
+ * options: [
155
+ * { value: 'draft', label: 'Draft' },
156
+ * { value: 'published', label: 'Published' }
157
+ * ]
158
+ * ```
159
+ */
160
+ options?: Array<{
161
+ /** Internal value stored in database */
162
+ value: string | number;
163
+ /** Human-readable label shown in UI */
164
+ label: string;
165
+ }>;
166
+ /**
167
+ * Whether the field is indexed for faster queries
168
+ *
169
+ * @defaultValue false
170
+ */
171
+ indexed?: boolean;
172
+ /**
173
+ * Whether the field is read-only
174
+ *
175
+ * @remarks
176
+ * Read-only fields can only be set by the system, not by users
177
+ *
178
+ * @defaultValue false
179
+ */
180
+ readonly?: boolean;
181
+ /**
182
+ * Whether the field is hidden from UI by default
183
+ *
184
+ * @remarks
185
+ * Hidden fields are still stored and queryable but not shown in standard forms/views
186
+ *
187
+ * @defaultValue false
188
+ */
189
+ hidden?: boolean;
190
+ /**
191
+ * Custom metadata for extensions and plugins
192
+ *
193
+ * @remarks
194
+ * Allows third-party code to attach arbitrary metadata to fields
195
+ * without modifying the core interface
196
+ */
197
+ metadata?: Record<string, unknown>;
198
+ }
199
+ //# sourceMappingURL=object-field.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"object-field.d.ts","sourceRoot":"","sources":["../../../src/types/meta/object-field.ts"],"names":[],"m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IACH,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACpC"}
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Object Field Interface
3
+ *
4
+ * Defines the structure of a field within an ObjectEntity.
5
+ * Fields represent individual data attributes and their metadata.
6
+ *
7
+ * @module types/meta/object-field
8
+ */
9
+ export {};