From 54453949fb90066d34dc0eadaa0f26835d60b66c Mon Sep 17 00:00:00 2001 From: Michael Krog Date: Tue, 6 Jun 2023 11:04:05 +0200 Subject: [PATCH] Adds ObservableCrudRepository. --- package-lock.json | 27 ++++++++++++++++++++ package.json | 7 ++--- src/repository/crud-repository-event.ts | 15 +++++++++++ src/repository/observable-crud-repository.ts | 12 +++++++++ 4 files changed, 58 insertions(+), 3 deletions(-) create mode 100644 src/repository/crud-repository-event.ts create mode 100644 src/repository/observable-crud-repository.ts diff --git a/package-lock.json b/package-lock.json index f053dd7..84aec6b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,6 +9,7 @@ "version": "1.0.2", "license": "MIT", "dependencies": { + "rxjs": "^7.8.1", "typescript": "^4.2.3" }, "devDependencies": { @@ -386,6 +387,14 @@ "rollup": "^2.0.0" } }, + "node_modules/rxjs": { + "version": "7.8.1", + "resolved": "https://registry.npmjs.org/rxjs/-/rxjs-7.8.1.tgz", + "integrity": "sha512-AA3TVj+0A2iuIoQkWEK/tqFjBq2j+6PO6Y0zJcvzLAFhEFIO3HL0vls9hWLncZbAAbK0mar7oZ4V079I/qPMxg==", + "dependencies": { + "tslib": "^2.1.0" + } + }, "node_modules/safe-buffer": { "version": "5.2.1", "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.2.1.tgz", @@ -499,6 +508,11 @@ "node": ">=10" } }, + "node_modules/tslib": { + "version": "2.5.3", + "resolved": "https://registry.npmjs.org/tslib/-/tslib-2.5.3.tgz", + "integrity": "sha512-mSxlJJwl3BMEQCUNnxXBU9jP4JBktcEGhURcPR6VQVlnP0FdDEsIaz0C35dXNGLyRfrATNofF0F5p2KPxQgB+w==" + }, "node_modules/typedarray-to-buffer": { "version": "3.1.5", "resolved": "https://registry.npmjs.org/typedarray-to-buffer/-/typedarray-to-buffer-3.1.5.tgz", @@ -820,6 +834,14 @@ "terser": "^5.0.0" } }, + "rxjs": { + "version": "7.8.1", + "resolved": "https://registry.npmjs.org/rxjs/-/rxjs-7.8.1.tgz", + "integrity": "sha512-AA3TVj+0A2iuIoQkWEK/tqFjBq2j+6PO6Y0zJcvzLAFhEFIO3HL0vls9hWLncZbAAbK0mar7oZ4V079I/qPMxg==", + "requires": { + "tslib": "^2.1.0" + } + }, "safe-buffer": { "version": "5.2.1", "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.2.1.tgz", @@ -900,6 +922,11 @@ "source-map-support": "~0.5.19" } }, + "tslib": { + "version": "2.5.3", + "resolved": "https://registry.npmjs.org/tslib/-/tslib-2.5.3.tgz", + "integrity": "sha512-mSxlJJwl3BMEQCUNnxXBU9jP4JBktcEGhURcPR6VQVlnP0FdDEsIaz0C35dXNGLyRfrATNofF0F5p2KPxQgB+w==" + }, "typedarray-to-buffer": { "version": "3.1.5", "resolved": "https://registry.npmjs.org/typedarray-to-buffer/-/typedarray-to-buffer-3.1.5.tgz", diff --git a/package.json b/package.json index 939cbb9..e70ecab 100644 --- a/package.json +++ b/package.json @@ -29,14 +29,15 @@ ], "devDependencies": { "esbuild": "^0.12.15", + "load-json-file": "^7.0.1", "rollup": "^2.52.7", "rollup-plugin-dts": "^3.0.2", "rollup-plugin-esbuild": "^4.5.0", "rollup-plugin-terser": "^7.0.2", - "load-json-file": "^7.0.1", - "write-json-file": "^5.0.0" + "write-json-file": "^5.0.0" }, "dependencies": { + "rxjs": "^7.8.1", "typescript": "^4.2.3" } -} \ No newline at end of file +} diff --git a/src/repository/crud-repository-event.ts b/src/repository/crud-repository-event.ts new file mode 100644 index 0000000..343510a --- /dev/null +++ b/src/repository/crud-repository-event.ts @@ -0,0 +1,15 @@ + +/** + * Interface for events emitted by ObservableCrudRepository. + */ +export interface CrudRepositoryEvent { + /** + * The type of the event. + */ + type: 'Created' | 'Updated' | 'Deleted'; + + /** + * The id of the entity changed in the repository. + */ + id: string; +} \ No newline at end of file diff --git a/src/repository/observable-crud-repository.ts b/src/repository/observable-crud-repository.ts new file mode 100644 index 0000000..4cc8719 --- /dev/null +++ b/src/repository/observable-crud-repository.ts @@ -0,0 +1,12 @@ +import { Observable } from "rxjs"; +import { CrudRepository } from "./crud-repository"; +import { CrudRepositoryEvent } from "./crud-repository-event"; + +/** + * Interface for Oberservable CrudRepositories. Adds changes observable upon the CrudRepository interface. + */ +export interface ObservableCrudRepository extends CrudRepository { + + changes: Observable; + +}