@luminix/core 0.0.1-beta.3 → 0.0.1-beta.4

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 (70) hide show
  1. package/dist/contracts/Builder.d.ts +49 -0
  2. package/dist/contracts/Collection.d.ts +190 -0
  3. package/dist/contracts/ModelCollection.d.ts +9 -0
  4. package/dist/contracts/Plugin.d.ts +8 -0
  5. package/dist/contracts/PropertyBag.d.ts +21 -0
  6. package/dist/contracts/Relation/BelongsTo.d.ts +20 -0
  7. package/dist/contracts/Relation/BelongsToMany.d.ts +31 -0
  8. package/dist/contracts/Relation/HasMany.d.ts +21 -0
  9. package/dist/contracts/Relation/HasOne.d.ts +15 -0
  10. package/dist/contracts/Relation/HasOneOrMany.d.ts +10 -0
  11. package/dist/contracts/Relation/MorphMany.d.ts +21 -0
  12. package/dist/contracts/Relation/MorphOne.d.ts +15 -0
  13. package/dist/contracts/Relation/MorphOneOrMany.d.ts +10 -0
  14. package/dist/contracts/Relation/MorphTo.d.ts +8 -0
  15. package/dist/contracts/Relation/MorphToMany.d.ts +16 -0
  16. package/dist/contracts/Relation.d.ts +44 -0
  17. package/dist/core.js +678 -653
  18. package/dist/exceptions/AttributeNotFillableException.d.ts +4 -0
  19. package/dist/exceptions/FacadeNotFoundException.d.ts +4 -0
  20. package/dist/exceptions/MethodNotImplementedException.d.ts +4 -0
  21. package/dist/exceptions/ModelInvalidRelatedTypeException.d.ts +4 -0
  22. package/dist/exceptions/ModelNotFoundException.d.ts +4 -0
  23. package/dist/exceptions/ModelNotPersistedException.d.ts +4 -0
  24. package/dist/exceptions/ModelWithoutPrimaryKeyException.d.ts +4 -0
  25. package/dist/exceptions/NoEmbedException.d.ts +4 -0
  26. package/dist/exceptions/NoInverseRelationException.d.ts +4 -0
  27. package/dist/exceptions/NotModelException.d.ts +4 -0
  28. package/dist/exceptions/NotReducibleException.d.ts +4 -0
  29. package/dist/exceptions/ReducerOverrideException.d.ts +4 -0
  30. package/dist/exceptions/RouteNotFoundException.d.ts +4 -0
  31. package/dist/exceptions/UnsupportedRelationException.d.ts +4 -0
  32. package/dist/facades/App.d.ts +30 -0
  33. package/dist/facades/Auth.d.ts +14 -0
  34. package/dist/facades/Error.d.ts +15 -0
  35. package/dist/facades/Log.d.ts +14 -0
  36. package/dist/facades/Model.d.ts +41 -0
  37. package/dist/facades/Route.d.ts +32 -0
  38. package/dist/helpers/app.d.ts +5 -0
  39. package/dist/helpers/auth.d.ts +3 -0
  40. package/dist/helpers/collect.d.ts +1 -0
  41. package/dist/helpers/config.d.ts +5 -0
  42. package/dist/helpers/error.d.ts +4 -0
  43. package/dist/helpers/log.d.ts +5 -0
  44. package/dist/helpers/model.d.ts +6 -0
  45. package/dist/helpers/route.d.ts +5 -0
  46. package/dist/index.d.ts +24 -0
  47. package/dist/mixins/BaseModel.d.ts +5 -0
  48. package/dist/mixins/HasEvents.d.ts +15 -0
  49. package/dist/mixins/Reducible.d.ts +17 -0
  50. package/dist/support/collection.d.ts +4 -0
  51. package/dist/support/model.d.ts +3 -0
  52. package/dist/support/reader.d.ts +2 -0
  53. package/dist/support/searchParams.d.ts +1 -0
  54. package/dist/types/App.d.ts +72 -0
  55. package/dist/types/Auth.d.ts +13 -0
  56. package/dist/types/Builder.d.ts +47 -0
  57. package/dist/types/Collection.d.ts +1804 -0
  58. package/dist/types/Config.d.ts +29 -0
  59. package/dist/types/Error.d.ts +31 -0
  60. package/dist/types/Event.d.ts +14 -0
  61. package/dist/types/Log.d.ts +37 -0
  62. package/dist/types/Model.d.ts +165 -0
  63. package/dist/types/Plugin.d.ts +4 -0
  64. package/dist/types/PropertyBag.d.ts +25 -0
  65. package/dist/types/Reducer.d.ts +17 -0
  66. package/dist/types/Relation.d.ts +30 -0
  67. package/dist/types/Route.d.ts +22 -0
  68. package/dist/types/Support.d.ts +7 -0
  69. package/package.json +1 -1
  70. package/vite.config.js +2 -2
@@ -0,0 +1,29 @@
1
+ import { PropertyBag } from './PropertyBag';
2
+ import { ModelSchema } from './Model';
3
+ import { RouteDefinition } from './Route';
4
+
5
+ export type AppConfiguration = {
6
+ app?: {
7
+ env?: string;
8
+ debug?: boolean;
9
+ url?: string;
10
+ bootUrl?: string | null | false;
11
+ enforceCamelCaseForModelAttributes?: boolean;
12
+ [key: string]: unknown;
13
+ };
14
+ auth?: {
15
+ user: {
16
+ id: number;
17
+ name: string;
18
+ email: string;
19
+ [key: string]: unknown;
20
+ } | null;
21
+ csrf?: string;
22
+ };
23
+ manifest?: {
24
+ models?: ModelSchema;
25
+ routes?: RouteDefinition;
26
+ };
27
+ [key: string]: unknown;
28
+ };
29
+ export type ConfigFacade = PropertyBag<AppConfiguration>;
@@ -0,0 +1,31 @@
1
+ import { default as PropertyBag } from '../contracts/PropertyBag';
2
+ import { Event, EventSource } from './Event';
3
+ import { PropertyBagEventMap } from './PropertyBag';
4
+
5
+ export type ErrorEventMap = {
6
+ change: (e: ErrorChangeEvent) => void;
7
+ };
8
+ export type ErrorChangeEvent = Event<ErrorFacade> & {
9
+ value: string | null;
10
+ key: string;
11
+ };
12
+ export type ErrorBag = EventSource<PropertyBagEventMap> & PropertyBag<Record<string, string>>;
13
+ export type ErrorFacade = {
14
+ add(key: string, value: string, bag?: string): void;
15
+ set(errors: Record<string, string>, bag?: string): void;
16
+ get(key: string, bag?: string): string | null;
17
+ all(bag?: string): Record<string, string>;
18
+ clear(bag?: string): void;
19
+ bag(name?: string): ErrorBag;
20
+ };
21
+ export type ValidationError = Error & {
22
+ response: {
23
+ status: 422;
24
+ data: {
25
+ message: string;
26
+ errors: {
27
+ [key: string]: string[];
28
+ };
29
+ };
30
+ };
31
+ };
@@ -0,0 +1,14 @@
1
+ import { Unsubscribe } from 'nanoevents';
2
+
3
+ export type Event<S = any> = {
4
+ source: S;
5
+ };
6
+ export type EventSourceEvents = {
7
+ [event: string]: (e: any) => void;
8
+ };
9
+ export type EventSource<T extends EventSourceEvents> = {
10
+ on<E extends keyof T>(event: E, callback: T[E]): Unsubscribe;
11
+ once<E extends keyof T>(event: E, callback: T[E]): void;
12
+ emit<E extends keyof T>(event: E, data?: EventData<T, E>): void;
13
+ };
14
+ export type EventData<T extends EventSourceEvents, E extends keyof T> = Omit<Parameters<T[E]>[0], 'source'>;
@@ -0,0 +1,37 @@
1
+ /**
2
+ * A facade for logging messages. Provides eight logging levels, defined in the RFC 5424 standard.
3
+ */
4
+ export type LogFacade = {
5
+ /**
6
+ * System is unusable. (Code: 0)
7
+ */
8
+ emergency(...args: any[]): void;
9
+ /**
10
+ * Action must be taken immediately. (Code: 1)
11
+ */
12
+ alert(...args: any[]): void;
13
+ /**
14
+ * Critical conditions. (Code: 2)
15
+ */
16
+ critical(...args: any[]): void;
17
+ /**
18
+ * Error conditions. (Code: 3)
19
+ */
20
+ error(...args: any[]): void;
21
+ /**
22
+ * Warning conditions. (Code: 4)
23
+ */
24
+ warning(...args: any[]): void;
25
+ /**
26
+ * Normal but significant condition. (Code: 5)
27
+ */
28
+ notice(...args: any[]): void;
29
+ /**
30
+ * Informational messages. (Code: 6)
31
+ */
32
+ info(...args: any[]): void;
33
+ /**
34
+ * Debug-level messages. (Code: 7)
35
+ */
36
+ debug(...args: any[]): void;
37
+ };
@@ -0,0 +1,165 @@
1
+ import { AxiosResponse } from 'axios';
2
+ import { EventSource, Event } from './Event';
3
+ import { Collection } from './Collection';
4
+ import { RelationInterface, BuilderInterface, Scope, ExtendedOperator } from './Relation';
5
+ import { JsonObject, JsonValue } from './Support';
6
+
7
+ export type RelationRepository = Record<string, RelationInterface<Model, ModelPaginatedResponse>>;
8
+ export type ModelEvents = {
9
+ 'change': (e: ModelChangeEvent) => void;
10
+ 'save': (e: ModelSaveEvent) => void;
11
+ 'delete': (e: ModelDeleteEvent) => void;
12
+ 'restore': (e: ModelRestoreEvent) => void;
13
+ 'create': (e: ModelSaveEvent) => void;
14
+ 'update': (e: ModelSaveEvent) => void;
15
+ 'error': (e: ModelErrorEvent) => void;
16
+ };
17
+ export type ModelChangeEvent = Event<BaseModel> & {
18
+ value: JsonObject;
19
+ };
20
+ export type ModelSaveEvent = Event<BaseModel> & {
21
+ value: JsonObject;
22
+ };
23
+ export type ModelDeleteEvent = Event<BaseModel> & {
24
+ force: boolean;
25
+ };
26
+ export type ModelRestoreEvent = Event<BaseModel> & {
27
+ value: JsonObject;
28
+ };
29
+ export type ModelErrorEvent = Event<BaseModel> & {
30
+ error: unknown;
31
+ operation: 'save' | 'delete' | 'restore' | 'forceDelete';
32
+ };
33
+ export declare class BaseModel implements EventSource<ModelEvents> {
34
+ constructor(attributes?: JsonObject);
35
+ get attributes(): JsonObject;
36
+ get original(): JsonObject;
37
+ get primaryKey(): string;
38
+ get timestamps(): boolean;
39
+ get fillable(): string[];
40
+ get relations(): RelationRepository;
41
+ get isDirty(): boolean;
42
+ get casts(): ModelSchemaAttributes['casts'];
43
+ exists: boolean;
44
+ getAttribute(key: string): unknown;
45
+ setAttribute(key: string, value: unknown): void;
46
+ getKey(): string | number;
47
+ getKeyName(): string;
48
+ fill(attributes: JsonObject): void;
49
+ toJson(): JsonObject;
50
+ diff(): JsonObject;
51
+ getType(): string;
52
+ dump(): void;
53
+ save(options?: ModelSaveOptions): Promise<AxiosResponse<unknown, unknown>>;
54
+ update(attributes: JsonObject): Promise<void>;
55
+ delete(): Promise<AxiosResponse<unknown, unknown>>;
56
+ forceDelete(): Promise<AxiosResponse<unknown, unknown>>;
57
+ restore(): Promise<AxiosResponse<unknown, unknown>>;
58
+ refresh(): Promise<void>;
59
+ relation(relationName: string): RelationInterface<Model, ModelPaginatedResponse> | undefined;
60
+ static getSchemaName(): string;
61
+ static getSchema(): ModelSchemaAttributes;
62
+ static query(): BuilderInterface<Model, ModelPaginatedResponse>;
63
+ static get(page?: number, replaceLinksWith?: string): Promise<ModelPaginatedResponse>;
64
+ static find(id: number | string): Promise<Model | null>;
65
+ static first(): Promise<Model | null>;
66
+ static where(scope: Scope<Model, ModelPaginatedResponse>): BuilderInterface<Model, ModelPaginatedResponse>;
67
+ static where(key: string, value: JsonValue): BuilderInterface<Model, ModelPaginatedResponse>;
68
+ static where(key: string, operator: ExtendedOperator, value: JsonValue): BuilderInterface<Model, ModelPaginatedResponse>;
69
+ static where(key: string | Scope<Model, ModelPaginatedResponse>, operatorOrValue?: ExtendedOperator | JsonValue, value?: JsonValue): BuilderInterface<Model, ModelPaginatedResponse>;
70
+ static whereNull(key: string): BuilderInterface<Model, ModelPaginatedResponse>;
71
+ static whereNotNull(key: string): BuilderInterface<Model, ModelPaginatedResponse>;
72
+ static whereBetween(key: string, value: [JsonValue, JsonValue]): BuilderInterface<Model, ModelPaginatedResponse>;
73
+ static whereNotBetween(key: string, value: [JsonValue, JsonValue]): BuilderInterface<Model, ModelPaginatedResponse>;
74
+ static orderBy(column: string, direction?: 'asc' | 'desc'): BuilderInterface<Model, ModelPaginatedResponse>;
75
+ static searchBy(term: string): BuilderInterface<Model, ModelPaginatedResponse>;
76
+ static minified(): BuilderInterface<Model, ModelPaginatedResponse>;
77
+ static limit(value: number): BuilderInterface<Model, ModelPaginatedResponse>;
78
+ static create(attributes: JsonObject): Promise<Model>;
79
+ static update(id: number | string, attributes: JsonObject): Promise<Model>;
80
+ static delete(id: number | string): Promise<AxiosResponse>;
81
+ static delete(ids: Array<number | string>): Promise<AxiosResponse>;
82
+ static restore(id: number | string): Promise<AxiosResponse>;
83
+ static restore(ids: Array<number | string>): Promise<AxiosResponse>;
84
+ static forceDelete(id: number | string): Promise<AxiosResponse>;
85
+ static forceDelete(ids: Array<number | string>): Promise<AxiosResponse>;
86
+ static singular(): string;
87
+ static plural(): string;
88
+ on: EventSource<ModelEvents>['on'];
89
+ once: EventSource<ModelEvents>['once'];
90
+ emit: EventSource<ModelEvents>['emit'];
91
+ }
92
+ export declare class Model extends BaseModel {
93
+ [key: string]: any;
94
+ [Symbol.toStringTag]: string;
95
+ }
96
+ export interface ModelSaveOptions {
97
+ additionalPayload?: object;
98
+ sendsOnlyModifiedFields?: boolean;
99
+ }
100
+ export type ModelFillCallback = (data: object) => void;
101
+ export type ModelJsonCallback = () => object;
102
+ export type ModelDiffCallback = () => object | false;
103
+ export type ModelSaveCallback = (options?: ModelSaveOptions) => Promise<boolean>;
104
+ export interface ModelTableColumnDefinition {
105
+ key: string;
106
+ label: string;
107
+ sortable?: boolean;
108
+ }
109
+ export interface ModelSchemaAttributes {
110
+ displayName: {
111
+ singular: string;
112
+ plural: string;
113
+ };
114
+ fillable: string[];
115
+ relations: Record<string, Omit<RelationMetaData, 'name'>>;
116
+ casts: Record<string, string>;
117
+ primaryKey: string;
118
+ timestamps: boolean;
119
+ labeledBy: string;
120
+ }
121
+ export interface RelationMetaData {
122
+ model: string;
123
+ type: 'HasOne' | 'HasMany' | 'BelongsTo' | 'BelongsToMany' | 'MorphOne' | 'MorphMany' | 'MorphTo' | 'MorphToMany' | 'MorphedByMany';
124
+ foreignKey: string | null;
125
+ name: string;
126
+ }
127
+ export interface ModelSchema {
128
+ [abstract: string]: ModelSchemaAttributes;
129
+ }
130
+ export type ModelQuery = JsonObject & {
131
+ q?: string;
132
+ page?: number;
133
+ per_page?: number;
134
+ order_by?: string;
135
+ where?: JsonObject;
136
+ tab?: string;
137
+ minified?: boolean;
138
+ };
139
+ export type ModelGetOptions = {
140
+ query?: ModelQuery;
141
+ linkBase?: string;
142
+ };
143
+ export type ModelPaginatedLink = {
144
+ url: string | null;
145
+ label: string;
146
+ active: boolean;
147
+ };
148
+ export type ModelPaginatedResponse = {
149
+ data: Collection<Model>;
150
+ links: {
151
+ first: string;
152
+ last: string;
153
+ prev: string | null;
154
+ next: string | null;
155
+ };
156
+ meta: {
157
+ current_page: number;
158
+ from: number;
159
+ last_page: number;
160
+ per_page: number;
161
+ to: number;
162
+ total: number;
163
+ links: Array<ModelPaginatedLink>;
164
+ };
165
+ };
@@ -0,0 +1,4 @@
1
+ export type PluginInterface<A, F> = {
2
+ register(app: A): void;
3
+ boot(facades: F): void;
4
+ };
@@ -0,0 +1,25 @@
1
+ import { Unsubscribe } from 'nanoevents';
2
+ import { Event } from './Event';
3
+
4
+ export type PropertyBagChangeEvent<T extends object> = Event<PropertyBag<T>> & {
5
+ path: string;
6
+ value: unknown;
7
+ type: 'set' | 'merge' | 'delete';
8
+ };
9
+ export type PropertyBagEventMap<T extends object = any> = {
10
+ 'change': (e: PropertyBagChangeEvent<T>) => void;
11
+ };
12
+ export type PropertyBag<T extends object> = {
13
+ get(path: string, defaultValue?: unknown): unknown;
14
+ set(path: string, value: unknown): void;
15
+ merge(path: string, value: unknown): void;
16
+ has(path: string): boolean;
17
+ delete(path: string): void;
18
+ lock(path: string): void;
19
+ clone(): PropertyBag<T>;
20
+ all(): T;
21
+ isEmpty(): boolean;
22
+ on<K extends keyof PropertyBagEventMap<T>>(event: K, callback: PropertyBagEventMap<T>[K]): Unsubscribe;
23
+ once<K extends keyof PropertyBagEventMap<T>>(event: K, callback: PropertyBagEventMap<T>[K]): void;
24
+ emit<K extends keyof PropertyBagEventMap<T>>(event: K, payload: Omit<Parameters<PropertyBagEventMap<T>[K]>[0], 'source'>): void;
25
+ };
@@ -0,0 +1,17 @@
1
+ import { Collection } from './Collection';
2
+
3
+ export type ReducerCallback = (value: any, ...params: any[]) => any;
4
+ export interface Reducer {
5
+ callback: ReducerCallback;
6
+ priority: number;
7
+ }
8
+ export type Unsubscribe = () => void;
9
+ export type ReducibleInterface = {
10
+ reducer(name: string, callback: ReducerCallback, priority?: number): Unsubscribe;
11
+ removeReducer(name: string, callback: ReducerCallback): void;
12
+ getReducer(name: string): Collection<Reducer>;
13
+ hasReducer(name: string): boolean;
14
+ clearReducer(name: string): void;
15
+ flushReducers(): void;
16
+ [reducer: string]: unknown;
17
+ };
@@ -0,0 +1,30 @@
1
+ import { BuilderInterface, ExtendedOperator, Scope } from './Builder';
2
+ import { Collection } from './Collection';
3
+ import { Constructor, JsonValue } from './Support';
4
+
5
+ export type { BuilderInterface, ExtendedOperator, Scope, };
6
+ export type RelationInterface<R, C> = {
7
+ guessInverseRelation(): string;
8
+ make(data: JsonValue): void;
9
+ set(items: R | Collection<R> | null): void;
10
+ getForeignKey(): string | null;
11
+ getName(): string;
12
+ getType(): string;
13
+ getModel(): string;
14
+ getRelated(): Constructor<R>;
15
+ isSingle(): boolean;
16
+ isMultiple(): boolean;
17
+ query(): BuilderInterface<R, C>;
18
+ isLoaded(): boolean;
19
+ getLoadedItems(): R | Collection<R> | null;
20
+ where(scope: Scope<R, C>): BuilderInterface<R, C>;
21
+ where(key: string, value: JsonValue): BuilderInterface<R, C>;
22
+ where(key: string, operator: ExtendedOperator, value: JsonValue): BuilderInterface<R, C>;
23
+ whereNull(key: string): BuilderInterface<R, C>;
24
+ whereNotNull(key: string): BuilderInterface<R, C>;
25
+ whereNotBetween(key: string, value: [JsonValue, JsonValue]): BuilderInterface<R, C>;
26
+ orderBy(column: string, direction?: 'asc' | 'desc'): BuilderInterface<R, C>;
27
+ searchBy(term: string): BuilderInterface<R, C>;
28
+ minified(): BuilderInterface<R, C>;
29
+ limit(value: number): BuilderInterface<R, C>;
30
+ };
@@ -0,0 +1,22 @@
1
+ import { AxiosRequestConfig, AxiosResponse } from 'axios';
2
+ import { ReducibleInterface } from './Reducer';
3
+
4
+ export type RouteReplacer = {
5
+ [key: string]: string | number;
6
+ };
7
+ export type RouteFacade = ReducibleInterface & {
8
+ get(name: string): RouteTuple;
9
+ url(generator: RouteGenerator): string;
10
+ exists(name: string): boolean;
11
+ call(generator: RouteGenerator, config?: RouteCallConfig): Promise<AxiosResponse>;
12
+ methods(generator: RouteGenerator): HttpMethod[];
13
+ };
14
+ export type RouteGenerator = string | [string, RouteReplacer];
15
+ export type HttpMethod = 'get' | 'post' | 'put' | 'patch' | 'delete';
16
+ export type RouteTuple = [string, ...HttpMethod[]];
17
+ export type RouteDefinition = {
18
+ [routeName: string]: RouteTuple | RouteDefinition;
19
+ };
20
+ export type RouteCallConfig = Omit<AxiosRequestConfig, 'url'> & {
21
+ errorBag?: string;
22
+ };
@@ -0,0 +1,7 @@
1
+ export type TypeOf = 'string' | 'number' | 'boolean' | 'object' | 'undefined' | 'function' | 'symbol' | 'bigint';
2
+ export type Constructor<T = {}> = new (...args: any[]) => T;
3
+ export type Operator = '=' | '!=' | '>' | '<' | '>=' | '<=';
4
+ export type JsonObject = {
5
+ [key: string]: JsonValue;
6
+ };
7
+ export type JsonValue = string | number | boolean | null | JsonObject | Array<string | number | boolean | null | JsonObject>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@luminix/core",
3
- "version": "0.0.1-beta.3",
3
+ "version": "0.0.1-beta.4",
4
4
  "description": "> Projeto em desenvolvimento",
5
5
  "main": "dist/core.js",
6
6
  "types": "dist/index.d.ts",
package/vite.config.js CHANGED
@@ -1,12 +1,12 @@
1
1
  import { defineConfig } from 'vite';
2
2
  import { resolve } from 'path';
3
3
 
4
- //import dts from 'vite-plugin-dts';
4
+ import dts from 'vite-plugin-dts';
5
5
 
6
6
  import packageJson from './package.json';
7
7
 
8
8
  export default defineConfig({
9
- //plugins: [dts({ insertTypesEntry: true })],
9
+ plugins: [dts({ insertTypesEntry: true })],
10
10
  build: {
11
11
  lib: {
12
12
  entry: resolve(__dirname, 'src/index.ts'),