@tallyui/database 1.0.0 → 2.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/LICENSE +21 -0
- package/dist/index.d.ts +304 -5
- package/dist/index.js +626 -20
- package/package.json +9 -3
- package/src/connector-collection.ts +20 -0
- package/src/create-db.ts +54 -10
- package/src/engine.ts +5 -0
- package/src/fingerprint-reconcile.ts +158 -0
- package/src/id-reconcile.ts +131 -0
- package/src/index.ts +18 -1
- package/src/live-tab.ts +280 -0
- package/src/pass-queue.ts +19 -0
- package/src/reconcile.ts +150 -0
- package/src/replication.ts +8 -1
- package/src/stock-levels.ts +32 -0
- package/src/storage-watchdog.ts +134 -0
- package/src/storage.ts +11 -5
- package/src/replication.test.ts +0 -97
- package/src/storage.test.ts +0 -19
package/src/replication.test.ts
DELETED
|
@@ -1,97 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
|
|
2
|
-
import { createRxDatabase, addRxPlugin } from 'rxdb';
|
|
3
|
-
import { RxDBDevModePlugin } from 'rxdb/plugins/dev-mode';
|
|
4
|
-
import { getRxStorageMemory } from 'rxdb/plugins/storage-memory';
|
|
5
|
-
import { wrappedValidateAjvStorage } from 'rxdb/plugins/validate-ajv';
|
|
6
|
-
|
|
7
|
-
import { startReplication } from './replication';
|
|
8
|
-
import type { ReplicationAdapter, SyncContext } from '@tallyui/core';
|
|
9
|
-
|
|
10
|
-
addRxPlugin(RxDBDevModePlugin);
|
|
11
|
-
|
|
12
|
-
const storage = wrappedValidateAjvStorage({ storage: getRxStorageMemory() });
|
|
13
|
-
|
|
14
|
-
const testSchema = {
|
|
15
|
-
version: 0,
|
|
16
|
-
primaryKey: 'id',
|
|
17
|
-
type: 'object' as const,
|
|
18
|
-
properties: {
|
|
19
|
-
id: { type: 'string', maxLength: 100 },
|
|
20
|
-
name: { type: 'string' },
|
|
21
|
-
},
|
|
22
|
-
required: ['id', 'name'],
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
const context: SyncContext = {
|
|
26
|
-
connectorId: 'test',
|
|
27
|
-
baseUrl: 'https://example.com',
|
|
28
|
-
headers: {},
|
|
29
|
-
};
|
|
30
|
-
|
|
31
|
-
describe('startReplication', () => {
|
|
32
|
-
let db: any;
|
|
33
|
-
|
|
34
|
-
beforeEach(async () => {
|
|
35
|
-
db = await createRxDatabase({
|
|
36
|
-
name: `test_${Date.now()}`,
|
|
37
|
-
storage,
|
|
38
|
-
multiInstance: false,
|
|
39
|
-
ignoreDuplicate: true,
|
|
40
|
-
});
|
|
41
|
-
await db.addCollections({ products: { schema: testSchema } });
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
afterEach(async () => {
|
|
45
|
-
await db?.close();
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
it('starts replication and pulls documents', async () => {
|
|
49
|
-
const adapter: ReplicationAdapter<any, any> = {
|
|
50
|
-
pull: {
|
|
51
|
-
handler: vi.fn().mockResolvedValueOnce({
|
|
52
|
-
documents: [
|
|
53
|
-
{ id: '1', name: 'Widget', _deleted: false },
|
|
54
|
-
],
|
|
55
|
-
checkpoint: { id: '1' },
|
|
56
|
-
}).mockResolvedValue({
|
|
57
|
-
documents: [],
|
|
58
|
-
checkpoint: { id: '1' },
|
|
59
|
-
}),
|
|
60
|
-
},
|
|
61
|
-
};
|
|
62
|
-
|
|
63
|
-
const state = startReplication({
|
|
64
|
-
collection: db.products,
|
|
65
|
-
adapter,
|
|
66
|
-
context,
|
|
67
|
-
});
|
|
68
|
-
|
|
69
|
-
await state.awaitInSync();
|
|
70
|
-
|
|
71
|
-
const docs = await db.products.find().exec();
|
|
72
|
-
expect(docs).toHaveLength(1);
|
|
73
|
-
expect(docs[0].name).toBe('Widget');
|
|
74
|
-
|
|
75
|
-
await state.cancel();
|
|
76
|
-
});
|
|
77
|
-
|
|
78
|
-
it('returns RxReplicationState with observables', async () => {
|
|
79
|
-
const adapter: ReplicationAdapter<any, any> = {
|
|
80
|
-
pull: {
|
|
81
|
-
handler: vi.fn().mockResolvedValue({ documents: [], checkpoint: {} }),
|
|
82
|
-
},
|
|
83
|
-
};
|
|
84
|
-
|
|
85
|
-
const state = startReplication({
|
|
86
|
-
collection: db.products,
|
|
87
|
-
adapter,
|
|
88
|
-
context,
|
|
89
|
-
});
|
|
90
|
-
|
|
91
|
-
expect(state.error$).toBeDefined();
|
|
92
|
-
expect(state.active$).toBeDefined();
|
|
93
|
-
expect(state.received$).toBeDefined();
|
|
94
|
-
|
|
95
|
-
await state.cancel();
|
|
96
|
-
});
|
|
97
|
-
});
|
package/src/storage.test.ts
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
// @vitest-environment node
|
|
2
|
-
import { describe, it, expect } from 'vitest';
|
|
3
|
-
|
|
4
|
-
import { getStorage } from './storage';
|
|
5
|
-
|
|
6
|
-
describe('getStorage', () => {
|
|
7
|
-
it('returns a storage object with a name property', () => {
|
|
8
|
-
const storage = getStorage();
|
|
9
|
-
expect(storage).toBeDefined();
|
|
10
|
-
expect(storage.name).toBeDefined();
|
|
11
|
-
expect(typeof storage.createStorageInstance).toBe('function');
|
|
12
|
-
});
|
|
13
|
-
|
|
14
|
-
it('returns memory storage in node/test environment', () => {
|
|
15
|
-
const storage = getStorage();
|
|
16
|
-
// In Node.js (test env), we expect memory storage
|
|
17
|
-
expect(storage.name).toBe('memory');
|
|
18
|
-
});
|
|
19
|
-
});
|