Files
metabuilder/packages/json_script_example/seed/script.schema.json
2025-12-31 13:53:37 +00:00

481 lines
14 KiB
JSON

{
"$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" }
}
}
}
}
}