From 8ce18469b9cffd181c733f09636e5bf9992527a2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timoth=C3=A9e=20Rebours?= Date: Thu, 10 Mar 2022 08:41:09 +0100 Subject: [PATCH] change signature in typings for loadDatabase --- CHANGELOG.md | 4 ++++ index.d.ts | 2 +- typings-tests.ts | 6 ++++++ 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2e6adc6..6910b4d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [2.2.2] - 2022-03-10 +### Fixed +- [#21](https://github.com/seald/nedb/issues/21) Typings for loadDatabase now support a callback. + ## [2.2.1] - 2022-01-18 ### Changed - [#20](https://github.com/seald/nedb/pull/20) storage.js: check fsync capability from return code rather than using process.platform heuristics (Thanks [@bitmeal](https://github.com/bitmeal)). diff --git a/index.d.ts b/index.d.ts index 6ff68df..7b8beb6 100644 --- a/index.d.ts +++ b/index.d.ts @@ -17,7 +17,7 @@ declare class Nedb extends EventEmitter { persistence: Nedb.Persistence; - loadDatabase(): void; + loadDatabase(callback?: (err: Error | null) => void): void; getAllData(): T[]; diff --git a/typings-tests.ts b/typings-tests.ts index 3144ec0..5cc5b6a 100644 --- a/typings-tests.ts +++ b/typings-tests.ts @@ -16,6 +16,12 @@ let db = new Datastore() db = new Datastore({ filename: 'path/to/datafile' }) db.loadDatabase() +// Type 2 bis: Persistent datastore with manual loading with a callback +db = new Datastore({ filename: 'path/to/datafile' }) +db.loadDatabase((err: Error | null) => { + // should not fail +}) + // Type 3: Persistent datastore with automatic loading db = new Datastore({ filename: 'path/to/datafile_2', autoload: true }) // You can issue commands right away