@snowtop/ent 0.1.0-alpha90 → 0.1.0-alpha92-56721980-4046-11ed-ba1f-832778cd7daa

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 (64) hide show
  1. package/action/orchestrator.js +5 -1
  2. package/core/clause.d.ts +15 -0
  3. package/core/clause.js +44 -2
  4. package/core/config.js +5 -1
  5. package/core/db.js +5 -1
  6. package/core/ent.js +7 -8
  7. package/core/loaders/assoc_count_loader.d.ts +1 -0
  8. package/core/loaders/assoc_count_loader.js +8 -1
  9. package/core/loaders/assoc_edge_loader.js +5 -1
  10. package/core/loaders/object_loader.js +5 -1
  11. package/core/loaders/query_loader.js +5 -1
  12. package/core/loaders/raw_count_loader.js +5 -1
  13. package/core/privacy.d.ts +6 -6
  14. package/core/query/assoc_query.d.ts +1 -0
  15. package/core/query/assoc_query.js +9 -1
  16. package/core/query/custom_clause_query.d.ts +2 -0
  17. package/core/query/custom_clause_query.js +9 -3
  18. package/core/query/custom_query.d.ts +2 -2
  19. package/core/query/custom_query.js +29 -21
  20. package/core/query/query.d.ts +7 -3
  21. package/core/query/query.js +101 -60
  22. package/core/query/shared_assoc_test.d.ts +2 -1
  23. package/core/query/shared_assoc_test.js +24 -45
  24. package/core/query/shared_test.d.ts +5 -1
  25. package/core/query/shared_test.js +354 -301
  26. package/graphql/graphql.js +10 -6
  27. package/graphql/query/shared_edge_connection.js +1 -15
  28. package/imports/index.js +5 -1
  29. package/index.js +5 -1
  30. package/package.json +1 -1
  31. package/schema/field.d.ts +13 -0
  32. package/schema/field.js +63 -52
  33. package/schema/index.js +5 -1
  34. package/schema/schema.d.ts +1 -0
  35. package/scripts/custom_compiler.js +10 -6
  36. package/scripts/custom_graphql.js +5 -1
  37. package/scripts/read_schema.js +5 -1
  38. package/testutils/db/temp_db.d.ts +6 -5
  39. package/testutils/db/temp_db.js +40 -28
  40. package/testutils/db_mock.js +3 -1
  41. package/testutils/ent-graphql-tests/index.js +8 -1
  42. package/testutils/fake_data/const.d.ts +2 -1
  43. package/testutils/fake_data/const.js +3 -0
  44. package/testutils/fake_data/fake_contact.d.ts +2 -0
  45. package/testutils/fake_data/fake_tag.d.ts +35 -0
  46. package/testutils/fake_data/fake_tag.js +88 -0
  47. package/testutils/fake_data/fake_user.d.ts +2 -0
  48. package/testutils/fake_data/index.js +5 -1
  49. package/testutils/fake_data/internal.d.ts +2 -0
  50. package/testutils/fake_data/internal.js +7 -1
  51. package/testutils/fake_data/tag_query.d.ts +13 -0
  52. package/testutils/fake_data/tag_query.js +43 -0
  53. package/testutils/fake_data/test_helpers.d.ts +8 -2
  54. package/testutils/fake_data/test_helpers.js +21 -7
  55. package/testutils/fake_data/user_query.d.ts +5 -0
  56. package/testutils/fake_data/user_query.js +28 -3
  57. package/testutils/test_edge_global_schema.js +5 -1
  58. package/testutils/write.js +5 -1
  59. package/tsc/ast.js +5 -1
  60. package/tsc/compilerOptions.js +5 -1
  61. package/tsc/move_generated.js +5 -1
  62. package/tsc/transform.js +5 -1
  63. package/tsc/transform_action.js +5 -1
  64. package/tsc/transform_schema.js +5 -1
@@ -63,11 +63,9 @@ const isGraphQLScalarType = (type) => {
63
63
  };
64
64
  const addCustomType = (type) => {
65
65
  // TODO these should return ReadOnly objects...
66
- const customType = GQLCapture.getCustomTypes().get(type.type);
67
- if (customType && customType !== type) {
68
- throw new Error(`cannot add multiple custom types of name ${type.type}`);
69
- }
70
- if (customType) {
66
+ const customTypes = GQLCapture.getCustomTypes();
67
+ const customType = customTypes.get(type.type);
68
+ if (customType && customType === type) {
71
69
  return;
72
70
  }
73
71
  try {
@@ -93,7 +91,13 @@ const addCustomType = (type) => {
93
91
  }
94
92
  return;
95
93
  }
96
- GQLCapture.getCustomTypes().set(type.type, type);
94
+ if (customType) {
95
+ if (JSON.stringify(customType) !== JSON.stringify(type)) {
96
+ throw new Error(`cannot add multiple custom types of name ${type.type}`);
97
+ }
98
+ return;
99
+ }
100
+ customTypes.set(type.type, type);
97
101
  };
98
102
  exports.addCustomType = addCustomType;
99
103
  const getType = (typ, result) => {
@@ -48,23 +48,9 @@ class TestConnection {
48
48
  }
49
49
  const commonTests = (opts) => {
50
50
  function getCursorFrom(contacts, idx) {
51
- // we depend on the fact that the same time is used for the edge and created_at
52
- // based on getContactBuilder
53
- // so regardless of if we're doing assoc or custom queries, we can get the time
54
- // from the created_at field
55
51
  return (0, ent_1.getCursor)({
56
52
  row: contacts[idx],
57
- col: "createdAt",
58
- conv: (t) => {
59
- //sqlite
60
- if (typeof t === "string") {
61
- return Date.parse(t);
62
- }
63
- return t.getTime();
64
- },
65
- // we want the right column to be encoded in the cursor as opposed e.g. time for
66
- // assoc queries, created_at for index/custom queries
67
- cursorKey: opts.sortCol,
53
+ col: "id",
68
54
  });
69
55
  }
70
56
  describe("no filters", () => {
package/imports/index.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];
package/index.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];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@snowtop/ent",
3
- "version": "0.1.0-alpha90",
3
+ "version": "0.1.0-alpha92-56721980-4046-11ed-ba1f-832778cd7daa",
4
4
  "description": "snowtop ent framework",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
package/schema/field.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import { Builder } from "../action/action";
1
2
  import { Field, FieldMap, FieldOptions, ForeignKey, PolymorphicOptions, Type } from "./schema";
2
3
  export declare abstract class BaseField {
3
4
  name: string;
@@ -88,6 +89,18 @@ export declare class StringField extends BaseField implements Field {
88
89
  trimLeft(): this;
89
90
  trimRight(): this;
90
91
  }
92
+ interface PolymorphicStringOptions extends StringOptions {
93
+ parentFieldToValidate: string;
94
+ types?: string[];
95
+ }
96
+ export declare class PolymorphicStringField extends StringField {
97
+ private opts;
98
+ private camelCaseVals;
99
+ constructor(opts: PolymorphicStringOptions);
100
+ validateWithFullData(val: any, b: Builder<any>): boolean;
101
+ valid(val: any): boolean;
102
+ format(val: any): any;
103
+ }
91
104
  export declare function StringType(options?: StringOptions): StringField;
92
105
  export interface TimestampOptions extends FieldOptions {
93
106
  withTimezone?: boolean;
package/schema/field.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,9 +23,10 @@ var __importStar = (this && this.__importStar) || function (mod) {
19
23
  return result;
20
24
  };
21
25
  Object.defineProperty(exports, "__esModule", { value: true });
22
- exports.UUIDListType = exports.IntegerEnumListType = exports.EnumListType = exports.DateListType = exports.TimetzListType = exports.TimeListType = exports.TimestamptzListType = exports.TimestampListType = exports.BooleanListType = exports.BigIntegerListType = exports.FloatListType = exports.IntegerListType = exports.IntListType = exports.StringListType = exports.ListField = exports.IntegerEnumType = exports.IntegerEnumField = exports.EnumType = exports.StringEnumField = exports.EnumField = exports.DateType = exports.DateField = exports.TimetzType = exports.TimeType = exports.TimeField = exports.leftPad = exports.TimestamptzType = exports.TimestampType = exports.TimestampField = exports.StringType = exports.StringField = exports.BooleanType = exports.BooleanField = exports.FloatType = exports.FloatField = exports.BigIntegerType = exports.BigIntegerField = exports.IntegerType = exports.IntegerField = exports.UUIDType = exports.UUIDField = exports.BaseField = void 0;
26
+ exports.UUIDListType = exports.IntegerEnumListType = exports.EnumListType = exports.DateListType = exports.TimetzListType = exports.TimeListType = exports.TimestamptzListType = exports.TimestampListType = exports.BooleanListType = exports.BigIntegerListType = exports.FloatListType = exports.IntegerListType = exports.IntListType = exports.StringListType = exports.ListField = exports.IntegerEnumType = exports.IntegerEnumField = exports.EnumType = exports.StringEnumField = exports.EnumField = exports.DateType = exports.DateField = exports.TimetzType = exports.TimeType = exports.TimeField = exports.leftPad = exports.TimestamptzType = exports.TimestampType = exports.TimestampField = exports.StringType = exports.PolymorphicStringField = exports.StringField = exports.BooleanType = exports.BooleanField = exports.FloatType = exports.FloatField = exports.BigIntegerType = exports.BigIntegerField = exports.IntegerType = exports.IntegerField = exports.UUIDType = exports.UUIDField = exports.BaseField = void 0;
23
27
  const luxon_1 = require("luxon");
24
28
  const snake_case_1 = require("snake-case");
29
+ const camel_case_1 = require("camel-case");
25
30
  const util_1 = require("util");
26
31
  const uuid_1 = require("uuid");
27
32
  const base_1 = require("../core/base");
@@ -62,32 +67,26 @@ class UUIDField extends BaseField {
62
67
  else {
63
68
  throw new Error(`unsupported id polymorhpic type ${fieldName}`);
64
69
  }
70
+ let types;
71
+ let serverDefault = undefined;
72
+ if (typeof polymorphic === "object") {
73
+ serverDefault = polymorphic.serverDefault;
74
+ types = polymorphic.types;
75
+ }
65
76
  // polymorphic field automatically hidden from GraphQL
66
77
  // can be made visible with custom fields if user wants to change this behavior
67
78
  // can't be foreignKey so need to make other changes to the field
68
79
  // intentionally not made private as it doesn't seem like it needs to be hidden
69
- if (typeof polymorphic === "object" && polymorphic.types) {
70
- // an enum with types validated here
71
- return {
72
- [name]: PolymorphicStringEnumType({
73
- values: polymorphic.types,
74
- hideFromGraphQL: true,
75
- derivedWhenEmbedded: true,
76
- nullable: this.options?.nullable,
77
- parentFieldToValidate: fieldName,
78
- }),
79
- };
80
- }
81
- else {
82
- return {
83
- [name]: PolymorphicStringType({
84
- hideFromGraphQL: true,
85
- derivedWhenEmbedded: true,
86
- nullable: this.options?.nullable,
87
- parentFieldToValidate: fieldName,
88
- }),
89
- };
90
- }
80
+ return {
81
+ [name]: PolymorphicStringType({
82
+ types: types,
83
+ hideFromGraphQL: true,
84
+ derivedWhenEmbedded: true,
85
+ nullable: this.options?.nullable,
86
+ parentFieldToValidate: fieldName,
87
+ serverDefault: serverDefault,
88
+ }),
89
+ };
91
90
  }
92
91
  return {};
93
92
  }
@@ -313,29 +312,54 @@ class StringField extends BaseField {
313
312
  }
314
313
  }
315
314
  exports.StringField = StringField;
316
- function validatePolymorphicTypeWithFullData(val, b, field) {
317
- const input = b.getInput();
318
- const inputKey = b.orchestrator.__getOptions().fieldInfo[field].inputKey;
319
- const v = input[inputKey];
320
- if (val === null) {
321
- // if this is being set to null, ok if v is also null
322
- return v === null;
323
- }
324
- // if this is not being set, ok if v is not being set
325
- if (val === undefined && b.operation === base_1.WriteOperation.Insert) {
326
- return v === undefined;
327
- }
328
- return true;
329
- }
330
315
  class PolymorphicStringField extends StringField {
331
316
  constructor(opts) {
332
317
  super(opts);
333
318
  this.opts = opts;
319
+ if (opts.types) {
320
+ this.camelCaseVals = opts.types.map((v) => (0, camel_case_1.camelCase)(v));
321
+ }
334
322
  }
335
323
  validateWithFullData(val, b) {
336
- return validatePolymorphicTypeWithFullData(val, b, this.opts.parentFieldToValidate);
324
+ const input = b.getInput();
325
+ const inputKey = b.orchestrator.__getOptions().fieldInfo[this.opts.parentFieldToValidate]
326
+ .inputKey;
327
+ const v = input[inputKey];
328
+ if (val === null) {
329
+ // if this is being set to null, ok if v is also null
330
+ return v === null;
331
+ }
332
+ // if this is not being set, ok if v is not being set
333
+ if (val === undefined && b.operation === base_1.WriteOperation.Insert) {
334
+ return v === undefined;
335
+ }
336
+ return true;
337
+ }
338
+ valid(val) {
339
+ if (!this.camelCaseVals) {
340
+ return true;
341
+ }
342
+ let str = (0, camel_case_1.camelCase)(String(val));
343
+ // allow different cases because it could be coming from different clients who don't have strong typing
344
+ return this.camelCaseVals.some((value) => value === str);
345
+ }
346
+ format(val) {
347
+ if (!this.camelCaseVals) {
348
+ return val;
349
+ }
350
+ const converted = (0, camel_case_1.camelCase)(String(val));
351
+ for (const v of this.camelCaseVals) {
352
+ if (v === val) {
353
+ return val;
354
+ }
355
+ if (converted === v) {
356
+ return converted;
357
+ }
358
+ }
359
+ return val;
337
360
  }
338
361
  }
362
+ exports.PolymorphicStringField = PolymorphicStringField;
339
363
  function PolymorphicStringType(opts) {
340
364
  let result = new PolymorphicStringField(opts);
341
365
  return Object.assign(result, opts);
@@ -586,19 +610,6 @@ exports.EnumField = EnumField;
586
610
  class StringEnumField extends EnumField {
587
611
  }
588
612
  exports.StringEnumField = StringEnumField;
589
- class PolymorphicStringEnumField extends StringEnumField {
590
- constructor(opts) {
591
- super(opts);
592
- this.opts = opts;
593
- }
594
- validateWithFullData(val, b) {
595
- return validatePolymorphicTypeWithFullData(val, b, this.opts.parentFieldToValidate);
596
- }
597
- }
598
- function PolymorphicStringEnumType(options) {
599
- let result = new PolymorphicStringEnumField(options);
600
- return Object.assign(result, options);
601
- }
602
613
  function EnumType(options) {
603
614
  let result = new StringEnumField(options);
604
615
  return Object.assign(result, options);
package/schema/index.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];
@@ -215,6 +215,7 @@ export interface PolymorphicOptions {
215
215
  types?: string[];
216
216
  hideFromInverseGraphQL?: boolean;
217
217
  disableBuilderType?: boolean;
218
+ serverDefault?: any;
218
219
  }
219
220
  export interface Field extends FieldOptions {
220
221
  type: Type;
@@ -2,7 +2,11 @@
2
2
  "use strict";
3
3
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
4
4
  if (k2 === undefined) k2 = k;
5
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
+ var desc = Object.getOwnPropertyDescriptor(m, k);
6
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
7
+ desc = { enumerable: true, get: function() { return m[k]; } };
8
+ }
9
+ Object.defineProperty(o, k2, desc);
6
10
  }) : (function(o, m, k, k2) {
7
11
  if (k2 === undefined) k2 = k;
8
12
  o[k2] = m[k];
@@ -193,7 +197,7 @@ class Compiler {
193
197
  }
194
198
  relPath = path.relative(
195
199
  // just because of how imports work. it's relative from directory not current path
196
- path.dirname(fullPath), path.join(text.substr(0, idx).replace(r, str.substr(0, strIdx)), text.substr(idx)));
200
+ path.dirname(fullPath), path.join(text.substring(0, idx).replace(r, str.substring(0, strIdx)), text.substring(idx)));
197
201
  // if file ends with "..", we've reached a case where we're trying to
198
202
  // import something like foo/contact(.ts) from within foo/contact/bar/baz/page.ts
199
203
  // and we're confused about it so we need to detect that case and handle it
@@ -204,7 +208,7 @@ class Compiler {
204
208
  let text2 = text + ".ts";
205
209
  relPath = path.relative(
206
210
  // just because of how imports work. it's relative from directory not current path
207
- path.dirname(fullPath), path.join(text2.substr(0, idx).replace(r, str.substr(0, strIdx)), text2.substr(idx)));
211
+ path.dirname(fullPath), path.join(text2.substring(0, idx).replace(r, str.substring(0, strIdx)), text2.substring(idx)));
208
212
  }
209
213
  }
210
214
  if (!relPath.startsWith("..")) {
@@ -213,7 +217,7 @@ class Compiler {
213
217
  // tsc removes this by default so we need to also do it
214
218
  let tsIdx = relPath.indexOf(".ts");
215
219
  if (tsIdx !== -1) {
216
- relPath = relPath.substr(0, tsIdx);
220
+ relPath = relPath.substring(0, tsIdx);
217
221
  }
218
222
  return relPath;
219
223
  }
@@ -225,7 +229,7 @@ class Compiler {
225
229
  let relPath = checkPath(paths, text);
226
230
  if (relPath) {
227
231
  // update the node...
228
- return typescript_1.default.updateImportDeclaration(importNode, importNode.decorators, importNode.modifiers, importNode.importClause, typescript_1.default.createLiteral(relPath));
232
+ return typescript_1.default.factory.updateImportDeclaration(importNode, importNode.decorators, importNode.modifiers, importNode.importClause, typescript_1.default.factory.createStringLiteral(relPath), importNode.assertClause);
229
233
  }
230
234
  }
231
235
  if (node.kind === typescript_1.default.SyntaxKind.ExportDeclaration) {
@@ -235,7 +239,7 @@ class Compiler {
235
239
  let relPath = checkPath(paths, text);
236
240
  if (relPath) {
237
241
  // update the node...
238
- return typescript_1.default.updateExportDeclaration(exportNode, exportNode.decorators, exportNode.modifiers, exportNode.exportClause, typescript_1.default.createLiteral(relPath), exportNode.isTypeOnly);
242
+ return typescript_1.default.updateExportDeclaration(exportNode, exportNode.decorators, exportNode.modifiers, exportNode.exportClause, typescript_1.default.factory.createStringLiteral(relPath), exportNode.isTypeOnly);
239
243
  }
240
244
  }
241
245
  }
@@ -2,7 +2,11 @@
2
2
  "use strict";
3
3
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
4
4
  if (k2 === undefined) k2 = k;
5
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
+ var desc = Object.getOwnPropertyDescriptor(m, k);
6
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
7
+ desc = { enumerable: true, get: function() { return m[k]; } };
8
+ }
9
+ Object.defineProperty(o, k2, desc);
6
10
  }) : (function(o, m, k, k2) {
7
11
  if (k2 === undefined) k2 = k;
8
12
  o[k2] = m[k];
@@ -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];
@@ -24,6 +24,7 @@ interface Constraint extends SchemaItem {
24
24
  }
25
25
  interface Index extends SchemaItem {
26
26
  generate(): string;
27
+ postCreate?(): boolean;
27
28
  }
28
29
  export interface CoreConcept {
29
30
  name: string;
@@ -42,10 +43,10 @@ export declare function foreignKey(name: string, cols: string[], fkey: {
42
43
  cols: string[];
43
44
  }): Constraint;
44
45
  interface indexOptions {
45
- type: string;
46
+ type?: string;
47
+ unique?: boolean;
46
48
  }
47
49
  export declare function index(tableName: string, cols: string[], opts?: indexOptions): Index;
48
- export declare function uniqueIndex(name: string): Constraint;
49
50
  export declare function uuid(name: string, opts?: options): Column;
50
51
  export declare function text(name: string, opts?: options): Column;
51
52
  export declare function enumCol(name: string, type: string): Column;
@@ -77,10 +78,10 @@ export declare class TempDB {
77
78
  private tables;
78
79
  private dialect;
79
80
  private sqlite;
80
- constructor(dialect: Dialect, tables?: CoreConcept[]);
81
- constructor(tables: CoreConcept[]);
81
+ private setTables;
82
+ constructor(dialect: Dialect, tables?: CoreConcept[] | (() => CoreConcept[]));
82
83
  getDialect(): Dialect;
83
- getTables(): Map<string, CoreConcept>;
84
+ __getTables(): Map<string, CoreConcept>;
84
85
  beforeAll(setupConnString?: boolean): Promise<void>;
85
86
  createImpl(table: CoreConcept): Promise<void>;
86
87
  getSqliteClient(): SqliteDatabase;
@@ -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];
@@ -22,7 +26,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
22
26
  return (mod && mod.__esModule) ? mod : { "default": mod };
23
27
  };
24
28
  Object.defineProperty(exports, "__esModule", { value: true });
25
- exports.getColumnFromField = exports.getSchemaTable = exports.setupSqlite = exports.assoc_edge_table = exports.assoc_edge_config_table = exports.TempDB = exports.enumType = exports.table = exports.boolList = exports.dateList = exports.timetzList = exports.timeList = exports.timestamptzList = exports.timestampList = exports.uuidList = exports.integerList = exports.textList = exports.jsonb = exports.json = exports.float = exports.integer = exports.bool = exports.date = exports.timetz = exports.time = exports.timestamptz = exports.timestamp = exports.enumCol = exports.text = exports.uuid = exports.uniqueIndex = exports.index = exports.foreignKey = exports.primaryKey = void 0;
29
+ exports.getColumnFromField = exports.getSchemaTable = exports.setupSqlite = exports.assoc_edge_table = exports.assoc_edge_config_table = exports.TempDB = exports.enumType = exports.table = exports.boolList = exports.dateList = exports.timetzList = exports.timeList = exports.timestamptzList = exports.timestampList = exports.uuidList = exports.integerList = exports.textList = exports.jsonb = exports.json = exports.float = exports.integer = exports.bool = exports.date = exports.timetz = exports.time = exports.timestamptz = exports.timestamp = exports.enumCol = exports.text = exports.uuid = exports.index = exports.foreignKey = exports.primaryKey = void 0;
26
30
  const pg_1 = require("pg");
27
31
  const db_1 = __importStar(require("../../core/db"));
28
32
  // this should only be used in tests so we expect to be able to import without shenanigans
@@ -51,25 +55,26 @@ function foreignKey(name, cols, fkey) {
51
55
  };
52
56
  }
53
57
  exports.foreignKey = foreignKey;
58
+ function isPostCreateIndex(s) {
59
+ return (s.postCreate !== undefined &&
60
+ s.postCreate());
61
+ }
54
62
  function index(tableName, cols, opts) {
55
63
  const name = `${tableName}_${cols.join("_")}_idx`;
56
64
  return {
57
65
  name,
58
66
  generate() {
59
- return `CREATE INDEX ${name} ON ${tableName} USING ${opts?.type || "btree"} (${cols.join(",")});`;
67
+ if (opts?.unique && db_1.Dialect.SQLite === db_1.default.getDialect()) {
68
+ return `UNIQUE (${cols.join(",")})`;
69
+ }
70
+ return `CREATE ${opts?.unique ? "UNIQUE " : ""}INDEX ${name} ON ${tableName} USING ${opts?.type || "btree"} (${cols.join(",")});`;
60
71
  },
61
- };
62
- }
63
- exports.index = index;
64
- function uniqueIndex(name) {
65
- return {
66
- name: "",
67
- generate() {
68
- return `UNIQUE (${name})`;
72
+ postCreate() {
73
+ return db_1.Dialect.Postgres === db_1.default.getDialect() && !!opts?.unique;
69
74
  },
70
75
  };
71
76
  }
72
- exports.uniqueIndex = uniqueIndex;
77
+ exports.index = index;
73
78
  function uuid(name, opts) {
74
79
  return {
75
80
  name,
@@ -287,7 +292,12 @@ function table(name, ...items) {
287
292
  cols.push(item);
288
293
  }
289
294
  else if (item.generate !== undefined) {
290
- constraints.push(item);
295
+ if (isPostCreateIndex(item) && item.postCreate()) {
296
+ indexes.push(item);
297
+ }
298
+ else {
299
+ constraints.push(item);
300
+ }
291
301
  }
292
302
  }
293
303
  return {
@@ -351,23 +361,15 @@ function isDialect(dialect) {
351
361
  class TempDB {
352
362
  constructor(dialect, tables) {
353
363
  this.tables = new Map();
354
- let tbles = [];
355
- if (isDialect(dialect)) {
356
- this.dialect = dialect;
357
- if (tables) {
358
- tbles = tables;
359
- }
360
- }
361
- else {
362
- this.dialect = db_1.Dialect.Postgres;
363
- tbles = dialect;
364
- }
365
- tbles.forEach((table) => this.tables.set(table.name, table));
364
+ this.dialect = dialect;
365
+ this.setTables = tables;
366
366
  }
367
367
  getDialect() {
368
368
  return this.dialect;
369
369
  }
370
- getTables() {
370
+ // NB: this won't be set until after beforeAll() is called since it depends on
371
+ // dialect being correctly set
372
+ __getTables() {
371
373
  return this.tables;
372
374
  }
373
375
  async beforeAll(setupConnString = true) {
@@ -410,6 +412,16 @@ class TempDB {
410
412
  const filePath = process.env.DB_CONNECTION_STRING.substr(10);
411
413
  this.sqlite = (0, better_sqlite3_1.default)(filePath);
412
414
  }
415
+ if (this.setTables) {
416
+ let tables = [];
417
+ if (typeof this.setTables === "function") {
418
+ tables = this.setTables();
419
+ }
420
+ else {
421
+ tables = this.setTables;
422
+ }
423
+ tables.forEach((table) => this.tables.set(table.name, table));
424
+ }
413
425
  for (const [_, table] of this.tables) {
414
426
  await this.createImpl(table);
415
427
  }
@@ -507,7 +519,7 @@ function assoc_edge_table(name, global) {
507
519
  }
508
520
  exports.assoc_edge_table = assoc_edge_table;
509
521
  function setupSqlite(connString, tables, opts) {
510
- let tdb = new TempDB(db_1.Dialect.SQLite, tables());
522
+ let tdb = new TempDB(db_1.Dialect.SQLite, tables);
511
523
  beforeAll(async () => {
512
524
  process.env.DB_CONNECTION_STRING = connString;
513
525
  (0, config_1.loadConfig)();
@@ -518,7 +530,7 @@ function setupSqlite(connString, tables, opts) {
518
530
  if (!opts?.disableDeleteAfterEachTest) {
519
531
  afterEach(async () => {
520
532
  const client = await db_1.default.getInstance().getNewClient();
521
- for (const [key, _] of tdb.getTables()) {
533
+ for (const [key, _] of tdb.__getTables()) {
522
534
  const query = `delete from ${key}`;
523
535
  if (isSyncClient(client))
524
536
  if (client.execSync) {
@@ -185,7 +185,9 @@ class QueryRecorder {
185
185
  }
186
186
  }
187
187
  static mockPool(pool) {
188
- const mockedPool = (0, jest_mock_1.mocked)(pool, true);
188
+ const mockedPool = (0, jest_mock_1.mocked)(pool);
189
+ // @ts-ignore
190
+ // TODO what changed in mockImplementation?
189
191
  mockedPool.mockImplementation(() => {
190
192
  return {
191
193
  totalCount: 1,
@@ -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];
@@ -45,6 +49,7 @@ function server(config) {
45
49
  if (config.init) {
46
50
  config.init(app);
47
51
  }
52
+ // @ts-ignore something changed. come back
48
53
  app.use(express_1.default.json());
49
54
  let handlers = config.customHandlers || [];
50
55
  handlers.push(async (req, res) => {
@@ -56,9 +61,11 @@ function server(config) {
56
61
  request: req,
57
62
  schema: config.schema,
58
63
  contextFactory: async (executionContext) => {
64
+ // @ts-ignore something changed. come back
59
65
  return (0, auth_1.buildContext)(req, res);
60
66
  },
61
67
  });
68
+ // @ts-ignore something changed. come back
62
69
  await (0, graphql_helix_1.sendResult)(result, res);
63
70
  });
64
71
  app.use(config.graphQLPath || "/graphql", ...handlers);
@@ -18,7 +18,8 @@ export declare enum EdgeType {
18
18
  export declare enum NodeType {
19
19
  FakeUser = "user",
20
20
  FakeContact = "contact",
21
- FakeEvent = "event"
21
+ FakeEvent = "event",
22
+ FakeTag = "tag"
22
23
  }
23
24
  export declare const SymmetricEdges: Set<string>;
24
25
  export declare const InverseEdges: Map<EdgeType, EdgeType>;
@@ -27,6 +27,7 @@ var NodeType;
27
27
  NodeType["FakeUser"] = "user";
28
28
  NodeType["FakeContact"] = "contact";
29
29
  NodeType["FakeEvent"] = "event";
30
+ NodeType["FakeTag"] = "tag";
30
31
  })(NodeType = exports.NodeType || (exports.NodeType = {}));
31
32
  exports.SymmetricEdges = new Set();
32
33
  exports.SymmetricEdges.add(EdgeType.UserToFriends);
@@ -48,6 +49,8 @@ function getLoaderOptions(type) {
48
49
  return internal_1.FakeUser.loaderOptions();
49
50
  case NodeType.FakeEvent:
50
51
  return internal_1.FakeEvent.loaderOptions();
52
+ case NodeType.FakeTag:
53
+ return internal_1.FakeTag.loaderOptions();
51
54
  }
52
55
  }
53
56
  exports.getLoaderOptions = getLoaderOptions;
@@ -28,6 +28,8 @@ export interface ContactCreateInput {
28
28
  lastName: string;
29
29
  emailAddress: string;
30
30
  userID: ID;
31
+ createdAt?: Date;
32
+ updatedAt?: Date;
31
33
  }
32
34
  export declare function getContactBuilder(viewer: Viewer, input: ContactCreateInput): SimpleBuilder<FakeContact, null>;
33
35
  export declare function createContact(viewer: Viewer, input: ContactCreateInput): Promise<void>;