Skip to content

Commit bcae71b

Browse files
authored
Update dependencies and fix bugs #197
this branch has been partially live for a while, everything except the server, which dependencies i didn't touch yet but the shared ones most likely broke it
2 parents f358a1e + b317199 commit bcae71b

31 files changed

Lines changed: 6241 additions & 5460 deletions

.circleci/config.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,5 +27,4 @@ workflows:
2727
filters:
2828
branches:
2929
only:
30-
- master
3130
- deploy-circleci

lib/package-lock.json

Lines changed: 251 additions & 1208 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/package.json

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,21 +10,15 @@
1010
"author": "Vladimir Feskov",
1111
"license": "MIT",
1212
"devDependencies": {
13-
"@types/chai": "^4.2.12",
14-
"@types/mocha": "^7.0.2",
15-
"@types/mongodb": "^3.5.25",
16-
"@types/mongoose": "^5.7.36",
17-
"@types/nock": "^11.1.0",
18-
"@types/node-fetch": "^2.5.7",
19-
"chai": "^4.2.0",
20-
"mocha": "^7.2.0",
21-
"nock": "^12.0.3",
22-
"ts-node": "^8.10.2",
23-
"typescript": "^3.9.7"
13+
"@types/node-fetch": "^2.6.2",
14+
"ts-node": "^10.9.1",
15+
"type-fest": "^2.19.0",
16+
"typescript": "^4.7.4"
2417
},
18+
"type": "module",
2519
"dependencies": {
26-
"mongodb": "^3.6.0",
27-
"mongoose": "^5.9.28",
28-
"node-fetch": "2.6.0"
20+
"mongoose": "^6.5.2",
21+
"node-fetch": "^3.2.10",
22+
"timeout-signal": "^1.1.0"
2923
}
3024
}

lib/src/db/AccessToken.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import "./connection";
2-
import * as mongoose from "mongoose";
1+
import "./connection.js";
2+
import mongoose from "mongoose";
33

44
const AccessTokenSchema = new mongoose.Schema(
5-
{ accessToken: String },
5+
{ accessToken: { type: String, required: true } },
66
{ bufferCommands: false }
77
);
88
export const AccessTokenModel = mongoose.model(

lib/src/db/User.ts

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
import { ObjectID } from "mongodb";
2-
import * as mongoose from "mongoose";
3-
import "./connection";
1+
import mongoose from "mongoose";
2+
import "./connection.js";
43
const { assign, keys } = Object;
54

65
const reposValidator = (repos: string[]) => {
@@ -58,10 +57,10 @@ const userSchemaObj: mongoose.SchemaDefinition = {
5857
validate: { validator: Number.isInteger },
5958
},
6059
};
61-
const UserSchema = new mongoose.Schema(userSchemaObj, {
60+
const UserSchema = new mongoose.Schema<RawUser>(userSchemaObj, {
6261
bufferCommands: false,
6362
});
64-
export const UserModel = mongoose.model("User", UserSchema);
63+
export const UserModel = mongoose.model<RawUser>("User", UserSchema);
6564

6665
export class CuteRepo {
6766
filter: number;
@@ -89,24 +88,26 @@ export class UpdateAllReposParams {
8988
}
9089

9190
export class RawUser {
92-
_id?: ObjectID;
93-
accessToken?: string;
94-
alerted?: string[][];
91+
_id: mongoose.Types.ObjectId;
92+
accessToken: string;
93+
alerted: string[][];
9594
checkAt?: number;
96-
email?: string;
95+
email: string;
9796
frequency?: string;
9897
githubId?: number;
99-
majors?: string[];
100-
minors?: string[];
101-
mutedRepos?: string[];
98+
majors: string[];
99+
minors: string[];
100+
mutedRepos: string[];
102101
passwordEncrypted?: string;
103-
patches?: string[];
104-
repos?: string[];
102+
patches: string[];
103+
repos: string[];
105104
watching?: boolean;
106105
watchingStars?: number;
107106
[key: string]: any;
108107
}
109108

109+
export type RawUserUpdate = Partial<RawUser>;
110+
110111
export class User extends CuteUser {
111112
constructor(params: CuteUser) {
112113
super();
@@ -189,7 +190,7 @@ export class User extends CuteUser {
189190
static async load(conditions: any) {
190191
const { id, ...rest } = conditions;
191192
if (id) {
192-
conditions = { _id: new ObjectID(id), ...rest };
193+
conditions = { _id: new mongoose.Types.ObjectId(id), ...rest };
193194
}
194195
const raw = await UserModel.findOne(conditions);
195196
return raw ? new User(toCute(raw)) : null;
@@ -261,7 +262,7 @@ export class User extends CuteUser {
261262
params: UpdateAllReposParams
262263
) {
263264
const { muted, filter } = params;
264-
const command: RawUser = {};
265+
const command: RawUserUpdate = {};
265266
const repoNames = repos.map((r) => r.repo);
266267
if (typeof muted !== "undefined") {
267268
command.mutedRepos = muted ? repoNames : [];
@@ -281,9 +282,9 @@ export class User extends CuteUser {
281282
}
282283

283284
function toRaw({ id, repos, ...rest }: CuteUser): RawUser {
284-
const result: RawUser = rest;
285+
const result: RawUserUpdate = rest;
285286
if (id) {
286-
result._id = new ObjectID(id);
287+
result._id = new mongoose.Types.ObjectId(id);
287288
}
288289
if (repos) {
289290
assign(result, {
@@ -296,7 +297,7 @@ function toRaw({ id, repos, ...rest }: CuteUser): RawUser {
296297
}
297298
return Object.keys(result)
298299
.filter((k) => k === "_id" || !!userSchemaObj[k])
299-
.reduce((r, k) => ({ ...r, [k]: result[k] }), {});
300+
.reduce((r, k) => ({ ...r, [k]: result[k] }), {} as RawUser);
300301
}
301302

302303
function toCute(raw: RawUser): CuteUser {

lib/src/db/connection.ts

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,18 @@
1-
import * as mongoose from "mongoose";
2-
import log from "../log";
1+
import mongoose from "mongoose";
2+
import log from "../log.js";
33

4-
export const connection = mongoose.connect(process.env.WAB_MONGODB_URL, {
5-
useNewUrlParser: true,
6-
useUnifiedTopology: true,
7-
bufferMaxEntries: 0,
8-
});
4+
export function connect() {
5+
return mongoose.connect(process.env.WAB_MONGODB_URL);
6+
}
7+
8+
export const connection = mongoose.connection;
99

1010
export function disconnect() {
11-
return connection.then(
12-
(con) => con.disconnect(),
13-
(e) =>
14-
log("disconnectError", {
15-
name: e.name,
16-
message: e.message,
17-
stack: e.stack,
18-
})
11+
return mongoose.disconnect().catch((e) =>
12+
log("disconnectError", {
13+
name: e.name,
14+
message: e.message,
15+
stack: e.stack,
16+
})
1917
);
2018
}

lib/src/db/index.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
export * from "./User";
2-
export * from "./AccessToken";
3-
export * from "./connection";
1+
export * from "./User.js";
2+
export * from "./AccessToken.js";
3+
export * from "./connection.js";

lib/src/githubAtom.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
// Reusable service to work with GitHub's Atom feeds
22
import fetch from "node-fetch";
3+
import timeoutSignal from "timeout-signal";
34
import { Agent } from "https";
4-
import log from "./log";
5-
import timeout from "./timeout";
5+
import log from "./log.js";
6+
import timeout from "./timeout.js";
67

78
export const FETCH_ATTEMPTS = 3;
89
export const FETCH_ATTEMPTS_INTERVAL = 60000;
@@ -26,7 +27,10 @@ export async function fetchAtom(url: string, includeEntry: boolean) {
2627
while (attempts < FETCH_ATTEMPTS) {
2728
try {
2829
attempts++;
29-
const response = await fetch(url, { agent, timeout: FETCH_TIMEOUT });
30+
const response = await fetch(url, {
31+
// agent,
32+
signal: timeoutSignal(FETCH_TIMEOUT),
33+
});
3034
const { status } = response;
3135
if (status >= 400 && status < 500) {
3236
throw new BadRequest(status);
@@ -132,7 +136,7 @@ export class BadRequest extends BaseErrorWithStatus {
132136
}
133137

134138
const ENTRY_REGEXP = /<entry>[\s\S]*?<\/entry>/gm;
135-
const ID_REGEXP = new RegExp("<id>[^<]+/([^/<]+)</id>");
139+
const ID_REGEXP = new RegExp("<id>[^<]+Repository/\\d+/([^<]+)</id>");
136140

137141
function parse(xml: string, includeEntry: boolean) {
138142
return (xml.match(ENTRY_REGEXP) || [])

lib/src/timeout.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export function timeout(ms: number) {
1010
}
1111

1212
export function testTimeout(ms: number) {
13-
return new Promise((resolve) => {
13+
return new Promise<void>((resolve) => {
1414
_testTimePassed += ms;
1515
resolve();
1616
});

lib/tsconfig.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
{
22
"compilerOptions": {
3-
"module": "commonjs",
3+
"module": "ESNext",
4+
"moduleResolution": "node",
45
"noImplicitAny": true,
56
"removeComments": true,
67
"declaration": true,
78
"target": "es2017",
8-
"outDir": "."
9+
"outDir": ".",
10+
"esModuleInterop": true
911
},
1012
"include": ["src/**/*"],
1113
"exclude": ["node_modules", "**/*.spec.ts"]

0 commit comments

Comments
 (0)