mirror of
https://github.com/johndoe6345789/metabuilder.git
synced 2026-04-25 06:14:59 +00:00
WorkflowEditor (325→80): CWorkflowState.qml + WorkflowConnectionState.js DashboardView (121→95): DashboardDBAL.js + config/dashboard-config.json Storybook (114→78): StorybookSidebar + config/storybook-components.json + 7 components compacted to under 100 via formatting (no logic changes) + Multiple view/component splits across all remaining 100+ LOC files Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
45 lines
8.3 KiB
JSON
45 lines
8.3 KiB
JSON
[
|
|
{
|
|
"name": "validate_email",
|
|
"description": "Validates email format using pattern matching",
|
|
"returnType": "boolean",
|
|
"params": [{ "name": "email", "type": "string" }],
|
|
"code": "-- validate_email.lua\n-- Validates an email address against RFC 5322 simplified pattern\n\nlocal function validate_email(email)\n if type(email) ~= \"string\" then\n return false, \"Input must be a string\"\n end\n\n if #email == 0 or #email > 254 then\n return false, \"Email length out of range\"\n end\n\n local pattern = \"^[%w%.%%%+%-]+@[%w%.%-]+%.%a%a+$\"\n if not email:match(pattern) then\n return false, \"Invalid email format\"\n end\n\n local local_part, domain = email:match(\"^(.+)@(.+)$\")\n if #local_part > 64 then\n return false, \"Local part exceeds 64 characters\"\n end\n\n -- Check for consecutive dots\n if email:find(\"..\") then\n return false, \"Consecutive dots not allowed\"\n end\n\n return true, \"Valid email\"\nend\n\nreturn validate_email"
|
|
},
|
|
{
|
|
"name": "hash_password",
|
|
"description": "Hashes a password with salt using SHA-512 via built-in crypto",
|
|
"returnType": "string",
|
|
"params": [{ "name": "password", "type": "string" }, { "name": "salt", "type": "string" }],
|
|
"code": "-- hash_password.lua\n-- Secure password hashing with salt and iteration\n\nlocal crypto = require(\"metabuilder.crypto\")\n\nlocal ITERATIONS = 10000\nlocal HASH_LENGTH = 64\n\nlocal function hash_password(password, salt)\n if type(password) ~= \"string\" or #password < 8 then\n error(\"Password must be at least 8 characters\")\n end\n\n if type(salt) ~= \"string\" or #salt < 16 then\n error(\"Salt must be at least 16 characters\")\n end\n\n local derived = crypto.pbkdf2({\n password = password,\n salt = salt,\n iterations = ITERATIONS,\n hash = \"sha512\",\n length = HASH_LENGTH\n })\n\n return string.format(\n \"$pbkdf2-sha512$i=%d$%s$%s\",\n ITERATIONS,\n crypto.base64_encode(salt),\n crypto.base64_encode(derived)\n )\nend\n\nreturn hash_password"
|
|
},
|
|
{
|
|
"name": "format_date",
|
|
"description": "Formats a UNIX timestamp into human-readable date strings",
|
|
"returnType": "string",
|
|
"params": [{ "name": "timestamp", "type": "number" }, { "name": "format", "type": "string" }],
|
|
"code": "-- format_date.lua\n-- Flexible date formatting from UNIX timestamps\n\nlocal FORMATS = {\n iso8601 = \"!%Y-%m-%dT%H:%M:%SZ\",\n short = \"%Y-%m-%d\",\n long = \"%B %d, %Y %H:%M\",\n relative = nil,\n rfc2822 = \"!%a, %d %b %Y %H:%M:%S GMT\"\n}\n\nlocal function relative_time(timestamp)\n local diff = os.time() - timestamp\n if diff < 60 then return \"just now\" end\n if diff < 3600 then return math.floor(diff / 60) .. \" minutes ago\" end\n if diff < 86400 then return math.floor(diff / 3600) .. \" hours ago\" end\n if diff < 2592000 then return math.floor(diff / 86400) .. \" days ago\" end\n return math.floor(diff / 2592000) .. \" months ago\"\nend\n\nlocal function format_date(timestamp, format)\n timestamp = tonumber(timestamp)\n if not timestamp then\n error(\"Invalid timestamp\")\n end\n\n format = format or \"iso8601\"\n\n if format == \"relative\" then\n return relative_time(timestamp)\n end\n\n local fmt = FORMATS[format]\n if not fmt then\n error(\"Unknown format: \" .. format)\n end\n\n return os.date(fmt, timestamp)\nend\n\nreturn format_date"
|
|
},
|
|
{
|
|
"name": "send_notification",
|
|
"description": "Sends a notification through the event bus to subscribed channels",
|
|
"returnType": "table",
|
|
"params": [{ "name": "user_id", "type": "string" }, { "name": "message", "type": "string" }, { "name": "channel", "type": "string" }],
|
|
"code": "-- send_notification.lua\n-- Dispatches notifications through the MetaBuilder event bus\n\nlocal eventbus = require(\"metabuilder.eventbus\")\nlocal json = require(\"metabuilder.json\")\n\nlocal CHANNELS = {\n email = { priority = 1, retry = 3 },\n push = { priority = 2, retry = 1 },\n sms = { priority = 3, retry = 2 },\n slack = { priority = 2, retry = 2 },\n webhook = { priority = 4, retry = 5 }\n}\n\nlocal function send_notification(user_id, message, channel)\n if not user_id or #user_id == 0 then\n return { success = false, error = \"user_id is required\" }\n end\n\n if not message or #message == 0 then\n return { success = false, error = \"message is required\" }\n end\n\n channel = channel or \"push\"\n local ch_config = CHANNELS[channel]\n if not ch_config then\n return { success = false, error = \"Unknown channel: \" .. channel }\n end\n\n local payload = {\n type = \"notification\",\n user_id = user_id,\n message = message,\n channel = channel,\n priority = ch_config.priority,\n timestamp = os.time(),\n retry_count = ch_config.retry\n }\n\n local ok, err = eventbus.publish(\"notifications\", json.encode(payload))\n if not ok then\n return { success = false, error = err }\n end\n\n return { success = true, id = payload.timestamp, channel = channel }\nend\n\nreturn send_notification"
|
|
},
|
|
{
|
|
"name": "check_permissions",
|
|
"description": "Checks user permissions against ACL rules from JSON config",
|
|
"returnType": "boolean",
|
|
"params": [{ "name": "user_id", "type": "string" }, { "name": "resource", "type": "string" }, { "name": "action", "type": "string" }],
|
|
"code": "-- check_permissions.lua\n-- ACL permission checker against JSON-defined rules\n\nlocal dbal = require(\"metabuilder.dbal\")\nlocal json = require(\"metabuilder.json\")\n\nlocal ACTIONS = { \"read\", \"write\", \"delete\", \"admin\" }\nlocal ACTION_HIERARCHY = { read = 1, write = 2, delete = 3, admin = 4 }\n\nlocal function check_permissions(user_id, resource, action)\n if not user_id or not resource or not action then\n return false, \"All parameters are required\"\n end\n\n if not ACTION_HIERARCHY[action] then\n return false, \"Invalid action: \" .. tostring(action)\n end\n\n local user = dbal.get(\"core\", \"users\", user_id)\n if not user then\n return false, \"User not found\"\n end\n\n if user.role == \"god\" then\n return true, \"God role: unrestricted\"\n end\n\n local acl = dbal.get(\"core\", \"acl_rules\", resource)\n if not acl then\n return false, \"No ACL rules for resource\"\n end\n\n local allowed = acl.roles[user.role]\n if not allowed then\n return false, \"Role not permitted\"\n end\n\n local required_level = ACTION_HIERARCHY[action]\n local granted_level = ACTION_HIERARCHY[allowed.max_action] or 0\n\n return granted_level >= required_level,\n granted_level >= required_level and \"Permitted\" or \"Insufficient privileges\"\nend\n\nreturn check_permissions"
|
|
},
|
|
{
|
|
"name": "generate_slug",
|
|
"description": "Generates URL-safe slugs from arbitrary text with transliteration",
|
|
"returnType": "string",
|
|
"params": [{ "name": "text", "type": "string" }, { "name": "max_length", "type": "number" }],
|
|
"code": "-- generate_slug.lua\n-- URL-safe slug generation with Unicode transliteration\n\nlocal TRANSLITERATE = {\n [\"a\"] = \"a\", [\"o\"] = \"o\", [\"u\"] = \"u\",\n [\"A\"] = \"A\", [\"O\"] = \"O\", [\"U\"] = \"U\",\n [\"n\"] = \"n\", [\"c\"] = \"c\", [\"e\"] = \"e\",\n [\"ss\"] = \"ss\"\n}\n\nlocal function generate_slug(text, max_length)\n if type(text) ~= \"string\" or #text == 0 then\n error(\"Input text is required\")\n end\n\n max_length = max_length or 80\n local slug = text\n slug = slug:lower()\n for from, to in pairs(TRANSLITERATE) do\n slug = slug:gsub(from, to)\n end\n slug = slug:gsub(\"[^%w%-]\", \"-\")\n slug = slug:gsub(\"%-+\", \"-\")\n slug = slug:gsub(\"^%-+\", \"\"):gsub(\"%-+$\", \"\")\n if #slug > max_length then\n slug = slug:sub(1, max_length)\n local last_hyphen = slug:find(\"%-[^%-]*$\")\n if last_hyphen and last_hyphen > max_length * 0.5 then\n slug = slug:sub(1, last_hyphen - 1)\n end\n end\n return slug\nend\n\nreturn generate_slug"
|
|
}
|
|
]
|