Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(Typescript): Improve types [breaking] #15

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@
"indent": [
"error",
2,
{ "SwitchCase": 1 }
{
"SwitchCase": 1
}
],
"quotes": [
"error",
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ typings/
# dotenv environment variables file
.env

*.tsbuildinfo

.idea
.vscode

Expand Down
16 changes: 10 additions & 6 deletions __tests__/Collection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,8 @@ declare global {
}

Connect({
default: {
database: global.__MONGO_DB_NAME__,
connection: global.__MONGO_CONNECTION__,
},
database: global.__MONGO_DB_NAME__,
connection: global.__MONGO_CONNECTION__,
});

it("Should create collection with the given indexes (async/await)", async () => {
Expand All @@ -22,7 +20,10 @@ it("Should create collection with the given indexes (async/await)", async () =>
const collection = new Collection("tests");

collection
.index({ field_1: 1, field_2: -1 }, { name: "field_1_field_2", background: true, unique: true })
.index(
{ field_1: 1, field_2: -1 },
{ name: "field_1_field_2", background: true, unique: true },
)
.index({ field_3: 1 }, { name: "field_3", background: true })
.timestamps()
.softDelete();
Expand All @@ -36,7 +37,10 @@ it("Should create collection with the given indexes (callback)", (done) => {
const collection = new Collection("tests2");

collection
.index({ field_1: 1, field_2: -1 }, { name: "field_1_field_2", background: true, unique: true })
.index(
{ field_1: 1, field_2: -1 },
{ name: "field_1_field_2", background: true, unique: true },
)
.index({ field_3: 1 }, { name: "field_3", background: true })
.timestamps()
.softDelete();
Expand Down
6 changes: 2 additions & 4 deletions __tests__/DB.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,8 @@ const JOIN_ITEMS = [

beforeAll(async () => {
Connect({
default: {
database: global.__MONGO_DB_NAME__,
connection: global.__MONGO_CONNECTION__,
},
database: global.__MONGO_DB_NAME__,
connection: global.__MONGO_CONNECTION__,
});

await DB.collection(COLLECTION).insert(ITEMS);
Expand Down
6 changes: 2 additions & 4 deletions __tests__/Model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,8 @@ const ITEMS = [
];

Odin.Connect({
default: {
database: global.__MONGO_DB_NAME__,
connection: global.__MONGO_CONNECTION__,
},
database: global.__MONGO_DB_NAME__,
connection: global.__MONGO_CONNECTION__,
});

beforeAll(async () => {
Expand Down
12 changes: 7 additions & 5 deletions __tests__/__internals__/setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,11 @@ module.exports = async () => {
await MONGOD.start();

global.__CONNECTION__ = await mongodb.connect(
await MONGOD.getConnectionString(), {
useNewUrlParser: true
}
await MONGOD.getConnectionString(),
{
useNewUrlParser: true,
useUnifiedTopology: true,
},
);

global.__MONGOD__ = MONGOD;
Expand All @@ -52,7 +54,7 @@ module.exports = async () => {

// await sleep(2000);

// global.__REPLICA_CONN__ = await mongodb.connect(
// global.__REPLICA_CONN__ = await mongo.connect(
// await REPLICA.getConnectionString(), {
// useNewUrlParser: true,
// readConcern: {
Expand All @@ -64,4 +66,4 @@ module.exports = async () => {
// );

// global.__REPLICA__ = REPLICA;
}
};
6 changes: 2 additions & 4 deletions __tests__/relations/EmbedMany.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,8 @@ const MESSAGES = [
];

Odin.Connect({
default: {
database: global.__MONGO_DB_NAME__,
connection: global.__MONGO_CONNECTION__,
},
database: global.__MONGO_DB_NAME__,
connection: global.__MONGO_CONNECTION__,
});

@Odin.register
Expand Down
6 changes: 2 additions & 4 deletions __tests__/relations/HasMany.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,8 @@ const MESSAGES = [
];

Odin.Connect({
default: {
database: global.__MONGO_DB_NAME__,
connection: global.__MONGO_CONNECTION__,
},
database: global.__MONGO_DB_NAME__,
connection: global.__MONGO_CONNECTION__,
});

@Odin.register
Expand Down
6 changes: 2 additions & 4 deletions __tests__/relations/HasOne.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,8 @@ const MESSAGES = [
];

Odin.Connect({
default: {
database: global.__MONGO_DB_NAME__,
connection: global.__MONGO_CONNECTION__,
},
database: global.__MONGO_DB_NAME__,
connection: global.__MONGO_CONNECTION__,
});

@Odin.register
Expand Down
6 changes: 2 additions & 4 deletions __tests__/relations/MorphMany.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,8 @@ const MESSAGES = [
];

Odin.Connect({
default: {
database: global.__MONGO_DB_NAME__,
connection: global.__MONGO_CONNECTION__,
},
database: global.__MONGO_DB_NAME__,
connection: global.__MONGO_CONNECTION__,
});

@Odin.register
Expand Down
6 changes: 2 additions & 4 deletions __tests__/relations/MorphOne.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,8 @@ const MESSAGES = [
];

Odin.Connect({
default: {
database: global.__MONGO_DB_NAME__,
connection: global.__MONGO_CONNECTION__,
},
database: global.__MONGO_DB_NAME__,
connection: global.__MONGO_CONNECTION__,
});

@Odin.register
Expand Down
86 changes: 41 additions & 45 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 8 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,24 +48,24 @@
"dependencies": {
"@types/graphql": "^0.13.4",
"@types/graphql-iso-date": "^3.3.1",
"@types/mongodb": "^3.1.19",
"@types/node": "^11.9.3",
"@types/mongodb": "^3.5.27",
"@types/node": "^14.6.4",
"async": "^2.6.2",
"caller-id": "^0.1.0",
"deasync": "^0.1.14",
"deasync": "^0.1.20",
"graphql": "^0.13.2",
"graphql-iso-date": "^3.6.1",
"mongodb": "^3.6.1",
"prototyped.js": "^1.0.0",
"prototyped.js": "^1.0.1",
"verifications": "^0.3.0"
},
"peerDependencies": {
"@foxify/schema": "^1.0.1"
"@foxify/schema": "^2.0.0"
},
"devDependencies": {
"@foxify/schema": "^1.0.1",
"@types/async": "^2.4.1",
"@types/deasync": "^0.1.0",
"@foxify/schema": "^2.0.0",
"@types/async": "^2.4.2",
"@types/deasync": "^0.1.1",
"@types/jest": "^26.0.13",
"@typescript-eslint/eslint-plugin": "^4.0.1",
"@typescript-eslint/parser": "^4.0.1",
Expand Down
Loading