@snowtop/ent 0.1.0-alpha6 → 0.1.0-alpha60

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