UNPKG

@ournet/news-data

Version:
92 lines (91 loc) 2.79 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const dynamo_item_1 = require("dynamo-item"); class DynamoNewsItemHelper { static createLocaleKey(locale) { return `${locale.country.toUpperCase()}_${locale.lang.toUpperCase()}`; } static mapFromNews(data) { const item = Object.assign({}, data, { locale: DynamoNewsItemHelper.createLocaleKey(data) }); return item; } static mapToNews(item) { delete item.locale; const data = item; return data; } static mapFromPartialNews(data) { const item = Object.assign({}, data); return item; } } exports.DynamoNewsItemHelper = DynamoNewsItemHelper; class NewsItemModel extends dynamo_item_1.DynamoItem { localeIndexName() { return "locale-index"; } sourceIndexName() { return "source-index"; } eventIndexName() { return "event-index"; } constructor(client, tableSuffix) { super({ hashKey: { name: "id", type: "S" }, name: "news", tableName: `ournet_news_${tableSuffix}`, indexes: [ { name: "source-index", hashKey: { name: "sourceId", type: "S" }, rangeKey: { name: "publishedAt", type: "S" }, type: "GLOBAL", projection: { type: "KEYS_ONLY" } }, { name: "event-index", hashKey: { name: "eventId", type: "S" }, rangeKey: { name: "publishedAt", type: "S" }, type: "GLOBAL", projection: { type: "KEYS_ONLY" } }, { name: "locale-index", hashKey: { name: "locale", type: "S" }, rangeKey: { name: "publishedAt", type: "S" }, type: "GLOBAL", projection: { type: "KEYS_ONLY" } } ] }, client); } } exports.NewsItemModel = NewsItemModel;