mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-18 02:21:13 +00:00
n8n-3867-progressively-apply-prettier-to-all (#3873)
* 🔨 formatting nodes with prettier
This commit is contained in:
@@ -1,6 +1,4 @@
|
||||
import {
|
||||
INodeProperties,
|
||||
} from 'n8n-workflow';
|
||||
import { INodeProperties } from 'n8n-workflow';
|
||||
|
||||
export const collectionOperations: INodeProperties[] = [
|
||||
{
|
||||
@@ -10,9 +8,7 @@ export const collectionOperations: INodeProperties[] = [
|
||||
noDataExpression: true,
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: [
|
||||
'collection',
|
||||
],
|
||||
resource: ['collection'],
|
||||
},
|
||||
},
|
||||
options: [
|
||||
@@ -41,15 +37,12 @@ export const collectionFields: INodeProperties[] = [
|
||||
},
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: [
|
||||
'collection',
|
||||
],
|
||||
operation: [
|
||||
'getAll',
|
||||
],
|
||||
resource: ['collection'],
|
||||
operation: ['getAll'],
|
||||
},
|
||||
},
|
||||
description: 'As displayed in firebase console URL. Choose from the list, or specify an ID using an <a href="https://docs.n8n.io/code-examples/expressions/">expression</a>.',
|
||||
description:
|
||||
'As displayed in firebase console URL. Choose from the list, or specify an ID using an <a href="https://docs.n8n.io/code-examples/expressions/">expression</a>.',
|
||||
required: true,
|
||||
},
|
||||
{
|
||||
@@ -59,12 +52,8 @@ export const collectionFields: INodeProperties[] = [
|
||||
default: '(default)',
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: [
|
||||
'collection',
|
||||
],
|
||||
operation: [
|
||||
'getAll',
|
||||
],
|
||||
resource: ['collection'],
|
||||
operation: ['getAll'],
|
||||
},
|
||||
},
|
||||
description: 'Usually the provided default value will work',
|
||||
@@ -77,12 +66,8 @@ export const collectionFields: INodeProperties[] = [
|
||||
default: false,
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: [
|
||||
'collection',
|
||||
],
|
||||
operation: [
|
||||
'getAll',
|
||||
],
|
||||
resource: ['collection'],
|
||||
operation: ['getAll'],
|
||||
},
|
||||
},
|
||||
description: 'Whether to return all results or only up to a given limit',
|
||||
@@ -94,15 +79,9 @@ export const collectionFields: INodeProperties[] = [
|
||||
type: 'number',
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: [
|
||||
'collection',
|
||||
],
|
||||
operation: [
|
||||
'getAll',
|
||||
],
|
||||
returnAll: [
|
||||
false,
|
||||
],
|
||||
resource: ['collection'],
|
||||
operation: ['getAll'],
|
||||
returnAll: [false],
|
||||
},
|
||||
},
|
||||
typeOptions: {
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
import {
|
||||
INodeProperties,
|
||||
} from 'n8n-workflow';
|
||||
import { INodeProperties } from 'n8n-workflow';
|
||||
|
||||
export const documentOperations: INodeProperties[] = [
|
||||
{
|
||||
@@ -10,9 +8,7 @@ export const documentOperations: INodeProperties[] = [
|
||||
noDataExpression: true,
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: [
|
||||
'document',
|
||||
],
|
||||
resource: ['document'],
|
||||
},
|
||||
},
|
||||
options: [
|
||||
@@ -25,7 +21,8 @@ export const documentOperations: INodeProperties[] = [
|
||||
{
|
||||
name: 'Create or Update',
|
||||
value: 'upsert',
|
||||
description: 'Create a new document, or update the current one if it already exists (upsert)',
|
||||
description:
|
||||
'Create a new document, or update the current one if it already exists (upsert)',
|
||||
action: 'Create or update a document',
|
||||
},
|
||||
{
|
||||
@@ -76,15 +73,12 @@ export const documentFields: INodeProperties[] = [
|
||||
},
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: [
|
||||
'document',
|
||||
],
|
||||
operation: [
|
||||
'create',
|
||||
],
|
||||
resource: ['document'],
|
||||
operation: ['create'],
|
||||
},
|
||||
},
|
||||
description: 'As displayed in firebase console URL. Choose from the list, or specify an ID using an <a href="https://docs.n8n.io/code-examples/expressions/">expression</a>.',
|
||||
description:
|
||||
'As displayed in firebase console URL. Choose from the list, or specify an ID using an <a href="https://docs.n8n.io/code-examples/expressions/">expression</a>.',
|
||||
required: true,
|
||||
},
|
||||
{
|
||||
@@ -94,12 +88,8 @@ export const documentFields: INodeProperties[] = [
|
||||
default: '(default)',
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: [
|
||||
'document',
|
||||
],
|
||||
operation: [
|
||||
'create',
|
||||
],
|
||||
resource: ['document'],
|
||||
operation: ['create'],
|
||||
},
|
||||
},
|
||||
description: 'Usually the provided default value will work',
|
||||
@@ -112,12 +102,8 @@ export const documentFields: INodeProperties[] = [
|
||||
default: '',
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: [
|
||||
'document',
|
||||
],
|
||||
operation: [
|
||||
'create',
|
||||
],
|
||||
resource: ['document'],
|
||||
operation: ['create'],
|
||||
},
|
||||
},
|
||||
description: 'Collection name',
|
||||
@@ -130,12 +116,8 @@ export const documentFields: INodeProperties[] = [
|
||||
default: '',
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: [
|
||||
'document',
|
||||
],
|
||||
operation: [
|
||||
'create',
|
||||
],
|
||||
resource: ['document'],
|
||||
operation: ['create'],
|
||||
},
|
||||
},
|
||||
description: 'List of attributes to save',
|
||||
@@ -148,12 +130,8 @@ export const documentFields: INodeProperties[] = [
|
||||
type: 'boolean',
|
||||
displayOptions: {
|
||||
show: {
|
||||
operation: [
|
||||
'create',
|
||||
],
|
||||
resource: [
|
||||
'document',
|
||||
],
|
||||
operation: ['create'],
|
||||
resource: ['document'],
|
||||
},
|
||||
},
|
||||
default: true,
|
||||
@@ -173,15 +151,12 @@ export const documentFields: INodeProperties[] = [
|
||||
},
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: [
|
||||
'document',
|
||||
],
|
||||
operation: [
|
||||
'get',
|
||||
],
|
||||
resource: ['document'],
|
||||
operation: ['get'],
|
||||
},
|
||||
},
|
||||
description: 'As displayed in firebase console URL. Choose from the list, or specify an ID using an <a href="https://docs.n8n.io/code-examples/expressions/">expression</a>.',
|
||||
description:
|
||||
'As displayed in firebase console URL. Choose from the list, or specify an ID using an <a href="https://docs.n8n.io/code-examples/expressions/">expression</a>.',
|
||||
required: true,
|
||||
},
|
||||
{
|
||||
@@ -191,12 +166,8 @@ export const documentFields: INodeProperties[] = [
|
||||
default: '(default)',
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: [
|
||||
'document',
|
||||
],
|
||||
operation: [
|
||||
'get',
|
||||
],
|
||||
resource: ['document'],
|
||||
operation: ['get'],
|
||||
},
|
||||
},
|
||||
description: 'Usually the provided default value will work',
|
||||
@@ -209,12 +180,8 @@ export const documentFields: INodeProperties[] = [
|
||||
default: '',
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: [
|
||||
'document',
|
||||
],
|
||||
operation: [
|
||||
'get',
|
||||
],
|
||||
resource: ['document'],
|
||||
operation: ['get'],
|
||||
},
|
||||
},
|
||||
description: 'Collection name',
|
||||
@@ -226,12 +193,8 @@ export const documentFields: INodeProperties[] = [
|
||||
type: 'string',
|
||||
displayOptions: {
|
||||
show: {
|
||||
operation: [
|
||||
'get',
|
||||
],
|
||||
resource: [
|
||||
'document',
|
||||
],
|
||||
operation: ['get'],
|
||||
resource: ['document'],
|
||||
},
|
||||
},
|
||||
default: '',
|
||||
@@ -243,12 +206,8 @@ export const documentFields: INodeProperties[] = [
|
||||
type: 'boolean',
|
||||
displayOptions: {
|
||||
show: {
|
||||
operation: [
|
||||
'get',
|
||||
],
|
||||
resource: [
|
||||
'document',
|
||||
],
|
||||
operation: ['get'],
|
||||
resource: ['document'],
|
||||
},
|
||||
},
|
||||
default: true,
|
||||
@@ -268,15 +227,12 @@ export const documentFields: INodeProperties[] = [
|
||||
},
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: [
|
||||
'document',
|
||||
],
|
||||
operation: [
|
||||
'getAll',
|
||||
],
|
||||
resource: ['document'],
|
||||
operation: ['getAll'],
|
||||
},
|
||||
},
|
||||
description: 'As displayed in firebase console URL. Choose from the list, or specify an ID using an <a href="https://docs.n8n.io/code-examples/expressions/">expression</a>.',
|
||||
description:
|
||||
'As displayed in firebase console URL. Choose from the list, or specify an ID using an <a href="https://docs.n8n.io/code-examples/expressions/">expression</a>.',
|
||||
required: true,
|
||||
},
|
||||
{
|
||||
@@ -286,12 +242,8 @@ export const documentFields: INodeProperties[] = [
|
||||
default: '(default)',
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: [
|
||||
'document',
|
||||
],
|
||||
operation: [
|
||||
'getAll',
|
||||
],
|
||||
resource: ['document'],
|
||||
operation: ['getAll'],
|
||||
},
|
||||
},
|
||||
description: 'Usually the provided default value will work',
|
||||
@@ -304,12 +256,8 @@ export const documentFields: INodeProperties[] = [
|
||||
default: '',
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: [
|
||||
'document',
|
||||
],
|
||||
operation: [
|
||||
'getAll',
|
||||
],
|
||||
resource: ['document'],
|
||||
operation: ['getAll'],
|
||||
},
|
||||
},
|
||||
description: 'Collection name',
|
||||
@@ -322,12 +270,8 @@ export const documentFields: INodeProperties[] = [
|
||||
default: false,
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: [
|
||||
'document',
|
||||
],
|
||||
operation: [
|
||||
'getAll',
|
||||
],
|
||||
resource: ['document'],
|
||||
operation: ['getAll'],
|
||||
},
|
||||
},
|
||||
description: 'Whether to return all results or only up to a given limit',
|
||||
@@ -339,15 +283,9 @@ export const documentFields: INodeProperties[] = [
|
||||
type: 'number',
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: [
|
||||
'document',
|
||||
],
|
||||
operation: [
|
||||
'getAll',
|
||||
],
|
||||
returnAll: [
|
||||
false,
|
||||
],
|
||||
resource: ['document'],
|
||||
operation: ['getAll'],
|
||||
returnAll: [false],
|
||||
},
|
||||
},
|
||||
typeOptions: {
|
||||
@@ -363,12 +301,8 @@ export const documentFields: INodeProperties[] = [
|
||||
type: 'boolean',
|
||||
displayOptions: {
|
||||
show: {
|
||||
operation: [
|
||||
'getAll',
|
||||
],
|
||||
resource: [
|
||||
'document',
|
||||
],
|
||||
operation: ['getAll'],
|
||||
resource: ['document'],
|
||||
},
|
||||
},
|
||||
default: true,
|
||||
@@ -388,15 +322,12 @@ export const documentFields: INodeProperties[] = [
|
||||
},
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: [
|
||||
'document',
|
||||
],
|
||||
operation: [
|
||||
'delete',
|
||||
],
|
||||
resource: ['document'],
|
||||
operation: ['delete'],
|
||||
},
|
||||
},
|
||||
description: 'As displayed in firebase console URL. Choose from the list, or specify an ID using an <a href="https://docs.n8n.io/code-examples/expressions/">expression</a>.',
|
||||
description:
|
||||
'As displayed in firebase console URL. Choose from the list, or specify an ID using an <a href="https://docs.n8n.io/code-examples/expressions/">expression</a>.',
|
||||
required: true,
|
||||
},
|
||||
{
|
||||
@@ -406,12 +337,8 @@ export const documentFields: INodeProperties[] = [
|
||||
default: '(default)',
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: [
|
||||
'document',
|
||||
],
|
||||
operation: [
|
||||
'delete',
|
||||
],
|
||||
resource: ['document'],
|
||||
operation: ['delete'],
|
||||
},
|
||||
},
|
||||
description: 'Usually the provided default value will work',
|
||||
@@ -424,12 +351,8 @@ export const documentFields: INodeProperties[] = [
|
||||
default: '',
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: [
|
||||
'document',
|
||||
],
|
||||
operation: [
|
||||
'delete',
|
||||
],
|
||||
resource: ['document'],
|
||||
operation: ['delete'],
|
||||
},
|
||||
},
|
||||
description: 'Collection name',
|
||||
@@ -441,12 +364,8 @@ export const documentFields: INodeProperties[] = [
|
||||
type: 'string',
|
||||
displayOptions: {
|
||||
show: {
|
||||
operation: [
|
||||
'delete',
|
||||
],
|
||||
resource: [
|
||||
'document',
|
||||
],
|
||||
operation: ['delete'],
|
||||
resource: ['document'],
|
||||
},
|
||||
},
|
||||
default: '',
|
||||
@@ -580,15 +499,12 @@ export const documentFields: INodeProperties[] = [
|
||||
},
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: [
|
||||
'document',
|
||||
],
|
||||
operation: [
|
||||
'upsert',
|
||||
],
|
||||
resource: ['document'],
|
||||
operation: ['upsert'],
|
||||
},
|
||||
},
|
||||
description: 'As displayed in firebase console URL. Choose from the list, or specify an ID using an <a href="https://docs.n8n.io/code-examples/expressions/">expression</a>.',
|
||||
description:
|
||||
'As displayed in firebase console URL. Choose from the list, or specify an ID using an <a href="https://docs.n8n.io/code-examples/expressions/">expression</a>.',
|
||||
required: true,
|
||||
},
|
||||
{
|
||||
@@ -598,12 +514,8 @@ export const documentFields: INodeProperties[] = [
|
||||
default: '(default)',
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: [
|
||||
'document',
|
||||
],
|
||||
operation: [
|
||||
'upsert',
|
||||
],
|
||||
resource: ['document'],
|
||||
operation: ['upsert'],
|
||||
},
|
||||
},
|
||||
description: 'Usually the provided default value will work',
|
||||
@@ -616,12 +528,8 @@ export const documentFields: INodeProperties[] = [
|
||||
default: '',
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: [
|
||||
'document',
|
||||
],
|
||||
operation: [
|
||||
'upsert',
|
||||
],
|
||||
resource: ['document'],
|
||||
operation: ['upsert'],
|
||||
},
|
||||
},
|
||||
description: 'Collection name',
|
||||
@@ -633,12 +541,8 @@ export const documentFields: INodeProperties[] = [
|
||||
type: 'string',
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: [
|
||||
'document',
|
||||
],
|
||||
operation: [
|
||||
'upsert',
|
||||
],
|
||||
resource: ['document'],
|
||||
operation: ['upsert'],
|
||||
},
|
||||
},
|
||||
default: '',
|
||||
@@ -653,12 +557,8 @@ export const documentFields: INodeProperties[] = [
|
||||
default: '',
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: [
|
||||
'document',
|
||||
],
|
||||
operation: [
|
||||
'upsert',
|
||||
],
|
||||
resource: ['document'],
|
||||
operation: ['upsert'],
|
||||
},
|
||||
},
|
||||
description: 'Columns to insert',
|
||||
@@ -678,15 +578,12 @@ export const documentFields: INodeProperties[] = [
|
||||
},
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: [
|
||||
'document',
|
||||
],
|
||||
operation: [
|
||||
'query',
|
||||
],
|
||||
resource: ['document'],
|
||||
operation: ['query'],
|
||||
},
|
||||
},
|
||||
description: 'As displayed in firebase console URL. Choose from the list, or specify an ID using an <a href="https://docs.n8n.io/code-examples/expressions/">expression</a>.',
|
||||
description:
|
||||
'As displayed in firebase console URL. Choose from the list, or specify an ID using an <a href="https://docs.n8n.io/code-examples/expressions/">expression</a>.',
|
||||
required: true,
|
||||
},
|
||||
{
|
||||
@@ -696,12 +593,8 @@ export const documentFields: INodeProperties[] = [
|
||||
default: '(default)',
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: [
|
||||
'document',
|
||||
],
|
||||
operation: [
|
||||
'query',
|
||||
],
|
||||
resource: ['document'],
|
||||
operation: ['query'],
|
||||
},
|
||||
},
|
||||
description: 'Usually the provided default value will work',
|
||||
@@ -714,12 +607,8 @@ export const documentFields: INodeProperties[] = [
|
||||
default: '',
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: [
|
||||
'document',
|
||||
],
|
||||
operation: [
|
||||
'query',
|
||||
],
|
||||
resource: ['document'],
|
||||
operation: ['query'],
|
||||
},
|
||||
},
|
||||
description: 'JSON query to execute',
|
||||
@@ -727,7 +616,8 @@ export const documentFields: INodeProperties[] = [
|
||||
typeOptions: {
|
||||
alwaysOpenEditWindow: true,
|
||||
},
|
||||
placeholder: '{"structuredQuery": {"where": {"fieldFilter": {"field": {"fieldPath": "age"},"op": "EQUAL", "value": {"integerValue": 28}}}, "from": [{"collectionId": "users-collection"}]}}',
|
||||
placeholder:
|
||||
'{"structuredQuery": {"where": {"fieldFilter": {"field": {"fieldPath": "age"},"op": "EQUAL", "value": {"integerValue": 28}}}, "from": [{"collectionId": "users-collection"}]}}',
|
||||
},
|
||||
{
|
||||
displayName: 'Simplify',
|
||||
@@ -735,12 +625,8 @@ export const documentFields: INodeProperties[] = [
|
||||
type: 'boolean',
|
||||
displayOptions: {
|
||||
show: {
|
||||
operation: [
|
||||
'query',
|
||||
],
|
||||
resource: [
|
||||
'document',
|
||||
],
|
||||
operation: ['query'],
|
||||
resource: ['document'],
|
||||
},
|
||||
},
|
||||
default: true,
|
||||
|
||||
@@ -1,21 +1,21 @@
|
||||
import {
|
||||
OptionsWithUri,
|
||||
} from 'request';
|
||||
import { OptionsWithUri } from 'request';
|
||||
|
||||
import {
|
||||
IExecuteFunctions,
|
||||
IExecuteSingleFunctions,
|
||||
ILoadOptionsFunctions,
|
||||
} from 'n8n-core';
|
||||
import { IExecuteFunctions, IExecuteSingleFunctions, ILoadOptionsFunctions } from 'n8n-core';
|
||||
|
||||
import {
|
||||
IDataObject, NodeApiError,
|
||||
} from 'n8n-workflow';
|
||||
import { IDataObject, NodeApiError } from 'n8n-workflow';
|
||||
|
||||
import moment from 'moment-timezone';
|
||||
|
||||
export async function googleApiRequest(this: IExecuteFunctions | IExecuteSingleFunctions | ILoadOptionsFunctions, method: string, resource: string, body: any = {}, qs: IDataObject = {}, uri: string | null = null): Promise<any> { // tslint:disable-line:no-any
|
||||
|
||||
export async function googleApiRequest(
|
||||
this: IExecuteFunctions | IExecuteSingleFunctions | ILoadOptionsFunctions,
|
||||
method: string,
|
||||
resource: string,
|
||||
// tslint:disable-next-line:no-any
|
||||
body: any = {},
|
||||
qs: IDataObject = {},
|
||||
uri: string | null = null,
|
||||
// tslint:disable-next-line:no-any
|
||||
): Promise<any> {
|
||||
const options: OptionsWithUri = {
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
@@ -35,14 +35,27 @@ export async function googleApiRequest(this: IExecuteFunctions | IExecuteSingleF
|
||||
}
|
||||
|
||||
//@ts-ignore
|
||||
return await this.helpers.requestOAuth2.call(this, 'googleFirebaseCloudFirestoreOAuth2Api', options);
|
||||
return await this.helpers.requestOAuth2.call(
|
||||
this,
|
||||
'googleFirebaseCloudFirestoreOAuth2Api',
|
||||
options,
|
||||
);
|
||||
} catch (error) {
|
||||
throw new NodeApiError(this.getNode(), error);
|
||||
}
|
||||
}
|
||||
|
||||
export async function googleApiRequestAllItems(this: IExecuteFunctions | ILoadOptionsFunctions, propertyName: string, method: string, endpoint: string, body: any = {}, query: IDataObject = {}, uri: string | null = null): Promise<any> { // tslint:disable-line:no-any
|
||||
|
||||
export async function googleApiRequestAllItems(
|
||||
this: IExecuteFunctions | ILoadOptionsFunctions,
|
||||
propertyName: string,
|
||||
method: string,
|
||||
endpoint: string,
|
||||
// tslint:disable-next-line:no-any
|
||||
body: any = {},
|
||||
query: IDataObject = {},
|
||||
uri: string | null = null,
|
||||
// tslint:disable-next-line:no-any
|
||||
): Promise<any> {
|
||||
const returnData: IDataObject[] = [];
|
||||
|
||||
let responseData;
|
||||
@@ -52,44 +65,42 @@ export async function googleApiRequestAllItems(this: IExecuteFunctions | ILoadOp
|
||||
responseData = await googleApiRequest.call(this, method, endpoint, body, query, uri);
|
||||
query.pageToken = responseData['nextPageToken'];
|
||||
returnData.push.apply(returnData, responseData[propertyName]);
|
||||
} while (
|
||||
responseData['nextPageToken'] !== undefined &&
|
||||
responseData['nextPageToken'] !== ''
|
||||
);
|
||||
} while (responseData['nextPageToken'] !== undefined && responseData['nextPageToken'] !== '');
|
||||
|
||||
return returnData;
|
||||
}
|
||||
|
||||
const isValidDate = (str: string) => moment(str, ['YYYY-MM-DD HH:mm:ss Z', moment.ISO_8601], true).isValid();
|
||||
const isValidDate = (str: string) =>
|
||||
moment(str, ['YYYY-MM-DD HH:mm:ss Z', moment.ISO_8601], true).isValid();
|
||||
|
||||
// Both functions below were taken from Stack Overflow jsonToDocument was fixed as it was unable to handle null values correctly
|
||||
// https://stackoverflow.com/questions/62246410/how-to-convert-a-firestore-document-to-plain-json-and-vice-versa
|
||||
// Great thanks to https://stackoverflow.com/users/3915246/mahindar
|
||||
export function jsonToDocument(value: string | number | IDataObject | IDataObject[]): IDataObject {
|
||||
if (value === 'true' || value === 'false' || typeof value === 'boolean') {
|
||||
return { 'booleanValue': value };
|
||||
return { booleanValue: value };
|
||||
} else if (value === null) {
|
||||
return { 'nullValue': null };
|
||||
return { nullValue: null };
|
||||
} else if (!isNaN(value as number)) {
|
||||
if (value.toString().indexOf('.') !== -1) {
|
||||
return { 'doubleValue': value };
|
||||
return { doubleValue: value };
|
||||
} else {
|
||||
return { 'integerValue': value };
|
||||
return { integerValue: value };
|
||||
}
|
||||
} else if (isValidDate(value as string)) {
|
||||
const date = new Date(Date.parse(value as string));
|
||||
return { 'timestampValue': date.toISOString() };
|
||||
return { timestampValue: date.toISOString() };
|
||||
} else if (typeof value === 'string') {
|
||||
return { 'stringValue': value };
|
||||
return { stringValue: value };
|
||||
} else if (value && value.constructor === Array) {
|
||||
return { 'arrayValue': { values: value.map(v => jsonToDocument(v)) } };
|
||||
return { arrayValue: { values: value.map((v) => jsonToDocument(v)) } };
|
||||
} else if (typeof value === 'object') {
|
||||
const obj = {};
|
||||
for (const o of Object.keys(value)) {
|
||||
//@ts-ignore
|
||||
obj[o] = jsonToDocument(value[o]);
|
||||
}
|
||||
return { 'mapValue': { fields: obj } };
|
||||
return { mapValue: { fields: obj } };
|
||||
}
|
||||
|
||||
return {};
|
||||
@@ -109,17 +120,33 @@ export function fullDocumentToJson(data: IDataObject): IDataObject {
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
export function documentToJson(fields: IDataObject): IDataObject {
|
||||
if (fields === undefined) return {};
|
||||
const result = {};
|
||||
for (const f of Object.keys(fields)) {
|
||||
const key = f, value = fields[f],
|
||||
isDocumentType = ['stringValue', 'booleanValue', 'doubleValue',
|
||||
'integerValue', 'timestampValue', 'mapValue', 'arrayValue', 'nullValue', 'geoPointValue'].find(t => t === key);
|
||||
const key = f,
|
||||
value = fields[f],
|
||||
isDocumentType = [
|
||||
'stringValue',
|
||||
'booleanValue',
|
||||
'doubleValue',
|
||||
'integerValue',
|
||||
'timestampValue',
|
||||
'mapValue',
|
||||
'arrayValue',
|
||||
'nullValue',
|
||||
'geoPointValue',
|
||||
].find((t) => t === key);
|
||||
if (isDocumentType) {
|
||||
const item = ['stringValue', 'booleanValue', 'doubleValue', 'integerValue', 'timestampValue', 'nullValue', 'geoPointValue']
|
||||
.find(t => t === key);
|
||||
const item = [
|
||||
'stringValue',
|
||||
'booleanValue',
|
||||
'doubleValue',
|
||||
'integerValue',
|
||||
'timestampValue',
|
||||
'nullValue',
|
||||
'geoPointValue',
|
||||
].find((t) => t === key);
|
||||
if (item) {
|
||||
return value as IDataObject;
|
||||
} else if ('mapValue' === key) {
|
||||
@@ -129,7 +156,7 @@ export function documentToJson(fields: IDataObject): IDataObject {
|
||||
// @ts-ignore
|
||||
const list = value.values as IDataObject[];
|
||||
// @ts-ignore
|
||||
return !!list ? list.map(l => documentToJson(l)) : [];
|
||||
return !!list ? list.map((l) => documentToJson(l)) : [];
|
||||
}
|
||||
} else {
|
||||
// @ts-ignore
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
import {
|
||||
IExecuteFunctions,
|
||||
} from 'n8n-core';
|
||||
import { IExecuteFunctions } from 'n8n-core';
|
||||
|
||||
import {
|
||||
IDataObject,
|
||||
@@ -15,18 +13,12 @@ import {
|
||||
fullDocumentToJson,
|
||||
googleApiRequest,
|
||||
googleApiRequestAllItems,
|
||||
jsonToDocument
|
||||
jsonToDocument,
|
||||
} from './GenericFunctions';
|
||||
|
||||
import {
|
||||
collectionFields,
|
||||
collectionOperations,
|
||||
} from './CollectionDescription';
|
||||
import { collectionFields, collectionOperations } from './CollectionDescription';
|
||||
|
||||
import {
|
||||
documentFields,
|
||||
documentOperations,
|
||||
} from './DocumentDescription';
|
||||
import { documentFields, documentOperations } from './DocumentDescription';
|
||||
|
||||
export class GoogleFirebaseCloudFirestore implements INodeType {
|
||||
description: INodeTypeDescription = {
|
||||
@@ -76,9 +68,7 @@ export class GoogleFirebaseCloudFirestore implements INodeType {
|
||||
|
||||
methods = {
|
||||
loadOptions: {
|
||||
async getProjects(
|
||||
this: ILoadOptionsFunctions,
|
||||
): Promise<INodePropertyOptions[]> {
|
||||
async getProjects(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> {
|
||||
const collections = await googleApiRequestAllItems.call(
|
||||
this,
|
||||
'results',
|
||||
@@ -89,14 +79,16 @@ export class GoogleFirebaseCloudFirestore implements INodeType {
|
||||
'https://firebase.googleapis.com/v1beta1/projects',
|
||||
);
|
||||
// @ts-ignore
|
||||
const returnData = collections.map(o => ({ name: o.projectId, value: o.projectId })) as INodePropertyOptions[];
|
||||
const returnData = collections.map((o) => ({
|
||||
name: o.projectId,
|
||||
value: o.projectId,
|
||||
})) as INodePropertyOptions[];
|
||||
return returnData;
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
async execute(this: IExecuteFunctions): Promise<INodeExecutionData[][]> {
|
||||
|
||||
const items = this.getInputData();
|
||||
const returnData: IDataObject[] = [];
|
||||
let responseData;
|
||||
@@ -121,7 +113,7 @@ export class GoogleFirebaseCloudFirestore implements INodeType {
|
||||
{ documents: documentList },
|
||||
);
|
||||
|
||||
responseData = responseData.map((element: { found: { id: string, name: string } }) => {
|
||||
responseData = responseData.map((element: { found: { id: string; name: string } }) => {
|
||||
if (element.found) {
|
||||
element.found.id = (element.found.name as string).split('/').pop() as string;
|
||||
}
|
||||
@@ -131,39 +123,52 @@ export class GoogleFirebaseCloudFirestore implements INodeType {
|
||||
if (simple === false) {
|
||||
returnData.push.apply(returnData, responseData as IDataObject[]);
|
||||
} else {
|
||||
returnData.push.apply(returnData, responseData.map((element: IDataObject) => {
|
||||
return fullDocumentToJson(element.found as IDataObject);
|
||||
}).filter((el: IDataObject) => !!el));
|
||||
returnData.push.apply(
|
||||
returnData,
|
||||
responseData
|
||||
.map((element: IDataObject) => {
|
||||
return fullDocumentToJson(element.found as IDataObject);
|
||||
})
|
||||
.filter((el: IDataObject) => !!el),
|
||||
);
|
||||
}
|
||||
} else if (operation === 'create') {
|
||||
const projectId = this.getNodeParameter('projectId', 0) as string;
|
||||
const database = this.getNodeParameter('database', 0) as string;
|
||||
const simple = this.getNodeParameter('simple', 0) as boolean;
|
||||
|
||||
await Promise.all(items.map(async (item: IDataObject, i: number) => {
|
||||
const collection = this.getNodeParameter('collection', i) as string;
|
||||
const columns = this.getNodeParameter('columns', i) as string;
|
||||
const columnList = columns.split(',').map(column => column.trim());
|
||||
const document = { fields: {} };
|
||||
columnList.map(column => {
|
||||
// @ts-ignore
|
||||
document.fields[column] = item['json'][column] ? jsonToDocument(item['json'][column]) : jsonToDocument(null);
|
||||
});
|
||||
responseData = await googleApiRequest.call(
|
||||
this,
|
||||
'POST',
|
||||
`/${projectId}/databases/${database}/documents/${collection}`,
|
||||
document,
|
||||
);
|
||||
await Promise.all(
|
||||
items.map(async (item: IDataObject, i: number) => {
|
||||
const collection = this.getNodeParameter('collection', i) as string;
|
||||
const columns = this.getNodeParameter('columns', i) as string;
|
||||
const columnList = columns.split(',').map((column) => column.trim());
|
||||
const document = { fields: {} };
|
||||
columnList.map((column) => {
|
||||
// @ts-ignore
|
||||
if (item['json'][column]) {
|
||||
// @ts-ignore
|
||||
document.fields[column] = jsonToDocument(item['json'][column]);
|
||||
} else {
|
||||
// @ts-ignore
|
||||
document.fields[column] = jsonToDocument(null);
|
||||
}
|
||||
});
|
||||
responseData = await googleApiRequest.call(
|
||||
this,
|
||||
'POST',
|
||||
`/${projectId}/databases/${database}/documents/${collection}`,
|
||||
document,
|
||||
);
|
||||
|
||||
responseData.id = (responseData.name as string).split('/').pop();
|
||||
responseData.id = (responseData.name as string).split('/').pop();
|
||||
|
||||
if (simple === false) {
|
||||
returnData.push(responseData);
|
||||
} else {
|
||||
returnData.push(fullDocumentToJson(responseData as IDataObject));
|
||||
}
|
||||
}));
|
||||
if (simple === false) {
|
||||
returnData.push(responseData);
|
||||
} else {
|
||||
returnData.push(fullDocumentToJson(responseData as IDataObject));
|
||||
}
|
||||
}),
|
||||
);
|
||||
} else if (operation === 'getAll') {
|
||||
const projectId = this.getNodeParameter('projectId', 0) as string;
|
||||
const database = this.getNodeParameter('database', 0) as string;
|
||||
@@ -180,13 +185,13 @@ export class GoogleFirebaseCloudFirestore implements INodeType {
|
||||
);
|
||||
} else {
|
||||
const limit = this.getNodeParameter('limit', 0) as string;
|
||||
const getAllResponse = await googleApiRequest.call(
|
||||
const getAllResponse = (await googleApiRequest.call(
|
||||
this,
|
||||
'GET',
|
||||
`/${projectId}/databases/${database}/documents/${collection}`,
|
||||
{},
|
||||
{ pageSize: limit },
|
||||
) as IDataObject;
|
||||
)) as IDataObject;
|
||||
responseData = getAllResponse.documents;
|
||||
}
|
||||
responseData = responseData.map((element: IDataObject) => {
|
||||
@@ -196,29 +201,31 @@ export class GoogleFirebaseCloudFirestore implements INodeType {
|
||||
if (simple === false) {
|
||||
returnData.push.apply(returnData, responseData);
|
||||
} else {
|
||||
returnData.push.apply(returnData, responseData.map((element: IDataObject) => fullDocumentToJson(element as IDataObject)));
|
||||
returnData.push.apply(
|
||||
returnData,
|
||||
responseData.map((element: IDataObject) => fullDocumentToJson(element as IDataObject)),
|
||||
);
|
||||
}
|
||||
|
||||
} else if (operation === 'delete') {
|
||||
const responseData: IDataObject[] = [];
|
||||
|
||||
await Promise.all(items.map(async (item: IDataObject, i: number) => {
|
||||
const projectId = this.getNodeParameter('projectId', i) as string;
|
||||
const database = this.getNodeParameter('database', i) as string;
|
||||
const collection = this.getNodeParameter('collection', i) as string;
|
||||
const documentId = this.getNodeParameter('documentId', i) as string;
|
||||
await Promise.all(
|
||||
items.map(async (item: IDataObject, i: number) => {
|
||||
const projectId = this.getNodeParameter('projectId', i) as string;
|
||||
const database = this.getNodeParameter('database', i) as string;
|
||||
const collection = this.getNodeParameter('collection', i) as string;
|
||||
const documentId = this.getNodeParameter('documentId', i) as string;
|
||||
|
||||
await googleApiRequest.call(
|
||||
this,
|
||||
'DELETE',
|
||||
`/${projectId}/databases/${database}/documents/${collection}/${documentId}`,
|
||||
);
|
||||
await googleApiRequest.call(
|
||||
this,
|
||||
'DELETE',
|
||||
`/${projectId}/databases/${database}/documents/${collection}/${documentId}`,
|
||||
);
|
||||
|
||||
responseData.push({ success: true });
|
||||
|
||||
}));
|
||||
responseData.push({ success: true });
|
||||
}),
|
||||
);
|
||||
returnData.push.apply(returnData, responseData);
|
||||
|
||||
} else if (operation === 'upsert') {
|
||||
const projectId = this.getNodeParameter('projectId', 0) as string;
|
||||
const database = this.getNodeParameter('database', 0) as string;
|
||||
@@ -229,11 +236,17 @@ export class GoogleFirebaseCloudFirestore implements INodeType {
|
||||
// @ts-ignore
|
||||
const documentId = item['json'][updateKey] as string;
|
||||
const columns = this.getNodeParameter('columns', i) as string;
|
||||
const columnList = columns.split(',').map(column => column.trim()) as string[];
|
||||
const columnList = columns.split(',').map((column) => column.trim()) as string[];
|
||||
const document = {};
|
||||
columnList.map(column => {
|
||||
columnList.map((column) => {
|
||||
// @ts-ignore
|
||||
document[column] = item['json'].hasOwnProperty(column) ? jsonToDocument(item['json'][column]) : jsonToDocument(null);
|
||||
if (item['json'].hasOwnProperty(column)) {
|
||||
// @ts-ignore
|
||||
document[column] = jsonToDocument(item['json'][column]);
|
||||
} else {
|
||||
// @ts-ignore
|
||||
document[column] = jsonToDocument(null);
|
||||
}
|
||||
});
|
||||
|
||||
return {
|
||||
@@ -245,7 +258,6 @@ export class GoogleFirebaseCloudFirestore implements INodeType {
|
||||
fieldPaths: columnList,
|
||||
},
|
||||
};
|
||||
|
||||
});
|
||||
|
||||
responseData = [];
|
||||
@@ -295,38 +307,47 @@ export class GoogleFirebaseCloudFirestore implements INodeType {
|
||||
// returnData.push(fullDocumentToJson(responseData as IDataObject));
|
||||
// }
|
||||
// }));
|
||||
|
||||
} else if (operation === 'query') {
|
||||
const projectId = this.getNodeParameter('projectId', 0) as string;
|
||||
const database = this.getNodeParameter('database', 0) as string;
|
||||
const simple = this.getNodeParameter('simple', 0) as boolean;
|
||||
|
||||
await Promise.all(
|
||||
items.map(async (item: IDataObject, i: number) => {
|
||||
const query = this.getNodeParameter('query', i) as string;
|
||||
responseData = await googleApiRequest.call(
|
||||
this,
|
||||
'POST',
|
||||
`/${projectId}/databases/${database}/documents:runQuery`,
|
||||
JSON.parse(query),
|
||||
);
|
||||
|
||||
await Promise.all(items.map(async (item: IDataObject, i: number) => {
|
||||
const query = this.getNodeParameter('query', i) as string;
|
||||
responseData = await googleApiRequest.call(
|
||||
this,
|
||||
'POST',
|
||||
`/${projectId}/databases/${database}/documents:runQuery`,
|
||||
JSON.parse(query),
|
||||
);
|
||||
responseData = responseData.map(
|
||||
(element: { document: { id: string; name: string } }) => {
|
||||
if (element.document) {
|
||||
element.document.id = (element.document.name as string)
|
||||
.split('/')
|
||||
.pop() as string;
|
||||
}
|
||||
return element;
|
||||
},
|
||||
);
|
||||
|
||||
responseData = responseData.map((element: { document: { id: string, name: string } }) => {
|
||||
if (element.document) {
|
||||
element.document.id = (element.document.name as string).split('/').pop() as string;
|
||||
if (simple === false) {
|
||||
returnData.push.apply(returnData, responseData);
|
||||
} else {
|
||||
//@ts-ignore
|
||||
returnData.push.apply(
|
||||
returnData,
|
||||
responseData
|
||||
.map((element: IDataObject) => {
|
||||
return fullDocumentToJson(element.document as IDataObject);
|
||||
})
|
||||
.filter((element: IDataObject) => !!element),
|
||||
);
|
||||
}
|
||||
return element;
|
||||
});
|
||||
|
||||
if (simple === false) {
|
||||
returnData.push.apply(returnData, responseData);
|
||||
} else {
|
||||
//@ts-ignore
|
||||
returnData.push.apply(returnData, responseData.map((element: IDataObject) => {
|
||||
return fullDocumentToJson(element.document as IDataObject);
|
||||
}).filter((element: IDataObject) => !!element));
|
||||
}
|
||||
}));
|
||||
}),
|
||||
);
|
||||
}
|
||||
} else if (resource === 'collection') {
|
||||
if (operation === 'getAll') {
|
||||
@@ -342,18 +363,18 @@ export class GoogleFirebaseCloudFirestore implements INodeType {
|
||||
`/${projectId}/databases/${database}/documents:listCollectionIds`,
|
||||
);
|
||||
// @ts-ignore
|
||||
responseData = getAllResponse.map(o => ({ name: o }));
|
||||
responseData = getAllResponse.map((o) => ({ name: o }));
|
||||
} else {
|
||||
const limit = this.getNodeParameter('limit', 0) as string;
|
||||
const getAllResponse = await googleApiRequest.call(
|
||||
const getAllResponse = (await googleApiRequest.call(
|
||||
this,
|
||||
'POST',
|
||||
`/${projectId}/databases/${database}/documents:listCollectionIds`,
|
||||
{},
|
||||
{ pageSize: limit },
|
||||
) as IDataObject;
|
||||
)) as IDataObject;
|
||||
// @ts-ignore
|
||||
responseData = getAllResponse.collectionIds.map(o => ({ name: o }));
|
||||
responseData = getAllResponse.collectionIds.map((o) => ({ name: o }));
|
||||
}
|
||||
returnData.push.apply(returnData, responseData);
|
||||
}
|
||||
|
||||
@@ -1,20 +1,24 @@
|
||||
import {
|
||||
OptionsWithUrl,
|
||||
} from 'request';
|
||||
import { OptionsWithUrl } from 'request';
|
||||
|
||||
import {
|
||||
IExecuteFunctions,
|
||||
IExecuteSingleFunctions,
|
||||
ILoadOptionsFunctions,
|
||||
} from 'n8n-core';
|
||||
import { IExecuteFunctions, IExecuteSingleFunctions, ILoadOptionsFunctions } from 'n8n-core';
|
||||
|
||||
import {
|
||||
IDataObject, JsonObject, NodeApiError,
|
||||
} from 'n8n-workflow';
|
||||
import { IDataObject, JsonObject, NodeApiError } from 'n8n-workflow';
|
||||
|
||||
export async function googleApiRequest(this: IExecuteFunctions | IExecuteSingleFunctions | ILoadOptionsFunctions, projectId: string, method: string, resource: string, body: any = {}, qs: IDataObject = {}, headers: IDataObject = {}, uri: string | null = null): Promise<any> { // tslint:disable-line:no-any
|
||||
|
||||
const { region } = await this.getCredentials('googleFirebaseRealtimeDatabaseOAuth2Api') as IDataObject;
|
||||
export async function googleApiRequest(
|
||||
this: IExecuteFunctions | IExecuteSingleFunctions | ILoadOptionsFunctions,
|
||||
projectId: string,
|
||||
method: string,
|
||||
resource: string,
|
||||
// tslint:disable-next-line:no-any
|
||||
body: any = {},
|
||||
qs: IDataObject = {},
|
||||
headers: IDataObject = {},
|
||||
uri: string | null = null,
|
||||
// tslint:disable-next-line:no-any
|
||||
): Promise<any> {
|
||||
const { region } = (await this.getCredentials(
|
||||
'googleFirebaseRealtimeDatabaseOAuth2Api',
|
||||
)) as IDataObject;
|
||||
|
||||
const options: OptionsWithUrl = {
|
||||
headers: {
|
||||
@@ -35,28 +39,47 @@ export async function googleApiRequest(this: IExecuteFunctions | IExecuteSingleF
|
||||
delete options.body;
|
||||
}
|
||||
|
||||
return await this.helpers.requestOAuth2!.call(this, 'googleFirebaseRealtimeDatabaseOAuth2Api', options);
|
||||
return await this.helpers.requestOAuth2!.call(
|
||||
this,
|
||||
'googleFirebaseRealtimeDatabaseOAuth2Api',
|
||||
options,
|
||||
);
|
||||
} catch (error) {
|
||||
throw new NodeApiError(this.getNode(), error as JsonObject);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
export async function googleApiRequestAllItems(this: IExecuteFunctions | IExecuteSingleFunctions | ILoadOptionsFunctions, projectId: string, method: string, resource: string, body: any = {}, qs: IDataObject = {}, headers: IDataObject = {}, uri: string | null = null): Promise<any> { // tslint:disable-line:no-any
|
||||
|
||||
export async function googleApiRequestAllItems(
|
||||
this: IExecuteFunctions | IExecuteSingleFunctions | ILoadOptionsFunctions,
|
||||
projectId: string,
|
||||
method: string,
|
||||
resource: string,
|
||||
// tslint:disable-next-line:no-any
|
||||
body: any = {},
|
||||
qs: IDataObject = {},
|
||||
headers: IDataObject = {},
|
||||
uri: string | null = null,
|
||||
// tslint:disable-next-line:no-any
|
||||
): Promise<any> {
|
||||
const returnData: IDataObject[] = [];
|
||||
|
||||
let responseData;
|
||||
qs.pageSize = 100;
|
||||
|
||||
do {
|
||||
responseData = await googleApiRequest.call(this, projectId, method, resource, body, qs, {}, uri);
|
||||
responseData = await googleApiRequest.call(
|
||||
this,
|
||||
projectId,
|
||||
method,
|
||||
resource,
|
||||
body,
|
||||
qs,
|
||||
{},
|
||||
uri,
|
||||
);
|
||||
qs.pageToken = responseData['nextPageToken'];
|
||||
returnData.push.apply(returnData, responseData[resource]);
|
||||
} while (
|
||||
responseData['nextPageToken'] !== undefined &&
|
||||
responseData['nextPageToken'] !== ''
|
||||
);
|
||||
} while (responseData['nextPageToken'] !== undefined && responseData['nextPageToken'] !== '');
|
||||
|
||||
return returnData;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
import {
|
||||
IExecuteFunctions,
|
||||
} from 'n8n-core';
|
||||
import { IExecuteFunctions } from 'n8n-core';
|
||||
|
||||
import {
|
||||
IDataObject,
|
||||
@@ -14,10 +12,7 @@ import {
|
||||
NodeOperationError,
|
||||
} from 'n8n-workflow';
|
||||
|
||||
import {
|
||||
googleApiRequest,
|
||||
googleApiRequestAllItems,
|
||||
} from './GenericFunctions';
|
||||
import { googleApiRequest, googleApiRequestAllItems } from './GenericFunctions';
|
||||
|
||||
export class GoogleFirebaseRealtimeDatabase implements INodeType {
|
||||
description: INodeTypeDescription = {
|
||||
@@ -47,7 +42,8 @@ export class GoogleFirebaseRealtimeDatabase implements INodeType {
|
||||
typeOptions: {
|
||||
loadOptionsMethod: 'getProjects',
|
||||
},
|
||||
description: 'As displayed in firebase console URL. Choose from the list, or specify an ID using an <a href="https://docs.n8n.io/code-examples/expressions/">expression</a>.',
|
||||
description:
|
||||
'As displayed in firebase console URL. Choose from the list, or specify an ID using an <a href="https://docs.n8n.io/code-examples/expressions/">expression</a>.',
|
||||
required: true,
|
||||
},
|
||||
{
|
||||
@@ -101,7 +97,7 @@ export class GoogleFirebaseRealtimeDatabase implements INodeType {
|
||||
required: true,
|
||||
displayOptions: {
|
||||
hide: {
|
||||
'operation': [ 'get' ],
|
||||
operation: ['get'],
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -116,7 +112,7 @@ export class GoogleFirebaseRealtimeDatabase implements INodeType {
|
||||
hint: 'Leave blank to get a whole database object',
|
||||
displayOptions: {
|
||||
show: {
|
||||
'operation': [ 'get' ],
|
||||
operation: ['get'],
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -127,11 +123,7 @@ export class GoogleFirebaseRealtimeDatabase implements INodeType {
|
||||
default: '',
|
||||
displayOptions: {
|
||||
show: {
|
||||
operation: [
|
||||
'create',
|
||||
'push',
|
||||
'update',
|
||||
],
|
||||
operation: ['create', 'push', 'update'],
|
||||
},
|
||||
},
|
||||
description: 'Attributes to save',
|
||||
@@ -143,9 +135,7 @@ export class GoogleFirebaseRealtimeDatabase implements INodeType {
|
||||
|
||||
methods = {
|
||||
loadOptions: {
|
||||
async getProjects(
|
||||
this: ILoadOptionsFunctions,
|
||||
): Promise<INodePropertyOptions[]> {
|
||||
async getProjects(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> {
|
||||
const projects = await googleApiRequestAllItems.call(
|
||||
this,
|
||||
'',
|
||||
@@ -158,14 +148,14 @@ export class GoogleFirebaseRealtimeDatabase implements INodeType {
|
||||
);
|
||||
|
||||
const returnData = projects
|
||||
// select only realtime database projects
|
||||
.filter((project: IDataObject) => (project.resources as IDataObject).realtimeDatabaseInstance )
|
||||
.map((project: IDataObject) => (
|
||||
{
|
||||
name: project.projectId,
|
||||
value: (project.resources as IDataObject).realtimeDatabaseInstance,
|
||||
}
|
||||
)) as INodePropertyOptions[];
|
||||
// select only realtime database projects
|
||||
.filter(
|
||||
(project: IDataObject) => (project.resources as IDataObject).realtimeDatabaseInstance,
|
||||
)
|
||||
.map((project: IDataObject) => ({
|
||||
name: project.projectId,
|
||||
value: (project.resources as IDataObject).realtimeDatabaseInstance,
|
||||
})) as INodePropertyOptions[];
|
||||
|
||||
return returnData;
|
||||
},
|
||||
@@ -180,8 +170,11 @@ export class GoogleFirebaseRealtimeDatabase implements INodeType {
|
||||
const operation = this.getNodeParameter('operation', 0) as string;
|
||||
//https://firebase.google.com/docs/reference/rest/database
|
||||
|
||||
|
||||
if (['push', 'create', 'update'].includes(operation) && items.length === 1 && Object.keys(items[0].json).length === 0) {
|
||||
if (
|
||||
['push', 'create', 'update'].includes(operation) &&
|
||||
items.length === 1 &&
|
||||
Object.keys(items[0].json).length === 0
|
||||
) {
|
||||
throw new NodeOperationError(this.getNode(), `The ${operation} operation needs input data`);
|
||||
}
|
||||
|
||||
@@ -189,7 +182,8 @@ export class GoogleFirebaseRealtimeDatabase implements INodeType {
|
||||
try {
|
||||
const projectId = this.getNodeParameter('projectId', i) as string;
|
||||
|
||||
let method = 'GET', attributes = '';
|
||||
let method = 'GET',
|
||||
attributes = '';
|
||||
const document: IDataObject = {};
|
||||
if (operation === 'create') {
|
||||
method = 'PUT';
|
||||
@@ -207,7 +201,7 @@ export class GoogleFirebaseRealtimeDatabase implements INodeType {
|
||||
}
|
||||
|
||||
if (attributes) {
|
||||
const attributeList = attributes.split(',').map(el => el.trim());
|
||||
const attributeList = attributes.split(',').map((el) => el.trim());
|
||||
attributeList.map((attribute: string) => {
|
||||
if (items[i].json.hasOwnProperty(attribute)) {
|
||||
document[attribute] = items[i].json[attribute];
|
||||
@@ -225,7 +219,9 @@ export class GoogleFirebaseRealtimeDatabase implements INodeType {
|
||||
|
||||
if (responseData === null) {
|
||||
if (operation === 'get') {
|
||||
throw new NodeApiError(this.getNode(), responseData, { message: `Requested entity was not found.` });
|
||||
throw new NodeApiError(this.getNode(), responseData, {
|
||||
message: `Requested entity was not found.`,
|
||||
});
|
||||
} else if (method === 'DELETE') {
|
||||
responseData = { success: true };
|
||||
}
|
||||
@@ -240,7 +236,9 @@ export class GoogleFirebaseRealtimeDatabase implements INodeType {
|
||||
if (Array.isArray(responseData)) {
|
||||
returnData.push.apply(returnData, responseData as IDataObject[]);
|
||||
} else if (typeof responseData === 'string' || typeof responseData === 'number') {
|
||||
returnData.push({ [this.getNodeParameter('path', i) as string]: responseData } as IDataObject);
|
||||
returnData.push({
|
||||
[this.getNodeParameter('path', i) as string]: responseData,
|
||||
} as IDataObject);
|
||||
} else {
|
||||
returnData.push(responseData as IDataObject);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user