@luminix/support 0.0.1-beta.1 → 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.
package/package.json CHANGED
@@ -1,10 +1,11 @@
1
1
  {
2
2
  "name": "@luminix/support",
3
- "version": "0.0.1-beta.1",
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 CHANGED
@@ -1,18 +1,25 @@
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[];
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;
@@ -1,15 +1,18 @@
1
1
  import { Unsubscribe } from 'nanoevents';
2
- export type Event<TData = any, TSource extends EventSource = EventSource> = TData & {
2
+ export type Event<TData = any, TSource extends EventSource = any> = TData & {
3
3
  source: TSource;
4
4
  };
5
5
  export type EventMap = {
6
6
  [key: string]: (event: Event) => void;
7
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];
8
11
  export default class EventSource<TEvents extends EventMap = EventMap> {
9
12
  private emitter;
10
13
  constructor();
11
14
  on<E extends keyof TEvents>(event: E, callback: TEvents[E]): Unsubscribe;
12
15
  once<E extends keyof TEvents>(event: E, callback: TEvents[E]): void;
13
16
  emit<E extends keyof TEvents>(event: E, ...data: Parameters<TEvents[E]>): void;
14
- static foo(): string;
17
+ flushEvents(): void;
15
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,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>;
@@ -15,6 +15,8 @@ export default class Client {
15
15
  replaceOptions(options: RequestOptions): this;
16
16
  withQueryParameters(params: string | object): this;
17
17
  replaceQueryParameters(params: string | object): this;
18
+ withData(data: object): this;
19
+ replaceData(data: object): this;
18
20
  withBasicAuth(username: string, password: string): this;
19
21
  withToken(token: string): this;
20
22
  get<TResponse = any>(url: string, query?: string | object): Request<TResponse, any>;
@@ -1,12 +1,14 @@
1
1
  import { AxiosResponse } from 'axios';
2
2
  export default class Response<TResponse = any, TData = any> {
3
- private response;
4
- private error?;
5
- constructor(response: AxiosResponse<TResponse, TData>, error?: Error | undefined);
3
+ protected _response: AxiosResponse<TResponse, TData>;
4
+ protected _error?: Error | undefined;
5
+ constructor(_response: AxiosResponse<TResponse, TData>, _error?: Error | undefined);
6
+ error(): Error | undefined;
6
7
  body(): string;
7
8
  json(): TResponse;
8
9
  json<K extends keyof TResponse>(key: K): TResponse[K];
9
10
  json(key: string, defaultValue?: any): any;
11
+ has(key: string): boolean;
10
12
  status(): number;
11
13
  successful(): boolean;
12
14
  redirect(): boolean;
@@ -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 CHANGED
@@ -1,2 +1,6 @@
1
- export type Constructor<T = {}> = new (...args: any[]) => T;
1
+ export type Constructor<TInstance = {}, TArgs extends Array<any> = any[]> = new (...args: TArgs) => TInstance;
2
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,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>;
package/types/Obj.d.ts CHANGED
@@ -1,14 +1,20 @@
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;
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;
package/types/Query.d.ts CHANGED
@@ -1,4 +1,4 @@
1
1
  export type Operator = '=' | '!=' | '>' | '>=' | '<' | '<=';
2
2
  export declare function fromObject(object: object): URLSearchParams;
3
- export declare function toObject(searchParams: URLSearchParams): object;
3
+ export declare function toObject(searchParams: URLSearchParams): Record<string, any>;
4
4
  export declare function merge(...parts: (string | URLSearchParams)[]): URLSearchParams;
package/types/Str.d.ts CHANGED
@@ -3,8 +3,16 @@ export declare function afterLast(string: string, search: string): string;
3
3
  export declare function before(string: string, search: string): string;
4
4
  export declare function beforeLast(string: string, search: string): string;
5
5
  export declare function camel(string: string): string;
6
+ export declare function lcfirst(string: string): string;
7
+ export declare function lower(string: string): string;
6
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;
7
13
  export declare function studly(string: string): string;
8
14
  export declare function snake(string: string): string;
15
+ export declare function title(string: string): string;
9
16
  export declare function trim(string: string, chars?: string): string;
10
- export declare function upperFirst(string: string): string;
17
+ export declare function ucfirst(string: string): string;
18
+ export declare function upper(string: string): string;
package/types/index.d.ts CHANGED
@@ -1,10 +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';
1
4
  import { default as Collection } from './Collection';
2
5
  import { default as EventSource } from './Contracts/EventSource';
3
- import { default as Http } from './Http';
4
- import { default as Reducible } from './Mixins/Reducible';
5
6
  import { default as Macroable } from './Mixins/Macroable';
6
- import * as Arr from './Arr';
7
- import * as Obj from './Obj';
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';
8
20
  import * as Query from './Query';
9
21
  import * as Str from './Str';
10
- export { Arr, Collection, EventSource, Http, Reducible, Macroable, Obj, Query, 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;
package/vite.config.js CHANGED
@@ -12,11 +12,6 @@ export default defineConfig({
12
12
  entry: resolve(__dirname, 'src/index.ts'),
13
13
  formats: ['es'],
14
14
  },
15
- rollupOptions: {
16
- external: [
17
- 'immer',
18
- ]
19
- }
20
15
  },
21
16
 
22
17
  });
@@ -1,6 +0,0 @@
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
@@ -1,25 +0,0 @@
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;
package/types/Http.d.ts DELETED
@@ -1,30 +0,0 @@
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,2 +0,0 @@
1
- export default class ApplicationService {
2
- }