Skip to content

Commit

Permalink
refactor(operators): convert operators to typescript (#13731)
Browse files Browse the repository at this point in the history
* 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 <sdepold@users.noreply.github.com>
Co-authored-by: Sascha Depold <sascha@depold.com>
  • Loading branch information
3 people committed Dec 17, 2021
1 parent b7b472e commit b97f934
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 114 deletions.
91 changes: 0 additions & 91 deletions lib/operators.js

This file was deleted.

50 changes: 45 additions & 5 deletions types/lib/operators.d.ts → 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)
*
Expand Down Expand Up @@ -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;
34 changes: 17 additions & 17 deletions 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
Expand Down
2 changes: 1 addition & 1 deletion types/lib/model.d.ts
Expand Up @@ -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 {
/**
Expand Down

0 comments on commit b97f934

Please sign in to comment.