From f7a2deb87c76e644c9b0ecf77d9ab4256052ac7e Mon Sep 17 00:00:00 2001 From: PINGUET Julien Date: Thu, 22 Feb 2018 12:37:14 +0100 Subject: [PATCH] [mongorito] Typing for version 3.0 --- types/mongorito/index.d.ts | 297 ++++++++++++++++ types/mongorito/mongorito-tests.ts | 553 +++++++++++++++++++++++++++++ types/mongorito/tsconfig.json | 23 ++ types/mongorito/tslint.json | 79 +++++ 4 files changed, 952 insertions(+) create mode 100644 types/mongorito/index.d.ts create mode 100644 types/mongorito/mongorito-tests.ts create mode 100644 types/mongorito/tsconfig.json create mode 100644 types/mongorito/tslint.json diff --git a/types/mongorito/index.d.ts b/types/mongorito/index.d.ts new file mode 100644 index 0000000000..8342495926 --- /dev/null +++ b/types/mongorito/index.d.ts @@ -0,0 +1,297 @@ +// Type definitions for mongorito v3.0.4 +// Project: https://github.com/vadimdemedes/mongorito +// Definitions by: Pinguet62 +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.4 + +import {Collection, CommonOptions, Db, IndexOptions, Long, MongoClientOptions, ReadPreference} from 'mongodb'; + +declare namespace mongorito { +} + +export {Timestamp, ObjectId, MinKey, MaxKey, DBRef, Long} from 'mongodb'; + +type Class = new (...args: any[]) => T; +export type ModelClass = Class; + +declare class MQuery { +} + +// "extends MQuery": not actually inheritance, but more easy to implement +export class Query extends MQuery { + static find(this: Class, query?: object): Promise; + + static findOne(this: Class, query?: object): Promise; + + static findById(this: Class, id: object | string): Promise; + + static count(query?: object): Promise; + + static sort(field: string | string[], value?: string): Query; + static sort(query: object): Query; // TODO best parameter type + + static include(field: string | string[], value?: number): Query; + static include(query: object): Query; // TODO best parameter type + + static exclude(field: string | string[], value?: number): Query; + static exclude(query: object): Query; // TODO best parameter type + + static remove(query?: object): Promise; + + Model: ModelClass; + query: Array<[string, object]>; +} + +// "extends Query": not actually inheritance, but more easy to implement +export class Model extends Query { + + /** + * @see Model#database + * @see Database#connection() + */ + static getConnection(): Promise; + + /** + * @see Db#collection(string) + */ + static getCollection(): Promise>; + + static use(plugins?: Plugin | Plugin[]): void; + + static modifyReducer(reducerModifier: ReducerModifier): void; + + static query(method: string, query: [string, any][]): Promise; + + /** + * @see mongodb.Collection#listIndexes() + * @return {Promise} {@link CommandCursor#toArray()} + */ + static listIndexes(options?: { batchSize?: number, readPreference?: ReadPreference | string }): Promise; + + /** + * @see mongodb.Collection#createIndex() + */ + static createIndex(fieldOrSpec: string | any, options?: IndexOptions): Promise; + + /** + * @see mongodb.Collection#dropIndex() + */ + static dropIndex(indexName: string, options?: CommonOptions): Promise; + + static embeds(key: string, model: ModelClass): void; + + constructor(fields?: object); + + collection(): string; + + getConnection(): Promise; + + getCollection(): Promise>; + + set(key: string, value: any): void; + set(value: object): void; + + get(key?: string): any; + + unset(keys?: string | string[]): void; + + toJSON(): object; + + isSaved(): boolean; + + save(): Promise; + + increment(key: string, value?: number): Promise; + increment(keys: { [key: string]: number }): Promise; + + refresh(): Promise; + + remove(): Promise; +} + +export enum ActionTypes { + GET = "@@mongorito/GET", + SET = "@@mongorito/SET", + UNSET = "@@mongorito/UNSET", + REFRESH = "@@mongorito/REFRESH", + REFRESHED = "@@mongorito/REFRESHED", + SAVE = "@@mongorito/SAVE", + CREATE = "@@mongorito/CREATE", + CREATED = "@@mongorito/CREATED", + UPDATE = "@@mongorito/UPDATE", + UPDATED = "@@mongorito/UPDATED", + REMOVE = "@@mongorito/REMOVE", + REMOVED = "@@mongorito/REMOVED", + INCREMENT = "@@mongorito/INCREMENT", + CREATE_INDEX = "@@mongorito/CREATE_INDEX", + DROP_INDEX = "@@mongorito/DROP_INDEX", + LIST_INDEXES = "@@mongorito/LIST_INDEXES", + QUERY = "@@mongorito/QUERY", + CALL = "@@mongorito/CALL" +} + +export interface GetAction { + type: string; // ActionTypes.GET + key?: string; +} + +export interface SetAction { + type: string; // ActionTypes.SET + fields: object; +} + +export interface UnsetAction { + type: string; // ActionTypes.UNSET + keys: string | string[]; +} + +export interface RefreshAction { + type: string; // ActionTypes.REFRESH +} + +export interface RefreshedAction { + type: string; // ActionTypes.REFRESHED + fields: object; +} + +export interface SaveAction { + type: string; // ActionTypes.SAVE + fields: object; +} + +export interface CreateAction { + type: string; // ActionTypes.CREATE + id: object; +} + +export interface CreatedAction { + type: string; // ActionTypes.CREATED + id: object; +} + +export interface UpdateAction { + type: string; // ActionTypes.UPDATE + fields: object; +} + +export interface UpdatedAction { + type: string; // ActionTypes.UPDATED + fields: object; +} + +export interface RemoveAction { + type: string; // ActionTypes.REMOVE +} + +export interface RemovedAction { + type: string; // ActionTypes.REMOVED +} + +export interface IncrementAction { + type: string; // ActionTypes.INCREMENT + fields: object; +} + +export interface CreateIndexAction { + type: string; // ActionTypes.CREATE_INDEX + args: any[]; +} + +export interface DropIndexAction { + type: string; // ActionTypes.DROP_INDEX + args: any[]; +} + +export interface ListIndexesAction { + type: string; // ActionTypes.LIST_INDEXES + args: any[]; +} + +export interface QueryAction { + type: string; // ActionTypes.QUERY + method: string; + query: { method: string, args: any }[]; +} + +export interface CallAction { + type: string; // ActionTypes.CALL + method: string; + args: { method: string, args: any }[]; +} + +export type Action = + GetAction + | SetAction + | UnsetAction + | RefreshAction + | RefreshedAction + | SaveAction + | CreateAction + | CreatedAction + | UpdateAction + | UpdatedAction + | RemoveAction + | RemovedAction + | IncrementAction + | CreateIndexAction + | DropIndexAction + | ListIndexesAction + | QueryAction + | CallAction + +export type PluginNext = (action: Action) => void; + +interface DefaultState { + unset: string[], + fields: object +} + +export type State = DefaultState & any; + +export interface PluginStore { + dispatch: (arg: any) => any, + getState: () => State, + modelClass: ModelClass, + model?: Model +} + +export type Reducer = (state: S, action: Action) => Reducer; + +export interface DefaultReducer { + unset: Reducer; + fields: Reducer; +} + +export type ReducerState = DefaultReducer & Map; + +export type ReducerModifier = (reducerState: ReducerState) => ReducerState; + +export type Plugin = (modelClass: ModelClass) => (store: PluginStore) => (next: PluginNext) => (action: Action) => void; + +export enum DatabaseState { + STATE_CONNECTED = 0, + STATE_CONNECTING = 1, + STATE_DISCONNECTED = 2 +} + +export class Database { + options: MongoClientOptions; + state: DatabaseState; + models: ModelClass[]; + plugins: Plugin[]; + + constructor(urls?: string | string[], options?: MongoClientOptions); + + connect(): Promise; + + connection(): Promise; + + disconnect(): Promise; + + register(models: ModelClass | ModelClass[]): void; + + /** + * @see Model#use() + */ + use(plugins?: Plugin | Plugin[]): void; +} diff --git a/types/mongorito/mongorito-tests.ts b/types/mongorito/mongorito-tests.ts new file mode 100644 index 0000000000..88a7b51cc0 --- /dev/null +++ b/types/mongorito/mongorito-tests.ts @@ -0,0 +1,553 @@ +/** + * - Compilation type-check: using TS compiler "strict" options, and DefinitelyTyped linter (based on comments) + * - Dynamic type-check: using `expect(...).toBeInstanceOf(...)` on a simple workflow (require Mongodb instance) + */ + +import { + Collection, + Db, + DBRef as MongodbDBRef, + Long as MongodbLong, + MaxKey as MongodbMaxKey, + MinKey as MongodbMinKey, + MongoClientOptions, + ObjectId as MongodbObjectId, + Timestamp as MongodbTimestamp +} from 'mongodb'; +import { + Action, + ActionTypes, + CreatedAction, + Database, + DBRef, + Long, + MaxKey, + MinKey, + Model, + ModelClass, + ObjectId, + Plugin, + PluginNext, + PluginStore, + Query, + ReducerModifier, + ReducerState, + RefreshedAction, + RemovedAction, + State, + Timestamp, + UpdatedAction +} from 'mongorito'; + +const URL = `192.168.99.100:27017`; + +// "jest" dependency +declare function describe(description: string, callback: Function): void; +declare function it(description: string, callback: Function | Promise): void; +declare function expect(obj: any): any; + +function expectToBeAModelClass(obj: ModelClass) { + expect(obj).toBeInstanceOf(Function); + expect(obj).toHaveProperty('constructor'); + expect(obj).toHaveProperty('database'); // static field set by "Database.register()" call +} + +function expectToBeAPluginStore(obj: PluginStore) { + expect(obj.dispatch).toBeInstanceOf(Function); + + expect(obj.getState).toBeInstanceOf(Function); + let storeState: State = obj.getState(); + expectToBeAState(storeState); + + expectToBeAModelClass(obj.modelClass); + + expect(obj.model).toBeInstanceOf(Model); +} + +function expectToBeAState(obj: State) { + expect(obj).toHaveProperty('unset'); + expect(Array.isArray(obj.unset)).toBe(true); + expect(obj).toHaveProperty('fields'); + expect(obj.fields).toBeInstanceOf(Object); +} + +function expectToBeAQuery(obj: Query) { + expectToBeAModelClass(obj.Model); + expect(Array.isArray(obj.query)).toBe(true); +} + +function expectToBeAAction(obj: Action) { + expect(obj).toBeInstanceOf(Object); + expect(typeof obj.type).toBe("string"); +} + +function expectToBeACreatedAction(obj: CreatedAction | UpdatedAction) { + expect(obj).toBeInstanceOf(Object); + expect(obj.type).toEqual(ActionTypes.CREATED); + expect((obj as any).id).toBeInstanceOf(ObjectId); +} + +function expectToBeAUpdatedAction(obj: CreatedAction | UpdatedAction) { + expect(obj).toBeInstanceOf(Object); + expect(obj.type).toEqual(ActionTypes.UPDATED); + expect((obj as any).fields).toBeInstanceOf(Object); +} + +function expectToBeARefreshedAction(obj: RefreshedAction) { + expect(obj).toBeInstanceOf(Object); + expect(obj.type).toEqual(ActionTypes.REFRESHED); + expect(obj.fields).toBeInstanceOf(Object); +} + +function expectToBeARemovedAction(obj: RemovedAction) { + expect(obj).toBeInstanceOf(Object); + expect(obj.type).toEqual(ActionTypes.REMOVED); +} + +function expectToBeACollection(obj: Collection) { + // expect(obj).toBeInstanceOf(Object); + expect(typeof obj.collectionName).toBe("string"); + expect(typeof obj.namespace).toBe("string"); + // expect(obj).toHaveProperty("writeConcern"); + // expect(obj).toHaveProperty("readConcern"); + // expect(obj).toHaveProperty("hint"); +} + +describe('mongorito', () => { + const plugin1: Plugin = (modelClass: ModelClass) => (store: PluginStore) => (next: PluginNext) => (action: Action) => { + // next(action); + }; + const plugin2: Plugin = (modelClass: ModelClass) => (store: PluginStore) => (next: PluginNext) => (action: Action) => { + // next(action); + }; + const plugin3: Plugin = (modelClass: ModelClass) => (store: PluginStore) => (next: PluginNext) => (action: Action) => { + // next(action); + }; + + it('Plugin', async () => { + let plugin: Plugin = (modelClass: ModelClass) => { + expectToBeAModelClass(modelClass); + return (store: PluginStore) => { + expectToBeAPluginStore(store); + return (next: PluginNext) => { + expect(next).toBeInstanceOf(Function); + return (action: Action) => { + expectToBeAAction(action); + // next(action); + } + } + } + }; + + let database = new Database(URL); + await database.connect(); + + class PluggedModel extends Model { + } + + database.register(PluggedModel); + PluggedModel.use(plugin); + let obj: Model = new PluggedModel({attr: 42}); + await obj.save() + }); + + it('Database', async () => { + // ----- constructor ----- + + new Database(URL); + let options: MongoClientOptions = {}; + let database = new Database(URL, options); + + new Database(URL); + + new Database(['other', URL]); + + new Database(['other', URL], options); + + // ----- connect ----- + + let connectResultPromise: Promise = database.connect(); + expect(connectResultPromise).toBeInstanceOf(Promise); + let connectResult: Db = await connectResultPromise; + expect(connectResult).toBeInstanceOf(Db); + + // ----- connection ----- + + let connectionResultPromise: Promise = database.connection(); + expect(connectionResultPromise).toBeInstanceOf(Promise); + let connectionResult: Db = await connectionResultPromise; + expect(connectionResult).toBeInstanceOf(Db); + + // ----- disconnect ----- + + let disconnectResultPromise: Promise = database.disconnect(); + expect(disconnectResultPromise).toBeInstanceOf(Promise); + let disconnectResult = await disconnectResultPromise; + expect(disconnectResult).toBeUndefined(); + + // ----- register ----- + class RegisteredModel extends Model { + constructor(fields?: Object) { + super(fields); + } + } + + class RegisteredModelA extends Model { + constructor(fields?: Object) { + super(fields); + } + } + + class RegisteredModelB extends Model { + constructor(fields?: Object) { + super(fields); + } + } + + expect(database.register(RegisteredModel)).toBeUndefined(); + expect(database.register([RegisteredModelA, RegisteredModelB])).toBeUndefined(); + + // ----- use ----- + + expect(database.use(plugin1)).toBeUndefined(); + expect(database.use([plugin2, plugin3])).toBeUndefined(); + }); + + describe('Model', () => { + it('base static', async () => { + let database = new Database(URL); + await database.connect(); + + class Sample extends Model { + constructor(fields?: Object) { + super(fields); + } + } + + database.register(Sample); + + const fieldOrSpec: string = 'any'; + + // ----- getConnection ----- + + let getConnectionResultPromise: Promise = Sample.getConnection(); + expect(getConnectionResultPromise).toBeInstanceOf(Promise); + let getConnectionResult: Db = await getConnectionResultPromise; + expect(getConnectionResult).toBeInstanceOf(Db); + + // ----- getCollection ----- + + let getCollectionResultPromise: Promise> = Sample.getCollection(); + expect(getCollectionResultPromise).toBeInstanceOf(Promise); + let getCollectionResult: Collection = await getCollectionResultPromise; + expectToBeACollection(getCollectionResult); + + // ----- use ----- + + // expect(Sample.use(plugin1)).toBeUndefined(); + // expect(Sample.use([plugin2, plugin3])).toBeUndefined(); + + // ----- modifyReducer ----- + + let reducer: ReducerModifier = (reducerState: ReducerState) => { + expect(reducerState.unset).toBeInstanceOf(Function); + expect(reducerState.fields).toBeInstanceOf(Function); + return reducerState + }; + expect(Sample.modifyReducer(reducer)).toBeUndefined(); + + // ----- query ----- + await new Sample({'attr': 'first'}).save(); + await new Sample({'attr': 'second'}).save(); + + let method: string = 'find'; + let query: [string, any][] = [ + ['where', {'attr': {$exists: true}}], + ['limit', 5] + ]; + let queryResultPromise: Promise = Sample.query(method, query); + expect(queryResultPromise).toBeInstanceOf(Promise); + let queryResult: Object[] = await queryResultPromise; + expect(Array.isArray(queryResult)).toBe(true); + expect(queryResult.length).toBeGreaterThan(0); + queryResult.forEach(x => expect(x).toBeInstanceOf(Object)); + + // ----- listIndexes ----- + + let listIndexesResultPromise: Promise = Sample.listIndexes(); + expect(listIndexesResultPromise).toBeInstanceOf(Promise); + let listIndexesResult: any[] = await listIndexesResultPromise; + expect(Array.isArray(listIndexesResult)).toBe(true); + listIndexesResult.forEach(x => expect(x).not.toBeUndefined()); + + // ----- createIndex ----- + + let createIndexResultPromise: Promise = Sample.createIndex(fieldOrSpec); + expect(createIndexResultPromise).toBeInstanceOf(Promise); + let createIndexResult: string = await createIndexResultPromise; + expect(typeof createIndexResult).toBe('string'); + + // ----- dropIndex ----- + + let dropIndexResultPromise: Promise = Sample.dropIndex(createIndexResult); + expect(dropIndexResultPromise).toBeInstanceOf(Promise); + let dropIndexResult: object = await dropIndexResultPromise; + expect(dropIndexResult).not.toBeUndefined(); + + // ----- embeds ----- + class EmbeddedModel extends Model { + } + + let key: string = 'any'; + let model: ModelClass = EmbeddedModel; + expect(Sample.embeds(key, model)).toBeUndefined() + }); + + it('base', async () => { + let database = new Database(URL); + await database.connect(); + + class Sample extends Model { + constructor(fields?: Object) { + super(fields); + } + } + + database.register(Sample); + + // ----- constructor ----- + + let fields: Object = {views: 5, comments: 2}; + let model = new Sample(fields); + + new Sample(); + + // ----- collection ----- + + let collectionResult: string = model.collection(); + expect(typeof collectionResult).toBe('string'); + + // ----- getConnection ----- + + let getConnectionResultPromise: Promise = model.getConnection(); + expect(getConnectionResultPromise).toBeInstanceOf(Promise); + let getConnectionResult: Db = await getConnectionResultPromise; + expect(getConnectionResult).toBeInstanceOf(Db); + + // ----- getCollection ----- + + let getCollectionResultPromise: Promise> = model.getCollection(); + expect(getCollectionResultPromise).toBeInstanceOf(Promise); + let getCollectionResult: Collection = await getCollectionResultPromise; + expectToBeACollection(getCollectionResult); + + // ----- set ----- + let key: string = 'attr'; + let key2: string = 'attr2'; + let key3: string = 'attr3'; + + expect(model.set(key, 'val')).toBeUndefined(); + expect(model.set({key2: 'val1', key3: 'val2'})).toBeUndefined(); + + // ----- get ----- + + let getResult1: any = model.get(key); + expect(getResult1).not.toBeUndefined(); + + let getResult2: any = model.get(); + expect(getResult2).not.toBeUndefined(); + + // ----- unset ----- + + expect(model.unset(key)).toBeUndefined(); + + let keys: string[] = [key2, key3]; + expect(model.unset(keys)).toBeUndefined(); + + // ----- toJSON ----- + + let toJSONResult: object = model.toJSON(); + expect(toJSONResult).toBeInstanceOf(Object); + + // ----- isSaved ----- + + let isSavedResult: boolean = model.isSaved(); + expect(typeof isSavedResult).toBe('boolean'); + + // ----- save ----- + + let save1ResultPromise: Promise = model.save(); + expect(save1ResultPromise).toBeInstanceOf(Promise); + let save1Result: CreatedAction | UpdatedAction = await save1ResultPromise; + expectToBeACreatedAction(save1Result); + + let save2ResultPromise: Promise = model.save(); + expect(save2ResultPromise).toBeInstanceOf(Promise); + let save2Result: CreatedAction | UpdatedAction = await save2ResultPromise; + expectToBeAUpdatedAction(save2Result); + + // ----- increment ----- + + let incrementResultPromise1: Promise = model.increment('views'); + expect(incrementResultPromise1).toBeInstanceOf(Promise); + let incrementResult1: any = await incrementResultPromise1; + expectToBeARefreshedAction(incrementResult1); + + let incrementResultPromise2: Promise = model.increment('views', 2); + expect(incrementResultPromise2).toBeInstanceOf(Promise); + let incrementResult2: any = await incrementResultPromise2; + expectToBeARefreshedAction(incrementResult2); + + let incrementResultPromise3: Promise = model.increment({views: 10, comments: 3}); + expect(incrementResultPromise3).toBeInstanceOf(Promise); + let incrementResult3: any = await incrementResultPromise3; + expectToBeARefreshedAction(incrementResult3); + + // ----- refresh ----- + + let refreshResultPromise: Promise = model.refresh(); + expect(refreshResultPromise).toBeInstanceOf(Promise); + let refreshResult: RefreshedAction = await refreshResultPromise; + expectToBeARefreshedAction(refreshResult); + + // ----- remove ----- + + let removeResultPromise: Promise = model.remove(); + expect(removeResultPromise).toBeInstanceOf(Promise); + let removeResult: RemovedAction = await removeResultPromise; + expectToBeARemovedAction(removeResult); + }); + + it('Query', async () => { + let database = new Database(URL); + await database.connect(); + + class Sample extends Model { + constructor(fields?: Object) { + super(fields); + } + } + + database.register(Sample); + + let cas = new Sample(); + await cas.save(); + let ID = cas.get('_id'); + + let query: object = {_id: ID}; + + // ----- find ----- + + let findResultPromise1: Promise = Sample.find(); + expect(findResultPromise1).toBeInstanceOf(Promise); + let findResult1: Sample[] = await findResultPromise1; + expect(Array.isArray(findResult1)).toBe(true); + expect(findResult1[0]).toBeInstanceOf(Sample); + + let findResultPromise2: Promise = Sample.find(query); + expect(findResultPromise2).toBeInstanceOf(Promise); + let findResult2: Sample[] = await findResultPromise2; + expect(Array.isArray(findResult2)).toBe(true); + expect(findResult2[0]).toBeInstanceOf(Sample); + + // ----- findOne ----- + + let findOneResultPromise1: Promise = Sample.findOne(); + expect(findOneResultPromise1).toBeInstanceOf(Promise); + let findOneResult1: Sample | null = await findOneResultPromise1; + expect(findOneResult1).toBeInstanceOf(Sample); + + let findOneResultPromise2: Promise = Sample.findOne(query); + expect(findOneResultPromise2).toBeInstanceOf(Promise); + let findOneResult2: Sample | null = await findOneResultPromise2; + expect(findOneResult2).toBeInstanceOf(Sample); + + // ----- findById ----- + + let findByIdResultPromise: Promise = Sample.findById(ID); + expect(findByIdResultPromise).toBeInstanceOf(Promise); + let findByIdResult: Sample | null = await findByIdResultPromise; + expect(findByIdResult).toBeInstanceOf(Sample); + + await Sample.findById(ID.toString()); + + // ----- count ----- + + let countResultPromise: Promise = Sample.count(); + expect(countResultPromise).toBeInstanceOf(Promise); + let countResult: number = await countResultPromise; + expect(typeof countResult).toBe('number'); + + await Sample.count(query); + + // ----- sort ----- + + let sortResult1: Query = Sample.sort('field-test'); + expectToBeAQuery(sortResult1); + + let sortResult2: Query = Sample.sort({field: 1, test: -1}); + expectToBeAQuery(sortResult2); + + // ----- include ----- + + let includeResult1: Query = Sample.include('field-test'); + expectToBeAQuery(includeResult1); + + let includeResult2: Query = Sample.include({field: 1, test: -1}); + expectToBeAQuery(includeResult2); + + // ----- exclude ----- + + let excludeResult1: Query = Sample.exclude('field-test'); + expectToBeAQuery(excludeResult1); + + let excludeResult2: Query = Sample.exclude({field: 1, test: -1}); + expectToBeAQuery(excludeResult2); + + // ----- remove ----- + + let removeResultPromise: Promise = Sample.remove(); + expect(removeResultPromise).toBeInstanceOf(Promise); + let removeResult: object = await removeResultPromise; + expect(removeResult).toBeInstanceOf(Object); + + await Sample.remove(query); + }); + }); + + it('Timestamp', async () => { + let obj: Timestamp = new Timestamp(1, 9); + expect(obj).toBeInstanceOf(Timestamp); + expect(obj).toBeInstanceOf(MongodbTimestamp); + }); + + it('ObjectId', async () => { + let obj: ObjectId = new ObjectId(); + expect(obj).toBeInstanceOf(ObjectId); + expect(obj).toBeInstanceOf(MongodbObjectId); + }); + + it('MinKey', async () => { + let obj: MinKey = new MinKey(); + expect(obj).toBeInstanceOf(MinKey); + expect(obj).toBeInstanceOf(MongodbMinKey); + }); + + it('MaxKey', async () => { + let obj: MaxKey = new MaxKey(); + expect(obj).toBeInstanceOf(MaxKey); + expect(obj).toBeInstanceOf(MongodbMaxKey); + }); + + it('DBRef', async () => { + let obj: DBRef = new DBRef('namespace', new ObjectId()); + expect(obj).toBeInstanceOf(DBRef); + expect(obj).toBeInstanceOf(MongodbDBRef); + }); + + it('Long', async () => { + let obj: Long = new Long(1, 9); + expect(obj).toBeInstanceOf(Long); + expect(obj).toBeInstanceOf(MongodbLong); + }); +}); diff --git a/types/mongorito/tsconfig.json b/types/mongorito/tsconfig.json new file mode 100644 index 0000000000..142c17e29f --- /dev/null +++ b/types/mongorito/tsconfig.json @@ -0,0 +1,23 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "strictFunctionTypes": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "mongorito-tests.ts" + ] +} diff --git a/types/mongorito/tslint.json b/types/mongorito/tslint.json new file mode 100644 index 0000000000..a41bf5d19a --- /dev/null +++ b/types/mongorito/tslint.json @@ -0,0 +1,79 @@ +{ + "extends": "dtslint/dt.json", + "rules": { + "adjacent-overload-signatures": false, + "array-type": false, + "arrow-return-shorthand": false, + "ban-types": false, + "callable-types": false, + "comment-format": false, + "dt-header": false, + "eofline": false, + "export-just-namespace": false, + "import-spacing": false, + "interface-name": false, + "interface-over-type-literal": false, + "jsdoc-format": false, + "max-line-length": false, + "member-access": false, + "new-parens": false, + "no-any-union": false, + "no-boolean-literal-compare": false, + "no-conditional-assignment": false, + "no-consecutive-blank-lines": false, + "no-construct": false, + "no-declare-current-package": false, + "no-duplicate-imports": false, + "no-duplicate-variable": false, + "no-empty-interface": false, + "no-for-in-array": false, + "no-inferrable-types": false, + "no-internal-module": false, + "no-irregular-whitespace": false, + "no-mergeable-namespace": false, + "no-misused-new": false, + "no-namespace": false, + "no-object-literal-type-assertion": false, + "no-padding": false, + "no-redundant-jsdoc": false, + "no-redundant-jsdoc-2": false, + "no-redundant-undefined": false, + "no-reference-import": false, + "no-relative-import-in-test": false, + "no-self-import": false, + "no-single-declare-module": false, + "no-string-throw": false, + "no-unnecessary-callback-wrapper": false, + "no-unnecessary-class": false, + "no-unnecessary-generics": false, + "no-unnecessary-qualifier": false, + "no-unnecessary-type-assertion": false, + "no-useless-files": false, + "no-var-keyword": false, + "no-var-requires": false, + "no-void-expression": false, + "no-trailing-whitespace": false, + "object-literal-key-quotes": false, + "object-literal-shorthand": false, + "one-line": false, + "one-variable-per-declaration": false, + "only-arrow-functions": false, + "prefer-conditional-expression": false, + "prefer-const": false, + "prefer-declare-function": false, + "prefer-for-of": false, + "prefer-method-signature": false, + "prefer-template": false, + "radix": false, + "semicolon": false, + "space-before-function-paren": false, + "space-within-parens": false, + "strict-export-declare-modifiers": false, + "trim-file": false, + "triple-equals": false, + "typedef-whitespace": false, + "unified-signatures": false, + "void-return": false, + "whitespace": false + } +}