Skip to content

Commit

Permalink
Clean up and add example recipe
Browse files Browse the repository at this point in the history
  • Loading branch information
ShishKabab committed Aug 26, 2020
1 parent 1573ede commit ec73c30
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 16 deletions.
39 changes: 39 additions & 0 deletions recipes/memex-tag.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{
"select": {
"placeholder": "tag",
"app": "io.worldbrain.memex",
"remote": true,
"collection": "tags",
"pk": ["name", "url"],
"where": { "name": "share-textile" }
},
"on": {
"add": [
{
"placeholder": "page",
"operation": "findObject",
"app": "io.worldbrain.memex",
"remote": true,
"collection": "pages",
"where": { "url": { "$logic": "$tag.pk.1" } }
},
{
"app": "io.textile",
"call": "pushBucket",
"args": {
"bucketName": "memexPages",
"path": { "$logic": "`/${page.url}.json`" },
"content": {
"$logic": {
"object": {
"normalizedUrl": "$page.url",
"fullUrl": "$page.fullUrl",
"fulTitle": "$page.fullTitle"
}
}
}
}
}
]
}
}
22 changes: 6 additions & 16 deletions ts/application.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,17 +129,6 @@ export class Application {
return { status: 'invalid-args' }
}
const client = await this.getThreadsClient()
// console.log(client.context)
// console.log('creating collection in thread', threadID, collectionName, schema)
// const schema2 = {
// properties: {
// _id: { type: 'string' },
// fullName: { type: 'string' },
// age: { type: 'integer', minimum: 0 },
// },
// }
// console.log(await client.listDBs())
// await client.newCollection(threadID, collectionName, schema2)
await client.newCollection(threadID, collectionName, schema)
return { status: 'success', result: {} }
}
Expand Down Expand Up @@ -183,8 +172,8 @@ export class Application {

// Version 2
const result = await client.open(args.bucketName)
if (!result?.key) throw new Error('bucket not created')
const bucketKey = result.key
const bucketKey = result?.key
if (!bucketKey) throw new Error('bucket not created')

return { bucketKey }
}
Expand All @@ -200,8 +189,6 @@ export class Application {
}
const client = await this.getThreadsClient()
const resultList = await client.find(threadID, collection, where)
console.log(resultList.instancesList)

return { status: 'call-not-found' }
}

Expand All @@ -216,12 +203,15 @@ export class Application {
}

async pushBucket(args: { bucketName: string, path: string, content: any }) {
console.log(`Pushing to bucket ${args.bucketName}, path ${args.path}`)
const client = await this.getBucketsClient()
console.log(`Got bucket client, ensuring bucket exists`)
const { bucketKey } = await this.ensureBucket({ bucketName: args.bucketName })
console.log(`Ensured bucket exists, pushing content`)
const content = typeof args.content === 'string' ? args.content : JSON.stringify(args.content)
const file = { path: args.path, content: Buffer.from(content) }
const pushResult = await client.pushPath(bucketKey, args.path, file)
console.log(pushResult)
console.log('Successful push! Result:', pushResult)
return { pushResult }
}

Expand Down

0 comments on commit ec73c30

Please sign in to comment.