@luminix/support 0.0.1-beta.0 → 0.0.1-beta.1

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@luminix/support",
3
- "version": "0.0.1-beta.0",
3
+ "version": "0.0.1-beta.1",
4
4
  "module": "dist/support.js",
5
5
  "types": "types/index.d.ts",
6
6
  "type": "module",
@@ -0,0 +1,6 @@
1
+ export default class ServiceContainer<TServices extends Map<string, any> = Map<string, any>> {
2
+ private services;
3
+ bind<K extends keyof TServices>(abstract: K, concrete: () => TServices[K]): void;
4
+ singleton<K extends keyof TServices>(abstract: K, concrete: TServices[K]): void;
5
+ get(serviceName: string): any;
6
+ }
File without changes
package/types/Arr.d.ts ADDED
@@ -0,0 +1,18 @@
1
+ /**
2
+ *
3
+ * Calculates the Cartesian product of the given arrays.
4
+ *
5
+ */
6
+ export declare function cartesian<T>(...arrays: T[][]): T[][];
7
+ /**
8
+ *
9
+ * Gets an array of random elements from the given `array`.
10
+ *
11
+ */
12
+ export declare function sampleSize(array: any[], n: number): any[];
13
+ /**
14
+ *
15
+ * Returns a shuffled copy of `array`.
16
+ *
17
+ */
18
+ export declare function shuffle<T>(array: T[]): T[];
@@ -0,0 +1,184 @@
1
+ import { default as EventSource, Event } from './Contracts/EventSource';
2
+ import { Constructor, TypeOf } from './Js';
3
+ import { Operator } from './Query';
4
+ export type CollectionChanged<T> = {
5
+ items: T[];
6
+ };
7
+ export type CollectionEvents<T> = {
8
+ 'change': (e: Event<CollectionChanged<T>, Collection<T>>) => void;
9
+ };
10
+ export type CollectionIteratorCallback<T = unknown, R = void> = (value: T, index: number, collection: Collection<T>) => R;
11
+ export type CollectionPipeCallback<T = unknown, R = unknown> = (collection: Collection<T>) => R;
12
+ export type CollectionSortCallback<T = unknown> = (a: T, b: T) => number;
13
+ export declare function isCollection(instance: unknown): instance is Collection<any>;
14
+ export default class Collection<T> extends EventSource<CollectionEvents<T>> {
15
+ #private;
16
+ constructor(items?: Array<T>);
17
+ get items(): T[];
18
+ [Symbol.iterator](): IterableIterator<T>;
19
+ [Symbol.toStringTag]: string;
20
+ all(): T[];
21
+ average(): number;
22
+ average<K extends keyof T>(key: K): number;
23
+ avg(): number;
24
+ avg<K extends keyof T>(key: K): number;
25
+ chunk(size: number): Collection<Collection<T>>;
26
+ chunkWhile(callback: CollectionIteratorCallback<T, boolean>): Collection<Collection<T>>;
27
+ collapse(): Collection<unknown>;
28
+ collect(): Collection<T>;
29
+ combine(values: Collection<any> | any[]): Record<string, any>;
30
+ concat(collection: Collection<unknown> | unknown[]): Collection<unknown>;
31
+ contains(value: T): boolean;
32
+ contains(key: keyof T, value: T): boolean;
33
+ contains(callback: CollectionIteratorCallback<T, boolean>): boolean;
34
+ containsOneItem(): boolean;
35
+ containsStrict(value: T): boolean;
36
+ containsStrict(key: keyof T, value: T): boolean;
37
+ containsStrict(callback: CollectionIteratorCallback<T, boolean>): boolean;
38
+ count(): number;
39
+ countBy(callback?: CollectionIteratorCallback<T, string | number>): Record<string | number, number>;
40
+ crossJoin<V>(...collections: (Collection<V> | V[])[]): Collection<Array<V | T>>;
41
+ diff(collection: Collection<T> | T[]): Collection<T>;
42
+ doesntContain(value: T): boolean;
43
+ doesntContain(key: keyof T, value: T): boolean;
44
+ doesntContain(callback: CollectionIteratorCallback<T, boolean>): boolean;
45
+ dump(): void;
46
+ duplicates(): Collection<T>;
47
+ duplicates<K extends keyof T>(key: K): Collection<T[K]>;
48
+ duplicatesStrict(): Collection<T>;
49
+ duplicatesStrict<K extends keyof T>(key: K): Collection<T[K]>;
50
+ each(callback: CollectionIteratorCallback<T, void | false>): this;
51
+ eachSpread(callback: (...args: unknown[]) => void | false): this;
52
+ ensure(type: TypeOf | Constructor | (TypeOf | Constructor)[]): this;
53
+ every(callback: CollectionIteratorCallback<T, boolean>): boolean;
54
+ except(indexes: Array<number>): Collection<T>;
55
+ filter(callback?: CollectionIteratorCallback<T, boolean>): Collection<T>;
56
+ first(callback?: CollectionIteratorCallback<T, boolean>): T | null;
57
+ firstOrFail(callback?: CollectionIteratorCallback<T, boolean>): T;
58
+ firstWhere<K extends keyof T>(key: K): T | null;
59
+ firstWhere<K extends keyof T>(key: K, value: T[K]): T | null;
60
+ firstWhere<K extends keyof T>(key: K, operator: Operator, value: T[K]): T | null;
61
+ flatMap<R>(callback: CollectionIteratorCallback<T, R | R[]>): Collection<R>;
62
+ forget(key: number): this;
63
+ forPage(page: number, perPage: number): Collection<T>;
64
+ get(key: number): T | null;
65
+ get<R>(key: number, defaultValue: R): T | R;
66
+ get<R>(key: number, defaultValue: () => R): T | R;
67
+ groupBy(key: keyof T): Record<string, T[]>;
68
+ groupBy(callback: CollectionIteratorCallback<T, string | string[]>): Record<string, T[]>;
69
+ groupBy(keys: (keyof T | CollectionIteratorCallback<T, string | string[]>)[]): Record<string, unknown>;
70
+ has(index: number): boolean;
71
+ hasAny(indexes: number[]): boolean;
72
+ implode(glue: string): string;
73
+ implode(key: keyof T, glue: string): string;
74
+ implode(callback: CollectionIteratorCallback<T, string>, glue: string): string;
75
+ intersect(values: Collection<T> | T[]): Collection<T>;
76
+ isEmpty(): boolean;
77
+ isNotEmpty(): boolean;
78
+ join(glue: string): string;
79
+ join(glue: string, final: string): string;
80
+ keyBy(key: keyof T): Record<string, T>;
81
+ keyBy(callback: CollectionIteratorCallback<T, string>): Record<string, T>;
82
+ last(callback?: CollectionIteratorCallback<T, boolean> | undefined): T | null;
83
+ map<R>(callback: CollectionIteratorCallback<T, R>): Collection<R>;
84
+ mapInto<R extends Constructor<InstanceType<R>>>(constructor: R): Collection<InstanceType<R>>;
85
+ mapSpread<R>(callback: (...args: unknown[]) => R): Collection<R>;
86
+ mapToGroups<R>(callback: CollectionIteratorCallback<T, Record<string, R>>): Record<string, R[]>;
87
+ mapWithKeys<R>(callback: CollectionIteratorCallback<T, Record<string, R>>): Record<string, R>;
88
+ max(): T | null;
89
+ max<K extends keyof T>(key: K): T[K] | null;
90
+ median(): T | null;
91
+ median<K extends keyof T>(key: K): T[K] | null;
92
+ merge(values: Collection<T> | T[]): Collection<T>;
93
+ merge<R>(values: Collection<R> | R[]): Collection<T | R>;
94
+ min(): T | null;
95
+ min<K extends keyof T>(key: K): T[K] | null;
96
+ mode(): T[];
97
+ mode<K extends keyof T>(key: K): T[K][];
98
+ nth(n: number, offset?: number): Collection<T>;
99
+ only(indexes: Array<number>): Collection<T>;
100
+ pad<R>(size: number, value?: R | null): Collection<T | R | null>;
101
+ partition(callback: CollectionIteratorCallback<T, boolean>): [Collection<T>, Collection<T>];
102
+ percentage(callback: CollectionIteratorCallback<T, boolean>, precision?: number): number;
103
+ pipe<R>(callback: CollectionPipeCallback<T, R>): R;
104
+ pipeInto<R extends Constructor<InstanceType<R>>>(constructor: R): InstanceType<R>;
105
+ pipeThrough<R>(pipeline: CollectionPipeCallback<unknown, Collection<unknown> | R>[]): R;
106
+ pluck<K extends keyof T>(key: K): Collection<T[K]>;
107
+ pop(): T | null;
108
+ pop(amount: number): Collection<T>;
109
+ prepend(value: T): number;
110
+ pull(index: number): T | null;
111
+ push(...items: T[]): number;
112
+ put(index: number, value: T): this;
113
+ random(): T | null;
114
+ random(amount: number): Collection<T>;
115
+ reduce<R>(callback: (carry: R | null, item: T, index: number, collection: this) => R, initialValue?: R | null): R | null;
116
+ reject(callback: CollectionIteratorCallback<T, boolean>): Collection<T>;
117
+ replace(data: Record<number, T>): Collection<T>;
118
+ reverse(): Collection<T>;
119
+ search(value: T): number | false;
120
+ search(value: T, strict: boolean): number | false;
121
+ search(callback: CollectionIteratorCallback<T, boolean>): number | false;
122
+ select<K extends Array<keyof T>>(keys: K): Collection<Pick<T, K[number]>>;
123
+ shift(): T | null;
124
+ shift(count: number): Collection<T>;
125
+ shuffle(): Collection<T>;
126
+ skip(amount: number): Collection<T>;
127
+ skipUntil(callback: CollectionIteratorCallback<T, boolean>): Collection<T>;
128
+ skipUntil(value: T): Collection<T>;
129
+ skipWhile(callback: CollectionIteratorCallback<T, boolean>): Collection<T>;
130
+ skipWhile(value: T): Collection<T>;
131
+ slice(start?: number, size?: number): Collection<T>;
132
+ sliding(size: number, step?: number): Collection<Collection<T>>;
133
+ sole(): T | null;
134
+ sole<K extends keyof T>(key: K, value: T[K]): T | null;
135
+ sole(callback: CollectionIteratorCallback<T, boolean>): T | null;
136
+ some(value: T): boolean;
137
+ some(key: keyof T, value: T): boolean;
138
+ some(callback: CollectionIteratorCallback<T, boolean>): boolean;
139
+ sort(compareFn?: CollectionSortCallback<T>): Collection<T>;
140
+ sortBy<K extends keyof T>(key: K, order?: 'asc' | 'desc'): Collection<T>;
141
+ sortBy<K extends keyof T>(columns: [K, 'asc' | 'desc'][]): Collection<T>;
142
+ sortBy(callback: CollectionIteratorCallback<T, number>): Collection<T>;
143
+ sortBy(stack: ((a: T, b: T) => number)[]): Collection<T>;
144
+ sortDesc(): Collection<T>;
145
+ splice(start: number): Collection<T>;
146
+ splice(start: number, deleteCount: number): Collection<T>;
147
+ splice(start: number, deleteCount: number, ...items: T[]): Collection<T>;
148
+ split(groups: number): Collection<Collection<T>>;
149
+ splitIn(groups: number): Collection<Collection<T>>;
150
+ sum(): number;
151
+ sum<K extends keyof T>(key: K): number;
152
+ take(amount: number): Collection<T>;
153
+ takeUntil(value: T): Collection<T>;
154
+ takeUntil(callback: CollectionIteratorCallback<T, boolean>): Collection<T>;
155
+ takeWhile(value: T): Collection<T>;
156
+ takeWhile(callback: CollectionIteratorCallback<T, boolean>): Collection<T>;
157
+ tap(callback: CollectionPipeCallback<T, void>): this;
158
+ toArray(): T[];
159
+ toJson(): string;
160
+ transform<R>(callback: CollectionIteratorCallback<T, R>): Collection<T | R>;
161
+ unique(): Collection<T>;
162
+ unique<K extends keyof T>(key: K): Collection<T>;
163
+ uniqueStrict(): Collection<T>;
164
+ uniqueStrict<K extends keyof T>(key: K): Collection<T>;
165
+ unless(condition: boolean, callback: CollectionPipeCallback<T, void>, otherwise?: CollectionPipeCallback<T, void>): this;
166
+ unlessEmpty(callback: CollectionPipeCallback<T, void>, otherwise?: CollectionPipeCallback<T, void>): this;
167
+ unlessNotEmpty(callback: CollectionPipeCallback<T, void>, otherwise?: CollectionPipeCallback<T, void>): this;
168
+ value<K extends keyof T>(key: K): T[K] | null;
169
+ when(condition: boolean, callback: CollectionPipeCallback<T, void>, otherwise?: CollectionPipeCallback<T, void>): this;
170
+ whenEmpty(callback: CollectionPipeCallback<T, void>, otherwise?: CollectionPipeCallback<T, void>): this;
171
+ whenNotEmpty(callback: CollectionPipeCallback<T, void>, otherwise?: CollectionPipeCallback<T, void>): this;
172
+ where<K extends keyof T>(key: K, value: T[K]): Collection<T>;
173
+ where<K extends keyof T>(key: K, operator: Operator, value: T[K]): Collection<T>;
174
+ whereStrict<K extends keyof T>(key: K, value: T[K]): Collection<T>;
175
+ whereStrict<K extends keyof T>(key: K, operator: Operator, value: T[K]): Collection<T>;
176
+ whereBetween<K extends keyof T>(key: K, [min, max]: [T[K], T[K]]): Collection<T>;
177
+ whereIn<K extends keyof T>(key: K, values: T[K][]): Collection<T>;
178
+ whereInstanceOf<R extends Constructor<T>>(constructor: R): Collection<T>;
179
+ whereNotBetween<K extends keyof T>(key: K, [min, max]: [T[K], T[K]]): Collection<T>;
180
+ whereNotIn<K extends keyof T>(key: K, values: T[K][]): Collection<T>;
181
+ whereNotNull<K extends keyof T>(key: K): Collection<T>;
182
+ whereNull<K extends keyof T>(key: K): Collection<T>;
183
+ zip<R>(items: Collection<R> | R[]): Collection<[T, NonNullable<R> | null]>;
184
+ }
@@ -0,0 +1,15 @@
1
+ import { Unsubscribe } from 'nanoevents';
2
+ export type Event<TData = any, TSource extends EventSource = EventSource> = TData & {
3
+ source: TSource;
4
+ };
5
+ export type EventMap = {
6
+ [key: string]: (event: Event) => void;
7
+ };
8
+ export default class EventSource<TEvents extends EventMap = EventMap> {
9
+ private emitter;
10
+ constructor();
11
+ on<E extends keyof TEvents>(event: E, callback: TEvents[E]): Unsubscribe;
12
+ once<E extends keyof TEvents>(event: E, callback: TEvents[E]): void;
13
+ emit<E extends keyof TEvents>(event: E, ...data: Parameters<TEvents[E]>): void;
14
+ static foo(): string;
15
+ }
@@ -0,0 +1,4 @@
1
+ export default class ReducerOverrideException extends Error {
2
+ [Symbol.toStringTag]: string;
3
+ constructor(name: string, target: unknown);
4
+ }
@@ -0,0 +1,25 @@
1
+ import { AxiosRequestConfig } from 'axios';
2
+ import { default as Request } from './Request';
3
+ export type RequestOptions = Omit<AxiosRequestConfig, 'url' | 'method'>;
4
+ export default class Client {
5
+ protected options: AxiosRequestConfig;
6
+ constructor(options?: AxiosRequestConfig);
7
+ private parseData;
8
+ baseUrl(baseUrl: string): this;
9
+ asForm(): this;
10
+ accept(type: string): this;
11
+ acceptJson(): this;
12
+ withHeaders(headers: Record<string, string>): this;
13
+ replaceHeaders(headers: Record<string, string>): this;
14
+ withOptions(options: RequestOptions): this;
15
+ replaceOptions(options: RequestOptions): this;
16
+ withQueryParameters(params: string | object): this;
17
+ replaceQueryParameters(params: string | object): this;
18
+ withBasicAuth(username: string, password: string): this;
19
+ withToken(token: string): this;
20
+ get<TResponse = any>(url: string, query?: string | object): Request<TResponse, any>;
21
+ post<TResponse = any, TData = any>(url: string, data?: TData): Request<TResponse, TData>;
22
+ put<TResponse = any, TData = any>(url: string, data?: TData): Request<TResponse, TData>;
23
+ patch<TResponse = any, TData = any>(url: string, data?: TData): Request<TResponse, TData>;
24
+ delete<TResponse = any>(url: string, query?: string | object): Request<TResponse, any>;
25
+ }
@@ -0,0 +1,11 @@
1
+ import { AxiosRequestConfig } from 'axios';
2
+ import { default as Response } from './Response';
3
+ export default class Request<TResponse = any, TData = any> implements Promise<Response<TResponse, TData>> {
4
+ private promise;
5
+ private response?;
6
+ constructor(options: AxiosRequestConfig);
7
+ [Symbol.toStringTag]: string;
8
+ then<TResult1 = Response<TResponse, TData>, TResult2 = never>(onfulfilled?: ((value: Response<TResponse, TData>) => TResult1 | PromiseLike<TResult1>) | null | undefined, onrejected?: ((reason: any) => TResult2 | PromiseLike<TResult2>) | null | undefined): Promise<TResult1 | TResult2>;
9
+ catch<TResult = never>(onrejected?: ((reason: any) => TResult | PromiseLike<TResult>) | null | undefined): Promise<Response<TResponse, TData> | TResult>;
10
+ finally(onfinally?: (() => void) | null | undefined): Promise<Response<TResponse, TData>>;
11
+ }
@@ -0,0 +1,40 @@
1
+ import { AxiosResponse } from 'axios';
2
+ export default class Response<TResponse = any, TData = any> {
3
+ private response;
4
+ private error?;
5
+ constructor(response: AxiosResponse<TResponse, TData>, error?: Error | undefined);
6
+ body(): string;
7
+ json(): TResponse;
8
+ json<K extends keyof TResponse>(key: K): TResponse[K];
9
+ json(key: string, defaultValue?: any): any;
10
+ status(): number;
11
+ successful(): boolean;
12
+ redirect(): boolean;
13
+ clientError(): boolean;
14
+ serverError(): boolean;
15
+ failed(): boolean;
16
+ header(header: string): string;
17
+ headers(): Record<string, string>;
18
+ ok(): boolean;
19
+ created(): boolean;
20
+ accepted(): boolean;
21
+ noContent(): boolean;
22
+ movedPermanently(): boolean;
23
+ found(): boolean;
24
+ badRequest(): boolean;
25
+ unauthorized(): boolean;
26
+ paymentRequired(): boolean;
27
+ forbidden(): boolean;
28
+ notFound(): boolean;
29
+ requestTimeout(): boolean;
30
+ conflict(): boolean;
31
+ unprocessableEntity(): boolean;
32
+ tooManyRequests(): boolean;
33
+ throw(): this;
34
+ throwIf(condition: boolean | ((response: Response) => boolean)): this;
35
+ throwUnless(condition: boolean | ((response: Response) => boolean)): this;
36
+ throwIfStatus(statusCode: number | ((status: number, response: Response) => boolean)): this;
37
+ throwUnlessStatus(statusCode: number | ((status: number, response: Response) => boolean)): this;
38
+ throwIfClientError(): this;
39
+ throwIfServerError(): this;
40
+ }
@@ -0,0 +1,25 @@
1
+ import { default as Client, RequestOptions } from './Client';
2
+ import { default as Response } from './Response';
3
+ import { default as Request } from './Request';
4
+ declare class HttpStatic {
5
+ get Client(): typeof Client;
6
+ get Response(): typeof Response;
7
+ get Request(): typeof Request;
8
+ getClient(): Client;
9
+ baseUrl(baseUrl: string): Client;
10
+ asForm(): Client;
11
+ accept(type: string): Client;
12
+ acceptJson(): Client;
13
+ withHeaders(headers: Record<string, string>): Client;
14
+ withOptions(options: RequestOptions): Client;
15
+ withQueryParameters(params: string | object): Client;
16
+ withBasicAuth(username: string, password: string): Client;
17
+ withToken(token: string): Client;
18
+ get<TResponse = any>(url: string, query?: string | object): Request<TResponse, any>;
19
+ post<TResponse = any, TData = any>(url: string, data?: TData): Request<TResponse, TData>;
20
+ put<TResponse = any, TData = any>(url: string, data?: TData): Request<TResponse, TData>;
21
+ patch<TResponse = any, TData = any>(url: string, data?: TData): Request<TResponse, TData>;
22
+ delete<TResponse = any>(url: string, query?: string | object): Request<TResponse, any>;
23
+ }
24
+ declare const Http: HttpStatic & import('../Mixins/Macroable').MacroMethodMap & import('../Mixins/Macroable').MacroableInterface<import('../Mixins/Macroable').MacroMethodMap>;
25
+ export default Http;
@@ -0,0 +1,30 @@
1
+ import { AxiosResponse } from 'axios';
2
+ declare class Response<T = any, D = any> {
3
+ _response: AxiosResponse<T, D>;
4
+ constructor(_response: AxiosResponse<T, D>);
5
+ body(): string;
6
+ json(): D;
7
+ status(): number;
8
+ successful(): boolean;
9
+ failed(): boolean;
10
+ header(header: string): string;
11
+ headers(): Record<string, string>;
12
+ ok(): boolean;
13
+ created(): boolean;
14
+ accepted(): boolean;
15
+ noContent(): boolean;
16
+ movedPermanently(): boolean;
17
+ found(): boolean;
18
+ badRequest(): boolean;
19
+ unauthorized(): boolean;
20
+ paymentRequired(): boolean;
21
+ forbidden(): boolean;
22
+ notFound(): boolean;
23
+ requestTimeout(): boolean;
24
+ conflict(): boolean;
25
+ unprocessableEntity(): boolean;
26
+ tooManyRequests(): boolean;
27
+ serverError(): boolean;
28
+ }
29
+ export declare function get(url: string, query?: string | object): Promise<Response>;
30
+ export {};
@@ -1,5 +1,2 @@
1
-
2
-
3
1
  export type Constructor<T = {}> = new (...args: any[]) => T;
4
-
5
2
  export type TypeOf = 'string' | 'number' | 'boolean' | 'object' | 'undefined' | 'function' | 'symbol' | 'bigint';
@@ -0,0 +1,29 @@
1
+ import { Constructor } from '../Js';
2
+ export type MacroMethodMap = Record<string, (...args: any[]) => any>;
3
+ export type MacroableInterface<TMacros extends MacroMethodMap> = {
4
+ /**
5
+ *
6
+ * Register a custom macro
7
+ *
8
+ * @param name
9
+ * @param macro
10
+ */
11
+ macro<K extends keyof TMacros>(name: K, macro: TMacros[K]): void;
12
+ /**
13
+ *
14
+ * Checks if a macro is registered
15
+ *
16
+ * @param name
17
+ */
18
+ hasMacro(name: string): boolean;
19
+ /**
20
+ *
21
+ * Flushes the existing macros.
22
+ *
23
+ */
24
+ flushMacros(): void;
25
+ };
26
+ export type MacroableOf<TBase extends Constructor, TMacros extends MacroMethodMap> = Omit<TBase, 'new'> & {
27
+ new (...args: ConstructorParameters<TBase>): InstanceType<TBase> & TMacros & MacroableInterface<TMacros>;
28
+ };
29
+ export default function Macroable<TMacros extends MacroMethodMap, TBase extends Constructor>(Base: TBase): MacroableOf<TBase, TMacros>;
@@ -0,0 +1,29 @@
1
+ import { Constructor } from '../Js';
2
+ import { default as Collection } from '../Collection';
3
+ export type ReducerRepository = {
4
+ [reducer: string]: Collection<Reducer<any, any[]>>;
5
+ };
6
+ export type ReducerCallback<TValue = any, TParams extends any[] = any[]> = (value: TValue, ...params: TParams) => TValue;
7
+ export interface Reducer<TValue = any, TParams extends any[] = any[]> {
8
+ callback: ReducerCallback<TValue, TParams>;
9
+ priority: number;
10
+ }
11
+ export type Unsubscribe = () => void;
12
+ export type ReducerMethodMap = Record<string, (value: any, ...params: any[]) => any>;
13
+ type First<T extends any[]> = T extends [infer A, ...any] ? A : unknown;
14
+ type Tail<T extends any[]> = T extends [any, ...infer R] ? R : unknown[];
15
+ export type ReducerCallbackFor<TReducers extends ReducerMethodMap, K extends keyof TReducers> = ReducerCallback<First<Parameters<TReducers[K]>>, Tail<Parameters<TReducers[K]>>>;
16
+ export type ReducerFor<TReducers extends ReducerMethodMap, K extends keyof TReducers> = Reducer<First<Parameters<TReducers[K]>>, Tail<Parameters<TReducers[K]>>>;
17
+ export type ReducibleInterface<TReducers extends ReducerMethodMap> = {
18
+ reducer<K extends keyof TReducers>(name: K, callback: ReducerCallbackFor<TReducers, K>, priority?: number): Unsubscribe;
19
+ removeReducer<K extends keyof TReducers>(name: K, callback: ReducerCallbackFor<TReducers, K>): void;
20
+ getReducer<K extends keyof TReducers>(name: K): Collection<ReducerFor<TReducers, K>>;
21
+ hasReducer(name: string): boolean;
22
+ clearReducer(name: string): void;
23
+ flushReducers(): void;
24
+ };
25
+ export type ReducibleOf<TBase extends Constructor, TReducers extends ReducerMethodMap> = Omit<TBase, 'new'> & {
26
+ new (...args: ConstructorParameters<TBase>): InstanceType<TBase> & TReducers & ReducibleInterface<TReducers>;
27
+ };
28
+ export default function Reducible<TReducers extends ReducerMethodMap, TBase extends Constructor>(Base: TBase): ReducibleOf<TBase, TReducers>;
29
+ export {};
package/types/Obj.d.ts ADDED
@@ -0,0 +1,14 @@
1
+ export type JsonProperty = null | boolean | number | string;
2
+ export declare function fromQuery(searchParams: URLSearchParams): Record<string, any>;
3
+ export declare function fromFormData(formData: FormData): Record<string, any>;
4
+ export declare function get(object: any, path: string, defaultValue?: any): any;
5
+ export declare function has(object: any, path: string): boolean;
6
+ export declare function isEmpty(object: any): boolean;
7
+ export declare function isEqual(object: any, other: any): boolean;
8
+ export declare function merge(object: any, ...sources: any[]): any;
9
+ export declare function omit(object: any, ...paths: string[]): any;
10
+ export declare function pick(object: any, ...paths: string[]): any;
11
+ export declare function set(object: any, path: string, value: any): void;
12
+ export declare function toQuery(object: any): URLSearchParams;
13
+ export declare function toFormData(object: any): FormData;
14
+ export declare function unset(object: any, path: string): void;
@@ -0,0 +1,4 @@
1
+ export type Operator = '=' | '!=' | '>' | '>=' | '<' | '<=';
2
+ export declare function fromObject(object: object): URLSearchParams;
3
+ export declare function toObject(searchParams: URLSearchParams): object;
4
+ export declare function merge(...parts: (string | URLSearchParams)[]): URLSearchParams;
@@ -1,7 +1,2 @@
1
-
2
-
3
1
  export default class ApplicationService {
4
-
5
2
  }
6
-
7
-
package/types/Str.d.ts ADDED
@@ -0,0 +1,10 @@
1
+ export declare function after(string: string, search: string): string;
2
+ export declare function afterLast(string: string, search: string): string;
3
+ export declare function before(string: string, search: string): string;
4
+ export declare function beforeLast(string: string, search: string): string;
5
+ export declare function camel(string: string): string;
6
+ export declare function kebab(string: string): string;
7
+ export declare function studly(string: string): string;
8
+ export declare function snake(string: string): string;
9
+ export declare function trim(string: string, chars?: string): string;
10
+ export declare function upperFirst(string: string): string;
@@ -0,0 +1,10 @@
1
+ import { default as Collection } from './Collection';
2
+ import { default as EventSource } from './Contracts/EventSource';
3
+ import { default as Http } from './Http';
4
+ import { default as Reducible } from './Mixins/Reducible';
5
+ import { default as Macroable } from './Mixins/Macroable';
6
+ import * as Arr from './Arr';
7
+ import * as Obj from './Obj';
8
+ import * as Query from './Query';
9
+ import * as Str from './Str';
10
+ export { Arr, Collection, EventSource, Http, Reducible, Macroable, Obj, Query, Str, };
@@ -1,32 +0,0 @@
1
-
2
-
3
-
4
-
5
-
6
- export default class ServiceContainer<TServices extends Map<string, any> = Map<string, any>> {
7
-
8
- private services: TServices = new Map() as TServices;
9
-
10
- bind<K extends keyof TServices>(abstract: K, concrete: () => TServices[K]): void {
11
- if (typeof abstract !== 'string') {
12
- throw new TypeError('Service name must be a string.');
13
- }
14
- this.services.set(abstract, concrete);
15
- }
16
-
17
- singleton<K extends keyof TServices>(abstract: K, concrete: TServices[K]): void {
18
- if (typeof abstract !== 'string') {
19
- throw new TypeError('Service name must be a string.');
20
- }
21
- this.services.set(abstract, concrete);
22
- }
23
-
24
- get(serviceName: string): any {
25
- const service = this.services.get(serviceName);
26
- if (!service) {
27
- throw new Error(`Service '${serviceName}' is not bound in the container.`);
28
- }
29
- return service;
30
- }
31
- }
32
-
package/src/App/index.ts DELETED
@@ -1,27 +0,0 @@
1
-
2
- // export type AppServices = {
3
-
4
- // };
5
-
6
- // class App {
7
-
8
-
9
- // private constructor() {
10
- // }
11
-
12
- // private static _instance?: App;
13
-
14
- // static getInstance() {
15
- // if (!this._instance) {
16
- // this._instance = new App();
17
- // }
18
-
19
- // return this._instance;
20
- // }
21
-
22
-
23
- // }
24
-
25
-
26
-
27
-
package/src/Arr.ts DELETED
@@ -1,33 +0,0 @@
1
- import * as _ from 'lodash-es';
2
-
3
- /**
4
- *
5
- * Calculates the Cartesian product of the given arrays.
6
- *
7
- */
8
- export function cartesian<T>(...arrays: T[][]): T[][] {
9
- return arrays.reduce((a, b) => a.flatMap((d) => b.map((e) => [d, e].flat())) as T[]) as T[][];
10
- }
11
-
12
-
13
- /**
14
- *
15
- * Gets an array of random elements from the given `array`.
16
- *
17
- */
18
- export function sampleSize(array: any[], n: number): any[] {
19
- return _.sampleSize(array, n);
20
- }
21
-
22
-
23
- /**
24
- *
25
- * Returns a shuffled copy of `array`.
26
- *
27
- */
28
- export function shuffle<T>(array: T[]): T[] {
29
- return _.shuffle(array);
30
- }
31
-
32
-
33
-