feat(firebase): add new child object in a firebase realtime database

This commit is contained in:
Rıdvan Akca
2024-04-19 11:27:55 +02:00
parent 686c834748
commit 1f520ed590
3 changed files with 82 additions and 1 deletions

View File

@@ -1,3 +1,7 @@
import newChildObjectInFirebaseRealtimeDatabase from './new-child-object-in-a-firebase-realtime-database/index.js';
import newDocumentsWithinFirestoreCollection from './new-documents-within-firestore-collection/index.js'; import newDocumentsWithinFirestoreCollection from './new-documents-within-firestore-collection/index.js';
export default [newDocumentsWithinFirestoreCollection]; export default [
newChildObjectInFirebaseRealtimeDatabase,
newDocumentsWithinFirestoreCollection,
];

View File

@@ -0,0 +1,75 @@
import Crypto from 'crypto';
import defineTrigger from '../../../../helpers/define-trigger.js';
export default defineTrigger({
name: 'New child object in a firebase realtime database',
key: 'newChildObjectInFirebaseRealtimeDatabase',
pollInterval: 15,
description:
'Triggers when a new child object is generated within a specific path.',
arguments: [
{
label: 'Path',
key: 'path',
type: 'string',
required: true,
description:
"Indicate the path to the key of the object where the child objects to be queried are located, for example, 'foo/bar/here.json'.",
variables: true,
},
{
label: 'Order',
key: 'order',
type: 'string',
required: false,
description:
'The key or path of the child that should be utilized for comparing objects/records. If unspecified, the order of $key is used.',
variables: true,
},
{
label: 'Location of newest objects',
key: 'locationOfNewestObjects',
type: 'dropdown',
required: false,
description:
'Specifies whether the new 100 records are positioned at the "top" or the "bottom" of the ordering. If left unspecified, the assumption is that the bottom/last result represents the "newest objects" (limitToLast).',
variables: true,
options: [
{ label: 'Top of results', value: 'limitToFirst' },
{ label: 'Bottom of results', value: 'limitToLast' },
],
},
],
async run($) {
const { path, order, locationOfNewestObjects } = $.step.parameters;
const params = {};
if (order) {
params.orderBy = `"${order}"`;
}
if (locationOfNewestObjects) {
params[`${locationOfNewestObjects}`] = 100;
}
const { data } = await $.http.get(path, {
params,
additionalProperties: {
setFirestoreBaseUrl: false,
},
});
if (!data) {
return;
}
$.pushTriggerItem({
raw: data,
meta: {
internalId: Crypto.randomUUID(),
},
});
},
});

View File

@@ -1,6 +1,8 @@
--- ---
favicon: /favicons/firebase.svg favicon: /favicons/firebase.svg
items: items:
- name: New child object in a firebase realtime database
desc: Triggers when a new child object is generated within a specific path.
- name: New documents within a firestore collection - name: New documents within a firestore collection
desc: Triggers when a new document is added within a Cloud Firestore collection. desc: Triggers when a new document is added within a Cloud Firestore collection.
--- ---