@arcaelas/dynamite 1.0.13 → 1.0.14
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/README.md +1165 -152
- package/package.json +6 -9
- package/LICENSE.txt +0 -32
- package/README.txt +0 -206
- package/SECURITY.md +0 -41
- package/src/@types/index.d.ts +0 -96
- package/src/@types/index.js +0 -9
- package/src/core/client.d.ts +0 -69
- package/src/core/client.js +0 -164
- package/src/core/table.d.ts +0 -98
- package/src/core/table.js +0 -459
- 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/index.d.ts +0 -22
- package/src/index.js +0 -47
- 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 -209
- package/src/utils/memory-manager.d.ts +0 -42
- package/src/utils/memory-manager.js +0 -108
- 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/relations.d.ts +0 -17
- package/src/utils/relations.js +0 -166
- package/src/utils/security-validator.d.ts +0 -49
- package/src/utils/security-validator.js +0 -152
- package/src/utils/throttle-manager.d.ts +0 -78
- package/src/utils/throttle-manager.js +0 -196
- package/src/utils/transaction-manager.d.ts +0 -88
- package/src/utils/transaction-manager.js +0 -298
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.default = Default;
|
|
4
|
-
const wrapper_1 = require("../core/wrapper");
|
|
5
|
-
const naming_1 = require("../utils/naming");
|
|
6
|
-
function Default(factory) {
|
|
7
|
-
return (target, prop) => {
|
|
8
|
-
const ctor = target.constructor;
|
|
9
|
-
const entry = (0, wrapper_1.ensureConfig)(ctor, (0, naming_1.toSnakePlural)(ctor.name));
|
|
10
|
-
const column = (0, wrapper_1.ensureColumn)(entry, prop, String(prop));
|
|
11
|
-
if (column.default)
|
|
12
|
-
throw new Error(`@Default duplicado en '${String(prop)}'`);
|
|
13
|
-
column.default = typeof factory === "function" ? factory : () => factory;
|
|
14
|
-
!Object.getOwnPropertyDescriptor(ctor.prototype, prop)?.set &&
|
|
15
|
-
defineVirtual(ctor.prototype, column, prop);
|
|
16
|
-
};
|
|
17
|
-
}
|
|
18
|
-
function defineVirtual(proto, col, prop) {
|
|
19
|
-
Object.defineProperty(proto, prop, {
|
|
20
|
-
get() {
|
|
21
|
-
return (this[wrapper_1.STORE] ?? {})[prop];
|
|
22
|
-
},
|
|
23
|
-
set(val) {
|
|
24
|
-
const buf = (this[wrapper_1.STORE] ??= {});
|
|
25
|
-
val =
|
|
26
|
-
val === undefined && col.default !== undefined
|
|
27
|
-
? typeof col.default === "function"
|
|
28
|
-
? col.default()
|
|
29
|
-
: col.default
|
|
30
|
-
: val;
|
|
31
|
-
if (col.mutate)
|
|
32
|
-
for (const m of col.mutate)
|
|
33
|
-
val = m(val);
|
|
34
|
-
if (col.validate) {
|
|
35
|
-
for (const v of col.validate) {
|
|
36
|
-
const r = v(val);
|
|
37
|
-
if (r !== true)
|
|
38
|
-
throw new Error(typeof r === "string" ? r : "Validación fallida");
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
buf[prop] = val;
|
|
42
|
-
},
|
|
43
|
-
enumerable: true,
|
|
44
|
-
configurable: true,
|
|
45
|
-
});
|
|
46
|
-
}
|
|
47
|
-
//# sourceMappingURL=default.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export default function HasMany(targetModel: () => any, foreignKey: string, localKey?: string): PropertyDecorator;
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.default = HasMany;
|
|
4
|
-
const wrapper_1 = require("../core/wrapper");
|
|
5
|
-
function HasMany(targetModel, foreignKey, localKey) {
|
|
6
|
-
return (target, prop) => {
|
|
7
|
-
const entry = (0, wrapper_1.ensureConfig)(target.constructor, target.constructor.name);
|
|
8
|
-
entry.relations.set(prop, {
|
|
9
|
-
type: "hasMany",
|
|
10
|
-
targetModel,
|
|
11
|
-
foreignKey,
|
|
12
|
-
localKey: localKey || "id",
|
|
13
|
-
});
|
|
14
|
-
// Crear getter dinámico para la relación
|
|
15
|
-
Object.defineProperty(target, prop, {
|
|
16
|
-
get() {
|
|
17
|
-
return this[`_${prop.toString()}`] || [];
|
|
18
|
-
},
|
|
19
|
-
enumerable: true,
|
|
20
|
-
configurable: true,
|
|
21
|
-
});
|
|
22
|
-
};
|
|
23
|
-
}
|
|
24
|
-
//# sourceMappingURL=has_many.js.map
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @file index.ts
|
|
3
|
-
* @descripcion Decorador @Index para Partition Key
|
|
4
|
-
* @autor Miguel Alejandro
|
|
5
|
-
* @fecha 2025-01-27
|
|
6
|
-
*/
|
|
7
|
-
/**
|
|
8
|
-
* Decorador para marcar propiedad como Partition Key.
|
|
9
|
-
* Configura la propiedad como índice principal para consultas.
|
|
10
|
-
*/
|
|
11
|
-
export default function Index(): PropertyDecorator;
|
package/src/decorators/index.js
DELETED
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* @file index.ts
|
|
4
|
-
* @descripcion Decorador @Index para Partition Key
|
|
5
|
-
* @autor Miguel Alejandro
|
|
6
|
-
* @fecha 2025-01-27
|
|
7
|
-
*/
|
|
8
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
-
exports.default = Index;
|
|
10
|
-
const wrapper_1 = require("../core/wrapper");
|
|
11
|
-
const naming_1 = require("../utils/naming");
|
|
12
|
-
/**
|
|
13
|
-
* Decorador para marcar propiedad como Partition Key.
|
|
14
|
-
* Configura la propiedad como índice principal para consultas.
|
|
15
|
-
*/
|
|
16
|
-
function Index() {
|
|
17
|
-
return (target, prop) => {
|
|
18
|
-
const ctor = target.constructor;
|
|
19
|
-
const tableName = (0, naming_1.toSnakePlural)(ctor.name);
|
|
20
|
-
const entry = (0, wrapper_1.ensureConfig)(ctor, tableName);
|
|
21
|
-
// Verificar si ya existe un índice primario
|
|
22
|
-
const existingIndex = [...entry.columns.values()].find((col) => col.index === true);
|
|
23
|
-
if (existingIndex && existingIndex.name !== String(prop)) {
|
|
24
|
-
throw new Error(`La tabla ${tableName} ya tiene definida una PartitionKey (${existingIndex.name}). ` +
|
|
25
|
-
`No se puede definir otra PartitionKey en '${String(prop)}'`);
|
|
26
|
-
}
|
|
27
|
-
// Obtener o crear la columna y marcar como índice
|
|
28
|
-
const column = (0, wrapper_1.ensureColumn)(entry, prop, String(prop));
|
|
29
|
-
column.index = true;
|
|
30
|
-
// Asegurar que la columna no sea nula por defecto
|
|
31
|
-
if (column.nullable === undefined) {
|
|
32
|
-
column.nullable = false;
|
|
33
|
-
}
|
|
34
|
-
};
|
|
35
|
-
}
|
|
36
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @file index_sort.ts
|
|
3
|
-
* @descripcion Decorador @IndexSort para Sort Key
|
|
4
|
-
* @autor Miguel Alejandro
|
|
5
|
-
* @fecha 2025-01-27
|
|
6
|
-
*/
|
|
7
|
-
/**
|
|
8
|
-
* Decorador para marcar propiedad como Sort Key.
|
|
9
|
-
* Configura la propiedad como clave de ordenación para consultas.
|
|
10
|
-
* Requiere que exista una PartitionKey (@Index) definida previamente.
|
|
11
|
-
*/
|
|
12
|
-
export default function IndexSort(): PropertyDecorator;
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* @file index_sort.ts
|
|
4
|
-
* @descripcion Decorador @IndexSort para Sort Key
|
|
5
|
-
* @autor Miguel Alejandro
|
|
6
|
-
* @fecha 2025-01-27
|
|
7
|
-
*/
|
|
8
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
-
exports.default = IndexSort;
|
|
10
|
-
const wrapper_1 = require("../core/wrapper");
|
|
11
|
-
const naming_1 = require("../utils/naming");
|
|
12
|
-
/**
|
|
13
|
-
* Decorador para marcar propiedad como Sort Key.
|
|
14
|
-
* Configura la propiedad como clave de ordenación para consultas.
|
|
15
|
-
* Requiere que exista una PartitionKey (@Index) definida previamente.
|
|
16
|
-
*/
|
|
17
|
-
function IndexSort() {
|
|
18
|
-
return (target, prop) => {
|
|
19
|
-
const ctor = target.constructor;
|
|
20
|
-
const tableName = (0, naming_1.toSnakePlural)(ctor.name);
|
|
21
|
-
const entry = (0, wrapper_1.ensureConfig)(ctor, tableName);
|
|
22
|
-
// Verificar que exista una PartitionKey definida
|
|
23
|
-
const hasPartitionKey = [...entry.columns.values()].some((col) => col.index === true);
|
|
24
|
-
if (!hasPartitionKey) {
|
|
25
|
-
throw new Error(`No se puede definir una SortKey en '${String(prop)}' sin una PartitionKey. ` +
|
|
26
|
-
`Asegúrate de marcar una propiedad con @Index primero.`);
|
|
27
|
-
}
|
|
28
|
-
// Verificar si ya existe una SortKey
|
|
29
|
-
const existingSortKey = [...entry.columns.values()].find((col) => col.indexSort === true);
|
|
30
|
-
if (existingSortKey && existingSortKey.name !== String(prop)) {
|
|
31
|
-
throw new Error(`La tabla ${tableName} ya tiene una SortKey definida (${existingSortKey.name}). ` +
|
|
32
|
-
`No se puede definir otra SortKey en '${String(prop)}'`);
|
|
33
|
-
}
|
|
34
|
-
// Obtener o crear la columna y marcar como índice de ordenación
|
|
35
|
-
const column = (0, wrapper_1.ensureColumn)(entry, prop, String(prop));
|
|
36
|
-
column.indexSort = true;
|
|
37
|
-
// Asegurar que la columna no sea nula por defecto
|
|
38
|
-
if (column.nullable === undefined) {
|
|
39
|
-
column.nullable = false;
|
|
40
|
-
}
|
|
41
|
-
};
|
|
42
|
-
}
|
|
43
|
-
//# sourceMappingURL=index_sort.js.map
|
package/src/decorators/mutate.js
DELETED
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.default = Mutate;
|
|
4
|
-
const wrapper_1 = require("../core/wrapper");
|
|
5
|
-
const naming_1 = require("../utils/naming");
|
|
6
|
-
function Mutate(fn) {
|
|
7
|
-
if (typeof fn !== "function")
|
|
8
|
-
throw new TypeError("@Mutate requiere función");
|
|
9
|
-
return (target, prop) => {
|
|
10
|
-
const ctor = target.constructor;
|
|
11
|
-
const entry = (0, wrapper_1.ensureConfig)(ctor, (0, naming_1.toSnakePlural)(ctor.name));
|
|
12
|
-
const col = (0, wrapper_1.ensureColumn)(entry, prop, String(prop));
|
|
13
|
-
col.mutate ??= [];
|
|
14
|
-
col.mutate.push(fn);
|
|
15
|
-
!Object.getOwnPropertyDescriptor(ctor.prototype, prop)?.set &&
|
|
16
|
-
defineVirtual(ctor.prototype, col, prop);
|
|
17
|
-
};
|
|
18
|
-
}
|
|
19
|
-
/** Define propiedad virtual con getter/setter para manejo de mutaciones */
|
|
20
|
-
function defineVirtual(proto, col, prop) {
|
|
21
|
-
Object.defineProperty(proto, prop, {
|
|
22
|
-
get() {
|
|
23
|
-
return (this[wrapper_1.STORE] ?? {})[prop];
|
|
24
|
-
},
|
|
25
|
-
set(val) {
|
|
26
|
-
const buf = (this[wrapper_1.STORE] ??= {});
|
|
27
|
-
val =
|
|
28
|
-
val === undefined && col.default !== undefined
|
|
29
|
-
? typeof col.default === "function"
|
|
30
|
-
? col.default()
|
|
31
|
-
: col.default
|
|
32
|
-
: val;
|
|
33
|
-
if (col.mutate)
|
|
34
|
-
for (const m of col.mutate)
|
|
35
|
-
val = m(val);
|
|
36
|
-
if (col.validate) {
|
|
37
|
-
for (const v of col.validate) {
|
|
38
|
-
const r = v(val);
|
|
39
|
-
r !== true &&
|
|
40
|
-
(() => {
|
|
41
|
-
throw new Error(typeof r === "string" ? r : "Validación fallida");
|
|
42
|
-
})();
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
buf[prop] = val;
|
|
46
|
-
},
|
|
47
|
-
enumerable: true,
|
|
48
|
-
configurable: true,
|
|
49
|
-
});
|
|
50
|
-
}
|
|
51
|
-
//# sourceMappingURL=mutate.js.map
|
package/src/decorators/name.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export default function Name(label: string): ClassDecorator & PropertyDecorator;
|
package/src/decorators/name.js
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.default = Name;
|
|
4
|
-
const wrapper_1 = require("../core/wrapper");
|
|
5
|
-
const naming_1 = require("../utils/naming");
|
|
6
|
-
function Name(label) {
|
|
7
|
-
if (!label || typeof label !== "string")
|
|
8
|
-
throw new TypeError("@Name requiere una cadena no vacía");
|
|
9
|
-
return (target, prop) => {
|
|
10
|
-
const ctor = prop === undefined ? target : target.constructor;
|
|
11
|
-
const entry = (0, wrapper_1.ensureConfig)(ctor, (0, naming_1.toSnakePlural)(ctor.name));
|
|
12
|
-
if (prop === undefined) {
|
|
13
|
-
const auto = (0, naming_1.toSnakePlural)(ctor.name);
|
|
14
|
-
if (entry.name !== auto && entry.name !== label && entry.name) {
|
|
15
|
-
throw new Error(`La clase ${ctor.name} ya tiene un @Name distinto (${entry.name})`);
|
|
16
|
-
}
|
|
17
|
-
entry.name = label;
|
|
18
|
-
}
|
|
19
|
-
else {
|
|
20
|
-
const col = (0, wrapper_1.ensureColumn)(entry, prop, label);
|
|
21
|
-
if (col.name && col.name !== label) {
|
|
22
|
-
throw new Error(`La columna '${String(prop)}' ya tiene @Name distinto (${col.name})`);
|
|
23
|
-
}
|
|
24
|
-
col.name = label;
|
|
25
|
-
}
|
|
26
|
-
};
|
|
27
|
-
}
|
|
28
|
-
//# sourceMappingURL=name.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export default function NotNull(): PropertyDecorator;
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.default = NotNull;
|
|
7
|
-
const validate_1 = __importDefault(require("./validate"));
|
|
8
|
-
function NotNull() {
|
|
9
|
-
return validate_1.default((value) => value !== null &&
|
|
10
|
-
value !== undefined &&
|
|
11
|
-
(typeof value !== "string" || value.trim() !== ""));
|
|
12
|
-
}
|
|
13
|
-
//# sourceMappingURL=not_null.js.map
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Decorador para marcar una propiedad como clave primaria.
|
|
3
|
-
* Aplica automáticamente @Index y @IndexSort y marca el campo como primaryKey en los metadatos.
|
|
4
|
-
* @param name - Nombre opcional para el índice (no utilizado actualmente, mantenido por compatibilidad)
|
|
5
|
-
*/
|
|
6
|
-
export default function PrimaryKey(name?: string): PropertyDecorator;
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.default = PrimaryKey;
|
|
7
|
-
const wrapper_1 = require("../core/wrapper");
|
|
8
|
-
const naming_1 = require("../utils/naming");
|
|
9
|
-
const index_1 = __importDefault(require("./index"));
|
|
10
|
-
const index_sort_1 = __importDefault(require("./index_sort"));
|
|
11
|
-
/**
|
|
12
|
-
* Decorador para marcar una propiedad como clave primaria.
|
|
13
|
-
* Aplica automáticamente @Index y @IndexSort y marca el campo como primaryKey en los metadatos.
|
|
14
|
-
* @param name - Nombre opcional para el índice (no utilizado actualmente, mantenido por compatibilidad)
|
|
15
|
-
*/
|
|
16
|
-
function PrimaryKey(name = "primary") {
|
|
17
|
-
return (target, prop) => {
|
|
18
|
-
// Aplicar decoradores de índice
|
|
19
|
-
(0, index_1.default)()(target, prop);
|
|
20
|
-
(0, index_sort_1.default)()(target, prop);
|
|
21
|
-
// Marcar explícitamente como clave primaria en los metadatos
|
|
22
|
-
const ctor = target.constructor;
|
|
23
|
-
const entry = (0, wrapper_1.ensureConfig)(ctor, (0, naming_1.toSnakePlural)(ctor.name));
|
|
24
|
-
const column = (0, wrapper_1.ensureColumn)(entry, prop, String(prop));
|
|
25
|
-
// Establecer metadatos adicionales para clave primaria
|
|
26
|
-
column.primaryKey = true;
|
|
27
|
-
column.nullable = false; // Las claves primarias no pueden ser nulas
|
|
28
|
-
};
|
|
29
|
-
}
|
|
30
|
-
//# sourceMappingURL=primary_key.js.map
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Decorador que marca una propiedad para que se actualice automáticamente con la fecha/hora actual
|
|
3
|
-
* cada vez que se guarde el modelo.
|
|
4
|
-
*
|
|
5
|
-
* @example
|
|
6
|
-
* class User extends Table<User> {
|
|
7
|
-
* @PrimaryKey() id: string;
|
|
8
|
-
* name: string;
|
|
9
|
-
* @UpdatedAt() updated_at: string;
|
|
10
|
-
* }
|
|
11
|
-
*/
|
|
12
|
-
export default function UpdatedAt(): (target: any, propertyKey: string | symbol) => void;
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.default = UpdatedAt;
|
|
4
|
-
const wrapper_1 = require("../core/wrapper");
|
|
5
|
-
/**
|
|
6
|
-
* Decorador que marca una propiedad para que se actualice automáticamente con la fecha/hora actual
|
|
7
|
-
* cada vez que se guarde el modelo.
|
|
8
|
-
*
|
|
9
|
-
* @example
|
|
10
|
-
* class User extends Table<User> {
|
|
11
|
-
* @PrimaryKey() id: string;
|
|
12
|
-
* name: string;
|
|
13
|
-
* @UpdatedAt() updated_at: string;
|
|
14
|
-
* }
|
|
15
|
-
*/
|
|
16
|
-
function UpdatedAt() {
|
|
17
|
-
return function (target, propertyKey) {
|
|
18
|
-
const ctor = target.constructor;
|
|
19
|
-
const entry = (0, wrapper_1.ensureConfig)(ctor, ctor.name);
|
|
20
|
-
const column = (0, wrapper_1.ensureColumn)(entry, propertyKey, propertyKey);
|
|
21
|
-
// Marcamos la columna como updatedAt para que se actualice automáticamente al guardar
|
|
22
|
-
column.updatedAt = true;
|
|
23
|
-
// No establecemos un valor por defecto aquí, se establecerá en el método save()
|
|
24
|
-
};
|
|
25
|
-
}
|
|
26
|
-
//# sourceMappingURL=updated_at.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export default function Validate(validators: ((v: unknown) => true | string) | ((v: unknown) => true | string)[]): PropertyDecorator;
|
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.default = Validate;
|
|
4
|
-
const wrapper_1 = require("../core/wrapper");
|
|
5
|
-
const naming_1 = require("../utils/naming");
|
|
6
|
-
function Validate(validators) {
|
|
7
|
-
const list = Array.isArray(validators) ? validators : [validators];
|
|
8
|
-
if (!list.length || list.some((v) => typeof v !== "function")) {
|
|
9
|
-
throw new TypeError("@Validate requiere funciones");
|
|
10
|
-
}
|
|
11
|
-
return (target, prop) => {
|
|
12
|
-
const ctor = target.constructor;
|
|
13
|
-
const entry = (0, wrapper_1.ensureConfig)(ctor, (0, naming_1.toSnakePlural)(ctor.name));
|
|
14
|
-
const col = (0, wrapper_1.ensureColumn)(entry, prop, String(prop));
|
|
15
|
-
col.validate ??= [];
|
|
16
|
-
col.validate.push(...list);
|
|
17
|
-
!Object.getOwnPropertyDescriptor(ctor.prototype, prop)?.set &&
|
|
18
|
-
defineVirtual(ctor.prototype, col, prop);
|
|
19
|
-
};
|
|
20
|
-
}
|
|
21
|
-
/** Define propiedad virtual con getter/setter para manejo de validaciones */
|
|
22
|
-
function defineVirtual(proto, col, prop) {
|
|
23
|
-
Object.defineProperty(proto, prop, {
|
|
24
|
-
get() {
|
|
25
|
-
return (this[wrapper_1.STORE] ?? {})[prop];
|
|
26
|
-
},
|
|
27
|
-
set(val) {
|
|
28
|
-
const buf = (this[wrapper_1.STORE] ??= {});
|
|
29
|
-
val =
|
|
30
|
-
val === undefined && col.default !== undefined
|
|
31
|
-
? typeof col.default === "function"
|
|
32
|
-
? col.default()
|
|
33
|
-
: col.default
|
|
34
|
-
: val;
|
|
35
|
-
if (col.mutate)
|
|
36
|
-
for (const m of col.mutate)
|
|
37
|
-
val = m(val);
|
|
38
|
-
if (col.validate) {
|
|
39
|
-
for (const v of col.validate) {
|
|
40
|
-
const r = v(val);
|
|
41
|
-
r !== true &&
|
|
42
|
-
(() => {
|
|
43
|
-
throw new Error(typeof r === "string" ? r : "Validación fallida");
|
|
44
|
-
})();
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
buf[prop] = val;
|
|
48
|
-
},
|
|
49
|
-
enumerable: true,
|
|
50
|
-
configurable: true,
|
|
51
|
-
});
|
|
52
|
-
}
|
|
53
|
-
//# sourceMappingURL=validate.js.map
|
package/src/index.d.ts
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @file index.ts
|
|
3
|
-
* @descripcion Punto de entrada público de la librería
|
|
4
|
-
* @autor Miguel Alejandro
|
|
5
|
-
* @fecha 2025-08-07
|
|
6
|
-
*/
|
|
7
|
-
export { Dynamite } from "./core/client";
|
|
8
|
-
export { default as Table } from "./core/table";
|
|
9
|
-
export { default as BelongsTo } from "./decorators/belongs_to";
|
|
10
|
-
export { default as CreatedAt } from "./decorators/created_at";
|
|
11
|
-
export { default as Default } from "./decorators/default";
|
|
12
|
-
export { default as HasMany } from "./decorators/has_many";
|
|
13
|
-
export { default as Index } from "./decorators/index";
|
|
14
|
-
export { default as IndexSort } from "./decorators/index_sort";
|
|
15
|
-
export { default as Mutate } from "./decorators/mutate";
|
|
16
|
-
export { default as Name } from "./decorators/name";
|
|
17
|
-
export { default as NotNull } from "./decorators/not_null";
|
|
18
|
-
export { default as PrimaryKey } from "./decorators/primary_key";
|
|
19
|
-
export { default as UpdatedAt } from "./decorators/updated_at";
|
|
20
|
-
export { default as Validate } from "./decorators/validate";
|
|
21
|
-
export { belongsTo, hasMany } from "./utils/relations";
|
|
22
|
-
export type { BelongsTo as BelongsToType, HasMany as HasManyType, NonAttribute, CreationOptional, InferAttributes, FilterableAttributes, QueryOperator, QueryResult, WhereOptions, WhereOptionsWithoutWhere, } from "./@types/index";
|
package/src/index.js
DELETED
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* @file index.ts
|
|
4
|
-
* @descripcion Punto de entrada público de la librería
|
|
5
|
-
* @autor Miguel Alejandro
|
|
6
|
-
* @fecha 2025-08-07
|
|
7
|
-
*/
|
|
8
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
9
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
10
|
-
};
|
|
11
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.hasMany = exports.belongsTo = exports.Validate = exports.UpdatedAt = exports.PrimaryKey = exports.NotNull = exports.Name = exports.Mutate = exports.IndexSort = exports.Index = exports.HasMany = exports.Default = exports.CreatedAt = exports.BelongsTo = exports.Table = exports.Dynamite = void 0;
|
|
13
|
-
// Clases núcleo
|
|
14
|
-
var client_1 = require("./core/client");
|
|
15
|
-
Object.defineProperty(exports, "Dynamite", { enumerable: true, get: function () { return client_1.Dynamite; } });
|
|
16
|
-
var table_1 = require("./core/table");
|
|
17
|
-
Object.defineProperty(exports, "Table", { enumerable: true, get: function () { return __importDefault(table_1).default; } });
|
|
18
|
-
// Decoradores
|
|
19
|
-
var belongs_to_1 = require("./decorators/belongs_to");
|
|
20
|
-
Object.defineProperty(exports, "BelongsTo", { enumerable: true, get: function () { return __importDefault(belongs_to_1).default; } });
|
|
21
|
-
var created_at_1 = require("./decorators/created_at");
|
|
22
|
-
Object.defineProperty(exports, "CreatedAt", { enumerable: true, get: function () { return __importDefault(created_at_1).default; } });
|
|
23
|
-
var default_1 = require("./decorators/default");
|
|
24
|
-
Object.defineProperty(exports, "Default", { enumerable: true, get: function () { return __importDefault(default_1).default; } });
|
|
25
|
-
var has_many_1 = require("./decorators/has_many");
|
|
26
|
-
Object.defineProperty(exports, "HasMany", { enumerable: true, get: function () { return __importDefault(has_many_1).default; } });
|
|
27
|
-
var index_1 = require("./decorators/index");
|
|
28
|
-
Object.defineProperty(exports, "Index", { enumerable: true, get: function () { return __importDefault(index_1).default; } });
|
|
29
|
-
var index_sort_1 = require("./decorators/index_sort");
|
|
30
|
-
Object.defineProperty(exports, "IndexSort", { enumerable: true, get: function () { return __importDefault(index_sort_1).default; } });
|
|
31
|
-
var mutate_1 = require("./decorators/mutate");
|
|
32
|
-
Object.defineProperty(exports, "Mutate", { enumerable: true, get: function () { return __importDefault(mutate_1).default; } });
|
|
33
|
-
var name_1 = require("./decorators/name");
|
|
34
|
-
Object.defineProperty(exports, "Name", { enumerable: true, get: function () { return __importDefault(name_1).default; } });
|
|
35
|
-
var not_null_1 = require("./decorators/not_null");
|
|
36
|
-
Object.defineProperty(exports, "NotNull", { enumerable: true, get: function () { return __importDefault(not_null_1).default; } });
|
|
37
|
-
var primary_key_1 = require("./decorators/primary_key");
|
|
38
|
-
Object.defineProperty(exports, "PrimaryKey", { enumerable: true, get: function () { return __importDefault(primary_key_1).default; } });
|
|
39
|
-
var updated_at_1 = require("./decorators/updated_at");
|
|
40
|
-
Object.defineProperty(exports, "UpdatedAt", { enumerable: true, get: function () { return __importDefault(updated_at_1).default; } });
|
|
41
|
-
var validate_1 = require("./decorators/validate");
|
|
42
|
-
Object.defineProperty(exports, "Validate", { enumerable: true, get: function () { return __importDefault(validate_1).default; } });
|
|
43
|
-
// Relaciones
|
|
44
|
-
var relations_1 = require("./utils/relations");
|
|
45
|
-
Object.defineProperty(exports, "belongsTo", { enumerable: true, get: function () { return relations_1.belongsTo; } });
|
|
46
|
-
Object.defineProperty(exports, "hasMany", { enumerable: true, get: function () { return relations_1.hasMany; } });
|
|
47
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @file batch-relations.ts
|
|
3
|
-
* @description Optimized batch loading for relations
|
|
4
|
-
* @autor Miguel Alejandro
|
|
5
|
-
* @fecha 2025-01-27
|
|
6
|
-
*/
|
|
7
|
-
/** Batch loader para hasMany relations */
|
|
8
|
-
export declare const batchLoadHasMany: (Model: any, parentItems: any[], relation: any) => Promise<Map<any, any>>;
|
|
9
|
-
/** Batch loader para belongsTo relations con cache */
|
|
10
|
-
export declare const batchLoadBelongsTo: (Model: any, parentItems: any[], relation: any) => Promise<Map<any, any>>;
|
|
11
|
-
/** Optimized processIncludes con batch loading */
|
|
12
|
-
export declare const processIncludesBatch: (Model: any, items: any[], include: any, depth?: number) => Promise<any[]>;
|
|
13
|
-
/** Clear expired cache entries */
|
|
14
|
-
export declare const cleanupRelationCache: () => void;
|
|
@@ -1,131 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* @file batch-relations.ts
|
|
4
|
-
* @description Optimized batch loading for relations
|
|
5
|
-
* @autor Miguel Alejandro
|
|
6
|
-
* @fecha 2025-01-27
|
|
7
|
-
*/
|
|
8
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
-
exports.cleanupRelationCache = exports.processIncludesBatch = exports.batchLoadBelongsTo = exports.batchLoadHasMany = void 0;
|
|
10
|
-
const wrapper_1 = require("../core/wrapper");
|
|
11
|
-
/** Cache multi-nivel con TTL */
|
|
12
|
-
const relCache = new Map();
|
|
13
|
-
/** Batch loader para hasMany relations */
|
|
14
|
-
const batchLoadHasMany = async (Model, parentItems, relation) => {
|
|
15
|
-
const { targetModel, foreignKey, localKey } = relation;
|
|
16
|
-
const TargetModel = targetModel();
|
|
17
|
-
// Agrupar claves para batch query
|
|
18
|
-
const parentKeys = parentItems.map((item) => item[localKey]).filter(Boolean);
|
|
19
|
-
if (!parentKeys.length)
|
|
20
|
-
return new Map();
|
|
21
|
-
// Single query con 'in' operator
|
|
22
|
-
const relatedItems = await TargetModel.where({
|
|
23
|
-
[foreignKey]: { in: parentKeys },
|
|
24
|
-
});
|
|
25
|
-
// Group by foreign key
|
|
26
|
-
const grouped = new Map();
|
|
27
|
-
relatedItems.forEach((item) => {
|
|
28
|
-
const key = item[foreignKey];
|
|
29
|
-
if (!grouped.has(key))
|
|
30
|
-
grouped.set(key, []);
|
|
31
|
-
grouped.get(key).push(item);
|
|
32
|
-
});
|
|
33
|
-
return grouped;
|
|
34
|
-
};
|
|
35
|
-
exports.batchLoadHasMany = batchLoadHasMany;
|
|
36
|
-
/** Batch loader para belongsTo relations con cache */
|
|
37
|
-
const batchLoadBelongsTo = async (Model, parentItems, relation) => {
|
|
38
|
-
const { targetModel, localKey, foreignKey } = relation;
|
|
39
|
-
const TargetModel = targetModel();
|
|
40
|
-
const cacheKey = `${TargetModel.name}_belongsTo`;
|
|
41
|
-
// Verificar cache existente
|
|
42
|
-
const cache = relCache.get(cacheKey) || new Map();
|
|
43
|
-
relCache.set(cacheKey, cache);
|
|
44
|
-
const now = Date.now();
|
|
45
|
-
// Separar keys en cache vs no-cache
|
|
46
|
-
const keysToFetch = [];
|
|
47
|
-
const cachedResults = new Map();
|
|
48
|
-
parentItems.forEach((item) => {
|
|
49
|
-
const key = item[localKey];
|
|
50
|
-
if (!key)
|
|
51
|
-
return;
|
|
52
|
-
const cached = cache.get(key);
|
|
53
|
-
if (cached && cached.expires > now) {
|
|
54
|
-
cachedResults.set(key, cached.data);
|
|
55
|
-
}
|
|
56
|
-
else {
|
|
57
|
-
keysToFetch.push(key);
|
|
58
|
-
}
|
|
59
|
-
});
|
|
60
|
-
// Fetch missing items
|
|
61
|
-
if (keysToFetch.length) {
|
|
62
|
-
const fetchedItems = await TargetModel.where({
|
|
63
|
-
[foreignKey]: { in: keysToFetch },
|
|
64
|
-
});
|
|
65
|
-
// Update cache (5min TTL)
|
|
66
|
-
const expires = now + 300000;
|
|
67
|
-
fetchedItems.forEach((item) => {
|
|
68
|
-
const key = item[foreignKey];
|
|
69
|
-
cache.set(key, { data: item, expires });
|
|
70
|
-
cachedResults.set(key, item);
|
|
71
|
-
});
|
|
72
|
-
}
|
|
73
|
-
return cachedResults;
|
|
74
|
-
};
|
|
75
|
-
exports.batchLoadBelongsTo = batchLoadBelongsTo;
|
|
76
|
-
/** Optimized processIncludes con batch loading */
|
|
77
|
-
const processIncludesBatch = async (Model, items, include, depth = 0) => {
|
|
78
|
-
if (!include || depth > 10 || !items.length)
|
|
79
|
-
return items;
|
|
80
|
-
const meta = (0, wrapper_1.mustMeta)(Model);
|
|
81
|
-
// Process all relations in parallel
|
|
82
|
-
const relationPromises = Object.entries(include).map(async ([relationKey, relationOptions]) => {
|
|
83
|
-
const relation = meta.relations.get(relationKey);
|
|
84
|
-
if (!relation)
|
|
85
|
-
return;
|
|
86
|
-
let relatedData;
|
|
87
|
-
// Use batch loading based on relation type
|
|
88
|
-
if (relation.type === "hasMany") {
|
|
89
|
-
relatedData = await (0, exports.batchLoadHasMany)(Model, items, relation);
|
|
90
|
-
}
|
|
91
|
-
else {
|
|
92
|
-
relatedData = await (0, exports.batchLoadBelongsTo)(Model, items, relation);
|
|
93
|
-
}
|
|
94
|
-
// Assign relations to items
|
|
95
|
-
items.forEach((item) => {
|
|
96
|
-
const key = item[relation.localKey];
|
|
97
|
-
const related = relatedData.get(key);
|
|
98
|
-
if (relation.type === "hasMany") {
|
|
99
|
-
item[relationKey] = related || [];
|
|
100
|
-
}
|
|
101
|
-
else {
|
|
102
|
-
item[relationKey] = related || null;
|
|
103
|
-
}
|
|
104
|
-
});
|
|
105
|
-
// Recursive processing for nested includes
|
|
106
|
-
if (relationOptions?.include && relatedData.size) {
|
|
107
|
-
const allRelated = Array.from(relatedData.values()).flat();
|
|
108
|
-
const TargetModel = relation.targetModel();
|
|
109
|
-
await (0, exports.processIncludesBatch)(TargetModel, allRelated, relationOptions.include, depth + 1);
|
|
110
|
-
}
|
|
111
|
-
});
|
|
112
|
-
await Promise.all(relationPromises);
|
|
113
|
-
return items;
|
|
114
|
-
};
|
|
115
|
-
exports.processIncludesBatch = processIncludesBatch;
|
|
116
|
-
/** Clear expired cache entries */
|
|
117
|
-
const cleanupRelationCache = () => {
|
|
118
|
-
const now = Date.now();
|
|
119
|
-
relCache.forEach((cache, modelKey) => {
|
|
120
|
-
cache.forEach((entry, key) => {
|
|
121
|
-
if (entry.expires <= now)
|
|
122
|
-
cache.delete(key);
|
|
123
|
-
});
|
|
124
|
-
if (cache.size === 0)
|
|
125
|
-
relCache.delete(modelKey);
|
|
126
|
-
});
|
|
127
|
-
};
|
|
128
|
-
exports.cleanupRelationCache = cleanupRelationCache;
|
|
129
|
-
// Auto cleanup every 5 minutes
|
|
130
|
-
setInterval(exports.cleanupRelationCache, 300000);
|
|
131
|
-
//# sourceMappingURL=batch-relations.js.map
|