UNPKG

git-goose

Version:

a mongoose plugin that enables git like change tracking

65 lines (64 loc) 3.1 kB
import { FilterQuery, ProjectionType, QueryOptions, Require_id } from 'mongoose'; import { Commit, CommitRef, Nullable, Patch, PatcherName, RefId } from '../types'; import { GitBase } from './base'; /** * Git manager with the knowledge of its target referenceId, enabling contextually aware operations * * @template TargetDocType - The type of the document to be generated * @template TPatcherName - The inferred name of the patcher to use (used for type hinting patches) */ export declare abstract class GitWithContext<TargetDocType, TPatcherName extends PatcherName> extends GitBase<TargetDocType, TPatcherName> { protected abstract get refId(): RefId; /** * @param commit - The commit identifier */ checkout(commit: CommitRef): Promise<Nullable<import('mongoose').IfAny<TargetDocType, any, import('mongoose').Document<unknown, {}, TargetDocType> & Require_id<TargetDocType>>>>; /** * Fetch the diff for the active document and the current HEAD commit * * Effectively an alias for {@link status} */ diff(): Promise<Patch<TPatcherName>>; /** * Return the difference between the active document and another commit * * @param commit - A commit identifier */ diff(commit: CommitRef): Promise<Patch<TPatcherName>>; /** * @param commitA - A commit identifier * @param commitB - A commit identifier */ diff(commitA?: CommitRef, commitB?: CommitRef): Promise<Patch<TPatcherName>>; /** * @param filter - Optional filter for further constraining. * - It will always be constrained by the [target]{@link DBCommit#refId} field * regardless whether you try to override it * @param projection - Optional projection on the {@link Commit} model. * - This is scoped on the {@link Commit} type as opposed to the * actual type {@link DBCommit} to influence intent * - If you try to fetch target or snapshot fields despite the warnings, we will remove them post-processing * @param options - Optional query options for further modifications of the response data * - Unless overridden it will default sort by descending date and limit to the top 10 commits */ log(filter?: FilterQuery<Commit>, projection?: ProjectionType<Commit> | null, options?: QueryOptions<Commit> & { lean: true; }): Promise<Commit[]>; /** * Show the non-committed changes * * Returns the difference between the active document and the current HEAD commit */ status(): Promise<Patch<TPatcherName>>; protected commit(curr?: Nullable<Require_id<TargetDocType>>): Promise<void>; /** * Fetch the current state of the active working reference document * * When no direct connection to the currently working document, we fetch from the db and objectify */ protected getActiveDoc(): Promise<Nullable<Require_id<TargetDocType>>>; /** * Fetch the current state of the HEAD commit reference document */ protected getHeadDoc(): Promise<Nullable<Require_id<TargetDocType>>>; }