@furystack/filesystem-store 4.0.10 → 4.0.11

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.
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=filesystem-store.spec.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"filesystem-store.spec.d.ts","sourceRoot":"","sources":["../src/filesystem-store.spec.ts"],"names":[],"mappings":""}
@@ -0,0 +1,75 @@
1
+ import { promises } from 'fs';
2
+ import { FileSystemStore } from './filesystem-store.js';
3
+ import { TestClass, createStoreTest } from '@furystack/core/create-physical-store-tests';
4
+ import { sleepAsync } from '@furystack/utils';
5
+ import { useFileSystemStore } from './store-manager-helpers.js';
6
+ import { describe, it, expect, vi, afterAll } from 'vitest';
7
+ import { StoreManager } from '@furystack/core';
8
+ let storeCount = 0;
9
+ describe('FileSystemStore', () => {
10
+ const storeNames = [];
11
+ const createStore = (i) => {
12
+ const fileName = `filestore-test-${storeCount++}.json`;
13
+ storeNames.push(fileName);
14
+ useFileSystemStore({
15
+ injector: i,
16
+ model: TestClass,
17
+ fileName,
18
+ primaryKey: 'id',
19
+ });
20
+ return i.getInstance(StoreManager).getStoreFor(TestClass, 'id');
21
+ };
22
+ createStoreTest({
23
+ createStore,
24
+ typeName: 'FileStore',
25
+ });
26
+ it('Should save data on tick', async () => {
27
+ const fileName = `filestore-test-${storeCount++}.json`;
28
+ storeNames.push(fileName);
29
+ const store = new FileSystemStore({ model: TestClass, fileName, primaryKey: 'id', tickMs: 500 });
30
+ store.saveChanges = vi.fn(store.saveChanges.bind(store));
31
+ await store.add({
32
+ id: 1,
33
+ dateValue: new Date(),
34
+ stringValue1: 'alma',
35
+ stringValue2: 'korte',
36
+ booleanValue: false,
37
+ numberValue1: 1,
38
+ numberValue2: 2,
39
+ });
40
+ await sleepAsync(501);
41
+ expect(store.saveChanges).toHaveBeenCalled();
42
+ await store.dispose();
43
+ });
44
+ it('Should reload data from disk', async () => {
45
+ const fileName = `filestore-test-${storeCount++}.json`;
46
+ storeNames.push(fileName);
47
+ const store = new FileSystemStore({ model: TestClass, fileName, primaryKey: 'id', tickMs: 500 });
48
+ await store.add({
49
+ id: 1,
50
+ dateValue: new Date(),
51
+ stringValue1: 'alma',
52
+ stringValue2: 'korte',
53
+ booleanValue: false,
54
+ numberValue1: 1,
55
+ numberValue2: 2,
56
+ });
57
+ await store.saveChanges();
58
+ await store.remove(1);
59
+ await store.reloadData();
60
+ const count = await store.count();
61
+ expect(count).toBe(1);
62
+ await store.dispose();
63
+ });
64
+ afterAll(async () => {
65
+ for (const fileName of storeNames) {
66
+ try {
67
+ await promises.unlink(fileName);
68
+ }
69
+ catch (error) {
70
+ // Ignore, maybe already deleted
71
+ }
72
+ }
73
+ });
74
+ });
75
+ //# sourceMappingURL=filesystem-store.spec.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"filesystem-store.spec.js","sourceRoot":"","sources":["../src/filesystem-store.spec.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,IAAI,CAAA;AAC7B,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAA;AACvD,OAAO,EAAE,SAAS,EAAE,eAAe,EAAE,MAAM,6CAA6C,CAAA;AACxF,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAA;AAE7C,OAAO,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAA;AAC/D,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,QAAQ,EAAE,MAAM,QAAQ,CAAA;AAC3D,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAA;AAE9C,IAAI,UAAU,GAAG,CAAC,CAAA;AAElB,QAAQ,CAAC,iBAAiB,EAAE,GAAG,EAAE;IAC/B,MAAM,UAAU,GAAa,EAAE,CAAA;IAC/B,MAAM,WAAW,GAAG,CAAC,CAAW,EAAE,EAAE;QAClC,MAAM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ec.d.ts","sourceRoot":"","sources":["../src/store-manager-helpers.spec.ts"],"names":[],"mappings":""}
@@ -0,0 +1,34 @@
1
+ import { promises, existsSync } from 'fs';
2
+ import { FileSystemStore } from './index.js';
3
+ import { useFileSystemStore } from './store-manager-helpers.js';
4
+ import { usingAsync } from '@furystack/utils';
5
+ import { Injector } from '@furystack/inject';
6
+ import { StoreManager } from '@furystack/core';
7
+ import { describe, it, expect, afterAll } from 'vitest';
8
+ import { TestClass } from '@furystack/core/create-physical-store-tests';
9
+ let storeCount = 0;
10
+ describe('FileSystemStore store manager extensions', () => {
11
+ const storeNames = [];
12
+ it('Should create a store with an extensions method from Store Manages', async () => {
13
+ await usingAsync(new Injector(), async (i) => {
14
+ const storeManager = i.getInstance(StoreManager);
15
+ const fileName = `filestore-test-${storeCount++}.json`;
16
+ storeNames.push(fileName);
17
+ useFileSystemStore({
18
+ injector: i,
19
+ model: TestClass,
20
+ fileName,
21
+ primaryKey: 'id',
22
+ });
23
+ expect(storeManager.getStoreFor(TestClass, 'id')).toBeInstanceOf(FileSystemStore);
24
+ });
25
+ });
26
+ afterAll(async () => {
27
+ await Promise.all(storeNames.map(async (fileName) => {
28
+ if (existsSync(fileName)) {
29
+ await promises.unlink(fileName);
30
+ }
31
+ }));
32
+ });
33
+ });
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,OAAO,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,IAAI,CAAA;AACzC,OAAO,EAAE,eAAe,EAAE,MAAM,YAAY,CAAA;AAC5C,OAAO,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAA;AAC/D,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAA;AAC7C,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAA;AAC5C,OAAO,EAAE,YAAY,E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name": "@furystack/filesystem-store",
3
- "version": "4.0.10",
3
+ "version": "4.0.11",
4
4
  "description": "Simple File System store implementation for FuryStack",
5
5
  "type": "module",
6
6
  "scripts": {
@@ -37,15 +37,15 @@
37
37
  },
38
38
  "homepage": "https://github.com/furystack/furystack",
39
39
  "dependencies": {
40
- "@furystack/core": "^12.0.10",
41
- "@furystack/inject": "^8.1.0",
42
- "@furystack/utils": "^4.0.9",
40
+ "@furystack/core": "^12.0.11",
41
+ "@furystack/inject": "^8.1.1",
42
+ "@furystack/utils": "^4.0.10",
43
43
  "semaphore-async-await": "^1.5.1"
44
44
  },
45
45
  "devDependencies": {
46
- "@types/node": "^20.5.6",
46
+ "@types/node": "^20.8.10",
47
47
  "typescript": "^5.2.2",
48
- "vitest": "^0.34.3"
48
+ "vitest": "^0.34.6"
49
49
  },
50
50
  "gitHead": "1045d854bfd8c475b7035471d130d401417a2321"
51
51
  }
@@ -1,9 +1,9 @@
1
1
  import { promises } from 'fs'
2
- import { FileSystemStore } from './filesystem-store'
2
+ import { FileSystemStore } from './filesystem-store.js'
3
3
  import { TestClass, createStoreTest } from '@furystack/core/create-physical-store-tests'
4
4
  import { sleepAsync } from '@furystack/utils'
5
5
  import type { Injector } from '@furystack/inject'
6
- import { useFileSystemStore } from './store-manager-helpers'
6
+ import { useFileSystemStore } from './store-manager-helpers.js'
7
7
  import { describe, it, expect, vi, afterAll } from 'vitest'
8
8
  import { StoreManager } from '@furystack/core'
9
9
 
@@ -1,10 +1,11 @@
1
1
  import { promises, existsSync } from 'fs'
2
- import { FileSystemStore } from './index'
3
- import { useFileSystemStore } from './store-manager-helpers'
2
+ import { FileSystemStore } from './index.js'
3
+ import { useFileSystemStore } from './store-manager-helpers.js'
4
4
  import { usingAsync } from '@furystack/utils'
5
5
  import { Injector } from '@furystack/inject'
6
- import { StoreManager, TestClass } from '@furystack/core'
6
+ import { StoreManager } from '@furystack/core'
7
7
  import { describe, it, expect, afterAll } from 'vitest'
8
+ import { TestClass } from '@furystack/core/create-physical-store-tests'
8
9
 
9
10
  let storeCount = 0
10
11