From 6052f91841f79bbd9a54ef858fc52be7405e8c9b Mon Sep 17 00:00:00 2001 From: Mike Cornwell Date: Mon, 6 Jan 2025 16:41:29 -0500 Subject: [PATCH 1/2] feat(noop): add noop datastore --- package.json | 5 +++- src/datastore/noop.ts | 29 ++++++++++++++++++ src/index.ts | 1 + test/src/noop.test.ts | 68 +++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 102 insertions(+), 1 deletion(-) create mode 100644 src/datastore/noop.ts create mode 100644 test/src/noop.test.ts diff --git a/package.json b/package.json index edd1b93..2d636fe 100644 --- a/package.json +++ b/package.json @@ -66,6 +66,7 @@ "devDependencies": { "@istanbuljs/nyc-config-typescript": "^1.0.2", "@types/chai": "^4.3.0", + "@types/chai-as-promised": "^7.1.8", "@types/lodash": "^4.14.177", "@types/mocha": "^9.0.0", "@types/node": "^16.11.7", @@ -74,6 +75,7 @@ "@typescript-eslint/parser": "^6.3.0", "babel-eslint": "^10.1.0", "chai": "^4.3.0", + "chai-as-promised": "^7.1.2", "cucumber": "^6.0.7", "cz-conventional-changelog": "^3.3.0", "eslint": "^8.46.0", @@ -83,12 +85,13 @@ "eslint-plugin-import": "^2.28.0", "mocha": "^10.4.0", "nodemon": "^3.1.0", - "nyc": "^15.1.0", + "nyc": "^17.1.0", "prettier": "^3.2.5", "proxyquire": "^2.1.3", "sinon": "^11.1.2", "source-map-support": "^0.5.21", "ts-node": "^10.9.2", + "tsx": "^4.19.2", "typescript": "^5.7.2" }, "homepage": "https://github.com/monolithst/functional-models-orm#readme", diff --git a/src/datastore/noop.ts b/src/datastore/noop.ts new file mode 100644 index 0000000..892babb --- /dev/null +++ b/src/datastore/noop.ts @@ -0,0 +1,29 @@ +import { DatastoreProvider } from '../interfaces' + +const create = (): DatastoreProvider => { + return { + save: () => { + return Promise.reject('Cannot run save in noop') + }, + delete: () => { + return Promise.reject('Cannot run delete in noop') + }, + retrieve: () => { + return Promise.reject('Cannot run retrieve in noop') + }, + search: () => { + return Promise.reject('Cannot run search in noop') + }, + bulkInsert: () => { + return Promise.reject('Cannot run bulkInsert in noop') + }, + createAndSave: () => { + return Promise.reject('Cannot run createAndSave in noop') + }, + count: () => { + return Promise.reject('Cannot run count in noop') + }, + } +} + +export { create } diff --git a/src/index.ts b/src/index.ts index 9743452..fd6821b 100644 --- a/src/index.ts +++ b/src/index.ts @@ -8,5 +8,6 @@ import * as interfaces from './interfaces' export * from './ormQuery' export * from './interfaces' export * from './properties' +export { create as createNoopDatastoreProvider } from './datastore/noop' export { interfaces, orm, ormQuery, datastore, validation, properties } diff --git a/test/src/noop.test.ts b/test/src/noop.test.ts new file mode 100644 index 0000000..cfd2912 --- /dev/null +++ b/test/src/noop.test.ts @@ -0,0 +1,68 @@ +import { assert } from 'chai' +import chai from 'chai' +import { create } from '../../src/datastore/noop' + +import asPromised from 'chai-as-promised' +// @ts-ignore +chai.use(asPromised) + +describe('/src/datastore/noop.ts', () => { + describe('#create()', () => { + describe('#search()', () => { + it('should reject the promise with the expected exception', () => { + const instance = create() + // @ts-ignore + const promise = instance.search({}) + return assert.isRejected(promise, 'Cannot run search in noop') + }) + }) + describe('#save()', () => { + it('should reject the promise with the expected exception', () => { + const instance = create() + // @ts-ignore + const promise = instance.save({}) + return assert.isRejected(promise, 'Cannot run save in noop') + }) + }) + describe('#delete()', () => { + it('should reject the promise with the expected exception', () => { + const instance = create() + // @ts-ignore + const promise = instance.delete({}) + return assert.isRejected(promise, 'Cannot run delete in noop') + }) + }) + describe('#retrieve()', () => { + it('should reject the promise with the expected exception', () => { + const instance = create() + // @ts-ignore + const promise = instance.retrieve({}) + return assert.isRejected(promise, 'Cannot run retrieve in noop') + }) + }) + describe('#createAndSave()', () => { + it('should reject the promise with the expected exception', () => { + const instance = create() + // @ts-ignore + const promise = instance.createAndSave({}) + return assert.isRejected(promise, 'Cannot run createAndSave in noop') + }) + }) + describe('#bulkInsert()', () => { + it('should reject the promise with the expected exception', () => { + const instance = create() + // @ts-ignore + const promise = instance.bulkInsert({}) + return assert.isRejected(promise, 'Cannot run bulkInsert in noop') + }) + }) + describe('#count()', () => { + it('should reject the promise with the expected exception', () => { + const instance = create() + // @ts-ignore + const promise = instance.count() + return assert.isRejected(promise, 'Cannot run count in noop') + }) + }) + }) +}) From 54842a2a98831fdd3bb003166bdb8aac11f01b5b Mon Sep 17 00:00:00 2001 From: Mike Cornwell Date: Mon, 6 Jan 2025 16:41:48 -0500 Subject: [PATCH 2/2] chore(version): bump version --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 2d636fe..944932c 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "functional-models-orm", - "version": "2.1.12", + "version": "2.1.13", "description": "A basic ORM building library using the functional-models library.", "main": "index.js", "types": "index.d.ts",