import { CoValueUniqueness } from "cojson"; import { Account, BranchDefinition, CoMap, DiscriminableCoValueSchemaDefinition, DiscriminableCoreCoValueSchema, Group, Settled, RefsToResolve, RefsToResolveStrict, Resolved, Simplify, SubscribeCallback, SubscribeListenerOptions, type Schema, CoValueCreateOptions, LoadCoValueCursorOption } from "../../../internal.js"; import { AnonymousJazzAgent } from "../../anonymousJazzAgent.js"; import { CoMapSchemaInit } from "../typeConverters/CoFieldSchemaInit.js"; import { InstanceOrPrimitiveOfSchema } from "../typeConverters/InstanceOrPrimitiveOfSchema.js"; import { InstanceOrPrimitiveOfSchemaCoValuesMaybeLoaded } from "../typeConverters/InstanceOrPrimitiveOfSchemaCoValuesMaybeLoaded.js"; import { z } from "../zodReExport.js"; import { AnyZodOrCoValueSchema, AnyZodSchema } from "../zodSchema.js"; import { CoOptionalSchema } from "./CoOptionalSchema.js"; import { CoreCoValueSchema, CoreResolveQuery } from "./CoValueSchema.js"; import { SchemaPermissions } from "../schemaPermissions.js"; type CoMapSchemaInstance = Simplify> & CoMap; export declare class CoMapSchema implements CoreCoMapSchema { #private; private coValueClass; collaborative: true; builtin: "CoMap"; shape: Shape; catchAll?: CatchAll; getDefinition: () => CoMapSchemaDefinition; getValidationSchema: () => z.ZodType>; /** * Default resolve query to be used when loading instances of this schema. * This resolve query will be used when no resolve query is provided to the load method. * @default true */ resolveQuery: DefaultResolveQuery; /** * Permissions to be used when creating or composing CoValues * @internal */ get permissions(): SchemaPermissions; constructor(coreSchema: CoreCoMapSchema, coValueClass: typeof CoMap); getDescriptorsSchema: () => CoMapDescriptorsSchema; create(init: CoMapSchemaInit, options?: CoValueCreateOptions): CoMapInstanceShape & CoMap; /** @deprecated Creating CoValues with an Account as owner is deprecated. Use a Group instead. */ create(init: CoMapSchemaInit, options?: CoValueCreateOptions<{}, Account | Group>): CoMapInstanceShape & CoMap; load> & CoMap> = DefaultResolveQuery>(id: string, options?: { resolve?: RefsToResolveStrict> & CoMap, R>; loadAs?: Account | AnonymousJazzAgent; skipRetry?: boolean; unstable_branch?: BranchDefinition; cursor?: LoadCoValueCursorOption; }): Promise> & CoMap, R>>>; unstable_merge> & CoMap> = DefaultResolveQuery>(id: string, options: { resolve?: RefsToResolveStrict> & CoMap, R>; loadAs?: Account | AnonymousJazzAgent; branch: BranchDefinition; }): Promise; subscribe> = DefaultResolveQuery>(id: string, listener: SubscribeCallback, R>>): () => void; subscribe> = DefaultResolveQuery>(id: string, options: SubscribeListenerOptions, R>, listener: SubscribeCallback, R>>): () => void; /** @deprecated Use `loadUnique` instead. */ findUnique(unique: CoValueUniqueness["uniqueness"], ownerID: string, as?: Account | Group | AnonymousJazzAgent): string; /** * Get an existing unique CoMap or create a new one if it doesn't exist. * * Unlike `upsertUnique`, this method does NOT update existing values with the provided value. * The provided value is only used when creating a new CoMap. * * @example * ```ts * const settings = await UserSettings.getOrCreateUnique({ * value: { theme: "dark", language: "en" }, * unique: "user-settings", * owner: me, * }); * ``` * * @param options The options for creating or loading the CoMap. * @returns Either an existing CoMap (unchanged), or a new initialised CoMap if none exists. * @category Subscription & Loading */ getOrCreateUnique> & CoMap> = DefaultResolveQuery>(options: { value: Simplify>; unique: CoValueUniqueness["uniqueness"]; owner: Owner; resolve?: RefsToResolveStrict> & CoMap, R>; }): Promise> & CoMap, R>>>; /** * @deprecated Use `getOrCreateUnique` instead. Note: getOrCreateUnique does not update existing values. * If you need to update, use getOrCreateUnique followed by direct property assignment. */ upsertUnique> & CoMap> = DefaultResolveQuery>(options: { value: Simplify>; unique: CoValueUniqueness["uniqueness"]; owner: Owner; resolve?: RefsToResolveStrict> & CoMap, R>; }): Promise> & CoMap, R>>>; loadUnique> & CoMap> = DefaultResolveQuery>(unique: CoValueUniqueness["uniqueness"], ownerID: string, options?: { resolve?: RefsToResolveStrict> & CoMap, R>; loadAs?: Account | AnonymousJazzAgent; }): Promise> & CoMap, R>>>; /** * @deprecated `co.map().catchall` will be removed in an upcoming version. * * Use a `co.record` nested inside a `co.map` if you need to store key-value properties. * * @example * ```ts * // Instead of: * const Image = co.map({ * original: co.fileStream(), * }).catchall(co.fileStream()); * * // Use: * const Image = co.map({ * original: co.fileStream(), * resolutions: co.record(z.string(), co.fileStream()), * }); * ``` */ catchall(schema: T): CoMapSchema; withMigration(migration: CoMapMigration): this; getCoValueClass(): typeof CoMap; optional(): CoOptionalSchema; /** * Creates a new CoMap schema by picking the specified keys from the original schema. * The new CoMap will **not** inherit any configurations (migration, catchall, permissions, default resolve query) * * @param keys - The keys to pick from the original schema. * @returns A new CoMap schema with the picked keys. */ pick(keys: { [key in Keys]: true; }): CoMapSchema>, unknown, Owner>; /** * Creates a new CoMap schema by omitting the specified keys from the original schema. * The new CoMap will **not** inherit any configurations (migration, catchall, permissions, default resolve query) * * @param keys - The keys to omit from the original schema. * @returns A new CoMap schema with the omitted keys. */ omit(keys: { [key in Keys]: true; }): CoMapSchema>, unknown, Owner>; /** * Creates a new CoMap schema by making all fields optional. * The new CoMap will **not** inherit any configurations (migration, permissions, default resolve query) except catchall * * @returns A new CoMap schema with all fields optional. */ partial(keys?: { [key in Keys]: true; }): CoMapSchema, CatchAll, Owner>; /** * Creates a new CoMap schema by extending the current schema with additional fields. * The new CoMap **will** inherit all configurations (migration, catchall, permissions, default resolve query) * * @param shape - The shape object with additional fields to add to the schema. * @returns A new CoMap schema with the additional fields. */ extend(shape: ExtendShape): CoMapSchema, CatchAll, Owner, DefaultResolveQuery>; /** * Creates a new CoMap schema by extending the current schema with additional fields, * while also making sure that no existing fields are accidentally overridden. * The new CoMap **will** inherit all configurations (migration, catchall, permissions, default resolve query) * * @param shape - The shape object with additional fields to add to the schema. * @returns A new CoMap schema with the additional fields. */ safeExtend(shape: SafeExtendShape & Partial>): CoMapSchema, CatchAll, Owner, DefaultResolveQuery>; /** * Adds a default resolve query to be used when loading instances of this schema. * This resolve query will be used when no resolve query is provided to the load method. */ resolved> & CoMap> = true>(resolveQuery: RefsToResolveStrict> & CoMap, R>): CoMapSchema; /** * Configure permissions to be used when creating or composing CoValues */ withPermissions(permissions: Omit): CoMapSchema; /** * Creates a copy of this schema, preserving all previous configuration */ private copy; } export declare function createCoreCoMapSchema(shape: Shape, catchAll?: CatchAll): CoreCoMapSchema; export interface CoMapSchemaDefinition extends DiscriminableCoValueSchemaDefinition { shape: Shape; catchall?: CatchAll; } export type CoMapDescriptorsSchema = { shape: Record; catchall?: Schema; }; export interface CoreCoMapSchema extends DiscriminableCoreCoValueSchema { builtin: "CoMap"; shape: Shape; catchAll?: CatchAll; getDescriptorsSchema: () => CoMapDescriptorsSchema; getDefinition: () => CoMapSchemaDefinition; } type CoMapMigration = (value: Resolved> & CoMap, true>) => undefined; export type CoMapInstanceShape = { readonly [key in keyof Shape]: InstanceOrPrimitiveOfSchema; } & (CatchAll extends AnyZodOrCoValueSchema ? { readonly [key: string]: InstanceOrPrimitiveOfSchema; } : {}); export type CoMapInstanceCoValuesMaybeLoaded = { readonly [key in keyof Shape]: InstanceOrPrimitiveOfSchemaCoValuesMaybeLoaded; }; export type PartialShape = Simplify<{ -readonly [key in keyof Shape]: key extends PartialKeys ? Shape[key] extends AnyZodSchema ? z.ZodOptional : Shape[key] extends CoreCoValueSchema ? CoOptionalSchema : never : Shape[key]; }>; export type SafeExtendShape = { [K in keyof Ext]: K extends keyof Base ? Base[K] extends z.core.SomeType ? Ext[K] extends z.core.SomeType ? InstanceOrPrimitiveOfSchema extends InstanceOrPrimitiveOfSchema ? z.core.input extends z.core.input ? Ext[K] : never : never : never : Ext[K] extends z.core.SomeType ? never : InstanceOrPrimitiveOfSchema extends InstanceOrPrimitiveOfSchema ? Ext[K] : never : Ext[K]; }; export {}; //# sourceMappingURL=CoMapSchema.d.ts.map