@dismissible/nestjs-storage 0.0.2-canary.8976e84.0 → 0.0.2-canary.a611bd3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +9 -11
- package/package.json +12 -11
- package/src/index.js +7 -0
- package/src/index.js.map +1 -0
- package/src/memory-storage.adapter.d.ts +29 -0
- package/src/memory-storage.adapter.js +67 -0
- package/src/memory-storage.adapter.js.map +1 -0
- package/src/storage.interface.d.ts +30 -0
- package/src/storage.interface.js +8 -0
- package/src/storage.interface.js.map +1 -0
- package/src/storage.module.d.ts +6 -0
- package/src/storage.module.js +22 -0
- package/src/storage.module.js.map +1 -0
- package/jest.config.ts +0 -10
- package/project.json +0 -42
- package/src/memory-storage.adapter.ts +0 -70
- package/src/storage.interface.ts +0 -34
- package/src/storage.module.ts +0 -18
- package/tsconfig.json +0 -13
- package/tsconfig.lib.json +0 -14
- /package/src/{index.ts → index.d.ts} +0 -0
package/README.md
CHANGED
|
@@ -49,28 +49,26 @@ You can implement your own storage adapter by implementing the `IDismissibleStor
|
|
|
49
49
|
```typescript
|
|
50
50
|
import { Injectable } from '@nestjs/common';
|
|
51
51
|
import { IDismissibleStorage, DISMISSIBLE_STORAGE_ADAPTER } from '@dismissible/nestjs-storage';
|
|
52
|
-
import { DismissibleItemDto
|
|
52
|
+
import { DismissibleItemDto } from '@dismissible/nestjs-dismissible-item';
|
|
53
53
|
import { DISMISSIBLE_LOGGER, IDismissibleLogger } from '@dismissible/nestjs-logger';
|
|
54
54
|
|
|
55
55
|
@Injectable()
|
|
56
|
-
export class MyCustomStorageAdapter
|
|
57
|
-
TMetadata extends BaseMetadata,
|
|
58
|
-
> implements IDismissibleStorage<TMetadata> {
|
|
56
|
+
export class MyCustomStorageAdapter implements IDismissibleStorage {
|
|
59
57
|
constructor(@Inject(DISMISSIBLE_LOGGER) private readonly logger: IDismissibleLogger) {}
|
|
60
58
|
|
|
61
|
-
async get(userId: string, itemId: string): Promise<DismissibleItemDto
|
|
59
|
+
async get(userId: string, itemId: string): Promise<DismissibleItemDto | null> {
|
|
62
60
|
// Your implementation
|
|
63
61
|
this.logger.debug('Getting item', { userId, itemId });
|
|
64
62
|
// ...
|
|
65
63
|
}
|
|
66
64
|
|
|
67
|
-
async create(item: DismissibleItemDto
|
|
65
|
+
async create(item: DismissibleItemDto): Promise<DismissibleItemDto> {
|
|
68
66
|
// Your implementation
|
|
69
67
|
this.logger.debug('Creating item', { itemId: item.id });
|
|
70
68
|
// ...
|
|
71
69
|
}
|
|
72
70
|
|
|
73
|
-
async update(item: DismissibleItemDto
|
|
71
|
+
async update(item: DismissibleItemDto): Promise<DismissibleItemDto> {
|
|
74
72
|
// Your implementation
|
|
75
73
|
this.logger.debug('Updating item', { itemId: item.id });
|
|
76
74
|
// ...
|
|
@@ -96,10 +94,10 @@ export class MyStorageModule {}
|
|
|
96
94
|
### IDismissibleStorage Interface
|
|
97
95
|
|
|
98
96
|
```typescript
|
|
99
|
-
interface IDismissibleStorage
|
|
100
|
-
get(userId: string, itemId: string): Promise<DismissibleItemDto
|
|
101
|
-
create(item: DismissibleItemDto
|
|
102
|
-
update(item: DismissibleItemDto
|
|
97
|
+
interface IDismissibleStorage {
|
|
98
|
+
get(userId: string, itemId: string): Promise<DismissibleItemDto | null>;
|
|
99
|
+
create(item: DismissibleItemDto): Promise<DismissibleItemDto>;
|
|
100
|
+
update(item: DismissibleItemDto): Promise<DismissibleItemDto>;
|
|
103
101
|
}
|
|
104
102
|
```
|
|
105
103
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dismissible/nestjs-storage",
|
|
3
|
-
"version": "0.0.2-canary.
|
|
3
|
+
"version": "0.0.2-canary.a611bd3.0",
|
|
4
4
|
"description": "In-memory storage adapter for Dismissible",
|
|
5
5
|
"main": "./src/index.js",
|
|
6
6
|
"types": "./src/index.d.ts",
|
|
@@ -11,20 +11,20 @@
|
|
|
11
11
|
"types": "./src/index.d.ts"
|
|
12
12
|
}
|
|
13
13
|
},
|
|
14
|
+
"files": [
|
|
15
|
+
"src",
|
|
16
|
+
"README.md"
|
|
17
|
+
],
|
|
18
|
+
"dependencies": {
|
|
19
|
+
"@dismissible/nestjs-logger": "0.0.2-canary.a611bd3.0",
|
|
20
|
+
"@dismissible/nestjs-dismissible-item": "0.0.2-canary.a611bd3.0"
|
|
21
|
+
},
|
|
14
22
|
"peerDependencies": {
|
|
15
|
-
"@nestjs/common": "^11.0.0"
|
|
16
|
-
"@dismissible/nestjs-logger": "^0.0.2-canary.8976e84.0",
|
|
17
|
-
"@dismissible/nestjs-dismissible-item": "^0.0.2-canary.8976e84.0"
|
|
23
|
+
"@nestjs/common": "10.0.0 || ^11.0.0"
|
|
18
24
|
},
|
|
19
25
|
"peerDependenciesMeta": {
|
|
20
26
|
"@nestjs/common": {
|
|
21
27
|
"optional": false
|
|
22
|
-
},
|
|
23
|
-
"@dismissible/nestjs-logger": {
|
|
24
|
-
"optional": false
|
|
25
|
-
},
|
|
26
|
-
"@dismissible/nestjs-dismissible-item": {
|
|
27
|
-
"optional": false
|
|
28
28
|
}
|
|
29
29
|
},
|
|
30
30
|
"keywords": [
|
|
@@ -42,5 +42,6 @@
|
|
|
42
42
|
},
|
|
43
43
|
"publishConfig": {
|
|
44
44
|
"access": "public"
|
|
45
|
-
}
|
|
45
|
+
},
|
|
46
|
+
"type": "commonjs"
|
|
46
47
|
}
|
package/src/index.js
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const tslib_1 = require("tslib");
|
|
4
|
+
tslib_1.__exportStar(require("./memory-storage.adapter"), exports);
|
|
5
|
+
tslib_1.__exportStar(require("./storage.interface"), exports);
|
|
6
|
+
tslib_1.__exportStar(require("./storage.module"), exports);
|
|
7
|
+
//# sourceMappingURL=index.js.map
|
package/src/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../libs/storage/src/index.ts"],"names":[],"mappings":";;;AAAA,mEAAyC;AACzC,8DAAoC;AACpC,2DAAiC"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { IDismissibleLogger } from '@dismissible/nestjs-logger';
|
|
2
|
+
import { IDismissibleStorage } from './storage.interface';
|
|
3
|
+
import { DismissibleItemDto } from '@dismissible/nestjs-dismissible-item';
|
|
4
|
+
/**
|
|
5
|
+
* In-memory storage provider for dismissible items.
|
|
6
|
+
* Suitable for development and testing; not for production use.
|
|
7
|
+
*/
|
|
8
|
+
export declare class MemoryStorageAdapter implements IDismissibleStorage {
|
|
9
|
+
private readonly logger;
|
|
10
|
+
private readonly storage;
|
|
11
|
+
constructor(logger: IDismissibleLogger);
|
|
12
|
+
/**
|
|
13
|
+
* Create a storage key from userId and itemId.
|
|
14
|
+
*/
|
|
15
|
+
private createKey;
|
|
16
|
+
get(userId: string, itemId: string): Promise<DismissibleItemDto | null>;
|
|
17
|
+
create(item: DismissibleItemDto): Promise<DismissibleItemDto>;
|
|
18
|
+
update(item: DismissibleItemDto): Promise<DismissibleItemDto>;
|
|
19
|
+
/**
|
|
20
|
+
* Clear all stored items.
|
|
21
|
+
* Useful for testing.
|
|
22
|
+
*/
|
|
23
|
+
clear(): void;
|
|
24
|
+
/**
|
|
25
|
+
* Get the number of stored items.
|
|
26
|
+
* Useful for testing/debugging.
|
|
27
|
+
*/
|
|
28
|
+
get size(): number;
|
|
29
|
+
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MemoryStorageAdapter = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const common_1 = require("@nestjs/common");
|
|
6
|
+
const nestjs_logger_1 = require("@dismissible/nestjs-logger");
|
|
7
|
+
/**
|
|
8
|
+
* In-memory storage provider for dismissible items.
|
|
9
|
+
* Suitable for development and testing; not for production use.
|
|
10
|
+
*/
|
|
11
|
+
let MemoryStorageAdapter = class MemoryStorageAdapter {
|
|
12
|
+
constructor(logger) {
|
|
13
|
+
this.logger = logger;
|
|
14
|
+
this.storage = new Map();
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Create a storage key from userId and itemId.
|
|
18
|
+
*/
|
|
19
|
+
createKey(userId, itemId) {
|
|
20
|
+
return `${userId}:${itemId}`;
|
|
21
|
+
}
|
|
22
|
+
async get(userId, itemId) {
|
|
23
|
+
const key = this.createKey(userId, itemId);
|
|
24
|
+
this.logger.debug(`Storage get`, { userId, itemId, key });
|
|
25
|
+
const item = this.storage.get(key);
|
|
26
|
+
if (!item) {
|
|
27
|
+
this.logger.debug(`Storage miss`, { userId, itemId });
|
|
28
|
+
return null;
|
|
29
|
+
}
|
|
30
|
+
this.logger.debug(`Storage hit`, { userId, itemId });
|
|
31
|
+
return item;
|
|
32
|
+
}
|
|
33
|
+
async create(item) {
|
|
34
|
+
const key = this.createKey(item.userId, item.id);
|
|
35
|
+
this.logger.debug(`Storage create`, { userId: item.userId, itemId: item.id, key });
|
|
36
|
+
this.storage.set(key, item);
|
|
37
|
+
return item;
|
|
38
|
+
}
|
|
39
|
+
async update(item) {
|
|
40
|
+
const key = this.createKey(item.userId, item.id);
|
|
41
|
+
this.logger.debug(`Storage update`, { userId: item.userId, itemId: item.id, key });
|
|
42
|
+
this.storage.set(key, item);
|
|
43
|
+
return item;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Clear all stored items.
|
|
47
|
+
* Useful for testing.
|
|
48
|
+
*/
|
|
49
|
+
clear() {
|
|
50
|
+
this.logger.debug(`Storage clear`, { previousSize: this.storage.size });
|
|
51
|
+
this.storage.clear();
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Get the number of stored items.
|
|
55
|
+
* Useful for testing/debugging.
|
|
56
|
+
*/
|
|
57
|
+
get size() {
|
|
58
|
+
return this.storage.size;
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
exports.MemoryStorageAdapter = MemoryStorageAdapter;
|
|
62
|
+
exports.MemoryStorageAdapter = MemoryStorageAdapter = tslib_1.__decorate([
|
|
63
|
+
(0, common_1.Injectable)(),
|
|
64
|
+
tslib_1.__param(0, (0, common_1.Inject)(nestjs_logger_1.DISMISSIBLE_LOGGER)),
|
|
65
|
+
tslib_1.__metadata("design:paramtypes", [Object])
|
|
66
|
+
], MemoryStorageAdapter);
|
|
67
|
+
//# sourceMappingURL=memory-storage.adapter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"memory-storage.adapter.js","sourceRoot":"","sources":["../../../../libs/storage/src/memory-storage.adapter.ts"],"names":[],"mappings":";;;;AAAA,2CAAoD;AACpD,8DAAoF;AAIpF;;;GAGG;AAEI,IAAM,oBAAoB,GAA1B,MAAM,oBAAoB;IAG/B,YAAwC,MAA2C;QAA1B,WAAM,GAAN,MAAM,CAAoB;QAFlE,YAAO,GAAG,IAAI,GAAG,EAA8B,CAAC;IAEqB,CAAC;IAEvF;;OAEG;IACK,SAAS,CAAC,MAAc,EAAE,MAAc;QAC9C,OAAO,GAAG,MAAM,IAAI,MAAM,EAAE,CAAC;IAC/B,CAAC;IAED,KAAK,CAAC,GAAG,CAAC,MAAc,EAAE,MAAc;QACtC,MAAM,GAAG,GAAG,IAAI,CAAC,SAAS,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;QAC3C,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,aAAa,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE,GAAG,EAAE,CAAC,CAAC;QAE1D,MAAM,IAAI,GAAG,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;QAEnC,IAAI,CAAC,IAAI,EAAE,CAAC;YACV,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,cAAc,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC,CAAC;YACtD,OAAO,IAAI,CAAC;QACd,CAAC;QAED,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,aAAa,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC,CAAC;QACrD,OAAO,IAAI,CAAC;IACd,CAAC;IAED,KAAK,CAAC,MAAM,CAAC,IAAwB;QACnC,MAAM,GAAG,GAAG,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,EAAE,CAAC,CAAC;QACjD,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,gBAAgB,EAAE,EAAE,MAAM,EAAE,IAAI,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,EAAE,GAAG,EAAE,CAAC,CAAC;QACnF,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC;QAC5B,OAAO,IAAI,CAAC;IACd,CAAC;IAED,KAAK,CAAC,MAAM,CAAC,IAAwB;QACnC,MAAM,GAAG,GAAG,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,EAAE,CAAC,CAAC;QACjD,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,gBAAgB,EAAE,EAAE,MAAM,EAAE,IAAI,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,EAAE,GAAG,EAAE,CAAC,CAAC;QACnF,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC;QAC5B,OAAO,IAAI,CAAC;IACd,CAAC;IAED;;;OAGG;IACH,KAAK;QACH,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,eAAe,EAAE,EAAE,YAAY,EAAE,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE,CAAC,CAAC;QACxE,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,CAAC;IACvB,CAAC;IAED;;;OAGG;IACH,IAAI,IAAI;QACN,OAAO,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC;IAC3B,CAAC;CACF,CAAA;AAzDY,oDAAoB;+BAApB,oBAAoB;IADhC,IAAA,mBAAU,GAAE;IAIE,mBAAA,IAAA,eAAM,EAAC,kCAAkB,CAAC,CAAA;;GAH5B,oBAAoB,CAyDhC"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { DismissibleItemDto } from '@dismissible/nestjs-dismissible-item';
|
|
2
|
+
/**
|
|
3
|
+
* Injection token for the storage provider.
|
|
4
|
+
*/
|
|
5
|
+
export declare const DISMISSIBLE_STORAGE_ADAPTER: unique symbol;
|
|
6
|
+
/**
|
|
7
|
+
* Interface for storage providers.
|
|
8
|
+
* Implementations handle the persistence of dismissible items.
|
|
9
|
+
*/
|
|
10
|
+
export interface IDismissibleStorage {
|
|
11
|
+
/**
|
|
12
|
+
* Retrieve an item by user ID and item ID.
|
|
13
|
+
* @param userId The user identifier
|
|
14
|
+
* @param itemId The item identifier
|
|
15
|
+
* @returns The item or null if not found
|
|
16
|
+
*/
|
|
17
|
+
get(userId: string, itemId: string): Promise<DismissibleItemDto | null>;
|
|
18
|
+
/**
|
|
19
|
+
* Create a new item.
|
|
20
|
+
* @param item The item to create (contains userId and id)
|
|
21
|
+
* @returns The created item
|
|
22
|
+
*/
|
|
23
|
+
create(item: DismissibleItemDto): Promise<DismissibleItemDto>;
|
|
24
|
+
/**
|
|
25
|
+
* Update an existing item.
|
|
26
|
+
* @param item The item to update (contains userId and id)
|
|
27
|
+
* @returns The updated item
|
|
28
|
+
*/
|
|
29
|
+
update(item: DismissibleItemDto): Promise<DismissibleItemDto>;
|
|
30
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DISMISSIBLE_STORAGE_ADAPTER = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Injection token for the storage provider.
|
|
6
|
+
*/
|
|
7
|
+
exports.DISMISSIBLE_STORAGE_ADAPTER = Symbol('DISMISSIBLE_STORAGE_ADAPTER');
|
|
8
|
+
//# sourceMappingURL=storage.interface.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"storage.interface.js","sourceRoot":"","sources":["../../../../libs/storage/src/storage.interface.ts"],"names":[],"mappings":";;;AAEA;;GAEG;AACU,QAAA,2BAA2B,GAAG,MAAM,CAAC,6BAA6B,CAAC,CAAC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.StorageModule = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const common_1 = require("@nestjs/common");
|
|
6
|
+
const storage_interface_1 = require("./storage.interface");
|
|
7
|
+
const memory_storage_adapter_1 = require("./memory-storage.adapter");
|
|
8
|
+
let StorageModule = class StorageModule {
|
|
9
|
+
};
|
|
10
|
+
exports.StorageModule = StorageModule;
|
|
11
|
+
exports.StorageModule = StorageModule = tslib_1.__decorate([
|
|
12
|
+
(0, common_1.Module)({
|
|
13
|
+
providers: [
|
|
14
|
+
{
|
|
15
|
+
provide: storage_interface_1.DISMISSIBLE_STORAGE_ADAPTER,
|
|
16
|
+
useClass: memory_storage_adapter_1.MemoryStorageAdapter,
|
|
17
|
+
},
|
|
18
|
+
],
|
|
19
|
+
exports: [storage_interface_1.DISMISSIBLE_STORAGE_ADAPTER],
|
|
20
|
+
})
|
|
21
|
+
], StorageModule);
|
|
22
|
+
//# sourceMappingURL=storage.module.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"storage.module.js","sourceRoot":"","sources":["../../../../libs/storage/src/storage.module.ts"],"names":[],"mappings":";;;;AAAA,2CAA6D;AAC7D,2DAAkE;AAClE,qEAAgE;AAezD,IAAM,aAAa,GAAnB,MAAM,aAAa;CAAG,CAAA;AAAhB,sCAAa;wBAAb,aAAa;IATzB,IAAA,eAAM,EAAC;QACN,SAAS,EAAE;YACT;gBACE,OAAO,EAAE,+CAA2B;gBACpC,QAAQ,EAAE,6CAAoB;aAC/B;SACF;QACD,OAAO,EAAE,CAAC,+CAA2B,CAAC;KACvC,CAAC;GACW,aAAa,CAAG"}
|
package/jest.config.ts
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
export default {
|
|
2
|
-
displayName: 'storage',
|
|
3
|
-
preset: '../../jest.preset.js',
|
|
4
|
-
testEnvironment: 'node',
|
|
5
|
-
transform: {
|
|
6
|
-
'^.+\\.[tj]s$': ['ts-jest', { tsconfig: '<rootDir>/tsconfig.json' }],
|
|
7
|
-
},
|
|
8
|
-
moduleFileExtensions: ['ts', 'js', 'html'],
|
|
9
|
-
coverageDirectory: '../../coverage/libs/storage',
|
|
10
|
-
};
|
package/project.json
DELETED
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "storage",
|
|
3
|
-
"$schema": "../../node_modules/nx/schemas/project-schema.json",
|
|
4
|
-
"sourceRoot": "libs/storage/src",
|
|
5
|
-
"projectType": "library",
|
|
6
|
-
"tags": [],
|
|
7
|
-
"targets": {
|
|
8
|
-
"build": {
|
|
9
|
-
"executor": "@nx/js:tsc",
|
|
10
|
-
"outputs": ["{options.outputPath}"],
|
|
11
|
-
"options": {
|
|
12
|
-
"outputPath": "dist/libs/storage",
|
|
13
|
-
"main": "libs/storage/src/index.ts",
|
|
14
|
-
"tsConfig": "libs/storage/tsconfig.lib.json",
|
|
15
|
-
"assets": ["libs/storage/package.json", "libs/storage/README.md"],
|
|
16
|
-
"generatePackageJson": true
|
|
17
|
-
}
|
|
18
|
-
},
|
|
19
|
-
"lint": {
|
|
20
|
-
"executor": "@nx/eslint:lint",
|
|
21
|
-
"outputs": ["{options.outputFile}"],
|
|
22
|
-
"options": {
|
|
23
|
-
"lintFilePatterns": ["libs/storage/**/*.ts"]
|
|
24
|
-
}
|
|
25
|
-
},
|
|
26
|
-
"test": {
|
|
27
|
-
"executor": "@nx/jest:jest",
|
|
28
|
-
"outputs": ["{workspaceRoot}/coverage/libs/storage"],
|
|
29
|
-
"options": {
|
|
30
|
-
"jestConfig": "libs/storage/jest.config.ts",
|
|
31
|
-
"passWithNoTests": true
|
|
32
|
-
}
|
|
33
|
-
},
|
|
34
|
-
"npm-publish": {
|
|
35
|
-
"executor": "nx:run-commands",
|
|
36
|
-
"options": {
|
|
37
|
-
"command": "npm publish --access public",
|
|
38
|
-
"cwd": "dist/libs/storage"
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
}
|
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
import { Injectable, Inject } from '@nestjs/common';
|
|
2
|
-
import { DISMISSIBLE_LOGGER, IDismissibleLogger } from '@dismissible/nestjs-logger';
|
|
3
|
-
import { IDismissibleStorage } from './storage.interface';
|
|
4
|
-
import { BaseMetadata, DismissibleItemDto } from '@dismissible/nestjs-dismissible-item';
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* In-memory storage provider for dismissible items.
|
|
8
|
-
* Suitable for development and testing; not for production use.
|
|
9
|
-
*/
|
|
10
|
-
@Injectable()
|
|
11
|
-
export class MemoryStorageAdapter<
|
|
12
|
-
TMetadata extends BaseMetadata = BaseMetadata,
|
|
13
|
-
> implements IDismissibleStorage<TMetadata> {
|
|
14
|
-
private readonly storage = new Map<string, DismissibleItemDto<TMetadata>>();
|
|
15
|
-
|
|
16
|
-
constructor(@Inject(DISMISSIBLE_LOGGER) private readonly logger: IDismissibleLogger) {}
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* Create a storage key from userId and itemId.
|
|
20
|
-
*/
|
|
21
|
-
private createKey(userId: string, itemId: string): string {
|
|
22
|
-
return `${userId}:${itemId}`;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
async get(userId: string, itemId: string): Promise<DismissibleItemDto<TMetadata> | null> {
|
|
26
|
-
const key = this.createKey(userId, itemId);
|
|
27
|
-
this.logger.debug(`Storage get`, { userId, itemId, key });
|
|
28
|
-
|
|
29
|
-
const item = this.storage.get(key);
|
|
30
|
-
|
|
31
|
-
if (!item) {
|
|
32
|
-
this.logger.debug(`Storage miss`, { userId, itemId });
|
|
33
|
-
return null;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
this.logger.debug(`Storage hit`, { userId, itemId });
|
|
37
|
-
return item;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
async create(item: DismissibleItemDto<TMetadata>): Promise<DismissibleItemDto<TMetadata>> {
|
|
41
|
-
const key = this.createKey(item.userId, item.id);
|
|
42
|
-
this.logger.debug(`Storage create`, { userId: item.userId, itemId: item.id, key });
|
|
43
|
-
this.storage.set(key, item);
|
|
44
|
-
return item;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
async update(item: DismissibleItemDto<TMetadata>): Promise<DismissibleItemDto<TMetadata>> {
|
|
48
|
-
const key = this.createKey(item.userId, item.id);
|
|
49
|
-
this.logger.debug(`Storage update`, { userId: item.userId, itemId: item.id, key });
|
|
50
|
-
this.storage.set(key, item);
|
|
51
|
-
return item;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
/**
|
|
55
|
-
* Clear all stored items.
|
|
56
|
-
* Useful for testing.
|
|
57
|
-
*/
|
|
58
|
-
clear(): void {
|
|
59
|
-
this.logger.debug(`Storage clear`, { previousSize: this.storage.size });
|
|
60
|
-
this.storage.clear();
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
/**
|
|
64
|
-
* Get the number of stored items.
|
|
65
|
-
* Useful for testing/debugging.
|
|
66
|
-
*/
|
|
67
|
-
get size(): number {
|
|
68
|
-
return this.storage.size;
|
|
69
|
-
}
|
|
70
|
-
}
|
package/src/storage.interface.ts
DELETED
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import { BaseMetadata, DismissibleItemDto } from '@dismissible/nestjs-dismissible-item';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Injection token for the storage provider.
|
|
5
|
-
*/
|
|
6
|
-
export const DISMISSIBLE_STORAGE_ADAPTER = Symbol('DISMISSIBLE_STORAGE_ADAPTER');
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* Interface for storage providers.
|
|
10
|
-
* Implementations handle the persistence of dismissible items.
|
|
11
|
-
*/
|
|
12
|
-
export interface IDismissibleStorage<TMetadata extends BaseMetadata = BaseMetadata> {
|
|
13
|
-
/**
|
|
14
|
-
* Retrieve an item by user ID and item ID.
|
|
15
|
-
* @param userId The user identifier
|
|
16
|
-
* @param itemId The item identifier
|
|
17
|
-
* @returns The item or null if not found
|
|
18
|
-
*/
|
|
19
|
-
get(userId: string, itemId: string): Promise<DismissibleItemDto<TMetadata> | null>;
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* Create a new item.
|
|
23
|
-
* @param item The item to create (contains userId and id)
|
|
24
|
-
* @returns The created item
|
|
25
|
-
*/
|
|
26
|
-
create(item: DismissibleItemDto<TMetadata>): Promise<DismissibleItemDto<TMetadata>>;
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
* Update an existing item.
|
|
30
|
-
* @param item The item to update (contains userId and id)
|
|
31
|
-
* @returns The updated item
|
|
32
|
-
*/
|
|
33
|
-
update(item: DismissibleItemDto<TMetadata>): Promise<DismissibleItemDto<TMetadata>>;
|
|
34
|
-
}
|
package/src/storage.module.ts
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { DynamicModule, Module, Type } from '@nestjs/common';
|
|
2
|
-
import { DISMISSIBLE_STORAGE_ADAPTER } from './storage.interface';
|
|
3
|
-
import { MemoryStorageAdapter } from './memory-storage.adapter';
|
|
4
|
-
|
|
5
|
-
export type IDismissibleStorageModuleOptions = {
|
|
6
|
-
storage?: Type<any> | DynamicModule;
|
|
7
|
-
};
|
|
8
|
-
|
|
9
|
-
@Module({
|
|
10
|
-
providers: [
|
|
11
|
-
{
|
|
12
|
-
provide: DISMISSIBLE_STORAGE_ADAPTER,
|
|
13
|
-
useClass: MemoryStorageAdapter,
|
|
14
|
-
},
|
|
15
|
-
],
|
|
16
|
-
exports: [DISMISSIBLE_STORAGE_ADAPTER],
|
|
17
|
-
})
|
|
18
|
-
export class StorageModule {}
|
package/tsconfig.json
DELETED
package/tsconfig.lib.json
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"extends": "./tsconfig.json",
|
|
3
|
-
"compilerOptions": {
|
|
4
|
-
"outDir": "../../dist/out-tsc",
|
|
5
|
-
"declaration": true,
|
|
6
|
-
"module": "commonjs",
|
|
7
|
-
"types": ["node"],
|
|
8
|
-
"emitDecoratorMetadata": true,
|
|
9
|
-
"experimentalDecorators": true,
|
|
10
|
-
"target": "ES2021"
|
|
11
|
-
},
|
|
12
|
-
"exclude": ["node_modules", "**/*.spec.ts", "**/*.test.ts"],
|
|
13
|
-
"include": ["src/**/*.ts"]
|
|
14
|
-
}
|
|
File without changes
|