@snowtop/ent 0.2.0-alpha.6.test → 0.2.0-alpha.7
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/core/clause.d.ts +44 -0
- package/core/clause.js +75 -2
- package/core/db.d.ts +1 -1
- package/core/db.js +2 -2
- package/core/ent.d.ts +10 -2
- package/core/ent.js +11 -18
- package/core/loaders/assoc_edge_loader.d.ts +1 -1
- package/core/loaders/assoc_edge_loader.js +3 -3
- package/core/query/assoc_query.d.ts +2 -2
- package/core/query/assoc_query.js +14 -2
- package/core/query/custom_clause_query.d.ts +1 -2
- package/core/query/custom_clause_query.js +1 -5
- package/core/query/custom_query.d.ts +2 -2
- package/core/query/custom_query.js +1 -1
- package/core/query/query.d.ts +3 -7
- package/core/query/query.js +73 -199
- package/core/query/shared_test.d.ts +3 -3
- package/core/query/shared_test.js +31 -23
- package/core/query_impl.d.ts +0 -1
- package/graphql/query/edge_connection.d.ts +5 -4
- package/graphql/query/edge_connection.js +19 -14
- package/graphql/query/shared_edge_connection.d.ts +2 -2
- package/graphql/query/shared_edge_connection.js +23 -12
- package/package.json +1 -1
- package/testutils/db_mock.d.ts +1 -1
- package/testutils/db_mock.js +1 -1
- package/testutils/ent-graphql-tests/index.d.ts +1 -1
- package/testutils/ent-graphql-tests/index.js +5 -5
- package/testutils/fake_data/user_query.d.ts +5 -5
- package/testutils/fake_data/user_query.js +11 -14
- package/tsc/compilerOptions.js +1 -4
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.commonTests = void 0;
|
|
4
|
-
const viewer_1 = require("../../core/viewer");
|
|
5
4
|
const ent_1 = require("../../core/ent");
|
|
6
|
-
const
|
|
5
|
+
const viewer_1 = require("../../core/viewer");
|
|
7
6
|
const index_1 = require("../../testutils/fake_data/index");
|
|
8
7
|
const test_helpers_1 = require("../../testutils/fake_data/test_helpers");
|
|
8
|
+
const edge_connection_1 = require("./edge_connection");
|
|
9
9
|
class TestConnection {
|
|
10
10
|
constructor(getQuery, ents, filter) {
|
|
11
11
|
this.getQuery = getQuery;
|
|
@@ -18,10 +18,20 @@ class TestConnection {
|
|
|
18
18
|
this.allContacts = this.allContacts.reverse();
|
|
19
19
|
this.conn = new edge_connection_1.GraphQLEdgeConnection(new viewer_1.IDViewer(this.user.id), this.user, (v, user) => this.getQuery(v, user));
|
|
20
20
|
if (this.filter) {
|
|
21
|
-
this.filter(this.conn, this.user, this.allContacts);
|
|
21
|
+
await this.filter(this.conn, this.user, this.allContacts);
|
|
22
22
|
}
|
|
23
23
|
this.filteredContacts = this.ents(this.allContacts);
|
|
24
24
|
}
|
|
25
|
+
async testAsyncConn() {
|
|
26
|
+
const asyncConn = new edge_connection_1.GraphQLEdgeConnection(new viewer_1.IDViewer(this.user.id), this.user, (v, user) => new Promise((resolve) => {
|
|
27
|
+
setTimeout(() => resolve(this.getQuery(v, user)), 0);
|
|
28
|
+
}));
|
|
29
|
+
if (this.filter) {
|
|
30
|
+
await this.filter(asyncConn, this.user, this.allContacts);
|
|
31
|
+
}
|
|
32
|
+
const count = await asyncConn.queryTotalCount();
|
|
33
|
+
expect(count).toBe(test_helpers_1.inputs.length);
|
|
34
|
+
}
|
|
25
35
|
async testTotalCount() {
|
|
26
36
|
const count = await this.conn.queryTotalCount();
|
|
27
37
|
expect(count).toBe(test_helpers_1.inputs.length);
|
|
@@ -39,7 +49,7 @@ class TestConnection {
|
|
|
39
49
|
for (let i = 0; i < this.filteredContacts.length; i++) {
|
|
40
50
|
const edge = edges[i];
|
|
41
51
|
expect(edge.node.id).toBe(this.filteredContacts[i].id);
|
|
42
|
-
expect(this.conn.query.dataToID(edge.edge)).toBe(this.filteredContacts[i].id);
|
|
52
|
+
expect((await this.conn.query).dataToID(edge.edge)).toBe(this.filteredContacts[i].id);
|
|
43
53
|
}
|
|
44
54
|
}
|
|
45
55
|
}
|
|
@@ -57,7 +67,8 @@ const commonTests = (opts) => {
|
|
|
57
67
|
if (isCustomQuery(q)) {
|
|
58
68
|
opts = {
|
|
59
69
|
row: contacts[idx],
|
|
60
|
-
|
|
70
|
+
cursorKeys: ["created_at", "id"],
|
|
71
|
+
rowKeys: ["createdAt", "id"],
|
|
61
72
|
};
|
|
62
73
|
}
|
|
63
74
|
else {
|
|
@@ -65,8 +76,8 @@ const commonTests = (opts) => {
|
|
|
65
76
|
// is from assoc_edge table id2 field and so cursor takes it from there
|
|
66
77
|
opts = {
|
|
67
78
|
row: contacts[idx],
|
|
68
|
-
|
|
69
|
-
|
|
79
|
+
cursorKeys: ["time", "id2"],
|
|
80
|
+
rowKeys: ["createdAt", "id"],
|
|
70
81
|
};
|
|
71
82
|
}
|
|
72
83
|
return (0, ent_1.getCursor)(opts);
|
|
@@ -92,7 +103,7 @@ const commonTests = (opts) => {
|
|
|
92
103
|
});
|
|
93
104
|
});
|
|
94
105
|
describe("filters. firstN", () => {
|
|
95
|
-
const filter = new TestConnection((v, user) => opts.getQuery(v, user), (contacts) => contacts.slice(0, 2), (conn) => {
|
|
106
|
+
const filter = new TestConnection((v, user) => opts.getQuery(v, user), (contacts) => contacts.slice(0, 2), async (conn) => {
|
|
96
107
|
conn.first(2);
|
|
97
108
|
});
|
|
98
109
|
beforeEach(async () => {
|
|
@@ -124,8 +135,8 @@ const commonTests = (opts) => {
|
|
|
124
135
|
const N = 3;
|
|
125
136
|
const filter = new TestConnection((v, user) => opts.getQuery(v, user),
|
|
126
137
|
// get the next 2
|
|
127
|
-
(contacts) => contacts.slice(idx + 1, idx + N), (conn, user, contacts) => {
|
|
128
|
-
const cursor = getCursorFrom(conn.query, contacts, idx);
|
|
138
|
+
(contacts) => contacts.slice(idx + 1, idx + N), async (conn, user, contacts) => {
|
|
139
|
+
const cursor = getCursorFrom(await conn.query, contacts, idx);
|
|
129
140
|
conn.first(2, cursor);
|
|
130
141
|
});
|
|
131
142
|
beforeEach(async () => {
|
|
@@ -153,9 +164,9 @@ const commonTests = (opts) => {
|
|
|
153
164
|
});
|
|
154
165
|
});
|
|
155
166
|
describe("filters. before cursor", () => {
|
|
156
|
-
const filter = new TestConnection((v, user) => opts.getQuery(v, user), (contacts) => contacts.slice(2, 4).reverse(), (conn, user, contacts) => {
|
|
167
|
+
const filter = new TestConnection((v, user) => opts.getQuery(v, user), (contacts) => contacts.slice(2, 4).reverse(), async (conn, user, contacts) => {
|
|
157
168
|
// get the 2 before it
|
|
158
|
-
const cursor = getCursorFrom(conn.query, contacts, 4);
|
|
169
|
+
const cursor = getCursorFrom(await conn.query, contacts, 4);
|
|
159
170
|
conn.last(2, cursor);
|
|
160
171
|
});
|
|
161
172
|
beforeEach(async () => {
|
package/package.json
CHANGED
package/testutils/db_mock.d.ts
CHANGED
package/testutils/db_mock.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.QueryRecorder = exports.queryType = void 0;
|
|
4
|
-
const uuid_1 = require("uuid");
|
|
5
4
|
const jest_mock_1 = require("jest-mock");
|
|
5
|
+
const uuid_1 = require("uuid");
|
|
6
6
|
const parse_sql_1 = require("./parse_sql");
|
|
7
7
|
const eventEmitter = {
|
|
8
8
|
on: jest.fn(),
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Express, RequestHandler } from "express";
|
|
2
|
-
import { Viewer } from "../../core/base";
|
|
3
2
|
import { GraphQLSchema } from "graphql";
|
|
4
3
|
import supertest from "supertest";
|
|
4
|
+
import { Viewer } from "../../core/base";
|
|
5
5
|
export type Option = [string, any] | [string, any, string];
|
|
6
6
|
interface queryConfig {
|
|
7
7
|
viewer?: Viewer;
|
|
@@ -30,12 +30,12 @@ exports.expectMutation = exports.expectQueryFromRoot = void 0;
|
|
|
30
30
|
// NB: this is copied from ent-graphql-tests package until I have time to figure out how to share code here effectively
|
|
31
31
|
// the circular dependencies btw this package and ent-graphql-tests seems to imply something needs to change
|
|
32
32
|
const express_1 = __importDefault(require("express"));
|
|
33
|
-
const
|
|
33
|
+
const fs = __importStar(require("fs"));
|
|
34
34
|
const graphql_1 = require("graphql");
|
|
35
|
-
const
|
|
35
|
+
const graphql_helix_1 = require("graphql-helix");
|
|
36
36
|
const supertest_1 = __importDefault(require("supertest"));
|
|
37
|
-
const fs = __importStar(require("fs"));
|
|
38
37
|
const util_1 = require("util");
|
|
38
|
+
const auth_1 = require("../../auth");
|
|
39
39
|
function server(config) {
|
|
40
40
|
const viewer = config.viewer;
|
|
41
41
|
if (viewer) {
|
|
@@ -125,7 +125,7 @@ function makeGraphQLRequest(config, query, fieldArgs) {
|
|
|
125
125
|
if (files.size) {
|
|
126
126
|
let ret = test
|
|
127
127
|
.post(config.graphQLPath || "/graphql")
|
|
128
|
-
.set(config.headers || {});
|
|
128
|
+
.set((config.headers || {}));
|
|
129
129
|
ret.field("operations", JSON.stringify({
|
|
130
130
|
query: query,
|
|
131
131
|
variables: variables,
|
|
@@ -152,7 +152,7 @@ function makeGraphQLRequest(config, query, fieldArgs) {
|
|
|
152
152
|
test,
|
|
153
153
|
test
|
|
154
154
|
.post(config.graphQLPath || "/graphql")
|
|
155
|
-
.set(config.headers || {})
|
|
155
|
+
.set((config.headers || {}))
|
|
156
156
|
.send({
|
|
157
157
|
query: query,
|
|
158
158
|
variables: JSON.stringify(variables),
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { Data, Ent, ID, Viewer } from "../../core/base";
|
|
2
|
-
import { CustomEdgeQueryBase } from "../../core/query/custom_query";
|
|
3
|
-
import { AssocEdge } from "../../core/ent";
|
|
4
2
|
import * as clause from "../../core/clause";
|
|
5
|
-
import {
|
|
6
|
-
import { FakeUser, FakeEvent, FakeContact, EventToAttendeesQuery, EventToDeclinedQuery, EventToHostsQuery, EventToInvitedQuery, EventToMaybeQuery } from "./internal";
|
|
7
|
-
import { RawCountLoaderFactory } from "../../core/loaders/raw_count_loader";
|
|
3
|
+
import { AssocEdge } from "../../core/ent";
|
|
8
4
|
import { QueryLoaderFactory } from "../../core/loaders/query_loader";
|
|
5
|
+
import { RawCountLoaderFactory } from "../../core/loaders/raw_count_loader";
|
|
6
|
+
import { AssocEdgeQueryBase, EdgeQuerySource } from "../../core/query/assoc_query";
|
|
7
|
+
import { CustomEdgeQueryBase } from "../../core/query/custom_query";
|
|
8
|
+
import { EventToAttendeesQuery, EventToDeclinedQuery, EventToHostsQuery, EventToInvitedQuery, EventToMaybeQuery, FakeContact, FakeEvent, FakeUser } from "./internal";
|
|
9
9
|
export declare class UserToContactsQuery extends AssocEdgeQueryBase<FakeUser, FakeContact, AssocEdge> {
|
|
10
10
|
constructor(viewer: Viewer, src: EdgeQuerySource<FakeUser>);
|
|
11
11
|
static query(viewer: Viewer, src: EdgeQuerySource<FakeUser>): UserToContactsQuery;
|
|
@@ -24,21 +24,20 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
24
24
|
};
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
26
|
exports.UserToFollowingQuery = exports.UserToEventsInNextWeekQuery = exports.getCompleteClause = exports.getNextWeekClause = exports.UserToHostedEventsQuery = exports.UserToEventsAttendingQuery = exports.UserToIncomingFriendRequestsQuery = exports.UserToFriendRequestsQuery = exports.UserToCustomEdgeQuery = exports.CustomEdge = exports.UserToFriendsQuery = exports.UserToContactsFkeyQueryDeletedAtAsc = exports.UserToContactsFkeyQueryAsc = exports.UserToContactsFkeyQueryDeletedAt = exports.UserToContactsFkeyQuery = exports.UserToContactsFkeyQueryDeprecated = exports.userToContactsDataLoaderFactory = exports.userToContactsCountLoaderFactory = exports.UserToContactsQuery = void 0;
|
|
27
|
-
const
|
|
28
|
-
const
|
|
27
|
+
const jest_date_mock_1 = require("jest-date-mock");
|
|
28
|
+
const _1 = require(".");
|
|
29
29
|
const clause = __importStar(require("../../core/clause"));
|
|
30
|
-
const
|
|
31
|
-
const internal_1 = require("./internal");
|
|
32
|
-
const raw_count_loader_1 = require("../../core/loaders/raw_count_loader");
|
|
30
|
+
const ent_1 = require("../../core/ent");
|
|
33
31
|
const assoc_count_loader_1 = require("../../core/loaders/assoc_count_loader");
|
|
34
32
|
const assoc_edge_loader_1 = require("../../core/loaders/assoc_edge_loader");
|
|
35
|
-
const fake_contact_1 = require("./fake_contact");
|
|
36
|
-
const jest_date_mock_1 = require("jest-date-mock");
|
|
37
|
-
const luxon_1 = require("luxon");
|
|
38
33
|
const query_loader_1 = require("../../core/loaders/query_loader");
|
|
39
|
-
const
|
|
40
|
-
const _1 = require(".");
|
|
34
|
+
const raw_count_loader_1 = require("../../core/loaders/raw_count_loader");
|
|
41
35
|
const privacy_1 = require("../../core/privacy");
|
|
36
|
+
const assoc_query_1 = require("../../core/query/assoc_query");
|
|
37
|
+
const custom_query_1 = require("../../core/query/custom_query");
|
|
38
|
+
const mock_date_1 = require("./../mock_date");
|
|
39
|
+
const fake_contact_1 = require("./fake_contact");
|
|
40
|
+
const internal_1 = require("./internal");
|
|
42
41
|
class UserToContactsQuery extends assoc_query_1.AssocEdgeQueryBase {
|
|
43
42
|
constructor(viewer, src) {
|
|
44
43
|
super(viewer, src, new assoc_count_loader_1.AssocEdgeCountLoaderFactory(internal_1.EdgeType.UserToContacts), new assoc_edge_loader_1.AssocEdgeLoaderFactory(internal_1.EdgeType.UserToContacts, ent_1.AssocEdge), internal_1.FakeContact.loaderOptions());
|
|
@@ -351,10 +350,8 @@ const getNextWeekClause = () => {
|
|
|
351
350
|
(0, jest_date_mock_1.clear)();
|
|
352
351
|
const start = mock_date_1.MockDate.getDate();
|
|
353
352
|
// 7 days
|
|
354
|
-
const end =
|
|
355
|
-
|
|
356
|
-
.toISO();
|
|
357
|
-
return clause.And(clause.GreaterEq("start_time", start.toISOString()), clause.LessEq("start_time", end));
|
|
353
|
+
const end = new Date(start.getTime() + 86400 * 1000 * 7);
|
|
354
|
+
return clause.And(clause.GreaterEq("start_time", start.toISOString()), clause.LessEq("start_time", end.toISOString()));
|
|
358
355
|
};
|
|
359
356
|
exports.getNextWeekClause = getNextWeekClause;
|
|
360
357
|
function getCompleteClause(id) {
|
package/tsc/compilerOptions.js
CHANGED
|
@@ -60,9 +60,6 @@ function readCompilerOptions(filePath) {
|
|
|
60
60
|
if (options.moduleResolution === "node") {
|
|
61
61
|
options.moduleResolution = typescript_1.default.ModuleResolutionKind.NodeJs;
|
|
62
62
|
}
|
|
63
|
-
if (this.options.target) {
|
|
64
|
-
options.target = getTarget(this.options.target);
|
|
65
|
-
}
|
|
66
63
|
return options;
|
|
67
64
|
}
|
|
68
65
|
exports.readCompilerOptions = readCompilerOptions;
|
|
@@ -95,7 +92,7 @@ function getTarget(target) {
|
|
|
95
92
|
exports.getTarget = getTarget;
|
|
96
93
|
function getTargetFromCurrentDir() {
|
|
97
94
|
const options = readCompilerOptions(".");
|
|
98
|
-
return options.target
|
|
95
|
+
return getTarget(options.target?.toString());
|
|
99
96
|
}
|
|
100
97
|
exports.getTargetFromCurrentDir = getTargetFromCurrentDir;
|
|
101
98
|
function createSourceFile(target, file) {
|