@plasmicapp/data-sources 1.0.16 → 1.0.18
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 +45 -37
- package/dist/index.esm.js +16 -15
- package/dist/index.esm.js.map +2 -2
- package/dist/index.js +17 -16
- package/dist/index.js.map +3 -3
- package/package.json +4 -5
package/dist/index.d.ts
CHANGED
|
@@ -22,6 +22,14 @@ export declare type BaseFieldConfig = {
|
|
|
22
22
|
fieldId?: string;
|
|
23
23
|
};
|
|
24
24
|
|
|
25
|
+
/**
|
|
26
|
+
* Initial context just before execution.
|
|
27
|
+
* @internal
|
|
28
|
+
*/
|
|
29
|
+
declare type ClientQueryExecutionContext = Pick<QueryExecutionContext, "$ctx" | "$props"> & {
|
|
30
|
+
$state: QueryExecutionContext["$state"] | null;
|
|
31
|
+
};
|
|
32
|
+
|
|
25
33
|
/**
|
|
26
34
|
* Represents the result of a client-side query.
|
|
27
35
|
* @deprecated See https://docs.plasmic.app/learn/integrations
|
|
@@ -99,6 +107,16 @@ declare interface ExecuteOpts {
|
|
|
99
107
|
/** @deprecated See https://docs.plasmic.app/learn/integrations */
|
|
100
108
|
export declare function executePlasmicDataOp<T extends SingleRowResult | ManyRowsResult>(op: DataOp, opts?: ExecuteOpts): Promise<T>;
|
|
101
109
|
|
|
110
|
+
/**
|
|
111
|
+
* Executes all queries from a serialized component tree and returns query results.
|
|
112
|
+
*
|
|
113
|
+
* 1. Walk the tree to discover queries, creating StatefulQueryResult + PlasmicQuery
|
|
114
|
+
* 2. Execute all newly discovered queries in parallel
|
|
115
|
+
* 3. After all settle, re-walk. Discover queries from newly expanded repeated nodes
|
|
116
|
+
* Continue until no new queries found.
|
|
117
|
+
*/
|
|
118
|
+
export declare function executePlasmicQueries(rootNode: QueryComponentNode, env: InitialQueryExecutionContext): Promise<ExecutePlasmicQueriesResult>;
|
|
119
|
+
|
|
102
120
|
declare interface ExecutePlasmicQueriesResult {
|
|
103
121
|
/** All queries, including nested, by query cache key hash. Passed to PlasmicRootProvider */
|
|
104
122
|
cache: Record<string, unknown>;
|
|
@@ -125,6 +143,12 @@ export declare interface FetcherProps extends DataOpConfig {
|
|
|
125
143
|
queries?: Record<string, any>;
|
|
126
144
|
}
|
|
127
145
|
|
|
146
|
+
/**
|
|
147
|
+
* Initial context just before execution.
|
|
148
|
+
* @internal
|
|
149
|
+
*/
|
|
150
|
+
declare type InitialQueryExecutionContext = Pick<QueryExecutionContext, "$ctx" | "$props">;
|
|
151
|
+
|
|
128
152
|
export declare function isPlasmicUndefinedDataErrorPromise(x: any): x is PlasmicUndefinedDataErrorPromise;
|
|
129
153
|
|
|
130
154
|
/** @deprecated See https://docs.plasmic.app/learn/integrations */
|
|
@@ -236,12 +260,6 @@ export declare type QueryExecutionContext = {
|
|
|
236
260
|
$q: Record<string, PlasmicQueryResult>;
|
|
237
261
|
};
|
|
238
262
|
|
|
239
|
-
/**
|
|
240
|
-
* Initial context just before execution.
|
|
241
|
-
* @internal
|
|
242
|
-
*/
|
|
243
|
-
declare type QueryExecutionInitialContext = Pick<QueryExecutionContext, "$ctx" | "$props">;
|
|
244
|
-
|
|
245
263
|
/** @internal */
|
|
246
264
|
declare type QueryNode = QueryComponentNode | QueryCodeComponentNode | QueryRepeatedNode | QueryDataProviderNode | QueryVisibilityNode;
|
|
247
265
|
|
|
@@ -372,15 +390,25 @@ export declare interface TableSchema {
|
|
|
372
390
|
|
|
373
391
|
export declare function throwIfPlasmicUndefinedDataError(err: unknown): void;
|
|
374
392
|
|
|
393
|
+
/** @deprecated See https://docs.plasmic.app/learn/integrations */
|
|
394
|
+
export declare function useNormalizedData(rawData: unknown): NormalizedData | undefined;
|
|
395
|
+
|
|
396
|
+
export { usePlasmicDataConfig }
|
|
397
|
+
|
|
398
|
+
/** @deprecated See https://docs.plasmic.app/learn/integrations */
|
|
399
|
+
export declare function usePlasmicDataMutationOp<T extends SingleRowResult | ManyRowsResult>(dataOp: ResolvableDataOp): () => Promise<T | undefined>;
|
|
400
|
+
|
|
401
|
+
/** @deprecated See https://docs.plasmic.app/learn/integrations */
|
|
402
|
+
export declare function usePlasmicDataOp<T extends SingleRowResult | ManyRowsResult, E = any>(dataOp: ResolvableDataOp, opts?: {
|
|
403
|
+
paginate?: Pagination;
|
|
404
|
+
noUndefinedDataProxy?: boolean;
|
|
405
|
+
}): ClientQueryResult<T["data"]>;
|
|
406
|
+
|
|
375
407
|
/**
|
|
376
|
-
*
|
|
377
|
-
*
|
|
378
|
-
* 1. Walk the tree to discover queries, creating StatefulQueryResult + PlasmicQuery
|
|
379
|
-
* 2. Execute all newly discovered queries in parallel
|
|
380
|
-
* 3. After all settle, re-walk. Discover queries from newly expanded repeated nodes
|
|
381
|
-
* Continue until no new queries found.
|
|
408
|
+
* Returns a function that invalidates cached query data. Accepts a list of invalidation keys
|
|
409
|
+
* or `plasmic_refresh_all` to invalidate everything.
|
|
382
410
|
*/
|
|
383
|
-
export declare function
|
|
411
|
+
export declare function usePlasmicInvalidate(): (invalidatedKeys: string[] | null | undefined) => Promise<any[] | undefined>;
|
|
384
412
|
|
|
385
413
|
/**
|
|
386
414
|
* @internal
|
|
@@ -394,7 +422,7 @@ export declare function unstable_executePlasmicQueries(rootNode: QueryComponentN
|
|
|
394
422
|
*
|
|
395
423
|
* Example codegen:
|
|
396
424
|
*
|
|
397
|
-
* export const
|
|
425
|
+
* export const queryTree = {
|
|
398
426
|
* type: "component",
|
|
399
427
|
* queries: {
|
|
400
428
|
* films: { fn: $$.fetch, id: "fetch", args: ({ $q, $props, $ctx }) => [...] }
|
|
@@ -403,37 +431,17 @@ export declare function unstable_executePlasmicQueries(rootNode: QueryComponentN
|
|
|
403
431
|
* };
|
|
404
432
|
*
|
|
405
433
|
* export function ClientComponent($props, $ctx) {
|
|
406
|
-
* const $q = usePlasmicQueries(
|
|
434
|
+
* const $q = usePlasmicQueries(queryTree, { $ctx, $props, $state: null });
|
|
407
435
|
* return <div>{$q.films.data}</div>
|
|
408
436
|
* }
|
|
409
437
|
*/
|
|
410
|
-
export declare function
|
|
438
|
+
export declare function usePlasmicQueries(tree: QueryComponentNode, env: ClientQueryExecutionContext): Record<string, PlasmicQueryResult>;
|
|
411
439
|
|
|
412
440
|
/**
|
|
413
441
|
* @internal
|
|
414
442
|
* Wraps each PlasmicQueryResult so that they return a hardcoded string for
|
|
415
443
|
* undefined/loading and error cases.
|
|
416
444
|
*/
|
|
417
|
-
export declare function
|
|
418
|
-
|
|
419
|
-
/** @deprecated See https://docs.plasmic.app/learn/integrations */
|
|
420
|
-
export declare function useNormalizedData(rawData: unknown): NormalizedData | undefined;
|
|
421
|
-
|
|
422
|
-
export { usePlasmicDataConfig }
|
|
423
|
-
|
|
424
|
-
/** @deprecated See https://docs.plasmic.app/learn/integrations */
|
|
425
|
-
export declare function usePlasmicDataMutationOp<T extends SingleRowResult | ManyRowsResult>(dataOp: ResolvableDataOp): () => Promise<T | undefined>;
|
|
426
|
-
|
|
427
|
-
/** @deprecated See https://docs.plasmic.app/learn/integrations */
|
|
428
|
-
export declare function usePlasmicDataOp<T extends SingleRowResult | ManyRowsResult, E = any>(dataOp: ResolvableDataOp, opts?: {
|
|
429
|
-
paginate?: Pagination;
|
|
430
|
-
noUndefinedDataProxy?: boolean;
|
|
431
|
-
}): ClientQueryResult<T["data"]>;
|
|
432
|
-
|
|
433
|
-
/**
|
|
434
|
-
* Returns a function that invalidates cached query data. Accepts a list of invalidation keys
|
|
435
|
-
* or `plasmic_refresh_all` to invalidate everything.
|
|
436
|
-
*/
|
|
437
|
-
export declare function usePlasmicInvalidate(): (invalidatedKeys: string[] | null | undefined) => Promise<any[] | undefined>;
|
|
445
|
+
export declare function wrapPlasmicQueriesForMetadata<T extends Record<string, PlasmicQueryResult>>(queries: T, ifUndefined?: (promise: PlasmicUndefinedDataErrorPromise) => unknown, ifError?: (err: unknown) => unknown): T;
|
|
438
446
|
|
|
439
447
|
export { }
|
package/dist/index.esm.js
CHANGED
|
@@ -231,7 +231,6 @@ import {
|
|
|
231
231
|
import * as React2 from "react";
|
|
232
232
|
|
|
233
233
|
// src/executor.tsx
|
|
234
|
-
import fetch from "@plasmicapp/isomorphic-unfetch";
|
|
235
234
|
import { wrapLoadingFetcher } from "@plasmicapp/query";
|
|
236
235
|
import stringify from "fast-stringify";
|
|
237
236
|
|
|
@@ -718,17 +717,17 @@ function resolveParams(queryId, params) {
|
|
|
718
717
|
})
|
|
719
718
|
);
|
|
720
719
|
}
|
|
721
|
-
function
|
|
722
|
-
return
|
|
723
|
-
|
|
720
|
+
function wrapPlasmicQueriesForMetadata(queries, ifUndefined, ifError) {
|
|
721
|
+
return wrapPlasmicQueriesWithFallbacks(
|
|
722
|
+
queries,
|
|
724
723
|
ifUndefined != null ? ifUndefined : (() => "\u2026"),
|
|
725
724
|
ifError != null ? ifError : (() => "[ERROR]")
|
|
726
725
|
);
|
|
727
726
|
}
|
|
728
|
-
function
|
|
727
|
+
function wrapPlasmicQueriesWithFallbacks(queries, ifUndefined, ifError) {
|
|
729
728
|
return mapRecords(
|
|
730
729
|
(_queryName, $query) => new FallbackQueryResult($query, ifUndefined, ifError),
|
|
731
|
-
|
|
730
|
+
queries
|
|
732
731
|
);
|
|
733
732
|
}
|
|
734
733
|
var FallbackQueryResult = class {
|
|
@@ -854,14 +853,16 @@ function createInitial$State($ctx, $props, $q, stateSpecs) {
|
|
|
854
853
|
|
|
855
854
|
// src/serverQueries/client.ts
|
|
856
855
|
var GLOBAL_CACHE = /* @__PURE__ */ new Map();
|
|
857
|
-
function usePlasmicQueries(tree,
|
|
856
|
+
function usePlasmicQueries(tree, env) {
|
|
858
857
|
var _a;
|
|
858
|
+
const { $ctx, $props } = env;
|
|
859
859
|
const wrappedQueries = React4.useMemo(() => wrapQueries(tree.queries), [tree]);
|
|
860
860
|
const $queries = React4.useMemo(
|
|
861
861
|
() => createDollarQueries(Object.keys(tree.queries)),
|
|
862
862
|
[tree]
|
|
863
863
|
);
|
|
864
864
|
const $queryStates = $queries;
|
|
865
|
+
let $state = env.$state;
|
|
865
866
|
if (!$state) {
|
|
866
867
|
$state = createInitial$State($ctx, $props, $queryStates, tree.stateSpecs);
|
|
867
868
|
}
|
|
@@ -1101,8 +1102,8 @@ var ROOT_COMPONENT_KEY_PATH = "root";
|
|
|
1101
1102
|
function appendKeyPath(currentKeyPath, currentInput) {
|
|
1102
1103
|
return currentKeyPath ? `${currentKeyPath}/${currentInput}` : currentInput;
|
|
1103
1104
|
}
|
|
1104
|
-
function executeQueryTree(rootNode,
|
|
1105
|
-
const { $props, $ctx } =
|
|
1105
|
+
function executeQueryTree(rootNode, env, queriesByComponent) {
|
|
1106
|
+
const { $props, $ctx } = env;
|
|
1106
1107
|
const initialContext = {
|
|
1107
1108
|
$props,
|
|
1108
1109
|
$ctx,
|
|
@@ -1300,12 +1301,12 @@ function executeRepeatedNode(node, params) {
|
|
|
1300
1301
|
);
|
|
1301
1302
|
});
|
|
1302
1303
|
}
|
|
1303
|
-
function executePlasmicQueries(rootNode,
|
|
1304
|
+
function executePlasmicQueries(rootNode, env) {
|
|
1304
1305
|
return __async(this, null, function* () {
|
|
1305
1306
|
const queriesByComponent = /* @__PURE__ */ new Map();
|
|
1306
1307
|
const discoveredQueries = [];
|
|
1307
1308
|
while (true) {
|
|
1308
|
-
const newQueries = executeQueryTree(rootNode,
|
|
1309
|
+
const newQueries = executeQueryTree(rootNode, env, queriesByComponent);
|
|
1309
1310
|
if (newQueries.length === 0) {
|
|
1310
1311
|
break;
|
|
1311
1312
|
}
|
|
@@ -1549,6 +1550,7 @@ export {
|
|
|
1549
1550
|
safeExecResult as _safeExecResult,
|
|
1550
1551
|
deriveFieldConfigs,
|
|
1551
1552
|
executePlasmicDataOp,
|
|
1553
|
+
executePlasmicQueries,
|
|
1552
1554
|
executeServerQuery,
|
|
1553
1555
|
isPlasmicUndefinedDataErrorPromise,
|
|
1554
1556
|
makeCacheKey,
|
|
@@ -1556,13 +1558,12 @@ export {
|
|
|
1556
1558
|
matchesQueryCacheKey,
|
|
1557
1559
|
normalizeData,
|
|
1558
1560
|
throwIfPlasmicUndefinedDataError,
|
|
1559
|
-
executePlasmicQueries as unstable_executePlasmicQueries,
|
|
1560
|
-
usePlasmicQueries as unstable_usePlasmicQueries,
|
|
1561
|
-
wrapDollarQueriesForMetadata as unstable_wrapDollarQueriesForMetadata,
|
|
1562
1561
|
useNormalizedData,
|
|
1563
1562
|
usePlasmicDataConfig4 as usePlasmicDataConfig,
|
|
1564
1563
|
usePlasmicDataMutationOp,
|
|
1565
1564
|
usePlasmicDataOp,
|
|
1566
|
-
usePlasmicInvalidate
|
|
1565
|
+
usePlasmicInvalidate,
|
|
1566
|
+
usePlasmicQueries,
|
|
1567
|
+
wrapPlasmicQueriesForMetadata
|
|
1567
1568
|
};
|
|
1568
1569
|
//# sourceMappingURL=index.esm.js.map
|