add documentation
This commit is contained in:
parent
50ee195043
commit
3c7e98642f
39
README.md
Normal file
39
README.md
Normal file
@ -0,0 +1,39 @@
|
||||
# InMemory Sessions
|
||||
|
||||
A Service to store Sessions in Memory.
|
||||
|
||||
## Install
|
||||
|
||||
```bash
|
||||
npm i --save @apihub24/in-memory-sessions
|
||||
```
|
||||
|
||||
## Dependencies
|
||||
|
||||
| Exported Injection Keys |
|
||||
| ------------------------- |
|
||||
| @apihub24/session_service |
|
||||
|
||||
## Usage
|
||||
|
||||
```typescript
|
||||
// NestJs usage
|
||||
import { InMemorySessionsModule } from "@apihub24/in-memory-sessions";
|
||||
|
||||
@Module({
|
||||
imports: [InMemorySessionsModule.forRoot()]
|
||||
})
|
||||
...
|
||||
|
||||
// Other usage
|
||||
import { InMemorySessionsModule } from "@apihub24/in-memory-sessions";
|
||||
|
||||
const sessionService = new InMemorySessionService();
|
||||
```
|
||||
|
||||
| Function | Description |
|
||||
| ------------------------------------------------------------------ | ------------------------------------------------------------------------------- |
|
||||
| create(account: IAccount): Promise<ISession> | Create a new Session from a IAccount and returns it |
|
||||
| getBy(filter: (account: IAccount) => boolean): Promise<ISession[]> | get a ISession by a IAccount filter |
|
||||
| getById(sessionId: string): Promise<ISession> | get a ISession by a session id. the returned ISession can be null if not exists |
|
||||
| remove(sessionId: string): Promise<void> | remove the ISession by a session id. |
|
||||
4
package-lock.json
generated
4
package-lock.json
generated
@ -1,12 +1,12 @@
|
||||
{
|
||||
"name": "@apihub24/in-memory-sessions",
|
||||
"version": "1.0.2",
|
||||
"version": "1.0.3",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "@apihub24/in-memory-sessions",
|
||||
"version": "1.0.2",
|
||||
"version": "1.0.3",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@apihub24/token-authentication": "^1.0.4",
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@apihub24/in-memory-sessions",
|
||||
"version": "1.0.2",
|
||||
"version": "1.0.3",
|
||||
"description": "",
|
||||
"main": "dist/index.js",
|
||||
"types": "./dist/index.d.ts",
|
||||
|
||||
@ -9,6 +9,11 @@ import { Injectable } from "@nestjs/common";
|
||||
export class InMemorySessionService implements ISessionService {
|
||||
private source: ISession[] = [];
|
||||
|
||||
/**
|
||||
* add a new Session into the Store and returns it.
|
||||
* @param account a apihub24 token-authentication Account
|
||||
* @returns a apihub24 token-authentication Session
|
||||
*/
|
||||
create(account: IAccount): Promise<ISession> {
|
||||
const s: ISession = {
|
||||
id: crypto.randomUUID().toString(),
|
||||
@ -19,16 +24,31 @@ export class InMemorySessionService implements ISessionService {
|
||||
return Promise.resolve(s);
|
||||
}
|
||||
|
||||
/**
|
||||
* select all Sessions that matches the given Account Filter
|
||||
* @param filter a Account Filter Function
|
||||
* @returns a apihub24 token-authentication Session
|
||||
*/
|
||||
getBy(filter: (account: IAccount) => boolean): Promise<ISession[]> {
|
||||
return Promise.resolve(this.source.filter((x) => filter(x.account)));
|
||||
}
|
||||
|
||||
/**
|
||||
* select the Session by the given id. If no Session with the id exists null was returned!
|
||||
* @param sessionId a session id
|
||||
* @returns a apihub24 token-authentication Session or null
|
||||
*/
|
||||
getById(sessionId: string): Promise<ISession | null> {
|
||||
return Promise.resolve(
|
||||
this.source.filter((x) => x.id === sessionId)[0] ?? null
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* delete the Session by the given id from the Store
|
||||
* @param sessionId a session id
|
||||
* @returns nothing
|
||||
*/
|
||||
remove(sessionId: string): Promise<void> {
|
||||
this.source = this.source.filter((x) => x.id !== sessionId);
|
||||
return Promise.resolve();
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user