@snowtop/ent 0.1.0-alpha9 → 0.1.0-alpha90
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 +36 -31
- package/action/action.js +2 -6
- 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 +38 -16
- package/action/orchestrator.js +219 -61
- package/action/privacy.d.ts +2 -2
- package/core/base.d.ts +45 -24
- package/core/base.js +7 -1
- package/core/clause.d.ts +68 -7
- package/core/clause.js +291 -62
- package/core/config.d.ts +8 -0
- package/core/context.d.ts +5 -3
- package/core/context.js +20 -2
- package/core/convert.d.ts +1 -1
- package/core/db.d.ts +2 -2
- package/core/db.js +1 -1
- package/core/ent.d.ts +79 -24
- package/core/ent.js +520 -168
- 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/index.d.ts +1 -1
- package/core/loaders/index.js +1 -3
- package/core/loaders/index_loader.d.ts +2 -2
- package/core/loaders/loader.js +5 -5
- package/core/loaders/object_loader.d.ts +6 -5
- package/core/loaders/object_loader.js +62 -58
- package/core/loaders/query_loader.d.ts +6 -12
- package/core/loaders/query_loader.js +47 -10
- 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_clause_query.d.ts +24 -0
- package/core/query/custom_clause_query.js +72 -0
- package/core/query/custom_query.d.ts +20 -5
- package/core/query/custom_query.js +77 -10
- package/core/query/index.d.ts +1 -0
- package/core/query/index.js +3 -1
- package/core/query/query.d.ts +1 -1
- package/core/query/query.js +8 -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 +211 -30
- package/core/viewer.d.ts +3 -3
- package/core/viewer.js +1 -1
- package/graphql/graphql.js +6 -0
- package/graphql/query/edge_connection.d.ts +9 -9
- package/graphql/query/page_info.d.ts +1 -1
- package/index.d.ts +11 -5
- package/index.js +15 -6
- package/package.json +1 -1
- package/parse_schema/parse.d.ts +12 -3
- package/parse_schema/parse.js +70 -11
- package/schema/base_schema.js +3 -0
- package/schema/field.d.ts +44 -8
- package/schema/field.js +125 -9
- 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 +65 -11
- package/schema/schema.js +18 -4
- package/schema/struct_field.d.ts +11 -1
- package/schema/struct_field.js +44 -5
- package/scripts/custom_graphql.js +8 -3
- 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 +15 -4
- package/testutils/builder.d.ts +31 -21
- package/testutils/builder.js +83 -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} +70 -16
- 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/fake_data/fake_contact.d.ts +5 -4
- package/testutils/fake_data/fake_contact.js +14 -6
- package/testutils/fake_data/fake_event.d.ts +5 -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 +3 -2
- package/testutils/fake_data/test_helpers.js +8 -6
- package/testutils/fake_data/user_query.d.ts +8 -6
- package/testutils/fake_data/user_query.js +28 -21
- 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 -445
package/core/clause.d.ts
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
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[];
|
|
7
|
+
compositeOp?: string;
|
|
6
8
|
}
|
|
7
9
|
export interface SensitiveValue {
|
|
8
10
|
value(): any;
|
|
@@ -12,10 +14,23 @@ declare class simpleClause implements Clause {
|
|
|
12
14
|
protected col: string;
|
|
13
15
|
private value;
|
|
14
16
|
private op;
|
|
15
|
-
private
|
|
16
|
-
constructor(col: string, value: any, op: string,
|
|
17
|
+
private handleNull?;
|
|
18
|
+
constructor(col: string, value: any, op: string, handleNull?: Clause | undefined);
|
|
17
19
|
clause(idx: number): string;
|
|
18
|
-
private
|
|
20
|
+
private nullClause;
|
|
21
|
+
columns(): string[];
|
|
22
|
+
values(): any[];
|
|
23
|
+
logValues(): any[];
|
|
24
|
+
instanceKey(): string;
|
|
25
|
+
}
|
|
26
|
+
export declare class inClause implements Clause {
|
|
27
|
+
private col;
|
|
28
|
+
private value;
|
|
29
|
+
private type;
|
|
30
|
+
static getPostgresInClauseValuesThreshold(): number;
|
|
31
|
+
constructor(col: string, value: any[], type?: string);
|
|
32
|
+
clause(idx: number): string;
|
|
33
|
+
columns(): string[];
|
|
19
34
|
values(): any[];
|
|
20
35
|
logValues(): any[];
|
|
21
36
|
instanceKey(): string;
|
|
@@ -23,18 +38,58 @@ declare class simpleClause implements Clause {
|
|
|
23
38
|
declare class compositeClause implements Clause {
|
|
24
39
|
private clauses;
|
|
25
40
|
private sep;
|
|
41
|
+
compositeOp: string;
|
|
26
42
|
constructor(clauses: Clause[], sep: string);
|
|
27
43
|
clause(idx: number): string;
|
|
44
|
+
columns(): string[];
|
|
28
45
|
values(): any[];
|
|
29
46
|
logValues(): any[];
|
|
30
47
|
instanceKey(): string;
|
|
31
48
|
}
|
|
49
|
+
/**
|
|
50
|
+
* creates a clause to determine if the given value is contained in the array stored in the column in the db
|
|
51
|
+
* only works with postgres gin indexes
|
|
52
|
+
* https://www.postgresql.org/docs/current/indexes-types.html#INDEXES-TYPES-GIN
|
|
53
|
+
*/
|
|
54
|
+
export declare function PostgresArrayContainsValue(col: string, value: any): Clause;
|
|
55
|
+
/**
|
|
56
|
+
* creates a clause to determine if every item in the list is stored in the array stored in the column in the db
|
|
57
|
+
* only works with postgres gin indexes
|
|
58
|
+
* https://www.postgresql.org/docs/current/indexes-types.html#INDEXES-TYPES-GIN
|
|
59
|
+
*/
|
|
60
|
+
export declare function PostgresArrayContains(col: string, value: any[]): Clause;
|
|
61
|
+
/**
|
|
62
|
+
* creates a clause to determine if the given value is NOT contained in the array stored in the column in the db
|
|
63
|
+
* only works with postgres gin indexes
|
|
64
|
+
* https://www.postgresql.org/docs/current/indexes-types.html#INDEXES-TYPES-GIN
|
|
65
|
+
*/
|
|
66
|
+
export declare function PostgresArrayNotContainsValue(col: string, value: any): Clause;
|
|
67
|
+
/**
|
|
68
|
+
* creates a clause to determine if every item in the list is NOT stored in the array stored in the column in the db
|
|
69
|
+
* only works with postgres gin indexes
|
|
70
|
+
* https://www.postgresql.org/docs/current/indexes-types.html#INDEXES-TYPES-GIN
|
|
71
|
+
*/
|
|
72
|
+
export declare function PostgresArrayNotContains(col: string, value: any[]): Clause;
|
|
73
|
+
/**
|
|
74
|
+
* creates a clause to determine if the arrays overlap, that is, do they have any elements in common
|
|
75
|
+
* only works with postgres gin indexes
|
|
76
|
+
* https://www.postgresql.org/docs/current/indexes-types.html#INDEXES-TYPES-GIN
|
|
77
|
+
*/
|
|
78
|
+
export declare function PostgresArrayOverlaps(col: string, value: any[]): Clause;
|
|
79
|
+
/**
|
|
80
|
+
* creates a clause to determine if the arrays do not overlap, that is, do they have any elements in common
|
|
81
|
+
* only works with postgres gin indexes
|
|
82
|
+
* https://www.postgresql.org/docs/current/indexes-types.html#INDEXES-TYPES-GIN
|
|
83
|
+
*/
|
|
84
|
+
export declare function PostgresArrayNotOverlaps(col: string, value: any[]): Clause;
|
|
85
|
+
/**
|
|
86
|
+
* @deprecated use PostgresArrayContainsValue
|
|
87
|
+
*/
|
|
32
88
|
export declare function ArrayEq(col: string, value: any): Clause;
|
|
89
|
+
/**
|
|
90
|
+
* @deprecated use PostgresNotArrayContains
|
|
91
|
+
*/
|
|
33
92
|
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
93
|
export declare function Eq(col: string, value: any): Clause;
|
|
39
94
|
export declare function NotEq(col: string, value: any): Clause;
|
|
40
95
|
export declare function Greater(col: string, value: any): simpleClause;
|
|
@@ -44,7 +99,9 @@ export declare function LessEq(col: string, value: any): simpleClause;
|
|
|
44
99
|
export declare function And(...args: Clause[]): compositeClause;
|
|
45
100
|
export declare function AndOptional(...args: (Clause | undefined)[]): Clause;
|
|
46
101
|
export declare function Or(...args: Clause[]): compositeClause;
|
|
102
|
+
export declare function OrOptional(...args: (Clause | undefined)[]): Clause;
|
|
47
103
|
export declare function In(col: string, ...values: any): Clause;
|
|
104
|
+
export declare function In(col: string, values: any[], type?: string): Clause;
|
|
48
105
|
interface TsQuery {
|
|
49
106
|
language: "english" | "french" | "german" | "simple";
|
|
50
107
|
value: string;
|
|
@@ -58,4 +115,8 @@ export declare function TsVectorPlainToTsQuery(col: string, val: string | TsQuer
|
|
|
58
115
|
export declare function TsVectorPhraseToTsQuery(col: string, val: string | TsQuery): Clause;
|
|
59
116
|
export declare function TsVectorWebsearchToTsQuery(col: string, val: string | TsQuery): Clause;
|
|
60
117
|
export declare function sensitiveValue(val: any): SensitiveValue;
|
|
118
|
+
export declare function JSONObjectFieldKeyASJSON(col: string, field: string): string;
|
|
119
|
+
export declare function JSONObjectFieldKeyAsText(col: string, field: string): string;
|
|
120
|
+
declare type predicate = "==" | ">" | "<" | "!=" | ">=" | "<=";
|
|
121
|
+
export declare function JSONPathValuePredicate(dbCol: string, path: string, val: any, pred: predicate): Clause;
|
|
61
122
|
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.OrOptional = 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,35 +33,35 @@ 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.
|
|
52
|
+
nullClause() {
|
|
53
|
+
if (!this.handleNull || this.value !== null) {
|
|
54
54
|
return;
|
|
55
55
|
}
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
return this.
|
|
56
|
+
return this.handleNull;
|
|
57
|
+
}
|
|
58
|
+
columns() {
|
|
59
|
+
return [this.col];
|
|
60
60
|
}
|
|
61
61
|
values() {
|
|
62
|
-
const
|
|
63
|
-
if (
|
|
64
|
-
return
|
|
62
|
+
const nullClause = this.nullClause();
|
|
63
|
+
if (nullClause) {
|
|
64
|
+
return nullClause.values();
|
|
65
65
|
}
|
|
66
66
|
if (isSensitive(this.value)) {
|
|
67
67
|
return [this.value.value()];
|
|
@@ -69,9 +69,9 @@ class simpleClause {
|
|
|
69
69
|
return [this.value];
|
|
70
70
|
}
|
|
71
71
|
logValues() {
|
|
72
|
-
const
|
|
73
|
-
if (
|
|
74
|
-
return
|
|
72
|
+
const nullClause = this.nullClause();
|
|
73
|
+
if (nullClause) {
|
|
74
|
+
return nullClause.logValues();
|
|
75
75
|
}
|
|
76
76
|
if (isSensitive(this.value)) {
|
|
77
77
|
return [this.value.logValue()];
|
|
@@ -79,9 +79,9 @@ class simpleClause {
|
|
|
79
79
|
return [this.value];
|
|
80
80
|
}
|
|
81
81
|
instanceKey() {
|
|
82
|
-
const
|
|
83
|
-
if (
|
|
84
|
-
return
|
|
82
|
+
const nullClause = this.nullClause();
|
|
83
|
+
if (nullClause) {
|
|
84
|
+
return nullClause.instanceKey();
|
|
85
85
|
}
|
|
86
86
|
return `${this.col}${this.op}${rawValue(this.value)}`;
|
|
87
87
|
}
|
|
@@ -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,19 +295,33 @@ 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;
|
|
208
302
|
this.sep = sep;
|
|
303
|
+
this.compositeOp = this.sep;
|
|
209
304
|
}
|
|
210
305
|
clause(idx) {
|
|
211
306
|
let clauses = [];
|
|
212
307
|
for (const clause of this.clauses) {
|
|
213
|
-
|
|
308
|
+
let cls = clause.clause(idx);
|
|
309
|
+
// if composite clause and a different op, add parens so that we enforce order of precedence
|
|
310
|
+
if (clause.compositeOp && clause.compositeOp !== this.sep) {
|
|
311
|
+
cls = `(${cls})`;
|
|
312
|
+
}
|
|
313
|
+
clauses.push(cls);
|
|
214
314
|
idx = idx + clause.values().length;
|
|
215
315
|
}
|
|
216
316
|
return clauses.join(this.sep);
|
|
217
317
|
}
|
|
318
|
+
columns() {
|
|
319
|
+
const ret = [];
|
|
320
|
+
for (const cls of this.clauses) {
|
|
321
|
+
ret.push(...cls.columns());
|
|
322
|
+
}
|
|
323
|
+
return ret;
|
|
324
|
+
}
|
|
218
325
|
values() {
|
|
219
326
|
let result = [];
|
|
220
327
|
for (const clause of this.clauses) {
|
|
@@ -231,7 +338,14 @@ class compositeClause {
|
|
|
231
338
|
}
|
|
232
339
|
instanceKey() {
|
|
233
340
|
let keys = [];
|
|
234
|
-
this.clauses.forEach((clause) =>
|
|
341
|
+
this.clauses.forEach((clause) => {
|
|
342
|
+
if (clause.compositeOp && clause.compositeOp != this.sep) {
|
|
343
|
+
keys.push(`(${clause.instanceKey()})`);
|
|
344
|
+
}
|
|
345
|
+
else {
|
|
346
|
+
keys.push(clause.instanceKey());
|
|
347
|
+
}
|
|
348
|
+
});
|
|
235
349
|
return keys.join(this.sep);
|
|
236
350
|
}
|
|
237
351
|
}
|
|
@@ -264,6 +378,9 @@ class tsQueryClause {
|
|
|
264
378
|
// FYI this doesn't actually work for sqlite since different
|
|
265
379
|
return `${this.col} @@ ${this.getFunction()}('${language}', ?)`;
|
|
266
380
|
}
|
|
381
|
+
columns() {
|
|
382
|
+
return [this.col];
|
|
383
|
+
}
|
|
267
384
|
values() {
|
|
268
385
|
const { value } = this.getInfo();
|
|
269
386
|
return [value];
|
|
@@ -298,31 +415,76 @@ class websearchTosQueryClause extends tsQueryClause {
|
|
|
298
415
|
return "websearch_to_tsquery";
|
|
299
416
|
}
|
|
300
417
|
}
|
|
301
|
-
//
|
|
418
|
+
// postgres array operators
|
|
419
|
+
// https://www.postgresql.org/docs/current/functions-array.html
|
|
420
|
+
/**
|
|
421
|
+
* creates a clause to determine if the given value is contained in the array stored in the column in the db
|
|
422
|
+
* only works with postgres gin indexes
|
|
423
|
+
* https://www.postgresql.org/docs/current/indexes-types.html#INDEXES-TYPES-GIN
|
|
424
|
+
*/
|
|
425
|
+
function PostgresArrayContainsValue(col, value) {
|
|
426
|
+
return new postgresArrayOperator(col, value, "@>");
|
|
427
|
+
}
|
|
428
|
+
exports.PostgresArrayContainsValue = PostgresArrayContainsValue;
|
|
429
|
+
/**
|
|
430
|
+
* creates a clause to determine if every item in the list is stored in the array stored in the column in the db
|
|
431
|
+
* only works with postgres gin indexes
|
|
432
|
+
* https://www.postgresql.org/docs/current/indexes-types.html#INDEXES-TYPES-GIN
|
|
433
|
+
*/
|
|
434
|
+
function PostgresArrayContains(col, value) {
|
|
435
|
+
return new postgresArrayOperatorList(col, value, "@>");
|
|
436
|
+
}
|
|
437
|
+
exports.PostgresArrayContains = PostgresArrayContains;
|
|
438
|
+
/**
|
|
439
|
+
* creates a clause to determine if the given value is NOT contained in the array stored in the column in the db
|
|
440
|
+
* only works with postgres gin indexes
|
|
441
|
+
* https://www.postgresql.org/docs/current/indexes-types.html#INDEXES-TYPES-GIN
|
|
442
|
+
*/
|
|
443
|
+
function PostgresArrayNotContainsValue(col, value) {
|
|
444
|
+
return new postgresArrayOperator(col, value, "@>", true);
|
|
445
|
+
}
|
|
446
|
+
exports.PostgresArrayNotContainsValue = PostgresArrayNotContainsValue;
|
|
447
|
+
/**
|
|
448
|
+
* creates a clause to determine if every item in the list is NOT stored in the array stored in the column in the db
|
|
449
|
+
* only works with postgres gin indexes
|
|
450
|
+
* https://www.postgresql.org/docs/current/indexes-types.html#INDEXES-TYPES-GIN
|
|
451
|
+
*/
|
|
452
|
+
function PostgresArrayNotContains(col, value) {
|
|
453
|
+
return new postgresArrayOperatorList(col, value, "@>", true);
|
|
454
|
+
}
|
|
455
|
+
exports.PostgresArrayNotContains = PostgresArrayNotContains;
|
|
456
|
+
/**
|
|
457
|
+
* creates a clause to determine if the arrays overlap, that is, do they have any elements in common
|
|
458
|
+
* only works with postgres gin indexes
|
|
459
|
+
* https://www.postgresql.org/docs/current/indexes-types.html#INDEXES-TYPES-GIN
|
|
460
|
+
*/
|
|
461
|
+
function PostgresArrayOverlaps(col, value) {
|
|
462
|
+
return new postgresArrayOperatorList(col, value, "&&");
|
|
463
|
+
}
|
|
464
|
+
exports.PostgresArrayOverlaps = PostgresArrayOverlaps;
|
|
465
|
+
/**
|
|
466
|
+
* creates a clause to determine if the arrays do not overlap, that is, do they have any elements in common
|
|
467
|
+
* only works with postgres gin indexes
|
|
468
|
+
* https://www.postgresql.org/docs/current/indexes-types.html#INDEXES-TYPES-GIN
|
|
469
|
+
*/
|
|
470
|
+
function PostgresArrayNotOverlaps(col, value) {
|
|
471
|
+
return new postgresArrayOperatorList(col, value, "&&", true);
|
|
472
|
+
}
|
|
473
|
+
exports.PostgresArrayNotOverlaps = PostgresArrayNotOverlaps;
|
|
474
|
+
/**
|
|
475
|
+
* @deprecated use PostgresArrayContainsValue
|
|
476
|
+
*/
|
|
302
477
|
function ArrayEq(col, value) {
|
|
303
478
|
return new arraySimpleClause(col, value, "=");
|
|
304
479
|
}
|
|
305
480
|
exports.ArrayEq = ArrayEq;
|
|
481
|
+
/**
|
|
482
|
+
* @deprecated use PostgresNotArrayContains
|
|
483
|
+
*/
|
|
306
484
|
function ArrayNotEq(col, value) {
|
|
307
485
|
return new arraySimpleClause(col, value, "!=");
|
|
308
486
|
}
|
|
309
487
|
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
488
|
function Eq(col, value) {
|
|
327
489
|
return new simpleClause(col, value, "=", new isNullClause(col));
|
|
328
490
|
}
|
|
@@ -364,9 +526,24 @@ function Or(...args) {
|
|
|
364
526
|
return new compositeClause(args, " OR ");
|
|
365
527
|
}
|
|
366
528
|
exports.Or = Or;
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
529
|
+
function OrOptional(...args) {
|
|
530
|
+
// @ts-ignore
|
|
531
|
+
let filtered = args.filter((v) => v !== undefined);
|
|
532
|
+
if (filtered.length === 1) {
|
|
533
|
+
return filtered[0];
|
|
534
|
+
}
|
|
535
|
+
return Or(...filtered);
|
|
536
|
+
}
|
|
537
|
+
exports.OrOptional = OrOptional;
|
|
538
|
+
function In(...args) {
|
|
539
|
+
if (args.length < 2) {
|
|
540
|
+
throw new Error(`invalid args passed to In`);
|
|
541
|
+
}
|
|
542
|
+
// 2nd overload
|
|
543
|
+
if (Array.isArray(args[1])) {
|
|
544
|
+
return new inClause(args[0], args[1], args[2]);
|
|
545
|
+
}
|
|
546
|
+
return new inClause(args[0], args.slice(1));
|
|
370
547
|
}
|
|
371
548
|
exports.In = In;
|
|
372
549
|
// if string defaults to english
|
|
@@ -437,3 +614,55 @@ function sensitiveValue(val) {
|
|
|
437
614
|
};
|
|
438
615
|
}
|
|
439
616
|
exports.sensitiveValue = sensitiveValue;
|
|
617
|
+
// These don't return Clauses but return helpful things that can be passed to clauses
|
|
618
|
+
// https://www.postgresql.org/docs/12/functions-json.html#FUNCTIONS-JSON-OP-TABLE
|
|
619
|
+
// see test in db_clause.test.ts
|
|
620
|
+
// unclear best time to use this...
|
|
621
|
+
function JSONObjectFieldKeyASJSON(col, field) {
|
|
622
|
+
return `${col}->'${field}'`;
|
|
623
|
+
}
|
|
624
|
+
exports.JSONObjectFieldKeyASJSON = JSONObjectFieldKeyASJSON;
|
|
625
|
+
function JSONObjectFieldKeyAsText(col, field) {
|
|
626
|
+
return `${col}->>'${field}'`;
|
|
627
|
+
}
|
|
628
|
+
exports.JSONObjectFieldKeyAsText = JSONObjectFieldKeyAsText;
|
|
629
|
+
class jSONPathValuePredicateClause {
|
|
630
|
+
constructor(col, path, value, pred) {
|
|
631
|
+
this.col = col;
|
|
632
|
+
this.path = path;
|
|
633
|
+
this.value = value;
|
|
634
|
+
this.pred = pred;
|
|
635
|
+
}
|
|
636
|
+
clause(idx) {
|
|
637
|
+
if (db_1.default.getDialect() !== db_1.Dialect.Postgres) {
|
|
638
|
+
throw new Error(`not supported`);
|
|
639
|
+
}
|
|
640
|
+
return `${this.col} @@ $${idx}`;
|
|
641
|
+
}
|
|
642
|
+
columns() {
|
|
643
|
+
return [this.col];
|
|
644
|
+
}
|
|
645
|
+
wrap(val) {
|
|
646
|
+
return `${this.path} ${this.pred} ${JSON.stringify(val)}`;
|
|
647
|
+
}
|
|
648
|
+
values() {
|
|
649
|
+
if (isSensitive(this.value)) {
|
|
650
|
+
return [this.wrap(this.value.value())];
|
|
651
|
+
}
|
|
652
|
+
return [this.wrap(this.value)];
|
|
653
|
+
}
|
|
654
|
+
logValues() {
|
|
655
|
+
if (isSensitive(this.value)) {
|
|
656
|
+
return [this.wrap(this.value.logValue())];
|
|
657
|
+
}
|
|
658
|
+
return [this.wrap(this.value)];
|
|
659
|
+
}
|
|
660
|
+
instanceKey() {
|
|
661
|
+
return `${this.col}${this.path}${rawValue(this.value)}${this.pred}`;
|
|
662
|
+
}
|
|
663
|
+
}
|
|
664
|
+
// https://www.postgresql.org/docs/12/functions-json.html#FUNCTIONS-JSON-OP-TABLE
|
|
665
|
+
function JSONPathValuePredicate(dbCol, path, val, pred) {
|
|
666
|
+
return new jSONPathValuePredicateClause(dbCol, path, val, pred);
|
|
667
|
+
}
|
|
668
|
+
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,17 +1,19 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
-
import { Viewer, Data, Loader } from "./base";
|
|
2
|
+
import { Viewer, Data, Loader, LoaderWithLoadMany } 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;
|
|
11
11
|
}
|
|
12
12
|
export declare class ContextCache {
|
|
13
13
|
loaders: Map<string, Loader<any, any>>;
|
|
14
|
+
loaderWithLoadMany: Map<string, LoaderWithLoadMany<any, any>>;
|
|
14
15
|
getLoader<T, V>(name: string, create: () => Loader<T, V>): Loader<T, V>;
|
|
16
|
+
getLoaderWithLoadMany<T, V>(name: string, create: () => LoaderWithLoadMany<T, V>): LoaderWithLoadMany<T, V>;
|
|
15
17
|
private itemMap;
|
|
16
18
|
private listMap;
|
|
17
19
|
private getkey;
|