@arcote.tech/arc 0.0.21 → 0.0.22
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/collection/queries/abstract-many-items.d.ts +1 -1
- package/dist/data-storage/data-storage-forked.d.ts +1 -1
- package/dist/data-storage/data-storage.abstract.d.ts +1 -1
- package/dist/data-storage/store-state-fork.d.ts +1 -1
- package/dist/data-storage/store-state.abstract.d.ts +1 -1
- package/dist/index.js +15 -25
- package/package.json +1 -1
|
@@ -5,7 +5,7 @@ import { ArcCollectionQuery } from "./abstract-collection-query";
|
|
|
5
5
|
export declare class QueryCollectionResult<C extends ArcCollectionAny> {
|
|
6
6
|
private result;
|
|
7
7
|
constructor(result: CollectionItem<C>[]);
|
|
8
|
-
get(id: util.GetType<C["id"]>): ({
|
|
8
|
+
get(id: util.GetType<C["id"]> | null): ({
|
|
9
9
|
_id: string;
|
|
10
10
|
} & ReturnType<C["deserialize"]> extends infer T ? { [KeyType in keyof T]: ({
|
|
11
11
|
_id: string;
|
|
@@ -9,7 +9,7 @@ export declare class ForkedDataStorage extends DataStorage {
|
|
|
9
9
|
getReadWriteTransaction(): Promise<ReadWriteTransaction>;
|
|
10
10
|
getStore<Item extends {
|
|
11
11
|
_id: string;
|
|
12
|
-
}>(storeName: string
|
|
12
|
+
}>(storeName: string): StoreState<Item>;
|
|
13
13
|
fork(): ForkedDataStorage;
|
|
14
14
|
merge(): Promise<void>;
|
|
15
15
|
}
|
|
@@ -5,7 +5,7 @@ import type { StoreState } from "./store-state.abstract";
|
|
|
5
5
|
export declare abstract class DataStorage {
|
|
6
6
|
abstract getStore<Item extends {
|
|
7
7
|
_id: string;
|
|
8
|
-
}>(storeName: string
|
|
8
|
+
}>(storeName: string): StoreState<Item>;
|
|
9
9
|
abstract fork(): ForkedDataStorage;
|
|
10
10
|
abstract getReadTransaction(): Promise<ReadTransaction>;
|
|
11
11
|
abstract getReadWriteTransaction(): Promise<ReadWriteTransaction>;
|
|
@@ -6,7 +6,7 @@ export declare class ForkedStoreState<Item extends {
|
|
|
6
6
|
master: StoreState<Item>;
|
|
7
7
|
protected changedItems: Map<string, Item | null>;
|
|
8
8
|
changes: StoreStateChange<Item>[];
|
|
9
|
-
constructor(storeName: string, dataStorage: DataStorage, master: StoreState<Item
|
|
9
|
+
constructor(storeName: string, dataStorage: DataStorage, master: StoreState<Item>);
|
|
10
10
|
applyChangeAndReturnEvent(change: StoreStateChange<Item>): Promise<{
|
|
11
11
|
from: Item | null;
|
|
12
12
|
to: Item | null;
|
|
@@ -5,7 +5,7 @@ export declare abstract class StoreState<Item extends {
|
|
|
5
5
|
}> {
|
|
6
6
|
storeName: string;
|
|
7
7
|
protected dataStorage: DataStorage;
|
|
8
|
-
|
|
8
|
+
deserialize?: ((data: any) => Item) | undefined;
|
|
9
9
|
protected listeners: Map<QueryListenerCallback<Item>, QueryListener<Item>>;
|
|
10
10
|
constructor(storeName: string, dataStorage: DataStorage, deserialize?: ((data: any) => Item) | undefined);
|
|
11
11
|
abstract applyChange(change: StoreStateChange<Item>): Promise<{
|
package/dist/index.js
CHANGED
|
@@ -55,7 +55,7 @@ class QueryCollectionResult {
|
|
|
55
55
|
this.result = result;
|
|
56
56
|
}
|
|
57
57
|
get(id) {
|
|
58
|
-
return this.result.find((r) => r._id === id);
|
|
58
|
+
return id ? this.result.find((r) => r._id === id) : undefined;
|
|
59
59
|
}
|
|
60
60
|
map(callbackfn) {
|
|
61
61
|
return this.result.map(callbackfn);
|
|
@@ -358,7 +358,7 @@ class ArcIndexedCollection extends ArcCollection {
|
|
|
358
358
|
if (!(name in this.indexes)) {
|
|
359
359
|
throw new Error(`Index "${name}" not found in collection "${this.name}"`);
|
|
360
360
|
}
|
|
361
|
-
return (data) => dataStorage.getStore(this.name
|
|
361
|
+
return (data) => dataStorage.getStore(this.name).findByIndex(name, data);
|
|
362
362
|
}
|
|
363
363
|
});
|
|
364
364
|
}
|
|
@@ -490,7 +490,7 @@ class StoreState {
|
|
|
490
490
|
this.deserialize = deserialize;
|
|
491
491
|
}
|
|
492
492
|
fork() {
|
|
493
|
-
return new ForkedStoreState(this.storeName, this.dataStorage, this
|
|
493
|
+
return new ForkedStoreState(this.storeName, this.dataStorage, this);
|
|
494
494
|
}
|
|
495
495
|
async set(item) {
|
|
496
496
|
const change = {
|
|
@@ -543,8 +543,8 @@ class ForkedStoreState extends StoreState {
|
|
|
543
543
|
master;
|
|
544
544
|
changedItems = new Map;
|
|
545
545
|
changes = [];
|
|
546
|
-
constructor(storeName, dataStorage, master
|
|
547
|
-
super(storeName, dataStorage, deserialize);
|
|
546
|
+
constructor(storeName, dataStorage, master) {
|
|
547
|
+
super(storeName, dataStorage, master.deserialize);
|
|
548
548
|
this.master = master;
|
|
549
549
|
}
|
|
550
550
|
async applyChangeAndReturnEvent(change) {
|
|
@@ -677,11 +677,11 @@ class ForkedDataStorage extends DataStorage {
|
|
|
677
677
|
getReadWriteTransaction() {
|
|
678
678
|
return this.master.getReadWriteTransaction();
|
|
679
679
|
}
|
|
680
|
-
getStore(storeName
|
|
680
|
+
getStore(storeName) {
|
|
681
681
|
if (this.stores.has(storeName))
|
|
682
682
|
return this.stores.get(storeName);
|
|
683
|
-
const masterStorage = this.master.getStore(storeName
|
|
684
|
-
const storage = new ForkedStoreState(storeName, this, masterStorage
|
|
683
|
+
const masterStorage = this.master.getStore(storeName);
|
|
684
|
+
const storage = new ForkedStoreState(storeName, this, masterStorage);
|
|
685
685
|
this.stores.set(storeName, storage);
|
|
686
686
|
return storage;
|
|
687
687
|
}
|
|
@@ -1240,28 +1240,18 @@ class RTCClient {
|
|
|
1240
1240
|
}
|
|
1241
1241
|
const { results, syncDate } = await response.json();
|
|
1242
1242
|
const pendingStoreChanges = [];
|
|
1243
|
+
const transaction = await this.storage.getReadWriteTransaction();
|
|
1243
1244
|
for (const { store, items } of results) {
|
|
1244
1245
|
this.syncProgressCallback?.({ store, size: items.length });
|
|
1245
|
-
const
|
|
1246
|
-
if (!storeState) {
|
|
1247
|
-
console.error(`Store ${store} not found`);
|
|
1248
|
-
continue;
|
|
1249
|
-
}
|
|
1250
|
-
const changes = items.map((item) => {
|
|
1246
|
+
for (const item of items) {
|
|
1251
1247
|
if (item.deleted) {
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
};
|
|
1248
|
+
await transaction.remove(store, item._id);
|
|
1249
|
+
} else {
|
|
1250
|
+
await transaction.set(store, item);
|
|
1256
1251
|
}
|
|
1257
|
-
|
|
1258
|
-
type: "set",
|
|
1259
|
-
data: item
|
|
1260
|
-
};
|
|
1261
|
-
});
|
|
1262
|
-
pendingStoreChanges.push(storeState.applyChanges(changes));
|
|
1252
|
+
}
|
|
1263
1253
|
}
|
|
1264
|
-
await
|
|
1254
|
+
await transaction.commit();
|
|
1265
1255
|
const stateStorage = this.storage.getStore("state");
|
|
1266
1256
|
await stateStorage.applyChanges([
|
|
1267
1257
|
{
|
package/package.json
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"types": "dist/index.d.ts",
|
|
6
6
|
"type": "module",
|
|
7
|
-
"version": "0.0.
|
|
7
|
+
"version": "0.0.22",
|
|
8
8
|
"private": false,
|
|
9
9
|
"author": "Przemysław Krasiński [arcote.tech]",
|
|
10
10
|
"description": "Arc is a framework designed to align code closely with business logic, streamlining development and enhancing productivity.",
|