From b97f93469bee6c3429d8cab7d0cb6418cbf05892 Mon Sep 17 00:00:00 2001 From: Fauzan Date: Sat, 18 Dec 2021 02:01:05 +0700 Subject: [PATCH] refactor(operators): convert operators to typescript (#13731) * refactor(operators): symbol keys prefix To avoid name clashes with your global symbol keys and other (library code) global symbols, it might be a good idea to prefix your symbols * feat: add operators.ts * feat: add operators.ts * Not an object * Change to string * refactor(operators): convert to typescript * fix(operators): revert values back to original values Co-authored-by: Sascha Depold Co-authored-by: Sascha Depold --- lib/operators.js | 91 -------------------- types/lib/operators.d.ts => lib/operators.ts | 50 +++++++++-- types/index.d.ts | 34 ++++---- types/lib/model.d.ts | 2 +- 4 files changed, 63 insertions(+), 114 deletions(-) delete mode 100644 lib/operators.js rename types/lib/operators.d.ts => lib/operators.ts (84%) diff --git a/lib/operators.js b/lib/operators.js deleted file mode 100644 index 7e8bb7cf9cdb..000000000000 --- a/lib/operators.js +++ /dev/null @@ -1,91 +0,0 @@ - -'use strict'; -/** - * Operator symbols to be used when querying data - * - * @see {@link Model#where} - * - * @property eq - * @property ne - * @property gte - * @property gt - * @property lte - * @property lt - * @property not - * @property is - * @property in - * @property notIn - * @property like - * @property notLike - * @property iLike - * @property notILike - * @property startsWith - * @property endsWith - * @property substring - * @property regexp - * @property notRegexp - * @property iRegexp - * @property notIRegexp - * @property between - * @property notBetween - * @property overlap - * @property contains - * @property contained - * @property adjacent - * @property strictLeft - * @property strictRight - * @property noExtendRight - * @property noExtendLeft - * @property and - * @property or - * @property any - * @property all - * @property values - * @property col - * @property placeholder - * @property join - */ -const Op = { - eq: Symbol.for('eq'), - ne: Symbol.for('ne'), - gte: Symbol.for('gte'), - gt: Symbol.for('gt'), - lte: Symbol.for('lte'), - lt: Symbol.for('lt'), - not: Symbol.for('not'), - is: Symbol.for('is'), - in: Symbol.for('in'), - notIn: Symbol.for('notIn'), - like: Symbol.for('like'), - notLike: Symbol.for('notLike'), - iLike: Symbol.for('iLike'), - notILike: Symbol.for('notILike'), - startsWith: Symbol.for('startsWith'), - endsWith: Symbol.for('endsWith'), - substring: Symbol.for('substring'), - regexp: Symbol.for('regexp'), - notRegexp: Symbol.for('notRegexp'), - iRegexp: Symbol.for('iRegexp'), - notIRegexp: Symbol.for('notIRegexp'), - between: Symbol.for('between'), - notBetween: Symbol.for('notBetween'), - overlap: Symbol.for('overlap'), - contains: Symbol.for('contains'), - contained: Symbol.for('contained'), - adjacent: Symbol.for('adjacent'), - strictLeft: Symbol.for('strictLeft'), - strictRight: Symbol.for('strictRight'), - noExtendRight: Symbol.for('noExtendRight'), - noExtendLeft: Symbol.for('noExtendLeft'), - and: Symbol.for('and'), - or: Symbol.for('or'), - any: Symbol.for('any'), - all: Symbol.for('all'), - values: Symbol.for('values'), - col: Symbol.for('col'), - placeholder: Symbol.for('placeholder'), - join: Symbol.for('join'), - match: Symbol.for('match') -}; - -module.exports = Op; diff --git a/types/lib/operators.d.ts b/lib/operators.ts similarity index 84% rename from types/lib/operators.d.ts rename to lib/operators.ts index 18d66589b9ef..d805f34a262a 100644 --- a/types/lib/operators.d.ts +++ b/lib/operators.ts @@ -1,7 +1,4 @@ -/** - * object that holds all operator symbols - */ -declare const Op: { +interface OpTypes { /** * Operator -|- (PG range is adjacent to operator) * @@ -479,6 +476,49 @@ declare const Op: { * ``` */ readonly values: unique symbol; -}; +} + +const Op: OpTypes = { + eq: Symbol.for('eq'), + ne: Symbol.for('ne'), + gte: Symbol.for('gte'), + gt: Symbol.for('gt'), + lte: Symbol.for('lte'), + lt: Symbol.for('lt'), + not: Symbol.for('not'), + is: Symbol.for('is'), + in: Symbol.for('in'), + notIn: Symbol.for('notIn'), + like: Symbol.for('like'), + notLike: Symbol.for('notLike'), + iLike: Symbol.for('iLike'), + notILike: Symbol.for('notILike'), + startsWith: Symbol.for('startsWith'), + endsWith: Symbol.for('endsWith'), + substring: Symbol.for('substring'), + regexp: Symbol.for('regexp'), + notRegexp: Symbol.for('notRegexp'), + iRegexp: Symbol.for('iRegexp'), + notIRegexp: Symbol.for('notIRegexp'), + between: Symbol.for('between'), + notBetween: Symbol.for('notBetween'), + overlap: Symbol.for('overlap'), + contains: Symbol.for('contains'), + contained: Symbol.for('contained'), + adjacent: Symbol.for('adjacent'), + strictLeft: Symbol.for('strictLeft'), + strictRight: Symbol.for('strictRight'), + noExtendRight: Symbol.for('noExtendRight'), + noExtendLeft: Symbol.for('noExtendLeft'), + and: Symbol.for('and'), + or: Symbol.for('or'), + any: Symbol.for('any'), + all: Symbol.for('all'), + values: Symbol.for('values'), + col: Symbol.for('col'), + placeholder: Symbol.for('placeholder'), + join: Symbol.for('join'), + match: Symbol.for('match') +} as OpTypes; export = Op; diff --git a/types/index.d.ts b/types/index.d.ts index c2b1b2993fed..b636752b4fbf 100644 --- a/types/index.d.ts +++ b/types/index.d.ts @@ -1,22 +1,22 @@ -import DataTypes = require('./lib/data-types'); -import Deferrable = require('./lib/deferrable'); -import Op = require('./lib/operators'); -import QueryTypes = require('./lib/query-types'); -import TableHints = require('./lib/table-hints'); -import IndexHints = require('./lib/index-hints'); -import Utils = require('./lib/utils'); +import DataTypes = require("./lib/data-types"); +import Deferrable = require("./lib/deferrable"); +import * as Op from "../lib/operators"; +import QueryTypes = require("./lib/query-types"); +import TableHints = require("./lib/table-hints"); +import IndexHints = require("./lib/index-hints"); +import Utils = require("./lib/utils"); -export * from './lib/sequelize'; -export * from './lib/query-interface'; -export * from './lib/data-types'; -export * from './lib/model'; -export * from './lib/transaction'; -export * from './lib/associations/index'; -export * from './lib/errors'; -export { BaseError as Error } from './lib/errors'; -export { useInflection } from './lib/utils'; +export * from "./lib/associations/index"; +export * from "./lib/data-types"; +export * from "./lib/errors"; +export { BaseError as Error } from "./lib/errors"; +export * from "./lib/model"; +export * from "./lib/query-interface"; +export * from "./lib/sequelize"; +export * from "./lib/transaction"; +export { useInflection } from "./lib/utils"; +export { Validator } from "./lib/utils/validator-extras"; export { Utils, QueryTypes, Op, TableHints, IndexHints, DataTypes, Deferrable }; -export { Validator } from './lib/utils/validator-extras'; /** * Type helper for making certain fields of an object optional. This is helpful diff --git a/types/lib/model.d.ts b/types/lib/model.d.ts index 89cc32e7864e..495a146db5ee 100644 --- a/types/lib/model.d.ts +++ b/types/lib/model.d.ts @@ -8,8 +8,8 @@ import { IndexesOptions, QueryOptions, TableName } from './query-interface'; import { Sequelize, SyncOptions } from './sequelize'; import { LOCK, Transaction } from './transaction'; import { Col, Fn, Literal, Where } from './utils'; -import Op = require('./operators'); import { SetRequired } from '../type-helpers/set-required' +import * as Op from '../../lib/operators'; export interface Logging { /**