Skip to content

Commit

Permalink
refactor: remove deprecated logic and tests
Browse files Browse the repository at this point in the history
Signed-off-by: Hasan Eroglu <[email protected]>
  • Loading branch information
hasanheroglu committed Jul 21, 2024
1 parent 2751844 commit 9d8e5d1
Show file tree
Hide file tree
Showing 7 changed files with 0 additions and 280 deletions.
86 changes: 0 additions & 86 deletions packages/core/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ module.exports.decompress = decompress;
module.exports.checkTmOptionalPointer = coreAssertions.checkTmOptionalPointer;
module.exports.checkLinkedAffordances = coreAssertions.checkLinkedAffordances;
module.exports.checkLinkedStructure = coreAssertions.checkLinkedStructure;
module.exports.detectProtocolSchemes = detectProtocolSchemes;
module.exports.convertTDJsonToYaml = convertTDJsonToYaml;
module.exports.convertTDYamlToJson = convertTDYamlToJson;

Expand Down Expand Up @@ -1297,91 +1296,6 @@ function decompress(data) {
return lzs.decompressFromEncodedURIComponent(data);
}

/**
* Detect protocl schemes of a TD
* @param {string} td TD string to detect protocols of
* return List of available protocol schemes
*/
function detectProtocolSchemes(td) {
let tdJson;

try {
tdJson = JSON.parse(td);
} catch (err) {
return [];
}

const baseUriProtocol = getHrefProtocol(tdJson.base);
const thingProtocols = detectProtocolInForms(tdJson.forms);
const actionsProtocols = detectProtocolInAffordance(tdJson.actions);
const eventsProtocols = detectProtocolInAffordance(tdJson.events);
const propertiesProtcols = detectProtocolInAffordance(tdJson.properties);
const protocolSchemes = [
...new Set([
baseUriProtocol,
...thingProtocols,
...actionsProtocols,
...eventsProtocols,
...propertiesProtcols,
]),
].filter((p) => p !== undefined);

return protocolSchemes;
}

/**
* Detect protocols in a TD affordance
* @param {object} affordance That belongs to a TD
* @returns List of protocol schemes
*/
function detectProtocolInAffordance(affordance) {
if (!affordance) {
return [];
}

let protocolSchemes = [];

for (const key in affordance) {
if (key) {
protocolSchemes = protocolSchemes.concat(detectProtocolInForms(affordance[key].forms));
}
}

return protocolSchemes;
}

/**
* Detect protocols in a TD forms or a TD affordance forms
* @param {object} forms Forms field of a TD or a TD affordance
* @returns List of protocol schemes
*/
function detectProtocolInForms(forms) {
if (!forms) {
return [];
}

const protocolSchemes = [];

forms.forEach((form) => {
protocolSchemes.push(getHrefProtocol(form.href));
});

return protocolSchemes;
}

/**
* Get protocol used in href
* @param {string} href URI string
* @returns Protocol name
*/
function getHrefProtocol(href) {
if (!href) {
return;
}

return href.split(":")[0];
}

/**
* Convert TD from json to yaml
* @param {string} td TD in json string form
Expand Down
69 changes: 0 additions & 69 deletions packages/core/tests/protocol-detection.test.js

This file was deleted.

22 changes: 0 additions & 22 deletions packages/core/tests/protocol-detection/httpAndMqtt.json

This file was deleted.

14 changes: 0 additions & 14 deletions packages/core/tests/protocol-detection/noProtocol.json

This file was deleted.

33 changes: 0 additions & 33 deletions packages/core/tests/protocol-detection/onlyHttp.json

This file was deleted.

33 changes: 0 additions & 33 deletions packages/core/tests/protocol-detection/onlyMqtt.json

This file was deleted.

23 changes: 0 additions & 23 deletions packages/core/tests/protocol-detection/secureProtocols.json

This file was deleted.

0 comments on commit 9d8e5d1

Please sign in to comment.