@arcaelas/dynamite 1.0.29 → 3.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (142) hide show
  1. package/README.md +13 -13
  2. package/{src → build/cjs}/@types/index.d.ts +26 -1
  3. package/build/cjs/@types/index.js.map +1 -0
  4. package/{src → build/cjs}/core/client.d.ts +22 -19
  5. package/build/cjs/core/client.js +384 -0
  6. package/build/cjs/core/client.js.map +1 -0
  7. package/build/cjs/core/decorator.d.ts +50 -0
  8. package/build/cjs/core/decorator.js +52 -0
  9. package/build/cjs/core/decorator.js.map +1 -0
  10. package/build/cjs/core/table.d.ts +73 -0
  11. package/build/cjs/core/table.js +953 -0
  12. package/build/cjs/core/table.js.map +1 -0
  13. package/build/cjs/decorators/hooks.d.ts +35 -0
  14. package/build/cjs/decorators/hooks.js +50 -0
  15. package/build/cjs/decorators/hooks.js.map +1 -0
  16. package/build/cjs/decorators/indexes.d.ts +20 -0
  17. package/build/cjs/decorators/indexes.js +45 -0
  18. package/build/cjs/decorators/indexes.js.map +1 -0
  19. package/{src → build/cjs}/decorators/relations.d.ts +8 -7
  20. package/{src → build/cjs}/decorators/relations.js +9 -8
  21. package/build/cjs/decorators/relations.js.map +1 -0
  22. package/build/cjs/decorators/timestamps.d.ts +20 -0
  23. package/build/cjs/decorators/timestamps.js +34 -0
  24. package/build/cjs/decorators/timestamps.js.map +1 -0
  25. package/build/cjs/decorators/transforms.d.ts +41 -0
  26. package/build/cjs/decorators/transforms.js +98 -0
  27. package/build/cjs/decorators/transforms.js.map +1 -0
  28. package/{src → build/cjs}/index.d.ts +7 -3
  29. package/{src → build/cjs}/index.js +15 -6
  30. package/build/cjs/index.js.map +1 -0
  31. package/build/cjs/package.json +1 -0
  32. package/build/cjs/test/basic.d.ts +1 -0
  33. package/build/cjs/test/basic.js +248 -0
  34. package/build/cjs/test/basic.js.map +1 -0
  35. package/build/cjs/test/bulk.d.ts +1 -0
  36. package/build/cjs/test/bulk.js +108 -0
  37. package/build/cjs/test/bulk.js.map +1 -0
  38. package/build/cjs/test/contracts.d.ts +1 -0
  39. package/build/cjs/test/contracts.js +343 -0
  40. package/build/cjs/test/contracts.js.map +1 -0
  41. package/build/cjs/test/filters.d.ts +1 -0
  42. package/build/cjs/test/filters.js +190 -0
  43. package/build/cjs/test/filters.js.map +1 -0
  44. package/build/cjs/test/hooks.d.ts +1 -0
  45. package/build/cjs/test/hooks.js +191 -0
  46. package/build/cjs/test/hooks.js.map +1 -0
  47. package/build/cjs/test/index.js +38 -0
  48. package/build/cjs/test/index.js.map +1 -0
  49. package/build/cjs/test/query_scan.d.ts +1 -0
  50. package/build/cjs/test/query_scan.js +195 -0
  51. package/build/cjs/test/query_scan.js.map +1 -0
  52. package/build/cjs/test/relations.d.ts +1 -0
  53. package/build/cjs/test/relations.js +246 -0
  54. package/build/cjs/test/relations.js.map +1 -0
  55. package/build/cjs/test/transactions.d.ts +1 -0
  56. package/build/cjs/test/transactions.js +145 -0
  57. package/build/cjs/test/transactions.js.map +1 -0
  58. package/{src → build/cjs}/utils/relations.js +1 -8
  59. package/build/cjs/utils/relations.js.map +1 -0
  60. package/build/cjs/utils/ulid.d.ts +10 -0
  61. package/build/cjs/utils/ulid.js +55 -0
  62. package/build/cjs/utils/ulid.js.map +1 -0
  63. package/build/esm/@types/index.d.ts +213 -0
  64. package/build/esm/@types/index.js +8 -0
  65. package/build/esm/@types/index.js.map +1 -0
  66. package/build/esm/core/client.d.ts +96 -0
  67. package/build/esm/core/client.js +375 -0
  68. package/build/esm/core/client.js.map +1 -0
  69. package/build/esm/core/decorator.d.ts +50 -0
  70. package/build/esm/core/decorator.js +47 -0
  71. package/build/esm/core/decorator.js.map +1 -0
  72. package/build/esm/core/table.d.ts +73 -0
  73. package/build/esm/core/table.js +950 -0
  74. package/build/esm/core/table.js.map +1 -0
  75. package/build/esm/decorators/hooks.d.ts +35 -0
  76. package/build/esm/decorators/hooks.js +47 -0
  77. package/build/esm/decorators/hooks.js.map +1 -0
  78. package/build/esm/decorators/indexes.d.ts +20 -0
  79. package/build/esm/decorators/indexes.js +42 -0
  80. package/build/esm/decorators/indexes.js.map +1 -0
  81. package/build/esm/decorators/relations.d.ts +75 -0
  82. package/build/esm/decorators/relations.js +112 -0
  83. package/build/esm/decorators/relations.js.map +1 -0
  84. package/build/esm/decorators/timestamps.d.ts +20 -0
  85. package/build/esm/decorators/timestamps.js +31 -0
  86. package/build/esm/decorators/timestamps.js.map +1 -0
  87. package/build/esm/decorators/transforms.d.ts +41 -0
  88. package/build/esm/decorators/transforms.js +92 -0
  89. package/build/esm/decorators/transforms.js.map +1 -0
  90. package/build/esm/index.d.ts +19 -0
  91. package/build/esm/index.js +26 -0
  92. package/build/esm/index.js.map +1 -0
  93. package/build/esm/package.json +1 -0
  94. package/build/esm/test/basic.d.ts +1 -0
  95. package/build/esm/test/basic.js +245 -0
  96. package/build/esm/test/basic.js.map +1 -0
  97. package/build/esm/test/bulk.d.ts +1 -0
  98. package/build/esm/test/bulk.js +105 -0
  99. package/build/esm/test/bulk.js.map +1 -0
  100. package/build/esm/test/contracts.d.ts +1 -0
  101. package/build/esm/test/contracts.js +340 -0
  102. package/build/esm/test/contracts.js.map +1 -0
  103. package/build/esm/test/filters.d.ts +1 -0
  104. package/build/esm/test/filters.js +187 -0
  105. package/build/esm/test/filters.js.map +1 -0
  106. package/build/esm/test/hooks.d.ts +1 -0
  107. package/build/esm/test/hooks.js +188 -0
  108. package/build/esm/test/hooks.js.map +1 -0
  109. package/build/esm/test/index.d.ts +1 -0
  110. package/build/esm/test/index.js +33 -0
  111. package/build/esm/test/index.js.map +1 -0
  112. package/build/esm/test/query_scan.d.ts +1 -0
  113. package/build/esm/test/query_scan.js +192 -0
  114. package/build/esm/test/query_scan.js.map +1 -0
  115. package/build/esm/test/relations.d.ts +1 -0
  116. package/build/esm/test/relations.js +243 -0
  117. package/build/esm/test/relations.js.map +1 -0
  118. package/build/esm/test/transactions.d.ts +1 -0
  119. package/build/esm/test/transactions.js +142 -0
  120. package/build/esm/test/transactions.js.map +1 -0
  121. package/build/esm/utils/relations.d.ts +42 -0
  122. package/build/esm/utils/relations.js +207 -0
  123. package/build/esm/utils/relations.js.map +1 -0
  124. package/build/esm/utils/ulid.d.ts +10 -0
  125. package/build/esm/utils/ulid.js +52 -0
  126. package/build/esm/utils/ulid.js.map +1 -0
  127. package/package.json +31 -9
  128. package/src/core/client.js +0 -296
  129. package/src/core/decorator.d.ts +0 -29
  130. package/src/core/decorator.js +0 -103
  131. package/src/core/table.d.ts +0 -81
  132. package/src/core/table.js +0 -892
  133. package/src/decorators/indexes.d.ts +0 -38
  134. package/src/decorators/indexes.js +0 -59
  135. package/src/decorators/timestamps.d.ts +0 -54
  136. package/src/decorators/timestamps.js +0 -72
  137. package/src/decorators/transforms.d.ts +0 -99
  138. package/src/decorators/transforms.js +0 -166
  139. package/src/index.test.js +0 -37
  140. /package/{src → build/cjs}/@types/index.js +0 -0
  141. /package/{src/index.test.d.ts → build/cjs/test/index.d.ts} +0 -0
  142. /package/{src → build/cjs}/utils/relations.d.ts +0 -0
@@ -1,38 +0,0 @@
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 const PrimaryKey: (...params: any[]) => (target: any, propertyKey: string | symbol) => void;
@@ -1,59 +0,0 @@
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.PrimaryKey = exports.IndexSort = exports.Index = void 0;
10
- const decorator_1 = require("../core/decorator");
11
- /**
12
- * @description Decorador para marcar propiedad como Partition Key
13
- * @example
14
- * ```typescript
15
- * class User extends Table<User> {
16
- * @Index() id: string;
17
- * }
18
- * ```
19
- */
20
- exports.Index = (0, decorator_1.decorator)((_schema, col) => {
21
- col.store.index = true;
22
- col.store.nullable = col.store.nullable ?? false;
23
- });
24
- /**
25
- * @description Decorador para marcar propiedad como Sort Key
26
- * @example
27
- * ```typescript
28
- * class Post extends Table<Post> {
29
- * @Index() user_id: string;
30
- * @IndexSort() created_at: string;
31
- * }
32
- * ```
33
- */
34
- exports.IndexSort = (0, decorator_1.decorator)((_schema, col) => {
35
- col.store.indexSort = true;
36
- col.store.nullable = col.store.nullable ?? false;
37
- });
38
- /**
39
- * @description Decorador para marcar una propiedad como clave primaria
40
- * @example
41
- * ```typescript
42
- * class User extends Table<User> {
43
- * @PrimaryKey() id: string;
44
- * name: string;
45
- * }
46
- * ```
47
- */
48
- exports.PrimaryKey = (0, decorator_1.decorator)((table_class, col) => {
49
- const schema = table_class[decorator_1.SCHEMA];
50
- // Configurar como primary key
51
- Object.assign(col.store, {
52
- index: true,
53
- primaryKey: true,
54
- nullable: false
55
- });
56
- // Obtener nombre de columna desde col.name
57
- schema.primary_key = col.name;
58
- });
59
- //# sourceMappingURL=indexes.js.map
@@ -1,54 +0,0 @@
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 usando pipelines.
9
- * El valor se genera en el getter si no existe, y se preserva en el setter.
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 actualiza automáticamente la fecha/hora en cada asignación usando pipelines.
21
- * El timestamp se actualiza cada vez que se escribe en la propiedad.
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;
@@ -1,72 +0,0 @@
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 usando pipelines.
13
- * El valor se genera en el getter si no existe, y se preserva en el setter.
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
- // Getter: asignar timestamp si no existe (solo primera vez)
24
- col.get.push((value) => value ?? new Date().toISOString());
25
- // Setter: preservar valor si ya existe, ignorar intentos de cambio
26
- col.set.push((current, next) => current ?? next ?? new Date().toISOString());
27
- });
28
- /**
29
- * @description Decorador que actualiza automáticamente la fecha/hora en cada asignación usando pipelines.
30
- * El timestamp se actualiza cada vez que se escribe en la propiedad.
31
- * @example
32
- * ```typescript
33
- * class User extends Table<User> {
34
- * @PrimaryKey() id: string;
35
- * name: string;
36
- * @UpdatedAt() updated_at: string;
37
- * }
38
- * ```
39
- */
40
- exports.UpdatedAt = (0, decorator_1.decorator)((_schema, col) => {
41
- // Getter: retornar valor actual o timestamp si no existe
42
- col.get.push((value) => value ?? new Date().toISOString());
43
- // Setter: siempre actualizar con nuevo timestamp (ignora el valor pasado)
44
- col.set.push((_current, _next) => new Date().toISOString());
45
- });
46
- /**
47
- * @description Decorador que marca una propiedad como columna de soft delete.
48
- * Cuando se llama destroy(), en lugar de eliminar el registro,
49
- * se establece esta columna con la fecha/hora actual.
50
- * @example
51
- * ```typescript
52
- * class User extends Table<User> {
53
- * @PrimaryKey() id: string;
54
- * name: string;
55
- * @DeleteAt() deleted_at?: string;
56
- * }
57
- *
58
- * // Soft delete (marca deleted_at con timestamp)
59
- * await user.destroy();
60
- *
61
- * // Queries normales excluyen soft deleted
62
- * await User.where({ status: "active" });
63
- *
64
- * // Incluir soft deleted
65
- * await User.withTrashed({ status: "active" });
66
- * ```
67
- */
68
- exports.DeleteAt = (0, decorator_1.decorator)((_schema, col) => {
69
- col.store.softDelete = true;
70
- col.store.nullable = true;
71
- });
72
- //# sourceMappingURL=timestamps.js.map
@@ -1,99 +0,0 @@
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 usando pipeline de getter
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 (se ejecuta en el setter)
36
- * @param validators Función o array de funciones validadoras
37
- * @example
38
- * ```typescript
39
- * class User extends Table<User> {
40
- * @Validate((v) => v.length > 0 || 'Email requerido')
41
- * declare email: string;
42
- *
43
- * @Validate([isEmail, isNotEmpty])
44
- * declare email2: string;
45
- * }
46
- * ```
47
- */
48
- export declare const Validate: (...params: any[]) => (target: any, propertyKey: string | symbol) => void;
49
- /**
50
- * @description Decorador para transformar valores entre DB y aplicación
51
- * @param fromDB Función que transforma al leer de DB
52
- * @param toDB Función que transforma al guardar en DB
53
- * @example
54
- * ```typescript
55
- * class User extends Table<User> {
56
- * @Serialize(JSON.parse, JSON.stringify)
57
- * declare metadata: Record<string, any>;
58
- * }
59
- * ```
60
- */
61
- export declare const Serialize: (...params: any[]) => (target: any, propertyKey: string | symbol) => void;
62
- /**
63
- * @description Decorador que valida que el valor no sea null, undefined o string vacío
64
- * @example
65
- * ```typescript
66
- * class User extends Table<User> {
67
- * @NotNull()
68
- * declare name: string;
69
- * }
70
- * ```
71
- */
72
- export declare const NotNull: (...params: any[]) => (target: any, propertyKey: string | symbol) => void;
73
- /**
74
- * @description Decorador dual para renombrar tabla o columna
75
- * @param label Nombre personalizado
76
- * @example
77
- * ```typescript
78
- * @Name('usuarios')
79
- * class User extends Table<User> {
80
- * @Name('user_email')
81
- * declare email: string;
82
- * }
83
- * ```
84
- */
85
- export declare function Name(label: string): ClassDecorator & PropertyDecorator;
86
- /**
87
- * @description Decorador para marcar una propiedad como columna sin agregar comportamiento especial
88
- * @example
89
- * ```typescript
90
- * class Product extends Table<Product> {
91
- * @Column()
92
- * price!: number;
93
- *
94
- * @Column()
95
- * category_id!: string;
96
- * }
97
- * ```
98
- */
99
- export declare const Column: (...params: any[]) => (target: any, propertyKey: string | symbol) => void;
@@ -1,166 +0,0 @@
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.Column = 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 usando pipeline de getter
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
- // Usar pipeline de getter con ?? para valores nullish
29
- col.get.push((value) => value ?? (typeof fallback === 'function' ? fallback() : fallback));
30
- });
31
- /**
32
- * @description Decorador para transformar valores en cada asignación
33
- * @param fn Función de transformación
34
- * @example
35
- * ```typescript
36
- * class User extends Table<User> {
37
- * @Mutate((v) => v.toLowerCase())
38
- * declare email: string;
39
- * }
40
- * ```
41
- */
42
- exports.Mutate = (0, decorator_1.decorator)((_schema, col, params) => {
43
- const fn = params[0];
44
- col.set.push((current, next) => fn(next));
45
- });
46
- /**
47
- * @description Decorador para validar valores (se ejecuta en el setter)
48
- * @param validators Función o array de funciones validadoras
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])
56
- * declare email2: string;
57
- * }
58
- * ```
59
- */
60
- exports.Validate = (0, decorator_1.decorator)((_schema, col, params) => {
61
- const validators = params[0];
62
- const list = Array.isArray(validators) ? validators : [validators];
63
- if (!list.length || list.some((v) => typeof v !== 'function')) {
64
- throw new TypeError('@Validate requiere funciones');
65
- }
66
- col.set.push((current, next) => {
67
- for (const fn of list) {
68
- const result = fn(next);
69
- if (result !== true) {
70
- throw new Error(typeof result === 'string' ? result : 'Validación fallida');
71
- }
72
- }
73
- return next;
74
- });
75
- });
76
- /**
77
- * @description Decorador para transformar valores entre DB y aplicación
78
- * @param fromDB Función que transforma al leer de DB
79
- * @param toDB Función que transforma al guardar en DB
80
- * @example
81
- * ```typescript
82
- * class User extends Table<User> {
83
- * @Serialize(JSON.parse, JSON.stringify)
84
- * declare metadata: Record<string, any>;
85
- * }
86
- * ```
87
- */
88
- exports.Serialize = (0, decorator_1.decorator)((_schema, col, params) => {
89
- const [fromDB, toDB] = params;
90
- if (fromDB)
91
- col.get.push((v) => v !== null && v !== undefined ? fromDB(v) : v);
92
- if (toDB)
93
- col.set.push((current, next) => next !== null && next !== undefined ? toDB(next) : next);
94
- });
95
- /**
96
- * @description Decorador que valida que el valor no sea null, undefined o string vacío
97
- * @example
98
- * ```typescript
99
- * class User extends Table<User> {
100
- * @NotNull()
101
- * declare name: string;
102
- * }
103
- * ```
104
- */
105
- exports.NotNull = (0, decorator_1.decorator)((_schema, col, params) => {
106
- const custom_message = params[0];
107
- col.store.nullable = false;
108
- col.store.notNullMessage = custom_message;
109
- col.set.push((current, next) => {
110
- const is_empty = next === null || next === undefined || (typeof next === 'string' && next.trim() === '');
111
- if (is_empty) {
112
- throw new Error(custom_message || `El campo ${col.name} no puede estar vacío`);
113
- }
114
- return next;
115
- });
116
- });
117
- /**
118
- * @description Decorador dual para renombrar tabla o columna
119
- * @param label Nombre personalizado
120
- * @example
121
- * ```typescript
122
- * @Name('usuarios')
123
- * class User extends Table<User> {
124
- * @Name('user_email')
125
- * declare email: string;
126
- * }
127
- * ```
128
- */
129
- function Name(label) {
130
- if (!label || typeof label !== 'string') {
131
- throw new TypeError('@Name requiere una cadena no vacía');
132
- }
133
- return (target, prop) => {
134
- const ctor = prop === undefined ? target : target.constructor;
135
- const schema = ctor[decorator_1.SCHEMA];
136
- if (prop === undefined) {
137
- // @Name en clase - renombrar tabla
138
- schema.name = label;
139
- }
140
- else {
141
- // @Name en propiedad - renombrar columna
142
- const column_name = String(prop);
143
- if (!schema.columns[column_name]) {
144
- schema.columns[column_name] = { name: column_name, get: [], set: [], store: {} };
145
- }
146
- schema.columns[column_name].name = label;
147
- }
148
- };
149
- }
150
- /**
151
- * @description Decorador para marcar una propiedad como columna sin agregar comportamiento especial
152
- * @example
153
- * ```typescript
154
- * class Product extends Table<Product> {
155
- * @Column()
156
- * price!: number;
157
- *
158
- * @Column()
159
- * category_id!: string;
160
- * }
161
- * ```
162
- */
163
- exports.Column = (0, decorator_1.decorator)((_schema, _col) => {
164
- // No hace nada, solo marca la propiedad como columna en schema.columns
165
- });
166
- //# sourceMappingURL=transforms.js.map
package/src/index.test.js DELETED
@@ -1,37 +0,0 @@
1
- "use strict";
2
- var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
- return c > 3 && r && Object.defineProperty(target, key, r), r;
7
- };
8
- var __metadata = (this && this.__metadata) || function (k, v) {
9
- if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
- };
11
- Object.defineProperty(exports, "__esModule", { value: true });
12
- const index_1 = require("./index");
13
- class User extends index_1.Table {
14
- }
15
- __decorate([
16
- (0, index_1.PrimaryKey)(),
17
- (0, index_1.Default)(() => crypto.randomUUID()),
18
- __metadata("design:type", Object)
19
- ], User.prototype, "id", void 0);
20
- __decorate([
21
- (0, index_1.Default)(() => "customer"),
22
- __metadata("design:type", Object)
23
- ], User.prototype, "role", void 0);
24
- __decorate([
25
- (0, index_1.CreatedAt)(),
26
- __metadata("design:type", Object)
27
- ], User.prototype, "created_at", void 0);
28
- __decorate([
29
- (0, index_1.UpdatedAt)(),
30
- __metadata("design:type", Object)
31
- ], User.prototype, "updated_at", void 0);
32
- (async function () {
33
- const dynamite = new index_1.Dynamite({ tables: [User] });
34
- await dynamite.connect();
35
- console.log("Connected successfully");
36
- })();
37
- //# sourceMappingURL=index.test.js.map
File without changes
File without changes