From 08fd76dcefb881ae293a840c00483f12e5ce2f93 Mon Sep 17 00:00:00 2001 From: admin Date: Wed, 20 Aug 2025 21:52:19 +0200 Subject: [PATCH] init --- .gitignore | 4 ++++ .npmignore | 6 ++++++ LICENSE | 21 ++++++++++++++++++++ package-lock.json | 39 +++++++++++++++++++++++++++++++++++++ package.json | 26 +++++++++++++++++++++++++ src/in.memory.repository.ts | 37 +++++++++++++++++++++++++++++++++++ src/index.ts | 1 + tsconfig.json | 26 +++++++++++++++++++++++++ 8 files changed, 160 insertions(+) create mode 100644 .gitignore create mode 100644 .npmignore create mode 100644 LICENSE create mode 100644 package-lock.json create mode 100644 package.json create mode 100644 src/in.memory.repository.ts create mode 100644 src/index.ts create mode 100644 tsconfig.json diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..c4c6c48 --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +.vscode +.idea +dist +node_modules diff --git a/.npmignore b/.npmignore new file mode 100644 index 0000000..fc59ab5 --- /dev/null +++ b/.npmignore @@ -0,0 +1,6 @@ +.vscode +.idea +node_modules +src +.gitignore +tsconfig.json \ No newline at end of file diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..2efc0b9 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2025 Markus Morgenstern + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. \ No newline at end of file diff --git a/package-lock.json b/package-lock.json new file mode 100644 index 0000000..411b321 --- /dev/null +++ b/package-lock.json @@ -0,0 +1,39 @@ +{ + "name": "@apihub24/in-memory-repository", + "version": "1.0.0", + "lockfileVersion": 3, + "requires": true, + "packages": { + "": { + "name": "@apihub24/in-memory-repository", + "version": "1.0.0", + "license": "MIT", + "dependencies": { + "@apihub24/repository": "^1.0.1" + }, + "devDependencies": { + "typescript": "^5.9.2" + } + }, + "node_modules/@apihub24/repository": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/@apihub24/repository/-/repository-1.0.1.tgz", + "integrity": "sha512-ex3Z+lxsHtVKDTolJQqLHswq9SKfXzM/hWv17zsrhKqJwuGxO7CeBFM60aiuApZX9NqBhGAkPGGj9jt+F/Y9HQ==", + "license": "MIT" + }, + "node_modules/typescript": { + "version": "5.9.2", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.9.2.tgz", + "integrity": "sha512-CWBzXQrc/qOkhidw1OzBTQuYRbfyxDXJMVJ1XNwUHGROVmuaeiEm3OslpZ1RV96d7SKKjZKrSJu3+t/xlw3R9A==", + "dev": true, + "license": "Apache-2.0", + "bin": { + "tsc": "bin/tsc", + "tsserver": "bin/tsserver" + }, + "engines": { + "node": ">=14.17" + } + } + } +} diff --git a/package.json b/package.json new file mode 100644 index 0000000..0d65753 --- /dev/null +++ b/package.json @@ -0,0 +1,26 @@ +{ + "name": "@apihub24/in-memory-repository", + "version": "1.0.0", + "description": "", + "main": "dist/index.js", + "types": "./dist/index.d.ts", + "scripts": { + "build": "tsc" + }, + "dependencies": { + "@apihub24/repository": "^1.0.1" + }, + "devDependencies": { + "typescript": "^5.9.2" + }, + "keywords": [], + "author": { + "email": "markusmorgenstern87@outlook.de", + "name": "Markus Morgenstern", + "url": "https://git.apihub24.de/" + }, + "license": "MIT", + "publishConfig": { + "access": "public" + } +} diff --git a/src/in.memory.repository.ts b/src/in.memory.repository.ts new file mode 100644 index 0000000..dd55810 --- /dev/null +++ b/src/in.memory.repository.ts @@ -0,0 +1,37 @@ +import { Repository } from '@apihub24/repository'; + +interface IdModel { + id: string; +} + +export class InMemoryRepository + implements Repository +{ + private source: TModel[] = []; + + getBy(filter: (model: TModel) => boolean): Promise { + const result: TModel[] = []; + for (const s of this.source) { + if (filter(s)) { + result.push(s); + } + } + return Promise.resolve(result); + } + + save(models: TModel[]): Promise { + for (const model of models) { + if (!model?.id) { + model.id = crypto.randomUUID().toString(); + } + this.source = this.source.filter((x) => x.id !== model.id); + this.source.push(model); + } + return Promise.resolve(this.source); + } + + deleteBy(filter: (model: TModel) => boolean): Promise { + this.source = this.source.filter(filter); + return Promise.resolve(true); + } +} diff --git a/src/index.ts b/src/index.ts new file mode 100644 index 0000000..dc85648 --- /dev/null +++ b/src/index.ts @@ -0,0 +1 @@ +export * from './in.memory.repository'; diff --git a/tsconfig.json b/tsconfig.json new file mode 100644 index 0000000..99c400b --- /dev/null +++ b/tsconfig.json @@ -0,0 +1,26 @@ +{ + "compilerOptions": { + "module": "nodenext", + "moduleResolution": "nodenext", + "resolvePackageJsonExports": true, + "esModuleInterop": true, + "isolatedModules": true, + "declaration": true, + "removeComments": true, + "emitDecoratorMetadata": true, + "experimentalDecorators": true, + "allowSyntheticDefaultImports": true, + "target": "ES2023", + "sourceMap": true, + "outDir": "./dist", + "baseUrl": "./", + "incremental": true, + "skipLibCheck": true, + "strictNullChecks": true, + "forceConsistentCasingInFileNames": true, + "noImplicitAny": false, + "strictBindCallApply": false, + "noFallthroughCasesInSwitch": false + }, + "include": ["./src"] +}