@arcaelas/dynamite 1.0.2 → 1.0.3

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 (42) hide show
  1. package/build/core/table.d.ts +17 -0
  2. package/build/core/table.js +223 -0
  3. package/build/core/table.js.map +1 -0
  4. package/build/core/wrapper.d.ts +47 -0
  5. package/build/core/wrapper.js +57 -0
  6. package/build/core/wrapper.js.map +1 -0
  7. package/build/decorators/created_at.d.ts +4 -0
  8. package/build/decorators/created_at.js +22 -0
  9. package/build/decorators/created_at.js.map +1 -0
  10. package/build/decorators/default.d.ts +1 -0
  11. package/build/decorators/default.js +55 -0
  12. package/build/decorators/default.js.map +1 -0
  13. package/build/decorators/index.d.ts +1 -0
  14. package/build/decorators/index.js +24 -0
  15. package/build/decorators/index.js.map +1 -0
  16. package/build/decorators/index_sort.d.ts +1 -0
  17. package/build/decorators/index_sort.js +27 -0
  18. package/build/decorators/index_sort.js.map +1 -0
  19. package/build/decorators/mutate.d.ts +2 -0
  20. package/build/decorators/mutate.js +53 -0
  21. package/build/decorators/mutate.js.map +1 -0
  22. package/build/decorators/name.d.ts +1 -0
  23. package/build/decorators/name.js +41 -0
  24. package/build/decorators/name.js.map +1 -0
  25. package/build/decorators/not_null.d.ts +4 -0
  26. package/build/decorators/not_null.js +28 -0
  27. package/build/decorators/not_null.js.map +1 -0
  28. package/build/decorators/primary_key.d.ts +7 -0
  29. package/build/decorators/primary_key.js +30 -0
  30. package/build/decorators/primary_key.js.map +1 -0
  31. package/build/decorators/updated_at.d.ts +4 -0
  32. package/build/decorators/updated_at.js +23 -0
  33. package/build/decorators/updated_at.js.map +1 -0
  34. package/build/decorators/validate.d.ts +1 -0
  35. package/build/decorators/validate.js +54 -0
  36. package/build/decorators/validate.js.map +1 -0
  37. package/build/index.d.ts +11 -130
  38. package/build/utils/naming.d.ts +1 -0
  39. package/build/utils/naming.js +18 -0
  40. package/build/utils/naming.js.map +1 -0
  41. package/package.json +5 -3
  42. package/tsconfig.json +0 -32
@@ -0,0 +1,17 @@
1
+ import { DynamoDBClientConfig } from "@aws-sdk/client-dynamodb";
2
+ import { STORE, WrapperEntry } from "./wrapper";
3
+ export declare function connect(cfg: DynamoDBClientConfig): void;
4
+ export default class Table<T extends object = object> {
5
+ private [STORE];
6
+ constructor(data?: Partial<T>);
7
+ toJSON(): Record<string, unknown>;
8
+ save(): Promise<this>;
9
+ update(patch: Partial<T>): Promise<this>;
10
+ destroy(): Promise<void>;
11
+ static create<M extends Table>(this: new (d?: Partial<M>) => M, data: Partial<M>): Promise<M>;
12
+ static update<M extends Table>(this: new (d?: Partial<M>) => M, id: string, record: Partial<M>): Promise<void>;
13
+ static destroy<M extends Table>(this: new () => M, id: string): Promise<null>;
14
+ static where<M extends Table>(this: new (d?: any) => M): Promise<M[]>;
15
+ }
16
+ export { STORE };
17
+ export type { WrapperEntry };
@@ -0,0 +1,223 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.STORE = void 0;
37
+ exports.connect = connect;
38
+ /* src/core/table.ts
39
+ * Dinamite ORM — runtime
40
+ * --------------------------------------------------
41
+ * CRUD + autocreación de tablas (DynamoDB v3)
42
+ * Serialización estricta mediante toJSON()
43
+ * © 2025 Miguel Alejandro
44
+ */
45
+ const client_dynamodb_1 = require("@aws-sdk/client-dynamodb");
46
+ const util_dynamodb_1 = require("@aws-sdk/util-dynamodb");
47
+ const wrapper_1 = __importStar(require("./wrapper"));
48
+ Object.defineProperty(exports, "STORE", { enumerable: true, get: function () { return wrapper_1.STORE; } });
49
+ /* ────────────────────────── Conexión global ────────────────────────── */
50
+ let client;
51
+ function connect(cfg) {
52
+ client = new client_dynamodb_1.DynamoDBClient(cfg);
53
+ }
54
+ /* ─────────── Creación automática de tablas a partir del wrapper ────── */
55
+ async function createTable(ctor) {
56
+ if (!client)
57
+ throw new Error("connect() no llamado");
58
+ const meta = wrapper_1.default.get(ctor);
59
+ if (!meta)
60
+ throw new Error(`Clase ${ctor.name} no registrada en wrapper`);
61
+ const cols = [...meta.columns.values()];
62
+ const pk = cols.find((c) => c.index);
63
+ if (!pk)
64
+ throw new Error(`PartitionKey faltante en ${ctor.name}`);
65
+ const sk = cols.find((c) => c.indexSort);
66
+ const attr = new Map();
67
+ attr.set(pk.name, "S");
68
+ if (sk)
69
+ attr.set(sk.name, "S");
70
+ const schema = [{ AttributeName: pk.name, KeyType: "HASH" }];
71
+ if (sk && sk.name !== pk.name)
72
+ schema.push({ AttributeName: sk.name, KeyType: "RANGE" });
73
+ await client.send(new client_dynamodb_1.CreateTableCommand({
74
+ TableName: meta.name,
75
+ BillingMode: "PAY_PER_REQUEST",
76
+ AttributeDefinitions: [...attr].map(([AttributeName, AttributeType]) => ({
77
+ AttributeName,
78
+ AttributeType,
79
+ })),
80
+ KeySchema: schema,
81
+ }));
82
+ }
83
+ /* ────────────────────────────── Table ──────────────────────────────── */
84
+ class Table {
85
+ constructor(data = {}) {
86
+ requireClient();
87
+ const meta = mustMeta(Object.getPrototypeOf(this).constructor);
88
+ /* defaults via setters */
89
+ meta.columns.forEach((c) => {
90
+ if (!(c.name in data))
91
+ this[c.name] = undefined;
92
+ });
93
+ Object.assign(this, data);
94
+ }
95
+ /* -------- serializa SOLO columnas válidas -------- */
96
+ toJSON() {
97
+ const meta = mustMeta(Object.getPrototypeOf(this).constructor);
98
+ const buf = this[wrapper_1.STORE] ?? {};
99
+ const out = {};
100
+ for (const [prop, col] of meta.columns) {
101
+ if (prop in buf)
102
+ out[col.name] = buf[prop];
103
+ else if (prop in this)
104
+ out[col.name] = this[prop];
105
+ }
106
+ return out;
107
+ }
108
+ /* ────────────── Métodos de instancia ────────────── */
109
+ async save() {
110
+ // @ts-ignore
111
+ const id = this.id;
112
+ const Ctor = this.constructor;
113
+ const record = this.toJSON();
114
+ if (id === undefined || id === null) {
115
+ delete record.id;
116
+ const fresh = await Ctor.create(record);
117
+ Object.assign(this, fresh);
118
+ }
119
+ else {
120
+ await Ctor.update(String(id), record);
121
+ }
122
+ return this;
123
+ }
124
+ async update(patch) {
125
+ // @ts-ignore
126
+ const id = this.id;
127
+ if (id === undefined || id === null)
128
+ throw new Error("update() requiere id");
129
+ Object.assign(this, patch);
130
+ const Ctor = this.constructor;
131
+ await Ctor.update(String(id), this.toJSON());
132
+ return this;
133
+ }
134
+ async destroy() {
135
+ // @ts-ignore
136
+ const id = this.id;
137
+ if (id === undefined || id === null)
138
+ throw new Error("destroy() requiere id");
139
+ const Ctor = this.constructor;
140
+ await Ctor.destroy(String(id));
141
+ }
142
+ /* ─────────────── CRUD estáticos ──────────────── */
143
+ static async create(data) {
144
+ const meta = mustMeta(this);
145
+ const payload = new this(data).toJSON(); // filtrado
146
+ const put = () => client.send(new client_dynamodb_1.PutItemCommand({
147
+ TableName: meta.name,
148
+ Item: (0, util_dynamodb_1.marshall)(payload, { removeUndefinedValues: true }),
149
+ }));
150
+ try {
151
+ await put();
152
+ }
153
+ catch (err) {
154
+ if (err?.name === "ResourceNotFoundException") {
155
+ await createTable(this);
156
+ await put();
157
+ }
158
+ else
159
+ throw err;
160
+ }
161
+ return new this(data);
162
+ }
163
+ static async update(id, record // ← ya es JSON completo desde instancia
164
+ ) {
165
+ const meta = mustMeta(this);
166
+ const payload = { ...record, id };
167
+ const put = () => client.send(new client_dynamodb_1.PutItemCommand({
168
+ TableName: meta.name,
169
+ Item: (0, util_dynamodb_1.marshall)(payload, { removeUndefinedValues: true }),
170
+ }));
171
+ try {
172
+ await put();
173
+ }
174
+ catch (err) {
175
+ if (err?.name === "ResourceNotFoundException") {
176
+ await createTable(this);
177
+ await put();
178
+ }
179
+ else
180
+ throw err;
181
+ }
182
+ }
183
+ static async destroy(id) {
184
+ requireClient();
185
+ try {
186
+ await client.send(new client_dynamodb_1.DeleteItemCommand({
187
+ TableName: mustMeta(this).name,
188
+ Key: (0, util_dynamodb_1.marshall)({ id }),
189
+ }));
190
+ }
191
+ catch (err) {
192
+ if (err.name === "ResourceNotFoundException")
193
+ return null;
194
+ throw err;
195
+ }
196
+ return null;
197
+ }
198
+ static async where() {
199
+ requireClient();
200
+ try {
201
+ const res = await client.send(new client_dynamodb_1.ScanCommand({ TableName: mustMeta(this).name }));
202
+ return (res.Items ?? []).map((i) => new this((0, util_dynamodb_1.unmarshall)(i)));
203
+ }
204
+ catch (err) {
205
+ if (err.name === "ResourceNotFoundException")
206
+ return [];
207
+ throw err;
208
+ }
209
+ }
210
+ }
211
+ exports.default = Table;
212
+ /* ─────────────────── Utilidades internas ─────────────────── */
213
+ function requireClient() {
214
+ if (!client)
215
+ throw new Error("connect() debe llamarse antes de usar Table");
216
+ }
217
+ function mustMeta(ctor) {
218
+ const meta = wrapper_1.default.get(ctor);
219
+ if (!meta)
220
+ throw new Error(`Metadata no encontrada para ${ctor.name}`);
221
+ return meta;
222
+ }
223
+ //# sourceMappingURL=table.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"table.js","sourceRoot":"","sources":["../../src/core/table.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAoBA,0BAEC;AAtBD;;;;;;GAMG;AACH,8DAOkC;AAClC,0DAA8D;AAC9D,qDAAyD;AAgNhD,sFAhNS,eAAK,OAgNT;AA9Md,2EAA2E;AAC3E,IAAI,MAAkC,CAAC;AACvC,SAAgB,OAAO,CAAC,GAAyB;IAC/C,MAAM,GAAG,IAAI,gCAAc,CAAC,GAAG,CAAC,CAAC;AACnC,CAAC;AAED,2EAA2E;AAC3E,KAAK,UAAU,WAAW,CAAC,IAAc;IACvC,IAAI,CAAC,MAAM;QAAE,MAAM,IAAI,KAAK,CAAC,sBAAsB,CAAC,CAAC;IACrD,MAAM,IAAI,GAAG,iBAAO,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;IAC/B,IAAI,CAAC,IAAI;QAAE,MAAM,IAAI,KAAK,CAAC,SAAS,IAAI,CAAC,IAAI,2BAA2B,CAAC,CAAC;IAE1E,MAAM,IAAI,GAAG,CAAC,GAAG,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC;IACxC,MAAM,EAAE,GAAG,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC;IACrC,IAAI,CAAC,EAAE;QAAE,MAAM,IAAI,KAAK,CAAC,4BAA4B,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC;IAElE,MAAM,EAAE,GAAG,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC;IAEzC,MAAM,IAAI,GAAG,I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+ export type Inmutable = string | number | boolean | null | object;
2
+ export type Mutate = (value: any) => Inmutable;
3
+ export type Default = Inmutable | (() => Inmutable);
4
+ export type Validate = (value: any) => true | string;
5
+ export interface Column {
6
+ /** nombre físico en la tabla (DynamoDB) */
7
+ name: string;
8
+ default?: Default;
9
+ mutate?: Mutate[];
10
+ validate?: Validate[];
11
+ index?: true;
12
+ indexSort?: true;
13
+ unique?: true;
14
+ }
15
+ /**
16
+ * Configuración completa por tabla
17
+ */
18
+ export interface WrapperEntry {
19
+ /** Nombre físico de la tabla (snake_plural o @Name) */
20
+ name: string;
21
+ /** Columnas asociadas a la clase. key = propiedad (string|symbol) */
22
+ columns: Map<string | symbol, Column>;
23
+ }
24
+ export type Wrapper = Map<Function, WrapperEntry>;
25
+ /**
26
+ * Mapa singleton (clase → configuración)
27
+ * Exportado como default para uso interno de la librería.
28
+ */
29
+ declare const wrapper: Wrapper;
30
+ export default wrapper;
31
+ /**
32
+ * Buffer privado en cada instancia de Table donde se guardan
33
+ * los valores procesados por los setters virtuales.
34
+ *
35
+ * Se exporta para que los decoradores puedan leer/escribir,
36
+ * pero **NO** se vuelve a exportar desde la raíz del paquete.
37
+ */
38
+ export declare const STORE: unique symbol;
39
+ /**
40
+ * Asegura que exista la entrada en el wrapper para la clase dada.
41
+ * Devuelve la entrada (recién creada o existente).
42
+ */
43
+ export declare function ensureConfig(ctor: Function, tableName: string): WrapperEntry;
44
+ /**
45
+ * Obtiene (o crea) el objeto Column para una propiedad concreta.
46
+ */
47
+ export declare function ensureColumn(entry: WrapperEntry, prop: string | symbol, columnName: string): Column;
@@ -0,0 +1,57 @@
1
+ "use strict";
2
+ /* src/core/wrapper.ts
3
+ * -------------------------------------------------
4
+ * Registro central (in-memory) de la configuración
5
+ * declarativa de cada modelo. Agnóstico: no depende
6
+ * de DynamoDB ni de otros módulos de la librería.
7
+ *
8
+ * © 2025 Miguel Alejandro
9
+ */
10
+ Object.defineProperty(exports, "__esModule", { value: true });
11
+ exports.STORE = void 0;
12
+ exports.ensureConfig = ensureConfig;
13
+ exports.ensureColumn = ensureColumn;
14
+ /**
15
+ * Mapa singleton (clase → configuración)
16
+ * Exportado como default para uso interno de la librería.
17
+ */
18
+ const wrapper = new Map();
19
+ exports.default = wrapper;
20
+ /* ------------------------------------------------------------------ */
21
+ /* 4. Símbolo de almacenamiento de valores reales */
22
+ /* ------------------------------------------------------------------ */
23
+ /**
24
+ * Buffer privado en cada instancia de Table donde se guardan
25
+ * los valores procesados por los setters virtuales.
26
+ *
27
+ * Se exporta para que los decoradores puedan leer/escribir,
28
+ * pero **NO** se vuelve a exportar desde la raíz del paquete.
29
+ */
30
+ exports.STORE = Symbol("dynamite:values");
31
+ /* ------------------------------------------------------------------ */
32
+ /* 5. Pequeños helpers opcionales */
33
+ /* ------------------------------------------------------------------ */
34
+ /**
35
+ * Asegura que exista la entrada en el wrapper para la clase dada.
36
+ * Devuelve la entrada (recién creada o existente).
37
+ */
38
+ function ensureConfig(ctor, tableName) {
39
+ let entry = wrapper.get(ctor);
40
+ if (!entry) {
41
+ entry = { name: tableName, columns: new Map() };
42
+ wrapper.set(ctor, entry);
43
+ }
44
+ return entry;
45
+ }
46
+ /**
47
+ * Obtiene (o crea) el objeto Column para una propiedad concreta.
48
+ */
49
+ function ensureColumn(entry, prop, columnName) {
50
+ let col = entry.columns.get(prop);
51
+ if (!col) {
52
+ col = { name: columnName, mutate: [], validate: [] };
53
+ entry.columns.set(prop, col);
54
+ }
55
+ return col;
56
+ }
57
+ //# sourceMappingURL=wrapper.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"wrapper.js","sourceRoot":"","sources":["../../src/core/wrapper.ts"],"names":[],"mappings":";AAAA;;;;;;;GAOG;;;AAwEH,oCAOC;AAKD,oCAWC;AAlDD;;;GAGG;AACH,MAAM,OAAO,GAAY,IAAI,GAAG,EAAE,CAAC;AACnC,kBAAe,OAAO,CAAC;AAEvB,wEAAwE;AACxE,wEAAwE;AACxE,wEAAwE;AACxE;;;;;;GAMG;AACU,QAAA,KAAK,GAAkB,MAAM,CAAC,iBAAiB,CAAC,CAAC;AAE9D,wEAAwE;AACxE,wEAAwE;AACxE,wEAAwE;AAExE;;;GAGG;AACH,SAAgB,YAAY,CAAC,IAAc,EAAE,SAAiB;IAC5D,IAAI,KAAK,GAAG,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;IAC9B,IAAI,CAAC,KAAK,EAAE,CAAC;QACX,KAAK,GAAG,EAAE,IAAI,EAAE,SAAS,EAAE,OAAO,EAAE,IAAI,GAAG,EAAE,EAAE,CAAC;QAChD,OAAO,CAAC,GAAG,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;IAC3B,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC;AAED;;GAEG;AACH,SAAgB,YAAY,CAC1B,KAAmB,EACnB,IAAqB,EACrB,UAAkB;IAElB,IAAI,GAAG,GAAG,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;IAClC,IAAI,CAAC,GAAG,EAAE,CAAC;QACT,GAAG,GAAG,EAAE,IAAI,EAAE,UAAU,EAAE,MAAM,EAAE,EAAE,EAAE,QAAQ,EAAE,EAAE,EAAE,CAAC;QACrD,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC;IAC/B,CAAC;IACD,OAAO,GAAG,CAAC;AACb,CAAC"}
@@ -0,0 +1,4 @@
1
+ /**
2
+ * Asigna automáticamente la fecha de creación en nuevas instancias.
3
+ */
4
+ export default function CreatedAt(): PropertyDecorator;
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ /*
3
+ * Dinamite ORM — @CreatedAt Decorator (wrapper)
4
+ * -------------------------------------------
5
+ * Establece un valor por defecto con la fecha/hora actual (ISO‑string)
6
+ * usando @Default.
7
+ *
8
+ * © 2025 Miguel Alejandro
9
+ */
10
+ var __importDefault = (this && this.__importDefault) || function (mod) {
11
+ return (mod && mod.__esModule) ? mod : { "default": mod };
12
+ };
13
+ Object.defineProperty(exports, "__esModule", { value: true });
14
+ exports.default = CreatedAt;
15
+ const default_1 = __importDefault(require("./default"));
16
+ /**
17
+ * Asigna automáticamente la fecha de creación en nuevas instancias.
18
+ */
19
+ function CreatedAt() {
20
+ return (0, default_1.default)(() => new Date().toISOString());
21
+ }
22
+ //# sourceMappingURL=created_at.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"created_at.js","sourceRoot":"","sources":["../../src/decorators/created_at.ts"],"names":[],"mappings":";AAAA;;;;;;;GAOG;;;;;AAOH,4BAEC;AAPD,wDAAgC;AAEhC;;GAEG;AACH,SAAwB,SAAS;IAC/B,OAAO,IAAA,iBAAO,EAAC,GAAG,EAAE,CAAC,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE,CAAC,CAAC;AACjD,CAAC"}
@@ -0,0 +1 @@
1
+ export default function Default(factory: () => unknown): PropertyDecorator;
@@ -0,0 +1,55 @@
1
+ "use strict";
2
+ /*
3
+ * Dinamite ORM — @Default
4
+ * -----------------------
5
+ * Registra un valor por defecto y crea (si falta) el
6
+ * getter/setter virtual de la propiedad.
7
+ */
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.default = Default;
10
+ const wrapper_1 = require("../core/wrapper");
11
+ const naming_1 = require("../utils/naming");
12
+ function Default(factory) {
13
+ if (typeof factory !== "function") {
14
+ throw new TypeError("@Default requiere una función factory");
15
+ }
16
+ return (target, prop) => {
17
+ const ctor = target.constructor;
18
+ const entry = (0, wrapper_1.ensureConfig)(ctor, (0, naming_1.toSnakePlural)(ctor.name));
19
+ const column = (0, wrapper_1.ensureColumn)(entry, prop, String(prop));
20
+ if (column.default)
21
+ throw new Error(`@Default duplicado en '${String(prop)}'`);
22
+ column.default = factory;
23
+ if (!Object.getOwnPropertyDescriptor(ctor.prototype, prop)?.set) {
24
+ defineVirtual(ctor.prototype, column, prop);
25
+ }
26
+ };
27
+ }
28
+ /* ------------------------------------------------------------------ */
29
+ function defineVirtual(proto, col, prop) {
30
+ Object.defineProperty(proto, prop, {
31
+ get() {
32
+ return (this[wrapper_1.STORE] ?? {})[prop];
33
+ },
34
+ set(val) {
35
+ const buf = (this[wrapper_1.STORE] ??= {});
36
+ if (val === undefined && col.default !== undefined) {
37
+ val = typeof col.default === "function" ? col.default() : col.default;
38
+ }
39
+ if (col.mutate)
40
+ for (const m of col.mutate)
41
+ val = m(val);
42
+ if (col.validate) {
43
+ for (const v of col.validate) {
44
+ const r = v(val);
45
+ if (r !== true)
46
+ throw new Error(typeof r === "string" ? r : "Validación fallida");
47
+ }
48
+ }
49
+ buf[prop] = val;
50
+ },
51
+ enumerable: true,
52
+ configurable: true,
53
+ });
54
+ }
55
+ //# sourceMappingURL=default.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"default.js","sourceRoot":"","sources":["../../src/decorators/default.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;AAKH,0BAkBC;AArBD,6CAA4E;AAC5E,4CAAgD;AAEhD,SAAwB,OAAO,CAAC,OAAsB;IACpD,IAAI,OAAO,OAAO,KAAK,UAAU,EAAE,CAAC;QAClC,MAAM,IAAI,SAAS,CAAC,uCAAuC,CAAC,CAAC;IAC/D,CAAC;IAED,OAAO,CAAC,MAAc,EAAE,IAAqB,EAAQ,EAAE;QACrD,MAAM,IAAI,GAAI,MAAc,CAAC,WAAW,CAAC;QACzC,MAAM,KAAK,GAAG,IAAA,sBAAY,EAAC,IAAI,EAAE,IAAA,sBAAa,EAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;QAC3D,MAAM,MAAM,GAAG,IAAA,sBAAY,EAAC,KAAK,EAAE,IAAI,EAAE,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC;QAEvD,IAAI,MAAM,CAAC,OAAO;YAChB,MAAM,IAAI,KAAK,CAAC,0BAA0B,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QAC7D,MAAM,CAAC,OAAO,GAAG,OAAO,CAAC;QAEzB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,CAAC;YACD,GAAG,CAAC,IAAI,CAAC,GAAG,GAAG,CAAC;QAClB,CAAC;QACD,UAAU,EAAE,IAAI;QAChB,YAAY,EAAE,IAAI;KACnB,CAAC,CAAC;AACL,CAAC"}
@@ -0,0 +1 @@
1
+ export default function Index(): PropertyDecorator;
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ /*
3
+ * Dinamite ORM — @Index (Partition Key)
4
+ * -------------------------------------
5
+ * Marca la propiedad como clave de partición.
6
+ */
7
+ Object.defineProperty(exports, "__esModule", { value: true });
8
+ exports.default = Index;
9
+ const wrapper_1 = require("../core/wrapper");
10
+ const naming_1 = require("../utils/naming");
11
+ function Index() {
12
+ return (target, prop) => {
13
+ const ctor = target.constructor;
14
+ const entry = (0, wrapper_1.ensureConfig)(ctor, (0, naming_1.toSnakePlural)(ctor.name));
15
+ /* Evitar duplicados */
16
+ const already = [...entry.columns.values()].find((c) => c.index);
17
+ if (already && already !== entry.columns.get(prop)) {
18
+ throw new Error(`La tabla ${ctor.name} ya tiene PartitionKey (${already.name})`);
19
+ }
20
+ const col = (0, wrapper_1.ensureColumn)(entry, prop, String(prop));
21
+ col.index = true;
22
+ };
23
+ }
24
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/decorators/index.ts"],"names":[],"mappings":";AAAA;;;;GAIG;;AAKH,wBAgBC;AAnBD,6CAA6D;AAC7D,4CAAgD;AAEhD,SAAwB,KAAK;IAC3B,OAAO,CAAC,MAAc,EAAE,IAAqB,EAAQ,EAAE;QACrD,MAAM,IAAI,GAAI,MAAc,CAAC,WAAW,CAAC;QACzC,MAAM,KAAK,GAAG,IAAA,sBAAY,EAAC,IAAI,EAAE,IAAA,sBAAa,EAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;QAE3D,uBAAuB;QACvB,MAAM,OAAO,GAAG,CAAC,GAAG,KAAK,CAAC,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC;QACjE,IAAI,OAAO,IAAI,OAAO,KAAK,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC;YACnD,MAAM,IAAI,KAAK,CACb,YAAY,IAAI,CAAC,IAAI,2BAA2B,OAAO,CAAC,IAAI,GAAG,CAChE,CAAC;QACJ,CAAC;QAED,MAAM,GAAG,GAAG,IAAA,sBAAY,EAAC,KAAK,EAAE,IAAI,EAAE,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC;QACpD,GAAG,CAAC,KAAK,GAAG,IAAI,CAAC;IACnB,CAAC,CAAC;AACJ,CAAC"}
@@ -0,0 +1 @@
1
+ export default function IndexSort(): PropertyDecorator;
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+ /*
3
+ * Dinamite ORM — @IndexSort (Sort Key)
4
+ * ------------------------------------
5
+ * Marca la propiedad como clave de ordenamiento.
6
+ */
7
+ Object.defineProperty(exports, "__esModule", { value: true });
8
+ exports.default = IndexSort;
9
+ const wrapper_1 = require("../core/wrapper");
10
+ const naming_1 = require("../utils/naming");
11
+ function IndexSort() {
12
+ return (target, prop) => {
13
+ const ctor = target.constructor;
14
+ const entry = (0, wrapper_1.ensureConfig)(ctor, (0, naming_1.toSnakePlural)(ctor.name));
15
+ const pkExists = [...entry.columns.values()].some((c) => c.index);
16
+ if (!pkExists) {
17
+ throw new Error(`PartitionKey no definido en ${ctor.name}; declara @Index primero`);
18
+ }
19
+ const already = [...entry.columns.values()].find((c) => c.indexSort);
20
+ if (already && already !== entry.columns.get(prop)) {
21
+ throw new Error(`La tabla ${ctor.name} ya tiene SortKey (${already.name})`);
22
+ }
23
+ const col = (0, wrapper_1.ensureColumn)(entry, prop, String(prop));
24
+ col.indexSort = true;
25
+ };
26
+ }
27
+ //# sourceMappingURL=index_sort.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index_sort.js","sourceRoot":"","sources":["../../src/decorators/index_sort.ts"],"names":[],"mappings":";AAAA;;;;GAIG;;AAKH,4BAsBC;AAzBD,6CAA6D;AAC7D,4CAAgD;AAEhD,SAAwB,SAAS;IAC/B,OAAO,CAAC,MAAc,EAAE,IAAqB,EAAQ,EAAE;QACrD,MAAM,IAAI,GAAI,MAAc,CAAC,WAAW,CAAC;QACzC,MAAM,KAAK,GAAG,IAAA,sBAAY,EAAC,IAAI,EAAE,IAAA,sBAAa,EAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;QAE3D,MAAM,QAAQ,GAAG,CAAC,GAAG,KAAK,CAAC,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC;QAClE,IAAI,CAAC,QAAQ,EAAE,CAAC;YACd,MAAM,IAAI,KAAK,CACb,+BAA+B,IAAI,CAAC,IAAI,0BAA0B,CACnE,CAAC;QACJ,CAAC;QAED,MAAM,OAAO,GAAG,CAAC,GAAG,KAAK,CAAC,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC;QACrE,IAAI,OAAO,IAAI,OAAO,KAAK,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC;YACnD,MAAM,IAAI,KAAK,CACb,YAAY,IAAI,CAAC,IAAI,sBAAsB,OAAO,CAAC,IAAI,GAAG,CAC3D,CAAC;QACJ,CAAC;QAED,MAAM,GAAG,GAAG,IAAA,sBAAY,EAAC,KAAK,EAAE,IAAI,EAAE,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC;QACpD,GAAG,CAAC,SAAS,GAAG,IAAI,CAAC;IACvB,CAAC,CAAC;AACJ,CAAC"}
@@ -0,0 +1,2 @@
1
+ import type { Mutate } from "../core/wrapper";
2
+ export default function Mutate(fn: Mutate): PropertyDecorator;
@@ -0,0 +1,53 @@
1
+ "use strict";
2
+ /*
3
+ * Dinamite ORM — @Mutate
4
+ * ----------------------
5
+ * Registra funciones transformadoras para un campo y virtualiza
6
+ * la propiedad si aún no existe.
7
+ */
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.default = Mutate;
10
+ const wrapper_1 = require("../core/wrapper");
11
+ const naming_1 = require("../utils/naming");
12
+ function Mutate(fn) {
13
+ if (typeof fn !== "function")
14
+ throw new TypeError("@Mutate requiere función");
15
+ return (target, prop) => {
16
+ const ctor = target.constructor;
17
+ const entry = (0, wrapper_1.ensureConfig)(ctor, (0, naming_1.toSnakePlural)(ctor.name));
18
+ const col = (0, wrapper_1.ensureColumn)(entry, prop, String(prop));
19
+ col.mutate ??= [];
20
+ col.mutate.push(fn);
21
+ if (!Object.getOwnPropertyDescriptor(ctor.prototype, prop)?.set) {
22
+ defineVirtual(ctor.prototype, col, prop);
23
+ }
24
+ };
25
+ }
26
+ /* ------------------------------------------------------------------ */
27
+ function defineVirtual(proto, col, prop) {
28
+ Object.defineProperty(proto, prop, {
29
+ get() {
30
+ return (this[wrapper_1.STORE] ?? {})[prop];
31
+ },
32
+ set(val) {
33
+ const buf = (this[wrapper_1.STORE] ??= {});
34
+ if (val === undefined && col.default !== undefined) {
35
+ val = typeof col.default === "function" ? col.default() : col.default;
36
+ }
37
+ if (col.mutate)
38
+ for (const m of col.mutate)
39
+ val = m(val);
40
+ if (col.validate) {
41
+ for (const v of col.validate) {
42
+ const r = v(val);
43
+ if (r !== true)
44
+ throw new Error(typeof r === "string" ? r : "Validación fallida");
45
+ }
46
+ }
47
+ buf[prop] = val;
48
+ },
49
+ enumerable: true,
50
+ configurable: true,
51
+ });
52
+ }
53
+ //# sourceMappingURL=mutate.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mutate.js","sourceRoot":"","sources":["../../src/decorators/mutate.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;AAMH,yBA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CAAC,OAAO,KAAK,UAAU,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC;YACxE,CAAC;YACD,IAAI,GAAG,CAAC,MAAM;gBAAE,KAAK,MAAM,CAAC,IAAI,GAAG,CAAC,MAAM;oBAAE,GAAG,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC;YACzD,IAAI,GAAG,CAAC,QAAQ,EAAE,CAAC;gBACjB,KAAK,MAAM,CAAC,IAAI,GAAG,CAAC,QAAQ,EAAE,CAAC;oBAC7B,MAAM,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC;oBACjB,IAAI,CAAC,KAAK,IAAI;wBACZ,MAAM,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,oBAAoB,CAAC,CAAC;gBACtE,CAAC;YACH,CAAC;YACD,GAAG,CAAC,IAAI,CAAC,GAAG,GAAG,CAAC;QAClB,CAAC;QACD,UAAU,EAAE,IAAI;QAChB,YAAY,EAAE,IAAI;KACnB,CAAC,CAAC;AACL,CAAC"}
@@ -0,0 +1 @@
1
+ export default function Name(label: string): ClassDecorator & PropertyDecorator;
@@ -0,0 +1,41 @@
1
+ "use strict";
2
+ /*
3
+ * Dinamite ORM — @Name
4
+ * --------------------
5
+ * • @Name("tabla") → nombre físico de la tabla
6
+ * • @Name("columna") → alias de columna
7
+ *
8
+ * Permite sobrescribir el nombre AUTO-generado (snake_plural)
9
+ * sin lanzar conflicto.
10
+ */
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.default = Name;
13
+ const wrapper_1 = require("../core/wrapper");
14
+ const naming_1 = require("../utils/naming");
15
+ function Name(label) {
16
+ if (!label || typeof label !== "string") {
17
+ throw new TypeError("@Name requiere una cadena no vacía");
18
+ }
19
+ return (target, prop) => {
20
+ const ctor = prop === undefined ? target : target.constructor;
21
+ const entry = (0, wrapper_1.ensureConfig)(ctor, (0, naming_1.toSnakePlural)(ctor.name));
22
+ if (prop === undefined) {
23
+ /* ---------- Nombre de la tabla ---------- */
24
+ const auto = (0, naming_1.toSnakePlural)(ctor.name);
25
+ // Solo error si ya se modificó conscientemente antes.
26
+ if (entry.name !== auto && entry.name !== label && entry.name) {
27
+ throw new Error(`La clase ${ctor.name} ya tiene un @Name distinto (${entry.name})`);
28
+ }
29
+ entry.name = label;
30
+ }
31
+ else {
32
+ /* ---------- Alias de columna ---------- */
33
+ const col = (0, wrapper_1.ensureColumn)(entry, prop, label);
34
+ if (col.name && col.name !== label) {
35
+ throw new Error(`La columna '${String(prop)}' ya tiene @Name distinto (${col.name})`);
36
+ }
37
+ col.name = label;
38
+ }
39
+ };
40
+ }
41
+ //# sourceMappingURL=name.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"name.js","sourceRoot":"","sources":["../../src/decorators/name.ts"],"names":[],"mappings":";AAAA;;;;;;;;GAQG;;AAKH,uBAoCC;AAvCD,6CAA6D;AAC7D,4CAAgD;AAEhD,SAAwB,IAAI,CAC1B,KAAa;IAEb,IAAI,CAAC,KAAK,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;QACxC,MAAM,IAAI,SAAS,CAAC,oCAAoC,CAAC,CAAC;IAC5D,CAAC;IAED,OAAO,CAAC,MAAW,EAAE,IAAsB,EAAQ,EAAE;QACnD,MAAM,IAAI,GAAG,IAAI,KAAK,SAAS,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,WAAW,CAAC;QAC9D,MAAM,KAAK,GAAG,IAAA,sBAAY,EAAC,IAAI,EAAE,IAAA,sBAAa,EAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;QAE3D,IAAI,IAAI,KAAK,SAAS,EAAE,CAAC;YACvB,8CAA8C;YAE9C,MAAM,IAAI,GAAG,IAAA,sBAAa,EAAC,IAAI,CAAC,IAAI,CAAC,CAAC;YAEtC,sDAAsD;YACtD,IAAI,KAAK,CAAC,IAAI,KAAK,IAAI,IAAI,KAAK,CAAC,IAAI,KAAK,KAAK,IAAI,KAAK,CAAC,IAAI,EAAE,CAAC;gBAC9D,MAAM,IAAI,KAAK,CACb,YAAY,IAAI,CAAC,IAAI,gCAAgC,KAAK,CAAC,IAAI,GAAG,CACnE,CAAC;YACJ,CAAC;YACD,KAAK,CAAC,IAAI,GAAG,KAAK,CAAC;QACrB,CAAC;aAAM,CAAC;YACN,4CAA4C;YAE5C,MAAM,GAAG,GAAG,IAAA,sBAAY,EAAC,KAAK,EAAE,IAAI,EAAE,KAAK,CAAC,CAAC;YAE7C,IAAI,GAAG,CAAC,IAAI,IAAI,GAAG,CAAC,IAAI,KAAK,KAAK,EAAE,CAAC;gBACnC,MAAM,IAAI,KAAK,CACb,eAAe,MAAM,CAAC,IAAI,CAAC,8BAA8B,GAAG,CAAC,IAAI,GAAG,CACrE,CAAC;YACJ,CAAC;YACD,GAAG,CAAC,IAAI,GAAG,KAAK,CAAC;QACnB,CAAC;IACH,CAAC,CAAC;AACJ,CAAC"}
@@ -0,0 +1,4 @@
1
+ /**
2
+ * Decorador wrapper que asegura no-null / no-empty.
3
+ */
4
+ export default function NotNull(): PropertyDecorator;
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+ /*
3
+ * Dinamite ORM — @NotNull Decorator (wrapper)
4
+ * ------------------------------------------
5
+ * Valida que el valor no sea null, undefined ni cadena vacía.
6
+ * Internamente aplica @Validate con una función sincrónica.
7
+ *
8
+ * © 2025 Miguel Alejandro
9
+ */
10
+ var __importDefault = (this && this.__importDefault) || function (mod) {
11
+ return (mod && mod.__esModule) ? mod : { "default": mod };
12
+ };
13
+ Object.defineProperty(exports, "__esModule", { value: true });
14
+ exports.default = NotNull;
15
+ const validate_1 = __importDefault(require("./validate"));
16
+ /**
17
+ * Decorador wrapper que asegura no-null / no-empty.
18
+ */
19
+ function NotNull() {
20
+ return validate_1.default((value, key) => {
21
+ if (value === null || value === undefined)
22
+ return false;
23
+ if (typeof value === "string" && value.trim() === "")
24
+ return false;
25
+ return true;
26
+ });
27
+ }
28
+ //# sourceMappingURL=not_null.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"not_null.js","sourceRoot":"","sources":["../../src/decorators/not_null.ts"],"names":[],"mappings":";AAAA;;;;;;;GAOG;;;;;AAOH,0BAMC;AAXD,0DAAkC;AAElC;;GAEG;AACH,SAAwB,OAAO;IAC7B,OAAQ,kBAAgB,CAAC,CAAC,KAAK,EAAE,GAAG,EAAE,EAAE;QACtC,IAAI,KAAK,KAAK,IAAI,IAAI,KAAK,KAAK,SAAS;YAAE,OAAO,KAAK,CAAC;QACxD,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,CAAC,IAAI,EAAE,KAAK,EAAE;YAAE,OAAO,KAAK,CAAC;QACnE,OAAO,IAAI,CAAC;IACd,CAAC,CAAC,CAAC;AACL,CAAC"}
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Atajo para definir clave primaria compuesta (PK + SK).
3
+ * El parámetro `name` queda reservado por si en el futuro
4
+ * se almacena un identificador lógico de índice, pero hoy
5
+ * NO se pasa a ningún decorador interno.
6
+ */
7
+ export default function PrimaryKey(name?: string): PropertyDecorator;
@@ -0,0 +1,30 @@
1
+ "use strict";
2
+ /*
3
+ * Dinamite ORM — @PrimaryKey
4
+ * --------------------------
5
+ * Declara simultáneamente Partition Key y Sort Key
6
+ * sobre la misma propiedad.
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.default = PrimaryKey;
13
+ const index_1 = __importDefault(require("./index"));
14
+ const index_sort_1 = __importDefault(require("./index_sort"));
15
+ /**
16
+ * Atajo para definir clave primaria compuesta (PK + SK).
17
+ * El parámetro `name` queda reservado por si en el futuro
18
+ * se almacena un identificador lógico de índice, pero hoy
19
+ * NO se pasa a ningún decorador interno.
20
+ */
21
+ function PrimaryKey(name = "primary") {
22
+ if (typeof name !== "string" || !name.trim()) {
23
+ throw new TypeError("@PrimaryKey requiere un nombre de índice válido");
24
+ }
25
+ return (target, prop) => {
26
+ (0, index_1.default)()(target, prop); // Partition Key
27
+ (0, index_sort_1.default)()(target, prop); // Sort Key
28
+ };
29
+ }
30
+ //# sourceMappingURL=primary_key.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"primary_key.js","sourceRoot":"","sources":["../../src/decorators/primary_key.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;;;AAWH,6BASC;AAlBD,oDAA4B;AAC5B,8DAAqC;AAErC;;;;;GAKG;AACH,SAAwB,UAAU,CAAC,IAAI,GAAG,SAAS;IACjD,IAAI,OAAO,IAAI,KAAK,QAAQ,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,EAAE,CAAC;QAC7C,MAAM,IAAI,SAAS,CAAC,iDAAiD,CAAC,CAAC;IACzE,CAAC;IAED,OAAO,CAAC,MAAc,EAAE,IAAqB,EAAQ,EAAE;QACrD,IAAA,eAAK,GAAE,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC,CAAC,gBAAgB;QACvC,IAAA,oBAAS,GAAE,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC,CAAC,WAAW;IACxC,CAAC,CAAC;AACJ,CAAC"}
@@ -0,0 +1,4 @@
1
+ /**
2
+ * Actualiza automáticamente la marca temporal en cada asignación.
3
+ */
4
+ export default function UpdatedAt(): PropertyDecorator;
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ /*
3
+ * Dinamite ORM — @UpdatedAt Decorator (wrapper)
4
+ * --------------------------------------------
5
+ * Actualiza la fecha/hora cada vez que la propiedad recibe un nuevo valor
6
+ * (incluyendo actualizaciones mediante Model.save()).
7
+ * Internamente aplica @Mutate con una factory de timestamp ISO.
8
+ *
9
+ * © 2025 Miguel Alejandro
10
+ */
11
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.default = UpdatedAt;
16
+ const mutate_1 = __importDefault(require("./mutate"));
17
+ /**
18
+ * Actualiza automáticamente la marca temporal en cada asignación.
19
+ */
20
+ function UpdatedAt() {
21
+ return (0, mutate_1.default)(() => new Date().toISOString());
22
+ }
23
+ //# sourceMappingURL=updated_at.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"updated_at.js","sourceRoot":"","sources":["../../src/decorators/updated_at.ts"],"names":[],"mappings":";AAAA;;;;;;;;GAQG;;;;;AAOH,4BAEC;AAPD,sDAA8B;AAE9B;;GAEG;AACH,SAAwB,SAAS;IAC/B,OAAO,IAAA,gBAAM,EAAC,GAAG,EAAE,CAAC,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE,CAAC,CAAC;AAChD,CAAC"}
@@ -0,0 +1 @@
1
+ export default function Validate(validators: ((v: unknown) => true | string) | ((v: unknown) => true | string)[]): PropertyDecorator;
@@ -0,0 +1,54 @@
1
+ "use strict";
2
+ /*
3
+ * Dinamite ORM — @Validate
4
+ * ------------------------
5
+ * Registra validadores y crea virtual si falta.
6
+ */
7
+ Object.defineProperty(exports, "__esModule", { value: true });
8
+ exports.default = Validate;
9
+ const wrapper_1 = require("../core/wrapper");
10
+ const naming_1 = require("../utils/naming");
11
+ function Validate(validators) {
12
+ const list = Array.isArray(validators) ? validators : [validators];
13
+ if (!list.length || list.some((v) => typeof v !== "function")) {
14
+ throw new TypeError("@Validate requiere funciones");
15
+ }
16
+ return (target, prop) => {
17
+ const ctor = target.constructor;
18
+ const entry = (0, wrapper_1.ensureConfig)(ctor, (0, naming_1.toSnakePlural)(ctor.name));
19
+ const col = (0, wrapper_1.ensureColumn)(entry, prop, String(prop));
20
+ col.validate ??= [];
21
+ col.validate.push(...list);
22
+ if (!Object.getOwnPropertyDescriptor(ctor.prototype, prop)?.set) {
23
+ defineVirtual(ctor.prototype, col, prop);
24
+ }
25
+ };
26
+ }
27
+ /* ------------------------------------------------------------------ */
28
+ function defineVirtual(proto, col, prop) {
29
+ Object.defineProperty(proto, prop, {
30
+ get() {
31
+ return (this[wrapper_1.STORE] ?? {})[prop];
32
+ },
33
+ set(val) {
34
+ const buf = (this[wrapper_1.STORE] ??= {});
35
+ if (val === undefined && col.default !== undefined) {
36
+ val = typeof col.default === "function" ? col.default() : col.default;
37
+ }
38
+ if (col.mutate)
39
+ for (const m of col.mutate)
40
+ val = m(val);
41
+ if (col.validate) {
42
+ for (const v of col.validate) {
43
+ const r = v(val);
44
+ if (r !== true)
45
+ throw new Error(typeof r === "string" ? r : "Validación fallida");
46
+ }
47
+ }
48
+ buf[prop] = val;
49
+ },
50
+ enumerable: true,
51
+ configurable: true,
52
+ });
53
+ }
54
+ //# sourceMappingURL=validate.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"validate.js","sourceRoot":"","sources":["../../src/decorators/validate.ts"],"names":[],"mappings":";AAAA;;;;GAIG;;AAKH,2BAsBC;AAzBD,6CAA4E;AAC5E,4CAAgD;AAEhD,SAAwB,QAAQ,CAC9B,UAEqC;IAErC,MAAM,IAAI,GAAG,KAAK,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC;IACnE,IAAI,CAAC,IAAI,CAAC,MAAM,IAAI,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,OAAO,CAAC,KAAK,UAAU,CAAC,EAAE,CAAC;QAC9D,MAAM,IAAI,SAAS,CAAC,8BAA8B,CAAC,CAAC;IACtD,CAAC;IAED,OAAO,CAAC,MAAc,EAAE,IAAqB,EAAQ,EAAE;QACrD,MAAM,IAAI,GAAI,MAAc,CAAC,WAAW,CAAC;QACzC,MAAM,KAAK,GAAG,IAAA,sBAAY,EAAC,IAAI,EAAE,IAAA,sBAAa,EAAC,IAAI,CAAC,IAAI,CA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,EAAE,CAAC;oBAC7B,MAAM,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC;oBACjB,IAAI,CAAC,KAAK,IAAI;wBACZ,MAAM,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,oBAAoB,CAAC,CAAC;gBACtE,CAAC;YACH,CAAC;YACD,GAAG,CAAC,IAAI,CAAC,GAAG,GAAG,CAAC;QAClB,CAAC;QACD,UAAU,EAAE,IAAI;QAChB,YAAY,EAAE,IAAI;KACnB,CAAC,CAAC;AACL,CAAC"}
package/build/index.d.ts CHANGED
@@ -1,130 +1,11 @@
1
- declare module "core/wrapper" {
2
- export type Inmutable = string | number | boolean | null | object;
3
- export type Mutate = (value: any) => Inmutable;
4
- export type Default = Inmutable | (() => Inmutable);
5
- export type Validate = (value: any) => true | string;
6
- export interface Column {
7
- /** nombre físico en la tabla (DynamoDB) */
8
- name: string;
9
- default?: Default;
10
- mutate?: Mutate[];
11
- validate?: Validate[];
12
- index?: true;
13
- indexSort?: true;
14
- unique?: true;
15
- }
16
- /**
17
- * Configuración completa por tabla
18
- */
19
- export interface WrapperEntry {
20
- /** Nombre físico de la tabla (snake_plural o @Name) */
21
- name: string;
22
- /** Columnas asociadas a la clase. key = propiedad (string|symbol) */
23
- columns: Map<string | symbol, Column>;
24
- }
25
- export type Wrapper = Map<Function, WrapperEntry>;
26
- /**
27
- * Mapa singleton (clase → configuración)
28
- * Exportado como default para uso interno de la librería.
29
- */
30
- const wrapper: Wrapper;
31
- export default wrapper;
32
- /**
33
- * Buffer privado en cada instancia de Table donde se guardan
34
- * los valores procesados por los setters virtuales.
35
- *
36
- * Se exporta para que los decoradores puedan leer/escribir,
37
- * pero **NO** se vuelve a exportar desde la raíz del paquete.
38
- */
39
- export const STORE: unique symbol;
40
- /**
41
- * Asegura que exista la entrada en el wrapper para la clase dada.
42
- * Devuelve la entrada (recién creada o existente).
43
- */
44
- export function ensureConfig(ctor: Function, tableName: string): WrapperEntry;
45
- /**
46
- * Obtiene (o crea) el objeto Column para una propiedad concreta.
47
- */
48
- export function ensureColumn(entry: WrapperEntry, prop: string | symbol, columnName: string): Column;
49
- }
50
- declare module "core/table" {
51
- import { DynamoDBClientConfig } from "@aws-sdk/client-dynamodb";
52
- import { STORE, WrapperEntry } from "core/wrapper";
53
- export function connect(cfg: DynamoDBClientConfig): void;
54
- export default class Table<T extends object = object> {
55
- private [STORE];
56
- constructor(data?: Partial<T>);
57
- toJSON(): Record<string, unknown>;
58
- save(): Promise<this>;
59
- update(patch: Partial<T>): Promise<this>;
60
- destroy(): Promise<void>;
61
- static create<M extends Table>(this: new (d?: Partial<M>) => M, data: Partial<M>): Promise<M>;
62
- static update<M extends Table>(this: new (d?: Partial<M>) => M, id: string, record: Partial<M>): Promise<void>;
63
- static destroy<M extends Table>(this: new () => M, id: string): Promise<null>;
64
- static where<M extends Table>(this: new (d?: any) => M): Promise<M[]>;
65
- }
66
- export { STORE };
67
- export type { WrapperEntry };
68
- }
69
- declare module "utils/naming" {
70
- export function toSnakePlural(input: string): string;
71
- }
72
- declare module "decorators/default" {
73
- export default function Default(factory: () => unknown): PropertyDecorator;
74
- }
75
- declare module "decorators/index" {
76
- export default function Index(): PropertyDecorator;
77
- }
78
- declare module "decorators/index_sort" {
79
- export default function IndexSort(): PropertyDecorator;
80
- }
81
- declare module "decorators/mutate" {
82
- import type { Mutate } from "core/wrapper";
83
- export default function Mutate(fn: Mutate): PropertyDecorator;
84
- }
85
- declare module "decorators/name" {
86
- export default function Name(label: string): ClassDecorator & PropertyDecorator;
87
- }
88
- declare module "decorators/validate" {
89
- export default function Validate(validators: ((v: unknown) => true | string) | ((v: unknown) => true | string)[]): PropertyDecorator;
90
- }
91
- declare module "decorators/created_at" {
92
- /**
93
- * Asigna automáticamente la fecha de creación en nuevas instancias.
94
- */
95
- export default function CreatedAt(): PropertyDecorator;
96
- }
97
- declare module "decorators/not_null" {
98
- /**
99
- * Decorador wrapper que asegura no-null / no-empty.
100
- */
101
- export default function NotNull(): PropertyDecorator;
102
- }
103
- declare module "decorators/primary_key" {
104
- /**
105
- * Atajo para definir clave primaria compuesta (PK + SK).
106
- * El parámetro `name` queda reservado por si en el futuro
107
- * se almacena un identificador lógico de índice, pero hoy
108
- * NO se pasa a ningún decorador interno.
109
- */
110
- export default function PrimaryKey(name?: string): PropertyDecorator;
111
- }
112
- declare module "decorators/updated_at" {
113
- /**
114
- * Actualiza automáticamente la marca temporal en cada asignación.
115
- */
116
- export default function UpdatedAt(): PropertyDecorator;
117
- }
118
- declare module "index" {
119
- export { connect, default as Table } from "core/table";
120
- export { default as Default } from "decorators/default";
121
- export { default as Index } from "decorators/index";
122
- export { default as IndexSort } from "decorators/index_sort";
123
- export { default as Mutate } from "decorators/mutate";
124
- export { default as Name } from "decorators/name";
125
- export { default as Validate } from "decorators/validate";
126
- export { default as CreatedAt } from "decorators/created_at";
127
- export { default as NotNull } from "decorators/not_null";
128
- export { default as PrimaryKey } from "decorators/primary_key";
129
- export { default as UpdatedAt } from "decorators/updated_at";
130
- }
1
+ export { connect, default as Table } from "./core/table";
2
+ export { default as Default } from "./decorators/default";
3
+ export { default as Index } from "./decorators/index";
4
+ export { default as IndexSort } from "./decorators/index_sort";
5
+ export { default as Mutate } from "./decorators/mutate";
6
+ export { default as Name } from "./decorators/name";
7
+ export { default as Validate } from "./decorators/validate";
8
+ export { default as CreatedAt } from "./decorators/created_at";
9
+ export { default as NotNull } from "./decorators/not_null";
10
+ export { default as PrimaryKey } from "./decorators/primary_key";
11
+ export { default as UpdatedAt } from "./decorators/updated_at";
@@ -0,0 +1 @@
1
+ export declare function toSnakePlural(input: string): string;
@@ -0,0 +1,18 @@
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.toSnakePlural = toSnakePlural;
7
+ /* src/utils/naming.ts
8
+ * -------------------------------------------------
9
+ * Convierte Camel/Pascal → snake_case y pluraliza.
10
+ * Se importa allí donde se necesite.
11
+ */
12
+ const pluralize_1 = __importDefault(require("pluralize"));
13
+ function toSnakePlural(input) {
14
+ // camelCase / PascalCase → snake_case
15
+ const snake = input.replace(/([a-z0-9])([A-Z])/g, "$1_$2").toLowerCase();
16
+ return (0, pluralize_1.default)(snake); // “user” → “users”, “status” → “statuses”…
17
+ }
18
+ //# sourceMappingURL=naming.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"naming.js","sourceRoot":"","sources":["../../src/utils/naming.ts"],"names":[],"mappings":";;;;;AAOA,sCAIC;AAXD;;;;GAIG;AACH,0DAAkC;AAElC,SAAgB,aAAa,CAAC,KAAa;IACzC,wCAAwC;IACxC,MAAM,KAAK,GAAG,KAAK,CAAC,OAAO,CAAC,oBAAoB,EAAE,OAAO,CAAC,CAAC,WAAW,EAAE,CAAC;IACzE,OAAO,IAAA,mBAAS,EAAC,KAAK,CAAC,CAAC,CAAC,2CAA2C;AACtE,CAAC"}
package/package.json CHANGED
@@ -21,6 +21,7 @@
21
21
  "reflect-metadata": "^0.2.2",
22
22
  "ts-jest": "^29.4.0",
23
23
  "ts-node": "^10.9.2",
24
+ "tsc-alias": "^1.8.16",
24
25
  "tsconfig-paths": "^4.2.0",
25
26
  "tsx": "^4.20.3",
26
27
  "typescript": "^5.8.3"
@@ -28,7 +29,8 @@
28
29
  "files": [
29
30
  "build/",
30
31
  "*.md",
31
- "*.json"
32
+ "*.json",
33
+ "!tsconfig.json"
32
34
  ],
33
35
  "homepage": "https://github.com/arcaelas/dynamite",
34
36
  "license": "ISC",
@@ -43,11 +45,11 @@
43
45
  "url": "https://github.com/arcaelas/dynamite.git"
44
46
  },
45
47
  "scripts": {
46
- "build": "tsc && node esbuild.js",
48
+ "build": "tsc && tsc-alias && node esbuild.js",
47
49
  "commit": "npm publish --access=public",
48
50
  "postpublish": "rm -rf build",
49
51
  "prepublishOnly": "yarn test && npm version patch",
50
52
  "test": "jest && yarn build"
51
53
  },
52
- "version": "1.0.2"
54
+ "version": "1.0.3"
53
55
  }
package/tsconfig.json DELETED
@@ -1,32 +0,0 @@
1
- {
2
- "include": ["src/**/*"],
3
- "compilerOptions": {
4
- "target": "ES2022",
5
- "module": "amd",
6
- "moduleResolution": "node",
7
- "baseUrl": "./",
8
- "paths": {
9
- "@type/*": ["src/@types/*"],
10
- "@controller/*": ["src/app/controllers/*"],
11
- "@provider/*": ["src/app/providers/*"],
12
- "@resource/*": ["src/resources/*"]
13
- },
14
- "esModuleInterop": true,
15
- "forceConsistentCasingInFileNames": true,
16
- "strict": true,
17
- "noImplicitAny": false,
18
- "skipLibCheck": true,
19
- "outFile": "./build/index.d.ts",
20
- "declaration": true,
21
- "emitDeclarationOnly": true,
22
- "resolveJsonModule": true,
23
- "experimentalDecorators": true,
24
- "emitDecoratorMetadata": true,
25
- "downlevelIteration": true,
26
- "lib": ["ES2022", "DOM"],
27
- "allowSyntheticDefaultImports": true,
28
- "useDefineForClassFields": false,
29
- "strictPropertyInitialization": false
30
- },
31
- "exclude": ["node_modules", "**/*.test.ts", "__tests__/**/*", "build/**/*"]
32
- }