@arcote.tech/arc 0.0.13 → 0.0.15
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-change.d.ts +1 -0
- package/dist/collection/collection.d.ts +35 -26
- package/dist/collection/db.d.ts +11 -12
- package/dist/collection/index.d.ts +1 -1
- package/dist/collection/queries/abstract-collection-query.d.ts +11 -14
- package/dist/collection/queries/abstract-many-items.d.ts +22 -13
- package/dist/collection/queries/all-items.d.ts +4 -3
- package/dist/collection/queries/indexed.d.ts +8 -8
- package/dist/collection/queries/one-item.d.ts +14 -6
- package/dist/collection/queries/util.d.ts +3 -6
- package/dist/collection/query-builders/abstract-many-items.d.ts +6 -6
- package/dist/collection/query-builders/all-items.d.ts +1 -0
- package/dist/collection/query-builders/indexed.d.ts +1 -0
- package/dist/collection/query-builders/one-item.d.ts +1 -0
- package/dist/context/commands.d.ts +3 -1
- package/dist/context/context.d.ts +13 -23
- package/dist/context/element.d.ts +7 -5
- package/dist/context/index.d.ts +4 -0
- package/dist/context/query-builders.d.ts +5 -2
- package/dist/context/query.d.ts +6 -2
- package/dist/data-storage/DataStorage.d.ts +11 -0
- package/dist/data-storage/ForkStoreState.d.ts +32 -0
- package/dist/data-storage/StoreState.d.ts +24 -0
- package/dist/data-storage/data-storage-forked.d.ts +16 -0
- package/dist/data-storage/data-storage-master.d.ts +24 -0
- package/dist/data-storage/data-storage.d.ts +2 -0
- package/dist/data-storage/data-storage.interface.d.ts +37 -0
- package/dist/data-storage/index.d.ts +7 -0
- package/dist/data-storage/master-store-state.d.ts +17 -0
- package/dist/data-storage/store-state-fork.d.ts +15 -0
- package/dist/data-storage/store-state-master.d.ts +14 -0
- package/dist/data-storage/store-state.abstract.d.ts +22 -0
- package/dist/data-storage/store-state.d.ts +24 -0
- package/dist/db/index.d.ts +2 -0
- package/dist/db/interface.d.ts +17 -0
- package/dist/elements/abstract-primitive.d.ts +1 -0
- package/dist/elements/abstract.d.ts +1 -0
- package/dist/elements/array.d.ts +1 -0
- package/dist/elements/boolean.d.ts +1 -0
- package/dist/elements/branded.d.ts +1 -0
- package/dist/elements/date.d.ts +1 -0
- package/dist/elements/default.d.ts +1 -0
- package/dist/elements/element.d.ts +1 -0
- package/dist/elements/id.d.ts +1 -0
- package/dist/elements/index.d.ts +1 -0
- package/dist/elements/number.d.ts +1 -0
- package/dist/elements/object.d.ts +1 -0
- package/dist/elements/optional.d.ts +1 -0
- package/dist/elements/string-enum.d.ts +1 -0
- package/dist/elements/string.d.ts +1 -0
- package/dist/elements/tests/object.test.d.ts +2 -0
- package/dist/index.d.ts +3 -1
- package/dist/index.js +452 -397
- package/dist/model/model.d.ts +18 -19
- package/dist/rtc/client.d.ts +2 -1
- package/dist/rtc/deserializeChanges.d.ts +1 -0
- package/dist/rtc/index.d.ts +1 -0
- package/dist/rtc/messages.d.ts +6 -5
- package/dist/rtc/rtc.d.ts +10 -0
- package/dist/state/db.d.ts +14 -0
- package/dist/state/index.d.ts +3 -0
- package/dist/state/query-builder.d.ts +8 -0
- package/dist/state/query.d.ts +22 -0
- package/dist/state/state-change.d.ts +13 -0
- package/dist/state/state.d.ts +28 -0
- package/dist/state/util.d.ts +2 -0
- package/dist/utils.d.ts +17 -14
- package/package.json +2 -2
- package/dist/collection/in-memory-db-proxy.d.ts +0 -10
- package/dist/elements/instanceOf.d.ts +0 -19
- package/dist/elements/or.d.ts +0 -11
- package/dist/elements/recurent.d.ts +0 -20
- package/dist/model/index.d.ts +0 -4
- package/dist/model/query-builder.d.ts +0 -3
- package/dist/model/rtc.d.ts +0 -6
- package/dist/model/submodel.d.ts +0 -23
|
@@ -1,17 +1,34 @@
|
|
|
1
|
-
import type { GetDraft } from "../context/context";
|
|
2
1
|
import type { ArcContextElement } from "../context/element";
|
|
3
2
|
import type { ArcIdAny } from "../elements/id";
|
|
4
3
|
import { type ArcObjectAny } from "../elements/object";
|
|
5
|
-
import
|
|
4
|
+
import { objectUtil, type util } from "../utils";
|
|
6
5
|
import type { CollectionChange } from "./collection-change";
|
|
7
|
-
import type {
|
|
6
|
+
import type { DataStorage } from "../data-storage";
|
|
7
|
+
import type { ArcDefault } from "../elements/default";
|
|
8
8
|
import { ArcAllItemsQueryBuilder } from "./query-builders/all-items";
|
|
9
9
|
import { ArcIndexedItemsQueryBuilder } from "./query-builders/indexed";
|
|
10
10
|
import { ArcOneItemQueryBuilder } from "./query-builders/one-item";
|
|
11
|
-
export type
|
|
11
|
+
export type CollectionItem<C extends ArcCollectionAny | ArcIndexedCollectionAny> = objectUtil.simplify<{
|
|
12
|
+
_id: string;
|
|
13
|
+
} & ReturnType<C["deserialize"]>>;
|
|
14
|
+
export type Deserialize<Id extends ArcIdAny, Schema extends ArcObjectAny | ArcDefault<ArcObjectAny>> = objectUtil.simplify<{
|
|
12
15
|
_id: ReturnType<Id["deserialize"]>;
|
|
13
16
|
} & ReturnType<Schema["deserialize"]>>;
|
|
14
|
-
|
|
17
|
+
type CollectionQueryBuilder<T extends ArcCollection<any, any, any>> = {
|
|
18
|
+
all: () => ArcAllItemsQueryBuilder<T>;
|
|
19
|
+
one: (id: util.GetType<T["id"]> | undefined) => ArcOneItemQueryBuilder<T>;
|
|
20
|
+
};
|
|
21
|
+
type CollectionCommandContext<Id extends ArcIdAny, Schema extends ArcObjectAny | ArcDefault<ArcObjectAny>> = {
|
|
22
|
+
one: (id: util.GetType<Id>) => Deserialize<Id, Schema>;
|
|
23
|
+
remove: (id: util.GetType<Id>) => Promise<any>;
|
|
24
|
+
all: () => Deserialize<Id, Schema>[];
|
|
25
|
+
add: (data: objectUtil.addQuestionMarks<util.FirstArgument<Schema["serialize"]>>) => Promise<{
|
|
26
|
+
id: util.GetType<Id>;
|
|
27
|
+
}>;
|
|
28
|
+
set: (id: util.GetType<Id>, data: util.FirstArgument<Schema["serialize"]>) => Promise<any>;
|
|
29
|
+
modify: (id: util.GetType<Id>, data: objectUtil.addQuestionMarks<Partial<util.FirstArgument<Schema["serialize"]>>>) => Promise<any>;
|
|
30
|
+
};
|
|
31
|
+
export declare class ArcCollection<Name extends string, Id extends ArcIdAny, Schema extends ArcObjectAny | ArcDefault<ArcObjectAny>> implements ArcContextElement<CollectionChange, CollectionChange> {
|
|
15
32
|
readonly name: Name;
|
|
16
33
|
readonly id: Id;
|
|
17
34
|
readonly schema: Schema;
|
|
@@ -25,32 +42,23 @@ declare class ArcCollection<Name extends string, Id extends ArcIdAny, Schema ext
|
|
|
25
42
|
deserialize(data: objectUtil.simplify<{
|
|
26
43
|
_id: util.FirstArgument<Id["deserialize"]>;
|
|
27
44
|
} & objectUtil.addQuestionMarks<util.FirstArgument<Schema["deserialize"]>>>): Deserialize<Id, Schema>;
|
|
28
|
-
queryBuilder():
|
|
29
|
-
|
|
30
|
-
one: (id: util.GetType<Id> | undefined) => ArcOneItemQueryBuilder<ArcCollection<Name, Id, Schema>>;
|
|
31
|
-
};
|
|
32
|
-
commandContext(transaction: ReadTransaction, changes: CollectionChange[], getDraft: GetDraft<any>): {
|
|
33
|
-
one: (id: util.GetType<Id>) => Deserialize<Id, Schema>;
|
|
34
|
-
remove: (id: util.GetType<Id>) => Promise<any>;
|
|
35
|
-
add: (data: objectUtil.addQuestionMarks<util.FirstArgument<Schema["serialize"]>>) => Promise<{
|
|
36
|
-
id: util.GetType<Id>;
|
|
37
|
-
}>;
|
|
38
|
-
set: (id: util.GetType<Id>, data: util.FirstArgument<Schema["serialize"]>) => Promise<any>;
|
|
39
|
-
};
|
|
40
|
-
applyChange(transaction: ReadWriteTransaction, change: CollectionChange, events: CollectionChange[]): Promise<void>;
|
|
45
|
+
queryBuilder(): CollectionQueryBuilder<ArcCollection<Name, Id, Schema>>;
|
|
46
|
+
commandContext(dataStorage: DataStorage): CollectionCommandContext<Id, Schema>;
|
|
41
47
|
indexBy<Indexes extends keyof ReturnType<Schema["deserialize"]>, const I extends {
|
|
42
48
|
[name: string]: Indexes[];
|
|
43
49
|
}>(indexes: I): ArcIndexedCollection<Name, Id, Schema, keyof ReturnType<Schema["deserialize"]>, I>;
|
|
44
50
|
}
|
|
45
|
-
export declare class ArcIndexedCollection<Name extends string, Id extends ArcIdAny, Schema extends ArcObjectAny
|
|
51
|
+
export declare class ArcIndexedCollection<Name extends string, Id extends ArcIdAny, Schema extends ArcObjectAny | ArcDefault<ArcObjectAny>, Indexes extends keyof ReturnType<Schema["deserialize"]>, const I extends {
|
|
46
52
|
[name: string]: Indexes[];
|
|
47
|
-
}> extends ArcCollection<Name, Id, Schema>
|
|
53
|
+
}> extends ArcCollection<Name, Id, Schema> {
|
|
48
54
|
readonly indexes: I;
|
|
49
55
|
constructor(name: Name, id: Id, schema: Schema, options: ArcCollectionOptions<Id, Schema>, indexes: I);
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
56
|
+
commandContext(dataStorage: DataStorage): CollectionCommandContext<Id, Schema> & {
|
|
57
|
+
[func in keyof I]: (args: {
|
|
58
|
+
[Key in I[func][number]]: util.GetType<Schema>[Key];
|
|
59
|
+
}) => Deserialize<Id, Schema>[];
|
|
60
|
+
};
|
|
61
|
+
queryBuilder(): CollectionQueryBuilder<ArcCollection<Name, Id, Schema>> & {
|
|
54
62
|
[func in keyof I]: (args: {
|
|
55
63
|
[Key in I[func][number]]: util.GetType<Schema>[Key];
|
|
56
64
|
}) => ArcIndexedItemsQueryBuilder<ArcIndexedCollection<Name, Id, Schema, Indexes, I>>;
|
|
@@ -58,8 +66,9 @@ export declare class ArcIndexedCollection<Name extends string, Id extends ArcIdA
|
|
|
58
66
|
}
|
|
59
67
|
export type ArcCollectionAny = ArcCollection<any, any, any>;
|
|
60
68
|
export type ArcIndexedCollectionAny = ArcIndexedCollection<any, any, any, any, any>;
|
|
61
|
-
type ArcCollectionOptions<Id extends ArcIdAny, Schema extends ArcObjectAny
|
|
69
|
+
type ArcCollectionOptions<Id extends ArcIdAny, Schema extends ArcObjectAny | ArcDefault<ArcObjectAny>> = {
|
|
62
70
|
sort?: (a: Deserialize<Id, Schema>, b: Deserialize<Id, Schema>) => number;
|
|
63
71
|
};
|
|
64
|
-
export declare function collection<Name extends string, Id extends ArcIdAny, Schema extends ArcObjectAny
|
|
72
|
+
export declare function collection<Name extends string, Id extends ArcIdAny, Schema extends ArcObjectAny | ArcDefault<ArcObjectAny>>(name: Name, id: Id, schema: Schema, options?: ArcCollectionOptions<Id, Schema>): ArcCollection<Name, Id, Schema>;
|
|
65
73
|
export {};
|
|
74
|
+
//# sourceMappingURL=collection.d.ts.map
|
package/dist/collection/db.d.ts
CHANGED
|
@@ -1,18 +1,17 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { ReadTransaction, ReadWriteTransaction } from "../db/interface";
|
|
2
2
|
import type { util } from "../utils";
|
|
3
3
|
import type { ArcCollectionAny, ArcIndexedCollectionAny } from "./collection";
|
|
4
|
-
export
|
|
4
|
+
export declare class CollectionReadTransaction {
|
|
5
|
+
protected dbTransaction: ReadTransaction;
|
|
6
|
+
constructor(dbTransaction: ReadTransaction);
|
|
7
|
+
findById<C extends ArcCollectionAny>(collection: C, id: util.GetType<C["id"]>): Promise<ReturnType<C["deserialize"]> | undefined>;
|
|
8
|
+
findByIndex<C extends ArcIndexedCollectionAny>(collection: C, index: string, data: any): Promise<ReturnType<C["deserialize"]>[]>;
|
|
9
|
+
findAll<C extends ArcCollectionAny>(collection: C): Promise<ReturnType<C["deserialize"]>[]>;
|
|
10
|
+
}
|
|
11
|
+
export declare class CollectionReadWriteTransaction extends CollectionReadTransaction {
|
|
12
|
+
protected dbTransaction: ReadWriteTransaction;
|
|
13
|
+
constructor(dbTransaction: ReadWriteTransaction);
|
|
5
14
|
remove<C extends ArcCollectionAny>(collection: C, id: util.GetType<C["id"]>): Promise<void>;
|
|
6
15
|
set<C extends ArcCollectionAny>(collection: C, data: util.CollectionItemWithId<C>): Promise<void>;
|
|
7
16
|
commit(): Promise<void>;
|
|
8
17
|
}
|
|
9
|
-
export interface ReadTransaction {
|
|
10
|
-
findById<C extends ArcCollectionAny>(collection: C, id: util.GetType<C["id"]>): Promise<util.CollectionItemWithId<C> | undefined>;
|
|
11
|
-
findByIndex<C extends ArcIndexedCollectionAny>(collection: C, index: string, data: any): Promise<util.CollectionItemWithId<C>[]>;
|
|
12
|
-
findAll<C extends ArcCollectionAny>(collection: C): Promise<util.CollectionItemWithId<C>[]>;
|
|
13
|
-
}
|
|
14
|
-
export interface DatabaseAdapter {
|
|
15
|
-
readWriteTransaction(collections: ArcCollectionAny[]): ReadWriteTransaction;
|
|
16
|
-
readTransaction(collections: ArcCollectionAny[]): ReadTransaction;
|
|
17
|
-
}
|
|
18
|
-
export type DBAdapterFactory = (context: ArcContextAny) => Promise<DatabaseAdapter>;
|
|
@@ -1,20 +1,17 @@
|
|
|
1
|
-
import { Subject } from "rxjs";
|
|
2
1
|
import type { ArcQuery } from "../../context/query";
|
|
3
|
-
import type {
|
|
4
|
-
import type {
|
|
5
|
-
|
|
6
|
-
export declare abstract class ArcCollectionQuery<Collection extends ArcCollectionAny, Response> implements ArcQuery {
|
|
2
|
+
import type { DataStorage, ListenerEvent, StoreState } from "../../data-storage";
|
|
3
|
+
import type { ArcCollectionAny, CollectionItem } from "../collection";
|
|
4
|
+
export type CollectionQueryListener<Response> = (result: Response) => void;
|
|
5
|
+
export declare abstract class ArcCollectionQuery<Collection extends ArcCollectionAny, Response> implements ArcQuery<Response> {
|
|
7
6
|
protected collection: Collection;
|
|
8
|
-
|
|
9
|
-
private
|
|
10
|
-
private subscriptions;
|
|
7
|
+
lastResult?: Response;
|
|
8
|
+
private listener?;
|
|
11
9
|
constructor(collection: Collection);
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
protected abstract
|
|
15
|
-
protected
|
|
16
|
-
private changeHandler;
|
|
10
|
+
run(dataStorage: DataStorage, listener?: CollectionQueryListener<Response>): Promise<Response>;
|
|
11
|
+
protected abstract onChange(change: ListenerEvent<CollectionItem<Collection>>): Response | false;
|
|
12
|
+
protected abstract fetch(store: StoreState<CollectionItem<Collection>>): Promise<Response>;
|
|
13
|
+
protected changeHandler(changes: ListenerEvent<CollectionItem<Collection>>[]): void;
|
|
17
14
|
unsubscribe(): void;
|
|
18
15
|
private nextResult;
|
|
19
|
-
isUnsubscribed(): boolean;
|
|
20
16
|
}
|
|
17
|
+
//# sourceMappingURL=abstract-collection-query.d.ts.map
|
|
@@ -1,20 +1,29 @@
|
|
|
1
|
+
import type { ListenerEvent } from "../../data-storage";
|
|
1
2
|
import type { util } from "../../utils";
|
|
2
|
-
import type { ArcCollectionAny } from "../collection";
|
|
3
|
-
import type { CollectionChangesWithoutMutate } from "../collection-change";
|
|
3
|
+
import type { ArcCollectionAny, CollectionItem } from "../collection";
|
|
4
4
|
import { ArcCollectionQuery } from "./abstract-collection-query";
|
|
5
5
|
export declare class QueryCollectionResult<C extends ArcCollectionAny> {
|
|
6
6
|
private result;
|
|
7
|
-
constructor(result:
|
|
8
|
-
get(id: util.GetType<C["id"]>):
|
|
9
|
-
|
|
10
|
-
|
|
7
|
+
constructor(result: CollectionItem<C>[]);
|
|
8
|
+
get(id: util.GetType<C["id"]>): ({
|
|
9
|
+
_id: string;
|
|
10
|
+
} & ReturnType<C["deserialize"]> extends infer T ? { [KeyType in keyof T]: ({
|
|
11
|
+
_id: string;
|
|
12
|
+
} & ReturnType<C["deserialize"]>)[KeyType]; } : never) | undefined;
|
|
13
|
+
map<U>(callbackfn: (value: CollectionItem<C>, index: number, array: CollectionItem<C>[]) => U): U[];
|
|
14
|
+
toArray(): ({
|
|
15
|
+
_id: string;
|
|
16
|
+
} & ReturnType<C["deserialize"]> extends infer T ? { [KeyType in keyof T]: ({
|
|
17
|
+
_id: string;
|
|
18
|
+
} & ReturnType<C["deserialize"]>)[KeyType]; } : never)[];
|
|
11
19
|
}
|
|
12
20
|
export declare abstract class ArcManyItemsQuery<Collection extends ArcCollectionAny> extends ArcCollectionQuery<Collection, QueryCollectionResult<Collection>> {
|
|
13
|
-
protected filterFn?: ((item:
|
|
14
|
-
protected sortFn?: ((a:
|
|
15
|
-
constructor(collection: Collection, filterFn?: ((item:
|
|
16
|
-
protected onChange(change:
|
|
17
|
-
protected createResult(result:
|
|
18
|
-
protected createFiltredResult(result:
|
|
19
|
-
protected checkItem(item:
|
|
21
|
+
protected filterFn?: ((item: CollectionItem<Collection>) => boolean) | undefined;
|
|
22
|
+
protected sortFn?: ((a: CollectionItem<Collection>, b: CollectionItem<Collection>) => number) | undefined;
|
|
23
|
+
constructor(collection: Collection, filterFn?: ((item: CollectionItem<Collection>) => boolean) | undefined, sortFn?: ((a: CollectionItem<Collection>, b: CollectionItem<Collection>) => number) | undefined);
|
|
24
|
+
protected onChange(change: ListenerEvent<CollectionItem<Collection>>): false | QueryCollectionResult<Collection>;
|
|
25
|
+
protected createResult(result: CollectionItem<Collection>[]): QueryCollectionResult<Collection>;
|
|
26
|
+
protected createFiltredResult(result: CollectionItem<Collection>[]): QueryCollectionResult<Collection>;
|
|
27
|
+
protected checkItem(item: CollectionItem<Collection>): boolean;
|
|
20
28
|
}
|
|
29
|
+
//# sourceMappingURL=abstract-many-items.d.ts.map
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import type
|
|
1
|
+
import type { StoreState } from "../../data-storage";
|
|
2
|
+
import { type ArcCollectionAny, type CollectionItem } from "../collection";
|
|
3
3
|
import { ArcManyItemsQuery } from "./abstract-many-items";
|
|
4
4
|
export declare class ArcAllItemsQuery<Collection extends ArcCollectionAny> extends ArcManyItemsQuery<Collection> {
|
|
5
|
-
protected fetch(
|
|
5
|
+
protected fetch(store: StoreState<CollectionItem<Collection>>): Promise<import("./abstract-many-items").QueryCollectionResult<Collection>>;
|
|
6
6
|
}
|
|
7
|
+
//# sourceMappingURL=all-items.d.ts.map
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type { ArcIndexedCollectionAny } from "../collection";
|
|
3
|
-
import type { ReadTransaction } from "../db";
|
|
1
|
+
import type { StoreState } from "../../data-storage";
|
|
2
|
+
import type { ArcIndexedCollectionAny, CollectionItem } from "../collection";
|
|
4
3
|
import { ArcManyItemsQuery } from "./abstract-many-items";
|
|
5
4
|
export declare class ArcIndexedItemsQuery<Collection extends ArcIndexedCollectionAny> extends ArcManyItemsQuery<Collection> {
|
|
6
5
|
private index;
|
|
7
6
|
private data;
|
|
8
|
-
protected filterFn?: ((item:
|
|
9
|
-
protected sortFn?: ((a:
|
|
10
|
-
constructor(collection: Collection, index: string, data: any, filterFn?: ((item:
|
|
11
|
-
protected checkItem(item:
|
|
12
|
-
protected fetch(
|
|
7
|
+
protected filterFn?: ((item: CollectionItem<Collection>) => boolean) | undefined;
|
|
8
|
+
protected sortFn?: ((a: CollectionItem<Collection>, b: CollectionItem<Collection>) => number) | undefined;
|
|
9
|
+
constructor(collection: Collection, index: string, data: any, filterFn?: ((item: CollectionItem<Collection>) => boolean) | undefined, sortFn?: ((a: CollectionItem<Collection>, b: CollectionItem<Collection>) => number) | undefined);
|
|
10
|
+
protected checkItem(item: CollectionItem<Collection>): boolean;
|
|
11
|
+
protected fetch(store: StoreState<CollectionItem<Collection>>): Promise<import("./abstract-many-items").QueryCollectionResult<Collection>>;
|
|
13
12
|
}
|
|
13
|
+
//# sourceMappingURL=indexed.d.ts.map
|
|
@@ -1,11 +1,19 @@
|
|
|
1
|
+
import type { ListenerEvent, StoreState } from "../../data-storage";
|
|
1
2
|
import type { util } from "../../utils";
|
|
2
|
-
import type { ArcCollectionAny } from "../collection";
|
|
3
|
-
import type { CollectionChange } from "../collection-change";
|
|
4
|
-
import type { ReadTransaction } from "../db";
|
|
3
|
+
import type { ArcCollectionAny, CollectionItem } from "../collection";
|
|
5
4
|
import { ArcCollectionQuery } from "./abstract-collection-query";
|
|
6
|
-
export declare class ArcOneItemQuery<Collection extends ArcCollectionAny> extends ArcCollectionQuery<Collection,
|
|
5
|
+
export declare class ArcOneItemQuery<Collection extends ArcCollectionAny> extends ArcCollectionQuery<Collection, CollectionItem<Collection> | null | undefined> {
|
|
7
6
|
private id;
|
|
8
7
|
constructor(collection: Collection, id: util.GetType<Collection["id"]>);
|
|
9
|
-
protected onChange(change:
|
|
10
|
-
|
|
8
|
+
protected onChange(change: ListenerEvent<CollectionItem<Collection>>): false | ({
|
|
9
|
+
_id: string;
|
|
10
|
+
} & ReturnType<Collection["deserialize"]> extends infer T ? { [KeyType in keyof T]: ({
|
|
11
|
+
_id: string;
|
|
12
|
+
} & ReturnType<Collection["deserialize"]>)[KeyType]; } : never) | undefined;
|
|
13
|
+
protected fetch(store: StoreState<CollectionItem<Collection>>): Promise<({
|
|
14
|
+
_id: string;
|
|
15
|
+
} & ReturnType<Collection["deserialize"]> extends infer T ? { [KeyType in keyof T]: ({
|
|
16
|
+
_id: string;
|
|
17
|
+
} & ReturnType<Collection["deserialize"]>)[KeyType]; } : never) | null | undefined>;
|
|
11
18
|
}
|
|
19
|
+
//# sourceMappingURL=one-item.d.ts.map
|
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
import type { ArcContextAny } from "../../context";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
import type { ArcCollectionAny, ArcIndexedCollectionAny } from "../collection";
|
|
5
|
-
import type { ArcCollectionQuery } from "./abstract-collection-query";
|
|
6
|
-
export type GetAnyCollectionQueryResult<QB extends QueryFactoryFunction<ArcContextAny>> = ReturnType<ReturnType<QB>["toQuery"]> extends ArcCollectionQuery<ArcCollectionAny | ArcIndexedCollectionAny, any> ? objectUtil.simplify<ReturnType<ReturnType<ReturnType<QB>["toQuery"]>["getLastResult"]>> : never;
|
|
1
|
+
import type { ArcContextAny, ArcQuery, QueryFactoryFunction } from "../../context";
|
|
2
|
+
export type QueryBuilderFunctionResult<QB extends QueryFactoryFunction<ArcContextAny>> = ReturnType<ReturnType<QB>["toQuery"]> extends ArcQuery<infer Result> ? Result : never;
|
|
3
|
+
//# sourceMappingURL=util.d.ts.map
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { ArcQueryBuilder } from "../../context/query-builders";
|
|
2
|
-
import type
|
|
3
|
-
|
|
4
|
-
type SortComparator<C extends ArcCollectionAny> = ((a: util.CollectionItemWithId<C>, b: util.CollectionItemWithId<C>) => number) | Array<[keyof util.CollectionItemWithId<C>, "ASC" | "DESC"]>;
|
|
2
|
+
import { type ArcCollectionAny, type CollectionItem } from "../collection";
|
|
3
|
+
type SortComparator<C extends ArcCollectionAny> = ((a: CollectionItem<C>, b: CollectionItem<C>) => number) | Array<[keyof CollectionItem<C>, "ASC" | "DESC"]>;
|
|
5
4
|
export declare abstract class ArcManyItemsQueryBuilder<C extends ArcCollectionAny> extends ArcQueryBuilder {
|
|
6
|
-
protected filterFn?: (item:
|
|
7
|
-
protected sortFn?: (a:
|
|
8
|
-
filter(callback: (item:
|
|
5
|
+
protected filterFn?: (item: CollectionItem<C>) => boolean;
|
|
6
|
+
protected sortFn?: (a: CollectionItem<C>, b: CollectionItem<C>) => number;
|
|
7
|
+
filter(callback: (item: CollectionItem<C>) => boolean): this;
|
|
9
8
|
sort(comparator: SortComparator<C>): this;
|
|
10
9
|
}
|
|
11
10
|
export {};
|
|
11
|
+
//# sourceMappingURL=abstract-many-items.d.ts.map
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { ArcContextAny } from "./context";
|
|
2
|
-
type
|
|
2
|
+
export type CommandContext<C extends ArcContextAny> = ReturnType<C["commandContext"]>;
|
|
3
|
+
type Command<C extends ArcContextAny> = (context: CommandContext<C>, ...args: any[]) => any;
|
|
3
4
|
export type Commands<C extends ArcContextAny> = {
|
|
4
5
|
[key: string]: Command<C>;
|
|
5
6
|
};
|
|
@@ -8,3 +9,4 @@ export type CommandsClient<Cmds extends Commands<any>> = {
|
|
|
8
9
|
[Key in keyof Cmds]: CommandProxy<Cmds[Key]>;
|
|
9
10
|
};
|
|
10
11
|
export {};
|
|
12
|
+
//# sourceMappingURL=commands.d.ts.map
|
|
@@ -1,31 +1,21 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type { ReadTransaction, ReadWriteTransaction } from "../collection/db";
|
|
1
|
+
import type { DataStorage } from "../data-storage";
|
|
3
2
|
import type { Commands } from "./commands";
|
|
4
|
-
import type {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
readonly
|
|
8
|
-
|
|
3
|
+
import type { ArcContextElementAny, ArcContextElementChanges } from "./element";
|
|
4
|
+
declare class ArcContext<const C extends ArcContextElementAny[]> {
|
|
5
|
+
readonly elements: C;
|
|
6
|
+
readonly commands: Commands<ArcContext<C>>;
|
|
7
|
+
readonly version: number;
|
|
8
|
+
elementsMap: {
|
|
9
9
|
[key: string]: C[number];
|
|
10
10
|
};
|
|
11
|
-
constructor(
|
|
11
|
+
constructor(elements: C, commands: Commands<ArcContext<C>>, version: number);
|
|
12
12
|
queryBuilder(): {
|
|
13
13
|
[Collection in C[number] as Collection["name"]]: ReturnType<Collection["queryBuilder"]>;
|
|
14
14
|
};
|
|
15
|
-
commandContext(
|
|
16
|
-
context: {
|
|
17
|
-
[Collection in C[number] as Collection["name"]]: ReturnType<Collection["commandContext"]>;
|
|
18
|
-
};
|
|
19
|
-
finalize: () => CollectionChange[];
|
|
20
|
-
};
|
|
21
|
-
applyChange(transaction: ReadWriteTransaction, change: CollectionChange, events: CollectionChange[]): Promise<void>;
|
|
22
|
-
withCommands<Cmds extends Commands<this>>(commands: Cmds): ArcContextWithCommands<C, Cmds>;
|
|
23
|
-
}
|
|
24
|
-
declare class ArcContextWithCommands<const C extends ArcContextElement[], Cmds extends Commands<ArcContext<C>>> extends ArcContext<C> {
|
|
25
|
-
readonly commands: Cmds;
|
|
26
|
-
constructor(context: C, commands: Cmds);
|
|
15
|
+
commandContext(dataStorage: DataStorage): { [ContextElement in C[number] as ContextElement["name"]]: ReturnType<ContextElement["commandContext"]>; };
|
|
27
16
|
}
|
|
28
|
-
export type ArcContextAny = ArcContext<
|
|
29
|
-
export type
|
|
30
|
-
export declare function context<const
|
|
17
|
+
export type ArcContextAny = ArcContext<ArcContextElementAny[]>;
|
|
18
|
+
export type ArcContextChanges<C extends ArcContextAny> = ArcContextElementChanges<C["elements"][number]>;
|
|
19
|
+
export declare function context<const Elements extends ArcContextElementAny[], Cmds extends Commands<ArcContext<Elements>>>(elements: Elements, commands: Cmds, version: number): ArcContext<Elements>;
|
|
31
20
|
export {};
|
|
21
|
+
//# sourceMappingURL=context.d.ts.map
|
|
@@ -1,8 +1,10 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
|
|
3
|
-
export interface ArcContextElement {
|
|
1
|
+
import type { DataStorage } from "../data-storage";
|
|
2
|
+
export interface ArcContextElement<Change, Event> {
|
|
4
3
|
name: string;
|
|
5
4
|
queryBuilder(): any;
|
|
6
|
-
commandContext(
|
|
7
|
-
|
|
5
|
+
commandContext(dataStorage: DataStorage): unknown;
|
|
6
|
+
deserialize?: (data: any) => any;
|
|
8
7
|
}
|
|
8
|
+
export type ArcContextElementAny = ArcContextElement<any, any>;
|
|
9
|
+
export type ArcContextElementChanges<Element extends ArcContextElementAny> = Element extends ArcContextElement<infer Change, any> ? Change : never;
|
|
10
|
+
//# sourceMappingURL=element.d.ts.map
|
package/dist/context/index.d.ts
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { ArcContextAny } from "./context";
|
|
2
|
+
import type { ArcQueryAny } from "./query";
|
|
2
3
|
export declare abstract class ArcQueryBuilder {
|
|
3
|
-
abstract toQuery():
|
|
4
|
+
abstract toQuery(): ArcQueryAny;
|
|
4
5
|
}
|
|
6
|
+
export type QueryFactoryFunction<C extends ArcContextAny> = (queryBuilder: ReturnType<C["queryBuilder"]>) => ArcQueryBuilder;
|
|
7
|
+
//# sourceMappingURL=query-builders.d.ts.map
|
package/dist/context/query.d.ts
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import type { DataStorage } from "../data-storage";
|
|
2
|
+
export interface ArcQuery<Result> {
|
|
3
|
+
run(store: DataStorage, callback?: (data: Result) => void): Promise<Result>;
|
|
4
|
+
unsubscribe(): void;
|
|
3
5
|
}
|
|
6
|
+
export type ArcQueryAny = ArcQuery<any>;
|
|
7
|
+
//# sourceMappingURL=query.d.ts.map
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { ReadTransaction, ReadWriteTransaction } from "../db";
|
|
2
|
+
import type { ForkedDataStorage, StoreState } from "./data-storage";
|
|
3
|
+
export interface DataStorage {
|
|
4
|
+
getStore<Item extends {
|
|
5
|
+
_id: string;
|
|
6
|
+
}>(storeName: string, deserialize?: (data: any) => Item): StoreState<Item>;
|
|
7
|
+
fork(): ForkedDataStorage;
|
|
8
|
+
getReadTransaction(): Promise<ReadTransaction>;
|
|
9
|
+
getReadWriteTransaction(): Promise<ReadWriteTransaction>;
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=DataStorage.d.ts.map
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { QueryListenerCallback, StoreStateChange } from "./data-storage";
|
|
2
|
+
import type { DataStorage } from "./data-storage.interface";
|
|
3
|
+
import type { MasterStoreState } from "./store-state-master";
|
|
4
|
+
import { StoreState } from "./store-state.abstract";
|
|
5
|
+
export declare class ForkStoreState<
|
|
6
|
+
Item extends {
|
|
7
|
+
_id: string;
|
|
8
|
+
},
|
|
9
|
+
> extends StoreState<Item> {
|
|
10
|
+
master: MasterStoreState<Item>;
|
|
11
|
+
protected changedItems: Map<string, Item>;
|
|
12
|
+
changes: StoreStateChange<Item>[];
|
|
13
|
+
constructor(
|
|
14
|
+
storeName: string,
|
|
15
|
+
dataStorage: DataStorage,
|
|
16
|
+
master: MasterStoreState<Item>,
|
|
17
|
+
deserialize?: (data: any) => Item
|
|
18
|
+
);
|
|
19
|
+
applyChanges(changes: StoreStateChange<Item>[]): Promise<void>;
|
|
20
|
+
findById(
|
|
21
|
+
id: string,
|
|
22
|
+
listener?: QueryListenerCallback<Item>
|
|
23
|
+
): Promise<Item | undefined>;
|
|
24
|
+
findByIndex(
|
|
25
|
+
index: string,
|
|
26
|
+
data: any,
|
|
27
|
+
listener?: QueryListenerCallback<Item>
|
|
28
|
+
): Promise<Item[]>;
|
|
29
|
+
findAll(listener?: QueryListenerCallback<Item>): Promise<Item[]>;
|
|
30
|
+
private matchesIndex;
|
|
31
|
+
}
|
|
32
|
+
//# sourceMappingURL=ForkStoreState.d.ts.map
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { ForkStoreState, QueryListener, QueryListenerCallback, StoreStateChange } from "./data-storage";
|
|
2
|
+
import type { DataStorage } from "./data-storage.interface";
|
|
3
|
+
export declare abstract class StoreState<Item extends {
|
|
4
|
+
_id: string;
|
|
5
|
+
}> {
|
|
6
|
+
storeName: string;
|
|
7
|
+
protected dataStorage: DataStorage;
|
|
8
|
+
protected deserialize?: ((data: any) => Item) | undefined;
|
|
9
|
+
protected listeners: Set<QueryListener<Item>>;
|
|
10
|
+
protected indexQueryCache: Map<string, Item[]>;
|
|
11
|
+
constructor(storeName: string, dataStorage: DataStorage, deserialize?: ((data: any) => Item) | undefined);
|
|
12
|
+
abstract applyChanges(changes: StoreStateChange<Item>[]): Promise<void>;
|
|
13
|
+
fork(): ForkStoreState<Item>;
|
|
14
|
+
findByIndex(index: string, data: any, listener?: QueryListenerCallback<Item>): Promise<Item[]>;
|
|
15
|
+
set(item: Item): void;
|
|
16
|
+
remove(id: string): void;
|
|
17
|
+
modify(id: string, data: Partial<Item>): void;
|
|
18
|
+
unsubscribe(listener: QueryListener<Item>): void;
|
|
19
|
+
private notifyListeners;
|
|
20
|
+
private getAllLocalItems;
|
|
21
|
+
private mergeWithLocalModifications;
|
|
22
|
+
private matchesIndex;
|
|
23
|
+
}
|
|
24
|
+
//# sourceMappingURL=StoreState.d.ts.map
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { ReadTransaction, ReadWriteTransaction } from "../db";
|
|
2
|
+
import type { DataStorage } from "./data-storage.interface";
|
|
3
|
+
import { StoreState } from "./store-state.abstract";
|
|
4
|
+
export declare class ForkedDataStorage implements DataStorage {
|
|
5
|
+
private master;
|
|
6
|
+
private stores;
|
|
7
|
+
constructor(master: DataStorage);
|
|
8
|
+
getReadTransaction(): Promise<ReadTransaction>;
|
|
9
|
+
getReadWriteTransaction(): Promise<ReadWriteTransaction>;
|
|
10
|
+
getStore<Item extends {
|
|
11
|
+
_id: string;
|
|
12
|
+
}>(storeName: string, deserialize?: (data: any) => Item): StoreState<Item>;
|
|
13
|
+
fork(): ForkedDataStorage;
|
|
14
|
+
merge(): Promise<void>;
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=data-storage-forked.d.ts.map
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { ArcContextAny } from "../context";
|
|
2
|
+
import type { DatabaseAdapter, ReadTransaction, ReadWriteTransaction } from "../db";
|
|
3
|
+
import type { RealTimeCommunicationAdapterFactory } from "../rtc/rtc";
|
|
4
|
+
import { ForkedDataStorage } from "./data-storage-forked";
|
|
5
|
+
import type { DataStorage } from "./data-storage.interface";
|
|
6
|
+
import type { StoreState } from "./store-state.abstract";
|
|
7
|
+
export declare class MasterDataStorage implements DataStorage {
|
|
8
|
+
private dbAdapter;
|
|
9
|
+
private arcContext;
|
|
10
|
+
private stores;
|
|
11
|
+
private rtcAdapter;
|
|
12
|
+
constructor(dbAdapter: Promise<DatabaseAdapter>, rtcAdapterFactory: RealTimeCommunicationAdapterFactory, arcContext: ArcContextAny);
|
|
13
|
+
getReadTransaction(): Promise<ReadTransaction>;
|
|
14
|
+
getReadWriteTransaction(): Promise<ReadWriteTransaction>;
|
|
15
|
+
getStore<Item extends {
|
|
16
|
+
_id: string;
|
|
17
|
+
}>(storeName: string): StoreState<Item>;
|
|
18
|
+
fork(): ForkedDataStorage;
|
|
19
|
+
sync(progressCallback: ({ store, size }: {
|
|
20
|
+
store: string;
|
|
21
|
+
size: number;
|
|
22
|
+
}) => void): Promise<void>;
|
|
23
|
+
}
|
|
24
|
+
//# sourceMappingURL=data-storage-master.d.ts.map
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import type { ReadTransaction, ReadWriteTransaction } from "../db";
|
|
2
|
+
import type { ForkedDataStorage } from "./data-storage-forked";
|
|
3
|
+
import type { StoreState } from "./store-state.abstract";
|
|
4
|
+
export interface DataStorage {
|
|
5
|
+
getStore<Item extends {
|
|
6
|
+
_id: string;
|
|
7
|
+
}>(storeName: string, deserialize?: (data: any) => Item): StoreState<Item>;
|
|
8
|
+
fork(): ForkedDataStorage;
|
|
9
|
+
getReadTransaction(): Promise<ReadTransaction>;
|
|
10
|
+
getReadWriteTransaction(): Promise<ReadWriteTransaction>;
|
|
11
|
+
}
|
|
12
|
+
export type StoreStateChange<Item> = {
|
|
13
|
+
type: "set";
|
|
14
|
+
data: Item;
|
|
15
|
+
} | {
|
|
16
|
+
type: "delete";
|
|
17
|
+
id: string;
|
|
18
|
+
} | {
|
|
19
|
+
type: "modify";
|
|
20
|
+
id: string;
|
|
21
|
+
data: Partial<Item>;
|
|
22
|
+
};
|
|
23
|
+
export type QueryListenerCallback<Item> = (events: ListenerEvent<Item>[]) => void;
|
|
24
|
+
export type QueryListener<Item> = {
|
|
25
|
+
callback: QueryListenerCallback<Item>;
|
|
26
|
+
id?: string;
|
|
27
|
+
};
|
|
28
|
+
export type ListenerEvent<Item> = {
|
|
29
|
+
type: "set";
|
|
30
|
+
item: Item;
|
|
31
|
+
id: string;
|
|
32
|
+
} | {
|
|
33
|
+
type: "delete";
|
|
34
|
+
item: null;
|
|
35
|
+
id: string;
|
|
36
|
+
};
|
|
37
|
+
//# sourceMappingURL=data-storage.interface.d.ts.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export * from "./data-storage-forked";
|
|
2
|
+
export * from "./data-storage-master";
|
|
3
|
+
export * from "./data-storage.interface";
|
|
4
|
+
export * from "./store-state-fork";
|
|
5
|
+
export * from "./store-state-master";
|
|
6
|
+
export * from "./store-state.abstract";
|
|
7
|
+
//# sourceMappingURL=index.d.ts.map
|