@snowtop/ent 0.1.0-alpha8 → 0.1.0-alpha80
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 +27 -25
- package/action/executor.d.ts +3 -3
- 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 +37 -16
- package/action/orchestrator.js +184 -54
- package/action/privacy.d.ts +2 -2
- package/core/base.d.ts +38 -22
- package/core/clause.d.ts +65 -7
- package/core/clause.js +261 -54
- package/core/config.d.ts +8 -0
- package/core/context.d.ts +5 -3
- package/core/context.js +7 -2
- package/core/convert.d.ts +1 -1
- package/core/db.d.ts +1 -2
- package/core/db.js +1 -1
- package/core/ent.d.ts +76 -24
- package/core/ent.js +459 -143
- 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 +2 -2
- package/core/loaders/loader.js +5 -5
- package/core/loaders/object_loader.d.ts +4 -3
- package/core/loaders/object_loader.js +22 -5
- 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 +26 -25
- package/core/privacy.js +21 -25
- 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 +3 -3
- package/core/viewer.js +1 -1
- package/graphql/builtins/connection.js +3 -3
- package/graphql/builtins/edge.js +2 -2
- package/graphql/builtins/node.js +1 -1
- package/graphql/graphql.js +8 -2
- 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 +10 -5
- package/index.js +13 -6
- package/package.json +2 -2
- package/parse_schema/parse.d.ts +14 -2
- package/parse_schema/parse.js +40 -2
- package/schema/base_schema.d.ts +1 -1
- package/schema/base_schema.js +3 -0
- package/schema/field.d.ts +36 -7
- package/schema/field.js +70 -2
- package/schema/index.d.ts +2 -2
- package/schema/json_field.d.ts +13 -1
- package/schema/json_field.js +28 -1
- package/schema/schema.d.ts +61 -10
- package/schema/schema.js +18 -4
- package/schema/struct_field.d.ts +11 -1
- package/schema/struct_field.js +43 -4
- package/scripts/custom_graphql.js +5 -1
- 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 +31 -21
- package/testutils/builder.js +82 -29
- package/testutils/db/fixture.d.ts +10 -0
- package/testutils/db/fixture.js +26 -0
- package/testutils/db/{test_db.d.ts → temp_db.d.ts} +15 -3
- package/testutils/db/{test_db.js → temp_db.js} +63 -15
- package/testutils/db/value.d.ts +6 -0
- package/testutils/db/value.js +251 -0
- package/testutils/db_time_zone.d.ts +4 -0
- package/testutils/db_time_zone.js +41 -0
- package/testutils/ent-graphql-tests/index.js +19 -12
- package/testutils/fake_data/fake_contact.d.ts +3 -3
- package/testutils/fake_data/fake_contact.js +9 -6
- package/testutils/fake_data/fake_event.d.ts +3 -3
- package/testutils/fake_data/fake_event.js +8 -5
- package/testutils/fake_data/fake_user.d.ts +4 -4
- package/testutils/fake_data/fake_user.js +16 -13
- package/testutils/fake_data/test_helpers.d.ts +2 -2
- package/testutils/fake_data/test_helpers.js +5 -5
- 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 +29 -7
- 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 -437
package/core/clause.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export interface Clause {
|
|
2
2
|
clause(idx: number): string;
|
|
3
|
+
columns(): string[];
|
|
3
4
|
values(): any[];
|
|
4
5
|
instanceKey(): string;
|
|
5
6
|
logValues(): any[];
|
|
@@ -12,10 +13,23 @@ declare class simpleClause implements Clause {
|
|
|
12
13
|
protected col: string;
|
|
13
14
|
private value;
|
|
14
15
|
private op;
|
|
15
|
-
private
|
|
16
|
-
constructor(col: string, value: any, op: string,
|
|
16
|
+
private handleNull?;
|
|
17
|
+
constructor(col: string, value: any, op: string, handleNull?: Clause | undefined);
|
|
17
18
|
clause(idx: number): string;
|
|
18
|
-
private
|
|
19
|
+
private nullClause;
|
|
20
|
+
columns(): string[];
|
|
21
|
+
values(): any[];
|
|
22
|
+
logValues(): any[];
|
|
23
|
+
instanceKey(): string;
|
|
24
|
+
}
|
|
25
|
+
export declare class inClause implements Clause {
|
|
26
|
+
private col;
|
|
27
|
+
private value;
|
|
28
|
+
private type;
|
|
29
|
+
static getPostgresInClauseValuesThreshold(): number;
|
|
30
|
+
constructor(col: string, value: any[], type?: string);
|
|
31
|
+
clause(idx: number): string;
|
|
32
|
+
columns(): string[];
|
|
19
33
|
values(): any[];
|
|
20
34
|
logValues(): any[];
|
|
21
35
|
instanceKey(): string;
|
|
@@ -25,16 +39,55 @@ declare class compositeClause implements Clause {
|
|
|
25
39
|
private sep;
|
|
26
40
|
constructor(clauses: Clause[], sep: string);
|
|
27
41
|
clause(idx: number): string;
|
|
42
|
+
columns(): string[];
|
|
28
43
|
values(): any[];
|
|
29
44
|
logValues(): any[];
|
|
30
45
|
instanceKey(): string;
|
|
31
46
|
}
|
|
47
|
+
/**
|
|
48
|
+
* creates a clause to determine if the given value is contained in the array stored in the column in the db
|
|
49
|
+
* only works with postgres gin indexes
|
|
50
|
+
* https://www.postgresql.org/docs/current/indexes-types.html#INDEXES-TYPES-GIN
|
|
51
|
+
*/
|
|
52
|
+
export declare function PostgresArrayContainsValue(col: string, value: any): Clause;
|
|
53
|
+
/**
|
|
54
|
+
* creates a clause to determine if every item in the list is stored in the array stored in the column in the db
|
|
55
|
+
* only works with postgres gin indexes
|
|
56
|
+
* https://www.postgresql.org/docs/current/indexes-types.html#INDEXES-TYPES-GIN
|
|
57
|
+
*/
|
|
58
|
+
export declare function PostgresArrayContains(col: string, value: any[]): Clause;
|
|
59
|
+
/**
|
|
60
|
+
* creates a clause to determine if the given value is NOT contained in the array stored in the column in the db
|
|
61
|
+
* only works with postgres gin indexes
|
|
62
|
+
* https://www.postgresql.org/docs/current/indexes-types.html#INDEXES-TYPES-GIN
|
|
63
|
+
*/
|
|
64
|
+
export declare function PostgresArrayNotContainsValue(col: string, value: any): Clause;
|
|
65
|
+
/**
|
|
66
|
+
* creates a clause to determine if every item in the list is NOT stored in the array stored in the column in the db
|
|
67
|
+
* only works with postgres gin indexes
|
|
68
|
+
* https://www.postgresql.org/docs/current/indexes-types.html#INDEXES-TYPES-GIN
|
|
69
|
+
*/
|
|
70
|
+
export declare function PostgresArrayNotContains(col: string, value: any[]): Clause;
|
|
71
|
+
/**
|
|
72
|
+
* creates a clause to determine if the arrays overlap, that is, do they have any elements in common
|
|
73
|
+
* only works with postgres gin indexes
|
|
74
|
+
* https://www.postgresql.org/docs/current/indexes-types.html#INDEXES-TYPES-GIN
|
|
75
|
+
*/
|
|
76
|
+
export declare function PostgresArrayOverlaps(col: string, value: any[]): Clause;
|
|
77
|
+
/**
|
|
78
|
+
* creates a clause to determine if the arrays do not overlap, that is, do they have any elements in common
|
|
79
|
+
* only works with postgres gin indexes
|
|
80
|
+
* https://www.postgresql.org/docs/current/indexes-types.html#INDEXES-TYPES-GIN
|
|
81
|
+
*/
|
|
82
|
+
export declare function PostgresArrayNotOverlaps(col: string, value: any[]): Clause;
|
|
83
|
+
/**
|
|
84
|
+
* @deprecated use PostgresArrayContainsValue
|
|
85
|
+
*/
|
|
32
86
|
export declare function ArrayEq(col: string, value: any): Clause;
|
|
87
|
+
/**
|
|
88
|
+
* @deprecated use PostgresNotArrayContains
|
|
89
|
+
*/
|
|
33
90
|
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;
|
|
38
91
|
export declare function Eq(col: string, value: any): Clause;
|
|
39
92
|
export declare function NotEq(col: string, value: any): Clause;
|
|
40
93
|
export declare function Greater(col: string, value: any): simpleClause;
|
|
@@ -45,6 +98,7 @@ export declare function And(...args: Clause[]): compositeClause;
|
|
|
45
98
|
export declare function AndOptional(...args: (Clause | undefined)[]): Clause;
|
|
46
99
|
export declare function Or(...args: Clause[]): compositeClause;
|
|
47
100
|
export declare function In(col: string, ...values: any): Clause;
|
|
101
|
+
export declare function In(col: string, values: any[], type?: string): Clause;
|
|
48
102
|
interface TsQuery {
|
|
49
103
|
language: "english" | "french" | "german" | "simple";
|
|
50
104
|
value: string;
|
|
@@ -58,4 +112,8 @@ export declare function TsVectorPlainToTsQuery(col: string, val: string | TsQuer
|
|
|
58
112
|
export declare function TsVectorPhraseToTsQuery(col: string, val: string | TsQuery): Clause;
|
|
59
113
|
export declare function TsVectorWebsearchToTsQuery(col: string, val: string | TsQuery): Clause;
|
|
60
114
|
export declare function sensitiveValue(val: any): SensitiveValue;
|
|
115
|
+
export declare function JSONObjectFieldKeyASJSON(col: string, field: string): string;
|
|
116
|
+
export declare function JSONObjectFieldKeyAsText(col: string, field: string): string;
|
|
117
|
+
declare type predicate = "==" | ">" | "<" | "!=" | ">=" | "<=";
|
|
118
|
+
export declare function JSONPathValuePredicate(dbCol: string, path: string, val: any, pred: predicate): Clause;
|
|
61
119
|
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.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.
|
|
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 = exports.inClause = void 0;
|
|
23
23
|
const db_1 = __importStar(require("./db"));
|
|
24
24
|
function isSensitive(val) {
|
|
25
25
|
return (val !== null &&
|
|
@@ -33,33 +33,33 @@ function rawValue(val) {
|
|
|
33
33
|
return val;
|
|
34
34
|
}
|
|
35
35
|
class simpleClause {
|
|
36
|
-
constructor(col, value, op,
|
|
36
|
+
constructor(col, value, op, handleNull) {
|
|
37
37
|
this.col = col;
|
|
38
38
|
this.value = value;
|
|
39
39
|
this.op = op;
|
|
40
|
-
this.
|
|
40
|
+
this.handleNull = handleNull;
|
|
41
41
|
}
|
|
42
42
|
clause(idx) {
|
|
43
|
-
const
|
|
44
|
-
if (
|
|
45
|
-
return
|
|
43
|
+
const nullClause = this.nullClause();
|
|
44
|
+
if (nullClause) {
|
|
45
|
+
return nullClause.clause(idx);
|
|
46
46
|
}
|
|
47
47
|
if (db_1.default.getDialect() === db_1.Dialect.Postgres) {
|
|
48
48
|
return `${this.col} ${this.op} $${idx}`;
|
|
49
49
|
}
|
|
50
50
|
return `${this.col} ${this.op} ?`;
|
|
51
51
|
}
|
|
52
|
-
|
|
53
|
-
if (!this.
|
|
54
|
-
return;
|
|
55
|
-
}
|
|
56
|
-
if (db_1.default.getDialect() !== db_1.Dialect.SQLite) {
|
|
52
|
+
nullClause() {
|
|
53
|
+
if (!this.handleNull || this.value !== null) {
|
|
57
54
|
return;
|
|
58
55
|
}
|
|
59
|
-
return this.
|
|
56
|
+
return this.handleNull;
|
|
57
|
+
}
|
|
58
|
+
columns() {
|
|
59
|
+
return [this.col];
|
|
60
60
|
}
|
|
61
61
|
values() {
|
|
62
|
-
const sqliteClause = this.
|
|
62
|
+
const sqliteClause = this.nullClause();
|
|
63
63
|
if (sqliteClause) {
|
|
64
64
|
return sqliteClause.values();
|
|
65
65
|
}
|
|
@@ -69,7 +69,7 @@ class simpleClause {
|
|
|
69
69
|
return [this.value];
|
|
70
70
|
}
|
|
71
71
|
logValues() {
|
|
72
|
-
const sqliteClause = this.
|
|
72
|
+
const sqliteClause = this.nullClause();
|
|
73
73
|
if (sqliteClause) {
|
|
74
74
|
return sqliteClause.logValues();
|
|
75
75
|
}
|
|
@@ -79,7 +79,7 @@ class simpleClause {
|
|
|
79
79
|
return [this.value];
|
|
80
80
|
}
|
|
81
81
|
instanceKey() {
|
|
82
|
-
const sqliteClause = this.
|
|
82
|
+
const sqliteClause = this.nullClause();
|
|
83
83
|
if (sqliteClause) {
|
|
84
84
|
return sqliteClause.instanceKey();
|
|
85
85
|
}
|
|
@@ -93,6 +93,9 @@ class isNullClause {
|
|
|
93
93
|
clause(idx) {
|
|
94
94
|
return `${this.col} IS NULL`;
|
|
95
95
|
}
|
|
96
|
+
columns() {
|
|
97
|
+
return [];
|
|
98
|
+
}
|
|
96
99
|
values() {
|
|
97
100
|
return [];
|
|
98
101
|
}
|
|
@@ -110,6 +113,9 @@ class isNotNullClause {
|
|
|
110
113
|
clause(idx) {
|
|
111
114
|
return `${this.col} IS NOT NULL`;
|
|
112
115
|
}
|
|
116
|
+
columns() {
|
|
117
|
+
return [];
|
|
118
|
+
}
|
|
113
119
|
values() {
|
|
114
120
|
return [];
|
|
115
121
|
}
|
|
@@ -132,6 +138,9 @@ class arraySimpleClause {
|
|
|
132
138
|
}
|
|
133
139
|
return `${this.col} ${this.op} ?`;
|
|
134
140
|
}
|
|
141
|
+
columns() {
|
|
142
|
+
return [this.col];
|
|
143
|
+
}
|
|
135
144
|
values() {
|
|
136
145
|
if (isSensitive(this.value)) {
|
|
137
146
|
return [this.value.value()];
|
|
@@ -148,18 +157,105 @@ class arraySimpleClause {
|
|
|
148
157
|
return `${this.col}${this.op}${rawValue(this.value)}`;
|
|
149
158
|
}
|
|
150
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
|
+
logValues() {
|
|
215
|
+
return [
|
|
216
|
+
`{${this.value
|
|
217
|
+
.map((v) => {
|
|
218
|
+
if (isSensitive(v)) {
|
|
219
|
+
return v.logValue();
|
|
220
|
+
}
|
|
221
|
+
return v;
|
|
222
|
+
})
|
|
223
|
+
.join(", ")}}`,
|
|
224
|
+
];
|
|
225
|
+
}
|
|
226
|
+
}
|
|
151
227
|
class inClause {
|
|
152
|
-
constructor(col, value) {
|
|
228
|
+
constructor(col, value, type = "uuid") {
|
|
153
229
|
this.col = col;
|
|
154
230
|
this.value = value;
|
|
231
|
+
this.type = type;
|
|
232
|
+
}
|
|
233
|
+
static getPostgresInClauseValuesThreshold() {
|
|
234
|
+
return 70;
|
|
155
235
|
}
|
|
156
236
|
clause(idx) {
|
|
157
|
-
|
|
237
|
+
// do a simple = when only one item
|
|
238
|
+
if (this.value.length === 1) {
|
|
239
|
+
return new simpleClause(this.col, this.value[0], "=").clause(idx);
|
|
240
|
+
}
|
|
241
|
+
const postgres = db_1.default.getDialect() === db_1.Dialect.Postgres;
|
|
242
|
+
const postgresValuesList = postgres &&
|
|
243
|
+
this.value.length >= inClause.getPostgresInClauseValuesThreshold();
|
|
158
244
|
let indices;
|
|
159
|
-
if (
|
|
245
|
+
if (postgres) {
|
|
160
246
|
indices = [];
|
|
161
247
|
for (let i = 0; i < this.value.length; i++) {
|
|
162
|
-
|
|
248
|
+
if (postgresValuesList) {
|
|
249
|
+
if (i === 0) {
|
|
250
|
+
indices.push(`($${idx}::${this.type})`);
|
|
251
|
+
}
|
|
252
|
+
else {
|
|
253
|
+
indices.push(`($${idx})`);
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
else {
|
|
257
|
+
indices.push(`$${idx}`);
|
|
258
|
+
}
|
|
163
259
|
idx++;
|
|
164
260
|
}
|
|
165
261
|
}
|
|
@@ -167,34 +263,31 @@ class inClause {
|
|
|
167
263
|
indices = new Array(this.value.length);
|
|
168
264
|
indices.fill("?", 0);
|
|
169
265
|
}
|
|
170
|
-
|
|
266
|
+
let inValue = indices.join(", ");
|
|
267
|
+
// wrap in VALUES list for postgres...
|
|
268
|
+
if (postgresValuesList) {
|
|
269
|
+
inValue = `VALUES${inValue}`;
|
|
270
|
+
}
|
|
171
271
|
return `${this.col} IN (${inValue})`;
|
|
172
272
|
// TODO we need to return idx at end to query builder...
|
|
173
273
|
// or anything that's doing a composite query so next clause knows where to start
|
|
174
274
|
// or change to a sqlx.Rebind format
|
|
175
275
|
// here's what sqlx does: https://play.golang.org/p/vPzvYqeAcP0
|
|
176
276
|
}
|
|
277
|
+
columns() {
|
|
278
|
+
return [this.col];
|
|
279
|
+
}
|
|
177
280
|
values() {
|
|
178
281
|
const result = [];
|
|
179
|
-
for (
|
|
180
|
-
|
|
181
|
-
result.push(value.value());
|
|
182
|
-
}
|
|
183
|
-
else {
|
|
184
|
-
result.push(value);
|
|
185
|
-
}
|
|
282
|
+
for (let value of this.value) {
|
|
283
|
+
result.push(rawValue(value));
|
|
186
284
|
}
|
|
187
285
|
return result;
|
|
188
286
|
}
|
|
189
287
|
logValues() {
|
|
190
288
|
const result = [];
|
|
191
|
-
for (
|
|
192
|
-
|
|
193
|
-
result.push(value.logValue());
|
|
194
|
-
}
|
|
195
|
-
else {
|
|
196
|
-
result.push(value);
|
|
197
|
-
}
|
|
289
|
+
for (let value of this.value) {
|
|
290
|
+
result.push(isSensitive(value) ? value.logValue() : value);
|
|
198
291
|
}
|
|
199
292
|
return result;
|
|
200
293
|
}
|
|
@@ -202,6 +295,7 @@ class inClause {
|
|
|
202
295
|
return `in:${this.col}:${this.values().join(",")}`;
|
|
203
296
|
}
|
|
204
297
|
}
|
|
298
|
+
exports.inClause = inClause;
|
|
205
299
|
class compositeClause {
|
|
206
300
|
constructor(clauses, sep) {
|
|
207
301
|
this.clauses = clauses;
|
|
@@ -215,6 +309,13 @@ class compositeClause {
|
|
|
215
309
|
}
|
|
216
310
|
return clauses.join(this.sep);
|
|
217
311
|
}
|
|
312
|
+
columns() {
|
|
313
|
+
const ret = [];
|
|
314
|
+
for (const cls of this.clauses) {
|
|
315
|
+
ret.push(...cls.columns());
|
|
316
|
+
}
|
|
317
|
+
return ret;
|
|
318
|
+
}
|
|
218
319
|
values() {
|
|
219
320
|
let result = [];
|
|
220
321
|
for (const clause of this.clauses) {
|
|
@@ -264,6 +365,9 @@ class tsQueryClause {
|
|
|
264
365
|
// FYI this doesn't actually work for sqlite since different
|
|
265
366
|
return `${this.col} @@ ${this.getFunction()}('${language}', ?)`;
|
|
266
367
|
}
|
|
368
|
+
columns() {
|
|
369
|
+
return [this.col];
|
|
370
|
+
}
|
|
267
371
|
values() {
|
|
268
372
|
const { value } = this.getInfo();
|
|
269
373
|
return [value];
|
|
@@ -298,31 +402,76 @@ class websearchTosQueryClause extends tsQueryClause {
|
|
|
298
402
|
return "websearch_to_tsquery";
|
|
299
403
|
}
|
|
300
404
|
}
|
|
301
|
-
//
|
|
405
|
+
// postgres array operators
|
|
406
|
+
// https://www.postgresql.org/docs/current/functions-array.html
|
|
407
|
+
/**
|
|
408
|
+
* creates a clause to determine if the given value is contained 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 PostgresArrayContainsValue(col, value) {
|
|
413
|
+
return new postgresArrayOperator(col, value, "@>");
|
|
414
|
+
}
|
|
415
|
+
exports.PostgresArrayContainsValue = PostgresArrayContainsValue;
|
|
416
|
+
/**
|
|
417
|
+
* creates a clause to determine if every item in the list is stored in the array stored in the column in the db
|
|
418
|
+
* only works with postgres gin indexes
|
|
419
|
+
* https://www.postgresql.org/docs/current/indexes-types.html#INDEXES-TYPES-GIN
|
|
420
|
+
*/
|
|
421
|
+
function PostgresArrayContains(col, value) {
|
|
422
|
+
return new postgresArrayOperatorList(col, value, "@>");
|
|
423
|
+
}
|
|
424
|
+
exports.PostgresArrayContains = PostgresArrayContains;
|
|
425
|
+
/**
|
|
426
|
+
* creates a clause to determine if the given value is NOT contained in the array stored in the column in the db
|
|
427
|
+
* only works with postgres gin indexes
|
|
428
|
+
* https://www.postgresql.org/docs/current/indexes-types.html#INDEXES-TYPES-GIN
|
|
429
|
+
*/
|
|
430
|
+
function PostgresArrayNotContainsValue(col, value) {
|
|
431
|
+
return new postgresArrayOperator(col, value, "@>", true);
|
|
432
|
+
}
|
|
433
|
+
exports.PostgresArrayNotContainsValue = PostgresArrayNotContainsValue;
|
|
434
|
+
/**
|
|
435
|
+
* creates a clause to determine if every item in the list is NOT stored in the array stored in the column in the db
|
|
436
|
+
* only works with postgres gin indexes
|
|
437
|
+
* https://www.postgresql.org/docs/current/indexes-types.html#INDEXES-TYPES-GIN
|
|
438
|
+
*/
|
|
439
|
+
function PostgresArrayNotContains(col, value) {
|
|
440
|
+
return new postgresArrayOperatorList(col, value, "@>", true);
|
|
441
|
+
}
|
|
442
|
+
exports.PostgresArrayNotContains = PostgresArrayNotContains;
|
|
443
|
+
/**
|
|
444
|
+
* creates a clause to determine if the arrays overlap, that is, do they have any elements in common
|
|
445
|
+
* only works with postgres gin indexes
|
|
446
|
+
* https://www.postgresql.org/docs/current/indexes-types.html#INDEXES-TYPES-GIN
|
|
447
|
+
*/
|
|
448
|
+
function PostgresArrayOverlaps(col, value) {
|
|
449
|
+
return new postgresArrayOperatorList(col, value, "&&");
|
|
450
|
+
}
|
|
451
|
+
exports.PostgresArrayOverlaps = PostgresArrayOverlaps;
|
|
452
|
+
/**
|
|
453
|
+
* creates a clause to determine if the arrays do not overlap, that is, do they have any elements in common
|
|
454
|
+
* only works with postgres gin indexes
|
|
455
|
+
* https://www.postgresql.org/docs/current/indexes-types.html#INDEXES-TYPES-GIN
|
|
456
|
+
*/
|
|
457
|
+
function PostgresArrayNotOverlaps(col, value) {
|
|
458
|
+
return new postgresArrayOperatorList(col, value, "&&", true);
|
|
459
|
+
}
|
|
460
|
+
exports.PostgresArrayNotOverlaps = PostgresArrayNotOverlaps;
|
|
461
|
+
/**
|
|
462
|
+
* @deprecated use PostgresArrayContainsValue
|
|
463
|
+
*/
|
|
302
464
|
function ArrayEq(col, value) {
|
|
303
465
|
return new arraySimpleClause(col, value, "=");
|
|
304
466
|
}
|
|
305
467
|
exports.ArrayEq = ArrayEq;
|
|
468
|
+
/**
|
|
469
|
+
* @deprecated use PostgresNotArrayContains
|
|
470
|
+
*/
|
|
306
471
|
function ArrayNotEq(col, value) {
|
|
307
472
|
return new arraySimpleClause(col, value, "!=");
|
|
308
473
|
}
|
|
309
474
|
exports.ArrayNotEq = ArrayNotEq;
|
|
310
|
-
function ArrayGreater(col, value) {
|
|
311
|
-
return new arraySimpleClause(col, value, ">");
|
|
312
|
-
}
|
|
313
|
-
exports.ArrayGreater = ArrayGreater;
|
|
314
|
-
function ArrayLess(col, value) {
|
|
315
|
-
return new arraySimpleClause(col, value, "<");
|
|
316
|
-
}
|
|
317
|
-
exports.ArrayLess = ArrayLess;
|
|
318
|
-
function ArrayGreaterEq(col, value) {
|
|
319
|
-
return new arraySimpleClause(col, value, ">=");
|
|
320
|
-
}
|
|
321
|
-
exports.ArrayGreaterEq = ArrayGreaterEq;
|
|
322
|
-
function ArrayLessEq(col, value) {
|
|
323
|
-
return new arraySimpleClause(col, value, "<=");
|
|
324
|
-
}
|
|
325
|
-
exports.ArrayLessEq = ArrayLessEq;
|
|
326
475
|
function Eq(col, value) {
|
|
327
476
|
return new simpleClause(col, value, "=", new isNullClause(col));
|
|
328
477
|
}
|
|
@@ -364,9 +513,15 @@ function Or(...args) {
|
|
|
364
513
|
return new compositeClause(args, " OR ");
|
|
365
514
|
}
|
|
366
515
|
exports.Or = Or;
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
516
|
+
function In(...args) {
|
|
517
|
+
if (args.length < 2) {
|
|
518
|
+
throw new Error(`invalid args passed to In`);
|
|
519
|
+
}
|
|
520
|
+
// 2nd overload
|
|
521
|
+
if (Array.isArray(args[1])) {
|
|
522
|
+
return new inClause(args[0], args[1], args[2]);
|
|
523
|
+
}
|
|
524
|
+
return new inClause(args[0], args.slice(1));
|
|
370
525
|
}
|
|
371
526
|
exports.In = In;
|
|
372
527
|
// if string defaults to english
|
|
@@ -437,3 +592,55 @@ function sensitiveValue(val) {
|
|
|
437
592
|
};
|
|
438
593
|
}
|
|
439
594
|
exports.sensitiveValue = sensitiveValue;
|
|
595
|
+
// These don't return Clauses but return helpful things that can be passed to clauses
|
|
596
|
+
// https://www.postgresql.org/docs/12/functions-json.html#FUNCTIONS-JSON-OP-TABLE
|
|
597
|
+
// see test in db_clause.test.ts
|
|
598
|
+
// unclear best time to use this...
|
|
599
|
+
function JSONObjectFieldKeyASJSON(col, field) {
|
|
600
|
+
return `${col}->'${field}'`;
|
|
601
|
+
}
|
|
602
|
+
exports.JSONObjectFieldKeyASJSON = JSONObjectFieldKeyASJSON;
|
|
603
|
+
function JSONObjectFieldKeyAsText(col, field) {
|
|
604
|
+
return `${col}->>'${field}'`;
|
|
605
|
+
}
|
|
606
|
+
exports.JSONObjectFieldKeyAsText = JSONObjectFieldKeyAsText;
|
|
607
|
+
class jSONPathValuePredicateClause {
|
|
608
|
+
constructor(col, path, value, pred) {
|
|
609
|
+
this.col = col;
|
|
610
|
+
this.path = path;
|
|
611
|
+
this.value = value;
|
|
612
|
+
this.pred = pred;
|
|
613
|
+
}
|
|
614
|
+
clause(idx) {
|
|
615
|
+
if (db_1.default.getDialect() !== db_1.Dialect.Postgres) {
|
|
616
|
+
throw new Error(`not supported`);
|
|
617
|
+
}
|
|
618
|
+
return `${this.col} @@ $${idx}`;
|
|
619
|
+
}
|
|
620
|
+
columns() {
|
|
621
|
+
return [this.col];
|
|
622
|
+
}
|
|
623
|
+
wrap(val) {
|
|
624
|
+
return `${this.path} ${this.pred} ${JSON.stringify(val)}`;
|
|
625
|
+
}
|
|
626
|
+
values() {
|
|
627
|
+
if (isSensitive(this.value)) {
|
|
628
|
+
return [this.wrap(this.value.value())];
|
|
629
|
+
}
|
|
630
|
+
return [this.wrap(this.value)];
|
|
631
|
+
}
|
|
632
|
+
logValues() {
|
|
633
|
+
if (isSensitive(this.value)) {
|
|
634
|
+
return [this.wrap(this.value.logValue())];
|
|
635
|
+
}
|
|
636
|
+
return [this.wrap(this.value)];
|
|
637
|
+
}
|
|
638
|
+
instanceKey() {
|
|
639
|
+
return `${this.col}${this.path}${rawValue(this.value)}${this.pred}`;
|
|
640
|
+
}
|
|
641
|
+
}
|
|
642
|
+
// https://www.postgresql.org/docs/12/functions-json.html#FUNCTIONS-JSON-OP-TABLE
|
|
643
|
+
function JSONPathValuePredicate(dbCol, path, val, pred) {
|
|
644
|
+
return new jSONPathValuePredicateClause(dbCol, path, val, pred);
|
|
645
|
+
}
|
|
646
|
+
exports.JSONPathValuePredicate = JSONPathValuePredicate;
|
package/core/config.d.ts
CHANGED
|
@@ -20,6 +20,7 @@ export interface Config {
|
|
|
20
20
|
log?: logType | logType[];
|
|
21
21
|
codegen?: CodegenConfig;
|
|
22
22
|
customGraphQLJSONPath?: string;
|
|
23
|
+
globalSchemaPath?: string;
|
|
23
24
|
}
|
|
24
25
|
interface CodegenConfig {
|
|
25
26
|
defaultEntPolicy?: PrivacyConfig;
|
|
@@ -35,6 +36,8 @@ interface CodegenConfig {
|
|
|
35
36
|
schemaSQLFilePath?: boolean;
|
|
36
37
|
databaseToCompareTo?: string;
|
|
37
38
|
fieldPrivacyEvaluated?: fieldPrivacyEvaluated;
|
|
39
|
+
templatizedViewer?: importedObject;
|
|
40
|
+
customAssocEdgePath?: importedObject;
|
|
38
41
|
}
|
|
39
42
|
interface PrettierConfig {
|
|
40
43
|
custom?: boolean;
|
|
@@ -45,5 +48,10 @@ interface PrivacyConfig {
|
|
|
45
48
|
policyName: string;
|
|
46
49
|
class?: boolean;
|
|
47
50
|
}
|
|
51
|
+
interface importedObject {
|
|
52
|
+
path: string;
|
|
53
|
+
name: string;
|
|
54
|
+
alias?: string;
|
|
55
|
+
}
|
|
48
56
|
export declare function loadConfig(file?: string | Buffer | Config): void;
|
|
49
57
|
export {};
|
package/core/context.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
-
import { Viewer, Data, Loader } from "./base";
|
|
2
|
+
import { Viewer, Data, Loader, Ent } 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;
|
|
@@ -14,12 +14,14 @@ export declare class ContextCache {
|
|
|
14
14
|
getLoader<T, V>(name: string, create: () => Loader<T, V>): Loader<T, V>;
|
|
15
15
|
private itemMap;
|
|
16
16
|
private listMap;
|
|
17
|
+
private entCache;
|
|
17
18
|
private getkey;
|
|
18
19
|
getCachedRows(options: queryOptions): Data[] | null;
|
|
19
20
|
getCachedRow(options: queryOptions): Data | null;
|
|
20
21
|
primeCache(options: queryOptions, rows: Data[]): void;
|
|
21
22
|
primeCache(options: queryOptions, rows: Data): void;
|
|
22
23
|
clearCache(): void;
|
|
24
|
+
getEntCache(): Map<string, Error | Ent<any> | null>;
|
|
23
25
|
}
|
|
24
26
|
interface queryOptions {
|
|
25
27
|
fields: string[];
|
package/core/context.js
CHANGED
|
@@ -8,6 +8,7 @@ class ContextCache {
|
|
|
8
8
|
// we have a per-table map to make it easier to purge and have less things to compare with
|
|
9
9
|
this.itemMap = new Map();
|
|
10
10
|
this.listMap = new Map();
|
|
11
|
+
this.entCache = new Map();
|
|
11
12
|
}
|
|
12
13
|
getLoader(name, create) {
|
|
13
14
|
let l = this.loaders.get(name);
|
|
@@ -39,7 +40,7 @@ class ContextCache {
|
|
|
39
40
|
const key = this.getkey(options);
|
|
40
41
|
let rows = m.get(key);
|
|
41
42
|
if (rows) {
|
|
42
|
-
(0, logger_1.log)("
|
|
43
|
+
(0, logger_1.log)("cache", {
|
|
43
44
|
"cache-hit": key,
|
|
44
45
|
"tableName": options.tableName,
|
|
45
46
|
});
|
|
@@ -54,7 +55,7 @@ class ContextCache {
|
|
|
54
55
|
const key = this.getkey(options);
|
|
55
56
|
let row = m.get(key);
|
|
56
57
|
if (row) {
|
|
57
|
-
(0, logger_1.log)("
|
|
58
|
+
(0, logger_1.log)("cache", {
|
|
58
59
|
"cache-hit": key,
|
|
59
60
|
"tableName": options.tableName,
|
|
60
61
|
});
|
|
@@ -82,6 +83,10 @@ class ContextCache {
|
|
|
82
83
|
this.loaders.clear();
|
|
83
84
|
this.itemMap.clear();
|
|
84
85
|
this.listMap.clear();
|
|
86
|
+
this.entCache.clear();
|
|
87
|
+
}
|
|
88
|
+
getEntCache() {
|
|
89
|
+
return this.entCache;
|
|
85
90
|
}
|
|
86
91
|
}
|
|
87
92
|
exports.ContextCache = ContextCache;
|
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
|
@@ -5,7 +5,6 @@ export interface Database extends PoolConfig {
|
|
|
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";
|
|
@@ -29,7 +28,7 @@ export default class DB {
|
|
|
29
28
|
getConnection(): Connection;
|
|
30
29
|
getPool(): Queryer;
|
|
31
30
|
getNewClient(): Promise<Client>;
|
|
32
|
-
getSQLiteClient():
|
|
31
|
+
getSQLiteClient(): Sqlite;
|
|
33
32
|
endPool(): Promise<void>;
|
|
34
33
|
static getInstance(): DB;
|
|
35
34
|
static getDialect(): Dialect;
|