@snowtop/ent 0.0.39-alpha7 → 0.0.39

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
@@ -45,5 +45,17 @@ export declare function And(...args: Clause[]): compositeClause;
45
45
  export declare function AndOptional(...args: (Clause | undefined)[]): Clause;
46
46
  export declare function Or(...args: Clause[]): compositeClause;
47
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;
56
+ export declare function TsVectorColTsQuery(col: string, val: string | TsQuery): Clause;
57
+ export declare function TsVectorPlainToTsQuery(col: string, val: string | TsQuery): Clause;
58
+ export declare function TsVectorPhraseToTsQuery(col: string, val: string | TsQuery): Clause;
59
+ export declare function TsVectorWebsearchToTsQuery(col: string, val: string | TsQuery): Clause;
48
60
  export declare function sensitiveValue(val: any): SensitiveValue;
49
61
  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 = exports.ArrayLessEq = exports.ArrayGreaterEq = exports.ArrayLess = exports.ArrayGreater = exports.ArrayNotEq = exports.ArrayEq = void 0;
22
+ exports.sensitiveValue = exports.TsVectorWebsearchToTsQuery = exports.TsVectorPhraseToTsQuery = exports.TsVectorPlainToTsQuery = exports.TsVectorColTsQuery = 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 &&
@@ -235,6 +235,69 @@ class compositeClause {
235
235
  return keys.join(this.sep);
236
236
  }
237
237
  }
238
+ class tsQueryClause {
239
+ constructor(col, val, tsVectorCol) {
240
+ this.col = col;
241
+ this.val = val;
242
+ this.tsVectorCol = tsVectorCol;
243
+ }
244
+ isTsQuery(val) {
245
+ return typeof val !== "string";
246
+ }
247
+ getInfo() {
248
+ if (this.isTsQuery(this.val)) {
249
+ return { value: this.val.value, language: this.val.language };
250
+ }
251
+ return {
252
+ language: "english",
253
+ value: this.val,
254
+ };
255
+ }
256
+ clause(idx) {
257
+ const { language } = this.getInfo();
258
+ if (db_1.Dialect.Postgres === db_1.default.getDialect()) {
259
+ if (this.tsVectorCol) {
260
+ return `to_tsvector(${this.col}) @@ ${this.getFunction()}('${language}', $${idx})`;
261
+ }
262
+ return `${this.col} @@ ${this.getFunction()}('${language}', $${idx})`;
263
+ }
264
+ // FYI this doesn't actually work for sqlite since different
265
+ return `${this.col} @@ ${this.getFunction()}('${language}', ?)`;
266
+ }
267
+ values() {
268
+ const { value } = this.getInfo();
269
+ return [value];
270
+ }
271
+ logValues() {
272
+ const { value } = this.getInfo();
273
+ return [value];
274
+ }
275
+ getFunction() {
276
+ return "to_tsquery";
277
+ }
278
+ instanceKey() {
279
+ const { language, value } = this.getInfo();
280
+ if (this.tsVectorCol) {
281
+ return `to_tsvector(${this.col})@@${this.getFunction()}:${language}:${value}`;
282
+ }
283
+ return `${this.col}@@${this.getFunction()}:${language}:${value}`;
284
+ }
285
+ }
286
+ class plainToTsQueryClause extends tsQueryClause {
287
+ getFunction() {
288
+ return "plainto_tsquery";
289
+ }
290
+ }
291
+ class phraseToTsQueryClause extends tsQueryClause {
292
+ getFunction() {
293
+ return "phraseto_tsquery";
294
+ }
295
+ }
296
+ class websearchTosQueryClause extends tsQueryClause {
297
+ getFunction() {
298
+ return "websearch_to_tsquery";
299
+ }
300
+ }
238
301
  // TODO we need to check sqlite version...
239
302
  function ArrayEq(col, value) {
240
303
  return new arraySimpleClause(col, value, "=");
@@ -306,6 +369,60 @@ function In(col, ...values) {
306
369
  return new inClause(col, values);
307
370
  }
308
371
  exports.In = In;
372
+ // if string defaults to english
373
+ // https://www.postgresql.org/docs/current/textsearch-controls.html#TEXTSEARCH-PARSING-QUERIES
374
+ // to_tsquery
375
+ // plainto_tsquery
376
+ // phraseto_tsquery;
377
+ // websearch_to_tsquery
378
+ function TsQuery(col, val) {
379
+ return new tsQueryClause(col, val);
380
+ }
381
+ exports.TsQuery = TsQuery;
382
+ function PlainToTsQuery(col, val) {
383
+ return new plainToTsQueryClause(col, val);
384
+ }
385
+ exports.PlainToTsQuery = PlainToTsQuery;
386
+ function PhraseToTsQuery(col, val) {
387
+ return new phraseToTsQueryClause(col, val);
388
+ }
389
+ exports.PhraseToTsQuery = PhraseToTsQuery;
390
+ function WebsearchToTsQuery(col, val) {
391
+ return new websearchTosQueryClause(col, val);
392
+ }
393
+ exports.WebsearchToTsQuery = WebsearchToTsQuery;
394
+ // TsVectorColTsQuery is used when the column is not a tsvector field e.g.
395
+ // when there's an index just on the field and is not a combination of multiple fields
396
+ function TsVectorColTsQuery(col, val) {
397
+ return new tsQueryClause(col, val, true);
398
+ }
399
+ exports.TsVectorColTsQuery = TsVectorColTsQuery;
400
+ // TsVectorPlainToTsQuery is used when the column is not a tsvector field e.g.
401
+ // when there's an index just on the field and is not a combination of multiple fields
402
+ // TODO do these 4 need TsQuery because would be nice to have language?
403
+ // it seems to default to the config of the column
404
+ function TsVectorPlainToTsQuery(col, val) {
405
+ return new plainToTsQueryClause(col, val, true);
406
+ }
407
+ exports.TsVectorPlainToTsQuery = TsVectorPlainToTsQuery;
408
+ // TsVectorPhraseToTsQuery is used when the column is not a tsvector field e.g.
409
+ // when there's an index just on the field and is not a combination of multiple fields
410
+ function TsVectorPhraseToTsQuery(col, val) {
411
+ return new phraseToTsQueryClause(col, val, true);
412
+ }
413
+ exports.TsVectorPhraseToTsQuery = TsVectorPhraseToTsQuery;
414
+ // TsVectorWebsearchToTsQuery is used when the column is not a tsvector field e.g.
415
+ // when there's an index just on the field and is not a combination of multiple fields
416
+ function TsVectorWebsearchToTsQuery(col, val) {
417
+ return new websearchTosQueryClause(col, val, true);
418
+ }
419
+ exports.TsVectorWebsearchToTsQuery = TsVectorWebsearchToTsQuery;
420
+ // TODO would be nice to support this with building blocks but not supporting for now
421
+ // AND: foo & bar,
422
+ // OR: foo | bar
423
+ // followed by: foo <-> bar
424
+ // NOT: !foo
425
+ // starts_with: theo:*
309
426
  // wrap a query in the db with this to ensure that it doesn't show up in the logs
310
427
  // e.g. if querying for password, SSN, etc
311
428
  // we'll pass the right fields to query and log something along the lines of `****`
package/core/config.d.ts CHANGED
@@ -28,6 +28,8 @@ interface CodegenConfig {
28
28
  generateRootResolvers?: boolean;
29
29
  defaultGraphQLMutationName?: graphqlMutationName;
30
30
  defaultGraphQLFieldFormat?: graphQLFieldFormat;
31
+ schemaSQLFilePath?: boolean;
32
+ databaseToCompareTo?: string;
31
33
  }
32
34
  interface PrettierConfig {
33
35
  custom?: boolean;
package/index.d.ts CHANGED
@@ -24,6 +24,14 @@ declare const query: {
24
24
  ArrayLess: typeof q.ArrayLess;
25
25
  ArrayGreaterEq: typeof q.ArrayGreaterEq;
26
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;
31
+ TsVectorColTsQuery: typeof q.TsVectorColTsQuery;
32
+ TsVectorPlainToTsQuery: typeof q.TsVectorPlainToTsQuery;
33
+ TsVectorPhraseToTsQuery: typeof q.TsVectorPhraseToTsQuery;
34
+ TsVectorWebsearchToTsQuery: typeof q.TsVectorWebsearchToTsQuery;
27
35
  };
28
36
  export { query };
29
37
  export { RequestContext, ContextCache } from "./core/context";
package/index.js CHANGED
@@ -122,6 +122,14 @@ const query = {
122
122
  ArrayLess: q.ArrayLess,
123
123
  ArrayGreaterEq: q.ArrayGreaterEq,
124
124
  ArrayLessEq: q.ArrayLessEq,
125
+ TsQuery: q.TsQuery,
126
+ PlainToTsQuery: q.PlainToTsQuery,
127
+ PhraseToTsQuery: q.PhraseToTsQuery,
128
+ WebsearchToTsQuery: q.WebsearchToTsQuery,
129
+ TsVectorColTsQuery: q.TsVectorColTsQuery,
130
+ TsVectorPlainToTsQuery: q.TsVectorPlainToTsQuery,
131
+ TsVectorPhraseToTsQuery: q.TsVectorPhraseToTsQuery,
132
+ TsVectorWebsearchToTsQuery: q.TsVectorWebsearchToTsQuery,
125
133
  };
126
134
  exports.query = query;
127
135
  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-alpha7",
3
+ "version": "0.0.39",
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;