@snowtop/ent 0.1.0-alpha155 → 0.1.0-alpha157

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/core/clause.d.ts CHANGED
@@ -11,10 +11,12 @@ export interface SensitiveValue {
11
11
  value(): any;
12
12
  logValue(): any;
13
13
  }
14
+ type InClauseOperator = "IN" | "NOT IN";
14
15
  export declare class inClause<T extends Data, K = keyof T> implements Clause<T, K> {
15
16
  private col;
16
17
  private value;
17
18
  private type;
19
+ protected op: InClauseOperator;
18
20
  static getPostgresInClauseValuesThreshold(): number;
19
21
  constructor(col: K, value: any[], type?: string);
20
22
  clause(idx: number): string;
@@ -23,6 +25,9 @@ export declare class inClause<T extends Data, K = keyof T> implements Clause<T,
23
25
  logValues(): any[];
24
26
  instanceKey(): string;
25
27
  }
28
+ export declare class notInClause<T extends Data, K = keyof T> extends inClause<T, K> {
29
+ protected op: InClauseOperator;
30
+ }
26
31
  /**
27
32
  * creates a clause to determine if the given value is contained in the array stored in the column in the db
28
33
  * only works with postgres gin indexes
@@ -89,6 +94,10 @@ export declare function UuidIn<T extends Data, K = keyof T>(col: K, values: ID[]
89
94
  export declare function IntegerIn<T extends Data, K = keyof T>(col: K, values: number[]): Clause<T, K>;
90
95
  export declare function TextIn<T extends Data, K = keyof T>(col: K, values: any[]): Clause<T, K>;
91
96
  export declare function DBTypeIn<T extends Data, K = keyof T>(col: K, values: any[], typ: string): Clause<T, K>;
97
+ export declare function UuidNotIn<T extends Data, K = keyof T>(col: K, values: ID[]): Clause<T, K>;
98
+ export declare function IntegerNotIn<T extends Data, K = keyof T>(col: K, values: number[]): Clause<T, K>;
99
+ export declare function TextNotIn<T extends Data, K = keyof T>(col: K, values: any[]): Clause<T, K>;
100
+ export declare function DBTypeNotIn<T extends Data, K = keyof T>(col: K, values: any[], typ: string): Clause<T, K>;
92
101
  interface TsQuery {
93
102
  language: "english" | "french" | "german" | "simple";
94
103
  value: string;
package/core/clause.js CHANGED
@@ -23,7 +23,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
23
23
  return result;
24
24
  };
25
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.getCombinedClause = exports.Modulo = exports.Divide = exports.Multiply = exports.Subtract = exports.Add = exports.PaginationMultipleColsSubQuery = exports.JSONPathValuePredicate = exports.JSONObjectFieldKeyAsText = exports.JSONObjectFieldKeyASJSON = exports.sensitiveValue = exports.TsVectorWebsearchToTsQuery = exports.TsVectorPhraseToTsQuery = exports.TsVectorPlainToTsQuery = exports.TsVectorColTsQuery = exports.WebsearchToTsQuery = exports.PhraseToTsQuery = exports.PlainToTsQuery = exports.TsQuery = exports.DBTypeIn = exports.TextIn = exports.IntegerIn = exports.UuidIn = exports.In = exports.OrOptional = exports.Or = exports.AndOptional = exports.And = exports.LessEq = exports.GreaterEq = exports.Less = exports.Greater = exports.NotEq = exports.Eq = exports.ArrayNotEq = exports.ArrayEq = exports.PostgresArrayNotOverlaps = exports.PostgresArrayOverlaps = exports.PostgresArrayNotContains = exports.PostgresArrayNotContainsValue = exports.PostgresArrayContains = exports.PostgresArrayContainsValue = exports.inClause = void 0;
26
+ exports.getCombinedClause = exports.Modulo = exports.Divide = exports.Multiply = exports.Subtract = exports.Add = exports.PaginationMultipleColsSubQuery = exports.JSONPathValuePredicate = exports.JSONObjectFieldKeyAsText = exports.JSONObjectFieldKeyASJSON = exports.sensitiveValue = exports.TsVectorWebsearchToTsQuery = exports.TsVectorPhraseToTsQuery = exports.TsVectorPlainToTsQuery = exports.TsVectorColTsQuery = exports.WebsearchToTsQuery = exports.PhraseToTsQuery = exports.PlainToTsQuery = exports.TsQuery = exports.DBTypeNotIn = exports.TextNotIn = exports.IntegerNotIn = exports.UuidNotIn = exports.DBTypeIn = exports.TextIn = exports.IntegerIn = exports.UuidIn = exports.In = exports.OrOptional = exports.Or = exports.AndOptional = exports.And = exports.LessEq = exports.GreaterEq = exports.Less = exports.Greater = exports.NotEq = exports.Eq = exports.ArrayNotEq = exports.ArrayEq = exports.PostgresArrayNotOverlaps = exports.PostgresArrayOverlaps = exports.PostgresArrayNotContains = exports.PostgresArrayNotContainsValue = exports.PostgresArrayContains = exports.PostgresArrayContainsValue = exports.notInClause = exports.inClause = void 0;
27
27
  const db_1 = __importStar(require("./db"));
28
28
  function isSensitive(val) {
29
29
  return (val !== null &&
@@ -236,11 +236,17 @@ class inClause {
236
236
  this.col = col;
237
237
  this.value = value;
238
238
  this.type = type;
239
+ this.op = "IN";
239
240
  }
240
241
  clause(idx) {
241
242
  // do a simple = when only one item
242
243
  if (this.value.length === 1) {
243
- return new simpleClause(this.col, this.value[0], "=").clause(idx);
244
+ if (this.op === "IN") {
245
+ return new simpleClause(this.col, this.value[0], "=").clause(idx);
246
+ }
247
+ else {
248
+ return new simpleClause(this.col, this.value[0], "!=").clause(idx);
249
+ }
244
250
  }
245
251
  const postgres = db_1.default.getDialect() === db_1.Dialect.Postgres;
246
252
  const postgresValuesList = postgres &&
@@ -272,7 +278,7 @@ class inClause {
272
278
  if (postgresValuesList) {
273
279
  inValue = `VALUES${inValue}`;
274
280
  }
275
- return `${this.col} IN (${inValue})`;
281
+ return `${this.col} ${this.op} (${inValue})`;
276
282
  // TODO we need to return idx at end to query builder...
277
283
  // or anything that's doing a composite query so next clause knows where to start
278
284
  // or change to a sqlx.Rebind format
@@ -296,10 +302,17 @@ class inClause {
296
302
  return result;
297
303
  }
298
304
  instanceKey() {
299
- return `in:${this.col}:${this.values().join(",")}`;
305
+ return `${this.op.toLowerCase()}:${this.col}:${this.values().join(",")}`;
300
306
  }
301
307
  }
302
308
  exports.inClause = inClause;
309
+ class notInClause extends inClause {
310
+ constructor() {
311
+ super(...arguments);
312
+ this.op = "NOT IN";
313
+ }
314
+ }
315
+ exports.notInClause = notInClause;
303
316
  class compositeClause {
304
317
  constructor(clauses, sep) {
305
318
  this.clauses = clauses;
@@ -570,6 +583,26 @@ function DBTypeIn(col, values, typ) {
570
583
  return new inClause(col, values, typ);
571
584
  }
572
585
  exports.DBTypeIn = DBTypeIn;
586
+ function UuidNotIn(col, values) {
587
+ return new notInClause(col, values, "uuid");
588
+ }
589
+ exports.UuidNotIn = UuidNotIn;
590
+ function IntegerNotIn(col, values) {
591
+ return new notInClause(col, values, "integer");
592
+ }
593
+ exports.IntegerNotIn = IntegerNotIn;
594
+ function TextNotIn(col, values) {
595
+ return new notInClause(col, values, "text");
596
+ }
597
+ exports.TextNotIn = TextNotIn;
598
+ /*
599
+ * if not uuid or text, pass the db type that can be used to cast this query
600
+ * if we end up with a large list of ids
601
+ */
602
+ function DBTypeNotIn(col, values, typ) {
603
+ return new notInClause(col, values, typ);
604
+ }
605
+ exports.DBTypeNotIn = DBTypeNotIn;
573
606
  // if string defaults to english
574
607
  // https://www.postgresql.org/docs/current/textsearch-controls.html#TEXTSEARCH-PARSING-QUERIES
575
608
  // to_tsquery
package/index.d.ts CHANGED
@@ -23,6 +23,10 @@ declare const query: {
23
23
  IntegerIn: typeof q.IntegerIn;
24
24
  TextIn: typeof q.TextIn;
25
25
  DBTypeIn: typeof q.DBTypeIn;
26
+ UuidNotIn: typeof q.UuidNotIn;
27
+ IntegerNotIn: typeof q.IntegerNotIn;
28
+ TextNotIn: typeof q.TextNotIn;
29
+ DBTypeNotIn: typeof q.DBTypeNotIn;
26
30
  Greater: typeof q.Greater;
27
31
  Less: typeof q.Less;
28
32
  GreaterEq: typeof q.GreaterEq;
package/index.js CHANGED
@@ -126,6 +126,10 @@ const query = {
126
126
  IntegerIn: q.IntegerIn,
127
127
  TextIn: q.TextIn,
128
128
  DBTypeIn: q.DBTypeIn,
129
+ UuidNotIn: q.UuidNotIn,
130
+ IntegerNotIn: q.IntegerNotIn,
131
+ TextNotIn: q.TextNotIn,
132
+ DBTypeNotIn: q.DBTypeNotIn,
129
133
  Greater: q.Greater,
130
134
  Less: q.Less,
131
135
  GreaterEq: q.GreaterEq,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@snowtop/ent",
3
- "version": "0.1.0-alpha155",
3
+ "version": "0.1.0-alpha157",
4
4
  "description": "snowtop ent framework",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",