@snowtop/ent 0.0.39-alpha4 → 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/action/action.d.ts +1 -1
- package/core/clause.d.ts +15 -0
- package/core/clause.js +145 -4
- package/core/config.d.ts +1 -0
- package/core/ent.js +2 -48
- package/core/loaders/index_loader.js +1 -0
- package/index.d.ts +7 -0
- package/index.js +7 -0
- package/package.json +1 -1
- package/schema/schema.d.ts +8 -0
package/action/action.d.ts
CHANGED
|
@@ -51,7 +51,7 @@ export interface Action<T extends Ent> {
|
|
|
51
51
|
observers?: Observer<T>[];
|
|
52
52
|
validators?: Validator<T>[];
|
|
53
53
|
getInput(): Data;
|
|
54
|
-
transformWrite?: (stmt: UpdateOperation<
|
|
54
|
+
transformWrite?: <T2 extends Ent>(stmt: UpdateOperation<T2>) => Promise<TransformedUpdateOperation<T2>> | TransformedUpdateOperation<T2> | undefined;
|
|
55
55
|
valid(): Promise<boolean>;
|
|
56
56
|
validX(): Promise<void>;
|
|
57
57
|
viewerForEntLoad?(data: Data): Viewer | Promise<Viewer>;
|
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;
|
|
@@ -36,7 +42,16 @@ export declare function Less(col: string, value: any): simpleClause;
|
|
|
36
42
|
export declare function GreaterEq(col: string, value: any): simpleClause;
|
|
37
43
|
export declare function LessEq(col: string, value: any): simpleClause;
|
|
38
44
|
export declare function And(...args: Clause[]): compositeClause;
|
|
45
|
+
export declare function AndOptional(...args: (Clause | undefined)[]): Clause;
|
|
39
46
|
export declare function Or(...args: Clause[]): compositeClause;
|
|
40
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;
|
|
41
56
|
export declare function sensitiveValue(val: any): SensitiveValue;
|
|
42
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.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 &&
|
|
@@ -50,11 +50,10 @@ class simpleClause {
|
|
|
50
50
|
return `${this.col} ${this.op} ?`;
|
|
51
51
|
}
|
|
52
52
|
sqliteNull() {
|
|
53
|
-
if (!this.handleSqliteNull) {
|
|
53
|
+
if (!this.handleSqliteNull || this.value !== null) {
|
|
54
54
|
return;
|
|
55
55
|
}
|
|
56
|
-
|
|
57
|
-
if (this.value !== null || dialect !== db_1.Dialect.SQLite) {
|
|
56
|
+
if (db_1.default.getDialect() !== db_1.Dialect.SQLite) {
|
|
58
57
|
return;
|
|
59
58
|
}
|
|
60
59
|
return this.handleSqliteNull;
|
|
@@ -121,6 +120,34 @@ class isNotNullClause {
|
|
|
121
120
|
return `${this.col} IS NOT NULL`;
|
|
122
121
|
}
|
|
123
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
|
+
}
|
|
124
151
|
class inClause {
|
|
125
152
|
constructor(col, value) {
|
|
126
153
|
this.col = col;
|
|
@@ -208,6 +235,83 @@ class compositeClause {
|
|
|
208
235
|
return keys.join(this.sep);
|
|
209
236
|
}
|
|
210
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
|
+
}
|
|
290
|
+
// TODO we need to check sqlite version...
|
|
291
|
+
function ArrayEq(col, value) {
|
|
292
|
+
return new arraySimpleClause(col, value, "=");
|
|
293
|
+
}
|
|
294
|
+
exports.ArrayEq = ArrayEq;
|
|
295
|
+
function ArrayNotEq(col, value) {
|
|
296
|
+
return new arraySimpleClause(col, value, "!=");
|
|
297
|
+
}
|
|
298
|
+
exports.ArrayNotEq = ArrayNotEq;
|
|
299
|
+
function ArrayGreater(col, value) {
|
|
300
|
+
return new arraySimpleClause(col, value, ">");
|
|
301
|
+
}
|
|
302
|
+
exports.ArrayGreater = ArrayGreater;
|
|
303
|
+
function ArrayLess(col, value) {
|
|
304
|
+
return new arraySimpleClause(col, value, "<");
|
|
305
|
+
}
|
|
306
|
+
exports.ArrayLess = ArrayLess;
|
|
307
|
+
function ArrayGreaterEq(col, value) {
|
|
308
|
+
return new arraySimpleClause(col, value, ">=");
|
|
309
|
+
}
|
|
310
|
+
exports.ArrayGreaterEq = ArrayGreaterEq;
|
|
311
|
+
function ArrayLessEq(col, value) {
|
|
312
|
+
return new arraySimpleClause(col, value, "<=");
|
|
313
|
+
}
|
|
314
|
+
exports.ArrayLessEq = ArrayLessEq;
|
|
211
315
|
function Eq(col, value) {
|
|
212
316
|
return new simpleClause(col, value, "=", new isNullClause(col));
|
|
213
317
|
}
|
|
@@ -236,6 +340,15 @@ function And(...args) {
|
|
|
236
340
|
return new compositeClause(args, " AND ");
|
|
237
341
|
}
|
|
238
342
|
exports.And = And;
|
|
343
|
+
function AndOptional(...args) {
|
|
344
|
+
// @ts-ignore
|
|
345
|
+
let filtered = args.filter((v) => v !== undefined);
|
|
346
|
+
if (filtered.length === 1) {
|
|
347
|
+
return filtered[0];
|
|
348
|
+
}
|
|
349
|
+
return And(...filtered);
|
|
350
|
+
}
|
|
351
|
+
exports.AndOptional = AndOptional;
|
|
239
352
|
function Or(...args) {
|
|
240
353
|
return new compositeClause(args, " OR ");
|
|
241
354
|
}
|
|
@@ -245,6 +358,34 @@ function In(col, ...values) {
|
|
|
245
358
|
return new inClause(col, values);
|
|
246
359
|
}
|
|
247
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:*
|
|
248
389
|
// wrap a query in the db with this to ensure that it doesn't show up in the logs
|
|
249
390
|
// e.g. if querying for password, SSN, etc
|
|
250
391
|
// we'll pass the right fields to query and log something along the lines of `****`
|
package/core/config.d.ts
CHANGED
package/core/ent.js
CHANGED
|
@@ -84,54 +84,8 @@ function createDataLoader(options) {
|
|
|
84
84
|
return result;
|
|
85
85
|
}, loaderOptions);
|
|
86
86
|
}
|
|
87
|
-
// TODO probably delete since we're going to generate it now
|
|
88
|
-
// instead of passing this here.
|
|
89
|
-
// async function doPerformQuery<T extends Ent>(
|
|
90
|
-
// viewer: Viewer,
|
|
91
|
-
// id: ID,
|
|
92
|
-
// options: LoadEntOptions<T>,
|
|
93
|
-
// ): Promise<Data | null> {
|
|
94
|
-
// let newClause: clause.Clause | undefined = undefined;
|
|
95
|
-
// if (options.schema) {
|
|
96
|
-
// const schema = getSchema(options.schema);
|
|
97
|
-
// if (schema.patterns) {
|
|
98
|
-
// for (const p of schema.patterns) {
|
|
99
|
-
// if (p.transformRead) {
|
|
100
|
-
// newClause = p.transformRead({
|
|
101
|
-
// op: QueryOperation.Select,
|
|
102
|
-
// clause: clause.Eq("id", id),
|
|
103
|
-
// });
|
|
104
|
-
// }
|
|
105
|
-
// }
|
|
106
|
-
// }
|
|
107
|
-
// }
|
|
108
|
-
// // we want a loader if possible . we don't want this to slow
|
|
109
|
-
// // things down...
|
|
110
|
-
// // id = x and deleted_at == null
|
|
111
|
-
// if (newClause) {
|
|
112
|
-
// // loader
|
|
113
|
-
// // return loadRow({});
|
|
114
|
-
// // TODO
|
|
115
|
-
// }
|
|
116
|
-
// // we want a deleted_at loader...
|
|
117
|
-
// return options.loaderFactory.createLoader(viewer.context).load(id);
|
|
118
|
-
// }
|
|
119
87
|
// Ent accessors
|
|
120
88
|
async function loadEnt(viewer, id, options) {
|
|
121
|
-
let newClause;
|
|
122
|
-
// if (options.schema) {
|
|
123
|
-
// const schema = getSchema(options.schema);
|
|
124
|
-
// if (schema.patterns) {
|
|
125
|
-
// for (const p of schema.patterns) {
|
|
126
|
-
// if (p.transformRead) {
|
|
127
|
-
// newClause = p.transformRead({
|
|
128
|
-
// op: QueryOperation.Select,
|
|
129
|
-
// clause: clause.Eq("id", id),
|
|
130
|
-
// });
|
|
131
|
-
// }
|
|
132
|
-
// }
|
|
133
|
-
// }
|
|
134
|
-
// }
|
|
135
89
|
const row = await options.loaderFactory.createLoader(viewer.context).load(id);
|
|
136
90
|
return await applyPrivacyPolicyForRow(viewer, options, row);
|
|
137
91
|
}
|
|
@@ -480,7 +434,7 @@ class EditNodeOperation {
|
|
|
480
434
|
};
|
|
481
435
|
if (this.existingEnt) {
|
|
482
436
|
if (this.hasData(options.fields)) {
|
|
483
|
-
// even this with returning *
|
|
437
|
+
// even this with returning * may not always work if transformed...
|
|
484
438
|
// we can have a transformed flag to see if it should be returned?
|
|
485
439
|
this.row = await editRow(queryer, options, this.existingEnt.id, "RETURNING *");
|
|
486
440
|
}
|
|
@@ -493,7 +447,7 @@ class EditNodeOperation {
|
|
|
493
447
|
}
|
|
494
448
|
}
|
|
495
449
|
reloadRow(queryer, id, options) {
|
|
496
|
-
// TODO this isn'
|
|
450
|
+
// TODO this isn't always an ObjectLoader. should throw or figure out a way to get query
|
|
497
451
|
// and run this on its own...
|
|
498
452
|
const loader = this.options.loadEntOptions.loaderFactory.createLoader(options.context);
|
|
499
453
|
const opts = loader.getOptions();
|
|
@@ -4,6 +4,7 @@ exports.IndexLoaderFactory = void 0;
|
|
|
4
4
|
const query_loader_1 = require("./query_loader");
|
|
5
5
|
// we're keeping this for legacy reasons so as to not break existing callers
|
|
6
6
|
// and to decouple the change here but all callers can safely be changed here to use QueryLoaderFactory
|
|
7
|
+
// @deprecated use QueryLoaderFactory
|
|
7
8
|
class IndexLoaderFactory {
|
|
8
9
|
constructor(options, col, opts) {
|
|
9
10
|
this.factory = new query_loader_1.QueryLoaderFactory({
|
package/index.d.ts
CHANGED
|
@@ -11,12 +11,19 @@ declare const query: {
|
|
|
11
11
|
Eq: typeof q.Eq;
|
|
12
12
|
NotEq: typeof q.NotEq;
|
|
13
13
|
And: typeof q.And;
|
|
14
|
+
AndOptional: typeof q.AndOptional;
|
|
14
15
|
Or: typeof q.Or;
|
|
15
16
|
In: typeof q.In;
|
|
16
17
|
Greater: typeof q.Greater;
|
|
17
18
|
Less: typeof q.Less;
|
|
18
19
|
GreaterEq: typeof q.GreaterEq;
|
|
19
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;
|
|
20
27
|
};
|
|
21
28
|
export { query };
|
|
22
29
|
export { RequestContext, ContextCache } from "./core/context";
|
package/index.js
CHANGED
|
@@ -109,12 +109,19 @@ const query = {
|
|
|
109
109
|
Eq: q.Eq,
|
|
110
110
|
NotEq: q.NotEq,
|
|
111
111
|
And: q.And,
|
|
112
|
+
AndOptional: q.AndOptional,
|
|
112
113
|
Or: q.Or,
|
|
113
114
|
In: q.In,
|
|
114
115
|
Greater: q.Greater,
|
|
115
116
|
Less: q.Less,
|
|
116
117
|
GreaterEq: q.GreaterEq,
|
|
117
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,
|
|
118
125
|
};
|
|
119
126
|
exports.query = query;
|
|
120
127
|
var context_1 = require("./core/context");
|
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;
|