Skip to content

Commit

Permalink
Collapse getAsset into getObject. Add some comments.
Browse files Browse the repository at this point in the history
Don't need a generic accessor (e.g. for docs, images, etc) yet. Will factor out when it's needed.
  • Loading branch information
John Schulz committed Jul 10, 2019
1 parent 04247a4 commit 5437feb
Showing 1 changed file with 8 additions and 12 deletions.
20 changes: 8 additions & 12 deletions x-pack/legacy/plugins/integrations_manager/server/registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,22 +135,18 @@ function ensureJsonValues(obj: SavedObject) {
return obj;
}

function getAsset(key: string) {
const value = cacheGet(key);
if (value === undefined) throw new Error(`Cannot find asset ${key}`);

const json = value.toString('utf8');
const asset = JSON.parse(json);
function getObject(key: string) {
const buffer = cacheGet(key);
if (buffer === undefined) throw new Error(`Cannot find asset ${key}`);

return asset;
}
// cache values are buffers. convert to string / JSON
const json = buffer.toString('utf8');
// convert that to an object & address issues with the formatting of some parts
const asset = ensureJsonValues(JSON.parse(json));

function getObject(key: string) {
const asset = getAsset(key);
const { type, file } = pathParts(key);

if (!asset.type) asset.type = type;
if (!asset.id) asset.id = file.replace('.json', '');

return ensureJsonValues(asset);
return asset;
}

0 comments on commit 5437feb

Please sign in to comment.