@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.
package/README.md ADDED
@@ -0,0 +1,154 @@
1
+ # ObjectStack Specification
2
+
3
+ The ObjectStack Protocol & Specification repository defines the core type definitions and interfaces for the ObjectStack ecosystem. This repository serves as the "Constitution" of the system, providing the contract between backend (ObjectQL) parsers and frontend (ObjectUI) renderers.
4
+
5
+ ## Purpose
6
+
7
+ This repository contains:
8
+ - **TypeScript Interfaces**: Shared types for the entire ObjectStack ecosystem
9
+ - **No Logic**: Only type definitions, no runtime code or business logic
10
+ - **Universal Compatibility**: Works in Node.js, Browser, and Electron environments
11
+
12
+ ## Metamodel Interfaces
13
+
14
+ The metamodel defines the structure for describing data models in ObjectStack:
15
+
16
+ ### Core Interfaces
17
+
18
+ #### `FieldType`
19
+ Defines the available field data types:
20
+ - Text types: `text`, `textarea`, `email`, `url`
21
+ - Numeric types: `number`, `currency`, `percentage`
22
+ - Date/Time types: `date`, `datetime`
23
+ - Relation types: `lookup`
24
+ - Selection types: `select`, `multiselect`
25
+ - Special types: `boolean`, `json`, `file`, `image`
26
+
27
+ #### `ObjectField`
28
+ Represents a field definition within an entity:
29
+ ```typescript
30
+ interface ObjectField {
31
+ name: string; // Field identifier
32
+ label: string; // Display label
33
+ type: FieldType; // Data type
34
+ required?: boolean; // Validation
35
+ unique?: boolean; // Constraint
36
+ lookupEntity?: string; // For lookup fields
37
+ // ... and more options
38
+ }
39
+ ```
40
+
41
+ #### `ObjectEntity`
42
+ Represents a complete entity (data model) definition:
43
+ ```typescript
44
+ interface ObjectEntity {
45
+ name: string; // Entity identifier
46
+ label: string; // Singular display label
47
+ pluralLabel: string; // Plural display label
48
+ fields: ObjectField[]; // Field definitions
49
+ primaryKey?: string; // Primary key field
50
+ displayField?: string; // Display field for lookups
51
+ // ... and more options
52
+ }
53
+ ```
54
+
55
+ #### `ObjectView`
56
+ Represents a view configuration for presenting entity data:
57
+ ```typescript
58
+ interface ObjectView {
59
+ name: string; // View identifier
60
+ label: string; // Display label
61
+ entityName: string; // Target entity
62
+ type: ViewType; // Presentation type (list, form, detail, etc.)
63
+ fields?: string[]; // Fields to display
64
+ columns?: ViewColumn[]; // Column configuration
65
+ filters?: ViewFilter[]; // Default filters
66
+ sort?: ViewSort[]; // Default sort order
67
+ // ... and more options
68
+ }
69
+ ```
70
+
71
+ ## Usage
72
+
73
+ ### Installation
74
+
75
+ ```bash
76
+ npm install @objectstack/spec
77
+ ```
78
+
79
+ ### Importing Types
80
+
81
+ ```typescript
82
+ // Import all metamodel types
83
+ import { ObjectEntity, ObjectField, ObjectView, FieldType } from '@objectstack/spec';
84
+
85
+ // Or import specific types
86
+ import type { ObjectEntity } from '@objectstack/spec';
87
+ ```
88
+
89
+ ### Example: Defining an Entity
90
+
91
+ ```typescript
92
+ import { ObjectEntity, ObjectField } from '@objectstack/spec';
93
+
94
+ const userEntity: ObjectEntity = {
95
+ name: 'User',
96
+ label: 'User',
97
+ pluralLabel: 'Users',
98
+ description: 'System user account',
99
+ fields: [
100
+ {
101
+ name: 'id',
102
+ label: 'ID',
103
+ type: 'text',
104
+ required: true,
105
+ readonly: true
106
+ },
107
+ {
108
+ name: 'email',
109
+ label: 'Email',
110
+ type: 'email',
111
+ required: true,
112
+ unique: true
113
+ },
114
+ {
115
+ name: 'name',
116
+ label: 'Full Name',
117
+ type: 'text',
118
+ required: true
119
+ },
120
+ {
121
+ name: 'role',
122
+ label: 'Role',
123
+ type: 'select',
124
+ required: true,
125
+ options: [
126
+ { value: 'admin', label: 'Administrator' },
127
+ { value: 'user', label: 'User' }
128
+ ]
129
+ }
130
+ ],
131
+ primaryKey: 'id',
132
+ displayField: 'name'
133
+ };
134
+ ```
135
+
136
+ ## Building
137
+
138
+ ```bash
139
+ npm install
140
+ npm run build
141
+ ```
142
+
143
+ This will compile TypeScript files to JavaScript and generate type declarations in the `dist/` directory.
144
+
145
+ ## Philosophy
146
+
147
+ Following the ObjectStack Protocol:
148
+ - **Strict Types, No Logic**: This repository contains only type definitions
149
+ - **Documentation as Code**: Every interface property has TSDoc comments for IntelliSense
150
+ - **Universal Compatibility**: Pure TypeScript with no platform-specific dependencies
151
+
152
+ ## License
153
+
154
+ MIT
@@ -0,0 +1,28 @@
1
+ /**
2
+ * Example Usage of ObjectStack Metamodel
3
+ *
4
+ * This file demonstrates how to use the metamodel interfaces
5
+ * to define entities and views.
6
+ */
7
+ import type { ObjectEntity, ObjectView } from './types/meta';
8
+ /**
9
+ * Example: User Entity Definition
10
+ */
11
+ export declare const UserEntity: ObjectEntity;
12
+ /**
13
+ * Example: All Users List View
14
+ */
15
+ export declare const AllUsersView: ObjectView;
16
+ /**
17
+ * Example: Active Users View (with filter)
18
+ */
19
+ export declare const ActiveUsersView: ObjectView;
20
+ /**
21
+ * Example: User Form View
22
+ */
23
+ export declare const UserFormView: ObjectView;
24
+ /**
25
+ * Example: Product Entity with Lookup
26
+ */
27
+ export declare const ProductEntity: ObjectEntity;
28
+ //# sourceMappingURL=examples.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"examples.d.ts","sourceRoot":"","sources":["../src/examples.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAE7D;;GAEG;AACH,eAAO,MAAM,UAAU,EAAE,YAgExB,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,YAAY,EAAE,UA+C1B,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,eAAe,EAAE,UAiC7B,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,YAAY,EAAE,UAsB1B,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,aAAa,EAAE,YA0D3B,CAAC"}
@@ -0,0 +1,250 @@
1
+ /**
2
+ * Example Usage of ObjectStack Metamodel
3
+ *
4
+ * This file demonstrates how to use the metamodel interfaces
5
+ * to define entities and views.
6
+ */
7
+ /**
8
+ * Example: User Entity Definition
9
+ */
10
+ export const UserEntity = {
11
+ name: 'User',
12
+ label: 'User',
13
+ pluralLabel: 'Users',
14
+ description: 'System user account',
15
+ fields: [
16
+ {
17
+ name: 'id',
18
+ label: 'ID',
19
+ type: 'text',
20
+ required: true,
21
+ readonly: true,
22
+ },
23
+ {
24
+ name: 'email',
25
+ label: 'Email Address',
26
+ type: 'email',
27
+ required: true,
28
+ unique: true,
29
+ maxLength: 255,
30
+ },
31
+ {
32
+ name: 'name',
33
+ label: 'Full Name',
34
+ type: 'text',
35
+ required: true,
36
+ maxLength: 100,
37
+ },
38
+ {
39
+ name: 'role',
40
+ label: 'Role',
41
+ type: 'select',
42
+ required: true,
43
+ options: [
44
+ { value: 'admin', label: 'Administrator' },
45
+ { value: 'editor', label: 'Editor' },
46
+ { value: 'viewer', label: 'Viewer' },
47
+ ],
48
+ },
49
+ {
50
+ name: 'status',
51
+ label: 'Status',
52
+ type: 'select',
53
+ required: true,
54
+ defaultValue: 'active',
55
+ options: [
56
+ { value: 'active', label: 'Active' },
57
+ { value: 'inactive', label: 'Inactive' },
58
+ { value: 'suspended', label: 'Suspended' },
59
+ ],
60
+ },
61
+ {
62
+ name: 'createdAt',
63
+ label: 'Created At',
64
+ type: 'datetime',
65
+ readonly: true,
66
+ },
67
+ ],
68
+ primaryKey: 'id',
69
+ displayField: 'name',
70
+ icon: 'user',
71
+ auditable: true,
72
+ searchable: true,
73
+ searchableFields: ['name', 'email'],
74
+ };
75
+ /**
76
+ * Example: All Users List View
77
+ */
78
+ export const AllUsersView = {
79
+ name: 'all_users',
80
+ label: 'All Users',
81
+ entityName: 'User',
82
+ type: 'list',
83
+ description: 'View all users in the system',
84
+ columns: [
85
+ {
86
+ field: 'name',
87
+ label: 'Name',
88
+ width: '25%',
89
+ sortable: true,
90
+ },
91
+ {
92
+ field: 'email',
93
+ label: 'Email',
94
+ width: '30%',
95
+ sortable: true,
96
+ },
97
+ {
98
+ field: 'role',
99
+ label: 'Role',
100
+ width: '15%',
101
+ sortable: true,
102
+ },
103
+ {
104
+ field: 'status',
105
+ label: 'Status',
106
+ width: '15%',
107
+ sortable: true,
108
+ },
109
+ {
110
+ field: 'createdAt',
111
+ label: 'Created',
112
+ width: '15%',
113
+ sortable: true,
114
+ format: 'date:MM/DD/YYYY',
115
+ },
116
+ ],
117
+ sort: [
118
+ {
119
+ field: 'name',
120
+ direction: 'asc',
121
+ },
122
+ ],
123
+ pageSize: 25,
124
+ default: true,
125
+ };
126
+ /**
127
+ * Example: Active Users View (with filter)
128
+ */
129
+ export const ActiveUsersView = {
130
+ name: 'active_users',
131
+ label: 'Active Users',
132
+ entityName: 'User',
133
+ type: 'list',
134
+ description: 'View only active users',
135
+ columns: [
136
+ {
137
+ field: 'name',
138
+ width: '30%',
139
+ },
140
+ {
141
+ field: 'email',
142
+ width: '40%',
143
+ },
144
+ {
145
+ field: 'role',
146
+ width: '30%',
147
+ },
148
+ ],
149
+ filters: [
150
+ {
151
+ field: 'status',
152
+ operator: 'equals',
153
+ value: 'active',
154
+ },
155
+ ],
156
+ sort: [
157
+ {
158
+ field: 'name',
159
+ direction: 'asc',
160
+ },
161
+ ],
162
+ };
163
+ /**
164
+ * Example: User Form View
165
+ */
166
+ export const UserFormView = {
167
+ name: 'user_form',
168
+ label: 'User Form',
169
+ entityName: 'User',
170
+ type: 'form',
171
+ description: 'Form for creating and editing users',
172
+ fields: ['name', 'email', 'role', 'status'],
173
+ layout: {
174
+ type: 'sections',
175
+ sections: [
176
+ {
177
+ id: 'basic',
178
+ title: 'Basic Information',
179
+ fields: ['name', 'email'],
180
+ },
181
+ {
182
+ id: 'settings',
183
+ title: 'Settings',
184
+ fields: ['role', 'status'],
185
+ },
186
+ ],
187
+ },
188
+ };
189
+ /**
190
+ * Example: Product Entity with Lookup
191
+ */
192
+ export const ProductEntity = {
193
+ name: 'Product',
194
+ label: 'Product',
195
+ pluralLabel: 'Products',
196
+ description: 'Product catalog',
197
+ fields: [
198
+ {
199
+ name: 'id',
200
+ label: 'ID',
201
+ type: 'text',
202
+ required: true,
203
+ readonly: true,
204
+ },
205
+ {
206
+ name: 'name',
207
+ label: 'Product Name',
208
+ type: 'text',
209
+ required: true,
210
+ maxLength: 200,
211
+ },
212
+ {
213
+ name: 'description',
214
+ label: 'Description',
215
+ type: 'textarea',
216
+ maxLength: 1000,
217
+ },
218
+ {
219
+ name: 'price',
220
+ label: 'Price',
221
+ type: 'currency',
222
+ required: true,
223
+ min: 0,
224
+ },
225
+ {
226
+ name: 'category',
227
+ label: 'Category',
228
+ type: 'lookup',
229
+ required: true,
230
+ lookupEntity: 'Category',
231
+ lookupDisplayField: 'name',
232
+ },
233
+ {
234
+ name: 'inStock',
235
+ label: 'In Stock',
236
+ type: 'boolean',
237
+ defaultValue: true,
238
+ },
239
+ {
240
+ name: 'image',
241
+ label: 'Product Image',
242
+ type: 'image',
243
+ },
244
+ ],
245
+ primaryKey: 'id',
246
+ displayField: 'name',
247
+ icon: 'package',
248
+ searchable: true,
249
+ searchableFields: ['name', 'description'],
250
+ };
@@ -0,0 +1,10 @@
1
+ /**
2
+ * ObjectStack Specification
3
+ *
4
+ * This module provides the core type definitions and interfaces for the ObjectStack ecosystem.
5
+ * It defines the contract between backend (ObjectQL) parsers and frontend (ObjectUI) renderers.
6
+ *
7
+ * @packageDocumentation
8
+ */
9
+ export * from './types';
10
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,cAAc,SAAS,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,9 @@
1
+ /**
2
+ * ObjectStack Specification
3
+ *
4
+ * This module provides the core type definitions and interfaces for the ObjectStack ecosystem.
5
+ * It defines the contract between backend (ObjectQL) parsers and frontend (ObjectUI) renderers.
6
+ *
7
+ * @packageDocumentation
8
+ */
9
+ export * from './types';
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Type Definitions
3
+ *
4
+ * This module exports all type definitions used in the ObjectStack specification.
5
+ *
6
+ * @module types
7
+ */
8
+ export * from './meta';
9
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,cAAc,QAAQ,CAAC"}
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Type Definitions
3
+ *
4
+ * This module exports all type definitions used in the ObjectStack specification.
5
+ *
6
+ * @module types
7
+ */
8
+ export * from './meta';
@@ -0,0 +1,54 @@
1
+ /**
2
+ * Field Type Definitions
3
+ *
4
+ * Defines the available field types in the ObjectStack metamodel.
5
+ * These types determine how fields are stored, validated, and rendered.
6
+ *
7
+ * @module types/meta/field-type
8
+ */
9
+ /**
10
+ * Available field types in the ObjectStack metamodel.
11
+ *
12
+ * @remarks
13
+ * Each field type corresponds to specific storage, validation, and rendering behavior:
14
+ *
15
+ * - `text`: Short text strings (single line)
16
+ * - `textarea`: Long text content (multi-line)
17
+ * - `number`: Numeric values (integer or decimal)
18
+ * - `boolean`: True/false values (checkbox)
19
+ * - `date`: Date values (without time)
20
+ * - `datetime`: Date and time values
21
+ * - `email`: Email address with validation
22
+ * - `url`: URL with validation
23
+ * - `lookup`: Reference to another entity (foreign key)
24
+ * - `select`: Single selection from predefined options
25
+ * - `multiselect`: Multiple selections from predefined options
26
+ * - `json`: Arbitrary JSON data structure
27
+ * - `file`: File attachment reference
28
+ * - `image`: Image file reference with preview
29
+ * - `currency`: Monetary values with precision
30
+ * - `percentage`: Percentage values (0-100)
31
+ *
32
+ * @example
33
+ * ```typescript
34
+ * const nameField: FieldType = 'text';
35
+ * const priceField: FieldType = 'currency';
36
+ * const ownerField: FieldType = 'lookup';
37
+ * ```
38
+ */
39
+ export type FieldType = 'text' | 'textarea' | 'number' | 'boolean' | 'date' | 'datetime' | 'email' | 'url' | 'lookup' | 'select' | 'multiselect' | 'json' | 'file' | 'image' | 'currency' | 'percentage';
40
+ /**
41
+ * Type guard to check if a string is a valid FieldType
42
+ *
43
+ * @param value - The value to check
44
+ * @returns True if the value is a valid FieldType
45
+ *
46
+ * @example
47
+ * ```typescript
48
+ * if (isFieldType('text')) {
49
+ * // value is a valid FieldType
50
+ * }
51
+ * ```
52
+ */
53
+ export declare function isFieldType(value: unknown): value is FieldType;
54
+ //# sourceMappingURL=field-type.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"field-type.d.ts","sourceRoot":"","sources":["../../../src/types/meta/field-type.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,MAAM,MAAM,SAAS,GACjB,MAAM,GACN,UAAU,GACV,QAAQ,GACR,SAAS,GACT,MAAM,GACN,UAAU,GACV,OAAO,GACP,KAAK,GACL,QAAQ,GACR,QAAQ,GACR,aAAa,GACb,MAAM,GACN,MAAM,GACN,OAAO,GACP,UAAU,GACV,YAAY,CAAC;AAEjB;;;;;;;;;;;;GAYG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,SAAS,CAoB9D"}
@@ -0,0 +1,42 @@
1
+ /**
2
+ * Field Type Definitions
3
+ *
4
+ * Defines the available field types in the ObjectStack metamodel.
5
+ * These types determine how fields are stored, validated, and rendered.
6
+ *
7
+ * @module types/meta/field-type
8
+ */
9
+ /**
10
+ * Type guard to check if a string is a valid FieldType
11
+ *
12
+ * @param value - The value to check
13
+ * @returns True if the value is a valid FieldType
14
+ *
15
+ * @example
16
+ * ```typescript
17
+ * if (isFieldType('text')) {
18
+ * // value is a valid FieldType
19
+ * }
20
+ * ```
21
+ */
22
+ export function isFieldType(value) {
23
+ const validTypes = [
24
+ 'text',
25
+ 'textarea',
26
+ 'number',
27
+ 'boolean',
28
+ 'date',
29
+ 'datetime',
30
+ 'email',
31
+ 'url',
32
+ 'lookup',
33
+ 'select',
34
+ 'multiselect',
35
+ 'json',
36
+ 'file',
37
+ 'image',
38
+ 'currency',
39
+ 'percentage',
40
+ ];
41
+ return typeof value === 'string' && validTypes.includes(value);
42
+ }
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Metamodel Type Definitions
3
+ *
4
+ * This module defines the core metamodel interfaces that form the contract
5
+ * between the backend (ObjectQL) parser and the frontend (ObjectUI) renderer.
6
+ *
7
+ * @module types/meta
8
+ */
9
+ export * from './field-type';
10
+ export * from './object-field';
11
+ export * from './object-entity';
12
+ export * from './object-view';
13
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/types/meta/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,cAAc,cAAc,CAAC;AAC7B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,iBAAiB,CAAC;AAChC,cAAc,eAAe,CAAC"}
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Metamodel Type Definitions
3
+ *
4
+ * This module defines the core metamodel interfaces that form the contract
5
+ * between the backend (ObjectQL) parser and the frontend (ObjectUI) renderer.
6
+ *
7
+ * @module types/meta
8
+ */
9
+ export * from './field-type';
10
+ export * from './object-field';
11
+ export * from './object-entity';
12
+ export * from './object-view';