You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/spec/metadata-format.md
+176Lines changed: 176 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -79,6 +79,7 @@ Files should use **Snake Case** filenames (e.g., `project_tasks.object.yml`).
79
79
|`description`|`string`| Internal description of the object. |
80
80
|`fields`|`Map`| Dictionary of field definitions. |
81
81
|`actions`|`Map`| Dictionary of custom action definitions. |
82
+
|`customizable`|`boolean`| Whether this object can be modified or deleted. System objects (e.g., `user`, `session`) should be set to `false`. **Default: `true`** (if not specified, the object is customizable). |
82
83
83
84
## 4. Field Definitions
84
85
@@ -103,6 +104,7 @@ fields:
103
104
| `searchable` | `boolean` | Hint to include this field in global search. |
104
105
| `sortable` | `boolean` | Hint that this field can be used for sorting in UI. |
105
106
| `description` | `string` | Help text or documentation for the field. |
107
+
| `customizable` | `boolean` | Whether this field can be modified or deleted. System fields (e.g., `_id`, `createdAt`, `updatedAt`) should be set to `false`. **Default: `true`** (if not specified, the field is customizable). |
106
108
107
109
### 4.2 Supported Field Types
108
110
@@ -664,3 +666,177 @@ settings:
664
666
tabPosition: top
665
667
```
666
668
669
+
## 9. Metadata Protection
670
+
671
+
Similar to Salesforce and other low-code platforms, ObjectQL supports protecting system metadata from modification or deletion. This is crucial for maintaining system integrity when integrating with authentication systems like better-auth.
672
+
673
+
### 9.1 Object-Level Protection
674
+
675
+
Objects can be marked as non-customizable using the `customizable` property:
676
+
677
+
```yaml
678
+
name: user
679
+
description: System user for authentication
680
+
customizable: false # Prevents modification or deletion of this object
681
+
fields:
682
+
email:
683
+
type: email
684
+
required: true
685
+
```
686
+
687
+
When an object is marked as `customizable: false`:
688
+
- The object cannot be deleted using `unregister()`
689
+
- Attempts to modify the object will throw a validation error
690
+
- The object cannot be removed as part of package unregistration
691
+
692
+
**Use Cases:**
693
+
- Authentication objects (user, session, account)
694
+
- Core system objects (organization, member)
695
+
- Third-party integration objects that must maintain a specific schema
696
+
697
+
### 9.2 Field-Level Protection
698
+
699
+
Individual fields can be marked as non-customizable, even within customizable objects:
700
+
701
+
```yaml
702
+
name: user
703
+
customizable: true # Allow adding custom fields
704
+
fields:
705
+
email:
706
+
type: email
707
+
customizable: false # But protect core system field
708
+
createdAt:
709
+
type: datetime
710
+
customizable: false # Protect audit fields
711
+
updatedAt:
712
+
type: datetime
713
+
customizable: false # Protect audit fields
714
+
customField:
715
+
type: text
716
+
customizable: true # Allow modification of custom fields
717
+
```
718
+
719
+
When a field is marked as `customizable: false`:
720
+
- The field cannot be modified or deleted
721
+
- Field properties (type, validation rules, etc.) cannot be changed
722
+
- The field will always appear in the object schema
723
+
724
+
**Common Protected Fields:**
725
+
- `_id` or `id`: Primary key
726
+
- `createdAt`: Record creation timestamp
727
+
- `updatedAt`: Record update timestamp
728
+
- `createdBy`: User who created the record
729
+
- `updatedBy`: User who last updated the record
730
+
731
+
### 9.3 Better-Auth Integration
732
+
733
+
All better-auth objects are marked as non-customizable to ensure authentication system integrity:
734
+
735
+
**Protected Objects:**
736
+
- `user`: User accounts and authentication
737
+
- `account`: OAuth provider accounts
738
+
- `session`: Active user sessions
739
+
- `verification`: Email/phone verification tokens
740
+
- `invitation`: Organization invitations
741
+
- `organization`: Multi-tenant organizations
742
+
- `member`: Organization memberships
743
+
744
+
**Example:**
745
+
```yaml
746
+
# packages/better-auth/src/user.object.yml
747
+
name: user
748
+
description: System user for authentication
749
+
customizable: false
750
+
fields:
751
+
email:
752
+
type: string
753
+
unique: true
754
+
password:
755
+
type: string
756
+
hidden: true
757
+
createdAt:
758
+
type: datetime
759
+
customizable: false
760
+
updatedAt:
761
+
type: datetime
762
+
customizable: false
763
+
```
764
+
765
+
### 9.4 Validation API
766
+
767
+
The MetadataRegistry provides validation methods to check if metadata can be modified:
768
+
769
+
```typescript
770
+
import { MetadataRegistry } from '@objectql/metadata';
0 commit comments