@snowtop/ent 0.0.39-alpha6 → 0.0.39-alpha9

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
@@ -29,6 +29,12 @@ declare class compositeClause implements Clause {
29
29
  logValues(): any[];
30
30
  instanceKey(): string;
31
31
  }
32
+ export declare function ArrayEq(col: string, value: any): Clause;
33
+ export declare function ArrayNotEq(col: string, value: any): Clause;
34
+ export declare function ArrayGreater(col: string, value: any): Clause;
35
+ export declare function ArrayLess(col: string, value: any): Clause;
36
+ export declare function ArrayGreaterEq(col: string, value: any): Clause;
37
+ export declare function ArrayLessEq(col: string, value: any): Clause;
32
38
  export declare function Eq(col: string, value: any): Clause;
33
39
  export declare function NotEq(col: string, value: any): Clause;
34
40
  export declare function Greater(col: string, value: any): simpleClause;
@@ -39,5 +45,13 @@ export declare function And(...args: Clause[]): compositeClause;
39
45
  export declare function AndOptional(...args: (Clause | undefined)[]): Clause;
40
46
  export declare function Or(...args: Clause[]): compositeClause;
41
47
  export declare function In(col: string, ...values: any): Clause;
48
+ interface TsQuery {
49
+ language: "english" | "french" | "german" | "simple";
50
+ value: string;
51
+ }
52
+ export declare function TsQuery(col: string, val: string | TsQuery): Clause;
53
+ export declare function PlainToTsQuery(col: string, val: string | TsQuery): Clause;
54
+ export declare function PhraseToTsQuery(col: string, val: string | TsQuery): Clause;
55
+ export declare function WebsearchToTsQuery(col: string, val: string | TsQuery): Clause;
42
56
  export declare function sensitiveValue(val: any): SensitiveValue;
43
57
  export {};
package/core/clause.js CHANGED
@@ -19,7 +19,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
19
19
  return result;
20
20
  };
21
21
  Object.defineProperty(exports, "__esModule", { value: true });
22
- exports.sensitiveValue = exports.In = exports.Or = exports.AndOptional = exports.And = exports.LessEq = exports.GreaterEq = exports.Less = exports.Greater = exports.NotEq = exports.Eq = void 0;
22
+ exports.sensitiveValue = exports.WebsearchToTsQuery = exports.PhraseToTsQuery = exports.PlainToTsQuery = exports.TsQuery = exports.In = exports.Or = exports.AndOptional = exports.And = exports.LessEq = exports.GreaterEq = exports.Less = exports.Greater = exports.NotEq = exports.Eq = exports.ArrayLessEq = exports.ArrayGreaterEq = exports.ArrayLess = exports.ArrayGreater = exports.ArrayNotEq = exports.ArrayEq = void 0;
23
23
  const db_1 = __importStar(require("./db"));
24
24
  function isSensitive(val) {
25
25
  return (val !== null &&
@@ -120,6 +120,34 @@ class isNotNullClause {
120
120
  return `${this.col} IS NOT NULL`;
121
121
  }
122
122
  }
123
+ class arraySimpleClause {
124
+ constructor(col, value, op) {
125
+ this.col = col;
126
+ this.value = value;
127
+ this.op = op;
128
+ }
129
+ clause(idx) {
130
+ if (db_1.default.getDialect() === db_1.Dialect.Postgres) {
131
+ return `$${idx} ${this.op} ANY(${this.col})`;
132
+ }
133
+ return `${this.col} ${this.op} ?`;
134
+ }
135
+ values() {
136
+ if (isSensitive(this.value)) {
137
+ return [this.value.value()];
138
+ }
139
+ return [this.value];
140
+ }
141
+ logValues() {
142
+ if (isSensitive(this.value)) {
143
+ return [this.value.logValue()];
144
+ }
145
+ return [this.value];
146
+ }
147
+ instanceKey() {
148
+ return `${this.col}${this.op}${rawValue(this.value)}`;
149
+ }
150
+ }
123
151
  class inClause {
124
152
  constructor(col, value) {
125
153
  this.col = col;
@@ -207,6 +235,86 @@ class compositeClause {
207
235
  return keys.join(this.sep);
208
236
  }
209
237
  }
238
+ class tsQueryClause {
239
+ constructor(col, val) {
240
+ this.col = col;
241
+ this.val = val;
242
+ }
243
+ isTsQuery(val) {
244
+ return typeof val !== "string";
245
+ }
246
+ getInfo() {
247
+ if (this.isTsQuery(this.val)) {
248
+ return { value: this.val.value, language: this.val.language };
249
+ }
250
+ return {
251
+ language: "english",
252
+ value: this.val,
253
+ };
254
+ }
255
+ clause(idx) {
256
+ const { language } = this.getInfo();
257
+ if (db_1.Dialect.Postgres === db_1.default.getDialect()) {
258
+ return `${this.col} @@ ${this.getFunction()}('${language}', $${idx})`;
259
+ }
260
+ return `${this.col} @@ ${this.getFunction()}('${language}', ?)`;
261
+ }
262
+ values() {
263
+ const { value } = this.getInfo();
264
+ return [value];
265
+ }
266
+ logValues() {
267
+ const { value } = this.getInfo();
268
+ return [value];
269
+ }
270
+ getFunction() {
271
+ return "to_tsquery";
272
+ }
273
+ instanceKey() {
274
+ const { language, value } = this.getInfo();
275
+ return `${this.col} @@${this.getFunction()}:${language}:${value}`;
276
+ }
277
+ }
278
+ class plainToTsQueryClause extends tsQueryClause {
279
+ getFunction() {
280
+ return "plainto_tsquery";
281
+ }
282
+ }
283
+ class phraseToTsQueryClause extends tsQueryClause {
284
+ getFunction() {
285
+ return "phraseto_tsquery";
286
+ }
287
+ }
288
+ class websearchTosQueryClause extends tsQueryClause {
289
+ getFunction() {
290
+ return "websearch_to_tsquery";
291
+ }
292
+ }
293
+ // TODO we need to check sqlite version...
294
+ function ArrayEq(col, value) {
295
+ return new arraySimpleClause(col, value, "=");
296
+ }
297
+ exports.ArrayEq = ArrayEq;
298
+ function ArrayNotEq(col, value) {
299
+ return new arraySimpleClause(col, value, "!=");
300
+ }
301
+ exports.ArrayNotEq = ArrayNotEq;
302
+ function ArrayGreater(col, value) {
303
+ return new arraySimpleClause(col, value, ">");
304
+ }
305
+ exports.ArrayGreater = ArrayGreater;
306
+ function ArrayLess(col, value) {
307
+ return new arraySimpleClause(col, value, "<");
308
+ }
309
+ exports.ArrayLess = ArrayLess;
310
+ function ArrayGreaterEq(col, value) {
311
+ return new arraySimpleClause(col, value, ">=");
312
+ }
313
+ exports.ArrayGreaterEq = ArrayGreaterEq;
314
+ function ArrayLessEq(col, value) {
315
+ return new arraySimpleClause(col, value, "<=");
316
+ }
317
+ exports.ArrayLessEq = ArrayLessEq;
210
318
  function Eq(col, value) {
211
319
  return new simpleClause(col, value, "=", new isNullClause(col));
212
320
  }
@@ -253,6 +361,34 @@ function In(col, ...values) {
253
361
  return new inClause(col, values);
254
362
  }
255
363
  exports.In = In;
364
+ // if string defaults to english
365
+ // https://www.postgresql.org/docs/current/textsearch-controls.html#TEXTSEARCH-PARSING-QUERIES
366
+ // to_tsquery
367
+ // plainto_tsquery
368
+ // phraseto_tsquery;
369
+ // websearch_to_tsquery
370
+ function TsQuery(col, val) {
371
+ return new tsQueryClause(col, val);
372
+ }
373
+ exports.TsQuery = TsQuery;
374
+ function PlainToTsQuery(col, val) {
375
+ return new plainToTsQueryClause(col, val);
376
+ }
377
+ exports.PlainToTsQuery = PlainToTsQuery;
378
+ function PhraseToTsQuery(col, val) {
379
+ return new phraseToTsQueryClause(col, val);
380
+ }
381
+ exports.PhraseToTsQuery = PhraseToTsQuery;
382
+ function WebsearchToTsQuery(col, val) {
383
+ return new websearchTosQueryClause(col, val);
384
+ }
385
+ exports.WebsearchToTsQuery = WebsearchToTsQuery;
386
+ // TODO would be nice to support this with building blocks but not supporting for now
387
+ // AND: foo & bar,
388
+ // OR: foo | bar
389
+ // followed by: foo <-> bar
390
+ // NOT: !foo
391
+ // starts_with: theo:*
256
392
  // wrap a query in the db with this to ensure that it doesn't show up in the logs
257
393
  // e.g. if querying for password, SSN, etc
258
394
  // we'll pass the right fields to query and log something along the lines of `****`
package/core/config.d.ts CHANGED
@@ -28,6 +28,7 @@ interface CodegenConfig {
28
28
  generateRootResolvers?: boolean;
29
29
  defaultGraphQLMutationName?: graphqlMutationName;
30
30
  defaultGraphQLFieldFormat?: graphQLFieldFormat;
31
+ schemaSQLFilePath?: boolean;
31
32
  }
32
33
  interface PrettierConfig {
33
34
  custom?: boolean;
package/index.d.ts CHANGED
@@ -18,6 +18,16 @@ declare const query: {
18
18
  Less: typeof q.Less;
19
19
  GreaterEq: typeof q.GreaterEq;
20
20
  LessEq: typeof q.LessEq;
21
+ ArrayEq: typeof q.ArrayEq;
22
+ ArrayNotEq: typeof q.ArrayNotEq;
23
+ ArrayGreater: typeof q.ArrayGreater;
24
+ ArrayLess: typeof q.ArrayLess;
25
+ ArrayGreaterEq: typeof q.ArrayGreaterEq;
26
+ ArrayLessEq: typeof q.ArrayLessEq;
27
+ TsQuery: typeof q.TsQuery;
28
+ PlainToTsQuery: typeof q.PlainToTsQuery;
29
+ PhraseToTsQuery: typeof q.PhraseToTsQuery;
30
+ WebsearchToTsQuery: typeof q.WebsearchToTsQuery;
21
31
  };
22
32
  export { query };
23
33
  export { RequestContext, ContextCache } from "./core/context";
package/index.js CHANGED
@@ -116,6 +116,16 @@ const query = {
116
116
  Less: q.Less,
117
117
  GreaterEq: q.GreaterEq,
118
118
  LessEq: q.LessEq,
119
+ ArrayEq: q.ArrayEq,
120
+ ArrayNotEq: q.ArrayNotEq,
121
+ ArrayGreater: q.ArrayGreater,
122
+ ArrayLess: q.ArrayLess,
123
+ ArrayGreaterEq: q.ArrayGreaterEq,
124
+ ArrayLessEq: q.ArrayLessEq,
125
+ TsQuery: q.TsQuery,
126
+ PlainToTsQuery: q.PlainToTsQuery,
127
+ PhraseToTsQuery: q.PhraseToTsQuery,
128
+ WebsearchToTsQuery: q.WebsearchToTsQuery,
119
129
  };
120
130
  exports.query = query;
121
131
  var context_1 = require("./core/context");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@snowtop/ent",
3
- "version": "0.0.39-alpha6",
3
+ "version": "0.0.39-alpha9",
4
4
  "description": "snowtop ent framework",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
@@ -223,10 +223,24 @@ export interface Constraint {
223
223
  fkey?: ForeignKeyInfo;
224
224
  condition?: string;
225
225
  }
226
+ export interface FullTextWeight {
227
+ A?: string[];
228
+ B?: string[];
229
+ C?: string[];
230
+ D?: string[];
231
+ }
232
+ export interface FullText {
233
+ generatedColumnName?: string;
234
+ language?: "english" | "french" | "german" | "simple";
235
+ languageColumn?: string;
236
+ indexType?: "gin" | "gist";
237
+ weights?: FullTextWeight;
238
+ }
226
239
  export interface Index {
227
240
  name: string;
228
241
  columns: string[];
229
242
  unique?: boolean;
243
+ fulltext?: FullText;
230
244
  }
231
245
  export interface ForeignKeyInfo {
232
246
  tableName: string;