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: refactor types #261

Merged
merged 8 commits into from
Jan 11, 2025
Merged

refactor: refactor types #261

merged 8 commits into from
Jan 11, 2025

Conversation

D-Sketon
Copy link
Member

@D-Sketon D-Sketon commented Jun 30, 2024

now

this.findById(id, { lean: true }); // <-- T
this.findById(id, { lean: false }); // <-- Document<T>
this.findById(id, {}); // <-- Document<T>
this.findById(id, {} as Partial<Options>); // <-- Document<T> | T

@coveralls
Copy link

coveralls commented Jun 30, 2024

Pull Request Test Coverage Report for Build 9732452201

Details

  • 123 of 123 (100.0%) changed or added relevant lines in 7 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.02%) to 98.295%

Totals Coverage Status
Change from base Build 9700112432: 0.02%
Covered Lines: 4438
Relevant Lines: 4515

💛 - Coveralls

@coveralls
Copy link

coveralls commented Jul 4, 2024

Pull Request Test Coverage Report for Build 9797301066

Details

  • 140 of 140 (100.0%) changed or added relevant lines in 7 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.02%) to 98.295%

Totals Coverage Status
Change from base Build 9700112432: 0.02%
Covered Lines: 4438
Relevant Lines: 4515

💛 - Coveralls

@D-Sketon D-Sketon marked this pull request as ready for review July 6, 2024 07:32
@coveralls
Copy link

coveralls commented Jul 6, 2024

Pull Request Test Coverage Report for Build 9817607131

Details

  • 185 of 185 (100.0%) changed or added relevant lines in 7 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.01%) to 98.289%

Totals Coverage Status
Change from base Build 9700112432: 0.01%
Covered Lines: 4424
Relevant Lines: 4501

💛 - Coveralls

SukkaW
SukkaW previously approved these changes Jul 6, 2024
@coveralls
Copy link

coveralls commented Jul 6, 2024

Pull Request Test Coverage Report for Build 9819663515

Details

  • 186 of 186 (100.0%) changed or added relevant lines in 7 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.02%) to 98.29%

Totals Coverage Status
Change from base Build 9700112432: 0.02%
Covered Lines: 4425
Relevant Lines: 4502

💛 - Coveralls

@@ -21,6 +21,7 @@ class Model<T> extends EventEmitter {
Document: { new<T>(data: T): Document<T> };
Query: { new<T>(data: Document<T>[]): Query<T> };
_database: Database;
[key : string]: any;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warehouse/src/model.ts

Lines 79 to 82 in af981d3

Object.assign(this, schema.statics);
// Apply instance methods
Object.assign(_Document.prototype, schema.methods);

Solve the above code, but as with #252, it's not a good solution. Model knows nothing about static and method types in Schema.
@SukkaW Do you have any good solutions?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was going to add another generic for setting the type of static and method, but its not possible to act directly on the class.

interface Extra {
  statics: Record<string, (...args: any[]) => any>;
  methods: Record<string, (...args: any[]) => any>;
}

type AddThis<R extends Record<string, (...args: any[]) => any>, T> = {
  [K in keyof R]: (this: T, ...args: Parameters<R[K]>) => ReturnType<R[K]>;
}

class Schema<T = any, K extends Partial<Extra> = Extra> {
  statics!: K['statics'] extends Record<string, (...args: any[]) => any> ? AddThis<K['statics'], T> : Record<string, (this: T, ...args: any[]) => any>;
  methods!: K['methods'] extends Record<string, (...args: any[]) => any> ? AddThis<K['methods'], T> : Record<string, (this: T, ...args: any[]) => any>;

}

interface AssetSchema {
  _id: string
}

const a = new Schema<AssetSchema, {
  statics: {
    add: (a: number, b: number) => number;
  }
}>().statics.add // <-- (this: AssetSchema, a: number, b: number) => ReturnType<(a: number, b: number) => number>

const b = new Schema<AssetSchema>().methods // <-- AddThis<Record<string, (...args: any[]) => any>, AssetSchema>

class Model<T, K extends Partial<Extra> = Extra> {
  schema!: Schema<T, K>
  // [key in keyof K['statics']]: K['statics'][key] illegal
}

Copy link
Member

@SukkaW SukkaW Dec 29, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have some vague ideas about this:

We can do this in another PR.

@coveralls
Copy link

coveralls commented Dec 28, 2024

Pull Request Test Coverage Report for Build 12721566187

Details

  • 186 of 186 (100.0%) changed or added relevant lines in 7 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.01%) to 98.297%

Totals Coverage Status
Change from base Build 12654109413: 0.01%
Covered Lines: 4444
Relevant Lines: 4521

💛 - Coveralls

@D-Sketon D-Sketon requested a review from a team December 28, 2024 13:53
import Database from '../../dist/database';
import Model from '../../dist/model';
import Database from '../../src/database';
import Model from '../../src/model';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

scripts preeslint, pretest could be deleted.

"preeslint": "npm run clean && npm run build",

"pretest": "npm run clean && npm run build",

@uiolee
Copy link
Member

uiolee commented Jan 9, 2025

Conflicts with branch master's code, could you update them?

@uiolee uiolee merged commit 73da886 into hexojs:master Jan 11, 2025
20 of 21 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants