@clickup/ent-framework
Version:
A PostgreSQL graph-database-alike library with microsharding and row-level security
79 lines • 4.38 kB
TypeScript
import type { Client } from "../../abstract/Client";
import type { OmitNew } from "../../internal/misc";
import type { InsertInput, LoadByInput, Row, Table, UniqueKey, UpdateField, UpdateInput } from "../../types";
import type { UpdateOriginalInput } from "../types";
import type { VC } from "../VC";
import type { PrimitiveClass, PrimitiveInstance } from "./PrimitiveMixin";
export interface HelpersInstance<TTable extends Table> extends PrimitiveInstance<TTable> {
/**
* Same as updateOriginal(), but updates only the fields which are different
* in input and in the current object.
* - This method can works with CAS; see $cas property of the passed object.
* If CAS fails, returns false, the same way as updateOriginal() does.
* - If there was no such Ent in the DB, returns false, the same way as
* updateOriginal() does.
* - If no changed fields are detected, returns null as an indication (it's
* still falsy, but is different from the parent updateOriginal's `false`).
* - Otherwise, when an update happened, returns the list of fields which were
* different and triggered that change (a truthy value). The order of fields
* in the list matches the order of fields in the Ent schema definition.
*/
updateChanged(input: UpdateOriginalInput<TTable>): Promise<Array<UpdateField<TTable>> | false | null>;
/**
* Same as updateChanged(), but returns the updated Ent (or the original one
* if no fields were updated).
*/
updateChangedReturningX<TEnt extends HelpersInstance<TTable>>(this: TEnt, input: UpdateInput<TTable>): Promise<TEnt>;
/**
* Same as updateOriginal(), but returns the updated Ent (or null of there
* was no such Ent in the database).
*/
updateReturningNullable<TEnt extends HelpersInstance<TTable>>(this: TEnt, input: UpdateInput<TTable>): Promise<TEnt | null>;
/**
* Same as updateOriginal(), but throws if the object wasn't updated or
* doesn't exist after the update.
*/
updateReturningX<TEnt extends HelpersInstance<TTable>>(this: TEnt, input: UpdateInput<TTable>): Promise<TEnt>;
}
export interface HelpersClass<TTable extends Table, TUniqueKey extends UniqueKey<TTable>, TClient extends Client> extends OmitNew<PrimitiveClass<TTable, TUniqueKey, TClient>> {
/**
* Same as insertIfNotExists(), but throws if the Ent violates unique key
* constraints.
*/
insert: (vc: VC, input: InsertInput<TTable>) => Promise<string>;
/**
* Same as insert(), but returns the created Ent.
*/
insertReturning: <TEnt extends HelpersInstance<TTable>>(this: new () => TEnt, vc: VC, input: InsertInput<TTable>) => Promise<TEnt>;
/**
* Same, but returns the created/updated Ent.
*/
upsertReturning: <TEnt extends HelpersInstance<TTable>>(this: new () => TEnt, vc: VC, input: InsertInput<TTable>) => Promise<TEnt>;
/**
* Same as loadNullable(), but if no permissions to read, returns null and
* doesn't throw. It's more a convenience function rather than a concept.
*/
loadIfReadableNullable: <TEnt extends HelpersInstance<TTable>>(this: new () => TEnt, vc: VC, id: string) => Promise<TEnt | null>;
/**
* Loads an Ent by its ID. Throws if no such Ent is found.
* This method is used VERY often.
*/
loadX: <TEnt extends HelpersInstance<TTable>>(this: new () => TEnt, vc: VC, id: string) => Promise<TEnt>;
/**
* Loads an Ent by its ID. Throws if no such Ent is found.
* This method is used VERY often.
*/
loadByX: <TEnt extends HelpersInstance<TTable>>(this: new () => TEnt, vc: VC, input: LoadByInput<TTable, TUniqueKey>) => Promise<TEnt>;
/**
* TS requires us to have a public constructor to infer instance types in
* various places. We make this constructor throw if it's called.
*/
new (): HelpersInstance<TTable> & Row<TTable>;
}
/**
* Modifies the passed class adding convenience methods (like loadX() which
* throws when an Ent can't be loaded instead of returning null as it's done in
* the primitive operations).
*/
export declare function HelpersMixin<TTable extends Table, TUniqueKey extends UniqueKey<TTable>, TClient extends Client>(Base: PrimitiveClass<TTable, TUniqueKey, TClient>): HelpersClass<TTable, TUniqueKey, TClient>;
//# sourceMappingURL=HelpersMixin.d.ts.map