@plasmicapp/data-sources 0.1.126 → 0.1.127
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/dist/components/Fetcher.d.ts +15 -15
- package/dist/executor.d.ts +17 -17
- package/dist/helpers.d.ts +18 -18
- package/dist/hooks/useDependencyAwareQuery.d.ts +11 -11
- package/dist/hooks/usePlasmicDataOp.d.ts +20 -20
- package/dist/index.d.ts +10 -8
- package/dist/index.esm.js +600 -0
- package/dist/index.esm.js.map +7 -0
- package/dist/index.js +622 -5
- package/dist/index.js.map +7 -0
- package/dist/types.d.ts +31 -31
- package/dist/utils.d.ts +31 -31
- package/package.json +22 -34
- package/dist/data-sources.cjs.development.js +0 -1171
- package/dist/data-sources.cjs.development.js.map +0 -1
- package/dist/data-sources.cjs.production.min.js +0 -2
- package/dist/data-sources.cjs.production.min.js.map +0 -1
- package/dist/data-sources.esm.js +0 -1151
- package/dist/data-sources.esm.js.map +0 -1
|
@@ -1,1171 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
-
|
|
5
|
-
function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }
|
|
6
|
-
|
|
7
|
-
var query = require('@plasmicapp/query');
|
|
8
|
-
var React = _interopDefault(require('react'));
|
|
9
|
-
var dataSourcesContext = require('@plasmicapp/data-sources-context');
|
|
10
|
-
var ph = require('@plasmicapp/host');
|
|
11
|
-
var fetch = _interopDefault(require('@plasmicapp/isomorphic-unfetch'));
|
|
12
|
-
var stringify = _interopDefault(require('fast-stringify'));
|
|
13
|
-
|
|
14
|
-
function _regeneratorRuntime() {
|
|
15
|
-
_regeneratorRuntime = function () {
|
|
16
|
-
return e;
|
|
17
|
-
};
|
|
18
|
-
var t,
|
|
19
|
-
e = {},
|
|
20
|
-
r = Object.prototype,
|
|
21
|
-
n = r.hasOwnProperty,
|
|
22
|
-
o = Object.defineProperty || function (t, e, r) {
|
|
23
|
-
t[e] = r.value;
|
|
24
|
-
},
|
|
25
|
-
i = "function" == typeof Symbol ? Symbol : {},
|
|
26
|
-
a = i.iterator || "@@iterator",
|
|
27
|
-
c = i.asyncIterator || "@@asyncIterator",
|
|
28
|
-
u = i.toStringTag || "@@toStringTag";
|
|
29
|
-
function define(t, e, r) {
|
|
30
|
-
return Object.defineProperty(t, e, {
|
|
31
|
-
value: r,
|
|
32
|
-
enumerable: !0,
|
|
33
|
-
configurable: !0,
|
|
34
|
-
writable: !0
|
|
35
|
-
}), t[e];
|
|
36
|
-
}
|
|
37
|
-
try {
|
|
38
|
-
define({}, "");
|
|
39
|
-
} catch (t) {
|
|
40
|
-
define = function (t, e, r) {
|
|
41
|
-
return t[e] = r;
|
|
42
|
-
};
|
|
43
|
-
}
|
|
44
|
-
function wrap(t, e, r, n) {
|
|
45
|
-
var i = e && e.prototype instanceof Generator ? e : Generator,
|
|
46
|
-
a = Object.create(i.prototype),
|
|
47
|
-
c = new Context(n || []);
|
|
48
|
-
return o(a, "_invoke", {
|
|
49
|
-
value: makeInvokeMethod(t, r, c)
|
|
50
|
-
}), a;
|
|
51
|
-
}
|
|
52
|
-
function tryCatch(t, e, r) {
|
|
53
|
-
try {
|
|
54
|
-
return {
|
|
55
|
-
type: "normal",
|
|
56
|
-
arg: t.call(e, r)
|
|
57
|
-
};
|
|
58
|
-
} catch (t) {
|
|
59
|
-
return {
|
|
60
|
-
type: "throw",
|
|
61
|
-
arg: t
|
|
62
|
-
};
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
e.wrap = wrap;
|
|
66
|
-
var h = "suspendedStart",
|
|
67
|
-
l = "suspendedYield",
|
|
68
|
-
f = "executing",
|
|
69
|
-
s = "completed",
|
|
70
|
-
y = {};
|
|
71
|
-
function Generator() {}
|
|
72
|
-
function GeneratorFunction() {}
|
|
73
|
-
function GeneratorFunctionPrototype() {}
|
|
74
|
-
var p = {};
|
|
75
|
-
define(p, a, function () {
|
|
76
|
-
return this;
|
|
77
|
-
});
|
|
78
|
-
var d = Object.getPrototypeOf,
|
|
79
|
-
v = d && d(d(values([])));
|
|
80
|
-
v && v !== r && n.call(v, a) && (p = v);
|
|
81
|
-
var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p);
|
|
82
|
-
function defineIteratorMethods(t) {
|
|
83
|
-
["next", "throw", "return"].forEach(function (e) {
|
|
84
|
-
define(t, e, function (t) {
|
|
85
|
-
return this._invoke(e, t);
|
|
86
|
-
});
|
|
87
|
-
});
|
|
88
|
-
}
|
|
89
|
-
function AsyncIterator(t, e) {
|
|
90
|
-
function invoke(r, o, i, a) {
|
|
91
|
-
var c = tryCatch(t[r], t, o);
|
|
92
|
-
if ("throw" !== c.type) {
|
|
93
|
-
var u = c.arg,
|
|
94
|
-
h = u.value;
|
|
95
|
-
return h && "object" == typeof h && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) {
|
|
96
|
-
invoke("next", t, i, a);
|
|
97
|
-
}, function (t) {
|
|
98
|
-
invoke("throw", t, i, a);
|
|
99
|
-
}) : e.resolve(h).then(function (t) {
|
|
100
|
-
u.value = t, i(u);
|
|
101
|
-
}, function (t) {
|
|
102
|
-
return invoke("throw", t, i, a);
|
|
103
|
-
});
|
|
104
|
-
}
|
|
105
|
-
a(c.arg);
|
|
106
|
-
}
|
|
107
|
-
var r;
|
|
108
|
-
o(this, "_invoke", {
|
|
109
|
-
value: function (t, n) {
|
|
110
|
-
function callInvokeWithMethodAndArg() {
|
|
111
|
-
return new e(function (e, r) {
|
|
112
|
-
invoke(t, n, e, r);
|
|
113
|
-
});
|
|
114
|
-
}
|
|
115
|
-
return r = r ? r.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg();
|
|
116
|
-
}
|
|
117
|
-
});
|
|
118
|
-
}
|
|
119
|
-
function makeInvokeMethod(e, r, n) {
|
|
120
|
-
var o = h;
|
|
121
|
-
return function (i, a) {
|
|
122
|
-
if (o === f) throw new Error("Generator is already running");
|
|
123
|
-
if (o === s) {
|
|
124
|
-
if ("throw" === i) throw a;
|
|
125
|
-
return {
|
|
126
|
-
value: t,
|
|
127
|
-
done: !0
|
|
128
|
-
};
|
|
129
|
-
}
|
|
130
|
-
for (n.method = i, n.arg = a;;) {
|
|
131
|
-
var c = n.delegate;
|
|
132
|
-
if (c) {
|
|
133
|
-
var u = maybeInvokeDelegate(c, n);
|
|
134
|
-
if (u) {
|
|
135
|
-
if (u === y) continue;
|
|
136
|
-
return u;
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) {
|
|
140
|
-
if (o === h) throw o = s, n.arg;
|
|
141
|
-
n.dispatchException(n.arg);
|
|
142
|
-
} else "return" === n.method && n.abrupt("return", n.arg);
|
|
143
|
-
o = f;
|
|
144
|
-
var p = tryCatch(e, r, n);
|
|
145
|
-
if ("normal" === p.type) {
|
|
146
|
-
if (o = n.done ? s : l, p.arg === y) continue;
|
|
147
|
-
return {
|
|
148
|
-
value: p.arg,
|
|
149
|
-
done: n.done
|
|
150
|
-
};
|
|
151
|
-
}
|
|
152
|
-
"throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg);
|
|
153
|
-
}
|
|
154
|
-
};
|
|
155
|
-
}
|
|
156
|
-
function maybeInvokeDelegate(e, r) {
|
|
157
|
-
var n = r.method,
|
|
158
|
-
o = e.iterator[n];
|
|
159
|
-
if (o === t) return r.delegate = null, "throw" === n && e.iterator.return && (r.method = "return", r.arg = t, maybeInvokeDelegate(e, r), "throw" === r.method) || "return" !== n && (r.method = "throw", r.arg = new TypeError("The iterator does not provide a '" + n + "' method")), y;
|
|
160
|
-
var i = tryCatch(o, e.iterator, r.arg);
|
|
161
|
-
if ("throw" === i.type) return r.method = "throw", r.arg = i.arg, r.delegate = null, y;
|
|
162
|
-
var a = i.arg;
|
|
163
|
-
return a ? a.done ? (r[e.resultName] = a.value, r.next = e.nextLoc, "return" !== r.method && (r.method = "next", r.arg = t), r.delegate = null, y) : a : (r.method = "throw", r.arg = new TypeError("iterator result is not an object"), r.delegate = null, y);
|
|
164
|
-
}
|
|
165
|
-
function pushTryEntry(t) {
|
|
166
|
-
var e = {
|
|
167
|
-
tryLoc: t[0]
|
|
168
|
-
};
|
|
169
|
-
1 in t && (e.catchLoc = t[1]), 2 in t && (e.finallyLoc = t[2], e.afterLoc = t[3]), this.tryEntries.push(e);
|
|
170
|
-
}
|
|
171
|
-
function resetTryEntry(t) {
|
|
172
|
-
var e = t.completion || {};
|
|
173
|
-
e.type = "normal", delete e.arg, t.completion = e;
|
|
174
|
-
}
|
|
175
|
-
function Context(t) {
|
|
176
|
-
this.tryEntries = [{
|
|
177
|
-
tryLoc: "root"
|
|
178
|
-
}], t.forEach(pushTryEntry, this), this.reset(!0);
|
|
179
|
-
}
|
|
180
|
-
function values(e) {
|
|
181
|
-
if (e || "" === e) {
|
|
182
|
-
var r = e[a];
|
|
183
|
-
if (r) return r.call(e);
|
|
184
|
-
if ("function" == typeof e.next) return e;
|
|
185
|
-
if (!isNaN(e.length)) {
|
|
186
|
-
var o = -1,
|
|
187
|
-
i = function next() {
|
|
188
|
-
for (; ++o < e.length;) if (n.call(e, o)) return next.value = e[o], next.done = !1, next;
|
|
189
|
-
return next.value = t, next.done = !0, next;
|
|
190
|
-
};
|
|
191
|
-
return i.next = i;
|
|
192
|
-
}
|
|
193
|
-
}
|
|
194
|
-
throw new TypeError(typeof e + " is not iterable");
|
|
195
|
-
}
|
|
196
|
-
return GeneratorFunction.prototype = GeneratorFunctionPrototype, o(g, "constructor", {
|
|
197
|
-
value: GeneratorFunctionPrototype,
|
|
198
|
-
configurable: !0
|
|
199
|
-
}), o(GeneratorFunctionPrototype, "constructor", {
|
|
200
|
-
value: GeneratorFunction,
|
|
201
|
-
configurable: !0
|
|
202
|
-
}), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, u, "GeneratorFunction"), e.isGeneratorFunction = function (t) {
|
|
203
|
-
var e = "function" == typeof t && t.constructor;
|
|
204
|
-
return !!e && (e === GeneratorFunction || "GeneratorFunction" === (e.displayName || e.name));
|
|
205
|
-
}, e.mark = function (t) {
|
|
206
|
-
return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, define(t, u, "GeneratorFunction")), t.prototype = Object.create(g), t;
|
|
207
|
-
}, e.awrap = function (t) {
|
|
208
|
-
return {
|
|
209
|
-
__await: t
|
|
210
|
-
};
|
|
211
|
-
}, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () {
|
|
212
|
-
return this;
|
|
213
|
-
}), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) {
|
|
214
|
-
void 0 === i && (i = Promise);
|
|
215
|
-
var a = new AsyncIterator(wrap(t, r, n, o), i);
|
|
216
|
-
return e.isGeneratorFunction(r) ? a : a.next().then(function (t) {
|
|
217
|
-
return t.done ? t.value : a.next();
|
|
218
|
-
});
|
|
219
|
-
}, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () {
|
|
220
|
-
return this;
|
|
221
|
-
}), define(g, "toString", function () {
|
|
222
|
-
return "[object Generator]";
|
|
223
|
-
}), e.keys = function (t) {
|
|
224
|
-
var e = Object(t),
|
|
225
|
-
r = [];
|
|
226
|
-
for (var n in e) r.push(n);
|
|
227
|
-
return r.reverse(), function next() {
|
|
228
|
-
for (; r.length;) {
|
|
229
|
-
var t = r.pop();
|
|
230
|
-
if (t in e) return next.value = t, next.done = !1, next;
|
|
231
|
-
}
|
|
232
|
-
return next.done = !0, next;
|
|
233
|
-
};
|
|
234
|
-
}, e.values = values, Context.prototype = {
|
|
235
|
-
constructor: Context,
|
|
236
|
-
reset: function (e) {
|
|
237
|
-
if (this.prev = 0, this.next = 0, this.sent = this._sent = t, this.done = !1, this.delegate = null, this.method = "next", this.arg = t, this.tryEntries.forEach(resetTryEntry), !e) for (var r in this) "t" === r.charAt(0) && n.call(this, r) && !isNaN(+r.slice(1)) && (this[r] = t);
|
|
238
|
-
},
|
|
239
|
-
stop: function () {
|
|
240
|
-
this.done = !0;
|
|
241
|
-
var t = this.tryEntries[0].completion;
|
|
242
|
-
if ("throw" === t.type) throw t.arg;
|
|
243
|
-
return this.rval;
|
|
244
|
-
},
|
|
245
|
-
dispatchException: function (e) {
|
|
246
|
-
if (this.done) throw e;
|
|
247
|
-
var r = this;
|
|
248
|
-
function handle(n, o) {
|
|
249
|
-
return a.type = "throw", a.arg = e, r.next = n, o && (r.method = "next", r.arg = t), !!o;
|
|
250
|
-
}
|
|
251
|
-
for (var o = this.tryEntries.length - 1; o >= 0; --o) {
|
|
252
|
-
var i = this.tryEntries[o],
|
|
253
|
-
a = i.completion;
|
|
254
|
-
if ("root" === i.tryLoc) return handle("end");
|
|
255
|
-
if (i.tryLoc <= this.prev) {
|
|
256
|
-
var c = n.call(i, "catchLoc"),
|
|
257
|
-
u = n.call(i, "finallyLoc");
|
|
258
|
-
if (c && u) {
|
|
259
|
-
if (this.prev < i.catchLoc) return handle(i.catchLoc, !0);
|
|
260
|
-
if (this.prev < i.finallyLoc) return handle(i.finallyLoc);
|
|
261
|
-
} else if (c) {
|
|
262
|
-
if (this.prev < i.catchLoc) return handle(i.catchLoc, !0);
|
|
263
|
-
} else {
|
|
264
|
-
if (!u) throw new Error("try statement without catch or finally");
|
|
265
|
-
if (this.prev < i.finallyLoc) return handle(i.finallyLoc);
|
|
266
|
-
}
|
|
267
|
-
}
|
|
268
|
-
}
|
|
269
|
-
},
|
|
270
|
-
abrupt: function (t, e) {
|
|
271
|
-
for (var r = this.tryEntries.length - 1; r >= 0; --r) {
|
|
272
|
-
var o = this.tryEntries[r];
|
|
273
|
-
if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) {
|
|
274
|
-
var i = o;
|
|
275
|
-
break;
|
|
276
|
-
}
|
|
277
|
-
}
|
|
278
|
-
i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null);
|
|
279
|
-
var a = i ? i.completion : {};
|
|
280
|
-
return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a);
|
|
281
|
-
},
|
|
282
|
-
complete: function (t, e) {
|
|
283
|
-
if ("throw" === t.type) throw t.arg;
|
|
284
|
-
return "break" === t.type || "continue" === t.type ? this.next = t.arg : "return" === t.type ? (this.rval = this.arg = t.arg, this.method = "return", this.next = "end") : "normal" === t.type && e && (this.next = e), y;
|
|
285
|
-
},
|
|
286
|
-
finish: function (t) {
|
|
287
|
-
for (var e = this.tryEntries.length - 1; e >= 0; --e) {
|
|
288
|
-
var r = this.tryEntries[e];
|
|
289
|
-
if (r.finallyLoc === t) return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y;
|
|
290
|
-
}
|
|
291
|
-
},
|
|
292
|
-
catch: function (t) {
|
|
293
|
-
for (var e = this.tryEntries.length - 1; e >= 0; --e) {
|
|
294
|
-
var r = this.tryEntries[e];
|
|
295
|
-
if (r.tryLoc === t) {
|
|
296
|
-
var n = r.completion;
|
|
297
|
-
if ("throw" === n.type) {
|
|
298
|
-
var o = n.arg;
|
|
299
|
-
resetTryEntry(r);
|
|
300
|
-
}
|
|
301
|
-
return o;
|
|
302
|
-
}
|
|
303
|
-
}
|
|
304
|
-
throw new Error("illegal catch attempt");
|
|
305
|
-
},
|
|
306
|
-
delegateYield: function (e, r, n) {
|
|
307
|
-
return this.delegate = {
|
|
308
|
-
iterator: values(e),
|
|
309
|
-
resultName: r,
|
|
310
|
-
nextLoc: n
|
|
311
|
-
}, "next" === this.method && (this.arg = t), y;
|
|
312
|
-
}
|
|
313
|
-
}, e;
|
|
314
|
-
}
|
|
315
|
-
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
|
|
316
|
-
try {
|
|
317
|
-
var info = gen[key](arg);
|
|
318
|
-
var value = info.value;
|
|
319
|
-
} catch (error) {
|
|
320
|
-
reject(error);
|
|
321
|
-
return;
|
|
322
|
-
}
|
|
323
|
-
if (info.done) {
|
|
324
|
-
resolve(value);
|
|
325
|
-
} else {
|
|
326
|
-
Promise.resolve(value).then(_next, _throw);
|
|
327
|
-
}
|
|
328
|
-
}
|
|
329
|
-
function _asyncToGenerator(fn) {
|
|
330
|
-
return function () {
|
|
331
|
-
var self = this,
|
|
332
|
-
args = arguments;
|
|
333
|
-
return new Promise(function (resolve, reject) {
|
|
334
|
-
var gen = fn.apply(self, args);
|
|
335
|
-
function _next(value) {
|
|
336
|
-
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
|
|
337
|
-
}
|
|
338
|
-
function _throw(err) {
|
|
339
|
-
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
|
|
340
|
-
}
|
|
341
|
-
_next(undefined);
|
|
342
|
-
});
|
|
343
|
-
};
|
|
344
|
-
}
|
|
345
|
-
function _extends() {
|
|
346
|
-
_extends = Object.assign ? Object.assign.bind() : function (target) {
|
|
347
|
-
for (var i = 1; i < arguments.length; i++) {
|
|
348
|
-
var source = arguments[i];
|
|
349
|
-
for (var key in source) {
|
|
350
|
-
if (Object.prototype.hasOwnProperty.call(source, key)) {
|
|
351
|
-
target[key] = source[key];
|
|
352
|
-
}
|
|
353
|
-
}
|
|
354
|
-
}
|
|
355
|
-
return target;
|
|
356
|
-
};
|
|
357
|
-
return _extends.apply(this, arguments);
|
|
358
|
-
}
|
|
359
|
-
|
|
360
|
-
var DEFAULT_HOST = 'https://data.plasmic.app';
|
|
361
|
-
var UNAUTHORIZED_MESSAGE = 'You do not have permission to perform this operation. Login to get access or contact the app owner to get access.';
|
|
362
|
-
function executePlasmicDataOp(_x, _x2) {
|
|
363
|
-
return _executePlasmicDataOp2.apply(this, arguments);
|
|
364
|
-
}
|
|
365
|
-
function _executePlasmicDataOp2() {
|
|
366
|
-
_executePlasmicDataOp2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(op, opts) {
|
|
367
|
-
var func, res;
|
|
368
|
-
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
369
|
-
while (1) switch (_context.prev = _context.next) {
|
|
370
|
-
case 0:
|
|
371
|
-
func = getConfig('__PLASMIC_EXECUTE_DATA_OP', _executePlasmicDataOp);
|
|
372
|
-
_context.next = 3;
|
|
373
|
-
return query.wrapLoadingFetcher(func)(op, opts);
|
|
374
|
-
case 3:
|
|
375
|
-
res = _context.sent;
|
|
376
|
-
return _context.abrupt("return", res);
|
|
377
|
-
case 5:
|
|
378
|
-
case "end":
|
|
379
|
-
return _context.stop();
|
|
380
|
-
}
|
|
381
|
-
}, _callee);
|
|
382
|
-
}));
|
|
383
|
-
return _executePlasmicDataOp2.apply(this, arguments);
|
|
384
|
-
}
|
|
385
|
-
function _executePlasmicDataOp(_x3, _x4) {
|
|
386
|
-
return _executePlasmicDataOp3.apply(this, arguments);
|
|
387
|
-
}
|
|
388
|
-
function _executePlasmicDataOp3() {
|
|
389
|
-
_executePlasmicDataOp3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(op, opts) {
|
|
390
|
-
var _op$userArgs;
|
|
391
|
-
var host, url, resp, text;
|
|
392
|
-
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
393
|
-
while (1) switch (_context2.prev = _context2.next) {
|
|
394
|
-
case 0:
|
|
395
|
-
if (!op.roleId) {
|
|
396
|
-
_context2.next = 4;
|
|
397
|
-
break;
|
|
398
|
-
}
|
|
399
|
-
if (!(!(opts != null && opts.user) || !opts.user.roleIds.includes(op.roleId))) {
|
|
400
|
-
_context2.next = 4;
|
|
401
|
-
break;
|
|
402
|
-
}
|
|
403
|
-
console.error(UNAUTHORIZED_MESSAGE);
|
|
404
|
-
throw new Error(UNAUTHORIZED_MESSAGE);
|
|
405
|
-
case 4:
|
|
406
|
-
host = getConfig('__PLASMIC_DATA_HOST', DEFAULT_HOST);
|
|
407
|
-
url = host + "/api/v1/server-data/sources/" + op.sourceId + "/execute";
|
|
408
|
-
_context2.next = 8;
|
|
409
|
-
return fetch(url, {
|
|
410
|
-
method: 'POST',
|
|
411
|
-
headers: _extends({
|
|
412
|
-
'Content-Type': 'application/json'
|
|
413
|
-
}, (opts == null ? void 0 : opts.userAuthToken) && {
|
|
414
|
-
'x-plasmic-data-user-auth-token': opts.userAuthToken
|
|
415
|
-
}),
|
|
416
|
-
body: stringify({
|
|
417
|
-
opId: op.opId,
|
|
418
|
-
userArgs: (_op$userArgs = op.userArgs) != null ? _op$userArgs : {},
|
|
419
|
-
paginate: opts == null ? void 0 : opts.paginate
|
|
420
|
-
})
|
|
421
|
-
});
|
|
422
|
-
case 8:
|
|
423
|
-
resp = _context2.sent;
|
|
424
|
-
if (!(resp.status !== 200)) {
|
|
425
|
-
_context2.next = 14;
|
|
426
|
-
break;
|
|
427
|
-
}
|
|
428
|
-
_context2.next = 12;
|
|
429
|
-
return resp.text();
|
|
430
|
-
case 12:
|
|
431
|
-
text = _context2.sent;
|
|
432
|
-
throw new Error(text);
|
|
433
|
-
case 14:
|
|
434
|
-
_context2.next = 16;
|
|
435
|
-
return resp.json();
|
|
436
|
-
case 16:
|
|
437
|
-
return _context2.abrupt("return", _context2.sent);
|
|
438
|
-
case 17:
|
|
439
|
-
case "end":
|
|
440
|
-
return _context2.stop();
|
|
441
|
-
}
|
|
442
|
-
}, _callee2);
|
|
443
|
-
}));
|
|
444
|
-
return _executePlasmicDataOp3.apply(this, arguments);
|
|
445
|
-
}
|
|
446
|
-
function getConfig(key, defaultValue) {
|
|
447
|
-
if (typeof globalThis === 'undefined') {
|
|
448
|
-
return defaultValue;
|
|
449
|
-
} else {
|
|
450
|
-
var _globalThis$key;
|
|
451
|
-
return (_globalThis$key = globalThis[key]) != null ? _globalThis$key : defaultValue;
|
|
452
|
-
}
|
|
453
|
-
}
|
|
454
|
-
|
|
455
|
-
function swallow(f) {
|
|
456
|
-
try {
|
|
457
|
-
return f();
|
|
458
|
-
} catch (_unused) {
|
|
459
|
-
return undefined;
|
|
460
|
-
}
|
|
461
|
-
}
|
|
462
|
-
function pick(obj) {
|
|
463
|
-
var res = {};
|
|
464
|
-
for (var _len = arguments.length, keys = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
|
|
465
|
-
keys[_key - 1] = arguments[_key];
|
|
466
|
-
}
|
|
467
|
-
for (var _i = 0, _keys = keys; _i < _keys.length; _i++) {
|
|
468
|
-
var key = _keys[_i];
|
|
469
|
-
if (key in obj) {
|
|
470
|
-
res[key] = obj[key];
|
|
471
|
-
}
|
|
472
|
-
}
|
|
473
|
-
return res;
|
|
474
|
-
}
|
|
475
|
-
var tuple = function tuple() {
|
|
476
|
-
for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
|
|
477
|
-
args[_key2] = arguments[_key2];
|
|
478
|
-
}
|
|
479
|
-
return args;
|
|
480
|
-
};
|
|
481
|
-
function mkIdMap(xs) {
|
|
482
|
-
return new Map(xs.map(function (x) {
|
|
483
|
-
return tuple(x.id, x);
|
|
484
|
-
}));
|
|
485
|
-
}
|
|
486
|
-
function withoutNils(xs) {
|
|
487
|
-
return xs.filter(function (x) {
|
|
488
|
-
return x != null;
|
|
489
|
-
});
|
|
490
|
-
}
|
|
491
|
-
|
|
492
|
-
function makeCacheKey(dataOp, opts) {
|
|
493
|
-
var queryDependencies = JSON.stringify({
|
|
494
|
-
sourceId: dataOp.sourceId,
|
|
495
|
-
opId: dataOp.opId,
|
|
496
|
-
args: dataOp.userArgs,
|
|
497
|
-
userAuthToken: opts == null ? void 0 : opts.userAuthToken,
|
|
498
|
-
paginate: opts == null ? void 0 : opts.paginate
|
|
499
|
-
});
|
|
500
|
-
return dataOp.cacheKey ? "" + dataOp.cacheKey + queryDependencies : queryDependencies;
|
|
501
|
-
}
|
|
502
|
-
/**
|
|
503
|
-
* Returns a function that can be used to invalidate Plasmic query groups.
|
|
504
|
-
*/
|
|
505
|
-
function usePlasmicInvalidate() {
|
|
506
|
-
// NOTE: we use `revalidateIfStale: false` with SWR.
|
|
507
|
-
// One quirk of this is that if you supply fallback data to swr,
|
|
508
|
-
// that data doesn't get entered into the cache if `revalidateIfStale: false`,
|
|
509
|
-
// so you won't see it if you iterate over keys of the cache. That's why
|
|
510
|
-
// we have usePlasmicInvalidate() which will iterate over both the cache
|
|
511
|
-
// and the fallback data.
|
|
512
|
-
var _usePlasmicDataConfig = query.usePlasmicDataConfig(),
|
|
513
|
-
cache = _usePlasmicDataConfig.cache,
|
|
514
|
-
fallback = _usePlasmicDataConfig.fallback,
|
|
515
|
-
mutate = _usePlasmicDataConfig.mutate;
|
|
516
|
-
return /*#__PURE__*/function () {
|
|
517
|
-
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(invalidatedKeys) {
|
|
518
|
-
var getKeysToInvalidate, keys, invalidateKey;
|
|
519
|
-
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
520
|
-
while (1) switch (_context2.prev = _context2.next) {
|
|
521
|
-
case 0:
|
|
522
|
-
getKeysToInvalidate = function getKeysToInvalidate() {
|
|
523
|
-
if (!invalidatedKeys) {
|
|
524
|
-
return [];
|
|
525
|
-
}
|
|
526
|
-
var allKeys = Array.from(new Set([].concat(Array.from(cache.keys()), fallback ? Object.keys(fallback) : []))).filter(function (key) {
|
|
527
|
-
return typeof key === 'string';
|
|
528
|
-
});
|
|
529
|
-
if (invalidatedKeys.includes('plasmic_refresh_all')) {
|
|
530
|
-
return allKeys;
|
|
531
|
-
}
|
|
532
|
-
return allKeys.filter(function (key) {
|
|
533
|
-
return invalidatedKeys.some(function (k) {
|
|
534
|
-
return key.includes(".$." + k + ".$.");
|
|
535
|
-
});
|
|
536
|
-
});
|
|
537
|
-
};
|
|
538
|
-
keys = getKeysToInvalidate();
|
|
539
|
-
if (!(keys.length === 0)) {
|
|
540
|
-
_context2.next = 4;
|
|
541
|
-
break;
|
|
542
|
-
}
|
|
543
|
-
return _context2.abrupt("return");
|
|
544
|
-
case 4:
|
|
545
|
-
invalidateKey = /*#__PURE__*/function () {
|
|
546
|
-
var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(key) {
|
|
547
|
-
var studioInvalidate;
|
|
548
|
-
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
549
|
-
while (1) switch (_context.prev = _context.next) {
|
|
550
|
-
case 0:
|
|
551
|
-
studioInvalidate = globalThis.__PLASMIC_MUTATE_DATA_OP;
|
|
552
|
-
if (!studioInvalidate) {
|
|
553
|
-
_context.next = 4;
|
|
554
|
-
break;
|
|
555
|
-
}
|
|
556
|
-
_context.next = 4;
|
|
557
|
-
return studioInvalidate(key);
|
|
558
|
-
case 4:
|
|
559
|
-
return _context.abrupt("return", mutate(key));
|
|
560
|
-
case 5:
|
|
561
|
-
case "end":
|
|
562
|
-
return _context.stop();
|
|
563
|
-
}
|
|
564
|
-
}, _callee);
|
|
565
|
-
}));
|
|
566
|
-
return function invalidateKey(_x2) {
|
|
567
|
-
return _ref2.apply(this, arguments);
|
|
568
|
-
};
|
|
569
|
-
}();
|
|
570
|
-
_context2.next = 7;
|
|
571
|
-
return Promise.all(keys.map(function (key) {
|
|
572
|
-
return invalidateKey(key);
|
|
573
|
-
}));
|
|
574
|
-
case 7:
|
|
575
|
-
return _context2.abrupt("return", _context2.sent);
|
|
576
|
-
case 8:
|
|
577
|
-
case "end":
|
|
578
|
-
return _context2.stop();
|
|
579
|
-
}
|
|
580
|
-
}, _callee2);
|
|
581
|
-
}));
|
|
582
|
-
return function (_x) {
|
|
583
|
-
return _ref.apply(this, arguments);
|
|
584
|
-
};
|
|
585
|
-
}();
|
|
586
|
-
}
|
|
587
|
-
var enableLoadingBoundaryKey = 'plasmicInternalEnableLoadingBoundary';
|
|
588
|
-
function mkUndefinedDataProxy(promiseRef, fetchAndUpdateCache) {
|
|
589
|
-
var fetchAndUpdatePromise = undefined;
|
|
590
|
-
return new Proxy({}, {
|
|
591
|
-
get: function get(_target, prop) {
|
|
592
|
-
if (prop === 'isPlasmicUndefinedDataProxy') {
|
|
593
|
-
return true;
|
|
594
|
-
}
|
|
595
|
-
if (!fetchAndUpdateCache) {
|
|
596
|
-
// There's no key so no fetch to kick off yet; when computing key,
|
|
597
|
-
// we encountered some thrown exception (that's not an undefined data promise),
|
|
598
|
-
// and so we can't fetch yet. This might be dependent on a $state or $prop value
|
|
599
|
-
// that's currently undefined, etc. We will act like an undefined data object,
|
|
600
|
-
// and trigger the usual fallback behavior
|
|
601
|
-
return undefined;
|
|
602
|
-
}
|
|
603
|
-
var doFetchAndUpdate = function doFetchAndUpdate() {
|
|
604
|
-
// We hold onto the promise last returned by fetchAndUpdateCache()
|
|
605
|
-
// and keep reusing it until it is resolved. The reason is that the
|
|
606
|
-
// Promise thrown here will be used as a dependency for memoized
|
|
607
|
-
// fetchAndUpdateCache, which is a dependency on the memoized returned value
|
|
608
|
-
// from usePlasmicDataOp(). If we have a fetch that's taking a long time,
|
|
609
|
-
// we want to make sure that our memoized returned value is stable,
|
|
610
|
-
// so that we don't keep calling setDollarQueries() (otherwise, for each
|
|
611
|
-
// render, we find an unstable result, and call setDollarQueries(),
|
|
612
|
-
// resulting in an infinite loop while fetch is happening).
|
|
613
|
-
if (!fetchAndUpdatePromise) {
|
|
614
|
-
fetchAndUpdatePromise = fetchAndUpdateCache()["finally"](function () {
|
|
615
|
-
fetchAndUpdatePromise = undefined;
|
|
616
|
-
});
|
|
617
|
-
}
|
|
618
|
-
return fetchAndUpdatePromise;
|
|
619
|
-
};
|
|
620
|
-
var promise =
|
|
621
|
-
// existing fetch
|
|
622
|
-
promiseRef.fetchingPromise ||
|
|
623
|
-
// No existing fetch, so kick off a fetch
|
|
624
|
-
doFetchAndUpdate();
|
|
625
|
-
promise.plasmicType = 'PlasmicUndefinedDataError';
|
|
626
|
-
promise.message = "Cannot read property " + String(prop) + " - data is still loading";
|
|
627
|
-
throw promise;
|
|
628
|
-
}
|
|
629
|
-
});
|
|
630
|
-
}
|
|
631
|
-
function isPlasmicUndefinedDataErrorPromise(x) {
|
|
632
|
-
return !!x && typeof x === 'object' && x.plasmicType === 'PlasmicUndefinedDataError';
|
|
633
|
-
}
|
|
634
|
-
var reactMajorVersion = + /*#__PURE__*/React.version.split('.')[0];
|
|
635
|
-
/**
|
|
636
|
-
* This returns either:
|
|
637
|
-
* * DataOp to perform
|
|
638
|
-
* * undefined/null, if no data op can be performed
|
|
639
|
-
* * PlasmicUndefinedDataErrorPromise, if when trying to evaluate the DataOp to perform,
|
|
640
|
-
* we encounter a PlasmicUndefinedDataErrorPromise, so this operation cannot be
|
|
641
|
-
* performed until that promise is resolved.
|
|
642
|
-
*/
|
|
643
|
-
function resolveDataOp(dataOp) {
|
|
644
|
-
if (typeof dataOp === 'function') {
|
|
645
|
-
try {
|
|
646
|
-
return dataOp();
|
|
647
|
-
} catch (err) {
|
|
648
|
-
if (isPlasmicUndefinedDataErrorPromise(err)) {
|
|
649
|
-
return err;
|
|
650
|
-
}
|
|
651
|
-
return null;
|
|
652
|
-
}
|
|
653
|
-
} else {
|
|
654
|
-
return dataOp;
|
|
655
|
-
}
|
|
656
|
-
}
|
|
657
|
-
/**
|
|
658
|
-
* Fetches can be kicked off two ways -- normally, by useSWR(), or by some
|
|
659
|
-
* expression accessing the `$queries.*` proxy when not ready yet. We need
|
|
660
|
-
* a global cache for proxy-invoked caches, so that different components
|
|
661
|
-
* with the same key can share the same fetch.
|
|
662
|
-
*
|
|
663
|
-
* The life cycle for this cache is short -- only the duration of a
|
|
664
|
-
* proxy-invoked fetch, and once the fetch is done. That's because we really
|
|
665
|
-
* just want SWR to be managing the cache, not us! Once the data is in SWR,
|
|
666
|
-
* we will use SWR for getting data.
|
|
667
|
-
*/
|
|
668
|
-
var PRE_FETCHES = /*#__PURE__*/new Map();
|
|
669
|
-
function usePlasmicDataOp(dataOp, opts) {
|
|
670
|
-
var _ph$useDataEnv;
|
|
671
|
-
var resolvedDataOp = resolveDataOp(dataOp);
|
|
672
|
-
var ctx = dataSourcesContext.usePlasmicDataSourceContext();
|
|
673
|
-
var enableLoadingBoundary = !!(ph.useDataEnv != null && (_ph$useDataEnv = ph.useDataEnv()) != null && _ph$useDataEnv[enableLoadingBoundaryKey]);
|
|
674
|
-
var _usePlasmicDataConfig2 = query.usePlasmicDataConfig(),
|
|
675
|
-
mutate = _usePlasmicDataConfig2.mutate,
|
|
676
|
-
cache = _usePlasmicDataConfig2.cache;
|
|
677
|
-
// Cannot perform this operation
|
|
678
|
-
var isNullDataOp = !resolvedDataOp;
|
|
679
|
-
// This operation depends on another data query to resolve first
|
|
680
|
-
var isWaitingOnDependentQuery = isPlasmicUndefinedDataErrorPromise(resolvedDataOp);
|
|
681
|
-
var key = !resolvedDataOp || isPlasmicUndefinedDataErrorPromise(resolvedDataOp) ? null : makeCacheKey(resolvedDataOp, {
|
|
682
|
-
paginate: opts == null ? void 0 : opts.paginate,
|
|
683
|
-
userAuthToken: ctx == null ? void 0 : ctx.userAuthToken
|
|
684
|
-
});
|
|
685
|
-
var fetchingData = React.useMemo(function () {
|
|
686
|
-
return {
|
|
687
|
-
fetchingPromise: undefined
|
|
688
|
-
};
|
|
689
|
-
}, [key]);
|
|
690
|
-
var fetcher = React.useMemo(function () {
|
|
691
|
-
return function () {
|
|
692
|
-
// If we are in this function, that means SWR cache missed.
|
|
693
|
-
if (!key) {
|
|
694
|
-
throw new Error("Fetcher should never be called without a proper key");
|
|
695
|
-
}
|
|
696
|
-
// dataOp is guaranteed to be a DataOp, and not an undefined promise or null
|
|
697
|
-
if (fetchingData.fetchingPromise) {
|
|
698
|
-
// Fetch is already underway from this hook
|
|
699
|
-
return fetchingData.fetchingPromise;
|
|
700
|
-
}
|
|
701
|
-
if (key && PRE_FETCHES.has(key)) {
|
|
702
|
-
// Some other usePlasmicDataOp() hook elsewhere has already
|
|
703
|
-
// started this fetch as well; re-use it here.
|
|
704
|
-
var existing = PRE_FETCHES.get(key);
|
|
705
|
-
fetchingData.fetchingPromise = existing;
|
|
706
|
-
return existing;
|
|
707
|
-
}
|
|
708
|
-
// Else we really need to kick off this fetch now...
|
|
709
|
-
var fetcherFn = function fetcherFn() {
|
|
710
|
-
return executePlasmicDataOp(resolvedDataOp, {
|
|
711
|
-
userAuthToken: (ctx == null ? void 0 : ctx.userAuthToken) || undefined,
|
|
712
|
-
user: ctx == null ? void 0 : ctx.user,
|
|
713
|
-
paginate: opts == null ? void 0 : opts.paginate
|
|
714
|
-
});
|
|
715
|
-
};
|
|
716
|
-
var fetcherPromise = fetcherFn();
|
|
717
|
-
fetchingData.fetchingPromise = fetcherPromise;
|
|
718
|
-
if (key) {
|
|
719
|
-
PRE_FETCHES.set(key, fetcherPromise);
|
|
720
|
-
// Once we have a result, we rely on swr to perform the caching,
|
|
721
|
-
// so remove from our cache as quickly as possible.
|
|
722
|
-
fetcherPromise.then(function () {
|
|
723
|
-
PRE_FETCHES["delete"](key);
|
|
724
|
-
}, function () {
|
|
725
|
-
PRE_FETCHES["delete"](key);
|
|
726
|
-
});
|
|
727
|
-
}
|
|
728
|
-
return fetcherPromise;
|
|
729
|
-
};
|
|
730
|
-
}, [key, fetchingData]);
|
|
731
|
-
var dependentKeyDataErrorPromise = isPlasmicUndefinedDataErrorPromise(resolvedDataOp) ? resolvedDataOp : undefined;
|
|
732
|
-
var fetchAndUpdateCache = React.useMemo(function () {
|
|
733
|
-
if (!key && !dependentKeyDataErrorPromise) {
|
|
734
|
-
// If there's no key, and no data query we're waiting for, then there's
|
|
735
|
-
// no way to perform a fetch
|
|
736
|
-
return undefined;
|
|
737
|
-
}
|
|
738
|
-
return function () {
|
|
739
|
-
// This function is called when the undefined data proxy is invoked.
|
|
740
|
-
// USUALLY, this means the data is not available in SWR yet, and
|
|
741
|
-
// we need to kick off a fetch.
|
|
742
|
-
if (fetchingData.fetchingPromise) {
|
|
743
|
-
// No need to update cache as the exist promise call site will do it
|
|
744
|
-
return fetchingData.fetchingPromise;
|
|
745
|
-
}
|
|
746
|
-
if (dependentKeyDataErrorPromise) {
|
|
747
|
-
// We can't actually fetch yet, because we couldn't even evaluate the dataOp
|
|
748
|
-
// to fetch for, because we depend on unfetched data. Once _that_
|
|
749
|
-
// dataOp we depend on is finished, then we can try again. So we
|
|
750
|
-
// will throw and wait for _that_ promise to be resolved instead.
|
|
751
|
-
return dependentKeyDataErrorPromise;
|
|
752
|
-
}
|
|
753
|
-
if (!key) {
|
|
754
|
-
throw new Error("Expected key to be non-null");
|
|
755
|
-
}
|
|
756
|
-
// SOMETIMES, SWR actually _does_ have the cache, but we still end up
|
|
757
|
-
// here. That's because of how we update $queries, which takes two
|
|
758
|
-
// cycles; each time we render, we build a `new$Queries`, and
|
|
759
|
-
// `set$Queries(new$Queries)`. So once the data is ready, at the
|
|
760
|
-
// first render, we will have data in `new$Queries` but not `$queries`,
|
|
761
|
-
// but we will still finish rendering that pass, which means any `$queries`
|
|
762
|
-
// access will still end up here. So we look into the SWR cache and
|
|
763
|
-
// return any data that's here.
|
|
764
|
-
var cached = cache.get(key);
|
|
765
|
-
if (cached) {
|
|
766
|
-
return Promise.resolve(cached);
|
|
767
|
-
}
|
|
768
|
-
var cachedError = cache.get("$swr$" + key);
|
|
769
|
-
if (cachedError) {
|
|
770
|
-
return Promise.reject(cachedError.error);
|
|
771
|
-
}
|
|
772
|
-
// Now, upon this proxy.get() miss, we want to kick off the fetch. We can't
|
|
773
|
-
// wait for useSWR() to kick off the fetch, because upon data miss we are
|
|
774
|
-
// throwing a promise, and useSWR() won't kick off the fetch till the effect,
|
|
775
|
-
// so it will never get a chance to fetch. Instead, we fetch, and then we
|
|
776
|
-
// put the fetched data into the SWR cache, so that next time useSWR() is called,
|
|
777
|
-
// it will just find it in the cache.
|
|
778
|
-
//
|
|
779
|
-
// However, we don't want to fetch SYNCHRONOUSLY RIGHT NOW, becase we are in
|
|
780
|
-
// the rendering phase (presumably, we're here because some component is trying
|
|
781
|
-
// to read fetched data while rendering). Doing a fetch right now would invoke
|
|
782
|
-
// the fetcher, which is wrapped by @plasmicapp/query to tracking loading state,
|
|
783
|
-
// and upon loading state toggled to true, it will fire loading event listeners,
|
|
784
|
-
// and for example, our antd's <GlobalLoadingIndicator /> will listen to this
|
|
785
|
-
// event and immediately ask antd to show the loading indicator, which mutates
|
|
786
|
-
// antd component's state. It is NOT LEGAL to call setState() on some other
|
|
787
|
-
// component's state during rendering phase!
|
|
788
|
-
//
|
|
789
|
-
// We therefore will delay kicking off the fetch by a tick, so that we will safely
|
|
790
|
-
// start the fetch outside of React rendering phase.
|
|
791
|
-
var fetcherPromise = new Promise(function (resolve, reject) {
|
|
792
|
-
setTimeout(function () {
|
|
793
|
-
fetcher().then(resolve, reject);
|
|
794
|
-
}, 1);
|
|
795
|
-
});
|
|
796
|
-
fetcherPromise.then(function (data) {
|
|
797
|
-
// Insert the fetched data into the SWR cache
|
|
798
|
-
mutate(key, data);
|
|
799
|
-
})["catch"](function (err) {
|
|
800
|
-
var _cache$get;
|
|
801
|
-
// Cache the error here to avoid infinite loop
|
|
802
|
-
var keyInfo = key ? '$swr$' + key : '';
|
|
803
|
-
cache.set(keyInfo, _extends({}, (_cache$get = cache.get(keyInfo)) != null ? _cache$get : {}, {
|
|
804
|
-
error: err
|
|
805
|
-
}));
|
|
806
|
-
});
|
|
807
|
-
return fetcherPromise;
|
|
808
|
-
};
|
|
809
|
-
}, [fetcher, fetchingData, cache, key, dependentKeyDataErrorPromise]);
|
|
810
|
-
var res = query.useMutablePlasmicQueryData(key, fetcher, {
|
|
811
|
-
shouldRetryOnError: false,
|
|
812
|
-
// If revalidateIfStale is true, then if there's a cache entry with a key,
|
|
813
|
-
// but no mounted hook with that key yet, and when the hook mounts with the key,
|
|
814
|
-
// swr will revalidate. This may be reasonable behavior, but for us, this
|
|
815
|
-
// happens all the time -- we prepopulate the cache with proxy-invoked fetch,
|
|
816
|
-
// sometimes before swr had a chance to run the effect. So we turn off
|
|
817
|
-
// revalidateIfStale here, and just let the user manage invalidation.
|
|
818
|
-
revalidateIfStale: false
|
|
819
|
-
});
|
|
820
|
-
var data = res.data,
|
|
821
|
-
error = res.error,
|
|
822
|
-
isLoading = res.isLoading;
|
|
823
|
-
if (fetchingData.fetchingPromise != null && data !== undefined) {
|
|
824
|
-
// Clear the fetching promise as the actual data is now used (so
|
|
825
|
-
// revalidation is possible)
|
|
826
|
-
fetchingData.fetchingPromise = undefined;
|
|
827
|
-
}
|
|
828
|
-
return React.useMemo(function () {
|
|
829
|
-
var result = _extends({}, data != null ? data : {}, pick(res, 'isLoading', 'error'));
|
|
830
|
-
if (!(opts != null && opts.noUndefinedDataProxy) && reactMajorVersion >= 18 && enableLoadingBoundary && (isLoading || isNullDataOp || isWaitingOnDependentQuery) && result.data === undefined && result.schema === undefined && result.error === undefined) {
|
|
831
|
-
result.data = mkUndefinedDataProxy(fetchingData, fetchAndUpdateCache);
|
|
832
|
-
result.schema = mkUndefinedDataProxy(fetchingData, fetchAndUpdateCache);
|
|
833
|
-
}
|
|
834
|
-
return result;
|
|
835
|
-
}, [isNullDataOp, isWaitingOnDependentQuery, data, error, isLoading, opts == null ? void 0 : opts.noUndefinedDataProxy, enableLoadingBoundary, fetchingData, fetchAndUpdateCache]);
|
|
836
|
-
}
|
|
837
|
-
function usePlasmicDataMutationOp(dataOp) {
|
|
838
|
-
var ctx = dataSourcesContext.usePlasmicDataSourceContext();
|
|
839
|
-
var userToken = ctx == null ? void 0 : ctx.userAuthToken;
|
|
840
|
-
var getRealDataOp = React.useCallback( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4() {
|
|
841
|
-
var tryGetRealDataOp;
|
|
842
|
-
return _regeneratorRuntime().wrap(function _callee4$(_context4) {
|
|
843
|
-
while (1) switch (_context4.prev = _context4.next) {
|
|
844
|
-
case 0:
|
|
845
|
-
tryGetRealDataOp = /*#__PURE__*/function () {
|
|
846
|
-
var _ref4 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3() {
|
|
847
|
-
var resolved;
|
|
848
|
-
return _regeneratorRuntime().wrap(function _callee3$(_context3) {
|
|
849
|
-
while (1) switch (_context3.prev = _context3.next) {
|
|
850
|
-
case 0:
|
|
851
|
-
resolved = resolveDataOp(dataOp);
|
|
852
|
-
if (resolved) {
|
|
853
|
-
_context3.next = 5;
|
|
854
|
-
break;
|
|
855
|
-
}
|
|
856
|
-
return _context3.abrupt("return", null);
|
|
857
|
-
case 5:
|
|
858
|
-
if (!isPlasmicUndefinedDataErrorPromise(resolved)) {
|
|
859
|
-
_context3.next = 11;
|
|
860
|
-
break;
|
|
861
|
-
}
|
|
862
|
-
_context3.next = 8;
|
|
863
|
-
return resolved;
|
|
864
|
-
case 8:
|
|
865
|
-
return _context3.abrupt("return", tryGetRealDataOp());
|
|
866
|
-
case 11:
|
|
867
|
-
return _context3.abrupt("return", resolved);
|
|
868
|
-
case 12:
|
|
869
|
-
case "end":
|
|
870
|
-
return _context3.stop();
|
|
871
|
-
}
|
|
872
|
-
}, _callee3);
|
|
873
|
-
}));
|
|
874
|
-
return function tryGetRealDataOp() {
|
|
875
|
-
return _ref4.apply(this, arguments);
|
|
876
|
-
};
|
|
877
|
-
}();
|
|
878
|
-
_context4.next = 3;
|
|
879
|
-
return tryGetRealDataOp();
|
|
880
|
-
case 3:
|
|
881
|
-
return _context4.abrupt("return", _context4.sent);
|
|
882
|
-
case 4:
|
|
883
|
-
case "end":
|
|
884
|
-
return _context4.stop();
|
|
885
|
-
}
|
|
886
|
-
}, _callee4);
|
|
887
|
-
})), [dataOp]);
|
|
888
|
-
return React.useCallback( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5() {
|
|
889
|
-
var _yield$getRealDataOp;
|
|
890
|
-
var _ref6, sourceId, opId, userArgs;
|
|
891
|
-
return _regeneratorRuntime().wrap(function _callee5$(_context5) {
|
|
892
|
-
while (1) switch (_context5.prev = _context5.next) {
|
|
893
|
-
case 0:
|
|
894
|
-
_context5.next = 2;
|
|
895
|
-
return getRealDataOp();
|
|
896
|
-
case 2:
|
|
897
|
-
_context5.t0 = _yield$getRealDataOp = _context5.sent;
|
|
898
|
-
if (!(_context5.t0 != null)) {
|
|
899
|
-
_context5.next = 7;
|
|
900
|
-
break;
|
|
901
|
-
}
|
|
902
|
-
_context5.t1 = _yield$getRealDataOp;
|
|
903
|
-
_context5.next = 8;
|
|
904
|
-
break;
|
|
905
|
-
case 7:
|
|
906
|
-
_context5.t1 = {};
|
|
907
|
-
case 8:
|
|
908
|
-
_ref6 = _context5.t1;
|
|
909
|
-
sourceId = _ref6.sourceId;
|
|
910
|
-
opId = _ref6.opId;
|
|
911
|
-
userArgs = _ref6.userArgs;
|
|
912
|
-
if (!(!sourceId || !opId)) {
|
|
913
|
-
_context5.next = 14;
|
|
914
|
-
break;
|
|
915
|
-
}
|
|
916
|
-
return _context5.abrupt("return", undefined);
|
|
917
|
-
case 14:
|
|
918
|
-
return _context5.abrupt("return", executePlasmicDataOp({
|
|
919
|
-
sourceId: sourceId,
|
|
920
|
-
opId: opId,
|
|
921
|
-
userArgs: userArgs
|
|
922
|
-
}, {
|
|
923
|
-
userAuthToken: userToken || undefined,
|
|
924
|
-
user: ctx == null ? void 0 : ctx.user
|
|
925
|
-
}));
|
|
926
|
-
case 15:
|
|
927
|
-
case "end":
|
|
928
|
-
return _context5.stop();
|
|
929
|
-
}
|
|
930
|
-
}, _callee5);
|
|
931
|
-
})), [getRealDataOp, userToken]);
|
|
932
|
-
}
|
|
933
|
-
|
|
934
|
-
function Fetcher(props) {
|
|
935
|
-
var _children;
|
|
936
|
-
var dataOp = props.dataOp,
|
|
937
|
-
children = props.children,
|
|
938
|
-
name = props.name,
|
|
939
|
-
pageIndex = props.pageIndex,
|
|
940
|
-
pageSize = props.pageSize;
|
|
941
|
-
var data = usePlasmicDataOp(dataOp, _extends({}, !!pageIndex && !!pageSize && {
|
|
942
|
-
paginate: {
|
|
943
|
-
pageIndex: pageIndex,
|
|
944
|
-
pageSize: pageSize
|
|
945
|
-
}
|
|
946
|
-
}));
|
|
947
|
-
var $queries = React.useMemo(function () {
|
|
948
|
-
var _extends2;
|
|
949
|
-
return _extends({}, props.queries, (_extends2 = {}, _extends2[name != null ? name : 'data'] = data, _extends2));
|
|
950
|
-
}, [props.queries, name, data]);
|
|
951
|
-
return (_children = children == null ? void 0 : children($queries)) != null ? _children : null;
|
|
952
|
-
}
|
|
953
|
-
var FetcherMeta = {
|
|
954
|
-
name: 'plasmic-data-source-fetcher',
|
|
955
|
-
displayName: 'Data Fetcher',
|
|
956
|
-
props: {
|
|
957
|
-
dataOp: {
|
|
958
|
-
type: 'dataSourceOp',
|
|
959
|
-
displayName: 'Data'
|
|
960
|
-
},
|
|
961
|
-
name: {
|
|
962
|
-
type: 'string',
|
|
963
|
-
displayName: 'Variable name'
|
|
964
|
-
},
|
|
965
|
-
children: {
|
|
966
|
-
type: 'slot',
|
|
967
|
-
renderPropParams: ['$queries']
|
|
968
|
-
},
|
|
969
|
-
pageSize: {
|
|
970
|
-
type: 'number',
|
|
971
|
-
advanced: true,
|
|
972
|
-
displayName: 'Page size',
|
|
973
|
-
description: 'Only fetch in batches of this size; for pagination'
|
|
974
|
-
},
|
|
975
|
-
pageIndex: {
|
|
976
|
-
type: 'number',
|
|
977
|
-
advanced: true,
|
|
978
|
-
displayName: 'Page index',
|
|
979
|
-
description: '0-based index of the paginated page to fetch'
|
|
980
|
-
}
|
|
981
|
-
},
|
|
982
|
-
importPath: '@plasmicapp/react-web/lib/data-sources',
|
|
983
|
-
importName: 'Fetcher',
|
|
984
|
-
alwaysAutoName: true,
|
|
985
|
-
styleSections: false
|
|
986
|
-
};
|
|
987
|
-
|
|
988
|
-
function normalizeData(rawData) {
|
|
989
|
-
var _rawData$schema;
|
|
990
|
-
if (!rawData) {
|
|
991
|
-
return undefined;
|
|
992
|
-
}
|
|
993
|
-
var dataArray = tryGetDataArray(rawData);
|
|
994
|
-
if (!dataArray) {
|
|
995
|
-
return undefined;
|
|
996
|
-
}
|
|
997
|
-
var schema = (_rawData$schema = rawData.schema) != null ? _rawData$schema : tryGetSchema(dataArray);
|
|
998
|
-
if (!schema) {
|
|
999
|
-
return undefined;
|
|
1000
|
-
}
|
|
1001
|
-
return {
|
|
1002
|
-
data: dataArray,
|
|
1003
|
-
schema: schema
|
|
1004
|
-
};
|
|
1005
|
-
}
|
|
1006
|
-
function tryGetDataArray(rawData) {
|
|
1007
|
-
if (rawData == null || typeof rawData !== 'object') {
|
|
1008
|
-
return undefined;
|
|
1009
|
-
}
|
|
1010
|
-
if (Array.isArray(rawData)) {
|
|
1011
|
-
if (isArrayOfObjects(rawData)) {
|
|
1012
|
-
return rawData;
|
|
1013
|
-
} else {
|
|
1014
|
-
// TODO: array of primitives? Maybe we can wrap this?
|
|
1015
|
-
return undefined;
|
|
1016
|
-
}
|
|
1017
|
-
}
|
|
1018
|
-
if (rawData == null) {
|
|
1019
|
-
return undefined;
|
|
1020
|
-
}
|
|
1021
|
-
if ('data' in rawData && typeof rawData.data === 'object') {
|
|
1022
|
-
if (Array.isArray(rawData.data) && isArrayOfObjects(rawData.data)) {
|
|
1023
|
-
return rawData.data;
|
|
1024
|
-
} else if (rawData.data != null) {
|
|
1025
|
-
return [rawData.data];
|
|
1026
|
-
} else {
|
|
1027
|
-
return undefined;
|
|
1028
|
-
}
|
|
1029
|
-
}
|
|
1030
|
-
if ('isLoading' in rawData || 'error' in rawData) {
|
|
1031
|
-
return undefined;
|
|
1032
|
-
}
|
|
1033
|
-
// Maybe a singleton record?
|
|
1034
|
-
return [rawData];
|
|
1035
|
-
}
|
|
1036
|
-
function isArrayOfObjects(arr) {
|
|
1037
|
-
return arr.every(function (x) {
|
|
1038
|
-
return typeof x === 'object' && !Array.isArray(x);
|
|
1039
|
-
});
|
|
1040
|
-
}
|
|
1041
|
-
function tryGetSchema(data) {
|
|
1042
|
-
var fieldMap = {};
|
|
1043
|
-
data.forEach(function (entry) {
|
|
1044
|
-
if (entry && typeof entry === 'object') {
|
|
1045
|
-
Array.from(Object.entries(entry)).forEach(function (_ref) {
|
|
1046
|
-
var k = _ref[0],
|
|
1047
|
-
v = _ref[1];
|
|
1048
|
-
var inferredType = typeof v === 'string' ? 'string' : typeof v === 'boolean' ? 'boolean' : typeof v === 'number' ? 'number' : 'unknown';
|
|
1049
|
-
if (fieldMap[k] && fieldMap[k] !== inferredType) {
|
|
1050
|
-
fieldMap[k] = 'unknown';
|
|
1051
|
-
} else {
|
|
1052
|
-
fieldMap[k] = inferredType;
|
|
1053
|
-
}
|
|
1054
|
-
});
|
|
1055
|
-
}
|
|
1056
|
-
});
|
|
1057
|
-
return {
|
|
1058
|
-
id: 'inferred',
|
|
1059
|
-
fields: Object.entries(fieldMap).map(function (_ref2) {
|
|
1060
|
-
var f = _ref2[0],
|
|
1061
|
-
t = _ref2[1];
|
|
1062
|
-
return {
|
|
1063
|
-
id: f,
|
|
1064
|
-
type: t,
|
|
1065
|
-
readOnly: false
|
|
1066
|
-
};
|
|
1067
|
-
})
|
|
1068
|
-
};
|
|
1069
|
-
}
|
|
1070
|
-
var mkShortId = function mkShortId() {
|
|
1071
|
-
return "" + Math.random();
|
|
1072
|
-
};
|
|
1073
|
-
function deriveFieldConfigs(specifiedFieldsPartial, schema, makeDefaultConfig) {
|
|
1074
|
-
var _schema$fields;
|
|
1075
|
-
var schemaFields = (_schema$fields = schema == null ? void 0 : schema.fields) != null ? _schema$fields : [];
|
|
1076
|
-
var fieldById = mkIdMap(schemaFields);
|
|
1077
|
-
var specifiedFieldIds = new Set(withoutNils(specifiedFieldsPartial.map(function (f) {
|
|
1078
|
-
return f.fieldId;
|
|
1079
|
-
})));
|
|
1080
|
-
var keptSpecifiedFields = specifiedFieldsPartial.flatMap(function (f) {
|
|
1081
|
-
if (!f.fieldId) {
|
|
1082
|
-
return [_extends({
|
|
1083
|
-
key: mkShortId()
|
|
1084
|
-
}, makeDefaultConfig(undefined), f)];
|
|
1085
|
-
}
|
|
1086
|
-
var field = fieldById.get(f.fieldId);
|
|
1087
|
-
// Drop configs with fieldIds no longer in the data.
|
|
1088
|
-
if (!field) {
|
|
1089
|
-
return [];
|
|
1090
|
-
}
|
|
1091
|
-
return [_extends({
|
|
1092
|
-
key: mkShortId()
|
|
1093
|
-
}, makeDefaultConfig(field), f)];
|
|
1094
|
-
});
|
|
1095
|
-
var newVirtualFields = schemaFields.filter(function (f) {
|
|
1096
|
-
return !specifiedFieldIds.has(f.id);
|
|
1097
|
-
}).map(function (f) {
|
|
1098
|
-
return _extends({
|
|
1099
|
-
key: mkShortId()
|
|
1100
|
-
}, makeDefaultConfig(f));
|
|
1101
|
-
});
|
|
1102
|
-
var mergedFields = [].concat(keptSpecifiedFields, newVirtualFields);
|
|
1103
|
-
var minimalFullLengthFields = [].concat(specifiedFieldsPartial, newVirtualFields.map(function (f) {
|
|
1104
|
-
return {
|
|
1105
|
-
key: f.key,
|
|
1106
|
-
fieldId: f.fieldId
|
|
1107
|
-
};
|
|
1108
|
-
}));
|
|
1109
|
-
return {
|
|
1110
|
-
mergedFields: mergedFields,
|
|
1111
|
-
minimalFullLengthFields: minimalFullLengthFields
|
|
1112
|
-
};
|
|
1113
|
-
}
|
|
1114
|
-
|
|
1115
|
-
function usePrevious(value) {
|
|
1116
|
-
var prevValue = React.useRef(undefined);
|
|
1117
|
-
React.useEffect(function () {
|
|
1118
|
-
prevValue.current = value;
|
|
1119
|
-
return function () {
|
|
1120
|
-
prevValue.current = undefined;
|
|
1121
|
-
};
|
|
1122
|
-
});
|
|
1123
|
-
return prevValue.current;
|
|
1124
|
-
}
|
|
1125
|
-
/**
|
|
1126
|
-
* @deprecated Prefer using `usePlasmicDataOp` directly instead.
|
|
1127
|
-
*/
|
|
1128
|
-
function useDependencyAwareQuery(_ref) {
|
|
1129
|
-
var $queries = _ref.$queries,
|
|
1130
|
-
getDataOp = _ref.getDataOp,
|
|
1131
|
-
setDollarQueries = _ref.setDollarQueries,
|
|
1132
|
-
name = _ref.name,
|
|
1133
|
-
pageIndex = _ref.pageIndex,
|
|
1134
|
-
pageSize = _ref.pageSize;
|
|
1135
|
-
var data = usePlasmicDataOp(swallow(getDataOp), _extends({}, !!pageIndex && !!pageSize && {
|
|
1136
|
-
paginate: {
|
|
1137
|
-
pageIndex: pageIndex,
|
|
1138
|
-
pageSize: pageSize
|
|
1139
|
-
}
|
|
1140
|
-
}));
|
|
1141
|
-
var finalName = name != null ? name : 'data';
|
|
1142
|
-
var prevName = usePrevious(finalName);
|
|
1143
|
-
React.useEffect(function () {
|
|
1144
|
-
if (!(finalName in $queries) || $queries[finalName] !== data) {
|
|
1145
|
-
var _extends2;
|
|
1146
|
-
var $queries2 = _extends({}, $queries, (_extends2 = {}, _extends2[finalName] = data, _extends2));
|
|
1147
|
-
if (prevName && finalName !== prevName && prevName in $queries) {
|
|
1148
|
-
delete $queries2[prevName];
|
|
1149
|
-
}
|
|
1150
|
-
setDollarQueries($queries2);
|
|
1151
|
-
}
|
|
1152
|
-
}, [finalName, prevName, data, $queries, setDollarQueries]);
|
|
1153
|
-
}
|
|
1154
|
-
|
|
1155
|
-
Object.defineProperty(exports, 'usePlasmicDataConfig', {
|
|
1156
|
-
enumerable: true,
|
|
1157
|
-
get: function () {
|
|
1158
|
-
return query.usePlasmicDataConfig;
|
|
1159
|
-
}
|
|
1160
|
-
});
|
|
1161
|
-
exports.Fetcher = Fetcher;
|
|
1162
|
-
exports.FetcherMeta = FetcherMeta;
|
|
1163
|
-
exports.deriveFieldConfigs = deriveFieldConfigs;
|
|
1164
|
-
exports.executePlasmicDataOp = executePlasmicDataOp;
|
|
1165
|
-
exports.makeCacheKey = makeCacheKey;
|
|
1166
|
-
exports.normalizeData = normalizeData;
|
|
1167
|
-
exports.useDependencyAwareQuery = useDependencyAwareQuery;
|
|
1168
|
-
exports.usePlasmicDataMutationOp = usePlasmicDataMutationOp;
|
|
1169
|
-
exports.usePlasmicDataOp = usePlasmicDataOp;
|
|
1170
|
-
exports.usePlasmicInvalidate = usePlasmicInvalidate;
|
|
1171
|
-
//# sourceMappingURL=data-sources.cjs.development.js.map
|