From 268208311fc983864336e8e214726465e5d6e2c8 Mon Sep 17 00:00:00 2001 From: Richard Ward Date: Wed, 31 Dec 2025 14:27:55 +0000 Subject: [PATCH] config: json,script,schema (1 files) --- .../seed/schema/entities.schema.json | 238 ++++++++++++++++++ 1 file changed, 238 insertions(+) create mode 100644 packages/json_script_example/seed/schema/entities.schema.json diff --git a/packages/json_script_example/seed/schema/entities.schema.json b/packages/json_script_example/seed/schema/entities.schema.json new file mode 100644 index 000000000..bc3fb0ea2 --- /dev/null +++ b/packages/json_script_example/seed/schema/entities.schema.json @@ -0,0 +1,238 @@ +{ + "$schema": "http://json-schema.org/draft-07/schema#", + "$id": "https://metabuilder.dev/schemas/entities.schema.json", + "title": "Entity Schema Definition", + "description": "Database entity definitions for MetaBuilder packages", + "type": "object", + "required": ["entities"], + "properties": { + "entities": { + "type": "array", + "description": "Array of entity definitions", + "items": { + "$ref": "#/definitions/entity" + } + } + }, + "definitions": { + "entity": { + "type": "object", + "required": ["name", "version", "fields"], + "properties": { + "name": { + "type": "string", + "description": "Entity name in PascalCase", + "pattern": "^[A-Z][a-zA-Z0-9]*$" + }, + "version": { + "type": "string", + "description": "Entity schema version", + "pattern": "^\\d+\\.\\d+$" + }, + "description": { + "type": "string", + "description": "Entity description" + }, + "checksum": { + "type": ["string", "null"], + "description": "Entity checksum for migration tracking" + }, + "fields": { + "type": "object", + "description": "Entity field definitions", + "additionalProperties": { + "$ref": "#/definitions/field" + }, + "minProperties": 1 + }, + "indexes": { + "type": "array", + "description": "Index definitions", + "items": { + "$ref": "#/definitions/index" + } + }, + "relations": { + "type": "array", + "description": "Relationship definitions", + "items": { + "$ref": "#/definitions/relation" + } + }, + "acl": { + "type": "object", + "description": "Access control rules", + "properties": { + "create": { + "type": "array", + "items": { "type": "string" }, + "description": "Roles allowed to create" + }, + "read": { + "type": "array", + "items": { "type": "string" }, + "description": "Roles allowed to read" + }, + "update": { + "type": "array", + "items": { "type": "string" }, + "description": "Roles allowed to update" + }, + "delete": { + "type": "array", + "items": { "type": "string" }, + "description": "Roles allowed to delete" + }, + "rowLevel": { + "type": "string", + "description": "Row-level security expression" + } + } + } + } + }, + "field": { + "type": "object", + "required": ["type"], + "properties": { + "type": { + "type": "string", + "enum": [ + "string", + "int", + "bigint", + "float", + "double", + "boolean", + "json", + "date", + "datetime", + "timestamp", + "cuid", + "uuid", + "text", + "blob" + ], + "description": "Field data type" + }, + "primary": { + "type": "boolean", + "description": "Whether this is a primary key" + }, + "generated": { + "type": "boolean", + "description": "Whether this field is auto-generated" + }, + "required": { + "type": "boolean", + "description": "Whether this field is required" + }, + "nullable": { + "type": "boolean", + "description": "Whether this field can be null" + }, + "unique": { + "type": "boolean", + "description": "Whether this field must be unique" + }, + "index": { + "type": "boolean", + "description": "Whether to create an index on this field" + }, + "default": { + "description": "Default value for this field" + }, + "maxLength": { + "type": "integer", + "description": "Maximum length for string fields" + }, + "minLength": { + "type": "integer", + "description": "Minimum length for string fields" + }, + "min": { + "type": "number", + "description": "Minimum value for numeric fields" + }, + "max": { + "type": "number", + "description": "Maximum value for numeric fields" + }, + "enum": { + "type": "array", + "items": { "type": "string" }, + "description": "Allowed enum values" + }, + "pattern": { + "type": "string", + "description": "Regex pattern for validation" + }, + "description": { + "type": "string", + "description": "Field description" + } + } + }, + "index": { + "type": "object", + "required": ["fields"], + "properties": { + "fields": { + "type": "array", + "items": { "type": "string" }, + "description": "Fields to include in this index", + "minItems": 1 + }, + "unique": { + "type": "boolean", + "description": "Whether this is a unique index" + }, + "name": { + "type": "string", + "description": "Index name" + } + } + }, + "relation": { + "type": "object", + "required": ["name", "type", "entity"], + "properties": { + "name": { + "type": "string", + "description": "Relation name" + }, + "type": { + "type": "string", + "enum": ["belongsTo", "hasMany", "hasOne", "manyToMany"], + "description": "Relationship type" + }, + "entity": { + "type": "string", + "description": "Related entity name" + }, + "field": { + "type": "string", + "description": "Foreign key field (for belongsTo)" + }, + "foreignKey": { + "type": "string", + "description": "Foreign key field on related entity (for hasMany/hasOne)" + }, + "through": { + "type": "string", + "description": "Junction table (for manyToMany)" + }, + "onDelete": { + "type": "string", + "enum": ["Cascade", "SetNull", "Restrict", "NoAction"], + "description": "Action on delete" + }, + "onUpdate": { + "type": "string", + "enum": ["Cascade", "SetNull", "Restrict", "NoAction"], + "description": "Action on update" + } + } + } + } +}