import type { BinaryStreamInfo, CojsonInternalTypes, CoValueUniqueness, RawBinaryCoStream, RawCoStream, SessionID } from "cojson"; import { AnonymousJazzAgent, CoFieldInit, CoValue, CoValueClass, Group, ID, MaybeLoaded, Settled, LoadedAndRequired, RefsToResolve, RefsToResolveStrict, Resolved, Schema, SubscribeListenerOptions, TypeSym, BranchDefinition, Account, CoValueBase, CoValueJazzApi, ItemsSym, Ref, inspect, CoreFileStreamSchema, CoValueCreateOptionsInternal, CoValueCursor, LoadCoValueCursorOption } from "../internal.js"; import { CoreCoFeedSchema } from "../implementation/zodSchema/schemaTypes/CoFeedSchema.js"; /** @deprecated Use CoFeedEntry instead */ export type CoStreamEntry = CoFeedEntry; export type CoFeedEntry = SingleCoFeedEntry & { all: IterableIterator>; }; /** @deprecated Use SingleCoFeedEntry instead */ export type SingleCoStreamEntry = SingleCoFeedEntry; export type SingleCoFeedEntry = { value: LoadedAndRequired extends CoValue ? MaybeLoaded> : Item; ref: LoadedAndRequired extends CoValue ? Ref> : never; by: Account | null; madeAt: Date; tx: CojsonInternalTypes.TransactionID; }; /** @deprecated Use CoFeed instead */ export { CoFeed as CoStream }; /** * CoFeeds are collaborative logs of data. * * @categoryDescription Content * They are similar to `CoList`s, but with a few key differences: * - They are append-only * - They consist of several internal append-only logs, one per account session (tab, device, app instance, etc.) * - They expose those as a per-account aggregated view (default) or a precise per-session view * * ```ts * favDog.push("Poodle"); * favDog.push("Schnowzer"); * ``` * * @category CoValues */ export declare class CoFeed extends CoValueBase implements CoValue { static coValueSchema?: CoreCoFeedSchema; $jazz: CoFeedJazzApi; /** @category Type Helpers */ [TypeSym]: "CoStream"; /** @internal This is only a marker type and doesn't exist at runtime */ [ItemsSym]: Item; /** * The current account's view of this `CoFeed` * @category Content */ get byMe(): CoFeedEntry | undefined; /** * The per-account view of this `CoFeed` * * @example * ```ts * // Access entries directly by account ID * const aliceEntries = feed[aliceAccount.id]; * console.log(aliceEntries.value); // Latest value from Alice * * // Iterate through all accounts' entries * for (const [accountId, entries] of Object.entries(feed)) { * console.log(`Latest entry from ${accountId}:`, entries.value); * * // Access all entries from this account * for (const entry of entries.all) { * console.log(`Entry made at ${entry.madeAt}:`, entry.value); * } * } * ``` * * @category Content */ get perAccount(): { [key: ID]: CoFeedEntry; }; /** * The per-session view of this `CoFeed` * @category Content */ get perSession(): { [key: SessionID]: CoFeedEntry; }; /** * The current session's view of this `CoFeed` * * This is a shortcut for `this.perSession` where the session ID is the current session ID. * * @category Content */ get inCurrentSession(): CoFeedEntry | undefined; /** @internal */ constructor(options: { fromRaw: RawCoStream; }); /** * Create a new `CoFeed` * @category Creation * @deprecated Use `co.feed(...).create` instead. */ static create(this: CoValueClass, init: S extends CoFeed ? Item[] : never, options?: CoValueCreateOptionsInternal): S; /** @deprecated Use `CoFeed.getOrCreateUnique` instead. */ static findUnique(this: CoValueClass, unique: CoValueUniqueness["uniqueness"], ownerID: ID | ID, as?: Account | Group | AnonymousJazzAgent): `co_z${string}`; /** * Get an existing unique CoFeed or create a new one if it doesn't exist. * * The provided value is only used when creating a new CoFeed. * * @example * ```ts * const feed = await MessageFeed.getOrCreateUnique({ * value: [], * unique: `messages-${conversationId}`, * owner: group, * }); * ``` * * @param options The options for creating or loading the CoFeed. * @returns Either an existing CoFeed (unchanged), or a new initialised CoFeed if none exists. * @category Subscription & Loading */ static getOrCreateUnique = true>(this: CoValueClass, options: { value: F extends CoFeed ? Item[] : never; unique: CoValueUniqueness["uniqueness"]; owner: Account | Group; resolve?: RefsToResolveStrict; }): Promise>>; /** * Get a JSON representation of the `CoFeed` * @category */ toJSON(): { $jazz: { id: string; }; [key: string]: unknown; in: { [key: string]: unknown; }; }; /** @internal */ [inspect](): { $jazz: { id: string; }; [key: string]: unknown; in: { [key: string]: unknown; }; }; /** @internal */ static schema(this: { new (...args: any): V; } & typeof CoFeed, def: { [ItemsSym]: CoFieldInit ? Item : never>; }): void; /** * Load a `CoFeed` * @category Subscription & Loading * @deprecated Use `co.feed(...).load` instead. */ static load = true>(this: CoValueClass, id: ID, options?: { resolve?: RefsToResolveStrict; loadAs?: Account | AnonymousJazzAgent; }): Promise>>; /** * Subscribe to a `CoFeed`, when you have an ID but don't have a `CoFeed` instance yet * @category Subscription & Loading * @deprecated Use `co.feed(...).subscribe` instead. */ static subscribe = true>(this: CoValueClass, id: ID, listener: (value: Resolved, unsubscribe: () => void) => void): () => void; static subscribe = true>(this: CoValueClass, id: ID, options: SubscribeListenerOptions, listener: (value: Resolved, unsubscribe: () => void) => void): () => void; } /** @internal */ type CoFeedItem = L extends CoFeed ? Item : never; export declare class CoFeedJazzApi extends CoValueJazzApi { private coFeed; raw: RawCoStream; private coFeedSchema; constructor(coFeed: F, raw: RawCoStream, coFeedSchema: CoreCoFeedSchema); private getItemSchema; get owner(): Group; /** * Push items to this `CoFeed` * * Items are appended to the current session's log. Each session (tab, device, app instance) * maintains its own append-only log, which is then aggregated into the per-account view. * * @example * ```ts * // Adds items to current session's log * feed.$jazz.push("item1", "item2"); * * // View items from current session * console.log(feed.inCurrentSession); * * // View aggregated items from all sessions for current account * console.log(feed.byMe); * ``` * * @category Content */ push(...items: CoFieldInit>[]): void; /** * Push items to this `CoFeed` without applying schema validation. * * @category Content */ pushLoose(...items: CoFieldInit>[]): void; private pushItem; /** * Ensure a `CoFeed` is loaded to the specified depth * * @returns A new instance of the same CoFeed that's loaded to the specified depth * @category Subscription & Loading */ ensureLoaded>(this: CoFeedJazzApi, options?: { resolve?: RefsToResolveStrict; unstable_branch?: BranchDefinition; cursor?: LoadCoValueCursorOption; }): Promise>; /** * An instance method to subscribe to an existing `CoFeed` * * No need to provide an ID or Account since they're already part of the instance. * @category Subscription & Loading */ subscribe>(this: CoFeedJazzApi, listener: (value: Resolved, unsubscribe: () => void) => void): () => void; subscribe>(this: CoFeedJazzApi, options: { resolve?: RefsToResolveStrict; unstable_branch?: BranchDefinition; cursor?: CoValueCursor; }, listener: (value: Resolved, unsubscribe: () => void) => void): () => void; /** * Wait for the `CoFeed` to be uploaded to the other peers. * * @category Subscription & Loading */ waitForSync(options?: { timeout?: number; }): Promise; /** * Get the descriptor for the items in the `CoFeed` * @internal */ getItemsDescriptor(): Schema; } /** * The proxy handler for `CoFeed` instances * @internal */ export declare const CoStreamPerAccountProxyHandler: (innerTarget: CoFeed) => ProxyHandler<{}>; /** @deprecated Use FileStream instead */ export { FileStream as BinaryCoStream }; /** * FileStreams are `CoFeed`s that contain binary data, collaborative versions of `Blob`s. * * @categoryDescription Declaration * `FileStream` can be referenced in schemas. * * ```ts * import { coField, FileStream } from "jazz-tools"; * * class MyCoMap extends CoMap { * file = coField.ref(FileStream); * } * ``` * * @category CoValues */ export declare class FileStream extends CoValueBase implements CoValue { $jazz: FileStreamJazzApi; /** @category Type Helpers */ [TypeSym]: "BinaryCoStream"; static coValueSchema?: CoreFileStreamSchema; constructor(options: { owner: Account | Group; } | { fromRaw: RawBinaryCoStream; }); /** * Create a new empty `FileStream` instance. * * @param options - Configuration options for the new FileStream * @param options.owner - The Account or Group that will own this FileStream and control access rights * @param schemaConfiguration - Internal schema configuration * * @example * ```typescript * // Create owned by an account * const stream = FileStream.create({ owner: myAccount }); * * // Create owned by a group * const stream = FileStream.create({ owner: teamGroup }); * * // Create with implicit owner * const stream = FileStream.create(myAccount); * ``` * * @remarks * For uploading an existing file or blob, use {@link FileStream.createFromBlob} instead. * * @category Creation * @deprecated Use `co.fileStream(...).create` instead. */ static create(this: CoValueClass, options?: { owner?: Account | Group; } | Account | Group): S; getMetadata(): BinaryStreamInfo | undefined; getChunks(options?: { allowUnfinished?: boolean; }): (BinaryStreamInfo & { chunks: Uint8Array[]; finished: boolean; }) | undefined; isBinaryStreamEnded(): boolean; start(options: BinaryStreamInfo): void; push(data: Uint8Array): void; end(): void; toBlob(options?: { allowUnfinished?: boolean; }): Blob | undefined; /** * Load a `FileStream` as a `Blob` * * @category Content * @deprecated Use `co.fileStream(...).loadAsBlob` instead. */ static loadAsBlob(id: ID, options?: { allowUnfinished?: boolean; loadAs?: Account | AnonymousJazzAgent; }): Promise; static loadAsBase64(id: ID, options?: { allowUnfinished?: boolean; loadAs?: Account | AnonymousJazzAgent; dataURL?: boolean; }): Promise; asBase64(options?: { allowUnfinished?: boolean; dataURL?: boolean; }): string | undefined; /** * Create a `FileStream` from a `Blob` or `File` * * @example * ```ts * import { coField, FileStream } from "jazz-tools"; * * const fileStream = await FileStream.createFromBlob(file, {owner: group}) * ``` * @category Content * @deprecated Use `co.fileStream(...).createFromBlob` instead. */ static createFromBlob(blob: Blob | File, options?: { owner?: Account | Group; onProgress?: (progress: number) => void; } | Account | Group): Promise; /** * Create a `FileStream` from a `Blob` or `File` * * @example * ```ts * import { coField, FileStream } from "jazz-tools"; * * const fileStream = await FileStream.createFromBlob(file, {owner: group}) * ``` * @category Content * @deprecated Use `co.fileStream(...).createFromArrayBuffer` instead. */ static createFromArrayBuffer(arrayBuffer: ArrayBuffer, mimeType: string, fileName: string | undefined, options?: { owner?: Account | Group; onProgress?: (progress: number) => void; } | Account | Group): Promise; /** * Get a JSON representation of the `FileStream` * @category Content */ toJSON(): { $jazz: { id: string; }; mimeType?: string; totalSizeBytes?: number; fileName?: string; chunks?: Uint8Array[]; finished?: boolean; }; /** @internal */ [inspect](): { $jazz: { id: string; }; mimeType?: string; totalSizeBytes?: number; fileName?: string; chunks?: Uint8Array[]; finished?: boolean; }; /** * Load a `FileStream` * @category Subscription & Loading * @deprecated Use `co.fileStream(...).load` instead. */ static load(this: CoValueClass, id: ID, options?: { loadAs?: Account | AnonymousJazzAgent; allowUnfinished?: boolean; }): Promise>; /** * Subscribe to a `FileStream`, when you have an ID but don't have a `FileStream` instance yet * @category Subscription & Loading * @deprecated Use `co.fileStream(...).subscribe` instead. */ static subscribe>(this: CoValueClass, id: ID, listener: (value: Resolved, unsubscribe: () => void) => void): () => void; static subscribe>(this: CoValueClass, id: ID, options: SubscribeListenerOptions, listener: (value: Resolved, unsubscribe: () => void) => void): () => void; } export declare class FileStreamJazzApi extends CoValueJazzApi { private fileStream; raw: RawBinaryCoStream; constructor(fileStream: F, raw: RawBinaryCoStream); get owner(): Group; /** * An instance method to subscribe to an existing `FileStream` * @category Subscription & Loading */ subscribe(this: FileStreamJazzApi, listener: (value: Resolved) => void): () => void; /** * Wait for the `FileStream` to be uploaded to the other peers. * * @category Subscription & Loading */ waitForSync(options?: { timeout?: number; }): Promise; } //# sourceMappingURL=coFeed.d.ts.map