import { MangoQuery, RxCollection, RxDatabase } from 'rxdb'; import { T as TaskModel, O as OrgModel, W as WorkspaceModel, P as ProjectModel, M as MilestoneModel, U as UserModel, a as TemplateModel, D as DocumentModel, A as ApprovalModel } from './Workspace-CoUdcswi.cjs'; import { D as DiscussionEntityType, a as DiscussionModel } from './types-5lxby8F5.cjs'; import { Observable } from 'rxjs'; /** * Shared TypeScript types for framework-agnostic operators * * These types are used by QueryOperator and MutationOperator to provide * type-safe interfaces for querying and mutating RxDB collections. * * @packageDocumentation */ /** * Options for configuring a query operation * * @template T - The document type being queried * * @example * ```typescript * const options: QueryOptions = { * selector: { orgId: { $eq: 'org_123' } }, * sort: [{ createdAt: 'desc' }], * limit: 50, * skip: 0 * }; * ``` */ interface QueryOptions { /** * MangoQuery selector for filtering documents * @see https://rxdb.info/rx-query.html */ selector: MangoQuery['selector']; /** * Sort order for results * @example [{ createdAt: 'desc' }] */ sort?: MangoQuery['sort']; /** * Maximum number of documents to return */ limit?: number; /** * Number of documents to skip (for pagination) */ skip?: number; } /** * Result returned by a query operation * * @template T - The document type being queried * * @remarks * This interface provides a consistent structure for query results across * all operators, including loading state and error handling. * * @example * ```typescript * const result: QueryResult = { * data: [{ id: 'task_1', title: 'My Task', ... }], * isLoading: false, * error: null * }; * ``` */ interface QueryResult { /** * Array of documents matching the query * Documents are automatically converted to JSON (not RxDB documents) */ data: T[]; /** * Whether the query is currently loading */ isLoading: boolean; /** * Error object if the query failed, null otherwise */ error: Error | null; } /** * State of a mutation operation * * @template T - The type of data returned by the mutation * * @remarks * Mutations track their own state including loading status and errors. * This state can be observed reactively using the mutation's state$ observable. * * @example * ```typescript * const state: MutationState = { * data: { id: 'task_1', title: 'My Task', ... }, * isLoading: false, * error: null * }; * ``` */ interface MutationState$1 { /** * Data returned by the mutation * Null if mutation hasn't completed or failed */ data: T | null; /** * Whether the mutation is currently executing */ isLoading: boolean; /** * Error object if the mutation failed, null otherwise */ error: Error | null; } /** * Options for configuring a mutation operation * * @template TData - The type of data returned by the mutation * @template TVariables - The type of variables/input passed to the mutation * * @remarks * Mutations are configured with a mutation function and optional callbacks * for success and error scenarios. * * @example * ```typescript * const options: MutationOptions = { * mutationFn: async (collection, input) => { * const task = { ...input, id: createId('task') }; * await collection.insert(task); * return task; * }, * onSuccess: (data, variables) => { * console.log('Task created:', data.id); * }, * onError: (error, variables) => { * console.error('Failed to create task:', error); * } * }; * ``` */ interface MutationOptions$1 { /** * Function that performs the mutation operation * * @param collection - The RxDB collection to operate on * @param variables - Input variables for the mutation * @returns Promise resolving to the mutation result * * @throws Error if the mutation fails */ mutationFn: (collection: RxCollection, variables: TVariables) => Promise; /** * Callback invoked when the mutation succeeds * * @param data - The data returned by the mutation * @param variables - The input variables that were used * * @remarks * Can be async - the mutation will wait for this to complete */ onSuccess?: (data: TData, variables: TVariables) => void | Promise; /** * Callback invoked when the mutation fails * * @param error - The error that occurred * @param variables - The input variables that were used * * @remarks * Can be async - the mutation will wait for this to complete */ onError?: (error: Error, variables: TVariables) => void | Promise; } /** * Framework-agnostic query operator * * Wraps RxDB queries with reactive observables that work in any environment. * Provides both imperative (exec) and reactive (observable) APIs. * * @example * ```typescript * // Imperative usage (Node.js, CLI) * const query = new QueryOperator(collection, { selector: { status: 'active' } }); * const results = await query.exec(); * * // Reactive usage (UI frameworks) * query.observable.subscribe(result => { * console.log('Data updated:', result.data); * }); * ``` */ declare class QueryOperator { private collection; private query; private resultSubject; private subscription?; private _isDestroyed; constructor(collection: RxCollection, options: QueryOptions); /** * Whether this operator has been destroyed. * Used by useQuery to detect StrictMode remounts with a stale operator. */ get isDestroyed(): boolean; /** * Build RxDB query from options */ private buildQuery; /** * Initialize reactive subscription to query results. * Safe to call multiple times (e.g., after reinitialize). */ private initialize; /** * Re-initialize after destroy. Needed for React StrictMode compatibility * where useMemo caches the operator but useEffect cleanup destroys it, * then the remount needs to resubscribe. */ reinitialize(): void; /** * Execute query imperatively and return results as Promise * * Use in Node.js scripts, CLI tools, and other imperative contexts. * * @returns Promise resolving to array of documents */ exec(): Promise; /** * Get reactive observable of query results * * Subscribe to this in UI frameworks for automatic updates. * * @returns Observable that emits QueryResult on every data change */ get observable(): Observable>; /** * Get current query result synchronously * * @returns Current QueryResult value */ get value(): QueryResult; /** * Refetch query results imperatively * * @returns Promise resolving to current query results */ refetch(): Promise; /** * Cleanup subscriptions and complete observables * * Call this when the query is no longer needed to prevent memory leaks. */ destroy(): void; } /** * Mutation state tracking */ interface MutationState { /** Result data from successful mutation */ data: T | null; /** True while mutation is executing */ isLoading: boolean; /** Error object if mutation failed, null otherwise */ error: Error | null; } /** * Mutation operator configuration */ interface MutationOptions { /** Function that performs the mutation on the collection */ mutationFn: (collection: RxCollection, variables: TVariables) => Promise; /** Optional callback invoked on successful mutation */ onSuccess?: (data: TData, variables: TVariables) => void | Promise; /** Optional callback invoked on mutation error */ onError?: (error: Error, variables: TVariables) => void | Promise; } /** * Framework-agnostic mutation operator * * Wraps RxDB write operations with state management and callbacks. * Works in any environment (Node.js, Browser, React Native, Electron). * * @example * ```typescript * // Create mutation operator * const createTask = new MutationOperator(collection, { * mutationFn: async (col, data) => { * await col.insert(data); * return data; * }, * onSuccess: (data) => console.log('Created:', data.id) * }); * * // Execute imperatively * const task = await createTask.execute({ title: 'New Task' }); * * // Or subscribe reactively * createTask.state$.subscribe(state => { * if (state.isLoading) console.log('Saving...'); * if (state.data) console.log('Saved!'); * }); * ``` */ declare class MutationOperator { private collection; private mutationFn; private onSuccess?; private onError?; private stateSubject; constructor(collection: RxCollection, options: MutationOptions); /** * Execute mutation imperatively * * Performs the mutation, updates state, and invokes callbacks. * Returns Promise for imperative usage in scripts and CLI tools. * * @param variables - Input variables for the mutation * @returns Promise resolving to mutation result data * @throws Error if mutation fails */ execute(variables: TVariables): Promise; /** * Get reactive state observable * * Subscribe to this in UI frameworks for automatic state updates. * * @returns Observable that emits MutationState on every state change */ get state$(): Observable>; /** * Get current mutation state synchronously * * @returns Current MutationState value */ get value(): MutationState; /** * Reset mutation state to initial values */ reset(): void; /** * Cleanup and complete observables * * Call this when the mutation operator is no longer needed. */ destroy(): void; } /** * Task query filters */ interface TaskFilters { /** Organization ID (required for multi-tenancy) */ orgId?: string; /** Filter by user ID */ userId?: string; /** Filter by workspace ID */ workspaceId?: string; /** Filter by project ID */ projectId?: string; /** Filter by milestone ID */ milestoneId?: string; /** Filter by parent task ID for subtasks */ parentTaskId?: string; /** Exclude subtasks (tasks with parentTaskId) - set to true to only show top-level tasks */ excludeSubtasks?: boolean; /** Filter by task status */ status?: TaskModel['status']; /** Filter by completion state */ completed?: boolean; /** Filter by archived state (default: false) */ archived?: boolean; } /** * Task creation input */ interface CreateTaskInput { /** Task title */ title: string; /** Task description */ description: string; /** Organization ID */ orgId: string; /** User ID who created the task */ userId: string; /** Parent workspace ID (required - all tasks belong to a workspace) */ workspaceId: string; /** Optional parent project ID (tasks can exist at workspace level) */ projectId?: string; /** Optional parent milestone ID (tasks can exist at project level) */ milestoneId?: string; /** Optional parent task ID for creating subtasks */ parentTaskId?: string; /** Optional task status (default: 'todo') */ status?: TaskModel['status']; /** Optional scheduled start date */ startAt?: string; /** Optional due date */ dueAt?: string; /** Optional task type (default: 'todo') */ type?: TaskModel['type']; /** Optional category ID */ categoryId?: string; /** Optional tag IDs */ tagIds?: string[]; /** Optional time budget in hours */ timeBudgetHours?: number; /** Optional start date */ startedAt?: string; /** Optional completion date */ completedAt?: string; /** Optional recurrence flag */ isRecurring?: boolean; /** Optional iCal RRULE recurrence rule string */ recurrenceRule?: string; /** Optional parent recurrence ID */ parentRecurrenceId?: string; /** Optional recurrence instance date */ recurrenceInstanceDate?: string; /** Optional priority (0-4, default: 0) */ priority?: number; /** Optional assignee team member ID */ assigneeId?: string; /** Optional sort order */ sortOrder?: number; } /** * Task update input */ interface UpdateTaskInput { /** Task ID to update */ id: string; /** Partial task data to update */ updates: Partial; } /** * Framework-agnostic task operations * * Provides query and mutation operators for tasks that work in any environment. * Use this directly in Node.js scripts or wrap with framework hooks (React, Vue, etc.). * * @example * ```typescript * // Node.js script usage * const taskOps = new TaskOperator(db); * const query = taskOps.query({ orgId: 'org_123', status: 'in_progress' }); * const tasks = await query.exec(); * * // Create task * const mutation = taskOps.createMutation(); * const newTask = await mutation.execute({ * title: 'New Task', * description: 'Task description', * orgId: 'org_123', * userId: 'user_456', * projectId: 'proj_789', * milestoneId: 'mile_101' * }); * ``` */ declare class TaskOperator { private db; constructor(db: RxDatabase); /** * Create a query operator for tasks * * Returns a QueryOperator that can be used imperatively (exec) or reactively (observable). * * @param filters - Task filters to apply * @param options - Optional query options (sort, limit, skip) * @returns QueryOperator instance for tasks */ query(filters: TaskFilters, options?: { sort?: string; limit?: number; skip?: number; }): QueryOperator; /** * Find a single task by ID * * @param taskId - Task ID to find * @returns Promise resolving to task or null if not found */ findOne(taskId: string): Promise; /** * Count tasks matching the given filters * * @param filters - Task filters to apply * @returns Promise resolving to count of matching tasks */ count(filters: TaskFilters): Promise; /** * Create a mutation operator for creating tasks * * @returns MutationOperator for task creation */ createMutation(): MutationOperator; /** * Create a mutation operator for updating tasks * * @returns MutationOperator for task updates */ updateMutation(): MutationOperator; /** * Create a mutation operator for deleting tasks (soft delete) * * Marks task as archived rather than physically deleting it. * * @returns MutationOperator for task deletion */ deleteMutation(): MutationOperator; /** * Create a mutation operator for completing tasks * * Sets task status to 'done' and marks as completed. * * @returns MutationOperator for task completion */ completeMutation(): MutationOperator; } interface OrgFilters { /** Filter by user ID (owner) */ userId?: string; /** Filter by archived state (default: false) */ archived?: boolean; } interface CreateOrgInput { /** Organization name */ name: string; /** Organization description */ description: string; /** User ID of organization creator/owner */ userId: string; } interface UpdateOrgInput { /** Org ID to update */ id: string; /** Partial org data to update */ updates: Partial; } declare class OrgOperator { private db; constructor(db: RxDatabase); query(filters: OrgFilters, options?: { sort?: string; limit?: number; skip?: number; }): QueryOperator; findOne(orgId: string): Promise; count(filters: OrgFilters): Promise; createMutation(): MutationOperator; updateMutation(): MutationOperator; deleteMutation(): MutationOperator; } interface WorkspaceFilters { /** Organization ID (optional - omit for cross-org queries in "View All" mode) */ orgId?: string; /** Filter by user ID */ userId?: string; /** Filter by workspace status */ status?: WorkspaceModel['status']; /** Filter by archived state (default: false) */ archived?: boolean; } interface CreateWorkspaceInput { /** Workspace name (kebab-case) */ name: string; /** Workspace title */ title: string; /** Workspace description */ description: string; /** Organization ID */ orgId: string; /** User ID of workspace creator */ userId: string; /** Optional workspace status (default: 'active') */ status?: WorkspaceModel['status']; /** Optional tags */ tags?: string[]; } interface UpdateWorkspaceInput { /** Workspace ID to update */ id: string; /** Partial workspace data to update */ updates: Partial; } declare class WorkspaceOperator { private db; constructor(db: RxDatabase); query(filters: WorkspaceFilters, options?: { sort?: string; limit?: number; skip?: number; }): QueryOperator; findOne(workspaceId: string): Promise; count(filters: WorkspaceFilters): Promise; createMutation(): MutationOperator; updateMutation(): MutationOperator; deleteMutation(): MutationOperator; } interface ProjectFilters { /** Organization ID (optional - omit for cross-org queries in "View All" mode) */ orgId?: string; /** Filter by user ID */ userId?: string; /** Filter by goal ID */ goalId?: string; /** Filter by workspace ID */ workspaceId?: string; /** Filter by codebase ID */ codebaseId?: string; /** Filter by category ID */ categoryId?: string; /** Filter by completion state */ completed?: boolean; /** Filter by archived state (default: false) */ archived?: boolean; } interface CreateProjectInput { /** Project name (kebab-case) */ name: string; /** Project title */ title: string; /** Project description */ description: string; /** Organization ID */ orgId: string; /** User ID of project creator */ userId: string; /** Parent goal ID */ goalId: string; /** Optional workspace ID */ workspaceId?: string; /** Optional codebase ID */ codebaseId?: string; /** Optional category ID */ categoryId?: string; /** Optional tag IDs */ tagIds?: string[]; /** Optional planned start date (ISO 8601) */ startAt?: string; /** Optional actual start date (ISO 8601) */ startedAt?: string; /** Optional due date (ISO 8601) */ dueAt?: string; /** Optional completion date (ISO 8601) */ completedAt?: string; /** Optional time budget in hours */ timeBudgetHours?: number; /** Optional MCP and spec tracking metadata */ metadata?: any; } interface UpdateProjectInput { /** Project ID to update */ id: string; /** Partial project data to update */ updates: Partial; } declare class ProjectOperator { private db; constructor(db: RxDatabase); query(filters: ProjectFilters, options?: { sort?: string; limit?: number; skip?: number; }): QueryOperator; findOne(projectId: string): Promise; count(filters: ProjectFilters): Promise; createMutation(): MutationOperator; updateMutation(): MutationOperator; deleteMutation(): MutationOperator; completeMutation(): MutationOperator; } interface MilestoneFilters { /** Organization ID (optional - omit for cross-org queries in "View All" mode) */ orgId?: string; /** Filter by workspace ID */ workspaceId?: string; /** Filter by user ID */ userId?: string; /** Filter by project ID */ projectId?: string; /** Filter by goal ID */ goalId?: string; /** Filter by completion state */ completed?: boolean; /** Filter by archived state (default: false) */ archived?: boolean; } interface CreateMilestoneInput { /** Milestone name (kebab-case) */ name: string; /** Milestone title */ title: string; /** Milestone description */ description: string; /** Organization ID */ orgId: string; /** User ID of milestone creator */ userId: string; /** Workspace ID */ workspaceId: string; /** Parent project ID */ projectId: string; /** Parent goal ID */ goalId: string; /** Optional planned start date (ISO 8601) */ startAt?: string; /** Optional actual start date (ISO 8601) */ startedAt?: string; /** Optional due date (ISO 8601) */ dueAt?: string; /** Optional completion date (ISO 8601) */ completedAt?: string; /** Optional time budget in hours */ timeBudgetHours?: number; /** Optional category ID */ categoryId?: string; /** Optional tag IDs */ tagIds?: string[]; /** Optional sort order */ sortOrder?: number; } interface UpdateMilestoneInput { /** Milestone ID to update */ id: string; /** Partial milestone data to update */ updates: Partial; } declare class MilestoneOperator { private db; constructor(db: RxDatabase); query(filters: MilestoneFilters, options?: { sort?: string; limit?: number; skip?: number; }): QueryOperator; findOne(milestoneId: string): Promise; count(filters: MilestoneFilters): Promise; createMutation(): MutationOperator; updateMutation(): MutationOperator; deleteMutation(): MutationOperator; completeMutation(): MutationOperator; } interface UserFilters { email?: string; onboarded?: boolean; archived?: boolean; authUserId?: string; } interface CreateUserInput { name: string; email: string; onboarded?: boolean; authUserId?: string; } interface UpdateUserInput { id: string; updates: Partial; } declare class UserOperator { private db; constructor(db: RxDatabase); query(filters: UserFilters, options?: { sort?: string; limit?: number; skip?: number; }): QueryOperator; findOne(userId: string): Promise; count(filters: UserFilters): Promise; createMutation(): MutationOperator; updateMutation(): MutationOperator; deleteMutation(): MutationOperator; } interface TemplateFilters { orgId: string; workspaceId?: string; templateType?: TemplateModel['templateType']; isDefault?: boolean; category?: 'spec' | 'steering'; } interface CreateTemplateInput { templateType: TemplateModel['templateType']; name: string; content: string; version: string; isDefault: boolean; orgId: string; workspaceId: string; userId?: string; metadata?: TemplateModel['metadata']; } interface UpdateTemplateInput { id: string; updates: Partial; } declare class TemplateOperator { private db; constructor(db: RxDatabase); query(filters: TemplateFilters, options?: { sort?: string; limit?: number; skip?: number; }): QueryOperator; findOne(templateId: string): Promise; count(filters: TemplateFilters): Promise; createMutation(): MutationOperator; updateMutation(): MutationOperator; deleteMutation(): MutationOperator; } interface DiscussionFilters { orgId: string; workspaceId?: string; userId?: string; entityType?: DiscussionEntityType; entityId?: string; parentId?: string; isDeleted?: boolean; } interface CreateDiscussionInput { content: string; entityType: DiscussionEntityType; entityId: string; orgId: string; workspaceId: string; userId: string; userName: string; userAvatar?: string; parentId?: string; contentHtml?: string; metadata?: Record; } interface UpdateDiscussionInput { id: string; updates: Partial; } declare class DiscussionOperator { private db; constructor(db: RxDatabase); query(filters: DiscussionFilters, options?: { sort?: string; limit?: number; skip?: number; }): QueryOperator; findOne(discussionId: string): Promise; count(filters: DiscussionFilters): Promise; createMutation(): MutationOperator; updateMutation(): MutationOperator; deleteMutation(): MutationOperator; } interface DocumentFilters { orgId: string; workspaceId?: string; projectId?: string; milestoneId?: string; taskId?: string; documentType?: DocumentModel['documentType']; approved?: boolean; } interface CreateDocumentInput { title: string; content: string; orgId: string; userId: string; documentType: DocumentModel['documentType']; workspaceId?: string; projectId?: string; milestoneId?: string; taskId?: string; codebaseId?: string; metadata?: DocumentModel['metadata']; } interface UpdateDocumentInput { id: string; updates: Partial; } declare class DocumentOperator { private db; constructor(db: RxDatabase); query(filters: DocumentFilters, options?: { sort?: string; limit?: number; skip?: number; }): QueryOperator; findOne(documentId: string): Promise; count(filters: DocumentFilters): Promise; createMutation(): MutationOperator; updateMutation(): MutationOperator; deleteMutation(): MutationOperator; approveMutation(): MutationOperator; } interface ApprovalFilters { orgId: string; workspaceId?: string; projectId?: string; milestoneId?: string; status?: ApprovalModel['status']; type?: ApprovalModel['type']; category?: ApprovalModel['category']; userId?: string; } interface CreateApprovalInput { projectId: string; milestoneId?: string; taskId?: string; documentId?: string; title: string; type: ApprovalModel['type']; category: ApprovalModel['category']; categoryName: string; documentType?: string; documentContent?: string; orgId: string; workspaceId: string; userId: string; } interface UpdateApprovalInput { id: string; updates: Partial; } declare class ApprovalOperator { private db; constructor(db: RxDatabase); query(filters: ApprovalFilters, options?: { sort?: string; limit?: number; skip?: number; }): QueryOperator; findOne(approvalId: string): Promise; count(filters: ApprovalFilters): Promise; createMutation(): MutationOperator; updateMutation(): MutationOperator; deleteMutation(): MutationOperator; } export { type DiscussionFilters as A, type CreateDiscussionInput as B, type CreateTaskInput as C, DiscussionOperator as D, type UpdateDiscussionInput as E, DocumentOperator as F, type DocumentFilters as G, type CreateDocumentInput as H, type UpdateDocumentInput as I, ApprovalOperator as J, type ApprovalFilters as K, type CreateApprovalInput as L, MutationOperator as M, type UpdateApprovalInput as N, OrgOperator as O, ProjectOperator as P, QueryOperator as Q, TaskOperator as T, type UpdateTaskInput as U, WorkspaceOperator as W, type QueryOptions as a, type QueryResult as b, type MutationOptions$1 as c, type MutationState$1 as d, type TaskFilters as e, type OrgFilters as f, type CreateOrgInput as g, type UpdateOrgInput as h, type WorkspaceFilters as i, type CreateWorkspaceInput as j, type UpdateWorkspaceInput as k, type ProjectFilters as l, type CreateProjectInput as m, type UpdateProjectInput as n, MilestoneOperator as o, type MilestoneFilters as p, type CreateMilestoneInput as q, type UpdateMilestoneInput as r, UserOperator as s, type UserFilters as t, type CreateUserInput as u, type UpdateUserInput as v, TemplateOperator as w, type TemplateFilters as x, type CreateTemplateInput as y, type UpdateTemplateInput as z };