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

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.
Files changed (45) hide show
  1. package/dist/support.js +8448 -0
  2. package/package.json +6 -5
  3. package/types/App/Application.d.ts +23 -0
  4. package/types/App/Interfaces.d.ts +35 -0
  5. package/types/App/ServiceProvider.d.ts +8 -0
  6. package/types/Arr.d.ts +25 -0
  7. package/types/Collection.d.ts +184 -0
  8. package/types/Contracts/EventSource.d.ts +18 -0
  9. package/types/DateTime.d.ts +2 -0
  10. package/types/Exceptions/NoEmbedException.d.ts +4 -0
  11. package/types/Exceptions/ReducerOverrideException.d.ts +4 -0
  12. package/types/Func.d.ts +3 -0
  13. package/types/Http/Client.d.ts +27 -0
  14. package/types/Http/Request.d.ts +11 -0
  15. package/types/Http/Response.d.ts +42 -0
  16. package/types/Http/Utils/isValidationError.d.ts +8 -0
  17. package/types/Js.d.ts +6 -0
  18. package/types/Mixins/Macroable.d.ts +29 -0
  19. package/types/Mixins/MakeFacade.d.ts +7 -0
  20. package/types/Mixins/Reducible.d.ts +29 -0
  21. package/types/Obj.d.ts +20 -0
  22. package/types/PropertyBag.d.ts +24 -0
  23. package/types/Query.d.ts +4 -0
  24. package/types/Str.d.ts +18 -0
  25. package/types/index.d.ts +33 -0
  26. package/types/reader.d.ts +2 -0
  27. package/vite.config.js +0 -5
  28. package/src/App/ServiceContainer.ts +0 -32
  29. package/src/App/index.ts +0 -27
  30. package/src/Arr.ts +0 -33
  31. package/src/Collection.ts +0 -1398
  32. package/src/Contracts/EventSource.ts +0 -46
  33. package/src/Exceptions/ReducerOverrideException.ts +0 -8
  34. package/src/Http/Client.ts +0 -139
  35. package/src/Http/Request.ts +0 -45
  36. package/src/Http/Response.ts +0 -170
  37. package/src/Http/index.ts +0 -90
  38. package/src/Js.ts +0 -5
  39. package/src/Mixins/Macroable.ts +0 -81
  40. package/src/Mixins/Reducible.ts +0 -126
  41. package/src/Obj.ts +0 -70
  42. package/src/Query.ts +0 -29
  43. package/src/Services/ApplicationService.ts +0 -7
  44. package/src/Str.ts +0 -53
  45. package/src/index.ts +0 -26
package/package.json CHANGED
@@ -1,10 +1,11 @@
1
1
  {
2
2
  "name": "@luminix/support",
3
- "version": "0.0.1-beta.0",
3
+ "version": "0.0.1-beta.19",
4
4
  "module": "dist/support.js",
5
5
  "types": "types/index.d.ts",
6
6
  "type": "module",
7
7
  "scripts": {
8
+ "prebuild": "rm -rf types",
8
9
  "build": "tsc && vite build",
9
10
  "lint": "eslint . --report-unused-disable-directives --max-warnings 0",
10
11
  "lint:fix": "eslint . --report-unused-disable-directives --max-warnings 0 --fix",
@@ -17,17 +18,17 @@
17
18
  "@types/lodash-es": "^4.17.12",
18
19
  "@typescript-eslint/eslint-plugin": "^8.4.0",
19
20
  "@typescript-eslint/parser": "^8.4.0",
20
- "axios": "^1.7.7",
21
21
  "eslint": "^9.9.1",
22
22
  "jest": "^29.7.0",
23
23
  "lodash-es": "^4.17.21",
24
- "nanoevents": "^9.0.0",
25
24
  "ts-jest": "^29.2.5",
26
25
  "typescript": "^5.5.4",
27
26
  "vite": "^5.4.3",
28
27
  "vite-plugin-dts": "^4.1.0"
29
28
  },
30
- "peerDependencies": {
31
- "immer": "^10.1.1"
29
+ "dependencies": {
30
+ "axios": "^1.7.7",
31
+ "immer": "^10.1.1",
32
+ "nanoevents": "^9.0.0"
32
33
  }
33
34
  }
@@ -0,0 +1,23 @@
1
+ import { default as EventSource } from '../Contracts/EventSource';
2
+ import { ApplicationEvents, ServiceLoader } from './Interfaces';
3
+ import { default as ServiceProvider } from './ServiceProvider';
4
+ export default class Application<TContainers extends Record<string, any> = Record<string, any>> extends EventSource<ApplicationEvents> {
5
+ protected providers: (typeof ServiceProvider)[];
6
+ protected _configuration: Record<string, any>;
7
+ protected singletons: Record<string, any>;
8
+ protected loaders: Record<string, ServiceLoader>;
9
+ constructor(providers?: (typeof ServiceProvider)[]);
10
+ get services(): Record<string, ServiceLoader>;
11
+ get configuration(): Record<string, any>;
12
+ loadConfiguration(): void;
13
+ bind<K extends keyof TContainers>(abstract: K, concrete: () => TContainers[K]): void;
14
+ singleton<K extends keyof TContainers>(abstract: K, concrete: () => TContainers[K]): void;
15
+ make<K extends keyof TContainers & string>(abstract: K): TContainers[K];
16
+ withConfiguration(configuration: Record<string, any>): this;
17
+ withProviders(providers: (typeof ServiceProvider)[]): this;
18
+ create(): void;
19
+ flush(): void;
20
+ dump(): void;
21
+ dump($return: true): Object;
22
+ dump($return: false | string): void;
23
+ }
@@ -0,0 +1,35 @@
1
+ import { default as EventSource } from '../Contracts/EventSource';
2
+ export type ApplicationEvents = {
3
+ init: (providers: ServiceProviderInterface[]) => void;
4
+ booting: () => void;
5
+ booted: () => void;
6
+ flushed: () => void;
7
+ flushing: () => void;
8
+ ready: () => void;
9
+ };
10
+ export declare class ApplicationInterface<TContainers extends Record<string, any> = Record<string, any>> extends EventSource<ApplicationEvents> {
11
+ get services(): Record<string, ServiceLoader>;
12
+ get configuration(): Record<string, any>;
13
+ loadConfiguration(): void;
14
+ bind<K extends keyof TContainers>(abstract: K, concrete: () => TContainers[K]): void;
15
+ singleton<K extends keyof TContainers>(abstract: K, concrete: () => TContainers[K]): void;
16
+ make<K extends keyof TContainers & string>(abstract: K): TContainers[K];
17
+ withConfiguration(configuration: Record<string, any>): this;
18
+ withProviders(providers: (typeof ServiceProviderInterface)[]): this;
19
+ create(): void;
20
+ flush(): void;
21
+ dump(): void;
22
+ dump($return: true): Object;
23
+ dump($return: false | string): void;
24
+ }
25
+ export interface ServiceLoader {
26
+ loader: () => any;
27
+ singleton?: boolean;
28
+ }
29
+ declare class ServiceProviderInterface {
30
+ constructor(app: ApplicationInterface);
31
+ boot?(): void;
32
+ register?(): void;
33
+ flush?(): void;
34
+ }
35
+ export {};
@@ -0,0 +1,8 @@
1
+ import { ApplicationInterface } from './Interfaces';
2
+ export default class ServiceProvider {
3
+ protected app: ApplicationInterface;
4
+ constructor(app: ApplicationInterface);
5
+ boot?(): void;
6
+ register?(): void;
7
+ flush?(): void;
8
+ }
package/types/Arr.d.ts ADDED
@@ -0,0 +1,25 @@
1
+ export declare class ArrMacros {
2
+ [x: string]: (...args: any[]) => any;
3
+ }
4
+ declare class ArrStatic {
5
+ /**
6
+ *
7
+ * Calculates the Cartesian product of the given arrays.
8
+ *
9
+ */
10
+ cartesian<T>(...arrays: T[][]): T[][];
11
+ /**
12
+ *
13
+ * Gets an array of random elements from the given `array`.
14
+ *
15
+ */
16
+ sampleSize(array: any[], n: number): any[];
17
+ /**
18
+ *
19
+ * Returns a shuffled copy of `array`.
20
+ *
21
+ */
22
+ shuffle<T>(array: T[]): T[];
23
+ }
24
+ declare const Arr: ArrStatic & ArrMacros & import('./Mixins/Macroable').MacroableInterface<ArrMacros>;
25
+ export default Arr;
@@ -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,18 @@
1
+ import { Unsubscribe } from 'nanoevents';
2
+ export type Event<TData = any, TSource extends EventSource = any> = TData & {
3
+ source: TSource;
4
+ };
5
+ export type EventMap = {
6
+ [key: string]: (event: Event) => void;
7
+ };
8
+ export type EventMapOf<TSource extends EventSource> = TSource extends EventSource<infer T> ? T : never;
9
+ export type EventsOf<TSource extends EventSource> = keyof EventMapOf<TSource>;
10
+ export type EventCallbackOf<TSource extends EventSource, E extends EventsOf<TSource>> = EventMapOf<TSource>[E];
11
+ export default class EventSource<TEvents extends EventMap = EventMap> {
12
+ private emitter;
13
+ constructor();
14
+ on<E extends keyof TEvents>(event: E, callback: TEvents[E]): Unsubscribe;
15
+ once<E extends keyof TEvents>(event: E, callback: TEvents[E]): void;
16
+ emit<E extends keyof TEvents>(event: E, ...data: Parameters<TEvents[E]>): void;
17
+ flushEvents(): void;
18
+ }
@@ -0,0 +1,2 @@
1
+ export declare function parse(value: Date | string): Date;
2
+ export declare function toDateTimeLocal(value: Date | string): string;
@@ -0,0 +1,4 @@
1
+ export default class NoEmbedException extends Error {
2
+ [Symbol.toStringTag]: string;
3
+ constructor();
4
+ }
@@ -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,3 @@
1
+ import { DebouncedFunc, DebounceSettings, ThrottleSettings } from 'lodash-es';
2
+ export declare function throttle<T extends (...args: any) => any>(func: T, wait?: number, options?: ThrottleSettings): DebouncedFunc<T>;
3
+ export declare function debounce<T extends (...args: any) => any>(func: T, wait?: number, options?: DebounceSettings): DebouncedFunc<T>;
@@ -0,0 +1,27 @@
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
+ withData(data: object): this;
19
+ replaceData(data: object): this;
20
+ withBasicAuth(username: string, password: string): this;
21
+ withToken(token: string): this;
22
+ get<TResponse = any>(url: string, query?: string | object): Request<TResponse, any>;
23
+ post<TResponse = any, TData = any>(url: string, data?: TData): Request<TResponse, TData>;
24
+ put<TResponse = any, TData = any>(url: string, data?: TData): Request<TResponse, TData>;
25
+ patch<TResponse = any, TData = any>(url: string, data?: TData): Request<TResponse, TData>;
26
+ delete<TResponse = any>(url: string, query?: string | object): Request<TResponse, any>;
27
+ }
@@ -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,42 @@
1
+ import { AxiosResponse } from 'axios';
2
+ export default class Response<TResponse = any, TData = any> {
3
+ protected _response: AxiosResponse<TResponse, TData>;
4
+ protected _error?: Error | undefined;
5
+ constructor(_response: AxiosResponse<TResponse, TData>, _error?: Error | undefined);
6
+ error(): Error | undefined;
7
+ body(): string;
8
+ json(): TResponse;
9
+ json<K extends keyof TResponse>(key: K): TResponse[K];
10
+ json(key: string, defaultValue?: any): any;
11
+ has(key: string): boolean;
12
+ status(): number;
13
+ successful(): boolean;
14
+ redirect(): boolean;
15
+ clientError(): boolean;
16
+ serverError(): boolean;
17
+ failed(): boolean;
18
+ header(header: string): string;
19
+ headers(): Record<string, string>;
20
+ ok(): boolean;
21
+ created(): boolean;
22
+ accepted(): boolean;
23
+ noContent(): boolean;
24
+ movedPermanently(): boolean;
25
+ found(): boolean;
26
+ badRequest(): boolean;
27
+ unauthorized(): boolean;
28
+ paymentRequired(): boolean;
29
+ forbidden(): boolean;
30
+ notFound(): boolean;
31
+ requestTimeout(): boolean;
32
+ conflict(): boolean;
33
+ unprocessableEntity(): boolean;
34
+ tooManyRequests(): boolean;
35
+ throw(): this;
36
+ throwIf(condition: boolean | ((response: Response) => boolean)): this;
37
+ throwUnless(condition: boolean | ((response: Response) => boolean)): this;
38
+ throwIfStatus(statusCode: number | ((status: number, response: Response) => boolean)): this;
39
+ throwUnlessStatus(statusCode: number | ((status: number, response: Response) => boolean)): this;
40
+ throwIfClientError(): this;
41
+ throwIfServerError(): this;
42
+ }
@@ -0,0 +1,8 @@
1
+ import { default as Response } from '../Response';
2
+ export type ValidationError = {
3
+ message: string;
4
+ errors: {
5
+ [key: string]: string[];
6
+ };
7
+ };
8
+ export default function isValidationError(response: unknown): response is Response<ValidationError>;
package/types/Js.d.ts ADDED
@@ -0,0 +1,6 @@
1
+ export type Constructor<TInstance = {}, TArgs extends Array<any> = any[]> = new (...args: TArgs) => TInstance;
2
+ export type TypeOf = 'string' | 'number' | 'boolean' | 'object' | 'undefined' | 'function' | 'symbol' | 'bigint';
3
+ export type JsonObject = {
4
+ [key: string]: JsonValue;
5
+ };
6
+ export type JsonValue = string | number | boolean | null | JsonObject | Array<string | number | boolean | null | JsonObject>;
@@ -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,7 @@
1
+ import { default as Application } from '../App/Application';
2
+ import { Constructor } from '../Js';
3
+ export type HasFacadeAccessor = {
4
+ getFacadeAccessor(): string | object;
5
+ };
6
+ export type FacadeOf<TService extends object, TBase extends HasFacadeAccessor> = TBase & TService;
7
+ export default function MakeFacade<TService extends object, TBase extends HasFacadeAccessor>(Base: Constructor<HasFacadeAccessor, []>, app?: Application): FacadeOf<TService, TBase>;
@@ -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,20 @@
1
+ export declare class ObjMacros {
2
+ [x: string]: (...args: any[]) => any;
3
+ }
4
+ export declare class ObjStatic {
5
+ fromQuery(searchParams: URLSearchParams): Record<string, any>;
6
+ fromFormData(formData: FormData): Record<string, any>;
7
+ get(object: any, path: string, defaultValue?: any): any;
8
+ has(object: any, path: string): boolean;
9
+ isEmpty(object: any): boolean;
10
+ isEqual(object: any, other: any): boolean;
11
+ merge(object: any, ...sources: any[]): any;
12
+ omit(object: any, ...paths: string[]): any;
13
+ pick(object: any, ...paths: string[]): any;
14
+ set(object: any, path: string, value: any): void;
15
+ toQuery(object: any): URLSearchParams;
16
+ toFormData(object: any): FormData;
17
+ unset(object: any, path: string): void;
18
+ }
19
+ declare const Obj: ObjStatic & ObjMacros & import('./Mixins/Macroable').MacroableInterface<ObjMacros>;
20
+ export default Obj;
@@ -0,0 +1,24 @@
1
+ import { default as EventSource, Event } from './Contracts/EventSource';
2
+ export type PropertyBagChangeEvent = {
3
+ path: string;
4
+ value: unknown;
5
+ type: 'set' | 'merge' | 'delete';
6
+ };
7
+ export type PropertyBagEventMap<T extends object = any> = {
8
+ 'change': (e: Event<PropertyBagChangeEvent, PropertyBag<T>>) => void;
9
+ };
10
+ declare class PropertyBag<T extends object> extends EventSource<PropertyBagEventMap<T>> {
11
+ private bag;
12
+ private locked;
13
+ constructor(bag: T);
14
+ get(path: string, defaultValue?: unknown): any;
15
+ set(path: string, value: unknown): void;
16
+ merge(path: string, value: unknown): void;
17
+ has(path: string): boolean;
18
+ delete(path: string): void;
19
+ lock(path: string): void;
20
+ clone(): PropertyBag<T>;
21
+ all(): T;
22
+ isEmpty(): boolean;
23
+ }
24
+ export default PropertyBag;
@@ -0,0 +1,4 @@
1
+ export type Operator = '=' | '!=' | '>' | '>=' | '<' | '<=';
2
+ export declare function fromObject(object: object): URLSearchParams;
3
+ export declare function toObject(searchParams: URLSearchParams): Record<string, any>;
4
+ export declare function merge(...parts: (string | URLSearchParams)[]): URLSearchParams;
package/types/Str.d.ts ADDED
@@ -0,0 +1,18 @@
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 lcfirst(string: string): string;
7
+ export declare function lower(string: string): string;
8
+ export declare function kebab(string: string): string;
9
+ export declare function padBoth(string: string, length: number, chars?: string): string;
10
+ export declare function padLeft(string: string, length: number, chars?: string): string;
11
+ export declare function padRight(string: string, length: number, chars?: string): string;
12
+ export declare function readable(string: string): string;
13
+ export declare function studly(string: string): string;
14
+ export declare function snake(string: string): string;
15
+ export declare function title(string: string): string;
16
+ export declare function trim(string: string, chars?: string): string;
17
+ export declare function ucfirst(string: string): string;
18
+ export declare function upper(string: string): string;
@@ -0,0 +1,33 @@
1
+ import { default as axios } from 'axios';
2
+ import { default as Application } from './App/Application';
3
+ import { default as Client } from './Http/Client';
4
+ import { default as Collection } from './Collection';
5
+ import { default as EventSource } from './Contracts/EventSource';
6
+ import { default as Macroable } from './Mixins/Macroable';
7
+ import { default as MakeFacade } from './Mixins/MakeFacade';
8
+ import { default as PropertyBag } from './PropertyBag';
9
+ import { default as reader } from './reader';
10
+ import { default as Reducible } from './Mixins/Reducible';
11
+ import { default as Request } from './Http/Request';
12
+ import { default as Response } from './Http/Response';
13
+ import { default as ServiceProvider } from './App/ServiceProvider';
14
+ import { default as isValidationError } from './Http/Utils/isValidationError';
15
+ import { default as Arr } from './Arr';
16
+ import { default as Obj } from './Obj';
17
+ import * as immer from 'immer';
18
+ import * as DateTime from './DateTime';
19
+ import * as Func from './Func';
20
+ import * as Query from './Query';
21
+ import * as Str from './Str';
22
+ export { Application, Arr, Client, Collection, DateTime, EventSource, Func, isValidationError, Macroable, MakeFacade, Obj, PropertyBag, reader, Reducible, Request, Response, ServiceProvider, Query, Str, axios, immer, };
23
+ export type { ArrMacros } from './Arr';
24
+ export type { ObjMacros } from './Obj';
25
+ export type { ApplicationInterface, ApplicationEvents } from './App/Interfaces';
26
+ export type { Event, EventMap, EventMapOf, EventsOf, EventCallbackOf } from './Contracts/EventSource';
27
+ export type { RequestOptions } from './Http/Client';
28
+ export type { MacroableOf, MacroableInterface } from './Mixins/Macroable';
29
+ export type { HasFacadeAccessor, FacadeOf } from './Mixins/MakeFacade';
30
+ export type { ReducibleInterface, ReducibleOf, ReducerCallback } from './Mixins/Reducible';
31
+ export type { CollectionIteratorCallback } from './Collection';
32
+ export type { Constructor, TypeOf, JsonObject, JsonValue } from './Js';
33
+ export type { PropertyBagEventMap } from './PropertyBag';
@@ -0,0 +1,2 @@
1
+ declare const reader: (name: string, type?: "data" | "error") => any;
2
+ export default reader;