@snowtop/ent 0.1.0-alpha8 → 0.1.0-alpha80
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.
- package/action/action.d.ts +27 -25
- package/action/executor.d.ts +3 -3
- package/action/executor.js +2 -2
- package/action/experimental_action.d.ts +29 -22
- package/action/experimental_action.js +29 -6
- package/action/orchestrator.d.ts +37 -16
- package/action/orchestrator.js +184 -54
- package/action/privacy.d.ts +2 -2
- package/core/base.d.ts +38 -22
- package/core/clause.d.ts +65 -7
- package/core/clause.js +261 -54
- package/core/config.d.ts +8 -0
- package/core/context.d.ts +5 -3
- package/core/context.js +7 -2
- package/core/convert.d.ts +1 -1
- package/core/db.d.ts +1 -2
- package/core/db.js +1 -1
- package/core/ent.d.ts +76 -24
- package/core/ent.js +459 -143
- package/core/loaders/assoc_count_loader.d.ts +2 -2
- package/core/loaders/assoc_count_loader.js +6 -1
- package/core/loaders/assoc_edge_loader.d.ts +2 -2
- package/core/loaders/loader.js +5 -5
- package/core/loaders/object_loader.d.ts +4 -3
- package/core/loaders/object_loader.js +22 -5
- package/core/loaders/query_loader.d.ts +2 -2
- package/core/loaders/raw_count_loader.d.ts +2 -2
- package/core/logger.d.ts +1 -1
- package/core/logger.js +1 -0
- package/core/privacy.d.ts +26 -25
- package/core/privacy.js +21 -25
- package/core/query/assoc_query.d.ts +6 -6
- package/core/query/custom_query.d.ts +5 -5
- package/core/query/query.d.ts +1 -1
- package/core/query/shared_assoc_test.d.ts +1 -1
- package/core/query/shared_assoc_test.js +17 -5
- package/core/query/shared_test.d.ts +3 -0
- package/core/query/shared_test.js +95 -17
- package/core/viewer.d.ts +3 -3
- package/core/viewer.js +1 -1
- package/graphql/builtins/connection.js +3 -3
- package/graphql/builtins/edge.js +2 -2
- package/graphql/builtins/node.js +1 -1
- package/graphql/graphql.js +8 -2
- package/graphql/query/connection_type.js +6 -6
- package/graphql/query/edge_connection.d.ts +9 -9
- package/graphql/query/page_info.d.ts +1 -1
- package/graphql/query/page_info.js +4 -4
- package/graphql/query/shared_assoc_test.js +2 -2
- package/graphql/scalars/time.d.ts +1 -1
- package/index.d.ts +10 -5
- package/index.js +13 -6
- package/package.json +2 -2
- package/parse_schema/parse.d.ts +14 -2
- package/parse_schema/parse.js +40 -2
- package/schema/base_schema.d.ts +1 -1
- package/schema/base_schema.js +3 -0
- package/schema/field.d.ts +36 -7
- package/schema/field.js +70 -2
- package/schema/index.d.ts +2 -2
- package/schema/json_field.d.ts +13 -1
- package/schema/json_field.js +28 -1
- package/schema/schema.d.ts +61 -10
- package/schema/schema.js +18 -4
- package/schema/struct_field.d.ts +11 -1
- package/schema/struct_field.js +43 -4
- package/scripts/custom_graphql.js +5 -1
- package/scripts/{transform_schema.d.ts → migrate_v0.1.d.ts} +0 -0
- package/scripts/migrate_v0.1.js +36 -0
- package/scripts/read_schema.js +25 -2
- package/testutils/builder.d.ts +31 -21
- package/testutils/builder.js +82 -29
- package/testutils/db/fixture.d.ts +10 -0
- package/testutils/db/fixture.js +26 -0
- package/testutils/db/{test_db.d.ts → temp_db.d.ts} +15 -3
- package/testutils/db/{test_db.js → temp_db.js} +63 -15
- package/testutils/db/value.d.ts +6 -0
- package/testutils/db/value.js +251 -0
- package/testutils/db_time_zone.d.ts +4 -0
- package/testutils/db_time_zone.js +41 -0
- package/testutils/ent-graphql-tests/index.js +19 -12
- package/testutils/fake_data/fake_contact.d.ts +3 -3
- package/testutils/fake_data/fake_contact.js +9 -6
- package/testutils/fake_data/fake_event.d.ts +3 -3
- package/testutils/fake_data/fake_event.js +8 -5
- package/testutils/fake_data/fake_user.d.ts +4 -4
- package/testutils/fake_data/fake_user.js +16 -13
- package/testutils/fake_data/test_helpers.d.ts +2 -2
- package/testutils/fake_data/test_helpers.js +5 -5
- package/testutils/fake_data/user_query.d.ts +2 -2
- package/testutils/fake_log.d.ts +3 -3
- package/testutils/parse_sql.d.ts +6 -0
- package/testutils/parse_sql.js +16 -2
- package/testutils/test_edge_global_schema.d.ts +15 -0
- package/testutils/test_edge_global_schema.js +58 -0
- package/testutils/write.d.ts +2 -2
- package/testutils/write.js +29 -7
- package/tsc/ast.d.ts +44 -0
- package/tsc/ast.js +267 -0
- package/tsc/compilerOptions.d.ts +6 -0
- package/tsc/compilerOptions.js +40 -1
- package/tsc/move_generated.d.ts +1 -0
- package/tsc/move_generated.js +160 -0
- package/tsc/transform.d.ts +21 -0
- package/tsc/transform.js +167 -0
- package/tsc/transform_action.d.ts +22 -0
- package/tsc/transform_action.js +179 -0
- package/tsc/transform_ent.d.ts +17 -0
- package/tsc/transform_ent.js +59 -0
- package/tsc/transform_schema.d.ts +27 -0
- package/tsc/transform_schema.js +379 -0
- package/scripts/transform_schema.js +0 -437
|
@@ -22,7 +22,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
22
22
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
23
23
|
};
|
|
24
24
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
25
|
-
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.foreignKey = exports.primaryKey = void 0;
|
|
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;
|
|
26
26
|
const pg_1 = require("pg");
|
|
27
27
|
const db_1 = __importStar(require("../../core/db"));
|
|
28
28
|
// this should only be used in tests so we expect to be able to import without shenanigans
|
|
@@ -32,6 +32,7 @@ const fs = __importStar(require("fs"));
|
|
|
32
32
|
const schema_1 = require("../../schema");
|
|
33
33
|
const snake_case_1 = require("snake-case");
|
|
34
34
|
const builder_1 = require("../builder");
|
|
35
|
+
const test_edge_global_schema_1 = require("../test_edge_global_schema");
|
|
35
36
|
function primaryKey(name, cols) {
|
|
36
37
|
return {
|
|
37
38
|
name: name,
|
|
@@ -50,6 +51,16 @@ function foreignKey(name, cols, fkey) {
|
|
|
50
51
|
};
|
|
51
52
|
}
|
|
52
53
|
exports.foreignKey = foreignKey;
|
|
54
|
+
function index(tableName, cols, opts) {
|
|
55
|
+
const name = `${tableName}_${cols.join("_")}_idx`;
|
|
56
|
+
return {
|
|
57
|
+
name,
|
|
58
|
+
generate() {
|
|
59
|
+
return `CREATE INDEX ${name} ON ${tableName} USING ${opts?.type || "btree"} (${cols.join(",")});`;
|
|
60
|
+
},
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
exports.index = index;
|
|
53
64
|
function uniqueIndex(name) {
|
|
54
65
|
return {
|
|
55
66
|
name: "",
|
|
@@ -248,9 +259,24 @@ exports.boolList = boolList;
|
|
|
248
259
|
function table(name, ...items) {
|
|
249
260
|
let cols = [];
|
|
250
261
|
let constraints = [];
|
|
262
|
+
let indexes = [];
|
|
251
263
|
for (const item of items) {
|
|
252
264
|
if (item.datatype !== undefined) {
|
|
253
265
|
const col = item;
|
|
266
|
+
if (col.index) {
|
|
267
|
+
let opts = {
|
|
268
|
+
type: "btree",
|
|
269
|
+
};
|
|
270
|
+
if (col.index === true) {
|
|
271
|
+
opts = {
|
|
272
|
+
type: "btree",
|
|
273
|
+
};
|
|
274
|
+
}
|
|
275
|
+
else {
|
|
276
|
+
opts = col.index;
|
|
277
|
+
}
|
|
278
|
+
indexes.push(index(name, [col.name], opts));
|
|
279
|
+
}
|
|
254
280
|
// add it as a constraint
|
|
255
281
|
if (col.foreignKey) {
|
|
256
282
|
constraints.push(foreignKey(`${name}_${col.name}_fkey`, [col.name], {
|
|
@@ -288,6 +314,9 @@ function table(name, ...items) {
|
|
|
288
314
|
constraints.forEach((constraint) => schemaStr.push(constraint.generate()));
|
|
289
315
|
return `CREATE TABLE IF NOT EXISTS ${name} (\n ${schemaStr})`;
|
|
290
316
|
},
|
|
317
|
+
postCreate() {
|
|
318
|
+
return indexes.map((index) => index.generate());
|
|
319
|
+
},
|
|
291
320
|
drop() {
|
|
292
321
|
return `DROP TABLE IF EXISTS ${name}`;
|
|
293
322
|
},
|
|
@@ -376,11 +405,24 @@ class TempDB {
|
|
|
376
405
|
this.sqlite = (0, better_sqlite3_1.default)(filePath);
|
|
377
406
|
}
|
|
378
407
|
for (const [_, table] of this.tables) {
|
|
379
|
-
|
|
380
|
-
|
|
408
|
+
await this.createImpl(table);
|
|
409
|
+
}
|
|
410
|
+
}
|
|
411
|
+
async createImpl(table) {
|
|
412
|
+
if (this.dialect == db_1.Dialect.Postgres) {
|
|
413
|
+
await this.dbClient.query(table.create());
|
|
414
|
+
if (table.postCreate) {
|
|
415
|
+
for (const q of table.postCreate()) {
|
|
416
|
+
await this.dbClient.query(q);
|
|
417
|
+
}
|
|
381
418
|
}
|
|
382
|
-
|
|
383
|
-
|
|
419
|
+
}
|
|
420
|
+
else {
|
|
421
|
+
this.sqlite.exec(table.create());
|
|
422
|
+
if (table.postCreate) {
|
|
423
|
+
for (const q of table.postCreate()) {
|
|
424
|
+
this.sqlite.exec(q);
|
|
425
|
+
}
|
|
384
426
|
}
|
|
385
427
|
}
|
|
386
428
|
}
|
|
@@ -431,12 +473,7 @@ class TempDB {
|
|
|
431
473
|
if (this.tables.has(table.name)) {
|
|
432
474
|
throw new Error(`table with name ${table.name} already exists`);
|
|
433
475
|
}
|
|
434
|
-
|
|
435
|
-
await this.dbClient.query(table.create());
|
|
436
|
-
}
|
|
437
|
-
else {
|
|
438
|
-
this.sqlite.exec(table.create());
|
|
439
|
-
}
|
|
476
|
+
await this.createImpl(table);
|
|
440
477
|
this.tables.set(table.name, table);
|
|
441
478
|
}
|
|
442
479
|
}
|
|
@@ -448,18 +485,26 @@ function assoc_edge_config_table() {
|
|
|
448
485
|
text("edge_type", { primaryKey: true }), text("edge_name"), bool("symmetric_edge", { default: "FALSE" }), text("inverse_edge_type", { nullable: true }), text("edge_table"), timestamptz("created_at"), timestamptz("updated_at"));
|
|
449
486
|
}
|
|
450
487
|
exports.assoc_edge_config_table = assoc_edge_config_table;
|
|
451
|
-
|
|
452
|
-
|
|
488
|
+
// if global flag is true, add any column from testEdgeGlobalSchema
|
|
489
|
+
// up to caller to set/clear that as needed
|
|
490
|
+
function assoc_edge_table(name, global) {
|
|
491
|
+
const t = table(name, uuid("id1"), text("id1_type"),
|
|
453
492
|
// same as in assoc_edge_config_table
|
|
454
493
|
text("edge_type"), uuid("id2"), text("id2_type"), timestamptz("time"), text("data", { nullable: true }), primaryKey(`${name}_pkey`, ["id1", "id2", "edge_type"]));
|
|
494
|
+
if (global) {
|
|
495
|
+
for (const k in test_edge_global_schema_1.testEdgeGlobalSchema.extraEdgeFields) {
|
|
496
|
+
const col = getColumnFromField(k, test_edge_global_schema_1.testEdgeGlobalSchema.extraEdgeFields[k], db_1.Dialect.Postgres);
|
|
497
|
+
t.columns.push(col);
|
|
498
|
+
}
|
|
499
|
+
}
|
|
500
|
+
return t;
|
|
455
501
|
}
|
|
456
502
|
exports.assoc_edge_table = assoc_edge_table;
|
|
457
503
|
function setupSqlite(connString, tables, opts) {
|
|
458
|
-
let tdb;
|
|
504
|
+
let tdb = new TempDB(db_1.Dialect.SQLite, tables());
|
|
459
505
|
beforeAll(async () => {
|
|
460
506
|
process.env.DB_CONNECTION_STRING = connString;
|
|
461
507
|
(0, config_1.loadConfig)();
|
|
462
|
-
tdb = new TempDB(db_1.Dialect.SQLite, tables());
|
|
463
508
|
await tdb.beforeAll();
|
|
464
509
|
const conn = db_1.default.getInstance().getConnection();
|
|
465
510
|
expect(conn.db.memory).toBe(false);
|
|
@@ -482,7 +527,9 @@ function setupSqlite(connString, tables, opts) {
|
|
|
482
527
|
afterAll(async () => {
|
|
483
528
|
await tdb.afterAll();
|
|
484
529
|
fs.rmSync(tdb.getSqliteClient().name);
|
|
530
|
+
delete process.env.DB_CONNECTION_STRING;
|
|
485
531
|
});
|
|
532
|
+
return tdb;
|
|
486
533
|
}
|
|
487
534
|
exports.setupSqlite = setupSqlite;
|
|
488
535
|
function getSchemaTable(schema, dialect) {
|
|
@@ -549,6 +596,7 @@ function getColumnFromField(fieldName, f, dialect) {
|
|
|
549
596
|
return getColumn(fieldName, f, fn);
|
|
550
597
|
}
|
|
551
598
|
}
|
|
599
|
+
exports.getColumnFromField = getColumnFromField;
|
|
552
600
|
function getColumn(fieldName, f, col) {
|
|
553
601
|
return col(storageKey(fieldName, f), buildOpts(f));
|
|
554
602
|
}
|
|
@@ -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,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;
|
|
@@ -26,7 +26,7 @@ exports.expectMutation = exports.expectQueryFromRoot = void 0;
|
|
|
26
26
|
// NB: this is copied from ent-graphql-tests package until I have time to figure out how to share code here effectively
|
|
27
27
|
// the circular dependencies btw this package and ent-graphql-tests seems to imply something needs to change
|
|
28
28
|
const express_1 = __importDefault(require("express"));
|
|
29
|
-
const
|
|
29
|
+
const graphql_helix_1 = require("graphql-helix");
|
|
30
30
|
const graphql_1 = require("graphql");
|
|
31
31
|
const auth_1 = require("../../auth");
|
|
32
32
|
const supertest_1 = __importDefault(require("supertest"));
|
|
@@ -45,17 +45,22 @@ function server(config) {
|
|
|
45
45
|
if (config.init) {
|
|
46
46
|
config.init(app);
|
|
47
47
|
}
|
|
48
|
+
app.use(express_1.default.json());
|
|
48
49
|
let handlers = config.customHandlers || [];
|
|
49
|
-
handlers.push(
|
|
50
|
-
const
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
50
|
+
handlers.push(async (req, res) => {
|
|
51
|
+
const { operationName, query, variables } = (0, graphql_helix_1.getGraphQLParameters)(req);
|
|
52
|
+
const result = await (0, graphql_helix_1.processRequest)({
|
|
53
|
+
operationName,
|
|
54
|
+
query,
|
|
55
|
+
variables,
|
|
56
|
+
request: req,
|
|
57
|
+
schema: config.schema,
|
|
58
|
+
contextFactory: async (executionContext) => {
|
|
59
|
+
return (0, auth_1.buildContext)(req, res);
|
|
60
|
+
},
|
|
61
|
+
});
|
|
62
|
+
await (0, graphql_helix_1.sendResult)(result, res);
|
|
63
|
+
});
|
|
59
64
|
app.use(config.graphQLPath || "/graphql", ...handlers);
|
|
60
65
|
return app;
|
|
61
66
|
}
|
|
@@ -355,7 +360,9 @@ async function expectFromRoot(config, ...options) {
|
|
|
355
360
|
else {
|
|
356
361
|
expect(res.ok, `expected ok response. instead got ${res.status} and result ${JSON.stringify(res.body)}`);
|
|
357
362
|
}
|
|
358
|
-
|
|
363
|
+
// res.ok = true in graphql-helix when there's errors...
|
|
364
|
+
// res.ok = false in express-graphql when there's errors...
|
|
365
|
+
if (!res.ok || (res.body.errors && res.body.errors.length > 0)) {
|
|
359
366
|
let errors = res.body.errors;
|
|
360
367
|
expect(errors.length).toBeGreaterThan(0);
|
|
361
368
|
if (config.expectedError) {
|
|
@@ -13,10 +13,10 @@ export declare class FakeContact implements Ent {
|
|
|
13
13
|
readonly lastName: string;
|
|
14
14
|
readonly emailAddress: string;
|
|
15
15
|
readonly userID: ID;
|
|
16
|
-
|
|
16
|
+
getPrivacyPolicy(): PrivacyPolicy<this>;
|
|
17
17
|
constructor(viewer: Viewer, data: Data);
|
|
18
18
|
static getFields(): string[];
|
|
19
|
-
static getTestTable(): import("../db/
|
|
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>;
|
|
@@ -28,6 +28,6 @@ export interface ContactCreateInput {
|
|
|
28
28
|
emailAddress: string;
|
|
29
29
|
userID: ID;
|
|
30
30
|
}
|
|
31
|
-
export declare function getContactBuilder(viewer: Viewer, input: ContactCreateInput): SimpleBuilder<FakeContact>;
|
|
31
|
+
export declare function getContactBuilder(viewer: Viewer, input: ContactCreateInput): SimpleBuilder<FakeContact, null>;
|
|
32
32
|
export declare function createContact(viewer: Viewer, input: ContactCreateInput): Promise<void>;
|
|
33
33
|
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
|
|
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,
|
|
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 {
|
|
@@ -75,7 +78,7 @@ function getContactBuilder(viewer, input) {
|
|
|
75
78
|
//To lock in the value of Date now incase of advanceTo/advanceBy
|
|
76
79
|
m.set("createdAt", new Date());
|
|
77
80
|
m.set("updatedAt", new Date());
|
|
78
|
-
return new builder_1.SimpleBuilder(viewer, exports.FakeContactSchema, m);
|
|
81
|
+
return new builder_1.SimpleBuilder(viewer, exports.FakeContactSchema, m, action_1.WriteOperation.Insert, null);
|
|
79
82
|
}
|
|
80
83
|
exports.getContactBuilder = getContactBuilder;
|
|
81
84
|
async function createContact(viewer, input) {
|
|
@@ -14,10 +14,10 @@ export declare class FakeEvent implements Ent {
|
|
|
14
14
|
readonly title: string;
|
|
15
15
|
readonly description: string | null;
|
|
16
16
|
readonly userID: ID;
|
|
17
|
-
|
|
17
|
+
getPrivacyPolicy(): PrivacyPolicy<this>;
|
|
18
18
|
constructor(viewer: Viewer, data: Data);
|
|
19
19
|
private static getFields;
|
|
20
|
-
static getTestTable(): import("../db/
|
|
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>;
|
|
@@ -31,5 +31,5 @@ export interface EventCreateInput {
|
|
|
31
31
|
description?: string | null;
|
|
32
32
|
userID: ID;
|
|
33
33
|
}
|
|
34
|
-
export declare function getEventBuilder(viewer: Viewer, input: EventCreateInput): SimpleBuilder<FakeEvent>;
|
|
34
|
+
export declare function getEventBuilder(viewer: Viewer, input: EventCreateInput): SimpleBuilder<FakeEvent, null>;
|
|
35
35
|
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
|
|
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,
|
|
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,
|
|
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) {
|