@webiny/api-headless-cms-ddb
Version:
DynamoDB storage operations plugin for Headless CMS API.
57 lines (55 loc) • 1.85 kB
JavaScript
;
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.createRevisionSortKey = exports.createPublishedSortKey = exports.createPartitionKey = exports.createLatestSortKey = exports.createGSISortKey = exports.createGSIPartitionKey = void 0;
var _utils = require("@webiny/utils");
var _error = _interopRequireDefault(require("@webiny/error"));
const createBasePartitionKey = params => {
const {
tenant,
locale
} = params;
if (!tenant) {
throw new _error.default(`Missing tenant variable when creating entry basePartitionKey`);
} else if (!locale) {
throw new _error.default(`Missing tenant variable when creating entry basePartitionKey`);
}
return `T#${tenant}#L#${locale}#CMS#CME`;
};
const createPartitionKey = params => {
const {
id: initialId
} = params;
const {
id
} = (0, _utils.parseIdentifier)(initialId);
return `${createBasePartitionKey(params)}#CME#${id}`;
};
exports.createPartitionKey = createPartitionKey;
const createRevisionSortKey = params => {
return `REV#${(0, _utils.zeroPad)(params.version)}`;
};
exports.createRevisionSortKey = createRevisionSortKey;
const createLatestSortKey = () => {
return "L";
};
exports.createLatestSortKey = createLatestSortKey;
const createPublishedSortKey = () => {
return "P";
};
exports.createPublishedSortKey = createPublishedSortKey;
const createGSIPartitionKey = (params, type) => {
const {
modelId
} = params;
const partitionKey = createBasePartitionKey(params);
return `${partitionKey}#M#${modelId}#${type}`;
};
exports.createGSIPartitionKey = createGSIPartitionKey;
const createGSISortKey = params => {
return params.id;
};
exports.createGSISortKey = createGSISortKey;
//# sourceMappingURL=keys.js.map