@plasmicapp/data-sources 0.1.171 → 0.1.173

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 CHANGED
@@ -8,6 +8,39 @@ export declare type BaseFieldConfig = {
8
8
  fieldId?: string;
9
9
  };
10
10
 
11
+ /**
12
+ * Represents the result of a client-side query.
13
+ */
14
+ export declare interface ClientQueryResult<T = any> {
15
+ /**
16
+ * The data returned by the query. May be undefined if the query has not yet completed.
17
+ */
18
+ data?: T;
19
+ /**
20
+ * The schema of the table from which the data was queried. Only available for plasmic data
21
+ * integration. May be undefined if the query has not yet completed.
22
+ */
23
+ schema?: TableSchema;
24
+ /**
25
+ * The total number of records available. Only available for plasmic data integration. May be
26
+ * undefined if the query has not yet completed.
27
+ */
28
+ total?: number;
29
+ /**
30
+ * Pagination information for the query result. Only available for plasmic data integration. May be
31
+ * undefined if the query has not yet completed.
32
+ */
33
+ paginate?: Pagination;
34
+ /**
35
+ * Any error that occurred during the query. This is optional and may be undefined.
36
+ */
37
+ error?: any;
38
+ /**
39
+ * Indicates whether the query is currently loading.
40
+ */
41
+ isLoading?: boolean;
42
+ }
43
+
11
44
  export declare interface DataOp {
12
45
  sourceId: string;
13
46
  opId: string;
@@ -50,7 +83,7 @@ export declare function executePlasmicDataOp<T extends SingleRowResult | ManyRow
50
83
  * Executes a server query, returning either the result of the query or a
51
84
  * PlasmicUndefinedServerProxy if the query depends on data that is not yet ready
52
85
  */
53
- export declare function executeServerQuery<F extends (...args: any[]) => any>(serverQuery: ServerQuery<F>): Promise<ServerQueryResult<ReturnType<F>> | ServerQueryResult<{}>>;
86
+ export declare function executeServerQuery<F extends (...args: any[]) => any>(serverQuery: ServerQuery<F>): Promise<ServerQueryResult<ReturnType<F> | {}>>;
54
87
 
55
88
  export declare function Fetcher(props: FetcherProps): React_2.ReactElement | null;
56
89
 
@@ -67,6 +100,8 @@ export declare function makeCacheKey(dataOp: DataOp, opts?: {
67
100
  userAuthToken?: string | null;
68
101
  }): string;
69
102
 
103
+ export declare function makeQueryCacheKey(id: string, params: any[]): string;
104
+
70
105
  export declare interface ManyRowsResult<T = any> {
71
106
  data: T[];
72
107
  total?: number;
@@ -98,9 +133,10 @@ export declare type QueryResult = Partial<ManyRowsResult<any>> & {
98
133
 
99
134
  declare type ResolvableDataOp = DataOp | undefined | null | (() => DataOp | undefined | null);
100
135
 
101
- export declare interface ServerQuery<F extends (...args: any[]) => any> {
136
+ export declare interface ServerQuery<F extends (...args: any[]) => Promise<any>> {
102
137
  fn: F;
103
138
  execParams: () => Parameters<F>;
139
+ id: string;
104
140
  }
105
141
 
106
142
  export declare interface ServerQueryResult<T = any> {
@@ -145,14 +181,15 @@ export declare function usePlasmicDataMutationOp<T extends SingleRowResult | Man
145
181
  export declare function usePlasmicDataOp<T extends SingleRowResult | ManyRowsResult, E = any>(dataOp: ResolvableDataOp, opts?: {
146
182
  paginate?: Pagination;
147
183
  noUndefinedDataProxy?: boolean;
148
- }): Partial<T> & {
149
- error?: E;
150
- isLoading?: boolean;
151
- };
184
+ }): ClientQueryResult<T["data"]>;
152
185
 
153
186
  /**
154
187
  * Returns a function that can be used to invalidate Plasmic query groups.
155
188
  */
156
189
  export declare function usePlasmicInvalidate(): (invalidatedKeys: string[] | null | undefined) => Promise<any[] | undefined>;
157
190
 
191
+ export declare function usePlasmicServerQuery<F extends (...args: any[]) => Promise<any>>(serverQuery: ServerQuery<F>, fallbackData?: ReturnType<F>, opts?: {
192
+ noUndefinedDataProxy?: boolean;
193
+ }): Partial<ServerQueryResult<ReturnType<F>>>;
194
+
158
195
  export { }
package/dist/index.esm.js CHANGED
@@ -39,19 +39,188 @@ var __async = (__this, __arguments, generator) => {
39
39
  };
40
40
 
41
41
  // src/index.tsx
42
- import { usePlasmicDataConfig as usePlasmicDataConfig2 } from "@plasmicapp/query";
42
+ import { usePlasmicDataConfig as usePlasmicDataConfig3 } from "@plasmicapp/query";
43
43
 
44
44
  // src/components/Fetcher.tsx
45
- import React2 from "react";
45
+ import React3 from "react";
46
46
 
47
47
  // src/hooks/usePlasmicDataOp.tsx
48
48
  import { usePlasmicDataSourceContext } from "@plasmicapp/data-sources-context";
49
- import * as ph from "@plasmicapp/host";
49
+ import {
50
+ usePlasmicDataConfig as usePlasmicDataConfig2
51
+ } from "@plasmicapp/query";
52
+ import * as React2 from "react";
53
+
54
+ // src/common.ts
50
55
  import {
51
56
  useMutablePlasmicQueryData,
52
57
  usePlasmicDataConfig
53
58
  } from "@plasmicapp/query";
54
- import * as React from "react";
59
+ import * as ph from "@plasmicapp/host";
60
+ import React from "react";
61
+ function isPlasmicUndefinedDataErrorPromise(x) {
62
+ return !!x && typeof x === "object" && (x == null ? void 0 : x.plasmicType) === "PlasmicUndefinedDataError";
63
+ }
64
+ function mkUndefinedDataProxy(promiseRef, fetchAndUpdateCache) {
65
+ let fetchAndUpdatePromise = void 0;
66
+ return new Proxy(
67
+ {},
68
+ {
69
+ get: (_target, prop) => {
70
+ if (prop === "isPlasmicUndefinedDataProxy") {
71
+ return true;
72
+ }
73
+ if (!fetchAndUpdateCache) {
74
+ return void 0;
75
+ }
76
+ const doFetchAndUpdate = () => {
77
+ if (!fetchAndUpdatePromise) {
78
+ fetchAndUpdatePromise = fetchAndUpdateCache().finally(() => {
79
+ fetchAndUpdatePromise = void 0;
80
+ });
81
+ }
82
+ return fetchAndUpdatePromise;
83
+ };
84
+ const promise = (
85
+ // existing fetch
86
+ promiseRef.fetchingPromise || // No existing fetch, so kick off a fetch
87
+ doFetchAndUpdate()
88
+ );
89
+ promise.plasmicType = "PlasmicUndefinedDataError";
90
+ promise.message = `Cannot read property ${String(
91
+ prop
92
+ )} - data is still loading`;
93
+ throw promise;
94
+ }
95
+ }
96
+ );
97
+ }
98
+ var isRSC = React.isRSC;
99
+ var reactMajorVersion = +React.version.split(".")[0];
100
+ var enableLoadingBoundaryKey = "plasmicInternalEnableLoadingBoundary";
101
+ var PRE_FETCHES = /* @__PURE__ */ new Map();
102
+ function usePlasmicFetch(key, resolvedParams, fetcherFn, resultMapper, undefinedDataProxyFields, opts) {
103
+ var _a, _b;
104
+ const enableLoadingBoundary = !!((_b = (_a = ph.useDataEnv) == null ? void 0 : _a()) == null ? void 0 : _b[enableLoadingBoundaryKey]);
105
+ const { mutate, cache } = isRSC ? {} : usePlasmicDataConfig();
106
+ const isNullParams = !resolvedParams;
107
+ const isWaitingOnDependentQuery = isPlasmicUndefinedDataErrorPromise(resolvedParams);
108
+ const fetchingData = React.useMemo(
109
+ () => ({
110
+ fetchingPromise: void 0
111
+ }),
112
+ [key]
113
+ );
114
+ const fetcher = React.useMemo(
115
+ () => () => {
116
+ if (!key) {
117
+ throw new Error(`Fetcher should never be called without a proper key`);
118
+ }
119
+ if (fetchingData.fetchingPromise) {
120
+ return fetchingData.fetchingPromise;
121
+ }
122
+ if (key && PRE_FETCHES.has(key)) {
123
+ const existing = PRE_FETCHES.get(key);
124
+ fetchingData.fetchingPromise = existing;
125
+ return existing;
126
+ }
127
+ const fetcherPromise = fetcherFn(resolvedParams);
128
+ fetchingData.fetchingPromise = fetcherPromise;
129
+ if (key) {
130
+ PRE_FETCHES.set(key, fetcherPromise);
131
+ fetcherPromise.then(
132
+ () => {
133
+ PRE_FETCHES.delete(key);
134
+ },
135
+ () => {
136
+ PRE_FETCHES.delete(key);
137
+ }
138
+ );
139
+ }
140
+ return fetcherPromise;
141
+ },
142
+ [key, fetchingData]
143
+ );
144
+ const dependentKeyDataErrorPromise = isPlasmicUndefinedDataErrorPromise(
145
+ resolvedParams
146
+ ) ? resolvedParams : void 0;
147
+ const fetchAndUpdateCache = React.useMemo(() => {
148
+ if (!key && !dependentKeyDataErrorPromise) {
149
+ return void 0;
150
+ }
151
+ return () => {
152
+ if (fetchingData.fetchingPromise) {
153
+ return fetchingData.fetchingPromise;
154
+ }
155
+ if (dependentKeyDataErrorPromise) {
156
+ return dependentKeyDataErrorPromise;
157
+ }
158
+ if (!key) {
159
+ throw new Error(`Expected key to be non-null`);
160
+ }
161
+ const cached = cache == null ? void 0 : cache.get(key);
162
+ if (cached) {
163
+ return Promise.resolve(cached);
164
+ }
165
+ const cachedError = cache == null ? void 0 : cache.get(`$swr$${key}`);
166
+ if (cachedError) {
167
+ return Promise.reject(cachedError.error);
168
+ }
169
+ const fetcherPromise = new Promise((resolve, reject) => {
170
+ setTimeout(() => {
171
+ fetcher().then(resolve, reject);
172
+ }, 1);
173
+ });
174
+ if (!isRSC) {
175
+ fetcherPromise.then((data2) => {
176
+ mutate == null ? void 0 : mutate(key, data2);
177
+ }).catch((err) => {
178
+ var _a2;
179
+ const keyInfo = key ? "$swr$" + key : "";
180
+ cache == null ? void 0 : cache.set(keyInfo, __spreadProps(__spreadValues({}, (_a2 = cache == null ? void 0 : cache.get(keyInfo)) != null ? _a2 : {}), { error: err }));
181
+ });
182
+ }
183
+ return fetcherPromise;
184
+ };
185
+ }, [fetcher, fetchingData, cache, key, dependentKeyDataErrorPromise]);
186
+ const res = useMutablePlasmicQueryData(key, fetcher, {
187
+ fallbackData: opts == null ? void 0 : opts.fallbackData,
188
+ shouldRetryOnError: false,
189
+ // If revalidateIfStale is true, then if there's a cache entry with a key,
190
+ // but no mounted hook with that key yet, and when the hook mounts with the key,
191
+ // swr will revalidate. This may be reasonable behavior, but for us, this
192
+ // happens all the time -- we prepopulate the cache with proxy-invoked fetch,
193
+ // sometimes before swr had a chance to run the effect. So we turn off
194
+ // revalidateIfStale here, and just let the user manage invalidation.
195
+ revalidateIfStale: false
196
+ });
197
+ const { data, error, isLoading } = res;
198
+ if (fetchingData.fetchingPromise != null && data !== void 0) {
199
+ fetchingData.fetchingPromise = void 0;
200
+ }
201
+ return React.useMemo(() => {
202
+ const result = resultMapper(res);
203
+ if (!(opts == null ? void 0 : opts.noUndefinedDataProxy) && reactMajorVersion >= 18 && enableLoadingBoundary && (isLoading || isNullParams || isWaitingOnDependentQuery) && undefinedDataProxyFields.every((field) => result[field] === void 0)) {
204
+ undefinedDataProxyFields.forEach((field) => {
205
+ if (field === "error") {
206
+ return;
207
+ }
208
+ result[field] = mkUndefinedDataProxy(fetchingData, fetchAndUpdateCache);
209
+ });
210
+ }
211
+ return result;
212
+ }, [
213
+ isNullParams,
214
+ isWaitingOnDependentQuery,
215
+ data,
216
+ error,
217
+ isLoading,
218
+ opts == null ? void 0 : opts.noUndefinedDataProxy,
219
+ enableLoadingBoundary,
220
+ fetchingData,
221
+ fetchAndUpdateCache
222
+ ]);
223
+ }
55
224
 
56
225
  // src/executor.tsx
57
226
  import fetch from "@plasmicapp/isomorphic-unfetch";
@@ -153,7 +322,6 @@ function withoutNils(xs) {
153
322
  }
154
323
 
155
324
  // src/hooks/usePlasmicDataOp.tsx
156
- var isRSC2 = React.isRSC;
157
325
  function makeCacheKey(dataOp, opts) {
158
326
  const queryDependencies = JSON.stringify({
159
327
  sourceId: dataOp.sourceId,
@@ -165,7 +333,7 @@ function makeCacheKey(dataOp, opts) {
165
333
  return dataOp.cacheKey ? `${dataOp.cacheKey}${queryDependencies}` : queryDependencies;
166
334
  }
167
335
  function usePlasmicInvalidate() {
168
- const { cache, fallback, mutate } = usePlasmicDataConfig();
336
+ const { cache, fallback, mutate } = usePlasmicDataConfig2();
169
337
  return (invalidatedKeys) => __async(this, null, function* () {
170
338
  const getKeysToInvalidate = () => {
171
339
  var _a, _b;
@@ -214,45 +382,6 @@ function usePlasmicInvalidate() {
214
382
  return yield Promise.all(keys.map((key) => invalidateKey(key)));
215
383
  });
216
384
  }
217
- var enableLoadingBoundaryKey = "plasmicInternalEnableLoadingBoundary";
218
- function mkUndefinedDataProxy(promiseRef, fetchAndUpdateCache) {
219
- let fetchAndUpdatePromise = void 0;
220
- return new Proxy(
221
- {},
222
- {
223
- get: (_target, prop) => {
224
- if (prop === "isPlasmicUndefinedDataProxy") {
225
- return true;
226
- }
227
- if (!fetchAndUpdateCache) {
228
- return void 0;
229
- }
230
- const doFetchAndUpdate = () => {
231
- if (!fetchAndUpdatePromise) {
232
- fetchAndUpdatePromise = fetchAndUpdateCache().finally(() => {
233
- fetchAndUpdatePromise = void 0;
234
- });
235
- }
236
- return fetchAndUpdatePromise;
237
- };
238
- const promise = (
239
- // existing fetch
240
- promiseRef.fetchingPromise || // No existing fetch, so kick off a fetch
241
- doFetchAndUpdate()
242
- );
243
- promise.plasmicType = "PlasmicUndefinedDataError";
244
- promise.message = `Cannot read property ${String(
245
- prop
246
- )} - data is still loading`;
247
- throw promise;
248
- }
249
- }
250
- );
251
- }
252
- function isPlasmicUndefinedDataErrorPromise(x) {
253
- return !!x && typeof x === "object" && x.plasmicType === "PlasmicUndefinedDataError";
254
- }
255
- var reactMajorVersion = +React.version.split(".")[0];
256
385
  function resolveDataOp(dataOp) {
257
386
  if (typeof dataOp === "function") {
258
387
  try {
@@ -267,138 +396,39 @@ function resolveDataOp(dataOp) {
267
396
  return dataOp;
268
397
  }
269
398
  }
270
- var PRE_FETCHES = /* @__PURE__ */ new Map();
271
399
  function usePlasmicDataOp(dataOp, opts) {
272
- var _a, _b;
273
400
  const resolvedDataOp = resolveDataOp(dataOp);
274
401
  const ctx = usePlasmicDataSourceContext();
275
- const enableLoadingBoundary = !!((_b = (_a = ph.useDataEnv) == null ? void 0 : _a()) == null ? void 0 : _b[enableLoadingBoundaryKey]);
276
- const { mutate, cache } = isRSC2 ? {} : usePlasmicDataConfig();
277
- const isNullDataOp = !resolvedDataOp;
278
- const isWaitingOnDependentQuery = isPlasmicUndefinedDataErrorPromise(resolvedDataOp);
279
402
  const key = !resolvedDataOp || isPlasmicUndefinedDataErrorPromise(resolvedDataOp) ? null : makeCacheKey(resolvedDataOp, {
280
403
  paginate: opts == null ? void 0 : opts.paginate,
281
404
  userAuthToken: ctx == null ? void 0 : ctx.userAuthToken
282
405
  });
283
- const fetchingData = React.useMemo(
284
- () => ({
285
- fetchingPromise: void 0
286
- }),
287
- [key]
288
- );
289
- const fetcher = React.useMemo(
290
- () => () => {
291
- if (!key) {
292
- throw new Error(`Fetcher should never be called without a proper key`);
293
- }
294
- if (fetchingData.fetchingPromise) {
295
- return fetchingData.fetchingPromise;
296
- }
297
- if (key && PRE_FETCHES.has(key)) {
298
- const existing = PRE_FETCHES.get(key);
299
- fetchingData.fetchingPromise = existing;
300
- return existing;
301
- }
302
- const fetcherFn = () => executePlasmicDataOp(resolvedDataOp, {
303
- userAuthToken: (ctx == null ? void 0 : ctx.userAuthToken) || void 0,
304
- user: ctx == null ? void 0 : ctx.user,
305
- paginate: opts == null ? void 0 : opts.paginate
306
- });
307
- const fetcherPromise = fetcherFn();
308
- fetchingData.fetchingPromise = fetcherPromise;
309
- if (key) {
310
- PRE_FETCHES.set(key, fetcherPromise);
311
- fetcherPromise.then(
312
- () => {
313
- PRE_FETCHES.delete(key);
314
- },
315
- () => {
316
- PRE_FETCHES.delete(key);
317
- }
318
- );
319
- }
320
- return fetcherPromise;
321
- },
322
- [key, fetchingData]
323
- );
324
- const dependentKeyDataErrorPromise = isPlasmicUndefinedDataErrorPromise(
325
- resolvedDataOp
326
- ) ? resolvedDataOp : void 0;
327
- const fetchAndUpdateCache = React.useMemo(() => {
328
- if (!key && !dependentKeyDataErrorPromise) {
329
- return void 0;
330
- }
331
- return () => {
332
- if (fetchingData.fetchingPromise) {
333
- return fetchingData.fetchingPromise;
334
- }
335
- if (dependentKeyDataErrorPromise) {
336
- return dependentKeyDataErrorPromise;
337
- }
338
- if (!key) {
339
- throw new Error(`Expected key to be non-null`);
340
- }
341
- const cached = cache == null ? void 0 : cache.get(key);
342
- if (cached) {
343
- return Promise.resolve(cached);
344
- }
345
- const cachedError = cache == null ? void 0 : cache.get(`$swr$${key}`);
346
- if (cachedError) {
347
- return Promise.reject(cachedError.error);
348
- }
349
- const fetcherPromise = new Promise((resolve, reject) => {
350
- setTimeout(() => {
351
- fetcher().then(resolve, reject);
352
- }, 1);
353
- });
354
- if (!isRSC2)
355
- fetcherPromise.then((data2) => {
356
- mutate == null ? void 0 : mutate(key, data2);
357
- }).catch((err) => {
358
- var _a2;
359
- const keyInfo = key ? "$swr$" + key : "";
360
- cache == null ? void 0 : cache.set(keyInfo, __spreadProps(__spreadValues({}, (_a2 = cache == null ? void 0 : cache.get(keyInfo)) != null ? _a2 : {}), { error: err }));
361
- });
362
- return fetcherPromise;
363
- };
364
- }, [fetcher, fetchingData, cache, key, dependentKeyDataErrorPromise]);
365
- const res = useMutablePlasmicQueryData(key, fetcher, {
366
- shouldRetryOnError: false,
367
- // If revalidateIfStale is true, then if there's a cache entry with a key,
368
- // but no mounted hook with that key yet, and when the hook mounts with the key,
369
- // swr will revalidate. This may be reasonable behavior, but for us, this
370
- // happens all the time -- we prepopulate the cache with proxy-invoked fetch,
371
- // sometimes before swr had a chance to run the effect. So we turn off
372
- // revalidateIfStale here, and just let the user manage invalidation.
373
- revalidateIfStale: false
374
- });
375
- const { data, error, isLoading } = res;
376
- if (fetchingData.fetchingPromise != null && data !== void 0) {
377
- fetchingData.fetchingPromise = void 0;
378
- }
379
- return React.useMemo(() => {
380
- const result = __spreadValues(__spreadValues({}, data != null ? data : {}), pick(res, "isLoading", "error"));
381
- if (!(opts == null ? void 0 : opts.noUndefinedDataProxy) && reactMajorVersion >= 18 && enableLoadingBoundary && (isLoading || isNullDataOp || isWaitingOnDependentQuery) && result.data === void 0 && result.schema === void 0 && result.error === void 0) {
382
- result.data = mkUndefinedDataProxy(fetchingData, fetchAndUpdateCache);
383
- result.schema = mkUndefinedDataProxy(fetchingData, fetchAndUpdateCache);
406
+ const fetcher = (op) => {
407
+ return executePlasmicDataOp(op, {
408
+ userAuthToken: (ctx == null ? void 0 : ctx.userAuthToken) || void 0,
409
+ user: ctx == null ? void 0 : ctx.user,
410
+ paginate: opts == null ? void 0 : opts.paginate
411
+ });
412
+ };
413
+ const resultMapper = (result) => {
414
+ var _a;
415
+ return __spreadValues(__spreadValues({}, (_a = result.data) != null ? _a : {}), pick(result, "error", "isLoading"));
416
+ };
417
+ return usePlasmicFetch(
418
+ key,
419
+ resolvedDataOp,
420
+ fetcher,
421
+ resultMapper,
422
+ ["data", "schema", "error"],
423
+ {
424
+ noUndefinedDataProxy: opts == null ? void 0 : opts.noUndefinedDataProxy
384
425
  }
385
- return result;
386
- }, [
387
- isNullDataOp,
388
- isWaitingOnDependentQuery,
389
- data,
390
- error,
391
- isLoading,
392
- opts == null ? void 0 : opts.noUndefinedDataProxy,
393
- enableLoadingBoundary,
394
- fetchingData,
395
- fetchAndUpdateCache
396
- ]);
426
+ );
397
427
  }
398
428
  function usePlasmicDataMutationOp(dataOp) {
399
429
  const ctx = usePlasmicDataSourceContext();
400
430
  const userToken = ctx == null ? void 0 : ctx.userAuthToken;
401
- const getRealDataOp = React.useCallback(() => __async(this, null, function* () {
431
+ const getRealDataOp = React2.useCallback(() => __async(this, null, function* () {
402
432
  const tryGetRealDataOp = () => __async(this, null, function* () {
403
433
  const resolved = resolveDataOp(dataOp);
404
434
  if (!resolved) {
@@ -412,7 +442,7 @@ function usePlasmicDataMutationOp(dataOp) {
412
442
  });
413
443
  return yield tryGetRealDataOp();
414
444
  }), [dataOp]);
415
- return React.useCallback(() => __async(this, null, function* () {
445
+ return React2.useCallback(() => __async(this, null, function* () {
416
446
  var _a;
417
447
  const { sourceId, opId, userArgs } = (_a = yield getRealDataOp()) != null ? _a : {};
418
448
  if (!sourceId || !opId) {
@@ -435,7 +465,7 @@ function Fetcher(props) {
435
465
  const data = usePlasmicDataOp(dataOp, __spreadValues({}, !!pageIndex && !!pageSize && {
436
466
  paginate: { pageIndex, pageSize }
437
467
  }));
438
- const $queries = React2.useMemo(
468
+ const $queries = React3.useMemo(
439
469
  () => __spreadProps(__spreadValues({}, props.queries), { [name != null ? name : "data"]: data }),
440
470
  [props.queries, name, data]
441
471
  );
@@ -477,7 +507,7 @@ var FetcherMeta = {
477
507
  };
478
508
 
479
509
  // src/helpers.ts
480
- import { useMemo as useMemo2 } from "react";
510
+ import { useMemo } from "react";
481
511
  function normalizeData(rawData) {
482
512
  var _a;
483
513
  if (!rawData) {
@@ -494,7 +524,7 @@ function normalizeData(rawData) {
494
524
  return { data: dataArray, schema };
495
525
  }
496
526
  function useNormalizedData(rawData) {
497
- return useMemo2(() => normalizeData(rawData), [rawData]);
527
+ return useMemo(() => normalizeData(rawData), [rawData]);
498
528
  }
499
529
  function tryGetDataArray(rawData) {
500
530
  if (rawData == null || typeof rawData !== "object") {
@@ -588,10 +618,10 @@ function deriveFieldConfigs(specifiedFieldsPartial, schema, makeDefaultConfig) {
588
618
  }
589
619
 
590
620
  // src/hooks/useDependencyAwareQuery.tsx
591
- import React3 from "react";
621
+ import React4 from "react";
592
622
  function usePrevious(value) {
593
- const prevValue = React3.useRef(void 0);
594
- React3.useEffect(() => {
623
+ const prevValue = React4.useRef(void 0);
624
+ React4.useEffect(() => {
595
625
  prevValue.current = value;
596
626
  return () => {
597
627
  prevValue.current = void 0;
@@ -612,7 +642,7 @@ function useDependencyAwareQuery({
612
642
  }));
613
643
  const finalName = name != null ? name : "data";
614
644
  const prevName = usePrevious(finalName);
615
- React3.useEffect(() => {
645
+ React4.useEffect(() => {
616
646
  if (!(finalName in $queries) || $queries[finalName] !== data) {
617
647
  const $queries2 = __spreadProps(__spreadValues({}, $queries), {
618
648
  [finalName]: data
@@ -625,6 +655,50 @@ function useDependencyAwareQuery({
625
655
  }, [finalName, prevName, data, $queries, setDollarQueries]);
626
656
  }
627
657
 
658
+ // src/serverQueries/client.ts
659
+ import {
660
+ wrapLoadingFetcher as wrapLoadingFetcher2
661
+ } from "@plasmicapp/query";
662
+
663
+ // src/serverQueries/common.ts
664
+ function resolveParams(params, errorFn) {
665
+ try {
666
+ return params();
667
+ } catch (err) {
668
+ return errorFn(err);
669
+ }
670
+ }
671
+
672
+ // src/serverQueries/client.ts
673
+ function makeQueryCacheKey(id, params) {
674
+ return `${id}:${JSON.stringify(params)}`;
675
+ }
676
+ function usePlasmicServerQuery(serverQuery, fallbackData, opts) {
677
+ const resolvedParams = resolveParams(serverQuery.execParams, (err) => {
678
+ if (isPlasmicUndefinedDataErrorPromise(err)) {
679
+ return err;
680
+ }
681
+ throw err;
682
+ });
683
+ const key = !resolvedParams || isPlasmicUndefinedDataErrorPromise(resolvedParams) ? null : makeQueryCacheKey(serverQuery.id, resolvedParams);
684
+ const fetcher = (params) => {
685
+ return wrapLoadingFetcher2(serverQuery.fn)(...params);
686
+ };
687
+ const resultMapper = (result) => {
688
+ return __spreadValues({}, pick(result, "data", "error", "isLoading"));
689
+ };
690
+ return usePlasmicFetch(
691
+ key,
692
+ resolvedParams,
693
+ fetcher,
694
+ resultMapper,
695
+ ["data", "error"],
696
+ __spreadValues({
697
+ fallbackData
698
+ }, opts)
699
+ );
700
+ }
701
+
628
702
  // src/serverQueries/server.ts
629
703
  var PlasmicUndefinedServerError = class extends Error {
630
704
  constructor(msg) {
@@ -653,19 +727,14 @@ function mkPlasmicUndefinedServerProxy() {
653
727
  isLoading: true
654
728
  };
655
729
  }
656
- function resolveParams(params) {
657
- try {
658
- return params();
659
- } catch (err) {
660
- if (isPlasmicUndefinedServerError(err)) {
661
- return err;
662
- }
663
- throw err;
664
- }
665
- }
666
730
  function executeServerQuery(serverQuery) {
667
731
  return __async(this, null, function* () {
668
- const resolvedParams = resolveParams(serverQuery.execParams);
732
+ const resolvedParams = resolveParams(serverQuery.execParams, (err) => {
733
+ if (isPlasmicUndefinedServerError(err)) {
734
+ return err;
735
+ }
736
+ throw err;
737
+ });
669
738
  if (isPlasmicUndefinedServerError(resolvedParams)) {
670
739
  return mkPlasmicUndefinedServerProxy();
671
740
  }
@@ -679,13 +748,15 @@ export {
679
748
  executePlasmicDataOp,
680
749
  executeServerQuery,
681
750
  makeCacheKey,
751
+ makeQueryCacheKey,
682
752
  mkPlasmicUndefinedServerProxy,
683
753
  normalizeData,
684
754
  useDependencyAwareQuery,
685
755
  useNormalizedData,
686
- usePlasmicDataConfig2 as usePlasmicDataConfig,
756
+ usePlasmicDataConfig3 as usePlasmicDataConfig,
687
757
  usePlasmicDataMutationOp,
688
758
  usePlasmicDataOp,
689
- usePlasmicInvalidate
759
+ usePlasmicInvalidate,
760
+ usePlasmicServerQuery
690
761
  };
691
762
  //# sourceMappingURL=index.esm.js.map