@plasmicapp/data-sources 0.1.202 → 0.1.203

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
@@ -82,8 +82,9 @@ export declare function executePlasmicDataOp<T extends SingleRowResult | ManyRow
82
82
  /**
83
83
  * Executes a server query, returning either the result of the query or a
84
84
  * PlasmicUndefinedServerProxy if the query depends on data that is not yet ready
85
+ * @deprecated
85
86
  */
86
- export declare function executeServerQuery<F extends (...args: any[]) => any>(serverQuery: ServerQuery<F>): Promise<ServerQueryResult<ReturnType<F> | {}>>;
87
+ export declare function executeServerQuery<F extends (...args: any[]) => any>(query: PlasmicQuery<F>): Promise<ServerQueryResult<ReturnType<F>>>;
87
88
 
88
89
  export declare function Fetcher(props: FetcherProps): React_2.ReactElement | null;
89
90
 
@@ -100,6 +101,7 @@ export declare function makeCacheKey(dataOp: DataOp, opts?: {
100
101
  userAuthToken?: string | null;
101
102
  }): string;
102
103
 
104
+ /** Make a cache key for a query */
103
105
  export declare function makeQueryCacheKey(id: string, params: any[]): string;
104
106
 
105
107
  export declare interface ManyRowsResult<T = any> {
@@ -109,10 +111,8 @@ export declare interface ManyRowsResult<T = any> {
109
111
  paginate?: Pagination;
110
112
  }
111
113
 
112
- export declare function mkPlasmicUndefinedServerProxy(): {
113
- data: {};
114
- isLoading: boolean;
115
- };
114
+ /** @deprecated */
115
+ export declare function mkPlasmicUndefinedServerProxy<T>(): ServerQueryResult<T>;
116
116
 
117
117
  export declare function normalizeData(rawData: unknown): NormalizedData | undefined;
118
118
 
@@ -126,6 +126,31 @@ export declare interface Pagination {
126
126
  pageIndex: number;
127
127
  }
128
128
 
129
+ export declare interface PlasmicQuery<F extends (...args: unknown[]) => Promise<unknown> = (...args: unknown[]) => Promise<unknown>> {
130
+ fn: F;
131
+ execParams: () => Parameters<F>;
132
+ id: string;
133
+ }
134
+
135
+ export declare interface PlasmicQueryResult<T = unknown> {
136
+ /**
137
+ * Returns the key if params have resolved.
138
+ */
139
+ key: string | null;
140
+ /**
141
+ * Returns the data if the query resolved.
142
+ * Throws the error if the query rejected.
143
+ * Throws PlasmicUndefinedDataErrorPromise if the query params are not ready.
144
+ */
145
+ data: T;
146
+ isLoading: boolean;
147
+ }
148
+
149
+ declare interface PlasmicUndefinedDataErrorPromise extends Promise<any> {
150
+ plasmicType: "PlasmicUndefinedDataError";
151
+ message: string;
152
+ }
153
+
129
154
  export declare type QueryResult = Partial<ManyRowsResult<any>> & {
130
155
  error?: any;
131
156
  isLoading?: boolean;
@@ -133,12 +158,7 @@ export declare type QueryResult = Partial<ManyRowsResult<any>> & {
133
158
 
134
159
  declare type ResolvableDataOp = DataOp | undefined | null | (() => DataOp | undefined | null);
135
160
 
136
- export declare interface ServerQuery<F extends (...args: any[]) => Promise<any>> {
137
- fn: F;
138
- execParams: () => Parameters<F>;
139
- id: string;
140
- }
141
-
161
+ /** @deprecated */
142
162
  export declare interface ServerQueryResult<T = any> {
143
163
  data: T;
144
164
  isLoading: boolean;
@@ -167,6 +187,111 @@ export declare interface TableSchema {
167
187
  fields: TableFieldSchema[];
168
188
  }
169
189
 
190
+ /**
191
+ * Creates a $queries variable that can be used before queries are completed.
192
+ *
193
+ * Each query gets a StatefulQueryResult which implements PlasmicQueryResult.
194
+ * If data is attempted to be accessed before query completion,
195
+ * PlasmicUndefinedDataErrorPromise is thrown. Dependent queries can catch this
196
+ * and delay its own execution until the dependent data is ready.
197
+ *
198
+ * When a query execution completes, the StatefulQueryResult must be notified
199
+ * via resolvePromise or rejectPromise.
200
+ */
201
+ export declare function unstable_createDollarQueries<QueryName extends string>(queryNames: QueryName[]): Record<QueryName, PlasmicQueryResult>;
202
+
203
+ /**
204
+ * Executes all queries and returns the query data keyed by cache key.
205
+ *
206
+ * Example codegen:
207
+ *
208
+ * export function create$Queries() {
209
+ * return createDollarQueries(["result", "dep"]);
210
+ * }
211
+ * type QueryName = keyof ReturnType<typeof create$Queries>;
212
+ * export function createQueries(
213
+ * $ctx: Record<string, any>,
214
+ * $queries: Record<QueryName, PlasmicQueryResult>,
215
+ * ) {
216
+ * return {
217
+ * result: {
218
+ * id: "plus",
219
+ * fn: (a, b) => a + b,
220
+ * execParams: () => [1, $queries.dep.data],
221
+ * },
222
+ * dep: {
223
+ * id: "times",
224
+ * fn: (a, b) => a * b,
225
+ * execParams: () => [2, 3],
226
+ * },
227
+ * }
228
+ * }
229
+ *
230
+ * export async function ServerComponent() {
231
+ * const $ctx = useDataEnv();
232
+ * const $queries = createDollarQueries();
233
+ * const queries = createQueries($ctx, $queries);
234
+ * const prefetchedCache = await executePlasmicQueries($queries, queries);
235
+ * return (
236
+ * <PlasmicQueryDataProvider prefetchedCache={prefetchedCache}>
237
+ * <ClientComponent />
238
+ * </PlasmicQueryDataProvider>
239
+ * );
240
+ * }
241
+ */
242
+ export declare function unstable_executePlasmicQueries<QueryName extends string>($queries: Record<QueryName, PlasmicQueryResult>, queries: Record<QueryName, PlasmicQuery>): Promise<{
243
+ [cacheKey: string]: unknown;
244
+ }>;
245
+
246
+ /**
247
+ * This hook's job is to execute queries and re-render when query state changes.
248
+ * Data caching can be controlled via @plasmicapp/query.
249
+ *
250
+ * The actual results will be available in $queries generated by
251
+ * createDollarQueries.
252
+ *
253
+ * Prefetched query data can be passed to
254
+ * <PlasmicQueryDataProvider prefetchedCache={...}>.
255
+ *
256
+ * Example codegen:
257
+ *
258
+ * export function create$Queries() {
259
+ * return createDollarQueries(["result", "dep"]);
260
+ * }
261
+ * type QueryName = keyof ReturnType<typeof create$Queries>;
262
+ * export function createQueries(
263
+ * $ctx: Record<string, any>,
264
+ * $queries: Record<QueryName, PlasmicQueryResult>,
265
+ * ) {
266
+ * return {
267
+ * result: {
268
+ * id: "plus",
269
+ * fn: (a, b) => a + b,
270
+ * execParams: () => [1, $queries.dep.data],
271
+ * },
272
+ * dep: {
273
+ * id: "times",
274
+ * fn: (a, b) => a * b,
275
+ * execParams: () => [2, 3],
276
+ * },
277
+ * }
278
+ * }
279
+ *
280
+ * export function ClientComponent() {
281
+ * const $queries = React.useMemo(create$Queries, []);
282
+ * const queries = React.useMemo(() => createQueries($queries), [$queries]);
283
+ * usePlasmicQueries($queries, queries);
284
+ * return <div>{$queries.result.data}</div> // $queries.result.data may suspend
285
+ * }
286
+ */
287
+ export declare function unstable_usePlasmicQueries<QueryName extends string>($queries: Record<QueryName, PlasmicQueryResult>, queries: Record<QueryName, PlasmicQuery>): void;
288
+
289
+ /**
290
+ * Wraps each PlasmicQueryResult so that they return a hardcoded string for
291
+ * undefined/loading and error cases.
292
+ */
293
+ export declare function unstable_wrapDollarQueriesForMetadata<T extends Record<string, PlasmicQueryResult>>($queries: T, ifUndefined?: (promise: PlasmicUndefinedDataErrorPromise) => unknown, ifError?: (err: unknown) => unknown): T;
294
+
170
295
  /**
171
296
  * @deprecated Prefer using `usePlasmicDataOp` directly instead.
172
297
  */
@@ -188,8 +313,19 @@ export declare function usePlasmicDataOp<T extends SingleRowResult | ManyRowsRes
188
313
  */
189
314
  export declare function usePlasmicInvalidate(): (invalidatedKeys: string[] | null | undefined) => Promise<any[] | undefined>;
190
315
 
191
- export declare function usePlasmicServerQuery<F extends (...args: any[]) => Promise<any>>(serverQuery: ServerQuery<F>, fallbackData?: ReturnType<F>, opts?: {
316
+ /**
317
+ * @deprecated
318
+ * This export will be deleted before RSC release.
319
+ * TODO: Rename to usePlasmicQuery
320
+ * TODO: Reference $query directly.
321
+ * TODO: Use paramsResult from usePlasmicQueries
322
+ */
323
+ export declare function usePlasmicServerQuery<T, F extends (...args: any[]) => Promise<T>>(query: PlasmicQuery<F>, fallbackData?: T, opts?: {
192
324
  noUndefinedDataProxy?: boolean;
193
- }): Partial<ServerQueryResult<ReturnType<F>>>;
325
+ settledCount?: number;
326
+ onStarted?: (key: string, promise: Promise<T>) => void;
327
+ onResolved?: (key: string, data: T) => void;
328
+ onRejected?: (key: string | null, error: unknown) => void;
329
+ }): Partial<PlasmicQueryResult<T>>;
194
330
 
195
331
  export { }