From d699c8aba9c1da1304ffab614be7123d78bca86d Mon Sep 17 00:00:00 2001 From: Eldad Fux Date: Wed, 5 May 2021 00:25:17 +0300 Subject: [PATCH] Updated functions service --- app/config/collections2.php | 1591 ++++++----------------------- app/controllers/api/functions.php | 304 +++--- app/init.php | 29 +- composer.lock | 4 +- 4 files changed, 467 insertions(+), 1461 deletions(-) diff --git a/app/config/collections2.php b/app/config/collections2.php index 7391493885..b29c8b505c 100644 --- a/app/config/collections2.php +++ b/app/config/collections2.php @@ -6,15 +6,6 @@ use Utopia\Database\Database; $providers = Config::getParam('providers', []); $auth = Config::getParam('auth', []); -// '$id' => 'title', -// 'type' => Database::VAR_STRING, -// 'format' => '', -// 'size' => 256, -// 'required' => true, -// 'signed' => true, -// 'array' => false, -// 'filters' => [], - $collections = [ 'users' => [ '$collection' => Database::COLLECTIONS, @@ -146,976 +137,7 @@ $collections = [ ], 'indexes' => [], ], - // Database::SYSTEM_COLLECTION_SESSIONS => [ - // '$collection' => Database::SYSTEM_COLLECTION_COLLECTIONS, - // '$id' => Database::SYSTEM_COLLECTION_SESSIONS, - // '$permissions' => ['read' => ['*']], - // 'name' => 'Session', - // 'structure' => true, - // 'rules' => [ - // [ - // '$collection' => Database::SYSTEM_COLLECTION_RULES, - // 'label' => 'User ID', - // 'key' => 'userId', - // 'type' => Database::SYSTEM_VAR_TYPE_TEXT, - // 'default' => null, - // 'required' => true, - // 'array' => false, - // ], - // [ - // '$collection' => Database::SYSTEM_COLLECTION_RULES, - // 'label' => 'Provider', - // 'key' => 'provider', - // 'type' => Database::SYSTEM_VAR_TYPE_TEXT, - // 'default' => '', - // 'required' => true, - // 'array' => false, - // ], - // [ - // '$collection' => Database::SYSTEM_COLLECTION_RULES, - // 'label' => 'Provider User Identifier', - // 'key' => 'providerUid', - // 'type' => Database::SYSTEM_VAR_TYPE_TEXT, - // 'default' => '', - // 'required' => false, - // 'array' => false, - // ], - // [ - // '$collection' => Database::SYSTEM_COLLECTION_RULES, - // 'label' => 'Provider Token', - // 'key' => 'providerToken', - // 'type' => Database::SYSTEM_VAR_TYPE_TEXT, - // 'default' => '', - // 'required' => false, - // 'array' => false, - // ], - // [ - // '$collection' => Database::SYSTEM_COLLECTION_RULES, - // 'label' => 'Secret', - // 'key' => 'secret', - // 'type' => Database::SYSTEM_VAR_TYPE_TEXT, - // 'default' => '', - // 'required' => true, - // 'array' => false, - // ], - // [ - // '$collection' => Database::SYSTEM_COLLECTION_RULES, - // 'label' => 'Expire', - // 'key' => 'expire', - // 'type' => Database::SYSTEM_VAR_TYPE_NUMERIC, - // 'default' => 0, - // 'required' => true, - // 'array' => false, - // ], - // [ - // '$collection' => Database::SYSTEM_COLLECTION_RULES, - // 'label' => 'User Agent', - // 'key' => 'userAgent', - // 'type' => Database::SYSTEM_VAR_TYPE_TEXT, - // 'default' => '', - // 'required' => true, - // 'array' => false, - // ], - // [ - // '$collection' => Database::SYSTEM_COLLECTION_RULES, - // 'label' => 'IP', - // 'key' => 'ip', - // 'type' => Database::SYSTEM_VAR_TYPE_IP, - // 'default' => '', - // 'required' => true, - // 'array' => false, - // ], - // [ - // '$collection' => Database::SYSTEM_COLLECTION_RULES, - // 'label' => 'OS Code', - // 'key' => 'osCode', - // 'type' => Database::SYSTEM_VAR_TYPE_TEXT, - // 'default' => '', - // 'required' => false, - // 'array' => false, - // ], - // [ - // '$collection' => Database::SYSTEM_COLLECTION_RULES, - // 'label' => 'OS Name', - // 'key' => 'osName', - // 'type' => Database::SYSTEM_VAR_TYPE_TEXT, - // 'default' => '', - // 'required' => false, - // 'array' => false, - // ], - // [ - // '$collection' => Database::SYSTEM_COLLECTION_RULES, - // 'label' => 'OS Version', - // 'key' => 'osVersion', - // 'type' => Database::SYSTEM_VAR_TYPE_TEXT, - // 'default' => '', - // 'required' => false, - // 'array' => false, - // ], - // [ - // '$collection' => Database::SYSTEM_COLLECTION_RULES, - // 'label' => 'Client Type', - // 'key' => 'clientType', - // 'type' => Database::SYSTEM_VAR_TYPE_TEXT, - // 'default' => '', - // 'required' => false, - // 'array' => false, - // ], - // [ - // '$collection' => Database::SYSTEM_COLLECTION_RULES, - // 'label' => 'Client Code', - // 'key' => 'clientCode', - // 'type' => Database::SYSTEM_VAR_TYPE_TEXT, - // 'default' => '', - // 'required' => false, - // 'array' => false, - // ], - // [ - // '$collection' => Database::SYSTEM_COLLECTION_RULES, - // 'label' => 'Client Name', - // 'key' => 'clientName', - // 'type' => Database::SYSTEM_VAR_TYPE_TEXT, - // 'default' => '', - // 'required' => false, - // 'array' => false, - // ], - // [ - // '$collection' => Database::SYSTEM_COLLECTION_RULES, - // 'label' => 'Client Version', - // 'key' => 'clientVersion', - // 'type' => Database::SYSTEM_VAR_TYPE_TEXT, - // 'default' => '', - // 'required' => false, - // 'array' => false, - // ], - // [ - // '$collection' => Database::SYSTEM_COLLECTION_RULES, - // 'label' => 'Client Engine', - // 'key' => 'clientEngine', - // 'type' => Database::SYSTEM_VAR_TYPE_TEXT, - // 'default' => '', - // 'required' => false, - // 'array' => false, - // ], - // [ - // '$collection' => Database::SYSTEM_COLLECTION_RULES, - // 'label' => 'Client Engine Version', - // 'key' => 'clientEngineVersion', - // 'type' => Database::SYSTEM_VAR_TYPE_TEXT, - // 'default' => '', - // 'required' => false, - // 'array' => false, - // ], - // [ - // '$collection' => Database::SYSTEM_COLLECTION_RULES, - // 'label' => 'Device Name', - // 'key' => 'deviceName', - // 'type' => Database::SYSTEM_VAR_TYPE_TEXT, - // 'default' => '', - // 'required' => false, - // 'array' => false, - // ], - // [ - // '$collection' => Database::SYSTEM_COLLECTION_RULES, - // 'label' => 'Device Brand', - // 'key' => 'deviceBrand', - // 'type' => Database::SYSTEM_VAR_TYPE_TEXT, - // 'default' => '', - // 'required' => false, - // 'array' => false, - // ], - // [ - // '$collection' => Database::SYSTEM_COLLECTION_RULES, - // 'label' => 'Device Model', - // 'key' => 'deviceModel', - // 'type' => Database::SYSTEM_VAR_TYPE_TEXT, - // 'default' => '', - // 'required' => false, - // 'array' => false, - // ], - // [ - // '$collection' => Database::SYSTEM_COLLECTION_RULES, - // 'label' => 'Country Code', - // 'key' => 'countryCode', - // 'type' => Database::SYSTEM_VAR_TYPE_TEXT, - // 'default' => '', - // 'required' => false, - // 'array' => false, - // ], - // ], - // ], - // Database::SYSTEM_COLLECTION_TOKENS => [ - // '$collection' => Database::SYSTEM_COLLECTION_COLLECTIONS, - // '$id' => Database::SYSTEM_COLLECTION_TOKENS, - // '$permissions' => ['read' => ['*']], - // 'name' => 'Token', - // 'structure' => true, - // 'rules' => [ - // [ - // '$collection' => Database::SYSTEM_COLLECTION_RULES, - // 'label' => 'User ID', - // 'key' => 'userId', - // 'type' => Database::SYSTEM_VAR_TYPE_TEXT, - // 'default' => null, - // 'required' => false, - // 'array' => false, - // ], - // [ - // '$collection' => Database::SYSTEM_COLLECTION_RULES, - // 'label' => 'Type', - // 'key' => 'type', - // 'type' => Database::SYSTEM_VAR_TYPE_NUMERIC, - // 'default' => null, - // 'required' => true, - // 'array' => false, - // ], - // [ - // '$collection' => Database::SYSTEM_COLLECTION_RULES, - // 'label' => 'Secret', - // 'key' => 'secret', - // 'type' => Database::SYSTEM_VAR_TYPE_TEXT, - // 'default' => '', - // 'required' => true, - // 'array' => false, - // ], - // [ - // '$collection' => Database::SYSTEM_COLLECTION_RULES, - // 'label' => 'Expire', - // 'key' => 'expire', - // 'type' => Database::SYSTEM_VAR_TYPE_NUMERIC, - // 'default' => 0, - // 'required' => true, - // 'array' => false, - // ], - // [ - // '$collection' => Database::SYSTEM_COLLECTION_RULES, - // 'label' => 'User Agent', - // 'key' => 'userAgent', - // 'type' => Database::SYSTEM_VAR_TYPE_TEXT, - // 'default' => '', - // 'required' => true, - // 'array' => false, - // ], - // [ - // '$collection' => Database::SYSTEM_COLLECTION_RULES, - // 'label' => 'IP', - // 'key' => 'ip', - // 'type' => Database::SYSTEM_VAR_TYPE_IP, - // 'default' => '', - // 'required' => true, - // 'array' => false, - // ], - // ], - // ], - // Database::SYSTEM_COLLECTION_MEMBERSHIPS => [ - // '$collection' => Database::SYSTEM_COLLECTION_COLLECTIONS, - // '$id' => Database::SYSTEM_COLLECTION_MEMBERSHIPS, - // '$permissions' => ['read' => ['*']], - // 'name' => 'Membership', - // 'structure' => true, - // 'rules' => [ - // [ - // '$collection' => Database::SYSTEM_COLLECTION_RULES, - // 'label' => 'Team ID', - // 'key' => 'teamId', - // 'type' => Database::SYSTEM_VAR_TYPE_TEXT, - // 'default' => null, - // 'required' => true, - // 'array' => false, - // ], - // [ - // '$collection' => Database::SYSTEM_COLLECTION_RULES, - // 'label' => 'User ID', - // 'key' => 'userId', - // 'type' => Database::SYSTEM_VAR_TYPE_TEXT, - // 'default' => null, - // 'required' => true, - // 'array' => false, - // ], - // [ - // '$collection' => Database::SYSTEM_COLLECTION_RULES, - // 'label' => 'Roles', - // 'key' => 'roles', - // 'type' => Database::SYSTEM_VAR_TYPE_TEXT, - // 'default' => '', - // 'required' => true, - // 'array' => true, - // ], - // [ - // '$collection' => Database::SYSTEM_COLLECTION_RULES, - // 'label' => 'Invited', - // 'key' => 'invited', - // 'type' => Database::SYSTEM_VAR_TYPE_NUMERIC, - // 'default' => 0, - // 'required' => false, //FIXME SHOULD BE REQUIRED - // 'array' => false, - // ], - // [ - // '$collection' => Database::SYSTEM_COLLECTION_RULES, - // 'label' => 'Joined', - // 'key' => 'joined', - // 'type' => Database::SYSTEM_VAR_TYPE_NUMERIC, - // 'default' => 0, - // 'required' => true, - // 'array' => false, - // ], - // [ - // '$collection' => Database::SYSTEM_COLLECTION_RULES, - // 'label' => 'Confirm', - // 'key' => 'confirm', - // 'type' => Database::SYSTEM_VAR_TYPE_BOOLEAN, - // 'default' => '', - // 'required' => true, - // 'array' => false, - // ], - // [ - // '$collection' => Database::SYSTEM_COLLECTION_RULES, - // 'label' => 'Secret', - // 'key' => 'secret', - // 'type' => Database::SYSTEM_VAR_TYPE_TEXT, - // 'default' => '', - // 'required' => false, - // 'array' => false, - // ], - // ], - // ], - // Database::SYSTEM_COLLECTION_TEAMS => [ - // '$collection' => Database::SYSTEM_COLLECTION_COLLECTIONS, - // '$id' => Database::SYSTEM_COLLECTION_TEAMS, - // '$permissions' => ['read' => ['*']], - // 'name' => 'Team', - // 'structure' => true, - // 'rules' => [ - // [ - // '$collection' => Database::SYSTEM_COLLECTION_RULES, - // 'label' => 'Name', - // 'key' => 'name', - // 'type' => Database::SYSTEM_VAR_TYPE_TEXT, - // 'default' => '', - // 'required' => true, - // 'array' => false, - // ], - // [ - // '$collection' => Database::SYSTEM_COLLECTION_RULES, - // 'label' => 'Date Created', - // 'key' => 'dateCreated', - // 'type' => Database::SYSTEM_VAR_TYPE_NUMERIC, - // 'default' => '', - // 'required' => false, - // 'array' => false, - // ], - // [ - // '$collection' => Database::SYSTEM_COLLECTION_RULES, - // 'label' => 'Sum', - // 'key' => 'sum', - // 'type' => Database::SYSTEM_VAR_TYPE_NUMERIC, - // 'default' => '', - // 'required' => false, - // 'array' => false, - // ], - // ], - // ], - // Database::SYSTEM_COLLECTION_PROJECTS => [ - // '$collection' => Database::SYSTEM_COLLECTION_COLLECTIONS, - // '$id' => Database::SYSTEM_COLLECTION_PROJECTS, - // '$permissions' => ['read' => ['*']], - // 'name' => 'Project', - // 'structure' => true, - // 'rules' => [ - // [ - // '$collection' => Database::SYSTEM_COLLECTION_RULES, - // 'label' => 'Name', - // 'key' => 'name', - // 'type' => Database::SYSTEM_VAR_TYPE_TEXT, - // 'default' => null, - // 'required' => true, - // 'array' => false, - // ], - // [ - // '$collection' => Database::SYSTEM_COLLECTION_RULES, - // 'label' => 'Description', - // 'key' => 'description', - // 'type' => Database::SYSTEM_VAR_TYPE_TEXT, - // 'default' => null, - // 'required' => false, - // 'array' => false, - // ], - // [ - // '$collection' => Database::SYSTEM_COLLECTION_RULES, - // 'label' => 'Logo', - // 'key' => 'logo', - // 'type' => Database::SYSTEM_VAR_TYPE_TEXT, - // 'default' => '', - // 'required' => false, - // ], - // [ - // '$collection' => Database::SYSTEM_COLLECTION_RULES, - // 'label' => 'URL', - // 'key' => 'url', - // 'type' => Database::SYSTEM_VAR_TYPE_URL, - // 'default' => '', - // 'required' => false, - // ], - // [ - // '$collection' => Database::SYSTEM_COLLECTION_RULES, - // 'label' => 'Team ID', - // 'key' => 'teamId', - // 'type' => Database::SYSTEM_VAR_TYPE_TEXT, - // 'default' => 0, - // 'required' => true, - // 'array' => false, - // ], - // [ - // '$collection' => Database::SYSTEM_COLLECTION_RULES, - // 'label' => 'Legal Name', - // 'key' => 'legalName', - // 'type' => Database::SYSTEM_VAR_TYPE_TEXT, - // 'default' => '', - // 'required' => false, - // ], - // [ - // '$collection' => Database::SYSTEM_COLLECTION_RULES, - // 'label' => 'Legal Country', - // 'key' => 'legalCountry', - // 'type' => Database::SYSTEM_VAR_TYPE_TEXT, - // 'default' => '', - // 'required' => false, - // ], - // [ - // '$collection' => Database::SYSTEM_COLLECTION_RULES, - // 'label' => 'Legal State', - // 'key' => 'legalState', - // 'type' => Database::SYSTEM_VAR_TYPE_TEXT, - // 'default' => '', - // 'required' => false, - // ], - // [ - // '$collection' => Database::SYSTEM_COLLECTION_RULES, - // 'label' => 'Legal City', - // 'key' => 'legalCity', - // 'type' => Database::SYSTEM_VAR_TYPE_TEXT, - // 'default' => '', - // 'required' => false, - // ], - // [ - // '$collection' => Database::SYSTEM_COLLECTION_RULES, - // 'label' => 'Legal Address', - // 'key' => 'legalAddress', - // 'type' => Database::SYSTEM_VAR_TYPE_TEXT, - // 'default' => '', - // 'required' => false, - // ], - // [ - // '$collection' => Database::SYSTEM_COLLECTION_RULES, - // 'label' => 'Legal Tax ID', - // 'key' => 'legalTaxId', - // 'type' => Database::SYSTEM_VAR_TYPE_TEXT, - // 'default' => '', - // 'required' => false, - // ], - // [ - // '$collection' => Database::SYSTEM_COLLECTION_RULES, - // 'label' => 'Max users allowed', - // 'key' => 'usersAuthLimit', - // 'type' => Database::SYSTEM_VAR_TYPE_NUMERIC, - // 'default' => 0, - // 'required' => false, - // ], - // [ - // '$collection' => Database::SYSTEM_COLLECTION_RULES, - // 'label' => 'Webhooks', - // 'key' => 'webhooks', - // 'type' => Database::SYSTEM_VAR_TYPE_DOCUMENT, - // 'default' => [], - // 'required' => false, - // 'array' => true, - // 'list' => [Database::SYSTEM_COLLECTION_WEBHOOKS], - // ], - // [ - // '$collection' => Database::SYSTEM_COLLECTION_RULES, - // 'label' => 'API Keys', - // 'key' => 'keys', - // 'type' => Database::SYSTEM_VAR_TYPE_DOCUMENT, - // 'default' => [], - // 'required' => false, - // 'array' => true, - // 'list' => [Database::SYSTEM_COLLECTION_KEYS], - // ], - // [ - // '$collection' => Database::SYSTEM_COLLECTION_RULES, - // 'label' => 'Tasks', - // 'key' => 'tasks', - // 'type' => Database::SYSTEM_VAR_TYPE_DOCUMENT, - // 'default' => [], - // 'required' => false, - // 'array' => true, - // 'list' => [Database::SYSTEM_COLLECTION_TASKS], - // ], - // [ - // '$collection' => Database::SYSTEM_COLLECTION_RULES, - // 'label' => 'Platforms', - // 'key' => 'platforms', - // 'type' => Database::SYSTEM_VAR_TYPE_DOCUMENT, - // 'default' => [], - // 'required' => false, - // 'array' => true, - // 'list' => [Database::SYSTEM_COLLECTION_PLATFORMS], - // ], - // [ - // '$collection' => Database::SYSTEM_COLLECTION_RULES, - // 'label' => 'Domains', - // 'key' => 'domains', - // 'type' => Database::SYSTEM_VAR_TYPE_DOCUMENT, - // 'default' => [], - // 'required' => false, - // 'array' => true, - // 'list' => [Database::SYSTEM_COLLECTION_DOMAINS], - // ], - // ], - // ], - // Database::SYSTEM_COLLECTION_WEBHOOKS => [ - // '$collection' => Database::SYSTEM_COLLECTION_COLLECTIONS, - // '$id' => Database::SYSTEM_COLLECTION_WEBHOOKS, - // '$permissions' => ['read' => ['*']], - // 'name' => 'Webhook', - // 'structure' => true, - // 'rules' => [ - // [ - // '$collection' => Database::SYSTEM_COLLECTION_RULES, - // 'label' => 'Name', - // 'key' => 'name', - // 'type' => Database::SYSTEM_VAR_TYPE_TEXT, - // 'default' => null, - // 'required' => true, - // 'array' => false, - // ], - // [ - // '$collection' => Database::SYSTEM_COLLECTION_RULES, - // 'label' => 'Events', - // 'key' => 'events', - // 'type' => Database::SYSTEM_VAR_TYPE_TEXT, - // 'default' => null, - // 'required' => false, - // 'array' => true, - // ], - // [ - // '$collection' => Database::SYSTEM_COLLECTION_RULES, - // 'label' => 'URL', - // 'key' => 'url', - // 'type' => Database::SYSTEM_VAR_TYPE_URL, - // 'default' => '', - // 'required' => false, - // 'array' => false, - // ], - // [ - // '$collection' => Database::SYSTEM_COLLECTION_RULES, - // 'label' => 'Security', - // 'key' => 'security', - // 'type' => Database::SYSTEM_VAR_TYPE_BOOLEAN, - // 'default' => '', - // 'required' => false, - // 'array' => false, - // ], - // [ - // '$collection' => Database::SYSTEM_COLLECTION_RULES, - // 'label' => 'HTTP User', - // 'key' => 'httpUser', - // 'type' => Database::SYSTEM_VAR_TYPE_TEXT, - // 'default' => '', - // 'required' => false, - // 'array' => false, - // ], - // [ - // '$collection' => Database::SYSTEM_COLLECTION_RULES, - // 'label' => 'HTTP Password', - // 'key' => 'httpPass', - // 'type' => Database::SYSTEM_VAR_TYPE_TEXT, - // 'default' => '', - // 'required' => false, - // 'array' => false, - // 'filter' => ['encrypt'], - // ], - // ], - // ], - // Database::SYSTEM_COLLECTION_KEYS => [ - // '$collection' => Database::SYSTEM_COLLECTION_COLLECTIONS, - // '$id' => Database::SYSTEM_COLLECTION_KEYS, - // '$permissions' => ['read' => ['*']], - // 'name' => 'Key', - // 'structure' => true, - // 'rules' => [ - // [ - // '$collection' => Database::SYSTEM_COLLECTION_RULES, - // 'label' => 'Name', - // 'key' => 'name', - // 'type' => Database::SYSTEM_VAR_TYPE_TEXT, - // 'default' => null, - // 'required' => true, - // 'array' => false, - // ], - // [ - // '$collection' => Database::SYSTEM_COLLECTION_RULES, - // 'label' => 'Scopes', - // 'key' => 'scopes', - // 'type' => Database::SYSTEM_VAR_TYPE_TEXT, - // 'default' => null, - // 'required' => false, - // 'array' => true, - // ], - // [ - // '$collection' => Database::SYSTEM_COLLECTION_RULES, - // 'label' => 'Secret', - // 'key' => 'secret', - // 'type' => Database::SYSTEM_VAR_TYPE_TEXT, - // 'default' => '', - // 'required' => false, - // 'filter' => ['encrypt'], - // ], - // ], - // ], - // Database::SYSTEM_COLLECTION_TASKS => [ - // '$collection' => Database::SYSTEM_COLLECTION_COLLECTIONS, - // '$id' => Database::SYSTEM_COLLECTION_TASKS, - // '$permissions' => ['read' => ['*']], - // 'name' => 'Task', - // 'structure' => true, - // 'rules' => [ - // [ - // '$collection' => Database::SYSTEM_COLLECTION_RULES, - // 'label' => 'Name', - // 'key' => 'name', - // 'type' => Database::SYSTEM_VAR_TYPE_TEXT, - // 'default' => null, - // 'required' => true, - // 'array' => false, - // ], - // [ - // '$collection' => Database::SYSTEM_COLLECTION_RULES, - // 'label' => 'Status', - // 'key' => 'status', - // 'type' => Database::SYSTEM_VAR_TYPE_TEXT, - // 'default' => '', - // 'required' => false, - // 'array' => false, - // ], - // [ - // '$collection' => Database::SYSTEM_COLLECTION_RULES, - // 'label' => 'Updated', - // 'key' => 'updated', - // 'type' => Database::SYSTEM_VAR_TYPE_NUMERIC, - // 'default' => '', - // 'required' => false, - // 'array' => false, - // ], - // [ - // '$collection' => Database::SYSTEM_COLLECTION_RULES, - // 'label' => 'Schedule', - // 'key' => 'schedule', - // 'type' => Database::SYSTEM_VAR_TYPE_TEXT, - // 'default' => '', - // 'required' => false, - // 'array' => false, - // ], - // [ - // '$collection' => Database::SYSTEM_COLLECTION_RULES, - // 'label' => 'Previous', - // 'key' => 'previous', - // 'type' => Database::SYSTEM_VAR_TYPE_NUMERIC, - // 'default' => '', - // 'required' => false, - // 'array' => false, - // ], - // [ - // '$collection' => Database::SYSTEM_COLLECTION_RULES, - // 'label' => 'Next', - // 'key' => 'next', - // 'type' => Database::SYSTEM_VAR_TYPE_NUMERIC, - // 'default' => '', - // 'required' => false, - // 'array' => false, - // ], - // [ - // '$collection' => Database::SYSTEM_COLLECTION_RULES, - // 'label' => 'Duration', - // 'key' => 'duration', - // 'type' => Database::SYSTEM_VAR_TYPE_NUMERIC, - // 'default' => '', - // 'required' => false, - // 'array' => false, - // ], - // [ - // '$collection' => Database::SYSTEM_COLLECTION_RULES, - // 'label' => 'Delay', - // 'key' => 'delay', - // 'type' => Database::SYSTEM_VAR_TYPE_NUMERIC, - // 'default' => '', - // 'required' => false, - // 'array' => false, - // ], - // [ - // '$collection' => Database::SYSTEM_COLLECTION_RULES, - // 'label' => 'Security', - // 'key' => 'security', - // 'type' => Database::SYSTEM_VAR_TYPE_BOOLEAN, - // 'default' => '', - // 'required' => false, - // 'array' => false, - // ], - // [ - // '$collection' => Database::SYSTEM_COLLECTION_RULES, - // 'label' => 'HTTP Method', - // 'key' => 'httpMethod', - // 'type' => Database::SYSTEM_VAR_TYPE_TEXT, - // 'default' => '', - // 'required' => false, - // 'array' => false, - // ], - // [ - // '$collection' => Database::SYSTEM_COLLECTION_RULES, - // 'label' => 'HTTP URL', - // 'key' => 'httpUrl', - // 'type' => Database::SYSTEM_VAR_TYPE_TEXT, - // 'default' => '', - // 'required' => false, - // 'array' => false, - // ], - // [ - // '$collection' => Database::SYSTEM_COLLECTION_RULES, - // 'label' => 'HTTP Headers', - // 'key' => 'httpHeaders', - // 'type' => Database::SYSTEM_VAR_TYPE_TEXT, - // 'default' => null, - // 'required' => false, - // 'array' => true, - // ], - // [ - // '$collection' => Database::SYSTEM_COLLECTION_RULES, - // 'label' => 'HTTP User', - // 'key' => 'httpUser', - // 'type' => Database::SYSTEM_VAR_TYPE_TEXT, - // 'default' => '', - // 'required' => false, - // 'array' => false, - // ], - // [ - // '$collection' => Database::SYSTEM_COLLECTION_RULES, - // 'label' => 'HTTP Password', - // 'key' => 'httpPass', - // 'type' => Database::SYSTEM_VAR_TYPE_TEXT, - // 'default' => '', - // 'required' => false, - // 'array' => false, - // 'filter' => ['encrypt'], - // ], - // [ - // '$collection' => Database::SYSTEM_COLLECTION_RULES, - // 'label' => 'Log', - // 'key' => 'log', - // 'type' => Database::SYSTEM_VAR_TYPE_TEXT, - // 'default' => '', - // 'required' => false, - // 'array' => false, - // ], - // [ - // '$collection' => Database::SYSTEM_COLLECTION_RULES, - // 'label' => 'Failures', - // 'key' => 'failures', - // 'type' => Database::SYSTEM_VAR_TYPE_NUMERIC, - // 'default' => '', - // 'required' => false, - // 'array' => false, - // ], - // ], - // ], - // Database::SYSTEM_COLLECTION_PLATFORMS => [ - // '$collection' => Database::SYSTEM_COLLECTION_COLLECTIONS, - // '$id' => Database::SYSTEM_COLLECTION_PLATFORMS, - // '$permissions' => ['read' => ['*']], - // 'name' => 'Platform', - // 'structure' => true, - // 'rules' => [ - // [ - // '$collection' => Database::SYSTEM_COLLECTION_RULES, - // 'label' => 'Type', - // 'key' => 'type', - // 'type' => Database::SYSTEM_VAR_TYPE_TEXT, - // 'default' => null, - // 'required' => true, - // 'array' => false, - // ], - // [ - // '$collection' => Database::SYSTEM_COLLECTION_RULES, - // 'label' => 'Name', - // 'key' => 'name', - // 'type' => Database::SYSTEM_VAR_TYPE_TEXT, - // 'default' => null, - // 'required' => true, - // 'array' => false, - // ], - // [ - // '$collection' => Database::SYSTEM_COLLECTION_RULES, - // 'label' => 'Date Created', - // 'key' => 'dateCreated', - // 'type' => Database::SYSTEM_VAR_TYPE_NUMERIC, - // 'default' => 0, - // 'required' => false, - // 'array' => false, - // ], - // [ - // '$collection' => Database::SYSTEM_COLLECTION_RULES, - // 'label' => 'Date Updated', - // 'key' => 'dateUpdated', - // 'type' => Database::SYSTEM_VAR_TYPE_NUMERIC, - // 'default' => 0, - // 'required' => false, - // 'array' => false, - // ], - // [ - // '$collection' => Database::SYSTEM_COLLECTION_RULES, - // 'label' => 'Key', - // 'key' => 'key', - // 'type' => Database::SYSTEM_VAR_TYPE_TEXT, - // 'default' => '', - // 'required' => false, - // 'array' => false, - // ], - // [ - // '$collection' => Database::SYSTEM_COLLECTION_RULES, - // 'label' => 'Store', - // 'key' => 'store', - // 'type' => Database::SYSTEM_VAR_TYPE_TEXT, - // 'default' => '', - // 'required' => false, - // 'array' => false, - // ], - // [ - // '$collection' => Database::SYSTEM_COLLECTION_RULES, - // 'label' => 'Hostname', - // 'key' => 'hostname', - // 'type' => Database::SYSTEM_VAR_TYPE_TEXT, - // 'default' => '', - // 'required' => false, - // 'array' => false, - // ], - // ], - // ], - // Database::SYSTEM_COLLECTION_DOMAINS => [ - // '$collection' => Database::SYSTEM_COLLECTION_COLLECTIONS, - // '$id' => Database::SYSTEM_COLLECTION_DOMAINS, - // '$permissions' => ['read' => ['*']], - // 'name' => 'Domains', - // 'structure' => true, - // 'rules' => [ - // [ - // '$collection' => Database::SYSTEM_COLLECTION_RULES, - // 'label' => 'Domain', - // 'key' => 'domain', - // 'type' => Database::SYSTEM_VAR_TYPE_TEXT, - // 'default' => null, - // 'required' => true, - // 'array' => false, - // ], - // [ - // '$collection' => Database::SYSTEM_COLLECTION_RULES, - // 'label' => 'Updated', - // 'key' => 'updated', - // 'type' => Database::SYSTEM_VAR_TYPE_NUMERIC, - // 'default' => 0, - // 'required' => false, - // 'array' => false, - // ], - // [ - // '$collection' => Database::SYSTEM_COLLECTION_RULES, - // 'label' => 'Top Level Domain', - // 'key' => 'tld', - // 'type' => Database::SYSTEM_VAR_TYPE_TEXT, - // 'default' => '', - // 'required' => false, - // 'array' => false, - // ], - // [ - // '$collection' => Database::SYSTEM_COLLECTION_RULES, - // 'label' => 'Registerable Domain', - // 'key' => 'registerable', - // 'type' => Database::SYSTEM_VAR_TYPE_TEXT, - // 'default' => '', - // 'required' => false, - // 'array' => false, - // ], - // [ - // '$collection' => Database::SYSTEM_COLLECTION_RULES, - // 'label' => 'Verification', - // 'key' => 'verification', - // 'type' => Database::SYSTEM_VAR_TYPE_BOOLEAN, - // 'default' => false, - // 'required' => true, - // 'array' => false, - // ], - // [ - // '$collection' => Database::SYSTEM_COLLECTION_RULES, - // 'label' => 'Certificate ID', - // 'key' => 'certificateId', - // 'type' => Database::SYSTEM_VAR_TYPE_KEY, - // 'default' => '', - // 'required' => false, - // 'array' => false, - // ], - // ], - // ], - // Database::SYSTEM_COLLECTION_CERTIFICATES => [ - // '$collection' => Database::SYSTEM_COLLECTION_COLLECTIONS, - // '$id' => Database::SYSTEM_COLLECTION_CERTIFICATES, - // '$permissions' => ['read' => ['*']], - // 'name' => 'Certificates', - // 'structure' => true, - // 'rules' => [ - // [ - // '$collection' => Database::SYSTEM_COLLECTION_RULES, - // 'label' => 'Domain', - // 'key' => 'domain', - // 'type' => Database::SYSTEM_VAR_TYPE_TEXT, - // 'default' => null, - // 'required' => true, - // 'array' => false, - // ], - // [ - // '$collection' => Database::SYSTEM_COLLECTION_RULES, - // 'label' => 'Issue Date', - // 'key' => 'issueDate', - // 'type' => Database::SYSTEM_VAR_TYPE_NUMERIC, - // 'default' => 0, - // 'required' => false, - // 'array' => false, - // ], - // [ - // '$collection' => Database::SYSTEM_COLLECTION_RULES, - // 'label' => 'Renew Date', - // 'key' => 'renewDate', - // 'type' => Database::SYSTEM_VAR_TYPE_NUMERIC, - // 'default' => 0, - // 'required' => false, - // 'array' => false, - // ], - // [ - // '$collection' => Database::SYSTEM_COLLECTION_RULES, - // 'label' => 'Attempts', - // 'key' => 'attempts', - // 'type' => Database::SYSTEM_VAR_TYPE_NUMERIC, - // 'default' => 0, - // 'required' => false, - // 'array' => false, - // ], - // [ - // '$collection' => Database::SYSTEM_COLLECTION_RULES, - // 'label' => 'Log', - // 'key' => 'log', - // 'type' => Database::SYSTEM_VAR_TYPE_TEXT, - // 'default' => '', - // 'required' => false, - // 'array' => false, - // ], - // ], - // ], + 'files' => [ '$collection' => Database::COLLECTIONS, '$id' => 'files', @@ -1143,7 +165,6 @@ $collections = [ 'filters' => [], ], [ - 'array' => false, '$id' => 'name', 'type' => Database::VAR_STRING, 'format' => '', @@ -1266,316 +287,306 @@ $collections = [ ], 'indexes' => [], ], - // Database::SYSTEM_COLLECTION_FUNCTIONS => [ - // '$collection' => Database::SYSTEM_COLLECTION_COLLECTIONS, - // '$id' => Database::SYSTEM_COLLECTION_FUNCTIONS, - // '$permissions' => ['read' => ['*']], - // 'name' => 'Functions', - // 'structure' => true, - // 'rules' => [ - // [ - // '$collection' => Database::SYSTEM_COLLECTION_RULES, - // 'label' => 'Date Created', - // 'key' => 'dateCreated', - // 'type' => Database::SYSTEM_VAR_TYPE_NUMERIC, - // 'default' => 0, - // 'required' => false, - // 'array' => false, - // ], - // [ - // '$collection' => Database::SYSTEM_COLLECTION_RULES, - // 'label' => 'Date Updated', - // 'key' => 'dateUpdated', - // 'type' => Database::SYSTEM_VAR_TYPE_NUMERIC, - // 'default' => 0, - // 'required' => false, - // 'array' => false, - // ], - // [ - // '$collection' => Database::SYSTEM_COLLECTION_RULES, - // 'label' => 'Status', - // 'key' => 'status', - // 'type' => Database::SYSTEM_VAR_TYPE_TEXT, - // 'default' => '', - // 'required' => false, - // 'array' => false, - // ], - // [ - // '$collection' => Database::SYSTEM_COLLECTION_RULES, - // 'label' => 'Name', - // 'key' => 'name', - // 'type' => Database::SYSTEM_VAR_TYPE_TEXT, - // 'default' => '', - // 'required' => false, - // 'array' => false, - // ], - // [ - // '$collection' => Database::SYSTEM_COLLECTION_RULES, - // 'label' => 'Env', - // 'key' => 'env', - // 'type' => Database::SYSTEM_VAR_TYPE_TEXT, - // 'default' => '', - // 'required' => false, - // 'array' => false, - // ], - // [ - // '$collection' => Database::SYSTEM_COLLECTION_RULES, - // 'label' => 'Tag', - // 'key' => 'tag', - // 'type' => Database::SYSTEM_VAR_TYPE_KEY, - // 'default' => '', - // 'required' => false, - // 'array' => false, - // ], - // [ - // '$collection' => Database::SYSTEM_COLLECTION_RULES, - // 'label' => 'Vars', - // 'key' => 'vars', - // 'type' => Database::SYSTEM_VAR_TYPE_TEXT, - // 'default' => '', - // 'required' => false, - // 'array' => false, - // 'filter' => ['json', 'encrypt'] - // ], - // [ - // '$collection' => Database::SYSTEM_COLLECTION_RULES, - // 'label' => 'Events', - // 'key' => 'events', - // 'type' => Database::SYSTEM_VAR_TYPE_TEXT, - // 'default' => '', - // 'required' => false, - // 'array' => true, - // ], - // [ - // '$collection' => Database::SYSTEM_COLLECTION_RULES, - // 'label' => 'Schedule', - // 'key' => 'schedule', - // 'type' => Database::SYSTEM_VAR_TYPE_TEXT, - // 'default' => '', - // 'required' => false, - // 'array' => false, - // ], - // [ - // '$collection' => Database::SYSTEM_COLLECTION_RULES, - // 'label' => 'Schedule Previous Run', - // 'key' => 'schedulePrevious', - // 'type' => Database::SYSTEM_VAR_TYPE_NUMERIC, - // 'default' => '', - // 'required' => false, - // 'array' => false, - // ], - // [ - // '$collection' => Database::SYSTEM_COLLECTION_RULES, - // 'label' => 'Schedule Next Run', - // 'key' => 'scheduleNext', - // 'type' => Database::SYSTEM_VAR_TYPE_NUMERIC, - // 'default' => '', - // 'required' => false, - // 'array' => false, - // ], - // [ - // '$collection' => Database::SYSTEM_COLLECTION_RULES, - // 'label' => 'Timeout', - // 'key' => 'timeout', - // 'type' => Database::SYSTEM_VAR_TYPE_NUMERIC, - // 'default' => '', - // 'required' => false, - // 'array' => false, - // ], - // ], - // ], - // Database::SYSTEM_COLLECTION_TAGS => [ - // '$collection' => Database::SYSTEM_COLLECTION_COLLECTIONS, - // '$id' => Database::SYSTEM_COLLECTION_TAGS, - // '$permissions' => ['read' => ['*']], - // 'name' => 'Tags', - // 'structure' => true, - // 'rules' => [ - // [ - // '$collection' => Database::SYSTEM_COLLECTION_RULES, - // 'label' => 'Date Created', - // 'key' => 'dateCreated', - // 'type' => Database::SYSTEM_VAR_TYPE_NUMERIC, - // 'default' => 0, - // 'required' => false, - // 'array' => false, - // ], - // [ - // '$collection' => Database::SYSTEM_COLLECTION_RULES, - // 'label' => 'Function ID', - // 'key' => 'functionId', - // 'type' => Database::SYSTEM_VAR_TYPE_KEY, - // 'default' => '', - // 'required' => false, - // 'array' => false, - // ], - // [ - // '$collection' => Database::SYSTEM_COLLECTION_RULES, - // 'label' => 'Command', - // 'key' => 'command', - // 'type' => Database::SYSTEM_VAR_TYPE_TEXT, - // 'default' => '', - // 'required' => false, - // 'array' => false, - // ], - // [ - // '$collection' => Database::SYSTEM_COLLECTION_RULES, - // 'label' => 'Code Path', - // 'key' => 'path', - // 'type' => Database::SYSTEM_VAR_TYPE_TEXT, - // 'default' => '', - // 'required' => false, - // 'array' => false, - // ], - // [ - // '$collection' => Database::SYSTEM_COLLECTION_RULES, - // 'label' => 'Code Size', - // 'key' => 'size', - // 'type' => Database::SYSTEM_VAR_TYPE_NUMERIC, - // 'default' => '', - // 'required' => false, - // 'array' => false, - // ], - // ], - // ], - // Database::SYSTEM_COLLECTION_EXECUTIONS => [ - // '$collection' => Database::SYSTEM_COLLECTION_COLLECTIONS, - // '$id' => Database::SYSTEM_COLLECTION_EXECUTIONS, - // '$permissions' => ['read' => ['*']], - // 'name' => 'Executions', - // 'structure' => true, - // 'rules' => [ - // [ - // '$collection' => Database::SYSTEM_COLLECTION_RULES, - // 'label' => 'Date Created', - // 'key' => 'dateCreated', - // 'type' => Database::SYSTEM_VAR_TYPE_NUMERIC, - // 'default' => 0, - // 'required' => false, - // 'array' => false, - // ], - // [ - // '$collection' => Database::SYSTEM_COLLECTION_RULES, - // 'label' => 'Function ID', - // 'key' => 'functionId', - // 'type' => Database::SYSTEM_VAR_TYPE_KEY, - // 'default' => '', - // 'required' => false, - // 'array' => false, - // ], - // [ - // '$collection' => Database::SYSTEM_COLLECTION_RULES, - // 'label' => 'Tag ID', - // 'key' => 'tagId', - // 'type' => Database::SYSTEM_VAR_TYPE_KEY, - // 'default' => '', - // 'required' => false, - // 'array' => false, - // ], - // [ - // '$collection' => Database::SYSTEM_COLLECTION_RULES, - // 'label' => 'Trigger', - // 'key' => 'trigger', - // 'type' => Database::SYSTEM_VAR_TYPE_TEXT, - // 'default' => '', - // 'required' => false, - // 'array' => false, - // ], - // [ - // '$collection' => Database::SYSTEM_COLLECTION_RULES, - // 'label' => 'Status', - // 'key' => 'status', - // 'type' => Database::SYSTEM_VAR_TYPE_TEXT, - // 'default' => '', - // 'required' => false, - // 'array' => false, - // ], - // [ - // '$collection' => Database::SYSTEM_COLLECTION_RULES, - // 'label' => 'Exit Code', - // 'key' => 'exitCode', - // 'type' => Database::SYSTEM_VAR_TYPE_NUMERIC, - // 'default' => '', - // 'required' => false, - // 'array' => false, - // ], - // [ - // '$collection' => Database::SYSTEM_COLLECTION_RULES, - // 'label' => 'Stdout', - // 'key' => 'stdout', - // 'type' => Database::SYSTEM_VAR_TYPE_TEXT, - // 'default' => '', - // 'required' => false, - // 'array' => false, - // ], - // [ - // '$collection' => Database::SYSTEM_COLLECTION_RULES, - // 'label' => 'Stderr', - // 'key' => 'stderr', - // 'type' => Database::SYSTEM_VAR_TYPE_TEXT, - // 'default' => '', - // 'required' => false, - // 'array' => false, - // ], - // [ - // '$collection' => Database::SYSTEM_COLLECTION_RULES, - // 'label' => 'Time', - // 'key' => 'time', - // 'type' => Database::SYSTEM_VAR_TYPE_NUMERIC, - // 'default' => '', - // 'required' => false, - // 'array' => false, - // ], - // ], - // ], - // Database::SYSTEM_COLLECTION_RESERVED => [ - // '$collection' => Database::SYSTEM_COLLECTION_COLLECTIONS, - // '$id' => Database::SYSTEM_COLLECTION_RESERVED, - // '$permissions' => ['read' => ['*']], - // 'name' => 'Reserved', - // 'structure' => true, - // ], + + 'functions' => [ + '$collection' => Database::COLLECTIONS, + '$id' => 'functions', + 'name' => 'Functions', + 'attributes' => [ + [ + '$id' => 'execute', + 'type' => Database::VAR_STRING, + 'format' => '', + 'size' => 128, + 'signed' => true, + 'required' => false, + 'array' => true, + 'filters' => [], + ], + [ + '$id' => 'dateCreated', + 'type' => Database::VAR_INTEGER, + 'format' => '', + 'size' => 0, + 'signed' => true, + 'required' => false, + 'array' => false, + 'filters' => [], + ], + [ + '$id' => 'dateUpdated', + 'type' => Database::VAR_INTEGER, + 'format' => '', + 'size' => 0, + 'signed' => true, + 'required' => false, + 'array' => false, + 'filters' => [], + ], + [ + 'array' => false, + '$id' => 'status', + 'type' => Database::VAR_STRING, + 'format' => '', + 'size' => Database::LENGTH_KEY, + 'signed' => true, + 'required' => false, + 'array' => false, + 'filters' => [], + ], + [ + '$id' => 'name', + 'type' => Database::VAR_STRING, + 'format' => '', + 'size' => 2048, + 'signed' => true, + 'required' => false, + 'array' => false, + 'filters' => [], + ], + [ + '$id' => 'env', + 'type' => Database::VAR_STRING, + 'format' => '', + 'size' => 2048, + 'signed' => true, + 'required' => false, + 'array' => false, + 'filters' => [], + ], + [ + '$id' => 'tag', + 'type' => Database::VAR_STRING, + 'format' => '', + 'size' => Database::LENGTH_KEY, + 'signed' => true, + 'required' => false, + 'array' => false, + 'filters' => [], + ], + [ + '$id' => 'vars', + 'type' => Database::VAR_STRING, + 'format' => '', + 'size' => 8192, + 'signed' => true, + 'required' => false, + 'array' => false, + 'filters' => ['json', 'encrypt'], + ], + [ + '$id' => 'events', + 'type' => Database::VAR_STRING, + 'format' => '', + 'size' => 256, + 'signed' => true, + 'required' => false, + 'array' => true, + 'filters' => [], + ], + [ + '$id' => 'schedule', + 'type' => Database::VAR_STRING, + 'format' => '', + 'size' => 128, + 'signed' => true, + 'required' => false, + 'array' => false, + 'filters' => [], + ], + [ + '$id' => 'schedulePrevious', + 'type' => Database::VAR_INTEGER, + 'format' => '', + 'size' => 0, + 'signed' => true, + 'required' => false, + 'array' => false, + 'filters' => [], + ], + [ + '$id' => 'scheduleNext', + 'type' => Database::VAR_INTEGER, + 'format' => '', + 'size' => 0, + 'signed' => true, + 'required' => false, + 'array' => false, + 'filters' => [], + ], + [ + '$id' => 'timeout', + 'type' => Database::VAR_INTEGER, + 'format' => '', + 'size' => 0, + 'signed' => true, + 'required' => false, + 'array' => false, + 'filters' => [], + ], + ], + 'indexes' => [], + ], + + 'tags' => [ + '$collection' => Database::COLLECTIONS, + '$id' => 'tags', + 'name' => 'Tags', + 'attributes' => [ + [ + '$id' => 'dateCreated', + 'type' => Database::VAR_INTEGER, + 'format' => '', + 'size' => 0, + 'signed' => true, + 'required' => false, + 'array' => false, + 'filters' => [], + ], + [ + '$id' => 'functionId', + 'type' => Database::VAR_STRING, + 'format' => '', + 'size' => Database::LENGTH_KEY, + 'signed' => true, + 'required' => false, + 'array' => false, + 'filters' => [], + ], + [ + 'array' => false, + '$id' => 'command', + 'type' => Database::VAR_STRING, + 'format' => '', + 'size' => 2048, + 'signed' => true, + 'required' => false, + 'array' => false, + 'filters' => [], + ], + [ + '$id' => 'path', + 'type' => Database::VAR_STRING, + 'format' => '', + 'size' => 2048, + 'signed' => true, + 'required' => false, + 'array' => false, + 'filters' => [], + ], + [ + '$id' => 'size', + 'type' => Database::VAR_INTEGER, + 'format' => '', + 'size' => 0, + 'signed' => true, + 'required' => false, + 'array' => false, + 'filters' => [], + ], + ], + 'indexes' => [], + ], + + 'executions' => [ + '$collection' => Database::COLLECTIONS, + '$id' => 'executions', + 'name' => 'Executions', + 'attributes' => [ + [ + '$id' => 'dateCreated', + 'type' => Database::VAR_INTEGER, + 'format' => '', + 'size' => 0, + 'signed' => true, + 'required' => false, + 'array' => false, + 'filters' => [], + ], + [ + '$id' => 'functionId', + 'type' => Database::VAR_STRING, + 'format' => '', + 'size' => Database::LENGTH_KEY, + 'signed' => true, + 'required' => false, + 'array' => false, + 'filters' => [], + ], + [ + '$id' => 'tagId', + 'type' => Database::VAR_STRING, + 'format' => '', + 'size' => Database::LENGTH_KEY, + 'signed' => true, + 'required' => false, + 'array' => false, + 'filters' => [], + ], + [ + 'array' => false, + '$id' => 'trigger', + 'type' => Database::VAR_STRING, + 'format' => '', + 'size' => 128, + 'signed' => true, + 'required' => false, + 'array' => false, + 'filters' => [], + ], + [ + '$id' => 'status', + 'type' => Database::VAR_STRING, + 'format' => '', + 'size' => 128, + 'signed' => true, + 'required' => false, + 'array' => false, + 'filters' => [], + ], + [ + '$id' => 'stdout', + 'type' => Database::VAR_STRING, + 'format' => '', + 'size' => 16384, + 'signed' => true, + 'required' => false, + 'array' => false, + 'filters' => [], + ], + [ + '$id' => 'stderr', + 'type' => Database::VAR_STRING, + 'format' => '', + 'size' => 16384, + 'signed' => true, + 'required' => false, + 'array' => false, + 'filters' => [], + ], + [ + '$id' => 'exitCode', + 'type' => Database::VAR_INTEGER, + 'format' => '', + 'size' => 0, + 'signed' => true, + 'required' => false, + 'array' => false, + 'filters' => [], + ], + [ + '$id' => 'time', + 'type' => Database::VAR_FLOAT, + 'format' => '', + 'size' => 0, + 'signed' => true, + 'required' => false, + 'array' => false, + 'filters' => [], + ], + ], + 'indexes' => [], + ], ]; -/* - * Add enabled OAuth2 providers to default data rules - */ -// foreach ($providers as $index => $provider) { -// if (!$provider['enabled']) { -// continue; -// } - -// $collections[Database::SYSTEM_COLLECTION_PROJECTS]['rules'][] = [ -// '$collection' => Database::SYSTEM_COLLECTION_RULES, -// 'label' => 'OAuth2 '.\ucfirst($index).' ID', -// 'key' => 'usersOauth2'.\ucfirst($index).'Appid', -// 'type' => Database::SYSTEM_VAR_TYPE_TEXT, -// 'default' => '', -// 'required' => false, -// 'array' => false, -// ]; - -// $collections[Database::SYSTEM_COLLECTION_PROJECTS]['rules'][] = [ -// '$collection' => Database::SYSTEM_COLLECTION_RULES, -// 'label' => 'OAuth2 '.\ucfirst($index).' Secret', -// 'key' => 'usersOauth2'.\ucfirst($index).'Secret', -// 'type' => Database::SYSTEM_VAR_TYPE_TEXT, -// 'default' => '', -// 'required' => false, -// 'array' => false, -// 'filter' => ['encrypt'], -// ]; -// } - -// foreach ($auth as $index => $method) { -// $collections[Database::SYSTEM_COLLECTION_PROJECTS]['rules'][] = [ -// '$collection' => Database::SYSTEM_COLLECTION_RULES, -// 'label' => $method['name'] || '', -// 'key' => $method['key'] || '', -// 'type' => Database::SYSTEM_VAR_TYPE_BOOLEAN, -// 'default' => true, -// 'required' => false, -// ]; -// } - return $collections; \ No newline at end of file diff --git a/app/controllers/api/functions.php b/app/controllers/api/functions.php index ff8b7d5bc9..84d5bc9219 100644 --- a/app/controllers/api/functions.php +++ b/app/controllers/api/functions.php @@ -2,9 +2,6 @@ use Ahc\Jwt\JWT; use Appwrite\Auth\Auth; -use Appwrite\Database\Database; -use Appwrite\Database\Document; -use Appwrite\Database\Validator\Authorization; use Appwrite\Database\Validator\UID; use Utopia\Storage\Storage; use Utopia\Storage\Validator\File; @@ -14,6 +11,10 @@ use Utopia\Storage\Validator\Upload; use Appwrite\Utopia\Response; use Appwrite\Task\Validator\Cron; use Utopia\App; +use Utopia\Exception; +use Utopia\Database\Document; +use Utopia\Database\Query; +use Utopia\Database\Validator\Authorization; use Utopia\Validator\ArrayList; use Utopia\Validator\Assoc; use Utopia\Validator\Text; @@ -21,7 +22,6 @@ use Utopia\Validator\Range; use Utopia\Validator\WhiteList; use Utopia\Config\Config; use Cron\CronExpression; -use Utopia\Exception; include_once __DIR__ . '/../shared/api.php'; @@ -45,16 +45,13 @@ App::post('/v1/functions') ->param('schedule', '', new Cron(), 'Schedule CRON syntax.', true) ->param('timeout', 15, new Range(1, 900), 'Function maximum execution time in seconds.', true) ->inject('response') - ->inject('projectDB') - ->action(function ($name, $execute, $env, $vars, $events, $schedule, $timeout, $response, $projectDB) { + ->inject('dbForInternal') + ->action(function ($name, $execute, $env, $vars, $events, $schedule, $timeout, $response, $dbForInternal) { /** @var Appwrite\Utopia\Response $response */ - /** @var Appwrite\Database\Database $projectDB */ + /** @var Utopia\Database\Database $dbForInternal */ - $function = $projectDB->createDocument([ - '$collection' => Database::SYSTEM_COLLECTION_FUNCTIONS, - '$permissions' => [ - 'execute' => $execute, - ], + $function = $dbForInternal->createDocument('functions', new Document([ + 'execute' => $execute, 'dateCreated' => time(), 'dateUpdated' => time(), 'status' => 'disabled', @@ -64,10 +61,10 @@ App::post('/v1/functions') 'vars' => $vars, 'events' => $events, 'schedule' => $schedule, - 'schedulePrevious' => null, - 'scheduleNext' => null, + 'schedulePrevious' => 0, + 'scheduleNext' => 0, 'timeout' => $timeout, - ]); + ])); if (false === $function) { throw new Exception('Failed saving function to DB', 500); @@ -75,7 +72,7 @@ App::post('/v1/functions') $response ->setStatusCode(Response::STATUS_CODE_CREATED) - ->dynamic($function, Response::MODEL_FUNCTION) + ->dynamic2($function, Response::MODEL_FUNCTION) ; }); @@ -95,24 +92,14 @@ App::get('/v1/functions') ->param('offset', 0, new Range(0, 2000), 'Results offset. The default value is 0. Use this param to manage pagination.', true) ->param('orderType', 'ASC', new WhiteList(['ASC', 'DESC'], true), 'Order result by ASC or DESC order.', true) ->inject('response') - ->inject('projectDB') - ->action(function ($search, $limit, $offset, $orderType, $response, $projectDB) { + ->inject('dbForInternal') + ->action(function ($search, $limit, $offset, $orderType, $response, $dbForInternal) { /** @var Appwrite\Utopia\Response $response */ - /** @var Appwrite\Database\Database $projectDB */ + /** @var Utopia\Database\Database $dbForInternal */ - $results = $projectDB->getCollection([ - 'limit' => $limit, - 'offset' => $offset, - 'orderType' => $orderType, - 'search' => $search, - 'filters' => [ - '$collection='.Database::SYSTEM_COLLECTION_FUNCTIONS, - ], - ]); - - $response->dynamic(new Document([ - 'sum' => $projectDB->getSum(), - 'functions' => $results + $response->dynamic2(new Document([ + 'sum' => $dbForInternal->count('functions', [], 5000), + 'functions' => $dbForInternal->find('functions', [], $limit, $offset, [], []) ]), Response::MODEL_FUNCTION_LIST); }); @@ -129,18 +116,18 @@ App::get('/v1/functions/:functionId') ->label('sdk.response.model', Response::MODEL_FUNCTION) ->param('functionId', '', new UID(), 'Function unique ID.') ->inject('response') - ->inject('projectDB') - ->action(function ($functionId, $response, $projectDB) { + ->inject('dbForInternal') + ->action(function ($functionId, $response, $dbForInternal) { /** @var Appwrite\Utopia\Response $response */ - /** @var Appwrite\Database\Database $projectDB */ + /** @var Utopia\Database\Database $dbForInternal */ - $function = $projectDB->getDocument($functionId); + $function = $dbForInternal->getDocument('functions', $functionId); - if (empty($function->getId()) || Database::SYSTEM_COLLECTION_FUNCTIONS != $function->getCollection()) { + if (empty($function->getId())) { throw new Exception('Function not found', 404); } - $response->dynamic($function, Response::MODEL_FUNCTION); + $response->dynamic2($function, Response::MODEL_FUNCTION); }); App::get('/v1/functions/:functionId/usage') @@ -154,18 +141,18 @@ App::get('/v1/functions/:functionId/usage') ->param('range', '30d', new WhiteList(['24h', '7d', '30d', '90d']), 'Date range.', true) ->inject('response') ->inject('project') - ->inject('projectDB') + ->inject('dbForInternal') ->inject('register') - ->action(function ($functionId, $range, $response, $project, $projectDB, $register) { + ->action(function ($functionId, $range, $response, $project, $dbForInternal, $register) { /** @var Appwrite\Utopia\Response $response */ /** @var Appwrite\Database\Document $project */ - /** @var Appwrite\Database\Database $consoleDB */ - /** @var Appwrite\Database\Database $projectDB */ + /** @var Utopia\Database\Database $consoleDB */ + /** @var Utopia\Database\Database $dbForInternal */ /** @var Utopia\Registry\Registry $register */ - $function = $projectDB->getDocument($functionId); + $function = $dbForInternal->getDocument('functions', $functionId); - if (empty($function->getId()) || Database::SYSTEM_COLLECTION_FUNCTIONS != $function->getCollection()) { + if (empty($function->getId())) { throw new Exception('Function not found', 404); } @@ -284,35 +271,33 @@ App::put('/v1/functions/:functionId') ->param('schedule', '', new Cron(), 'Schedule CRON syntax.', true) ->param('timeout', 15, new Range(1, 900), 'Function maximum execution time in seconds.', true) ->inject('response') - ->inject('projectDB') + ->inject('dbForInternal') ->inject('project') - ->action(function ($functionId, $name, $execute, $vars, $events, $schedule, $timeout, $response, $projectDB, $project) { + ->action(function ($functionId, $name, $execute, $vars, $events, $schedule, $timeout, $response, $dbForInternal, $project) { /** @var Appwrite\Utopia\Response $response */ - /** @var Appwrite\Database\Database $projectDB */ + /** @var Utopia\Database\Database $dbForInternal */ /** @var Appwrite\Database\Document $project */ - $function = $projectDB->getDocument($functionId); + $function = $dbForInternal->getDocument('functions', $functionId); - if (empty($function->getId()) || Database::SYSTEM_COLLECTION_FUNCTIONS != $function->getCollection()) { + if (empty($function->getId())) { throw new Exception('Function not found', 404); } $original = $function->getAttribute('schedule', ''); $cron = (!empty($function->getAttribute('tag', null)) && !empty($schedule)) ? new CronExpression($schedule) : null; - $next = (!empty($function->getAttribute('tag', null)) && !empty($schedule)) ? $cron->getNextRunDate()->format('U') : null; + $next = (!empty($function->getAttribute('tag', null)) && !empty($schedule)) ? $cron->getNextRunDate()->format('U') : 0; - $function = $projectDB->updateDocument(array_merge($function->getArrayCopy(), [ - '$permissions' => [ - 'execute' => $execute, - ], + $function = $dbForInternal->updateDocument('functions', $function->getId(), new Document(array_merge($function->getArrayCopy(), [ + 'execute' => $execute, 'dateUpdated' => time(), 'name' => $name, 'vars' => $vars, 'events' => $events, 'schedule' => $schedule, - 'scheduleNext' => $next, + 'scheduleNext' => (int)$next, 'timeout' => $timeout, - ])); + ]))); if (false === $function) { throw new Exception('Failed saving function to DB', 500); @@ -327,7 +312,7 @@ App::put('/v1/functions/:functionId') ]); // Async task rescheduale } - $response->dynamic($function, Response::MODEL_FUNCTION); + $response->dynamic2($function, Response::MODEL_FUNCTION); }); App::patch('/v1/functions/:functionId/tag') @@ -345,32 +330,32 @@ App::patch('/v1/functions/:functionId/tag') ->param('functionId', '', new UID(), 'Function unique ID.') ->param('tag', '', new UID(), 'Tag unique ID.') ->inject('response') - ->inject('projectDB') + ->inject('dbForInternal') ->inject('project') - ->action(function ($functionId, $tag, $response, $projectDB, $project) { + ->action(function ($functionId, $tag, $response, $dbForInternal, $project) { /** @var Appwrite\Utopia\Response $response */ - /** @var Appwrite\Database\Database $projectDB */ + /** @var Utopia\Database\Database $dbForInternal */ /** @var Appwrite\Database\Document $project */ - $function = $projectDB->getDocument($functionId); - $tag = $projectDB->getDocument($tag); + $function = $dbForInternal->getDocument('functions', $functionId); + $tag = $dbForInternal->getDocument('tags', $tag); - if (empty($function->getId()) || Database::SYSTEM_COLLECTION_FUNCTIONS != $function->getCollection()) { + if (empty($function->getId())) { throw new Exception('Function not found', 404); } - if (empty($tag->getId()) || Database::SYSTEM_COLLECTION_TAGS != $tag->getCollection()) { + if (empty($tag->getId())) { throw new Exception('Tag not found', 404); } $schedule = $function->getAttribute('schedule', ''); $cron = (empty($function->getAttribute('tag')) && !empty($schedule)) ? new CronExpression($schedule) : null; - $next = (empty($function->getAttribute('tag')) && !empty($schedule)) ? $cron->getNextRunDate()->format('U') : null; + $next = (empty($function->getAttribute('tag')) && !empty($schedule)) ? $cron->getNextRunDate()->format('U') : 0; - $function = $projectDB->updateDocument(array_merge($function->getArrayCopy(), [ + $function = $dbForInternal->updateDocument('functions', $function->getId(), new Document(array_merge($function->getArrayCopy(), [ 'tag' => $tag->getId(), - 'scheduleNext' => $next, - ])); + 'scheduleNext' => (int)$next, + ]))); if ($next) { // Init first schedule ResqueScheduler::enqueueAt($next, 'v1-functions', 'FunctionsV1', [ @@ -385,7 +370,7 @@ App::patch('/v1/functions/:functionId/tag') throw new Exception('Failed saving function to DB', 500); } - $response->dynamic($function, Response::MODEL_FUNCTION); + $response->dynamic2($function, Response::MODEL_FUNCTION); }); App::delete('/v1/functions/:functionId') @@ -401,20 +386,20 @@ App::delete('/v1/functions/:functionId') ->label('sdk.response.model', Response::MODEL_NONE) ->param('functionId', '', new UID(), 'Function unique ID.') ->inject('response') - ->inject('projectDB') + ->inject('dbForInternal') ->inject('deletes') - ->action(function ($functionId, $response, $projectDB, $deletes) { + ->action(function ($functionId, $response, $dbForInternal, $deletes) { /** @var Appwrite\Utopia\Response $response */ - /** @var Appwrite\Database\Database $projectDB */ + /** @var Utopia\Database\Database $dbForInternal */ /** @var Appwrite\Event\Event $deletes */ - $function = $projectDB->getDocument($functionId); + $function = $dbForInternal->getDocument('functions', $functionId); - if (empty($function->getId()) || Database::SYSTEM_COLLECTION_FUNCTIONS != $function->getCollection()) { + if (empty($function->getId())) { throw new Exception('Function not found', 404); } - if (!$projectDB->deleteDocument($function->getId())) { + if (!$dbForInternal->deleteDocument('functions', $function->getId())) { throw new Exception('Failed to remove function from DB', 500); } @@ -445,17 +430,17 @@ App::post('/v1/functions/:functionId/tags') ->param('code', [], new File(), 'Gzip file with your code package. When used with the Appwrite CLI, pass the path to your code directory, and the CLI will automatically package your code. Use a path that is within the current directory.', false) ->inject('request') ->inject('response') - ->inject('projectDB') + ->inject('dbForInternal') ->inject('usage') - ->action(function ($functionId, $command, $file, $request, $response, $projectDB, $usage) { + ->action(function ($functionId, $command, $file, $request, $response, $dbForInternal, $usage) { /** @var Utopia\Swoole\Request $request */ /** @var Appwrite\Utopia\Response $response */ - /** @var Appwrite\Database\Database $projectDB */ + /** @var Utopia\Database\Database $dbForInternal */ /** @var Appwrite\Event\Event $usage */ - $function = $projectDB->getDocument($functionId); + $function = $dbForInternal->getDocument('functions', $functionId); - if (empty($function->getId()) || Database::SYSTEM_COLLECTION_FUNCTIONS != $function->getCollection()) { + if (empty($function->getId())) { throw new Exception('Function not found', 404); } @@ -494,18 +479,15 @@ App::post('/v1/functions/:functionId/tags') throw new Exception('Failed moving file', 500); } - $tag = $projectDB->createDocument([ - '$collection' => Database::SYSTEM_COLLECTION_TAGS, - '$permissions' => [ - 'read' => [], - 'write' => [], - ], + $tag = $dbForInternal->createDocument('tags', new Document([ + '$read' => [], + '$write' => [], 'functionId' => $function->getId(), 'dateCreated' => time(), 'command' => $command, 'path' => $path, 'size' => $size, - ]); + ])); if (false === $tag) { throw new Exception('Failed saving tag to DB', 500); @@ -517,7 +499,7 @@ App::post('/v1/functions/:functionId/tags') $response ->setStatusCode(Response::STATUS_CODE_CREATED) - ->dynamic($tag, Response::MODEL_TAG) + ->dynamic2($tag, Response::MODEL_TAG) ; }); @@ -538,30 +520,27 @@ App::get('/v1/functions/:functionId/tags') ->param('offset', 0, new Range(0, 2000), 'Results offset. The default value is 0. Use this param to manage pagination.', true) ->param('orderType', 'ASC', new WhiteList(['ASC', 'DESC'], true), 'Order result by ASC or DESC order.', true) ->inject('response') - ->inject('projectDB') - ->action(function ($functionId, $search, $limit, $offset, $orderType, $response, $projectDB) { + ->inject('dbForInternal') + ->action(function ($functionId, $search, $limit, $offset, $orderType, $response, $dbForInternal) { /** @var Appwrite\Utopia\Response $response */ - /** @var Appwrite\Database\Database $projectDB */ + /** @var Utopia\Database\Database $dbForInternal */ - $function = $projectDB->getDocument($functionId); + $function = $dbForInternal->getDocument('functions', $functionId); - if (empty($function->getId()) || Database::SYSTEM_COLLECTION_FUNCTIONS != $function->getCollection()) { + if (empty($function->getId())) { throw new Exception('Function not found', 404); } - $results = $projectDB->getCollection([ - 'limit' => $limit, - 'offset' => $offset, - 'orderType' => $orderType, - 'search' => $search, - 'filters' => [ - '$collection='.Database::SYSTEM_COLLECTION_TAGS, - 'functionId='.$function->getId(), - ], - ]); + $results = $dbForInternal->find('tags', [ + new Query('functionId', Query::TYPE_EQUAL, [$function->getId()]), + ], $limit, $offset); + + $sum = $dbForInternal->count('tags', [ + new Query('functionId', Query::TYPE_EQUAL, [$function->getId()]), + ], 5000); - $response->dynamic(new Document([ - 'sum' => $projectDB->getSum(), + $response->dynamic2(new Document([ + 'sum' => $sum, 'tags' => $results ]), Response::MODEL_TAG_LIST); }); @@ -580,28 +559,28 @@ App::get('/v1/functions/:functionId/tags/:tagId') ->param('functionId', '', new UID(), 'Function unique ID.') ->param('tagId', '', new UID(), 'Tag unique ID.') ->inject('response') - ->inject('projectDB') - ->action(function ($functionId, $tagId, $response, $projectDB) { + ->inject('dbForInternal') + ->action(function ($functionId, $tagId, $response, $dbForInternal) { /** @var Appwrite\Utopia\Response $response */ - /** @var Appwrite\Database\Database $projectDB */ + /** @var Utopia\Database\Database $dbForInternal */ - $function = $projectDB->getDocument($functionId); + $function = $dbForInternal->getDocument('functions', $functionId); - if (empty($function->getId()) || Database::SYSTEM_COLLECTION_FUNCTIONS != $function->getCollection()) { + if (empty($function->getId())) { throw new Exception('Function not found', 404); } - $tag = $projectDB->getDocument($tagId); + $tag = $dbForInternal->getDocument('tags', $tagId); if ($tag->getAttribute('functionId') !== $function->getId()) { throw new Exception('Tag not found', 404); } - if (empty($tag->getId()) || Database::SYSTEM_COLLECTION_TAGS != $tag->getCollection()) { + if (empty($tag->getId())) { throw new Exception('Tag not found', 404); } - $response->dynamic($tag, Response::MODEL_TAG); + $response->dynamic2($tag, Response::MODEL_TAG); }); App::delete('/v1/functions/:functionId/tags/:tagId') @@ -618,41 +597,41 @@ App::delete('/v1/functions/:functionId/tags/:tagId') ->param('functionId', '', new UID(), 'Function unique ID.') ->param('tagId', '', new UID(), 'Tag unique ID.') ->inject('response') - ->inject('projectDB') + ->inject('dbForInternal') ->inject('usage') - ->action(function ($functionId, $tagId, $response, $projectDB, $usage) { + ->action(function ($functionId, $tagId, $response, $dbForInternal, $usage) { /** @var Appwrite\Utopia\Response $response */ - /** @var Appwrite\Database\Database $projectDB */ + /** @var Utopia\Database\Database $dbForInternal */ /** @var Appwrite\Event\Event $usage */ - $function = $projectDB->getDocument($functionId); + $function = $dbForInternal->getDocument('functions', $functionId); - if (empty($function->getId()) || Database::SYSTEM_COLLECTION_FUNCTIONS != $function->getCollection()) { + if (empty($function->getId())) { throw new Exception('Function not found', 404); } - $tag = $projectDB->getDocument($tagId); + $tag = $dbForInternal->getDocument('tags', $tagId); if ($tag->getAttribute('functionId') !== $function->getId()) { throw new Exception('Tag not found', 404); } - if (empty($tag->getId()) || Database::SYSTEM_COLLECTION_TAGS != $tag->getCollection()) { + if (empty($tag->getId())) { throw new Exception('Tag not found', 404); } $device = Storage::getDevice('functions'); if ($device->delete($tag->getAttribute('path', ''))) { - if (!$projectDB->deleteDocument($tag->getId())) { + if (!$dbForInternal->deleteDocument('tags', $tag->getId())) { throw new Exception('Failed to remove tag from DB', 500); } } if($function->getAttribute('tag') === $tag->getId()) { // Reset function tag - $function = $projectDB->updateDocument(array_merge($function->getArrayCopy(), [ + $function = $dbForInternal->updateDocument('functions', $function->getId(), new Document(array_merge($function->getArrayCopy(), [ 'tag' => '', - ])); + ]))); if (false === $function) { throw new Exception('Failed saving function to DB', 500); @@ -685,29 +664,29 @@ App::post('/v1/functions/:functionId/executions') // ->param('async', 1, new Range(0, 1), 'Execute code asynchronously. Pass 1 for true, 0 for false. Default value is 1.', true) ->inject('response') ->inject('project') - ->inject('projectDB') + ->inject('dbForInternal') ->inject('user') - ->action(function ($functionId, $data, /*$async,*/ $response, $project, $projectDB, $user) { + ->action(function ($functionId, $data, /*$async,*/ $response, $project, $dbForInternal, $user) { /** @var Appwrite\Utopia\Response $response */ /** @var Appwrite\Database\Document $project */ - /** @var Appwrite\Database\Database $projectDB */ + /** @var Utopia\Database\Database $dbForInternal */ /** @var Appwrite\Database\Document $user */ Authorization::disable(); - $function = $projectDB->getDocument($functionId); + $function = $dbForInternal->getDocument('functions', $functionId); - if (empty($function->getId()) || Database::SYSTEM_COLLECTION_FUNCTIONS != $function->getCollection()) { + if (empty($function->getId())) { throw new Exception('Function not found', 404); } - $tag = $projectDB->getDocument($function->getAttribute('tag')); + $tag = $dbForInternal->getDocument('tags', $function->getAttribute('tag')); if ($tag->getAttribute('functionId') !== $function->getId()) { throw new Exception('Tag not found. Deploy tag before trying to execute a function', 404); } - if (empty($tag->getId()) || Database::SYSTEM_COLLECTION_TAGS != $tag->getCollection()) { + if (empty($tag->getId())) { throw new Exception('Tag not found. Deploy tag before trying to execute a function', 404); } @@ -715,27 +694,25 @@ App::post('/v1/functions/:functionId/executions') $validator = new Authorization($function, 'execute'); - if (!$validator->isValid($function->getPermissions())) { // Check if user has write access to execute function + if (!$validator->isValid($function->getAttribute('execute'))) { // Check if user has write access to execute function throw new Exception($validator->getDescription(), 401); } Authorization::disable(); - $execution = $projectDB->createDocument([ - '$collection' => Database::SYSTEM_COLLECTION_EXECUTIONS, - '$permissions' => [ - 'read' => (!empty($user->getId())) ? ['user:' . $user->getId()] : [], - 'write' => [], - ], + $execution = $dbForInternal->createDocument('executions', new Document([ + '$read' => (!empty($user->getId())) ? ['user:' . $user->getId()] : [], + '$write' => [], 'dateCreated' => time(), 'functionId' => $function->getId(), + 'tagId' => $tag->getId(), 'trigger' => 'http', // http / schedule / event 'status' => 'waiting', // waiting / processing / completed / failed 'exitCode' => 0, 'stdout' => '', 'stderr' => '', - 'time' => 0, - ]); + 'time' => 0.0, + ])); Authorization::reset(); @@ -776,7 +753,7 @@ App::post('/v1/functions/:functionId/executions') $response ->setStatusCode(Response::STATUS_CODE_CREATED) - ->dynamic($execution, Response::MODEL_EXECUTION) + ->dynamic2($execution, Response::MODEL_EXECUTION) ; }); @@ -797,32 +774,29 @@ App::get('/v1/functions/:functionId/executions') ->param('offset', 0, new Range(0, 2000), 'Results offset. The default value is 0. Use this param to manage pagination.', true) ->param('orderType', 'ASC', new WhiteList(['ASC', 'DESC'], true), 'Order result by ASC or DESC order.', true) ->inject('response') - ->inject('projectDB') - ->action(function ($functionId, $search, $limit, $offset, $orderType, $response, $projectDB) { + ->inject('dbForInternal') + ->action(function ($functionId, $search, $limit, $offset, $orderType, $response, $dbForInternal) { /** @var Appwrite\Utopia\Response $response */ - /** @var Appwrite\Database\Database $projectDB */ + /** @var Utopia\Database\Database $dbForInternal */ Authorization::disable(); - $function = $projectDB->getDocument($functionId); + $function = $dbForInternal->getDocument('functions', $functionId); Authorization::reset(); - if (empty($function->getId()) || Database::SYSTEM_COLLECTION_FUNCTIONS != $function->getCollection()) { + if (empty($function->getId())) { throw new Exception('Function not found', 404); } - $results = $projectDB->getCollection([ - 'limit' => $limit, - 'offset' => $offset, - 'orderType' => $orderType, - 'search' => $search, - 'filters' => [ - '$collection='.Database::SYSTEM_COLLECTION_EXECUTIONS, - 'functionId='.$function->getId(), - ], - ]); + $results = $dbForInternal->find('executions', [ + new Query('functionId', Query::TYPE_EQUAL, [$function->getId()]), + ], $limit, $offset); + + $sum = $dbForInternal->count('executions', [ + new Query('functionId', Query::TYPE_EQUAL, [$function->getId()]), + ], 5000); - $response->dynamic(new Document([ - 'sum' => $projectDB->getSum(), + $response->dynamic2(new Document([ + 'sum' => $sum, 'executions' => $results ]), Response::MODEL_EXECUTION_LIST); }); @@ -841,28 +815,28 @@ App::get('/v1/functions/:functionId/executions/:executionId') ->param('functionId', '', new UID(), 'Function unique ID.') ->param('executionId', '', new UID(), 'Execution unique ID.') ->inject('response') - ->inject('projectDB') - ->action(function ($functionId, $executionId, $response, $projectDB) { + ->inject('dbForInternal') + ->action(function ($functionId, $executionId, $response, $dbForInternal) { /** @var Appwrite\Utopia\Response $response */ - /** @var Appwrite\Database\Database $projectDB */ + /** @var Utopia\Database\Database $dbForInternal */ Authorization::disable(); - $function = $projectDB->getDocument($functionId); + $function = $dbForInternal->getDocument('functions', $functionId); Authorization::reset(); - if (empty($function->getId()) || Database::SYSTEM_COLLECTION_FUNCTIONS != $function->getCollection()) { + if (empty($function->getId())) { throw new Exception('Function not found', 404); } - $execution = $projectDB->getDocument($executionId); + $execution = $dbForInternal->getDocument('executions', $executionId); if ($execution->getAttribute('functionId') !== $function->getId()) { throw new Exception('Execution not found', 404); } - if (empty($execution->getId()) || Database::SYSTEM_COLLECTION_EXECUTIONS != $execution->getCollection()) { + if (empty($execution->getId())) { throw new Exception('Execution not found', 404); } - $response->dynamic($execution, Response::MODEL_EXECUTION); + $response->dynamic2($execution, Response::MODEL_EXECUTION); }); diff --git a/app/init.php b/app/init.php index 666bf59f56..2990fc6276 100644 --- a/app/init.php +++ b/app/init.php @@ -33,7 +33,7 @@ use PDO as PDONative; use Utopia\Cache\Adapter\Redis as RedisCache; use Utopia\Cache\Cache; use Utopia\Database\Adapter\MariaDB; -use Utopia\Database\Database as DatabaseDatabase; +use Utopia\Database\Database as Database2; use Utopia\Database\Validator\Authorization as Authorization2; const APP_NAME = 'Appwrite'; @@ -147,6 +147,27 @@ Database::addFilter('encrypt', } ); +Database2::addFilter('encrypt', + function($value) { + $key = App::getEnv('_APP_OPENSSL_KEY_V1'); + $iv = OpenSSL::randomPseudoBytes(OpenSSL::cipherIVLength(OpenSSL::CIPHER_AES_128_GCM)); + $tag = null; + return json_encode([ + 'data' => OpenSSL::encrypt($value, OpenSSL::CIPHER_AES_128_GCM, $key, 0, $iv, $tag), + 'method' => OpenSSL::CIPHER_AES_128_GCM, + 'iv' => bin2hex($iv), + 'tag' => bin2hex($tag), + 'version' => '1', + ]); + }, + function($value) { + $value = json_decode($value, true); + $key = App::getEnv('_APP_OPENSSL_KEY_V'.$value['version']); + + return OpenSSL::decrypt($value['data'], $value['method'], $key, 0, hex2bin($value['iv']), hex2bin($value['tag'])); + } +); + /* * Registry */ @@ -512,7 +533,7 @@ App::setResource('projectDB', function($register, $project) { App::setResource('dbForInternal', function($register, $project) { $cache = new Cache(new RedisCache($register->get('cache'))); - $database = new DatabaseDatabase(new MariaDB($register->get('db')), $cache); + $database = new Database2(new MariaDB($register->get('db')), $cache); $database->setNamespace('project_'.$project->getId().'_internal'); return $database; @@ -521,7 +542,7 @@ App::setResource('dbForInternal', function($register, $project) { App::setResource('dbForExternal', function($register, $project) { $cache = new Cache(new RedisCache($register->get('cache'))); - $database = new DatabaseDatabase(new MariaDB($register->get('db')), $cache); + $database = new Database2(new MariaDB($register->get('db')), $cache); $database->setNamespace('project_'.$project->getId().'_external'); return $database; @@ -530,7 +551,7 @@ App::setResource('dbForExternal', function($register, $project) { App::setResource('dbForConsole', function($register) { $cache = new Cache(new RedisCache($register->get('cache'))); - $database = new DatabaseDatabase(new MariaDB($register->get('db')), $cache); + $database = new Database2(new MariaDB($register->get('db')), $cache); $database->setNamespace('project_console'); return $database; diff --git a/composer.lock b/composer.lock index 4fa4972aa0..997d6156df 100644 --- a/composer.lock +++ b/composer.lock @@ -1923,7 +1923,7 @@ "source": { "type": "git", "url": "https://github.com/utopia-php/database", - "reference": "2299091c63aec2315a4f40bc8dd16968c5bec6bf" + "reference": "52c8cacf1d7930c7ae4cad034666a4322e3c56b0" }, "require": { "ext-mongodb": "*", @@ -1970,7 +1970,7 @@ "upf", "utopia" ], - "time": "2021-05-03T22:49:00+00:00" + "time": "2021-05-04T21:14:11+00:00" }, { "name": "utopia-php/domains",