Files
metabuilder/schemas/package-schemas/validation_schema.json

503 lines
15 KiB
JSON

{
"$schema": "http://json-schema.org/draft-07/schema#",
"$id": "https://metabuilder.dev/schemas/json-script-validation.schema.json",
"title": "JSON Script Validation Functions",
"description": "Validation utility function definitions for JSON scripts",
"type": "object",
"required": ["schemaVersion", "package"],
"properties": {
"$schema": {
"type": "string",
"description": "JSON Schema reference"
},
"schemaVersion": {
"type": "string",
"description": "Schema version",
"pattern": "^\\d+\\.\\d+\\.\\d+$",
"default": "2.0.0"
},
"package": {
"type": "string",
"description": "Package identifier"
},
"description": {
"type": "string",
"description": "Validation module description"
},
"imports": {
"type": "array",
"description": "Module imports",
"items": {
"$ref": "#/definitions/import"
}
},
"exports": {
"type": "object",
"description": "Exported validation functions and patterns",
"properties": {
"functions": {
"type": "array",
"items": { "type": "string" }
},
"patterns": {
"type": "array",
"items": { "type": "string" }
}
}
},
"patterns": {
"type": "object",
"description": "Reusable validation patterns",
"properties": {
"email": {
"type": "string",
"description": "Email validation regex",
"default": "^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,}$"
},
"url": {
"type": "string",
"description": "URL validation regex",
"default": "^https?:\\/\\/(www\\.)?[-a-zA-Z0-9@:%._\\+~#=]{1,256}\\.[a-zA-Z0-9()]{1,6}\\b([-a-zA-Z0-9()@:%_\\+.~#?&//=]*)$"
},
"uuid": {
"type": "string",
"description": "UUID validation regex",
"default": "^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$"
},
"phoneUS": {
"type": "string",
"description": "US phone number regex",
"default": "^[+]?1?[-\\s.]?\\(?([0-9]{3})\\)?[-\\s.]?([0-9]{3})[-\\s.]?([0-9]{4})$"
},
"zipUS": {
"type": "string",
"description": "US ZIP code regex",
"default": "^[0-9]{5}(-[0-9]{4})?$"
},
"creditCard": {
"type": "string",
"description": "Credit card validation regex (Luhn check required separately)",
"default": "^[0-9]{13,19}$"
},
"ipv4": {
"type": "string",
"description": "IPv4 address regex",
"default": "^((25[0-5]|(2[0-4]|1\\d|[1-9]|)\\d)\\.?\\b){4}$"
},
"ipv6": {
"type": "string",
"description": "IPv6 address regex",
"default": "^(([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\\.){3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\\.){3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))$"
},
"slug": {
"type": "string",
"description": "URL-safe slug regex",
"default": "^[a-z0-9]+(?:-[a-z0-9]+)*$"
},
"password": {
"type": "string",
"description": "Strong password regex (8+ chars, uppercase, lowercase, number, special)",
"default": "^(?=.*[a-z])(?=.*[A-Z])(?=.*\\d)(?=.*[@$!%*?&])[A-Za-z\\d@$!%*?&]{8,}$"
},
"hexColor": {
"type": "string",
"description": "Hexadecimal color code regex",
"default": "^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3}|[A-Fa-f0-9]{8})$"
}
},
"additionalProperties": {
"type": "string",
"description": "Custom validation pattern"
}
},
"functions": {
"type": "array",
"description": "Validation function definitions",
"items": {
"$ref": "#/definitions/validationFunction"
}
}
},
"definitions": {
"import": {
"type": "object",
"required": ["from", "import"],
"properties": {
"from": {
"type": "string",
"description": "Module to import from"
},
"import": {
"type": "array",
"description": "Items to import",
"items": { "type": "string" }
}
}
},
"validationFunction": {
"type": "object",
"required": ["id", "name", "params", "returnType", "body"],
"properties": {
"id": {
"type": "string",
"description": "Unique function identifier"
},
"name": {
"type": "string",
"description": "Function name (camelCase)"
},
"description": {
"type": "string",
"description": "Function description"
},
"exported": {
"type": "boolean",
"description": "Whether function is exported",
"default": false
},
"async": {
"type": "boolean",
"description": "Whether validator is async (for server-side validation)",
"default": false
},
"severity": {
"type": "string",
"description": "Default severity level for validation failures",
"enum": ["error", "warning", "info"],
"default": "error"
},
"composable": {
"type": "boolean",
"description": "Whether this validator can be composed with others",
"default": true
},
"docstring": {
"$ref": "#/definitions/docstring"
},
"params": {
"type": "array",
"description": "Function parameters",
"items": {
"$ref": "#/definitions/param"
}
},
"returnType": {
"type": "string",
"description": "Return type",
"enum": ["boolean", "string", "number", "object", "array", "void", "ValidationResult", "Promise<ValidationResult>"]
},
"body": {
"type": "array",
"description": "Function body statements",
"items": {
"$ref": "#/definitions/statement"
}
}
}
},
"param": {
"type": "object",
"required": ["name", "type"],
"properties": {
"name": {
"type": "string",
"description": "Parameter name"
},
"type": {
"type": "string",
"description": "Parameter type",
"enum": ["string", "number", "boolean", "object", "array", "any"]
},
"optional": {
"type": "boolean",
"description": "Whether parameter is optional",
"default": false
},
"default": {
"description": "Default value"
},
"description": {
"type": "string",
"description": "Parameter description"
},
"sanitize": {
"type": "boolean",
"description": "Whether to sanitize this parameter (XSS/SQL injection prevention)",
"default": true
},
"sanitizeOptions": {
"type": "object",
"description": "Sanitization options",
"properties": {
"allowHtml": {
"type": "boolean",
"description": "Allow HTML tags (will be sanitized with whitelist)",
"default": false
},
"allowedTags": {
"type": "array",
"description": "Allowed HTML tags if allowHtml is true",
"items": { "type": "string" },
"default": ["b", "i", "em", "strong", "a"]
},
"allowedAttributes": {
"type": "object",
"description": "Allowed attributes per tag",
"additionalProperties": {
"type": "array",
"items": { "type": "string" }
},
"default": { "a": ["href", "title"] }
},
"stripScripts": {
"type": "boolean",
"description": "Strip JavaScript (on* handlers, javascript: protocols)",
"default": true
},
"sqlInjectionProtection": {
"type": "boolean",
"description": "Escape SQL special characters",
"default": true
}
}
}
}
},
"statement": {
"type": "object",
"required": ["type"],
"properties": {
"type": {
"type": "string",
"description": "Statement type",
"enum": [
"comment",
"const_declaration",
"let_declaration",
"assignment",
"if_statement",
"switch_statement",
"for_each_loop",
"while_loop",
"return",
"throw",
"call_expression",
"try_catch",
"await_expression"
]
},
"text": {
"type": "string",
"description": "Comment text (for comment type)"
},
"name": {
"type": "string",
"description": "Variable name (for declarations)"
},
"value": {
"description": "Value or expression"
},
"target": {
"type": "string",
"description": "Assignment target"
},
"condition": {
"description": "Condition expression (for if/while)"
},
"then": {
"type": "array",
"description": "Then branch statements",
"items": { "$ref": "#/definitions/statement" }
},
"else": {
"type": "array",
"description": "Else branch statements",
"items": { "$ref": "#/definitions/statement" }
},
"discriminant": {
"description": "Switch discriminant expression"
},
"cases": {
"type": "array",
"description": "Switch cases",
"items": {
"type": "object",
"properties": {
"test": { "description": "Case test value" },
"consequent": {
"type": "array",
"items": { "$ref": "#/definitions/statement" }
}
}
}
},
"default": {
"type": "array",
"description": "Default case",
"items": { "$ref": "#/definitions/statement" }
},
"iterator": {
"type": "string",
"description": "Loop iterator variable"
},
"iterable": {
"description": "Iterable expression"
},
"body": {
"type": "array",
"description": "Loop/try body",
"items": { "$ref": "#/definitions/statement" }
},
"callee": {
"type": "string",
"description": "Function to call"
},
"args": {
"type": "array",
"description": "Function arguments"
},
"argument": {
"description": "Throw/await argument"
},
"catch": {
"type": "object",
"properties": {
"param": { "type": "string" },
"body": {
"type": "array",
"items": { "$ref": "#/definitions/statement" }
}
}
},
"finally": {
"type": "array",
"items": { "$ref": "#/definitions/statement" }
}
}
},
"docstring": {
"type": "object",
"properties": {
"summary": {
"type": "string",
"description": "Brief summary"
},
"description": {
"type": "string",
"description": "Detailed description"
},
"params": {
"type": "array",
"description": "Parameter documentation",
"items": {
"type": "object",
"properties": {
"name": { "type": "string" },
"type": { "type": "string" },
"description": { "type": "string" }
}
}
},
"returns": {
"type": "object",
"description": "Return value documentation",
"properties": {
"type": { "type": "string" },
"description": { "type": "string" }
}
},
"examples": {
"type": "array",
"description": "Usage examples",
"items": {
"type": "object",
"properties": {
"title": { "type": "string" },
"code": { "type": "string" },
"input": { "description": "Example input" },
"output": { "description": "Example output/result" }
}
}
},
"throws": {
"type": "array",
"description": "Exception documentation",
"items": {
"type": "object",
"properties": {
"type": { "type": "string" },
"description": { "type": "string" }
}
}
},
"since": {
"type": "string",
"description": "Version when added"
},
"see": {
"type": "array",
"description": "Related references",
"items": { "type": "string" }
}
}
},
"ValidationResult": {
"type": "object",
"description": "Structured validation result returned by validator functions",
"required": ["valid"],
"properties": {
"valid": {
"type": "boolean",
"description": "Whether validation passed"
},
"errors": {
"type": "array",
"description": "Validation errors (if any)",
"items": {
"type": "object",
"properties": {
"field": {
"type": "string",
"description": "Field name that failed validation"
},
"message": {
"type": "string",
"description": "Error message"
},
"code": {
"type": "string",
"description": "Error code for programmatic handling"
},
"severity": {
"type": "string",
"enum": ["error", "warning", "info"],
"default": "error"
}
},
"required": ["message"]
},
"default": []
},
"warnings": {
"type": "array",
"description": "Non-blocking validation warnings",
"items": {
"type": "object",
"properties": {
"field": {"type": "string"},
"message": {"type": "string"}
},
"required": ["message"]
},
"default": []
},
"metadata": {
"type": "object",
"description": "Additional validation metadata",
"additionalProperties": true
}
}
}
}
}