From 37bba8b1b18a4d66097688a9b1f573db31762959 Mon Sep 17 00:00:00 2001 From: Yoonho Go Date: Tue, 24 Dec 2019 15:54:19 +0900 Subject: [PATCH 1/3] Create index.d.ts --- index.d.ts | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 index.d.ts diff --git a/index.d.ts b/index.d.ts new file mode 100644 index 0000000..d65a6b3 --- /dev/null +++ b/index.d.ts @@ -0,0 +1,15 @@ +declare module 'apollo-datasource-mongodb' { + import mongoose, { Document, Model } from 'mongoose' + import { DataSource, DataSourceConfig } from 'apollo-datasource' + + type Options = { ttl: number } + + export abstract class MongoDataSource extends DataSource { + collection: mongoose.Collection | Model + constructor(collection: mongoose.Collection | Model) + public initialize(config: DataSourceConfig): void + protected findOneById(id: string, { ttl }?: Options): T | null + protected findManyByIds(ids: string[], { ttl }?: Options): (T| null)[] + protected deleteFromCacheById(id: string): void + } +} From 3f76598908e60c215f7e219e292d04122c81a022 Mon Sep 17 00:00:00 2001 From: Yoonho Go Date: Tue, 24 Dec 2019 17:01:50 +0900 Subject: [PATCH 2/3] Update index.d.ts --- index.d.ts | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/index.d.ts b/index.d.ts index d65a6b3..63b5648 100644 --- a/index.d.ts +++ b/index.d.ts @@ -2,10 +2,15 @@ declare module 'apollo-datasource-mongodb' { import mongoose, { Document, Model } from 'mongoose' import { DataSource, DataSourceConfig } from 'apollo-datasource' - type Options = { ttl: number } + export { + DataSourceConfig + } + + interface Options { ttl: number } export abstract class MongoDataSource extends DataSource { - collection: mongoose.Collection | Model + collection: mongoose.Collection + model?: Model constructor(collection: mongoose.Collection | Model) public initialize(config: DataSourceConfig): void protected findOneById(id: string, { ttl }?: Options): T | null From b69334cb959f99fc4ac40dbc0170cb7d7778cfc0 Mon Sep 17 00:00:00 2001 From: Yoonho Go Date: Tue, 24 Dec 2019 17:42:47 +0900 Subject: [PATCH 3/3] Update index.d.ts --- index.d.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/index.d.ts b/index.d.ts index 63b5648..b878825 100644 --- a/index.d.ts +++ b/index.d.ts @@ -1,6 +1,6 @@ declare module 'apollo-datasource-mongodb' { - import mongoose, { Document, Model } from 'mongoose' import { DataSource, DataSourceConfig } from 'apollo-datasource' + import * as mongoose from 'mongoose' export { DataSourceConfig @@ -8,10 +8,10 @@ declare module 'apollo-datasource-mongodb' { interface Options { ttl: number } - export abstract class MongoDataSource extends DataSource { + export abstract class MongoDataSource extends DataSource { collection: mongoose.Collection - model?: Model - constructor(collection: mongoose.Collection | Model) + model?: mongoose.Model + constructor(collection: mongoose.Collection | mongoose.Model) public initialize(config: DataSourceConfig): void protected findOneById(id: string, { ttl }?: Options): T | null protected findManyByIds(ids: string[], { ttl }?: Options): (T| null)[]