@snowtop/ent 0.1.0-alpha9 → 0.1.0-alpha90

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 (116) hide show
  1. package/action/action.d.ts +36 -31
  2. package/action/action.js +2 -6
  3. package/action/executor.d.ts +3 -3
  4. package/action/executor.js +2 -2
  5. package/action/experimental_action.d.ts +29 -22
  6. package/action/experimental_action.js +29 -6
  7. package/action/orchestrator.d.ts +38 -16
  8. package/action/orchestrator.js +219 -61
  9. package/action/privacy.d.ts +2 -2
  10. package/core/base.d.ts +45 -24
  11. package/core/base.js +7 -1
  12. package/core/clause.d.ts +68 -7
  13. package/core/clause.js +291 -62
  14. package/core/config.d.ts +8 -0
  15. package/core/context.d.ts +5 -3
  16. package/core/context.js +20 -2
  17. package/core/convert.d.ts +1 -1
  18. package/core/db.d.ts +2 -2
  19. package/core/db.js +1 -1
  20. package/core/ent.d.ts +79 -24
  21. package/core/ent.js +520 -168
  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 +2 -2
  25. package/core/loaders/index.d.ts +1 -1
  26. package/core/loaders/index.js +1 -3
  27. package/core/loaders/index_loader.d.ts +2 -2
  28. package/core/loaders/loader.js +5 -5
  29. package/core/loaders/object_loader.d.ts +6 -5
  30. package/core/loaders/object_loader.js +62 -58
  31. package/core/loaders/query_loader.d.ts +6 -12
  32. package/core/loaders/query_loader.js +47 -10
  33. package/core/loaders/raw_count_loader.d.ts +2 -2
  34. package/core/logger.d.ts +1 -1
  35. package/core/logger.js +1 -0
  36. package/core/privacy.d.ts +26 -25
  37. package/core/privacy.js +21 -25
  38. package/core/query/assoc_query.d.ts +6 -6
  39. package/core/query/custom_clause_query.d.ts +24 -0
  40. package/core/query/custom_clause_query.js +72 -0
  41. package/core/query/custom_query.d.ts +20 -5
  42. package/core/query/custom_query.js +77 -10
  43. package/core/query/index.d.ts +1 -0
  44. package/core/query/index.js +3 -1
  45. package/core/query/query.d.ts +1 -1
  46. package/core/query/query.js +8 -1
  47. package/core/query/shared_assoc_test.d.ts +1 -1
  48. package/core/query/shared_assoc_test.js +17 -5
  49. package/core/query/shared_test.d.ts +3 -0
  50. package/core/query/shared_test.js +211 -30
  51. package/core/viewer.d.ts +3 -3
  52. package/core/viewer.js +1 -1
  53. package/graphql/graphql.js +6 -0
  54. package/graphql/query/edge_connection.d.ts +9 -9
  55. package/graphql/query/page_info.d.ts +1 -1
  56. package/index.d.ts +11 -5
  57. package/index.js +15 -6
  58. package/package.json +1 -1
  59. package/parse_schema/parse.d.ts +12 -3
  60. package/parse_schema/parse.js +70 -11
  61. package/schema/base_schema.js +3 -0
  62. package/schema/field.d.ts +44 -8
  63. package/schema/field.js +125 -9
  64. package/schema/index.d.ts +2 -2
  65. package/schema/json_field.d.ts +13 -1
  66. package/schema/json_field.js +28 -1
  67. package/schema/schema.d.ts +65 -11
  68. package/schema/schema.js +18 -4
  69. package/schema/struct_field.d.ts +11 -1
  70. package/schema/struct_field.js +44 -5
  71. package/scripts/custom_graphql.js +8 -3
  72. package/scripts/{transform_schema.d.ts → migrate_v0.1.d.ts} +0 -0
  73. package/scripts/migrate_v0.1.js +36 -0
  74. package/scripts/read_schema.js +15 -4
  75. package/testutils/builder.d.ts +31 -21
  76. package/testutils/builder.js +83 -29
  77. package/testutils/db/fixture.d.ts +10 -0
  78. package/testutils/db/fixture.js +26 -0
  79. package/testutils/db/{test_db.d.ts → temp_db.d.ts} +15 -3
  80. package/testutils/db/{test_db.js → temp_db.js} +70 -16
  81. package/testutils/db/value.d.ts +6 -0
  82. package/testutils/db/value.js +251 -0
  83. package/testutils/db_time_zone.d.ts +4 -0
  84. package/testutils/db_time_zone.js +41 -0
  85. package/testutils/fake_data/fake_contact.d.ts +5 -4
  86. package/testutils/fake_data/fake_contact.js +14 -6
  87. package/testutils/fake_data/fake_event.d.ts +5 -3
  88. package/testutils/fake_data/fake_event.js +8 -5
  89. package/testutils/fake_data/fake_user.d.ts +4 -4
  90. package/testutils/fake_data/fake_user.js +16 -13
  91. package/testutils/fake_data/test_helpers.d.ts +3 -2
  92. package/testutils/fake_data/test_helpers.js +8 -6
  93. package/testutils/fake_data/user_query.d.ts +8 -6
  94. package/testutils/fake_data/user_query.js +28 -21
  95. package/testutils/fake_log.d.ts +3 -3
  96. package/testutils/parse_sql.d.ts +6 -0
  97. package/testutils/parse_sql.js +16 -2
  98. package/testutils/test_edge_global_schema.d.ts +15 -0
  99. package/testutils/test_edge_global_schema.js +58 -0
  100. package/testutils/write.d.ts +2 -2
  101. package/testutils/write.js +29 -7
  102. package/tsc/ast.d.ts +44 -0
  103. package/tsc/ast.js +267 -0
  104. package/tsc/compilerOptions.d.ts +6 -0
  105. package/tsc/compilerOptions.js +40 -1
  106. package/tsc/move_generated.d.ts +1 -0
  107. package/tsc/move_generated.js +160 -0
  108. package/tsc/transform.d.ts +21 -0
  109. package/tsc/transform.js +167 -0
  110. package/tsc/transform_action.d.ts +22 -0
  111. package/tsc/transform_action.js +179 -0
  112. package/tsc/transform_ent.d.ts +17 -0
  113. package/tsc/transform_ent.js +59 -0
  114. package/tsc/transform_schema.d.ts +27 -0
  115. package/tsc/transform_schema.js +379 -0
  116. package/scripts/transform_schema.js +0 -445
@@ -0,0 +1,251 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getDefaultValue = void 0;
4
+ const uuid_1 = require("uuid");
5
+ const schema_1 = require("../../schema");
6
+ const schema_2 = require("../../schema");
7
+ function random() {
8
+ return Math.random().toString(16).substring(2);
9
+ }
10
+ function randomEmail(domain) {
11
+ domain = domain || "email.com";
12
+ return `test+${random()}@${domain}`;
13
+ }
14
+ function randomPhoneNumber() {
15
+ return `+1${Math.random().toString(10).substring(2, 11)}`;
16
+ }
17
+ function coinFlip() {
18
+ return Math.floor(Math.random() * 10) >= 5;
19
+ }
20
+ function specialType(typ, col) {
21
+ let list = m.get(typ.dbType);
22
+ if (list?.length) {
23
+ for (const l of list) {
24
+ let regex = [];
25
+ if (Array.isArray(l.regex)) {
26
+ regex = l.regex;
27
+ }
28
+ else {
29
+ regex = [l.regex];
30
+ }
31
+ for (const r of regex) {
32
+ if (r.test(col)) {
33
+ return l.newValue();
34
+ }
35
+ }
36
+ }
37
+ }
38
+ return undefined;
39
+ }
40
+ function getDefaultValue(f, col, infos) {
41
+ if (f.defaultValueOnCreate) {
42
+ // @ts-ignore
43
+ return f.defaultValueOnCreate();
44
+ }
45
+ // half the time, return null for nullable
46
+ if (f.nullable && coinFlip()) {
47
+ return null;
48
+ }
49
+ const specialVal = specialType(f.type, col);
50
+ if (specialVal !== undefined) {
51
+ return specialVal;
52
+ }
53
+ return getValueForType(f.type, f, infos);
54
+ }
55
+ exports.getDefaultValue = getDefaultValue;
56
+ function getValueForType(typ, f, infos) {
57
+ switch (typ.dbType) {
58
+ case schema_1.DBType.UUID:
59
+ return (0, uuid_1.v4)();
60
+ case schema_1.DBType.Boolean:
61
+ return coinFlip();
62
+ case schema_1.DBType.Date:
63
+ return (0, schema_2.DateType)().format(new Date());
64
+ case schema_1.DBType.Time:
65
+ return (0, schema_2.TimeType)().format(new Date());
66
+ case schema_1.DBType.Timetz:
67
+ return (0, schema_2.TimetzType)().format(new Date());
68
+ case schema_1.DBType.Timestamp:
69
+ return (0, schema_2.TimestampType)().format(new Date());
70
+ case schema_1.DBType.Timestamptz:
71
+ return (0, schema_2.TimestamptzType)().format(new Date());
72
+ case schema_1.DBType.String:
73
+ return random();
74
+ case schema_1.DBType.Int:
75
+ return Math.floor(Math.random() * 100000000);
76
+ case schema_1.DBType.Float:
77
+ return Math.random() * 100000000;
78
+ case schema_1.DBType.Enum:
79
+ case schema_1.DBType.StringEnum:
80
+ if (typ.values) {
81
+ const idx = Math.floor(Math.random() * typ.values.length);
82
+ return typ.values[idx];
83
+ }
84
+ if (typ.enumMap) {
85
+ const vals = Object.values(typ.enumMap);
86
+ const idx = Math.floor(Math.random() * vals.length);
87
+ return vals[idx];
88
+ }
89
+ if (f.foreignKey) {
90
+ const schema = f.foreignKey.schema;
91
+ const col = f.foreignKey.column;
92
+ if (!infos) {
93
+ throw new Error(`infos required for enum with foreignKey`);
94
+ }
95
+ const info = infos.get(schema);
96
+ if (!info) {
97
+ throw new Error(`couldn't load data for schema ${schema}`);
98
+ }
99
+ if (!info.schema.dbRows) {
100
+ throw new Error(`no dbRows for schema ${schema}`);
101
+ }
102
+ const idx = Math.floor(Math.random() * info.schema.dbRows.length);
103
+ return info.schema.dbRows[idx][col];
104
+ }
105
+ throw new Error("TODO: enum without values not currently supported");
106
+ case schema_1.DBType.IntEnum:
107
+ const vals = Object.values(typ.intEnumMap);
108
+ const idx = Math.floor(Math.random() * vals.length);
109
+ return vals[idx];
110
+ case schema_1.DBType.BigInt:
111
+ return BigInt(Math.floor(Math.random() * 100000000));
112
+ case schema_1.DBType.JSONB:
113
+ // type as list
114
+ if (typ.listElemType?.dbType === schema_1.DBType.JSONB) {
115
+ const values = [];
116
+ for (let i = 0; i < 10; i++) {
117
+ values.push(getValueForType(typ.listElemType, f, infos));
118
+ }
119
+ if (!f.format) {
120
+ throw new Error("invalid format");
121
+ }
122
+ return f.format(values);
123
+ }
124
+ return (0, schema_2.JSONBType)().format({});
125
+ case schema_1.DBType.JSON:
126
+ return (0, schema_2.JSONType)().format({});
127
+ case schema_1.DBType.List:
128
+ // just do 10
129
+ const values = [];
130
+ for (let i = 0; i < 10; i++) {
131
+ values.push(getValueForType(f.type.listElemType, f.__getElemField(), infos));
132
+ }
133
+ if (!f.format) {
134
+ throw new Error("invalid format");
135
+ }
136
+ return f.format(values);
137
+ default:
138
+ throw new Error(`unsupported type ${typ.dbType}`);
139
+ }
140
+ }
141
+ const emailType = {
142
+ dbType: schema_1.DBType.String,
143
+ newValue: () => {
144
+ return (0, schema_2.StringType)().format(randomEmail().toLowerCase());
145
+ },
146
+ regex: /^email(_address)|_email$/,
147
+ };
148
+ const pdt = (0, schema_2.StringType)();
149
+ const phoneType = {
150
+ dbType: schema_1.DBType.String,
151
+ newValue: () => {
152
+ return randomPhoneNumber();
153
+ },
154
+ regex: /^phone(_number)?|_phone$|_phone_number$/,
155
+ };
156
+ const passwordType = {
157
+ dbType: schema_1.DBType.String,
158
+ newValue: () => {
159
+ // we don't use password type because when we're generating so many rows, it's too slow...
160
+ return random();
161
+ },
162
+ regex: /^password/,
163
+ };
164
+ const firstNames = [
165
+ "Daenerys",
166
+ "Jon",
167
+ "Arya",
168
+ "Sansa",
169
+ "Eddard",
170
+ "Khal",
171
+ "Robb",
172
+ "Joffrey",
173
+ "Ramsay",
174
+ "Cersei",
175
+ "Bolton",
176
+ "Oberyn",
177
+ "Jojen",
178
+ "Petyr",
179
+ "Brienne",
180
+ "Ygritte",
181
+ "Missandei",
182
+ "Shae",
183
+ "Sandor",
184
+ "Theon",
185
+ "Catelyn",
186
+ "Gilly",
187
+ "Samwell",
188
+ "Jaime",
189
+ "Stannis",
190
+ "Tyene",
191
+ "Obara",
192
+ "Nymeria",
193
+ "Elia",
194
+ "Ellaria",
195
+ "Myrcella",
196
+ "Hodor",
197
+ "Osha",
198
+ "Meera",
199
+ "Davos",
200
+ "Gendry",
201
+ ];
202
+ const lastNames = [
203
+ "Stark",
204
+ "Targaryen",
205
+ "Lannister",
206
+ "Drogo",
207
+ "Baratheon",
208
+ "Reed",
209
+ "Martell",
210
+ "Tyrell",
211
+ "Clegane",
212
+ "Baelish",
213
+ "Greyjoy",
214
+ "Tarly",
215
+ "Sand",
216
+ "Snow",
217
+ "Bolton",
218
+ "Frey",
219
+ "Tarth",
220
+ "Payne",
221
+ "Seaworth",
222
+ ];
223
+ const firstNameType = {
224
+ dbType: schema_1.DBType.String,
225
+ newValue: () => {
226
+ let idx = Math.floor(firstNames.length * Math.random());
227
+ return firstNames[idx];
228
+ },
229
+ regex: /^first_?(name)?/,
230
+ };
231
+ const lastNameType = {
232
+ dbType: schema_1.DBType.String,
233
+ newValue: () => {
234
+ let idx = Math.floor(lastNames.length * Math.random());
235
+ return lastNames[idx];
236
+ },
237
+ regex: /^last_?(name)?/,
238
+ };
239
+ let types = [
240
+ phoneType,
241
+ emailType,
242
+ passwordType,
243
+ firstNameType,
244
+ lastNameType,
245
+ ];
246
+ let m = new Map();
247
+ for (const type of types) {
248
+ let list = m.get(type.dbType) || [];
249
+ list.push(type);
250
+ m.set(type.dbType, list);
251
+ }
@@ -0,0 +1,4 @@
1
+ export declare class DBTimeZone {
2
+ private static getVal;
3
+ static getDateOffset(d: Date): Promise<string>;
4
+ }
@@ -0,0 +1,41 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.DBTimeZone = void 0;
7
+ const luxon_1 = require("luxon");
8
+ const schema_1 = require("../schema");
9
+ const db_1 = __importDefault(require("../core/db"));
10
+ let dbCurrentZone = undefined;
11
+ class DBTimeZone {
12
+ static async getVal() {
13
+ if (dbCurrentZone !== undefined) {
14
+ return dbCurrentZone;
15
+ }
16
+ const r = await db_1.default.getInstance()
17
+ .getPool()
18
+ .query("SELECT current_setting('TIMEZONE');");
19
+ if (r.rows.length) {
20
+ dbCurrentZone = r.rows[0].current_setting;
21
+ }
22
+ else {
23
+ dbCurrentZone = null;
24
+ }
25
+ return dbCurrentZone;
26
+ }
27
+ static async getDateOffset(d) {
28
+ let zone = await DBTimeZone.getVal();
29
+ let dt = luxon_1.DateTime.fromJSDate(d);
30
+ if (zone) {
31
+ dt = dt.setZone(zone);
32
+ }
33
+ // use
34
+ const val = (0, schema_1.leftPad)(dt.get("offset") / 60);
35
+ if (val == "00") {
36
+ return "+00";
37
+ }
38
+ return val;
39
+ }
40
+ }
41
+ exports.DBTimeZone = DBTimeZone;
@@ -1,4 +1,4 @@
1
- import { ID, Ent, Viewer, Data, LoadEntOptions, PrivacyPolicy } from "../../core/base";
1
+ import { ID, Ent, Viewer, Data, LoadEntOptions, PrivacyPolicy, Context } from "../../core/base";
2
2
  import { SimpleBuilder } from "../builder";
3
3
  import { NodeType } from "./const";
4
4
  import { ObjectLoaderFactory } from "../../core/loaders";
@@ -13,13 +13,14 @@ export declare class FakeContact implements Ent {
13
13
  readonly lastName: string;
14
14
  readonly emailAddress: string;
15
15
  readonly userID: ID;
16
- privacyPolicy: PrivacyPolicy;
16
+ getPrivacyPolicy(): PrivacyPolicy<this>;
17
17
  constructor(viewer: Viewer, data: Data);
18
18
  static getFields(): string[];
19
- static getTestTable(): import("../db/test_db").Table;
19
+ static getTestTable(): import("../db/temp_db").Table;
20
20
  static loaderOptions(): LoadEntOptions<FakeContact>;
21
21
  static load(v: Viewer, id: ID): Promise<FakeContact | null>;
22
22
  static loadX(v: Viewer, id: ID): Promise<FakeContact>;
23
+ static loadRawData(id: ID, context?: Context): Promise<Data | null>;
23
24
  }
24
25
  export declare const FakeContactSchema: import("../builder").BuilderSchema<FakeContact>;
25
26
  export interface ContactCreateInput {
@@ -28,6 +29,6 @@ export interface ContactCreateInput {
28
29
  emailAddress: string;
29
30
  userID: ID;
30
31
  }
31
- export declare function getContactBuilder(viewer: Viewer, input: ContactCreateInput): SimpleBuilder<FakeContact>;
32
+ export declare function getContactBuilder(viewer: Viewer, input: ContactCreateInput): SimpleBuilder<FakeContact, null>;
32
33
  export declare function createContact(viewer: Viewer, input: ContactCreateInput): Promise<void>;
33
34
  export declare const contactLoader: ObjectLoaderFactory<unknown>;
@@ -6,16 +6,14 @@ const privacy_1 = require("../../core/privacy");
6
6
  const builder_1 = require("../builder");
7
7
  const schema_1 = require("../../schema");
8
8
  const const_1 = require("./const");
9
- const test_db_1 = require("../db/test_db");
9
+ const temp_db_1 = require("../db/temp_db");
10
10
  const loaders_1 = require("../../core/loaders");
11
11
  const convert_1 = require("../../core/convert");
12
+ const action_1 = require("../../action");
12
13
  class FakeContact {
13
14
  constructor(viewer, data) {
14
15
  this.viewer = viewer;
15
16
  this.nodeType = const_1.NodeType.FakeContact;
16
- this.privacyPolicy = {
17
- rules: [new privacy_1.AllowIfViewerIsRule("userID"), privacy_1.AlwaysDenyRule],
18
- };
19
17
  this.data = data;
20
18
  this.id = data.id;
21
19
  this.createdAt = (0, convert_1.convertDate)(data.created_at);
@@ -25,6 +23,11 @@ class FakeContact {
25
23
  this.emailAddress = data.email_address;
26
24
  this.userID = data.user_id;
27
25
  }
26
+ getPrivacyPolicy() {
27
+ return {
28
+ rules: [new privacy_1.AllowIfViewerIsRule("userID"), privacy_1.AlwaysDenyRule],
29
+ };
30
+ }
28
31
  static getFields() {
29
32
  return [
30
33
  "id",
@@ -37,7 +40,7 @@ class FakeContact {
37
40
  ];
38
41
  }
39
42
  static getTestTable() {
40
- return (0, test_db_1.table)("fake_contacts", (0, test_db_1.uuid)("id", { primaryKey: true }), (0, test_db_1.timestamptz)("created_at"), (0, test_db_1.timestamptz)("updated_at"), (0, test_db_1.text)("first_name"), (0, test_db_1.text)("last_name"), (0, test_db_1.text)("email_address"), (0, test_db_1.uuid)("user_id"));
43
+ return (0, temp_db_1.table)("fake_contacts", (0, temp_db_1.uuid)("id", { primaryKey: true }), (0, temp_db_1.timestamptz)("created_at"), (0, temp_db_1.timestamptz)("updated_at"), (0, temp_db_1.text)("first_name"), (0, temp_db_1.text)("last_name"), (0, temp_db_1.text)("email_address"), (0, temp_db_1.uuid)("user_id"));
41
44
  }
42
45
  static loaderOptions() {
43
46
  return {
@@ -57,6 +60,11 @@ class FakeContact {
57
60
  static async loadX(v, id) {
58
61
  return (0, ent_1.loadEntX)(v, id, FakeContact.loaderOptions());
59
62
  }
63
+ static async loadRawData(id, context) {
64
+ return FakeContact.loaderOptions()
65
+ .loaderFactory.createLoader(context)
66
+ .load(id);
67
+ }
60
68
  }
61
69
  exports.FakeContact = FakeContact;
62
70
  exports.FakeContactSchema = (0, builder_1.getBuilderSchemaFromFields)({
@@ -75,7 +83,7 @@ function getContactBuilder(viewer, input) {
75
83
  //To lock in the value of Date now incase of advanceTo/advanceBy
76
84
  m.set("createdAt", new Date());
77
85
  m.set("updatedAt", new Date());
78
- return new builder_1.SimpleBuilder(viewer, exports.FakeContactSchema, m);
86
+ return new builder_1.SimpleBuilder(viewer, exports.FakeContactSchema, m, action_1.WriteOperation.Insert, null);
79
87
  }
80
88
  exports.getContactBuilder = getContactBuilder;
81
89
  async function createContact(viewer, input) {
@@ -14,16 +14,18 @@ export declare class FakeEvent implements Ent {
14
14
  readonly title: string;
15
15
  readonly description: string | null;
16
16
  readonly userID: ID;
17
- privacyPolicy: PrivacyPolicy;
17
+ getPrivacyPolicy(): PrivacyPolicy<this>;
18
18
  constructor(viewer: Viewer, data: Data);
19
19
  private static getFields;
20
- static getTestTable(): import("../db/test_db").Table;
20
+ static getTestTable(): import("../db/temp_db").Table;
21
21
  static loaderOptions(): LoadEntOptions<FakeEvent>;
22
22
  static load(v: Viewer, id: ID): Promise<FakeEvent | null>;
23
23
  static loadX(v: Viewer, id: ID): Promise<FakeEvent>;
24
24
  }
25
25
  export declare const FakeEventSchema: import("../builder").BuilderSchema<FakeEvent>;
26
26
  export interface EventCreateInput {
27
+ createdAt?: Date;
28
+ updatedAt?: Date;
27
29
  startTime: Date;
28
30
  endTime?: Date | null;
29
31
  location: string;
@@ -31,5 +33,5 @@ export interface EventCreateInput {
31
33
  description?: string | null;
32
34
  userID: ID;
33
35
  }
34
- export declare function getEventBuilder(viewer: Viewer, input: EventCreateInput): SimpleBuilder<FakeEvent>;
36
+ export declare function getEventBuilder(viewer: Viewer, input: EventCreateInput): SimpleBuilder<FakeEvent, null>;
35
37
  export declare function createEvent(viewer: Viewer, input: EventCreateInput): Promise<void>;
@@ -6,14 +6,14 @@ const privacy_1 = require("../../core/privacy");
6
6
  const builder_1 = require("../builder");
7
7
  const schema_1 = require("../../schema");
8
8
  const const_1 = require("./const");
9
- const test_db_1 = require("../db/test_db");
9
+ const temp_db_1 = require("../db/temp_db");
10
10
  const loaders_1 = require("../../core/loaders");
11
11
  const convert_1 = require("../../core/convert");
12
+ const action_1 = require("../../action");
12
13
  class FakeEvent {
13
14
  constructor(viewer, data) {
14
15
  this.viewer = viewer;
15
16
  this.nodeType = const_1.NodeType.FakeEvent;
16
- this.privacyPolicy = privacy_1.AlwaysAllowPrivacyPolicy;
17
17
  this.data = data;
18
18
  this.id = data.id;
19
19
  this.createdAt = (0, convert_1.convertDate)(data.created_at);
@@ -25,6 +25,9 @@ class FakeEvent {
25
25
  this.description = data.description;
26
26
  this.userID = data.user_id;
27
27
  }
28
+ getPrivacyPolicy() {
29
+ return privacy_1.AlwaysAllowPrivacyPolicy;
30
+ }
28
31
  static getFields() {
29
32
  return [
30
33
  "id",
@@ -39,9 +42,9 @@ class FakeEvent {
39
42
  ];
40
43
  }
41
44
  static getTestTable() {
42
- return (0, test_db_1.table)("fake_events", (0, test_db_1.uuid)("id", { primaryKey: true }), (0, test_db_1.timestamptz)("created_at"), (0, test_db_1.timestamptz)("updated_at"),
45
+ return (0, temp_db_1.table)("fake_events", (0, temp_db_1.uuid)("id", { primaryKey: true }), (0, temp_db_1.timestamptz)("created_at"), (0, temp_db_1.timestamptz)("updated_at"),
43
46
  // TODO index:true
44
- (0, test_db_1.timestamptz)("start_time"), (0, test_db_1.timestamptz)("end_time", { nullable: true }), (0, test_db_1.text)("location"), (0, test_db_1.text)("title"), (0, test_db_1.text)("description", { nullable: true }), (0, test_db_1.uuid)("user_id"));
47
+ (0, temp_db_1.timestamptz)("start_time"), (0, temp_db_1.timestamptz)("end_time", { nullable: true }), (0, temp_db_1.text)("location"), (0, temp_db_1.text)("title"), (0, temp_db_1.text)("description", { nullable: true }), (0, temp_db_1.uuid)("user_id"));
45
48
  }
46
49
  static loaderOptions() {
47
50
  return {
@@ -84,7 +87,7 @@ function getEventBuilder(viewer, input) {
84
87
  for (const key in input) {
85
88
  m.set(key, input[key]);
86
89
  }
87
- return new builder_1.SimpleBuilder(viewer, exports.FakeEventSchema, m);
90
+ return new builder_1.SimpleBuilder(viewer, exports.FakeEventSchema, m, action_1.WriteOperation.Insert, null);
88
91
  }
89
92
  exports.getEventBuilder = getEventBuilder;
90
93
  async function createEvent(viewer, input) {
@@ -23,10 +23,10 @@ export declare class FakeUser implements Ent {
23
23
  readonly emailAddress: string;
24
24
  readonly phoneNumber: string | null;
25
25
  protected readonly password: string | null;
26
- privacyPolicy: PrivacyPolicy;
26
+ getPrivacyPolicy(): PrivacyPolicy<this>;
27
27
  constructor(viewer: Viewer, data: Data);
28
28
  static getFields(): string[];
29
- static getTestTable(): import("../db/test_db").Table;
29
+ static getTestTable(): import("../db/temp_db").Table;
30
30
  static loaderOptions(): LoadEntOptions<FakeUser>;
31
31
  static load(v: Viewer, id: ID): Promise<FakeUser | null>;
32
32
  static loadX(v: Viewer, id: ID): Promise<FakeUser>;
@@ -40,8 +40,8 @@ export interface UserCreateInput {
40
40
  password: string | null;
41
41
  }
42
42
  export declare type UserEditInput = Partial<UserCreateInput>;
43
- export declare function getUserBuilder(viewer: Viewer, input: UserCreateInput): import("../builder").SimpleBuilder<FakeUser>;
44
- export declare function getUserAction(viewer: Viewer, input: UserCreateInput): SimpleAction<FakeUser>;
43
+ export declare function getUserBuilder(viewer: Viewer, input: UserCreateInput): import("../builder").SimpleBuilder<FakeUser, null>;
44
+ export declare function getUserAction(viewer: Viewer, input: UserCreateInput): SimpleAction<FakeUser, null>;
45
45
  export declare function createUser(viewer: Viewer, input: UserCreateInput): Promise<FakeUser>;
46
46
  export declare const userLoader: ObjectLoaderFactory<unknown>;
47
47
  export declare const userEmailLoader: ObjectLoaderFactory<unknown>;
@@ -8,9 +8,10 @@ const schema_1 = require("../../schema");
8
8
  const internal_1 = require("./internal");
9
9
  const const_1 = require("./const");
10
10
  const viewer_1 = require("../../core/viewer");
11
- const test_db_1 = require("../db/test_db");
11
+ const temp_db_1 = require("../db/temp_db");
12
12
  const loaders_1 = require("../../core/loaders");
13
13
  const convert_1 = require("../../core/convert");
14
+ const action_1 = require("../../action");
14
15
  class ViewerWithAccessToken extends viewer_1.IDViewer {
15
16
  constructor(viewerID, opts) {
16
17
  super(viewerID, opts);
@@ -26,7 +27,18 @@ class FakeUser {
26
27
  constructor(viewer, data) {
27
28
  this.viewer = viewer;
28
29
  this.nodeType = const_1.NodeType.FakeUser;
29
- this.privacyPolicy = {
30
+ this.data = data;
31
+ this.id = data.id;
32
+ this.createdAt = (0, convert_1.convertDate)(data.created_at);
33
+ this.updatedAt = (0, convert_1.convertDate)(data.updated_at);
34
+ this.firstName = data.first_name;
35
+ this.lastName = data.last_name;
36
+ this.emailAddress = data.email_address;
37
+ this.phoneNumber = data.phone_number;
38
+ this.password = data.password;
39
+ }
40
+ getPrivacyPolicy() {
41
+ return {
30
42
  rules: [
31
43
  privacy_1.AllowIfViewerRule,
32
44
  //can view user if friends
@@ -48,15 +60,6 @@ class FakeUser {
48
60
  privacy_1.AlwaysDenyRule,
49
61
  ],
50
62
  };
51
- this.data = data;
52
- this.id = data.id;
53
- this.createdAt = (0, convert_1.convertDate)(data.created_at);
54
- this.updatedAt = (0, convert_1.convertDate)(data.updated_at);
55
- this.firstName = data.first_name;
56
- this.lastName = data.last_name;
57
- this.emailAddress = data.email_address;
58
- this.phoneNumber = data.phone_number;
59
- this.password = data.password;
60
63
  }
61
64
  static getFields() {
62
65
  return [
@@ -71,7 +74,7 @@ class FakeUser {
71
74
  ];
72
75
  }
73
76
  static getTestTable() {
74
- return (0, test_db_1.table)("fake_users", (0, test_db_1.uuid)("id", { primaryKey: true }), (0, test_db_1.timestamptz)("created_at"), (0, test_db_1.timestamptz)("updated_at"), (0, test_db_1.text)("first_name"), (0, test_db_1.text)("last_name"), (0, test_db_1.text)("email_address"), (0, test_db_1.text)("phone_number"), (0, test_db_1.text)("password"));
77
+ return (0, temp_db_1.table)("fake_users", (0, temp_db_1.uuid)("id", { primaryKey: true }), (0, temp_db_1.timestamptz)("created_at"), (0, temp_db_1.timestamptz)("updated_at"), (0, temp_db_1.text)("first_name"), (0, temp_db_1.text)("last_name"), (0, temp_db_1.text)("email_address"), (0, temp_db_1.text)("phone_number"), (0, temp_db_1.text)("password"));
75
78
  }
76
79
  static loaderOptions() {
77
80
  return {
@@ -108,7 +111,7 @@ function getUserAction(viewer, input) {
108
111
  for (const key in input) {
109
112
  m.set(key, input[key]);
110
113
  }
111
- const action = new builder_1.SimpleAction(viewer, exports.FakeUserSchema, m);
114
+ const action = new builder_1.SimpleAction(viewer, exports.FakeUserSchema, m, action_1.WriteOperation.Insert, null);
112
115
  action.viewerForEntLoad = (data) => {
113
116
  // load the created ent using a VC of the newly created user.
114
117
  return new viewer_1.IDViewer(data.id);
@@ -1,6 +1,6 @@
1
1
  import { Data, Ent } from "../../core/base";
2
2
  import { AssocEdge } from "../../core/ent";
3
- import { TempDB } from "../db/test_db";
3
+ import { TempDB } from "../db/temp_db";
4
4
  import { FakeUser, UserCreateInput, ContactCreateInput, FakeContact } from ".";
5
5
  import { EventCreateInput, FakeEvent } from "./fake_event";
6
6
  import { BuilderSchema } from "../builder";
@@ -20,12 +20,13 @@ export declare function createEdges(): Promise<void>;
20
20
  export declare function edgeTableNames(): string[];
21
21
  export declare function createTestEvent(user: FakeUser, input?: Partial<EventCreateInput>): Promise<FakeEvent>;
22
22
  export declare function setupTempDB(): Promise<TempDB>;
23
- export declare function tempDBTables(): import("../db/test_db").Table[];
23
+ export declare function tempDBTables(global?: boolean): import("../db/temp_db").Table[];
24
24
  interface options {
25
25
  howMany: number;
26
26
  interval: number;
27
27
  userInput?: Partial<UserCreateInput>;
28
28
  eventInputs?: Partial<EventCreateInput>[];
29
+ startTime?: number | Date;
29
30
  }
30
31
  export declare function createAllEvents(opts: options): Promise<[FakeUser, FakeEvent[]]>;
31
32
  export {};
@@ -6,7 +6,7 @@ const viewer_1 = require("../../core/viewer");
6
6
  const ent_1 = require("../../core/ent");
7
7
  const snake_case_1 = require("snake-case");
8
8
  const write_1 = require("../write");
9
- const test_db_1 = require("../db/test_db");
9
+ const temp_db_1 = require("../db/temp_db");
10
10
  const _1 = require(".");
11
11
  const fake_event_1 = require("./fake_event");
12
12
  const const_1 = require("./const");
@@ -41,6 +41,8 @@ function getEventInput(user, input) {
41
41
  title: "title",
42
42
  description: "fun event",
43
43
  userID: user.id,
44
+ createdAt: new Date(),
45
+ updatedAt: new Date(),
44
46
  ...input,
45
47
  };
46
48
  }
@@ -209,21 +211,21 @@ async function createTestEvent(user, input) {
209
211
  }
210
212
  exports.createTestEvent = createTestEvent;
211
213
  async function setupTempDB() {
212
- const tdb = new test_db_1.TempDB(tempDBTables());
214
+ const tdb = new temp_db_1.TempDB(tempDBTables());
213
215
  await tdb.beforeAll();
214
216
  // create once
215
217
  await createEdges();
216
218
  return tdb;
217
219
  }
218
220
  exports.setupTempDB = setupTempDB;
219
- function tempDBTables() {
221
+ function tempDBTables(global = false) {
220
222
  const tables = [
221
223
  _1.FakeUser.getTestTable(),
222
224
  _1.FakeContact.getTestTable(),
223
225
  fake_event_1.FakeEvent.getTestTable(),
224
- (0, test_db_1.assoc_edge_config_table)(),
226
+ (0, temp_db_1.assoc_edge_config_table)(),
225
227
  ];
226
- edgeTableNames().forEach((tableName) => tables.push((0, test_db_1.assoc_edge_table)(tableName)));
228
+ edgeTableNames().forEach((tableName) => tables.push((0, temp_db_1.assoc_edge_table)(tableName, global)));
227
229
  return tables;
228
230
  }
229
231
  exports.tempDBTables = tempDBTables;
@@ -232,7 +234,7 @@ async function createAllEvents(opts) {
232
234
  let arr = new Array(opts.howMany);
233
235
  arr.fill(1);
234
236
  // start at date in case something else has used a date already
235
- (0, jest_date_mock_1.advanceTo)(mock_date_1.MockDate.getDate());
237
+ (0, jest_date_mock_1.advanceTo)(opts.startTime || mock_date_1.MockDate.getDate());
236
238
  const events = await Promise.all(arr.map(async (v, idx) => {
237
239
  // just to make times deterministic so that tests can consistently work
238
240
  if (opts.interval > 0) {