feat(appwrite): add new documents trigger

This commit is contained in:
Rıdvan Akca
2024-01-25 16:02:43 +03:00
committed by Ali BARIN
parent 9dc82290b5
commit 6e5c0cc0c7
9 changed files with 163 additions and 1 deletions

View File

@@ -0,0 +1,4 @@
import listCollections from './list-collections/index.js';
import listDatabases from './list-databases/index.js';
export default [listCollections, listDatabases];

View File

@@ -0,0 +1,33 @@
export default {
name: 'List collections',
key: 'listCollections',
async run($) {
const collections = {
data: [],
};
const databaseId = $.step.parameters.databaseId;
if (!databaseId) {
return collections;
}
const { data } = await $.http.get(
`/v1/databases/${databaseId}/collections`
);
if (data?.collections) {
const sortedCollections = data.collections.sort((a, b) =>
a.$createdAt - b.$createdAt ? 1 : -1
);
for (const collection of sortedCollections) {
collections.data.push({
value: collection.$id,
name: collection.name,
});
}
}
return collections;
},
};

View File

@@ -0,0 +1,26 @@
export default {
name: 'List databases',
key: 'listDatabases',
async run($) {
const databases = {
data: [],
};
const { data } = await $.http.get('/v1/databases');
if (data?.databases) {
const sortedDatabases = data.databases.sort((a, b) =>
a.$createdAt - b.$createdAt ? 1 : -1
);
for (const database of sortedDatabases) {
databases.data.push({
value: database.$id,
name: database.name,
});
}
}
return databases;
},
};

View File

@@ -2,6 +2,8 @@ import defineApp from '../../helpers/define-app.js';
import addAuthHeader from './common/add-auth-header.js'; import addAuthHeader from './common/add-auth-header.js';
import setBaseUrl from './common/set-base-url.js'; import setBaseUrl from './common/set-base-url.js';
import auth from './auth/index.js'; import auth from './auth/index.js';
import triggers from './triggers/index.js';
import dynamicData from './dynamic-data/index.js';
export default defineApp({ export default defineApp({
name: 'Appwrite', name: 'Appwrite',
@@ -14,4 +16,6 @@ export default defineApp({
supportsConnections: true, supportsConnections: true,
beforeRequest: [setBaseUrl, addAuthHeader], beforeRequest: [setBaseUrl, addAuthHeader],
auth, auth,
triggers,
dynamicData,
}); });

View File

@@ -0,0 +1,3 @@
import newDocuments from './new-documents/index.js';
export default [newDocuments];

View File

@@ -0,0 +1,76 @@
import defineTrigger from '../../../../helpers/define-trigger.js';
export default defineTrigger({
name: 'New documents',
key: 'newDocuments',
pollInterval: 15,
description: 'Triggers when a new document is created.',
arguments: [
{
label: 'Database',
key: 'databaseId',
type: 'dropdown',
required: true,
description: '',
variables: true,
source: {
type: 'query',
name: 'getDynamicData',
arguments: [
{
name: 'key',
value: 'listDatabases',
},
],
},
},
{
label: 'Collection',
key: 'collectionId',
type: 'dropdown',
required: true,
dependsOn: ['parameters.databaseId'],
description: '',
variables: true,
source: {
type: 'query',
name: 'getDynamicData',
arguments: [
{
name: 'key',
value: 'listCollections',
},
{
name: 'parameters.databaseId',
value: '{parameters.databaseId}',
},
],
},
},
],
async run($) {
const { databaseId, collectionId } = $.step.parameters;
const { data } = await $.http.get(
`/v1/databases/${databaseId}/collections/${collectionId}/documents`
);
if (!data?.documents?.length) {
return;
}
const sortedDocuments = data.documents.sort((a, b) =>
a.$createdAt - b.$createdAt ? 1 : -1
);
for (const document of sortedDocuments) {
$.pushTriggerItem({
raw: document,
meta: {
internalId: document.$id,
},
});
}
},
});

View File

@@ -45,7 +45,10 @@ export default defineConfig({
text: 'Appwrite', text: 'Appwrite',
collapsible: true, collapsible: true,
collapsed: true, collapsed: true,
items: [{ text: 'Connection', link: '/apps/appwrite/connection' }], items: [
{ text: 'Triggers', link: '/apps/appwrite/triggers' },
{ text: 'Connection', link: '/apps/appwrite/connection' },
],
}, },
{ {
text: 'Carbone', text: 'Carbone',

View File

@@ -0,0 +1,12 @@
---
favicon: /favicons/appwrite.svg
items:
- name: New documets
desc: Triggers when a new document is created.
---
<script setup>
import CustomListing from '../../components/CustomListing.vue'
</script>
<CustomListing />

View File

@@ -3,6 +3,7 @@
The following integrations are currently supported by Automatisch. The following integrations are currently supported by Automatisch.
- [Airtable](/apps/airtable/actions) - [Airtable](/apps/airtable/actions)
- [Appwrite](/apps/appwrite/triggers)
- [Carbone](/apps/carbone/actions) - [Carbone](/apps/carbone/actions)
- [Datastore](/apps/datastore/actions) - [Datastore](/apps/datastore/actions)
- [DeepL](/apps/deepl/actions) - [DeepL](/apps/deepl/actions)