import { BaseService } from '@txstate-mws/graphql-server'; import type { Queryable } from 'mysql2-async'; import { type Index, type IndexStringified, type SearchRule, type Tag, type Versioned, type VersionedCommon, type VersionFilter } from '../internal.js'; export declare class VersionedService extends BaseService { protected static cleaningIndexValues: boolean; protected static optimizingTables: boolean; /** * Retrieve an object with a specific version or tag. * * This method is dataloaded so don't be afraid to make massively concurrent * requests for many objects. * * If you ask for a specific tag that doesn't exist, you'll receive undefined. */ get(id: number, { version, tag }?: { version?: number; tag?: string; }): Promise | undefined>; getMeta(id: number, opts?: { version?: number; tag?: string; }): Promise; /** * Indexed search where all index values must be present on a specified tag (or default latest). */ findAll(indexes: { indexName: string; value: string; }[], opts?: { tdb?: Queryable; tag?: string; }): Promise; /** * Indexed search for objects. */ find(rules: SearchRule[], type?: string, tag?: string, /** * limit search to the given ids to reduce the search space when possible */ ids?: string[], tdb?: Queryable): Promise; /** * See the indexes associated with a particular version * * Note that any numbers you passed in as indexes will have been stringified with * zerofill to 10 digits. This is to help normalize lexical vs numerical comparisons. */ getIndexes(id: number, version: number, tdb?: Queryable): Promise; getCurrentIndexValues(id: number, idxName: string, published?: boolean): Promise; /** * Completely overwrite all the indexes for a specific version of an object. */ setIndexes(id: number, version: number, indexes: Index[], tdb?: Queryable): Promise; /** * Only overwrite a single index type, leave the others alone. */ setIndex(id: number, version: number, index: Index): Promise; /** * Create a new versioned object. Returns its auto-generated id (a 10 character string). * * You are expected to provide your own index strings; they will be stored and kept for * the entire version history. * * You may optionally provide a user who is responsible for the update. * * @param tdb Optional transaction in which to perform creation. */ create(type: string, data: any, indexes: Index[], user?: string, tdb?: Queryable): Promise; /** * Update the timestamps of a current record. * * When migrating content from another data source, it may be desirable to retain the created and modified * dates/users from the original system. During the migration process, you may use this method to override the created * and modified times of the current version. * * If you are migrating a version history, you should call this.update() once per version, and call this method * after each update to update the modifiedAt stamp. This way the corrected stamp will make its way into the * version history when you send your next update. */ setStamps(id: number, stamps: { createdAt?: Date; modifiedAt?: Date; modifiedBy?: string; }, tdb?: Queryable): Promise; /** * Update an object, retaining the version history. * * You are expected to provide your own index strings; they will be stored and kept for * the entire version history. * * You may optionally provide a user who is responsible for the update and a comment string. * * You may also optionally provide the version that you had when you started the update for * an optimistic concurrency check. */ update(id: number, data: any, indexes: Index[], { user, comment, version, date }?: { user?: string; comment?: string; version?: number; date?: Date; }, tdb?: Queryable): Promise; /** * Restore a previous version of the object. Creates a new version. You could do * this with a .get and subsequent .update, but this is here for convenience. * * If you provide an indexes array, it will be used. Otherwise the indexes for the version * being restored will be restored as well. */ restore(id: number, { tag, version }: { tag?: string; version?: number; }, { indexes, user, comment, tdb }?: { indexes?: Index[]; user?: string; comment?: string; tdb?: Queryable; }): Promise; /** * Completely remove an object and its entire version history. Use with caution. May be * better to place a soft delete flag inside the object data. */ delete(id: number): Promise; /** * Tag a specific version of an object. A tag can only point to one version at a time, so this * replaces an existing tag on another version. Cannot be undone. * * A common example will be tagging a version as 'published' or 'approved' as part of a workflow. * * 'latest' is reserved for the most current version of an object. * * @param version If undefined, tags latest version. * @param user Person responsible for applying the tag. */ tag(id: number, tag: string, version?: number, user?: string, date?: Date, tdb?: Queryable): Promise; /** * Get the version number, user, and date associated with a tag on a given object. * * This method is dataloaded so it is safe to call it many times concurrently. * * If the object does not have the given tag, returns undefined. */ getTag(id: number, tag: string): Promise; /** * Get a list of tags that apply to the given version * * Does not include 'latest'. */ getTags(id: number, version: number): Promise; /** * Get the set of tags that apply to the latest version of the given object, not * including 'latest'. For instance, if the latest version happens to be tagged as * 'published', then this will return [{ id, version, tag: 'published', user, date }] */ getCurrentTags(id: number): Promise; /** * Remove a tag from an object, no matter which version it might be pointing at. Cannot be undone. */ removeTag(id: number, tag: string, tdb?: Queryable): Promise; removeTags(ids: number[], tags: string[], tdb?: Queryable): Promise; /** * Remove a tag from the system. Important to do this for obsolete tags so that versions * can be properly cleaned up. Any tag on a version will prevent it from being deleted by * retention policy. * * Use with caution, this cannot be undone. */ globalRemoveTag(tag: string): Promise; /** * List old versions of an object so one can be picked for retrieval. */ listVersions(id: number, filter?: VersionFilter): Promise<{ tags: string[]; id: number; version: number; date: Date; user: string; comment: string; markedAt?: Date; matches: number; }[]>; toggleMarked(id: number, version: number): Promise; /** * internal method to map a set of index strings to their id in indexvalues table * inserts any values that do not already exist */ protected getIndexValueIds(values: string[], db: Queryable): Promise>; protected getIndexNameIds(names: string[], db: Queryable): Promise>; /** * internal method to replace all indexes for a given version of a versioned object * the public create, update, and setIndexes all share this common logic */ protected _setIndexes(id: number, version: number, indexes: Index[], db: Queryable): Promise; /** * Delete old versions in the system to implement a retention policy. Will not * delete any versions newer than the oldest active tag. For instance, if an object on * version 7 has a version 2 made many years ago but still tagged as 'published', version 2 * and greater will be retained. Make sure any tags you use are managed carefully. */ static deleteOldVersions(olderThan: Date): Promise; /** * Delete all index rows for an object except those belonging to the specified versions. * This is useful for pruning indexes that will never be queried again, e.g. intermediate * draft versions between the published version and the latest version. */ deleteOtherIndexes(id: number, keepVersions: number[], tdb?: Queryable): Promise; static cleanAndOptimize(): Promise; /** * internal method to defragment and optimize the database tables */ protected static optimize(): Promise; /** * internal method to clean out value strings from the indexvalues table when they are no longer * used */ protected static cleanIndexValues(): Promise; static init(db: Queryable): Promise; }