@arcote.tech/arc 0.0.27 → 0.1.2
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 +28 -48
- package/dist/collection/queries/abstract-collection-query.d.ts +4 -6
- package/dist/collection/queries/{abstract-many-items.d.ts → find.d.ts} +8 -8
- package/dist/collection/queries/one-item.d.ts +1 -18
- package/dist/collection/query-builders/find-by-id.d.ts +2 -0
- package/dist/collection/query-builders/find-one.d.ts +2 -0
- package/dist/collection/query-builders/find.d.ts +13 -0
- package/dist/command/command.d.ts +29 -0
- package/dist/command/index.d.ts +2 -0
- package/dist/context/context.d.ts +34 -18
- package/dist/context/element.d.ts +36 -6
- package/dist/context/event.d.ts +39 -0
- package/dist/context/index.d.ts +4 -0
- package/dist/context/query-builder-context.d.ts +15 -0
- package/dist/context/query-builders.d.ts +11 -2
- package/dist/context/query-cache.d.ts +9 -0
- package/dist/context/query.d.ts +5 -3
- package/dist/context/reactive-query.d.ts +23 -0
- package/dist/context/serializable-query.d.ts +11 -0
- package/dist/data-storage/store-state-fork.d.ts +2 -3
- package/dist/data-storage/store-state-master.d.ts +2 -5
- package/dist/data-storage/store-state.abstract.d.ts +2 -3
- package/dist/data-storage/types.d.ts +28 -0
- package/dist/db/index.d.ts +1 -0
- package/dist/db/interface.d.ts +2 -17
- package/dist/db/sqliteAdapter.d.ts +39 -0
- package/dist/dist/index.d.ts +513 -0
- package/dist/elements/abstract-primitive.d.ts +0 -1
- package/dist/elements/abstract.d.ts +2 -1
- package/dist/elements/array.d.ts +61 -3
- package/dist/elements/class.d.ts +1 -24
- package/dist/elements/date.d.ts +35 -2
- package/dist/elements/index.d.ts +2 -0
- package/dist/elements/number.d.ts +21 -6
- package/dist/elements/object.d.ts +38 -11
- package/dist/elements/or.d.ts +1 -11
- package/dist/elements/record.d.ts +16 -4
- package/dist/elements/string-enum.d.ts +17 -3
- package/dist/elements/string.d.ts +74 -6
- package/dist/elements/utils/type-validator-builder.d.ts +8 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +1481 -752
- package/dist/model/index.d.ts +2 -0
- package/dist/model/model.d.ts +44 -38
- package/dist/state/query-builder.d.ts +1 -8
- package/dist/state/query.d.ts +1 -14
- package/dist/state/state.d.ts +1 -31
- package/dist/tests/context/context.test.d.ts +2 -0
- package/dist/tests/pipe.d.ts +2 -0
- package/dist/tests/query/advance-query.test.d.ts +2 -0
- package/dist/tests/query/collection-all.test.d.ts +2 -0
- package/dist/tests/utils/expect-not-false.d.ts +2 -0
- package/dist/tests/utils/sqlite-adapter.d.ts +3 -0
- package/dist/tests/utils/test-model.d.ts +26 -0
- package/dist/tests/validations/array.test.d.ts +2 -0
- package/dist/tests/validations/date.test.d.ts +2 -0
- package/dist/tests/validations/record.test.d.ts +2 -0
- package/dist/tests/validations/string-enum.test.d.ts +2 -0
- package/dist/utils/arcObjectToStoreSchema.d.ts +4 -0
- package/dist/utils/murmur-hash.d.ts +2 -0
- package/dist/utils.d.ts +4 -4
- package/dist/view/view.d.ts +49 -0
- package/package.json +11 -4
- package/dist/collection/collection-change.d.ts +0 -18
- package/dist/collection/db.d.ts +0 -17
- package/dist/collection/queries/all-items.d.ts +0 -7
- package/dist/collection/queries/indexed.d.ts +0 -13
- package/dist/collection/query-builders/abstract-many-items.d.ts +0 -11
- package/dist/collection/query-builders/all-items.d.ts +0 -9
- package/dist/collection/query-builders/indexed.d.ts +0 -11
- package/dist/collection/query-builders/one-item.d.ts +0 -11
- package/dist/collection/utils/index-query.d.ts +0 -6
- package/dist/data-storage/DataStorage.d.ts +0 -11
- package/dist/data-storage/ForkStoreState.d.ts +0 -32
- package/dist/data-storage/StoreState.d.ts +0 -39
- package/dist/data-storage/data-storage.d.ts +0 -2
- package/dist/data-storage/data-storage.interface.d.ts +0 -46
- package/dist/data-storage/master-store-state.d.ts +0 -30
- package/dist/data-storage/store-state.d.ts +0 -39
- package/dist/elements/object copy.d.ts +0 -29
- package/dist/rtc/deserializeChanges.d.ts +0 -3
- package/dist/state/db.d.ts +0 -15
- package/dist/state/state-change.d.ts +0 -14
- package/dist/state/util.d.ts +0 -3
- package/dist/tests/query/query.test.d.ts +0 -2
- package/dist/tests/query-notification-optimization.test copy.d.ts +0 -2
- package/dist/tests/query-notification-optimization.test.d.ts +0 -2
- package/dist/tests/validation.test.d.ts +0 -2
- package/dist/tests/validations/validation.test.d.ts +0 -2
- package/dist/utils/deep-merge.d.ts +0 -6
- /package/dist/{elements/tests → tests/validations}/object.test.d.ts +0 -0
|
@@ -1,39 +1,18 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ArcContextElementWithStore, type StoreSchema } from "../context/element";
|
|
2
2
|
import { type ArcIdAny } from "../elements/id";
|
|
3
3
|
import { type ArcObjectAny } from "../elements/object";
|
|
4
|
-
import {
|
|
4
|
+
import { type $type, type DeepPartial, type objectUtil, type util } from "../utils";
|
|
5
|
+
import type { QueryBuilderContext } from "../context/query-builder-context";
|
|
5
6
|
import type { DataStorage } from "../data-storage";
|
|
6
|
-
import type {
|
|
7
|
-
import {
|
|
8
|
-
|
|
9
|
-
import { ArcOneItemQueryBuilder } from "./query-builders/one-item";
|
|
10
|
-
export type CollectionItem<C extends ArcCollectionAny | ArcIndexedCollectionAny> = objectUtil.simplify<{
|
|
7
|
+
import type { FindOptions } from "../data-storage/types";
|
|
8
|
+
import { ArcFindQueryBuilder } from "./query-builders/find";
|
|
9
|
+
export type CollectionItem<C extends ArcCollectionAny> = objectUtil.simplify<{
|
|
11
10
|
_id: string;
|
|
12
|
-
} &
|
|
11
|
+
} & $type<C>>;
|
|
13
12
|
export type Deserialize<Id extends ArcIdAny, Schema extends ArcObjectAny> = objectUtil.simplify<{
|
|
14
|
-
_id:
|
|
15
|
-
} &
|
|
16
|
-
|
|
17
|
-
all: () => ArcAllItemsQueryBuilder<T>;
|
|
18
|
-
one: (id: util.GetType<T["id"]> | undefined | null) => ArcOneItemQueryBuilder<T>;
|
|
19
|
-
};
|
|
20
|
-
type CollectionCommandContext<Id extends ArcIdAny, Schema extends ArcObjectAny> = {
|
|
21
|
-
one: (id: util.GetType<Id>) => Deserialize<Id, Schema>;
|
|
22
|
-
remove: (id: util.GetType<Id>) => Promise<any>;
|
|
23
|
-
all: () => Deserialize<Id, Schema>[];
|
|
24
|
-
add: (data: objectUtil.addQuestionMarks<util.FirstArgument<Schema["serialize"]>>) => Promise<{
|
|
25
|
-
id: util.GetType<Id>;
|
|
26
|
-
}>;
|
|
27
|
-
set: (id: util.GetType<Id>, data: util.FirstArgument<Schema["serialize"]>) => Promise<any>;
|
|
28
|
-
edit: (id: util.GetType<Id>, editCallback: (item: Deserialize<Id, Schema>) => Promise<void> | void) => Promise<void>;
|
|
29
|
-
modify: (id: util.GetType<Id>, data: objectUtil.addQuestionMarks<DeepPartial<util.FirstArgument<Schema["serialize"]>>>) => Promise<any>;
|
|
30
|
-
};
|
|
31
|
-
type IndexValue<Schema extends ArcObjectAny, Indexes extends keyof ReturnType<Schema["deserialize"]>, I extends {
|
|
32
|
-
[name: string]: Indexes[];
|
|
33
|
-
}, func extends keyof I> = {
|
|
34
|
-
[Key in I[func][number]]: util.GetType<Schema>[Key];
|
|
35
|
-
};
|
|
36
|
-
export declare class ArcCollection<Name extends string, Id extends ArcIdAny, Schema extends ArcObjectAny> extends ArcContextElement<{
|
|
13
|
+
_id: $type<Id>;
|
|
14
|
+
} & $type<Schema>>;
|
|
15
|
+
export declare class ArcCollection<Name extends string, Id extends ArcIdAny, Schema extends ArcObjectAny> extends ArcContextElementWithStore<{
|
|
37
16
|
type: "delete";
|
|
38
17
|
from: CollectionItem<ArcCollection<Name, Id, Schema>>;
|
|
39
18
|
} | {
|
|
@@ -48,12 +27,13 @@ export declare class ArcCollection<Name extends string, Id extends ArcIdAny, Sch
|
|
|
48
27
|
type: "mutate";
|
|
49
28
|
from: CollectionItem<ArcCollection<Name, Id, Schema>>;
|
|
50
29
|
to: CollectionItem<ArcCollection<Name, Id, Schema>>;
|
|
51
|
-
}> {
|
|
30
|
+
}, Name> {
|
|
52
31
|
readonly name: Name;
|
|
53
32
|
readonly id: Id;
|
|
54
33
|
readonly schema: Schema;
|
|
55
34
|
readonly options: ArcCollectionOptions<Id, Schema>;
|
|
56
35
|
constructor(name: Name, id: Id, schema: Schema, options: ArcCollectionOptions<Id, Schema>);
|
|
36
|
+
storeSchema(): StoreSchema;
|
|
57
37
|
serialize(data: objectUtil.simplify<{
|
|
58
38
|
_id: util.FirstArgument<Id["serialize"]>;
|
|
59
39
|
} & objectUtil.addQuestionMarks<util.FirstArgument<Schema["serialize"]>>>): objectUtil.simplify<{
|
|
@@ -62,26 +42,26 @@ export declare class ArcCollection<Name extends string, Id extends ArcIdAny, Sch
|
|
|
62
42
|
deserialize(data: objectUtil.simplify<{
|
|
63
43
|
_id: util.FirstArgument<Id["deserialize"]>;
|
|
64
44
|
} & objectUtil.addQuestionMarks<util.FirstArgument<Schema["deserialize"]>>>): Deserialize<Id, Schema>;
|
|
65
|
-
queryBuilder(
|
|
66
|
-
|
|
67
|
-
indexBy<Indexes extends keyof ReturnType<Schema["deserialize"]>, const I extends {
|
|
68
|
-
[name: string]: Indexes[];
|
|
69
|
-
}>(indexes: I): ArcIndexedCollection<Name, Id, Schema, keyof ReturnType<Schema["deserialize"]>, I>;
|
|
70
|
-
}
|
|
71
|
-
export declare class ArcIndexedCollection<Name extends string, Id extends ArcIdAny, Schema extends ArcObjectAny, Indexes extends keyof ReturnType<Schema["deserialize"]>, const I extends {
|
|
72
|
-
[name: string]: Indexes[];
|
|
73
|
-
}> extends ArcCollection<Name, Id, Schema> {
|
|
74
|
-
readonly indexes: I;
|
|
75
|
-
constructor(name: Name, id: Id, schema: Schema, options: ArcCollectionOptions<Id, Schema>, indexes: I);
|
|
76
|
-
commandContext(dataStorage: DataStorage, publishEvent: (event: this["$event"]) => Promise<void>): CollectionCommandContext<Id, Schema> & {
|
|
77
|
-
[func in keyof I]: (args: objectUtil.simplify<IndexQueryArgument<objectUtil.simplify<IndexValue<Schema, Indexes, I, func>>>>) => Deserialize<Id, Schema>[];
|
|
45
|
+
queryBuilder: (context: QueryBuilderContext) => {
|
|
46
|
+
find: (options?: FindOptions<CollectionItem<ArcCollection<Name, Id, Schema>>>) => ArcFindQueryBuilder<ArcCollection<Name, Id, Schema>>;
|
|
78
47
|
};
|
|
79
|
-
|
|
80
|
-
|
|
48
|
+
commandContext: (dataStorage: DataStorage, publishEvent: (event: this["$event"]) => Promise<void>) => {
|
|
49
|
+
add: (data: $type<Schema>) => Promise<{
|
|
50
|
+
id: any;
|
|
51
|
+
}>;
|
|
52
|
+
remove: (id: $type<Id>) => Promise<{
|
|
53
|
+
success: boolean;
|
|
54
|
+
}>;
|
|
55
|
+
set: (id: $type<Id>, data: $type<Schema>) => Promise<{
|
|
56
|
+
success: boolean;
|
|
57
|
+
}>;
|
|
58
|
+
find: (options: FindOptions<Deserialize<Id, Schema>>) => Promise<Deserialize<Id, Schema>[]>;
|
|
59
|
+
findOne: (where: FindOptions<Deserialize<Id, Schema>>["where"]) => Promise<Deserialize<Id, Schema> | undefined>;
|
|
60
|
+
modify: (id: $type<Id>, data: DeepPartial<$type<Schema>>) => Promise<void>;
|
|
61
|
+
edit: (id: $type<Id>, editCallback: (item: Deserialize<Id, Schema>) => void) => Promise<void>;
|
|
81
62
|
};
|
|
82
63
|
}
|
|
83
64
|
export type ArcCollectionAny = ArcCollection<any, any, any>;
|
|
84
|
-
export type ArcIndexedCollectionAny = ArcIndexedCollection<any, any, any, any, any>;
|
|
85
65
|
type ArcCollectionOptions<Id extends ArcIdAny, Schema extends ArcObjectAny> = {
|
|
86
66
|
sort?: (a: Deserialize<Id, Schema>, b: Deserialize<Id, Schema>) => number;
|
|
87
67
|
};
|
|
@@ -1,16 +1,14 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ArcSerializableQuery } from "../../context/serializable-query";
|
|
2
2
|
import type { DataStorage, ListenerEvent, StoreState } from "../../data-storage";
|
|
3
3
|
import type { ArcCollectionAny, CollectionItem } from "../collection";
|
|
4
|
-
export declare abstract class ArcCollectionQuery<Collection extends ArcCollectionAny, Result> extends
|
|
4
|
+
export declare abstract class ArcCollectionQuery<Collection extends ArcCollectionAny, Result, Params> extends ArcSerializableQuery<Result, Params> {
|
|
5
5
|
protected collection: Collection;
|
|
6
6
|
protected bindedChangeHandler: (changes: ListenerEvent<CollectionItem<Collection>>[]) => void;
|
|
7
7
|
private store;
|
|
8
|
-
constructor(collection: Collection);
|
|
9
|
-
run(dataStorage: DataStorage
|
|
8
|
+
constructor(collection: Collection, params: Params);
|
|
9
|
+
run(dataStorage: DataStorage): Promise<Result>;
|
|
10
10
|
protected abstract onChange(change: ListenerEvent<CollectionItem<Collection>>): Result | false;
|
|
11
11
|
protected abstract fetch(store: StoreState<CollectionItem<Collection>>): Promise<Result>;
|
|
12
12
|
protected changeHandler(changes: ListenerEvent<CollectionItem<Collection>>[]): void;
|
|
13
|
-
unsubscribe(): void;
|
|
14
|
-
private nextResult;
|
|
15
13
|
}
|
|
16
14
|
//# sourceMappingURL=abstract-collection-query.d.ts.map
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import type { ListenerEvent } from "../../data-storage";
|
|
1
|
+
import type { ListenerEvent, StoreState } from "../../data-storage";
|
|
2
|
+
import type { FindOptions } from "../../data-storage/types";
|
|
2
3
|
import type { util } from "../../utils";
|
|
3
4
|
import type { ArcCollectionAny, CollectionItem } from "../collection";
|
|
4
5
|
import { ArcCollectionQuery } from "./abstract-collection-query";
|
|
@@ -17,13 +18,12 @@ export declare class QueryCollectionResult<C extends ArcCollectionAny> {
|
|
|
17
18
|
_id: string;
|
|
18
19
|
} & ReturnType<C["deserialize"]>)[KeyType]; } : never)[];
|
|
19
20
|
}
|
|
20
|
-
export declare
|
|
21
|
-
protected
|
|
22
|
-
|
|
23
|
-
|
|
21
|
+
export declare class ArcFindQuery<Collection extends ArcCollectionAny> extends ArcCollectionQuery<Collection, QueryCollectionResult<Collection>, FindOptions<CollectionItem<Collection>>> {
|
|
22
|
+
protected params: FindOptions<CollectionItem<Collection>>;
|
|
23
|
+
constructor(collection: Collection, params: FindOptions<CollectionItem<Collection>>);
|
|
24
|
+
protected fetch(store: StoreState<CollectionItem<Collection>>): Promise<QueryCollectionResult<Collection>>;
|
|
25
|
+
protected checkItem(item: CollectionItem<Collection>): boolean;
|
|
24
26
|
protected onChange(change: ListenerEvent<CollectionItem<Collection>>): false | QueryCollectionResult<Collection>;
|
|
25
27
|
protected createResult(result: CollectionItem<Collection>[]): QueryCollectionResult<Collection>;
|
|
26
|
-
protected createFiltredResult(result: CollectionItem<Collection>[]): QueryCollectionResult<Collection>;
|
|
27
|
-
protected checkItem(item: CollectionItem<Collection>): boolean;
|
|
28
28
|
}
|
|
29
|
-
//# sourceMappingURL=
|
|
29
|
+
//# sourceMappingURL=find.d.ts.map
|
|
@@ -1,19 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
import type { util } from "../../utils";
|
|
3
|
-
import type { ArcCollectionAny, CollectionItem } from "../collection";
|
|
4
|
-
import { ArcCollectionQuery } from "./abstract-collection-query";
|
|
5
|
-
export declare class ArcOneItemQuery<Collection extends ArcCollectionAny> extends ArcCollectionQuery<Collection, CollectionItem<Collection> | null | undefined> {
|
|
6
|
-
private id;
|
|
7
|
-
constructor(collection: Collection, id: util.GetType<Collection["id"]>);
|
|
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) | null;
|
|
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>;
|
|
18
|
-
}
|
|
1
|
+
export {};
|
|
19
2
|
//# sourceMappingURL=one-item.d.ts.map
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { QueryBuilderContext } from "../../context/query-builder-context";
|
|
2
|
+
import type { FindOptions } from "../../data-storage/types";
|
|
3
|
+
import { type ArcCollectionAny, type CollectionItem } from "../collection";
|
|
4
|
+
import { ArcFindQuery } from "../queries/find";
|
|
5
|
+
export declare class ArcFindQueryBuilder<C extends ArcCollectionAny> {
|
|
6
|
+
private collection;
|
|
7
|
+
protected queryContext: QueryBuilderContext;
|
|
8
|
+
protected options: FindOptions<CollectionItem<C>>;
|
|
9
|
+
constructor(collection: C, queryContext: QueryBuilderContext, options: FindOptions<CollectionItem<C>>);
|
|
10
|
+
toQuery(): ArcFindQuery<ArcCollectionAny>;
|
|
11
|
+
run(): import("../queries/find").QueryCollectionResult<ArcCollectionAny>;
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=find.d.ts.map
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { ArcCommandContext } from "../context";
|
|
2
|
+
import { ArcContextElement, type ArcContextElementAny } from "../context/element";
|
|
3
|
+
import { ArcObject, type ArcObjectAny, type ArcRawShape } from "../elements";
|
|
4
|
+
import type { $type } from "../utils";
|
|
5
|
+
export type ArcCommmandHandler<ContextElements extends ArcContextElementAny[], Params extends ArcObjectAny | null, Result extends ArcObjectAny> = (ctx: ArcCommandContext<ContextElements>, params: Params extends ArcObjectAny ? $type<Params> : null) => Promise<$type<Result>> | $type<Result>;
|
|
6
|
+
export declare class ArcCommand<Name extends string, Params extends ArcObjectAny | null, Result extends ArcObjectAny, const Elements extends ArcContextElementAny[]> extends ArcContextElement<{
|
|
7
|
+
type: "execute";
|
|
8
|
+
params: Params;
|
|
9
|
+
result: Result;
|
|
10
|
+
}, Name> {
|
|
11
|
+
readonly name: Name;
|
|
12
|
+
private _description?;
|
|
13
|
+
private _params?;
|
|
14
|
+
private _result?;
|
|
15
|
+
private _elements?;
|
|
16
|
+
private _handler?;
|
|
17
|
+
constructor(name: Name);
|
|
18
|
+
use<const E extends ArcContextElementAny[]>(elements: E): ArcCommand<Name, Params, Result, E>;
|
|
19
|
+
description(description: string): ArcCommand<Name, Params, Result, Elements>;
|
|
20
|
+
withParams<NewParams extends ArcRawShape>(schema: NewParams | ArcObject<NewParams>): ArcCommand<Name, ArcObject<NewParams>, Result, Elements>;
|
|
21
|
+
withResult<NewResult extends ArcRawShape>(schema: NewResult): ArcCommand<Name, Params, ArcObject<NewResult>, Elements>;
|
|
22
|
+
handle(handler: ArcCommmandHandler<Elements, Params, Result> | false): ArcCommand<Name, Params, Result, Elements>;
|
|
23
|
+
commandClient: (ctx: any) => (Params extends ArcObjectAny ? (params: $type<Params>) => Promise<$type<Result>> : () => Promise<$type<Result>>) & {
|
|
24
|
+
params: Params;
|
|
25
|
+
};
|
|
26
|
+
private clone;
|
|
27
|
+
}
|
|
28
|
+
export declare function command<Name extends string>(name: Name): ArcCommand<Name, null, any, any[]>;
|
|
29
|
+
//# sourceMappingURL=command.d.ts.map
|
|
@@ -1,25 +1,39 @@
|
|
|
1
1
|
import type { DataStorage } from "../data-storage";
|
|
2
2
|
import type { objectUtil } from "../utils";
|
|
3
|
-
import type { CommandContext
|
|
3
|
+
import type { CommandContext } from "./commands";
|
|
4
4
|
import type { ArcContextElement, ArcContextElementAny } from "./element";
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
5
|
+
import type { QueryBuilderContext } from "./query-builder-context";
|
|
6
|
+
type Filter<T extends any[], Method extends keyof T[number]> = T extends [
|
|
7
|
+
infer First,
|
|
8
|
+
...infer Rest
|
|
9
|
+
] ? First[Method] extends (...args: any) => any ? [First, ...Filter<Rest, Method>] : Filter<Rest, Method> : [];
|
|
10
|
+
type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends (k: infer I) => void ? I : never;
|
|
11
|
+
type ArcContextElementMethodReturnType<Elements extends ArcContextElementAny[], Method extends keyof Elements[number]> = UnionToIntersection<{
|
|
12
|
+
[Element in Filter<Elements, Method>[number] as number]: {
|
|
13
|
+
[ElementName in Element["name"]]: Element[Method] extends (...args: any) => any ? ReturnType<Element[Method]> : undefined;
|
|
12
14
|
};
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
15
|
+
}[number]>;
|
|
16
|
+
export type ArcCommandContext<E extends ArcContextElementAny[]> = ArcContextElementMethodReturnType<E, "commandContext"> & {
|
|
17
|
+
$client: any;
|
|
18
|
+
};
|
|
19
|
+
export type RemoveFalseAndResolvedPromiseFromArray<T extends any[]> = T extends [infer First, ...infer Rest] ? First extends false ? RemoveFalseAndResolvedPromiseFromArray<Rest> : First extends Promise<{
|
|
20
|
+
default: infer Inner;
|
|
21
|
+
}> ? RemoveFalseAndResolvedPromiseFromArray<[Inner, ...Rest]> : [First, ...RemoveFalseAndResolvedPromiseFromArray<Rest>] : [];
|
|
22
|
+
export declare class ArcContext<const E extends ArcContextElementAny[]> {
|
|
23
|
+
readonly elements: E;
|
|
24
|
+
private eventListeners;
|
|
25
|
+
constructor(elements: E);
|
|
26
|
+
pipe<const NewElements extends (ArcContextElementAny | false | Promise<{
|
|
27
|
+
default: ArcContextElementAny;
|
|
28
|
+
}>)[]>(newElements: NewElements): ArcContext<[
|
|
29
|
+
...E,
|
|
30
|
+
...RemoveFalseAndResolvedPromiseFromArray<NewElements>
|
|
31
|
+
]>;
|
|
32
|
+
queryBuilder(queryContext: QueryBuilderContext): ArcContextElementMethodReturnType<E, "queryBuilder">;
|
|
33
|
+
commandContext(client: string, dataStorage: DataStorage): ArcCommandContext<E>;
|
|
34
|
+
commandsClient(client: string, queryContext: QueryBuilderContext, dataStorage: DataStorage, catchErrorCallback: (error: any) => void): ArcContextElementMethodReturnType<E, "commandClient">;
|
|
21
35
|
}
|
|
22
|
-
export type ArcContextAny = ArcContext<ArcContextElementAny[]
|
|
36
|
+
export type ArcContextAny = ArcContext<ArcContextElementAny[]>;
|
|
23
37
|
export type ElementEvents<Element extends ArcContextElementAny> = Element extends ArcContextElement<any> ? Element["$event"] : never;
|
|
24
38
|
export type ContextEvents<Context extends ArcContextAny> = {
|
|
25
39
|
[Element in Context["elements"][number] as Element["name"]]: objectUtil.simplify<{
|
|
@@ -27,6 +41,8 @@ export type ContextEvents<Context extends ArcContextAny> = {
|
|
|
27
41
|
} & ElementEvents<Element>>;
|
|
28
42
|
}[Context["elements"][number]["name"]];
|
|
29
43
|
export type Listener<Context extends ArcContextAny> = (event: ContextEvents<Context>, context: CommandContext<Context>) => Promise<void> | void;
|
|
30
|
-
export declare function context<const Elements extends ArcContextElementAny
|
|
44
|
+
export declare function context<const Elements extends (ArcContextElementAny | false | Promise<{
|
|
45
|
+
default: ArcContextElementAny;
|
|
46
|
+
}>)[]>(elementsPromise: Elements): Promise<ArcContext<RemoveFalseAndResolvedPromiseFromArray<Elements>>>;
|
|
31
47
|
export {};
|
|
32
48
|
//# sourceMappingURL=context.d.ts.map
|
|
@@ -1,10 +1,40 @@
|
|
|
1
1
|
import type { DataStorage } from "../data-storage";
|
|
2
|
-
|
|
2
|
+
import type { QueryBuilderContext } from "./query-builder-context";
|
|
3
|
+
export type EventListener<Event> = (event: Event, dataStorage: DataStorage) => Promise<void>;
|
|
4
|
+
export type StoreColumn = {
|
|
5
|
+
name: string;
|
|
6
|
+
type: string;
|
|
7
|
+
isOptional?: boolean;
|
|
8
|
+
default?: any;
|
|
9
|
+
computed?: string | ((item: any, context: {
|
|
10
|
+
now: string;
|
|
11
|
+
}) => any);
|
|
12
|
+
};
|
|
13
|
+
export type StoreRelation = {
|
|
14
|
+
table: string;
|
|
15
|
+
type: "one-to-many" | "many-to-many" | "one-to-one";
|
|
16
|
+
foreignKey: string;
|
|
17
|
+
throughTable?: string;
|
|
18
|
+
};
|
|
19
|
+
export type StoreTable = {
|
|
20
|
+
name: string;
|
|
21
|
+
columns: StoreColumn[];
|
|
22
|
+
primaryKey: string;
|
|
23
|
+
};
|
|
24
|
+
export type StoreSchema = {
|
|
25
|
+
tables: StoreTable[];
|
|
26
|
+
relations?: StoreRelation[];
|
|
27
|
+
};
|
|
28
|
+
export declare abstract class ArcContextElement<const Event, const Name extends string | undefined = undefined> {
|
|
3
29
|
readonly $event: Event;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
30
|
+
readonly name?: Name;
|
|
31
|
+
queryBuilder?(queryContext: QueryBuilderContext): any;
|
|
32
|
+
commandContext?: (dataStorage: DataStorage, publishEvent: (event: Event) => Promise<void>) => any;
|
|
33
|
+
commandClient?: (commandContext: any) => (...args: any[]) => any;
|
|
34
|
+
observer?: () => Record<string, EventListener<Event>>;
|
|
8
35
|
}
|
|
9
|
-
export
|
|
36
|
+
export declare abstract class ArcContextElementWithStore<const Event, const Name extends string | undefined = undefined> extends ArcContextElement<Event, Name> {
|
|
37
|
+
abstract storeSchema(): StoreSchema;
|
|
38
|
+
}
|
|
39
|
+
export type ArcContextElementAny = ArcContextElement<any, any>;
|
|
10
40
|
//# sourceMappingURL=element.d.ts.map
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import type { DataStorage } from "../data-storage";
|
|
2
|
+
import { ArcObject, type ArcObjectAny, type ArcRawShape } from "../elements/object";
|
|
3
|
+
import type { $type } from "../utils";
|
|
4
|
+
import { ArcContextElementWithStore, type StoreSchema } from "./element";
|
|
5
|
+
export type EventMetadata = {
|
|
6
|
+
occurredAt: string;
|
|
7
|
+
createdBy?: {
|
|
8
|
+
id: string;
|
|
9
|
+
type: string;
|
|
10
|
+
};
|
|
11
|
+
source?: string;
|
|
12
|
+
correlationId?: string;
|
|
13
|
+
version?: number;
|
|
14
|
+
};
|
|
15
|
+
export declare class ArcEvent<const Name extends string, const PayloadShape extends ArcObjectAny | undefined> extends ArcContextElementWithStore<ArcEventInstance<ArcEvent<Name, PayloadShape>>, Name> {
|
|
16
|
+
readonly name: Name;
|
|
17
|
+
readonly payload: PayloadShape;
|
|
18
|
+
storeSchema: () => StoreSchema;
|
|
19
|
+
constructor(name: Name, payload: PayloadShape);
|
|
20
|
+
commandContext: (dataStorage: DataStorage, publishEvent: (event: ArcEventInstance<ArcEvent<Name, PayloadShape>>) => Promise<void>) => {
|
|
21
|
+
emit: (payload: PayloadShape extends ArcObjectAny ? $type<PayloadShape> : undefined) => Promise<void>;
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
export type ArcEventInstance<Event extends ArcEventAny> = {
|
|
25
|
+
type: Event["name"];
|
|
26
|
+
payload: Event["payload"] extends ArcObjectAny ? $type<Event["payload"]> : undefined;
|
|
27
|
+
} & EventMetadata;
|
|
28
|
+
export type ArcEventAny = ArcEvent<any, any>;
|
|
29
|
+
export declare function event<const Name extends string, PayloadShape extends ArcRawShape | undefined>(name: Name, payload?: PayloadShape): ArcEvent<Name, PayloadShape extends ArcRawShape ? ArcObject<PayloadShape, [{
|
|
30
|
+
name: "type";
|
|
31
|
+
validator: (value: any) => false | {
|
|
32
|
+
current: "string" | "number" | "bigint" | "boolean" | "symbol" | "undefined" | "object" | "function";
|
|
33
|
+
expected: "object";
|
|
34
|
+
};
|
|
35
|
+
}, {
|
|
36
|
+
name: "schema";
|
|
37
|
+
validator: (value: any) => false | { [key in keyof PayloadShape]: ReturnType<PayloadShape[key]["validate"]>; };
|
|
38
|
+
}]> : undefined>;
|
|
39
|
+
//# sourceMappingURL=event.d.ts.map
|
package/dist/context/index.d.ts
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
export * from "./commands";
|
|
2
2
|
export * from "./context";
|
|
3
|
+
export * from "./event";
|
|
3
4
|
export * from "./query";
|
|
5
|
+
export * from "./query-builder-context";
|
|
4
6
|
export * from "./query-builders";
|
|
7
|
+
export * from "./query-cache";
|
|
8
|
+
export * from "./reactive-query";
|
|
5
9
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { DataStorage } from "../data-storage/data-storage.abstract";
|
|
2
|
+
import type { ArcQueryAny } from "./query";
|
|
3
|
+
import { QueryCache } from "./query-cache";
|
|
4
|
+
export declare class QueryBuilderContext {
|
|
5
|
+
private readonly queryCache;
|
|
6
|
+
private readonly dataStorage;
|
|
7
|
+
private usedQueries;
|
|
8
|
+
constructor(queryCache: QueryCache, dataStorage: DataStorage);
|
|
9
|
+
cacheQuery<T extends ArcQueryAny, Arguments extends any[]>(QueryConstructor: (new (...args: Arguments) => T) & {
|
|
10
|
+
key: string;
|
|
11
|
+
}, args: Arguments): T;
|
|
12
|
+
runQuery<T extends ArcQueryAny>(query: T): T["lastResult"];
|
|
13
|
+
getUsedQueries(): ArcQueryAny[];
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=query-builder-context.d.ts.map
|
|
@@ -1,7 +1,16 @@
|
|
|
1
1
|
import type { ArcContextAny } from "./context";
|
|
2
2
|
import type { ArcQueryAny } from "./query";
|
|
3
|
-
|
|
3
|
+
import type { QueryBuilderContext } from "./query-builder-context";
|
|
4
|
+
export type RunQuery<T extends ArcQueryAny> = (query: T) => T["lastResult"];
|
|
5
|
+
export interface IArcQueryBuilder {
|
|
6
|
+
toQuery(context?: QueryBuilderContext): ArcQueryAny;
|
|
7
|
+
}
|
|
8
|
+
export declare abstract class ArcQueryBuilder implements IArcQueryBuilder {
|
|
9
|
+
protected queryContext: QueryBuilderContext;
|
|
10
|
+
constructor(queryContext: QueryBuilderContext);
|
|
4
11
|
abstract toQuery(): ArcQueryAny;
|
|
12
|
+
run(): ReturnType<this["toQuery"]>["lastResult"];
|
|
5
13
|
}
|
|
6
|
-
export type
|
|
14
|
+
export type UnaryFunction<T, R> = (input: T) => R;
|
|
15
|
+
export type QueryFactoryFunction<C extends ArcContextAny> = UnaryFunction<ReturnType<C["queryBuilder"]>, IArcQueryBuilder>;
|
|
7
16
|
//# sourceMappingURL=query-builders.d.ts.map
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { ArcQueryAny } from "./query";
|
|
2
|
+
export declare class QueryCache {
|
|
3
|
+
private cache;
|
|
4
|
+
private getIndexHash;
|
|
5
|
+
set(index: any[], query: ArcQueryAny): void;
|
|
6
|
+
get(index: any[]): ArcQueryAny | undefined;
|
|
7
|
+
debug(): Map<any, any>;
|
|
8
|
+
}
|
|
9
|
+
//# sourceMappingURL=query-cache.d.ts.map
|
package/dist/context/query.d.ts
CHANGED
|
@@ -2,9 +2,11 @@ import type { DataStorage } from "../data-storage";
|
|
|
2
2
|
export type ArcQueryListener<Result> = (result: Result) => void;
|
|
3
3
|
export declare abstract class ArcQuery<Result> {
|
|
4
4
|
lastResult: Result;
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
abstract run(dataStorage: DataStorage): Promise<Result>;
|
|
6
|
+
private listeners;
|
|
7
|
+
subscribe(listener: ArcQueryListener<Result>): void;
|
|
8
|
+
unsubscribe(listener: ArcQueryListener<Result>): void;
|
|
9
|
+
nextResult(result: Result): void;
|
|
8
10
|
}
|
|
9
11
|
export type ArcQueryAny = ArcQuery<any>;
|
|
10
12
|
//# sourceMappingURL=query.d.ts.map
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { ArcQuery } from "./query";
|
|
2
|
+
import type { QueryBuilderContext } from "./query-builder-context";
|
|
3
|
+
import { type IArcQueryBuilder, type UnaryFunction } from "./query-builders";
|
|
4
|
+
declare class ReactiveQuery<T, R> extends ArcQuery<Awaited<R>> {
|
|
5
|
+
private readonly queryContext;
|
|
6
|
+
private readonly queryBuilder;
|
|
7
|
+
private readonly fn;
|
|
8
|
+
queries: ArcQuery<any>[];
|
|
9
|
+
constructor(queryContext: QueryBuilderContext, queryBuilder: T, fn: UnaryFunction<T, R>);
|
|
10
|
+
run(): Promise<Awaited<R>>;
|
|
11
|
+
private onChangeHandler;
|
|
12
|
+
onChange(): Promise<void>;
|
|
13
|
+
runQuery(): Promise<R>;
|
|
14
|
+
}
|
|
15
|
+
declare class ReactiveQueryBuilder<T, R> implements IArcQueryBuilder {
|
|
16
|
+
private readonly queryBuilder;
|
|
17
|
+
private readonly fn;
|
|
18
|
+
constructor(queryBuilder: T, fn: UnaryFunction<T, R>);
|
|
19
|
+
toQuery(context: QueryBuilderContext): ReactiveQuery<T, R>;
|
|
20
|
+
}
|
|
21
|
+
export declare function reactive<T, R>(fn: UnaryFunction<T, R>): (context: T) => ReactiveQueryBuilder<T, R>;
|
|
22
|
+
export {};
|
|
23
|
+
//# sourceMappingURL=reactive-query.d.ts.map
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { ArcQuery } from "./query";
|
|
2
|
+
export declare abstract class ArcSerializableQuery<Result, Params> extends ArcQuery<Result> {
|
|
3
|
+
protected readonly params: Params;
|
|
4
|
+
static key: string;
|
|
5
|
+
constructor(params: Params);
|
|
6
|
+
serialize(): {
|
|
7
|
+
key: any;
|
|
8
|
+
params: Params;
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=serializable-query.d.ts.map
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { DataStorage, ListenerEvent, QueryListenerCallback, StoreStateChange } from "./data-storage.abstract";
|
|
2
2
|
import { StoreState } from "./store-state.abstract";
|
|
3
|
+
import type { FindOptions } from "./types";
|
|
3
4
|
export declare class ForkedStoreState<Item extends {
|
|
4
5
|
_id: string;
|
|
5
6
|
}> extends StoreState<Item> {
|
|
@@ -17,8 +18,6 @@ export declare class ForkedStoreState<Item extends {
|
|
|
17
18
|
to: Item | null;
|
|
18
19
|
}>;
|
|
19
20
|
applyChanges(changes: StoreStateChange<Item>[]): Promise<void>;
|
|
20
|
-
|
|
21
|
-
findByIndex(index: string, data: any, listener?: QueryListenerCallback<Item>): Promise<Item[]>;
|
|
22
|
-
findAll(listener?: QueryListenerCallback<Item>): Promise<Item[]>;
|
|
21
|
+
find(options: FindOptions<Item>, listener?: QueryListenerCallback<Item>): Promise<Item[]>;
|
|
23
22
|
}
|
|
24
23
|
//# sourceMappingURL=store-state-fork.d.ts.map
|
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
import type { ReadWriteTransaction } from "../db";
|
|
2
2
|
import type { DataStorage, ListenerEvent, QueryListenerCallback, StoreStateChange } from "./data-storage.abstract";
|
|
3
3
|
import { StoreState } from "./store-state.abstract";
|
|
4
|
+
import type { FindOptions } from "./types";
|
|
4
5
|
export declare class MasterStoreState<Item extends {
|
|
5
6
|
_id: string;
|
|
6
7
|
}> extends StoreState<Item> {
|
|
7
|
-
private items;
|
|
8
|
-
private isComplete;
|
|
9
8
|
constructor(storeName: string, dataStorage: DataStorage, deserialize?: (data: any) => Item);
|
|
10
9
|
applyChangeAndReturnEvent(transaction: ReadWriteTransaction, change: StoreStateChange<Item>): Promise<{
|
|
11
10
|
from: Item | null;
|
|
@@ -17,8 +16,6 @@ export declare class MasterStoreState<Item extends {
|
|
|
17
16
|
to: Item | null;
|
|
18
17
|
}>;
|
|
19
18
|
applyChanges(changes: StoreStateChange<Item>[]): Promise<void>;
|
|
20
|
-
|
|
21
|
-
findByIndex(index: string, data: any, listener?: QueryListenerCallback<Item>): Promise<Item[]>;
|
|
22
|
-
findAll(listener?: QueryListenerCallback<Item>): Promise<Item[]>;
|
|
19
|
+
find(options: FindOptions<Item>, listener?: QueryListenerCallback<Item>): Promise<Item[]>;
|
|
23
20
|
}
|
|
24
21
|
//# sourceMappingURL=store-state-master.d.ts.map
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { DataStorage, ListenerEvent, QueryListener, QueryListenerCallback, StoreStateChange } from "./data-storage.abstract";
|
|
2
2
|
import { ForkedStoreState } from "./store-state-fork";
|
|
3
|
+
import type { FindOptions } from "./types";
|
|
3
4
|
export declare abstract class StoreState<Item extends {
|
|
4
5
|
_id: string;
|
|
5
6
|
}> {
|
|
@@ -13,9 +14,7 @@ export declare abstract class StoreState<Item extends {
|
|
|
13
14
|
to: Item | null;
|
|
14
15
|
}>;
|
|
15
16
|
abstract applyChanges(changes: StoreStateChange<Item>[]): Promise<void>;
|
|
16
|
-
abstract
|
|
17
|
-
abstract findAll(listener?: QueryListenerCallback<Item>): Promise<Item[]>;
|
|
18
|
-
abstract findByIndex(index: string, data: any, listener?: QueryListenerCallback<Item>): Promise<Item[]>;
|
|
17
|
+
abstract find(options: FindOptions<Item>, listener?: QueryListenerCallback<Item>): Promise<Item[]>;
|
|
19
18
|
fork(): ForkedStoreState<Item>;
|
|
20
19
|
set(item: Item): Promise<void>;
|
|
21
20
|
remove(id: string): Promise<void>;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
export type WhereOperators<T> = {
|
|
2
|
+
$eq?: T;
|
|
3
|
+
$ne?: T;
|
|
4
|
+
$gt?: T;
|
|
5
|
+
$gte?: T;
|
|
6
|
+
$lt?: T;
|
|
7
|
+
$lte?: T;
|
|
8
|
+
$in?: T[];
|
|
9
|
+
$nin?: T[];
|
|
10
|
+
$exists?: boolean;
|
|
11
|
+
};
|
|
12
|
+
export type WhereCondition<T = any> = {
|
|
13
|
+
[K in keyof T]?: T[K] | WhereOperators<T[K]>;
|
|
14
|
+
};
|
|
15
|
+
export type OrderByCondition = {
|
|
16
|
+
[key: string]: "asc" | "desc";
|
|
17
|
+
};
|
|
18
|
+
export type FindOptions<T> = {
|
|
19
|
+
where?: WhereCondition<T>;
|
|
20
|
+
limit?: number;
|
|
21
|
+
offset?: number;
|
|
22
|
+
orderBy?: OrderByCondition;
|
|
23
|
+
};
|
|
24
|
+
export type QueryResult<T> = {
|
|
25
|
+
items: T[];
|
|
26
|
+
total: number;
|
|
27
|
+
};
|
|
28
|
+
//# sourceMappingURL=types.d.ts.map
|
package/dist/db/index.d.ts
CHANGED
package/dist/db/interface.d.ts
CHANGED
|
@@ -1,22 +1,7 @@
|
|
|
1
1
|
import type { ArcContextAny } from "../context";
|
|
2
|
-
|
|
3
|
-
$gt?: T;
|
|
4
|
-
$gte?: T;
|
|
5
|
-
$lt?: T;
|
|
6
|
-
$lte?: T;
|
|
7
|
-
} & ({
|
|
8
|
-
$gt: T;
|
|
9
|
-
} | {
|
|
10
|
-
$gte: T;
|
|
11
|
-
} | {
|
|
12
|
-
$lt: T;
|
|
13
|
-
} | {
|
|
14
|
-
$lte: T;
|
|
15
|
-
}));
|
|
2
|
+
import type { FindOptions } from "../data-storage/types";
|
|
16
3
|
export interface ReadTransaction {
|
|
17
|
-
|
|
18
|
-
findByIndex(store: string, index: string, data: IndexQueryArgument<any>): Promise<any[]>;
|
|
19
|
-
findAll(store: string): Promise<any[]>;
|
|
4
|
+
find(store: string, options: FindOptions<any>): Promise<any[]>;
|
|
20
5
|
}
|
|
21
6
|
export interface ReadWriteTransaction extends ReadTransaction {
|
|
22
7
|
remove(store: string, id: any): Promise<void>;
|