import Collection, { type Fieldnames } from "./collection.js"; import type Context from "../context.js"; import type { AttachmentOptions } from "./item-list.js"; import type { FieldsetInput, FieldsetOutput } from "./fieldset.js"; import { CollectionItemBody } from "./collection-item-body.js"; import type { ItemListResult } from "./item-list-result.js"; export type ItemMetadata = { modified_at: number; created_at: number; created_by: string | null; }; export type SerializedItem = ReturnType; export type SerializedItemBody = ReturnType; export default class CollectionItem { collection: T; body: CollectionItemBody; _metadata: ItemMetadata; id: string; fields_with_attachments: string[]; attachments: Record; private attachments_loaded; private save_mode; original_body: CollectionItemBody; has_been_replaced: boolean; parent_list: ItemListResult | null; constructor(collection: T, body: CollectionItemBody, _metadata?: ItemMetadata, id?: string, attachments?: Record); /** Checks whether or not it is allowed to save the given item to the DB using given context */ private canSave; private canDelete; throwIfInvalid(action: "create" | "edit", context: Context, replace_mode: boolean): Promise; /** Save the item to the database */ save(context: Context, is_http_api_request?: boolean): Promise; gatherDefaultValues(context: Context): Promise; /** sets a value */ set>(field_name: FieldName, field_value: FieldsetInput[FieldName], blessed_symbol?: symbol): CollectionItem; setMultiple(values: Partial>): this; /** Ensures that every field value is considered. This is useful for forms, where you can create a form with all fields for a collection, then add a new field to the collection and want to be notified by typescript about all forms that need to be updated */ setMultipleExtraSafe(values: FieldsetInput): this; replace(values: Partial>): void; get>(field_name: FieldName, include_raw?: boolean): FieldsetOutput[FieldName]; /** * if has decoded value it return this otherwise it decode it in first place * @param field_name name of field we want to get decoded * @param context */ getDecoded>(field_name: FieldName, context: Context): Promise; getDecodedBody(context: Context, is_http?: boolean): Promise>>; remove(context: Context): Promise; delete(context: Context): Promise; serialize(): { items: any[]; attachments: Record; fields_with_attachments: string[]; }; decode(context: Context, is_http_api_request?: boolean): Promise>; serializeBody(): { id: string; } & FieldsetOutput; safeLoadAttachments(context: Context, attachment_options: unknown): Promise; loadAttachments(context: Context, attachment_options?: AttachmentOptions): Promise; static fromSerialized(collection: T, data: { id: string; _metadata: ItemMetadata; }, attachments: { [id: string]: any; }): CollectionItem; fetchAs(context: Context): Promise>; getAttachmentIDs(field_name: FieldName): string[]; getAttachments(field_name: FieldName): CollectionItem[]; setParentList(list: ItemListResult): void; getBlessing(field_name: FieldName): symbol | null; summarizeChanges(context: Context): Promise>; }