Skip to content

Commit 10a3f4e

Browse files
Copilothuangyiirene
andcommitted
Create metamodel interfaces: ObjectEntity, ObjectField, ObjectView
Co-authored-by: huangyiirene <7665279+huangyiirene@users.noreply.github.com>
1 parent 8539108 commit 10a3f4e

13 files changed

Lines changed: 1601 additions & 1 deletion

.gitignore

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Dependencies
2+
node_modules/
3+
4+
# Build output
5+
dist/
6+
*.tsbuildinfo
7+
8+
# IDE
9+
.vscode/
10+
.idea/
11+
*.swp
12+
*.swo
13+
*~
14+
15+
# OS
16+
.DS_Store
17+
Thumbs.db
18+
19+
# Logs
20+
*.log
21+
npm-debug.log*
22+
yarn-debug.log*
23+
yarn-error.log*
24+
25+
# Testing
26+
coverage/
27+
28+
# Temporary files
29+
tmp/
30+
temp/

README.md

Lines changed: 154 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,154 @@
1-
# spec
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

package-lock.json

Lines changed: 30 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
{
2+
"name": "@objectstack/spec",
3+
"version": "0.1.0",
4+
"description": "ObjectStack Protocol & Specification - Type definitions and schemas",
5+
"main": "dist/index.js",
6+
"types": "dist/index.d.ts",
7+
"files": [
8+
"dist",
9+
"src"
10+
],
11+
"scripts": {
12+
"build": "tsc",
13+
"clean": "rm -rf dist"
14+
},
15+
"keywords": [
16+
"objectstack",
17+
"specification",
18+
"types",
19+
"metamodel"
20+
],
21+
"author": "ObjectStack",
22+
"license": "MIT",
23+
"devDependencies": {
24+
"typescript": "^5.9.3"
25+
}
26+
}

0 commit comments

Comments
 (0)