@snowtop/ent 0.1.0-alpha16 → 0.1.0-alpha160-test1

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.
Files changed (176) hide show
  1. package/action/action.d.ts +25 -14
  2. package/action/action.js +22 -7
  3. package/action/executor.d.ts +16 -3
  4. package/action/executor.js +89 -28
  5. package/action/experimental_action.d.ts +25 -16
  6. package/action/experimental_action.js +34 -14
  7. package/action/index.d.ts +4 -1
  8. package/action/index.js +7 -1
  9. package/action/operations.d.ts +126 -0
  10. package/action/operations.js +686 -0
  11. package/action/orchestrator.d.ts +43 -12
  12. package/action/orchestrator.js +461 -101
  13. package/action/relative_value.d.ts +47 -0
  14. package/action/relative_value.js +125 -0
  15. package/action/transaction.d.ts +10 -0
  16. package/action/transaction.js +23 -0
  17. package/auth/auth.d.ts +1 -1
  18. package/core/base.d.ts +56 -23
  19. package/core/base.js +7 -1
  20. package/core/clause.d.ts +103 -39
  21. package/core/clause.js +430 -66
  22. package/core/config.d.ts +13 -3
  23. package/core/config.js +10 -1
  24. package/core/const.d.ts +3 -0
  25. package/core/const.js +6 -0
  26. package/core/context.d.ts +6 -3
  27. package/core/context.js +22 -3
  28. package/core/convert.d.ts +1 -1
  29. package/core/date.js +1 -5
  30. package/core/db.d.ts +12 -8
  31. package/core/db.js +21 -9
  32. package/core/ent.d.ts +99 -95
  33. package/core/ent.js +550 -602
  34. package/core/global_schema.d.ts +7 -0
  35. package/core/global_schema.js +51 -0
  36. package/core/loaders/assoc_count_loader.d.ts +5 -2
  37. package/core/loaders/assoc_count_loader.js +19 -3
  38. package/core/loaders/assoc_edge_loader.d.ts +2 -3
  39. package/core/loaders/assoc_edge_loader.js +23 -17
  40. package/core/loaders/index.d.ts +1 -2
  41. package/core/loaders/index.js +1 -5
  42. package/core/loaders/loader.d.ts +3 -3
  43. package/core/loaders/loader.js +4 -21
  44. package/core/loaders/object_loader.d.ts +30 -9
  45. package/core/loaders/object_loader.js +226 -79
  46. package/core/loaders/query_loader.d.ts +7 -13
  47. package/core/loaders/query_loader.js +60 -24
  48. package/core/loaders/raw_count_loader.d.ts +1 -0
  49. package/core/loaders/raw_count_loader.js +8 -3
  50. package/core/logger.d.ts +1 -1
  51. package/core/logger.js +1 -0
  52. package/core/privacy.d.ts +26 -16
  53. package/core/privacy.js +68 -51
  54. package/core/query/assoc_query.d.ts +3 -2
  55. package/core/query/assoc_query.js +10 -2
  56. package/core/query/custom_clause_query.d.ts +29 -0
  57. package/core/query/custom_clause_query.js +105 -0
  58. package/core/query/custom_query.d.ts +19 -2
  59. package/core/query/custom_query.js +111 -13
  60. package/core/query/index.d.ts +1 -0
  61. package/core/query/index.js +3 -1
  62. package/core/query/query.d.ts +18 -4
  63. package/core/query/query.js +135 -58
  64. package/core/query/shared_assoc_test.d.ts +2 -1
  65. package/core/query/shared_assoc_test.js +186 -55
  66. package/core/query/shared_test.d.ts +9 -2
  67. package/core/query/shared_test.js +529 -236
  68. package/core/query_impl.d.ts +8 -0
  69. package/core/query_impl.js +28 -0
  70. package/core/viewer.d.ts +2 -0
  71. package/core/viewer.js +3 -1
  72. package/graphql/graphql.d.ts +108 -22
  73. package/graphql/graphql.js +183 -137
  74. package/graphql/graphql_field_helpers.d.ts +9 -3
  75. package/graphql/graphql_field_helpers.js +22 -2
  76. package/graphql/index.d.ts +2 -2
  77. package/graphql/index.js +5 -5
  78. package/graphql/query/connection_type.d.ts +9 -9
  79. package/graphql/query/shared_assoc_test.js +1 -1
  80. package/graphql/query/shared_edge_connection.js +1 -19
  81. package/graphql/scalars/orderby_direction.d.ts +2 -0
  82. package/graphql/scalars/orderby_direction.js +15 -0
  83. package/imports/dataz/example1/_auth.js +128 -47
  84. package/imports/dataz/example1/_viewer.js +87 -39
  85. package/imports/index.d.ts +7 -2
  86. package/imports/index.js +20 -5
  87. package/index.d.ts +23 -5
  88. package/index.js +35 -10
  89. package/package.json +19 -19
  90. package/parse_schema/parse.d.ts +33 -9
  91. package/parse_schema/parse.js +182 -33
  92. package/schema/base_schema.d.ts +13 -3
  93. package/schema/base_schema.js +13 -0
  94. package/schema/field.d.ts +78 -21
  95. package/schema/field.js +232 -72
  96. package/schema/index.d.ts +2 -2
  97. package/schema/index.js +7 -2
  98. package/schema/json_field.d.ts +16 -4
  99. package/schema/json_field.js +32 -2
  100. package/schema/schema.d.ts +109 -20
  101. package/schema/schema.js +42 -53
  102. package/schema/struct_field.d.ts +15 -3
  103. package/schema/struct_field.js +117 -22
  104. package/schema/union_field.d.ts +1 -1
  105. package/scripts/custom_compiler.js +12 -8
  106. package/scripts/custom_graphql.js +171 -64
  107. package/scripts/migrate_v0.1.js +36 -0
  108. package/scripts/move_types.js +120 -0
  109. package/scripts/read_schema.js +22 -7
  110. package/testutils/action/complex_schemas.d.ts +69 -0
  111. package/testutils/action/complex_schemas.js +405 -0
  112. package/testutils/builder.d.ts +37 -41
  113. package/testutils/builder.js +66 -46
  114. package/testutils/db/fixture.d.ts +10 -0
  115. package/testutils/db/fixture.js +26 -0
  116. package/testutils/db/{test_db.d.ts → temp_db.d.ts} +32 -8
  117. package/testutils/db/{test_db.js → temp_db.js} +251 -48
  118. package/testutils/db/value.d.ts +7 -0
  119. package/testutils/db/value.js +251 -0
  120. package/testutils/db_mock.d.ts +16 -4
  121. package/testutils/db_mock.js +52 -9
  122. package/testutils/db_time_zone.d.ts +4 -0
  123. package/testutils/db_time_zone.js +41 -0
  124. package/testutils/ent-graphql-tests/index.d.ts +7 -1
  125. package/testutils/ent-graphql-tests/index.js +56 -26
  126. package/testutils/fake_comms.js +1 -1
  127. package/testutils/fake_data/const.d.ts +2 -1
  128. package/testutils/fake_data/const.js +3 -0
  129. package/testutils/fake_data/fake_contact.d.ts +7 -3
  130. package/testutils/fake_data/fake_contact.js +13 -7
  131. package/testutils/fake_data/fake_event.d.ts +4 -1
  132. package/testutils/fake_data/fake_event.js +7 -6
  133. package/testutils/fake_data/fake_tag.d.ts +36 -0
  134. package/testutils/fake_data/fake_tag.js +89 -0
  135. package/testutils/fake_data/fake_user.d.ts +8 -5
  136. package/testutils/fake_data/fake_user.js +31 -19
  137. package/testutils/fake_data/index.js +5 -1
  138. package/testutils/fake_data/internal.d.ts +2 -0
  139. package/testutils/fake_data/internal.js +7 -1
  140. package/testutils/fake_data/tag_query.d.ts +13 -0
  141. package/testutils/fake_data/tag_query.js +48 -0
  142. package/testutils/fake_data/test_helpers.d.ts +14 -6
  143. package/testutils/fake_data/test_helpers.js +31 -15
  144. package/testutils/fake_data/user_query.d.ts +16 -6
  145. package/testutils/fake_data/user_query.js +72 -23
  146. package/testutils/fake_log.js +1 -1
  147. package/testutils/parse_sql.d.ts +6 -0
  148. package/testutils/parse_sql.js +16 -2
  149. package/testutils/test_edge_global_schema.d.ts +15 -0
  150. package/testutils/test_edge_global_schema.js +62 -0
  151. package/testutils/write.d.ts +2 -2
  152. package/testutils/write.js +33 -7
  153. package/tsc/ast.d.ts +15 -3
  154. package/tsc/ast.js +114 -23
  155. package/tsc/compilerOptions.js +5 -1
  156. package/tsc/move_generated.d.ts +1 -0
  157. package/tsc/move_generated.js +164 -0
  158. package/tsc/transform.d.ts +22 -0
  159. package/tsc/transform.js +182 -0
  160. package/tsc/transform_action.d.ts +22 -0
  161. package/tsc/transform_action.js +183 -0
  162. package/tsc/transform_ent.d.ts +17 -0
  163. package/tsc/transform_ent.js +60 -0
  164. package/tsc/transform_schema.d.ts +27 -0
  165. package/{scripts → tsc}/transform_schema.js +146 -117
  166. package/core/loaders/index_loader.d.ts +0 -14
  167. package/core/loaders/index_loader.js +0 -27
  168. package/graphql/enums.d.ts +0 -3
  169. package/graphql/enums.js +0 -25
  170. package/scripts/move_generated.js +0 -141
  171. package/scripts/transform_actions.js +0 -266
  172. package/scripts/transform_code.d.ts +0 -1
  173. package/scripts/transform_code.js +0 -111
  174. package/scripts/transform_schema.d.ts +0 -1
  175. /package/scripts/{move_generated.d.ts → migrate_v0.1.d.ts} +0 -0
  176. /package/scripts/{transform_actions.d.ts → move_types.d.ts} +0 -0
package/core/clause.js CHANGED
@@ -1,7 +1,11 @@
1
1
  "use strict";
2
2
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
3
  if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
5
9
  }) : (function(o, m, k, k2) {
6
10
  if (k2 === undefined) k2 = k;
7
11
  o[k2] = m[k];
@@ -19,7 +23,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
19
23
  return result;
20
24
  };
21
25
  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.ArrayLessEq = exports.ArrayGreaterEq = exports.ArrayLess = exports.ArrayGreater = exports.ArrayNotEq = exports.ArrayEq = void 0;
26
+ exports.getCombinedClause = exports.Modulo = exports.Divide = exports.Multiply = exports.Subtract = exports.Add = exports.PaginationMultipleColsSubQuery = 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.DBTypeNotIn = exports.TextNotIn = exports.IntegerNotIn = exports.UuidNotIn = exports.DBTypeIn = exports.TextIn = exports.IntegerIn = exports.UuidIn = 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.notInClause = exports.inClause = void 0;
23
27
  const db_1 = __importStar(require("./db"));
24
28
  function isSensitive(val) {
25
29
  return (val !== null &&
@@ -33,35 +37,35 @@ function rawValue(val) {
33
37
  return val;
34
38
  }
35
39
  class simpleClause {
36
- constructor(col, value, op, handleSqliteNull) {
40
+ constructor(col, value, op, handleNull) {
37
41
  this.col = col;
38
42
  this.value = value;
39
43
  this.op = op;
40
- this.handleSqliteNull = handleSqliteNull;
44
+ this.handleNull = handleNull;
41
45
  }
42
46
  clause(idx) {
43
- const sqliteClause = this.sqliteNull();
44
- if (sqliteClause) {
45
- return sqliteClause.clause(idx);
47
+ const nullClause = this.nullClause();
48
+ if (nullClause) {
49
+ return nullClause.clause(idx);
46
50
  }
47
51
  if (db_1.default.getDialect() === db_1.Dialect.Postgres) {
48
52
  return `${this.col} ${this.op} $${idx}`;
49
53
  }
50
54
  return `${this.col} ${this.op} ?`;
51
55
  }
52
- sqliteNull() {
53
- if (!this.handleSqliteNull || this.value !== null) {
54
- return;
55
- }
56
- if (db_1.default.getDialect() !== db_1.Dialect.SQLite) {
56
+ nullClause() {
57
+ if (!this.handleNull || this.value !== null) {
57
58
  return;
58
59
  }
59
- return this.handleSqliteNull;
60
+ return this.handleNull;
61
+ }
62
+ columns() {
63
+ return [this.col];
60
64
  }
61
65
  values() {
62
- const sqliteClause = this.sqliteNull();
63
- if (sqliteClause) {
64
- return sqliteClause.values();
66
+ const nullClause = this.nullClause();
67
+ if (nullClause) {
68
+ return nullClause.values();
65
69
  }
66
70
  if (isSensitive(this.value)) {
67
71
  return [this.value.value()];
@@ -69,9 +73,9 @@ class simpleClause {
69
73
  return [this.value];
70
74
  }
71
75
  logValues() {
72
- const sqliteClause = this.sqliteNull();
73
- if (sqliteClause) {
74
- return sqliteClause.logValues();
76
+ const nullClause = this.nullClause();
77
+ if (nullClause) {
78
+ return nullClause.logValues();
75
79
  }
76
80
  if (isSensitive(this.value)) {
77
81
  return [this.value.logValue()];
@@ -79,9 +83,9 @@ class simpleClause {
79
83
  return [this.value];
80
84
  }
81
85
  instanceKey() {
82
- const sqliteClause = this.sqliteNull();
83
- if (sqliteClause) {
84
- return sqliteClause.instanceKey();
86
+ const nullClause = this.nullClause();
87
+ if (nullClause) {
88
+ return nullClause.instanceKey();
85
89
  }
86
90
  return `${this.col}${this.op}${rawValue(this.value)}`;
87
91
  }
@@ -90,9 +94,12 @@ class isNullClause {
90
94
  constructor(col) {
91
95
  this.col = col;
92
96
  }
93
- clause(idx) {
97
+ clause(_idx) {
94
98
  return `${this.col} IS NULL`;
95
99
  }
100
+ columns() {
101
+ return [];
102
+ }
96
103
  values() {
97
104
  return [];
98
105
  }
@@ -110,6 +117,9 @@ class isNotNullClause {
110
117
  clause(idx) {
111
118
  return `${this.col} IS NOT NULL`;
112
119
  }
120
+ columns() {
121
+ return [];
122
+ }
113
123
  values() {
114
124
  return [];
115
125
  }
@@ -132,6 +142,9 @@ class arraySimpleClause {
132
142
  }
133
143
  return `${this.col} ${this.op} ?`;
134
144
  }
145
+ columns() {
146
+ return [this.col];
147
+ }
135
148
  values() {
136
149
  if (isSensitive(this.value)) {
137
150
  return [this.value.value()];
@@ -148,18 +161,111 @@ class arraySimpleClause {
148
161
  return `${this.col}${this.op}${rawValue(this.value)}`;
149
162
  }
150
163
  }
164
+ class postgresArrayOperator {
165
+ constructor(col, value, op, not) {
166
+ this.col = col;
167
+ this.value = value;
168
+ this.op = op;
169
+ this.not = not;
170
+ }
171
+ clause(idx) {
172
+ if (db_1.default.getDialect() === db_1.Dialect.Postgres) {
173
+ if (this.not) {
174
+ return `NOT ${this.col} ${this.op} $${idx}`;
175
+ }
176
+ return `${this.col} ${this.op} $${idx}`;
177
+ }
178
+ throw new Error(`not supported`);
179
+ }
180
+ columns() {
181
+ return [this.col];
182
+ }
183
+ values() {
184
+ if (isSensitive(this.value)) {
185
+ return [`{${this.value.value()}}`];
186
+ }
187
+ return [`{${this.value}}`];
188
+ }
189
+ logValues() {
190
+ if (isSensitive(this.value)) {
191
+ return [`{${this.value.logValue()}}`];
192
+ }
193
+ return [`{${this.value}}`];
194
+ }
195
+ instanceKey() {
196
+ if (this.not) {
197
+ return `NOT:${this.col}${this.op}${rawValue(this.value)}`;
198
+ }
199
+ return `${this.col}${this.op}${rawValue(this.value)}`;
200
+ }
201
+ }
202
+ class postgresArrayOperatorList extends postgresArrayOperator {
203
+ constructor(col, value, op, not) {
204
+ super(col, value, op, not);
205
+ }
206
+ values() {
207
+ return [
208
+ `{${this.value
209
+ .map((v) => {
210
+ if (isSensitive(v)) {
211
+ return v.value();
212
+ }
213
+ return v;
214
+ })
215
+ .join(", ")}}`,
216
+ ];
217
+ }
218
+ logValues() {
219
+ return [
220
+ `{${this.value
221
+ .map((v) => {
222
+ if (isSensitive(v)) {
223
+ return v.logValue();
224
+ }
225
+ return v;
226
+ })
227
+ .join(", ")}}`,
228
+ ];
229
+ }
230
+ }
151
231
  class inClause {
152
- constructor(col, value) {
232
+ static getPostgresInClauseValuesThreshold() {
233
+ return 70;
234
+ }
235
+ constructor(col, value, type = "uuid") {
153
236
  this.col = col;
154
237
  this.value = value;
238
+ this.type = type;
239
+ this.op = "IN";
155
240
  }
156
241
  clause(idx) {
157
- const dialect = db_1.default.getDialect();
242
+ // do a simple = when only one item
243
+ if (this.value.length === 1) {
244
+ if (this.op === "IN") {
245
+ return new simpleClause(this.col, this.value[0], "=").clause(idx);
246
+ }
247
+ else {
248
+ return new simpleClause(this.col, this.value[0], "!=").clause(idx);
249
+ }
250
+ }
251
+ const postgres = db_1.default.getDialect() === db_1.Dialect.Postgres;
252
+ const postgresValuesList = postgres &&
253
+ this.value.length >= inClause.getPostgresInClauseValuesThreshold();
158
254
  let indices;
159
- if (dialect === db_1.Dialect.Postgres) {
255
+ if (postgres) {
160
256
  indices = [];
161
257
  for (let i = 0; i < this.value.length; i++) {
162
- indices.push(`$${idx}`);
258
+ if (postgresValuesList) {
259
+ if (i === 0) {
260
+ indices.push(`($${idx}::${this.type})`);
261
+ }
262
+ else {
263
+ indices.push(`($${idx})`);
264
+ }
265
+ }
266
+ else {
267
+ indices.push(`$${idx}`);
268
+ }
163
269
  idx++;
164
270
  }
165
271
  }
@@ -167,54 +273,72 @@ class inClause {
167
273
  indices = new Array(this.value.length);
168
274
  indices.fill("?", 0);
169
275
  }
170
- const inValue = indices.join(", ");
171
- return `${this.col} IN (${inValue})`;
276
+ let inValue = indices.join(", ");
277
+ // wrap in VALUES list for postgres...
278
+ if (postgresValuesList) {
279
+ inValue = `VALUES${inValue}`;
280
+ }
281
+ return `${this.col} ${this.op} (${inValue})`;
172
282
  // TODO we need to return idx at end to query builder...
173
283
  // or anything that's doing a composite query so next clause knows where to start
174
284
  // or change to a sqlx.Rebind format
175
285
  // here's what sqlx does: https://play.golang.org/p/vPzvYqeAcP0
176
286
  }
287
+ columns() {
288
+ return [this.col];
289
+ }
177
290
  values() {
178
291
  const result = [];
179
- for (const value of this.value) {
180
- if (isSensitive(value)) {
181
- result.push(value.value());
182
- }
183
- else {
184
- result.push(value);
185
- }
292
+ for (let value of this.value) {
293
+ result.push(rawValue(value));
186
294
  }
187
295
  return result;
188
296
  }
189
297
  logValues() {
190
298
  const result = [];
191
- for (const value of this.value) {
192
- if (isSensitive(value)) {
193
- result.push(value.logValue());
194
- }
195
- else {
196
- result.push(value);
197
- }
299
+ for (let value of this.value) {
300
+ result.push(isSensitive(value) ? value.logValue() : value);
198
301
  }
199
302
  return result;
200
303
  }
201
304
  instanceKey() {
202
- return `in:${this.col}:${this.values().join(",")}`;
305
+ return `${this.op.toLowerCase()}:${this.col}:${this.values().join(",")}`;
203
306
  }
204
307
  }
308
+ exports.inClause = inClause;
309
+ class notInClause extends inClause {
310
+ constructor() {
311
+ super(...arguments);
312
+ this.op = "NOT IN";
313
+ }
314
+ }
315
+ exports.notInClause = notInClause;
205
316
  class compositeClause {
206
317
  constructor(clauses, sep) {
207
318
  this.clauses = clauses;
208
319
  this.sep = sep;
320
+ this.compositeOp = this.sep;
209
321
  }
210
322
  clause(idx) {
211
323
  let clauses = [];
212
324
  for (const clause of this.clauses) {
213
- clauses.push(clause.clause(idx));
325
+ let cls = clause.clause(idx);
326
+ // if composite clause and a different op, add parens so that we enforce order of precedence
327
+ if (clause.compositeOp && clause.compositeOp !== this.sep) {
328
+ cls = `(${cls})`;
329
+ }
330
+ clauses.push(cls);
214
331
  idx = idx + clause.values().length;
215
332
  }
216
333
  return clauses.join(this.sep);
217
334
  }
335
+ columns() {
336
+ const ret = [];
337
+ for (const cls of this.clauses) {
338
+ ret.push(...cls.columns());
339
+ }
340
+ return ret;
341
+ }
218
342
  values() {
219
343
  let result = [];
220
344
  for (const clause of this.clauses) {
@@ -231,7 +355,14 @@ class compositeClause {
231
355
  }
232
356
  instanceKey() {
233
357
  let keys = [];
234
- this.clauses.forEach((clause) => keys.push(clause.instanceKey()));
358
+ this.clauses.forEach((clause) => {
359
+ if (clause.compositeOp && clause.compositeOp != this.sep) {
360
+ keys.push(`(${clause.instanceKey()})`);
361
+ }
362
+ else {
363
+ keys.push(clause.instanceKey());
364
+ }
365
+ });
235
366
  return keys.join(this.sep);
236
367
  }
237
368
  }
@@ -264,6 +395,9 @@ class tsQueryClause {
264
395
  // FYI this doesn't actually work for sqlite since different
265
396
  return `${this.col} @@ ${this.getFunction()}('${language}', ?)`;
266
397
  }
398
+ columns() {
399
+ return [this.col];
400
+ }
267
401
  values() {
268
402
  const { value } = this.getInfo();
269
403
  return [value];
@@ -298,31 +432,76 @@ class websearchTosQueryClause extends tsQueryClause {
298
432
  return "websearch_to_tsquery";
299
433
  }
300
434
  }
301
- // TODO we need to check sqlite version...
435
+ // postgres array operators
436
+ // https://www.postgresql.org/docs/current/functions-array.html
437
+ /**
438
+ * creates a clause to determine if the given value is contained in the array stored in the column in the db
439
+ * only works with postgres gin indexes
440
+ * https://www.postgresql.org/docs/current/indexes-types.html#INDEXES-TYPES-GIN
441
+ */
442
+ function PostgresArrayContainsValue(col, value) {
443
+ return new postgresArrayOperator(col, value, "@>");
444
+ }
445
+ exports.PostgresArrayContainsValue = PostgresArrayContainsValue;
446
+ /**
447
+ * creates a clause to determine if every item in the list is stored in the array stored in the column in the db
448
+ * only works with postgres gin indexes
449
+ * https://www.postgresql.org/docs/current/indexes-types.html#INDEXES-TYPES-GIN
450
+ */
451
+ function PostgresArrayContains(col, value) {
452
+ return new postgresArrayOperatorList(col, value, "@>");
453
+ }
454
+ exports.PostgresArrayContains = PostgresArrayContains;
455
+ /**
456
+ * creates a clause to determine if the given value is NOT contained in the array stored in the column in the db
457
+ * only works with postgres gin indexes
458
+ * https://www.postgresql.org/docs/current/indexes-types.html#INDEXES-TYPES-GIN
459
+ */
460
+ function PostgresArrayNotContainsValue(col, value) {
461
+ return new postgresArrayOperator(col, value, "@>", true);
462
+ }
463
+ exports.PostgresArrayNotContainsValue = PostgresArrayNotContainsValue;
464
+ /**
465
+ * creates a clause to determine if every item in the list is NOT stored in the array stored in the column in the db
466
+ * only works with postgres gin indexes
467
+ * https://www.postgresql.org/docs/current/indexes-types.html#INDEXES-TYPES-GIN
468
+ */
469
+ function PostgresArrayNotContains(col, value) {
470
+ return new postgresArrayOperatorList(col, value, "@>", true);
471
+ }
472
+ exports.PostgresArrayNotContains = PostgresArrayNotContains;
473
+ /**
474
+ * creates a clause to determine if the arrays overlap, that is, do they have any elements in common
475
+ * only works with postgres gin indexes
476
+ * https://www.postgresql.org/docs/current/indexes-types.html#INDEXES-TYPES-GIN
477
+ */
478
+ function PostgresArrayOverlaps(col, value) {
479
+ return new postgresArrayOperatorList(col, value, "&&");
480
+ }
481
+ exports.PostgresArrayOverlaps = PostgresArrayOverlaps;
482
+ /**
483
+ * creates a clause to determine if the arrays do not overlap, that is, do they have any elements in common
484
+ * only works with postgres gin indexes
485
+ * https://www.postgresql.org/docs/current/indexes-types.html#INDEXES-TYPES-GIN
486
+ */
487
+ function PostgresArrayNotOverlaps(col, value) {
488
+ return new postgresArrayOperatorList(col, value, "&&", true);
489
+ }
490
+ exports.PostgresArrayNotOverlaps = PostgresArrayNotOverlaps;
491
+ /**
492
+ * @deprecated use PostgresArrayContainsValue
493
+ */
302
494
  function ArrayEq(col, value) {
303
495
  return new arraySimpleClause(col, value, "=");
304
496
  }
305
497
  exports.ArrayEq = ArrayEq;
498
+ /**
499
+ * @deprecated use PostgresNotArrayContains
500
+ */
306
501
  function ArrayNotEq(col, value) {
307
502
  return new arraySimpleClause(col, value, "!=");
308
503
  }
309
504
  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
505
  function Eq(col, value) {
327
506
  return new simpleClause(col, value, "=", new isNullClause(col));
328
507
  }
@@ -364,11 +543,66 @@ function Or(...args) {
364
543
  return new compositeClause(args, " OR ");
365
544
  }
366
545
  exports.Or = Or;
367
- // TODO this breaks if values.length ===1 and array. todo fix
368
- function In(col, ...values) {
369
- return new inClause(col, values);
546
+ function OrOptional(...args) {
547
+ // @ts-ignore
548
+ let filtered = args.filter((v) => v !== undefined);
549
+ if (filtered.length === 1) {
550
+ return filtered[0];
551
+ }
552
+ return Or(...filtered);
553
+ }
554
+ exports.OrOptional = OrOptional;
555
+ function In(...args) {
556
+ if (args.length < 2) {
557
+ throw new Error(`invalid args passed to In`);
558
+ }
559
+ // 2nd overload
560
+ if (Array.isArray(args[1])) {
561
+ return new inClause(args[0], args[1], args[2]);
562
+ }
563
+ return new inClause(args[0], args.slice(1));
370
564
  }
371
565
  exports.In = In;
566
+ function UuidIn(col, values) {
567
+ return new inClause(col, values, "uuid");
568
+ }
569
+ exports.UuidIn = UuidIn;
570
+ function IntegerIn(col, values) {
571
+ return new inClause(col, values, "integer");
572
+ }
573
+ exports.IntegerIn = IntegerIn;
574
+ function TextIn(col, values) {
575
+ return new inClause(col, values, "text");
576
+ }
577
+ exports.TextIn = TextIn;
578
+ /*
579
+ * if not uuid or text, pass the db type that can be used to cast this query
580
+ * if we end up with a large list of ids
581
+ */
582
+ function DBTypeIn(col, values, typ) {
583
+ return new inClause(col, values, typ);
584
+ }
585
+ exports.DBTypeIn = DBTypeIn;
586
+ function UuidNotIn(col, values) {
587
+ return new notInClause(col, values, "uuid");
588
+ }
589
+ exports.UuidNotIn = UuidNotIn;
590
+ function IntegerNotIn(col, values) {
591
+ return new notInClause(col, values, "integer");
592
+ }
593
+ exports.IntegerNotIn = IntegerNotIn;
594
+ function TextNotIn(col, values) {
595
+ return new notInClause(col, values, "text");
596
+ }
597
+ exports.TextNotIn = TextNotIn;
598
+ /*
599
+ * if not uuid or text, pass the db type that can be used to cast this query
600
+ * if we end up with a large list of ids
601
+ */
602
+ function DBTypeNotIn(col, values, typ) {
603
+ return new notInClause(col, values, typ);
604
+ }
605
+ exports.DBTypeNotIn = DBTypeNotIn;
372
606
  // if string defaults to english
373
607
  // https://www.postgresql.org/docs/current/textsearch-controls.html#TEXTSEARCH-PARSING-QUERIES
374
608
  // to_tsquery
@@ -437,3 +671,133 @@ function sensitiveValue(val) {
437
671
  };
438
672
  }
439
673
  exports.sensitiveValue = sensitiveValue;
674
+ // These don't return Clauses but return helpful things that can be passed to clauses
675
+ // https://www.postgresql.org/docs/12/functions-json.html#FUNCTIONS-JSON-OP-TABLE
676
+ // see test in db_clause.test.ts
677
+ // unclear best time to use this...
678
+ function JSONObjectFieldKeyASJSON(col, field) {
679
+ // type as keyof T to make it easier to use in other queries
680
+ return `${col}->'${field}'`;
681
+ }
682
+ exports.JSONObjectFieldKeyASJSON = JSONObjectFieldKeyASJSON;
683
+ function JSONObjectFieldKeyAsText(col, field) {
684
+ // type as keyof T to make it easier to use in other queries
685
+ return `${col}->>'${field}'`;
686
+ }
687
+ exports.JSONObjectFieldKeyAsText = JSONObjectFieldKeyAsText;
688
+ class jSONPathValuePredicateClause {
689
+ constructor(col, path, value, pred) {
690
+ this.col = col;
691
+ this.path = path;
692
+ this.value = value;
693
+ this.pred = pred;
694
+ }
695
+ clause(idx) {
696
+ if (db_1.default.getDialect() !== db_1.Dialect.Postgres) {
697
+ throw new Error(`not supported`);
698
+ }
699
+ return `${this.col} @@ $${idx}`;
700
+ }
701
+ columns() {
702
+ return [this.col];
703
+ }
704
+ wrap(val) {
705
+ return `${this.path} ${this.pred} ${JSON.stringify(val)}`;
706
+ }
707
+ values() {
708
+ if (isSensitive(this.value)) {
709
+ return [this.wrap(this.value.value())];
710
+ }
711
+ return [this.wrap(this.value)];
712
+ }
713
+ logValues() {
714
+ if (isSensitive(this.value)) {
715
+ return [this.wrap(this.value.logValue())];
716
+ }
717
+ return [this.wrap(this.value)];
718
+ }
719
+ instanceKey() {
720
+ return `${this.col}${this.path}${rawValue(this.value)}${this.pred}`;
721
+ }
722
+ }
723
+ // https://www.postgresql.org/docs/12/functions-json.html#FUNCTIONS-JSON-OP-TABLE
724
+ function JSONPathValuePredicate(dbCol, path, val, pred) {
725
+ return new jSONPathValuePredicateClause(dbCol, path, val, pred);
726
+ }
727
+ exports.JSONPathValuePredicate = JSONPathValuePredicate;
728
+ // TODO need a better name for this lol
729
+ // this assumes we're doing the same direction twice which isn't necessarily accurate in the future...
730
+ class paginationMultipleColumnsSubQueryClause {
731
+ constructor(col, op, tableName, uniqueCol, val) {
732
+ this.col = col;
733
+ this.op = op;
734
+ this.tableName = tableName;
735
+ this.uniqueCol = uniqueCol;
736
+ this.val = val;
737
+ }
738
+ buildSimpleQuery(clause, idx) {
739
+ return `SELECT ${this.col} FROM ${this.tableName} WHERE ${clause.clause(idx)}`;
740
+ }
741
+ clause(idx) {
742
+ const eq1 = this.buildSimpleQuery(Eq(this.uniqueCol, this.val), idx);
743
+ const eq2 = this.buildSimpleQuery(Eq(this.uniqueCol, this.val), idx + 1);
744
+ const op = new simpleClause(this.uniqueCol, this.val, this.op).clause(idx + 2);
745
+ // nest in () to make sure it's scoped correctly
746
+ return `(${this.col} ${this.op} (${eq1}) OR (${this.col} = (${eq2}) AND ${op}))`;
747
+ }
748
+ columns() {
749
+ return [this.col];
750
+ }
751
+ values() {
752
+ return [this.val, this.val, this.val];
753
+ }
754
+ logValues() {
755
+ const log = isSensitive(this.val) ? this.val.logValue() : this.val;
756
+ return [log, log, log];
757
+ }
758
+ instanceKey() {
759
+ return `${this.col}-${this.op}-${this.tableName}-${this.uniqueCol}-${this.val}`;
760
+ }
761
+ }
762
+ function PaginationMultipleColsSubQuery(col, op, tableName, uniqueCol, val) {
763
+ return new paginationMultipleColumnsSubQueryClause(col, op, tableName, uniqueCol, val);
764
+ }
765
+ exports.PaginationMultipleColsSubQuery = PaginationMultipleColsSubQuery;
766
+ // These 5 are used on the RHS of an expression
767
+ function Add(col, value) {
768
+ return new simpleClause(col, value, "+", new isNullClause(col));
769
+ }
770
+ exports.Add = Add;
771
+ function Subtract(col, value) {
772
+ return new simpleClause(col, value, "-", new isNullClause(col));
773
+ }
774
+ exports.Subtract = Subtract;
775
+ function Multiply(col, value) {
776
+ return new simpleClause(col, value, "*", new isNullClause(col));
777
+ }
778
+ exports.Multiply = Multiply;
779
+ function Divide(col, value) {
780
+ return new simpleClause(col, value, "/", new isNullClause(col));
781
+ }
782
+ exports.Divide = Divide;
783
+ function Modulo(col, value) {
784
+ return new simpleClause(col, value, "%", new isNullClause(col));
785
+ }
786
+ exports.Modulo = Modulo;
787
+ function getCombinedClause(options, cls) {
788
+ if (options.clause) {
789
+ let optionClause;
790
+ if (typeof options.clause === "function") {
791
+ optionClause = options.clause();
792
+ }
793
+ else {
794
+ optionClause = options.clause;
795
+ }
796
+ if (optionClause) {
797
+ // @ts-expect-error different types
798
+ cls = And(cls, optionClause);
799
+ }
800
+ }
801
+ return cls;
802
+ }
803
+ exports.getCombinedClause = getCombinedClause;
package/core/config.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  /// <reference types="node" />
2
2
  import { Database, DBDict } from "./db";
3
- declare type logType = "query" | "warn" | "info" | "error" | "debug";
3
+ type logType = "query" | "warn" | "info" | "error" | "debug";
4
4
  declare enum graphqlMutationName {
5
5
  NOUN_VERB = "NounVerb",
6
6
  VERB_NOUN = "VerbNoun"
@@ -18,8 +18,14 @@ export interface Config {
18
18
  dbFile?: string;
19
19
  db?: Database | DBDict;
20
20
  log?: logType | logType[];
21
+ logQueryWithError?: boolean;
22
+ defaultConnectionLimit?: number;
23
+ }
24
+ export interface ConfigWithCodegen extends Config {
21
25
  codegen?: CodegenConfig;
22
26
  customGraphQLJSONPath?: string;
27
+ dynamicScriptCustomGraphQLJSONPath?: string;
28
+ globalSchemaPath?: string;
23
29
  }
24
30
  interface CodegenConfig {
25
31
  defaultEntPolicy?: PrivacyConfig;
@@ -35,7 +41,10 @@ interface CodegenConfig {
35
41
  schemaSQLFilePath?: boolean;
36
42
  databaseToCompareTo?: string;
37
43
  fieldPrivacyEvaluated?: fieldPrivacyEvaluated;
38
- templatizedViewer?: templatizedViewer;
44
+ templatizedViewer?: importedObject;
45
+ customAssocEdgePath?: importedObject;
46
+ globalImportPath?: string;
47
+ userOveriddenFiles?: string[];
39
48
  }
40
49
  interface PrettierConfig {
41
50
  custom?: boolean;
@@ -46,9 +55,10 @@ interface PrivacyConfig {
46
55
  policyName: string;
47
56
  class?: boolean;
48
57
  }
49
- interface templatizedViewer {
58
+ interface importedObject {
50
59
  path: string;
51
60
  name: string;
61
+ alias?: string;
52
62
  }
53
63
  export declare function loadConfig(file?: string | Buffer | Config): void;
54
64
  export {};