@arcote.tech/arc 0.0.16 → 0.0.17
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/collection.d.ts +16 -12
- package/dist/collection/queries/abstract-collection-query.d.ts +7 -8
- package/dist/collection/queries/one-item.d.ts +1 -1
- package/dist/collection/queries/util.d.ts +2 -2
- package/dist/context/context.d.ts +4 -2
- package/dist/context/query.d.ts +6 -3
- package/dist/data-storage/ForkStoreState.d.ts +1 -1
- package/dist/data-storage/StoreState.d.ts +37 -22
- package/dist/data-storage/data-storage-forked.d.ts +2 -2
- package/dist/data-storage/data-storage-master.d.ts +5 -3
- package/dist/data-storage/data-storage.abstract.d.ts +47 -0
- package/dist/data-storage/data-storage.interface.d.ts +14 -5
- package/dist/data-storage/deep-merge.d.ts +6 -0
- package/dist/data-storage/index.d.ts +1 -1
- package/dist/data-storage/master-store-state.d.ts +26 -13
- package/dist/data-storage/store-state-fork.d.ts +1 -1
- package/dist/data-storage/store-state-master.d.ts +1 -1
- package/dist/data-storage/store-state.abstract.d.ts +7 -3
- package/dist/data-storage/store-state.d.ts +37 -22
- package/dist/elements/date.d.ts +1 -1
- package/dist/elements/index.d.ts +1 -0
- package/dist/elements/object copy.d.ts +29 -0
- package/dist/elements/object.d.ts +15 -0
- package/dist/elements/record.d.ts +19 -0
- package/dist/elements/state.d.ts +2 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +342 -43
- package/dist/rtc/index.d.ts +1 -0
- package/dist/rtc/messages.d.ts +3 -3
- package/dist/rtc/rtc.d.ts +4 -3
- package/dist/state/db.d.ts +1 -0
- package/dist/state/index.d.ts +1 -2
- package/dist/state/query-builder.d.ts +3 -2
- package/dist/state/query.d.ts +10 -17
- package/dist/state/state-change.d.ts +1 -0
- package/dist/state/state.d.ts +20 -16
- package/dist/state/util.d.ts +1 -0
- package/dist/utils/deep-merge.d.ts +6 -0
- package/dist/utils.d.ts +10 -1
- package/package.json +1 -1
|
@@ -1,23 +1,22 @@
|
|
|
1
1
|
import { ArcContextElement } from "../context/element";
|
|
2
2
|
import type { ArcIdAny } from "../elements/id";
|
|
3
3
|
import { type ArcObjectAny } from "../elements/object";
|
|
4
|
-
import { objectUtil, type util } from "../utils";
|
|
4
|
+
import { objectUtil, type DeepPartial, type util } from "../utils";
|
|
5
5
|
import type { DataStorage } from "../data-storage";
|
|
6
|
-
import type { ArcDefault } from "../elements/default";
|
|
7
6
|
import { ArcAllItemsQueryBuilder } from "./query-builders/all-items";
|
|
8
7
|
import { ArcIndexedItemsQueryBuilder } from "./query-builders/indexed";
|
|
9
8
|
import { ArcOneItemQueryBuilder } from "./query-builders/one-item";
|
|
10
9
|
export type CollectionItem<C extends ArcCollectionAny | ArcIndexedCollectionAny> = objectUtil.simplify<{
|
|
11
10
|
_id: string;
|
|
12
11
|
} & ReturnType<C["deserialize"]>>;
|
|
13
|
-
export type Deserialize<Id extends ArcIdAny, Schema extends ArcObjectAny
|
|
12
|
+
export type Deserialize<Id extends ArcIdAny, Schema extends ArcObjectAny> = objectUtil.simplify<{
|
|
14
13
|
_id: ReturnType<Id["deserialize"]>;
|
|
15
14
|
} & ReturnType<Schema["deserialize"]>>;
|
|
16
15
|
type CollectionQueryBuilder<T extends ArcCollection<any, any, any>> = {
|
|
17
16
|
all: () => ArcAllItemsQueryBuilder<T>;
|
|
18
17
|
one: (id: util.GetType<T["id"]> | undefined) => ArcOneItemQueryBuilder<T>;
|
|
19
18
|
};
|
|
20
|
-
type CollectionCommandContext<Id extends ArcIdAny, Schema extends ArcObjectAny
|
|
19
|
+
type CollectionCommandContext<Id extends ArcIdAny, Schema extends ArcObjectAny> = {
|
|
21
20
|
one: (id: util.GetType<Id>) => Deserialize<Id, Schema>;
|
|
22
21
|
remove: (id: util.GetType<Id>) => Promise<any>;
|
|
23
22
|
all: () => Deserialize<Id, Schema>[];
|
|
@@ -25,19 +24,24 @@ type CollectionCommandContext<Id extends ArcIdAny, Schema extends ArcObjectAny |
|
|
|
25
24
|
id: util.GetType<Id>;
|
|
26
25
|
}>;
|
|
27
26
|
set: (id: util.GetType<Id>, data: util.FirstArgument<Schema["serialize"]>) => Promise<any>;
|
|
28
|
-
|
|
27
|
+
edit: (id: util.GetType<Id>, editCallback: (item: Deserialize<Id, Schema>) => Promise<void> | void) => Promise<void>;
|
|
28
|
+
modify: (id: util.GetType<Id>, data: objectUtil.addQuestionMarks<DeepPartial<util.FirstArgument<Schema["serialize"]>>>) => Promise<any>;
|
|
29
29
|
};
|
|
30
|
-
export declare class ArcCollection<Name extends string, Id extends ArcIdAny, Schema extends ArcObjectAny
|
|
30
|
+
export declare class ArcCollection<Name extends string, Id extends ArcIdAny, Schema extends ArcObjectAny> extends ArcContextElement<{
|
|
31
31
|
type: "delete";
|
|
32
|
-
|
|
32
|
+
from: CollectionItem<ArcCollection<Name, Id, Schema>>;
|
|
33
33
|
} | {
|
|
34
34
|
type: "set";
|
|
35
|
-
|
|
35
|
+
to: CollectionItem<ArcCollection<Name, Id, Schema>>;
|
|
36
36
|
} | {
|
|
37
37
|
type: "modify";
|
|
38
38
|
from: CollectionItem<ArcCollection<Name, Id, Schema>>;
|
|
39
39
|
to: CollectionItem<ArcCollection<Name, Id, Schema>>;
|
|
40
|
-
changes: objectUtil.simplify<
|
|
40
|
+
changes: objectUtil.simplify<DeepPartial<util.FirstArgument<Schema["serialize"]>>>;
|
|
41
|
+
} | {
|
|
42
|
+
type: "mutate";
|
|
43
|
+
from: CollectionItem<ArcCollection<Name, Id, Schema>>;
|
|
44
|
+
to: CollectionItem<ArcCollection<Name, Id, Schema>>;
|
|
41
45
|
}> {
|
|
42
46
|
readonly name: Name;
|
|
43
47
|
readonly id: Id;
|
|
@@ -58,7 +62,7 @@ export declare class ArcCollection<Name extends string, Id extends ArcIdAny, Sch
|
|
|
58
62
|
[name: string]: Indexes[];
|
|
59
63
|
}>(indexes: I): ArcIndexedCollection<Name, Id, Schema, keyof ReturnType<Schema["deserialize"]>, I>;
|
|
60
64
|
}
|
|
61
|
-
export declare class ArcIndexedCollection<Name extends string, Id extends ArcIdAny, Schema extends ArcObjectAny
|
|
65
|
+
export declare class ArcIndexedCollection<Name extends string, Id extends ArcIdAny, Schema extends ArcObjectAny, Indexes extends keyof ReturnType<Schema["deserialize"]>, const I extends {
|
|
62
66
|
[name: string]: Indexes[];
|
|
63
67
|
}> extends ArcCollection<Name, Id, Schema> {
|
|
64
68
|
readonly indexes: I;
|
|
@@ -76,9 +80,9 @@ export declare class ArcIndexedCollection<Name extends string, Id extends ArcIdA
|
|
|
76
80
|
}
|
|
77
81
|
export type ArcCollectionAny = ArcCollection<any, any, any>;
|
|
78
82
|
export type ArcIndexedCollectionAny = ArcIndexedCollection<any, any, any, any, any>;
|
|
79
|
-
type ArcCollectionOptions<Id extends ArcIdAny, Schema extends ArcObjectAny
|
|
83
|
+
type ArcCollectionOptions<Id extends ArcIdAny, Schema extends ArcObjectAny> = {
|
|
80
84
|
sort?: (a: Deserialize<Id, Schema>, b: Deserialize<Id, Schema>) => number;
|
|
81
85
|
};
|
|
82
|
-
export declare function collection<Name extends string, Id extends ArcIdAny, Schema extends ArcObjectAny
|
|
86
|
+
export declare function collection<Name extends string, Id extends ArcIdAny, Schema extends ArcObjectAny>(name: Name, id: Id, schema: Schema, options?: ArcCollectionOptions<Id, Schema>): ArcCollection<Name, Id, Schema>;
|
|
83
87
|
export {};
|
|
84
88
|
//# sourceMappingURL=collection.d.ts.map
|
|
@@ -1,15 +1,14 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { ArcQuery, type ArcQueryListener } from "../../context/query";
|
|
2
2
|
import type { DataStorage, ListenerEvent, StoreState } from "../../data-storage";
|
|
3
3
|
import type { ArcCollectionAny, CollectionItem } from "../collection";
|
|
4
|
-
export
|
|
5
|
-
export declare abstract class ArcCollectionQuery<Collection extends ArcCollectionAny, Response> implements ArcQuery<Response> {
|
|
4
|
+
export declare abstract class ArcCollectionQuery<Collection extends ArcCollectionAny, Result> extends ArcQuery<Result> {
|
|
6
5
|
protected collection: Collection;
|
|
7
|
-
|
|
8
|
-
private
|
|
6
|
+
protected bindedChangeHandler: (changes: ListenerEvent<CollectionItem<Collection>>[]) => void;
|
|
7
|
+
private store;
|
|
9
8
|
constructor(collection: Collection);
|
|
10
|
-
run(dataStorage: DataStorage, listener?:
|
|
11
|
-
protected abstract onChange(change: ListenerEvent<CollectionItem<Collection>>):
|
|
12
|
-
protected abstract fetch(store: StoreState<CollectionItem<Collection>>): Promise<
|
|
9
|
+
run(dataStorage: DataStorage, listener?: ArcQueryListener<Result>): Promise<Result>;
|
|
10
|
+
protected abstract onChange(change: ListenerEvent<CollectionItem<Collection>>): Result | false;
|
|
11
|
+
protected abstract fetch(store: StoreState<CollectionItem<Collection>>): Promise<Result>;
|
|
13
12
|
protected changeHandler(changes: ListenerEvent<CollectionItem<Collection>>[]): void;
|
|
14
13
|
unsubscribe(): void;
|
|
15
14
|
private nextResult;
|
|
@@ -9,7 +9,7 @@ export declare class ArcOneItemQuery<Collection extends ArcCollectionAny> extend
|
|
|
9
9
|
_id: string;
|
|
10
10
|
} & ReturnType<Collection["deserialize"]> extends infer T ? { [KeyType in keyof T]: ({
|
|
11
11
|
_id: string;
|
|
12
|
-
} & ReturnType<Collection["deserialize"]>)[KeyType]; } : never) |
|
|
12
|
+
} & ReturnType<Collection["deserialize"]>)[KeyType]; } : never) | null;
|
|
13
13
|
protected fetch(store: StoreState<CollectionItem<Collection>>): Promise<({
|
|
14
14
|
_id: string;
|
|
15
15
|
} & ReturnType<Collection["deserialize"]> extends infer T ? { [KeyType in keyof T]: ({
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import type { ArcContextAny,
|
|
2
|
-
export type QueryBuilderFunctionResult<QB extends QueryFactoryFunction<ArcContextAny>> = ReturnType<ReturnType<QB>["toQuery"]>
|
|
1
|
+
import type { ArcContextAny, QueryFactoryFunction } from "../../context";
|
|
2
|
+
export type QueryBuilderFunctionResult<QB extends QueryFactoryFunction<ArcContextAny>> = ReturnType<ReturnType<QB>["toQuery"]>["lastResult"];
|
|
3
3
|
//# sourceMappingURL=util.d.ts.map
|
|
@@ -14,8 +14,10 @@ declare class ArcContext<const C extends ArcContextElementAny[], const Cmds exte
|
|
|
14
14
|
queryBuilder(): {
|
|
15
15
|
[Collection in C[number] as Collection["name"]]: ReturnType<Collection["queryBuilder"]>;
|
|
16
16
|
};
|
|
17
|
-
commandContext(dataStorage: DataStorage, publishEvent: (event: any) => Promise<void>): { [ContextElement in C[number] as ContextElement["name"]]: ReturnType<ContextElement["commandContext"]>; }
|
|
18
|
-
|
|
17
|
+
commandContext(client: string, dataStorage: DataStorage, publishEvent: (event: any) => Promise<void>): { [ContextElement in C[number] as ContextElement["name"]]: ReturnType<ContextElement["commandContext"]>; } & {
|
|
18
|
+
$client: string;
|
|
19
|
+
};
|
|
20
|
+
commandsClient(client: string, dataStorage: DataStorage, catchErrorCallback: (error: any) => void): CommandsClient<Cmds>;
|
|
19
21
|
}
|
|
20
22
|
export type ArcContextAny = ArcContext<ArcContextElementAny[], Commands<any>, any>;
|
|
21
23
|
export type ElementEvents<Element extends ArcContextElementAny> = Element extends ArcContextElement<any> ? Element["$event"] : never;
|
package/dist/context/query.d.ts
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
import type { DataStorage } from "../data-storage";
|
|
2
|
-
export
|
|
3
|
-
|
|
4
|
-
|
|
2
|
+
export type ArcQueryListener<Result> = (result: Result) => void;
|
|
3
|
+
export declare abstract class ArcQuery<Result> {
|
|
4
|
+
lastResult: Result;
|
|
5
|
+
listener?: ArcQueryListener<Result>;
|
|
6
|
+
abstract run(store: DataStorage, callback?: ArcQueryListener<Result>): Promise<Result>;
|
|
7
|
+
abstract unsubscribe(): void;
|
|
5
8
|
}
|
|
6
9
|
export type ArcQueryAny = ArcQuery<any>;
|
|
7
10
|
//# sourceMappingURL=query.d.ts.map
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { QueryListenerCallback, StoreStateChange } from "./data-storage";
|
|
2
|
-
import type { DataStorage } from "./data-storage.
|
|
2
|
+
import type { DataStorage } from "./data-storage.abstract";
|
|
3
3
|
import type { MasterStoreState } from "./store-state-master";
|
|
4
4
|
import { StoreState } from "./store-state.abstract";
|
|
5
5
|
export declare class ForkStoreState<
|
|
@@ -1,24 +1,39 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import {
|
|
2
|
+
ForkStoreState,
|
|
3
|
+
QueryListener,
|
|
4
|
+
QueryListenerCallback,
|
|
5
|
+
StoreStateChange,
|
|
6
|
+
} from "./data-storage";
|
|
7
|
+
import type { DataStorage } from "./data-storage.abstract";
|
|
8
|
+
export declare abstract class StoreState<
|
|
9
|
+
Item extends {
|
|
4
10
|
_id: string;
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
11
|
+
},
|
|
12
|
+
> {
|
|
13
|
+
storeName: string;
|
|
14
|
+
protected dataStorage: DataStorage;
|
|
15
|
+
protected deserialize?: ((data: any) => Item) | undefined;
|
|
16
|
+
protected listeners: Set<QueryListener<Item>>;
|
|
17
|
+
protected indexQueryCache: Map<string, Item[]>;
|
|
18
|
+
constructor(
|
|
19
|
+
storeName: string,
|
|
20
|
+
dataStorage: DataStorage,
|
|
21
|
+
deserialize?: ((data: any) => Item) | undefined
|
|
22
|
+
);
|
|
23
|
+
abstract applyChanges(changes: StoreStateChange<Item>[]): Promise<void>;
|
|
24
|
+
fork(): ForkStoreState<Item>;
|
|
25
|
+
findByIndex(
|
|
26
|
+
index: string,
|
|
27
|
+
data: any,
|
|
28
|
+
listener?: QueryListenerCallback<Item>
|
|
29
|
+
): Promise<Item[]>;
|
|
30
|
+
set(item: Item): void;
|
|
31
|
+
remove(id: string): void;
|
|
32
|
+
modify(id: string, data: Partial<Item>): void;
|
|
33
|
+
unsubscribe(listener: QueryListener<Item>): void;
|
|
34
|
+
private notifyListeners;
|
|
35
|
+
private getAllLocalItems;
|
|
36
|
+
private mergeWithLocalModifications;
|
|
37
|
+
private matchesIndex;
|
|
23
38
|
}
|
|
24
|
-
//# sourceMappingURL=StoreState.d.ts.map
|
|
39
|
+
//# sourceMappingURL=StoreState.d.ts.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { ReadTransaction, ReadWriteTransaction } from "../db";
|
|
2
|
-
import
|
|
2
|
+
import { DataStorage } from "./data-storage.abstract";
|
|
3
3
|
import { StoreState } from "./store-state.abstract";
|
|
4
|
-
export declare class ForkedDataStorage
|
|
4
|
+
export declare class ForkedDataStorage extends DataStorage {
|
|
5
5
|
private master;
|
|
6
6
|
private stores;
|
|
7
7
|
constructor(master: DataStorage);
|
|
@@ -2,19 +2,21 @@ import type { ArcContextAny } from "../context";
|
|
|
2
2
|
import type { DatabaseAdapter, ReadTransaction, ReadWriteTransaction } from "../db";
|
|
3
3
|
import type { RealTimeCommunicationAdapterFactory } from "../rtc/rtc";
|
|
4
4
|
import { ForkedDataStorage } from "./data-storage-forked";
|
|
5
|
-
import
|
|
5
|
+
import { DataStorage, type DataStorageChanges } from "./data-storage.abstract";
|
|
6
6
|
import type { StoreState } from "./store-state.abstract";
|
|
7
|
-
export declare class MasterDataStorage
|
|
7
|
+
export declare class MasterDataStorage extends DataStorage {
|
|
8
8
|
private dbAdapter;
|
|
9
9
|
private arcContext;
|
|
10
10
|
private stores;
|
|
11
11
|
private rtcAdapter;
|
|
12
|
-
constructor(dbAdapter: Promise<DatabaseAdapter
|
|
12
|
+
constructor(dbAdapter: Promise<DatabaseAdapter> | DatabaseAdapter, rtcAdapterFactory: RealTimeCommunicationAdapterFactory, arcContext: ArcContextAny);
|
|
13
13
|
getReadTransaction(): Promise<ReadTransaction>;
|
|
14
14
|
getReadWriteTransaction(): Promise<ReadWriteTransaction>;
|
|
15
15
|
getStore<Item extends {
|
|
16
16
|
_id: string;
|
|
17
17
|
}>(storeName: string): StoreState<Item>;
|
|
18
|
+
applyChanges(changes: DataStorageChanges[]): Promise<void[]>;
|
|
19
|
+
commitChanges(changes: DataStorageChanges[]): Promise<void>;
|
|
18
20
|
fork(): ForkedDataStorage;
|
|
19
21
|
sync(progressCallback: ({ store, size }: {
|
|
20
22
|
store: string;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { type Patch } from "mutative";
|
|
2
|
+
import type { ReadTransaction, ReadWriteTransaction } from "../db";
|
|
3
|
+
import type { ForkedDataStorage } from "./data-storage-forked";
|
|
4
|
+
import type { StoreState } from "./store-state.abstract";
|
|
5
|
+
export declare abstract class DataStorage {
|
|
6
|
+
abstract getStore<Item extends {
|
|
7
|
+
_id: string;
|
|
8
|
+
}>(storeName: string, deserialize?: (data: any) => Item): StoreState<Item>;
|
|
9
|
+
abstract fork(): ForkedDataStorage;
|
|
10
|
+
abstract getReadTransaction(): Promise<ReadTransaction>;
|
|
11
|
+
abstract getReadWriteTransaction(): Promise<ReadWriteTransaction>;
|
|
12
|
+
commitChanges(changes: DataStorageChanges[]): Promise<void>;
|
|
13
|
+
}
|
|
14
|
+
export type StoreStateChange<Item> = {
|
|
15
|
+
type: "set";
|
|
16
|
+
data: Item;
|
|
17
|
+
} | {
|
|
18
|
+
type: "delete";
|
|
19
|
+
id: string;
|
|
20
|
+
} | {
|
|
21
|
+
type: "modify";
|
|
22
|
+
id: string;
|
|
23
|
+
data: Partial<Item>;
|
|
24
|
+
} | {
|
|
25
|
+
type: "mutate";
|
|
26
|
+
id: string;
|
|
27
|
+
patches: Patch[];
|
|
28
|
+
};
|
|
29
|
+
export type QueryListenerCallback<Item> = (events: ListenerEvent<Item>[]) => void;
|
|
30
|
+
export type QueryListener<Item> = {
|
|
31
|
+
callback: QueryListenerCallback<Item>;
|
|
32
|
+
id?: string;
|
|
33
|
+
};
|
|
34
|
+
export type ListenerEvent<Item> = {
|
|
35
|
+
type: "set";
|
|
36
|
+
item: Item;
|
|
37
|
+
id: string;
|
|
38
|
+
} | {
|
|
39
|
+
type: "delete";
|
|
40
|
+
item: null;
|
|
41
|
+
id: string;
|
|
42
|
+
};
|
|
43
|
+
export type DataStorageChanges = {
|
|
44
|
+
store: string;
|
|
45
|
+
changes: StoreStateChange<any>[];
|
|
46
|
+
};
|
|
47
|
+
//# sourceMappingURL=data-storage.abstract.d.ts.map
|
|
@@ -1,13 +1,14 @@
|
|
|
1
|
+
import { type Patch } from "mutative";
|
|
1
2
|
import type { ReadTransaction, ReadWriteTransaction } from "../db";
|
|
2
3
|
import type { ForkedDataStorage } from "./data-storage-forked";
|
|
3
4
|
import type { StoreState } from "./store-state.abstract";
|
|
4
|
-
export
|
|
5
|
-
getStore<Item extends {
|
|
5
|
+
export declare abstract class DataStorage {
|
|
6
|
+
abstract getStore<Item extends {
|
|
6
7
|
_id: string;
|
|
7
8
|
}>(storeName: string, deserialize?: (data: any) => Item): StoreState<Item>;
|
|
8
|
-
fork(): ForkedDataStorage;
|
|
9
|
-
getReadTransaction(): Promise<ReadTransaction>;
|
|
10
|
-
getReadWriteTransaction(): Promise<ReadWriteTransaction>;
|
|
9
|
+
abstract fork(): ForkedDataStorage;
|
|
10
|
+
abstract getReadTransaction(): Promise<ReadTransaction>;
|
|
11
|
+
abstract getReadWriteTransaction(): Promise<ReadWriteTransaction>;
|
|
11
12
|
}
|
|
12
13
|
export type StoreStateChange<Item> = {
|
|
13
14
|
type: "set";
|
|
@@ -19,6 +20,10 @@ export type StoreStateChange<Item> = {
|
|
|
19
20
|
type: "modify";
|
|
20
21
|
id: string;
|
|
21
22
|
data: Partial<Item>;
|
|
23
|
+
} | {
|
|
24
|
+
type: "mutate";
|
|
25
|
+
id: string;
|
|
26
|
+
patches: Patch[];
|
|
22
27
|
};
|
|
23
28
|
export type QueryListenerCallback<Item> = (events: ListenerEvent<Item>[]) => void;
|
|
24
29
|
export type QueryListener<Item> = {
|
|
@@ -34,4 +39,8 @@ export type ListenerEvent<Item> = {
|
|
|
34
39
|
item: null;
|
|
35
40
|
id: string;
|
|
36
41
|
};
|
|
42
|
+
export type DataStorageChanges = {
|
|
43
|
+
store: string;
|
|
44
|
+
changes: StoreStateChange<any>[];
|
|
45
|
+
};
|
|
37
46
|
//# sourceMappingURL=data-storage.interface.d.ts.map
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export * from "./data-storage-forked";
|
|
2
2
|
export * from "./data-storage-master";
|
|
3
|
-
export * from "./data-storage.
|
|
3
|
+
export * from "./data-storage.abstract";
|
|
4
4
|
export * from "./store-state-fork";
|
|
5
5
|
export * from "./store-state-master";
|
|
6
6
|
export * from "./store-state.abstract";
|
|
@@ -1,17 +1,30 @@
|
|
|
1
1
|
import type { QueryListenerCallback, StoreStateChange } from "./data-storage";
|
|
2
|
-
import type { DataStorage } from "./data-storage.
|
|
2
|
+
import type { DataStorage } from "./data-storage.abstract";
|
|
3
3
|
import { StoreState } from "./store-state.abstract";
|
|
4
|
-
export declare class MasterStoreState<
|
|
4
|
+
export declare class MasterStoreState<
|
|
5
|
+
Item extends {
|
|
5
6
|
_id: string;
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
7
|
+
},
|
|
8
|
+
> extends StoreState<Item> {
|
|
9
|
+
protected items: Map<string, Item>;
|
|
10
|
+
protected isComplete: boolean;
|
|
11
|
+
constructor(
|
|
12
|
+
storeName: string,
|
|
13
|
+
dataStorage: DataStorage,
|
|
14
|
+
deserialize?: (data: any) => Item
|
|
15
|
+
);
|
|
16
|
+
applyChanges(changes: StoreStateChange<Item>[]): Promise<void>;
|
|
17
|
+
findById(
|
|
18
|
+
id: string,
|
|
19
|
+
listener?: QueryListenerCallback<Item>
|
|
20
|
+
): Promise<Item | undefined>;
|
|
21
|
+
findByIndex(
|
|
22
|
+
index: string,
|
|
23
|
+
data: any,
|
|
24
|
+
listener?: QueryListenerCallback<Item>
|
|
25
|
+
): Promise<Item[]>;
|
|
26
|
+
findAll(listener?: QueryListenerCallback<Item>): Promise<Item[]>;
|
|
27
|
+
private mergeWithLocalModifications;
|
|
28
|
+
private matchesIndex;
|
|
16
29
|
}
|
|
17
|
-
//# sourceMappingURL=master-store-state.d.ts.map
|
|
30
|
+
//# sourceMappingURL=master-store-state.d.ts.map
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { DataStorage, ListenerEvent, QueryListenerCallback, StoreStateChange } from "./data-storage.
|
|
1
|
+
import type { DataStorage, ListenerEvent, QueryListenerCallback, StoreStateChange } from "./data-storage.abstract";
|
|
2
2
|
import { StoreState } from "./store-state.abstract";
|
|
3
3
|
export declare class ForkedStoreState<Item extends {
|
|
4
4
|
_id: string;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { ReadWriteTransaction } from "../db";
|
|
2
|
-
import type { DataStorage, ListenerEvent, QueryListenerCallback, StoreStateChange } from "./data-storage.
|
|
2
|
+
import type { DataStorage, ListenerEvent, QueryListenerCallback, StoreStateChange } from "./data-storage.abstract";
|
|
3
3
|
import { StoreState } from "./store-state.abstract";
|
|
4
4
|
export declare class MasterStoreState<Item extends {
|
|
5
5
|
_id: string;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { DataStorage, ListenerEvent, QueryListener, QueryListenerCallback, StoreStateChange } from "./data-storage.
|
|
1
|
+
import type { DataStorage, ListenerEvent, QueryListener, QueryListenerCallback, StoreStateChange } from "./data-storage.abstract";
|
|
2
2
|
import { ForkedStoreState } from "./store-state-fork";
|
|
3
3
|
export declare abstract class StoreState<Item extends {
|
|
4
4
|
_id: string;
|
|
@@ -6,7 +6,7 @@ export declare abstract class StoreState<Item extends {
|
|
|
6
6
|
storeName: string;
|
|
7
7
|
protected dataStorage: DataStorage;
|
|
8
8
|
protected deserialize?: ((data: any) => Item) | undefined;
|
|
9
|
-
protected listeners:
|
|
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<{
|
|
12
12
|
from: Item | null;
|
|
@@ -23,7 +23,11 @@ export declare abstract class StoreState<Item extends {
|
|
|
23
23
|
from: Item | null;
|
|
24
24
|
to: Item | null;
|
|
25
25
|
}>;
|
|
26
|
-
|
|
26
|
+
mutate(id: string, editCallback: (item: Item) => Promise<void>): Promise<{
|
|
27
|
+
from: Item | null;
|
|
28
|
+
to: Item | null;
|
|
29
|
+
}>;
|
|
30
|
+
unsubscribe(listener: QueryListenerCallback<Item>): void;
|
|
27
31
|
protected notifyListeners(events: ListenerEvent<Item>[]): void;
|
|
28
32
|
}
|
|
29
33
|
//# sourceMappingURL=store-state.abstract.d.ts.map
|
|
@@ -1,24 +1,39 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import {
|
|
2
|
+
ForkStoreState,
|
|
3
|
+
QueryListener,
|
|
4
|
+
QueryListenerCallback,
|
|
5
|
+
StoreStateChange,
|
|
6
|
+
} from "./data-storage";
|
|
7
|
+
import type { DataStorage } from "./data-storage.abstract";
|
|
8
|
+
export declare abstract class StoreState<
|
|
9
|
+
Item extends {
|
|
4
10
|
_id: string;
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
11
|
+
},
|
|
12
|
+
> {
|
|
13
|
+
storeName: string;
|
|
14
|
+
protected dataStorage: DataStorage;
|
|
15
|
+
protected deserialize?: ((data: any) => Item) | undefined;
|
|
16
|
+
protected listeners: Set<QueryListener<Item>>;
|
|
17
|
+
protected indexQueryCache: Map<string, Item[]>;
|
|
18
|
+
constructor(
|
|
19
|
+
storeName: string,
|
|
20
|
+
dataStorage: DataStorage,
|
|
21
|
+
deserialize?: ((data: any) => Item) | undefined
|
|
22
|
+
);
|
|
23
|
+
abstract applyChanges(changes: StoreStateChange<Item>[]): Promise<void>;
|
|
24
|
+
fork(): ForkStoreState<Item>;
|
|
25
|
+
findByIndex(
|
|
26
|
+
index: string,
|
|
27
|
+
data: any,
|
|
28
|
+
listener?: QueryListenerCallback<Item>
|
|
29
|
+
): Promise<Item[]>;
|
|
30
|
+
set(item: Item): void;
|
|
31
|
+
remove(id: string): void;
|
|
32
|
+
modify(id: string, data: Partial<Item>): void;
|
|
33
|
+
unsubscribe(listener: QueryListener<Item>): void;
|
|
34
|
+
private notifyListeners;
|
|
35
|
+
private getAllLocalItems;
|
|
36
|
+
private mergeWithLocalModifications;
|
|
37
|
+
private matchesIndex;
|
|
23
38
|
}
|
|
24
|
-
//# sourceMappingURL=store-state.d.ts.map
|
|
39
|
+
//# sourceMappingURL=store-state.d.ts.map
|
package/dist/elements/date.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { ArcAbstract } from "./abstract";
|
|
|
2
2
|
export declare class ArcDate extends ArcAbstract {
|
|
3
3
|
constructor();
|
|
4
4
|
parse(value: string | number | Date): Date;
|
|
5
|
-
serialize(value: Date):
|
|
5
|
+
serialize(value: Date): number;
|
|
6
6
|
deserialize(value: string): Date;
|
|
7
7
|
}
|
|
8
8
|
export declare function date(): ArcDate;
|
package/dist/elements/index.d.ts
CHANGED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { objectUtil, type util } from "../utils";
|
|
2
|
+
import { ArcAbstract } from "./abstract";
|
|
3
|
+
import type { ArcElement } from "./element";
|
|
4
|
+
export declare type ArcRawShape = {
|
|
5
|
+
[k: string]: ArcElement;
|
|
6
|
+
};
|
|
7
|
+
export declare class ArcObject<E extends ArcRawShape> extends ArcAbstract {
|
|
8
|
+
private rawShape;
|
|
9
|
+
constructor(rawShape: E);
|
|
10
|
+
parse(value: {
|
|
11
|
+
[key in keyof E]: util.FirstArgument<E[key]["parse"]>;
|
|
12
|
+
}): {
|
|
13
|
+
[key in keyof E]: ReturnType<E[key]["parse"]>;
|
|
14
|
+
};
|
|
15
|
+
serialize(value: {
|
|
16
|
+
[key in keyof E]: util.FirstArgument<E[key]["serialize"]>;
|
|
17
|
+
}): {
|
|
18
|
+
[key in keyof E]: ReturnType<E[key]["serialize"]>;
|
|
19
|
+
};
|
|
20
|
+
deserialize(value: objectUtil.addQuestionMarks<{
|
|
21
|
+
[key in keyof E]: util.FirstArgument<E[key]["deserialize"]>;
|
|
22
|
+
}>): {
|
|
23
|
+
[key in keyof E]: ReturnType<E[key]["deserialize"]>;
|
|
24
|
+
};
|
|
25
|
+
deserializePath(path: string[], value: any): any;
|
|
26
|
+
}
|
|
27
|
+
export type ArcObjectAny = ArcObject<any>;
|
|
28
|
+
export declare function object<E extends ArcRawShape>(element: E): ArcObject<E>;
|
|
29
|
+
//# sourceMappingURL=object%20copy.d.ts.map
|
|
@@ -23,6 +23,21 @@ export declare class ArcObject<E extends ArcRawShape> extends ArcAbstract {
|
|
|
23
23
|
[key in keyof E]: ReturnType<E[key]["deserialize"]>;
|
|
24
24
|
};
|
|
25
25
|
deserializePath(path: string[], value: any): any;
|
|
26
|
+
parsePartial(value: Partial<{
|
|
27
|
+
[key in keyof E]: util.FirstArgument<E[key]["parse"]>;
|
|
28
|
+
}>): {
|
|
29
|
+
[key in keyof E]: ReturnType<E[key]["parse"]>;
|
|
30
|
+
};
|
|
31
|
+
deserializePartial(value: Partial<{
|
|
32
|
+
[key in keyof E]: util.FirstArgument<E[key]["deserialize"]>;
|
|
33
|
+
}>): {
|
|
34
|
+
[key in keyof E]: ReturnType<E[key]["deserialize"]>;
|
|
35
|
+
};
|
|
36
|
+
serializePartial(value: Partial<{
|
|
37
|
+
[key in keyof E]: util.FirstArgument<E[key]["serialize"]>;
|
|
38
|
+
}>): {
|
|
39
|
+
[key in keyof E]: ReturnType<E[key]["serialize"]>;
|
|
40
|
+
};
|
|
26
41
|
}
|
|
27
42
|
export type ArcObjectAny = ArcObject<any>;
|
|
28
43
|
export declare function object<E extends ArcRawShape>(element: E): ArcObject<E>;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { type util } from "../utils";
|
|
2
|
+
import { ArcAbstract } from "./abstract";
|
|
3
|
+
import type { ArcElement } from "./element";
|
|
4
|
+
import type { ArcId } from "./id";
|
|
5
|
+
import type { ArcNumber } from "./number";
|
|
6
|
+
import type { ArcString } from "./string";
|
|
7
|
+
type ArcKey = ArcString | ArcNumber | ArcId<any>;
|
|
8
|
+
export declare class ArcRecord<Key extends ArcKey, E extends ArcElement> extends ArcAbstract {
|
|
9
|
+
private key;
|
|
10
|
+
private element;
|
|
11
|
+
constructor(key: Key, element: E);
|
|
12
|
+
parse(value: Record<util.FirstArgument<Key["parse"]>, util.FirstArgument<E["parse"]>>): Record<ReturnType<Key["parse"]>, ReturnType<E["parse"]>>;
|
|
13
|
+
serialize(value: Record<ReturnType<Key["serialize"]>, ReturnType<E["serialize"]>>): Record<ReturnType<Key["serialize"]>, ReturnType<E["serialize"]>>;
|
|
14
|
+
deserialize(value: Record<ReturnType<Key["deserialize"]>, ReturnType<E["deserialize"]>>): Record<ReturnType<Key["deserialize"]>, ReturnType<E["deserialize"]>>;
|
|
15
|
+
}
|
|
16
|
+
export type ArcRecordAny = ArcRecord<any, any>;
|
|
17
|
+
export declare function record<Key extends ArcKey, E extends ArcElement>(key: Key, element: E): ArcRecord<Key, E>;
|
|
18
|
+
export {};
|
|
19
|
+
//# sourceMappingURL=record.d.ts.map
|