Skip to content

Commit

Permalink
feat: add bot.getBacklinks, update @tradle/dynamodb
Browse files Browse the repository at this point in the history
  • Loading branch information
mvayngrib committed Apr 17, 2018
1 parent 9f12099 commit 4bd9f49
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 15 deletions.
4 changes: 2 additions & 2 deletions npm-shrinkwrap.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 16 additions & 7 deletions src/bot/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ type LambdaMap = {
}

type GetResourceOpts = {
backlinks?: boolean
backlinks?: boolean|string[]
resolveEmbeds?: boolean
}

Expand Down Expand Up @@ -523,6 +523,19 @@ export class Bot extends EventEmitter implements IReady, IHasModels {
})
}

public getBacklink = async (props: GetResourceIdentifierInput, backlink: string) => {
return await this.getBacklinks(props, [backlink])
}

public getBacklinks = async (props: GetResourceIdentifierInput, backlinks?: string[]) => {
const { type, permalink } = getResourceIdentifier(props)
return await this.backlinks.fetchBacklinks({
type,
permalink,
properties: backlinks
})
}

public getResource = async (props: GetResourceIdentifierInput, opts: GetResourceOpts={}):Promise<ITradleObject> => {
const { backlinks, resolveEmbeds } = opts
let promiseResource = this._getResource(props)
Expand All @@ -537,7 +550,7 @@ export class Bot extends EventEmitter implements IReady, IHasModels {
const { type, permalink, link } = getResourceIdentifier(props)
const [resource, backlinksObj] = await Promise.all([
promiseResource,
this.backlinks.fetchBacklinks({ type, permalink })
this.getBacklinks({ type, permalink }, typeof backlinks === 'boolean' ? null : backlinks)
])

return {
Expand All @@ -561,11 +574,7 @@ export class Bot extends EventEmitter implements IReady, IHasModels {
public getResourceByStub = this.getResource

public addBacklinks = async (resource: ITradleObject) => {
const backlinks = await this.backlinks.fetchBacklinks({
type: resource[TYPE],
permalink: buildResource.permalink(resource)
})

const backlinks = await this.getBacklinks(resource)
return _.extend(resource, backlinks)
}

Expand Down
6 changes: 1 addition & 5 deletions src/db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,11 +112,7 @@ export = function createDB (tradle:Tradle) {
tableDefinition: cloudformation,
// all key props are derived
derivedProps: pluck(cloudformation.AttributeDefinitions, 'AttributeName'),
deriveProps: defaults.deriveProps,
resolveOrderBy: defaults.resolveOrderBy,
parseDerivedProps: defaults.parseDerivedProps,
getPrimaryKeysForModel: defaults.getPrimaryKeysForModel,
getIndexesForModel,
getIndexesForModel
})

const controlLatestHooks = method => async ({ args }) => {
Expand Down
6 changes: 5 additions & 1 deletion src/resolvers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,11 @@ export const createResolvers = ({ db, backlinks, objects, models, postProcess }:
}
}

const container = await backlinks.fetchBacklinks(parseStub(backlink.target))
const container = await backlinks.fetchBacklinks({
type: backlink.target[TYPE],
permalink: backlink.target._permalink
})

const results = container[propertyName]
const items = results ? await normalizeBacklinkResults({ ...opts, results }) : []
return {
Expand Down

0 comments on commit 4bd9f49

Please sign in to comment.