@ddd-ts/store-inmemory 0.0.3-49 → 0.0.3-50
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/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -1
- package/dist/index.js.map +1 -1
- package/package.json +16 -18
- package/dist/store/in-memory.store.spec.d.ts +0 -2
- package/dist/store/in-memory.store.spec.d.ts.map +0 -1
- package/dist/store/in-memory.store.spec.js +0 -94
- package/dist/store/in-memory.store.spec.js.map +0 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
export { InMemoryTransactionPerformer, FakeInMemoryTransactionPerformer, InMemoryTransaction, } from "./in-memory.transaction";
|
|
2
|
-
export { InMemoryDatabase, InMemoryUnderlyingTransaction, } from "./store/in-memory.database";
|
|
2
|
+
export { InMemoryDatabase, InMemoryUnderlyingTransaction, CannotReadAfterWrites, TransactionCollidedTooManyTimes, } from "./store/in-memory.database";
|
|
3
3
|
export { InMemoryStore } from "./store/in-memory.store";
|
|
4
4
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,4BAA4B,EAC5B,gCAAgC,EAChC,mBAAmB,GACnB,MAAM,yBAAyB,CAAC;AACjC,OAAO,EACN,gBAAgB,EAChB,6BAA6B,EAC7B,qBAAqB,EACrB,+BAA+B,GAC/B,MAAM,4BAA4B,CAAC;AACpC,OAAO,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.InMemoryStore = exports.InMemoryUnderlyingTransaction = exports.InMemoryDatabase = exports.InMemoryTransaction = exports.FakeInMemoryTransactionPerformer = exports.InMemoryTransactionPerformer = void 0;
|
|
3
|
+
exports.InMemoryStore = exports.TransactionCollidedTooManyTimes = exports.CannotReadAfterWrites = exports.InMemoryUnderlyingTransaction = exports.InMemoryDatabase = exports.InMemoryTransaction = exports.FakeInMemoryTransactionPerformer = exports.InMemoryTransactionPerformer = void 0;
|
|
4
4
|
var in_memory_transaction_1 = require("./in-memory.transaction");
|
|
5
5
|
Object.defineProperty(exports, "InMemoryTransactionPerformer", { enumerable: true, get: function () { return in_memory_transaction_1.InMemoryTransactionPerformer; } });
|
|
6
6
|
Object.defineProperty(exports, "FakeInMemoryTransactionPerformer", { enumerable: true, get: function () { return in_memory_transaction_1.FakeInMemoryTransactionPerformer; } });
|
|
@@ -8,6 +8,8 @@ Object.defineProperty(exports, "InMemoryTransaction", { enumerable: true, get: f
|
|
|
8
8
|
var in_memory_database_1 = require("./store/in-memory.database");
|
|
9
9
|
Object.defineProperty(exports, "InMemoryDatabase", { enumerable: true, get: function () { return in_memory_database_1.InMemoryDatabase; } });
|
|
10
10
|
Object.defineProperty(exports, "InMemoryUnderlyingTransaction", { enumerable: true, get: function () { return in_memory_database_1.InMemoryUnderlyingTransaction; } });
|
|
11
|
+
Object.defineProperty(exports, "CannotReadAfterWrites", { enumerable: true, get: function () { return in_memory_database_1.CannotReadAfterWrites; } });
|
|
12
|
+
Object.defineProperty(exports, "TransactionCollidedTooManyTimes", { enumerable: true, get: function () { return in_memory_database_1.TransactionCollidedTooManyTimes; } });
|
|
11
13
|
var in_memory_store_1 = require("./store/in-memory.store");
|
|
12
14
|
Object.defineProperty(exports, "InMemoryStore", { enumerable: true, get: function () { return in_memory_store_1.InMemoryStore; } });
|
|
13
15
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,iEAIiC;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,iEAIiC;AAHhC,qIAAA,4BAA4B,OAAA;AAC5B,yIAAA,gCAAgC,OAAA;AAChC,4HAAA,mBAAmB,OAAA;AAEpB,iEAKoC;AAJnC,sHAAA,gBAAgB,OAAA;AAChB,mIAAA,6BAA6B,OAAA;AAC7B,2HAAA,qBAAqB,OAAA;AACrB,qIAAA,+BAA+B,OAAA;AAEhC,2DAAwD;AAA/C,gHAAA,aAAa,OAAA"}
|
package/package.json
CHANGED
|
@@ -1,20 +1,18 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
"@ddd-ts/types": "*"
|
|
19
|
-
}
|
|
2
|
+
"name": "@ddd-ts/store-inmemory",
|
|
3
|
+
"version": "0.0.3-50",
|
|
4
|
+
"main": "dist/index.js",
|
|
5
|
+
"types": "dist/index.d.ts",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"scripts": {
|
|
8
|
+
"build": "builder"
|
|
9
|
+
},
|
|
10
|
+
"dependencies": {
|
|
11
|
+
"@ddd-ts/model": "*",
|
|
12
|
+
"@ddd-ts/serialization": "*"
|
|
13
|
+
},
|
|
14
|
+
"devDependencies": {
|
|
15
|
+
"@ddd-ts/dev": "*",
|
|
16
|
+
"@ddd-ts/types": "*"
|
|
17
|
+
}
|
|
20
18
|
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"in-memory.store.spec.d.ts","sourceRoot":"","sources":["../../src/store/in-memory.store.spec.ts"],"names":[],"mappings":""}
|
|
@@ -1,94 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const tests_1 = require("@ddd-ts/tests");
|
|
4
|
-
const __1 = require("..");
|
|
5
|
-
const in_memory_database_1 = require("./in-memory.database");
|
|
6
|
-
class MyElementStore extends __1.InMemoryStore {
|
|
7
|
-
constructor(database) {
|
|
8
|
-
super("my_collection", database, new tests_1.MyElementSerializer());
|
|
9
|
-
}
|
|
10
|
-
loadEven() {
|
|
11
|
-
return this.filter((e) => e.even);
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
describe("InMemoryStore", () => {
|
|
15
|
-
function getStore() {
|
|
16
|
-
const database = new __1.InMemoryDatabase();
|
|
17
|
-
return {
|
|
18
|
-
store: new MyElementStore(database),
|
|
19
|
-
transactionPerformer: new __1.InMemoryTransactionPerformer(database),
|
|
20
|
-
};
|
|
21
|
-
}
|
|
22
|
-
(0, tests_1.StoreSuite)(getStore);
|
|
23
|
-
it("fails transactionally read after write", async () => {
|
|
24
|
-
const { store, transactionPerformer } = getStore();
|
|
25
|
-
await expect(transactionPerformer.perform(async (transaction) => {
|
|
26
|
-
const element = new tests_1.MyElement("myid", "timothee", false);
|
|
27
|
-
await store.save(element, transaction);
|
|
28
|
-
await store.load(element.id, transaction);
|
|
29
|
-
})).rejects.toThrow(in_memory_database_1.CannotReadAfterWrites);
|
|
30
|
-
});
|
|
31
|
-
it("fails transactionally trying 5 times to write", async () => {
|
|
32
|
-
let uniqueId = 0;
|
|
33
|
-
const { store, transactionPerformer } = getStore();
|
|
34
|
-
const element = new tests_1.MyElement("myid", "timothee", false);
|
|
35
|
-
await store.save(element);
|
|
36
|
-
let effectCalled = 0;
|
|
37
|
-
await expect(transactionPerformer.perform(async (transaction) => {
|
|
38
|
-
effectCalled += 1;
|
|
39
|
-
await store.load(element.id, transaction);
|
|
40
|
-
element.setName("elies");
|
|
41
|
-
uniqueId += 1;
|
|
42
|
-
await store.save(new tests_1.MyElement(element.id, uniqueId.toString(), false));
|
|
43
|
-
await store.save(element, transaction);
|
|
44
|
-
})).rejects.toThrow(in_memory_database_1.TransactionCollidedTooManyTimes);
|
|
45
|
-
expect(effectCalled).toBe(5);
|
|
46
|
-
});
|
|
47
|
-
it("transactionally writes after 1 fail", async () => {
|
|
48
|
-
let uniqueId = 0;
|
|
49
|
-
const { store, transactionPerformer } = getStore();
|
|
50
|
-
const element = new tests_1.MyElement("myid", "timothee", false);
|
|
51
|
-
await store.save(element);
|
|
52
|
-
let effectCalled = 0;
|
|
53
|
-
await transactionPerformer.perform(async (transaction) => {
|
|
54
|
-
effectCalled += 1;
|
|
55
|
-
const loadedElement = await store.load(element.id, transaction);
|
|
56
|
-
expect(loadedElement).toBeTruthy();
|
|
57
|
-
if (!loadedElement) {
|
|
58
|
-
return;
|
|
59
|
-
}
|
|
60
|
-
loadedElement.setName("elies");
|
|
61
|
-
if (uniqueId === 0) {
|
|
62
|
-
await store.save(new tests_1.MyElement(element.id, uniqueId.toString(), false));
|
|
63
|
-
uniqueId += 1;
|
|
64
|
-
}
|
|
65
|
-
await store.save(loadedElement, transaction);
|
|
66
|
-
});
|
|
67
|
-
expect(effectCalled).toBe(2);
|
|
68
|
-
});
|
|
69
|
-
it("transactionally writes after 1 fail and calls onCommit only once", async () => {
|
|
70
|
-
let uniqueId = 0;
|
|
71
|
-
const { store, transactionPerformer } = getStore();
|
|
72
|
-
const element = new tests_1.MyElement("myid", "timothee", false);
|
|
73
|
-
await store.save(element);
|
|
74
|
-
let onCommitCalled = 0;
|
|
75
|
-
await transactionPerformer.perform(async (transaction) => {
|
|
76
|
-
transaction.onCommit(() => {
|
|
77
|
-
onCommitCalled += 1;
|
|
78
|
-
});
|
|
79
|
-
const loadedElement = await store.load(element.id, transaction);
|
|
80
|
-
expect(loadedElement).toBeTruthy();
|
|
81
|
-
if (!loadedElement) {
|
|
82
|
-
return;
|
|
83
|
-
}
|
|
84
|
-
loadedElement.setName("elies");
|
|
85
|
-
if (uniqueId === 0) {
|
|
86
|
-
await store.save(new tests_1.MyElement(element.id, uniqueId.toString(), false));
|
|
87
|
-
uniqueId += 1;
|
|
88
|
-
}
|
|
89
|
-
await store.save(loadedElement, transaction);
|
|
90
|
-
});
|
|
91
|
-
expect(onCommitCalled).toBe(1);
|
|
92
|
-
});
|
|
93
|
-
});
|
|
94
|
-
//# sourceMappingURL=in-memory.store.spec.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"in-memory.store.spec.js","sourceRoot":"","sources":["../../src/store/in-memory.store.spec.ts"],"names":[],"mappings":";;AAAA,yCAA2E;AAC3E,0BAIY;AACZ,6DAG8B;AAE9B,MAAM,cAAe,SAAQ,iBAAwB;IACnD,YAAY,QAA0B;QACpC,KAAK,CAAC,eAAe,EAAE,QAAQ,EAAE,IAAI,2BAAmB,EAAE,CAAC,CAAC;IAC9D,CAAC;IAED,QAAQ;QACN,OAAO,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;IACpC,CAAC;CACF;AAED,QAAQ,CAAC,eAAe,EAAE,GAAG,EAAE;IAC7B,SAAS,QAAQ;QACf,MAAM,QAAQ,GAAG,IAAI,oBAAgB,EAAE,CAAC;QACxC,OAAO;YACL,KAAK,EAAE,IAAI,cAAc,CAAC,QAAQ,CAAC;YACnC,oBAAoB,EAAE,IAAI,gCAA4B,CAAC,QAAQ,CAAC;SACjE,CAAC;IACJ,CAAC;IAED,IAAA,kBAAU,EAAC,QAAQ,CAAC,CAAC;IAErB,EAAE,CAAC,wCAAwC,EAAE,KAAK,IAAI,EAAE;QACtD,MAAM,EAAE,KAAK,EAAE,oBAAoB,EAAE,GAAG,QAAQ,EAAE,CAAC;QAEnD,MAAM,MAAM,CACV,oBAAoB,CAAC,OAAO,CAAC,KAAK,EAAE,WAAW,EAAE,EAAE;YACjD,MAAM,OA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