@snowtop/ent 0.1.0-alpha7 → 0.1.0-alpha73
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 +28 -24
- package/action/executor.d.ts +4 -4
- package/action/executor.js +2 -2
- package/action/experimental_action.d.ts +29 -22
- package/action/experimental_action.js +29 -6
- package/action/orchestrator.d.ts +44 -16
- package/action/orchestrator.js +287 -73
- package/action/privacy.d.ts +2 -2
- package/core/base.d.ts +35 -23
- package/core/base.js +16 -0
- package/core/clause.d.ts +69 -3
- package/core/clause.js +420 -5
- package/core/config.d.ts +26 -0
- package/core/config.js +17 -0
- package/core/context.d.ts +2 -2
- package/core/context.js +2 -2
- package/core/convert.d.ts +1 -1
- package/core/db.d.ts +3 -4
- package/core/db.js +2 -0
- package/core/ent.d.ts +62 -27
- package/core/ent.js +272 -63
- package/core/loaders/assoc_count_loader.d.ts +2 -2
- package/core/loaders/assoc_count_loader.js +6 -1
- package/core/loaders/assoc_edge_loader.d.ts +3 -3
- package/core/loaders/assoc_edge_loader.js +5 -4
- package/core/loaders/index_loader.js +1 -0
- package/core/loaders/loader.js +5 -5
- package/core/loaders/object_loader.d.ts +10 -5
- package/core/loaders/object_loader.js +58 -4
- package/core/loaders/query_loader.d.ts +2 -2
- package/core/loaders/raw_count_loader.d.ts +2 -2
- package/core/logger.d.ts +1 -1
- package/core/logger.js +1 -0
- package/core/privacy.d.ts +25 -25
- package/core/privacy.js +5 -5
- package/core/query/assoc_query.d.ts +6 -6
- package/core/query/custom_query.d.ts +5 -5
- package/core/query/query.d.ts +1 -1
- package/core/query/shared_assoc_test.d.ts +1 -1
- package/core/query/shared_assoc_test.js +17 -5
- package/core/query/shared_test.d.ts +3 -0
- package/core/query/shared_test.js +95 -17
- package/core/viewer.d.ts +4 -3
- package/core/viewer.js +4 -0
- package/graphql/builtins/connection.js +3 -3
- package/graphql/builtins/edge.js +2 -2
- package/graphql/builtins/node.js +1 -1
- package/graphql/graphql.d.ts +3 -2
- package/graphql/graphql.js +30 -23
- package/graphql/node_resolver.d.ts +0 -1
- package/graphql/query/connection_type.js +6 -6
- package/graphql/query/edge_connection.d.ts +9 -9
- package/graphql/query/page_info.d.ts +1 -1
- package/graphql/query/page_info.js +4 -4
- package/graphql/query/shared_assoc_test.js +2 -2
- package/graphql/scalars/time.d.ts +1 -1
- package/index.d.ts +21 -1
- package/index.js +24 -5
- package/package.json +3 -3
- package/parse_schema/parse.d.ts +24 -5
- package/parse_schema/parse.js +90 -8
- package/schema/base_schema.d.ts +36 -1
- package/schema/base_schema.js +51 -2
- package/schema/field.d.ts +34 -6
- package/schema/field.js +67 -2
- package/schema/index.d.ts +2 -2
- package/schema/index.js +8 -1
- package/schema/schema.d.ts +100 -2
- package/schema/schema.js +127 -5
- package/scripts/custom_graphql.js +127 -16
- package/scripts/{transform_schema.d.ts → migrate_v0.1.d.ts} +0 -0
- package/scripts/migrate_v0.1.js +36 -0
- package/scripts/read_schema.js +25 -2
- package/testutils/builder.d.ts +36 -22
- package/testutils/builder.js +110 -13
- package/testutils/context/test_context.d.ts +2 -2
- package/testutils/context/test_context.js +7 -1
- package/testutils/db/{test_db.d.ts → temp_db.d.ts} +17 -4
- package/testutils/db/{test_db.js → temp_db.js} +76 -19
- package/testutils/ent-graphql-tests/index.d.ts +2 -0
- package/testutils/ent-graphql-tests/index.js +26 -17
- package/testutils/fake_data/fake_contact.d.ts +5 -9
- package/testutils/fake_data/fake_contact.js +17 -21
- package/testutils/fake_data/fake_event.d.ts +5 -9
- package/testutils/fake_data/fake_event.js +24 -28
- package/testutils/fake_data/fake_user.d.ts +6 -10
- package/testutils/fake_data/fake_user.js +25 -29
- package/testutils/fake_data/test_helpers.d.ts +2 -2
- package/testutils/fake_data/test_helpers.js +6 -6
- package/testutils/fake_data/user_query.d.ts +2 -2
- package/testutils/fake_log.d.ts +3 -3
- package/testutils/parse_sql.d.ts +6 -0
- package/testutils/parse_sql.js +16 -2
- package/testutils/test_edge_global_schema.d.ts +15 -0
- package/testutils/test_edge_global_schema.js +58 -0
- package/testutils/write.d.ts +2 -2
- package/testutils/write.js +3 -3
- package/tsc/ast.d.ts +44 -0
- package/tsc/ast.js +267 -0
- package/tsc/compilerOptions.d.ts +6 -0
- package/tsc/compilerOptions.js +40 -1
- package/tsc/move_generated.d.ts +1 -0
- package/tsc/move_generated.js +160 -0
- package/tsc/transform.d.ts +21 -0
- package/tsc/transform.js +167 -0
- package/tsc/transform_action.d.ts +22 -0
- package/tsc/transform_action.js +179 -0
- package/tsc/transform_ent.d.ts +17 -0
- package/tsc/transform_ent.js +59 -0
- package/tsc/transform_schema.d.ts +27 -0
- package/tsc/transform_schema.js +379 -0
- package/scripts/transform_schema.js +0 -288
package/core/clause.js
CHANGED
|
@@ -19,10 +19,12 @@ 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.JSONPathValuePredicate = exports.JSONObjectFieldKeyAsText = exports.JSONObjectFieldKeyASJSON = 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.ArrayNotEq = exports.ArrayEq = exports.PostgresArrayNotOverlaps = exports.PostgresArrayOverlaps = exports.PostgresArrayNotContains = exports.PostgresArrayNotContainsValue = exports.PostgresArrayContains = exports.PostgresArrayContainsValue = void 0;
|
|
23
23
|
const db_1 = __importStar(require("./db"));
|
|
24
24
|
function isSensitive(val) {
|
|
25
|
-
return (
|
|
25
|
+
return (val !== null &&
|
|
26
|
+
typeof val === "object" &&
|
|
27
|
+
val.logValue !== undefined);
|
|
26
28
|
}
|
|
27
29
|
function rawValue(val) {
|
|
28
30
|
if (isSensitive(val)) {
|
|
@@ -31,33 +33,185 @@ function rawValue(val) {
|
|
|
31
33
|
return val;
|
|
32
34
|
}
|
|
33
35
|
class simpleClause {
|
|
34
|
-
constructor(col, value, op) {
|
|
36
|
+
constructor(col, value, op, handleNull) {
|
|
35
37
|
this.col = col;
|
|
36
38
|
this.value = value;
|
|
37
39
|
this.op = op;
|
|
40
|
+
this.handleNull = handleNull;
|
|
38
41
|
}
|
|
39
42
|
clause(idx) {
|
|
43
|
+
const nullClause = this.nullClause();
|
|
44
|
+
if (nullClause) {
|
|
45
|
+
return nullClause.clause(idx);
|
|
46
|
+
}
|
|
40
47
|
if (db_1.default.getDialect() === db_1.Dialect.Postgres) {
|
|
41
48
|
return `${this.col} ${this.op} $${idx}`;
|
|
42
49
|
}
|
|
43
50
|
return `${this.col} ${this.op} ?`;
|
|
44
51
|
}
|
|
52
|
+
nullClause() {
|
|
53
|
+
if (!this.handleNull || this.value !== null) {
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
return this.handleNull;
|
|
57
|
+
}
|
|
58
|
+
columns() {
|
|
59
|
+
return [this.col];
|
|
60
|
+
}
|
|
45
61
|
values() {
|
|
62
|
+
const sqliteClause = this.nullClause();
|
|
63
|
+
if (sqliteClause) {
|
|
64
|
+
return sqliteClause.values();
|
|
65
|
+
}
|
|
46
66
|
if (isSensitive(this.value)) {
|
|
47
67
|
return [this.value.value()];
|
|
48
68
|
}
|
|
49
69
|
return [this.value];
|
|
50
70
|
}
|
|
51
71
|
logValues() {
|
|
72
|
+
const sqliteClause = this.nullClause();
|
|
73
|
+
if (sqliteClause) {
|
|
74
|
+
return sqliteClause.logValues();
|
|
75
|
+
}
|
|
52
76
|
if (isSensitive(this.value)) {
|
|
53
77
|
return [this.value.logValue()];
|
|
54
78
|
}
|
|
55
79
|
return [this.value];
|
|
56
80
|
}
|
|
57
81
|
instanceKey() {
|
|
82
|
+
const sqliteClause = this.nullClause();
|
|
83
|
+
if (sqliteClause) {
|
|
84
|
+
return sqliteClause.instanceKey();
|
|
85
|
+
}
|
|
58
86
|
return `${this.col}${this.op}${rawValue(this.value)}`;
|
|
59
87
|
}
|
|
60
88
|
}
|
|
89
|
+
class isNullClause {
|
|
90
|
+
constructor(col) {
|
|
91
|
+
this.col = col;
|
|
92
|
+
}
|
|
93
|
+
clause(idx) {
|
|
94
|
+
return `${this.col} IS NULL`;
|
|
95
|
+
}
|
|
96
|
+
columns() {
|
|
97
|
+
return [];
|
|
98
|
+
}
|
|
99
|
+
values() {
|
|
100
|
+
return [];
|
|
101
|
+
}
|
|
102
|
+
logValues() {
|
|
103
|
+
return [];
|
|
104
|
+
}
|
|
105
|
+
instanceKey() {
|
|
106
|
+
return `${this.col} IS NULL`;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
class isNotNullClause {
|
|
110
|
+
constructor(col) {
|
|
111
|
+
this.col = col;
|
|
112
|
+
}
|
|
113
|
+
clause(idx) {
|
|
114
|
+
return `${this.col} IS NOT NULL`;
|
|
115
|
+
}
|
|
116
|
+
columns() {
|
|
117
|
+
return [];
|
|
118
|
+
}
|
|
119
|
+
values() {
|
|
120
|
+
return [];
|
|
121
|
+
}
|
|
122
|
+
logValues() {
|
|
123
|
+
return [];
|
|
124
|
+
}
|
|
125
|
+
instanceKey() {
|
|
126
|
+
return `${this.col} IS NOT NULL`;
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
class arraySimpleClause {
|
|
130
|
+
constructor(col, value, op) {
|
|
131
|
+
this.col = col;
|
|
132
|
+
this.value = value;
|
|
133
|
+
this.op = op;
|
|
134
|
+
}
|
|
135
|
+
clause(idx) {
|
|
136
|
+
if (db_1.default.getDialect() === db_1.Dialect.Postgres) {
|
|
137
|
+
return `$${idx} ${this.op} ANY(${this.col})`;
|
|
138
|
+
}
|
|
139
|
+
return `${this.col} ${this.op} ?`;
|
|
140
|
+
}
|
|
141
|
+
columns() {
|
|
142
|
+
return [this.col];
|
|
143
|
+
}
|
|
144
|
+
values() {
|
|
145
|
+
if (isSensitive(this.value)) {
|
|
146
|
+
return [this.value.value()];
|
|
147
|
+
}
|
|
148
|
+
return [this.value];
|
|
149
|
+
}
|
|
150
|
+
logValues() {
|
|
151
|
+
if (isSensitive(this.value)) {
|
|
152
|
+
return [this.value.logValue()];
|
|
153
|
+
}
|
|
154
|
+
return [this.value];
|
|
155
|
+
}
|
|
156
|
+
instanceKey() {
|
|
157
|
+
return `${this.col}${this.op}${rawValue(this.value)}`;
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
class postgresArrayOperator {
|
|
161
|
+
constructor(col, value, op, not) {
|
|
162
|
+
this.col = col;
|
|
163
|
+
this.value = value;
|
|
164
|
+
this.op = op;
|
|
165
|
+
this.not = not;
|
|
166
|
+
}
|
|
167
|
+
clause(idx) {
|
|
168
|
+
if (db_1.default.getDialect() === db_1.Dialect.Postgres) {
|
|
169
|
+
if (this.not) {
|
|
170
|
+
return `NOT ${this.col} ${this.op} $${idx}`;
|
|
171
|
+
}
|
|
172
|
+
return `${this.col} ${this.op} $${idx}`;
|
|
173
|
+
}
|
|
174
|
+
throw new Error(`not supported`);
|
|
175
|
+
}
|
|
176
|
+
columns() {
|
|
177
|
+
return [this.col];
|
|
178
|
+
}
|
|
179
|
+
values() {
|
|
180
|
+
if (isSensitive(this.value)) {
|
|
181
|
+
return [`{${this.value.value()}}`];
|
|
182
|
+
}
|
|
183
|
+
return [`{${this.value}}`];
|
|
184
|
+
}
|
|
185
|
+
logValues() {
|
|
186
|
+
if (isSensitive(this.value)) {
|
|
187
|
+
return [this.value.logValue()];
|
|
188
|
+
}
|
|
189
|
+
return [this.value];
|
|
190
|
+
}
|
|
191
|
+
instanceKey() {
|
|
192
|
+
if (this.not) {
|
|
193
|
+
return `NOT:${this.col}${this.op}${rawValue(this.value)}`;
|
|
194
|
+
}
|
|
195
|
+
return `${this.col}${this.op}${rawValue(this.value)}`;
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
class postgresArrayOperatorList extends postgresArrayOperator {
|
|
199
|
+
constructor(col, value, op, not) {
|
|
200
|
+
super(col, value, op, not);
|
|
201
|
+
}
|
|
202
|
+
values() {
|
|
203
|
+
return [
|
|
204
|
+
`{${this.value
|
|
205
|
+
.map((v) => {
|
|
206
|
+
if (isSensitive(v)) {
|
|
207
|
+
return v.value();
|
|
208
|
+
}
|
|
209
|
+
return v;
|
|
210
|
+
})
|
|
211
|
+
.join(", ")}}`,
|
|
212
|
+
];
|
|
213
|
+
}
|
|
214
|
+
}
|
|
61
215
|
class inClause {
|
|
62
216
|
constructor(col, value) {
|
|
63
217
|
this.col = col;
|
|
@@ -84,6 +238,9 @@ class inClause {
|
|
|
84
238
|
// or change to a sqlx.Rebind format
|
|
85
239
|
// here's what sqlx does: https://play.golang.org/p/vPzvYqeAcP0
|
|
86
240
|
}
|
|
241
|
+
columns() {
|
|
242
|
+
return [this.col];
|
|
243
|
+
}
|
|
87
244
|
values() {
|
|
88
245
|
const result = [];
|
|
89
246
|
for (const value of this.value) {
|
|
@@ -125,6 +282,13 @@ class compositeClause {
|
|
|
125
282
|
}
|
|
126
283
|
return clauses.join(this.sep);
|
|
127
284
|
}
|
|
285
|
+
columns() {
|
|
286
|
+
const ret = [];
|
|
287
|
+
for (const cls of this.clauses) {
|
|
288
|
+
ret.push(...cls.columns());
|
|
289
|
+
}
|
|
290
|
+
return ret;
|
|
291
|
+
}
|
|
128
292
|
values() {
|
|
129
293
|
let result = [];
|
|
130
294
|
for (const clause of this.clauses) {
|
|
@@ -145,12 +309,148 @@ class compositeClause {
|
|
|
145
309
|
return keys.join(this.sep);
|
|
146
310
|
}
|
|
147
311
|
}
|
|
312
|
+
class tsQueryClause {
|
|
313
|
+
constructor(col, val, tsVectorCol) {
|
|
314
|
+
this.col = col;
|
|
315
|
+
this.val = val;
|
|
316
|
+
this.tsVectorCol = tsVectorCol;
|
|
317
|
+
}
|
|
318
|
+
isTsQuery(val) {
|
|
319
|
+
return typeof val !== "string";
|
|
320
|
+
}
|
|
321
|
+
getInfo() {
|
|
322
|
+
if (this.isTsQuery(this.val)) {
|
|
323
|
+
return { value: this.val.value, language: this.val.language };
|
|
324
|
+
}
|
|
325
|
+
return {
|
|
326
|
+
language: "english",
|
|
327
|
+
value: this.val,
|
|
328
|
+
};
|
|
329
|
+
}
|
|
330
|
+
clause(idx) {
|
|
331
|
+
const { language } = this.getInfo();
|
|
332
|
+
if (db_1.Dialect.Postgres === db_1.default.getDialect()) {
|
|
333
|
+
if (this.tsVectorCol) {
|
|
334
|
+
return `to_tsvector(${this.col}) @@ ${this.getFunction()}('${language}', $${idx})`;
|
|
335
|
+
}
|
|
336
|
+
return `${this.col} @@ ${this.getFunction()}('${language}', $${idx})`;
|
|
337
|
+
}
|
|
338
|
+
// FYI this doesn't actually work for sqlite since different
|
|
339
|
+
return `${this.col} @@ ${this.getFunction()}('${language}', ?)`;
|
|
340
|
+
}
|
|
341
|
+
columns() {
|
|
342
|
+
return [this.col];
|
|
343
|
+
}
|
|
344
|
+
values() {
|
|
345
|
+
const { value } = this.getInfo();
|
|
346
|
+
return [value];
|
|
347
|
+
}
|
|
348
|
+
logValues() {
|
|
349
|
+
const { value } = this.getInfo();
|
|
350
|
+
return [value];
|
|
351
|
+
}
|
|
352
|
+
getFunction() {
|
|
353
|
+
return "to_tsquery";
|
|
354
|
+
}
|
|
355
|
+
instanceKey() {
|
|
356
|
+
const { language, value } = this.getInfo();
|
|
357
|
+
if (this.tsVectorCol) {
|
|
358
|
+
return `to_tsvector(${this.col})@@${this.getFunction()}:${language}:${value}`;
|
|
359
|
+
}
|
|
360
|
+
return `${this.col}@@${this.getFunction()}:${language}:${value}`;
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
class plainToTsQueryClause extends tsQueryClause {
|
|
364
|
+
getFunction() {
|
|
365
|
+
return "plainto_tsquery";
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
class phraseToTsQueryClause extends tsQueryClause {
|
|
369
|
+
getFunction() {
|
|
370
|
+
return "phraseto_tsquery";
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
class websearchTosQueryClause extends tsQueryClause {
|
|
374
|
+
getFunction() {
|
|
375
|
+
return "websearch_to_tsquery";
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
// postgres array operators
|
|
379
|
+
// https://www.postgresql.org/docs/current/functions-array.html
|
|
380
|
+
/**
|
|
381
|
+
* creates a clause to determine if the given value is contained in the array stored in the column in the db
|
|
382
|
+
* only works with postgres gin indexes
|
|
383
|
+
* https://www.postgresql.org/docs/current/indexes-types.html#INDEXES-TYPES-GIN
|
|
384
|
+
*/
|
|
385
|
+
function PostgresArrayContainsValue(col, value) {
|
|
386
|
+
return new postgresArrayOperator(col, value, "@>");
|
|
387
|
+
}
|
|
388
|
+
exports.PostgresArrayContainsValue = PostgresArrayContainsValue;
|
|
389
|
+
/**
|
|
390
|
+
* creates a clause to determine if every item in the list is stored in the array stored in the column in the db
|
|
391
|
+
* only works with postgres gin indexes
|
|
392
|
+
* https://www.postgresql.org/docs/current/indexes-types.html#INDEXES-TYPES-GIN
|
|
393
|
+
*/
|
|
394
|
+
function PostgresArrayContains(col, value) {
|
|
395
|
+
return new postgresArrayOperatorList(col, value, "@>");
|
|
396
|
+
}
|
|
397
|
+
exports.PostgresArrayContains = PostgresArrayContains;
|
|
398
|
+
/**
|
|
399
|
+
* creates a clause to determine if the given value is NOT contained in the array stored in the column in the db
|
|
400
|
+
* only works with postgres gin indexes
|
|
401
|
+
* https://www.postgresql.org/docs/current/indexes-types.html#INDEXES-TYPES-GIN
|
|
402
|
+
*/
|
|
403
|
+
function PostgresArrayNotContainsValue(col, value) {
|
|
404
|
+
return new postgresArrayOperator(col, value, "@>", true);
|
|
405
|
+
}
|
|
406
|
+
exports.PostgresArrayNotContainsValue = PostgresArrayNotContainsValue;
|
|
407
|
+
/**
|
|
408
|
+
* creates a clause to determine if every item in the list is NOT stored in the array stored in the column in the db
|
|
409
|
+
* only works with postgres gin indexes
|
|
410
|
+
* https://www.postgresql.org/docs/current/indexes-types.html#INDEXES-TYPES-GIN
|
|
411
|
+
*/
|
|
412
|
+
function PostgresArrayNotContains(col, value) {
|
|
413
|
+
return new postgresArrayOperatorList(col, value, "@>", true);
|
|
414
|
+
}
|
|
415
|
+
exports.PostgresArrayNotContains = PostgresArrayNotContains;
|
|
416
|
+
/**
|
|
417
|
+
* creates a clause to determine if the arrays overlap, that is, do they have any elements in common
|
|
418
|
+
* only works with postgres gin indexes
|
|
419
|
+
* https://www.postgresql.org/docs/current/indexes-types.html#INDEXES-TYPES-GIN
|
|
420
|
+
*/
|
|
421
|
+
function PostgresArrayOverlaps(col, value) {
|
|
422
|
+
return new postgresArrayOperatorList(col, value, "&&");
|
|
423
|
+
}
|
|
424
|
+
exports.PostgresArrayOverlaps = PostgresArrayOverlaps;
|
|
425
|
+
/**
|
|
426
|
+
* creates a clause to determine if the arrays do not overlap, that is, do they have any elements in common
|
|
427
|
+
* only works with postgres gin indexes
|
|
428
|
+
* https://www.postgresql.org/docs/current/indexes-types.html#INDEXES-TYPES-GIN
|
|
429
|
+
*/
|
|
430
|
+
function PostgresArrayNotOverlaps(col, value) {
|
|
431
|
+
return new postgresArrayOperatorList(col, value, "&&", true);
|
|
432
|
+
}
|
|
433
|
+
exports.PostgresArrayNotOverlaps = PostgresArrayNotOverlaps;
|
|
434
|
+
/**
|
|
435
|
+
* @deprecated use PostgresArrayContainsValue
|
|
436
|
+
*/
|
|
437
|
+
function ArrayEq(col, value) {
|
|
438
|
+
return new arraySimpleClause(col, value, "=");
|
|
439
|
+
}
|
|
440
|
+
exports.ArrayEq = ArrayEq;
|
|
441
|
+
/**
|
|
442
|
+
* @deprecated use PostgresNotArrayContains
|
|
443
|
+
*/
|
|
444
|
+
function ArrayNotEq(col, value) {
|
|
445
|
+
return new arraySimpleClause(col, value, "!=");
|
|
446
|
+
}
|
|
447
|
+
exports.ArrayNotEq = ArrayNotEq;
|
|
148
448
|
function Eq(col, value) {
|
|
149
|
-
return new simpleClause(col, value, "=");
|
|
449
|
+
return new simpleClause(col, value, "=", new isNullClause(col));
|
|
150
450
|
}
|
|
151
451
|
exports.Eq = Eq;
|
|
152
452
|
function NotEq(col, value) {
|
|
153
|
-
return new simpleClause(col, value, "!=");
|
|
453
|
+
return new simpleClause(col, value, "!=", new isNotNullClause(col));
|
|
154
454
|
}
|
|
155
455
|
exports.NotEq = NotEq;
|
|
156
456
|
function Greater(col, value) {
|
|
@@ -173,6 +473,15 @@ function And(...args) {
|
|
|
173
473
|
return new compositeClause(args, " AND ");
|
|
174
474
|
}
|
|
175
475
|
exports.And = And;
|
|
476
|
+
function AndOptional(...args) {
|
|
477
|
+
// @ts-ignore
|
|
478
|
+
let filtered = args.filter((v) => v !== undefined);
|
|
479
|
+
if (filtered.length === 1) {
|
|
480
|
+
return filtered[0];
|
|
481
|
+
}
|
|
482
|
+
return And(...filtered);
|
|
483
|
+
}
|
|
484
|
+
exports.AndOptional = AndOptional;
|
|
176
485
|
function Or(...args) {
|
|
177
486
|
return new compositeClause(args, " OR ");
|
|
178
487
|
}
|
|
@@ -182,6 +491,60 @@ function In(col, ...values) {
|
|
|
182
491
|
return new inClause(col, values);
|
|
183
492
|
}
|
|
184
493
|
exports.In = In;
|
|
494
|
+
// if string defaults to english
|
|
495
|
+
// https://www.postgresql.org/docs/current/textsearch-controls.html#TEXTSEARCH-PARSING-QUERIES
|
|
496
|
+
// to_tsquery
|
|
497
|
+
// plainto_tsquery
|
|
498
|
+
// phraseto_tsquery;
|
|
499
|
+
// websearch_to_tsquery
|
|
500
|
+
function TsQuery(col, val) {
|
|
501
|
+
return new tsQueryClause(col, val);
|
|
502
|
+
}
|
|
503
|
+
exports.TsQuery = TsQuery;
|
|
504
|
+
function PlainToTsQuery(col, val) {
|
|
505
|
+
return new plainToTsQueryClause(col, val);
|
|
506
|
+
}
|
|
507
|
+
exports.PlainToTsQuery = PlainToTsQuery;
|
|
508
|
+
function PhraseToTsQuery(col, val) {
|
|
509
|
+
return new phraseToTsQueryClause(col, val);
|
|
510
|
+
}
|
|
511
|
+
exports.PhraseToTsQuery = PhraseToTsQuery;
|
|
512
|
+
function WebsearchToTsQuery(col, val) {
|
|
513
|
+
return new websearchTosQueryClause(col, val);
|
|
514
|
+
}
|
|
515
|
+
exports.WebsearchToTsQuery = WebsearchToTsQuery;
|
|
516
|
+
// TsVectorColTsQuery is used when the column is not a tsvector field e.g.
|
|
517
|
+
// when there's an index just on the field and is not a combination of multiple fields
|
|
518
|
+
function TsVectorColTsQuery(col, val) {
|
|
519
|
+
return new tsQueryClause(col, val, true);
|
|
520
|
+
}
|
|
521
|
+
exports.TsVectorColTsQuery = TsVectorColTsQuery;
|
|
522
|
+
// TsVectorPlainToTsQuery is used when the column is not a tsvector field e.g.
|
|
523
|
+
// when there's an index just on the field and is not a combination of multiple fields
|
|
524
|
+
// TODO do these 4 need TsQuery because would be nice to have language?
|
|
525
|
+
// it seems to default to the config of the column
|
|
526
|
+
function TsVectorPlainToTsQuery(col, val) {
|
|
527
|
+
return new plainToTsQueryClause(col, val, true);
|
|
528
|
+
}
|
|
529
|
+
exports.TsVectorPlainToTsQuery = TsVectorPlainToTsQuery;
|
|
530
|
+
// TsVectorPhraseToTsQuery is used when the column is not a tsvector field e.g.
|
|
531
|
+
// when there's an index just on the field and is not a combination of multiple fields
|
|
532
|
+
function TsVectorPhraseToTsQuery(col, val) {
|
|
533
|
+
return new phraseToTsQueryClause(col, val, true);
|
|
534
|
+
}
|
|
535
|
+
exports.TsVectorPhraseToTsQuery = TsVectorPhraseToTsQuery;
|
|
536
|
+
// TsVectorWebsearchToTsQuery is used when the column is not a tsvector field e.g.
|
|
537
|
+
// when there's an index just on the field and is not a combination of multiple fields
|
|
538
|
+
function TsVectorWebsearchToTsQuery(col, val) {
|
|
539
|
+
return new websearchTosQueryClause(col, val, true);
|
|
540
|
+
}
|
|
541
|
+
exports.TsVectorWebsearchToTsQuery = TsVectorWebsearchToTsQuery;
|
|
542
|
+
// TODO would be nice to support this with building blocks but not supporting for now
|
|
543
|
+
// AND: foo & bar,
|
|
544
|
+
// OR: foo | bar
|
|
545
|
+
// followed by: foo <-> bar
|
|
546
|
+
// NOT: !foo
|
|
547
|
+
// starts_with: theo:*
|
|
185
548
|
// wrap a query in the db with this to ensure that it doesn't show up in the logs
|
|
186
549
|
// e.g. if querying for password, SSN, etc
|
|
187
550
|
// we'll pass the right fields to query and log something along the lines of `****`
|
|
@@ -196,3 +559,55 @@ function sensitiveValue(val) {
|
|
|
196
559
|
};
|
|
197
560
|
}
|
|
198
561
|
exports.sensitiveValue = sensitiveValue;
|
|
562
|
+
// These don't return Clauses but return helpful things that can be passed to clauses
|
|
563
|
+
// https://www.postgresql.org/docs/12/functions-json.html#FUNCTIONS-JSON-OP-TABLE
|
|
564
|
+
// see test in db_clause.test.ts
|
|
565
|
+
// unclear best time to use this...
|
|
566
|
+
function JSONObjectFieldKeyASJSON(col, field) {
|
|
567
|
+
return `${col}->'${field}'`;
|
|
568
|
+
}
|
|
569
|
+
exports.JSONObjectFieldKeyASJSON = JSONObjectFieldKeyASJSON;
|
|
570
|
+
function JSONObjectFieldKeyAsText(col, field) {
|
|
571
|
+
return `${col}->>'${field}'`;
|
|
572
|
+
}
|
|
573
|
+
exports.JSONObjectFieldKeyAsText = JSONObjectFieldKeyAsText;
|
|
574
|
+
class jSONPathValuePredicateClause {
|
|
575
|
+
constructor(col, path, value, pred) {
|
|
576
|
+
this.col = col;
|
|
577
|
+
this.path = path;
|
|
578
|
+
this.value = value;
|
|
579
|
+
this.pred = pred;
|
|
580
|
+
}
|
|
581
|
+
clause(idx) {
|
|
582
|
+
if (db_1.default.getDialect() !== db_1.Dialect.Postgres) {
|
|
583
|
+
throw new Error(`not supported`);
|
|
584
|
+
}
|
|
585
|
+
return `${this.col} @@ $${idx}`;
|
|
586
|
+
}
|
|
587
|
+
columns() {
|
|
588
|
+
return [this.col];
|
|
589
|
+
}
|
|
590
|
+
wrap(val) {
|
|
591
|
+
return `${this.path} ${this.pred} ${JSON.stringify(val)}`;
|
|
592
|
+
}
|
|
593
|
+
values() {
|
|
594
|
+
if (isSensitive(this.value)) {
|
|
595
|
+
return [this.wrap(this.value.value())];
|
|
596
|
+
}
|
|
597
|
+
return [this.wrap(this.value)];
|
|
598
|
+
}
|
|
599
|
+
logValues() {
|
|
600
|
+
if (isSensitive(this.value)) {
|
|
601
|
+
return [this.wrap(this.value.logValue())];
|
|
602
|
+
}
|
|
603
|
+
return [this.wrap(this.value)];
|
|
604
|
+
}
|
|
605
|
+
instanceKey() {
|
|
606
|
+
return `${this.col}${this.path}${rawValue(this.value)}${this.pred}`;
|
|
607
|
+
}
|
|
608
|
+
}
|
|
609
|
+
// https://www.postgresql.org/docs/12/functions-json.html#FUNCTIONS-JSON-OP-TABLE
|
|
610
|
+
function JSONPathValuePredicate(dbCol, path, val, pred) {
|
|
611
|
+
return new jSONPathValuePredicateClause(dbCol, path, val, pred);
|
|
612
|
+
}
|
|
613
|
+
exports.JSONPathValuePredicate = JSONPathValuePredicate;
|
package/core/config.d.ts
CHANGED
|
@@ -1,12 +1,26 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import { Database, DBDict } from "./db";
|
|
3
3
|
declare type logType = "query" | "warn" | "info" | "error" | "debug";
|
|
4
|
+
declare enum graphqlMutationName {
|
|
5
|
+
NOUN_VERB = "NounVerb",
|
|
6
|
+
VERB_NOUN = "VerbNoun"
|
|
7
|
+
}
|
|
8
|
+
declare enum graphQLFieldFormat {
|
|
9
|
+
LOWER_CAMEL = "lowerCamel",
|
|
10
|
+
SNAKE_CASE = "snake_case"
|
|
11
|
+
}
|
|
12
|
+
declare enum fieldPrivacyEvaluated {
|
|
13
|
+
AT_ENT_LOAD = "at_ent_load",
|
|
14
|
+
ON_DEMAND = "on_demand"
|
|
15
|
+
}
|
|
4
16
|
export interface Config {
|
|
5
17
|
dbConnectionString?: string;
|
|
6
18
|
dbFile?: string;
|
|
7
19
|
db?: Database | DBDict;
|
|
8
20
|
log?: logType | logType[];
|
|
9
21
|
codegen?: CodegenConfig;
|
|
22
|
+
customGraphQLJSONPath?: string;
|
|
23
|
+
globalSchemaPath?: string;
|
|
10
24
|
}
|
|
11
25
|
interface CodegenConfig {
|
|
12
26
|
defaultEntPolicy?: PrivacyConfig;
|
|
@@ -17,6 +31,13 @@ interface CodegenConfig {
|
|
|
17
31
|
generatedHeader?: string;
|
|
18
32
|
disableBase64Encoding?: boolean;
|
|
19
33
|
generateRootResolvers?: boolean;
|
|
34
|
+
defaultGraphQLMutationName?: graphqlMutationName;
|
|
35
|
+
defaultGraphQLFieldFormat?: graphQLFieldFormat;
|
|
36
|
+
schemaSQLFilePath?: boolean;
|
|
37
|
+
databaseToCompareTo?: string;
|
|
38
|
+
fieldPrivacyEvaluated?: fieldPrivacyEvaluated;
|
|
39
|
+
templatizedViewer?: importedObject;
|
|
40
|
+
customAssocEdgePath?: importedObject;
|
|
20
41
|
}
|
|
21
42
|
interface PrettierConfig {
|
|
22
43
|
custom?: boolean;
|
|
@@ -27,5 +48,10 @@ interface PrivacyConfig {
|
|
|
27
48
|
policyName: string;
|
|
28
49
|
class?: boolean;
|
|
29
50
|
}
|
|
51
|
+
interface importedObject {
|
|
52
|
+
path: string;
|
|
53
|
+
name: string;
|
|
54
|
+
alias?: string;
|
|
55
|
+
}
|
|
30
56
|
export declare function loadConfig(file?: string | Buffer | Config): void;
|
|
31
57
|
export {};
|
package/core/config.js
CHANGED
|
@@ -28,6 +28,23 @@ const js_yaml_1 = require("js-yaml");
|
|
|
28
28
|
const db_1 = __importDefault(require("./db"));
|
|
29
29
|
const path = __importStar(require("path"));
|
|
30
30
|
const logger_1 = require("./logger");
|
|
31
|
+
// ent.config.ts eventually. for now ent.yml
|
|
32
|
+
// or ent.yml?
|
|
33
|
+
var graphqlMutationName;
|
|
34
|
+
(function (graphqlMutationName) {
|
|
35
|
+
graphqlMutationName["NOUN_VERB"] = "NounVerb";
|
|
36
|
+
graphqlMutationName["VERB_NOUN"] = "VerbNoun";
|
|
37
|
+
})(graphqlMutationName || (graphqlMutationName = {}));
|
|
38
|
+
var graphQLFieldFormat;
|
|
39
|
+
(function (graphQLFieldFormat) {
|
|
40
|
+
graphQLFieldFormat["LOWER_CAMEL"] = "lowerCamel";
|
|
41
|
+
graphQLFieldFormat["SNAKE_CASE"] = "snake_case";
|
|
42
|
+
})(graphQLFieldFormat || (graphQLFieldFormat = {}));
|
|
43
|
+
var fieldPrivacyEvaluated;
|
|
44
|
+
(function (fieldPrivacyEvaluated) {
|
|
45
|
+
fieldPrivacyEvaluated["AT_ENT_LOAD"] = "at_ent_load";
|
|
46
|
+
fieldPrivacyEvaluated["ON_DEMAND"] = "on_demand";
|
|
47
|
+
})(fieldPrivacyEvaluated || (fieldPrivacyEvaluated = {}));
|
|
31
48
|
function setConfig(cfg) {
|
|
32
49
|
if (cfg.log) {
|
|
33
50
|
(0, logger_1.setLogLevels)(cfg.log);
|
package/core/context.d.ts
CHANGED
|
@@ -3,8 +3,8 @@ import { Viewer, Data, Loader } from "./base";
|
|
|
3
3
|
import { IncomingMessage, ServerResponse } from "http";
|
|
4
4
|
import * as clause from "./clause";
|
|
5
5
|
import { Context } from "./base";
|
|
6
|
-
export interface RequestContext extends Context {
|
|
7
|
-
authViewer(viewer:
|
|
6
|
+
export interface RequestContext<TViewer extends Viewer = Viewer> extends Context<TViewer> {
|
|
7
|
+
authViewer(viewer: TViewer): Promise<void>;
|
|
8
8
|
logout(): Promise<void>;
|
|
9
9
|
request: IncomingMessage;
|
|
10
10
|
response: ServerResponse;
|
package/core/context.js
CHANGED
|
@@ -39,7 +39,7 @@ class ContextCache {
|
|
|
39
39
|
const key = this.getkey(options);
|
|
40
40
|
let rows = m.get(key);
|
|
41
41
|
if (rows) {
|
|
42
|
-
(0, logger_1.log)("
|
|
42
|
+
(0, logger_1.log)("cache", {
|
|
43
43
|
"cache-hit": key,
|
|
44
44
|
"tableName": options.tableName,
|
|
45
45
|
});
|
|
@@ -54,7 +54,7 @@ class ContextCache {
|
|
|
54
54
|
const key = this.getkey(options);
|
|
55
55
|
let row = m.get(key);
|
|
56
56
|
if (row) {
|
|
57
|
-
(0, logger_1.log)("
|
|
57
|
+
(0, logger_1.log)("cache", {
|
|
58
58
|
"cache-hit": key,
|
|
59
59
|
"tableName": options.tableName,
|
|
60
60
|
});
|
package/core/convert.d.ts
CHANGED
|
@@ -10,5 +10,5 @@ export declare function convertBoolList(val: any): boolean[];
|
|
|
10
10
|
export declare function convertNullableBoolList(val: any): boolean[] | null;
|
|
11
11
|
export declare function convertJSON(val: any): any;
|
|
12
12
|
export declare function convertNullableJSON(val: any): any | null;
|
|
13
|
-
export declare function convertJSONList(val: any):
|
|
13
|
+
export declare function convertJSONList(val: any): any[];
|
|
14
14
|
export declare function convertNullableJSONList(val: any): any[] | null;
|
package/core/db.d.ts
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
|
-
import { Pool,
|
|
2
|
-
export interface Database {
|
|
1
|
+
import { Pool, PoolClient, PoolConfig } from "pg";
|
|
2
|
+
export interface Database extends PoolConfig {
|
|
3
3
|
database?: string;
|
|
4
4
|
user?: string;
|
|
5
5
|
password?: string;
|
|
6
6
|
host?: string;
|
|
7
7
|
port?: number;
|
|
8
|
-
ssl?: boolean;
|
|
9
8
|
sslmode?: string;
|
|
10
9
|
}
|
|
11
10
|
export declare type env = "production" | "test" | "development";
|
|
@@ -16,7 +15,7 @@ export declare enum Dialect {
|
|
|
16
15
|
}
|
|
17
16
|
interface DatabaseInfo {
|
|
18
17
|
dialect: Dialect;
|
|
19
|
-
config:
|
|
18
|
+
config: PoolConfig;
|
|
20
19
|
filePath?: string;
|
|
21
20
|
}
|
|
22
21
|
export default class DB {
|