@plasmicapp/data-sources 0.1.209 → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +122 -106
- package/dist/index.esm.js +306 -65
- package/dist/index.esm.js.map +4 -4
- package/dist/index.js +306 -65
- package/dist/index.js.map +4 -4
- package/package.json +8 -11
package/dist/index.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { CodeComponentMeta } from '@plasmicapp/host/registerComponent';
|
|
2
2
|
import { PlasmicDataSourceContextValue } from '@plasmicapp/data-sources-context';
|
|
3
3
|
import { default as React_2 } from 'react';
|
|
4
|
-
import { SWRResponse } from '@plasmicapp/query';
|
|
5
4
|
import { usePlasmicDataConfig } from '@plasmicapp/query';
|
|
6
5
|
|
|
6
|
+
/** @deprecated See https://docs.plasmic.app/learn/integrations */
|
|
7
7
|
export declare type BaseFieldConfig = {
|
|
8
8
|
key?: string;
|
|
9
9
|
fieldId?: string;
|
|
@@ -11,6 +11,7 @@ export declare type BaseFieldConfig = {
|
|
|
11
11
|
|
|
12
12
|
/**
|
|
13
13
|
* Represents the result of a client-side query.
|
|
14
|
+
* @deprecated See https://docs.plasmic.app/learn/integrations
|
|
14
15
|
*/
|
|
15
16
|
export declare interface ClientQueryResult<T = any> {
|
|
16
17
|
/**
|
|
@@ -42,6 +43,13 @@ export declare interface ClientQueryResult<T = any> {
|
|
|
42
43
|
isLoading?: boolean;
|
|
43
44
|
}
|
|
44
45
|
|
|
46
|
+
/**
|
|
47
|
+
* A function that takes the execution context and returns a value.
|
|
48
|
+
* Used for all dynamic expressions in the query tree (args, collectionExpr, visibilityExpr, data, propsContext values).
|
|
49
|
+
*/
|
|
50
|
+
declare type ContextFn<R> = (ctx: QueryExecutionContext) => R;
|
|
51
|
+
|
|
52
|
+
/** @deprecated See https://docs.plasmic.app/learn/integrations */
|
|
45
53
|
export declare interface DataOp {
|
|
46
54
|
sourceId: string;
|
|
47
55
|
opId: string;
|
|
@@ -51,22 +59,19 @@ export declare interface DataOp {
|
|
|
51
59
|
roleId?: string | null;
|
|
52
60
|
}
|
|
53
61
|
|
|
62
|
+
/** @deprecated See https://docs.plasmic.app/learn/integrations */
|
|
54
63
|
declare interface DataOpConfig {
|
|
55
64
|
name?: string;
|
|
56
65
|
pageIndex?: number;
|
|
57
66
|
pageSize?: number;
|
|
58
67
|
}
|
|
59
68
|
|
|
69
|
+
/** @deprecated See https://docs.plasmic.app/learn/integrations */
|
|
60
70
|
export declare interface DataSourceSchema {
|
|
61
71
|
tables: TableSchema[];
|
|
62
72
|
}
|
|
63
73
|
|
|
64
|
-
|
|
65
|
-
$queries: Record<string, any>;
|
|
66
|
-
setDollarQueries: ($queries: Record<string, any>) => void;
|
|
67
|
-
getDataOp: () => DataOp;
|
|
68
|
-
}
|
|
69
|
-
|
|
74
|
+
/** @deprecated See https://docs.plasmic.app/learn/integrations */
|
|
70
75
|
export declare function deriveFieldConfigs<T extends BaseFieldConfig>(specifiedFieldsPartial: Partial<T>[], schema: TableSchema | undefined, makeDefaultConfig: (field: TableFieldSchema | undefined) => T): {
|
|
71
76
|
mergedFields: T[];
|
|
72
77
|
minimalFullLengthFields: Partial<T>[];
|
|
@@ -78,26 +83,39 @@ declare interface ExecuteOpts {
|
|
|
78
83
|
paginate?: Pagination;
|
|
79
84
|
}
|
|
80
85
|
|
|
86
|
+
/** @deprecated See https://docs.plasmic.app/learn/integrations */
|
|
81
87
|
export declare function executePlasmicDataOp<T extends SingleRowResult | ManyRowsResult>(op: DataOp, opts?: ExecuteOpts): Promise<T>;
|
|
82
88
|
|
|
89
|
+
declare interface ExecutePlasmicQueriesResult {
|
|
90
|
+
/** All queries, including nested, by query cache key hash. Passed to PlasmicRootProvider */
|
|
91
|
+
cache: Record<string, unknown>;
|
|
92
|
+
/** Root component query results keyed by query name. */
|
|
93
|
+
queries: Record<string, PlasmicQueryResult>;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/** @deprecated See https://docs.plasmic.app/learn/integrations */
|
|
83
97
|
export declare function Fetcher(props: FetcherProps): React_2.ReactElement | null;
|
|
84
98
|
|
|
99
|
+
/** @deprecated See https://docs.plasmic.app/learn/integrations */
|
|
85
100
|
export declare const FetcherMeta: CodeComponentMeta<FetcherProps>;
|
|
86
101
|
|
|
102
|
+
/** @deprecated See https://docs.plasmic.app/learn/integrations */
|
|
87
103
|
export declare interface FetcherProps extends DataOpConfig {
|
|
88
104
|
dataOp?: DataOp;
|
|
89
105
|
children?: ($queries: Record<string, any>) => React_2.ReactElement | null;
|
|
90
106
|
queries?: Record<string, any>;
|
|
91
107
|
}
|
|
92
108
|
|
|
109
|
+
/** @deprecated See https://docs.plasmic.app/learn/integrations */
|
|
93
110
|
export declare function makeCacheKey(dataOp: DataOp, opts?: {
|
|
94
111
|
paginate?: Pagination;
|
|
95
112
|
userAuthToken?: string | null;
|
|
96
113
|
}): string;
|
|
97
114
|
|
|
98
|
-
/** Make a cache key for a query */
|
|
115
|
+
/** @internal Make a cache key for a query */
|
|
99
116
|
export declare function makeQueryCacheKey(id: string, params: any[]): string;
|
|
100
117
|
|
|
118
|
+
/** @deprecated See https://docs.plasmic.app/learn/integrations */
|
|
101
119
|
export declare interface ManyRowsResult<T = any> {
|
|
102
120
|
data: T[];
|
|
103
121
|
total?: number;
|
|
@@ -105,24 +123,29 @@ export declare interface ManyRowsResult<T = any> {
|
|
|
105
123
|
paginate?: Pagination;
|
|
106
124
|
}
|
|
107
125
|
|
|
126
|
+
/** @deprecated See https://docs.plasmic.app/learn/integrations */
|
|
108
127
|
export declare function normalizeData(rawData: unknown): NormalizedData | undefined;
|
|
109
128
|
|
|
129
|
+
/** @deprecated See https://docs.plasmic.app/learn/integrations */
|
|
110
130
|
export declare interface NormalizedData {
|
|
111
131
|
data: Record<string, unknown>[];
|
|
112
132
|
schema?: TableSchema;
|
|
113
133
|
}
|
|
114
134
|
|
|
135
|
+
/** @deprecated See https://docs.plasmic.app/learn/integrations */
|
|
115
136
|
export declare interface Pagination {
|
|
116
137
|
pageSize: number;
|
|
117
138
|
pageIndex: number;
|
|
118
139
|
}
|
|
119
140
|
|
|
141
|
+
/** @internal */
|
|
120
142
|
export declare interface PlasmicQuery<F extends (...args: unknown[]) => Promise<unknown> = (...args: unknown[]) => Promise<unknown>> {
|
|
121
143
|
fn: F;
|
|
122
144
|
execParams: () => Parameters<F>;
|
|
123
145
|
id: string;
|
|
124
146
|
}
|
|
125
147
|
|
|
148
|
+
/** @internal */
|
|
126
149
|
export declare interface PlasmicQueryResult<T = unknown> {
|
|
127
150
|
/**
|
|
128
151
|
* Returns the key if params have resolved.
|
|
@@ -142,17 +165,76 @@ declare interface PlasmicUndefinedDataErrorPromise extends Promise<any> {
|
|
|
142
165
|
message: string;
|
|
143
166
|
}
|
|
144
167
|
|
|
168
|
+
/** @internal */
|
|
169
|
+
declare interface QueryCodeComponentNode {
|
|
170
|
+
type: "codeComponent";
|
|
171
|
+
propsContext: Record<string, ContextFn<unknown>>;
|
|
172
|
+
serverRenderingConfig?: SerializedServerRenderingConfig;
|
|
173
|
+
children: QueryNode[];
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
/** @internal */
|
|
177
|
+
export declare interface QueryComponentNode {
|
|
178
|
+
type: "component";
|
|
179
|
+
queries: Record<string, SerializedServerQuery>;
|
|
180
|
+
propsContext: Record<string, ContextFn<unknown>>;
|
|
181
|
+
children: QueryNode[];
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
/** @internal */
|
|
185
|
+
declare interface QueryDataProviderNode {
|
|
186
|
+
type: "dataProvider";
|
|
187
|
+
name: string;
|
|
188
|
+
data: ContextFn<unknown>;
|
|
189
|
+
children: QueryNode[];
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
declare interface QueryExecutionContext {
|
|
193
|
+
$props: Record<string, unknown>;
|
|
194
|
+
$ctx: Record<string, unknown>;
|
|
195
|
+
$state: Record<string, unknown>;
|
|
196
|
+
$q: Record<string, PlasmicQueryResult>;
|
|
197
|
+
$scopedItemVars: Record<string, unknown>;
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
/** @internal */
|
|
201
|
+
declare type QueryExecutionInitialContext = Pick<QueryExecutionContext, "$props" | "$ctx">;
|
|
202
|
+
|
|
203
|
+
/** @internal */
|
|
204
|
+
declare type QueryNode = QueryComponentNode | QueryCodeComponentNode | QueryRepeatedNode | QueryDataProviderNode | QueryVisibilityNode;
|
|
205
|
+
|
|
206
|
+
/** @internal */
|
|
207
|
+
declare interface QueryRepeatedNode {
|
|
208
|
+
type: "repeated";
|
|
209
|
+
collectionExpr: ContextFn<unknown>;
|
|
210
|
+
itemName: string;
|
|
211
|
+
indexName: string;
|
|
212
|
+
children: QueryNode[];
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
/** @deprecated See https://docs.plasmic.app/learn/integrations */
|
|
145
216
|
export declare type QueryResult = Partial<ManyRowsResult<any>> & {
|
|
146
217
|
error?: any;
|
|
147
218
|
isLoading?: boolean;
|
|
148
219
|
};
|
|
149
220
|
|
|
221
|
+
/** @internal */
|
|
222
|
+
declare interface QueryVisibilityNode {
|
|
223
|
+
type: "visibility";
|
|
224
|
+
visibilityExpr: ContextFn<unknown>;
|
|
225
|
+
children: QueryNode[];
|
|
226
|
+
}
|
|
227
|
+
|
|
150
228
|
declare type ResolvableDataOp = DataOp | undefined | null | (() => DataOp | undefined | null);
|
|
151
229
|
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
230
|
+
declare interface SerializedServerQuery {
|
|
231
|
+
id: string;
|
|
232
|
+
fn: (...args: unknown[]) => Promise<unknown>;
|
|
233
|
+
args: ContextFn<unknown[]>;
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
declare type SerializedServerRenderingConfig = boolean;
|
|
237
|
+
|
|
156
238
|
declare class SettablePromise<T> {
|
|
157
239
|
readonly promise: Promise<T>;
|
|
158
240
|
private _resolve;
|
|
@@ -162,6 +244,7 @@ declare class SettablePromise<T> {
|
|
|
162
244
|
reject(error: unknown): void;
|
|
163
245
|
}
|
|
164
246
|
|
|
247
|
+
/** @deprecated See https://docs.plasmic.app/learn/integrations */
|
|
165
248
|
export declare interface SingleRowResult<T = any> {
|
|
166
249
|
data: T;
|
|
167
250
|
schema: TableSchema;
|
|
@@ -221,6 +304,7 @@ export declare type _StatefulQueryState<T = unknown> = {
|
|
|
221
304
|
/** @internal */
|
|
222
305
|
export declare type _StateListener<T = unknown> = (state: _StatefulQueryState<T>, prevState: _StatefulQueryState<T>) => void;
|
|
223
306
|
|
|
307
|
+
/** @deprecated See https://docs.plasmic.app/learn/integrations */
|
|
224
308
|
export declare interface TableFieldSchema {
|
|
225
309
|
id: string;
|
|
226
310
|
label?: string;
|
|
@@ -230,8 +314,10 @@ export declare interface TableFieldSchema {
|
|
|
230
314
|
options?: string[];
|
|
231
315
|
}
|
|
232
316
|
|
|
317
|
+
/** @deprecated See https://docs.plasmic.app/learn/integrations */
|
|
233
318
|
export declare type TableFieldType = "string" | "boolean" | "number" | "date" | "datetime" | "enum" | "json" | "unknown";
|
|
234
319
|
|
|
320
|
+
/** @deprecated See https://docs.plasmic.app/learn/integrations */
|
|
235
321
|
export declare interface TableSchema {
|
|
236
322
|
id: string;
|
|
237
323
|
schema?: string;
|
|
@@ -240,134 +326,64 @@ export declare interface TableSchema {
|
|
|
240
326
|
}
|
|
241
327
|
|
|
242
328
|
/**
|
|
243
|
-
*
|
|
244
|
-
*
|
|
245
|
-
* Each query gets a StatefulQueryResult which implements PlasmicQueryResult.
|
|
246
|
-
* If data is attempted to be accessed before query completion,
|
|
247
|
-
* PlasmicUndefinedDataErrorPromise is thrown. Dependent queries can catch this
|
|
248
|
-
* and delay its own execution until the dependent data is ready.
|
|
249
|
-
*
|
|
250
|
-
* When a query execution completes, the StatefulQueryResult must be notified
|
|
251
|
-
* via resolvePromise or rejectPromise.
|
|
252
|
-
*/
|
|
253
|
-
export declare function unstable_createDollarQueries<QueryName extends string>(queryNames: QueryName[]): Record<QueryName, PlasmicQueryResult>;
|
|
254
|
-
|
|
255
|
-
/**
|
|
256
|
-
* Executes all queries and returns the query data keyed by cache key.
|
|
257
|
-
*
|
|
258
|
-
* Example codegen:
|
|
329
|
+
* Executes all queries from a serialized component tree and returns query results.
|
|
259
330
|
*
|
|
260
|
-
*
|
|
261
|
-
*
|
|
262
|
-
*
|
|
263
|
-
*
|
|
264
|
-
* export function createQueries(
|
|
265
|
-
* $ctx: Record<string, any>,
|
|
266
|
-
* $queries: Record<QueryName, PlasmicQueryResult>,
|
|
267
|
-
* ) {
|
|
268
|
-
* return {
|
|
269
|
-
* result: {
|
|
270
|
-
* id: "plus",
|
|
271
|
-
* fn: (a, b) => a + b,
|
|
272
|
-
* execParams: () => [1, $queries.dep.data],
|
|
273
|
-
* },
|
|
274
|
-
* dep: {
|
|
275
|
-
* id: "times",
|
|
276
|
-
* fn: (a, b) => a * b,
|
|
277
|
-
* execParams: () => [2, 3],
|
|
278
|
-
* },
|
|
279
|
-
* }
|
|
280
|
-
* }
|
|
281
|
-
*
|
|
282
|
-
* export async function ServerComponent() {
|
|
283
|
-
* const $ctx = useDataEnv();
|
|
284
|
-
* const $queries = createDollarQueries();
|
|
285
|
-
* const queries = createQueries($ctx, $queries);
|
|
286
|
-
* const prefetchedCache = await executePlasmicQueries($queries, queries);
|
|
287
|
-
* return (
|
|
288
|
-
* <PlasmicQueryDataProvider prefetchedCache={prefetchedCache}>
|
|
289
|
-
* <ClientComponent />
|
|
290
|
-
* </PlasmicQueryDataProvider>
|
|
291
|
-
* );
|
|
292
|
-
* }
|
|
331
|
+
* 1. Walk the tree to discover queries, creating StatefulQueryResult + PlasmicQuery
|
|
332
|
+
* 2. Execute all newly discovered queries in parallel
|
|
333
|
+
* 3. After all settle, re-walk. Discover queries from newly expanded repeated nodes
|
|
334
|
+
* Continue until no new queries found.
|
|
293
335
|
*/
|
|
294
|
-
export declare function unstable_executePlasmicQueries
|
|
295
|
-
[cacheKey: string]: unknown;
|
|
296
|
-
}>;
|
|
336
|
+
export declare function unstable_executePlasmicQueries(rootNode: QueryComponentNode, options: QueryExecutionInitialContext): Promise<ExecutePlasmicQueriesResult>;
|
|
297
337
|
|
|
298
338
|
/**
|
|
339
|
+
* @internal
|
|
299
340
|
* This hook's job is to execute queries and re-render when query state changes.
|
|
300
341
|
* Data caching can be controlled via @plasmicapp/query.
|
|
301
342
|
*
|
|
302
|
-
* The actual results will be available in $queries
|
|
303
|
-
* createDollarQueries.
|
|
343
|
+
* The actual results will be available in the returned $queries object.
|
|
304
344
|
*
|
|
305
345
|
* Prefetched query data can be passed to
|
|
306
346
|
* <PlasmicQueryDataProvider prefetchedCache={...}>.
|
|
307
347
|
*
|
|
308
348
|
* Example codegen:
|
|
309
349
|
*
|
|
310
|
-
* export
|
|
311
|
-
*
|
|
312
|
-
*
|
|
313
|
-
*
|
|
314
|
-
*
|
|
315
|
-
*
|
|
316
|
-
*
|
|
317
|
-
* ) {
|
|
318
|
-
* return {
|
|
319
|
-
* result: {
|
|
320
|
-
* id: "plus",
|
|
321
|
-
* fn: (a, b) => a + b,
|
|
322
|
-
* execParams: () => [1, $queries.dep.data],
|
|
323
|
-
* },
|
|
324
|
-
* dep: {
|
|
325
|
-
* id: "times",
|
|
326
|
-
* fn: (a, b) => a * b,
|
|
327
|
-
* execParams: () => [2, 3],
|
|
328
|
-
* },
|
|
329
|
-
* }
|
|
330
|
-
* }
|
|
350
|
+
* export const serverQueryTree = {
|
|
351
|
+
* type: "component",
|
|
352
|
+
* queries: {
|
|
353
|
+
* films: { fn: $$.fetch, id: "fetch", args: ({ $q, $props, $ctx }) => [...] }
|
|
354
|
+
* },
|
|
355
|
+
* propsContext: {},
|
|
356
|
+
* };
|
|
331
357
|
*
|
|
332
|
-
* export function ClientComponent() {
|
|
333
|
-
* const $
|
|
334
|
-
*
|
|
335
|
-
* usePlasmicQueries($queries, queries);
|
|
336
|
-
* return <div>{$queries.result.data}</div> // $queries.result.data may suspend
|
|
358
|
+
* export function ClientComponent($props, $ctx) {
|
|
359
|
+
* const $q = usePlasmicQueries(serverQueryTree, $props, $ctx);
|
|
360
|
+
* return <div>{$q.films.data}</div>
|
|
337
361
|
* }
|
|
338
362
|
*/
|
|
339
|
-
export declare function unstable_usePlasmicQueries
|
|
363
|
+
export declare function unstable_usePlasmicQueries(tree: QueryComponentNode, $props: Record<string, unknown>, $ctx: Record<string, unknown>, $state?: Record<string, unknown>): Record<string, PlasmicQueryResult>;
|
|
340
364
|
|
|
341
365
|
/**
|
|
366
|
+
* @internal
|
|
342
367
|
* Wraps each PlasmicQueryResult so that they return a hardcoded string for
|
|
343
368
|
* undefined/loading and error cases.
|
|
344
369
|
*/
|
|
345
370
|
export declare function unstable_wrapDollarQueriesForMetadata<T extends Record<string, PlasmicQueryResult>>($queries: T, ifUndefined?: (promise: PlasmicUndefinedDataErrorPromise) => unknown, ifError?: (err: unknown) => unknown): T;
|
|
346
371
|
|
|
347
|
-
/**
|
|
348
|
-
* @deprecated Prefer using `usePlasmicDataOp` directly instead.
|
|
349
|
-
*/
|
|
350
|
-
export declare function useDependencyAwareQuery({ $queries, getDataOp, setDollarQueries, name, pageIndex, pageSize, }: DependencyAwareQueryConfig): void;
|
|
351
|
-
|
|
372
|
+
/** @deprecated See https://docs.plasmic.app/learn/integrations */
|
|
352
373
|
export declare function useNormalizedData(rawData: unknown): NormalizedData | undefined;
|
|
353
374
|
|
|
354
375
|
export { usePlasmicDataConfig }
|
|
355
376
|
|
|
377
|
+
/** @deprecated See https://docs.plasmic.app/learn/integrations */
|
|
356
378
|
export declare function usePlasmicDataMutationOp<T extends SingleRowResult | ManyRowsResult>(dataOp: ResolvableDataOp): () => Promise<T | undefined>;
|
|
357
379
|
|
|
380
|
+
/** @deprecated See https://docs.plasmic.app/learn/integrations */
|
|
358
381
|
export declare function usePlasmicDataOp<T extends SingleRowResult | ManyRowsResult, E = any>(dataOp: ResolvableDataOp, opts?: {
|
|
359
382
|
paginate?: Pagination;
|
|
360
383
|
noUndefinedDataProxy?: boolean;
|
|
361
384
|
}): ClientQueryResult<T["data"]>;
|
|
362
385
|
|
|
363
|
-
/**
|
|
364
|
-
* Returns a function that can be used to invalidate Plasmic query groups.
|
|
365
|
-
*/
|
|
386
|
+
/** @deprecated See https://docs.plasmic.app/learn/integrations */
|
|
366
387
|
export declare function usePlasmicInvalidate(): (invalidatedKeys: string[] | null | undefined) => Promise<any[] | undefined>;
|
|
367
388
|
|
|
368
|
-
/**
|
|
369
|
-
* TODO: Use paramsResult from usePlasmicQueries
|
|
370
|
-
*/
|
|
371
|
-
declare function usePlasmicQuery<T, F extends (...args: any[]) => Promise<T>>($query: PlasmicQueryResult<T>, query: PlasmicQuery<F>, settledCount?: number): SWRResponse<T, unknown>;
|
|
372
|
-
|
|
373
389
|
export { }
|