diff --git a/.yarn/cache/follow-redirects-npm-1.15.2-1ec1dd82be-faa66059b6.zip b/.yarn/cache/follow-redirects-npm-1.15.2-1ec1dd82be-faa66059b6.zip
deleted file mode 100644
index b50d775..0000000
Binary files a/.yarn/cache/follow-redirects-npm-1.15.2-1ec1dd82be-faa66059b6.zip and /dev/null differ
diff --git a/.yarn/cache/follow-redirects-npm-1.15.3-ca69c47b72-584da22ec5.zip b/.yarn/cache/follow-redirects-npm-1.15.3-ca69c47b72-584da22ec5.zip
new file mode 100644
index 0000000..7dbb7d2
Binary files /dev/null and b/.yarn/cache/follow-redirects-npm-1.15.3-ca69c47b72-584da22ec5.zip differ
diff --git a/.yarn/cache/graceful-fs-npm-4.2.10-79c70989ca-3f109d70ae.zip b/.yarn/cache/graceful-fs-npm-4.2.11-24bb648a68-ac85f94da9.zip
similarity index 65%
rename from .yarn/cache/graceful-fs-npm-4.2.10-79c70989ca-3f109d70ae.zip
rename to .yarn/cache/graceful-fs-npm-4.2.11-24bb648a68-ac85f94da9.zip
index 2d04255..99f412b 100644
Binary files a/.yarn/cache/graceful-fs-npm-4.2.10-79c70989ca-3f109d70ae.zip and b/.yarn/cache/graceful-fs-npm-4.2.11-24bb648a68-ac85f94da9.zip differ
diff --git a/.yarn/cache/mustache-npm-4.2.0-1fe3d6d77a-928fcb63e3.zip b/.yarn/cache/mustache-npm-4.2.0-1fe3d6d77a-928fcb63e3.zip
new file mode 100644
index 0000000..ecb3972
Binary files /dev/null and b/.yarn/cache/mustache-npm-4.2.0-1fe3d6d77a-928fcb63e3.zip differ
diff --git a/node-red-grist/records.html b/node-red-grist/records.html
index 7c982e9..6c5ebe4 100644
--- a/node-red-grist/records.html
+++ b/node-red-grist/records.html
@@ -1,28 +1,29 @@
\ No newline at end of file
diff --git a/node-red-grist/records.js b/node-red-grist/records.js
index 57a8132..5a7b4aa 100644
--- a/node-red-grist/records.js
+++ b/node-red-grist/records.js
@@ -1,24 +1,25 @@
-const {GristDocAPI} = require('grist-api');
-
-module.exports = function(RED) {
+const { GristDocAPI } = require('grist-api');
+const mustache = require('mustache');
+module.exports = function (RED) {
function RecordsNode(config) {
- RED.nodes.createNode(this,config);
+ RED.nodes.createNode(this, config);
let node = this;
this.document = RED.nodes.getNode(config.document);
this.server = RED.nodes.getNode(config.server);
this.table = config.tableId
this.filter = config.filter
-
- node.on('input', async function(msg, send, done) {
- const protocol=this.server.tlsEnabled === true ? "https" : "http";
- const url=protocol+"://"+this.server.hostname+":"+this.server.port;
- const filter=this.filter && this.filter !== "" ? JSON.parse(this.filter) : undefined
- const api = new GristDocAPI(this.document.docid,{apiKey:this.server.apiKey,server:url});
- api.fetchTable(this.table,filter).then(data => {
- node.send({payload:data,topic:this.table})
- }).catch(reason => done(reason,"Failed to perform grist request to "+url));
-
+
+ node.on('input', async function (msg, send, done) {
+ const protocol = this.server.tlsEnabled === true ? "https" : "http";
+ const url = protocol + "://" + this.server.hostname + ":" + this.server.port;
+ const filter = this.filter && this.filter !== "" ? JSON.parse(mustache.render(this.filter, { msg })) : undefined
+ node.log(`filter evaluated to: ${JSON.stringify(filter)}`)
+ const api = new GristDocAPI(this.document.docid, { apiKey: this.server.apiKey, server: url });
+ api.fetchTable(this.table, filter).then(data => {
+ node.send({ payload: data, topic: this.table })
+ }).catch(reason => done(reason, "Failed to perform grist request to " + url));
+
});
}
- RED.nodes.registerType("grist-records",RecordsNode);
+ RED.nodes.registerType("grist-records", RecordsNode);
}
\ No newline at end of file
diff --git a/package.json b/package.json
index e5e29cd..63967f1 100644
--- a/package.json
+++ b/package.json
@@ -28,6 +28,7 @@
"node": ">=14.0.0"
},
"dependencies": {
- "grist-api": "^0.1.7"
+ "grist-api": "^0.1.7",
+ "mustache": "^4.2.0"
}
}
diff --git a/yarn.lock b/yarn.lock
index 1431f3b..f92b349 100644
--- a/yarn.lock
+++ b/yarn.lock
@@ -10,6 +10,7 @@ __metadata:
resolution: "@gorootde/node-red-grist@workspace:."
dependencies:
grist-api: ^0.1.7
+ mustache: ^4.2.0
languageName: unknown
linkType: soft
@@ -35,12 +36,12 @@ __metadata:
linkType: hard
"follow-redirects@npm:^1.14.0":
- version: 1.15.2
- resolution: "follow-redirects@npm:1.15.2"
+ version: 1.15.3
+ resolution: "follow-redirects@npm:1.15.3"
peerDependenciesMeta:
debug:
optional: true
- checksum: faa66059b66358ba65c234c2f2a37fcec029dc22775f35d9ad6abac56003268baf41e55f9ee645957b32c7d9f62baf1f0b906e68267276f54ec4b4c597c2b190
+ checksum: 584da22ec5420c837bd096559ebfb8fe69d82512d5585004e36a3b4a6ef6d5905780e0c74508c7b72f907d1fa2b7bd339e613859e9c304d0dc96af2027fd0231
languageName: node
linkType: hard
@@ -56,9 +57,9 @@ __metadata:
linkType: hard
"graceful-fs@npm:^4.1.6, graceful-fs@npm:^4.2.0":
- version: 4.2.10
- resolution: "graceful-fs@npm:4.2.10"
- checksum: 3f109d70ae123951905d85032ebeae3c2a5a7a997430df00ea30df0e3a6c60cf6689b109654d6fdacd28810a053348c4d14642da1d075049e6be1ba5216218da
+ version: 4.2.11
+ resolution: "graceful-fs@npm:4.2.11"
+ checksum: ac85f94da92d8eb6b7f5a8b20ce65e43d66761c55ce85ac96df6865308390da45a8d3f0296dd3a663de65d30ba497bd46c696cc1e248c72b13d6d567138a4fc7
languageName: node
linkType: hard
@@ -100,6 +101,15 @@ __metadata:
languageName: node
linkType: hard
+"mustache@npm:^4.2.0":
+ version: 4.2.0
+ resolution: "mustache@npm:4.2.0"
+ bin:
+ mustache: bin/mustache
+ checksum: 928fcb63e3aa44a562bfe9b59ba202cccbe40a46da50be6f0dd831b495be1dd7e38ca4657f0ecab2c1a89dc7bccba0885eab7ee7c1b215830da765758c7e0506
+ languageName: node
+ linkType: hard
+
"universalify@npm:^0.1.0":
version: 0.1.2
resolution: "universalify@npm:0.1.2"