@plasmicapp/data-sources 1.0.5 → 1.0.7

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
@@ -3,6 +3,19 @@ import { PlasmicDataSourceContextValue } from '@plasmicapp/data-sources-context'
3
3
  import { default as React_2 } from 'react';
4
4
  import { usePlasmicDataConfig } from '@plasmicapp/query';
5
5
 
6
+ declare interface $StateSpec<T = any> {
7
+ path: string;
8
+ initFunc?: (env: QueryExecutionContext & {
9
+ /** @deprecated This field is here to conform to react-web's $StateSpec. */
10
+ $queries: Record<string, any>;
11
+ /** @deprecated This field is here to conform to react-web's $StateSpec. */
12
+ $refs: Record<string, any>;
13
+ }) => T;
14
+ initVal?: T;
15
+ type: "private" | "readonly" | "writable";
16
+ valueProp?: string;
17
+ }
18
+
6
19
  /** @deprecated See https://docs.plasmic.app/learn/integrations */
7
20
  export declare type BaseFieldConfig = {
8
21
  key?: string;
@@ -139,9 +152,9 @@ export declare interface Pagination {
139
152
  }
140
153
 
141
154
  /** @internal */
142
- export declare interface PlasmicQuery<F extends (...args: unknown[]) => Promise<unknown> = (...args: unknown[]) => Promise<unknown>> {
155
+ export declare interface PlasmicQuery<F extends (...args: any[]) => Promise<unknown> = (...args: any[]) => Promise<unknown>> {
143
156
  fn: F;
144
- execParams: () => Parameters<F>;
157
+ args: ContextFn<Parameters<F>>;
145
158
  id: string;
146
159
  }
147
160
 
@@ -176,8 +189,12 @@ declare interface QueryCodeComponentNode {
176
189
  /** @internal */
177
190
  export declare interface QueryComponentNode {
178
191
  type: "component";
179
- queries: Record<string, SerializedServerQuery>;
192
+ queries: Record<string, PlasmicQuery>;
180
193
  propsContext: Record<string, ContextFn<unknown>>;
194
+ /**
195
+ * Lazily initializes $state proxy for this component.
196
+ */
197
+ stateSpecs: $StateSpec[];
181
198
  children: QueryNode[];
182
199
  }
183
200
 
@@ -189,16 +206,22 @@ declare interface QueryDataProviderNode {
189
206
  children: QueryNode[];
190
207
  }
191
208
 
192
- export declare interface QueryExecutionContext {
193
- $props: Record<string, unknown>;
209
+ /**
210
+ * Context during execution.
211
+ * @internal
212
+ */
213
+ export declare type QueryExecutionContext = {
194
214
  $ctx: Record<string, unknown>;
215
+ $props: Record<string, unknown>;
195
216
  $state: Record<string, unknown>;
196
217
  $q: Record<string, PlasmicQueryResult>;
197
- $scopedItemVars: Record<string, unknown>;
198
- }
218
+ };
199
219
 
200
- /** @internal */
201
- declare type QueryExecutionInitialContext = Pick<QueryExecutionContext, "$props" | "$ctx">;
220
+ /**
221
+ * Initial context just before execution.
222
+ * @internal
223
+ */
224
+ declare type QueryExecutionInitialContext = Pick<QueryExecutionContext, "$ctx" | "$props">;
202
225
 
203
226
  /** @internal */
204
227
  declare type QueryNode = QueryComponentNode | QueryCodeComponentNode | QueryRepeatedNode | QueryDataProviderNode | QueryVisibilityNode;
@@ -227,14 +250,12 @@ declare interface QueryVisibilityNode {
227
250
 
228
251
  declare type ResolvableDataOp = DataOp | undefined | null | (() => DataOp | undefined | null);
229
252
 
230
- declare interface SerializedServerQuery {
231
- id: string;
232
- fn: (...args: unknown[]) => Promise<unknown>;
233
- args: ContextFn<unknown[]>;
234
- }
235
-
236
253
  declare type SerializedServerRenderingConfig = boolean;
237
254
 
255
+ /**
256
+ * Wraps a Promise so that it can be easily resolved/rejected
257
+ * outside the executor param of the Promise constructor.
258
+ */
238
259
  declare class SettablePromise<T> {
239
260
  readonly promise: Promise<T>;
240
261
  private _resolve;
@@ -262,11 +283,6 @@ export declare class _StatefulQueryResult<T = unknown> implements PlasmicQueryRe
262
283
  private notifyListeners;
263
284
  reset(): void;
264
285
  loadingPromise(key: string, promise: Promise<T>): void;
265
- /**
266
- * Resolve is allowed if:
267
- * 1) no key / state is initial, which means we are resolving from cache
268
- * 2) key / state is loading, which means we need to check the keys match
269
- */
270
286
  resolvePromise(key: string, data: T): void;
271
287
  /**
272
288
  * Reject is allowed if:
@@ -274,6 +290,7 @@ export declare class _StatefulQueryResult<T = unknown> implements PlasmicQueryRe
274
290
  * 2) key / state is loading, which means we need to check the keys match
275
291
  */
276
292
  rejectPromise(key: string | null, error: unknown): void;
293
+ toJSON(): _StatefulQueryState<T>;
277
294
  get key(): string | null;
278
295
  get data(): T;
279
296
  get isLoading(): boolean;
@@ -358,11 +375,11 @@ export declare function unstable_executePlasmicQueries(rootNode: QueryComponentN
358
375
  * };
359
376
  *
360
377
  * export function ClientComponent($props, $ctx) {
361
- * const $q = usePlasmicQueries(serverQueryTree, $props, $ctx);
378
+ * const $q = usePlasmicQueries(serverQueryTree, $ctx, $props, null);
362
379
  * return <div>{$q.films.data}</div>
363
380
  * }
364
381
  */
365
- export declare function unstable_usePlasmicQueries(tree: QueryComponentNode, $props: Record<string, unknown>, $ctx: Record<string, unknown>, $state?: Record<string, unknown>): Record<string, PlasmicQueryResult>;
382
+ export declare function unstable_usePlasmicQueries(tree: QueryComponentNode, $ctx: QueryExecutionContext["$ctx"], $props: QueryExecutionContext["$props"], $state: QueryExecutionContext["$state"] | null): Record<string, PlasmicQueryResult>;
366
383
 
367
384
  /**
368
385
  * @internal