From 7b630168725ce653c025ca6a14023995dc4ad164 Mon Sep 17 00:00:00 2001 From: Flam3rboy <34555296+Flam3rboy@users.noreply.github.com> Date: Mon, 4 Oct 2021 22:43:51 +0200 Subject: [PATCH] :sparkles: generalize primary column to work with mongodb object id --- api/package-lock.json | 14 +++++++------- api/package.json | 2 +- bundle/package-lock.json | 30 +++++++++++++++--------------- bundle/package.json | 2 +- cdn/package-lock.json | 14 +++++++------- cdn/package.json | 2 +- gateway/package-lock.json | 12 +++++++----- gateway/package.json | 2 +- util/package-lock.json | 14 +++++++------- util/package.json | 2 +- util/src/entities/BaseClass.ts | 8 ++++---- util/src/entities/Config.ts | 10 +++++----- util/src/entities/Invite.ts | 8 ++++---- util/src/entities/Member.ts | 2 -- util/src/entities/Template.ts | 2 +- util/src/util/Database.ts | 2 +- 16 files changed, 63 insertions(+), 63 deletions(-) diff --git a/api/package-lock.json b/api/package-lock.json index 1633a945..dccd3c21 100644 --- a/api/package-lock.json +++ b/api/package-lock.json @@ -31,7 +31,7 @@ "i18next-node-fs-backend": "^2.1.3", "jsonwebtoken": "^8.5.1", "lambert-server": "^1.2.10", - "missing-native-js-functions": "^1.2.15", + "missing-native-js-functions": "^1.2.16", "mongoose": "^5.12.3", "mongoose-autopopulate": "^0.12.3", "mongoose-long": "^0.3.2", @@ -10653,9 +10653,9 @@ } }, "node_modules/missing-native-js-functions": { - "version": "1.2.15", - "resolved": "https://registry.npmjs.org/missing-native-js-functions/-/missing-native-js-functions-1.2.15.tgz", - "integrity": "sha512-NNsxPSHnG22xellXsdGkzmF/SSzYNRgZcWQt2OKG+I3Wv8p37kTax13trTMthVkEOhvNv8M2l4A4JwK1p42ZHg==" + "version": "1.2.16", + "resolved": "https://registry.npmjs.org/missing-native-js-functions/-/missing-native-js-functions-1.2.16.tgz", + "integrity": "sha512-XiSrIpYeLfk6OMHoqgg1zxgpOS3dV2J4Elk/GVKqQ2zoRLEJTxPb6RXiAVCv5/JxutMypablImU9JOqV0Vpi9w==" }, "node_modules/mixin-deep": { "version": "1.3.2", @@ -24542,9 +24542,9 @@ } }, "missing-native-js-functions": { - "version": "1.2.15", - "resolved": "https://registry.npmjs.org/missing-native-js-functions/-/missing-native-js-functions-1.2.15.tgz", - "integrity": "sha512-NNsxPSHnG22xellXsdGkzmF/SSzYNRgZcWQt2OKG+I3Wv8p37kTax13trTMthVkEOhvNv8M2l4A4JwK1p42ZHg==" + "version": "1.2.16", + "resolved": "https://registry.npmjs.org/missing-native-js-functions/-/missing-native-js-functions-1.2.16.tgz", + "integrity": "sha512-XiSrIpYeLfk6OMHoqgg1zxgpOS3dV2J4Elk/GVKqQ2zoRLEJTxPb6RXiAVCv5/JxutMypablImU9JOqV0Vpi9w==" }, "mixin-deep": { "version": "1.3.2", diff --git a/api/package.json b/api/package.json index 4fee791c..fa6866f3 100644 --- a/api/package.json +++ b/api/package.json @@ -92,7 +92,7 @@ "i18next-node-fs-backend": "^2.1.3", "jsonwebtoken": "^8.5.1", "lambert-server": "^1.2.10", - "missing-native-js-functions": "^1.2.15", + "missing-native-js-functions": "^1.2.16", "mongoose": "^5.12.3", "mongoose-autopopulate": "^0.12.3", "mongoose-long": "^0.3.2", diff --git a/bundle/package-lock.json b/bundle/package-lock.json index 53bfdf1c..9438c102 100644 --- a/bundle/package-lock.json +++ b/bundle/package-lock.json @@ -17,7 +17,7 @@ "async-exit-hook": "^2.0.1", "dotenv": "^10.0.0", "express": "^4.17.1", - "missing-native-js-functions": "^1.2.15", + "missing-native-js-functions": "^1.2.16", "nanocolors": "^0.2.12", "node-os-utils": "^1.3.5", "tsconfig-paths": "^3.11.0" @@ -71,7 +71,7 @@ "i18next-node-fs-backend": "^2.1.3", "jsonwebtoken": "^8.5.1", "lambert-server": "^1.2.10", - "missing-native-js-functions": "^1.2.15", + "missing-native-js-functions": "^1.2.16", "mongoose": "^5.12.3", "mongoose-autopopulate": "^0.12.3", "mongoose-long": "^0.3.2", @@ -138,7 +138,7 @@ "jest": "^27.0.6", "lambert-db": "^1.2.3", "lambert-server": "^1.2.8", - "missing-native-js-functions": "^1.2.15", + "missing-native-js-functions": "^1.2.16", "multer": "^1.4.2", "nanocolors": "^0.2.12", "node-fetch": "^2.6.1", @@ -177,7 +177,7 @@ "dotenv": "^8.2.0", "jsonwebtoken": "^8.5.1", "lambert-server": "^1.2.8", - "missing-native-js-functions": "^1.2.15", + "missing-native-js-functions": "^1.2.16", "mongoose-autopopulate": "^0.12.3", "node-fetch": "^2.6.1", "typeorm": "^0.2.37", @@ -216,7 +216,7 @@ "env-paths": "^2.2.1", "jsonwebtoken": "^8.5.1", "lambert-server": "^1.2.10", - "missing-native-js-functions": "^1.2.15", + "missing-native-js-functions": "^1.2.16", "multer": "^1.4.3", "nanocolors": "^0.2.12", "node-fetch": "^2.6.1", @@ -1259,9 +1259,9 @@ "integrity": "sha512-FM9nNUYrRBAELZQT3xeZQ7fmMOBg6nWNmJKTcgsJeaLstP/UODVpGsr5OhXhhXg6f+qtJ8uiZ+PUxkDWcgIXLw==" }, "node_modules/missing-native-js-functions": { - "version": "1.2.15", - "resolved": "https://registry.npmjs.org/missing-native-js-functions/-/missing-native-js-functions-1.2.15.tgz", - "integrity": "sha512-NNsxPSHnG22xellXsdGkzmF/SSzYNRgZcWQt2OKG+I3Wv8p37kTax13trTMthVkEOhvNv8M2l4A4JwK1p42ZHg==" + "version": "1.2.16", + "resolved": "https://registry.npmjs.org/missing-native-js-functions/-/missing-native-js-functions-1.2.16.tgz", + "integrity": "sha512-XiSrIpYeLfk6OMHoqgg1zxgpOS3dV2J4Elk/GVKqQ2zoRLEJTxPb6RXiAVCv5/JxutMypablImU9JOqV0Vpi9w==" }, "node_modules/ms": { "version": "2.0.0", @@ -1757,7 +1757,7 @@ "jest-runtime": "^27.2.1", "jsonwebtoken": "^8.5.1", "lambert-server": "^1.2.10", - "missing-native-js-functions": "^1.2.15", + "missing-native-js-functions": "^1.2.16", "mongoose": "^5.12.3", "mongoose-autopopulate": "^0.12.3", "mongoose-long": "^0.3.2", @@ -1808,7 +1808,7 @@ "jest": "^27.0.6", "lambert-db": "^1.2.3", "lambert-server": "^1.2.8", - "missing-native-js-functions": "^1.2.15", + "missing-native-js-functions": "^1.2.16", "multer": "^1.4.2", "nanocolors": "^0.2.12", "node-fetch": "^2.6.1", @@ -1838,7 +1838,7 @@ "dotenv": "^8.2.0", "jsonwebtoken": "^8.5.1", "lambert-server": "^1.2.8", - "missing-native-js-functions": "^1.2.15", + "missing-native-js-functions": "^1.2.16", "mongoose-autopopulate": "^0.12.3", "node-fetch": "^2.6.1", "ts-node-dev": "^1.1.6", @@ -1866,7 +1866,7 @@ "jest": "^27.0.6", "jsonwebtoken": "^8.5.1", "lambert-server": "^1.2.10", - "missing-native-js-functions": "^1.2.15", + "missing-native-js-functions": "^1.2.16", "multer": "^1.4.3", "nanocolors": "^0.2.12", "node-fetch": "^2.6.1", @@ -2658,9 +2658,9 @@ "integrity": "sha512-FM9nNUYrRBAELZQT3xeZQ7fmMOBg6nWNmJKTcgsJeaLstP/UODVpGsr5OhXhhXg6f+qtJ8uiZ+PUxkDWcgIXLw==" }, "missing-native-js-functions": { - "version": "1.2.15", - "resolved": "https://registry.npmjs.org/missing-native-js-functions/-/missing-native-js-functions-1.2.15.tgz", - "integrity": "sha512-NNsxPSHnG22xellXsdGkzmF/SSzYNRgZcWQt2OKG+I3Wv8p37kTax13trTMthVkEOhvNv8M2l4A4JwK1p42ZHg==" + "version": "1.2.16", + "resolved": "https://registry.npmjs.org/missing-native-js-functions/-/missing-native-js-functions-1.2.16.tgz", + "integrity": "sha512-XiSrIpYeLfk6OMHoqgg1zxgpOS3dV2J4Elk/GVKqQ2zoRLEJTxPb6RXiAVCv5/JxutMypablImU9JOqV0Vpi9w==" }, "ms": { "version": "2.0.0", diff --git a/bundle/package.json b/bundle/package.json index 5124fcdf..3fb4cb05 100644 --- a/bundle/package.json +++ b/bundle/package.json @@ -56,7 +56,7 @@ "async-exit-hook": "^2.0.1", "dotenv": "^10.0.0", "express": "^4.17.1", - "missing-native-js-functions": "^1.2.15", + "missing-native-js-functions": "^1.2.16", "nanocolors": "^0.2.12", "node-os-utils": "^1.3.5", "tsconfig-paths": "^3.11.0" diff --git a/cdn/package-lock.json b/cdn/package-lock.json index b8d4f924..d88251b3 100644 --- a/cdn/package-lock.json +++ b/cdn/package-lock.json @@ -24,7 +24,7 @@ "jest": "^27.0.6", "lambert-db": "^1.2.3", "lambert-server": "^1.2.8", - "missing-native-js-functions": "^1.2.15", + "missing-native-js-functions": "^1.2.16", "multer": "^1.4.2", "nanocolors": "^0.2.12", "node-fetch": "^2.6.1", @@ -4094,9 +4094,9 @@ "integrity": "sha512-FM9nNUYrRBAELZQT3xeZQ7fmMOBg6nWNmJKTcgsJeaLstP/UODVpGsr5OhXhhXg6f+qtJ8uiZ+PUxkDWcgIXLw==" }, "node_modules/missing-native-js-functions": { - "version": "1.2.15", - "resolved": "https://registry.npmjs.org/missing-native-js-functions/-/missing-native-js-functions-1.2.15.tgz", - "integrity": "sha512-NNsxPSHnG22xellXsdGkzmF/SSzYNRgZcWQt2OKG+I3Wv8p37kTax13trTMthVkEOhvNv8M2l4A4JwK1p42ZHg==" + "version": "1.2.16", + "resolved": "https://registry.npmjs.org/missing-native-js-functions/-/missing-native-js-functions-1.2.16.tgz", + "integrity": "sha512-XiSrIpYeLfk6OMHoqgg1zxgpOS3dV2J4Elk/GVKqQ2zoRLEJTxPb6RXiAVCv5/JxutMypablImU9JOqV0Vpi9w==" }, "node_modules/mkdirp": { "version": "0.5.5", @@ -8865,9 +8865,9 @@ "integrity": "sha512-FM9nNUYrRBAELZQT3xeZQ7fmMOBg6nWNmJKTcgsJeaLstP/UODVpGsr5OhXhhXg6f+qtJ8uiZ+PUxkDWcgIXLw==" }, "missing-native-js-functions": { - "version": "1.2.15", - "resolved": "https://registry.npmjs.org/missing-native-js-functions/-/missing-native-js-functions-1.2.15.tgz", - "integrity": "sha512-NNsxPSHnG22xellXsdGkzmF/SSzYNRgZcWQt2OKG+I3Wv8p37kTax13trTMthVkEOhvNv8M2l4A4JwK1p42ZHg==" + "version": "1.2.16", + "resolved": "https://registry.npmjs.org/missing-native-js-functions/-/missing-native-js-functions-1.2.16.tgz", + "integrity": "sha512-XiSrIpYeLfk6OMHoqgg1zxgpOS3dV2J4Elk/GVKqQ2zoRLEJTxPb6RXiAVCv5/JxutMypablImU9JOqV0Vpi9w==" }, "mkdirp": { "version": "0.5.5", diff --git a/cdn/package.json b/cdn/package.json index 62c21c9a..11cac162 100644 --- a/cdn/package.json +++ b/cdn/package.json @@ -54,7 +54,7 @@ "jest": "^27.0.6", "lambert-db": "^1.2.3", "lambert-server": "^1.2.8", - "missing-native-js-functions": "^1.2.15", + "missing-native-js-functions": "^1.2.16", "multer": "^1.4.2", "nanocolors": "^0.2.12", "node-fetch": "^2.6.1", diff --git a/gateway/package-lock.json b/gateway/package-lock.json index 4296feae..cc89ffbd 100644 --- a/gateway/package-lock.json +++ b/gateway/package-lock.json @@ -16,7 +16,7 @@ "dotenv": "^8.2.0", "jsonwebtoken": "^8.5.1", "lambert-server": "^1.2.8", - "missing-native-js-functions": "^1.2.15", + "missing-native-js-functions": "^1.2.16", "mongoose-autopopulate": "^0.12.3", "node-fetch": "^2.6.1", "typeorm": "^0.2.37", @@ -8351,8 +8351,9 @@ } }, "node_modules/missing-native-js-functions": { - "version": "1.2.15", - "integrity": "sha512-NNsxPSHnG22xellXsdGkzmF/SSzYNRgZcWQt2OKG+I3Wv8p37kTax13trTMthVkEOhvNv8M2l4A4JwK1p42ZHg==" + "version": "1.2.16", + "resolved": "https://registry.npmjs.org/missing-native-js-functions/-/missing-native-js-functions-1.2.16.tgz", + "integrity": "sha512-XiSrIpYeLfk6OMHoqgg1zxgpOS3dV2J4Elk/GVKqQ2zoRLEJTxPb6RXiAVCv5/JxutMypablImU9JOqV0Vpi9w==" }, "node_modules/mkdirp": { "version": "1.0.4", @@ -15962,8 +15963,9 @@ } }, "missing-native-js-functions": { - "version": "1.2.15", - "integrity": "sha512-NNsxPSHnG22xellXsdGkzmF/SSzYNRgZcWQt2OKG+I3Wv8p37kTax13trTMthVkEOhvNv8M2l4A4JwK1p42ZHg==" + "version": "1.2.16", + "resolved": "https://registry.npmjs.org/missing-native-js-functions/-/missing-native-js-functions-1.2.16.tgz", + "integrity": "sha512-XiSrIpYeLfk6OMHoqgg1zxgpOS3dV2J4Elk/GVKqQ2zoRLEJTxPb6RXiAVCv5/JxutMypablImU9JOqV0Vpi9w==" }, "mkdirp": { "version": "1.0.4", diff --git a/gateway/package.json b/gateway/package.json index 863d7f4e..22387dcb 100644 --- a/gateway/package.json +++ b/gateway/package.json @@ -35,7 +35,7 @@ "dotenv": "^8.2.0", "jsonwebtoken": "^8.5.1", "lambert-server": "^1.2.8", - "missing-native-js-functions": "^1.2.15", + "missing-native-js-functions": "^1.2.16", "mongoose-autopopulate": "^0.12.3", "node-fetch": "^2.6.1", "typeorm": "^0.2.37", diff --git a/util/package-lock.json b/util/package-lock.json index d48403dd..67d4d73f 100644 --- a/util/package-lock.json +++ b/util/package-lock.json @@ -17,7 +17,7 @@ "env-paths": "^2.2.1", "jsonwebtoken": "^8.5.1", "lambert-server": "^1.2.10", - "missing-native-js-functions": "^1.2.15", + "missing-native-js-functions": "^1.2.16", "multer": "^1.4.3", "nanocolors": "^0.2.12", "node-fetch": "^2.6.1", @@ -4717,9 +4717,9 @@ } }, "node_modules/missing-native-js-functions": { - "version": "1.2.15", - "resolved": "https://registry.npmjs.org/missing-native-js-functions/-/missing-native-js-functions-1.2.15.tgz", - "integrity": "sha512-NNsxPSHnG22xellXsdGkzmF/SSzYNRgZcWQt2OKG+I3Wv8p37kTax13trTMthVkEOhvNv8M2l4A4JwK1p42ZHg==" + "version": "1.2.16", + "resolved": "https://registry.npmjs.org/missing-native-js-functions/-/missing-native-js-functions-1.2.16.tgz", + "integrity": "sha512-XiSrIpYeLfk6OMHoqgg1zxgpOS3dV2J4Elk/GVKqQ2zoRLEJTxPb6RXiAVCv5/JxutMypablImU9JOqV0Vpi9w==" }, "node_modules/mkdirp": { "version": "0.5.5", @@ -11138,9 +11138,9 @@ } }, "missing-native-js-functions": { - "version": "1.2.15", - "resolved": "https://registry.npmjs.org/missing-native-js-functions/-/missing-native-js-functions-1.2.15.tgz", - "integrity": "sha512-NNsxPSHnG22xellXsdGkzmF/SSzYNRgZcWQt2OKG+I3Wv8p37kTax13trTMthVkEOhvNv8M2l4A4JwK1p42ZHg==" + "version": "1.2.16", + "resolved": "https://registry.npmjs.org/missing-native-js-functions/-/missing-native-js-functions-1.2.16.tgz", + "integrity": "sha512-XiSrIpYeLfk6OMHoqgg1zxgpOS3dV2J4Elk/GVKqQ2zoRLEJTxPb6RXiAVCv5/JxutMypablImU9JOqV0Vpi9w==" }, "mkdirp": { "version": "0.5.5", diff --git a/util/package.json b/util/package.json index 3bdc04be..3e888c21 100644 --- a/util/package.json +++ b/util/package.json @@ -44,7 +44,7 @@ "env-paths": "^2.2.1", "jsonwebtoken": "^8.5.1", "lambert-server": "^1.2.10", - "missing-native-js-functions": "^1.2.15", + "missing-native-js-functions": "^1.2.16", "multer": "^1.4.3", "nanocolors": "^0.2.12", "node-fetch": "^2.6.1", diff --git a/util/src/entities/BaseClass.ts b/util/src/entities/BaseClass.ts index d18757f2..f105086a 100644 --- a/util/src/entities/BaseClass.ts +++ b/util/src/entities/BaseClass.ts @@ -5,10 +5,8 @@ import { BeforeUpdate, EntityMetadata, FindConditions, - getConnection, - getManager, + ObjectIdColumn, PrimaryColumn, - RemoveOptions, } from "typeorm"; import { Snowflake } from "../util/Snowflake"; import "missing-native-js-functions"; @@ -117,8 +115,10 @@ export class BaseClassWithoutId extends BaseEntity { // } } +export const PrimaryIdColumn = process.env.DATABASE?.startsWith("mongodb") ? ObjectIdColumn : PrimaryColumn; + export class BaseClass extends BaseClassWithoutId { - @PrimaryColumn() + @PrimaryIdColumn() id: string; assign(props: any = {}) { diff --git a/util/src/entities/Config.ts b/util/src/entities/Config.ts index edce92a9..28926233 100644 --- a/util/src/entities/Config.ts +++ b/util/src/entities/Config.ts @@ -1,11 +1,11 @@ -import { Column, Entity, JoinColumn, ManyToOne, PrimaryColumn } from "typeorm"; -import { BaseClass, BaseClassWithoutId } from "./BaseClass"; +import { Column, Entity } from "typeorm"; +import { BaseClassWithoutId, PrimaryIdColumn } from "./BaseClass"; import crypto from "crypto"; import { Snowflake } from "../util/Snowflake"; @Entity("config") export class ConfigEntity extends BaseClassWithoutId { - @PrimaryColumn() + @PrimaryIdColumn() key: string; @Column({ type: "simple-json", nullable: true }) @@ -144,7 +144,7 @@ export interface ConfigValue { useDefaultAsOptimal: boolean; available: Region[]; }; - + guild: { showAllGuildsInDiscovery: boolean; }; @@ -299,7 +299,7 @@ export const DefaultConfigOptions: ConfigValue = { }, ], }, - + guild: { showAllGuildsInDiscovery: false, }, diff --git a/util/src/entities/Invite.ts b/util/src/entities/Invite.ts index 78545b02..82556fab 100644 --- a/util/src/entities/Invite.ts +++ b/util/src/entities/Invite.ts @@ -1,6 +1,6 @@ -import { Column, Entity, JoinColumn, ManyToOne, PrimaryColumn, RelationId } from "typeorm"; -import { Member } from "."; -import { BaseClass } from "./BaseClass"; +import { Column, Entity, JoinColumn, ManyToOne, RelationId } from "typeorm"; +import { Member } from "./Member"; +import { BaseClass, PrimaryIdColumn } from "./BaseClass"; import { Channel } from "./Channel"; import { Guild } from "./Guild"; import { User } from "./User"; @@ -9,7 +9,7 @@ export const PublicInviteRelation = ["inviter", "guild", "channel"]; @Entity("invites") export class Invite extends BaseClass { - @PrimaryColumn() + @PrimaryIdColumn() code: string; @Column() diff --git a/util/src/entities/Member.ts b/util/src/entities/Member.ts index feb9c069..7d7ac40a 100644 --- a/util/src/entities/Member.ts +++ b/util/src/entities/Member.ts @@ -8,8 +8,6 @@ import { JoinTable, ManyToMany, ManyToOne, - OneToMany, - PrimaryColumn, PrimaryGeneratedColumn, RelationId, } from "typeorm"; diff --git a/util/src/entities/Template.ts b/util/src/entities/Template.ts index c9c32f42..1d952283 100644 --- a/util/src/entities/Template.ts +++ b/util/src/entities/Template.ts @@ -1,4 +1,4 @@ -import { Column, Entity, Index, JoinColumn, ManyToOne, PrimaryColumn, RelationId } from "typeorm"; +import { Column, Entity, JoinColumn, ManyToOne, RelationId } from "typeorm"; import { BaseClass } from "./BaseClass"; import { Guild } from "./Guild"; import { User } from "./User"; diff --git a/util/src/util/Database.ts b/util/src/util/Database.ts index 5f622805..6445bd60 100644 --- a/util/src/util/Database.ts +++ b/util/src/util/Database.ts @@ -24,7 +24,7 @@ export function initDatabase() { url: isSqlite ? undefined : dbConnectionString, database: isSqlite ? dbConnectionString : undefined, entities: Object.values(Models).filter((x) => x.constructor.name !== "Object"), - synchronize: true, + synchronize: type !== "mongodb", logging: false, cache: { duration: 1000 * 3, // cache all find queries for 3 seconds