From bb0d1bf6f8aae87edd53f308397b690110cdfcf6 Mon Sep 17 00:00:00 2001 From: Richard Ward Date: Wed, 31 Dec 2025 15:01:48 +0000 Subject: [PATCH] config: schemas,schema,package (3 files) --- schemas/package-schemas/entities.schema.json | 238 +++++++++ schemas/package-schemas/script.schema.json | 480 +++++++++++++++++++ schemas/package-schemas/types.schema.json | 128 +++++ 3 files changed, 846 insertions(+) create mode 100644 schemas/package-schemas/entities.schema.json create mode 100644 schemas/package-schemas/script.schema.json create mode 100644 schemas/package-schemas/types.schema.json diff --git a/schemas/package-schemas/entities.schema.json b/schemas/package-schemas/entities.schema.json new file mode 100644 index 000000000..bc3fb0ea2 --- /dev/null +++ b/schemas/package-schemas/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" + } + } + } + } +} diff --git a/schemas/package-schemas/script.schema.json b/schemas/package-schemas/script.schema.json new file mode 100644 index 000000000..2004c1fac --- /dev/null +++ b/schemas/package-schemas/script.schema.json @@ -0,0 +1,480 @@ +{ + "$schema": "http://json-schema.org/draft-07/schema#", + "$id": "https://metabuilder.dev/schemas/json-script.schema.json", + "title": "JSON Script", + "description": "JSON-based scripting language with runtime interpretation", + "type": "object", + "required": ["schema_version", "package"], + "properties": { + "schema_version": { + "type": "string", + "description": "JSON Script schema version", + "pattern": "^\\d+\\.\\d+\\.\\d+$", + "default": "2.1.0" + }, + "package": { + "type": "string", + "description": "Package identifier" + }, + "description": { + "type": "string", + "description": "Script file description" + }, + "imports": { + "type": "array", + "description": "Imports from other modules", + "items": { + "type": "object", + "required": ["from", "import"], + "properties": { + "from": { + "type": "string", + "description": "Module name to import from" + }, + "import": { + "type": "array", + "description": "List of functions/constants to import", + "items": { "type": "string" } + } + } + } + }, + "exports": { + "type": "object", + "description": "Exported functions and constants", + "properties": { + "functions": { + "type": "array", + "items": { "type": "string" } + }, + "constants": { + "type": "array", + "items": { "type": "string" } + } + } + }, + "constants": { + "type": "array", + "description": "Constant definitions", + "items": { + "$ref": "#/definitions/constant" + } + }, + "functions": { + "type": "array", + "description": "Function definitions", + "items": { + "$ref": "#/definitions/function" + } + } + }, + "definitions": { + "constant": { + "type": "object", + "required": ["id", "name", "value"], + "properties": { + "id": { + "type": "string", + "description": "Unique identifier" + }, + "name": { + "type": "string", + "description": "Constant name (UPPER_CASE)" + }, + "type": { + "type": "string", + "description": "Type annotation" + }, + "value": { + "description": "Constant value" + }, + "exported": { + "type": "boolean", + "description": "Whether constant is exported" + }, + "docstring": { + "$ref": "#/definitions/docstring" + } + } + }, + "function": { + "type": "object", + "required": ["id", "name", "body"], + "properties": { + "id": { + "type": "string", + "description": "Unique identifier" + }, + "name": { + "type": "string", + "description": "Function name" + }, + "description": { + "type": "string", + "description": "Short description" + }, + "async": { + "type": "boolean", + "description": "Whether function is async" + }, + "exported": { + "type": "boolean", + "description": "Whether function is exported" + }, + "params": { + "type": "array", + "description": "Function parameters", + "items": { + "$ref": "#/definitions/parameter" + } + }, + "returnType": { + "type": "string", + "description": "Return type annotation" + }, + "docstring": { + "$ref": "#/definitions/docstring" + }, + "body": { + "type": "array", + "description": "Function body statements", + "items": { + "$ref": "#/definitions/statement" + } + } + } + }, + "parameter": { + "type": "object", + "required": ["name"], + "properties": { + "name": { + "type": "string", + "description": "Parameter name" + }, + "type": { + "type": "string", + "description": "Type annotation" + }, + "optional": { + "type": "boolean", + "description": "Whether parameter is optional" + }, + "default": { + "description": "Default value" + } + } + }, + "docstring": { + "type": "object", + "required": ["summary"], + "properties": { + "summary": { + "type": "string", + "description": "One-line summary", + "maxLength": 200 + }, + "description": { + "type": "string", + "description": "Detailed description" + }, + "params": { + "type": "array", + "items": { + "type": "object", + "required": ["name", "description"], + "properties": { + "name": { "type": "string" }, + "type": { "type": "string" }, + "description": { "type": "string" }, + "optional": { "type": "boolean" }, + "default": {} + } + } + }, + "returns": { + "type": "object", + "required": ["description"], + "properties": { + "type": { "type": "string" }, + "description": { "type": "string" } + } + }, + "examples": { + "type": "array", + "items": { + "type": "object", + "required": ["title", "code"], + "properties": { + "title": { "type": "string" }, + "code": { "type": "string" } + } + } + }, + "throws": { + "type": "array", + "items": { + "type": "object", + "required": ["type", "description"], + "properties": { + "type": { "type": "string" }, + "description": { "type": "string" } + } + } + }, + "see": { + "type": "array", + "items": { "type": "string" } + }, + "since": { "type": "string" }, + "deprecated": { + "oneOf": [ + { "type": "boolean" }, + { + "type": "object", + "properties": { + "version": { "type": "string" }, + "reason": { "type": "string" }, + "alternative": { "type": "string" } + } + } + ] + }, + "author": { "type": "string" }, + "version": { "type": "string" }, + "tags": { + "type": "array", + "items": { "type": "string" } + }, + "internal": { "type": "boolean" } + } + }, + "statement": { + "oneOf": [ + { "$ref": "#/definitions/comment" }, + { "$ref": "#/definitions/const_declaration" }, + { "$ref": "#/definitions/let_declaration" }, + { "$ref": "#/definitions/assignment" }, + { "$ref": "#/definitions/if_statement" }, + { "$ref": "#/definitions/for_each_loop" }, + { "$ref": "#/definitions/try_catch" }, + { "$ref": "#/definitions/return_statement" } + ] + }, + "comment": { + "type": "object", + "required": ["type", "text"], + "properties": { + "type": { "const": "comment" }, + "text": { "type": "string" } + } + }, + "const_declaration": { + "type": "object", + "required": ["type", "name", "value"], + "properties": { + "type": { "const": "const_declaration" }, + "name": { "type": "string" }, + "value": { "$ref": "#/definitions/expression" } + } + }, + "let_declaration": { + "type": "object", + "required": ["type", "name", "value"], + "properties": { + "type": { "const": "let_declaration" }, + "name": { "type": "string" }, + "value": { "$ref": "#/definitions/expression" } + } + }, + "assignment": { + "type": "object", + "required": ["type", "target", "value"], + "properties": { + "type": { "const": "assignment" }, + "target": { "type": "string" }, + "value": { "$ref": "#/definitions/expression" } + } + }, + "if_statement": { + "type": "object", + "required": ["type", "condition", "then"], + "properties": { + "type": { "const": "if_statement" }, + "condition": { "$ref": "#/definitions/expression" }, + "then": { + "type": "array", + "items": { "$ref": "#/definitions/statement" } + }, + "else": { + "type": "array", + "items": { "$ref": "#/definitions/statement" } + } + } + }, + "for_each_loop": { + "type": "object", + "required": ["type", "iterator", "iterable", "body"], + "properties": { + "type": { "const": "for_each_loop" }, + "iterator": { "type": "string" }, + "iterable": { "$ref": "#/definitions/expression" }, + "body": { + "type": "array", + "items": { "$ref": "#/definitions/statement" } + } + } + }, + "try_catch": { + "type": "object", + "required": ["type", "try"], + "properties": { + "type": { "const": "try_catch" }, + "try": { + "type": "array", + "items": { "$ref": "#/definitions/statement" } + }, + "catch": { + "type": "object", + "required": ["param", "body"], + "properties": { + "param": { "type": "string" }, + "body": { + "type": "array", + "items": { "$ref": "#/definitions/statement" } + } + } + }, + "finally": { + "type": "array", + "items": { "$ref": "#/definitions/statement" } + } + } + }, + "return_statement": { + "type": "object", + "required": ["type", "value"], + "properties": { + "type": { "const": "return" }, + "value": { "$ref": "#/definitions/expression" } + } + }, + "expression": { + "oneOf": [ + { "type": "string" }, + { "type": "number" }, + { "type": "boolean" }, + { "type": "null" }, + { "$ref": "#/definitions/binary_expression" }, + { "$ref": "#/definitions/logical_expression" }, + { "$ref": "#/definitions/unary_expression" }, + { "$ref": "#/definitions/conditional_expression" }, + { "$ref": "#/definitions/call_expression" }, + { "$ref": "#/definitions/member_access" }, + { "$ref": "#/definitions/template_literal" }, + { "$ref": "#/definitions/object_literal" }, + { "$ref": "#/definitions/array_literal" } + ] + }, + "binary_expression": { + "type": "object", + "required": ["type", "left", "operator", "right"], + "properties": { + "type": { "const": "binary_expression" }, + "left": { "$ref": "#/definitions/expression" }, + "operator": { + "enum": ["+", "-", "*", "/", "%", "==", "!=", "<", ">", "<=", ">="] + }, + "right": { "$ref": "#/definitions/expression" } + } + }, + "logical_expression": { + "type": "object", + "required": ["type", "left", "operator", "right"], + "properties": { + "type": { "const": "logical_expression" }, + "left": { "$ref": "#/definitions/expression" }, + "operator": { "enum": ["&&", "||", "??"] }, + "right": { "$ref": "#/definitions/expression" } + } + }, + "unary_expression": { + "type": "object", + "required": ["type", "operator", "argument"], + "properties": { + "type": { "const": "unary_expression" }, + "operator": { "enum": ["!", "-", "+", "~", "typeof", "void"] }, + "argument": { "$ref": "#/definitions/expression" } + } + }, + "conditional_expression": { + "type": "object", + "required": ["type", "test", "consequent", "alternate"], + "properties": { + "type": { "const": "conditional_expression" }, + "test": { "$ref": "#/definitions/expression" }, + "consequent": { "$ref": "#/definitions/expression" }, + "alternate": { "$ref": "#/definitions/expression" } + } + }, + "call_expression": { + "type": "object", + "required": ["type", "callee", "args"], + "properties": { + "type": { "const": "call_expression" }, + "callee": { "$ref": "#/definitions/expression" }, + "args": { + "type": "array", + "items": { "$ref": "#/definitions/expression" } + } + } + }, + "member_access": { + "type": "object", + "required": ["type", "object", "property"], + "properties": { + "type": { "const": "member_access" }, + "object": { "$ref": "#/definitions/expression" }, + "property": { + "oneOf": [ + { "type": "string" }, + { "$ref": "#/definitions/expression" } + ] + }, + "computed": { "type": "boolean" }, + "optional": { "type": "boolean" } + } + }, + "template_literal": { + "type": "object", + "required": ["type", "template"], + "properties": { + "type": { "const": "template_literal" }, + "template": { "type": "string" }, + "values": { "type": "object" } + } + }, + "object_literal": { + "type": "object", + "required": ["type", "properties"], + "properties": { + "type": { "const": "object_literal" }, + "properties": { + "type": "object", + "additionalProperties": { "$ref": "#/definitions/expression" } + } + } + }, + "array_literal": { + "type": "object", + "required": ["type", "elements"], + "properties": { + "type": { "const": "array_literal" }, + "elements": { + "type": "array", + "items": { "$ref": "#/definitions/expression" } + } + } + } + } +} diff --git a/schemas/package-schemas/types.schema.json b/schemas/package-schemas/types.schema.json new file mode 100644 index 000000000..7b164bac8 --- /dev/null +++ b/schemas/package-schemas/types.schema.json @@ -0,0 +1,128 @@ +{ + "$schema": "http://json-schema.org/draft-07/schema#", + "$id": "https://metabuilder.dev/schemas/json-script-types.schema.json", + "title": "JSON Script Types", + "description": "TypeScript-style type definitions for JSON scripts", + "type": "object", + "required": ["schema_version", "package", "types"], + "properties": { + "schema_version": { + "type": "string", + "description": "Schema version", + "pattern": "^\\d+\\.\\d+\\.\\d+$" + }, + "package": { + "type": "string", + "description": "Package identifier" + }, + "description": { + "type": "string", + "description": "Type file description" + }, + "types": { + "type": "array", + "description": "Type definitions", + "items": { + "$ref": "#/definitions/typeDefinition" + } + }, + "exports": { + "type": "object", + "properties": { + "types": { + "type": "array", + "items": { "type": "string" } + } + } + } + }, + "definitions": { + "typeDefinition": { + "type": "object", + "required": ["id", "name", "type"], + "properties": { + "id": { + "type": "string", + "description": "Unique identifier" + }, + "name": { + "type": "string", + "description": "Type name (PascalCase)" + }, + "type": { + "type": "string", + "description": "Base type", + "enum": ["object", "string", "number", "boolean", "array", "null", "any"] + }, + "exported": { + "type": "boolean", + "description": "Whether type is exported" + }, + "description": { + "type": "string", + "description": "Type description" + }, + "docstring": { + "type": "object", + "properties": { + "summary": { "type": "string" }, + "description": { "type": "string" }, + "examples": { + "type": "array", + "items": { + "type": "object", + "properties": { + "title": { "type": "string" }, + "code": { "type": "string" } + } + } + }, + "see": { + "type": "array", + "items": { "type": "string" } + }, + "since": { "type": "string" } + } + }, + "properties": { + "type": "object", + "description": "Object type properties", + "additionalProperties": { + "$ref": "#/definitions/propertyDefinition" + } + }, + "enum": { + "type": "array", + "description": "Enum values", + "items": { "type": "string" } + }, + "additionalProperties": { + "type": "object", + "description": "Schema for dynamic keys", + "properties": { + "type": { "type": "string" }, + "description": { "type": "string" } + } + } + } + }, + "propertyDefinition": { + "type": "object", + "required": ["type"], + "properties": { + "type": { + "type": "string", + "description": "Property type" + }, + "required": { + "type": "boolean", + "description": "Whether property is required" + }, + "description": { + "type": "string", + "description": "Property description" + } + } + } + } +}