@snowtop/ent 0.1.0-alpha15 → 0.1.0-alpha150

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 (170) hide show
  1. package/action/action.d.ts +27 -16
  2. package/action/action.js +22 -7
  3. package/action/executor.d.ts +16 -3
  4. package/action/executor.js +90 -23
  5. package/action/experimental_action.d.ts +25 -16
  6. package/action/experimental_action.js +35 -9
  7. package/action/index.d.ts +3 -1
  8. package/action/index.js +7 -1
  9. package/action/operations.d.ts +125 -0
  10. package/action/operations.js +684 -0
  11. package/action/orchestrator.d.ts +38 -12
  12. package/action/orchestrator.js +427 -102
  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 +51 -21
  19. package/core/base.js +7 -1
  20. package/core/clause.d.ts +85 -40
  21. package/core/clause.js +375 -64
  22. package/core/config.d.ts +15 -1
  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 +4 -2
  27. package/core/context.js +20 -2
  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 +18 -8
  32. package/core/ent.d.ts +68 -94
  33. package/core/ent.js +535 -586
  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 +1 -0
  37. package/core/loaders/assoc_count_loader.js +10 -2
  38. package/core/loaders/assoc_edge_loader.d.ts +1 -1
  39. package/core/loaders/assoc_edge_loader.js +10 -13
  40. package/core/loaders/index.d.ts +1 -1
  41. package/core/loaders/index.js +1 -3
  42. package/core/loaders/index_loader.d.ts +3 -3
  43. package/core/loaders/loader.d.ts +2 -2
  44. package/core/loaders/loader.js +5 -5
  45. package/core/loaders/object_loader.d.ts +30 -9
  46. package/core/loaders/object_loader.js +225 -78
  47. package/core/loaders/query_loader.d.ts +6 -12
  48. package/core/loaders/query_loader.js +54 -13
  49. package/core/loaders/raw_count_loader.js +5 -1
  50. package/core/logger.d.ts +1 -1
  51. package/core/logger.js +1 -0
  52. package/core/privacy.d.ts +7 -6
  53. package/core/privacy.js +21 -25
  54. package/core/query/assoc_query.d.ts +3 -2
  55. package/core/query/assoc_query.js +9 -1
  56. package/core/query/custom_clause_query.d.ts +27 -0
  57. package/core/query/custom_clause_query.js +88 -0
  58. package/core/query/custom_query.d.ts +17 -2
  59. package/core/query/custom_query.js +88 -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 +15 -3
  63. package/core/query/query.js +128 -53
  64. package/core/query/shared_assoc_test.d.ts +2 -1
  65. package/core/query/shared_assoc_test.js +44 -54
  66. package/core/query/shared_test.d.ts +8 -1
  67. package/core/query/shared_test.js +532 -236
  68. package/core/viewer.d.ts +2 -0
  69. package/core/viewer.js +3 -1
  70. package/graphql/graphql.d.ts +52 -19
  71. package/graphql/graphql.js +174 -136
  72. package/graphql/graphql_field_helpers.d.ts +7 -1
  73. package/graphql/graphql_field_helpers.js +21 -1
  74. package/graphql/index.d.ts +2 -2
  75. package/graphql/index.js +3 -5
  76. package/graphql/query/connection_type.d.ts +9 -9
  77. package/graphql/query/shared_assoc_test.js +1 -1
  78. package/graphql/query/shared_edge_connection.js +1 -19
  79. package/graphql/scalars/orderby_direction.d.ts +2 -0
  80. package/graphql/scalars/orderby_direction.js +15 -0
  81. package/imports/dataz/example1/_auth.js +128 -47
  82. package/imports/dataz/example1/_viewer.js +87 -39
  83. package/imports/index.d.ts +7 -2
  84. package/imports/index.js +20 -5
  85. package/index.d.ts +14 -5
  86. package/index.js +26 -10
  87. package/package.json +18 -17
  88. package/parse_schema/parse.d.ts +31 -9
  89. package/parse_schema/parse.js +179 -32
  90. package/schema/base_schema.d.ts +13 -3
  91. package/schema/base_schema.js +13 -0
  92. package/schema/field.d.ts +78 -21
  93. package/schema/field.js +231 -71
  94. package/schema/index.d.ts +2 -2
  95. package/schema/index.js +7 -2
  96. package/schema/json_field.d.ts +16 -4
  97. package/schema/json_field.js +32 -2
  98. package/schema/schema.d.ts +109 -20
  99. package/schema/schema.js +42 -53
  100. package/schema/struct_field.d.ts +15 -3
  101. package/schema/struct_field.js +117 -22
  102. package/schema/union_field.d.ts +1 -1
  103. package/scripts/custom_compiler.js +12 -8
  104. package/scripts/custom_graphql.js +145 -34
  105. package/scripts/migrate_v0.1.js +36 -0
  106. package/scripts/move_types.js +120 -0
  107. package/scripts/read_schema.js +22 -7
  108. package/testutils/action/complex_schemas.d.ts +69 -0
  109. package/testutils/action/complex_schemas.js +405 -0
  110. package/testutils/builder.d.ts +39 -43
  111. package/testutils/builder.js +75 -49
  112. package/testutils/db/fixture.d.ts +10 -0
  113. package/testutils/db/fixture.js +26 -0
  114. package/testutils/db/{test_db.d.ts → temp_db.d.ts} +32 -8
  115. package/testutils/db/{test_db.js → temp_db.js} +244 -48
  116. package/testutils/db/value.d.ts +7 -0
  117. package/testutils/db/value.js +251 -0
  118. package/testutils/db_mock.d.ts +16 -4
  119. package/testutils/db_mock.js +52 -9
  120. package/testutils/db_time_zone.d.ts +4 -0
  121. package/testutils/db_time_zone.js +41 -0
  122. package/testutils/ent-graphql-tests/index.d.ts +7 -1
  123. package/testutils/ent-graphql-tests/index.js +56 -26
  124. package/testutils/fake_comms.js +1 -1
  125. package/testutils/fake_data/const.d.ts +2 -1
  126. package/testutils/fake_data/const.js +3 -0
  127. package/testutils/fake_data/fake_contact.d.ts +7 -3
  128. package/testutils/fake_data/fake_contact.js +13 -7
  129. package/testutils/fake_data/fake_event.d.ts +4 -1
  130. package/testutils/fake_data/fake_event.js +7 -6
  131. package/testutils/fake_data/fake_tag.d.ts +36 -0
  132. package/testutils/fake_data/fake_tag.js +89 -0
  133. package/testutils/fake_data/fake_user.d.ts +8 -5
  134. package/testutils/fake_data/fake_user.js +16 -15
  135. package/testutils/fake_data/index.js +5 -1
  136. package/testutils/fake_data/internal.d.ts +2 -0
  137. package/testutils/fake_data/internal.js +7 -1
  138. package/testutils/fake_data/tag_query.d.ts +13 -0
  139. package/testutils/fake_data/tag_query.js +43 -0
  140. package/testutils/fake_data/test_helpers.d.ts +11 -4
  141. package/testutils/fake_data/test_helpers.js +29 -13
  142. package/testutils/fake_data/user_query.d.ts +11 -4
  143. package/testutils/fake_data/user_query.js +54 -22
  144. package/testutils/fake_log.js +1 -1
  145. package/testutils/parse_sql.d.ts +6 -0
  146. package/testutils/parse_sql.js +16 -2
  147. package/testutils/test_edge_global_schema.d.ts +15 -0
  148. package/testutils/test_edge_global_schema.js +62 -0
  149. package/testutils/write.d.ts +2 -2
  150. package/testutils/write.js +33 -7
  151. package/tsc/ast.d.ts +25 -2
  152. package/tsc/ast.js +141 -17
  153. package/tsc/compilerOptions.js +5 -1
  154. package/tsc/move_generated.d.ts +1 -0
  155. package/tsc/move_generated.js +164 -0
  156. package/tsc/transform.d.ts +22 -0
  157. package/tsc/transform.js +182 -0
  158. package/tsc/transform_action.d.ts +22 -0
  159. package/tsc/transform_action.js +183 -0
  160. package/tsc/transform_ent.d.ts +17 -0
  161. package/tsc/transform_ent.js +60 -0
  162. package/tsc/transform_schema.d.ts +27 -0
  163. package/{scripts → tsc}/transform_schema.js +146 -117
  164. package/graphql/enums.d.ts +0 -3
  165. package/graphql/enums.js +0 -25
  166. package/scripts/move_generated.js +0 -142
  167. package/scripts/transform_code.js +0 -113
  168. package/scripts/transform_schema.d.ts +0 -1
  169. /package/scripts/{move_generated.d.ts → migrate_v0.1.d.ts} +0 -0
  170. /package/scripts/{transform_code.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.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
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,105 @@ 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;
155
239
  }
156
240
  clause(idx) {
157
- const dialect = db_1.default.getDialect();
241
+ // do a simple = when only one item
242
+ if (this.value.length === 1) {
243
+ return new simpleClause(this.col, this.value[0], "=").clause(idx);
244
+ }
245
+ const postgres = db_1.default.getDialect() === db_1.Dialect.Postgres;
246
+ const postgresValuesList = postgres &&
247
+ this.value.length >= inClause.getPostgresInClauseValuesThreshold();
158
248
  let indices;
159
- if (dialect === db_1.Dialect.Postgres) {
249
+ if (postgres) {
160
250
  indices = [];
161
251
  for (let i = 0; i < this.value.length; i++) {
162
- indices.push(`$${idx}`);
252
+ if (postgresValuesList) {
253
+ if (i === 0) {
254
+ indices.push(`($${idx}::${this.type})`);
255
+ }
256
+ else {
257
+ indices.push(`($${idx})`);
258
+ }
259
+ }
260
+ else {
261
+ indices.push(`$${idx}`);
262
+ }
163
263
  idx++;
164
264
  }
165
265
  }
@@ -167,34 +267,31 @@ class inClause {
167
267
  indices = new Array(this.value.length);
168
268
  indices.fill("?", 0);
169
269
  }
170
- const inValue = indices.join(", ");
270
+ let inValue = indices.join(", ");
271
+ // wrap in VALUES list for postgres...
272
+ if (postgresValuesList) {
273
+ inValue = `VALUES${inValue}`;
274
+ }
171
275
  return `${this.col} IN (${inValue})`;
172
276
  // TODO we need to return idx at end to query builder...
173
277
  // or anything that's doing a composite query so next clause knows where to start
174
278
  // or change to a sqlx.Rebind format
175
279
  // here's what sqlx does: https://play.golang.org/p/vPzvYqeAcP0
176
280
  }
281
+ columns() {
282
+ return [this.col];
283
+ }
177
284
  values() {
178
285
  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
- }
286
+ for (let value of this.value) {
287
+ result.push(rawValue(value));
186
288
  }
187
289
  return result;
188
290
  }
189
291
  logValues() {
190
292
  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
- }
293
+ for (let value of this.value) {
294
+ result.push(isSensitive(value) ? value.logValue() : value);
198
295
  }
199
296
  return result;
200
297
  }
@@ -202,19 +299,33 @@ class inClause {
202
299
  return `in:${this.col}:${this.values().join(",")}`;
203
300
  }
204
301
  }
302
+ exports.inClause = inClause;
205
303
  class compositeClause {
206
304
  constructor(clauses, sep) {
207
305
  this.clauses = clauses;
208
306
  this.sep = sep;
307
+ this.compositeOp = this.sep;
209
308
  }
210
309
  clause(idx) {
211
310
  let clauses = [];
212
311
  for (const clause of this.clauses) {
213
- clauses.push(clause.clause(idx));
312
+ let cls = clause.clause(idx);
313
+ // if composite clause and a different op, add parens so that we enforce order of precedence
314
+ if (clause.compositeOp && clause.compositeOp !== this.sep) {
315
+ cls = `(${cls})`;
316
+ }
317
+ clauses.push(cls);
214
318
  idx = idx + clause.values().length;
215
319
  }
216
320
  return clauses.join(this.sep);
217
321
  }
322
+ columns() {
323
+ const ret = [];
324
+ for (const cls of this.clauses) {
325
+ ret.push(...cls.columns());
326
+ }
327
+ return ret;
328
+ }
218
329
  values() {
219
330
  let result = [];
220
331
  for (const clause of this.clauses) {
@@ -231,7 +342,14 @@ class compositeClause {
231
342
  }
232
343
  instanceKey() {
233
344
  let keys = [];
234
- this.clauses.forEach((clause) => keys.push(clause.instanceKey()));
345
+ this.clauses.forEach((clause) => {
346
+ if (clause.compositeOp && clause.compositeOp != this.sep) {
347
+ keys.push(`(${clause.instanceKey()})`);
348
+ }
349
+ else {
350
+ keys.push(clause.instanceKey());
351
+ }
352
+ });
235
353
  return keys.join(this.sep);
236
354
  }
237
355
  }
@@ -264,6 +382,9 @@ class tsQueryClause {
264
382
  // FYI this doesn't actually work for sqlite since different
265
383
  return `${this.col} @@ ${this.getFunction()}('${language}', ?)`;
266
384
  }
385
+ columns() {
386
+ return [this.col];
387
+ }
267
388
  values() {
268
389
  const { value } = this.getInfo();
269
390
  return [value];
@@ -298,31 +419,76 @@ class websearchTosQueryClause extends tsQueryClause {
298
419
  return "websearch_to_tsquery";
299
420
  }
300
421
  }
301
- // TODO we need to check sqlite version...
422
+ // postgres array operators
423
+ // https://www.postgresql.org/docs/current/functions-array.html
424
+ /**
425
+ * creates a clause to determine if the given value is contained in the array stored in the column in the db
426
+ * only works with postgres gin indexes
427
+ * https://www.postgresql.org/docs/current/indexes-types.html#INDEXES-TYPES-GIN
428
+ */
429
+ function PostgresArrayContainsValue(col, value) {
430
+ return new postgresArrayOperator(col, value, "@>");
431
+ }
432
+ exports.PostgresArrayContainsValue = PostgresArrayContainsValue;
433
+ /**
434
+ * creates a clause to determine if every item in the list is stored in the array stored in the column in the db
435
+ * only works with postgres gin indexes
436
+ * https://www.postgresql.org/docs/current/indexes-types.html#INDEXES-TYPES-GIN
437
+ */
438
+ function PostgresArrayContains(col, value) {
439
+ return new postgresArrayOperatorList(col, value, "@>");
440
+ }
441
+ exports.PostgresArrayContains = PostgresArrayContains;
442
+ /**
443
+ * creates a clause to determine if the given value is NOT contained in the array stored in the column in the db
444
+ * only works with postgres gin indexes
445
+ * https://www.postgresql.org/docs/current/indexes-types.html#INDEXES-TYPES-GIN
446
+ */
447
+ function PostgresArrayNotContainsValue(col, value) {
448
+ return new postgresArrayOperator(col, value, "@>", true);
449
+ }
450
+ exports.PostgresArrayNotContainsValue = PostgresArrayNotContainsValue;
451
+ /**
452
+ * creates a clause to determine if every item in the list is NOT stored in the array stored in the column in the db
453
+ * only works with postgres gin indexes
454
+ * https://www.postgresql.org/docs/current/indexes-types.html#INDEXES-TYPES-GIN
455
+ */
456
+ function PostgresArrayNotContains(col, value) {
457
+ return new postgresArrayOperatorList(col, value, "@>", true);
458
+ }
459
+ exports.PostgresArrayNotContains = PostgresArrayNotContains;
460
+ /**
461
+ * creates a clause to determine if the arrays overlap, that is, do they have any elements in common
462
+ * only works with postgres gin indexes
463
+ * https://www.postgresql.org/docs/current/indexes-types.html#INDEXES-TYPES-GIN
464
+ */
465
+ function PostgresArrayOverlaps(col, value) {
466
+ return new postgresArrayOperatorList(col, value, "&&");
467
+ }
468
+ exports.PostgresArrayOverlaps = PostgresArrayOverlaps;
469
+ /**
470
+ * creates a clause to determine if the arrays do not overlap, that is, do they have any elements in common
471
+ * only works with postgres gin indexes
472
+ * https://www.postgresql.org/docs/current/indexes-types.html#INDEXES-TYPES-GIN
473
+ */
474
+ function PostgresArrayNotOverlaps(col, value) {
475
+ return new postgresArrayOperatorList(col, value, "&&", true);
476
+ }
477
+ exports.PostgresArrayNotOverlaps = PostgresArrayNotOverlaps;
478
+ /**
479
+ * @deprecated use PostgresArrayContainsValue
480
+ */
302
481
  function ArrayEq(col, value) {
303
482
  return new arraySimpleClause(col, value, "=");
304
483
  }
305
484
  exports.ArrayEq = ArrayEq;
485
+ /**
486
+ * @deprecated use PostgresNotArrayContains
487
+ */
306
488
  function ArrayNotEq(col, value) {
307
489
  return new arraySimpleClause(col, value, "!=");
308
490
  }
309
491
  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
492
  function Eq(col, value) {
327
493
  return new simpleClause(col, value, "=", new isNullClause(col));
328
494
  }
@@ -364,9 +530,24 @@ function Or(...args) {
364
530
  return new compositeClause(args, " OR ");
365
531
  }
366
532
  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);
533
+ function OrOptional(...args) {
534
+ // @ts-ignore
535
+ let filtered = args.filter((v) => v !== undefined);
536
+ if (filtered.length === 1) {
537
+ return filtered[0];
538
+ }
539
+ return Or(...filtered);
540
+ }
541
+ exports.OrOptional = OrOptional;
542
+ function In(...args) {
543
+ if (args.length < 2) {
544
+ throw new Error(`invalid args passed to In`);
545
+ }
546
+ // 2nd overload
547
+ if (Array.isArray(args[1])) {
548
+ return new inClause(args[0], args[1], args[2]);
549
+ }
550
+ return new inClause(args[0], args.slice(1));
370
551
  }
371
552
  exports.In = In;
372
553
  // if string defaults to english
@@ -437,3 +618,133 @@ function sensitiveValue(val) {
437
618
  };
438
619
  }
439
620
  exports.sensitiveValue = sensitiveValue;
621
+ // These don't return Clauses but return helpful things that can be passed to clauses
622
+ // https://www.postgresql.org/docs/12/functions-json.html#FUNCTIONS-JSON-OP-TABLE
623
+ // see test in db_clause.test.ts
624
+ // unclear best time to use this...
625
+ function JSONObjectFieldKeyASJSON(col, field) {
626
+ // type as keyof T to make it easier to use in other queries
627
+ return `${col}->'${field}'`;
628
+ }
629
+ exports.JSONObjectFieldKeyASJSON = JSONObjectFieldKeyASJSON;
630
+ function JSONObjectFieldKeyAsText(col, field) {
631
+ // type as keyof T to make it easier to use in other queries
632
+ return `${col}->>'${field}'`;
633
+ }
634
+ exports.JSONObjectFieldKeyAsText = JSONObjectFieldKeyAsText;
635
+ class jSONPathValuePredicateClause {
636
+ constructor(col, path, value, pred) {
637
+ this.col = col;
638
+ this.path = path;
639
+ this.value = value;
640
+ this.pred = pred;
641
+ }
642
+ clause(idx) {
643
+ if (db_1.default.getDialect() !== db_1.Dialect.Postgres) {
644
+ throw new Error(`not supported`);
645
+ }
646
+ return `${this.col} @@ $${idx}`;
647
+ }
648
+ columns() {
649
+ return [this.col];
650
+ }
651
+ wrap(val) {
652
+ return `${this.path} ${this.pred} ${JSON.stringify(val)}`;
653
+ }
654
+ values() {
655
+ if (isSensitive(this.value)) {
656
+ return [this.wrap(this.value.value())];
657
+ }
658
+ return [this.wrap(this.value)];
659
+ }
660
+ logValues() {
661
+ if (isSensitive(this.value)) {
662
+ return [this.wrap(this.value.logValue())];
663
+ }
664
+ return [this.wrap(this.value)];
665
+ }
666
+ instanceKey() {
667
+ return `${this.col}${this.path}${rawValue(this.value)}${this.pred}`;
668
+ }
669
+ }
670
+ // https://www.postgresql.org/docs/12/functions-json.html#FUNCTIONS-JSON-OP-TABLE
671
+ function JSONPathValuePredicate(dbCol, path, val, pred) {
672
+ return new jSONPathValuePredicateClause(dbCol, path, val, pred);
673
+ }
674
+ exports.JSONPathValuePredicate = JSONPathValuePredicate;
675
+ // TODO need a better name for this lol
676
+ // this assumes we're doing the same direction twice which isn't necessarily accurate in the future...
677
+ class paginationMultipleColumnsSubQueryClause {
678
+ constructor(col, op, tableName, uniqueCol, val) {
679
+ this.col = col;
680
+ this.op = op;
681
+ this.tableName = tableName;
682
+ this.uniqueCol = uniqueCol;
683
+ this.val = val;
684
+ }
685
+ buildSimpleQuery(clause, idx) {
686
+ return `SELECT ${this.col} FROM ${this.tableName} WHERE ${clause.clause(idx)}`;
687
+ }
688
+ clause(idx) {
689
+ const eq1 = this.buildSimpleQuery(Eq(this.uniqueCol, this.val), idx);
690
+ const eq2 = this.buildSimpleQuery(Eq(this.uniqueCol, this.val), idx + 1);
691
+ const op = new simpleClause(this.uniqueCol, this.val, this.op).clause(idx + 2);
692
+ // nest in () to make sure it's scoped correctly
693
+ return `(${this.col} ${this.op} (${eq1}) OR (${this.col} = (${eq2}) AND ${op}))`;
694
+ }
695
+ columns() {
696
+ return [this.col];
697
+ }
698
+ values() {
699
+ return [this.val, this.val, this.val];
700
+ }
701
+ logValues() {
702
+ const log = isSensitive(this.val) ? this.val.logValue() : this.val;
703
+ return [log, log, log];
704
+ }
705
+ instanceKey() {
706
+ return `${this.col}-${this.op}-${this.tableName}-${this.uniqueCol}-${this.val}`;
707
+ }
708
+ }
709
+ function PaginationMultipleColsSubQuery(col, op, tableName, uniqueCol, val) {
710
+ return new paginationMultipleColumnsSubQueryClause(col, op, tableName, uniqueCol, val);
711
+ }
712
+ exports.PaginationMultipleColsSubQuery = PaginationMultipleColsSubQuery;
713
+ // These 5 are used on the RHS of an expression
714
+ function Add(col, value) {
715
+ return new simpleClause(col, value, "+", new isNullClause(col));
716
+ }
717
+ exports.Add = Add;
718
+ function Subtract(col, value) {
719
+ return new simpleClause(col, value, "-", new isNullClause(col));
720
+ }
721
+ exports.Subtract = Subtract;
722
+ function Multiply(col, value) {
723
+ return new simpleClause(col, value, "*", new isNullClause(col));
724
+ }
725
+ exports.Multiply = Multiply;
726
+ function Divide(col, value) {
727
+ return new simpleClause(col, value, "/", new isNullClause(col));
728
+ }
729
+ exports.Divide = Divide;
730
+ function Modulo(col, value) {
731
+ return new simpleClause(col, value, "%", new isNullClause(col));
732
+ }
733
+ exports.Modulo = Modulo;
734
+ function getCombinedClause(options, cls) {
735
+ if (options.clause) {
736
+ let optionClause;
737
+ if (typeof options.clause === "function") {
738
+ optionClause = options.clause();
739
+ }
740
+ else {
741
+ optionClause = options.clause;
742
+ }
743
+ if (optionClause) {
744
+ // @ts-expect-error different types
745
+ cls = And(cls, optionClause);
746
+ }
747
+ }
748
+ return cls;
749
+ }
750
+ 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,6 +41,9 @@ interface CodegenConfig {
35
41
  schemaSQLFilePath?: boolean;
36
42
  databaseToCompareTo?: string;
37
43
  fieldPrivacyEvaluated?: fieldPrivacyEvaluated;
44
+ templatizedViewer?: importedObject;
45
+ customAssocEdgePath?: importedObject;
46
+ globalImportPath?: string;
38
47
  }
39
48
  interface PrettierConfig {
40
49
  custom?: boolean;
@@ -45,5 +54,10 @@ interface PrivacyConfig {
45
54
  policyName: string;
46
55
  class?: boolean;
47
56
  }
57
+ interface importedObject {
58
+ path: string;
59
+ name: string;
60
+ alias?: string;
61
+ }
48
62
  export declare function loadConfig(file?: string | Buffer | Config): void;
49
63
  export {};
package/core/config.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];
@@ -28,6 +32,7 @@ const js_yaml_1 = require("js-yaml");
28
32
  const db_1 = __importDefault(require("./db"));
29
33
  const path = __importStar(require("path"));
30
34
  const logger_1 = require("./logger");
35
+ const ent_1 = require("./ent");
31
36
  // ent.config.ts eventually. for now ent.yml
32
37
  // or ent.yml?
33
38
  var graphqlMutationName;
@@ -56,6 +61,10 @@ function setConfig(cfg) {
56
61
  db: cfg.db,
57
62
  });
58
63
  }
64
+ (0, ent_1.___setLogQueryErrorWithError)(cfg.logQueryWithError);
65
+ if (cfg.defaultConnectionLimit) {
66
+ (0, ent_1.setDefaultLimit)(cfg.defaultConnectionLimit);
67
+ }
59
68
  }
60
69
  function isBuffer(b) {
61
70
  return b.write !== undefined;
@@ -0,0 +1,3 @@
1
+ export declare const PACKAGE = "@snowtop/ent";
2
+ export declare const GRAPHQL_PATH = "@snowtop/ent/graphql";
3
+ export declare const SCHEMA_PATH = "@snowtop/ent/schema";
package/core/const.js ADDED
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SCHEMA_PATH = exports.GRAPHQL_PATH = exports.PACKAGE = void 0;
4
+ exports.PACKAGE = "@snowtop/ent";
5
+ exports.GRAPHQL_PATH = "@snowtop/ent/graphql";
6
+ exports.SCHEMA_PATH = "@snowtop/ent/schema";