import React from "react"; import Realm from "realm"; import { RestrictivePick } from "./helpers"; type PartialRealmConfiguration = Partial; export type RealmProviderFallback = React.ComponentType; /** Props used for a configuration-based Realm provider */ type RealmProviderConfigurationProps = { /** * If false, Realm will not be closed when the component unmounts. * @default true */ closeOnUnmount?: boolean; /** * A ref to the Realm instance. This is useful if you need to access the Realm * instance outside of a component that uses the Realm hooks. */ realmRef?: React.MutableRefObject; /** * The fallback component to render if the Realm is not open. */ fallback?: RealmProviderFallback | React.ComponentType | React.ReactElement | null | undefined; children: React.ReactNode; } & PartialRealmConfiguration; /** Props used for a Realm instance-based Realm provider */ type RealmProviderRealmProps = { /** * The Realm instance to be used by the provider. */ realm: Realm; children: React.ReactNode; }; type RealmProviderProps = RealmProviderConfigurationProps & RealmProviderRealmProps; /** * Represents the provider returned from `createRealmContext` with a Realm instance i.e. `createRealmContext(new Realm(...))`. * Omits "realm" as it gets set at creation and cannot be changed. * **Note:** the hooks returned from `createRealmContext` using an existing Realm can be used outside of the scope of the provider. */ export type RealmProviderFromRealm = React.FC>; /** * Represents the provider returned from `createRealmContext` with a configuration, i.e. `createRealmContext({schema: [...]})`. */ export type RealmProviderFromConfiguration = React.FC; /** * Represents properties of a {@link DynamicRealmProvider} where Realm instance props are set and Configuration props are disallowed. */ export type DynamicRealmProviderWithRealmProps = RestrictivePick; /** * Represents properties of a {@link DynamicRealmProvider} where Realm configuration props are set and Realm instance props are disallowed. */ export type DynamicRealmProviderWithConfigurationProps = RestrictivePick; /** * Represents the provider returned from creating context with no arguments (including the default context). * Supports either {@link RealmProviderRealmProps} or {@link RealmProviderConfigurationProps}. */ export type DynamicRealmProvider = React.FC; export declare function createRealmProviderFromRealm(realm: Realm, RealmContext: React.Context): RealmProviderFromRealm; /** * Generates a `RealmProvider` given a {@link Realm.Configuration} and {@link React.Context}. * @param realmConfig - The configuration of the Realm to be instantiated * @param RealmContext - The context that will contain the Realm instance * @returns a RealmProvider component that provides context to all context hooks */ export declare function createRealmProviderFromConfig(realmConfig: Realm.Configuration, RealmContext: React.Context): RealmProviderFromConfiguration; /** * Generates a `RealmProvider` which is either based on a configuration * or based on a realm, depending on its props. * @param RealmContext - The context that will contain the Realm instance * @returns a RealmProvider component that provides context to all context hooks */ export declare function createDynamicRealmProvider(RealmContext: React.Context): DynamicRealmProvider; /** * Generates the appropriate `RealmProvider` based on whether there is a config, realm, or neither given. * @param realmOrConfig - A Realm instance, a configuration, or undefined (including default provider). * @param RealmContext - The context that will contain the Realm instance * @returns a RealmProvider component that provides context to all context hooks */ export declare function createRealmProvider(realmOrConfig: Realm.Configuration | Realm | undefined, RealmContext: React.Context): RealmProviderFromConfiguration | RealmProviderFromRealm | DynamicRealmProvider; /** * Merge two configurations, creating a configuration using `configA` as the default, * merged with `configB`, with properties in `configB` overriding `configA`. * @param configA - The default config object * @param configB - Config overrides object * @returns Merged config object */ export declare function mergeRealmConfiguration(configA: PartialRealmConfiguration, configB: PartialRealmConfiguration): Realm.Configuration; /** * Utility function that does a deep comparison (key: value) of object a with object b * @param a - Object to compare * @param b - Object to compare * @returns True if the objects are identical */ export declare function areConfigurationsIdentical(a: Realm.Configuration, b: Realm.Configuration): boolean; export {}; //# sourceMappingURL=RealmProvider.d.ts.map