@arcaelas/dynamite 1.0.17 → 1.0.18

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 (66) hide show
  1. package/package.json +40 -2
  2. package/src/@types/index.d.ts +27 -21
  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 +9 -16
  20. package/src/index.js +35 -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/core/wrapper.d.ts +0 -17
  26. package/src/core/wrapper.js +0 -46
  27. package/src/decorators/belongs_to.d.ts +0 -1
  28. package/src/decorators/belongs_to.js +0 -24
  29. package/src/decorators/created_at.d.ts +0 -1
  30. package/src/decorators/created_at.js +0 -11
  31. package/src/decorators/default.d.ts +0 -1
  32. package/src/decorators/default.js +0 -47
  33. package/src/decorators/has_many.d.ts +0 -1
  34. package/src/decorators/has_many.js +0 -24
  35. package/src/decorators/index.d.ts +0 -11
  36. package/src/decorators/index.js +0 -36
  37. package/src/decorators/index_sort.d.ts +0 -12
  38. package/src/decorators/index_sort.js +0 -43
  39. package/src/decorators/mutate.d.ts +0 -2
  40. package/src/decorators/mutate.js +0 -51
  41. package/src/decorators/name.d.ts +0 -1
  42. package/src/decorators/name.js +0 -28
  43. package/src/decorators/not_null.d.ts +0 -1
  44. package/src/decorators/not_null.js +0 -13
  45. package/src/decorators/primary_key.d.ts +0 -6
  46. package/src/decorators/primary_key.js +0 -30
  47. package/src/decorators/updated_at.d.ts +0 -12
  48. package/src/decorators/updated_at.js +0 -26
  49. package/src/decorators/validate.d.ts +0 -1
  50. package/src/decorators/validate.js +0 -53
  51. package/src/utils/batch-relations.d.ts +0 -14
  52. package/src/utils/batch-relations.js +0 -131
  53. package/src/utils/circular-detector.d.ts +0 -82
  54. package/src/utils/circular-detector.js +0 -212
  55. package/src/utils/memory-manager.d.ts +0 -42
  56. package/src/utils/memory-manager.js +0 -107
  57. package/src/utils/naming.d.ts +0 -8
  58. package/src/utils/naming.js +0 -18
  59. package/src/utils/projection.d.ts +0 -12
  60. package/src/utils/projection.js +0 -51
  61. package/src/utils/security-validator.d.ts +0 -49
  62. package/src/utils/security-validator.js +0 -163
  63. package/src/utils/throttle-manager.d.ts +0 -78
  64. package/src/utils/throttle-manager.js +0 -201
  65. package/src/utils/transaction-manager.d.ts +0 -88
  66. package/src/utils/transaction-manager.js +0 -300
@@ -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
@@ -1,98 +1,56 @@
1
1
  /**
2
2
  * @file table.ts
3
- * @descripcion Clase Table rediseñada con API completa y tipado estricto
3
+ * @description Tabla autocontenida con arquitectura minimalista y Symbol storage
4
4
  * @autor Miguel Alejandro
5
- * @fecha 2025-07-30
5
+ * @fecha 2025-01-28
6
6
  */
7
- import type { InferAttributes, QueryOperator, WhereQueryOptions, WrapperEntry } from "../@types/index";
8
- import { STORE } from "./wrapper";
9
- export default class Table<T = any> {
10
- protected [STORE]: {
11
- [K in keyof T]?: T[K];
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
- constructor(data: InferAttributes<T>);
14
- /** Serializar instancia a JSON plano */
15
- toJSON(): Record<string, any>;
16
- /** Guardar instancia (crear o actualizar) */
17
- save(): Promise<this>;
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
- * Eliminar registros de la base de datos
28
+ * @description Serializa la instancia a JSON incluyendo relaciones recursivamente
29
+ * @returns Objeto JSON con todas las propiedades y relaciones
41
30
  */
42
- static delete<M extends Table>(this: {
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
- * Obtener el primer registro que coincida con los filtros
33
+ * @description Serializa la instancia a string JSON
34
+ * @returns String JSON con todas las propiedades y relaciones
68
35
  */
69
- static first<M extends Table, K extends keyof InferAttributes<M>>(this: {
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
- * Obtener el último registro que coincida con los filtros
38
+ * @description Genera payload para operaciones de DB (excluye relaciones)
83
39
  */
84
- static last<M extends Table, K extends keyof InferAttributes<M>>(this: {
85
- new (data: InferAttributes<M>): M;
86
- prototype: M;
87
- }, field: K, value: InferAttributes<M>[K]): Promise<M | undefined>;
88
- static last<M extends Table, K extends keyof InferAttributes<M>>(this: {
89
- new (data: InferAttributes<M>): M;
90
- prototype: M;
91
- }, field: K, operator: QueryOperator, value: InferAttributes<M>[K] | InferAttributes<M>[K][]): Promise<M | undefined>;
92
- static last<M extends Table>(this: {
93
- new (data: InferAttributes<M>): M;
94
- prototype: M;
95
- }, filters: Partial<InferAttributes<M>>): Promise<M | undefined>;
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 { STORE };
98
- export type { WrapperEntry };
56
+ export type { QueryOptions, IncludeRelationOptions, QueryOperator };