@plasmicapp/data-sources 0.1.204 → 0.1.206
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/index.d.ts +68 -26
- package/dist/index.esm.js +70 -147
- package/dist/index.esm.js.map +4 -4
- package/dist/index.js +70 -147
- package/dist/index.js.map +4 -4
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -69,12 +69,11 @@ var src_exports = {};
|
|
|
69
69
|
__export(src_exports, {
|
|
70
70
|
Fetcher: () => Fetcher,
|
|
71
71
|
FetcherMeta: () => FetcherMeta,
|
|
72
|
+
_StatefulQueryResult: () => StatefulQueryResult,
|
|
72
73
|
deriveFieldConfigs: () => deriveFieldConfigs,
|
|
73
74
|
executePlasmicDataOp: () => executePlasmicDataOp,
|
|
74
|
-
executeServerQuery: () => executeServerQuery,
|
|
75
75
|
makeCacheKey: () => makeCacheKey,
|
|
76
76
|
makeQueryCacheKey: () => makeQueryCacheKey,
|
|
77
|
-
mkPlasmicUndefinedServerProxy: () => mkPlasmicUndefinedServerProxy,
|
|
78
77
|
normalizeData: () => normalizeData,
|
|
79
78
|
unstable_createDollarQueries: () => createDollarQueries,
|
|
80
79
|
unstable_executePlasmicQueries: () => executePlasmicQueries,
|
|
@@ -85,8 +84,7 @@ __export(src_exports, {
|
|
|
85
84
|
usePlasmicDataConfig: () => import_query5.usePlasmicDataConfig,
|
|
86
85
|
usePlasmicDataMutationOp: () => usePlasmicDataMutationOp,
|
|
87
86
|
usePlasmicDataOp: () => usePlasmicDataOp,
|
|
88
|
-
usePlasmicInvalidate: () => usePlasmicInvalidate
|
|
89
|
-
usePlasmicServerQuery: () => usePlasmicServerQuery
|
|
87
|
+
usePlasmicInvalidate: () => usePlasmicInvalidate
|
|
90
88
|
});
|
|
91
89
|
module.exports = __toCommonJS(src_exports);
|
|
92
90
|
|
|
@@ -94,6 +92,61 @@ module.exports = __toCommonJS(src_exports);
|
|
|
94
92
|
var import_query2 = require("@plasmicapp/query");
|
|
95
93
|
var React3 = __toESM(require("react"));
|
|
96
94
|
|
|
95
|
+
// src/utils.ts
|
|
96
|
+
function noopFn() {
|
|
97
|
+
}
|
|
98
|
+
function swallow(f) {
|
|
99
|
+
try {
|
|
100
|
+
return f();
|
|
101
|
+
} catch (e) {
|
|
102
|
+
return void 0;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
function pick(obj, ...keys) {
|
|
106
|
+
const res = {};
|
|
107
|
+
for (const key of keys) {
|
|
108
|
+
if (key in obj) {
|
|
109
|
+
res[key] = obj[key];
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
return res;
|
|
113
|
+
}
|
|
114
|
+
var tuple = (...args) => args;
|
|
115
|
+
function mkIdMap(xs) {
|
|
116
|
+
return new Map(xs.map((x) => tuple(x.id, x)));
|
|
117
|
+
}
|
|
118
|
+
function notNil(x) {
|
|
119
|
+
return x !== null && x !== void 0;
|
|
120
|
+
}
|
|
121
|
+
function withoutNils(xs) {
|
|
122
|
+
return xs.filter(notNil);
|
|
123
|
+
}
|
|
124
|
+
function mapRecordEntries(callback, record1, record2, record3) {
|
|
125
|
+
return Object.entries(record1).map(([k, v1]) => {
|
|
126
|
+
const v2 = record2 == null ? void 0 : record2[k];
|
|
127
|
+
const v3 = record3 == null ? void 0 : record3[k];
|
|
128
|
+
return callback(
|
|
129
|
+
k,
|
|
130
|
+
v1,
|
|
131
|
+
v2,
|
|
132
|
+
v3
|
|
133
|
+
);
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
function mapRecords(callback, record1, record2, record3) {
|
|
137
|
+
return Object.fromEntries(
|
|
138
|
+
mapRecordEntries(
|
|
139
|
+
(k, v1, v2, v3) => [k, callback(k, v1, v2, v3)],
|
|
140
|
+
record1,
|
|
141
|
+
record2,
|
|
142
|
+
record3
|
|
143
|
+
)
|
|
144
|
+
);
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
// src/serverQueries/common.ts
|
|
148
|
+
var import_react2 = __toESM(require("react"));
|
|
149
|
+
|
|
97
150
|
// src/common.ts
|
|
98
151
|
var import_query = require("@plasmicapp/query");
|
|
99
152
|
var ph = __toESM(require("@plasmicapp/host"));
|
|
@@ -269,69 +322,8 @@ function usePlasmicFetch(key, resolvedParams, fetcherFn, resultMapper, undefined
|
|
|
269
322
|
fetchAndUpdateCache
|
|
270
323
|
]);
|
|
271
324
|
}
|
|
272
|
-
function getConfig(key, defaultValue) {
|
|
273
|
-
var _a, _b;
|
|
274
|
-
if (typeof globalThis === "undefined") {
|
|
275
|
-
return defaultValue;
|
|
276
|
-
} else {
|
|
277
|
-
return (_b = (_a = globalThis.__PLASMIC__) == null ? void 0 : _a[key]) != null ? _b : defaultValue;
|
|
278
|
-
}
|
|
279
|
-
}
|
|
280
|
-
|
|
281
|
-
// src/utils.ts
|
|
282
|
-
function noopFn() {
|
|
283
|
-
}
|
|
284
|
-
function swallow(f) {
|
|
285
|
-
try {
|
|
286
|
-
return f();
|
|
287
|
-
} catch (e) {
|
|
288
|
-
return void 0;
|
|
289
|
-
}
|
|
290
|
-
}
|
|
291
|
-
function pick(obj, ...keys) {
|
|
292
|
-
const res = {};
|
|
293
|
-
for (const key of keys) {
|
|
294
|
-
if (key in obj) {
|
|
295
|
-
res[key] = obj[key];
|
|
296
|
-
}
|
|
297
|
-
}
|
|
298
|
-
return res;
|
|
299
|
-
}
|
|
300
|
-
var tuple = (...args) => args;
|
|
301
|
-
function mkIdMap(xs) {
|
|
302
|
-
return new Map(xs.map((x) => tuple(x.id, x)));
|
|
303
|
-
}
|
|
304
|
-
function notNil(x) {
|
|
305
|
-
return x !== null && x !== void 0;
|
|
306
|
-
}
|
|
307
|
-
function withoutNils(xs) {
|
|
308
|
-
return xs.filter(notNil);
|
|
309
|
-
}
|
|
310
|
-
function mapRecordEntries(callback, record1, record2, record3) {
|
|
311
|
-
return Object.entries(record1).map(([k, v1]) => {
|
|
312
|
-
const v2 = record2 == null ? void 0 : record2[k];
|
|
313
|
-
const v3 = record3 == null ? void 0 : record3[k];
|
|
314
|
-
return callback(
|
|
315
|
-
k,
|
|
316
|
-
v1,
|
|
317
|
-
v2,
|
|
318
|
-
v3
|
|
319
|
-
);
|
|
320
|
-
});
|
|
321
|
-
}
|
|
322
|
-
function mapRecords(callback, record1, record2, record3) {
|
|
323
|
-
return Object.fromEntries(
|
|
324
|
-
mapRecordEntries(
|
|
325
|
-
(k, v1, v2, v3) => [k, callback(k, v1, v2, v3)],
|
|
326
|
-
record1,
|
|
327
|
-
record2,
|
|
328
|
-
record3
|
|
329
|
-
)
|
|
330
|
-
);
|
|
331
|
-
}
|
|
332
325
|
|
|
333
326
|
// src/serverQueries/common.ts
|
|
334
|
-
var import_react2 = __toESM(require("react"));
|
|
335
327
|
function createDollarQueries(queryNames) {
|
|
336
328
|
return Object.fromEntries(
|
|
337
329
|
queryNames.map((queryName) => {
|
|
@@ -697,18 +689,9 @@ function usePlasmicQueries($queries, queries) {
|
|
|
697
689
|
},
|
|
698
690
|
[wrappedQueries, $queryStates, settledCount]
|
|
699
691
|
);
|
|
700
|
-
|
|
692
|
+
return mapRecords(
|
|
701
693
|
(_queryName, $query, query) => {
|
|
702
|
-
|
|
703
|
-
query,
|
|
704
|
-
void 0,
|
|
705
|
-
{
|
|
706
|
-
settledCount,
|
|
707
|
-
onStarted: $query.loadingPromise.bind($query),
|
|
708
|
-
onResolved: $query.resolvePromise.bind($query),
|
|
709
|
-
onRejected: $query.rejectPromise.bind($query)
|
|
710
|
-
}
|
|
711
|
-
);
|
|
694
|
+
return usePlasmicQuery($query, query, settledCount);
|
|
712
695
|
},
|
|
713
696
|
$queryStates,
|
|
714
697
|
wrappedQueries
|
|
@@ -722,15 +705,7 @@ function wrapQueries(queries) {
|
|
|
722
705
|
if (cached) {
|
|
723
706
|
return cached.promise;
|
|
724
707
|
}
|
|
725
|
-
const
|
|
726
|
-
"EXECUTE_SERVER_QUERY",
|
|
727
|
-
(_, fn, ...args2) => fn(...args2)
|
|
728
|
-
);
|
|
729
|
-
const promise = (0, import_query2.wrapLoadingFetcher)(wrapStudioCache)(
|
|
730
|
-
query.id,
|
|
731
|
-
query.fn,
|
|
732
|
-
...args
|
|
733
|
-
);
|
|
708
|
+
const promise = (0, import_query2.wrapLoadingFetcher)(query.fn)(...args);
|
|
734
709
|
GLOBAL_CACHE.set(cacheKey, new SyncPromise(promise));
|
|
735
710
|
return promise;
|
|
736
711
|
};
|
|
@@ -793,11 +768,11 @@ function initPlasmicQueriesSync($queries, queries, prefetchedCache, clientCache)
|
|
|
793
768
|
);
|
|
794
769
|
} while (anySettled);
|
|
795
770
|
}
|
|
796
|
-
function
|
|
797
|
-
|
|
771
|
+
function usePlasmicQuery($query, query, settledCount) {
|
|
772
|
+
const $queryState = $query;
|
|
798
773
|
const paramsResult = React3.useMemo(() => {
|
|
799
774
|
return resolveParams(query.execParams);
|
|
800
|
-
}, [query.execParams,
|
|
775
|
+
}, [query.execParams, settledCount]);
|
|
801
776
|
const { key, fetcher } = React3.useMemo(() => {
|
|
802
777
|
switch (paramsResult.status) {
|
|
803
778
|
case "blocked":
|
|
@@ -817,9 +792,8 @@ function usePlasmicServerQuery(query, fallbackData, opts) {
|
|
|
817
792
|
return {
|
|
818
793
|
key: cacheKey,
|
|
819
794
|
fetcher: () => {
|
|
820
|
-
var _a2;
|
|
821
795
|
const promise = query.fn(...paramsResult.resolvedParams);
|
|
822
|
-
|
|
796
|
+
$queryState.loadingPromise(cacheKey, promise);
|
|
823
797
|
return promise.finally(() => {
|
|
824
798
|
GLOBAL_CACHE.delete(cacheKey);
|
|
825
799
|
});
|
|
@@ -835,17 +809,13 @@ function usePlasmicServerQuery(query, fallbackData, opts) {
|
|
|
835
809
|
// happens all the time -- we prepopulate the cache with proxy-invoked fetch,
|
|
836
810
|
// sometimes before swr had a chance to run the effect. So we turn off
|
|
837
811
|
// revalidateIfStale here, and just let the user manage invalidation.
|
|
838
|
-
revalidateIfStale: false
|
|
839
|
-
// TODO: Remove per-hook fallbackData
|
|
840
|
-
// Only used in older server query implementation.
|
|
841
|
-
// New implementation should use prefetchedCache instead.
|
|
842
|
-
fallbackData
|
|
812
|
+
revalidateIfStale: false
|
|
843
813
|
});
|
|
844
814
|
if (!result.isLoading) {
|
|
845
815
|
if (result.error) {
|
|
846
|
-
|
|
816
|
+
$queryState.rejectPromise(key, result.error);
|
|
847
817
|
} else if (key && result.data !== void 0) {
|
|
848
|
-
|
|
818
|
+
$queryState.resolvePromise(key, result.data);
|
|
849
819
|
}
|
|
850
820
|
}
|
|
851
821
|
return result;
|
|
@@ -902,53 +872,6 @@ function executePlasmicQuery($query, query) {
|
|
|
902
872
|
} while (true);
|
|
903
873
|
});
|
|
904
874
|
}
|
|
905
|
-
var PlasmicUndefinedServerError = class extends Error {
|
|
906
|
-
constructor(msg) {
|
|
907
|
-
super(msg);
|
|
908
|
-
this.plasmicType = "PlasmicUndefinedServerError";
|
|
909
|
-
}
|
|
910
|
-
};
|
|
911
|
-
function isPlasmicUndefinedServerError(x) {
|
|
912
|
-
return !!x && typeof x === "object" && x.plasmicType === "PlasmicUndefinedServerError";
|
|
913
|
-
}
|
|
914
|
-
function mkPlasmicUndefinedServerProxy() {
|
|
915
|
-
return {
|
|
916
|
-
data: new Proxy(
|
|
917
|
-
{},
|
|
918
|
-
{
|
|
919
|
-
get: (_, prop) => {
|
|
920
|
-
if (prop === "isUndefinedServerProxy") {
|
|
921
|
-
return true;
|
|
922
|
-
} else if (prop === "then") {
|
|
923
|
-
return void 0;
|
|
924
|
-
}
|
|
925
|
-
throw new PlasmicUndefinedServerError("Data is not available yet");
|
|
926
|
-
}
|
|
927
|
-
}
|
|
928
|
-
),
|
|
929
|
-
isLoading: true
|
|
930
|
-
};
|
|
931
|
-
}
|
|
932
|
-
function executeServerQuery(query) {
|
|
933
|
-
return __async(this, null, function* () {
|
|
934
|
-
const resolvedParams = resolveServerParams(query.execParams);
|
|
935
|
-
if (isPlasmicUndefinedServerError(resolvedParams)) {
|
|
936
|
-
return mkPlasmicUndefinedServerProxy();
|
|
937
|
-
}
|
|
938
|
-
return { data: yield query.fn(...resolvedParams), isLoading: false };
|
|
939
|
-
});
|
|
940
|
-
}
|
|
941
|
-
function resolveServerParams(params) {
|
|
942
|
-
try {
|
|
943
|
-
return params();
|
|
944
|
-
} catch (err) {
|
|
945
|
-
if (isPlasmicUndefinedServerError(err)) {
|
|
946
|
-
return err;
|
|
947
|
-
} else {
|
|
948
|
-
throw err;
|
|
949
|
-
}
|
|
950
|
-
}
|
|
951
|
-
}
|
|
952
875
|
|
|
953
876
|
// src/index.tsx
|
|
954
877
|
var import_query5 = require("@plasmicapp/query");
|
|
@@ -986,7 +909,7 @@ var DEFAULT_HOST = "https://data.plasmic.app";
|
|
|
986
909
|
var UNAUTHORIZED_MESSAGE = "You do not have permission to perform this operation. Login to get access or contact the app owner to get access.";
|
|
987
910
|
function executePlasmicDataOp(op, opts) {
|
|
988
911
|
return __async(this, null, function* () {
|
|
989
|
-
const func =
|
|
912
|
+
const func = getConfig(
|
|
990
913
|
"__PLASMIC_EXECUTE_DATA_OP",
|
|
991
914
|
_executePlasmicDataOp
|
|
992
915
|
);
|
|
@@ -1004,7 +927,7 @@ function _executePlasmicDataOp(op, opts) {
|
|
|
1004
927
|
throw new Error(UNAUTHORIZED_MESSAGE);
|
|
1005
928
|
}
|
|
1006
929
|
}
|
|
1007
|
-
const host =
|
|
930
|
+
const host = getConfig("__PLASMIC_DATA_HOST", DEFAULT_HOST);
|
|
1008
931
|
const url = `${host}/api/v1/server-data/sources/${op.sourceId}/execute`;
|
|
1009
932
|
const resp = yield (0, import_isomorphic_unfetch.default)(url, {
|
|
1010
933
|
method: "POST",
|
|
@@ -1026,7 +949,7 @@ function _executePlasmicDataOp(op, opts) {
|
|
|
1026
949
|
return yield resp.json();
|
|
1027
950
|
});
|
|
1028
951
|
}
|
|
1029
|
-
function
|
|
952
|
+
function getConfig(key, defaultValue) {
|
|
1030
953
|
var _a;
|
|
1031
954
|
if (typeof globalThis === "undefined") {
|
|
1032
955
|
return defaultValue;
|