@ddd-ts/store-inmemory 0.0.3-25 → 0.0.3-26
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.
|
@@ -1,22 +1,22 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Store, Model } from "@ddd-ts/model";
|
|
2
2
|
import { InMemoryDatabase, InMemoryTransactionId } from "./in-memory.database";
|
|
3
3
|
import { InMemoryTransaction } from "../in-memory.transaction";
|
|
4
|
+
import { ISerializer } from "@ddd-ts/serialization";
|
|
4
5
|
/**
|
|
5
6
|
* This in memory store is a copy store. It stores a copy of the actual model.
|
|
6
7
|
* It is the recommended inmemory store to use, as it reflects more closely the behaviour of a real store.
|
|
7
8
|
*/
|
|
8
|
-
export declare class InMemoryStore<Model
|
|
9
|
-
toString(): string;
|
|
10
|
-
}> implements Store<Model, Id> {
|
|
9
|
+
export declare class InMemoryStore<M extends Model> implements Store<M> {
|
|
11
10
|
readonly collection: string;
|
|
12
11
|
readonly database: InMemoryDatabase;
|
|
13
|
-
readonly serializer:
|
|
14
|
-
constructor(collection: string, database: InMemoryDatabase, serializer:
|
|
15
|
-
|
|
12
|
+
readonly serializer: ISerializer<M>;
|
|
13
|
+
constructor(collection: string, database: InMemoryDatabase, serializer: ISerializer<M>);
|
|
14
|
+
private getIdFromModel;
|
|
15
|
+
protected filter(predicate: (model: M) => boolean, trx?: InMemoryTransactionId): Promise<M[]>;
|
|
16
16
|
clear(): void;
|
|
17
|
-
save(model:
|
|
18
|
-
load(id:
|
|
19
|
-
loadAll(): Promise<
|
|
20
|
-
delete(id:
|
|
17
|
+
save(model: M, trx?: InMemoryTransaction): Promise<void>;
|
|
18
|
+
load(id: M['id'], trx?: InMemoryTransaction): Promise<M | undefined>;
|
|
19
|
+
loadAll(): Promise<M[]>;
|
|
20
|
+
delete(id: M['id']): Promise<void>;
|
|
21
21
|
}
|
|
22
22
|
//# sourceMappingURL=in-memory.store.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"in-memory.store.d.ts","sourceRoot":"","sources":["../../src/store/in-memory.store.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"in-memory.store.d.ts","sourceRoot":"","sources":["../../src/store/in-memory.store.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AAC7C,OAAO,EAAE,gBAAgB,EAAE,qBAAqB,EAAE,MAAM,sBAAsB,CAAC;AAC/E,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAC/D,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AACpD;;;GAGG;AACH,qBAAa,aAAa,CAAC,CAAC,SAAS,KAAK,CACxC,YAAW,KAAK,CAAC,CAAC,CAAC;aAGD,UAAU,EAAE,MAAM;aAClB,QAAQ,EAAE,gBAAgB;aAC1B,UAAU,EAAE,WAAW,CAAC,CAAC,CAAC;gBAF1B,UAAU,EAAE,MAAM,EAClB,QAAQ,EAAE,gBAAgB,EAC1B,UAAU,EAAE,WAAW,CAAC,CAAC,CAAC;IAG5C,OAAO,CAAC,cAAc;cASN,MAAM,CACpB,SAAS,EAAE,CAAC,KAAK,EAAE,CAAC,KAAK,OAAO,EAChC,GAAG,CAAC,EAAE,qBAAqB,GAC1B,OAAO,CAAC,CAAC,EAAE,CAAC;IAUf,KAAK;IAIC,IAAI,CAAC,KAAK,EAAE,CAAC,EAAE,GAAG,CAAC,EAAE,mBAAmB,GAAG,OAAO,CAAC,IAAI,CAAC;IASxD,IAAI,CAAC,EAAE,EAAE,CAAC,CAAC,IAAI,CAAC,EAAE,GAAG,CAAC,EAAE,mBAAmB,GAAG,OAAO,CAAC,CAAC,GAAG,SAAS,CAAC;IAc1E,OAAO,IAAI,OAAO,CAAC,CAAC,EAAE,CAAC;IAMjB,MAAM,CAAC,EAAE,EAAE,CAAC,CAAC,IAAI,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC;CAGzC"}
|
|
@@ -14,6 +14,14 @@ class InMemoryStore {
|
|
|
14
14
|
this.database = database;
|
|
15
15
|
this.serializer = serializer;
|
|
16
16
|
}
|
|
17
|
+
getIdFromModel(m) {
|
|
18
|
+
if (Object.getOwnPropertyNames(m.id).includes('serialize')) {
|
|
19
|
+
if ('serialize' in m.id) {
|
|
20
|
+
return m.id.serialize();
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
return m.id.toString();
|
|
24
|
+
}
|
|
17
25
|
async filter(predicate, trx) {
|
|
18
26
|
const serialized = await this.database.loadAll(this.collection, trx);
|
|
19
27
|
const all = await Promise.all(serialized.map((s) => this.serializer.deserialize(s)));
|
|
@@ -23,7 +31,7 @@ class InMemoryStore {
|
|
|
23
31
|
this.database.clear(this.collection);
|
|
24
32
|
}
|
|
25
33
|
async save(model, trx) {
|
|
26
|
-
await this.database.save(this.collection, this.
|
|
34
|
+
await this.database.save(this.collection, this.getIdFromModel(model), await this.serializer.serialize(model), trx?.transaction);
|
|
27
35
|
}
|
|
28
36
|
async load(id, trx) {
|
|
29
37
|
const serialized = await this.database.load(this.collection, id.toString(), trx?.transaction);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"in-memory.store.js","sourceRoot":"","sources":["../../src/store/in-memory.store.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"in-memory.store.js","sourceRoot":"","sources":["../../src/store/in-memory.store.ts"],"names":[],"mappings":";;;AAIA;;;GAGG;AACH,MAAa,aAAa;IAIN;IACA;IACA;IAHlB,YACkB,UAAkB,EAClB,QAA0B,EAC1B,UAA0B;QAF1B,eAAU,GAAV,UAAU,CAAQ;QAClB,aAAQ,GAAR,QAAQ,CAAkB;QAC1B,eAAU,GAAV,UAAU,CAAgB;IACxC,CAAC;IAEG,cAAc,CAAC,CAAQ;QAC7B,IAAI,MAAM,CAAC,mBAAmB,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC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;SAClB;QAED,OAAO,IAAI,CAAC,UAAU,CAAC,WAAW,CAAC,UAAU,CAAC,CAAC;IACjD,CAAC;IAED,OAAO;QACL,MAAM,UAAU,GAAG,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;QAE1D,OAAO,OAAO,CAAC,GAAG,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,UAAU,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;IAC5E,CAAC;IAED,KAAK,CAAC,MAAM,CAAC,EAAW;QACtB,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,IAAI,CAAC,UAAU,EAAE,EAAE,CAAC,QAAQ,EAAE,CAAC,CAAC;IACvD,CAAC;CACF;AAnED,sCAmEC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ddd-ts/store-inmemory",
|
|
3
|
-
"version": "0.0.3-
|
|
3
|
+
"version": "0.0.3-26",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"types": "dist/index.d.ts",
|
|
6
6
|
"license": "MIT",
|
|
@@ -8,7 +8,8 @@
|
|
|
8
8
|
"build": "builder"
|
|
9
9
|
},
|
|
10
10
|
"peerDependencies": {
|
|
11
|
-
"@ddd-ts/model": "*"
|
|
11
|
+
"@ddd-ts/model": "*",
|
|
12
|
+
"@ddd-ts/serialization": "*"
|
|
12
13
|
},
|
|
13
14
|
"devDependencies": {
|
|
14
15
|
"@ddd-ts/dev": "*",
|