From ec73c3054b480d15539cd843d38b1f341f7d3873 Mon Sep 17 00:00:00 2001 From: Vincent den Boer Date: Wed, 26 Aug 2020 12:01:02 +0200 Subject: [PATCH] Clean up and add example recipe --- recipes/memex-tag.json | 39 +++++++++++++++++++++++++++++++++++++++ ts/application.ts | 22 ++++++---------------- 2 files changed, 45 insertions(+), 16 deletions(-) create mode 100644 recipes/memex-tag.json diff --git a/recipes/memex-tag.json b/recipes/memex-tag.json new file mode 100644 index 0000000..0c81354 --- /dev/null +++ b/recipes/memex-tag.json @@ -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" + } + } + } + } + } + ] + } +} diff --git a/ts/application.ts b/ts/application.ts index 61e6109..f0c631c 100644 --- a/ts/application.ts +++ b/ts/application.ts @@ -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: {} } } @@ -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 } } @@ -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' } } @@ -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 } }