From 0e3f4a4745f0024873156040d8f9f1cc55edbba6 Mon Sep 17 00:00:00 2001 From: Bluefox Date: Sat, 20 Jul 2024 19:04:17 +0900 Subject: [PATCH] Extension of localLinks structure in io-package.json (#2844) * Extension of localLinks structure in io-package.json * Extension of localLinks structure in io-package.json * Extension of localLinks structure in io-package.json * Extension of localLinks structure in io-package.json * Extension of localLinks structure in io-package.json * do not merge visWidgets and localLinks * Update schemas/io-package.json Co-authored-by: Max Hauser * Added comments and removed deprecationMessages * added test * format --------- Co-authored-by: Max Hauser --- packages/cli/src/lib/setup/setupUpload.ts | 9 +++- packages/types-dev/config.d.ts | 6 +-- packages/types-dev/objects.d.ts | 37 ++++++++++++---- packages/types-public/index.test-d.ts | 7 +++ schemas/io-package.json | 54 +++++++++++++++++++++-- 5 files changed, 97 insertions(+), 16 deletions(-) diff --git a/packages/cli/src/lib/setup/setupUpload.ts b/packages/cli/src/lib/setup/setupUpload.ts index 19ba2da946..0bb36e0861 100644 --- a/packages/cli/src/lib/setup/setupUpload.ts +++ b/packages/cli/src/lib/setup/setupUpload.ts @@ -1,7 +1,7 @@ /** * Upload adapter files into DB * - * Copyright 2013-2023 bluefox + * Copyright 2013-2024 bluefox * * MIT License * @@ -744,12 +744,19 @@ export class Upload { newObject.common.installedVersion = ioPack.common.version; newObject.common.installedFrom = ioPack.common.installedFrom; + // do not merge visWidgets and localLinks if (ioPack.common.visWidgets) { newObject.common.visWidgets = ioPack.common.visWidgets; } else { delete newObject.common.visWidgets; } + if (ioPack.common.localLinks) { + newObject.common.localLinks = ioPack.common.localLinks; + } else { + delete newObject.common.localLinks; + } + if (!ioPack.common.compact && newObject.common.compact) { newObject.common.compact = ioPack.common.compact; } diff --git a/packages/types-dev/config.d.ts b/packages/types-dev/config.d.ts index 1305113ffa..4c519a23dc 100644 --- a/packages/types-dev/config.d.ts +++ b/packages/types-dev/config.d.ts @@ -9,7 +9,7 @@ interface DatabaseBackupOptions { /** by default backup every 2 hours. Time is in minutes. To disable backup set the value to 0 */ period: number; '// period': string; - /** Absolute path to backup directory or empty to backup in data directory */ + /** Absolute path to back-up directory or empty to back-up in data directory */ path: string; '// path': string; } @@ -33,7 +33,7 @@ interface JsonlOptions { '// throttleFS (1)': string; '// throttleFS (2)': string; /** - * By default, the database immediately writes to the database file. Write accesses can be reduced using the throttleFS option. + * By default, the database immediately writes to the database file. Write access can be reduced using the throttleFS option. * Be aware that buffered changes will be lost in case the process crashes */ throttleFS: { @@ -41,7 +41,7 @@ interface JsonlOptions { /** Write to the database file no more than every intervalMs milliseconds. */ intervalMs: number; '// maxBufferedCommands': string; - /** Force writing after this many changes have been buffered. This reduces memory consumption and data loss in case of a crash. */ + /** Force writing of buffered commands after so many changes. This reduces memory consumption and data loss in case of a crash. */ maxBufferedCommands: number; }; } diff --git a/packages/types-dev/objects.d.ts b/packages/types-dev/objects.d.ts index 439d18ae34..b3c6d4e055 100644 --- a/packages/types-dev/objects.d.ts +++ b/packages/types-dev/objects.d.ts @@ -574,6 +574,27 @@ declare global { type ConnectionType = 'local' | 'cloud'; + type LocalLink = { + /** Link to the web service of this adapter, like: "%web_protocol%://%ip%:%web_port%/vis-2/edit.html" */ + link: string; + /** Name of the link. Could be multi-language */ + name?: ioBroker.StringOrTranslated; + /** Color */ + color?: string; + /** Link to icon, like "vis-2/img/favicon.png" */ + icon?: string; + /** Link to the adapter if it could be shown in the free cloud, like: vis-2/index.html according to "https://iobroker.net/" */ + cloud?: string; + /** Link to the adapter if it could be shown in the pro-cloud, like: vis-2/edit.html according to "https://iobroker.pro/" */ + pro?: string; + /** If this link should be shown on the intro tab in admin. false = do not show */ + intro?: boolean; + /** Order of the card. Used on "intro" and cloud tabs to sort the links */ + order?: number; + /** Description of the link. Could be multi-language */ + description?: ioBroker.StringOrTranslated; + }; + interface AdapterCommon extends ObjectCommon { /** Custom attributes to be shown in admin in the object browser */ adminColumns?: string | (string | CustomAdminColumn)[]; @@ -604,7 +625,7 @@ declare global { blockly?: boolean; /** Where the adapter will get its data from. Set this together with @see dataSource */ connectionType?: ConnectionType; - /** If true, this adapter can be started in compact mode (in the same process as other adpaters) */ + /** If true, this adapter can be started in compact mode (in the same process as other adapters) */ compact?: boolean; /** The directory relative to iobroker-data where the adapter stores the data. Supports the placeholder `%INSTANCE%`. This folder will be backed up and restored automatically. */ dataFolder?: string; @@ -626,7 +647,7 @@ declare global { getHistory?: boolean; /** Filename of the local icon which is shown for installed adapters. Should be located in the `admin` directory */ icon?: string; - /** The adapter will be executed once additionally after installation and the `install` event will be emitted during this run. This allows for executing one time installation code. */ + /** The adapter will be executed once additionally after installation, and the `install` event will be emitted during this run. This allows for executing one time installation code. */ install?: boolean; /** Source, where this adapter has been installed from, to enable reinstalling on e.g., backup restore */ installedFrom?: InstalledFrom; @@ -634,17 +655,17 @@ declare global { installedVersion: string; keywords?: string[]; /** A dictionary of links to web services this adapter provides */ - localLinks?: Record; + localLinks?: Record; /** @deprecated Use @see localLinks */ localLink?: string; loglevel?: LogLevel; - /** Whether this adapter receives logs from other hosts and adapters (e.g., to strore them somewhere) */ + /** Whether this adapter receives logs from other hosts and adapters (e.g., to store them somewhere) */ logTransporter?: boolean; /** Path to the start file of the adapter. Should be the same as in `package.json` */ main?: string; - /** Whether the admin tab is written in materialize style. Required for Admin 3+ */ + /** Whether the admin tab is written in materialized style. Required for Admin 3+ */ materializeTab?: boolean; - /** Whether the admin configuration dialog is written in materialize style. Required for Admin 3+ */ + /** Whether the admin configuration dialog is written in materialized style. Required for Admin 3+ */ materialize: boolean; /** @deprecated Use @see supportedMessages up from controller v5 */ messagebox?: true; @@ -720,9 +741,9 @@ declare global { webExtension?: string; webPreSettings?: any; // ? webservers?: any; // ? - /** A list of pages that should be shown on the "web" index page */ + /** @deprecated (use localLinks) A list of pages that should be shown on the "web" index page */ welcomeScreen?: WelcomeScreenEntry[]; - /** A list of pages that should be shown on the ioBroker cloud index page */ + /** @deprecated (use localLinks) A list of pages that should be shown on the ioBroker cloud index page */ welcomeScreenPro?: WelcomeScreenEntry[]; wwwDontUpload?: boolean; /** @deprecated Use 'common.licenseInformation' instead */ diff --git a/packages/types-public/index.test-d.ts b/packages/types-public/index.test-d.ts index 00921aeb54..99278a3082 100644 --- a/packages/types-public/index.test-d.ts +++ b/packages/types-public/index.test-d.ts @@ -788,6 +788,13 @@ const _adapterObject: ioBroker.AdapterObject = { name: 'test', automaticUpgrade: 'minor', platform: 'Javascript/Node.js', + localLinks: { + link1: '%web_protocol%://%ip%:%web_port%/vis-2/edit.html', + link2: { + name: { en: 'Service' }, + link: '%web_protocol%://%ip%:%web_port%/vis-2/edit.html' + } + }, supportedMessages: { deviceManager: true }, diff --git a/schemas/io-package.json b/schemas/io-package.json index 641e777ed2..11bbf9a133 100644 --- a/schemas/io-package.json +++ b/schemas/io-package.json @@ -1179,21 +1179,67 @@ ".+": { "anyOf": [ { - "type": "string" + "type": "string", + "description": "DEPRECATED: Please use structure {link, color, pro, cloud, intro, icon, name, order} instead of string" }, { "properties": { "link": { - "type": "string" + "type": "string", + "description": "Link to the web service of this adapter, like: %web_protocol%://%ip%:%web_port%/vis-2/edit.html" }, "color": { "type": "string" }, "pro": { + "anyOf": [ + { + "type": "boolean", + "description": "DEPRECATED: Please use link template as string instead of boolean" + }, + { + "description": "Link to the adapter, like: vis-2/index.html according to \"https://iobroker.pro/\"", + "type": "string" + } + ] + }, + "cloud": { + "description": "Link to the adapter, like: vis-2/index.html according to \"https://iobroker.net/\"", + "type": "string" + }, + "intro": { + "description": "If this link should be shown on the intro tab in admin", "type": "boolean" }, "icon": { + "description": "Link to icon, like \"vis-2/img/favicon.png\"", "type": "string" + }, + "name": { + "description": "Name of the link. Could be multi-language", + "anyOf": [ + { + "type": "string" + }, + { + "$ref": "#/definitions/multilingual" + } + ] + }, + "order": { + "description": "Used on \"intro\" and cloud tabs to sort the links", + "type": "number" + }, + "description": { + "description": "Description of the link. Could be multi-language", + "anyOf": [ + { + "type": "string" + }, + { + "$ref": "#/definitions/multilingual" + } + ] } }, "additionalProperties": false, @@ -1461,7 +1507,7 @@ } }, "welcomeScreen": { - "description": "Array of pages, that should be shown on the \"web\" index.html page. [\"vis/edit.html\", \"vis/index.html\"] or [{\"link\": \"vis/edit.html\", \"name\": \"Vis editor\", \"img\": \"vis/img/edit.png\", \"color\": \"blue\"}, \"vis/index.html\"]", + "description": "DEPRECATED: Please use common.localLinks instead. Array of pages, that should be shown on the \"web\" index.html page. [\"vis/edit.html\", \"vis/index.html\"] or [{\"link\": \"vis/edit.html\", \"name\": \"Vis editor\", \"img\": \"vis/img/edit.png\", \"color\": \"blue\"}, \"vis/index.html\"]", "type": "array", "items": { "type": [ @@ -1471,7 +1517,7 @@ } }, "welcomeScreenPro": { - "description": "Array of pages used on access via ioBroker cloud, that should be shown on the \"web\" index.html page. [\"vis/edit.html\", \"vis/index.html\"] or [{\"link\": \"vis/edit.html\", \"name\": \"Vis editor\", \"img\": \"vis/img/edit.png\", \"color\": \"blue\"}, \"vis/index.html\"]", + "description": "DEPRECATED: Please use common.localLinks instead. Array of pages used on access via ioBroker cloud, that should be shown on the \"web\" index.html page. [\"vis/edit.html\", \"vis/index.html\"] or [{\"link\": \"vis/edit.html\", \"name\": \"Vis editor\", \"img\": \"vis/img/edit.png\", \"color\": \"blue\"}, \"vis/index.html\"]", "type": "array", "items": { "type": [