@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.
Files changed (67) hide show
  1. package/package.json +40 -2
  2. package/src/@types/index.d.ts +116 -75
  3. package/src/core/client.d.ts +36 -0
  4. package/src/core/client.js +80 -27
  5. package/src/core/decorator.d.ts +44 -0
  6. package/src/core/decorator.js +133 -0
  7. package/src/core/method.d.ts +73 -0
  8. package/src/core/method.js +140 -0
  9. package/src/core/table.d.ts +44 -86
  10. package/src/core/table.js +510 -310
  11. package/src/decorators/indexes.d.ts +38 -0
  12. package/src/decorators/indexes.js +67 -0
  13. package/src/decorators/relations.d.ts +55 -0
  14. package/src/decorators/relations.js +84 -0
  15. package/src/decorators/timestamps.d.ts +54 -0
  16. package/src/decorators/timestamps.js +67 -0
  17. package/src/decorators/transforms.d.ts +86 -0
  18. package/src/decorators/transforms.js +154 -0
  19. package/src/index.d.ts +10 -16
  20. package/src/index.js +50 -32
  21. package/src/index.test.d.ts +13 -0
  22. package/src/index.test.js +1992 -0
  23. package/src/utils/relations.d.ts +34 -12
  24. package/src/utils/relations.js +109 -133
  25. package/src/@types/index.js +0 -9
  26. package/src/core/wrapper.d.ts +0 -17
  27. package/src/core/wrapper.js +0 -46
  28. package/src/decorators/belongs_to.d.ts +0 -1
  29. package/src/decorators/belongs_to.js +0 -24
  30. package/src/decorators/created_at.d.ts +0 -1
  31. package/src/decorators/created_at.js +0 -11
  32. package/src/decorators/default.d.ts +0 -1
  33. package/src/decorators/default.js +0 -47
  34. package/src/decorators/has_many.d.ts +0 -1
  35. package/src/decorators/has_many.js +0 -24
  36. package/src/decorators/index.d.ts +0 -11
  37. package/src/decorators/index.js +0 -36
  38. package/src/decorators/index_sort.d.ts +0 -12
  39. package/src/decorators/index_sort.js +0 -43
  40. package/src/decorators/mutate.d.ts +0 -2
  41. package/src/decorators/mutate.js +0 -51
  42. package/src/decorators/name.d.ts +0 -1
  43. package/src/decorators/name.js +0 -28
  44. package/src/decorators/not_null.d.ts +0 -1
  45. package/src/decorators/not_null.js +0 -13
  46. package/src/decorators/primary_key.d.ts +0 -6
  47. package/src/decorators/primary_key.js +0 -30
  48. package/src/decorators/updated_at.d.ts +0 -12
  49. package/src/decorators/updated_at.js +0 -26
  50. package/src/decorators/validate.d.ts +0 -1
  51. package/src/decorators/validate.js +0 -53
  52. package/src/utils/batch-relations.d.ts +0 -14
  53. package/src/utils/batch-relations.js +0 -131
  54. package/src/utils/circular-detector.d.ts +0 -82
  55. package/src/utils/circular-detector.js +0 -212
  56. package/src/utils/memory-manager.d.ts +0 -42
  57. package/src/utils/memory-manager.js +0 -107
  58. package/src/utils/naming.d.ts +0 -8
  59. package/src/utils/naming.js +0 -18
  60. package/src/utils/projection.d.ts +0 -12
  61. package/src/utils/projection.js +0 -51
  62. package/src/utils/security-validator.d.ts +0 -49
  63. package/src/utils/security-validator.js +0 -163
  64. package/src/utils/throttle-manager.d.ts +0 -78
  65. package/src/utils/throttle-manager.js +0 -201
  66. package/src/utils/transaction-manager.d.ts +0 -88
  67. package/src/utils/transaction-manager.js +0 -300
@@ -0,0 +1,38 @@
1
+ /**
2
+ * @file indexes.ts
3
+ * @description Decoradores de índices con Symbol storage
4
+ * @autor Miguel Alejandro
5
+ * @fecha 2025-01-28
6
+ */
7
+ /**
8
+ * @description Decorador para marcar propiedad como Partition Key
9
+ * @example
10
+ * ```typescript
11
+ * class User extends Table<User> {
12
+ * @Index() id: string;
13
+ * }
14
+ * ```
15
+ */
16
+ export declare const Index: (...params: any[]) => (target: any, propertyKey: string | symbol) => void;
17
+ /**
18
+ * @description Decorador para marcar propiedad como Sort Key
19
+ * @example
20
+ * ```typescript
21
+ * class Post extends Table<Post> {
22
+ * @Index() user_id: string;
23
+ * @IndexSort() created_at: string;
24
+ * }
25
+ * ```
26
+ */
27
+ export declare const IndexSort: (...params: any[]) => (target: any, propertyKey: string | symbol) => void;
28
+ /**
29
+ * @description Decorador para marcar una propiedad como clave primaria
30
+ * @example
31
+ * ```typescript
32
+ * class User extends Table<User> {
33
+ * @PrimaryKey() id: string;
34
+ * name: string;
35
+ * }
36
+ * ```
37
+ */
38
+ export declare function PrimaryKey(): PropertyDecorator;
@@ -0,0 +1,67 @@
1
+ "use strict";
2
+ /**
3
+ * @file indexes.ts
4
+ * @description Decoradores de índices con Symbol storage
5
+ * @autor Miguel Alejandro
6
+ * @fecha 2025-01-28
7
+ */
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.IndexSort = exports.Index = void 0;
10
+ exports.PrimaryKey = PrimaryKey;
11
+ const decorator_1 = require("../core/decorator");
12
+ /**
13
+ * @description Decorador para marcar propiedad como Partition Key
14
+ * @example
15
+ * ```typescript
16
+ * class User extends Table<User> {
17
+ * @Index() id: string;
18
+ * }
19
+ * ```
20
+ */
21
+ exports.Index = (0, decorator_1.decorator)((_schema, col) => {
22
+ col.store.index = true;
23
+ col.store.nullable = col.store.nullable ?? false;
24
+ });
25
+ /**
26
+ * @description Decorador para marcar propiedad como Sort Key
27
+ * @example
28
+ * ```typescript
29
+ * class Post extends Table<Post> {
30
+ * @Index() user_id: string;
31
+ * @IndexSort() created_at: string;
32
+ * }
33
+ * ```
34
+ */
35
+ exports.IndexSort = (0, decorator_1.decorator)((_schema, col) => {
36
+ col.store.indexSort = true;
37
+ col.store.nullable = col.store.nullable ?? false;
38
+ });
39
+ /**
40
+ * @description Decorador para marcar una propiedad como clave primaria
41
+ * @example
42
+ * ```typescript
43
+ * class User extends Table<User> {
44
+ * @PrimaryKey() id: string;
45
+ * name: string;
46
+ * }
47
+ * ```
48
+ */
49
+ function PrimaryKey() {
50
+ return (target, prop) => {
51
+ const table_class = target.constructor;
52
+ const column_name = String(prop);
53
+ const schema = (0, decorator_1.ensureSchema)(table_class);
54
+ // Crear columna si no existe
55
+ if (!schema.columns[column_name]) {
56
+ schema.columns[column_name] = { name: column_name, get: [], set: [], store: {} };
57
+ }
58
+ // Configurar como primary key
59
+ Object.assign(schema.columns[column_name].store, {
60
+ index: true,
61
+ primaryKey: true,
62
+ nullable: false
63
+ });
64
+ schema.primary_key = column_name;
65
+ };
66
+ }
67
+ //# sourceMappingURL=indexes.js.map
@@ -0,0 +1,55 @@
1
+ /**
2
+ * @file relations.ts
3
+ * @description Decoradores de relaciones: @HasMany, @HasOne, @BelongsTo
4
+ * @autor Miguel Alejandro
5
+ * @fecha 2025-01-28
6
+ */
7
+ /**
8
+ * @description Decorador para relaciones uno a muchos (1:N)
9
+ * @param model Función que retorna la clase del modelo relacionado
10
+ * @param foreignKey Clave foránea en el modelo relacionado
11
+ * @param localKey Clave local (por defecto 'id')
12
+ * @example
13
+ * ```typescript
14
+ * class User extends Table<User> {
15
+ * @PrimaryKey() id: string;
16
+ *
17
+ * @HasMany(() => Post, 'id_user', 'id')
18
+ * declare posts: HasMany<Post>;
19
+ * }
20
+ * ```
21
+ */
22
+ export declare const HasMany: (...params: any[]) => (target: any, propertyKey: string | symbol) => void;
23
+ /**
24
+ * @description Decorador para relaciones uno a uno (1:1)
25
+ * @param model Función que retorna la clase del modelo relacionado
26
+ * @param foreignKey Clave foránea en el modelo relacionado
27
+ * @param localKey Clave local (por defecto 'id')
28
+ * @example
29
+ * ```typescript
30
+ * class User extends Table<User> {
31
+ * @PrimaryKey() id: string;
32
+ *
33
+ * @HasOne(() => Profile, 'id_user', 'id')
34
+ * declare profile: HasOne<Profile>;
35
+ * }
36
+ * ```
37
+ */
38
+ export declare const HasOne: (...params: any[]) => (target: any, propertyKey: string | symbol) => void;
39
+ /**
40
+ * @description Decorador para relaciones muchos a uno (N:1)
41
+ * @param model Función que retorna la clase del modelo relacionado
42
+ * @param localKey Clave local que referencia al modelo padre
43
+ * @param foreignKey Clave en el modelo padre (por defecto 'id')
44
+ * @example
45
+ * ```typescript
46
+ * class Post extends Table<Post> {
47
+ * @PrimaryKey() id: string;
48
+ * id_user: string;
49
+ *
50
+ * @BelongsTo(() => User, 'id_user', 'id')
51
+ * declare author: BelongsTo<User>;
52
+ * }
53
+ * ```
54
+ */
55
+ export declare const BelongsTo: (...params: any[]) => (target: any, propertyKey: string | symbol) => void;
@@ -0,0 +1,84 @@
1
+ "use strict";
2
+ /**
3
+ * @file relations.ts
4
+ * @description Decoradores de relaciones: @HasMany, @HasOne, @BelongsTo
5
+ * @autor Miguel Alejandro
6
+ * @fecha 2025-01-28
7
+ */
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.BelongsTo = exports.HasOne = exports.HasMany = void 0;
10
+ const decorator_1 = require("../core/decorator");
11
+ /**
12
+ * @description Decorador para relaciones uno a muchos (1:N)
13
+ * @param model Función que retorna la clase del modelo relacionado
14
+ * @param foreignKey Clave foránea en el modelo relacionado
15
+ * @param localKey Clave local (por defecto 'id')
16
+ * @example
17
+ * ```typescript
18
+ * class User extends Table<User> {
19
+ * @PrimaryKey() id: string;
20
+ *
21
+ * @HasMany(() => Post, 'id_user', 'id')
22
+ * declare posts: HasMany<Post>;
23
+ * }
24
+ * ```
25
+ */
26
+ exports.HasMany = (0, decorator_1.decorator)((_schema, col, params) => {
27
+ const [model, foreignKey, localKey = 'id'] = params;
28
+ col.store.relation = {
29
+ type: 'HasMany',
30
+ model,
31
+ foreignKey,
32
+ localKey
33
+ };
34
+ });
35
+ /**
36
+ * @description Decorador para relaciones uno a uno (1:1)
37
+ * @param model Función que retorna la clase del modelo relacionado
38
+ * @param foreignKey Clave foránea en el modelo relacionado
39
+ * @param localKey Clave local (por defecto 'id')
40
+ * @example
41
+ * ```typescript
42
+ * class User extends Table<User> {
43
+ * @PrimaryKey() id: string;
44
+ *
45
+ * @HasOne(() => Profile, 'id_user', 'id')
46
+ * declare profile: HasOne<Profile>;
47
+ * }
48
+ * ```
49
+ */
50
+ exports.HasOne = (0, decorator_1.decorator)((_schema, col, params) => {
51
+ const [model, foreignKey, localKey = 'id'] = params;
52
+ col.store.relation = {
53
+ type: 'HasOne',
54
+ model,
55
+ foreignKey,
56
+ localKey
57
+ };
58
+ });
59
+ /**
60
+ * @description Decorador para relaciones muchos a uno (N:1)
61
+ * @param model Función que retorna la clase del modelo relacionado
62
+ * @param localKey Clave local que referencia al modelo padre
63
+ * @param foreignKey Clave en el modelo padre (por defecto 'id')
64
+ * @example
65
+ * ```typescript
66
+ * class Post extends Table<Post> {
67
+ * @PrimaryKey() id: string;
68
+ * id_user: string;
69
+ *
70
+ * @BelongsTo(() => User, 'id_user', 'id')
71
+ * declare author: BelongsTo<User>;
72
+ * }
73
+ * ```
74
+ */
75
+ exports.BelongsTo = (0, decorator_1.decorator)((_schema, col, params) => {
76
+ const [model, localKey, foreignKey = 'id'] = params;
77
+ col.store.relation = {
78
+ type: 'BelongsTo',
79
+ model,
80
+ foreignKey,
81
+ localKey
82
+ };
83
+ });
84
+ //# sourceMappingURL=relations.js.map
@@ -0,0 +1,54 @@
1
+ /**
2
+ * @file timestamps.ts
3
+ * @description Decoradores de timestamps: @CreatedAt, @UpdatedAt, @DeleteAt
4
+ * @autor Miguel Alejandro
5
+ * @fecha 2025-01-28
6
+ */
7
+ /**
8
+ * @description Decorador que establece automáticamente la fecha/hora de creación.
9
+ * El valor se genera solo si no existe uno previo.
10
+ * @example
11
+ * ```typescript
12
+ * class User extends Table<User> {
13
+ * @PrimaryKey() id: string;
14
+ * @CreatedAt() created_at: string;
15
+ * }
16
+ * ```
17
+ */
18
+ export declare const CreatedAt: (...params: any[]) => (target: any, propertyKey: string | symbol) => void;
19
+ /**
20
+ * @description Decorador que marca una propiedad para que se actualice automáticamente
21
+ * con la fecha/hora actual cada vez que se guarde el modelo.
22
+ * @example
23
+ * ```typescript
24
+ * class User extends Table<User> {
25
+ * @PrimaryKey() id: string;
26
+ * name: string;
27
+ * @UpdatedAt() updated_at: string;
28
+ * }
29
+ * ```
30
+ */
31
+ export declare const UpdatedAt: (...params: any[]) => (target: any, propertyKey: string | symbol) => void;
32
+ /**
33
+ * @description Decorador que marca una propiedad como columna de soft delete.
34
+ * Cuando se llama destroy(), en lugar de eliminar el registro,
35
+ * se establece esta columna con la fecha/hora actual.
36
+ * @example
37
+ * ```typescript
38
+ * class User extends Table<User> {
39
+ * @PrimaryKey() id: string;
40
+ * name: string;
41
+ * @DeleteAt() deleted_at?: string;
42
+ * }
43
+ *
44
+ * // Soft delete (marca deleted_at con timestamp)
45
+ * await user.destroy();
46
+ *
47
+ * // Queries normales excluyen soft deleted
48
+ * await User.where({ status: "active" });
49
+ *
50
+ * // Incluir soft deleted
51
+ * await User.withTrashed({ status: "active" });
52
+ * ```
53
+ */
54
+ export declare const DeleteAt: (...params: any[]) => (target: any, propertyKey: string | symbol) => void;
@@ -0,0 +1,67 @@
1
+ "use strict";
2
+ /**
3
+ * @file timestamps.ts
4
+ * @description Decoradores de timestamps: @CreatedAt, @UpdatedAt, @DeleteAt
5
+ * @autor Miguel Alejandro
6
+ * @fecha 2025-01-28
7
+ */
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.DeleteAt = exports.UpdatedAt = exports.CreatedAt = void 0;
10
+ const decorator_1 = require("../core/decorator");
11
+ /**
12
+ * @description Decorador que establece automáticamente la fecha/hora de creación.
13
+ * El valor se genera solo si no existe uno previo.
14
+ * @example
15
+ * ```typescript
16
+ * class User extends Table<User> {
17
+ * @PrimaryKey() id: string;
18
+ * @CreatedAt() created_at: string;
19
+ * }
20
+ * ```
21
+ */
22
+ exports.CreatedAt = (0, decorator_1.decorator)((_schema, col) => {
23
+ col.store.createdAt = true;
24
+ col.get.push((value) => value ?? new Date().toISOString());
25
+ });
26
+ /**
27
+ * @description Decorador que marca una propiedad para que se actualice automáticamente
28
+ * con la fecha/hora actual cada vez que se guarde el modelo.
29
+ * @example
30
+ * ```typescript
31
+ * class User extends Table<User> {
32
+ * @PrimaryKey() id: string;
33
+ * name: string;
34
+ * @UpdatedAt() updated_at: string;
35
+ * }
36
+ * ```
37
+ */
38
+ exports.UpdatedAt = (0, decorator_1.decorator)((_schema, col) => {
39
+ col.store.updatedAt = true;
40
+ });
41
+ /**
42
+ * @description Decorador que marca una propiedad como columna de soft delete.
43
+ * Cuando se llama destroy(), en lugar de eliminar el registro,
44
+ * se establece esta columna con la fecha/hora actual.
45
+ * @example
46
+ * ```typescript
47
+ * class User extends Table<User> {
48
+ * @PrimaryKey() id: string;
49
+ * name: string;
50
+ * @DeleteAt() deleted_at?: string;
51
+ * }
52
+ *
53
+ * // Soft delete (marca deleted_at con timestamp)
54
+ * await user.destroy();
55
+ *
56
+ * // Queries normales excluyen soft deleted
57
+ * await User.where({ status: "active" });
58
+ *
59
+ * // Incluir soft deleted
60
+ * await User.withTrashed({ status: "active" });
61
+ * ```
62
+ */
63
+ exports.DeleteAt = (0, decorator_1.decorator)((_schema, col) => {
64
+ col.store.softDelete = true;
65
+ col.store.nullable = true;
66
+ });
67
+ //# sourceMappingURL=timestamps.js.map
@@ -0,0 +1,86 @@
1
+ /**
2
+ * @file transforms.ts
3
+ * @description Decoradores de transformación con pipelines directas
4
+ * @autor Miguel Alejandro
5
+ * @fecha 2025-01-28
6
+ */
7
+ /**
8
+ * @description Decorador para establecer valor por defecto
9
+ * @param factory Valor por defecto o función que lo genera
10
+ * @example
11
+ * ```typescript
12
+ * class User extends Table<User> {
13
+ * @Default(uuid)
14
+ * declare id: string;
15
+ *
16
+ * @Default(() => 0)
17
+ * declare score: number;
18
+ * }
19
+ * ```
20
+ */
21
+ export declare const Default: (...params: any[]) => (target: any, propertyKey: string | symbol) => void;
22
+ /**
23
+ * @description Decorador para transformar valores en cada asignación
24
+ * @param fn Función de transformación
25
+ * @example
26
+ * ```typescript
27
+ * class User extends Table<User> {
28
+ * @Mutate((v) => v.toLowerCase())
29
+ * declare email: string;
30
+ * }
31
+ * ```
32
+ */
33
+ export declare const Mutate: (...params: any[]) => (target: any, propertyKey: string | symbol) => void;
34
+ /**
35
+ * @description Decorador para validar valores
36
+ * @param validators Función o array de funciones validadoras
37
+ * @param options Opciones de validación (lazy: true para validar en save())
38
+ * @example
39
+ * ```typescript
40
+ * class User extends Table<User> {
41
+ * @Validate((v) => v.length > 0 || 'Email requerido')
42
+ * declare email: string;
43
+ *
44
+ * @Validate([isEmail, isNotEmpty], { lazy: true })
45
+ * declare email2: string;
46
+ * }
47
+ * ```
48
+ */
49
+ export declare const Validate: (...params: any[]) => (target: any, propertyKey: string | symbol) => void;
50
+ /**
51
+ * @description Decorador para transformar valores entre DB y aplicación
52
+ * @param fromDB Función que transforma al leer de DB
53
+ * @param toDB Función que transforma al guardar en DB
54
+ * @example
55
+ * ```typescript
56
+ * class User extends Table<User> {
57
+ * @Serialize(JSON.parse, JSON.stringify)
58
+ * declare metadata: Record<string, any>;
59
+ * }
60
+ * ```
61
+ */
62
+ export declare const Serialize: (...params: any[]) => (target: any, propertyKey: string | symbol) => void;
63
+ /**
64
+ * @description Decorador que valida que el valor no sea null, undefined o string vacío
65
+ * @example
66
+ * ```typescript
67
+ * class User extends Table<User> {
68
+ * @NotNull()
69
+ * declare name: string;
70
+ * }
71
+ * ```
72
+ */
73
+ export declare const NotNull: (...params: any[]) => (target: any, propertyKey: string | symbol) => void;
74
+ /**
75
+ * @description Decorador dual para renombrar tabla o columna
76
+ * @param label Nombre personalizado
77
+ * @example
78
+ * ```typescript
79
+ * @Name('usuarios')
80
+ * class User extends Table<User> {
81
+ * @Name('user_email')
82
+ * declare email: string;
83
+ * }
84
+ * ```
85
+ */
86
+ export declare function Name(label: string): ClassDecorator & PropertyDecorator;
@@ -0,0 +1,154 @@
1
+ "use strict";
2
+ /**
3
+ * @file transforms.ts
4
+ * @description Decoradores de transformación con pipelines directas
5
+ * @autor Miguel Alejandro
6
+ * @fecha 2025-01-28
7
+ */
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.NotNull = exports.Serialize = exports.Validate = exports.Mutate = exports.Default = void 0;
10
+ exports.Name = Name;
11
+ const decorator_1 = require("../core/decorator");
12
+ /**
13
+ * @description Decorador para establecer valor por defecto
14
+ * @param factory Valor por defecto o función que lo genera
15
+ * @example
16
+ * ```typescript
17
+ * class User extends Table<User> {
18
+ * @Default(uuid)
19
+ * declare id: string;
20
+ *
21
+ * @Default(() => 0)
22
+ * declare score: number;
23
+ * }
24
+ * ```
25
+ */
26
+ exports.Default = (0, decorator_1.decorator)((_schema, col, params) => {
27
+ const fallback = params[0];
28
+ col.get.push((value) => value ?? (typeof fallback === 'function' ? fallback() : fallback));
29
+ });
30
+ /**
31
+ * @description Decorador para transformar valores en cada asignación
32
+ * @param fn Función de transformación
33
+ * @example
34
+ * ```typescript
35
+ * class User extends Table<User> {
36
+ * @Mutate((v) => v.toLowerCase())
37
+ * declare email: string;
38
+ * }
39
+ * ```
40
+ */
41
+ exports.Mutate = (0, decorator_1.decorator)((_schema, col, params) => {
42
+ const fn = params[0];
43
+ col.set.push((value) => fn(value));
44
+ });
45
+ /**
46
+ * @description Decorador para validar valores
47
+ * @param validators Función o array de funciones validadoras
48
+ * @param options Opciones de validación (lazy: true para validar en save())
49
+ * @example
50
+ * ```typescript
51
+ * class User extends Table<User> {
52
+ * @Validate((v) => v.length > 0 || 'Email requerido')
53
+ * declare email: string;
54
+ *
55
+ * @Validate([isEmail, isNotEmpty], { lazy: true })
56
+ * declare email2: string;
57
+ * }
58
+ * ```
59
+ */
60
+ exports.Validate = (0, decorator_1.decorator)((_schema, col, params) => {
61
+ const [validators, options] = params;
62
+ const list = Array.isArray(validators) ? validators : [validators];
63
+ const is_lazy = options?.lazy ?? false;
64
+ if (!list.length || list.some((v) => typeof v !== 'function')) {
65
+ throw new TypeError('@Validate requiere funciones');
66
+ }
67
+ if (is_lazy) {
68
+ col.store.lazy_validators = list;
69
+ }
70
+ else {
71
+ col.set.push((value) => {
72
+ for (const fn of list) {
73
+ const result = fn(value);
74
+ if (result !== true) {
75
+ throw new Error(typeof result === 'string' ? result : 'Validación fallida');
76
+ }
77
+ }
78
+ return value;
79
+ });
80
+ }
81
+ });
82
+ /**
83
+ * @description Decorador para transformar valores entre DB y aplicación
84
+ * @param fromDB Función que transforma al leer de DB
85
+ * @param toDB Función que transforma al guardar en DB
86
+ * @example
87
+ * ```typescript
88
+ * class User extends Table<User> {
89
+ * @Serialize(JSON.parse, JSON.stringify)
90
+ * declare metadata: Record<string, any>;
91
+ * }
92
+ * ```
93
+ */
94
+ exports.Serialize = (0, decorator_1.decorator)((_schema, col, params) => {
95
+ const [fromDB, toDB] = params;
96
+ if (fromDB)
97
+ col.get.push((v) => v !== null && v !== undefined ? fromDB(v) : v);
98
+ if (toDB)
99
+ col.set.push((v) => v !== null && v !== undefined ? toDB(v) : v);
100
+ });
101
+ /**
102
+ * @description Decorador que valida que el valor no sea null, undefined o string vacío
103
+ * @example
104
+ * ```typescript
105
+ * class User extends Table<User> {
106
+ * @NotNull()
107
+ * declare name: string;
108
+ * }
109
+ * ```
110
+ */
111
+ exports.NotNull = (0, decorator_1.decorator)((_schema, col) => {
112
+ col.store.nullable = false;
113
+ col.set.push((value) => {
114
+ const is_empty = value === null || value === undefined || (typeof value === 'string' && value.trim() === '');
115
+ if (is_empty) {
116
+ throw new Error(`El campo ${col.name} no puede estar vacío`);
117
+ }
118
+ return value;
119
+ });
120
+ });
121
+ /**
122
+ * @description Decorador dual para renombrar tabla o columna
123
+ * @param label Nombre personalizado
124
+ * @example
125
+ * ```typescript
126
+ * @Name('usuarios')
127
+ * class User extends Table<User> {
128
+ * @Name('user_email')
129
+ * declare email: string;
130
+ * }
131
+ * ```
132
+ */
133
+ function Name(label) {
134
+ if (!label || typeof label !== 'string') {
135
+ throw new TypeError('@Name requiere una cadena no vacía');
136
+ }
137
+ return (target, prop) => {
138
+ const ctor = prop === undefined ? target : target.constructor;
139
+ const schema = (0, decorator_1.ensureSchema)(ctor);
140
+ if (prop === undefined) {
141
+ // @Name en clase - renombrar tabla
142
+ schema.name = label;
143
+ }
144
+ else {
145
+ // @Name en propiedad - renombrar columna
146
+ const column_name = String(prop);
147
+ if (!schema.columns[column_name]) {
148
+ schema.columns[column_name] = { name: column_name, get: [], set: [], store: {} };
149
+ }
150
+ schema.columns[column_name].name = label;
151
+ }
152
+ };
153
+ }
154
+ //# sourceMappingURL=transforms.js.map
package/src/index.d.ts CHANGED
@@ -1,22 +1,16 @@
1
1
  /**
2
2
  * @file index.ts
3
- * @descripcion Punto de entrada público de la librería
3
+ * @description Punto de entrada público de la librería - Arquitectura Minimalista
4
4
  * @autor Miguel Alejandro
5
- * @fecha 2025-08-07
5
+ * @fecha 2025-01-28
6
6
  */
7
7
  export { Dynamite } from "./core/client";
8
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, CreationOptional, FilterableAttributes, HasMany as HasManyType, InferAttributes, NonAttribute, QueryOperator, QueryResult, WhereOptions, WhereOptionsWithoutWhere, } from "./@types/index";
9
+ export { decorator, relationDecorator, SCHEMA, VALUES } from "./core/decorator";
10
+ export { Index, IndexSort, PrimaryKey } from "./decorators/indexes";
11
+ export { CreatedAt, DeleteAt, UpdatedAt } from "./decorators/timestamps";
12
+ export { Default, Mutate, Name, NotNull, Serialize, Validate, } from "./decorators/transforms";
13
+ export { BelongsTo, HasMany, HasOne } from "./decorators/relations";
14
+ export type { IncludeRelationOptions, QueryOperator, QueryOptions, } from "./core/table";
15
+ export * from "./@types/index";
16
+ export { TransactionContext } from "./core/client";