@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
@@ -1,126 +0,0 @@
1
- /* eslint-disable @typescript-eslint/ban-types */
2
- /* eslint-disable @typescript-eslint/no-explicit-any */
3
- import { isDraftable, produce } from 'immer';
4
-
5
- import { Constructor } from '../Js';
6
-
7
- import Collection from '../Collection';
8
- import ReducerOverrideException from '../Exceptions/ReducerOverrideException';
9
-
10
-
11
- export type ReducerRepository = {
12
- [reducer: string]: Collection<Reducer<any, any[]>>;
13
- };
14
-
15
- export type ReducerCallback<TValue = any, TParams extends any[] = any[]> = (value: TValue, ...params: TParams) => TValue;
16
-
17
- export interface Reducer<TValue = any, TParams extends any[] = any[]> {
18
- callback: ReducerCallback<TValue, TParams>,
19
- priority: number,
20
- }
21
-
22
- export type Unsubscribe = () => void;
23
-
24
- export type ReducerMethodMap = Record<string, (value: any, ...params: any[]) => any>;
25
-
26
- type First<T extends any[]> = T extends [infer A, ...any] ? A : unknown;
27
- type Tail<T extends any[]> = T extends [any, ...infer R] ? R : unknown[];
28
-
29
- export type ReducerCallbackFor<
30
- TReducers extends ReducerMethodMap,
31
- K extends keyof TReducers
32
- > = ReducerCallback<First<Parameters<TReducers[K]>>, Tail<Parameters<TReducers[K]>>>;
33
-
34
- export type ReducerFor<
35
- TReducers extends ReducerMethodMap,
36
- K extends keyof TReducers
37
- > = Reducer<First<Parameters<TReducers[K]>>, Tail<Parameters<TReducers[K]>>>;
38
-
39
- export type ReducibleInterface<TReducers extends ReducerMethodMap> = {
40
-
41
- reducer<K extends keyof TReducers>(name: K, callback: ReducerCallbackFor<TReducers, K>, priority?: number): Unsubscribe;
42
- removeReducer<K extends keyof TReducers>(name: K, callback: ReducerCallbackFor<TReducers, K>): void;
43
- getReducer<K extends keyof TReducers>(name: K): Collection<ReducerFor<TReducers, K>>;
44
- hasReducer(name: string): boolean;
45
- clearReducer(name: string): void;
46
- flushReducers(): void;
47
- };
48
-
49
- export type ReducibleOf<TBase extends Constructor, TReducers extends ReducerMethodMap> = Omit<TBase, 'new'> & {
50
- new (...args: ConstructorParameters<TBase>): InstanceType<TBase> & TReducers & ReducibleInterface<TReducers>; /* & {
51
- [key: string]: (value: any, ...args: any[]) => any;
52
- };*/
53
- };
54
-
55
- export default function Reducible<TReducers extends ReducerMethodMap, TBase extends Constructor>(Base: TBase): ReducibleOf<TBase, TReducers> {
56
- return class extends Base {
57
- _reducers: ReducerRepository = {};
58
-
59
- constructor(...args: any[]) {
60
- super(...args);
61
- return new Proxy(this, {
62
- get(target, prop, receiver) {
63
- if (typeof prop === 'symbol' || prop in target) {
64
- return Reflect.get(target, prop, receiver);
65
- }
66
- return (value: unknown, ...args: unknown[]) => {
67
- const { [prop]: reducers = new Collection<Reducer>() } = target._reducers;
68
-
69
- if (isDraftable(value)) {
70
- return produce(value, (draft: unknown) => {
71
- return reducers
72
- .sortBy('priority')
73
- .reduce((prevValue, item) => item.callback(prevValue, ...args), draft);
74
- });
75
- }
76
-
77
- return reducers
78
- .sortBy('priority')
79
- .reduce((prevValue, item) => item.callback(prevValue, ...args), value);
80
- };
81
- },
82
-
83
- });
84
- }
85
-
86
- reducer(name: string, callback: ReducerCallback, priority: number = 10) {
87
- if (name in this) {
88
- throw new ReducerOverrideException(name, this);
89
- }
90
- if (!this._reducers[name]) {
91
- this._reducers[name] = new Collection<Reducer>();
92
- }
93
-
94
- this._reducers[name].push({ callback, priority });
95
-
96
- return () => this.removeReducer(name, callback);
97
- }
98
-
99
- removeReducer(name: string, callback: ReducerCallback) {
100
- const index = this._reducers[name].search((reducer) => reducer.callback === callback);
101
- if (index === false) {
102
- return;
103
- }
104
- this._reducers[name].pull(index);
105
- }
106
-
107
- getReducer(name: string): Collection<Reducer> {
108
- if (!this._reducers[name]) {
109
- this._reducers[name] = new Collection<Reducer>();
110
- }
111
- return this._reducers[name];
112
- }
113
-
114
- hasReducer(name: string): boolean {
115
- return !!this._reducers[name] && this._reducers[name].count() > 0;
116
- }
117
-
118
- clearReducer(name: string) {
119
- this._reducers[name].splice(0, this._reducers[name].count());
120
- }
121
-
122
- flushReducers() {
123
- Object.values(this._reducers).forEach((collection) => collection.splice(0, collection.count()));
124
- }
125
- } as any;
126
- }
package/src/Obj.ts DELETED
@@ -1,70 +0,0 @@
1
-
2
- import { toFormData as toPlatformData } from 'axios';
3
- import * as _ from 'lodash-es';
4
-
5
- export type JsonProperty = null | boolean | number | string;
6
-
7
-
8
- export function fromQuery(searchParams: URLSearchParams): Record<string, any> {
9
- const object: Record<string, string> = {};
10
-
11
- for (const [key, value] of searchParams.entries()) {
12
- set(object, key, value);
13
- }
14
-
15
- return object;
16
- }
17
-
18
- export function fromFormData(formData: FormData): Record<string, any> {
19
- return fromQuery(formData as unknown as URLSearchParams);
20
- }
21
-
22
- export function get(object: any, path: string, defaultValue?: any): any {
23
- return _.get(object, path, defaultValue);
24
- }
25
-
26
- export function has(object: any, path: string): boolean {
27
- return _.has(object, path);
28
- }
29
-
30
- export function isEmpty(object: any): boolean {
31
- return _.isEmpty(object);
32
- }
33
-
34
- export function isEqual(object: any, other: any): boolean {
35
- return _.isEqual(object, other);
36
- }
37
-
38
- export function merge(object: any, ...sources: any[]): any {
39
- return _.merge(object, ...sources);
40
- }
41
-
42
- export function omit(object: any, ...paths: string[]): any {
43
- return _.omit(object, ...paths);
44
- }
45
-
46
- export function pick(object: any, ...paths: string[]): any {
47
- return _.pick(object, ...paths);
48
- }
49
-
50
- export function set(object: any, path: string, value: any): void {
51
-
52
-
53
- _.set(object, path, value);
54
- }
55
-
56
- export function toQuery(object: any): URLSearchParams {
57
- return toPlatformData(object, new URLSearchParams()) as URLSearchParams;
58
- }
59
-
60
- export function toFormData(object: any): FormData {
61
- return toPlatformData(object, new FormData()) as FormData;
62
- }
63
-
64
- export function unset(object: any, path: string): void {
65
- _.unset(object, path);
66
- }
67
-
68
-
69
-
70
-
package/src/Query.ts DELETED
@@ -1,29 +0,0 @@
1
- import * as Obj from "./Obj";
2
- import * as Str from "./Str";
3
-
4
- export type Operator = '=' | '!=' | '>' | '>=' | '<' | '<=';
5
-
6
- export function fromObject(object: object): URLSearchParams {
7
- return Obj.toQuery(object);
8
- }
9
-
10
- export function toObject(searchParams: URLSearchParams): object {
11
- return Obj.fromQuery(searchParams);
12
- }
13
-
14
- export function merge(...parts: (string | URLSearchParams)[]): URLSearchParams {
15
-
16
- const searchParams = new URLSearchParams();
17
- parts.forEach((part) => {
18
-
19
- const params = typeof part === 'string'
20
- ? new URLSearchParams(Str.after(part, '?'))
21
- : part;
22
-
23
- params.forEach((value, key) => {
24
- searchParams.set(key, value);
25
- });
26
- });
27
-
28
- return searchParams;
29
- }
@@ -1,7 +0,0 @@
1
-
2
-
3
- export default class ApplicationService {
4
-
5
- }
6
-
7
-
package/src/Str.ts DELETED
@@ -1,53 +0,0 @@
1
- import * as _ from "lodash-es";
2
-
3
- export function after(string: string, search: string): string {
4
- if (!string.includes(search)) {
5
- return '';
6
- }
7
- return string.split(search).slice(1).join('');
8
- }
9
-
10
- export function afterLast(string: string, search: string): string {
11
- if (!string.includes(search)) {
12
- return '';
13
- }
14
- return string.split(search).slice(-1).join('');
15
- }
16
-
17
- export function before(string: string, search: string): string {
18
- if (!string.includes(search)) {
19
- return '';
20
- }
21
- return string.split(search).slice(0, 1).join('');
22
- }
23
-
24
- export function beforeLast(string: string, search: string): string {
25
- if (!string.includes(search)) {
26
- return '';
27
- }
28
- return string.split(search).slice(0, -1).join('');
29
- }
30
-
31
- export function camel(string: string): string {
32
- return _.camelCase(string);
33
- }
34
-
35
- export function kebab(string: string): string {
36
- return _.kebabCase(string);
37
- }
38
-
39
- export function studly(string: string): string {
40
- return _.upperFirst(camel(string));
41
- }
42
-
43
- export function snake(string: string): string {
44
- return _.snakeCase(string);
45
- }
46
-
47
- export function trim(string: string, chars?: string): string {
48
- return _.trim(string, chars);
49
- }
50
-
51
- export function upperFirst(string: string): string {
52
- return _.upperFirst(string);
53
- }
package/src/index.ts DELETED
@@ -1,26 +0,0 @@
1
- import * as Arr from './Arr';
2
- import Collection from './Collection';
3
- import EventSource from './Contracts/EventSource';
4
- import Http from './Http';
5
- import Reducible from './Mixins/Reducible';
6
- import Macroable from './Mixins/Macroable';
7
- import * as Obj from './Obj';
8
- import * as Query from './Query';
9
- import * as Str from './Str';
10
-
11
-
12
- export {
13
- Arr,
14
- Collection,
15
- EventSource,
16
- Http,
17
- Reducible,
18
- Macroable,
19
- Obj,
20
- Query,
21
- Str,
22
-
23
-
24
- };
25
-
26
-