diff --git a/build/nodes/locales/en-US/firestore-get.html b/build/nodes/locales/en-US/firestore-get.html index cbfd855..ae45c21 100644 --- a/build/nodes/locales/en-US/firestore-get.html +++ b/build/nodes/locales/en-US/firestore-get.html @@ -64,25 +64,25 @@

Details

  • limitToFirstnumber
  • limitToLastnumber
  • offsetnumber
  • -
  • orderByobject
  • +
  • orderByarray
  • selectstring | string array
  • startAftervarious
  • startAtvarious
  • -
  • whereobject
  • +
  • wherearray
  • The msg.constraints will look like this:

     {
       "limitToFirst": 5,
    -  "orderBy": {
    +  "orderBy": [{
         "fieldPath": "some-path",
         "direction": "asc"
    -  },
    -  "where": {
    +  }],
    +  "where": [{
         "fieldPath": "some-path",
         "filter": ">",
         "value": 1
    -  }
    +  }]
     }

    Click here diff --git a/build/nodes/locales/en-US/firestore-in.html b/build/nodes/locales/en-US/firestore-in.html index bafa285..2ee8463 100644 --- a/build/nodes/locales/en-US/firestore-in.html +++ b/build/nodes/locales/en-US/firestore-in.html @@ -68,25 +68,25 @@

    Details

  • limitToFirstnumber
  • limitToLastnumber
  • offsetnumber
  • -
  • orderByobject
  • +
  • orderByarray
  • selectstring | string array
  • startAftervarious
  • startAtvarious
  • -
  • whereobject
  • +
  • wherearray
  • The msg.constraints will look like this:

     {
       "limitToFirst": 5,
    -  "orderBy": {
    +  "orderBy": [{
         "fieldPath": "some-path",
         "direction": "asc"
    -  },
    -  "where": {
    +  }],
    +  "where": [{
         "fieldPath": "some-path",
         "filter": ">",
         "value": 1
    -  }
    +  }]
     }

    Click here diff --git a/build/nodes/locales/fr/firestore-get.html b/build/nodes/locales/fr/firestore-get.html index e9aad4d..6a7f03b 100644 --- a/build/nodes/locales/fr/firestore-get.html +++ b/build/nodes/locales/fr/firestore-get.html @@ -61,25 +61,25 @@

    Détails

  • limitToFirstnombre
  • limitToLastnombre
  • offsetnombre
  • -
  • orderByobjet
  • +
  • orderBytableau
  • selectchaîne | tableau de chaînes
  • startAfterdivers
  • startAtdivers
  • -
  • whereobjet
  • +
  • wheretableau
  • Le msg.constraints ressemblera à ceci :

     {
       "limitToFirst": 5,
    -  "orderBy": {
    +  "orderBy": [{
         "fieldPath": "some-path",
         "direction": "asc"
    -  },
    -  "where": {
    +  }],
    +  "where": [{
         "fieldPath": "some-path",
         "filter": ">",
         "value": 1
    -  }
    +  }]
     }

    Cliquer ici diff --git a/build/nodes/locales/fr/firestore-in.html b/build/nodes/locales/fr/firestore-in.html index 28768bd..983329e 100644 --- a/build/nodes/locales/fr/firestore-in.html +++ b/build/nodes/locales/fr/firestore-in.html @@ -65,25 +65,25 @@

    Détails

  • limitToFirstnombre
  • limitToLastnombre
  • offsetnombre
  • -
  • orderByobjet
  • +
  • orderBytableau
  • selectchaîne | tableau de chaînes
  • startAfterdivers
  • startAtdivers
  • -
  • whereobjet
  • +
  • wheretableau
  • Le msg.constraints ressemblera à ceci :

     {
       "limitToFirst": 5,
    -  "orderBy": {
    +  "orderBy": [{
         "fieldPath": "some-path",
         "direction": "asc"
    -  },
    -  "where": {
    +  }],
    +  "where": [{
         "fieldPath": "some-path",
         "filter": ">",
         "value": 1
    -  }
    +  }]
     }

    Cliquer ici diff --git a/package-lock.json b/package-lock.json index 8434b9d..52f776d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,7 +9,7 @@ "version": "0.0.1", "license": "MIT", "dependencies": { - "@gogovega/firebase-config-node": "^0.1.0" + "@gogovega/firebase-config-node": "^0.1.1" }, "devDependencies": { "@types/node-red": "^1.3.5", @@ -162,9 +162,9 @@ "license": "MIT" }, "node_modules/@firebase/app": { - "version": "0.10.8", - "resolved": "https://registry.npmjs.org/@firebase/app/-/app-0.10.8.tgz", - "integrity": "sha512-xSLmW0/RShcnUEXH7l+wC0AFWaUtty4tUFF2loIgbtXTRmra0UH/SqYDf/IcfreUninRrCsusNmvoTidGkXJPw==", + "version": "0.10.9", + "resolved": "https://registry.npmjs.org/@firebase/app/-/app-0.10.9.tgz", + "integrity": "sha512-AmGlPg/4SoDhwCdvVDeZsN5Yn+czYD/m/NAEOOCOhwn3Cz1xmEFKAKcyZKKahLrh5QPmge5Adyw+sk3cBTubBg==", "license": "Apache-2.0", "dependencies": { "@firebase/component": "0.6.8", @@ -187,9 +187,9 @@ "license": "Apache-2.0" }, "node_modules/@firebase/auth": { - "version": "1.7.6", - "resolved": "https://registry.npmjs.org/@firebase/auth/-/auth-1.7.6.tgz", - "integrity": "sha512-T+lA5xoug9CByGYkD5WkfTh2ujEYq/frGZPbk0H+fNU6fNl7nqg88KcsmzsC6Fsqbjm3LLEb/i6wJvF6NSNEig==", + "version": "1.7.7", + "resolved": "https://registry.npmjs.org/@firebase/auth/-/auth-1.7.7.tgz", + "integrity": "sha512-gMB0uRRNiIvYorEDLtIq1mc7x5D080EsoghTIph9xnbLqcQS3qRBREEC2o21nMEhviAeiGJMelRkKhAkkggjmA==", "license": "Apache-2.0", "dependencies": { "@firebase/component": "0.6.8", @@ -264,9 +264,9 @@ } }, "node_modules/@firebase/firestore": { - "version": "4.6.5", - "resolved": "https://registry.npmjs.org/@firebase/firestore/-/firestore-4.6.5.tgz", - "integrity": "sha512-0+Ascaht4qUzj4pCopMPWmoAujk8HKjwCpaNYOOjbYMZ65RVfZPsfZwwbWi/zWMXj6xvPsai5oBiErUUkrLwNw==", + "version": "4.7.0", + "resolved": "https://registry.npmjs.org/@firebase/firestore/-/firestore-4.7.0.tgz", + "integrity": "sha512-wGOp84P1qa1pfpdct6lckfyowTuvIlUDHoiRcN8dFDT4WnZDh0tZW1X77SMiBUVejK8xIRLBCK3yDTejlRVrUA==", "license": "Apache-2.0", "dependencies": { "@firebase/component": "0.6.8", @@ -310,15 +310,15 @@ "license": "Apache-2.0" }, "node_modules/@gogovega/firebase-config-node": { - "version": "0.1.0", - "resolved": "https://registry.npmjs.org/@gogovega/firebase-config-node/-/firebase-config-node-0.1.0.tgz", - "integrity": "sha512-en+5IqmQrEvwX7f80EDX63vWEpalEcO3RNJnPqiindnlrVqpDGBGO4Zp9uH0liXh9BbIr3ui3YoWEjkcGpPbJA==", + "version": "0.1.1", + "resolved": "https://registry.npmjs.org/@gogovega/firebase-config-node/-/firebase-config-node-0.1.1.tgz", + "integrity": "sha512-bTLi7Wpy1lguZEMxAOdWwBh1Mbsb5NYyb6vgIXenadJMQoMP0saaBjuyHi1A+ZZvCfPtjvRurB78dr/1CLPNkg==", "license": "MIT", "dependencies": { - "@firebase/app": "0.10.8", - "@firebase/auth": "1.7.6", + "@firebase/app": "0.10.9", + "@firebase/auth": "1.7.7", "@firebase/database": "1.0.7", - "@firebase/firestore": "4.6.5", + "@firebase/firestore": "4.7.0", "firebase-admin": "^12.3.1", "tiny-typed-emitter": "^2.1.0" }, @@ -7256,9 +7256,9 @@ "integrity": "sha512-83rnH2nCvclWaPQQKvkJ2pdOjG4TZyEVuFDnlOF6KP08lDaaceVyw/W63mDuafQT+MKHCvXIPpE5uYWeM0rT4w==" }, "@firebase/app": { - "version": "0.10.8", - "resolved": "https://registry.npmjs.org/@firebase/app/-/app-0.10.8.tgz", - "integrity": "sha512-xSLmW0/RShcnUEXH7l+wC0AFWaUtty4tUFF2loIgbtXTRmra0UH/SqYDf/IcfreUninRrCsusNmvoTidGkXJPw==", + "version": "0.10.9", + "resolved": "https://registry.npmjs.org/@firebase/app/-/app-0.10.9.tgz", + "integrity": "sha512-AmGlPg/4SoDhwCdvVDeZsN5Yn+czYD/m/NAEOOCOhwn3Cz1xmEFKAKcyZKKahLrh5QPmge5Adyw+sk3cBTubBg==", "requires": { "@firebase/component": "0.6.8", "@firebase/logger": "0.4.2", @@ -7278,9 +7278,9 @@ "integrity": "sha512-oMEZ1TDlBz479lmABwWsWjzHwheQKiAgnuKxE0pz0IXCVx7/rtlkx1fQ6GfgK24WCrxDKMplZrT50Kh04iMbXQ==" }, "@firebase/auth": { - "version": "1.7.6", - "resolved": "https://registry.npmjs.org/@firebase/auth/-/auth-1.7.6.tgz", - "integrity": "sha512-T+lA5xoug9CByGYkD5WkfTh2ujEYq/frGZPbk0H+fNU6fNl7nqg88KcsmzsC6Fsqbjm3LLEb/i6wJvF6NSNEig==", + "version": "1.7.7", + "resolved": "https://registry.npmjs.org/@firebase/auth/-/auth-1.7.7.tgz", + "integrity": "sha512-gMB0uRRNiIvYorEDLtIq1mc7x5D080EsoghTIph9xnbLqcQS3qRBREEC2o21nMEhviAeiGJMelRkKhAkkggjmA==", "requires": { "@firebase/component": "0.6.8", "@firebase/logger": "0.4.2", @@ -7340,9 +7340,9 @@ } }, "@firebase/firestore": { - "version": "4.6.5", - "resolved": "https://registry.npmjs.org/@firebase/firestore/-/firestore-4.6.5.tgz", - "integrity": "sha512-0+Ascaht4qUzj4pCopMPWmoAujk8HKjwCpaNYOOjbYMZ65RVfZPsfZwwbWi/zWMXj6xvPsai5oBiErUUkrLwNw==", + "version": "4.7.0", + "resolved": "https://registry.npmjs.org/@firebase/firestore/-/firestore-4.7.0.tgz", + "integrity": "sha512-wGOp84P1qa1pfpdct6lckfyowTuvIlUDHoiRcN8dFDT4WnZDh0tZW1X77SMiBUVejK8xIRLBCK3yDTejlRVrUA==", "requires": { "@firebase/component": "0.6.8", "@firebase/logger": "0.4.2", @@ -7376,14 +7376,14 @@ "integrity": "sha512-jmEnr/pk0yVkA7mIlHNnxCi+wWzOFUg0WyIotgkKAb2u1J7fAeDBcVNSTjTihbAYNusCLQdW5s9IJ5qwnEufcQ==" }, "@gogovega/firebase-config-node": { - "version": "0.1.0", - "resolved": "https://registry.npmjs.org/@gogovega/firebase-config-node/-/firebase-config-node-0.1.0.tgz", - "integrity": "sha512-en+5IqmQrEvwX7f80EDX63vWEpalEcO3RNJnPqiindnlrVqpDGBGO4Zp9uH0liXh9BbIr3ui3YoWEjkcGpPbJA==", + "version": "0.1.1", + "resolved": "https://registry.npmjs.org/@gogovega/firebase-config-node/-/firebase-config-node-0.1.1.tgz", + "integrity": "sha512-bTLi7Wpy1lguZEMxAOdWwBh1Mbsb5NYyb6vgIXenadJMQoMP0saaBjuyHi1A+ZZvCfPtjvRurB78dr/1CLPNkg==", "requires": { - "@firebase/app": "0.10.8", - "@firebase/auth": "1.7.6", + "@firebase/app": "0.10.9", + "@firebase/auth": "1.7.7", "@firebase/database": "1.0.7", - "@firebase/firestore": "4.6.5", + "@firebase/firestore": "4.7.0", "firebase-admin": "^12.3.1", "tiny-typed-emitter": "^2.1.0" } diff --git a/package.json b/package.json index 99bf64c..291ed79 100644 --- a/package.json +++ b/package.json @@ -41,7 +41,7 @@ "version": ">=3" }, "dependencies": { - "@gogovega/firebase-config-node": "^0.1.0" + "@gogovega/firebase-config-node": "^0.1.1" }, "devDependencies": { "@types/node-red": "^1.3.5", diff --git a/resources/constraints.js b/resources/constraints.js index a7f96ac..a736617 100644 --- a/resources/constraints.js +++ b/resources/constraints.js @@ -91,7 +91,18 @@ var FirestoreQueryConstraintsContainer = FirestoreQueryConstraintsContainer || ( #constraintsHandler() { if (this.useConstraints?.prop("checked") === true) { - const constraints = Object.entries(this.node.constraints || {}); + const constraints = Object.entries(this.node.constraints || {}).reduce((array, [type, value]) => { + // For `orderBy` or `where` + if (Array.isArray(value)) { + value.forEach((val) => { + array.push([type, val]); + }); + } else { + array.push([type, value]); + } + + return array; + }, []); if (!constraints.length) constraints.push(["limitToLast", { value: "5", valueType: "num" }]); @@ -163,7 +174,8 @@ var FirestoreQueryConstraintsContainer = FirestoreQueryConstraintsContainer || ( case "orderBy": if (pathType === "str" && validators.path()(path) !== true) RED.notify("Query Constraints: Setted value is not a valid path!", "error"); - node.constraints[constraintType] = { path: path, pathType: pathType, direction: options }; + node.constraints[constraintType] ||= []; + node.constraints[constraintType].push({ path: path, pathType: pathType, direction: options }); break; case "select": { const result = isSelectValueValid(value, {}); @@ -178,7 +190,8 @@ var FirestoreQueryConstraintsContainer = FirestoreQueryConstraintsContainer || ( case "where": if (pathType === "str" && validators.path()(path) !== true) RED.notify("Query Constraints: Setted value is not a valid path!", "error"); - node.constraints[constraintType] = { path: path, pathType: pathType, value: value, valueType: valueType, filter: options }; + node.constraints[constraintType] ||= []; + node.constraints[constraintType].push({ path: path, pathType: pathType, value: value, valueType: valueType, filter: options }); break; } }); diff --git a/src/lib/firestore-node.ts b/src/lib/firestore-node.ts index b7f6eda..523295f 100644 --- a/src/lib/firestore-node.ts +++ b/src/lib/firestore-node.ts @@ -261,17 +261,28 @@ class Firestore = ["flow", "global", "jsonata", "env", "msg", "str"]; - if (!typesAllowed.includes(value.pathType)) - throw new Error(`Invalid type (${value.pathType}) for the ${key} field. Please reconfigure this node.`); + const typesAllowed = ["flow", "global", "jsonata", "env", "msg", "str"]; + let valArray = value; - constraints[key] = { - fieldPath: await this.evaluateNodeProperty(value.path, value.pathType, this.node, msg), - direction: value.direction, - }; + // Ensure it's an array - v < 0.0.2 + if (!Array.isArray(value)) { + valArray = [value]; + } + + for (const [index, val] of valArray.entries()) { + if (!typesAllowed.includes(val.pathType)) + throw new Error(`Invalid type (${val.pathType}) for the ${key} field. Please reconfigure this node.`); + + constraints[key] ||= []; + constraints[key][index] = { + fieldPath: await this.evaluateNodeProperty(val.path, val.pathType, this.node, msg), + direction: val.direction, + }; + + if (typeof constraints[key][index].fieldPath !== "string") + throw new TypeError("The OrderBy fieldPath value of Query Constraints must be a string."); + } - if (typeof constraints[key].fieldPath !== "string") - throw new TypeError("The OrderBy fieldPath value of Query Constraints must be a string."); break; } case "select": { @@ -296,7 +307,7 @@ class Firestore = [ + const valueTypesAllowed = [ "bool", "date", "env", @@ -309,20 +320,31 @@ class Firestore = ["flow", "global", "jsonata", "env", "msg", "str"]; - if (!valueTypesAllowed.includes(value.valueType)) - throw new Error(`Invalid type (${value.valueType}) for the ${key} field. Please reconfigure this node.`); - if (!pathTypesAllowed.includes(value.pathType)) - throw new Error(`Invalid type (${value.pathType}) for the ${key} field. Please reconfigure this node.`); + const pathTypesAllowed = ["flow", "global", "jsonata", "env", "msg", "str"]; + let valArray = value; + + // Ensure it's an array - v < 0.0.2 + if (!Array.isArray(value)) { + valArray = [value]; + } - constraints[key] = { - fieldPath: await this.evaluateNodeProperty(value.path, value.pathType, this.node, msg), - filter: value.filter, - value: await this.evaluateNodeProperty(value.value, value.valueType, this.node, msg), - }; + for (const [index, val] of valArray.entries()) { + if (!valueTypesAllowed.includes(val.valueType)) + throw new Error(`Invalid type (${val.valueType}) for the ${key} field. Please reconfigure this node.`); + if (!pathTypesAllowed.includes(val.pathType)) + throw new Error(`Invalid type (${val.pathType}) for the ${key} field. Please reconfigure this node.`); + + constraints[key] ||= []; + constraints[key][index] = { + fieldPath: await this.evaluateNodeProperty(val.path, val.pathType, this.node, msg), + filter: val.filter, + value: await this.evaluateNodeProperty(val.value, val.valueType, this.node, msg), + }; + + if (typeof constraints[key][index].fieldPath !== "string") + throw new TypeError("The Where fieldPath value of Query Constraints must be a string."); + } - if (typeof constraints[key].fieldPath !== "string") - throw new TypeError("The Where fieldPath value of Query Constraints must be a string."); break; } } diff --git a/src/lib/types/firestore-config.ts b/src/lib/types/firestore-config.ts index c6d783a..dee039d 100644 --- a/src/lib/types/firestore-config.ts +++ b/src/lib/types/firestore-config.ts @@ -85,12 +85,12 @@ interface Constraint { endBefore?: FieldValues; limitToFirst?: Limit; limitToLast?: Limit; - orderBy?: OrderBy; + orderBy?: Array; offset?: Offset; select?: Select; startAfter?: FieldValues; startAt?: FieldValues; - where?: Where; + where?: Array; } export type DocumentChangeType = "added" | "removed" | "modified";