Skip to content

Commit

Permalink
Feature/event bus (#59)
Browse files Browse the repository at this point in the history
* Removed unnecessary files, updated the docs and removed unnecessary methods for some classes

* Added IEventBus and IEventBusAdapter contracts

* Added redis event bus adapter

* Added memory event bus adapter

* Added event bus class

* Added reusable tests for event bus

* Added tests for memory event bus adapter

* Added tests for redis event bus adapter

* Added tests for event bus class

* Added exports
  • Loading branch information
yousif-khalil-abdulkarim authored Jan 2, 2025
1 parent e3dc339 commit ec94bfc
Show file tree
Hide file tree
Showing 141 changed files with 1,804 additions and 1,844 deletions.
2 changes: 2 additions & 0 deletions src/_module.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
export * from "@/collection/implementations/_module";
export * from "@/collection/contracts/_module";
export * from "@/event-bus/implementations/_module";
export * from "@/event-bus/contracts/_module";
export * from "@/serializer/implementations/_module";
export * from "@/serializer/contracts/_module";
export * from "@/storage/implementations/_module";
Expand Down
3 changes: 0 additions & 3 deletions src/_shared/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@
* @module Shared
*/

export type EnsureType<TValue, TType> =
Exclude<TValue, TType> extends never ? TValue : never;

export type RecordItem<TKey, TValue> = [key: TKey, value: TValue];

export type Lazyable<TValue> = TValue | (() => TValue);
Expand Down
16 changes: 8 additions & 8 deletions src/collection/contracts/async-collection.contract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ import type {
import type {
RecordItem,
AsyncLazyable,
EnsureType,
AsyncIterableValue,
} from "@/_shared/types";
import type { TimeSpan } from "@/utilities/_module";
Expand All @@ -43,7 +42,8 @@ export type AsyncCollapse<TValue> = TValue extends
: TValue;

/**
* <i>IAsyncCollection</i> is immutable. The <i>throwOnIndexOverflow</i> parameter in the <i>IAsyncCollection</i> methods is used for preventing the index to overflow by throwing an error.
* The <i>IAsyncCollection</i> contract offers a fluent and efficient approach to working with {@link AsyncIterable} objects.
* <i>IAsyncCollection</i> is immutable.
* @throws {CollectionError} {@link CollectionError}
* @throws {UnexpectedCollectionError}
* @throws {ItemNotFoundCollectionError}
Expand Down Expand Up @@ -167,7 +167,7 @@ export type IAsyncCollection<TInput> = AsyncIterable<TInput> & {
* await collection.map(item => item.toString()).join("_");
* // "1_2_3_4"
*/
join(separator?: string): PromiseLike<EnsureType<TInput, string>>;
join(separator?: string): PromiseLike<Extract<TInput, string>>;

/**
* The <i>collapse</i> method collapses a collection of iterables into a single, flat collection.
Expand Down Expand Up @@ -239,7 +239,7 @@ export type IAsyncCollection<TInput> = AsyncIterable<TInput> & {
* @throws {TypeCollectionError} {@link TypeCollectionError}
* @throws {EmptyCollectionError} {@link EmptyCollectionError}
*/
sum(): PromiseLike<EnsureType<TInput, number>>;
sum(): PromiseLike<Extract<TInput, number>>;

/**
* The <i>average</i> method returns the average of all items in the collection. If the collection includes other than number items an error will be thrown.
Expand All @@ -254,7 +254,7 @@ export type IAsyncCollection<TInput> = AsyncIterable<TInput> & {
* @throws {TypeCollectionError} {@link TypeCollectionError}
* @throws {EmptyCollectionError} {@link EmptyCollectionError}
*/
average(): PromiseLike<EnsureType<TInput, number>>;
average(): PromiseLike<Extract<TInput, number>>;

/**
* The <i>median</i> method returns the median of all items in the collection. If the collection includes other than number items an error will be thrown.
Expand All @@ -269,7 +269,7 @@ export type IAsyncCollection<TInput> = AsyncIterable<TInput> & {
* @throws {TypeCollectionError} {@link TypeCollectionError}
* @throws {EmptyCollectionError} {@link EmptyCollectionError}
*/
median(): PromiseLike<EnsureType<TInput, number>>;
median(): PromiseLike<Extract<TInput, number>>;

/**
* The <i>min</i> method returns the min of all items in the collection. If the collection includes other than number items an error will be thrown.
Expand All @@ -284,7 +284,7 @@ export type IAsyncCollection<TInput> = AsyncIterable<TInput> & {
* @throws {TypeCollectionError} {@link TypeCollectionError}
* @throws {EmptyCollectionError} {@link EmptyCollectionError}
*/
min(): PromiseLike<EnsureType<TInput, number>>;
min(): PromiseLike<Extract<TInput, number>>;

/**
* The <i>max</i> method returns the max of all items in the collection. If the collection includes other than number items an error will be thrown.
Expand All @@ -299,7 +299,7 @@ export type IAsyncCollection<TInput> = AsyncIterable<TInput> & {
* @throws {TypeCollectionError} {@link TypeCollectionError}
* @throws {EmptyCollectionError} {@link EmptyCollectionError}
*/
max(): PromiseLike<EnsureType<TInput, number>>;
max(): PromiseLike<Extract<TInput, number>>;

/**
* The <i>percentage</i> method may be used to quickly determine the percentage of items in the collection that pass <i>predicateFn</i>.
Expand Down
15 changes: 8 additions & 7 deletions src/collection/contracts/collection.contract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import type {
Reduce,
CrossJoinResult,
} from "@/collection/contracts/_shared";
import type { Lazyable, RecordItem, EnsureType } from "@/_shared/types";
import type { Lazyable, RecordItem } from "@/_shared/types";

export type Collapse<TValue> = TValue extends
| Array<infer TItem>
Expand All @@ -36,6 +36,7 @@ export type Collapse<TValue> = TValue extends
: TValue;

/**
* The <i>ICollection</i> contract offers a fluent and efficient approach to working with {@link Iterable} objects.
* <i>ICollection</i> is immutable.
* @throws {CollectionError}
* @throws {UnexpectedCollectionError}
Expand Down Expand Up @@ -158,7 +159,7 @@ export type ICollection<TInput> = Iterable<TInput> & {
* collection.map(item => item.toString()).join("_");
* // "1_2_3_4"
*/
join(separator?: string): EnsureType<TInput, string>;
join(separator?: string): Extract<TInput, string>;

/**
* The <i>collapse</i> method collapses a collection of iterables into a single, flat collection.
Expand Down Expand Up @@ -227,7 +228,7 @@ export type ICollection<TInput> = Iterable<TInput> & {
* @throws {TypeCollectionError} {@link TypeCollectionError}
* @throws {EmptyCollectionError} {@link EmptyCollectionError}
*/
sum(): EnsureType<TInput, number>;
sum(): Extract<TInput, number>;

/**
* The <i>average</i> method returns the average of all items in the collection. If the collection includes other than number items an error will be thrown.
Expand All @@ -243,7 +244,7 @@ export type ICollection<TInput> = Iterable<TInput> & {
* @throws {TypeCollectionError} {@link TypeCollectionError}
* @throws {EmptyCollectionError} {@link EmptyCollectionError}
*/
average(): EnsureType<TInput, number>;
average(): Extract<TInput, number>;

/**
* The <i>median</i> method returns the median of all items in the collection. If the collection includes other than number items an error will be thrown.
Expand All @@ -259,7 +260,7 @@ export type ICollection<TInput> = Iterable<TInput> & {
* @throws {TypeCollectionError} {@link TypeCollectionError}
* @throws {EmptyCollectionError} {@link EmptyCollectionError}
*/
median(): EnsureType<TInput, number>;
median(): Extract<TInput, number>;

/**
* The <i>min</i> method returns the min of all items in the collection. If the collection includes other than number items an error will be thrown.
Expand All @@ -275,7 +276,7 @@ export type ICollection<TInput> = Iterable<TInput> & {
* @throws {TypeCollectionError} {@link TypeCollectionError}
* @throws {EmptyCollectionError} {@link EmptyCollectionError}
*/
min(): EnsureType<TInput, number>;
min(): Extract<TInput, number>;

/**
* The <i>max</i> method returns the max of all items in the collection. If the collection includes other than number items an error will be thrown.
Expand All @@ -291,7 +292,7 @@ export type ICollection<TInput> = Iterable<TInput> & {
* @throws {TypeCollectionError} {@link TypeCollectionError}
* @throws {EmptyCollectionError} {@link EmptyCollectionError}
*/
max(): EnsureType<TInput, number>;
max(): Extract<TInput, number>;

/**
* The <i>percentage</i> method may be used to quickly determine the percentage of items in the collection that pass <i>predicateFn</i>.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
/**
* @module Collection
*/

import { type IAsyncCollection } from "@/collection/contracts/_module";
import { type AsyncIterableValue } from "@/_shared/types";

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
/**
* @module Collection
*/

import {
type AsyncPredicate,
type IAsyncCollection,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
/**
* @module Collection
*/

import {
isAsyncIterable,
isIterable,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
/**
* @module Collection
*/

import {
type AsyncMap,
type IAsyncCollection,
} from "@/collection/contracts/_module";
import { type RecordItem } from "@/_shared/types";

/**
* @internal
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
/**
* @module Collection
*/

import type { CrossJoinResult } from "@/collection/contracts/_module";
import { type IAsyncCollection } from "@/collection/contracts/_module";
import { type AsyncIterableValue } from "@/_shared/types";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
/**
* @module Collection
*/

import { type AsyncIterableValue } from "@/_shared/types";
import { type RecordItem } from "@/_shared/types";

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
/**
* @module Collection
*/

export class AsyncErrorHandlerIterable<TInput>
implements AsyncIterable<TInput>
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
/**
* @module Collection
*/

import {
type AsyncPredicate,
type IAsyncCollection,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
/**
* @module Collection
*/

import {
type AsyncMap,
type IAsyncCollection,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
/**
* @module Collection
*/

import {
type AsyncMap,
type IAsyncCollection,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
/**
* @module Collection
*/

import {
type AsyncPredicate,
type IAsyncCollection,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
/**
* @module Collection
*/

import {
type AsyncPredicate,
type IAsyncCollection,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
/**
* @module Collection
*/

import {
type AsyncMap,
type IAsyncCollection,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import {} from "@/collection/contracts/_module";
/**
* @module Collection
*/

import { type AsyncIterableValue } from "@/_shared/types";

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
/**
* @module Collection
*/

import { type IAsyncCollection } from "@/collection/contracts/_module";
import { type AsyncIterableValue } from "@/_shared/types";

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
/**
* @module Collection
*/

import { type IAsyncCollection } from "@/collection/contracts/_module";
import { type AsyncIterableValue } from "@/_shared/types";

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
/**
* @module Collection
*/

import {
type AsyncPredicate,
type IAsyncCollection,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
/**
* @module Collection
*/

import { type IAsyncCollection } from "@/collection/contracts/_module";
import { type AsyncIterableValue } from "@/_shared/types";

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
/**
* @module Collection
*/

import { type IAsyncCollection } from "@/collection/contracts/_module";
import { type AsyncIterableValue } from "@/_shared/types";

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
/**
* @module Collection
*/

import { type IAsyncCollection } from "@/collection/contracts/_module";

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
/**
* @module Collection
*/

import { type IAsyncCollection } from "@/collection/contracts/_module";

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
/**
* @module Collection
*/

import {
type AsyncPredicate,
type IAsyncCollection,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
/**
* @module Collection
*/

import { type IAsyncCollection } from "@/collection/contracts/_module";

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
/**
* @module Collection
*/

import { type IAsyncCollection } from "@/collection/contracts/_module";

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
/**
* @module Collection
*/

import {
type Comparator,
type IAsyncCollection,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
/**
* @module Collection
*/

import { type IAsyncCollection } from "@/collection/contracts/_module";
import { type AsyncIterableValue } from "@/_shared/types";

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
/**
* @module Collection
*/

import { type IAsyncCollection } from "@/collection/contracts/_module";

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
/**
* @module Collection
*/

import {
type AsyncPredicate,
type IAsyncCollection,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
/**
* @module Collection
*/

import {
type AsyncTap,
type IAsyncCollection,
Expand Down
Loading

0 comments on commit ec94bfc

Please sign in to comment.