@codification/cutwater-aws
Version:
A library providing general functionality for TypeScript based AWS projects.
45 lines • 1.77 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.CompoundItemId = void 0;
const CompoundValue_1 = require("../CompoundValue");
const CompoundKey_1 = require("./CompoundKey");
class CompoundItemId {
constructor(parentId = undefined, name) {
this.parentId = parentId;
this.name = name;
}
static fromItemId(itemId) {
return new CompoundItemId(CompoundItemId.toParentId(itemId), CompoundItemId.toName(itemId));
}
static fromKeys(partitionKey, sortKey) {
const parent = partitionKey === CompoundKey_1.CompoundKey.DEFAULT_PARENT
? undefined
: CompoundValue_1.CompoundValue.create(partitionKey).parts.join(CompoundItemId.ID_SEPARATOR);
return new CompoundItemId(parent, CompoundValue_1.CompoundValue.create(sortKey).parts.pop());
}
static create(parentId, name) {
return new CompoundItemId(parentId, name);
}
withName(name) {
return new CompoundItemId(this.itemId, name);
}
get itemId() {
return this.parentId ? [this.parentId, this.name].join(CompoundItemId.ID_SEPARATOR) : this.name;
}
get idParts() {
return this.itemId.split(CompoundItemId.ID_SEPARATOR);
}
get parentIdParts() {
return this.parentId ? this.parentId.split(CompoundItemId.ID_SEPARATOR) : [];
}
static toParentId(itemId) {
const rval = itemId.split(CompoundItemId.ID_SEPARATOR).slice(0, -1).join(this.ID_SEPARATOR);
return rval.length !== 0 ? rval : undefined;
}
static toName(itemId) {
return itemId.split(CompoundItemId.ID_SEPARATOR).pop();
}
}
exports.CompoundItemId = CompoundItemId;
CompoundItemId.ID_SEPARATOR = ':';
//# sourceMappingURL=CompoundItemId.js.map