UNPKG

@palmares/databases

Version:

Add support for working with databases with palmares framework

91 lines 6.64 kB
import type { Field } from './fields'; import type { BaseModel, Model, ModelType } from './model'; import type { DatabaseAdapter } from '../engine'; import type { AdapterFields } from '../engine/fields'; import type { InitializedModelsType } from '../types'; /** * This is used to store the models that are related to each other. IT IS NOT direct relations. * A direct relation would be when a model defines a ForeignKeyField to another model. * * An INDIRECT relation would be when the model has was defined as a ForeignKeyField in another model. For example: * * @example * ```ts * class User extends Model { * static fields = { * id: AutoField.new(); * } * } * * class Post extends Model { * static fields = { * userId: ForeignKeyField.new({ relatedTo: User }) * } * }; * ``` * * See that Post is related to User? There is no way of User knowing that Post is related to it, but * Post knows that it is related to User. This is an indirect relation. */ export declare const indirectlyRelatedModels: { [modelName: string]: { [relatedModelName: string]: string[]; }; } & { $set: { [modelName: string]: () => void; }; }; /** * Those are the default model options. It will exist in every model and will be used to * define the default options of the model. */ export declare const getDefaultModelOptions: () => { abstract: boolean; underscored: boolean; tableName: undefined; managed: boolean; ordering: never[]; indexes: never[]; databases: string[]; customOptions: {}; }; /** * Used to retrieve the input and output parsers from the field and cache it on the field itself for faster access * next time. */ export declare function retrieveInputAndOutputParsersFromFieldAndCache(engine: DatabaseAdapter, model: ModelType<any, any> & typeof BaseModel, fieldName: string, field: Field<any, any, any>): { input: ((args: import("..").AdapterFieldParserInputAndOutputArgs<"field" | "auto" | "big-auto" | "big-integer" | "boolean" | "char" | "date" | "decimal" | "enum" | "foreign-key" | "integer" | "text" | "uuid">) => Promise<any>) | null; output: ((args: import("..").AdapterFieldParserInputAndOutputArgs<"field" | "auto" | "big-auto" | "big-integer" | "boolean" | "char" | "date" | "decimal" | "enum" | "foreign-key" | "integer" | "text" | "uuid">) => Promise<any>) | null; } | { input: ((args: import("..").AdapterFieldParserInputAndOutputArgs<"field" | "auto" | "big-auto" | "big-integer" | "boolean" | "char" | "date" | "decimal" | "enum" | "foreign-key" | "integer" | "text" | "uuid">) => Promise<any>) | ((args: import("..").AdapterFieldParserInputAndOutputArgs<"auto">) => Promise<any>) | ((args: import("..").AdapterFieldParserInputAndOutputArgs<"integer">) => Promise<any>) | ((args: import("..").AdapterFieldParserInputAndOutputArgs<"big-integer">) => Promise<any>) | ((args: import("..").AdapterFieldParserInputAndOutputArgs<"foreign-key">) => Promise<any>) | ((args: import("..").AdapterFieldParserInputAndOutputArgs<"decimal">) => Promise<any>) | ((args: import("..").AdapterFieldParserInputAndOutputArgs<"uuid">) => Promise<any>) | ((args: import("..").AdapterFieldParserInputAndOutputArgs<"enum">) => Promise<any>) | ((args: import("..").AdapterFieldParserInputAndOutputArgs<"date">) => Promise<any>) | ((args: import("..").AdapterFieldParserInputAndOutputArgs<"char">) => Promise<any>) | ((args: import("..").AdapterFieldParserInputAndOutputArgs<"text">) => Promise<any>) | ((args: import("..").AdapterFieldParserInputAndOutputArgs<"boolean">) => Promise<any>) | undefined; output: ((args: import("..").AdapterFieldParserInputAndOutputArgs<"field" | "auto" | "big-auto" | "big-integer" | "boolean" | "char" | "date" | "decimal" | "enum" | "foreign-key" | "integer" | "text" | "uuid">) => Promise<any>) | ((args: import("..").AdapterFieldParserInputAndOutputArgs<"auto">) => Promise<any>) | ((args: import("..").AdapterFieldParserInputAndOutputArgs<"integer">) => Promise<any>) | ((args: import("..").AdapterFieldParserInputAndOutputArgs<"big-integer">) => Promise<any>) | ((args: import("..").AdapterFieldParserInputAndOutputArgs<"foreign-key">) => Promise<any>) | ((args: import("..").AdapterFieldParserInputAndOutputArgs<"decimal">) => Promise<any>) | ((args: import("..").AdapterFieldParserInputAndOutputArgs<"uuid">) => Promise<any>) | ((args: import("..").AdapterFieldParserInputAndOutputArgs<"enum">) => Promise<any>) | ((args: import("..").AdapterFieldParserInputAndOutputArgs<"date">) => Promise<any>) | ((args: import("..").AdapterFieldParserInputAndOutputArgs<"char">) => Promise<any>) | ((args: import("..").AdapterFieldParserInputAndOutputArgs<"text">) => Promise<any>) | ((args: import("..").AdapterFieldParserInputAndOutputArgs<"boolean">) => Promise<any>) | undefined; }; /** * This is used for the engine to parse the fields that are going to be used in * the model in the database. For every field of a model we will call this function. * * The special use case is ForeignKeyFields, ForeignKeyFields can be attached to a * ForeignKeyField, so we need to retrieve the field that is going to be used. */ export declare function parse(engine: DatabaseAdapter, engineFields: AdapterFields, model: Model, field: Field<any, any, any>, callbackForLazyEvaluation: (translatedField: any, shouldReturnData?: boolean, field?: Field<any, any, any>) => void): Promise<any>; /** * This is utils function and it takes both an engine and a list of models and we call * the _init method on those models to initialize and translate them to something that * the engine can understand. By default engines (like Sequelize, Prisma, etc) does * not understand the Palmares models, it understands their own model implementations. * That's exactly what this does is that it takes the Palmares models and, with the * engine, we translate them to something that the engine can understand. */ export declare function initializeModels(engine: DatabaseAdapter, models: (ModelType<any, any> & typeof BaseModel & typeof Model)[]): Promise<(InitializedModelsType & { modifyItself: (newModel: any) => void; })[]>; /** * This factory function is used to create a default model translate callback. * A library user can call this function at any time to run the default behavior * of the model translation. */ export declare function factoryFunctionForModelTranslate(engine: DatabaseAdapter, model: Model, callbackToParseAfterAllModelsAreTranslated: (field: Field, translatedField: any) => void, options: { forceTranslate?: boolean; }): () => Promise<any>; //# sourceMappingURL=utils.d.ts.map