UNPKG

4.11 kBTypeScriptView Raw
1import { DataType } from './data-types';
2import { Model, WhereOptions } from './model';
3
4export type Primitive = 'string' | 'number' | 'boolean';
5
6export interface Inflector {
7 singularize(str: string): string;
8 pluralize(str: string): string;
9}
10
11export function useInflection(inflection: Inflector): void;
12
13export function camelizeIf(string: string, condition?: boolean): string;
14export function underscoredIf(string: string, condition?: boolean): string;
15export function isPrimitive(val: unknown): val is Primitive;
16
17/** Same concept as _.merge, but don't overwrite properties that have already been assigned */
18export function mergeDefaults<T>(a: T, b: Partial<T>): T;
19export function spliceStr(str: string, index: number, count: number, add: string): string;
20export function camelize(str: string): string;
21export function format(arr: string[], dialect: string): string;
22export function formatNamedParameters(sql: string, parameters: {
23 [key: string]: string | number | boolean;
24}, dialect: string): string;
25export function cloneDeep<T>(obj: T, fn?: (el: unknown) => unknown): T;
26
27export interface OptionsForMapping {
28 attributes?: string[];
29 where?: WhereOptions;
30}
31
32/** Expand and normalize finder options */
33export function mapFinderOptions<T extends OptionsForMapping>(options: T, model: typeof Model): T;
34
35/* Used to map field names in attributes and where conditions */
36export function mapOptionFieldNames<T extends OptionsForMapping>(options: T, model: typeof Model): T;
37
38export function mapWhereFieldNames(attributes: object, model: typeof Model): object;
39/** Used to map field names in values */
40export function mapValueFieldNames(dataValues: object, fields: string[], model: typeof Model): object;
41
42export function isColString(value: string): boolean;
43export function canTreatArrayAsAnd(arr: unknown[]): boolean;
44export function combineTableNames(tableName1: string, tableName2: string): string;
45
46export function singularize(s: string): string;
47export function pluralize(s: string): string;
48
49export function toDefaultValue<T>(value: unknown): unknown;
50
51/**
52 * Determine if the default value provided exists and can be described
53 * in a db schema using the DEFAULT directive.
54 *
55 * @param value Any default value.
56 */
57export function defaultValueSchemable(hash: DataType): boolean;
58export function stack(): NodeJS.CallSite[];
59export function now(dialect: string): Date;
60
61// Note: Use the `quoteIdentifier()` and `escape()` methods on the
62// `QueryInterface` instead for more portable code.
63export const TICK_CHAR: string;
64export function addTicks(s: string, tickChar?: string): string;
65export function removeTicks(s: string, tickChar?: string): string;
66
67/**
68 * Wraps a constructor to not need the `new` keyword using a proxy.
69 * Only used for data types.
70 */
71export function classToInvokable<T extends new (...args: any[]) => any>(ctor: T): T & {
72 (...args: ConstructorParameters<T>): T;
73}
74
75export class SequelizeMethod {
76
77}
78
79/*
80 * Utility functions for representing SQL functions, and columns that should be escaped.
81 * Please do not use these functions directly, use Sequelize.fn and Sequelize.col instead.
82 */
83export class Fn extends SequelizeMethod {
84 constructor(fn: string, args: unknown[]);
85 public clone(): this;
86}
87
88export class Col extends SequelizeMethod {
89 public col: string;
90 constructor(col: string);
91}
92
93export class Cast extends SequelizeMethod {
94 public val: unknown;
95 public type: string;
96 constructor(val: unknown, type?: string);
97}
98
99export class Literal extends SequelizeMethod {
100 public val: unknown;
101 constructor(val: unknown);
102}
103
104export class Json extends SequelizeMethod {
105 public conditions: object;
106 public path: string;
107 public value: string | number | boolean;
108 constructor(conditionsOrPath: string | object, value?: string | number | boolean);
109}
110
111export class Where extends SequelizeMethod {
112 public attribute: object;
113 public comparator: string;
114 public logic: string | object;
115 constructor(attr: object, comparator: string, logic: string | object);
116 constructor(attr: object, logic: string | object);
117}
118
119export { Promise } from './promise';