@firestone-hs/content-craetor-input 0.0.9 → 0.0.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/data-model.d.ts
CHANGED
|
@@ -11,7 +11,7 @@ export interface BgsCompAdvice {
|
|
|
11
11
|
export interface BgsCompCardAdvice {
|
|
12
12
|
readonly cardId: string;
|
|
13
13
|
readonly name?: string;
|
|
14
|
-
readonly status: 'CORE' | 'ADDON' | 'ENABLER' | 'CYCLE';
|
|
14
|
+
readonly status: 'CORE' | 'ADDON' | 'ENABLER' | 'CYCLE' | 'TRINKET';
|
|
15
15
|
readonly tips: BgsCompCardTip[];
|
|
16
16
|
}
|
|
17
17
|
export interface BgsCompTip {
|
package/dist/data-model.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"data-model.js","sourceRoot":"","sources":["../src/data-model.ts"],"names":[],"mappings":"","sourcesContent":["import { Race } from '@firestone-hs/reference-data';\r\n\r\nexport interface BgsCompAdvice {\r\n\treadonly compId: string;\r\n\treadonly name?: string;\r\n\treadonly difficulty: 'Easy' | 'Medium' | 'Hard';\r\n\treadonly powerLevel: 'D' | 'C' | 'B' | 'A' | 'S';\r\n\treadonly cards: BgsCompCardAdvice[];\r\n\treadonly forcedTribes: readonly Race[];\r\n\treadonly tips: BgsCompTip[];\r\n}\r\nexport interface BgsCompCardAdvice {\r\n\treadonly cardId: string;\r\n\treadonly name?: string;\r\n\treadonly status: 'CORE' | 'ADDON' | 'ENABLER' | 'CYCLE';\r\n\treadonly tips: BgsCompCardTip[];\r\n}\r\nexport interface BgsCompTip {\r\n\treadonly author: string;\r\n\treadonly date: string;\r\n\treadonly patchNumber: number;\r\n\treadonly language: string;\r\n\treadonly tip: string;\r\n\treadonly whenToCommit: string;\r\n}\r\nexport interface BgsCompCardTip {\r\n\treadonly author: string;\r\n\treadonly date: string;\r\n\treadonly patchNumber: number;\r\n\treadonly language: string;\r\n\treadonly tip: string;\r\n}\r\n"]}
|
|
1
|
+
{"version":3,"file":"data-model.js","sourceRoot":"","sources":["../src/data-model.ts"],"names":[],"mappings":"","sourcesContent":["import { Race } from '@firestone-hs/reference-data';\r\n\r\nexport interface BgsCompAdvice {\r\n\treadonly compId: string;\r\n\treadonly name?: string;\r\n\treadonly difficulty: 'Easy' | 'Medium' | 'Hard';\r\n\treadonly powerLevel: 'D' | 'C' | 'B' | 'A' | 'S';\r\n\treadonly cards: BgsCompCardAdvice[];\r\n\treadonly forcedTribes: readonly Race[];\r\n\treadonly tips: BgsCompTip[];\r\n}\r\nexport interface BgsCompCardAdvice {\r\n\treadonly cardId: string;\r\n\treadonly name?: string;\r\n\treadonly status: 'CORE' | 'ADDON' | 'ENABLER' | 'CYCLE'|'TRINKET';\r\n\treadonly tips: BgsCompCardTip[];\r\n}\r\nexport interface BgsCompTip {\r\n\treadonly author: string;\r\n\treadonly date: string;\r\n\treadonly patchNumber: number;\r\n\treadonly language: string;\r\n\treadonly tip: string;\r\n\treadonly whenToCommit: string;\r\n}\r\nexport interface BgsCompCardTip {\r\n\treadonly author: string;\r\n\treadonly date: string;\r\n\treadonly patchNumber: number;\r\n\treadonly language: string;\r\n\treadonly tip: string;\r\n}\r\n"]}
|
package/dist/types/bgs-comps.js
CHANGED
|
@@ -78,7 +78,7 @@ const updateComp = (inputComp, result, author, bgPatch) => {
|
|
|
78
78
|
cards: [],
|
|
79
79
|
difficulty: inputComp.difficulty,
|
|
80
80
|
powerLevel: inputComp.powerLevel,
|
|
81
|
-
forcedTribes: inputComp?.forcedTribes
|
|
81
|
+
forcedTribes: inputComp?.forcedTribes?.split(',').map((tribe) => reference_data_1.Race[tribe.trim()]) ?? [],
|
|
82
82
|
tips: [],
|
|
83
83
|
};
|
|
84
84
|
result.push(existingComp);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bgs-comps.js","sourceRoot":"","sources":["../../src/types/bgs-comps.ts"],"names":[],"mappings":";;;AACA,qEAA+D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CAAC,GAAG,GAAG,SAAS,CAAC,GAAG,CAAC;gBAChC,WAAW,CAAC,YAAY,GAAG,SAAS,CAAC,YAAY,CAAC;gBAClD,WAAW,CAAC,IAAI,GAAG,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE,CAAC,SAAS,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;gBAC7D,WAAW,CAAC,WAAW,GAAG,OAAO,CAAC,MAAM,CAAC;aACzC;SACD;aAAM;YACN,YAAY,CAAC,IAAI,GAAG,YAAY,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,MAAM,KAAK,MAAM,CAAC,CAAC;SACzE;KACD;IACD,OAAO,YAAY,CAAC;AACrB,CAAC,CAAC;AAEF,MAAM,gBAAgB,GAAG,KAAK,IAAqC,EAAE;IACpE,MAAM,EAAE,GAAG,IAAI,qBAAE,EAAE,CAAC;IAEpB,MAAM,QAAQ,GAAG,MAAM,EAAE,CAAC,eAAe,CAAC,MAAM,EAAE,OAAO,EAAE,CAAC,CAAC,CAAC;IAE9D,IAAI,CAAC,QAAQ,EAAE;QACd,OAAO,EAAE,CAAC;KACV;IACD,OAAO,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;AAC7B,CAAC,CAAC;AAEF,MAAM,QAAQ,GAAG,KAAK,EAAE,IAA8B,EAAE,EAAE;IACzD,MAAM,EAAE,GAAG,IAAI,qBAAE,EAAE,CAAC;IACpB,MAAM,EAAE,CAAC,SAAS,CAAC,IAAA,eAAQ,EAAC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,EAAE,MAAM,EAAE,OAAO,EAAE,kBAAkB,EAAE,MAAM,CAAC,CAAC;AACjG,CAAC,CAAC","sourcesContent":["/* eslint-disable no-extra-boolean-cast */\r\nimport { PatchInfo, S3 } from '@firestone-hs/aws-lambda-utils';\r\nimport { AllCardsService, Race } from '@firestone-hs/reference-data';\r\nimport { gzipSync } from 'zlib';\r\nimport { BgsCompAdvice, BgsCompCardAdvice, BgsCompCardTip, BgsCompTip } from '../data-model';\r\nimport { BgsCompsCardDataRow, BgsCompsDataRow, BgsCompsInput } from '../input-model';\r\nimport { deepEqual, Mutable } from '../utils';\r\n\r\nconst bucket = 'static.zerotoheroes.com';\r\nconst fileKey = 'hearthstone/data/battlegrounds-strategies/bgs-comps-strategies.gz.json';\r\n\r\nexport const processBgsComps = async (input: BgsCompsInput, bgPatch: PatchInfo, allCards: AllCardsService) => {\r\n\tconst author = input.author;\r\n\tconsole.debug('processing', author, input);\r\n\tlet result = await loadExistingInfo();\r\n\tconsole.debug('loaded existing info', result);\r\n\r\n\tfor (const inputComp of input.compsData) {\r\n\t\tconst comp = updateComp(inputComp, result, author, bgPatch);\r\n\t\tconst cardsData = input.cardsData.filter((card) => card.compId === inputComp.compId);\r\n\t\tif (author === 'ref') {\r\n\t\t\tconst existingCards = [...comp.cards];\r\n\t\t\tfor (const existing of existingCards) {\r\n\t\t\t\tconst cardData = cardsData.find(\r\n\t\t\t\t\t(card) => card.cardId === existing.cardId && card.status === existing.status,\r\n\t\t\t\t);\r\n\t\t\t\tif (!cardData) {\r\n\t\t\t\t\t// Remove it\r\n\t\t\t\t\tcomp.cards = comp.cards.filter((card) => card !== existing);\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t\tfor (const card of cardsData) {\r\n\t\t\tupdateCompCard(card, comp, author, bgPatch);\r\n\t\t}\r\n\t}\r\n\t// Remove old comps\r\n\tif (author === 'ref') {\r\n\t\tresult = result.filter((comp) => input.compsData.map((comp) => comp.compId).includes(comp.compId));\r\n\t}\r\n\r\n\tconsole.debug('built aggregated tips', result);\r\n\tawait saveInfo(result);\r\n\tconsole.debug('saved aggregated tips');\r\n};\r\n\r\nconst updateCompCard = (\r\n\tinputCard: BgsCompsCardDataRow,\r\n\tcomp: MutableBgsCompAdvice,\r\n\tauthor: string,\r\n\tbgPatch: PatchInfo,\r\n): void => {\r\n\tconsole.debug('updating card', comp.compId, inputCard.cardId, inputCard.tip, inputCard);\r\n\tlet existingCard: Mutable<BgsCompCardAdvice> = comp.cards.find(\r\n\t\t(t) => t.cardId === inputCard.cardId && t.status === inputCard.status,\r\n\t);\r\n\tif (!existingCard) {\r\n\t\texistingCard = {\r\n\t\t\tcardId: inputCard.cardId,\r\n\t\t\tname: inputCard.cardName,\r\n\t\t\ttips: [],\r\n\t\t} as BgsCompCardAdvice;\r\n\t\tcomp.cards.push(existingCard);\r\n\t}\r\n\texistingCard.status = inputCard.status;\r\n\r\n\tif (!!author && author !== 'ref') {\r\n\t\tif (!!inputCard.tip?.length) {\r\n\t\t\tlet existingTip: Mutable<BgsCompCardTip> = existingCard.tips.find((t) => t.author === author);\r\n\t\t\tif (!existingTip) {\r\n\t\t\t\texistingTip = {\r\n\t\t\t\t\tauthor: author,\r\n\t\t\t\t\tlanguage: 'enUS',\r\n\t\t\t\t} as BgsCompTip;\r\n\t\t\t\texistingCard.tips.push(existingTip);\r\n\t\t\t}\r\n\t\t\tif (!deepEqual(existingTip.tip, inputCard.tip)) {\r\n\t\t\t\texistingTip.tip = inputCard.tip;\r\n\t\t\t\texistingTip.date = new Date().toISOString().substring(0, 10);\r\n\t\t\t\texistingTip.patchNumber = bgPatch.number;\r\n\t\t\t}\r\n\t\t} else {\r\n\t\t\texistingCard.tips = existingCard.tips.filter((t) => t.author !== author);\r\n\t\t}\r\n\t}\r\n};\r\n\r\nconst updateComp = (\r\n\tinputComp: BgsCompsDataRow,\r\n\tresult: MutableBgsCompAdvice[],\r\n\tauthor: string,\r\n\tbgPatch: PatchInfo,\r\n): MutableBgsCompAdvice => {\r\n\tlet existingComp = result.find((t) => t.compId === inputComp.compId);\r\n\tif (!existingComp) {\r\n\t\t// This should maybe come from another process to handle the ref data\r\n\t\texistingComp = {\r\n\t\t\tcompId: inputComp.compId,\r\n\t\t\tname: inputComp.name,\r\n\t\t\tcards: [],\r\n\t\t\tdifficulty: inputComp.difficulty,\r\n\t\t\tpowerLevel: inputComp.powerLevel,\r\n\t\t\tforcedTribes: inputComp?.forcedTribes.split(',').map((tribe) => Race[tribe.trim()]),\r\n\t\t\ttips: [],\r\n\t\t};\r\n\t\tresult.push(existingComp);\r\n\t}\r\n\r\n\texistingComp.name = inputComp.name;\r\n\texistingComp.difficulty = inputComp.difficulty;\r\n\texistingComp.powerLevel = inputComp.powerLevel;\r\n\r\n\tif (!!author && author !== 'ref') {\r\n\t\tif (!!inputComp.tip?.length) {\r\n\t\t\tlet existingTip: Mutable<BgsCompTip> = existingComp.tips.find((t) => t.author === author);\r\n\t\t\tif (!existingTip) {\r\n\t\t\t\texistingTip = {\r\n\t\t\t\t\tauthor: author,\r\n\t\t\t\t\tlanguage: 'enUS',\r\n\t\t\t\t} as BgsCompTip;\r\n\t\t\t\texistingComp.tips.push(existingTip);\r\n\t\t\t}\r\n\t\t\tif (\r\n\t\t\t\t!deepEqual(existingTip.tip, inputComp.tip) ||\r\n\t\t\t\t!deepEqual(existingTip.whenToCommit, inputComp.whenToCommit)\r\n\t\t\t) {\r\n\t\t\t\texistingTip.tip = inputComp.tip;\r\n\t\t\t\texistingTip.whenToCommit = inputComp.whenToCommit;\r\n\t\t\t\texistingTip.date = new Date().toISOString().substring(0, 10);\r\n\t\t\t\texistingTip.patchNumber = bgPatch.number;\r\n\t\t\t}\r\n\t\t} else {\r\n\t\t\texistingComp.tips = existingComp.tips.filter((t) => t.author !== author);\r\n\t\t}\r\n\t}\r\n\treturn existingComp;\r\n};\r\n\r\nconst loadExistingInfo = async (): Promise<MutableBgsCompAdvice[]> => {\r\n\tconst s3 = new S3();\r\n\t// console.debug('created s3');\r\n\tconst asString = await s3.readGzipContent(bucket, fileKey, 5);\r\n\t// console.debug('loaded existing info', asString?.length);\r\n\tif (!asString) {\r\n\t\treturn [];\r\n\t}\r\n\treturn JSON.parse(asString);\r\n};\r\n\r\nconst saveInfo = async (info: readonly BgsCompAdvice[]) => {\r\n\tconst s3 = new S3();\r\n\tawait s3.writeFile(gzipSync(JSON.stringify(info)), bucket, fileKey, 'application/json', 'gzip');\r\n};\r\n\r\ntype MutableBgsCompAdvice = Mutable<BgsCompAdvice>;\r\n"]}
|
|
1
|
+
{"version":3,"file":"bgs-comps.js","sourceRoot":"","sources":["../../src/types/bgs-comps.ts"],"names":[],"mappings":";;;AACA,qEAA+D;AAC/D,iEAAqE;AACrE,+BAAgC;AAGhC,oCAA8C;AAE9C,MAAM,MAAM,GAAG,yBAAyB,CAAC;AACzC,MAAM,OAAO,GAAG,wEAAwE,CAAC;AAElF,MAAM,eAAe,GAAG,KAAK,EAAE,KAAoB,EAAE,OAAkB,EAAE,QAAyB,EAAE,EAAE;IAC5G,MAAM,MAAM,GAAG,KAAK,CAAC,MAAM,CAAC;IAC5B,OAAO,CAAC,KAAK,CAAC,YAAY,EAAE,MAAM,EAAE,KAAK,CAAC,CAAC;IAC3C,IAAI,MAAM,GAAG,MAAM,gBAAgB,EAAE,CAAC;IACtC,OAAO,CAAC,KAAK,CAAC,sBAAsB,EAAE,MAAM,CAAC,CAAC;IAE9C,KAAK,MAAM,SAAS,IAAI,KAAK,CAAC,SAAS,EAAE;QACxC,MAAM,IAAI,GAAG,UAAU,CAAC,SAAS,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC;QAC5D,MAAM,SAAS,GAAG,KAAK,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,MAAM,KAAK,SAAS,CAAC,MAAM,CAAC,CAAC;QACrF,IAAI,MAAM,KAAK,KAAK,EAAE;YACrB,MAAM,aAAa,GAAG,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC;YACtC,KAAK,MAAM,QAAQ,IAAI,aAAa,EAAE;gBACrC,MAAM,QAAQ,GAAG,SAAS,CAAC,IAAI,CAC9B,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,MAAM,KAAK,QAAQ,CAAC,MAAM,IAAI,IAAI,CAAC,M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MAAM,EAAE,OAAO,EAAE,kBAAkB,EAAE,MAAM,CAAC,CAAC;AACjG,CAAC,CAAC","sourcesContent":["/* eslint-disable no-extra-boolean-cast */\r\nimport { PatchInfo, S3 } from '@firestone-hs/aws-lambda-utils';\r\nimport { AllCardsService, Race } from '@firestone-hs/reference-data';\r\nimport { gzipSync } from 'zlib';\r\nimport { BgsCompAdvice, BgsCompCardAdvice, BgsCompCardTip, BgsCompTip } from '../data-model';\r\nimport { BgsCompsCardDataRow, BgsCompsDataRow, BgsCompsInput } from '../input-model';\r\nimport { deepEqual, Mutable } from '../utils';\r\n\r\nconst bucket = 'static.zerotoheroes.com';\r\nconst fileKey = 'hearthstone/data/battlegrounds-strategies/bgs-comps-strategies.gz.json';\r\n\r\nexport const processBgsComps = async (input: BgsCompsInput, bgPatch: PatchInfo, allCards: AllCardsService) => {\r\n\tconst author = input.author;\r\n\tconsole.debug('processing', author, input);\r\n\tlet result = await loadExistingInfo();\r\n\tconsole.debug('loaded existing info', result);\r\n\r\n\tfor (const inputComp of input.compsData) {\r\n\t\tconst comp = updateComp(inputComp, result, author, bgPatch);\r\n\t\tconst cardsData = input.cardsData.filter((card) => card.compId === inputComp.compId);\r\n\t\tif (author === 'ref') {\r\n\t\t\tconst existingCards = [...comp.cards];\r\n\t\t\tfor (const existing of existingCards) {\r\n\t\t\t\tconst cardData = cardsData.find(\r\n\t\t\t\t\t(card) => card.cardId === existing.cardId && card.status === existing.status,\r\n\t\t\t\t);\r\n\t\t\t\tif (!cardData) {\r\n\t\t\t\t\t// Remove it\r\n\t\t\t\t\tcomp.cards = comp.cards.filter((card) => card !== existing);\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t\tfor (const card of cardsData) {\r\n\t\t\tupdateCompCard(card, comp, author, bgPatch);\r\n\t\t}\r\n\t}\r\n\t// Remove old comps\r\n\tif (author === 'ref') {\r\n\t\tresult = result.filter((comp) => input.compsData.map((comp) => comp.compId).includes(comp.compId));\r\n\t}\r\n\r\n\tconsole.debug('built aggregated tips', result);\r\n\tawait saveInfo(result);\r\n\tconsole.debug('saved aggregated tips');\r\n};\r\n\r\nconst updateCompCard = (\r\n\tinputCard: BgsCompsCardDataRow,\r\n\tcomp: MutableBgsCompAdvice,\r\n\tauthor: string,\r\n\tbgPatch: PatchInfo,\r\n): void => {\r\n\tconsole.debug('updating card', comp.compId, inputCard.cardId, inputCard.tip, inputCard);\r\n\tlet existingCard: Mutable<BgsCompCardAdvice> = comp.cards.find(\r\n\t\t(t) => t.cardId === inputCard.cardId && t.status === inputCard.status,\r\n\t);\r\n\tif (!existingCard) {\r\n\t\texistingCard = {\r\n\t\t\tcardId: inputCard.cardId,\r\n\t\t\tname: inputCard.cardName,\r\n\t\t\ttips: [],\r\n\t\t} as BgsCompCardAdvice;\r\n\t\tcomp.cards.push(existingCard);\r\n\t}\r\n\texistingCard.status = inputCard.status;\r\n\r\n\tif (!!author && author !== 'ref') {\r\n\t\tif (!!inputCard.tip?.length) {\r\n\t\t\tlet existingTip: Mutable<BgsCompCardTip> = existingCard.tips.find((t) => t.author === author);\r\n\t\t\tif (!existingTip) {\r\n\t\t\t\texistingTip = {\r\n\t\t\t\t\tauthor: author,\r\n\t\t\t\t\tlanguage: 'enUS',\r\n\t\t\t\t} as BgsCompTip;\r\n\t\t\t\texistingCard.tips.push(existingTip);\r\n\t\t\t}\r\n\t\t\tif (!deepEqual(existingTip.tip, inputCard.tip)) {\r\n\t\t\t\texistingTip.tip = inputCard.tip;\r\n\t\t\t\texistingTip.date = new Date().toISOString().substring(0, 10);\r\n\t\t\t\texistingTip.patchNumber = bgPatch.number;\r\n\t\t\t}\r\n\t\t} else {\r\n\t\t\texistingCard.tips = existingCard.tips.filter((t) => t.author !== author);\r\n\t\t}\r\n\t}\r\n};\r\n\r\nconst updateComp = (\r\n\tinputComp: BgsCompsDataRow,\r\n\tresult: MutableBgsCompAdvice[],\r\n\tauthor: string,\r\n\tbgPatch: PatchInfo,\r\n): MutableBgsCompAdvice => {\r\n\tlet existingComp = result.find((t) => t.compId === inputComp.compId);\r\n\tif (!existingComp) {\r\n\t\t// This should maybe come from another process to handle the ref data\r\n\t\texistingComp = {\r\n\t\t\tcompId: inputComp.compId,\r\n\t\t\tname: inputComp.name,\r\n\t\t\tcards: [],\r\n\t\t\tdifficulty: inputComp.difficulty,\r\n\t\t\tpowerLevel: inputComp.powerLevel,\r\n\t\t\tforcedTribes: inputComp?.forcedTribes?.split(',').map((tribe) => Race[tribe.trim()]) ?? [],\r\n\t\t\ttips: [],\r\n\t\t};\r\n\t\tresult.push(existingComp);\r\n\t}\r\n\r\n\texistingComp.name = inputComp.name;\r\n\texistingComp.difficulty = inputComp.difficulty;\r\n\texistingComp.powerLevel = inputComp.powerLevel;\r\n\r\n\tif (!!author && author !== 'ref') {\r\n\t\tif (!!inputComp.tip?.length) {\r\n\t\t\tlet existingTip: Mutable<BgsCompTip> = existingComp.tips.find((t) => t.author === author);\r\n\t\t\tif (!existingTip) {\r\n\t\t\t\texistingTip = {\r\n\t\t\t\t\tauthor: author,\r\n\t\t\t\t\tlanguage: 'enUS',\r\n\t\t\t\t} as BgsCompTip;\r\n\t\t\t\texistingComp.tips.push(existingTip);\r\n\t\t\t}\r\n\t\t\tif (\r\n\t\t\t\t!deepEqual(existingTip.tip, inputComp.tip) ||\r\n\t\t\t\t!deepEqual(existingTip.whenToCommit, inputComp.whenToCommit)\r\n\t\t\t) {\r\n\t\t\t\texistingTip.tip = inputComp.tip;\r\n\t\t\t\texistingTip.whenToCommit = inputComp.whenToCommit;\r\n\t\t\t\texistingTip.date = new Date().toISOString().substring(0, 10);\r\n\t\t\t\texistingTip.patchNumber = bgPatch.number;\r\n\t\t\t}\r\n\t\t} else {\r\n\t\t\texistingComp.tips = existingComp.tips.filter((t) => t.author !== author);\r\n\t\t}\r\n\t}\r\n\treturn existingComp;\r\n};\r\n\r\nconst loadExistingInfo = async (): Promise<MutableBgsCompAdvice[]> => {\r\n\tconst s3 = new S3();\r\n\t// console.debug('created s3');\r\n\tconst asString = await s3.readGzipContent(bucket, fileKey, 5);\r\n\t// console.debug('loaded existing info', asString?.length);\r\n\tif (!asString) {\r\n\t\treturn [];\r\n\t}\r\n\treturn JSON.parse(asString);\r\n};\r\n\r\nconst saveInfo = async (info: readonly BgsCompAdvice[]) => {\r\n\tconst s3 = new S3();\r\n\tawait s3.writeFile(gzipSync(JSON.stringify(info)), bucket, fileKey, 'application/json', 'gzip');\r\n};\r\n\r\ntype MutableBgsCompAdvice = Mutable<BgsCompAdvice>;\r\n"]}
|