@arcaelas/dynamite 1.0.17 → 1.0.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 +40 -2
- package/src/@types/index.d.ts +116 -75
- package/src/core/client.d.ts +36 -0
- package/src/core/client.js +80 -27
- package/src/core/decorator.d.ts +44 -0
- package/src/core/decorator.js +133 -0
- package/src/core/method.d.ts +73 -0
- package/src/core/method.js +140 -0
- package/src/core/table.d.ts +44 -86
- package/src/core/table.js +510 -310
- package/src/decorators/indexes.d.ts +38 -0
- package/src/decorators/indexes.js +67 -0
- package/src/decorators/relations.d.ts +55 -0
- package/src/decorators/relations.js +84 -0
- package/src/decorators/timestamps.d.ts +54 -0
- package/src/decorators/timestamps.js +67 -0
- package/src/decorators/transforms.d.ts +86 -0
- package/src/decorators/transforms.js +154 -0
- package/src/index.d.ts +10 -16
- package/src/index.js +50 -32
- package/src/index.test.d.ts +13 -0
- package/src/index.test.js +1992 -0
- package/src/utils/relations.d.ts +34 -12
- package/src/utils/relations.js +109 -133
- package/src/@types/index.js +0 -9
- package/src/core/wrapper.d.ts +0 -17
- package/src/core/wrapper.js +0 -46
- package/src/decorators/belongs_to.d.ts +0 -1
- package/src/decorators/belongs_to.js +0 -24
- package/src/decorators/created_at.d.ts +0 -1
- package/src/decorators/created_at.js +0 -11
- package/src/decorators/default.d.ts +0 -1
- package/src/decorators/default.js +0 -47
- package/src/decorators/has_many.d.ts +0 -1
- package/src/decorators/has_many.js +0 -24
- package/src/decorators/index.d.ts +0 -11
- package/src/decorators/index.js +0 -36
- package/src/decorators/index_sort.d.ts +0 -12
- package/src/decorators/index_sort.js +0 -43
- package/src/decorators/mutate.d.ts +0 -2
- package/src/decorators/mutate.js +0 -51
- package/src/decorators/name.d.ts +0 -1
- package/src/decorators/name.js +0 -28
- package/src/decorators/not_null.d.ts +0 -1
- package/src/decorators/not_null.js +0 -13
- package/src/decorators/primary_key.d.ts +0 -6
- package/src/decorators/primary_key.js +0 -30
- package/src/decorators/updated_at.d.ts +0 -12
- package/src/decorators/updated_at.js +0 -26
- package/src/decorators/validate.d.ts +0 -1
- package/src/decorators/validate.js +0 -53
- package/src/utils/batch-relations.d.ts +0 -14
- package/src/utils/batch-relations.js +0 -131
- package/src/utils/circular-detector.d.ts +0 -82
- package/src/utils/circular-detector.js +0 -212
- package/src/utils/memory-manager.d.ts +0 -42
- package/src/utils/memory-manager.js +0 -107
- package/src/utils/naming.d.ts +0 -8
- package/src/utils/naming.js +0 -18
- package/src/utils/projection.d.ts +0 -12
- package/src/utils/projection.js +0 -51
- package/src/utils/security-validator.d.ts +0 -49
- package/src/utils/security-validator.js +0 -163
- package/src/utils/throttle-manager.d.ts +0 -78
- package/src/utils/throttle-manager.js +0 -201
- package/src/utils/transaction-manager.d.ts +0 -88
- package/src/utils/transaction-manager.js +0 -300
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file method.ts
|
|
3
|
+
* @descripcion Sistema de métodos extensibles para Table
|
|
4
|
+
* @autor Miguel Alejandro
|
|
5
|
+
*/
|
|
6
|
+
/** Handler para métodos estáticos: (TableClass, args) => result */
|
|
7
|
+
export type StaticMethodHandler<R = any> = (table: any, args: any[]) => R | Promise<R>;
|
|
8
|
+
/** Handler para métodos de instancia: (TableClass, instance, args) => result */
|
|
9
|
+
export type InstanceMethodHandler<R = any> = (table: any, instance: any, args: any[]) => R | Promise<R>;
|
|
10
|
+
/**
|
|
11
|
+
* @description Configura la clase Table para el sistema de métodos
|
|
12
|
+
* @param TableClass Clase Table
|
|
13
|
+
*/
|
|
14
|
+
export declare function setTableClass(TableClass: any): void;
|
|
15
|
+
/**
|
|
16
|
+
* @description Registra un método estático en Table y lo define en la clase
|
|
17
|
+
* @param name Nombre del método
|
|
18
|
+
* @param handler Función que implementa el método
|
|
19
|
+
* @example
|
|
20
|
+
* ```typescript
|
|
21
|
+
* registerStaticMethod('customFind', function(t, args) {
|
|
22
|
+
* const meta = mustMeta(t);
|
|
23
|
+
* return instances;
|
|
24
|
+
* });
|
|
25
|
+
* // Uso: User.customFind(...)
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
28
|
+
export declare function registerStaticMethod<R = any>(name: string, handler: StaticMethodHandler<R>): void;
|
|
29
|
+
/**
|
|
30
|
+
* @description Registra un método de instancia en Table y lo define en el prototype
|
|
31
|
+
* @param name Nombre del método
|
|
32
|
+
* @param handler Función que implementa el método
|
|
33
|
+
* @example
|
|
34
|
+
* ```typescript
|
|
35
|
+
* registerInstanceMethod('duplicate', function(t, m, args) {
|
|
36
|
+
* return t.create({ ...m.toJSON(), id: undefined });
|
|
37
|
+
* });
|
|
38
|
+
* // Uso: user.duplicate()
|
|
39
|
+
* ```
|
|
40
|
+
*/
|
|
41
|
+
export declare function registerInstanceMethod<R = any>(name: string, handler: InstanceMethodHandler<R>): void;
|
|
42
|
+
/**
|
|
43
|
+
* @description Obtiene un método estático registrado
|
|
44
|
+
*/
|
|
45
|
+
export declare function getStaticMethod(name: string): StaticMethodHandler | undefined;
|
|
46
|
+
/**
|
|
47
|
+
* @description Obtiene un método de instancia registrado
|
|
48
|
+
*/
|
|
49
|
+
export declare function getInstanceMethod(name: string): InstanceMethodHandler | undefined;
|
|
50
|
+
/**
|
|
51
|
+
* @description Ejecuta un método estático registrado
|
|
52
|
+
*/
|
|
53
|
+
export declare function callStaticMethod<R = any>(name: string, table: any, args: any[]): R | Promise<R>;
|
|
54
|
+
/**
|
|
55
|
+
* @description Ejecuta un método de instancia registrado
|
|
56
|
+
*/
|
|
57
|
+
export declare function callInstanceMethod<R = any>(name: string, table: any, instance: any, args: any[]): R | Promise<R>;
|
|
58
|
+
/**
|
|
59
|
+
* @description Verifica si un método estático está registrado
|
|
60
|
+
*/
|
|
61
|
+
export declare function hasStaticMethod(name: string): boolean;
|
|
62
|
+
/**
|
|
63
|
+
* @description Verifica si un método de instancia está registrado
|
|
64
|
+
*/
|
|
65
|
+
export declare function hasInstanceMethod(name: string): boolean;
|
|
66
|
+
/**
|
|
67
|
+
* @description Lista todos los métodos estáticos registrados
|
|
68
|
+
*/
|
|
69
|
+
export declare function listStaticMethods(): string[];
|
|
70
|
+
/**
|
|
71
|
+
* @description Lista todos los métodos de instancia registrados
|
|
72
|
+
*/
|
|
73
|
+
export declare function listInstanceMethods(): string[];
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @file method.ts
|
|
4
|
+
* @descripcion Sistema de métodos extensibles para Table
|
|
5
|
+
* @autor Miguel Alejandro
|
|
6
|
+
*/
|
|
7
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
+
exports.setTableClass = setTableClass;
|
|
9
|
+
exports.registerStaticMethod = registerStaticMethod;
|
|
10
|
+
exports.registerInstanceMethod = registerInstanceMethod;
|
|
11
|
+
exports.getStaticMethod = getStaticMethod;
|
|
12
|
+
exports.getInstanceMethod = getInstanceMethod;
|
|
13
|
+
exports.callStaticMethod = callStaticMethod;
|
|
14
|
+
exports.callInstanceMethod = callInstanceMethod;
|
|
15
|
+
exports.hasStaticMethod = hasStaticMethod;
|
|
16
|
+
exports.hasInstanceMethod = hasInstanceMethod;
|
|
17
|
+
exports.listStaticMethods = listStaticMethods;
|
|
18
|
+
exports.listInstanceMethods = listInstanceMethods;
|
|
19
|
+
/** Registro de métodos estáticos */
|
|
20
|
+
const static_methods = new Map();
|
|
21
|
+
/** Registro de métodos de instancia */
|
|
22
|
+
const instance_methods = new Map();
|
|
23
|
+
/** Referencia a la clase Table para definir propiedades */
|
|
24
|
+
let table_class = null;
|
|
25
|
+
/**
|
|
26
|
+
* @description Configura la clase Table para el sistema de métodos
|
|
27
|
+
* @param TableClass Clase Table
|
|
28
|
+
*/
|
|
29
|
+
function setTableClass(TableClass) {
|
|
30
|
+
table_class = TableClass;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* @description Registra un método estático en Table y lo define en la clase
|
|
34
|
+
* @param name Nombre del método
|
|
35
|
+
* @param handler Función que implementa el método
|
|
36
|
+
* @example
|
|
37
|
+
* ```typescript
|
|
38
|
+
* registerStaticMethod('customFind', function(t, args) {
|
|
39
|
+
* const meta = mustMeta(t);
|
|
40
|
+
* return instances;
|
|
41
|
+
* });
|
|
42
|
+
* // Uso: User.customFind(...)
|
|
43
|
+
* ```
|
|
44
|
+
*/
|
|
45
|
+
function registerStaticMethod(name, handler) {
|
|
46
|
+
static_methods.set(name, handler);
|
|
47
|
+
// Definir método en la clase Table si está configurada
|
|
48
|
+
if (table_class && !Object.prototype.hasOwnProperty.call(table_class, name)) {
|
|
49
|
+
Object.defineProperty(table_class, name, {
|
|
50
|
+
value: function (...args) {
|
|
51
|
+
return callStaticMethod(name, this, args);
|
|
52
|
+
},
|
|
53
|
+
writable: true,
|
|
54
|
+
configurable: true,
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* @description Registra un método de instancia en Table y lo define en el prototype
|
|
60
|
+
* @param name Nombre del método
|
|
61
|
+
* @param handler Función que implementa el método
|
|
62
|
+
* @example
|
|
63
|
+
* ```typescript
|
|
64
|
+
* registerInstanceMethod('duplicate', function(t, m, args) {
|
|
65
|
+
* return t.create({ ...m.toJSON(), id: undefined });
|
|
66
|
+
* });
|
|
67
|
+
* // Uso: user.duplicate()
|
|
68
|
+
* ```
|
|
69
|
+
*/
|
|
70
|
+
function registerInstanceMethod(name, handler) {
|
|
71
|
+
instance_methods.set(name, handler);
|
|
72
|
+
// Definir método en el prototype de Table si está configurado
|
|
73
|
+
if (table_class &&
|
|
74
|
+
!Object.prototype.hasOwnProperty.call(table_class.prototype, name)) {
|
|
75
|
+
Object.defineProperty(table_class.prototype, name, {
|
|
76
|
+
value: function (...args) {
|
|
77
|
+
return callInstanceMethod(name, this.constructor, this, args);
|
|
78
|
+
},
|
|
79
|
+
writable: true,
|
|
80
|
+
configurable: true,
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* @description Obtiene un método estático registrado
|
|
86
|
+
*/
|
|
87
|
+
function getStaticMethod(name) {
|
|
88
|
+
return static_methods.get(name);
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* @description Obtiene un método de instancia registrado
|
|
92
|
+
*/
|
|
93
|
+
function getInstanceMethod(name) {
|
|
94
|
+
return instance_methods.get(name);
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* @description Ejecuta un método estático registrado
|
|
98
|
+
*/
|
|
99
|
+
function callStaticMethod(name, table, args) {
|
|
100
|
+
const handler = static_methods.get(name);
|
|
101
|
+
if (!handler) {
|
|
102
|
+
throw new Error(`Método estático '${name}' no registrado`);
|
|
103
|
+
}
|
|
104
|
+
return handler(table, args);
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* @description Ejecuta un método de instancia registrado
|
|
108
|
+
*/
|
|
109
|
+
function callInstanceMethod(name, table, instance, args) {
|
|
110
|
+
const handler = instance_methods.get(name);
|
|
111
|
+
if (!handler) {
|
|
112
|
+
throw new Error(`Método de instancia '${name}' no registrado`);
|
|
113
|
+
}
|
|
114
|
+
return handler(table, instance, args);
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* @description Verifica si un método estático está registrado
|
|
118
|
+
*/
|
|
119
|
+
function hasStaticMethod(name) {
|
|
120
|
+
return static_methods.has(name);
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* @description Verifica si un método de instancia está registrado
|
|
124
|
+
*/
|
|
125
|
+
function hasInstanceMethod(name) {
|
|
126
|
+
return instance_methods.has(name);
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* @description Lista todos los métodos estáticos registrados
|
|
130
|
+
*/
|
|
131
|
+
function listStaticMethods() {
|
|
132
|
+
return Array.from(static_methods.keys());
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* @description Lista todos los métodos de instancia registrados
|
|
136
|
+
*/
|
|
137
|
+
function listInstanceMethods() {
|
|
138
|
+
return Array.from(instance_methods.keys());
|
|
139
|
+
}
|
|
140
|
+
//# sourceMappingURL=method.js.map
|
package/src/core/table.d.ts
CHANGED
|
@@ -1,98 +1,56 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @file table.ts
|
|
3
|
-
* @
|
|
3
|
+
* @description Tabla autocontenida con arquitectura minimalista y Symbol storage
|
|
4
4
|
* @autor Miguel Alejandro
|
|
5
|
-
* @fecha 2025-
|
|
5
|
+
* @fecha 2025-01-28
|
|
6
6
|
*/
|
|
7
|
-
import
|
|
8
|
-
import {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
7
|
+
import { TransactionContext } from "./client";
|
|
8
|
+
import { VALUES } from "./decorator";
|
|
9
|
+
interface QueryOptions<T> {
|
|
10
|
+
order?: 'ASC' | 'DESC';
|
|
11
|
+
skip?: number;
|
|
12
|
+
limit?: number;
|
|
13
|
+
attributes?: (keyof T)[];
|
|
14
|
+
include?: IncludeRelationOptions;
|
|
15
|
+
_includeTrashed?: boolean;
|
|
16
|
+
}
|
|
17
|
+
interface IncludeRelationOptions {
|
|
18
|
+
[relationName: string]: boolean | {
|
|
19
|
+
where?: any;
|
|
20
|
+
limit?: number;
|
|
12
21
|
};
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
/** Actualizar instancia */
|
|
19
|
-
update(patch: Partial<InferAttributes<T>>): Promise<this>;
|
|
20
|
-
/** Eliminar instancia */
|
|
21
|
-
destroy(): Promise<null>;
|
|
22
|
-
/**
|
|
23
|
-
* Crear un nuevo registro en la base de datos
|
|
24
|
-
*/
|
|
25
|
-
static create<M extends Table>(this: {
|
|
26
|
-
new (data: InferAttributes<M>): M;
|
|
27
|
-
prototype: M;
|
|
28
|
-
}, data: InferAttributes<M>): Promise<M>;
|
|
29
|
-
/**
|
|
30
|
-
* Actualizar registros en la base de datos
|
|
31
|
-
* @param updates - Campos a actualizar. Los campos con valor `undefined` se ignoran.
|
|
32
|
-
* @param filters - Filtros para seleccionar los registros a actualizar
|
|
33
|
-
* @returns Número de registros actualizados
|
|
34
|
-
*/
|
|
35
|
-
static update<M extends Table>(this: {
|
|
36
|
-
new (data: InferAttributes<M>): M;
|
|
37
|
-
prototype: M;
|
|
38
|
-
}, updates: Partial<InferAttributes<M>>, filters: Partial<InferAttributes<M>>): Promise<number>;
|
|
22
|
+
}
|
|
23
|
+
type QueryOperator = "=" | "!=" | "<" | "<=" | ">" | ">=" | "in" | "not-in" | "contains" | "begins-with";
|
|
24
|
+
export default class Table<T = any> {
|
|
25
|
+
private readonly [VALUES];
|
|
26
|
+
constructor(props?: Partial<T>);
|
|
39
27
|
/**
|
|
40
|
-
*
|
|
28
|
+
* @description Serializa la instancia a JSON incluyendo relaciones recursivamente
|
|
29
|
+
* @returns Objeto JSON con todas las propiedades y relaciones
|
|
41
30
|
*/
|
|
42
|
-
|
|
43
|
-
new (data: InferAttributes<M>): M;
|
|
44
|
-
prototype: M;
|
|
45
|
-
}, filters: Partial<InferAttributes<M>>): Promise<number>;
|
|
46
|
-
/** Filtrar registros por campo igual a valor */
|
|
47
|
-
static where<M extends Table, K extends keyof InferAttributes<M>>(this: {
|
|
48
|
-
new (data: InferAttributes<M>): M;
|
|
49
|
-
prototype: M;
|
|
50
|
-
}, field: K, value: InferAttributes<M>[K] | InferAttributes<M>[K][]): Promise<M[]>;
|
|
51
|
-
/** Filtrar registros por campo con operador específico */
|
|
52
|
-
static where<M extends Table, K extends keyof InferAttributes<M>>(this: {
|
|
53
|
-
new (data: InferAttributes<M>): M;
|
|
54
|
-
prototype: M;
|
|
55
|
-
}, field: K, operator: QueryOperator, value: InferAttributes<M>[K] | InferAttributes<M>[K][]): Promise<M[]>;
|
|
56
|
-
/** Filtrar registros por múltiples campos (AND) */
|
|
57
|
-
static where<M extends Table>(this: {
|
|
58
|
-
new (data: InferAttributes<M>): M;
|
|
59
|
-
prototype: M;
|
|
60
|
-
}, filters: Partial<InferAttributes<M>>): Promise<M[]>;
|
|
61
|
-
/** Filtrar registros con opciones avanzadas */
|
|
62
|
-
static where<M extends Table>(this: {
|
|
63
|
-
new (data: InferAttributes<M>): M;
|
|
64
|
-
prototype: M;
|
|
65
|
-
}, filters: Partial<InferAttributes<M>>, options: WhereQueryOptions<M>): Promise<M[]>;
|
|
31
|
+
toJSON(): Record<string, unknown>;
|
|
66
32
|
/**
|
|
67
|
-
*
|
|
33
|
+
* @description Serializa la instancia a string JSON
|
|
34
|
+
* @returns String JSON con todas las propiedades y relaciones
|
|
68
35
|
*/
|
|
69
|
-
|
|
70
|
-
new (data: InferAttributes<M>): M;
|
|
71
|
-
prototype: M;
|
|
72
|
-
}, field: K, value: InferAttributes<M>[K]): Promise<M | undefined>;
|
|
73
|
-
static first<M extends Table, K extends keyof InferAttributes<M>>(this: {
|
|
74
|
-
new (data: InferAttributes<M>): M;
|
|
75
|
-
prototype: M;
|
|
76
|
-
}, field: K, operator: QueryOperator, value: InferAttributes<M>[K] | InferAttributes<M>[K][]): Promise<M | undefined>;
|
|
77
|
-
static first<M extends Table>(this: {
|
|
78
|
-
new (data: InferAttributes<M>): M;
|
|
79
|
-
prototype: M;
|
|
80
|
-
}, filters: Partial<InferAttributes<M>>): Promise<M | undefined>;
|
|
36
|
+
toString(): string;
|
|
81
37
|
/**
|
|
82
|
-
*
|
|
38
|
+
* @description Genera payload para operaciones de DB (excluye relaciones)
|
|
83
39
|
*/
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
static
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
static
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
40
|
+
private _toDBPayload;
|
|
41
|
+
save(): Promise<this>;
|
|
42
|
+
destroy(): Promise<null>;
|
|
43
|
+
forceDestroy(): Promise<null>;
|
|
44
|
+
static create<T extends Table>(this: new (data: any) => T, data: any, tx?: TransactionContext): Promise<T>;
|
|
45
|
+
static update<T extends Table>(this: new (data: any) => T, updates: any, filters: any, tx?: TransactionContext): Promise<number>;
|
|
46
|
+
static delete<T extends Table>(this: new (data: any) => T, filters: any, tx?: TransactionContext): Promise<number>;
|
|
47
|
+
static where<T extends Table>(this: new (props?: any) => T, field_or_filters: any, operator_or_value?: any, value?: any, options?: QueryOptions<T>): Promise<T[]>;
|
|
48
|
+
static first<T extends Table>(this: new (props?: any) => T, field_or_filters: any, operator_or_value?: any, value_or_options?: any): Promise<T | undefined>;
|
|
49
|
+
static last<T extends Table>(this: new (props?: any) => T, field_or_filters?: any, operator_or_value?: any): Promise<T | undefined>;
|
|
50
|
+
static withTrashed<T extends Table>(this: new (props?: any) => T, filters?: any, options?: QueryOptions<T>): Promise<T[]>;
|
|
51
|
+
static onlyTrashed<T extends Table>(this: new (props?: any) => T, filters?: any, options?: QueryOptions<T>): Promise<T[]>;
|
|
52
|
+
private insertIntoDynamoDB;
|
|
53
|
+
private updateInDynamoDB;
|
|
54
|
+
private deleteFromDynamoDB;
|
|
96
55
|
}
|
|
97
|
-
export {
|
|
98
|
-
export type { WrapperEntry };
|
|
56
|
+
export type { QueryOptions, IncludeRelationOptions, QueryOperator };
|