@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
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Reads the target class name of a Parse Relation field value, i.e. a value
|
|
4
|
+
* shaped like { __type: "Relation", className: "Something" }. Returns undefined
|
|
5
|
+
* for anything else.
|
|
6
|
+
*/
|
|
7
|
+
function relationTargetClass(value) {
|
|
8
|
+
if (value && typeof value === "object") {
|
|
9
|
+
const rel = value;
|
|
10
|
+
if (rel.__type === "Relation" && typeof rel.className === "string") {
|
|
11
|
+
return rel.className;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
return undefined;
|
|
15
|
+
}
|
|
16
|
+
const nodeInit = (RED) => {
|
|
17
|
+
function OpenincParseFetchRelationNodeConstructor(config) {
|
|
18
|
+
RED.nodes.createNode(this, config);
|
|
19
|
+
const node = this;
|
|
20
|
+
const server = RED.nodes.getNode(config.server);
|
|
21
|
+
node.on("input", async function (msg, send, done) {
|
|
22
|
+
var _a, _b, _c, _d, _e;
|
|
23
|
+
if (!server) {
|
|
24
|
+
node.status({
|
|
25
|
+
fill: "red",
|
|
26
|
+
shape: "ring",
|
|
27
|
+
text: "Select a Parse Server configuration.",
|
|
28
|
+
});
|
|
29
|
+
done();
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
const fail = (text, logMsg) => {
|
|
33
|
+
node.status({ fill: "red", shape: "dot", text });
|
|
34
|
+
node.error(logMsg !== null && logMsg !== void 0 ? logMsg : text, msg);
|
|
35
|
+
done();
|
|
36
|
+
};
|
|
37
|
+
// Relation key: msg.relationKey wins over the configured default.
|
|
38
|
+
const relationKey = (typeof msg.relationKey === "string" && msg.relationKey) ||
|
|
39
|
+
config.relationKey;
|
|
40
|
+
if (!relationKey) {
|
|
41
|
+
fail("No relationKey", "No relation key configured and none provided in msg.relationKey");
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
// Identify the parent object and (if possible) the relation target class.
|
|
45
|
+
let parentClassName;
|
|
46
|
+
let parentObjectId;
|
|
47
|
+
let targetClassName = config.targetClassName || undefined;
|
|
48
|
+
if (config.source === "payload") {
|
|
49
|
+
const payload = msg.payload;
|
|
50
|
+
if (!payload || typeof payload !== "object" || Array.isArray(payload)) {
|
|
51
|
+
fail("payload not an object", "source is 'payload' but msg.payload is not a single Parse object");
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
parentClassName = payload.className;
|
|
55
|
+
parentObjectId = payload.objectId;
|
|
56
|
+
// A relation field on a fetched object carries its own target class.
|
|
57
|
+
targetClassName =
|
|
58
|
+
targetClassName !== null && targetClassName !== void 0 ? targetClassName : relationTargetClass(payload[relationKey]);
|
|
59
|
+
}
|
|
60
|
+
else {
|
|
61
|
+
// "config" — parent identified by the node settings (msg may override).
|
|
62
|
+
parentClassName =
|
|
63
|
+
config.className ||
|
|
64
|
+
(typeof msg.className === "string" ? msg.className : undefined);
|
|
65
|
+
parentObjectId =
|
|
66
|
+
config.objectId ||
|
|
67
|
+
(typeof msg.objectId === "string" ? msg.objectId : undefined);
|
|
68
|
+
}
|
|
69
|
+
if (!parentClassName || !parentObjectId) {
|
|
70
|
+
fail("No parent class/id", "Could not determine the parent object's className and objectId");
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
node.status({ fill: "blue", shape: "dot", text: "resolving..." });
|
|
74
|
+
// If we still don't know the target class, fetch the parent object and
|
|
75
|
+
// read it off the relation field itself.
|
|
76
|
+
if (!targetClassName) {
|
|
77
|
+
const parent = await server.api.request("GET", `/classes/${parentClassName}/${parentObjectId}`);
|
|
78
|
+
if (parent.status === "error") {
|
|
79
|
+
fail("Error: " + ((_a = parent.payload.error) !== null && _a !== void 0 ? _a : "unknown"), "Failed to fetch parent object to detect relation target class");
|
|
80
|
+
node.error(parent.payload, msg);
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
targetClassName = relationTargetClass((_b = parent.payload) === null || _b === void 0 ? void 0 : _b[relationKey]);
|
|
84
|
+
}
|
|
85
|
+
if (!targetClassName) {
|
|
86
|
+
fail("Unknown target class", `Could not determine the target class of relation "${relationKey}". ` +
|
|
87
|
+
"Set the Target Class field, or feed an object whose relation field is populated.");
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
// A $relatedTo query returns the members of the relation.
|
|
91
|
+
const query = {
|
|
92
|
+
className: targetClassName,
|
|
93
|
+
where: {
|
|
94
|
+
$relatedTo: {
|
|
95
|
+
object: {
|
|
96
|
+
__type: "Pointer",
|
|
97
|
+
className: parentClassName,
|
|
98
|
+
objectId: parentObjectId,
|
|
99
|
+
},
|
|
100
|
+
key: relationKey,
|
|
101
|
+
},
|
|
102
|
+
},
|
|
103
|
+
};
|
|
104
|
+
if (config.limit !== "") {
|
|
105
|
+
const limit = parseInt(config.limit, 10);
|
|
106
|
+
if (!isNaN(limit))
|
|
107
|
+
query.limit = limit;
|
|
108
|
+
}
|
|
109
|
+
if (config.order !== "") {
|
|
110
|
+
query.order = config.order;
|
|
111
|
+
}
|
|
112
|
+
node.status({ fill: "blue", shape: "dot", text: "querying..." });
|
|
113
|
+
const result = await server.api.find(query);
|
|
114
|
+
if (result.status === "error") {
|
|
115
|
+
node.status({
|
|
116
|
+
fill: "red",
|
|
117
|
+
shape: "dot",
|
|
118
|
+
text: "Error: " + ((_c = result.payload.error) !== null && _c !== void 0 ? _c : "unknown"),
|
|
119
|
+
});
|
|
120
|
+
node.error(result.payload, msg);
|
|
121
|
+
done();
|
|
122
|
+
return;
|
|
123
|
+
}
|
|
124
|
+
node.status({
|
|
125
|
+
fill: "green",
|
|
126
|
+
shape: "dot",
|
|
127
|
+
text: `${(_e = (_d = result.payload.results) === null || _d === void 0 ? void 0 : _d.length) !== null && _e !== void 0 ? _e : 0} results`,
|
|
128
|
+
});
|
|
129
|
+
send({
|
|
130
|
+
...msg,
|
|
131
|
+
payload: result.payload.results,
|
|
132
|
+
count: result.payload.count,
|
|
133
|
+
query,
|
|
134
|
+
parent: { className: parentClassName, objectId: parentObjectId },
|
|
135
|
+
});
|
|
136
|
+
done();
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
RED.nodes.registerType("openinc-parse-fetch-relation", OpenincParseFetchRelationNodeConstructor);
|
|
140
|
+
};
|
|
141
|
+
module.exports = nodeInit;
|
|
142
|
+
//# sourceMappingURL=openinc-parse-fetch-relation.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"openinc-parse-fetch-relation.js","sourceRoot":"","sources":["../../../src/nodes/openinc-parse-fetch-relation/openinc-parse-fetch-relation.ts"],"names":[],"mappings":";AAQA;;;;GAIG;AACH,SAAS,mBAAmB,CAAC,KAAc;IACzC,IAAI,KAAK,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;QACvC,MAAM,GAAG,GAAG,KAA4B,CAAC;QACzC,IAAI,GAAG,CAAC,MAAM,KAAK,UAAU,IAAI,OAAO,GAAG,CAAC,SAAS,KAAK,QAAQ,EAAE,CAAC;YACnE,OAAO,GAAG,CAAC,SAAS,CAAC;QACvB,CAAC;IACH,CAAC;IACD,OAAO,SAAS,CAAC;AACnB,CAAC;AAED,MAAM,QAAQ,GAAoB,CAAC,GAAG,EAAQ,EAAE;IAC9C,SAAS,wCAAwC,CAE/C,MAAwC;QAExC,GAAG,CAAC,KA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
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../src/nodes/openinc-parse-find/modules/types.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,245 @@
|
|
|
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-find", {
|
|
155
|
+
category: "parse",
|
|
156
|
+
color: "#61b7f2",
|
|
157
|
+
defaults: {
|
|
158
|
+
name: { value: "" },
|
|
159
|
+
server: { value: "", type: "openinc-parse-config" },
|
|
160
|
+
className: { value: "" },
|
|
161
|
+
limit: { value: "" },
|
|
162
|
+
order: { value: "" },
|
|
163
|
+
},
|
|
164
|
+
inputs: 1,
|
|
165
|
+
outputs: 1,
|
|
166
|
+
icon: "font-awesome/fa-search",
|
|
167
|
+
paletteLabel: "parse find",
|
|
168
|
+
label: function () {
|
|
169
|
+
return (this.name ||
|
|
170
|
+
(this.className ? "parse find: ".concat(this.className) : "parse find"));
|
|
171
|
+
},
|
|
172
|
+
oneditprepare: function () {
|
|
173
|
+
attachClassAutocomplete("#node-input-className");
|
|
174
|
+
},
|
|
175
|
+
});
|
|
176
|
+
|
|
177
|
+
})();
|
|
178
|
+
</script>
|
|
179
|
+
<script type="text/html" data-help-name="openinc-parse-find">
|
|
180
|
+
<p>
|
|
181
|
+
Runs a query against a Parse Server class and outputs the matching
|
|
182
|
+
objects.
|
|
183
|
+
</p>
|
|
184
|
+
|
|
185
|
+
<h2>Configuration</h2>
|
|
186
|
+
|
|
187
|
+
<ul>
|
|
188
|
+
<li><strong>Server:</strong> The Parse Server configuration node.</li>
|
|
189
|
+
<li>
|
|
190
|
+
<strong>Class:</strong> Name of the Parse class. Can be overridden per
|
|
191
|
+
message via <code>msg.payload.className</code>.
|
|
192
|
+
</li>
|
|
193
|
+
<li><strong>Limit / Order:</strong> Optional defaults used when the
|
|
194
|
+
incoming query does not set them.</li>
|
|
195
|
+
</ul>
|
|
196
|
+
|
|
197
|
+
<h2>Input</h2>
|
|
198
|
+
|
|
199
|
+
<p><code>msg.payload</code> can be either:</p>
|
|
200
|
+
|
|
201
|
+
<ul>
|
|
202
|
+
<li>
|
|
203
|
+
A full query object as produced by the
|
|
204
|
+
<strong>parse querybuilder</strong> node:
|
|
205
|
+
<code>{ className, where, limit, skip, order, keys, include, count }</code>
|
|
206
|
+
</li>
|
|
207
|
+
<li>
|
|
208
|
+
A plain <a href="https://docs.parseplatform.org/rest/guide/#queries">where
|
|
209
|
+
object</a>, e.g. <code>{ "status": "active" }</code>
|
|
210
|
+
</li>
|
|
211
|
+
<li>Empty, to fetch all objects of the configured class.</li>
|
|
212
|
+
</ul>
|
|
213
|
+
|
|
214
|
+
<h2>Output</h2>
|
|
215
|
+
|
|
216
|
+
<ul>
|
|
217
|
+
<li><strong>msg.payload:</strong> Array of matching objects.</li>
|
|
218
|
+
<li><strong>msg.count:</strong> Total count (only when the query sets
|
|
219
|
+
<code>count: true</code>).</li>
|
|
220
|
+
<li><strong>msg.query:</strong> The query that was executed.</li>
|
|
221
|
+
</ul>
|
|
222
|
+
</script>
|
|
223
|
+
|
|
224
|
+
<script type="text/html" data-template-name="openinc-parse-find">
|
|
225
|
+
<div class="form-row">
|
|
226
|
+
<label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
|
|
227
|
+
<input type="text" id="node-input-name" placeholder="Name">
|
|
228
|
+
</div>
|
|
229
|
+
<div class="form-row">
|
|
230
|
+
<label for="node-input-server"><i class="fa fa-server"></i> Server</label>
|
|
231
|
+
<input type="text" id="node-input-server" placeholder="Parse Server...">
|
|
232
|
+
</div>
|
|
233
|
+
<div class="form-row">
|
|
234
|
+
<label for="node-input-className"><i class="fa fa-table"></i> Class</label>
|
|
235
|
+
<input type="text" id="node-input-className" placeholder="(or msg.payload.className)">
|
|
236
|
+
</div>
|
|
237
|
+
<div class="form-row">
|
|
238
|
+
<label for="node-input-limit"><i class="fa fa-list-ol"></i> Limit</label>
|
|
239
|
+
<input type="text" id="node-input-limit" placeholder="(optional, default 100)">
|
|
240
|
+
</div>
|
|
241
|
+
<div class="form-row">
|
|
242
|
+
<label for="node-input-order"><i class="fa fa-sort"></i> Order</label>
|
|
243
|
+
<input type="text" id="node-input-order" placeholder="(optional, e.g. -createdAt)">
|
|
244
|
+
</div>
|
|
245
|
+
</script>
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
const helper_1 = require("../shared/helper");
|
|
3
|
+
const nodeInit = (RED) => {
|
|
4
|
+
function OpenincParseFindNodeConstructor(config) {
|
|
5
|
+
RED.nodes.createNode(this, config);
|
|
6
|
+
const node = this;
|
|
7
|
+
const server = RED.nodes.getNode(config.server);
|
|
8
|
+
node.on("input", async function (msg, send, done) {
|
|
9
|
+
var _a, _b, _c;
|
|
10
|
+
if (!server) {
|
|
11
|
+
node.status({
|
|
12
|
+
fill: "red",
|
|
13
|
+
shape: "ring",
|
|
14
|
+
text: "Select a Parse Server configuration.",
|
|
15
|
+
});
|
|
16
|
+
done();
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
const query = (0, helper_1.resolveQuery)(msg.payload, config.className);
|
|
20
|
+
if (!query.className) {
|
|
21
|
+
node.status({ fill: "red", shape: "dot", text: "No className" });
|
|
22
|
+
node.error("No className configured and none provided in msg.payload.className", msg);
|
|
23
|
+
done();
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
if (query.limit === undefined && config.limit !== "") {
|
|
27
|
+
const limit = parseInt(config.limit, 10);
|
|
28
|
+
if (!isNaN(limit))
|
|
29
|
+
query.limit = limit;
|
|
30
|
+
}
|
|
31
|
+
if (!query.order && config.order !== "") {
|
|
32
|
+
query.order = config.order;
|
|
33
|
+
}
|
|
34
|
+
node.status({ fill: "blue", shape: "dot", text: "querying..." });
|
|
35
|
+
const result = await server.api.find(query);
|
|
36
|
+
if (result.status === "error") {
|
|
37
|
+
node.status({
|
|
38
|
+
fill: "red",
|
|
39
|
+
shape: "dot",
|
|
40
|
+
text: "Error: " + ((_a = result.payload.error) !== null && _a !== void 0 ? _a : "unknown"),
|
|
41
|
+
});
|
|
42
|
+
node.error(result.payload, msg);
|
|
43
|
+
done();
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
node.status({
|
|
47
|
+
fill: "green",
|
|
48
|
+
shape: "dot",
|
|
49
|
+
text: `${(_c = (_b = result.payload.results) === null || _b === void 0 ? void 0 : _b.length) !== null && _c !== void 0 ? _c : 0} results`,
|
|
50
|
+
});
|
|
51
|
+
send({
|
|
52
|
+
...msg,
|
|
53
|
+
payload: result.payload.results,
|
|
54
|
+
count: result.payload.count,
|
|
55
|
+
query,
|
|
56
|
+
});
|
|
57
|
+
done();
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
RED.nodes.registerType("openinc-parse-find", OpenincParseFindNodeConstructor);
|
|
61
|
+
};
|
|
62
|
+
module.exports = nodeInit;
|
|
63
|
+
//# sourceMappingURL=openinc-parse-find.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"openinc-parse-find.js","sourceRoot":"","sources":["../../../src/nodes/openinc-parse-find/openinc-parse-find.ts"],"names":[],"mappings":";AAIA,6CAAgD;AAEhD,MAAM,QAAQ,GAAoB,CAAC,GAAG,EAAQ,EAAE;IAC9C,SAAS,+BAA+B,CAEtC,MAA+B;QAE/B,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,EAAE,CAAC,OAAO,EAAE,KAAK,WAAW,GAAgB,EAAE,IAAI,EAAE,IAAI;;YAC3D,IAAI,CAAC,MAAM,EAAE,CAAC;gBACZ,IAAI,CAAC,MAAM,CAAC;oBACV,IAAI,EAAE,KAAK;oBACX,KAAK,EAAE,MAAM;oBACb,IAAI,EAAE,sCAAsC;iBAC7C,CAAC,CAAC;gBACH,IAAI,EAAE,CAAC;gBACP,OAAO;YACT,CAAC;YAED,MAAM,KAAK,GAAG,IAAA,qBAAY,EAAC,GAAG,CAAC,OAAO,EAAE,MAAM,CAAC,SAAS,CAAC,CAAC;YAE1D,IAAI,CAAC,KAAK,CAAC,SAAS,EAAE,CAAC;gBACrB,IAAI,CAAC,MAAM,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,IAAI,EAAE,cAAc,EAAE,CAAC,CAAC;gBACjE,IAAI,CAAC,KAAK,CACR,oEAAoE,EACpE,GAAG,CACJ,CAAC;gBACF,IAAI,EAAE,CAAC;gBACP,OAAO;YACT,CAAC;YAED,IAA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,MAAM,CAAC,OAAO,CAAC,OAAO;gBAC/B,KAAK,EAAE,MAAM,CAAC,OAAO,CAAC,KAAK;gBAC3B,KAAK;aACS,CAAC,CAAC;YAClB,IAAI,EAAE,CAAC;QACT,CAAC,CAAC,CAAC;IACL,CAAC;IAED,GAAG,CAAC,KAAK,CAAC,YAAY,CAAC,oBAAoB,EAAE,+BAA+B,CAAC,CAAC;AAChF,CAAC,CAAC;AAEF,iBAAS,QAAQ,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../src/nodes/openinc-parse-find/shared/types.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../src/nodes/openinc-parse-querybuilder/modules/types.ts"],"names":[],"mappings":""}
|