@snowtop/ent 0.1.0-alpha6 → 0.1.0-alpha63

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 +65 -3
  12. package/core/clause.js +368 -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 +18 -1
  58. package/index.js +21 -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 +95 -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,76 @@ 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
+ * creates a clause to determine if the arrays overlap, that is, do they have any elements in common
61
+ * only works with postgres gin indexes
62
+ * https://www.postgresql.org/docs/current/indexes-types.html#INDEXES-TYPES-GIN
63
+ */
64
+ export declare function PostgresArrayOverlaps(col: string, value: any[]): Clause;
65
+ /**
66
+ * creates a clause to determine if the arrays do not overlap, that is, do they have any elements in common
67
+ * only works with postgres gin indexes
68
+ * https://www.postgresql.org/docs/current/indexes-types.html#INDEXES-TYPES-GIN
69
+ */
70
+ export declare function PostgresArrayNotOverlaps(col: string, value: any[]): Clause;
71
+ /**
72
+ * @deprecated use PostgresArrayContainsValue
73
+ */
74
+ export declare function ArrayEq(col: string, value: any): Clause;
75
+ /**
76
+ * @deprecated use PostgresNotArrayContains
77
+ */
78
+ export declare function ArrayNotEq(col: string, value: any): Clause;
79
+ export declare function Eq(col: string, value: any): Clause;
80
+ export declare function NotEq(col: string, value: any): Clause;
32
81
  export declare function Greater(col: string, value: any): simpleClause;
33
82
  export declare function Less(col: string, value: any): simpleClause;
34
83
  export declare function GreaterEq(col: string, value: any): simpleClause;
35
84
  export declare function LessEq(col: string, value: any): simpleClause;
36
85
  export declare function And(...args: Clause[]): compositeClause;
86
+ export declare function AndOptional(...args: (Clause | undefined)[]): Clause;
37
87
  export declare function Or(...args: Clause[]): compositeClause;
38
88
  export declare function In(col: string, ...values: any): Clause;
89
+ interface TsQuery {
90
+ language: "english" | "french" | "german" | "simple";
91
+ value: string;
92
+ }
93
+ export declare function TsQuery(col: string, val: string | TsQuery): Clause;
94
+ export declare function PlainToTsQuery(col: string, val: string | TsQuery): Clause;
95
+ export declare function PhraseToTsQuery(col: string, val: string | TsQuery): Clause;
96
+ export declare function WebsearchToTsQuery(col: string, val: string | TsQuery): Clause;
97
+ export declare function TsVectorColTsQuery(col: string, val: string | TsQuery): Clause;
98
+ export declare function TsVectorPlainToTsQuery(col: string, val: string | TsQuery): Clause;
99
+ export declare function TsVectorPhraseToTsQuery(col: string, val: string | TsQuery): Clause;
100
+ export declare function TsVectorWebsearchToTsQuery(col: string, val: string | TsQuery): Clause;
39
101
  export declare function sensitiveValue(val: any): SensitiveValue;
40
102
  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.PostgresArrayNotOverlaps = exports.PostgresArrayOverlaps = 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,17 +33,114 @@ 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
+ }
61
+ values() {
62
+ const sqliteClause = this.nullClause();
63
+ if (sqliteClause) {
64
+ return sqliteClause.values();
65
+ }
66
+ if (isSensitive(this.value)) {
67
+ return [this.value.value()];
68
+ }
69
+ return [this.value];
70
+ }
71
+ logValues() {
72
+ const sqliteClause = this.nullClause();
73
+ if (sqliteClause) {
74
+ return sqliteClause.logValues();
75
+ }
76
+ if (isSensitive(this.value)) {
77
+ return [this.value.logValue()];
78
+ }
79
+ return [this.value];
80
+ }
81
+ instanceKey() {
82
+ const sqliteClause = this.nullClause();
83
+ if (sqliteClause) {
84
+ return sqliteClause.instanceKey();
85
+ }
86
+ return `${this.col}${this.op}${rawValue(this.value)}`;
87
+ }
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
+ }
45
144
  values() {
46
145
  if (isSensitive(this.value)) {
47
146
  return [this.value.value()];
@@ -58,6 +157,61 @@ class simpleClause {
58
157
  return `${this.col}${this.op}${rawValue(this.value)}`;
59
158
  }
60
159
  }
160
+ class postgresArrayOperator {
161
+ constructor(col, value, op, not) {
162
+ this.col = col;
163
+ this.value = value;
164
+ this.op = op;
165
+ this.not = not;
166
+ }
167
+ clause(idx) {
168
+ if (db_1.default.getDialect() === db_1.Dialect.Postgres) {
169
+ if (this.not) {
170
+ return `NOT ${this.col} ${this.op} $${idx}`;
171
+ }
172
+ return `${this.col} ${this.op} $${idx}`;
173
+ }
174
+ throw new Error(`not supported`);
175
+ }
176
+ columns() {
177
+ return [this.col];
178
+ }
179
+ values() {
180
+ if (isSensitive(this.value)) {
181
+ return [`{${this.value.value()}}`];
182
+ }
183
+ return [`{${this.value}}`];
184
+ }
185
+ logValues() {
186
+ if (isSensitive(this.value)) {
187
+ return [this.value.logValue()];
188
+ }
189
+ return [this.value];
190
+ }
191
+ instanceKey() {
192
+ if (this.not) {
193
+ return `NOT:${this.col}${this.op}${rawValue(this.value)}`;
194
+ }
195
+ return `${this.col}${this.op}${rawValue(this.value)}`;
196
+ }
197
+ }
198
+ class postgresArrayOperatorList extends postgresArrayOperator {
199
+ constructor(col, value, op, not) {
200
+ super(col, value, op, not);
201
+ }
202
+ values() {
203
+ return [
204
+ `{${this.value
205
+ .map((v) => {
206
+ if (isSensitive(v)) {
207
+ return v.value();
208
+ }
209
+ return v;
210
+ })
211
+ .join(", ")}}`,
212
+ ];
213
+ }
214
+ }
61
215
  class inClause {
62
216
  constructor(col, value) {
63
217
  this.col = col;
@@ -84,6 +238,9 @@ class inClause {
84
238
  // or change to a sqlx.Rebind format
85
239
  // here's what sqlx does: https://play.golang.org/p/vPzvYqeAcP0
86
240
  }
241
+ columns() {
242
+ return [this.col];
243
+ }
87
244
  values() {
88
245
  const result = [];
89
246
  for (const value of this.value) {
@@ -125,6 +282,13 @@ class compositeClause {
125
282
  }
126
283
  return clauses.join(this.sep);
127
284
  }
285
+ columns() {
286
+ const ret = [];
287
+ for (const cls of this.clauses) {
288
+ ret.push(...cls.columns());
289
+ }
290
+ return ret;
291
+ }
128
292
  values() {
129
293
  let result = [];
130
294
  for (const clause of this.clauses) {
@@ -145,12 +309,148 @@ class compositeClause {
145
309
  return keys.join(this.sep);
146
310
  }
147
311
  }
312
+ class tsQueryClause {
313
+ constructor(col, val, tsVectorCol) {
314
+ this.col = col;
315
+ this.val = val;
316
+ this.tsVectorCol = tsVectorCol;
317
+ }
318
+ isTsQuery(val) {
319
+ return typeof val !== "string";
320
+ }
321
+ getInfo() {
322
+ if (this.isTsQuery(this.val)) {
323
+ return { value: this.val.value, language: this.val.language };
324
+ }
325
+ return {
326
+ language: "english",
327
+ value: this.val,
328
+ };
329
+ }
330
+ clause(idx) {
331
+ const { language } = this.getInfo();
332
+ if (db_1.Dialect.Postgres === db_1.default.getDialect()) {
333
+ if (this.tsVectorCol) {
334
+ return `to_tsvector(${this.col}) @@ ${this.getFunction()}('${language}', $${idx})`;
335
+ }
336
+ return `${this.col} @@ ${this.getFunction()}('${language}', $${idx})`;
337
+ }
338
+ // FYI this doesn't actually work for sqlite since different
339
+ return `${this.col} @@ ${this.getFunction()}('${language}', ?)`;
340
+ }
341
+ columns() {
342
+ return [this.col];
343
+ }
344
+ values() {
345
+ const { value } = this.getInfo();
346
+ return [value];
347
+ }
348
+ logValues() {
349
+ const { value } = this.getInfo();
350
+ return [value];
351
+ }
352
+ getFunction() {
353
+ return "to_tsquery";
354
+ }
355
+ instanceKey() {
356
+ const { language, value } = this.getInfo();
357
+ if (this.tsVectorCol) {
358
+ return `to_tsvector(${this.col})@@${this.getFunction()}:${language}:${value}`;
359
+ }
360
+ return `${this.col}@@${this.getFunction()}:${language}:${value}`;
361
+ }
362
+ }
363
+ class plainToTsQueryClause extends tsQueryClause {
364
+ getFunction() {
365
+ return "plainto_tsquery";
366
+ }
367
+ }
368
+ class phraseToTsQueryClause extends tsQueryClause {
369
+ getFunction() {
370
+ return "phraseto_tsquery";
371
+ }
372
+ }
373
+ class websearchTosQueryClause extends tsQueryClause {
374
+ getFunction() {
375
+ return "websearch_to_tsquery";
376
+ }
377
+ }
378
+ // postgres array operators
379
+ // https://www.postgresql.org/docs/current/functions-array.html
380
+ /**
381
+ * creates a clause to determine if the given value is contained in the array stored in the column in the db
382
+ * only works with postgres gin indexes
383
+ * https://www.postgresql.org/docs/current/indexes-types.html#INDEXES-TYPES-GIN
384
+ */
385
+ function PostgresArrayContainsValue(col, value) {
386
+ return new postgresArrayOperator(col, value, "@>");
387
+ }
388
+ exports.PostgresArrayContainsValue = PostgresArrayContainsValue;
389
+ /**
390
+ * creates a clause to determine if every item in the list is stored in the array stored in the column in the db
391
+ * only works with postgres gin indexes
392
+ * https://www.postgresql.org/docs/current/indexes-types.html#INDEXES-TYPES-GIN
393
+ */
394
+ function PostgresArrayContains(col, value) {
395
+ return new postgresArrayOperatorList(col, value, "@>");
396
+ }
397
+ exports.PostgresArrayContains = PostgresArrayContains;
398
+ /**
399
+ * creates a clause to determine if the given value is NOT contained in the array stored in the column in the db
400
+ * only works with postgres gin indexes
401
+ * https://www.postgresql.org/docs/current/indexes-types.html#INDEXES-TYPES-GIN
402
+ */
403
+ function PostgresArrayNotContainsValue(col, value) {
404
+ return new postgresArrayOperator(col, value, "@>", true);
405
+ }
406
+ exports.PostgresArrayNotContainsValue = PostgresArrayNotContainsValue;
407
+ /**
408
+ * creates a clause to determine if every item in the list is NOT stored in the array stored in the column in the db
409
+ * only works with postgres gin indexes
410
+ * https://www.postgresql.org/docs/current/indexes-types.html#INDEXES-TYPES-GIN
411
+ */
412
+ function PostgresArrayNotContains(col, value) {
413
+ return new postgresArrayOperatorList(col, value, "@>", true);
414
+ }
415
+ exports.PostgresArrayNotContains = PostgresArrayNotContains;
416
+ /**
417
+ * creates a clause to determine if the arrays overlap, that is, do they have any elements in common
418
+ * only works with postgres gin indexes
419
+ * https://www.postgresql.org/docs/current/indexes-types.html#INDEXES-TYPES-GIN
420
+ */
421
+ function PostgresArrayOverlaps(col, value) {
422
+ return new postgresArrayOperatorList(col, value, "&&");
423
+ }
424
+ exports.PostgresArrayOverlaps = PostgresArrayOverlaps;
425
+ /**
426
+ * creates a clause to determine if the arrays do not overlap, that is, do they have any elements in common
427
+ * only works with postgres gin indexes
428
+ * https://www.postgresql.org/docs/current/indexes-types.html#INDEXES-TYPES-GIN
429
+ */
430
+ function PostgresArrayNotOverlaps(col, value) {
431
+ return new postgresArrayOperatorList(col, value, "&&", true);
432
+ }
433
+ exports.PostgresArrayNotOverlaps = PostgresArrayNotOverlaps;
434
+ /**
435
+ * @deprecated use PostgresArrayContainsValue
436
+ */
437
+ function ArrayEq(col, value) {
438
+ return new arraySimpleClause(col, value, "=");
439
+ }
440
+ exports.ArrayEq = ArrayEq;
441
+ /**
442
+ * @deprecated use PostgresNotArrayContains
443
+ */
444
+ function ArrayNotEq(col, value) {
445
+ return new arraySimpleClause(col, value, "!=");
446
+ }
447
+ exports.ArrayNotEq = ArrayNotEq;
148
448
  function Eq(col, value) {
149
- return new simpleClause(col, value, "=");
449
+ return new simpleClause(col, value, "=", new isNullClause(col));
150
450
  }
151
451
  exports.Eq = Eq;
152
452
  function NotEq(col, value) {
153
- return new simpleClause(col, value, "!=");
453
+ return new simpleClause(col, value, "!=", new isNotNullClause(col));
154
454
  }
155
455
  exports.NotEq = NotEq;
156
456
  function Greater(col, value) {
@@ -173,6 +473,15 @@ function And(...args) {
173
473
  return new compositeClause(args, " AND ");
174
474
  }
175
475
  exports.And = And;
476
+ function AndOptional(...args) {
477
+ // @ts-ignore
478
+ let filtered = args.filter((v) => v !== undefined);
479
+ if (filtered.length === 1) {
480
+ return filtered[0];
481
+ }
482
+ return And(...filtered);
483
+ }
484
+ exports.AndOptional = AndOptional;
176
485
  function Or(...args) {
177
486
  return new compositeClause(args, " OR ");
178
487
  }
@@ -182,6 +491,60 @@ function In(col, ...values) {
182
491
  return new inClause(col, values);
183
492
  }
184
493
  exports.In = In;
494
+ // if string defaults to english
495
+ // https://www.postgresql.org/docs/current/textsearch-controls.html#TEXTSEARCH-PARSING-QUERIES
496
+ // to_tsquery
497
+ // plainto_tsquery
498
+ // phraseto_tsquery;
499
+ // websearch_to_tsquery
500
+ function TsQuery(col, val) {
501
+ return new tsQueryClause(col, val);
502
+ }
503
+ exports.TsQuery = TsQuery;
504
+ function PlainToTsQuery(col, val) {
505
+ return new plainToTsQueryClause(col, val);
506
+ }
507
+ exports.PlainToTsQuery = PlainToTsQuery;
508
+ function PhraseToTsQuery(col, val) {
509
+ return new phraseToTsQueryClause(col, val);
510
+ }
511
+ exports.PhraseToTsQuery = PhraseToTsQuery;
512
+ function WebsearchToTsQuery(col, val) {
513
+ return new websearchTosQueryClause(col, val);
514
+ }
515
+ exports.WebsearchToTsQuery = WebsearchToTsQuery;
516
+ // TsVectorColTsQuery is used when the column is not a tsvector field e.g.
517
+ // when there's an index just on the field and is not a combination of multiple fields
518
+ function TsVectorColTsQuery(col, val) {
519
+ return new tsQueryClause(col, val, true);
520
+ }
521
+ exports.TsVectorColTsQuery = TsVectorColTsQuery;
522
+ // TsVectorPlainToTsQuery is used when the column is not a tsvector field e.g.
523
+ // when there's an index just on the field and is not a combination of multiple fields
524
+ // TODO do these 4 need TsQuery because would be nice to have language?
525
+ // it seems to default to the config of the column
526
+ function TsVectorPlainToTsQuery(col, val) {
527
+ return new plainToTsQueryClause(col, val, true);
528
+ }
529
+ exports.TsVectorPlainToTsQuery = TsVectorPlainToTsQuery;
530
+ // TsVectorPhraseToTsQuery is used when the column is not a tsvector field e.g.
531
+ // when there's an index just on the field and is not a combination of multiple fields
532
+ function TsVectorPhraseToTsQuery(col, val) {
533
+ return new phraseToTsQueryClause(col, val, true);
534
+ }
535
+ exports.TsVectorPhraseToTsQuery = TsVectorPhraseToTsQuery;
536
+ // TsVectorWebsearchToTsQuery is used when the column is not a tsvector field e.g.
537
+ // when there's an index just on the field and is not a combination of multiple fields
538
+ function TsVectorWebsearchToTsQuery(col, val) {
539
+ return new websearchTosQueryClause(col, val, true);
540
+ }
541
+ exports.TsVectorWebsearchToTsQuery = TsVectorWebsearchToTsQuery;
542
+ // TODO would be nice to support this with building blocks but not supporting for now
543
+ // AND: foo & bar,
544
+ // OR: foo | bar
545
+ // followed by: foo <-> bar
546
+ // NOT: !foo
547
+ // starts_with: theo:*
185
548
  // wrap a query in the db with this to ensure that it doesn't show up in the logs
186
549
  // e.g. if querying for password, SSN, etc
187
550
  // 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;