diff --git a/package.json b/package.json index d959ecc..f5bdcf6 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "appwrite-databases", - "version": "1.2.3", + "version": "1.3.0", "description": "Manage Databases, Collections, and Documents in Appwrite", "main": "src/index.ts", "license": "MIT", diff --git a/schema.json b/schema.json index c78c021..c7e6a6d 100644 --- a/schema.json +++ b/schema.json @@ -9,7 +9,8 @@ "datasource": { "endpoint": { "type": "string", - "required": true + "required": true, + "default": "https://cloud.appwrite.io/v1" }, "projectId": { "type": "string", @@ -73,6 +74,10 @@ "documentId": { "type": "string", "required": false + }, + "queries": { + "type": "string", + "required": false } } }, diff --git a/src/datasource.ts b/src/datasource.ts index c520638..c1c3ff6 100644 --- a/src/datasource.ts +++ b/src/datasource.ts @@ -25,23 +25,31 @@ class CustomIntegration implements IntegrationBase { return await this.databases.createDocument(query.databaseId, query.collectionId, query.documentId, query.data) } - async read(query: { databaseId: string; collectionId: string; documentId: string; extra: { [key:string]: string; } }) { + async read(query: { databaseId: string; collectionId: string; documentId: string; queries: string; extra: { [key:string]: string; } }) { + let queries + if (query.queries) { + try { + queries = JSON.parse(query.queries) + } catch(e) { + throw "Invalid queries - must be a valid array." + } + } if (query.extra.type === "Documents") { if (query.documentId) { return await this.databases.getDocument(query.databaseId, query.collectionId, query.documentId) } - return await this.databases.listDocuments(query.databaseId, query.collectionId) + return await this.databases.listDocuments(query.databaseId, query.collectionId, queries) } if (query.extra.type === "Collections") { if (query.collectionId) { return await this.databases.getCollection(query.databaseId, query.collectionId) } - return await this.databases.listCollections(query.databaseId) + return await this.databases.listCollections(query.databaseId, queries) } if (query.databaseId) { return await this.databases.get(query.databaseId) } - return await this.databases.list() + return await this.databases.list(queries) } async update(query: { databaseId: string; collectionId: string; name: string; extra: { [key:string]: string; } }) {