Skip to content
Merged
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
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@
"prepublishOnly": "npm install && npm run clean && npm run build",
"build": "tsc -b",
"clean": "tsc -b --clean",
"preeslint": "npm run clean && npm run build",
"eslint": "eslint src test",
"pretest": "npm run clean && npm run build",
"test": "mocha -r ts-node/register 'test/scripts/**/*.ts'",
"test-cov": "c8 --reporter=lcovonly --reporter=text-summary npm test",
"typedoc": "typedoc --entryPointStrategy expand ./src"
Expand All @@ -41,6 +39,7 @@
"devDependencies": {
"@types/bluebird": "^3.5.37",
"@types/chai": "^4.3.3",
"@types/chai-as-promised": "^8.0.1",
"@types/graceful-fs": "^4.1.5",
"@types/jsonstream": "^0.8.30",
"@types/mocha": "^10.0.0",
Expand Down
4 changes: 2 additions & 2 deletions src/database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ async function exportAsync(database: Database, path: string): Promise<void> {
interface DatabaseOptions {
version: number,
path: string,
onUpgrade: (...args: any[]) => any,
onDowngrade: (...args: any[]) => any
onUpgrade: (oldVersion: number, newVersion: number) => any,
onDowngrade: (oldVersion: number, newVersion: number) => any
}

class Database {
Expand Down
10 changes: 5 additions & 5 deletions src/document.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ import rfdc from 'rfdc';
import type Model from './model';
import type Schema from './schema';
import type BluebirdPromise from 'bluebird';
import type { NodeJSLikeCallback } from './types';
import type { NodeJSLikeCallback, Options } from './types';
const cloneDeep = rfdc();

abstract class Document<T> {
abstract _model: Model<T>;
_id!: string | number | undefined;
_id!: string;
abstract _schema: Schema<T>;
[key : string]: any;

Expand Down Expand Up @@ -69,7 +69,7 @@ abstract class Document<T> {
*
* @return {object}
*/
toObject(): T {
toObject(): T extends object ? T : never {
const keys = Object.keys(this);
const obj: Partial<T> = {};

Expand All @@ -80,7 +80,7 @@ abstract class Document<T> {
obj[key] = isGetter(this, key) ? this[key] : cloneDeep(this[key]);
}

return obj as T;
return obj as T extends object ? T : never;
}

/**
Expand All @@ -98,7 +98,7 @@ abstract class Document<T> {
* @param {String|Object} expr
* @return {Document}
*/
populate(expr: string | any[] | { path?: string; model?: any; [key: PropertyKey]: any }): Document<T> {
populate(expr: string | string[] | Partial<Options>[] | Partial<Options>): Document<T> {
const stack = this._schema._parsePopulate(expr);
return this._model._populate(this, stack);
}
Expand Down
Loading
Loading