@furystack/filesystem-store 2.0.34 → 3.0.2

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.
Files changed (32) hide show
  1. package/dist/filesystem-store.spec.js +9 -9
  2. package/dist/filesystem-store.spec.js.map +1 -1
  3. package/dist/index.js +1 -1
  4. package/dist/index.js.map +1 -1
  5. package/dist/store-manager-helpers.js +20 -0
  6. package/dist/store-manager-helpers.js.map +1 -0
  7. package/dist/{store-manager-extensions.spec.js → store-manager-helpers.spec.js} +8 -8
  8. package/dist/store-manager-helpers.spec.js.map +1 -0
  9. package/package.json +9 -10
  10. package/src/filesystem-store.spec.ts +6 -5
  11. package/src/index.ts +1 -1
  12. package/src/{store-manager-extensions.spec.ts → store-manager-helpers.spec.ts} +8 -7
  13. package/src/store-manager-helpers.ts +23 -0
  14. package/{dist → types}/filesystem-store.d.ts +0 -0
  15. package/{dist → types}/filesystem-store.d.ts.map +0 -0
  16. package/{dist → types}/filesystem-store.spec.d.ts +0 -0
  17. package/{dist → types}/filesystem-store.spec.d.ts.map +0 -0
  18. package/types/index.d.ts +3 -0
  19. package/{dist → types}/index.d.ts.map +1 -1
  20. package/types/store-manager-helpers.d.ts +18 -0
  21. package/types/store-manager-helpers.d.ts.map +1 -0
  22. package/types/store-manager-helpers.spec.d.ts +2 -0
  23. package/types/store-manager-helpers.spec.d.ts.map +1 -0
  24. package/dist/index.d.ts +0 -3
  25. package/dist/store-manager-extensions.d.ts +0 -25
  26. package/dist/store-manager-extensions.d.ts.map +0 -1
  27. package/dist/store-manager-extensions.js +0 -10
  28. package/dist/store-manager-extensions.js.map +0 -1
  29. package/dist/store-manager-extensions.spec.d.ts +0 -2
  30. package/dist/store-manager-extensions.spec.d.ts.map +0 -1
  31. package/dist/store-manager-extensions.spec.js.map +0 -1
  32. package/src/store-manager-extensions.ts +0 -33
@@ -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 create_physical_store_tests_1 = require("@furystack/core/dist/create-physical-store-tests");
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-${(0, uuid_1.v4)()}.json`;
11
+ const fileName = `filestore-test-${storeCount++}.json`;
12
12
  storeNames.push(fileName);
13
- return new filesystem_store_1.FileSystemStore({ model: create_physical_store_tests_1.TestClass, fileName, primaryKey: 'id' });
13
+ return new filesystem_store_1.FileSystemStore({ model: core_1.TestClass, fileName, primaryKey: 'id' });
14
14
  };
15
- (0, create_physical_store_tests_1.createStoreTest)({
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-${(0, uuid_1.v4)()}.json`;
20
+ const fileName = `filestore-test-${storeCount++}.json`;
21
21
  storeNames.push(fileName);
22
- const store = new filesystem_store_1.FileSystemStore({ model: create_physical_store_tests_1.TestClass, fileName, primaryKey: 'id', tickMs: 500 });
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-${(0, uuid_1.v4)()}.json`;
38
+ const fileName = `filestore-test-${storeCount++}.json`;
39
39
  storeNames.push(fileName);
40
- const store = new filesystem_store_1.FileSystemStore({ model: create_physical_store_tests_1.TestClass, fileName, primaryKey: 'id', tickMs: 500 });
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,kGAA6F;AAC7F,+BAAyB;AACzB,4CAA6C;AAE7C,QAAQ,CAAC,iBAAiB,EAAE,GAAG,EAAE;IAC/B,MAAM,UAAU,GAAa,EAAE,CAAA;IAC/B,MAAM,WAAW,GAAG,GAAG,EAAE;QACvB,MAAM,QAAQ,GAAG,kBAAkB,IAAA,SAAE,GAAE,OAAO,CAAA;QAC9C,UAAU,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAA;QACzB,OAAO,IAAI,kCAAe,CAAC,EAAE,KAAK,EAAE,uCAAS,EAAE,QAAQ,EAAE,UAAU,EAAE,IAAI,EAAE,CAAC,CAAA;IAC9E,CAAC,CAAA;IAED,IAAA,6CAAe,EAAC;QACd,WAAW;QACX,QAAQ,EAAE,WAAW;KACtB,CAAC,CAAA;IAEF,EAAE,CAAC,0BAA0B,EAAE,KAAK,IAAI,EAAE;QACxC,MAAM,QAAQ,GAAG,kBAAkB,IAAA,SAAE,GAAE,OAAO,CAAA;QAC9C,UAAU,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAA;QACzB,MAAM,KAAK,GAAG,IAAI,kCAAe,CAAC,EAAE,KAAK,EAAE,uCAAS,EAAE,QAAQ,EAAE,UAAU,EAAE,IAAI,EAAE,MAAM,EAAE,GAAG,EAAE,CAAC,CAAA;QAChG,KAAK,CAAC,WAAW,GAAG,IAAI,CAAC,EAAE,CAAC,KAAK,CAAC,WAAW,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAA;QAE1D,MAAM,KAAK,CAAC,GAAG,CAAC;YACd,EAAE,EAAE,CAAC;YACL,SAAS,EAAE,IAAI,IAAI,EAAE;YACrB,YAAY,EAAE,MAAM;YACpB,YAAY,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C,IAAI,CAAC,CAAC,CAAC,CAAA;QACrB,MAAM,KAAK,CAAC,OAAO,EAAE,CAAA;IACvB,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/dist/index.js CHANGED
@@ -2,5 +2,5 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const tslib_1 = require("tslib");
4
4
  tslib_1.__exportStar(require("./filesystem-store"), exports);
5
- require("./store-manager-extensions");
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,6DAAkC;AAClC,sCAAmC"}
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 create_physical_store_tests_1 = require("@furystack/core/dist/create-physical-store-tests");
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-${(0, uuid_1.v4)()}.json`;
15
+ const fileName = `filestore-test-${storeCount++}.json`;
17
16
  storeNames.push(fileName);
18
- const store = storeManager.useFileSystem({
19
- model: create_physical_store_tests_1.TestClass,
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(store.getStoreFor(create_physical_store_tests_1.TestClass, 'id')).toBeInstanceOf(index_1.FileSystemStore);
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-extensions.spec.js.map
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": "2.0.34",
3
+ "version": "3.0.2",
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": "^10.4.10",
32
- "@furystack/inject": "^5.0.7",
33
- "@furystack/utils": "^2.1.0",
32
+ "@furystack/core": "^11.0.2",
33
+ "@furystack/inject": "^6.0.2",
34
+ "@furystack/utils": "^3.0.2",
34
35
  "semaphore-async-await": "^1.5.1",
35
- "tslib": "^2.3.1"
36
+ "tslib": "^2.4.0"
36
37
  },
37
38
  "devDependencies": {
38
- "@types/jest": "^27.4.1",
39
- "@types/node": "^17.0.23",
40
- "@types/uuid": "^8.3.4",
41
- "uuid": "^8.3.2"
39
+ "@types/jest": "^27.5.0",
40
+ "@types/node": "^17.0.31"
42
41
  },
43
- "typings": "./dist/index.d.ts",
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/dist/create-physical-store-tests'
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-${v4()}.json`
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-${v4()}.json`
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-${v4()}.json`
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
- import './store-manager-extensions'
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 { TestClass } from '@furystack/core/dist/create-physical-store-tests'
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-${v4()}.json`
16
+ const fileName = `filestore-test-${storeCount++}.json`
17
17
  storeNames.push(fileName)
18
- const store = storeManager.useFileSystem({
18
+ useFileSystemStore({
19
+ injector: i,
19
20
  model: TestClass,
20
21
  fileName,
21
22
  primaryKey: 'id',
22
23
  })
23
- expect(store.getStoreFor(TestClass, 'id')).toBeInstanceOf(FileSystemStore)
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
@@ -0,0 +1,3 @@
1
+ export * from './filesystem-store';
2
+ export * from './store-manager-helpers';
3
+ //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAA;AAClC,OAAO,4BAA4B,CAAA"}
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,2 @@
1
+ export {};
2
+ //# sourceMappingURL=store-manager-helpers.spec.d.ts.map
@@ -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,3 +0,0 @@
1
- export * from './filesystem-store';
2
- import './store-manager-extensions';
3
- //# sourceMappingURL=index.d.ts.map
@@ -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,2 +0,0 @@
1
- import './store-manager-extensions';
2
- //# sourceMappingURL=store-manager-extensions.spec.d.ts.map
@@ -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
- }