import { type Type } from 'arktype'; import { type Maybe, type Milliseconds } from '@dereekb/util'; import { type FirestoreModelKey, type OnCallCreateModelResult, type TargetModelParams } from '../../common'; import { type FirebaseFunctionTypeConfigMap, type ModelFirebaseCreateFunction, type ModelFirebaseCrudFunction, type ModelFirebaseCrudFunctionConfigMap, type ModelFirebaseFunctionMap } from '../../client'; import { type StorageFileId } from '../storagefile/storagefile.id'; import { type FormSpaceData, type FormSpaceTypes } from './formspace'; import { type FormSpaceFileSlot, type FormSpaceType } from './formspace.id'; /** * @module formspace.api * * ARKTYPE PARAM/RESULT TYPES plus the callable CRUD map for the FormSpace model. * * Unlike Calendar — which is driven entirely internally — a FormSpace is a CLIENT-FACING container: the * user creates it, edits it, and submits it, so every one of those is a callable. */ /** * Parameters for creating a FormSpace. * * @dbxModelApiParams */ export interface CreateFormSpaceParams { /** * The registered {@link FormSpaceType} to create. Creation of an unregistered type is rejected. */ readonly formSpaceType: FormSpaceType; /** * Display name for the space. */ readonly displayName?: Maybe; /** * The model this space is being opened against, if any. */ readonly targetModelKey?: Maybe; /** * Initial form data. */ readonly data?: Maybe; } export declare const createFormSpaceParamsType: Type; /** * Parameters for updating a draft FormSpace's content. * * `data` REPLACES the stored JSON rather than merging into it. The client owns the whole form; a merge * would make clearing a field impossible to express. * * @dbxModelApiParams */ export interface UpdateFormSpaceParams extends TargetModelParams { readonly displayName?: Maybe; readonly data?: Maybe; } export declare const updateFormSpaceParamsType: Type; /** * Parameters for submitting a FormSpace. * * @dbxModelApiParams */ export interface SubmitFormSpaceParams extends TargetModelParams { /** * Whether to run the submission's processing task immediately rather than waiting for the queue. */ readonly runImmediately?: Maybe; } export declare const submitFormSpaceParamsType: Type; /** * Result of submitting a FormSpace. */ export interface SubmitFormSpaceResult { /** * The key of the NotificationTask processing the submission. */ readonly processingNotificationKey: string; /** * True if the processing task was newly created by this call. */ readonly processingTaskCreated: boolean; } /** * Parameters for reopening a submitted FormSpace back into an editable draft. * * No options: whether the space may be reopened is the type's policy plus the caller's `reopen` role, and * neither is anything a client gets to say. The acting user is taken from the request, never the body, * because it is what `rby` records. * * @dbxModelApiParams */ export interface ReopenFormSpaceParams extends TargetModelParams { } export declare const reopenFormSpaceParamsType: Type; /** * Parameters for locking a submitted FormSpace's submission immediately. * * @dbxModelApiParams */ export interface LockFormSpaceParams extends TargetModelParams { } export declare const lockFormSpaceParamsType: Type; /** * Parameters for removing one uploaded file from a FormSpace slot. * * The file is dropped from the space's `f` array and its StorageFile is FLAGGED for deletion, never deleted * inline — the StorageFile delete sweep owns removing the object, and a second code path that removed it * here is how an orphaned object gets left behind. * * @dbxModelApiParams */ export interface RemoveFormSpaceFileParams extends TargetModelParams { /** * The slot holding the file. */ readonly slot: FormSpaceFileSlot; /** * The StorageFile to remove. * * Optional only when the slot holds exactly one file: a folder slot with several files has no unambiguous * "the" file, so omitting it there is an error rather than a guess. */ readonly storageFileId?: Maybe; } export declare const removeFormSpaceFileParamsType: Type; /** * Parameters for deleting a FormSpace and flagging its uploaded files for deletion. * * @dbxModelApiParams */ export interface DeleteFormSpaceParams extends TargetModelParams { } export declare const deleteFormSpaceParamsType: Type; /** * Parameters for the backstop sweep over FormSpaces stuck in QUEUED_FOR_PROCESSING. */ export interface ProcessAllQueuedFormSpacesParams { /** * Maximum number of spaces to visit. Defaults to unbounded. */ readonly limit?: Maybe; } export declare const processAllQueuedFormSpacesParamsType: Type; /** * Result of the backstop processing sweep. */ export interface ProcessAllQueuedFormSpacesResult { readonly formSpacesVisited: number; readonly formSpacesProcessStarted: number; readonly formSpacesFailedStarting: number; } /** * Parameters for the expiration sweep. */ export interface ExpireAllExpiredFormSpacesParams { /** * Spaces whose `eat` is at or before this instant are expired. Defaults to now. */ readonly before?: Maybe; /** * Spaces expired per page. */ readonly pageSize?: Maybe; /** * Hard wall-clock budget for the whole sweep. */ readonly maxRunTimeMs?: Maybe; /** * Maximum number of pages. Defaults to unlimited, bounded by the time budget. */ readonly maxPages?: Maybe; } export declare const expireAllExpiredFormSpacesParamsType: Type; /** * Result of the expiration sweep. */ export interface ExpireAllExpiredFormSpacesResult { readonly formSpacesExpired: number; readonly storageFilesFlaggedForDelete: number; readonly pages: number; /** * Whether the sweep stopped because its time budget ran out rather than because nothing was left. */ readonly stoppedForTimeBudget: boolean; readonly durationMs: Milliseconds; } /** * Custom (non-CRUD) function type map for FormSpace. Currently empty — all operations use CRUD functions. */ export type FormSpaceFunctionTypeMap = {}; export declare const FORM_SPACE_FUNCTION_TYPE_CONFIG_MAP: FirebaseFunctionTypeConfigMap; /** * CRUD function configuration map for the FormSpace model family. */ export type FormSpaceModelCrudFunctionsConfig = { readonly formSpace: { create: { _: CreateFormSpaceParams; }; update: { _: UpdateFormSpaceParams; submit: [SubmitFormSpaceParams, SubmitFormSpaceResult]; reopen: ReopenFormSpaceParams; lock: LockFormSpaceParams; removeFile: RemoveFormSpaceFileParams; }; delete: { _: DeleteFormSpaceParams; }; }; }; export declare const FORM_SPACE_MODEL_CRUD_FUNCTIONS_CONFIG: ModelFirebaseCrudFunctionConfigMap; /** * Abstract class defining all callable FormSpace cloud functions. * * Implement this in your app module to wire up the function endpoints. * Use {@link formSpaceFunctionMap} to create a client-side callable map. */ export declare abstract class FormSpaceFunctions implements ModelFirebaseFunctionMap { abstract formSpace: { createFormSpace: { create: ModelFirebaseCreateFunction; }; updateFormSpace: { update: ModelFirebaseCrudFunction; submit: ModelFirebaseCrudFunction; reopen: ModelFirebaseCrudFunction; lock: ModelFirebaseCrudFunction; removeFile: ModelFirebaseCrudFunction; }; deleteFormSpace: { delete: ModelFirebaseCrudFunction; }; }; } /** * Client-side callable function map factory for all FormSpace CRUD operations. * * @example * ```ts * const functions = formSpaceFunctionMap(callableFactory); * const result = await functions.formSpace.createFormSpace.create({ formSpaceType: 'demo_example' }); * ``` */ export declare const formSpaceFunctionMap: import("../..").ModelFirebaseFunctionMapFactory;