@openinc/node-red-contrib-openinc-parse 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +33 -0
- package/dist/nodes/openinc-parse-changestream/modules/types.js +3 -0
- package/dist/nodes/openinc-parse-changestream/modules/types.js.map +1 -0
- package/dist/nodes/openinc-parse-changestream/openinc-parse-changestream.html +267 -0
- package/dist/nodes/openinc-parse-changestream/openinc-parse-changestream.js +147 -0
- package/dist/nodes/openinc-parse-changestream/openinc-parse-changestream.js.map +1 -0
- package/dist/nodes/openinc-parse-changestream/shared/types.js +3 -0
- package/dist/nodes/openinc-parse-changestream/shared/types.js.map +1 -0
- package/dist/nodes/openinc-parse-config/modules/types.js +3 -0
- package/dist/nodes/openinc-parse-config/modules/types.js.map +1 -0
- package/dist/nodes/openinc-parse-config/openinc-parse-config.html +416 -0
- package/dist/nodes/openinc-parse-config/openinc-parse-config.js +102 -0
- package/dist/nodes/openinc-parse-config/openinc-parse-config.js.map +1 -0
- package/dist/nodes/openinc-parse-config/shared/types.js +3 -0
- package/dist/nodes/openinc-parse-config/shared/types.js.map +1 -0
- package/dist/nodes/openinc-parse-delete/modules/types.js +3 -0
- package/dist/nodes/openinc-parse-delete/modules/types.js.map +1 -0
- package/dist/nodes/openinc-parse-delete/openinc-parse-delete.html +231 -0
- package/dist/nodes/openinc-parse-delete/openinc-parse-delete.js +60 -0
- package/dist/nodes/openinc-parse-delete/openinc-parse-delete.js.map +1 -0
- package/dist/nodes/openinc-parse-delete/shared/types.js +3 -0
- package/dist/nodes/openinc-parse-delete/shared/types.js.map +1 -0
- package/dist/nodes/openinc-parse-fetch-relation/modules/types.js +3 -0
- package/dist/nodes/openinc-parse-fetch-relation/modules/types.js.map +1 -0
- package/dist/nodes/openinc-parse-fetch-relation/openinc-parse-fetch-relation.html +306 -0
- package/dist/nodes/openinc-parse-fetch-relation/openinc-parse-fetch-relation.js +142 -0
- package/dist/nodes/openinc-parse-fetch-relation/openinc-parse-fetch-relation.js.map +1 -0
- package/dist/nodes/openinc-parse-fetch-relation/shared/types.js +3 -0
- package/dist/nodes/openinc-parse-fetch-relation/shared/types.js.map +1 -0
- package/dist/nodes/openinc-parse-find/modules/types.js +3 -0
- package/dist/nodes/openinc-parse-find/modules/types.js.map +1 -0
- package/dist/nodes/openinc-parse-find/openinc-parse-find.html +245 -0
- package/dist/nodes/openinc-parse-find/openinc-parse-find.js +63 -0
- package/dist/nodes/openinc-parse-find/openinc-parse-find.js.map +1 -0
- package/dist/nodes/openinc-parse-find/shared/types.js +3 -0
- package/dist/nodes/openinc-parse-find/shared/types.js.map +1 -0
- package/dist/nodes/openinc-parse-querybuilder/modules/types.js +3 -0
- package/dist/nodes/openinc-parse-querybuilder/modules/types.js.map +1 -0
- package/dist/nodes/openinc-parse-querybuilder/openinc-parse-querybuilder.html +440 -0
- package/dist/nodes/openinc-parse-querybuilder/openinc-parse-querybuilder.js +153 -0
- package/dist/nodes/openinc-parse-querybuilder/openinc-parse-querybuilder.js.map +1 -0
- package/dist/nodes/openinc-parse-querybuilder/shared/types.js +3 -0
- package/dist/nodes/openinc-parse-querybuilder/shared/types.js.map +1 -0
- package/dist/nodes/openinc-parse-save/modules/types.js +3 -0
- package/dist/nodes/openinc-parse-save/modules/types.js.map +1 -0
- package/dist/nodes/openinc-parse-save/openinc-parse-save.html +241 -0
- package/dist/nodes/openinc-parse-save/openinc-parse-save.js +75 -0
- package/dist/nodes/openinc-parse-save/openinc-parse-save.js.map +1 -0
- package/dist/nodes/openinc-parse-save/shared/types.js +3 -0
- package/dist/nodes/openinc-parse-save/shared/types.js.map +1 -0
- package/dist/nodes/openinc-parse-subscribe/modules/types.js +3 -0
- package/dist/nodes/openinc-parse-subscribe/modules/types.js.map +1 -0
- package/dist/nodes/openinc-parse-subscribe/openinc-parse-subscribe.html +260 -0
- package/dist/nodes/openinc-parse-subscribe/openinc-parse-subscribe.js +106 -0
- package/dist/nodes/openinc-parse-subscribe/openinc-parse-subscribe.js.map +1 -0
- package/dist/nodes/openinc-parse-subscribe/shared/types.js +3 -0
- package/dist/nodes/openinc-parse-subscribe/shared/types.js.map +1 -0
- package/dist/nodes/shared/helper.js +45 -0
- package/dist/nodes/shared/helper.js.map +1 -0
- package/dist/nodes/shared/livequery.js +171 -0
- package/dist/nodes/shared/livequery.js.map +1 -0
- package/dist/nodes/shared/parse-api.js +121 -0
- package/dist/nodes/shared/parse-api.js.map +1 -0
- package/dist/nodes/shared/schema-editor.js +163 -0
- package/dist/nodes/shared/schema-editor.js.map +1 -0
- package/dist/nodes/shared/types.js +3 -0
- package/dist/nodes/shared/types.js.map +1 -0
- package/package.json +61 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 open.INC GmbH
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
# @openinc/node-red-contrib-openinc-parse
|
|
2
|
+
|
|
3
|
+
Node-RED nodes to interact with a configurable [Parse Server](https://parseplatform.org/):
|
|
4
|
+
|
|
5
|
+
| Node | Description |
|
|
6
|
+
| ----------------------- | ------------------------------------------------------------------------------------------------------------------------ |
|
|
7
|
+
| **parse config** | Configuration node: server URL, LiveQuery URL, App ID, REST/JavaScript/Master key, session token. Includes a connection test. |
|
|
8
|
+
| **parse save** | Creates or updates an object. Updates when an `objectId` is set in the node settings or in `msg.payload.objectId`, otherwise creates. |
|
|
9
|
+
| **parse delete** | Deletes an object by `className` + `objectId` (settings or `msg.payload`). |
|
|
10
|
+
| **parse find** | Runs a query. Accepts a full query object or a plain `where` object on `msg.payload`. |
|
|
11
|
+
| **parse querybuilder** | Builds a query object from configurable conditions (UI) and writes it to `msg.payload`. |
|
|
12
|
+
| **parse subscribe** | Subscribes to LiveQuery events (`create`, `update`, `delete`, `enter`, `leave`) with automatic reconnect. |
|
|
13
|
+
| **parse changestream** | Polls the `OD3_Changelog` class (available on open.INC installations) in a configurable interval and outputs new entries as a change stream. |
|
|
14
|
+
|
|
15
|
+
## Typical flow
|
|
16
|
+
|
|
17
|
+
```
|
|
18
|
+
[inject] → [parse querybuilder] → [parse find] → [debug]
|
|
19
|
+
↘ [parse subscribe] → [debug]
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
## Development
|
|
23
|
+
|
|
24
|
+
This package is part of the open.INC Node-RED monorepo and uses the same
|
|
25
|
+
build setup as `@openinc/node-red-contrib-openware`:
|
|
26
|
+
|
|
27
|
+
```bash
|
|
28
|
+
pnpm install
|
|
29
|
+
pnpm build # or: pnpm dev for watch mode
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
The runtime code is compiled with `tsc`, the editor code is bundled per node
|
|
33
|
+
with Rollup into a single `.html` file next to the runtime `.js`.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../src/nodes/openinc-parse-changestream/modules/types.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,267 @@
|
|
|
1
|
+
<script type="text/javascript">
|
|
2
|
+
(function () {
|
|
3
|
+
'use strict';
|
|
4
|
+
|
|
5
|
+
/******************************************************************************
|
|
6
|
+
Copyright (c) Microsoft Corporation.
|
|
7
|
+
|
|
8
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
|
9
|
+
purpose with or without fee is hereby granted.
|
|
10
|
+
|
|
11
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
12
|
+
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
13
|
+
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
14
|
+
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
15
|
+
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
16
|
+
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
17
|
+
PERFORMANCE OF THIS SOFTWARE.
|
|
18
|
+
***************************************************************************** */
|
|
19
|
+
/* global Reflect, Promise, SuppressedError, Symbol, Iterator */
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
var __assign = function() {
|
|
23
|
+
__assign = Object.assign || function __assign(t) {
|
|
24
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
25
|
+
s = arguments[i];
|
|
26
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
|
|
27
|
+
}
|
|
28
|
+
return t;
|
|
29
|
+
};
|
|
30
|
+
return __assign.apply(this, arguments);
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
|
|
34
|
+
var e = new Error(message);
|
|
35
|
+
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
// Editor-only helpers (run in the Node-RED editor, not the runtime). They parse
|
|
39
|
+
// a Parse schema — as exported from the dashboard or fetched from /schemas — and
|
|
40
|
+
// wire jQuery-UI autocomplete onto class-name / field-name inputs. Other node
|
|
41
|
+
// editors read the schema straight off the referenced config node, so no server
|
|
42
|
+
// round-trip is needed while editing.
|
|
43
|
+
var EMPTY = {
|
|
44
|
+
classNames: [],
|
|
45
|
+
fieldsByClass: {},
|
|
46
|
+
relationsByClass: {},
|
|
47
|
+
};
|
|
48
|
+
/**
|
|
49
|
+
* Parses a schema JSON string. Accepts the shapes the Parse dashboard / REST
|
|
50
|
+
* API produce: an array of class schemas, `{ results: [...] }`, or a single
|
|
51
|
+
* class object.
|
|
52
|
+
*/
|
|
53
|
+
function parseSchema(raw) {
|
|
54
|
+
if (!raw || typeof raw !== "string" || raw.trim() === "")
|
|
55
|
+
return EMPTY;
|
|
56
|
+
var data;
|
|
57
|
+
try {
|
|
58
|
+
data = JSON.parse(raw);
|
|
59
|
+
}
|
|
60
|
+
catch (_a) {
|
|
61
|
+
return EMPTY;
|
|
62
|
+
}
|
|
63
|
+
var classes = [];
|
|
64
|
+
if (Array.isArray(data)) {
|
|
65
|
+
classes = data;
|
|
66
|
+
}
|
|
67
|
+
else if (data && Array.isArray(data.results)) {
|
|
68
|
+
classes = data.results;
|
|
69
|
+
}
|
|
70
|
+
else if (data && typeof data.className === "string") {
|
|
71
|
+
classes = [data];
|
|
72
|
+
}
|
|
73
|
+
else if (data && typeof data === "object") {
|
|
74
|
+
// Object keyed by class name -> schema.
|
|
75
|
+
classes = Object.keys(data).map(function (key) {
|
|
76
|
+
return data[key] && data[key].className ? data[key] : __assign({ className: key }, data[key]);
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
var result = {
|
|
80
|
+
classNames: [],
|
|
81
|
+
fieldsByClass: {},
|
|
82
|
+
relationsByClass: {},
|
|
83
|
+
};
|
|
84
|
+
var _loop_1 = function (cls) {
|
|
85
|
+
if (!cls || typeof cls !== "object")
|
|
86
|
+
return "continue";
|
|
87
|
+
var name_1 = cls.className;
|
|
88
|
+
if (typeof name_1 !== "string" || name_1 === "")
|
|
89
|
+
return "continue";
|
|
90
|
+
if (result.classNames.indexOf(name_1) === -1)
|
|
91
|
+
result.classNames.push(name_1);
|
|
92
|
+
var fields = cls.fields && typeof cls.fields === "object" ? cls.fields : {};
|
|
93
|
+
var fieldNames = Object.keys(fields);
|
|
94
|
+
result.fieldsByClass[name_1] = fieldNames;
|
|
95
|
+
result.relationsByClass[name_1] = fieldNames.filter(function (field) { return fields[field] && fields[field].type === "Relation"; });
|
|
96
|
+
};
|
|
97
|
+
for (var _i = 0, classes_1 = classes; _i < classes_1.length; _i++) {
|
|
98
|
+
var cls = classes_1[_i];
|
|
99
|
+
_loop_1(cls);
|
|
100
|
+
}
|
|
101
|
+
result.classNames.sort();
|
|
102
|
+
return result;
|
|
103
|
+
}
|
|
104
|
+
/** Parsed schema of the referenced config node (by its node id). */
|
|
105
|
+
function schemaForServer(serverId) {
|
|
106
|
+
if (!serverId)
|
|
107
|
+
return EMPTY;
|
|
108
|
+
var cfg = RED.nodes.node(serverId);
|
|
109
|
+
return parseSchema(cfg && cfg.schema);
|
|
110
|
+
}
|
|
111
|
+
var datalistCounter = 0;
|
|
112
|
+
function escapeAttr(value) {
|
|
113
|
+
return value.replace(/&/g, "&").replace(/"/g, """);
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Attaches suggestions to a text input via a native <datalist>. `sourceFn` is
|
|
117
|
+
* re-evaluated on focus/input so the options can depend on other live fields
|
|
118
|
+
* (e.g. the class currently typed). Native datalists work in every browser and
|
|
119
|
+
* need no editor framework support.
|
|
120
|
+
*/
|
|
121
|
+
function attachAutocomplete(input, sourceFn) {
|
|
122
|
+
var el = input && input.jquery ? input[0] : input || null;
|
|
123
|
+
if (!el || !el.parentNode)
|
|
124
|
+
return;
|
|
125
|
+
var listId = el.getAttribute("list") || "";
|
|
126
|
+
var datalist = listId
|
|
127
|
+
? document.getElementById(listId)
|
|
128
|
+
: null;
|
|
129
|
+
if (!datalist) {
|
|
130
|
+
listId = "openinc-parse-dl-" + ++datalistCounter;
|
|
131
|
+
datalist = document.createElement("datalist");
|
|
132
|
+
datalist.id = listId;
|
|
133
|
+
el.setAttribute("list", listId);
|
|
134
|
+
el.parentNode.appendChild(datalist);
|
|
135
|
+
}
|
|
136
|
+
var refresh = function () {
|
|
137
|
+
var items = sourceFn() || [];
|
|
138
|
+
datalist.innerHTML = items
|
|
139
|
+
.map(function (item) { return "<option value=\"".concat(escapeAttr(String(item)), "\"></option>"); })
|
|
140
|
+
.join("");
|
|
141
|
+
};
|
|
142
|
+
el.addEventListener("focus", refresh);
|
|
143
|
+
el.addEventListener("input", refresh);
|
|
144
|
+
refresh();
|
|
145
|
+
}
|
|
146
|
+
/** Class-name autocomplete sourced from the node's server (config) field. */
|
|
147
|
+
function attachClassAutocomplete(inputSelector, serverSelector) {
|
|
148
|
+
if (serverSelector === void 0) { serverSelector = "#node-input-server"; }
|
|
149
|
+
attachAutocomplete($(inputSelector), function () {
|
|
150
|
+
return schemaForServer($(serverSelector).val()).classNames;
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
RED.nodes.registerType("openinc-parse-changestream", {
|
|
155
|
+
category: "parse",
|
|
156
|
+
color: "#61b7f2",
|
|
157
|
+
defaults: {
|
|
158
|
+
name: { value: "" },
|
|
159
|
+
server: { value: "", type: "openinc-parse-config" },
|
|
160
|
+
className: { value: "" },
|
|
161
|
+
operations: { value: "" },
|
|
162
|
+
interval: { value: "10" },
|
|
163
|
+
limit: { value: "100" },
|
|
164
|
+
emitExisting: { value: false },
|
|
165
|
+
},
|
|
166
|
+
inputs: 1,
|
|
167
|
+
outputs: 1,
|
|
168
|
+
icon: "font-awesome/fa-history",
|
|
169
|
+
paletteLabel: "parse changestream",
|
|
170
|
+
label: function () {
|
|
171
|
+
return (this.name ||
|
|
172
|
+
(this.className
|
|
173
|
+
? "parse changestream: ".concat(this.className)
|
|
174
|
+
: "parse changestream"));
|
|
175
|
+
},
|
|
176
|
+
oneditprepare: function () {
|
|
177
|
+
attachClassAutocomplete("#node-input-className");
|
|
178
|
+
},
|
|
179
|
+
});
|
|
180
|
+
|
|
181
|
+
})();
|
|
182
|
+
</script>
|
|
183
|
+
<script type="text/html" data-help-name="openinc-parse-changestream">
|
|
184
|
+
<p>
|
|
185
|
+
Polls the <code>OD3_Changelog</code> class of an open.INC Parse Server in
|
|
186
|
+
a configurable interval and outputs every new changelog entry as a
|
|
187
|
+
change stream. This is an alternative to LiveQuery when websockets are
|
|
188
|
+
not available.
|
|
189
|
+
</p>
|
|
190
|
+
|
|
191
|
+
<h2>Configuration</h2>
|
|
192
|
+
|
|
193
|
+
<ul>
|
|
194
|
+
<li><strong>Server:</strong> The Parse Server configuration node. The
|
|
195
|
+
configured user needs read access to <code>OD3_Changelog</code>
|
|
196
|
+
(authenticated user or master key).</li>
|
|
197
|
+
<li><strong>Class:</strong> Optional filter on the changed class
|
|
198
|
+
(<code>nameOfClass</code>). Empty = changes of all classes.</li>
|
|
199
|
+
<li><strong>Operations:</strong> Optional comma separated filter on the
|
|
200
|
+
operation, e.g. <code>create,update,delete</code>.</li>
|
|
201
|
+
<li><strong>Interval:</strong> Poll interval in seconds (default 10).</li>
|
|
202
|
+
<li><strong>Batch limit:</strong> Maximum entries fetched per request.
|
|
203
|
+
If a poll returns a full batch, the node immediately fetches the next
|
|
204
|
+
batch until it caught up.</li>
|
|
205
|
+
<li><strong>Emit existing:</strong> If checked, all existing changelog
|
|
206
|
+
entries are emitted once after deploy. Otherwise the stream starts
|
|
207
|
+
with changes that happen after the deploy.</li>
|
|
208
|
+
</ul>
|
|
209
|
+
|
|
210
|
+
<h2>Input</h2>
|
|
211
|
+
|
|
212
|
+
<p>Any incoming message triggers an immediate poll.</p>
|
|
213
|
+
|
|
214
|
+
<h2>Output</h2>
|
|
215
|
+
|
|
216
|
+
<p>One message per changelog entry, ordered by <code>createdAt</code>:</p>
|
|
217
|
+
|
|
218
|
+
<pre>msg.payload = {
|
|
219
|
+
event, // operation: create | update | delete | ...
|
|
220
|
+
className, // nameOfClass
|
|
221
|
+
objectId, // changedObject
|
|
222
|
+
value, // new values (if recorded)
|
|
223
|
+
original, // previous values (if recorded)
|
|
224
|
+
actingUser, // pointer to the acting _User
|
|
225
|
+
changelog, // the full OD3_Changelog object
|
|
226
|
+
}</pre>
|
|
227
|
+
|
|
228
|
+
<h2>Status</h2>
|
|
229
|
+
|
|
230
|
+
<ul>
|
|
231
|
+
<li><strong>watching:</strong> Connected, no new changes in the last
|
|
232
|
+
poll.</li>
|
|
233
|
+
<li><strong>n changes @ time:</strong> New entries were emitted.</li>
|
|
234
|
+
<li><strong>Error:</strong> The query failed (see debug sidebar).</li>
|
|
235
|
+
</ul>
|
|
236
|
+
</script>
|
|
237
|
+
|
|
238
|
+
<script type="text/html" data-template-name="openinc-parse-changestream">
|
|
239
|
+
<div class="form-row">
|
|
240
|
+
<label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
|
|
241
|
+
<input type="text" id="node-input-name" placeholder="Name">
|
|
242
|
+
</div>
|
|
243
|
+
<div class="form-row">
|
|
244
|
+
<label for="node-input-server"><i class="fa fa-server"></i> Server</label>
|
|
245
|
+
<input type="text" id="node-input-server" placeholder="Parse Server...">
|
|
246
|
+
</div>
|
|
247
|
+
<div class="form-row">
|
|
248
|
+
<label for="node-input-className"><i class="fa fa-table"></i> Class</label>
|
|
249
|
+
<input type="text" id="node-input-className" placeholder="(optional, filter on nameOfClass)">
|
|
250
|
+
</div>
|
|
251
|
+
<div class="form-row">
|
|
252
|
+
<label for="node-input-operations"><i class="fa fa-pencil"></i> Operations</label>
|
|
253
|
+
<input type="text" id="node-input-operations" placeholder="(optional, e.g. create,update,delete)">
|
|
254
|
+
</div>
|
|
255
|
+
<div class="form-row">
|
|
256
|
+
<label for="node-input-interval"><i class="fa fa-clock-o"></i> Interval (s)</label>
|
|
257
|
+
<input type="text" id="node-input-interval" placeholder="10">
|
|
258
|
+
</div>
|
|
259
|
+
<div class="form-row">
|
|
260
|
+
<label for="node-input-limit"><i class="fa fa-list-ol"></i> Batch limit</label>
|
|
261
|
+
<input type="text" id="node-input-limit" placeholder="100">
|
|
262
|
+
</div>
|
|
263
|
+
<div class="form-row">
|
|
264
|
+
<label for="node-input-emitExisting"><i class="fa fa-fast-backward"></i> Emit existing</label>
|
|
265
|
+
<input type="checkbox" id="node-input-emitExisting" style="display:inline-block;width:auto;vertical-align:top;">
|
|
266
|
+
</div>
|
|
267
|
+
</script>
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
const CHANGELOG_CLASS = "OD3_Changelog";
|
|
3
|
+
const nodeInit = (RED) => {
|
|
4
|
+
function OpenincParseChangestreamNodeConstructor(config) {
|
|
5
|
+
RED.nodes.createNode(this, config);
|
|
6
|
+
const node = this;
|
|
7
|
+
const server = RED.nodes.getNode(config.server);
|
|
8
|
+
if (!server) {
|
|
9
|
+
node.status({
|
|
10
|
+
fill: "red",
|
|
11
|
+
shape: "ring",
|
|
12
|
+
text: "Select a Parse Server configuration.",
|
|
13
|
+
});
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
16
|
+
const intervalMs = Math.max(1, parseInt(config.interval, 10) || 10) * 1000;
|
|
17
|
+
const limit = Math.max(1, parseInt(config.limit, 10) || 100);
|
|
18
|
+
const whereBase = {};
|
|
19
|
+
if (config.className) {
|
|
20
|
+
whereBase.nameOfClass = config.className;
|
|
21
|
+
}
|
|
22
|
+
if (config.operations) {
|
|
23
|
+
const operations = config.operations
|
|
24
|
+
.split(",")
|
|
25
|
+
.map((entry) => entry.trim())
|
|
26
|
+
.filter((entry) => entry !== "");
|
|
27
|
+
if (operations.length === 1) {
|
|
28
|
+
whereBase.operation = operations[0];
|
|
29
|
+
}
|
|
30
|
+
else if (operations.length > 1) {
|
|
31
|
+
whereBase.operation = { $in: operations };
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
// Keyset cursor over (createdAt, objectId). Paging strictly "after" this
|
|
35
|
+
// compound key makes pagination deterministic even when many entries share
|
|
36
|
+
// a createdAt timestamp — no entry is ever emitted twice and the loop
|
|
37
|
+
// always advances.
|
|
38
|
+
let cursorCreatedAt = null;
|
|
39
|
+
let cursorObjectId = null;
|
|
40
|
+
let polling = false;
|
|
41
|
+
let timer = null;
|
|
42
|
+
const emitEntry = (entry) => {
|
|
43
|
+
node.send({
|
|
44
|
+
payload: {
|
|
45
|
+
event: entry.operation,
|
|
46
|
+
className: entry.nameOfClass,
|
|
47
|
+
objectId: entry.changedObject,
|
|
48
|
+
value: entry.value,
|
|
49
|
+
original: entry.original,
|
|
50
|
+
actingUser: entry.actingUser,
|
|
51
|
+
changelog: entry,
|
|
52
|
+
},
|
|
53
|
+
});
|
|
54
|
+
};
|
|
55
|
+
// Seed the cursor without hitting the server. "Emit existing" starts from
|
|
56
|
+
// the epoch (dumps the whole changelog once); otherwise start from now so
|
|
57
|
+
// only entries created after deploy are emitted. This avoids an expensive
|
|
58
|
+
// "-createdAt" scan that some Parse deployments reject with a 500.
|
|
59
|
+
const initCursor = () => {
|
|
60
|
+
cursorCreatedAt = config.emitExisting
|
|
61
|
+
? new Date(0).toISOString()
|
|
62
|
+
: new Date().toISOString();
|
|
63
|
+
cursorObjectId = null;
|
|
64
|
+
};
|
|
65
|
+
const poll = async () => {
|
|
66
|
+
var _a, _b;
|
|
67
|
+
if (polling)
|
|
68
|
+
return;
|
|
69
|
+
polling = true;
|
|
70
|
+
try {
|
|
71
|
+
if (cursorCreatedAt === null)
|
|
72
|
+
initCursor();
|
|
73
|
+
let more = true;
|
|
74
|
+
while (more) {
|
|
75
|
+
// First page (no objectId yet) is an inclusive lower bound; after
|
|
76
|
+
// that, page strictly after the last (createdAt, objectId) key.
|
|
77
|
+
const afterClause = cursorObjectId === null
|
|
78
|
+
? {
|
|
79
|
+
createdAt: { $gte: { __type: "Date", iso: cursorCreatedAt } },
|
|
80
|
+
}
|
|
81
|
+
: {
|
|
82
|
+
$or: [
|
|
83
|
+
{
|
|
84
|
+
createdAt: { $gt: { __type: "Date", iso: cursorCreatedAt } },
|
|
85
|
+
},
|
|
86
|
+
{
|
|
87
|
+
createdAt: { __type: "Date", iso: cursorCreatedAt },
|
|
88
|
+
objectId: { $gt: cursorObjectId },
|
|
89
|
+
},
|
|
90
|
+
],
|
|
91
|
+
};
|
|
92
|
+
const result = await server.api.find({
|
|
93
|
+
className: CHANGELOG_CLASS,
|
|
94
|
+
where: { ...whereBase, ...afterClause },
|
|
95
|
+
order: "createdAt,objectId",
|
|
96
|
+
limit,
|
|
97
|
+
});
|
|
98
|
+
if (result.status === "error") {
|
|
99
|
+
node.status({
|
|
100
|
+
fill: "red",
|
|
101
|
+
shape: "dot",
|
|
102
|
+
text: "Error: " + ((_a = result.payload.error) !== null && _a !== void 0 ? _a : "unknown"),
|
|
103
|
+
});
|
|
104
|
+
node.error(result.payload);
|
|
105
|
+
return;
|
|
106
|
+
}
|
|
107
|
+
const results = ((_b = result.payload.results) !== null && _b !== void 0 ? _b : []);
|
|
108
|
+
results.forEach(emitEntry);
|
|
109
|
+
if (results.length > 0) {
|
|
110
|
+
const last = results[results.length - 1];
|
|
111
|
+
cursorCreatedAt = last.createdAt;
|
|
112
|
+
cursorObjectId = last.objectId;
|
|
113
|
+
node.status({
|
|
114
|
+
fill: "green",
|
|
115
|
+
shape: "dot",
|
|
116
|
+
text: `${results.length} changes @ ${new Date().toLocaleTimeString()}`,
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
else {
|
|
120
|
+
node.status({ fill: "green", shape: "ring", text: "watching" });
|
|
121
|
+
}
|
|
122
|
+
// A full page means there may be more entries waiting.
|
|
123
|
+
more = results.length >= limit;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
finally {
|
|
127
|
+
polling = false;
|
|
128
|
+
}
|
|
129
|
+
};
|
|
130
|
+
timer = setInterval(poll, intervalMs);
|
|
131
|
+
poll();
|
|
132
|
+
// Any input triggers an immediate poll (e.g. to reduce latency after
|
|
133
|
+
// own writes).
|
|
134
|
+
node.on("input", function (_msg, _send, done) {
|
|
135
|
+
poll().then(() => done());
|
|
136
|
+
});
|
|
137
|
+
node.on("close", function () {
|
|
138
|
+
if (timer) {
|
|
139
|
+
clearInterval(timer);
|
|
140
|
+
timer = null;
|
|
141
|
+
}
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
RED.nodes.registerType("openinc-parse-changestream", OpenincParseChangestreamNodeConstructor);
|
|
145
|
+
};
|
|
146
|
+
module.exports = nodeInit;
|
|
147
|
+
//# sourceMappingURL=openinc-parse-changestream.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"openinc-parse-changestream.js","sourceRoot":"","sources":["../../../src/nodes/openinc-parse-changestream/openinc-parse-changestream.ts"],"names":[],"mappings":";AAQA,MAAM,eAAe,GAAG,eAAe,CAAC;AAExC,MAAM,QAAQ,GAAoB,CAAC,GAAG,EAAQ,EAAE;IAC9C,SAAS,uCAAuC,CAE9C,MAAuC;QAEvC,GAAG,CAAC,KAAK,CAAC,UAAU,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;QACnC,MAAM,IAAI,GAAG,IAAI,CAAC;QAClB,MAAM,MAAM,GAAG,GAAG,CAAC,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,MAAM,CAA2B,CAAC;QAE1E,IAAI,CAAC,MAAM,EAAE,CAAC;YACZ,IAAI,CAAC,MAAM,CAAC;gBACV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4BACV,IAAI,EAAE,OAAO;4BACb,KAAK,EAAE,KAAK;4BACZ,IAAI,EAAE,GAAG,OAAO,CAAC,MAAM,cAAc,IAAI,IAAI,EAAE,CAAC,kBAAkB,EAAE,EAAE;yBACvE,CAAC,CAAC;oBACL,CAAC;yBAAM,CAAC;wBACN,IAAI,CAAC,MAAM,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,UAAU,EAAE,CAAC,CAAC;oBAClE,CAAC;oBAED,uDAAuD;oBACvD,IAAI,GAAG,OAAO,CAAC,MAAM,IAAI,KAAK,CAAC;gBACjC,CAAC;YACH,CAAC;oBAAS,CAAC;gBACT,OAAO,GAAG,KAAK,CAAC;YAClB,CAAC;QACH,CAAC,CAAC;QAEF,KAAK,GAAG,WAAW,CAAC,IAAI,EAAE,UAAU,CAAC,CAAC;QACtC,IAAI,EAAE,CAAC;QAEP,qEAAqE;QACrE,eAAe;QACf,IAAI,CAAC,EAAE,CAAC,OAAO,EAAE,UAAU,IAAI,EAAE,KAAK,EAAE,IAAI;YAC1C,IAAI,EAAE,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,IAAI,EAAE,CAAC,CAAC;QAC5B,CAAC,CAAC,CAAC;QAEH,IAAI,CAAC,EAAE,CAAC,OAAO,EAAE;YACf,IAAI,KAAK,EAAE,CAAC;gBACV,aAAa,CAAC,KAAK,CAAC,CAAC;gBACrB,KAAK,GAAG,IAAI,CAAC;YACf,CAAC;QACH,CAAC,CAAC,CAAC;IACL,CAAC;IAED,GAAG,CAAC,KAAK,CAAC,YAAY,CACpB,4BAA4B,EAC5B,uCAAuC,CACxC,CAAC;AACJ,CAAC,CAAC;AAEF,iBAAS,QAAQ,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../src/nodes/openinc-parse-changestream/shared/types.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../src/nodes/openinc-parse-config/modules/types.ts"],"names":[],"mappings":""}
|