UNPKG

apisearch

Version:
82 lines (81 loc) 1.79 kB
"use strict"; exports.__esModule = true; exports.ItemUUID = void 0; var InvalidFormatError_1 = require("../Error/InvalidFormatError"); /** * ItemUUID class */ var ItemUUID = /** @class */ (function () { /** * Constructor * * @param id * @param type */ function ItemUUID(id, type) { this.id = id; this.type = type; } /** * Create composed UUID * * @param composedUUID * * @returns {ItemUUID} */ ItemUUID.createByComposedUUID = function (composedUUID) { var parts = composedUUID.split("~"); if (2 != parts.length) { throw InvalidFormatError_1.InvalidFormatError.composedItemUUIDNotValid(); } return new ItemUUID(parts[0], parts[1]); }; /** * Return id * * @returns {string} */ ItemUUID.prototype.getId = function () { return this.id; }; /** * Get type * * @returns {string} */ ItemUUID.prototype.getType = function () { return this.type; }; /** * To array * * @returns {{id: *, type: *}} */ ItemUUID.prototype.toArray = function () { return { id: this.id, type: this.type }; }; /** * Create from array * * @param array {{id:string, type:string}} * * @return {ItemUUID} */ ItemUUID.createFromArray = function (array) { array = JSON.parse(JSON.stringify(array)); return new ItemUUID(array.id, array.type); }; /** * Compose unique id * * @returns {string} */ ItemUUID.prototype.composedUUID = function () { return this.id + "~" + this.type; }; return ItemUUID; }()); exports.ItemUUID = ItemUUID;