Added more nodes
This commit is contained in:
parent
a33c6da509
commit
1dc5e9fdb1
16 changed files with 228 additions and 10 deletions
BIN
.yarn/cache/data-uri-to-buffer-npm-4.0.1-5c66a78beb-0d0790b67f.zip
vendored
Normal file
BIN
.yarn/cache/data-uri-to-buffer-npm-4.0.1-5c66a78beb-0d0790b67f.zip
vendored
Normal file
Binary file not shown.
BIN
.yarn/cache/fetch-blob-npm-3.2.0-28e01becfc-f19bc28a2a.zip
vendored
Normal file
BIN
.yarn/cache/fetch-blob-npm-3.2.0-28e01becfc-f19bc28a2a.zip
vendored
Normal file
Binary file not shown.
BIN
.yarn/cache/formdata-polyfill-npm-4.0.10-e03013c013-82a34df292.zip
vendored
Normal file
BIN
.yarn/cache/formdata-polyfill-npm-4.0.10-e03013c013-82a34df292.zip
vendored
Normal file
Binary file not shown.
BIN
.yarn/cache/node-domexception-npm-1.0.0-e1e813b76f-ee1d37dd2a.zip
vendored
Normal file
BIN
.yarn/cache/node-domexception-npm-1.0.0-e1e813b76f-ee1d37dd2a.zip
vendored
Normal file
Binary file not shown.
BIN
.yarn/cache/node-fetch-npm-3.3.2-5267e015f2-06a04095a2.zip
vendored
Normal file
BIN
.yarn/cache/node-fetch-npm-3.3.2-5267e015f2-06a04095a2.zip
vendored
Normal file
Binary file not shown.
BIN
.yarn/cache/web-streams-polyfill-npm-3.2.1-835bd3857e-b119c78574.zip
vendored
Normal file
BIN
.yarn/cache/web-streams-polyfill-npm-3.2.1-835bd3857e-b119c78574.zip
vendored
Normal file
Binary file not shown.
Binary file not shown.
|
|
@ -5,6 +5,8 @@
|
||||||
**THIS IS A VERY EARLY DEVELOPMENT VERSION** USE AT YOUR OWN RISK
|
**THIS IS A VERY EARLY DEVELOPMENT VERSION** USE AT YOUR OWN RISK
|
||||||
|
|
||||||
### Included Nodes
|
### Included Nodes
|
||||||
- `records` - Read records of a table
|
- `get records` - Read records of a table
|
||||||
|
- `update records` - Update records of a table
|
||||||
|
- `add records` - Add records of a table
|
||||||
- `server` - Config node for a grist server instance
|
- `server` - Config node for a grist server instance
|
||||||
- `document` - Config node for a grist document
|
- `document` - Config node for a grist document
|
||||||
55
node-red-grist/add-records.html
Normal file
55
node-red-grist/add-records.html
Normal file
|
|
@ -0,0 +1,55 @@
|
||||||
|
<script type="text/javascript">
|
||||||
|
RED.nodes.registerType('grist-add-records', {
|
||||||
|
|
||||||
|
category: 'grist',
|
||||||
|
color: '#00bb00',
|
||||||
|
defaults: {
|
||||||
|
server: { value: "", type: "grist-server", required: true },
|
||||||
|
document: { value: "", type: "grist-document", required: true },
|
||||||
|
tableId: { value: "", required: true },
|
||||||
|
|
||||||
|
},
|
||||||
|
inputs: 1,
|
||||||
|
outputs: 1,
|
||||||
|
icon: "font-awesome/fa-table",
|
||||||
|
label: function () {
|
||||||
|
return this.tableId ? `[Add] ${this.tableId}` : "Add records";
|
||||||
|
},
|
||||||
|
paletteLabel: "Add records",
|
||||||
|
oneditprepare: function () {
|
||||||
|
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<script type="text/html" data-template-name="grist-add-records">
|
||||||
|
<div class="form-row">
|
||||||
|
<label for="node-input-document"><i class="fa fa-file-text"></i> Document</label>
|
||||||
|
<input type="text" id="node-input-document" placeholder="Document">
|
||||||
|
</div>
|
||||||
|
<div class="form-row">
|
||||||
|
<label for="node-input-server"><i class="fa fa-server"></i> Server</label>
|
||||||
|
<input type="text" id="node-input-server" placeholder="Server">
|
||||||
|
</div>
|
||||||
|
<div class="form-row">
|
||||||
|
<label for="node-input-tableId"><i class="fa fa-table"></i> Table Name</label>
|
||||||
|
<input type="text" id="node-input-tableId" placeholder="Table Name">
|
||||||
|
</div>
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<script type="text/html" data-help-name="grist-add-records">
|
||||||
|
<p>Adds records to a grist table.</p>
|
||||||
|
<h3>Inputs</h3>
|
||||||
|
<p>
|
||||||
|
<code>msg.payload</code> array of records (or a single record object) to add.
|
||||||
|
</p>
|
||||||
|
<h3>Outputs</h3>
|
||||||
|
<p>
|
||||||
|
Array of records that have been added
|
||||||
|
</p>
|
||||||
|
<h3>Attributes</h3>
|
||||||
|
<p>
|
||||||
|
|
||||||
|
</script>
|
||||||
24
node-red-grist/add-records.js
Normal file
24
node-red-grist/add-records.js
Normal file
|
|
@ -0,0 +1,24 @@
|
||||||
|
const { GristDocAPI } = require('grist-api');
|
||||||
|
const mustache = require('mustache');
|
||||||
|
module.exports = function (RED) {
|
||||||
|
function AddRecordsNode(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
|
||||||
|
|
||||||
|
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 api = new GristDocAPI(this.document.docid, { apiKey: this.server.apiKey, server: url });
|
||||||
|
const data = Array.isArray(msg.payload) ? msg.payload : [msg.payload]
|
||||||
|
|
||||||
|
api.addRecords(this.table, data).then(data => {
|
||||||
|
node.send({ payload: data, topic: this.table })
|
||||||
|
}).catch(reason => done(reason, "Failed to perform grist request to " + url));
|
||||||
|
|
||||||
|
});
|
||||||
|
}
|
||||||
|
RED.nodes.registerType("grist-add-records", AddRecordsNode);
|
||||||
|
}
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
RED.nodes.registerType('grist-records', {
|
RED.nodes.registerType('grist-get-records', {
|
||||||
name: "Get records",
|
name: "Get records",
|
||||||
category: 'grist',
|
category: 'grist',
|
||||||
color: '#00bb00',
|
color: '#00bb00',
|
||||||
|
|
@ -13,8 +13,10 @@
|
||||||
outputs: 1,
|
outputs: 1,
|
||||||
icon: "font-awesome/fa-table",
|
icon: "font-awesome/fa-table",
|
||||||
label: function () {
|
label: function () {
|
||||||
return this.tableId || "Get records";
|
return this.tableId ? `[Get] ${this.tableId}` : "Get records";
|
||||||
|
|
||||||
},
|
},
|
||||||
|
paletteLabel: "Get records",
|
||||||
oneditprepare: function () {
|
oneditprepare: function () {
|
||||||
$("#node-input-filter").typedInput({
|
$("#node-input-filter").typedInput({
|
||||||
type: "json",
|
type: "json",
|
||||||
|
|
@ -26,7 +28,7 @@
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<script type="text/html" data-template-name="grist-records">
|
<script type="text/html" data-template-name="grist-get-records">
|
||||||
<div class="form-row">
|
<div class="form-row">
|
||||||
<label for="node-input-document"><i class="fa fa-file-text"></i> Document</label>
|
<label for="node-input-document"><i class="fa fa-file-text"></i> Document</label>
|
||||||
<input type="text" id="node-input-document" placeholder="Document">
|
<input type="text" id="node-input-document" placeholder="Document">
|
||||||
|
|
@ -47,7 +49,7 @@
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<script type="text/html" data-help-name="grist-records">
|
<script type="text/html" data-help-name="grist-get-records">
|
||||||
<p>Retrieves records from a grist table.</p>
|
<p>Retrieves records from a grist table.</p>
|
||||||
<h3>Inputs</h3>
|
<h3>Inputs</h3>
|
||||||
<p>
|
<p>
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
const { GristDocAPI } = require('grist-api');
|
const { GristDocAPI } = require('grist-api');
|
||||||
const mustache = require('mustache');
|
const mustache = require('mustache');
|
||||||
module.exports = function (RED) {
|
module.exports = function (RED) {
|
||||||
function RecordsNode(config) {
|
function GetRecordsNode(config) {
|
||||||
RED.nodes.createNode(this, config);
|
RED.nodes.createNode(this, config);
|
||||||
let node = this;
|
let node = this;
|
||||||
this.document = RED.nodes.getNode(config.document);
|
this.document = RED.nodes.getNode(config.document);
|
||||||
|
|
@ -21,5 +21,5 @@ module.exports = function (RED) {
|
||||||
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
RED.nodes.registerType("grist-records", RecordsNode);
|
RED.nodes.registerType("grist-get-records", GetRecordsNode);
|
||||||
}
|
}
|
||||||
57
node-red-grist/update-records.html
Normal file
57
node-red-grist/update-records.html
Normal file
|
|
@ -0,0 +1,57 @@
|
||||||
|
<script type="text/javascript">
|
||||||
|
|
||||||
|
RED.nodes.registerType('grist-update-records', {
|
||||||
|
|
||||||
|
category: 'grist',
|
||||||
|
color: '#00bb00',
|
||||||
|
defaults: {
|
||||||
|
server: { value: "", type: "grist-server", required: true },
|
||||||
|
document: { value: "", type: "grist-document", required: true },
|
||||||
|
tableId: { value: "", required: true },
|
||||||
|
|
||||||
|
},
|
||||||
|
inputs: 1,
|
||||||
|
outputs: 1,
|
||||||
|
icon: "font-awesome/fa-table",
|
||||||
|
label: function () {
|
||||||
|
return this.tableId ? `[Update] ${this.tableId}` : "Update records";
|
||||||
|
},
|
||||||
|
paletteLabel: "Update records",
|
||||||
|
oneditprepare: async function () {
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<script type="text/html" data-template-name="grist-update-records">
|
||||||
|
<div class="form-row">
|
||||||
|
<label for="node-input-document"><i class="fa fa-file-text"></i> Document</label>
|
||||||
|
<input type="text" id="node-input-document" placeholder="Document">
|
||||||
|
</div>
|
||||||
|
<div class="form-row">
|
||||||
|
<label for="node-input-server"><i class="fa fa-server"></i> Server</label>
|
||||||
|
<input type="text" id="node-input-server" placeholder="Server">
|
||||||
|
</div>
|
||||||
|
<div class="form-row">
|
||||||
|
<label for="node-input-tableId"><i class="fa fa-table"></i> Table Name</label>
|
||||||
|
<input type="text" id="node-input-tableId" placeholder="Table Name">
|
||||||
|
</div>
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<script type="text/html" data-help-name="grist-update-records">
|
||||||
|
<p>Updates records in a grist table.</p>
|
||||||
|
<h3>Inputs</h3>
|
||||||
|
<p>
|
||||||
|
<code>msg.payload</code> array of records (or a single record object) to add. Each record must contain the ID.
|
||||||
|
</p>
|
||||||
|
<h3>Outputs</h3>
|
||||||
|
<p>
|
||||||
|
No data. Called as soon as update was performed.
|
||||||
|
</p>
|
||||||
|
<h3>Attributes</h3>
|
||||||
|
<p>
|
||||||
|
|
||||||
|
</script>
|
||||||
24
node-red-grist/update-records.js
Normal file
24
node-red-grist/update-records.js
Normal file
|
|
@ -0,0 +1,24 @@
|
||||||
|
const { GristDocAPI } = require('grist-api');
|
||||||
|
const mustache = require('mustache');
|
||||||
|
module.exports = function (RED) {
|
||||||
|
function UpdateRecordsNode(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
|
||||||
|
|
||||||
|
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 api = new GristDocAPI(this.document.docid, { apiKey: this.server.apiKey, server: url });
|
||||||
|
const data = Array.isArray(msg.payload) ? msg.payload : [msg.payload]
|
||||||
|
|
||||||
|
api.updateRecords(this.table, data).then(data => {
|
||||||
|
node.send({ payload: data, topic: this.table })
|
||||||
|
}).catch(reason => done(reason, "Failed to perform grist request to " + url));
|
||||||
|
|
||||||
|
});
|
||||||
|
}
|
||||||
|
RED.nodes.registerType("grist-update-records", UpdateRecordsNode);
|
||||||
|
}
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "@gorootde/node-red-grist",
|
"name": "@gorootde/node-red-grist",
|
||||||
"version": "1.1.0",
|
"version": "2.0.0",
|
||||||
"description": "getgrist.com connectivity for NodeRed",
|
"description": "getgrist.com connectivity for NodeRed",
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"packageManager": "yarn@3.3.1",
|
"packageManager": "yarn@3.3.1",
|
||||||
|
|
@ -19,7 +19,9 @@
|
||||||
"node-red": {
|
"node-red": {
|
||||||
"version": ">=2.0.0",
|
"version": ">=2.0.0",
|
||||||
"nodes": {
|
"nodes": {
|
||||||
"grist-records": "node-red-grist/records.js",
|
"grist-add-records": "node-red-grist/add-records.js",
|
||||||
|
"grist-get-records": "node-red-grist/get-records.js",
|
||||||
|
"grist-update-records": "node-red-grist/update-records.js",
|
||||||
"grist-document": "node-red-grist/document.js",
|
"grist-document": "node-red-grist/document.js",
|
||||||
"grist-server": "node-red-grist/server.js"
|
"grist-server": "node-red-grist/server.js"
|
||||||
}
|
}
|
||||||
|
|
@ -31,4 +33,4 @@
|
||||||
"grist-api": "^0.1.7",
|
"grist-api": "^0.1.7",
|
||||||
"mustache": "^4.2.0"
|
"mustache": "^4.2.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
52
yarn.lock
52
yarn.lock
|
|
@ -11,6 +11,7 @@ __metadata:
|
||||||
dependencies:
|
dependencies:
|
||||||
grist-api: ^0.1.7
|
grist-api: ^0.1.7
|
||||||
mustache: ^4.2.0
|
mustache: ^4.2.0
|
||||||
|
node-fetch: ^3.3.2
|
||||||
languageName: unknown
|
languageName: unknown
|
||||||
linkType: soft
|
linkType: soft
|
||||||
|
|
||||||
|
|
@ -23,6 +24,13 @@ __metadata:
|
||||||
languageName: node
|
languageName: node
|
||||||
linkType: hard
|
linkType: hard
|
||||||
|
|
||||||
|
"data-uri-to-buffer@npm:^4.0.0":
|
||||||
|
version: 4.0.1
|
||||||
|
resolution: "data-uri-to-buffer@npm:4.0.1"
|
||||||
|
checksum: 0d0790b67ffec5302f204c2ccca4494f70b4e2d940fea3d36b09f0bb2b8539c2e86690429eb1f1dc4bcc9e4df0644193073e63d9ee48ac9fce79ec1506e4aa4c
|
||||||
|
languageName: node
|
||||||
|
linkType: hard
|
||||||
|
|
||||||
"debug@npm:^4.1.1":
|
"debug@npm:^4.1.1":
|
||||||
version: 4.3.4
|
version: 4.3.4
|
||||||
resolution: "debug@npm:4.3.4"
|
resolution: "debug@npm:4.3.4"
|
||||||
|
|
@ -35,6 +43,16 @@ __metadata:
|
||||||
languageName: node
|
languageName: node
|
||||||
linkType: hard
|
linkType: hard
|
||||||
|
|
||||||
|
"fetch-blob@npm:^3.1.2, fetch-blob@npm:^3.1.4":
|
||||||
|
version: 3.2.0
|
||||||
|
resolution: "fetch-blob@npm:3.2.0"
|
||||||
|
dependencies:
|
||||||
|
node-domexception: ^1.0.0
|
||||||
|
web-streams-polyfill: ^3.0.3
|
||||||
|
checksum: f19bc28a2a0b9626e69fd7cf3a05798706db7f6c7548da657cbf5026a570945f5eeaedff52007ea35c8bcd3d237c58a20bf1543bc568ab2422411d762dd3d5bf
|
||||||
|
languageName: node
|
||||||
|
linkType: hard
|
||||||
|
|
||||||
"follow-redirects@npm:^1.14.0":
|
"follow-redirects@npm:^1.14.0":
|
||||||
version: 1.15.3
|
version: 1.15.3
|
||||||
resolution: "follow-redirects@npm:1.15.3"
|
resolution: "follow-redirects@npm:1.15.3"
|
||||||
|
|
@ -45,6 +63,15 @@ __metadata:
|
||||||
languageName: node
|
languageName: node
|
||||||
linkType: hard
|
linkType: hard
|
||||||
|
|
||||||
|
"formdata-polyfill@npm:^4.0.10":
|
||||||
|
version: 4.0.10
|
||||||
|
resolution: "formdata-polyfill@npm:4.0.10"
|
||||||
|
dependencies:
|
||||||
|
fetch-blob: ^3.1.2
|
||||||
|
checksum: 82a34df292afadd82b43d4a740ce387bc08541e0a534358425193017bf9fb3567875dc5f69564984b1da979979b70703aa73dee715a17b6c229752ae736dd9db
|
||||||
|
languageName: node
|
||||||
|
linkType: hard
|
||||||
|
|
||||||
"fs-extra@npm:^8.1.0":
|
"fs-extra@npm:^8.1.0":
|
||||||
version: 8.1.0
|
version: 8.1.0
|
||||||
resolution: "fs-extra@npm:8.1.0"
|
resolution: "fs-extra@npm:8.1.0"
|
||||||
|
|
@ -110,9 +137,34 @@ __metadata:
|
||||||
languageName: node
|
languageName: node
|
||||||
linkType: hard
|
linkType: hard
|
||||||
|
|
||||||
|
"node-domexception@npm:^1.0.0":
|
||||||
|
version: 1.0.0
|
||||||
|
resolution: "node-domexception@npm:1.0.0"
|
||||||
|
checksum: ee1d37dd2a4eb26a8a92cd6b64dfc29caec72bff5e1ed9aba80c294f57a31ba4895a60fd48347cf17dd6e766da0ae87d75657dfd1f384ebfa60462c2283f5c7f
|
||||||
|
languageName: node
|
||||||
|
linkType: hard
|
||||||
|
|
||||||
|
"node-fetch@npm:^3.3.2":
|
||||||
|
version: 3.3.2
|
||||||
|
resolution: "node-fetch@npm:3.3.2"
|
||||||
|
dependencies:
|
||||||
|
data-uri-to-buffer: ^4.0.0
|
||||||
|
fetch-blob: ^3.1.4
|
||||||
|
formdata-polyfill: ^4.0.10
|
||||||
|
checksum: 06a04095a2ddf05b0830a0d5302699704d59bda3102894ea64c7b9d4c865ecdff2d90fd042df7f5bc40337266961cb6183dcc808ea4f3000d024f422b462da92
|
||||||
|
languageName: node
|
||||||
|
linkType: hard
|
||||||
|
|
||||||
"universalify@npm:^0.1.0":
|
"universalify@npm:^0.1.0":
|
||||||
version: 0.1.2
|
version: 0.1.2
|
||||||
resolution: "universalify@npm:0.1.2"
|
resolution: "universalify@npm:0.1.2"
|
||||||
checksum: 40cdc60f6e61070fe658ca36016a8f4ec216b29bf04a55dce14e3710cc84c7448538ef4dad3728d0bfe29975ccd7bfb5f414c45e7b78883567fb31b246f02dff
|
checksum: 40cdc60f6e61070fe658ca36016a8f4ec216b29bf04a55dce14e3710cc84c7448538ef4dad3728d0bfe29975ccd7bfb5f414c45e7b78883567fb31b246f02dff
|
||||||
languageName: node
|
languageName: node
|
||||||
linkType: hard
|
linkType: hard
|
||||||
|
|
||||||
|
"web-streams-polyfill@npm:^3.0.3":
|
||||||
|
version: 3.2.1
|
||||||
|
resolution: "web-streams-polyfill@npm:3.2.1"
|
||||||
|
checksum: b119c78574b6d65935e35098c2afdcd752b84268e18746606af149e3c424e15621b6f1ff0b42b2676dc012fc4f0d313f964b41a4b5031e525faa03997457da02
|
||||||
|
languageName: node
|
||||||
|
linkType: hard
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue