@daiso-tech/core 0.8.1 → 0.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/collection/implementations/async-iterable-collection/_shared/async-update-iterable.js.map +1 -1
- package/dist/cjs/collection/implementations/async-iterable-collection/async-iterable-collection.js +19 -0
- package/dist/cjs/collection/implementations/async-iterable-collection/async-iterable-collection.js.map +1 -1
- package/dist/cjs/collection/implementations/iterable-collection/_shared/update-iterable.js.map +1 -1
- package/dist/cjs/collection/implementations/iterable-collection/iterable-collection.js +19 -0
- package/dist/cjs/collection/implementations/iterable-collection/iterable-collection.js.map +1 -1
- package/dist/cjs/collection/implementations/list-collection/list-collection.js +31 -2
- package/dist/cjs/collection/implementations/list-collection/list-collection.js.map +1 -1
- package/dist/esm/collection/implementations/async-iterable-collection/_shared/async-update-iterable.js.map +1 -1
- package/dist/esm/collection/implementations/async-iterable-collection/async-iterable-collection.js +19 -0
- package/dist/esm/collection/implementations/async-iterable-collection/async-iterable-collection.js.map +1 -1
- package/dist/esm/collection/implementations/iterable-collection/_shared/update-iterable.js.map +1 -1
- package/dist/esm/collection/implementations/iterable-collection/iterable-collection.js +19 -0
- package/dist/esm/collection/implementations/iterable-collection/iterable-collection.js.map +1 -1
- package/dist/esm/collection/implementations/list-collection/list-collection.js +31 -2
- package/dist/esm/collection/implementations/list-collection/list-collection.js.map +1 -1
- package/dist/types/collection/contracts/_shared.d.ts +0 -1
- package/dist/types/collection/contracts/async-collection.contract.d.ts +91 -37
- package/dist/types/collection/contracts/collection.contract.d.ts +56 -2
- package/dist/types/collection/implementations/async-iterable-collection/_shared/async-update-iterable.d.ts +3 -3
- package/dist/types/collection/implementations/async-iterable-collection/async-iterable-collection.d.ts +5 -2
- package/dist/types/collection/implementations/iterable-collection/_shared/update-iterable.d.ts +3 -3
- package/dist/types/collection/implementations/iterable-collection/iterable-collection.d.ts +5 -2
- package/dist/types/collection/implementations/list-collection/list-collection.d.ts +5 -2
- package/dist/types/event-bus/contracts/event-bus.contract.d.ts +9 -8
- package/dist/types/event-bus/implementations/event-bus/event-bus.d.ts +2 -2
- package/dist/types/serializer/contracts/serializer.contract.d.ts +2 -2
- package/dist/types/storage/contracts/storage.contract.d.ts +23 -22
- package/dist/types/storage/implementations/storage/storage.d.ts +6 -6
- package/package.json +1 -1
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @module Collection
|
|
3
3
|
*/
|
|
4
|
-
import type { Comparator, Predicate, ForEach, Map, Modifier, Tap, Transform,
|
|
4
|
+
import type { Comparator, Predicate, ForEach, Map, Modifier, Tap, Transform, Reduce, CrossJoinResult } from "../../collection/contracts/_shared";
|
|
5
5
|
import type { Lazyable, RecordItem } from "../../_shared/types";
|
|
6
6
|
export type Collapse<TValue> = TValue extends Array<infer TItem> | Iterable<infer TItem> | ICollection<infer TItem> ? TItem : TValue;
|
|
7
7
|
/**
|
|
@@ -154,7 +154,61 @@ export type ICollection<TInput> = Iterable<TInput> & {
|
|
|
154
154
|
* // [1, 4, 3, 8, 5]
|
|
155
155
|
* ```
|
|
156
156
|
*/
|
|
157
|
-
change<TFilterOutput extends TInput, TMapOutput>(predicateFn: Predicate<TInput, ICollection<TInput>, TFilterOutput>, mapFn: Map<TFilterOutput, ICollection<TInput>, TMapOutput>): ICollection<
|
|
157
|
+
change<TFilterOutput extends TInput, TMapOutput>(predicateFn: Predicate<TInput, ICollection<TInput>, TFilterOutput>, mapFn: Map<TFilterOutput, ICollection<TInput>, TMapOutput>): ICollection<TInput | TFilterOutput | TMapOutput>;
|
|
158
|
+
/**
|
|
159
|
+
* The <i>set</i> method changes a item by i>index</i> using <i>value</i>.
|
|
160
|
+
* @example
|
|
161
|
+
* ```ts
|
|
162
|
+
* import { ListCollection } from "@daiso-tech/core";;
|
|
163
|
+
*
|
|
164
|
+
* const collection = new ListCollection([1, 2, 3, 4, 5]);
|
|
165
|
+
* const newCollection = collection.set(1, -1);
|
|
166
|
+
* newCollection.toArray();
|
|
167
|
+
* // [1, -1, 3, 4, 5]
|
|
168
|
+
* ```
|
|
169
|
+
* @example
|
|
170
|
+
* ```ts
|
|
171
|
+
* import { ListCollection } from "@daiso-tech/core";;
|
|
172
|
+
*
|
|
173
|
+
* const collection = new ListCollection([1, 2, 3, 4, 5]);
|
|
174
|
+
* const newCollection = collection.set(1, (prevValue) => prevValue - 2);
|
|
175
|
+
* newCollection.toArray();
|
|
176
|
+
* // [1, 0, 3, 4, 5]
|
|
177
|
+
* ```
|
|
178
|
+
*/
|
|
179
|
+
set(index: number, value: TInput | Map<TInput, ICollection<TInput>, TInput>): ICollection<TInput>;
|
|
180
|
+
/**
|
|
181
|
+
* The <i>get</i> method returns the item by index. If the item is not found null will returned.
|
|
182
|
+
* @example
|
|
183
|
+
* ```ts
|
|
184
|
+
* import { ListCollection } from "@daiso-tech/core";;
|
|
185
|
+
*
|
|
186
|
+
* const collection = new ListCollection([1, 4, 2, 8, -2]);
|
|
187
|
+
* // Will be 2
|
|
188
|
+
* collection.get(2);
|
|
189
|
+
*
|
|
190
|
+
* // Will be null
|
|
191
|
+
* collection.get(5);
|
|
192
|
+
* ```
|
|
193
|
+
*/
|
|
194
|
+
get(index: number): TInput | null;
|
|
195
|
+
/**
|
|
196
|
+
* The <i>getOrFail</i> method returns the item by index. If the item is not found an error will be thrown.
|
|
197
|
+
* @throws {UnexpectedCollectionError} {@link UnexpectedCollectionError}
|
|
198
|
+
* @throws {ItemNotFoundCollectionError} {@link ItemNotFoundCollectionError}
|
|
199
|
+
* @example
|
|
200
|
+
* ```ts
|
|
201
|
+
* import { ListCollection } from "@daiso-tech/core";;
|
|
202
|
+
*
|
|
203
|
+
* const collection = new ListCollection([1, 4, 2, 8, -2]);
|
|
204
|
+
* // Will be 2
|
|
205
|
+
* collection.getOrFail(2);
|
|
206
|
+
*
|
|
207
|
+
* // An error will thrown
|
|
208
|
+
* collection.getOrFail(5);
|
|
209
|
+
* ```
|
|
210
|
+
*/
|
|
211
|
+
getOrFail(index: number): TInput;
|
|
158
212
|
/**
|
|
159
213
|
* The <i>page</i> method returns a new collection containing the items that would be present on <i> page </i> with custom <i> pageSize </i>.
|
|
160
214
|
* @example
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @module Collection
|
|
3
3
|
*/
|
|
4
|
-
import { type AsyncPredicate, type AsyncMap, type IAsyncCollection
|
|
4
|
+
import { type AsyncPredicate, type AsyncMap, type IAsyncCollection } from "../../../../collection/contracts/_module";
|
|
5
5
|
/**
|
|
6
6
|
* @internal
|
|
7
7
|
*/
|
|
8
|
-
export declare class AsyncUpdateIterable<TInput, TFilterOutput extends TInput, TMapOutput> implements AsyncIterable<
|
|
8
|
+
export declare class AsyncUpdateIterable<TInput, TFilterOutput extends TInput, TMapOutput> implements AsyncIterable<TInput | TFilterOutput | TMapOutput> {
|
|
9
9
|
private collection;
|
|
10
10
|
private predicateFn;
|
|
11
11
|
private mapFn;
|
|
12
12
|
constructor(collection: IAsyncCollection<TInput>, predicateFn: AsyncPredicate<TInput, IAsyncCollection<TInput>, TFilterOutput>, mapFn: AsyncMap<TFilterOutput, IAsyncCollection<TInput>, TMapOutput>);
|
|
13
|
-
[Symbol.asyncIterator](): AsyncIterator<
|
|
13
|
+
[Symbol.asyncIterator](): AsyncIterator<TInput | TFilterOutput | TMapOutput>;
|
|
14
14
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @module Collection
|
|
3
3
|
*/
|
|
4
|
-
import { type AsyncCollapse, type AsyncPredicate, type AsyncForEach, type AsyncMap, type AsyncModifier, type AsyncTap, type AsyncTransform, type Comparator, type IAsyncCollection, type
|
|
4
|
+
import { type AsyncCollapse, type AsyncPredicate, type AsyncForEach, type AsyncMap, type AsyncModifier, type AsyncTap, type AsyncTransform, type Comparator, type IAsyncCollection, type AsyncReduce, type CrossJoinResult } from "../../../collection/contracts/_module";
|
|
5
5
|
import { type AsyncIterableValue, type AsyncLazyable } from "../../../_shared/types";
|
|
6
6
|
import { type RecordItem } from "../../../_shared/types";
|
|
7
7
|
import type { TimeSpan } from "../../../utilities/_module";
|
|
@@ -34,7 +34,10 @@ export declare class AsyncIterableCollection<TInput> implements IAsyncCollection
|
|
|
34
34
|
join(separator?: string): LazyPromise<Extract<TInput, string>>;
|
|
35
35
|
collapse(): IAsyncCollection<AsyncCollapse<TInput>>;
|
|
36
36
|
flatMap<TOutput>(mapFn: AsyncMap<TInput, IAsyncCollection<TInput>, Iterable<TOutput>>): IAsyncCollection<TOutput>;
|
|
37
|
-
change<TFilterOutput extends TInput, TMapOutput>(predicateFn: AsyncPredicate<TInput, IAsyncCollection<TInput>, TFilterOutput>, mapFn: AsyncMap<TFilterOutput, IAsyncCollection<TInput>, TMapOutput>): IAsyncCollection<
|
|
37
|
+
change<TFilterOutput extends TInput, TMapOutput>(predicateFn: AsyncPredicate<TInput, IAsyncCollection<TInput>, TFilterOutput>, mapFn: AsyncMap<TFilterOutput, IAsyncCollection<TInput>, TMapOutput>): IAsyncCollection<TInput | TFilterOutput | TMapOutput>;
|
|
38
|
+
set(index: number, value: TInput | AsyncMap<TInput, IAsyncCollection<TInput>, TInput>): IAsyncCollection<TInput>;
|
|
39
|
+
get(index: number): LazyPromise<TInput | null>;
|
|
40
|
+
getOrFail(index: number): LazyPromise<TInput>;
|
|
38
41
|
page(page: number, pageSize: number): IAsyncCollection<TInput>;
|
|
39
42
|
sum(): LazyPromise<Extract<TInput, number>>;
|
|
40
43
|
average(): LazyPromise<Extract<TInput, number>>;
|
package/dist/types/collection/implementations/iterable-collection/_shared/update-iterable.d.ts
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @module Collection
|
|
3
3
|
*/
|
|
4
|
-
import { type Predicate, type ICollection, type Map
|
|
4
|
+
import { type Predicate, type ICollection, type Map } from "../../../../collection/contracts/_module";
|
|
5
5
|
/**
|
|
6
6
|
* @internal
|
|
7
7
|
*/
|
|
8
|
-
export declare class UpdateIterable<TInput, TFilterOutput extends TInput, TMapOutput> implements Iterable<
|
|
8
|
+
export declare class UpdateIterable<TInput, TFilterOutput extends TInput, TMapOutput> implements Iterable<TInput | TFilterOutput | TMapOutput> {
|
|
9
9
|
private collection;
|
|
10
10
|
private predicateFn;
|
|
11
11
|
private mapFn;
|
|
12
12
|
constructor(collection: ICollection<TInput>, predicateFn: Predicate<TInput, ICollection<TInput>, TFilterOutput>, mapFn: Map<TFilterOutput, ICollection<TInput>, TMapOutput>);
|
|
13
|
-
[Symbol.iterator](): Iterator<
|
|
13
|
+
[Symbol.iterator](): Iterator<TInput | TFilterOutput | TMapOutput>;
|
|
14
14
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @module Collection
|
|
3
3
|
*/
|
|
4
|
-
import { type Collapse, type Comparator, type Predicate, type ForEach, type ICollection, type Map, type Modifier, type Tap, type Transform, type
|
|
4
|
+
import { type Collapse, type Comparator, type Predicate, type ForEach, type ICollection, type Map, type Modifier, type Tap, type Transform, type Reduce, type CrossJoinResult } from "../../../collection/contracts/_module";
|
|
5
5
|
import { type Lazyable } from "../../../_shared/types";
|
|
6
6
|
import { type RecordItem } from "../../../_shared/types";
|
|
7
7
|
/**
|
|
@@ -31,7 +31,10 @@ export declare class IterableCollection<TInput> implements ICollection<TInput> {
|
|
|
31
31
|
join(separator?: string): Extract<TInput, string>;
|
|
32
32
|
collapse(): ICollection<Collapse<TInput>>;
|
|
33
33
|
flatMap<TOutput>(mapFn: Map<TInput, ICollection<TInput>, Iterable<TOutput>>): ICollection<TOutput>;
|
|
34
|
-
change<TFilterOutput extends TInput, TMapOutput>(predicateFn: Predicate<TInput, ICollection<TInput>, TFilterOutput>, mapFn: Map<TFilterOutput, ICollection<TInput>, TMapOutput>): ICollection<
|
|
34
|
+
change<TFilterOutput extends TInput, TMapOutput>(predicateFn: Predicate<TInput, ICollection<TInput>, TFilterOutput>, mapFn: Map<TFilterOutput, ICollection<TInput>, TMapOutput>): ICollection<TInput | TFilterOutput | TMapOutput>;
|
|
35
|
+
set(index: number, value: TInput | Map<TInput, ICollection<TInput>, TInput>): ICollection<TInput>;
|
|
36
|
+
get(index: number): TInput | null;
|
|
37
|
+
getOrFail(index: number): TInput;
|
|
35
38
|
page(page: number, pageSize: number): ICollection<TInput>;
|
|
36
39
|
sum(): Extract<TInput, number>;
|
|
37
40
|
average(): Extract<TInput, number>;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @module Collection
|
|
3
3
|
*/
|
|
4
|
-
import { type Collapse, type Comparator, type Predicate, type ICollection, type Map, type Modifier, type Tap, type Transform, type
|
|
4
|
+
import { type Collapse, type Comparator, type Predicate, type ICollection, type Map, type Modifier, type Tap, type Transform, type Reduce, type ForEach, type CrossJoinResult } from "../../../collection/contracts/_module";
|
|
5
5
|
import { type Lazyable } from "../../../_shared/types";
|
|
6
6
|
import { type RecordItem } from "../../../_shared/types";
|
|
7
7
|
/**
|
|
@@ -28,7 +28,10 @@ export declare class ListCollection<TInput> implements ICollection<TInput> {
|
|
|
28
28
|
join(separator?: string): Extract<TInput, string>;
|
|
29
29
|
collapse(): ICollection<Collapse<TInput>>;
|
|
30
30
|
flatMap<TOutput>(mapFn: Map<TInput, ICollection<TInput>, Iterable<TOutput>>): ICollection<TOutput>;
|
|
31
|
-
change<TFilterOutput extends TInput, TMapOutput>(predicateFn: Predicate<TInput, ICollection<TInput>, TFilterOutput>, mapFn: Map<TFilterOutput, ICollection<TInput>, TMapOutput>): ICollection<
|
|
31
|
+
change<TFilterOutput extends TInput, TMapOutput>(predicateFn: Predicate<TInput, ICollection<TInput>, TFilterOutput>, mapFn: Map<TFilterOutput, ICollection<TInput>, TMapOutput>): ICollection<TInput | TFilterOutput | TMapOutput>;
|
|
32
|
+
set(index: number, value: TInput | Map<TInput, ICollection<TInput>, TInput>): ICollection<TInput>;
|
|
33
|
+
get(index: number): TInput | null;
|
|
34
|
+
getOrFail(index: number): TInput;
|
|
32
35
|
page(page: number, pageSize: number): ICollection<TInput>;
|
|
33
36
|
sum(): Extract<TInput, number>;
|
|
34
37
|
average(): Extract<TInput, number>;
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @module EventBus
|
|
3
3
|
*/
|
|
4
|
+
import type { LazyPromise } from "../../_module";
|
|
4
5
|
import type { OneOrMore } from "../../_shared/types";
|
|
5
6
|
import type { IBaseEvent, Listener } from "../../event-bus/contracts/_shared";
|
|
6
7
|
export type SelectEvent<TEvents extends IBaseEvent, TEventType extends TEvents["type"]> = Extract<TEvents, {
|
|
7
8
|
type: IBaseEvent extends TEvents ? string : TEventType;
|
|
8
9
|
}>;
|
|
9
|
-
export type Unsubscribe = () =>
|
|
10
|
+
export type Unsubscribe = () => LazyPromise<void>;
|
|
10
11
|
/**
|
|
11
12
|
* The <i>IListenable</i> contract defines a way listening to events independent of underlying technology
|
|
12
13
|
* @group Contracts
|
|
@@ -17,35 +18,35 @@ export type IListenable<TEvents extends IBaseEvent = IBaseEvent> = {
|
|
|
17
18
|
* A listener can only be added once for a specific event. Adding the same listener multiple times will have no effect and nothing will occur.
|
|
18
19
|
* @throws {AddListenerEventBusError} {@link AddListenerEventBusError}
|
|
19
20
|
*/
|
|
20
|
-
addListener<TEventType extends TEvents["type"]>(event: TEventType, listener: Listener<SelectEvent<TEvents, TEventType>>):
|
|
21
|
+
addListener<TEventType extends TEvents["type"]>(event: TEventType, listener: Listener<SelectEvent<TEvents, TEventType>>): LazyPromise<void>;
|
|
21
22
|
/**
|
|
22
23
|
* The <i>addListenerMany</i> method is used for adding multiple <i>{@link Listener | listeners}</i> for certain <i>events</i>.
|
|
23
24
|
* A listener can only be added once for a specific event. Adding the same listener multiple times will have no effect and nothing will occur.
|
|
24
25
|
* @throws {AddListenerEventBusError} {@link AddListenerEventBusError}
|
|
25
26
|
*/
|
|
26
|
-
addListenerMany<TEventType extends TEvents["type"]>(events: TEventType[], listener: Listener<SelectEvent<TEvents, TEventType>>):
|
|
27
|
+
addListenerMany<TEventType extends TEvents["type"]>(events: TEventType[], listener: Listener<SelectEvent<TEvents, TEventType>>): LazyPromise<void>;
|
|
27
28
|
/**
|
|
28
29
|
* The <i>removeListener</i> method is used for removing <i>{@link Listener | listener}</i> for certain <i>event</i>.
|
|
29
30
|
* Removing unadded listener will have no effect and nothing will occur.
|
|
30
31
|
* @throws {RemoveListenerEventBusError} {@link RemoveListenerEventBusError}
|
|
31
32
|
*/
|
|
32
|
-
removeListener<TEventType extends TEvents["type"]>(event: TEventType, listener: Listener<SelectEvent<TEvents, TEventType>>):
|
|
33
|
+
removeListener<TEventType extends TEvents["type"]>(event: TEventType, listener: Listener<SelectEvent<TEvents, TEventType>>): LazyPromise<void>;
|
|
33
34
|
/**
|
|
34
35
|
* The <i>removeListener</i> method is used for removing multiple <i>{@link Listener | listeners}</i> for certain <i>event</i>.
|
|
35
36
|
* Removing unadded listener will have no effect and nothing will occur.
|
|
36
37
|
* @throws {RemoveListenerEventBusError} {@link RemoveListenerEventBusError}
|
|
37
38
|
*/
|
|
38
|
-
removeListenerMany<TEventType extends TEvents["type"]>(events: TEventType[], listener: Listener<SelectEvent<TEvents, TEventType>>):
|
|
39
|
+
removeListenerMany<TEventType extends TEvents["type"]>(events: TEventType[], listener: Listener<SelectEvent<TEvents, TEventType>>): LazyPromise<void>;
|
|
39
40
|
/**
|
|
40
41
|
* The <i>subscribe</i> method is used for adding <i>{@link Listener | listener}</i> for certain <i>event</i>.
|
|
41
42
|
* A listener can only be added once for a specific event. Adding the same listener multiple times will have no effect and nothing will occur.
|
|
42
43
|
*/
|
|
43
|
-
subscribe<TEventType extends TEvents["type"]>(event: TEventType, listener: Listener<SelectEvent<TEvents, TEventType>>):
|
|
44
|
+
subscribe<TEventType extends TEvents["type"]>(event: TEventType, listener: Listener<SelectEvent<TEvents, TEventType>>): LazyPromise<Unsubscribe>;
|
|
44
45
|
/**
|
|
45
46
|
* The <i>subscribeMany</i> method is used for adding <i>{@link Listener | listener}</i> for multiple <i>events</i>.
|
|
46
47
|
* A listener can only be added once for a specific event. Adding the same listener multiple times will have no effect and nothing will occur.
|
|
47
48
|
*/
|
|
48
|
-
subscribeMany<TEventType extends TEvents["type"]>(events: TEventType[], listener: Listener<SelectEvent<TEvents, TEventType>>):
|
|
49
|
+
subscribeMany<TEventType extends TEvents["type"]>(events: TEventType[], listener: Listener<SelectEvent<TEvents, TEventType>>): LazyPromise<Unsubscribe>;
|
|
49
50
|
};
|
|
50
51
|
/**
|
|
51
52
|
* The <i>IEventBus</i> contract defines a way for dispatching and listening to events independent of underlying technology.
|
|
@@ -58,7 +59,7 @@ export type IEventBus<TEvents extends IBaseEvent = IBaseEvent> = IListenable<TEv
|
|
|
58
59
|
|
|
59
60
|
* @throws {DispatchEventBusError} {@link DispatchEventBusError}
|
|
60
61
|
*/
|
|
61
|
-
dispatch(events: OneOrMore<TEvents>):
|
|
62
|
+
dispatch(events: OneOrMore<TEvents>): LazyPromise<void>;
|
|
62
63
|
/**
|
|
63
64
|
* The <i>getNamespace</i> method return the complete namespace.
|
|
64
65
|
* @example
|
|
@@ -96,7 +96,7 @@ export declare class EventBus<TEvents extends IBaseEvent = IBaseEvent> implement
|
|
|
96
96
|
addListenerMany<TEventType extends TEvents["type"]>(events: TEventType[], listener: Listener<SelectEvent<TEvents, TEventType>>): LazyPromise<void>;
|
|
97
97
|
removeListener<TEventType extends TEvents["type"]>(event: TEventType, listener: Listener<SelectEvent<TEvents, TEventType>>): LazyPromise<void>;
|
|
98
98
|
removeListenerMany<TEventType extends TEvents["type"]>(events: TEventType[], listener: Listener<SelectEvent<TEvents, TEventType>>): LazyPromise<void>;
|
|
99
|
-
subscribe<TEventType extends TEvents["type"]>(event: TEventType, listener: Listener<SelectEvent<TEvents, TEventType>>):
|
|
100
|
-
subscribeMany<TEventType extends TEvents["type"]>(events: TEventType[], listener: Listener<SelectEvent<TEvents, TEventType>>):
|
|
99
|
+
subscribe<TEventType extends TEvents["type"]>(event: TEventType, listener: Listener<SelectEvent<TEvents, TEventType>>): LazyPromise<Unsubscribe>;
|
|
100
|
+
subscribeMany<TEventType extends TEvents["type"]>(events: TEventType[], listener: Listener<SelectEvent<TEvents, TEventType>>): LazyPromise<Unsubscribe>;
|
|
101
101
|
dispatch(events: OneOrMore<TEvents>): LazyPromise<void>;
|
|
102
102
|
}
|
|
@@ -26,9 +26,9 @@ export type ISerializer<TSerialized = unknown> = {
|
|
|
26
26
|
/**
|
|
27
27
|
* @throws {SerializationError} {@link SerializationError}
|
|
28
28
|
*/
|
|
29
|
-
serialize<TValue>(value: TValue):
|
|
29
|
+
serialize<TValue>(value: TValue): PromiseLike<TSerialized>;
|
|
30
30
|
/**
|
|
31
31
|
* @throws {DeserializationError} {@link DeserializationError}
|
|
32
32
|
*/
|
|
33
|
-
deserialize<TValue>(value: TSerialized):
|
|
33
|
+
deserialize<TValue>(value: TSerialized): PromiseLike<TValue>;
|
|
34
34
|
};
|
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
import type { IListenable } from "../../event-bus/contracts/_module";
|
|
5
5
|
import { type AnyFunction, type AsyncLazyable, type GetOrAddValue } from "../../_shared/types";
|
|
6
6
|
import type { AllStorageEvents } from "../../storage/contracts/_module";
|
|
7
|
+
import type { LazyPromise } from "../../_module";
|
|
7
8
|
export type StorageValue<T> = Exclude<T, AnyFunction | undefined | null>;
|
|
8
9
|
/**
|
|
9
10
|
* The <i>IStorageListenable</i> contract defines a way for listening <i>{@link IStorage}</i> crud operations.
|
|
@@ -19,98 +20,98 @@ export type IStorage<TType = unknown> = IStorageListenable & {
|
|
|
19
20
|
* The <i>exists</i> method returns true when <i>key</i> is found otherwise false will be returned.
|
|
20
21
|
* @throws {UnexpectedStorageError} {@link UnexpectedStorageError}
|
|
21
22
|
*/
|
|
22
|
-
exists(key: string):
|
|
23
|
+
exists(key: string): LazyPromise<boolean>;
|
|
23
24
|
/**
|
|
24
25
|
* The <i>existsMany</i> method returns true for the <i>keys</i> that are found otherwise false will be returned.
|
|
25
26
|
* @throws {UnexpectedStorageError} {@link UnexpectedStorageError}
|
|
26
27
|
*/
|
|
27
|
-
existsMany<TKeys extends string>(keys: TKeys[]):
|
|
28
|
+
existsMany<TKeys extends string>(keys: TKeys[]): LazyPromise<Record<TKeys, boolean>>;
|
|
28
29
|
/**
|
|
29
30
|
* The <i>missing</i> method returns true when <i>key</i> is not found otherwise false will be returned.
|
|
30
31
|
* @throws {UnexpectedStorageError} {@link UnexpectedStorageError}
|
|
31
32
|
*/
|
|
32
|
-
missing(key: string):
|
|
33
|
+
missing(key: string): LazyPromise<boolean>;
|
|
33
34
|
/**
|
|
34
35
|
* The <i>missingMany</i> method returns true for the <i>keys</i> that are not found otherwise false will be returned.
|
|
35
36
|
* @throws {UnexpectedStorageError} {@link UnexpectedStorageError}
|
|
36
37
|
*/
|
|
37
|
-
missingMany<TKeys extends string>(keys: TKeys[]):
|
|
38
|
+
missingMany<TKeys extends string>(keys: TKeys[]): LazyPromise<Record<TKeys, boolean>>;
|
|
38
39
|
/**
|
|
39
40
|
* The <i>get</i> method returns the value when <i>key</i> is found otherwise null will be returned.
|
|
40
41
|
* @throws {UnexpectedStorageError} {@link UnexpectedStorageError}
|
|
41
42
|
*/
|
|
42
|
-
get(key: string):
|
|
43
|
+
get(key: string): LazyPromise<TType | null>;
|
|
43
44
|
/**
|
|
44
45
|
* The <i>getMany</i> returns the value for the <i>keys</i> that are found otherwise null will be returned.
|
|
45
46
|
* @throws {UnexpectedStorageError} {@link UnexpectedStorageError}
|
|
46
47
|
*/
|
|
47
|
-
getMany<TKeys extends string>(keys: TKeys[]):
|
|
48
|
+
getMany<TKeys extends string>(keys: TKeys[]): LazyPromise<Record<TKeys, TType | null>>;
|
|
48
49
|
/**
|
|
49
50
|
* The <i>getOr</i> method returns the value when <i>key</i> is found otherwise <i>defaultValue</i> will be returned.
|
|
50
51
|
* @throws {UnexpectedStorageError} {@link UnexpectedStorageError}
|
|
51
52
|
*/
|
|
52
|
-
getOr(key: string, defaultValue: AsyncLazyable<TType>):
|
|
53
|
+
getOr(key: string, defaultValue: AsyncLazyable<TType>): LazyPromise<TType>;
|
|
53
54
|
/**
|
|
54
55
|
* The <i>getOrMany</i> method returns the value for the keys that are found otherwise defaultValue will be returned.
|
|
55
56
|
* @throws {UnexpectedStorageError} {@link UnexpectedStorageError}
|
|
56
57
|
*/
|
|
57
|
-
getOrMany<TKeys extends string>(keysWithDefaults: Record<TKeys, AsyncLazyable<TType>>):
|
|
58
|
+
getOrMany<TKeys extends string>(keysWithDefaults: Record<TKeys, AsyncLazyable<TType>>): LazyPromise<Record<TKeys, TType>>;
|
|
58
59
|
/**
|
|
59
60
|
* The <i>getOrFail</i> method returns the value when <i>key</i> is found otherwise an error will be thrown.
|
|
60
61
|
* @throws {UnexpectedStorageError} {@link UnexpectedStorageError}
|
|
61
62
|
* @throws {KeyNotFoundStorageError} {@link KeyNotFoundStorageError}
|
|
62
63
|
*/
|
|
63
|
-
getOrFail(key: string):
|
|
64
|
+
getOrFail(key: string): LazyPromise<TType>;
|
|
64
65
|
/**
|
|
65
66
|
* The <i>add</i> method adds a <i>key</i> with given <i>value</i> when key doesn't exists. Returns true when key doesn't exists otherwise false will be returned.
|
|
66
67
|
* @throws {UnexpectedStorageError} {@link UnexpectedStorageError}
|
|
67
68
|
*/
|
|
68
|
-
add(key: string, value: StorageValue<TType>):
|
|
69
|
+
add(key: string, value: StorageValue<TType>): LazyPromise<boolean>;
|
|
69
70
|
/**
|
|
70
71
|
* The <i>addMany</i> method adds the keys that doesn't exists. Returns true for the keys that doesn't exists otherwise false will be returned.
|
|
71
72
|
* @throws {UnexpectedStorageError} {@link UnexpectedStorageError}
|
|
72
73
|
*/
|
|
73
|
-
addMany<TKeys extends string>(values: Record<TKeys, StorageValue<TType>>):
|
|
74
|
+
addMany<TKeys extends string>(values: Record<TKeys, StorageValue<TType>>): LazyPromise<Record<TKeys, boolean>>;
|
|
74
75
|
/**
|
|
75
76
|
* The <i>update</i> method updates the given <i>key</i> with given <i>value</i>. Returns true when key otherwise false will be returned.
|
|
76
77
|
* @throws {UnexpectedStorageError} {@link UnexpectedStorageError}
|
|
77
78
|
*/
|
|
78
|
-
update(key: string, value: TType):
|
|
79
|
+
update(key: string, value: TType): LazyPromise<boolean>;
|
|
79
80
|
/**
|
|
80
81
|
* The <i>updateMany</i> method updates the given keys. Returns true for the keys that exists otherwise false will be returned.
|
|
81
82
|
* @throws {UnexpectedStorageError} {@link UnexpectedStorageError}
|
|
82
83
|
*/
|
|
83
|
-
updateMany<TKeys extends string>(values: Record<TKeys, TType>):
|
|
84
|
+
updateMany<TKeys extends string>(values: Record<TKeys, TType>): LazyPromise<Record<TKeys, boolean>>;
|
|
84
85
|
/**
|
|
85
86
|
* The <i>put</i> method replaces the key with given <i>value</i> if found. If the <i>key</i> is not found it will just be added. True is returned if the key is found otherwise false will be returned.
|
|
86
87
|
* @throws {UnexpectedStorageError} {@link UnexpectedStorageError}
|
|
87
88
|
*/
|
|
88
|
-
put(key: string, value: StorageValue<TType>):
|
|
89
|
+
put(key: string, value: StorageValue<TType>): LazyPromise<boolean>;
|
|
89
90
|
/**
|
|
90
91
|
* The <i>putMany</i> method replaces the keys that are found. Adds keys that are not found. Returns true for all the keys that are found otherwise false is returned.
|
|
91
92
|
* @throws {UnexpectedStorageError} {@link UnexpectedStorageError}
|
|
92
93
|
*/
|
|
93
|
-
putMany<TKeys extends string>(values: Record<TKeys, StorageValue<TType>>):
|
|
94
|
+
putMany<TKeys extends string>(values: Record<TKeys, StorageValue<TType>>): LazyPromise<Record<TKeys, boolean>>;
|
|
94
95
|
/**
|
|
95
96
|
* The <i>remove</i> method removes the given <i>key</i> when found. Returns true if the key is found otherwise false is returned.
|
|
96
97
|
* @throws {UnexpectedStorageError} {@link UnexpectedStorageError}
|
|
97
98
|
*/
|
|
98
|
-
remove(key: string):
|
|
99
|
+
remove(key: string): LazyPromise<boolean>;
|
|
99
100
|
/**
|
|
100
101
|
* The <i>removesMany</i> method removes the keys that are found. Returns true for the keys that are found otherwise false is returned.
|
|
101
102
|
* @throws {UnexpectedStorageError} {@link UnexpectedStorageError}
|
|
102
103
|
*/
|
|
103
|
-
removeMany<TKeys extends string>(keys: TKeys[]):
|
|
104
|
+
removeMany<TKeys extends string>(keys: TKeys[]): LazyPromise<Record<TKeys, boolean>>;
|
|
104
105
|
/**
|
|
105
106
|
* The <i>getAndRemove</i> method removes the given <i>key</i> and returns it when found otherwise null will be returned.
|
|
106
107
|
* @throws {UnexpectedStorageError} {@link UnexpectedStorageError}
|
|
107
108
|
*/
|
|
108
|
-
getAndRemove(key: string):
|
|
109
|
+
getAndRemove(key: string): LazyPromise<TType | null>;
|
|
109
110
|
/**
|
|
110
111
|
* The <i>getOrAdd</i> method will retrieve the given <i>key</i> if found otherwise <i>valueToAdd</i> will be added and returned.
|
|
111
112
|
* @throws {UnexpectedStorageError} {@link UnexpectedStorageError}
|
|
112
113
|
*/
|
|
113
|
-
getOrAdd(key: string, valueToAdd: AsyncLazyable<StorageValue<GetOrAddValue<TType>>>):
|
|
114
|
+
getOrAdd(key: string, valueToAdd: AsyncLazyable<StorageValue<GetOrAddValue<TType>>>): LazyPromise<TType>;
|
|
114
115
|
/**
|
|
115
116
|
* The <i>increment</i> method will increment the given <i>key</i> if found otherwise nonthing will occur.
|
|
116
117
|
* Returns true if key exists otherwise false will be returned.
|
|
@@ -118,7 +119,7 @@ export type IStorage<TType = unknown> = IStorageListenable & {
|
|
|
118
119
|
* @throws {UnexpectedStorageError} {@link UnexpectedStorageError}
|
|
119
120
|
* @throws {TypeStorageError} {@link TypeStorageError}
|
|
120
121
|
*/
|
|
121
|
-
increment(key: string, value?: Extract<TType, number>):
|
|
122
|
+
increment(key: string, value?: Extract<TType, number>): LazyPromise<boolean>;
|
|
122
123
|
/**
|
|
123
124
|
* The <i>decrement</i> method will decrement the given <i>key</i> if found otherwise nonthing will occur.
|
|
124
125
|
* Returns true if key exists otherwise false will be returned.
|
|
@@ -127,12 +128,12 @@ export type IStorage<TType = unknown> = IStorageListenable & {
|
|
|
127
128
|
* @throws {TypeStorageError} {@link TypeStorageError}
|
|
128
129
|
* An error will thrown if the key is not a number.
|
|
129
130
|
*/
|
|
130
|
-
decrement(key: string, value?: Extract<TType, number>):
|
|
131
|
+
decrement(key: string, value?: Extract<TType, number>): LazyPromise<boolean>;
|
|
131
132
|
/**
|
|
132
133
|
* The <i>clear</i> method removes all the keys in the storage.
|
|
133
134
|
* @throws {UnexpectedStorageError} {@link UnexpectedStorageError}
|
|
134
135
|
*/
|
|
135
|
-
clear():
|
|
136
|
+
clear(): LazyPromise<void>;
|
|
136
137
|
/**
|
|
137
138
|
* The <i>getNamespace</i> method return the complete namespace.
|
|
138
139
|
* @example
|
|
@@ -81,12 +81,12 @@ export declare class Storage<TType = unknown> implements INamespacedStorage<TTyp
|
|
|
81
81
|
private readonly validator;
|
|
82
82
|
private readonly eventBus;
|
|
83
83
|
constructor(storageAdapter: IStorageAdapter<any>, settings?: StorageSettings<TType>);
|
|
84
|
-
addListener<TEventType extends AllStorageEvents<TType>["type"]>(event: TEventType, listener: Listener<SelectEvent<AllStorageEvents<TType>, TEventType>>):
|
|
85
|
-
addListenerMany<TEventType extends AllStorageEvents<TType>["type"]>(events: TEventType[], listener: Listener<SelectEvent<AllStorageEvents<TType>, TEventType>>):
|
|
86
|
-
removeListener<TEventType extends AllStorageEvents<TType>["type"]>(event: TEventType, listener: Listener<SelectEvent<AllStorageEvents<TType>, TEventType>>):
|
|
87
|
-
removeListenerMany<TEventType extends AllStorageEvents<TType>["type"]>(events: TEventType[], listener: Listener<SelectEvent<AllStorageEvents<TType>, TEventType>>):
|
|
88
|
-
subscribe<TEventType extends AllStorageEvents<TType>["type"]>(event: TEventType, listener: Listener<SelectEvent<AllStorageEvents<TType>, TEventType>>):
|
|
89
|
-
subscribeMany<TEventType extends AllStorageEvents<TType>["type"]>(events: TEventType[], listener: Listener<SelectEvent<AllStorageEvents<TType>, TEventType>>):
|
|
84
|
+
addListener<TEventType extends AllStorageEvents<TType>["type"]>(event: TEventType, listener: Listener<SelectEvent<AllStorageEvents<TType>, TEventType>>): LazyPromise<void>;
|
|
85
|
+
addListenerMany<TEventType extends AllStorageEvents<TType>["type"]>(events: TEventType[], listener: Listener<SelectEvent<AllStorageEvents<TType>, TEventType>>): LazyPromise<void>;
|
|
86
|
+
removeListener<TEventType extends AllStorageEvents<TType>["type"]>(event: TEventType, listener: Listener<SelectEvent<AllStorageEvents<TType>, TEventType>>): LazyPromise<void>;
|
|
87
|
+
removeListenerMany<TEventType extends AllStorageEvents<TType>["type"]>(events: TEventType[], listener: Listener<SelectEvent<AllStorageEvents<TType>, TEventType>>): LazyPromise<void>;
|
|
88
|
+
subscribe<TEventType extends AllStorageEvents<TType>["type"]>(event: TEventType, listener: Listener<SelectEvent<AllStorageEvents<TType>, TEventType>>): LazyPromise<Unsubscribe>;
|
|
89
|
+
subscribeMany<TEventType extends AllStorageEvents<TType>["type"]>(events: TEventType[], listener: Listener<SelectEvent<AllStorageEvents<TType>, TEventType>>): LazyPromise<Unsubscribe>;
|
|
90
90
|
withNamespace(namespace: string): IStorage<TType>;
|
|
91
91
|
getNamespace(): string;
|
|
92
92
|
exists(key: string): LazyPromise<boolean>;
|