@snowtop/ent 0.1.0-alpha96-2a5ea200-82e5-11ed-8c55-4da1cd949242 → 0.1.0-alpha97
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 +3 -3
- package/action/executor.js +6 -1
- package/action/experimental_action.d.ts +5 -2
- package/action/experimental_action.js +15 -12
- package/action/index.d.ts +2 -0
- package/action/index.js +7 -1
- package/action/orchestrator.d.ts +4 -2
- package/action/orchestrator.js +6 -0
- package/action/relative_value.d.ts +47 -0
- package/action/relative_value.js +125 -0
- package/action/transaction.d.ts +10 -0
- package/action/transaction.js +23 -0
- package/auth/auth.d.ts +1 -1
- package/core/base.d.ts +4 -2
- package/core/clause.d.ts +6 -1
- package/core/clause.js +25 -4
- package/core/config.d.ts +2 -1
- package/core/config.js +2 -0
- package/core/date.js +1 -5
- package/core/db.d.ts +9 -6
- package/core/db.js +14 -6
- package/core/ent.d.ts +3 -1
- package/core/ent.js +76 -26
- package/core/logger.d.ts +1 -1
- package/core/query/assoc_query.d.ts +2 -2
- package/core/query/shared_assoc_test.js +1 -2
- package/core/query/shared_test.js +0 -1
- package/graphql/graphql.d.ts +6 -6
- package/graphql/graphql.js +1 -0
- package/graphql/query/connection_type.d.ts +1 -1
- package/graphql/query/shared_assoc_test.js +1 -1
- package/graphql/query/shared_edge_connection.js +0 -4
- package/imports/index.d.ts +6 -1
- package/imports/index.js +14 -3
- package/index.d.ts +1 -0
- package/package.json +16 -16
- package/parse_schema/parse.d.ts +7 -7
- package/schema/base_schema.d.ts +3 -3
- package/schema/field.d.ts +17 -12
- package/schema/field.js +18 -8
- package/schema/schema.d.ts +10 -10
- package/schema/schema.js +0 -16
- package/scripts/custom_graphql.js +30 -4
- package/testutils/action/complex_schemas.d.ts +69 -0
- package/testutils/action/complex_schemas.js +398 -0
- package/testutils/builder.d.ts +21 -36
- package/testutils/builder.js +39 -45
- package/testutils/db/temp_db.d.ts +6 -3
- package/testutils/db/temp_db.js +79 -7
- package/testutils/db/value.d.ts +1 -0
- package/testutils/db/value.js +2 -2
- package/testutils/db_mock.d.ts +16 -4
- package/testutils/db_mock.js +48 -5
- package/testutils/ent-graphql-tests/index.d.ts +7 -1
- package/testutils/ent-graphql-tests/index.js +17 -5
- package/testutils/fake_data/fake_contact.d.ts +1 -0
- package/testutils/fake_data/fake_contact.js +6 -5
- package/testutils/fake_data/fake_event.d.ts +1 -0
- package/testutils/fake_data/fake_event.js +4 -3
- package/testutils/fake_data/fake_tag.d.ts +2 -1
- package/testutils/fake_data/fake_tag.js +6 -5
- package/testutils/fake_data/fake_user.d.ts +2 -1
- package/testutils/fake_data/fake_user.js +14 -13
- package/tsc/ast.d.ts +1 -1
|
@@ -36,12 +36,13 @@ export interface Table extends CoreConcept {
|
|
|
36
36
|
columns: Column[];
|
|
37
37
|
constraints?: Constraint[];
|
|
38
38
|
}
|
|
39
|
-
|
|
39
|
+
type options = Pick<Column, "nullable" | "primaryKey" | "default" | "foreignKey" | "unique" | "index">;
|
|
40
40
|
export declare function primaryKey(name: string, cols: string[]): Constraint;
|
|
41
41
|
export declare function foreignKey(name: string, cols: string[], fkey: {
|
|
42
42
|
table: string;
|
|
43
43
|
cols: string[];
|
|
44
44
|
}): Constraint;
|
|
45
|
+
export declare function check(name: string, condition: string): Constraint;
|
|
45
46
|
interface indexOptions {
|
|
46
47
|
type?: string;
|
|
47
48
|
unique?: boolean;
|
|
@@ -94,10 +95,12 @@ export declare class TempDB {
|
|
|
94
95
|
}
|
|
95
96
|
export declare function assoc_edge_config_table(): Table;
|
|
96
97
|
export declare function assoc_edge_table(name: string, global?: boolean): Table;
|
|
97
|
-
interface
|
|
98
|
+
interface setupOptions {
|
|
98
99
|
disableDeleteAfterEachTest?: boolean;
|
|
99
100
|
}
|
|
100
|
-
export declare function setupSqlite(connString: string, tables: () => Table[], opts?:
|
|
101
|
+
export declare function setupSqlite(connString: string, tables: () => Table[], opts?: setupOptions): TempDB;
|
|
102
|
+
export declare function setupPostgres(tables: () => Table[], opts?: setupOptions): void;
|
|
103
|
+
export declare function doSQLiteTestFromSchemas(schemas: BuilderSchema<Ent>[], doTest: () => Promise<void>, db?: string): Promise<TempDB>;
|
|
101
104
|
export declare function getSchemaTable(schema: BuilderSchema<Ent>, dialect: Dialect): Table;
|
|
102
105
|
export declare function getColumnFromField(fieldName: string, f: Field, dialect: Dialect): Column;
|
|
103
106
|
export {};
|
package/testutils/db/temp_db.js
CHANGED
|
@@ -26,7 +26,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
26
26
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
27
|
};
|
|
28
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
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;
|
|
29
|
+
exports.getColumnFromField = exports.getSchemaTable = exports.doSQLiteTestFromSchemas = exports.setupPostgres = 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.check = exports.foreignKey = exports.primaryKey = void 0;
|
|
30
30
|
const pg_1 = require("pg");
|
|
31
31
|
const db_1 = __importStar(require("../../core/db"));
|
|
32
32
|
// this should only be used in tests so we expect to be able to import without shenanigans
|
|
@@ -55,6 +55,15 @@ function foreignKey(name, cols, fkey) {
|
|
|
55
55
|
};
|
|
56
56
|
}
|
|
57
57
|
exports.foreignKey = foreignKey;
|
|
58
|
+
function check(name, condition) {
|
|
59
|
+
return {
|
|
60
|
+
name,
|
|
61
|
+
generate() {
|
|
62
|
+
return `CONSTRAINT ${name} CHECK(${condition})`;
|
|
63
|
+
},
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
exports.check = check;
|
|
58
67
|
function isPostCreateIndex(s) {
|
|
59
68
|
return (s.postCreate !== undefined &&
|
|
60
69
|
s.postCreate());
|
|
@@ -382,13 +391,17 @@ class TempDB {
|
|
|
382
391
|
this.db = randomDB();
|
|
383
392
|
await this.client.query(`CREATE DATABASE ${this.db}`);
|
|
384
393
|
if (setupConnString) {
|
|
394
|
+
delete process.env.DB_CONNECTION_STRING;
|
|
395
|
+
let connStr = "";
|
|
385
396
|
if (user && password) {
|
|
386
|
-
|
|
397
|
+
connStr = `postgres://${user}:${password}@localhost:5432/${this.db}`;
|
|
387
398
|
}
|
|
388
399
|
else {
|
|
389
|
-
|
|
400
|
+
connStr = `postgres://localhost/${this.db}?`;
|
|
390
401
|
}
|
|
391
|
-
db_1.default.initDB(
|
|
402
|
+
db_1.default.initDB({
|
|
403
|
+
connectionString: connStr,
|
|
404
|
+
});
|
|
392
405
|
}
|
|
393
406
|
else {
|
|
394
407
|
// will probably be setup via loadConfig
|
|
@@ -547,13 +560,72 @@ function setupSqlite(connString, tables, opts) {
|
|
|
547
560
|
return tdb;
|
|
548
561
|
}
|
|
549
562
|
exports.setupSqlite = setupSqlite;
|
|
563
|
+
function setupPostgres(tables, opts) {
|
|
564
|
+
let tdb;
|
|
565
|
+
beforeAll(async () => {
|
|
566
|
+
tdb = new TempDB(db_1.Dialect.Postgres, tables());
|
|
567
|
+
await tdb.beforeAll();
|
|
568
|
+
});
|
|
569
|
+
// TODO need to fix this implementation...
|
|
570
|
+
if (!opts?.disableDeleteAfterEachTest) {
|
|
571
|
+
afterEach(async () => {
|
|
572
|
+
const client = await db_1.default.getInstance().getNewClient();
|
|
573
|
+
for (const [key, _] of tdb.__getTables()) {
|
|
574
|
+
const query = `delete from ${key}`;
|
|
575
|
+
await client.exec(query);
|
|
576
|
+
}
|
|
577
|
+
client.release();
|
|
578
|
+
});
|
|
579
|
+
}
|
|
580
|
+
afterAll(async () => {
|
|
581
|
+
await tdb.afterAll();
|
|
582
|
+
});
|
|
583
|
+
}
|
|
584
|
+
exports.setupPostgres = setupPostgres;
|
|
585
|
+
async function doSQLiteTestFromSchemas(schemas, doTest, db) {
|
|
586
|
+
const connString = `sqlite:///${db || randomDB()}.db`;
|
|
587
|
+
const tables = schemas.map((schema) => getSchemaTable(schema, db_1.Dialect.SQLite));
|
|
588
|
+
let tdb = new TempDB(db_1.Dialect.SQLite, tables);
|
|
589
|
+
process.env.DB_CONNECTION_STRING = connString;
|
|
590
|
+
(0, config_1.loadConfig)();
|
|
591
|
+
await tdb.beforeAll();
|
|
592
|
+
await doTest();
|
|
593
|
+
await tdb.afterAll();
|
|
594
|
+
delete process.env.DB_CONNECTION_STRING;
|
|
595
|
+
return tdb;
|
|
596
|
+
}
|
|
597
|
+
exports.doSQLiteTestFromSchemas = doSQLiteTestFromSchemas;
|
|
550
598
|
function getSchemaTable(schema, dialect) {
|
|
551
599
|
const fields = (0, schema_1.getFields)(schema);
|
|
552
|
-
const
|
|
600
|
+
const items = [];
|
|
553
601
|
for (const [fieldName, field] of fields) {
|
|
554
|
-
|
|
602
|
+
items.push(getColumnFromField(fieldName, field, dialect));
|
|
603
|
+
}
|
|
604
|
+
if (schema.constraints) {
|
|
605
|
+
for (const constraint of schema.constraints) {
|
|
606
|
+
switch (constraint.type) {
|
|
607
|
+
case schema_1.ConstraintType.PrimaryKey:
|
|
608
|
+
items.push(primaryKey(constraint.name, constraint.columns));
|
|
609
|
+
break;
|
|
610
|
+
case schema_1.ConstraintType.ForeignKey:
|
|
611
|
+
if (!constraint.fkey) {
|
|
612
|
+
throw new Error(`need 'fkey' field for foreign key constraint`);
|
|
613
|
+
}
|
|
614
|
+
items.push(foreignKey(constraint.name, constraint.columns, {
|
|
615
|
+
table: constraint.fkey.tableName,
|
|
616
|
+
cols: constraint.fkey.columns,
|
|
617
|
+
}));
|
|
618
|
+
break;
|
|
619
|
+
case schema_1.ConstraintType.Check:
|
|
620
|
+
if (!constraint.condition) {
|
|
621
|
+
throw new Error(`need 'condition' field for check constraint`);
|
|
622
|
+
}
|
|
623
|
+
items.push(check(constraint.name, constraint.condition));
|
|
624
|
+
break;
|
|
625
|
+
}
|
|
626
|
+
}
|
|
555
627
|
}
|
|
556
|
-
return table((0, builder_1.getTableName)(schema), ...
|
|
628
|
+
return table((0, builder_1.getTableName)(schema), ...items);
|
|
557
629
|
}
|
|
558
630
|
exports.getSchemaTable = getSchemaTable;
|
|
559
631
|
function getColumnForDbType(t, dialect) {
|
package/testutils/db/value.d.ts
CHANGED
package/testutils/db/value.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getDefaultValue = void 0;
|
|
3
|
+
exports.getDefaultValue = exports.randomEmail = void 0;
|
|
4
4
|
const uuid_1 = require("uuid");
|
|
5
5
|
const schema_1 = require("../../schema");
|
|
6
6
|
const schema_2 = require("../../schema");
|
|
@@ -11,6 +11,7 @@ function randomEmail(domain) {
|
|
|
11
11
|
domain = domain || "email.com";
|
|
12
12
|
return `test+${random()}@${domain}`;
|
|
13
13
|
}
|
|
14
|
+
exports.randomEmail = randomEmail;
|
|
14
15
|
function randomPhoneNumber() {
|
|
15
16
|
return `+1${Math.random().toString(10).substring(2, 11)}`;
|
|
16
17
|
}
|
|
@@ -145,7 +146,6 @@ const emailType = {
|
|
|
145
146
|
},
|
|
146
147
|
regex: /^email(_address)|_email$/,
|
|
147
148
|
};
|
|
148
|
-
const pdt = (0, schema_2.StringType)();
|
|
149
149
|
const phoneType = {
|
|
150
150
|
dbType: schema_1.DBType.String,
|
|
151
151
|
newValue: () => {
|
package/testutils/db_mock.d.ts
CHANGED
|
@@ -18,7 +18,8 @@ export declare enum queryType {
|
|
|
18
18
|
UPDATE = 2,
|
|
19
19
|
BEGIN = 3,
|
|
20
20
|
COMMIT = 4,
|
|
21
|
-
ROLLBACK = 5
|
|
21
|
+
ROLLBACK = 5,
|
|
22
|
+
DELETE = 6
|
|
22
23
|
}
|
|
23
24
|
export interface queryStructure {
|
|
24
25
|
tableName?: string;
|
|
@@ -32,11 +33,14 @@ interface internalQueryStructure extends queryStructure {
|
|
|
32
33
|
suffix?: string;
|
|
33
34
|
setClause?: string;
|
|
34
35
|
}
|
|
36
|
+
/**
|
|
37
|
+
* @deprecated
|
|
38
|
+
*/
|
|
35
39
|
export declare class QueryRecorder {
|
|
36
40
|
private static queries;
|
|
37
41
|
private static ids;
|
|
38
42
|
private static data;
|
|
39
|
-
|
|
43
|
+
static getQueryStructure(query: any): internalQueryStructure | null;
|
|
40
44
|
private static recordQuery;
|
|
41
45
|
static newID(): ID;
|
|
42
46
|
static getCurrentIDs(): ID[];
|
|
@@ -46,8 +50,16 @@ export declare class QueryRecorder {
|
|
|
46
50
|
static clear(): void;
|
|
47
51
|
static clearQueries(): void;
|
|
48
52
|
static getCurrentQueries(): queryOptions[];
|
|
49
|
-
|
|
50
|
-
|
|
53
|
+
/**
|
|
54
|
+
* @deprecated will keep this since it's just using ml.logs
|
|
55
|
+
* which we still want around (I think) but we should eventually
|
|
56
|
+
* probably stop using this
|
|
57
|
+
*/
|
|
58
|
+
static validateQueryStructuresFromLogs(ml: MockLogs, expected: queryStructure[], opts?: {
|
|
59
|
+
skipSelect?: boolean;
|
|
60
|
+
flagBeginCommit?: boolean;
|
|
61
|
+
}): void;
|
|
62
|
+
private static validateQueryStructuresImpl;
|
|
51
63
|
static mockPool(pool: typeof Pool): void;
|
|
52
64
|
}
|
|
53
65
|
export {};
|
package/testutils/db_mock.js
CHANGED
|
@@ -29,7 +29,11 @@ var queryType;
|
|
|
29
29
|
queryType[queryType["BEGIN"] = 3] = "BEGIN";
|
|
30
30
|
queryType[queryType["COMMIT"] = 4] = "COMMIT";
|
|
31
31
|
queryType[queryType["ROLLBACK"] = 5] = "ROLLBACK";
|
|
32
|
+
queryType[queryType["DELETE"] = 6] = "DELETE";
|
|
32
33
|
})(queryType = exports.queryType || (exports.queryType = {}));
|
|
34
|
+
/**
|
|
35
|
+
* @deprecated
|
|
36
|
+
*/
|
|
33
37
|
class QueryRecorder {
|
|
34
38
|
// TODO kill use AST or just throw away
|
|
35
39
|
static getQueryStructure(query) {
|
|
@@ -76,6 +80,36 @@ class QueryRecorder {
|
|
|
76
80
|
};
|
|
77
81
|
}
|
|
78
82
|
}
|
|
83
|
+
if (/^DELETE/.test(query)) {
|
|
84
|
+
// regex can't do returning
|
|
85
|
+
let execArray = /^DELETE FROM (.+) WHERE (.+) /.exec(query);
|
|
86
|
+
if (execArray) {
|
|
87
|
+
return {
|
|
88
|
+
tableName: execArray[1],
|
|
89
|
+
whereClause: execArray[2],
|
|
90
|
+
type: queryType.DELETE,
|
|
91
|
+
query: execArray[0],
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
if (/^BEGIN/.test(query)) {
|
|
96
|
+
return {
|
|
97
|
+
type: queryType.BEGIN,
|
|
98
|
+
query: query,
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
if (/^COMMIT/.test(query)) {
|
|
102
|
+
return {
|
|
103
|
+
type: queryType.COMMIT,
|
|
104
|
+
query: query,
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
if (/^ROLLBACK/.test(query)) {
|
|
108
|
+
return {
|
|
109
|
+
type: queryType.ROLLBACK,
|
|
110
|
+
query: query,
|
|
111
|
+
};
|
|
112
|
+
}
|
|
79
113
|
return null;
|
|
80
114
|
}
|
|
81
115
|
static recordQuery(query, values) {
|
|
@@ -131,7 +165,12 @@ class QueryRecorder {
|
|
|
131
165
|
static getCurrentQueries() {
|
|
132
166
|
return QueryRecorder.queries;
|
|
133
167
|
}
|
|
134
|
-
|
|
168
|
+
/**
|
|
169
|
+
* @deprecated will keep this since it's just using ml.logs
|
|
170
|
+
* which we still want around (I think) but we should eventually
|
|
171
|
+
* probably stop using this
|
|
172
|
+
*/
|
|
173
|
+
static validateQueryStructuresFromLogs(ml, expected, opts) {
|
|
135
174
|
const queries = ml.logs.map((log) => {
|
|
136
175
|
const qs = QueryRecorder.getQueryStructure(log.query);
|
|
137
176
|
if (!qs) {
|
|
@@ -142,12 +181,16 @@ class QueryRecorder {
|
|
|
142
181
|
qs,
|
|
143
182
|
};
|
|
144
183
|
});
|
|
145
|
-
QueryRecorder.
|
|
184
|
+
QueryRecorder.validateQueryStructuresImpl(expected, queries, opts);
|
|
146
185
|
}
|
|
147
|
-
static
|
|
148
|
-
if (skipSelect) {
|
|
186
|
+
static validateQueryStructuresImpl(expected, queries, opts) {
|
|
187
|
+
if (opts?.skipSelect) {
|
|
149
188
|
queries = queries.filter((query) => query.qs?.type !== queryType.SELECT);
|
|
150
189
|
}
|
|
190
|
+
if (!opts?.flagBeginCommit) {
|
|
191
|
+
queries = queries.filter((query) => query.qs?.type !== queryType.BEGIN &&
|
|
192
|
+
query.qs?.type !== queryType.COMMIT);
|
|
193
|
+
}
|
|
151
194
|
// console.log(queries, expected);
|
|
152
195
|
expect(queries.length).toBe(expected.length);
|
|
153
196
|
for (let i = 0; i < expected.length; i++) {
|
|
@@ -167,7 +210,7 @@ class QueryRecorder {
|
|
|
167
210
|
expect(query.values).toBe(undefined);
|
|
168
211
|
break;
|
|
169
212
|
case queryType.SELECT:
|
|
170
|
-
if (!skipSelect) {
|
|
213
|
+
if (!opts?.skipSelect) {
|
|
171
214
|
console.error("validating select query structure not supported yet");
|
|
172
215
|
}
|
|
173
216
|
// TODO INSERT and UPDATE tests here...
|
|
@@ -2,7 +2,7 @@ import { Express, RequestHandler } from "express";
|
|
|
2
2
|
import { Viewer } from "../../core/base";
|
|
3
3
|
import { GraphQLSchema } from "graphql";
|
|
4
4
|
import supertest from "supertest";
|
|
5
|
-
export
|
|
5
|
+
export type Option = [string, any];
|
|
6
6
|
interface queryConfig {
|
|
7
7
|
viewer?: Viewer;
|
|
8
8
|
init?: (app: Express) => void;
|
|
@@ -11,6 +11,12 @@ interface queryConfig {
|
|
|
11
11
|
headers?: object;
|
|
12
12
|
debugMode?: boolean;
|
|
13
13
|
args: {};
|
|
14
|
+
extraVariables?: {
|
|
15
|
+
[key: string]: {
|
|
16
|
+
graphqlType: string;
|
|
17
|
+
value: string;
|
|
18
|
+
};
|
|
19
|
+
};
|
|
14
20
|
expectedStatus?: number;
|
|
15
21
|
expectedError?: string | RegExp;
|
|
16
22
|
callback?: (res: supertest.Response) => void;
|
|
@@ -35,6 +35,7 @@ const graphql_1 = require("graphql");
|
|
|
35
35
|
const auth_1 = require("../../auth");
|
|
36
36
|
const supertest_1 = __importDefault(require("supertest"));
|
|
37
37
|
const fs = __importStar(require("fs"));
|
|
38
|
+
const util_1 = require("util");
|
|
38
39
|
function server(config) {
|
|
39
40
|
const viewer = config.viewer;
|
|
40
41
|
if (viewer) {
|
|
@@ -115,17 +116,23 @@ function makeGraphQLRequest(config, query, fieldArgs) {
|
|
|
115
116
|
}
|
|
116
117
|
}
|
|
117
118
|
});
|
|
119
|
+
let variables = {
|
|
120
|
+
...config.args,
|
|
121
|
+
};
|
|
122
|
+
for (const k in config.extraVariables) {
|
|
123
|
+
variables[k] = config.extraVariables[k].value;
|
|
124
|
+
}
|
|
118
125
|
if (files.size) {
|
|
119
126
|
let ret = test
|
|
120
127
|
.post(config.graphQLPath || "/graphql")
|
|
121
128
|
.set(config.headers || {});
|
|
122
129
|
ret.field("operations", JSON.stringify({
|
|
123
130
|
query: query,
|
|
124
|
-
variables:
|
|
131
|
+
variables: variables,
|
|
125
132
|
}));
|
|
126
133
|
let m = {};
|
|
127
134
|
let idx = 0;
|
|
128
|
-
for (const [key
|
|
135
|
+
for (const [key] of files) {
|
|
129
136
|
m[idx] = [`variables.${key}`];
|
|
130
137
|
idx++;
|
|
131
138
|
}
|
|
@@ -148,7 +155,7 @@ function makeGraphQLRequest(config, query, fieldArgs) {
|
|
|
148
155
|
.set(config.headers || {})
|
|
149
156
|
.send({
|
|
150
157
|
query: query,
|
|
151
|
-
variables: JSON.stringify(
|
|
158
|
+
variables: JSON.stringify(variables),
|
|
152
159
|
}),
|
|
153
160
|
];
|
|
154
161
|
}
|
|
@@ -309,13 +316,18 @@ async function expectFromRoot(config, ...options) {
|
|
|
309
316
|
let fieldArgs = field.args;
|
|
310
317
|
let queryParams = [];
|
|
311
318
|
fieldArgs.forEach((fieldArg) => {
|
|
312
|
-
|
|
319
|
+
const arg = config.args[fieldArg.name];
|
|
313
320
|
// let the graphql runtime handle this (it may be optional for example)
|
|
314
321
|
if (arg === undefined) {
|
|
315
322
|
return;
|
|
316
323
|
}
|
|
317
324
|
queryParams.push(`$${fieldArg.name}: ${fieldArg.type}`);
|
|
318
325
|
});
|
|
326
|
+
// add extra variables in queryArgs...
|
|
327
|
+
for (const key in config.extraVariables) {
|
|
328
|
+
const v = config.extraVariables[key];
|
|
329
|
+
queryParams.push(`$${key}: ${v.graphqlType}`);
|
|
330
|
+
}
|
|
319
331
|
let params = [];
|
|
320
332
|
for (let key in config.args) {
|
|
321
333
|
params.push(`${key}: $${key}`);
|
|
@@ -354,7 +366,7 @@ async function expectFromRoot(config, ...options) {
|
|
|
354
366
|
let [st, temp] = makeGraphQLRequest(config, q, fieldArgs);
|
|
355
367
|
const res = await temp.expect("Content-Type", /json/);
|
|
356
368
|
if (config.debugMode) {
|
|
357
|
-
console.log(res.body);
|
|
369
|
+
console.log((0, util_1.inspect)(res.body, false, 3));
|
|
358
370
|
}
|
|
359
371
|
// if there's a callback, let everything be done there and we're done
|
|
360
372
|
if (config.callback) {
|
|
@@ -15,6 +15,7 @@ export declare class FakeContact implements Ent {
|
|
|
15
15
|
readonly userID: ID;
|
|
16
16
|
getPrivacyPolicy(): PrivacyPolicy<this>;
|
|
17
17
|
constructor(viewer: Viewer, data: Data);
|
|
18
|
+
__setRawDBData(data: Data): void;
|
|
18
19
|
static getFields(): string[];
|
|
19
20
|
static getTestTable(): import("../db/temp_db").Table;
|
|
20
21
|
static loaderOptions(): LoadEntOptions<FakeContact>;
|
|
@@ -11,6 +11,11 @@ const loaders_1 = require("../../core/loaders");
|
|
|
11
11
|
const convert_1 = require("../../core/convert");
|
|
12
12
|
const action_1 = require("../../action");
|
|
13
13
|
class FakeContact {
|
|
14
|
+
getPrivacyPolicy() {
|
|
15
|
+
return {
|
|
16
|
+
rules: [new privacy_1.AllowIfViewerIsRule("userID"), privacy_1.AlwaysDenyRule],
|
|
17
|
+
};
|
|
18
|
+
}
|
|
14
19
|
constructor(viewer, data) {
|
|
15
20
|
this.viewer = viewer;
|
|
16
21
|
this.nodeType = const_1.NodeType.FakeContact;
|
|
@@ -23,11 +28,7 @@ class FakeContact {
|
|
|
23
28
|
this.emailAddress = data.email_address;
|
|
24
29
|
this.userID = data.user_id;
|
|
25
30
|
}
|
|
26
|
-
|
|
27
|
-
return {
|
|
28
|
-
rules: [new privacy_1.AllowIfViewerIsRule("userID"), privacy_1.AlwaysDenyRule],
|
|
29
|
-
};
|
|
30
|
-
}
|
|
31
|
+
__setRawDBData(data) { }
|
|
31
32
|
static getFields() {
|
|
32
33
|
return [
|
|
33
34
|
"id",
|
|
@@ -16,6 +16,7 @@ export declare class FakeEvent implements Ent {
|
|
|
16
16
|
readonly userID: ID;
|
|
17
17
|
getPrivacyPolicy(): PrivacyPolicy<this>;
|
|
18
18
|
constructor(viewer: Viewer, data: Data);
|
|
19
|
+
__setRawDBData(data: Data): void;
|
|
19
20
|
private static getFields;
|
|
20
21
|
static getTestTable(): import("../db/temp_db").Table;
|
|
21
22
|
static loaderOptions(): LoadEntOptions<FakeEvent>;
|
|
@@ -11,6 +11,9 @@ const loaders_1 = require("../../core/loaders");
|
|
|
11
11
|
const convert_1 = require("../../core/convert");
|
|
12
12
|
const action_1 = require("../../action");
|
|
13
13
|
class FakeEvent {
|
|
14
|
+
getPrivacyPolicy() {
|
|
15
|
+
return privacy_1.AlwaysAllowPrivacyPolicy;
|
|
16
|
+
}
|
|
14
17
|
constructor(viewer, data) {
|
|
15
18
|
this.viewer = viewer;
|
|
16
19
|
this.nodeType = const_1.NodeType.FakeEvent;
|
|
@@ -25,9 +28,7 @@ class FakeEvent {
|
|
|
25
28
|
this.description = data.description;
|
|
26
29
|
this.userID = data.user_id;
|
|
27
30
|
}
|
|
28
|
-
|
|
29
|
-
return privacy_1.AlwaysAllowPrivacyPolicy;
|
|
30
|
-
}
|
|
31
|
+
__setRawDBData(data) { }
|
|
31
32
|
static getFields() {
|
|
32
33
|
return [
|
|
33
34
|
"id",
|
|
@@ -14,6 +14,7 @@ export declare class FakeTag implements Ent {
|
|
|
14
14
|
readonly ownerID: string;
|
|
15
15
|
getPrivacyPolicy(): PrivacyPolicy<this>;
|
|
16
16
|
constructor(viewer: Viewer, data: Data);
|
|
17
|
+
__setRawDBData(data: Data): void;
|
|
17
18
|
static getFields(): string[];
|
|
18
19
|
static getTestTable(): import("../db/temp_db").Table;
|
|
19
20
|
static loaderOptions(): LoadEntOptions<FakeTag>;
|
|
@@ -28,7 +29,7 @@ export interface TagCreateInput {
|
|
|
28
29
|
createdAt?: Date;
|
|
29
30
|
updatedAt?: Date;
|
|
30
31
|
}
|
|
31
|
-
export
|
|
32
|
+
export type TagEditInput = Partial<TagCreateInput>;
|
|
32
33
|
export declare function getTagBuilder(viewer: Viewer, input: TagCreateInput): import("../builder").SimpleBuilder<FakeTag, null>;
|
|
33
34
|
export declare function getTagAction(viewer: Viewer, input: TagCreateInput): SimpleAction<FakeTag, null>;
|
|
34
35
|
export declare function createTag(viewer: Viewer, input: TagCreateInput): Promise<FakeTag>;
|
|
@@ -11,6 +11,11 @@ const loaders_1 = require("../../core/loaders");
|
|
|
11
11
|
const convert_1 = require("../../core/convert");
|
|
12
12
|
const action_1 = require("../../action");
|
|
13
13
|
class FakeTag {
|
|
14
|
+
getPrivacyPolicy() {
|
|
15
|
+
return {
|
|
16
|
+
rules: [new privacy_1.AllowIfViewerIsEntPropertyRule("ownerID"), privacy_1.AlwaysDenyRule],
|
|
17
|
+
};
|
|
18
|
+
}
|
|
14
19
|
constructor(viewer, data) {
|
|
15
20
|
this.viewer = viewer;
|
|
16
21
|
this.nodeType = const_1.NodeType.FakeUser;
|
|
@@ -22,11 +27,7 @@ class FakeTag {
|
|
|
22
27
|
this.canonicalName = data.canonical_name;
|
|
23
28
|
this.ownerID = data.owner_id;
|
|
24
29
|
}
|
|
25
|
-
|
|
26
|
-
return {
|
|
27
|
-
rules: [new privacy_1.AllowIfViewerIsEntPropertyRule("ownerID"), privacy_1.AlwaysDenyRule],
|
|
28
|
-
};
|
|
29
|
-
}
|
|
30
|
+
__setRawDBData(data) { }
|
|
30
31
|
static getFields() {
|
|
31
32
|
return [
|
|
32
33
|
"id",
|
|
@@ -25,6 +25,7 @@ export declare class FakeUser implements Ent {
|
|
|
25
25
|
protected readonly password: string | null;
|
|
26
26
|
getPrivacyPolicy(): PrivacyPolicy<this>;
|
|
27
27
|
constructor(viewer: Viewer, data: Data);
|
|
28
|
+
__setRawDBData(data: Data): void;
|
|
28
29
|
static getFields(): string[];
|
|
29
30
|
static getTestTable(): import("../db/temp_db").Table;
|
|
30
31
|
static loaderOptions(): LoadEntOptions<FakeUser>;
|
|
@@ -41,7 +42,7 @@ export interface UserCreateInput {
|
|
|
41
42
|
createdAt?: Date;
|
|
42
43
|
updatedAt?: Date;
|
|
43
44
|
}
|
|
44
|
-
export
|
|
45
|
+
export type UserEditInput = Partial<UserCreateInput>;
|
|
45
46
|
export declare function getUserBuilder(viewer: Viewer, input: UserCreateInput): import("../builder").SimpleBuilder<FakeUser, null>;
|
|
46
47
|
export declare function getUserAction(viewer: Viewer, input: UserCreateInput): SimpleAction<FakeUser, null>;
|
|
47
48
|
export declare function createUser(viewer: Viewer, input: UserCreateInput): Promise<FakeUser>;
|
|
@@ -24,19 +24,6 @@ class ViewerWithAccessToken extends viewer_1.IDViewer {
|
|
|
24
24
|
}
|
|
25
25
|
exports.ViewerWithAccessToken = ViewerWithAccessToken;
|
|
26
26
|
class FakeUser {
|
|
27
|
-
constructor(viewer, data) {
|
|
28
|
-
this.viewer = viewer;
|
|
29
|
-
this.nodeType = const_1.NodeType.FakeUser;
|
|
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
27
|
getPrivacyPolicy() {
|
|
41
28
|
return {
|
|
42
29
|
rules: [
|
|
@@ -61,6 +48,20 @@ class FakeUser {
|
|
|
61
48
|
],
|
|
62
49
|
};
|
|
63
50
|
}
|
|
51
|
+
constructor(viewer, data) {
|
|
52
|
+
this.viewer = viewer;
|
|
53
|
+
this.nodeType = const_1.NodeType.FakeUser;
|
|
54
|
+
this.data = data;
|
|
55
|
+
this.id = data.id;
|
|
56
|
+
this.createdAt = (0, convert_1.convertDate)(data.created_at);
|
|
57
|
+
this.updatedAt = (0, convert_1.convertDate)(data.updated_at);
|
|
58
|
+
this.firstName = data.first_name;
|
|
59
|
+
this.lastName = data.last_name;
|
|
60
|
+
this.emailAddress = data.email_address;
|
|
61
|
+
this.phoneNumber = data.phone_number;
|
|
62
|
+
this.password = data.password;
|
|
63
|
+
}
|
|
64
|
+
__setRawDBData(data) { }
|
|
64
65
|
static getFields() {
|
|
65
66
|
return [
|
|
66
67
|
"id",
|
package/tsc/ast.d.ts
CHANGED
|
@@ -10,7 +10,7 @@ export interface ClassInfo {
|
|
|
10
10
|
wrapClassContents(inner: string): string;
|
|
11
11
|
}
|
|
12
12
|
export declare function getClassInfo(fileContents: string, sourceFile: ts.SourceFile, node: ts.ClassDeclaration): ClassInfo | undefined;
|
|
13
|
-
|
|
13
|
+
type transformImportFn = (imp: string) => string;
|
|
14
14
|
interface transformOpts {
|
|
15
15
|
removeImports?: string[];
|
|
16
16
|
newImports?: string[];
|