@snowtop/ent 0.0.39-alpha7 → 0.0.39-alpha8
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 +8 -0
- package/core/clause.js +81 -1
- package/core/config.d.ts +1 -0
- package/package.json +1 -1
- package/schema/schema.d.ts +8 -0
package/core/clause.d.ts
CHANGED
|
@@ -45,5 +45,13 @@ 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;
|
|
48
56
|
export declare function sensitiveValue(val: any): SensitiveValue;
|
|
49
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 = exports.ArrayLessEq = exports.ArrayGreaterEq = exports.ArrayLess = exports.ArrayGreater = exports.ArrayNotEq = exports.ArrayEq = 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 &&
|
|
@@ -235,6 +235,58 @@ class compositeClause {
|
|
|
235
235
|
return keys.join(this.sep);
|
|
236
236
|
}
|
|
237
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, value } = this.getInfo();
|
|
257
|
+
return `${this.col} @@ ${this.getFunction()}('${language}', '${value}')`;
|
|
258
|
+
}
|
|
259
|
+
values() {
|
|
260
|
+
const { value } = this.getInfo();
|
|
261
|
+
return [value];
|
|
262
|
+
}
|
|
263
|
+
logValues() {
|
|
264
|
+
const { value } = this.getInfo();
|
|
265
|
+
return [value];
|
|
266
|
+
}
|
|
267
|
+
getFunction() {
|
|
268
|
+
return "to_tsquery";
|
|
269
|
+
}
|
|
270
|
+
instanceKey() {
|
|
271
|
+
const { language, value } = this.getInfo();
|
|
272
|
+
return `${this.col} @@${this.getFunction()}:${language}:${value}`;
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
class plainToTsQueryClause extends tsQueryClause {
|
|
276
|
+
getFunction() {
|
|
277
|
+
return "plainto_tsquery";
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
class phraseToTsQueryClause extends tsQueryClause {
|
|
281
|
+
getFunction() {
|
|
282
|
+
return "phraseto_tsquery";
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
class websearchTosQueryClause extends tsQueryClause {
|
|
286
|
+
getFunction() {
|
|
287
|
+
return "websearch_to_tsquery";
|
|
288
|
+
}
|
|
289
|
+
}
|
|
238
290
|
// TODO we need to check sqlite version...
|
|
239
291
|
function ArrayEq(col, value) {
|
|
240
292
|
return new arraySimpleClause(col, value, "=");
|
|
@@ -306,6 +358,34 @@ function In(col, ...values) {
|
|
|
306
358
|
return new inClause(col, values);
|
|
307
359
|
}
|
|
308
360
|
exports.In = In;
|
|
361
|
+
// if string defaults to english
|
|
362
|
+
// https://www.postgresql.org/docs/current/textsearch-controls.html#TEXTSEARCH-PARSING-QUERIES
|
|
363
|
+
// to_tsquery
|
|
364
|
+
// plainto_tsquery
|
|
365
|
+
// phraseto_tsquery;
|
|
366
|
+
// websearch_to_tsquery
|
|
367
|
+
function TsQuery(col, val) {
|
|
368
|
+
return new tsQueryClause(col, val);
|
|
369
|
+
}
|
|
370
|
+
exports.TsQuery = TsQuery;
|
|
371
|
+
function PlainToTsQuery(col, val) {
|
|
372
|
+
return new plainToTsQueryClause(col, val);
|
|
373
|
+
}
|
|
374
|
+
exports.PlainToTsQuery = PlainToTsQuery;
|
|
375
|
+
function PhraseToTsQuery(col, val) {
|
|
376
|
+
return new phraseToTsQueryClause(col, val);
|
|
377
|
+
}
|
|
378
|
+
exports.PhraseToTsQuery = PhraseToTsQuery;
|
|
379
|
+
function WebsearchToTsQuery(col, val) {
|
|
380
|
+
return new websearchTosQueryClause(col, val);
|
|
381
|
+
}
|
|
382
|
+
exports.WebsearchToTsQuery = WebsearchToTsQuery;
|
|
383
|
+
// TODO would be nice to support this with building blocks but not supporting for now
|
|
384
|
+
// AND: foo & bar,
|
|
385
|
+
// OR: foo | bar
|
|
386
|
+
// followed by: foo <-> bar
|
|
387
|
+
// NOT: !foo
|
|
388
|
+
// starts_with: theo:*
|
|
309
389
|
// wrap a query in the db with this to ensure that it doesn't show up in the logs
|
|
310
390
|
// e.g. if querying for password, SSN, etc
|
|
311
391
|
// we'll pass the right fields to query and log something along the lines of `****`
|
package/core/config.d.ts
CHANGED
package/package.json
CHANGED
package/schema/schema.d.ts
CHANGED
|
@@ -223,10 +223,18 @@ export interface Constraint {
|
|
|
223
223
|
fkey?: ForeignKeyInfo;
|
|
224
224
|
condition?: string;
|
|
225
225
|
}
|
|
226
|
+
export interface FullText {
|
|
227
|
+
generatedColumnName?: string;
|
|
228
|
+
language?: "english" | "french" | "german" | "simple";
|
|
229
|
+
languageColumn?: string;
|
|
230
|
+
indexType?: "gin" | "gist";
|
|
231
|
+
weights?: string[];
|
|
232
|
+
}
|
|
226
233
|
export interface Index {
|
|
227
234
|
name: string;
|
|
228
235
|
columns: string[];
|
|
229
236
|
unique?: boolean;
|
|
237
|
+
fulltext?: FullText;
|
|
230
238
|
}
|
|
231
239
|
export interface ForeignKeyInfo {
|
|
232
240
|
tableName: string;
|