@luminix/core 0.0.1-beta.8 → 0.1.0-beta.0
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/dist/core.js +1034 -1922
- package/package.json +7 -10
- package/types/contracts/Builder.d.ts +46 -0
- package/types/contracts/ModelCollection.d.ts +7 -0
- package/{dist → types}/contracts/Plugin.d.ts +3 -3
- package/{dist → types}/contracts/Relation/BelongsTo.d.ts +3 -5
- package/{dist → types}/contracts/Relation/BelongsToMany.d.ts +7 -9
- package/{dist → types}/contracts/Relation/HasMany.d.ts +6 -7
- package/{dist → types}/contracts/Relation/HasOne.d.ts +3 -4
- package/{dist → types}/contracts/Relation/HasOneOrMany.d.ts +0 -1
- package/{dist → types}/contracts/Relation/MorphMany.d.ts +6 -7
- package/{dist → types}/contracts/Relation/MorphOne.d.ts +3 -4
- package/{dist → types}/contracts/Relation/MorphOneOrMany.d.ts +0 -1
- package/{dist → types}/contracts/Relation/MorphTo.d.ts +0 -1
- package/types/contracts/Relation/MorphToMany.d.ts +8 -0
- package/{dist → types}/contracts/Relation.d.ts +12 -9
- package/types/facades/App.d.ts +12 -0
- package/types/facades/Auth.d.ts +7 -0
- package/types/facades/Config.d.ts +7 -0
- package/types/facades/Error.d.ts +10 -0
- package/types/facades/Http.d.ts +8 -0
- package/types/facades/Log.d.ts +7 -0
- package/types/facades/Model.d.ts +8 -0
- package/types/facades/Route.d.ts +7 -0
- package/types/helpers/app.d.ts +4 -0
- package/{dist → types}/helpers/auth.d.ts +0 -1
- package/types/helpers/collect.d.ts +2 -0
- package/{dist → types}/helpers/config.d.ts +0 -1
- package/{dist → types}/helpers/error.d.ts +0 -1
- package/types/helpers/log.d.ts +5 -0
- package/{dist → types}/helpers/model.d.ts +2 -3
- package/{dist → types}/helpers/route.d.ts +2 -2
- package/{dist → types}/index.d.ts +10 -10
- package/types/mixins/BaseModel.d.ts +7 -0
- package/types/providers/LuminixServiceProvider.d.ts +9 -0
- package/types/services/AuthService.d.ts +18 -0
- package/{dist/facades/Error.d.ts → types/services/ErrorService.d.ts} +2 -6
- package/types/services/HttpService.d.ts +21 -0
- package/{dist/facades/Log.d.ts → types/services/LogService.d.ts} +2 -4
- package/types/services/ModelService.d.ts +21 -0
- package/types/services/RouteService.d.ts +21 -0
- package/{dist → types}/support/model.d.ts +0 -1
- package/types/types/App.d.ts +88 -0
- package/{dist → types}/types/Auth.d.ts +0 -1
- package/types/types/Builder.d.ts +46 -0
- package/{dist → types}/types/Config.d.ts +4 -2
- package/types/types/Error.d.ts +17 -0
- package/types/types/Http.d.ts +20 -0
- package/{dist → types}/types/Model.d.ts +62 -44
- package/{dist → types}/types/Relation.d.ts +1 -2
- package/types/types/Route.d.ts +27 -0
- package/{dist → types}/types/Support.d.ts +3 -2
- package/vite.config.js +2 -2
- package/dist/contracts/Builder.d.ts +0 -53
- package/dist/contracts/Collection.d.ts +0 -190
- package/dist/contracts/ModelCollection.d.ts +0 -9
- package/dist/contracts/PropertyBag.d.ts +0 -21
- package/dist/contracts/Relation/MorphToMany.d.ts +0 -16
- package/dist/facades/App.d.ts +0 -37
- package/dist/facades/Auth.d.ts +0 -14
- package/dist/facades/Model.d.ts +0 -41
- package/dist/facades/Route.d.ts +0 -32
- package/dist/helpers/app.d.ts +0 -5
- package/dist/helpers/collect.d.ts +0 -1
- package/dist/helpers/log.d.ts +0 -5
- package/dist/mixins/BaseModel.d.ts +0 -5
- package/dist/mixins/HasEvents.d.ts +0 -15
- package/dist/mixins/Reducible.d.ts +0 -17
- package/dist/support/collection.d.ts +0 -4
- package/dist/support/reader.d.ts +0 -2
- package/dist/support/searchParams.d.ts +0 -1
- package/dist/types/App.d.ts +0 -79
- package/dist/types/Builder.d.ts +0 -51
- package/dist/types/Collection.d.ts +0 -1804
- package/dist/types/Error.d.ts +0 -31
- package/dist/types/Event.d.ts +0 -14
- package/dist/types/PropertyBag.d.ts +0 -25
- package/dist/types/Reducer.d.ts +0 -17
- package/dist/types/Route.d.ts +0 -22
- /package/{dist → types}/exceptions/AttributeNotFillableException.d.ts +0 -0
- /package/{dist → types}/exceptions/FacadeNotFoundException.d.ts +0 -0
- /package/{dist → types}/exceptions/MethodNotImplementedException.d.ts +0 -0
- /package/{dist → types}/exceptions/ModelInvalidRelatedTypeException.d.ts +0 -0
- /package/{dist → types}/exceptions/ModelNotFoundException.d.ts +0 -0
- /package/{dist → types}/exceptions/ModelNotPersistedException.d.ts +0 -0
- /package/{dist → types}/exceptions/ModelWithoutPrimaryKeyException.d.ts +0 -0
- /package/{dist → types}/exceptions/NoEmbedException.d.ts +0 -0
- /package/{dist → types}/exceptions/NoInverseRelationException.d.ts +0 -0
- /package/{dist → types}/exceptions/NotModelException.d.ts +0 -0
- /package/{dist → types}/exceptions/NotReducibleException.d.ts +0 -0
- /package/{dist → types}/exceptions/ReducerOverrideException.d.ts +0 -0
- /package/{dist → types}/exceptions/RouteNotFoundException.d.ts +0 -0
- /package/{dist → types}/exceptions/UnsupportedRelationException.d.ts +0 -0
- /package/{dist → types}/types/Log.d.ts +0 -0
- /package/{dist → types}/types/Plugin.d.ts +0 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { Client, Response } from '@luminix/support';
|
|
2
|
+
import { RouteDefinition, RouteTuple as RouteTuple, HttpMethod, RouteGenerator, RouteReducers } from '../types/Route';
|
|
3
|
+
import { ErrorFacade } from '../types/Error';
|
|
4
|
+
export declare class RouteService {
|
|
5
|
+
protected routes: RouteDefinition;
|
|
6
|
+
protected error: ErrorFacade;
|
|
7
|
+
protected http: () => Client;
|
|
8
|
+
protected appUrl: string;
|
|
9
|
+
constructor(routes: RouteDefinition, error: ErrorFacade, http: () => Client, appUrl?: string);
|
|
10
|
+
private isRouteTuple;
|
|
11
|
+
private extractGenerator;
|
|
12
|
+
get(name: string): RouteTuple;
|
|
13
|
+
url(generator: RouteGenerator): string;
|
|
14
|
+
methods(generator: RouteGenerator): HttpMethod[];
|
|
15
|
+
exists(name: string): boolean;
|
|
16
|
+
call<TResponse = any>(generator: RouteGenerator, tap?: (client: Client) => Client): Promise<Response<TResponse>>;
|
|
17
|
+
toString(): string;
|
|
18
|
+
[reducer: string]: unknown;
|
|
19
|
+
}
|
|
20
|
+
declare const _default: import('@luminix/support').ReducibleOf<typeof RouteService, RouteReducers>;
|
|
21
|
+
export default _default;
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { EventSource, Event, ReducibleInterface, FacadeOf, HasFacadeAccessor, Application, MacroableInterface } from '@luminix/support';
|
|
2
|
+
import { AppConfiguration, ConfigFacade } from './Config';
|
|
3
|
+
import { PluginInterface } from './Plugin';
|
|
4
|
+
import { LogFacade } from './Log';
|
|
5
|
+
import { BaseModel, Model, ModelPaginatedResponse, ModelReducers, ModelSchema, ModelSchemaAttributes } from './Model';
|
|
6
|
+
import { RouteFacade } from './Route';
|
|
7
|
+
import { ErrorFacade } from './Error';
|
|
8
|
+
import { Constructor } from './Support';
|
|
9
|
+
import { RelationInterface } from './Relation';
|
|
10
|
+
import { AuthFacade } from './Auth';
|
|
11
|
+
import { HttpFacade } from './Http';
|
|
12
|
+
type Plugin = PluginInterface<AppFacade, AppContainers>;
|
|
13
|
+
export type GlobalModelEvents = {
|
|
14
|
+
'save': (e: ModelGlobalEvent) => void;
|
|
15
|
+
'delete': (e: ModelGlobalEvent) => void;
|
|
16
|
+
'restore': (e: ModelGlobalEvent) => void;
|
|
17
|
+
'create': (e: ModelGlobalEvent) => void;
|
|
18
|
+
'update': (e: ModelGlobalEvent) => void;
|
|
19
|
+
'fetch': (e: ModelGlobalEvent) => void;
|
|
20
|
+
'error': (e: ModelGlobalErrorEvent) => void;
|
|
21
|
+
};
|
|
22
|
+
export type ModelGlobalEvent = Event<{
|
|
23
|
+
class: string;
|
|
24
|
+
model: BaseModel;
|
|
25
|
+
force?: boolean;
|
|
26
|
+
}, ModelFacade>;
|
|
27
|
+
export type ModelGlobalErrorEvent = ModelGlobalEvent & {
|
|
28
|
+
error: unknown;
|
|
29
|
+
operation: 'save' | 'delete' | 'restore' | 'forceDelete';
|
|
30
|
+
};
|
|
31
|
+
export type ModelFacade = EventSource<GlobalModelEvents> & ModelReducers & ReducibleInterface<ModelReducers> & {
|
|
32
|
+
schema(): ModelSchema;
|
|
33
|
+
schema(abstract: string): ModelSchemaAttributes;
|
|
34
|
+
make(): Record<string, typeof Model>;
|
|
35
|
+
make(abstract: string): typeof Model;
|
|
36
|
+
boot(app: AppFacade): void;
|
|
37
|
+
getRelationConstructors(abstract: string): Record<string, Constructor<RelationInterface<Model, ModelPaginatedResponse>>>;
|
|
38
|
+
};
|
|
39
|
+
export type AppEvents = {
|
|
40
|
+
'init': (e: InitEvent) => void;
|
|
41
|
+
'booted': (e: Event<{}, AppFacade>) => void;
|
|
42
|
+
'booting': (e: Event<{}, AppFacade>) => void;
|
|
43
|
+
};
|
|
44
|
+
export type InitEvent = Event<{
|
|
45
|
+
register(plugin: Plugin): void;
|
|
46
|
+
}, AppFacade>;
|
|
47
|
+
/** @deprecated */
|
|
48
|
+
export type AppExternal = {
|
|
49
|
+
boot: (config?: AppConfiguration) => Promise<AppContainers>;
|
|
50
|
+
/** @deprecated */
|
|
51
|
+
make(): AppContainers;
|
|
52
|
+
make<T extends keyof AppContainers>(key: T): AppContainers[T];
|
|
53
|
+
plugins: () => Plugin[];
|
|
54
|
+
on: EventSource<AppEvents>['once'];
|
|
55
|
+
environment(): string;
|
|
56
|
+
environment(...environments: string[]): boolean;
|
|
57
|
+
getPlugin<T extends Plugin>(abstract: Constructor<T>): T | undefined;
|
|
58
|
+
getLocale(): string;
|
|
59
|
+
hasDebugModeEnabled(): boolean;
|
|
60
|
+
isLocal(): boolean;
|
|
61
|
+
isProduction(): boolean;
|
|
62
|
+
setInstance(app: AppFacade): void;
|
|
63
|
+
};
|
|
64
|
+
export type AppFacade = FacadeOf<Application<AppContainers> & AppMacros & MacroableInterface<AppMacros>, HasFacadeAccessor> & {
|
|
65
|
+
down(): void;
|
|
66
|
+
};
|
|
67
|
+
export type AppContainers = {
|
|
68
|
+
auth: FacadeOf<AuthFacade, HasFacadeAccessor>;
|
|
69
|
+
config: FacadeOf<ConfigFacade, HasFacadeAccessor>;
|
|
70
|
+
error: FacadeOf<ErrorFacade, HasFacadeAccessor>;
|
|
71
|
+
http: FacadeOf<HttpFacade, HasFacadeAccessor>;
|
|
72
|
+
log: FacadeOf<LogFacade, HasFacadeAccessor>;
|
|
73
|
+
model: FacadeOf<ModelFacade, HasFacadeAccessor>;
|
|
74
|
+
route: FacadeOf<RouteFacade, HasFacadeAccessor>;
|
|
75
|
+
[key: string]: any;
|
|
76
|
+
};
|
|
77
|
+
export type BootOptions = {
|
|
78
|
+
config?: AppConfiguration;
|
|
79
|
+
skipBootRequest?: boolean;
|
|
80
|
+
};
|
|
81
|
+
export type AppMacros = {
|
|
82
|
+
environment(...environments: string[]): string | boolean;
|
|
83
|
+
getLocale(): string;
|
|
84
|
+
hasDebugModeEnabled(): boolean;
|
|
85
|
+
isLocal(): boolean;
|
|
86
|
+
isProduction(): boolean;
|
|
87
|
+
};
|
|
88
|
+
export {};
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { EventSource, Collection, PropertyBag, Query, Event, PropertyBagEventMap, JsonObject, JsonValue } from '@luminix/support';
|
|
2
|
+
export type Scope<TSingle, TMany> = (builder: BuilderInterface<TSingle, TMany>) => BuilderInterface<TSingle, TMany> | void;
|
|
3
|
+
export type ExtendedOperator = Query.Operator | 'like' | 'notLike' | 'between' | 'notBetween' | 'null' | 'notNull';
|
|
4
|
+
export type BuilderInterface<TSingle, TMany = Collection<TSingle>> = EventSource<BuilderEventMap<TSingle, TMany>> & {
|
|
5
|
+
lock(path: string): void;
|
|
6
|
+
where(scope: Scope<TSingle, TMany>): BuilderInterface<TSingle, TMany>;
|
|
7
|
+
where(key: string, value: JsonValue): BuilderInterface<TSingle, TMany>;
|
|
8
|
+
where(key: string, operator: ExtendedOperator, value: JsonValue): BuilderInterface<TSingle, TMany>;
|
|
9
|
+
where(key: string | Scope<TSingle, TMany>, operatorOrValue?: ExtendedOperator | JsonValue, value?: JsonValue): BuilderInterface<TSingle, TMany>;
|
|
10
|
+
with(relation: string | string[]): BuilderInterface<TSingle, TMany>;
|
|
11
|
+
withOnly(relation: string | string[]): BuilderInterface<TSingle, TMany>;
|
|
12
|
+
without(relation: string | string[]): BuilderInterface<TSingle, TMany>;
|
|
13
|
+
whereNull(key: string): BuilderInterface<TSingle, TMany>;
|
|
14
|
+
whereNotNull(key: string): BuilderInterface<TSingle, TMany>;
|
|
15
|
+
whereBetween(key: string, value: [JsonValue, JsonValue]): BuilderInterface<TSingle, TMany>;
|
|
16
|
+
whereNotBetween(key: string, value: [JsonValue, JsonValue]): BuilderInterface<TSingle, TMany>;
|
|
17
|
+
orderBy(column: string, direction?: 'asc' | 'desc'): BuilderInterface<TSingle, TMany>;
|
|
18
|
+
searchBy(term: string): BuilderInterface<TSingle, TMany>;
|
|
19
|
+
minified(): BuilderInterface<TSingle, TMany>;
|
|
20
|
+
limit(value: number): BuilderInterface<TSingle, TMany>;
|
|
21
|
+
include(searchParams: URLSearchParams): BuilderInterface<TSingle, TMany>;
|
|
22
|
+
get(page?: number, replaceLinksWith?: string): Promise<TMany>;
|
|
23
|
+
all(): Promise<Collection<TSingle>>;
|
|
24
|
+
first(): Promise<TSingle | null>;
|
|
25
|
+
find(id: string | number): Promise<TSingle | null>;
|
|
26
|
+
unset(key: string): BuilderInterface<TSingle, TMany>;
|
|
27
|
+
};
|
|
28
|
+
export type BuilderEventMap<TSingle, TMany> = PropertyBagEventMap & {
|
|
29
|
+
'change': (e: BuilderChangeEvent<TSingle, TMany>) => void;
|
|
30
|
+
'submit': (e: BuilderSubmitEvent<TSingle, TMany>) => void;
|
|
31
|
+
'success': (e: BuilderSuccessEvent<TSingle, TMany>) => void;
|
|
32
|
+
'error': (e: BuilderErrorEvent<TSingle, TMany>) => void;
|
|
33
|
+
};
|
|
34
|
+
export type BuilderChangeEvent<TSingle, TMany> = Event<{
|
|
35
|
+
data: PropertyBag<JsonObject>;
|
|
36
|
+
}, BuilderInterface<TSingle, TMany>>;
|
|
37
|
+
export type BuilderSubmitEvent<TSingle, TMany> = Event<{
|
|
38
|
+
data: PropertyBag<JsonObject>;
|
|
39
|
+
}, BuilderInterface<TSingle, TMany>>;
|
|
40
|
+
export type BuilderErrorEvent<TSingle, TMany> = Event<{
|
|
41
|
+
error: unknown;
|
|
42
|
+
}, BuilderInterface<TSingle, TMany>>;
|
|
43
|
+
export type BuilderSuccessEvent<TSingle, TMany> = Event<{
|
|
44
|
+
response: TMany;
|
|
45
|
+
items: TSingle | Collection<TSingle> | null;
|
|
46
|
+
}, BuilderInterface<TSingle, TMany>>;
|
|
@@ -1,13 +1,15 @@
|
|
|
1
|
-
import { PropertyBag } from '
|
|
1
|
+
import { PropertyBag } from '@luminix/support';
|
|
2
2
|
import { ModelSchema } from './Model';
|
|
3
3
|
import { RouteDefinition } from './Route';
|
|
4
|
-
|
|
5
4
|
export type AppConfiguration = {
|
|
6
5
|
app?: {
|
|
6
|
+
name?: string;
|
|
7
7
|
env?: string;
|
|
8
8
|
debug?: boolean;
|
|
9
9
|
url?: string;
|
|
10
|
+
port?: string | number;
|
|
10
11
|
bootUrl?: string | null | false;
|
|
12
|
+
/** @deprecated */
|
|
11
13
|
enforceCamelCaseForModelAttributes?: boolean;
|
|
12
14
|
[key: string]: unknown;
|
|
13
15
|
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { PropertyBag } from '@luminix/support';
|
|
2
|
+
export type ErrorBag = PropertyBag<Record<string, string>>;
|
|
3
|
+
export type ErrorFacade = {
|
|
4
|
+
add(key: string, value: string, bag?: string): void;
|
|
5
|
+
set(errors: Record<string, string>, bag?: string): void;
|
|
6
|
+
get(key: string, bag?: string): string | null;
|
|
7
|
+
all(bag?: string): Record<string, string>;
|
|
8
|
+
clear(bag?: string): void;
|
|
9
|
+
bag(name?: string): ErrorBag;
|
|
10
|
+
};
|
|
11
|
+
/** @deprecated */
|
|
12
|
+
export type ValidationError = {
|
|
13
|
+
message: string;
|
|
14
|
+
errors: {
|
|
15
|
+
[key: string]: string[];
|
|
16
|
+
};
|
|
17
|
+
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { Client, MacroableInterface, RequestOptions, Response } from '@luminix/support';
|
|
2
|
+
export type HttpMacro = (...args: any) => Client;
|
|
3
|
+
export type HttpFacade = Record<string, HttpMacro> & MacroableInterface<Record<string, HttpMacro>> & {
|
|
4
|
+
getClient(): Client;
|
|
5
|
+
baseUrl(baseUrl: string): Client;
|
|
6
|
+
asForm(): Client;
|
|
7
|
+
accept(type: string): Client;
|
|
8
|
+
acceptJson(): Client;
|
|
9
|
+
withHeaders(headers: Record<string, string>): Client;
|
|
10
|
+
withOptions(options: RequestOptions): Client;
|
|
11
|
+
withData(data: object): Client;
|
|
12
|
+
withQueryParameters(params: string | object): Client;
|
|
13
|
+
withBasicAuth(username: string, password: string): Client;
|
|
14
|
+
withToken(token: string): Client;
|
|
15
|
+
get<TResponse = any>(url: string, query?: string | object): Promise<Response<TResponse>>;
|
|
16
|
+
post<TResponse = any, TData = any>(url: string, data?: TData): Promise<Response<TResponse>>;
|
|
17
|
+
put<TResponse = any, TData = any>(url: string, data?: TData): Promise<Response<TResponse>>;
|
|
18
|
+
patch<TResponse = any, TData = any>(url: string, data?: TData): Promise<Response<TResponse>>;
|
|
19
|
+
delete<TResponse = any>(url: string, query?: string | object): Promise<Response<TResponse>>;
|
|
20
|
+
};
|
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { Collection } from './Collection';
|
|
4
|
-
import { RelationInterface, BuilderInterface, Scope, ExtendedOperator } from './Relation';
|
|
1
|
+
import { EventSource, Collection, Response, Event, Constructor } from '@luminix/support';
|
|
2
|
+
import { RelationInterface as RawRelationInterface, BuilderInterface, Scope, ExtendedOperator } from './Relation';
|
|
5
3
|
import { JsonObject, JsonValue } from './Support';
|
|
6
|
-
|
|
7
|
-
|
|
4
|
+
import { RouteGenerator } from './Route';
|
|
5
|
+
type RelationInterface = RawRelationInterface<Model, ModelPaginatedResponse>;
|
|
6
|
+
export type RelationRepository = Record<string, RelationInterface>;
|
|
8
7
|
export type ModelEvents = {
|
|
9
8
|
'change': (e: ModelChangeEvent) => void;
|
|
10
9
|
'save': (e: ModelSaveEvent) => void;
|
|
@@ -14,23 +13,29 @@ export type ModelEvents = {
|
|
|
14
13
|
'update': (e: ModelSaveEvent) => void;
|
|
15
14
|
'error': (e: ModelErrorEvent) => void;
|
|
16
15
|
};
|
|
17
|
-
export type
|
|
18
|
-
|
|
16
|
+
export type ModelReducers = {
|
|
17
|
+
model(constructor: typeof BaseModel, abstract: string): typeof BaseModel;
|
|
18
|
+
relationMap(relationMap: Record<string, Constructor<RelationInterface>>, abstract: string): Record<string, Constructor<RelationInterface>>;
|
|
19
|
+
guessInverseRelation(relationMap: Record<string, string[]>, parent: BaseModel, relationType: string, relatedClass: typeof BaseModel): Record<string, string[]>;
|
|
20
|
+
[key: string]: (value: any, ...params: any[]) => any;
|
|
19
21
|
};
|
|
20
|
-
export type
|
|
22
|
+
export type ModelChangeEvent = Event<{
|
|
21
23
|
value: JsonObject;
|
|
22
|
-
}
|
|
23
|
-
export type
|
|
24
|
+
}, BaseModel>;
|
|
25
|
+
export type ModelSaveEvent = Event<{
|
|
26
|
+
value: JsonObject;
|
|
27
|
+
}, BaseModel>;
|
|
28
|
+
export type ModelDeleteEvent = Event<{
|
|
24
29
|
force: boolean;
|
|
25
|
-
}
|
|
26
|
-
export type ModelRestoreEvent = Event<
|
|
30
|
+
}, BaseModel>;
|
|
31
|
+
export type ModelRestoreEvent = Event<{
|
|
27
32
|
value: JsonObject;
|
|
28
|
-
}
|
|
29
|
-
export type ModelErrorEvent = Event<
|
|
33
|
+
}, BaseModel>;
|
|
34
|
+
export type ModelErrorEvent = Event<{
|
|
30
35
|
error: unknown;
|
|
31
36
|
operation: 'save' | 'delete' | 'restore' | 'forceDelete';
|
|
32
|
-
}
|
|
33
|
-
export declare class BaseModel
|
|
37
|
+
}, BaseModel>;
|
|
38
|
+
export declare class BaseModel extends EventSource<ModelEvents> {
|
|
34
39
|
constructor(attributes?: JsonObject);
|
|
35
40
|
get attributes(): JsonObject;
|
|
36
41
|
get original(): JsonObject;
|
|
@@ -41,22 +46,29 @@ export declare class BaseModel implements EventSource<ModelEvents> {
|
|
|
41
46
|
get isDirty(): boolean;
|
|
42
47
|
get casts(): ModelSchemaAttributes['casts'];
|
|
43
48
|
exists: boolean;
|
|
49
|
+
wasRecentlyCreated: boolean;
|
|
44
50
|
getAttribute(key: string): unknown;
|
|
45
51
|
setAttribute(key: string, value: unknown): void;
|
|
46
52
|
getKey(): string | number;
|
|
47
53
|
getKeyName(): string;
|
|
48
|
-
|
|
54
|
+
getLabel(): string;
|
|
55
|
+
fill(attributes: object): void;
|
|
49
56
|
toJson(): JsonObject;
|
|
50
57
|
diff(): JsonObject;
|
|
51
58
|
getType(): string;
|
|
52
59
|
dump(): void;
|
|
53
|
-
save(options?: ModelSaveOptions): Promise<
|
|
60
|
+
save(options?: ModelSaveOptions): Promise<Response | void>;
|
|
54
61
|
update(attributes: JsonObject): Promise<void>;
|
|
55
|
-
delete(): Promise<
|
|
56
|
-
forceDelete(): Promise<
|
|
57
|
-
restore(): Promise<
|
|
62
|
+
delete(): Promise<Response>;
|
|
63
|
+
forceDelete(): Promise<Response>;
|
|
64
|
+
restore(): Promise<Response>;
|
|
58
65
|
refresh(): Promise<void>;
|
|
59
|
-
relation(relationName: string): RelationInterface
|
|
66
|
+
relation(relationName: string): RelationInterface | undefined;
|
|
67
|
+
getErrorBag(method: string): string;
|
|
68
|
+
getRouteForSave(): RouteGenerator;
|
|
69
|
+
getRouteForUpdate(): RouteGenerator;
|
|
70
|
+
getRouteForDelete(): RouteGenerator;
|
|
71
|
+
getRouteForRefresh(): RouteGenerator;
|
|
60
72
|
static getSchemaName(): string;
|
|
61
73
|
static getSchema(): ModelSchemaAttributes;
|
|
62
74
|
static query(): BuilderInterface<Model, ModelPaginatedResponse>;
|
|
@@ -77,12 +89,12 @@ export declare class BaseModel implements EventSource<ModelEvents> {
|
|
|
77
89
|
static limit(value: number): BuilderInterface<Model, ModelPaginatedResponse>;
|
|
78
90
|
static create(attributes: JsonObject): Promise<Model>;
|
|
79
91
|
static update(id: number | string, attributes: JsonObject): Promise<Model>;
|
|
80
|
-
static delete(id: number | string): Promise<
|
|
81
|
-
static delete(ids: Array<number | string>): Promise<
|
|
82
|
-
static restore(id: number | string): Promise<
|
|
83
|
-
static restore(ids: Array<number | string>): Promise<
|
|
84
|
-
static forceDelete(id: number | string): Promise<
|
|
85
|
-
static forceDelete(ids: Array<number | string>): Promise<
|
|
92
|
+
static delete(id: number | string): Promise<Response>;
|
|
93
|
+
static delete(ids: Array<number | string>): Promise<Response>;
|
|
94
|
+
static restore(id: number | string): Promise<Response>;
|
|
95
|
+
static restore(ids: Array<number | string>): Promise<Response>;
|
|
96
|
+
static forceDelete(id: number | string): Promise<Response>;
|
|
97
|
+
static forceDelete(ids: Array<number | string>): Promise<Response>;
|
|
86
98
|
static singular(): string;
|
|
87
99
|
static plural(): string;
|
|
88
100
|
on: EventSource<ModelEvents>['on'];
|
|
@@ -106,22 +118,23 @@ export interface ModelTableColumnDefinition {
|
|
|
106
118
|
label: string;
|
|
107
119
|
sortable?: boolean;
|
|
108
120
|
}
|
|
121
|
+
export type ModelAttribute = {
|
|
122
|
+
appended: true | null;
|
|
123
|
+
cast: string | null;
|
|
124
|
+
default: string | null;
|
|
125
|
+
fillable: boolean;
|
|
126
|
+
hidden: boolean;
|
|
127
|
+
increments: boolean;
|
|
128
|
+
name: string;
|
|
129
|
+
nullable: boolean;
|
|
130
|
+
phpType: string | null;
|
|
131
|
+
primary: boolean;
|
|
132
|
+
type: string | null;
|
|
133
|
+
unique: boolean;
|
|
134
|
+
virtual: boolean;
|
|
135
|
+
};
|
|
109
136
|
export interface ModelSchemaAttributes {
|
|
110
|
-
attributes:
|
|
111
|
-
appended: true | null;
|
|
112
|
-
cast: string | null;
|
|
113
|
-
default: string | null;
|
|
114
|
-
fillable: boolean;
|
|
115
|
-
hidden: boolean;
|
|
116
|
-
increments: boolean;
|
|
117
|
-
name: string;
|
|
118
|
-
nullable: boolean;
|
|
119
|
-
phpType: string | null;
|
|
120
|
-
primary: boolean;
|
|
121
|
-
type: string | null;
|
|
122
|
-
unique: boolean;
|
|
123
|
-
virtual: boolean;
|
|
124
|
-
}[];
|
|
137
|
+
attributes: ModelAttribute[];
|
|
125
138
|
displayName: {
|
|
126
139
|
singular: string;
|
|
127
140
|
plural: string;
|
|
@@ -132,6 +145,7 @@ export interface ModelSchemaAttributes {
|
|
|
132
145
|
primaryKey: string;
|
|
133
146
|
timestamps: boolean;
|
|
134
147
|
labeledBy: string;
|
|
148
|
+
softDeletes: boolean;
|
|
135
149
|
[key: string]: any;
|
|
136
150
|
}
|
|
137
151
|
export interface RelationMetaData {
|
|
@@ -161,6 +175,9 @@ export type ModelPaginatedLink = {
|
|
|
161
175
|
label: string;
|
|
162
176
|
active: boolean;
|
|
163
177
|
};
|
|
178
|
+
export type ModelRawPaginatedResponse = Omit<ModelPaginatedResponse, 'data'> & {
|
|
179
|
+
data: JsonObject[];
|
|
180
|
+
};
|
|
164
181
|
export type ModelPaginatedResponse = {
|
|
165
182
|
data: Collection<Model>;
|
|
166
183
|
links: {
|
|
@@ -179,3 +196,4 @@ export type ModelPaginatedResponse = {
|
|
|
179
196
|
links: Array<ModelPaginatedLink>;
|
|
180
197
|
};
|
|
181
198
|
};
|
|
199
|
+
export {};
|
|
@@ -1,7 +1,6 @@
|
|
|
1
|
+
import { Collection } from '@luminix/support';
|
|
1
2
|
import { BuilderInterface, ExtendedOperator, Scope } from './Builder';
|
|
2
|
-
import { Collection } from './Collection';
|
|
3
3
|
import { Constructor, JsonValue } from './Support';
|
|
4
|
-
|
|
5
4
|
export type { BuilderInterface, ExtendedOperator, Scope, };
|
|
6
5
|
export type RelationInterface<R, C> = {
|
|
7
6
|
guessInverseRelation(): string;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { ReducibleInterface, Response, Client, RequestOptions } from '@luminix/support';
|
|
2
|
+
export type RouteReplacer = {
|
|
3
|
+
[key: string]: string | number;
|
|
4
|
+
};
|
|
5
|
+
export type RouteReducers = {
|
|
6
|
+
clientOptions(config: RequestOptions, routeName: string): RequestOptions;
|
|
7
|
+
clientError(errors: Record<string, string>, event: {
|
|
8
|
+
response: Response;
|
|
9
|
+
name: string;
|
|
10
|
+
replace: RouteReplacer;
|
|
11
|
+
client: Client;
|
|
12
|
+
}): Record<string, string>;
|
|
13
|
+
replaceRouteParams(url: string): string;
|
|
14
|
+
};
|
|
15
|
+
export type RouteFacade = ReducibleInterface<RouteReducers> & {
|
|
16
|
+
get(name: string): RouteTuple;
|
|
17
|
+
url(generator: RouteGenerator): string;
|
|
18
|
+
exists(name: string): boolean;
|
|
19
|
+
call<TResponse = unknown>(generator: RouteGenerator, tap?: (client: Client) => Client): Promise<Response<TResponse>>;
|
|
20
|
+
methods(generator: RouteGenerator): HttpMethod[];
|
|
21
|
+
};
|
|
22
|
+
export type RouteGenerator = string | [string, RouteReplacer];
|
|
23
|
+
export type HttpMethod = 'get' | 'post' | 'put' | 'patch' | 'delete';
|
|
24
|
+
export type RouteTuple = [string, ...HttpMethod[]];
|
|
25
|
+
export type RouteDefinition = {
|
|
26
|
+
[routeName: string]: RouteTuple | RouteDefinition;
|
|
27
|
+
};
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
|
|
1
|
+
/** @deprecated */
|
|
2
2
|
export type Constructor<T = {}> = new (...args: any[]) => T;
|
|
3
|
-
|
|
3
|
+
/** @deprecated */
|
|
4
4
|
export type JsonObject = {
|
|
5
5
|
[key: string]: JsonValue;
|
|
6
6
|
};
|
|
7
|
+
/** @deprecated */
|
|
7
8
|
export type JsonValue = string | number | boolean | null | JsonObject | Array<string | number | boolean | null | JsonObject>;
|
package/vite.config.js
CHANGED
|
@@ -6,11 +6,11 @@ import dts from 'vite-plugin-dts';
|
|
|
6
6
|
import packageJson from './package.json';
|
|
7
7
|
|
|
8
8
|
export default defineConfig({
|
|
9
|
-
plugins: [dts({ insertTypesEntry: true })],
|
|
9
|
+
plugins: [dts({ insertTypesEntry: true, outDir: 'types' })],
|
|
10
10
|
build: {
|
|
11
11
|
lib: {
|
|
12
12
|
entry: resolve(__dirname, 'src/index.ts'),
|
|
13
|
-
formats: ['es']
|
|
13
|
+
formats: ['es'],
|
|
14
14
|
},
|
|
15
15
|
rollupOptions: {
|
|
16
16
|
external: Object.keys(packageJson.peerDependencies),
|
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
import { Unsubscribe } from 'nanoevents';
|
|
2
|
-
import { AppFacades } from '../types/App';
|
|
3
|
-
import { BuilderEventMap as BuilderEvents, BuilderInterface as BuilderBase, ExtendedOperator } from '../types/Builder';
|
|
4
|
-
import { EventData } from '../types/Event';
|
|
5
|
-
import { Model, ModelPaginatedResponse, ModelQuery } from '../types/Model';
|
|
6
|
-
import { JsonValue } from '../types/Support';
|
|
7
|
-
import { Collection as CollectionInterface } from '../types/Collection';
|
|
8
|
-
|
|
9
|
-
type BuilderInterface = BuilderBase<Model, ModelPaginatedResponse>;
|
|
10
|
-
type BuilderEventMap = BuilderEvents<Model, ModelPaginatedResponse>;
|
|
11
|
-
declare class Builder implements BuilderInterface {
|
|
12
|
-
protected facades: AppFacades;
|
|
13
|
-
protected abstract: string;
|
|
14
|
-
protected query: ModelQuery;
|
|
15
|
-
private bag;
|
|
16
|
-
constructor(facades: AppFacades, abstract: string, query?: ModelQuery);
|
|
17
|
-
on<T extends keyof BuilderEventMap>(_: T, __: BuilderEventMap[T]): Unsubscribe;
|
|
18
|
-
once<T extends keyof BuilderEventMap>(_: T, __: BuilderEventMap[T]): void;
|
|
19
|
-
emit<T extends keyof BuilderEventMap>(_: T, __: EventData<BuilderEventMap, T>): void;
|
|
20
|
-
lock(path: string): void;
|
|
21
|
-
whereBetween(key: string, value: [JsonValue, JsonValue]): this;
|
|
22
|
-
whereNotBetween(key: string, value: [JsonValue, JsonValue]): this;
|
|
23
|
-
whereNull(key: string): this;
|
|
24
|
-
whereNotNull(key: string): this;
|
|
25
|
-
limit(value: number): this;
|
|
26
|
-
where(scope: (builder: BuilderInterface) => BuilderInterface | void): this;
|
|
27
|
-
where(key: string, value: JsonValue): this;
|
|
28
|
-
where(key: string, operator: ExtendedOperator, value: JsonValue): this;
|
|
29
|
-
with(relation: string | string[]): this;
|
|
30
|
-
withOnly(relation: string | string[]): this;
|
|
31
|
-
without(relation: string | string[]): this;
|
|
32
|
-
orderBy(column: string, direction?: 'asc' | 'desc'): this;
|
|
33
|
-
searchBy(term: string): this;
|
|
34
|
-
minified(): this;
|
|
35
|
-
unset(key: string): this;
|
|
36
|
-
include(searchParams: URLSearchParams): this;
|
|
37
|
-
private exec;
|
|
38
|
-
get(page?: number, replaceLinksWith?: string): Promise<ModelPaginatedResponse>;
|
|
39
|
-
first(): Promise<Model | null>;
|
|
40
|
-
find(id: string | number): Promise<Model | null>;
|
|
41
|
-
all(): Promise<CollectionInterface<Model>>;
|
|
42
|
-
}
|
|
43
|
-
declare const _default: {
|
|
44
|
-
new (...args: any[]): {
|
|
45
|
-
"__#1@#emitter": import('nanoevents').Emitter<import('../types/Event').EventSourceEvents>;
|
|
46
|
-
"__#1@#createNanoEvents"(): import('nanoevents').Emitter<import('../types/Event').EventSourceEvents>;
|
|
47
|
-
on<E extends "change" | "submit" | "success" | "error">(event: E, callback: BuilderEventMap[E]): Unsubscribe;
|
|
48
|
-
once<E_1 extends "change" | "submit" | "success" | "error">(event: E_1, callback: BuilderEventMap[E_1]): void;
|
|
49
|
-
emit<E_2 extends "change" | "submit" | "success" | "error">(event: E_2, data?: Omit<Parameters<BuilderEventMap[E_2]>[0], "source">): void;
|
|
50
|
-
[Symbol.toStringTag]: string;
|
|
51
|
-
};
|
|
52
|
-
} & typeof Builder;
|
|
53
|
-
export default _default;
|