import { CodeComponentMeta } from '@plasmicapp/host/registerComponent'; import { PlasmicDataSourceContextValue } from '@plasmicapp/data-sources-context'; import { default as React_2 } from 'react'; import { usePlasmicDataConfig } from '@plasmicapp/query'; declare interface $StateSpec { path: string; initFunc?: (env: QueryExecutionContext & { /** @deprecated This field is here to conform to react-web's $StateSpec. */ $queries: Record; /** @deprecated This field is here to conform to react-web's $StateSpec. */ $refs: Record; }) => T; initVal?: T; type: "private" | "readonly" | "writable"; valueProp?: string; } /** @deprecated See https://docs.plasmic.app/learn/integrations */ export declare type BaseFieldConfig = { key?: string; fieldId?: string; }; /** * Initial context just before execution. * @internal */ declare type ClientQueryExecutionContext = Pick & { $state: QueryExecutionContext["$state"] | null; }; /** * Represents the result of a client-side query. * @deprecated See https://docs.plasmic.app/learn/integrations */ export declare interface ClientQueryResult { /** * The data returned by the query. May be undefined if the query has not yet completed. */ data?: T; /** * The schema of the table from which the data was queried. Only available for plasmic data * integration. May be undefined if the query has not yet completed. */ schema?: TableSchema; /** * The total number of records available. Only available for plasmic data integration. May be * undefined if the query has not yet completed. */ total?: number; /** * Pagination information for the query result. Only available for plasmic data integration. May be * undefined if the query has not yet completed. */ paginate?: Pagination; /** * Any error that occurred during the query. This is optional and may be undefined. */ error?: any; /** * Indicates whether the query is currently loading. */ isLoading?: boolean; } /** * A function that takes the execution context and returns a value. * Used for all dynamic expressions in the query tree (args, collectionExpr, visibilityExpr, data, propsContext values). */ declare type ContextFn = (ctx: QueryExecutionContext) => R; /** @deprecated See https://docs.plasmic.app/learn/integrations */ export declare interface DataOp { sourceId: string; opId: string; userArgs?: Record; cacheKey?: string; invalidatedKeys?: string[] | null; roleId?: string | null; } /** @deprecated See https://docs.plasmic.app/learn/integrations */ declare interface DataOpConfig { name?: string; pageIndex?: number; pageSize?: number; } /** @deprecated See https://docs.plasmic.app/learn/integrations */ export declare interface DataSourceSchema { tables: TableSchema[]; } /** @deprecated See https://docs.plasmic.app/learn/integrations */ export declare function deriveFieldConfigs(specifiedFieldsPartial: Partial[], schema: TableSchema | undefined, makeDefaultConfig: (field: TableFieldSchema | undefined) => T): { mergedFields: T[]; minimalFullLengthFields: Partial[]; }; declare interface ExecuteOpts { userAuthToken?: string; user?: PlasmicDataSourceContextValue["user"]; paginate?: Pagination; } /** @deprecated See https://docs.plasmic.app/learn/integrations */ export declare function executePlasmicDataOp(op: DataOp, opts?: ExecuteOpts): Promise; /** * Executes all queries from a serialized component tree and returns query results. * * 1. Walk the tree to discover queries, creating StatefulQueryResult + PlasmicQuery * 2. Execute all newly discovered queries in parallel * 3. After all settle, re-walk. Discover queries from newly expanded repeated nodes * Continue until no new queries found. */ export declare function executePlasmicQueries(rootNode: QueryComponentNode, env: InitialQueryExecutionContext): Promise; declare interface ExecutePlasmicQueriesResult { /** All queries, including nested, by query cache key hash. Passed to PlasmicRootProvider */ cache: Record; /** Root component query results keyed by query name. */ queries: Record; } /** @deprecated no-op function for compatibility only */ export declare function executeServerQuery any>(_query?: any): Promise<{ data: ReturnType; isLoading: boolean; }>; /** @deprecated See https://docs.plasmic.app/learn/integrations */ export declare function Fetcher(props: FetcherProps): React_2.ReactElement | null; /** @deprecated See https://docs.plasmic.app/learn/integrations */ export declare const FetcherMeta: CodeComponentMeta; /** @deprecated See https://docs.plasmic.app/learn/integrations */ export declare interface FetcherProps extends DataOpConfig { dataOp?: DataOp; children?: ($queries: Record) => React_2.ReactElement | null; queries?: Record; } /** * Initial context just before execution. * @internal */ declare type InitialQueryExecutionContext = Pick; export declare function isPlasmicUndefinedDataErrorPromise(x: any): x is PlasmicUndefinedDataErrorPromise; /** @deprecated See https://docs.plasmic.app/learn/integrations */ export declare function makeCacheKey(dataOp: DataOp, opts?: { paginate?: Pagination; userAuthToken?: string | null; }): string; /** * @internal Make a cache key for a query. * * Wrapped in `.$.` delimiters to match data op cache keys, so invalidation can match * the id via `matchesQueryCacheKey` without colliding with other SWR cache keys. */ export declare function makeQueryCacheKey(id: string, params: any[]): string; /** @deprecated See https://docs.plasmic.app/learn/integrations */ export declare interface ManyRowsResult { data: T[]; total?: number; schema: TableSchema; paginate?: Pagination; } /** * Returns whether `cacheKey` is invalidated by `invalidationKey`. Works for both server * query cache keys (built by `makeQueryCacheKey`) and data op cache keys. */ export declare function matchesQueryCacheKey(cacheKey: string, invalidationKey: string): boolean; /** @deprecated See https://docs.plasmic.app/learn/integrations */ export declare function normalizeData(rawData: unknown): NormalizedData | undefined; /** @deprecated See https://docs.plasmic.app/learn/integrations */ export declare interface NormalizedData { data: Record[]; schema?: TableSchema; } /** @deprecated See https://docs.plasmic.app/learn/integrations */ export declare interface Pagination { pageSize: number; pageIndex: number; } /** @internal */ export declare interface PlasmicQuery Promise = (...args: any[]) => Promise> { fn: F; args: ContextFn>; id: string; } /** @internal */ export declare interface PlasmicQueryResult { /** * Returns the key if params have resolved. */ key: string | null; /** * Returns the data if the query resolved. * Throws the error if the query rejected. * Throws PlasmicUndefinedDataErrorPromise if the query params are not ready. */ data: T; isLoading: boolean; } export declare interface PlasmicUndefinedDataErrorPromise extends Promise { plasmicType: "PlasmicUndefinedDataError"; message: string; } /** @internal */ declare interface QueryCodeComponentNode { type: "codeComponent"; propsContext: Record>; subtreePrefetchingConfig?: SerializedSubtreePrefetchingConfig; children: QueryNode[]; } /** @internal */ export declare interface QueryComponentNode { type: "component"; queries: Record; propsContext: Record>; /** * Lazily initializes $state proxy for this component. */ stateSpecs: $StateSpec[]; children: QueryNode[]; } /** @internal */ declare interface QueryDataProviderNode { type: "dataProvider"; name: string; data: ContextFn; children: QueryNode[]; } /** * Context during execution. * @internal */ export declare type QueryExecutionContext = { $ctx: Record; $props: Record; $state: Record; $q: Record; }; /** @internal */ declare type QueryNode = QueryComponentNode | QueryCodeComponentNode | QueryRepeatedNode | QueryDataProviderNode | QueryVisibilityNode; /** @internal */ declare interface QueryRepeatedNode { type: "repeated"; collectionExpr: ContextFn; itemName: string; indexName: string; children: QueryNode[]; } /** @deprecated See https://docs.plasmic.app/learn/integrations */ export declare type QueryResult = Partial> & { error?: any; isLoading?: boolean; }; /** @internal */ declare interface QueryVisibilityNode { type: "visibility"; visibilityExpr: ContextFn; children: QueryNode[]; } declare type ResolvableDataOp = DataOp | undefined | null | (() => DataOp | undefined | null); /** Execute a function, returning a result-like type. */ export declare function _safeExecResult(tryData: () => T): { data: T; } | { promise: PlasmicUndefinedDataErrorPromise; } | { error: unknown; }; declare type SerializedSubtreePrefetchingConfig = boolean; /** * Wraps a Promise so that it can be easily resolved/rejected * outside the executor param of the Promise constructor. */ declare class SettablePromise { readonly promise: Promise; private _resolve; private _reject; constructor(); resolve(value: T): void; reject(error: unknown): void; } /** @deprecated See https://docs.plasmic.app/learn/integrations */ export declare interface SingleRowResult { data: T; schema: TableSchema; } /** @internal */ export declare class _StatefulQueryResult implements PlasmicQueryResult { current: _StatefulQueryState; settable: SettablePromise; private readonly listeners; constructor(); private transitionState; addListener(listener: _StateListener): void; removeListener(listener: _StateListener): void; private notifyListeners; reset(): void; loadingPromise(key: string, promise: Promise): void; resolvePromise(key: string, data: T): void; /** * Reject is allowed if: * 1) no key / state is initial, which means params resolution failed * 2) key / state is loading, which means we need to check the keys match */ rejectPromise(key: string | null, error: unknown): void; toJSON(): _StatefulQueryState; get key(): string | null; get data(): T; get isLoading(): boolean; getDoneResult(): Promise & { current: { state: "done"; }; }>; } /** @internal */ export declare type _StatefulQueryState = { state: "initial"; key: null; } | { state: "loading"; key: string; } | { state: "done"; key: string; data: T; } | { state: "done"; key: string | null; error: unknown; }; /** @internal */ export declare type _StateListener = (state: _StatefulQueryState, prevState: _StatefulQueryState) => void; /** @deprecated See https://docs.plasmic.app/learn/integrations */ export declare interface TableFieldSchema { id: string; label?: string; type: TableFieldType; readOnly: boolean; primaryKey?: boolean; options?: string[]; } /** @deprecated See https://docs.plasmic.app/learn/integrations */ export declare type TableFieldType = "string" | "boolean" | "number" | "date" | "datetime" | "enum" | "json" | "unknown"; /** @deprecated See https://docs.plasmic.app/learn/integrations */ export declare interface TableSchema { id: string; schema?: string; label?: string; fields: TableFieldSchema[]; } export declare function throwIfPlasmicUndefinedDataError(err: unknown): void; /** @deprecated See https://docs.plasmic.app/learn/integrations */ export declare function useNormalizedData(rawData: unknown): NormalizedData | undefined; export { usePlasmicDataConfig } /** @deprecated See https://docs.plasmic.app/learn/integrations */ export declare function usePlasmicDataMutationOp(dataOp: ResolvableDataOp): () => Promise; /** @deprecated See https://docs.plasmic.app/learn/integrations */ export declare function usePlasmicDataOp(dataOp: ResolvableDataOp, opts?: { paginate?: Pagination; noUndefinedDataProxy?: boolean; }): ClientQueryResult; /** * Returns a function that invalidates cached query data. Accepts a list of invalidation keys * or `plasmic_refresh_all` to invalidate everything. */ export declare function usePlasmicInvalidate(): (invalidatedKeys: string[] | null | undefined) => Promise; /** * @internal * This hook's job is to execute queries and re-render when query state changes. * Data caching can be controlled via @plasmicapp/query. * * The actual results will be available in the returned $queries object. * * Prefetched query data can be passed to * . * * Example codegen: * * export const queryTree = { * type: "component", * queries: { * films: { fn: $$.fetch, id: "fetch", args: ({ $q, $props, $ctx }) => [...] } * }, * propsContext: {}, * }; * * export function ClientComponent($props, $ctx) { * const $q = usePlasmicQueries(queryTree, { $ctx, $props, $state: null }); * return
{$q.films.data}
* } */ export declare function usePlasmicQueries(tree: QueryComponentNode, env: ClientQueryExecutionContext): Record; /** * @internal * Wraps each PlasmicQueryResult so that they return a hardcoded string for * undefined/loading and error cases. */ export declare function wrapPlasmicQueriesForMetadata>(queries: T, ifUndefined?: (promise: PlasmicUndefinedDataErrorPromise) => unknown, ifError?: (err: unknown) => unknown): T; export { }