MCPcopy Create free account
hub / github.com/Automattic/mongoose / schemaInstanceMethodsAndQueryHelpers

Function schemaInstanceMethodsAndQueryHelpers

test/types/models.test.ts:444–481  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

442}
443
444function schemaInstanceMethodsAndQueryHelpers() {
445 type UserModelQuery = Query<any, HydratedDocument<User>, UserQueryHelpers> & UserQueryHelpers;
446 interface UserQueryHelpers {
447 byName(this: UserModelQuery, name: string): this
448 }
449 interface User {
450 name: string;
451 }
452 interface UserInstanceMethods {
453 doSomething(this: HydratedDocument<User>): string;
454 }
455 interface UserStaticMethods {
456 findByName(name: string): Promise<HydratedDocument<User>>;
457 }
458 type UserModel = Model<User, UserQueryHelpers, UserInstanceMethods> & UserStaticMethods;
459
460 const userSchema = new Schema<User, UserModel, UserInstanceMethods, UserQueryHelpers, any, UserStaticMethods>({
461 name: String
462 }, {
463 statics: {
464 findByName(name: string) {
465 return model('User').findOne({ name }).orFail();
466 }
467 },
468 methods: {
469 doSomething() {
470 return 'test';
471 }
472 },
473 query: {
474 byName(this: UserModelQuery, name: string) {
475 return this.where({ name });
476 }
477 }
478 });
479
480 const TestModel = model<User, UserModel, UserQueryHelpers>('User', userSchema);
481}
482
483function gh12100() {
484 const schema = new Schema();

Callers

nothing calls this directly

Calls 1

modelFunction · 0.85

Tested by

no test coverage detected