UNPKG

2.58 kBTypeScriptView Raw
1/// <reference path="../../adonis-typings/index.d.ts" />
2import { LucidRow, ModelObject, CherryPickFields, RelationshipsContract } from '@ioc:Adonis/Lucid/Orm';
3import { FileNode, QueryClientContract, TransactionClientContract } from '@ioc:Adonis/Lucid/Database';
4/**
5 * Ensure that relation is defined
6 */
7export declare function ensureRelation<T extends RelationshipsContract>(name: string, relation?: T): relation is T;
8/**
9 * Ensure a key value is not null or undefined inside an object.
10 */
11export declare function ensureValue(collection: any, key: string, missingCallback: () => void): any;
12/**
13 * Collects values for a key inside an array. Similar to `Array.map`, but
14 * reports missing values.
15 */
16export declare function collectValues(payload: any[], key: string, missingCallback: () => void): any[];
17/**
18 * Raises exception when a relationship `booted` property is false.
19 */
20export declare function ensureRelationIsBooted(relation: RelationshipsContract): void;
21/**
22 * Returns the value for a key from the model instance and raises descriptive
23 * exception when the value is missing
24 */
25export declare function getValue(model: LucidRow | ModelObject, key: string, relation: RelationshipsContract, action?: string): any;
26/**
27 * Helper to find if value is a valid Object or
28 * not
29 */
30export declare function isObject(value: any): boolean;
31/**
32 * Drops duplicate values from an array
33 */
34export declare function unique(value: any[]): any[];
35/**
36 * Returns a diff of rows to be updated or inserted when performing
37 * a many to many `attach`
38 */
39export declare function syncDiff(original: ModelObject, incoming: ModelObject): {
40 added: ModelObject;
41 updated: ModelObject;
42};
43/**
44 * Invokes a callback by wrapping it inside managed transaction
45 * when passed client is not transaction itself.
46 */
47export declare function managedTransaction<T>(client: QueryClientContract | TransactionClientContract, callback: (trx: TransactionClientContract) => Promise<T>): Promise<T>;
48/**
49 * Returns the sql method for a DDL statement
50 */
51export declare function getDDLMethod(sql: string): "create" | "alter" | "drop" | "unknown";
52/**
53 * Normalizes the cherry picking object to always be an object with
54 * `pick` and `omit` properties
55 */
56export declare function normalizeCherryPickObject(fields: CherryPickFields): {
57 pick: string[] | undefined;
58 omit: string[] | undefined;
59};
60/**
61 * Sources files from a given directory
62 */
63export declare function sourceFiles(fromLocation: string, directory: string): Promise<{
64 directory: string;
65 files: FileNode<unknown>[];
66}>;