@furystack/filesystem-store 2.0.32 → 3.0.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/dist/filesystem-store.js +1 -1
- package/dist/filesystem-store.js.map +1 -1
- package/dist/filesystem-store.spec.js +9 -9
- package/dist/filesystem-store.spec.js.map +1 -1
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/dist/store-manager-helpers.js +20 -0
- package/dist/store-manager-helpers.js.map +1 -0
- package/dist/{store-manager-extensions.spec.js → store-manager-helpers.spec.js} +8 -8
- package/dist/store-manager-helpers.spec.js.map +1 -0
- package/package.json +9 -10
- package/src/filesystem-store.spec.ts +6 -5
- package/src/index.ts +1 -1
- package/src/{store-manager-extensions.spec.ts → store-manager-helpers.spec.ts} +8 -7
- package/src/store-manager-helpers.ts +23 -0
- package/{dist → types}/filesystem-store.d.ts +0 -0
- package/{dist → types}/filesystem-store.d.ts.map +0 -0
- package/{dist → types}/filesystem-store.spec.d.ts +0 -0
- package/{dist → types}/filesystem-store.spec.d.ts.map +0 -0
- package/types/index.d.ts +3 -0
- package/{dist → types}/index.d.ts.map +1 -1
- package/types/store-manager-helpers.d.ts +18 -0
- package/types/store-manager-helpers.d.ts.map +1 -0
- package/types/store-manager-helpers.spec.d.ts +2 -0
- package/types/store-manager-helpers.spec.d.ts.map +1 -0
- package/dist/index.d.ts +0 -3
- package/dist/store-manager-extensions.d.ts +0 -25
- package/dist/store-manager-extensions.d.ts.map +0 -1
- package/dist/store-manager-extensions.js +0 -10
- package/dist/store-manager-extensions.js.map +0 -1
- package/dist/store-manager-extensions.spec.d.ts +0 -2
- package/dist/store-manager-extensions.spec.d.ts.map +0 -1
- package/dist/store-manager-extensions.spec.js.map +0 -1
- package/src/store-manager-extensions.ts +0 -33
package/dist/filesystem-store.js
CHANGED
|
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.FileSystemStore = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const fs_1 = require("fs");
|
|
6
|
-
const semaphore_async_await_1 =
|
|
6
|
+
const semaphore_async_await_1 = tslib_1.__importDefault(require("semaphore-async-await"));
|
|
7
7
|
const core_1 = require("@furystack/core");
|
|
8
8
|
/**
|
|
9
9
|
* Store implementation that stores info in a simple JSON file
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"filesystem-store.js","sourceRoot":"","sources":["../src/filesystem-store.ts"],"names":[],"mappings":";;;;AAAA,2BAA+C;AAE/C
|
|
1
|
+
{"version":3,"file":"filesystem-store.js","sourceRoot":"","sources":["../src/filesystem-store.ts"],"names":[],"mappings":";;;;AAAA,2BAA+C;AAE/C,0FAA6C;AAC7C,0CAAuG;AAEvG;;GAEG;AACH,MAAa,eAAe;IAqG1B,YACmB,OAKhB;QALgB,YAAO,GAAP,OAAO,CAKvB;QAvFI,SAAI,GAAG,WAAW,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,WAAW,EAAE,EAAE,IAAI,CAAC,OAAO,CAAC,MAAM,IAAI,IAAI,CAAC,CAAA;QACzE,eAAU,GAAG,KAAK,CAAA;QA2BjB,aAAQ,GAAG,IAAI,+BAAS,CAAC,CAAC,CAAC,CAAA;QAkD5B,aAAQ,GAAG,aAAQ,CAAC,QAAQ,CAAA;QAC5B,cAAS,GAAG,aAAQ,CAAC,SAAS,CAAA;QAUnC,IAAI,CAAC,UAAU,GAAG,OAAO,CAAC,UAAU,CAAA;QACpC,IAAI,CAAC,KAAK,GAAG,OAAO,CAAC,KAAK,CAAA;QAC1B,IAAI,CAAC,aAAa,GAAG,IAAI,oBAAa,CAAC,EAAE,KAAK,EAAE,IAAI,CAAC,KAAK,EAAE,UAAU,EAAE,IAAI,CAAC,UAAU,EAAE,CAAC,CAAA;QAE1F,IAAI;YACF,IAAI,CAAC,UAAU,EAAE,CAAA;YACjB,IAAI,CAAC,OAAO,GAAG,IAAA,UAAK,EAAC,IAA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,CAAC,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAA;YACvD,MAAM,IAAI,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,QAAQ,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE,CAAQ,CAAA;YAC7D,IAAI,CAAC,KAAK,CAAC,KAAK,EAAE,CAAA;YAClB,KAAK,MAAM,MAAM,IAAI,IAAI,EAAE;gBACzB,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,EAAE,MAAM,CAAC,CAAA;aAChD;SACF;QAAC,OAAO,GAAG,EAAE;YACZ,gCAAgC;YAChC,IAAI,GAAG,YAAY,KAAK,IAAK,GAAW,CAAC,IAAI,KAAK,QAAQ,EAAE;gBAC1D,MAAM,GAAG,CAAA;aACV;SACF;gBAAS;YACR,IAAI,CAAC,QAAQ,CAAC,OAAO,EAAE,CAAA;SACxB;IACH,CAAC;IAEM,KAAK,CAAC,MAAM,CAAC,EAAkB,EAAE,IAAO;QAC7C,MAAM,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,KAAK,IAAI,EAAE;YACrC,OAAO,IAAI,CAAC,aAAa,CAAC,MAAM,CAAC,EAAE,EAAE,IAAI,CAAC,CAAA;QAC5C,CAAC,CAAC,CAAA;QACF,IAAI,CAAC,UAAU,GAAG,IAAI,CAAA;IACxB,CAAC;CA0BF;AA1HD,0CA0HC"}
|
|
@@ -2,24 +2,24 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const fs_1 = require("fs");
|
|
4
4
|
const filesystem_store_1 = require("./filesystem-store");
|
|
5
|
-
const
|
|
6
|
-
const uuid_1 = require("uuid");
|
|
5
|
+
const core_1 = require("@furystack/core");
|
|
7
6
|
const utils_1 = require("@furystack/utils");
|
|
7
|
+
let storeCount = 0;
|
|
8
8
|
describe('FileSystemStore', () => {
|
|
9
9
|
const storeNames = [];
|
|
10
10
|
const createStore = () => {
|
|
11
|
-
const fileName = `filestore-test-${
|
|
11
|
+
const fileName = `filestore-test-${storeCount++}.json`;
|
|
12
12
|
storeNames.push(fileName);
|
|
13
|
-
return new filesystem_store_1.FileSystemStore({ model:
|
|
13
|
+
return new filesystem_store_1.FileSystemStore({ model: core_1.TestClass, fileName, primaryKey: 'id' });
|
|
14
14
|
};
|
|
15
|
-
(0,
|
|
15
|
+
(0, core_1.createStoreTest)({
|
|
16
16
|
createStore,
|
|
17
17
|
typeName: 'FileStore',
|
|
18
18
|
});
|
|
19
19
|
it('Should save data on tick', async () => {
|
|
20
|
-
const fileName = `filestore-test-${
|
|
20
|
+
const fileName = `filestore-test-${storeCount++}.json`;
|
|
21
21
|
storeNames.push(fileName);
|
|
22
|
-
const store = new filesystem_store_1.FileSystemStore({ model:
|
|
22
|
+
const store = new filesystem_store_1.FileSystemStore({ model: core_1.TestClass, fileName, primaryKey: 'id', tickMs: 500 });
|
|
23
23
|
store.saveChanges = jest.fn(store.saveChanges.bind(store));
|
|
24
24
|
await store.add({
|
|
25
25
|
id: 1,
|
|
@@ -35,9 +35,9 @@ describe('FileSystemStore', () => {
|
|
|
35
35
|
await store.dispose();
|
|
36
36
|
});
|
|
37
37
|
it('Should reload data from disk', async () => {
|
|
38
|
-
const fileName = `filestore-test-${
|
|
38
|
+
const fileName = `filestore-test-${storeCount++}.json`;
|
|
39
39
|
storeNames.push(fileName);
|
|
40
|
-
const store = new filesystem_store_1.FileSystemStore({ model:
|
|
40
|
+
const store = new filesystem_store_1.FileSystemStore({ model: core_1.TestClass, fileName, primaryKey: 'id', tickMs: 500 });
|
|
41
41
|
await store.add({
|
|
42
42
|
id: 1,
|
|
43
43
|
dateValue: new Date(),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"filesystem-store.spec.js","sourceRoot":"","sources":["../src/filesystem-store.spec.ts"],"names":[],"mappings":";;AAAA,2BAAyC;AACzC,yDAAoD;AACpD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I,IAAA,eAAU,EAAC,QAAQ,CAAC,EAAE;gBACxB,MAAM,aAAQ,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAA;aAChC;QACH,CAAC,CAAC,CACH,CAAA;IACH,CAAC,CAAC,CAAA;AACJ,CAAC,CAAC,CAAA"}
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const tslib_1 = require("tslib");
|
|
4
|
-
|
|
5
|
-
require("./store-manager-
|
|
4
|
+
tslib_1.__exportStar(require("./filesystem-store"), exports);
|
|
5
|
+
tslib_1.__exportStar(require("./store-manager-helpers"), exports);
|
|
6
6
|
//# 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,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,6DAAkC;AAClC,kEAAuC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useFileSystemStore = void 0;
|
|
4
|
+
const core_1 = require("@furystack/core");
|
|
5
|
+
const filesystem_store_1 = require("./filesystem-store");
|
|
6
|
+
/**
|
|
7
|
+
*
|
|
8
|
+
* @param options The Options for store creation
|
|
9
|
+
* @param options.injector The injector to use for creating the store
|
|
10
|
+
* @param options.model The model to use for the store
|
|
11
|
+
* @param options.primaryKey The primary key of the model
|
|
12
|
+
* @param options.fileName The name of the file to use for the store
|
|
13
|
+
* @param options.tickMs The time in ms to wait between each save
|
|
14
|
+
*/
|
|
15
|
+
const useFileSystemStore = (options) => {
|
|
16
|
+
const store = new filesystem_store_1.FileSystemStore({ ...options });
|
|
17
|
+
(0, core_1.addStore)(options.injector, store);
|
|
18
|
+
};
|
|
19
|
+
exports.useFileSystemStore = useFileSystemStore;
|
|
20
|
+
//# sourceMappingURL=store-manager-helpers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"store-manager-helpers.js","sourceRoot":"","sources":["../src/store-manager-helpers.ts"],"names":[],"mappings":";;;AAAA,0CAA0C;AAE1C,yDAAoD;AAEpD;;;;;;;;GAQG;AACI,MAAM,kBAAkB,GAAG,CAAI,OAMrC,EAAE,EAAE;IACH,MAAM,KAAK,GAAG,IAAI,kCAAe,CAAC,EAAE,GAAG,OAAO,EAAE,CAAC,CAAA;IACjD,IAAA,eAAQ,EAAC,OAAO,CAAC,QAAQ,EAAE,KAAK,CAAC,CAAA;AACnC,CAAC,CAAA;AATY,QAAA,kBAAkB,sBAS9B"}
|
|
@@ -2,25 +2,25 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const fs_1 = require("fs");
|
|
4
4
|
const index_1 = require("./index");
|
|
5
|
-
const
|
|
6
|
-
require("./store-manager-extensions");
|
|
7
|
-
const uuid_1 = require("uuid");
|
|
5
|
+
const store_manager_helpers_1 = require("./store-manager-helpers");
|
|
8
6
|
const utils_1 = require("@furystack/utils");
|
|
9
7
|
const inject_1 = require("@furystack/inject");
|
|
10
8
|
const core_1 = require("@furystack/core");
|
|
9
|
+
let storeCount = 0;
|
|
11
10
|
describe('FileSystemStore store manager extensions', () => {
|
|
12
11
|
const storeNames = [];
|
|
13
12
|
it('Should create a store with an extensions method from Store Manages', async () => {
|
|
14
13
|
await (0, utils_1.usingAsync)(new inject_1.Injector(), async (i) => {
|
|
15
14
|
const storeManager = i.getInstance(core_1.StoreManager);
|
|
16
|
-
const fileName = `filestore-test-${
|
|
15
|
+
const fileName = `filestore-test-${storeCount++}.json`;
|
|
17
16
|
storeNames.push(fileName);
|
|
18
|
-
|
|
19
|
-
|
|
17
|
+
(0, store_manager_helpers_1.useFileSystemStore)({
|
|
18
|
+
injector: i,
|
|
19
|
+
model: core_1.TestClass,
|
|
20
20
|
fileName,
|
|
21
21
|
primaryKey: 'id',
|
|
22
22
|
});
|
|
23
|
-
expect(
|
|
23
|
+
expect(storeManager.getStoreFor(core_1.TestClass, 'id')).toBeInstanceOf(index_1.FileSystemStore);
|
|
24
24
|
});
|
|
25
25
|
});
|
|
26
26
|
afterAll(async () => {
|
|
@@ -31,4 +31,4 @@ describe('FileSystemStore store manager extensions', () => {
|
|
|
31
31
|
}));
|
|
32
32
|
});
|
|
33
33
|
});
|
|
34
|
-
//# sourceMappingURL=store-manager-
|
|
34
|
+
//# sourceMappingURL=store-manager-helpers.spec.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"store-manager-helpers.spec.js","sourceRoot":"","sources":["../src/store-manager-helpers.spec.ts"],"names":[],"mappings":";;AAAA,2BAAyC;AACzC,mCAAyC;AACzC,mEAA4D;AAC5D,4CAA6C;AAC7C,8CAA4C;AAC5C,0CAAyD;AAEzD,IAAI,UAAU,GAAG,CAAC,CAAA;AAElB,QAAQ,CAAC,0CAA0C,EAAE,GAAG,EAAE;IACxD,MAAM,UAAU,GAAa,EAAE,CAAA;IAE/B,EAAE,CAAC,oEAAoE,EAAE,KAAK,IAAI,EAAE;QAClF,MAAM,IAAA,kBAAU,EAAC,IAAI,iBAAQ,EAAE,EAAE,KAAK,EAAE,CAAC,EAAE,EAAE;YAC3C,MAAM,YAAY,GAAG,CAAC,CAAC,WAAW,CAAC,mBAAY,CAAC,CAAA;YAChD,MAAM,QAAQ,GAAG,kBAAkB,UAAU,EAAE,OAAO,CAAA;YACtD,UAAU,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAA;YACzB,IAAA,0CAAkB,EAAC;gBACjB,QAAQ,EAAE,CAAC;gBACX,KAAK,EAAE,gBAAS;gBAChB,QAAQ;gBACR,UAAU,EAAE,IAAI;aACjB,CAAC,CAAA;YACF,MAAM,CAAC,YAAY,CAAC,WAAW,CAAC,gBAAS,EAAE,IAAI,CAAC,CAAC,CAAC,cAAc,CAAC,uBAAe,CAAC,CAAA;QACnF,CAAC,CAAC,CAAA;IACJ,CAAC,CAAC,CAAA;IAEF,QAAQ,CAAC,KAAK,IAAI,EAAE;QAClB,MAAM,OAAO,CAAC,GAAG,CACf,UAAU,CAAC,GAAG,CAAC,KAAK,EAAE,QAAQ,EAAE,EAAE;YAChC,IAAI,IAAA,eAAU,EAAC,QAAQ,CAAC,EAAE;gBACxB,MAAM,aAAQ,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAA;aAChC;QACH,CAAC,CAAC,CACH,CAAA;IACH,CAAC,CAAC,CAAA;AACJ,CAAC,CAAC,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@furystack/filesystem-store",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.0",
|
|
4
4
|
"description": "Simple File System store implementation for FuryStack",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"files": [
|
|
7
7
|
"dist",
|
|
8
|
+
"types",
|
|
8
9
|
"src"
|
|
9
10
|
],
|
|
10
11
|
"repository": {
|
|
@@ -28,18 +29,16 @@
|
|
|
28
29
|
},
|
|
29
30
|
"homepage": "https://github.com/furystack/furystack",
|
|
30
31
|
"dependencies": {
|
|
31
|
-
"@furystack/core": "^
|
|
32
|
-
"@furystack/inject": "^
|
|
33
|
-
"@furystack/utils": "^
|
|
32
|
+
"@furystack/core": "^11.0.0",
|
|
33
|
+
"@furystack/inject": "^6.0.0",
|
|
34
|
+
"@furystack/utils": "^3.0.0",
|
|
34
35
|
"semaphore-async-await": "^1.5.1",
|
|
35
|
-
"tslib": "^2.
|
|
36
|
+
"tslib": "^2.4.0"
|
|
36
37
|
},
|
|
37
38
|
"devDependencies": {
|
|
38
|
-
"@types/jest": "^27.4.
|
|
39
|
-
"@types/node": "^17.0.
|
|
40
|
-
"@types/uuid": "^8.3.4",
|
|
41
|
-
"uuid": "^8.3.2"
|
|
39
|
+
"@types/jest": "^27.4.1",
|
|
40
|
+
"@types/node": "^17.0.30"
|
|
42
41
|
},
|
|
43
|
-
"typings": "./
|
|
42
|
+
"typings": "./types/index.d.ts",
|
|
44
43
|
"gitHead": "1045d854bfd8c475b7035471d130d401417a2321"
|
|
45
44
|
}
|
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
import { promises, existsSync } from 'fs'
|
|
2
2
|
import { FileSystemStore } from './filesystem-store'
|
|
3
|
-
import { TestClass, createStoreTest } from '@furystack/core
|
|
4
|
-
import { v4 } from 'uuid'
|
|
3
|
+
import { TestClass, createStoreTest } from '@furystack/core'
|
|
5
4
|
import { sleepAsync } from '@furystack/utils'
|
|
6
5
|
|
|
6
|
+
let storeCount = 0
|
|
7
|
+
|
|
7
8
|
describe('FileSystemStore', () => {
|
|
8
9
|
const storeNames: string[] = []
|
|
9
10
|
const createStore = () => {
|
|
10
|
-
const fileName = `filestore-test-${
|
|
11
|
+
const fileName = `filestore-test-${storeCount++}.json`
|
|
11
12
|
storeNames.push(fileName)
|
|
12
13
|
return new FileSystemStore({ model: TestClass, fileName, primaryKey: 'id' })
|
|
13
14
|
}
|
|
@@ -18,7 +19,7 @@ describe('FileSystemStore', () => {
|
|
|
18
19
|
})
|
|
19
20
|
|
|
20
21
|
it('Should save data on tick', async () => {
|
|
21
|
-
const fileName = `filestore-test-${
|
|
22
|
+
const fileName = `filestore-test-${storeCount++}.json`
|
|
22
23
|
storeNames.push(fileName)
|
|
23
24
|
const store = new FileSystemStore({ model: TestClass, fileName, primaryKey: 'id', tickMs: 500 })
|
|
24
25
|
store.saveChanges = jest.fn(store.saveChanges.bind(store))
|
|
@@ -39,7 +40,7 @@ describe('FileSystemStore', () => {
|
|
|
39
40
|
})
|
|
40
41
|
|
|
41
42
|
it('Should reload data from disk', async () => {
|
|
42
|
-
const fileName = `filestore-test-${
|
|
43
|
+
const fileName = `filestore-test-${storeCount++}.json`
|
|
43
44
|
storeNames.push(fileName)
|
|
44
45
|
const store = new FileSystemStore({ model: TestClass, fileName, primaryKey: 'id', tickMs: 500 })
|
|
45
46
|
await store.add({
|
package/src/index.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export * from './filesystem-store'
|
|
2
|
-
|
|
2
|
+
export * from './store-manager-helpers'
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { promises, existsSync } from 'fs'
|
|
2
2
|
import { FileSystemStore } from './index'
|
|
3
|
-
import {
|
|
4
|
-
import './store-manager-extensions'
|
|
5
|
-
import { v4 } from 'uuid'
|
|
3
|
+
import { useFileSystemStore } from './store-manager-helpers'
|
|
6
4
|
import { usingAsync } from '@furystack/utils'
|
|
7
5
|
import { Injector } from '@furystack/inject'
|
|
8
|
-
import { StoreManager } from '@furystack/core'
|
|
6
|
+
import { StoreManager, TestClass } from '@furystack/core'
|
|
7
|
+
|
|
8
|
+
let storeCount = 0
|
|
9
9
|
|
|
10
10
|
describe('FileSystemStore store manager extensions', () => {
|
|
11
11
|
const storeNames: string[] = []
|
|
@@ -13,14 +13,15 @@ describe('FileSystemStore store manager extensions', () => {
|
|
|
13
13
|
it('Should create a store with an extensions method from Store Manages', async () => {
|
|
14
14
|
await usingAsync(new Injector(), async (i) => {
|
|
15
15
|
const storeManager = i.getInstance(StoreManager)
|
|
16
|
-
const fileName = `filestore-test-${
|
|
16
|
+
const fileName = `filestore-test-${storeCount++}.json`
|
|
17
17
|
storeNames.push(fileName)
|
|
18
|
-
|
|
18
|
+
useFileSystemStore({
|
|
19
|
+
injector: i,
|
|
19
20
|
model: TestClass,
|
|
20
21
|
fileName,
|
|
21
22
|
primaryKey: 'id',
|
|
22
23
|
})
|
|
23
|
-
expect(
|
|
24
|
+
expect(storeManager.getStoreFor(TestClass, 'id')).toBeInstanceOf(FileSystemStore)
|
|
24
25
|
})
|
|
25
26
|
})
|
|
26
27
|
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { addStore } from '@furystack/core'
|
|
2
|
+
import { Constructable, Injector } from '@furystack/inject'
|
|
3
|
+
import { FileSystemStore } from './filesystem-store'
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
*
|
|
7
|
+
* @param options The Options for store creation
|
|
8
|
+
* @param options.injector The injector to use for creating the store
|
|
9
|
+
* @param options.model The model to use for the store
|
|
10
|
+
* @param options.primaryKey The primary key of the model
|
|
11
|
+
* @param options.fileName The name of the file to use for the store
|
|
12
|
+
* @param options.tickMs The time in ms to wait between each save
|
|
13
|
+
*/
|
|
14
|
+
export const useFileSystemStore = <T>(options: {
|
|
15
|
+
injector: Injector
|
|
16
|
+
model: Constructable<T>
|
|
17
|
+
primaryKey: keyof T
|
|
18
|
+
fileName: string
|
|
19
|
+
tickMs?: number
|
|
20
|
+
}) => {
|
|
21
|
+
const store = new FileSystemStore({ ...options })
|
|
22
|
+
addStore(options.injector, store)
|
|
23
|
+
}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
package/types/index.d.ts
ADDED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAA;AAClC,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAA;AAClC,cAAc,yBAAyB,CAAA"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { Constructable, Injector } from '@furystack/inject';
|
|
2
|
+
/**
|
|
3
|
+
*
|
|
4
|
+
* @param options The Options for store creation
|
|
5
|
+
* @param options.injector The injector to use for creating the store
|
|
6
|
+
* @param options.model The model to use for the store
|
|
7
|
+
* @param options.primaryKey The primary key of the model
|
|
8
|
+
* @param options.fileName The name of the file to use for the store
|
|
9
|
+
* @param options.tickMs The time in ms to wait between each save
|
|
10
|
+
*/
|
|
11
|
+
export declare const useFileSystemStore: <T>(options: {
|
|
12
|
+
injector: Injector;
|
|
13
|
+
model: Constructable<T>;
|
|
14
|
+
primaryKey: keyof T;
|
|
15
|
+
fileName: string;
|
|
16
|
+
tickMs?: number | undefined;
|
|
17
|
+
}) => void;
|
|
18
|
+
//# sourceMappingURL=store-manager-helpers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"store-manager-helpers.d.ts","sourceRoot":"","sources":["../src/store-manager-helpers.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAA;AAG3D;;;;;;;;GAQG;AACH,eAAO,MAAM,kBAAkB;cACnB,QAAQ;;;cAGR,MAAM;;UAKjB,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"store-manager-helpers.spec.d.ts","sourceRoot":"","sources":["../src/store-manager-helpers.spec.ts"],"names":[],"mappings":""}
|
package/dist/index.d.ts
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import { Constructable } from '@furystack/inject';
|
|
2
|
-
declare module '@furystack/core/dist/store-manager' {
|
|
3
|
-
/**
|
|
4
|
-
* Defines an extended Injector instance
|
|
5
|
-
*/
|
|
6
|
-
interface StoreManager {
|
|
7
|
-
/**
|
|
8
|
-
* Registers a filesystem-store for the provided model in the StoreManager
|
|
9
|
-
* usage example:
|
|
10
|
-
* ````ts
|
|
11
|
-
* import '@furystack/filesystem-store'
|
|
12
|
-
*
|
|
13
|
-
* defaultInjector
|
|
14
|
-
* .useFileSystem(sm => sm.useFileSystem({model: MyModel, primaryKey: 'myId', fileName: 'asd.json')
|
|
15
|
-
* ````
|
|
16
|
-
*/
|
|
17
|
-
useFileSystem: <T>(options: {
|
|
18
|
-
model: Constructable<T>;
|
|
19
|
-
primaryKey: keyof T;
|
|
20
|
-
fileName: string;
|
|
21
|
-
tickMs?: number;
|
|
22
|
-
}) => this;
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
//# sourceMappingURL=store-manager-extensions.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"store-manager-extensions.d.ts","sourceRoot":"","sources":["../src/store-manager-extensions.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAA;AAGjD,OAAO,QAAQ,oCAAoC,CAAC;IAClD;;OAEG;IACH,UAAU,YAAY;QACpB;;;;;;;;;WASG;QACH,aAAa,EAAE,CAAC,CAAC,EAAE,OAAO,EAAE;YAC1B,KAAK,EAAE,aAAa,CAAC,CAAC,CAAC,CAAA;YACvB,UAAU,EAAE,MAAM,CAAC,CAAA;YACnB,QAAQ,EAAE,MAAM,CAAA;YAChB,MAAM,CAAC,EAAE,MAAM,CAAA;SAChB,KAAK,IAAI,CAAA;KACX;CACF"}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const store_manager_1 = require("@furystack/core/dist/store-manager");
|
|
4
|
-
const filesystem_store_1 = require("./filesystem-store");
|
|
5
|
-
store_manager_1.StoreManager.prototype.useFileSystem = function (options) {
|
|
6
|
-
const store = new filesystem_store_1.FileSystemStore({ ...options });
|
|
7
|
-
this.addStore(store);
|
|
8
|
-
return this;
|
|
9
|
-
};
|
|
10
|
-
//# sourceMappingURL=store-manager-extensions.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"store-manager-extensions.js","sourceRoot":"","sources":["../src/store-manager-extensions.ts"],"names":[],"mappings":";;AAAA,sEAAiE;AAEjE,yDAAoD;AA0BpD,4BAAY,CAAC,SAAS,CAAC,aAAa,GAAG,UAAU,OAAO;IACtD,MAAM,KAAK,GAAG,IAAI,kCAAe,CAAC,EAAE,GAAG,OAAO,EAAE,CAAC,CAAA;IACjD,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAA;IACpB,OAAO,IAAI,CAAA;AACb,CAAC,CAAA"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"store-manager-extensions.spec.d.ts","sourceRoot":"","sources":["../src/store-manager-extensions.spec.ts"],"names":[],"mappings":"AAGA,OAAO,4BAA4B,CAAA"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"store-manager-extensions.spec.js","sourceRoot":"","sources":["../src/store-manager-extensions.spec.ts"],"names":[],"mappings":";;AAAA,2BAAyC;AACzC,mCAAyC;AACzC,kGAA4E;AAC5E,sCAAmC;AACnC,+BAAyB;AACzB,4CAA6C;AAC7C,8CAA4C;AAC5C,0CAA8C;AAE9C,QAAQ,CAAC,0CAA0C,EAAE,GAAG,EAAE;IACxD,MAAM,UAAU,GAAa,EAAE,CAAA;IAE/B,EAAE,CAAC,oEAAoE,EAAE,KAAK,IAAI,EAAE;QAClF,MAAM,IAAA,kBAAU,EAAC,IAAI,iBAAQ,EAAE,EAAE,KAAK,EAAE,CAAC,EAAE,EAAE;YAC3C,MAAM,YAAY,GAAG,CAAC,CAAC,WAAW,CAAC,mBAAY,CAAC,CAAA;YAChD,MAAM,QAAQ,GAAG,kBAAkB,IAAA,SAAE,GAAE,OAAO,CAAA;YAC9C,UAAU,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAA;YACzB,MAAM,KAAK,GAAG,YAAY,CAAC,aAAa,CAAC;gBACvC,KAAK,EAAE,uCAAS;gBAChB,QAAQ;gBACR,UAAU,EAAE,IAAI;aACjB,CAAC,CAAA;YACF,MAAM,CAAC,KAAK,CAAC,WAAW,CAAC,uCAAS,EAAE,IAAI,CAAC,CAAC,CAAC,cAAc,CAAC,uBAAe,CAAC,CAAA;QAC5E,CAAC,CAAC,CAAA;IACJ,CAAC,CAAC,CAAA;IAEF,QAAQ,CAAC,KAAK,IAAI,EAAE;QAClB,MAAM,OAAO,CAAC,GAAG,CACf,UAAU,CAAC,GAAG,CAAC,KAAK,EAAE,QAAQ,EAAE,EAAE;YAChC,IAAI,IAAA,eAAU,EAAC,QAAQ,CAAC,EAAE;gBACxB,MAAM,aAAQ,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAA;aAChC;QACH,CAAC,CAAC,CACH,CAAA;IACH,CAAC,CAAC,CAAA;AACJ,CAAC,CAAC,CAAA"}
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import { StoreManager } from '@furystack/core/dist/store-manager'
|
|
2
|
-
import { Constructable } from '@furystack/inject'
|
|
3
|
-
import { FileSystemStore } from './filesystem-store'
|
|
4
|
-
|
|
5
|
-
declare module '@furystack/core/dist/store-manager' {
|
|
6
|
-
/**
|
|
7
|
-
* Defines an extended Injector instance
|
|
8
|
-
*/
|
|
9
|
-
interface StoreManager {
|
|
10
|
-
/**
|
|
11
|
-
* Registers a filesystem-store for the provided model in the StoreManager
|
|
12
|
-
* usage example:
|
|
13
|
-
* ````ts
|
|
14
|
-
* import '@furystack/filesystem-store'
|
|
15
|
-
*
|
|
16
|
-
* defaultInjector
|
|
17
|
-
* .useFileSystem(sm => sm.useFileSystem({model: MyModel, primaryKey: 'myId', fileName: 'asd.json')
|
|
18
|
-
* ````
|
|
19
|
-
*/
|
|
20
|
-
useFileSystem: <T>(options: {
|
|
21
|
-
model: Constructable<T>
|
|
22
|
-
primaryKey: keyof T
|
|
23
|
-
fileName: string
|
|
24
|
-
tickMs?: number
|
|
25
|
-
}) => this
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
StoreManager.prototype.useFileSystem = function (options) {
|
|
30
|
-
const store = new FileSystemStore({ ...options })
|
|
31
|
-
this.addStore(store)
|
|
32
|
-
return this
|
|
33
|
-
}
|