@arcaelas/dynamite 1.0.2 → 1.0.4

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 (44) hide show
  1. package/build/core/table.d.ts +32 -0
  2. package/build/core/table.js +216 -0
  3. package/build/core/table.js.map +1 -0
  4. package/build/core/wrapper.d.ts +44 -0
  5. package/build/core/wrapper.js +26 -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/index.js +31 -2
  39. package/build/index.js.map +1 -7
  40. package/build/utils/naming.d.ts +1 -0
  41. package/build/utils/naming.js +18 -0
  42. package/build/utils/naming.js.map +1 -0
  43. package/package.json +8 -6
  44. package/tsconfig.json +0 -32
@@ -0,0 +1,32 @@
1
+ import { DynamoDBClientConfig } from "@aws-sdk/client-dynamodb";
2
+ import { InferAttributes, STORE, WrapperEntry } from "./wrapper";
3
+ export declare function connect(cfg: DynamoDBClientConfig): void;
4
+ export default class Table<T extends {} = any> {
5
+ protected [STORE]: {
6
+ [K in keyof T]?: T[K];
7
+ };
8
+ constructor(data: InferAttributes<T>);
9
+ save(): Promise<this>;
10
+ update(patch: InferAttributes<T>): Promise<this>;
11
+ destroy(): Promise<void>;
12
+ static create<M extends Table>(this: {
13
+ new (data: InferAttributes<M>): M;
14
+ prototype: M;
15
+ }, data: InferAttributes<M>): Promise<M>;
16
+ static update<M extends Table>(this: {
17
+ new (data: InferAttributes<M>): M;
18
+ prototype: M;
19
+ }, id: string, record: InferAttributes<M>): Promise<void>;
20
+ static destroy<M extends Table>(this: {
21
+ new (dara: InferAttributes<M>): M;
22
+ prototype: M;
23
+ }, id: string): Promise<null>;
24
+ static where<M extends Table>(this: {
25
+ new (data: InferAttributes<M>): M;
26
+ prototype: M;
27
+ }): Promise<M[]>;
28
+ toJSON(): Record<string, unknown>;
29
+ toString(): string;
30
+ }
31
+ export { STORE };
32
+ export type { WrapperEntry };
@@ -0,0 +1,216 @@
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
+ async function createTable(ctor) {
50
+ if (!client)
51
+ throw new Error("connect() no llamado");
52
+ const meta = wrapper_1.default.get(ctor);
53
+ if (!meta)
54
+ throw new Error(`Clase ${ctor.name} no registrada en wrapper`);
55
+ const cols = [...meta.columns.values()];
56
+ const pk = cols.find((c) => c.index);
57
+ if (!pk)
58
+ throw new Error(`PartitionKey faltante en ${ctor.name}`);
59
+ const sk = cols.find((c) => c.indexSort);
60
+ const attr = new Map();
61
+ attr.set(pk.name, "S");
62
+ if (sk)
63
+ attr.set(sk.name, "S");
64
+ const schema = [{ AttributeName: pk.name, KeyType: "HASH" }];
65
+ if (sk && sk.name !== pk.name)
66
+ schema.push({ AttributeName: sk.name, KeyType: "RANGE" });
67
+ await client.send(new client_dynamodb_1.CreateTableCommand({
68
+ TableName: meta.name,
69
+ BillingMode: "PAY_PER_REQUEST",
70
+ AttributeDefinitions: [...attr].map(([AttributeName, AttributeType]) => ({
71
+ AttributeName,
72
+ AttributeType,
73
+ })),
74
+ KeySchema: schema,
75
+ }));
76
+ }
77
+ function requireClient() {
78
+ if (!client)
79
+ throw new Error("connect() debe llamarse antes de usar Table");
80
+ }
81
+ function mustMeta(ctor) {
82
+ const meta = wrapper_1.default.get(ctor);
83
+ if (!meta)
84
+ throw new Error(`Metadata no encontrada para ${ctor.name}`);
85
+ return meta;
86
+ }
87
+ let client;
88
+ function connect(cfg) {
89
+ client = new client_dynamodb_1.DynamoDBClient(cfg);
90
+ }
91
+ class Table {
92
+ constructor(data) {
93
+ requireClient();
94
+ const meta = mustMeta(Object.getPrototypeOf(this).constructor);
95
+ meta.columns.forEach((c) => {
96
+ if (!(c.name in data))
97
+ this[c.name] = undefined;
98
+ });
99
+ Object.assign(this, data);
100
+ }
101
+ async save() {
102
+ const id = this["id"];
103
+ const Ctor = this.constructor;
104
+ const record = this.toJSON();
105
+ if (id === undefined || id === null) {
106
+ delete record.id;
107
+ const fresh = await Ctor.create(record);
108
+ Object.assign(this, fresh);
109
+ }
110
+ else {
111
+ await Ctor.update(String(id), record);
112
+ }
113
+ return this;
114
+ }
115
+ async update(patch) {
116
+ const id = this["id"];
117
+ if (id === undefined || id === null)
118
+ throw new Error("update() requiere id");
119
+ Object.assign(this, patch);
120
+ const Ctor = this.constructor;
121
+ await Ctor.update(String(id), this.toJSON());
122
+ return this;
123
+ }
124
+ async destroy() {
125
+ const id = this["id"];
126
+ if (id === undefined || id === null)
127
+ throw new Error("destroy() requiere id");
128
+ const Ctor = this.constructor;
129
+ await Ctor.destroy(String(id));
130
+ }
131
+ static async create(data) {
132
+ const meta = mustMeta(this);
133
+ const payload = new this(data).toJSON();
134
+ const put = () => client.send(new client_dynamodb_1.PutItemCommand({
135
+ TableName: meta.name,
136
+ Item: (0, util_dynamodb_1.marshall)(payload, { removeUndefinedValues: true }),
137
+ }));
138
+ try {
139
+ await put();
140
+ }
141
+ catch (err) {
142
+ if (err?.name === "ResourceNotFoundException") {
143
+ await createTable(this);
144
+ await put();
145
+ }
146
+ else
147
+ throw err;
148
+ }
149
+ return new this(data);
150
+ }
151
+ // prettier-ignore
152
+ static async update(id, record) {
153
+ const meta = mustMeta(this);
154
+ const payload = { ...record, id };
155
+ const put = () => client.send(new client_dynamodb_1.PutItemCommand({
156
+ TableName: meta.name,
157
+ Item: (0, util_dynamodb_1.marshall)(payload, { removeUndefinedValues: true }),
158
+ }));
159
+ try {
160
+ await put();
161
+ }
162
+ catch (err) {
163
+ if (err?.name === "ResourceNotFoundException") {
164
+ await createTable(this);
165
+ await put();
166
+ }
167
+ else
168
+ throw err;
169
+ }
170
+ }
171
+ // prettier-ignore
172
+ static async destroy(id) {
173
+ requireClient();
174
+ try {
175
+ await client.send(new client_dynamodb_1.DeleteItemCommand({
176
+ TableName: mustMeta(this).name,
177
+ Key: (0, util_dynamodb_1.marshall)({ id }),
178
+ }));
179
+ }
180
+ catch (err) {
181
+ if (err.name === "ResourceNotFoundException")
182
+ return null;
183
+ throw err;
184
+ }
185
+ return null;
186
+ }
187
+ static async where() {
188
+ requireClient();
189
+ try {
190
+ const res = await client.send(new client_dynamodb_1.ScanCommand({ TableName: mustMeta(this).name }));
191
+ return (res.Items ?? []).map((i) => new this((0, util_dynamodb_1.unmarshall)(i)));
192
+ }
193
+ catch (err) {
194
+ if (err.name === "ResourceNotFoundException")
195
+ return [];
196
+ throw err;
197
+ }
198
+ }
199
+ toJSON() {
200
+ const meta = mustMeta(Object.getPrototypeOf(this).constructor);
201
+ const buf = this[wrapper_1.STORE] ?? {};
202
+ const out = {};
203
+ for (const [prop, col] of meta.columns) {
204
+ if (prop in buf)
205
+ out[col.name] = buf[prop];
206
+ else if (prop in this)
207
+ out[col.name] = this[prop];
208
+ }
209
+ return out;
210
+ }
211
+ toString() {
212
+ return JSON.stringify(this.toJSON());
213
+ }
214
+ }
215
+ exports.default = Table;
216
+ //# sourceMappingURL=table.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"table.js","sourceRoot":"","sources":["../../src/core/table.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA4DA,0BAEC;AA9DD;;;;;;GAMG;AACH,8DAOkC;AAClC,0DAA8D;AAC9D,qDAA0E;AAmMjE,sFAnM0B,eAAK,OAmM1B;AAjMd,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,IAAI,GAAG,EAA2B,CAAC;IAChD,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC;IACvB,IAAI,EAAE;QAAE,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,IAAI,EAAE,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eBrand]?: true;
4
+ };
5
+ declare const CreationOptionalBrand: unique symbol;
6
+ export type CreationOptional<T> = T & {
7
+ [CreationOptionalBrand]?: true;
8
+ };
9
+ type IsBranded<T, Brand extends symbol> = keyof NonNullable<T> extends keyof Omit<NonNullable<T>, Brand> ? false : true;
10
+ type RemoveNullish<T> = Omit<T, keyof KeepNullish<T>>;
11
+ type RemoveFunction<T> = Omit<T, keyof KeepFunction<T>>;
12
+ type RemoveBranded<T, Brand extends symbol> = Omit<T, keyof KeepBranded<T, Brand>>;
13
+ type KeepNullish<T> = {
14
+ [K in keyof T as undefined extends T[K] ? K : never]: T[K];
15
+ };
16
+ type KeepFunction<T> = {
17
+ [K in keyof T as T[K] extends (...args: any[]) => any ? K : never]: T[K];
18
+ };
19
+ type KeepBranded<T, Brand extends symbol> = {
20
+ [K in keyof T as IsBranded<T[K], Brand> extends true ? K : never]: T[K];
21
+ };
22
+ export type InferAttributes<T> = RemoveFunction<RemoveNullish<RemoveBranded<RemoveBranded<T, typeof CreationOptionalBrand>, typeof NonAttributeBrand>>> & Partial<KeepBranded<T, typeof CreationOptionalBrand>>;
23
+ export type Mutate = (value: any) => Inmutable;
24
+ export type Default = Inmutable | (() => Inmutable);
25
+ export type Validate = (value: any) => true | string;
26
+ export type Inmutable = string | number | boolean | null | object;
27
+ export interface Column {
28
+ name: string;
29
+ default?: Default;
30
+ mutate?: Mutate[];
31
+ validate?: Validate[];
32
+ index?: true;
33
+ indexSort?: true;
34
+ unique?: true;
35
+ }
36
+ export interface WrapperEntry {
37
+ name: string;
38
+ columns: Map<string | symbol, Column>;
39
+ }
40
+ declare const wrapper: Map<Function, WrapperEntry>;
41
+ export declare const STORE: unique symbol;
42
+ export default wrapper;
43
+ export declare function ensureConfig(ctor: Function, tableName: string): WrapperEntry;
44
+ export declare function ensureColumn(entry: WrapperEntry, prop: string | symbol, columnName: string): Column;
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.STORE = void 0;
4
+ exports.ensureConfig = ensureConfig;
5
+ exports.ensureColumn = ensureColumn;
6
+ const wrapper = new Map();
7
+ exports.STORE = Symbol("dynamite:values");
8
+ exports.default = wrapper;
9
+ function ensureConfig(ctor, tableName) {
10
+ let entry = wrapper.get(ctor);
11
+ if (!entry) {
12
+ entry = { name: tableName, columns: new Map() };
13
+ wrapper.set(ctor, entry);
14
+ }
15
+ return entry;
16
+ }
17
+ // prettier-ignore
18
+ function ensureColumn(entry, prop, columnName) {
19
+ let col = entry.columns.get(prop);
20
+ if (!col) {
21
+ col = { name: columnName, mutate: [], validate: [] };
22
+ entry.columns.set(prop, col);
23
+ }
24
+ return col;
25
+ }
26
+ //# sourceMappingURL=wrapper.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"wrapper.js","sourceRoot":"","sources":["../../src/core/wrapper.ts"],"names":[],"mappings":";;;AAmDA,oCAOC;AAGD,oCAOC;AArBD,MAAM,OAAO,GAAG,IAAI,GAAG,EAA0B,CAAC;AACrC,QAAA,KAAK,GAAkB,MAAM,CAAC,iBAAiB,CAAC,CAAC;AAC9D,kBAAe,OAAO,CAAC;AAEvB,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,kBAAkB;AAClB,SAAgB,YAAY,CAAC,KAAmB,EAAE,IAAqB,EAAE,UAAkB;IACzF,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,O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G,OAAO,GAAG,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 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,yBAeC;AAlBD,6CAAoE;AACpE,4CAAgD;AAEhD,SAAwB,MAAM,CAAC,EAAU;IACvC,IAAI,OAAO,EAAE,KAAK,UAAU;QAAE,MAAM,IAAI,SAAS,CAAC,0BAA0B,CAAC,CAAC;IAE9E,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,GAAG,GAAG,IAAA,sBAAY,EAAC,KAAK,EAAE,IAAI,EAAE,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC;QAEpD,GAAG,CAAC,MAAM,KAAK,EAAE,CAAC;QAClB,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;QAEpB,IAAI,CAAC,MAAM,CAAC,wBAAwB,CAAC,IAAI,CAAC,SAAS,EAAE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AC;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,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ACH,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,2BAs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CAAC,CAAC,IAAI,CAAC,CAAC;QACnC,CAAC;QACD,GAAG,CAAC,GAAY;YACd,MAAM,GAAG,GAAG,CAAC,IAAI,CAAC,eAAK,CAAC,KAAK,EAAE,CAAC,CAAC;YAEjC,IAAI,GAAG,KAAK,SAAS,IAAI,GAAG,CAAC,OAAO,KAAK,SAAS,EAAE,CAAC;gBACnD,GAAG,GAAG,OAAO,GAAG,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"}
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";
package/build/index.js CHANGED
@@ -1,2 +1,31 @@
1
- "use strict";var R=Object.create;var P=Object.defineProperty;var $=Object.getOwnPropertyDescriptor;var V=Object.getOwnPropertyNames;var q=Object.getPrototypeOf,W=Object.prototype.hasOwnProperty;var F=(r,t)=>{for(var e in t)P(r,e,{get:t[e],enumerable:!0})},v=(r,t,e,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of V(t))!W.call(r,o)&&o!==e&&P(r,o,{get:()=>t[o],enumerable:!(n=$(t,o))||n.enumerable});return r};var B=(r,t,e)=>(e=r!=null?R(q(r)):{},v(t||!r||!r.__esModule?P(e,"default",{value:r,enumerable:!0}):e,r)),L=r=>v(P({},"__esModule",{value:!0}),r);var _={};F(_,{CreatedAt:()=>M,Default:()=>h,Index:()=>g,IndexSort:()=>b,Mutate:()=>x,Name:()=>D,NotNull:()=>N,PrimaryKey:()=>O,Table:()=>w,UpdatedAt:()=>k,Validate:()=>S,connect:()=>I});module.exports=L(_);var c=require("@aws-sdk/client-dynamodb"),p=require("@aws-sdk/util-dynamodb");var C=new Map,E=C,u=Symbol("dynamite:values");function f(r,t){let e=C.get(r);return e||(e={name:t,columns:new Map},C.set(r,e)),e}function m(r,t,e){let n=r.columns.get(t);return n||(n={name:e,mutate:[],validate:[]},r.columns.set(t,n)),n}var l;function I(r){l=new c.DynamoDBClient(r)}async function j(r){if(!l)throw new Error("connect() no llamado");let t=E.get(r);if(!t)throw new Error(`Clase ${r.name} no registrada en wrapper`);let e=[...t.columns.values()],n=e.find(d=>d.index);if(!n)throw new Error(`PartitionKey faltante en ${r.name}`);let o=e.find(d=>d.indexSort),a=new Map;a.set(n.name,"S"),o&&a.set(o.name,"S");let i=[{AttributeName:n.name,KeyType:"HASH"}];o&&o.name!==n.name&&i.push({AttributeName:o.name,KeyType:"RANGE"}),await l.send(new c.CreateTableCommand({TableName:t.name,BillingMode:"PAY_PER_REQUEST",AttributeDefinitions:[...a].map(([d,K])=>({AttributeName:d,AttributeType:K})),KeySchema:i}))}u;var w=class{constructor(t={}){T(),y(Object.getPrototypeOf(this).constructor).columns.forEach(n=>{n.name in t||(this[n.name]=void 0)}),Object.assign(this,t)}toJSON(){let t=y(Object.getPrototypeOf(this).constructor),e=this[u]??{},n={};for(let[o,a]of t.columns)o in e?n[a.name]=e[o]:o in this&&(n[a.name]=this[o]);return n}async save(){let t=this.id,e=this.constructor,n=this.toJSON();if(t==null){delete n.id;let o=await e.create(n);Object.assign(this,o)}else await e.update(String(t),n);return this}async update(t){let e=this.id;if(e==null)throw new Error("update() requiere id");return Object.assign(this,t),await this.constructor.update(String(e),this.toJSON()),this}async destroy(){let t=this.id;if(t==null)throw new Error("destroy() requiere id");await this.constructor.destroy(String(t))}static async create(t){let e=y(this),n=new this(t).toJSON(),o=()=>l.send(new c.PutItemCommand({TableName:e.name,Item:(0,p.marshall)(n,{removeUndefinedValues:!0})}));try{await o()}catch(a){if(a?.name==="ResourceNotFoundException")await j(this),await o();else throw a}return new this(t)}static async update(t,e){let n=y(this),o={...e,id:t},a=()=>l.send(new c.PutItemCommand({TableName:n.name,Item:(0,p.marshall)(o,{removeUndefinedValues:!0})}));try{await a()}catch(i){if(i?.name==="ResourceNotFoundException")await j(this),await a();else throw i}}static async destroy(t){T();try{await l.send(new c.DeleteItemCommand({TableName:y(this).name,Key:(0,p.marshall)({id:t})}))}catch(e){if(e.name==="ResourceNotFoundException")return null;throw e}return null}static async where(){T();try{return((await l.send(new c.ScanCommand({TableName:y(this).name}))).Items??[]).map(e=>new this((0,p.unmarshall)(e)))}catch(t){if(t.name==="ResourceNotFoundException")return[];throw t}}};function T(){if(!l)throw new Error("connect() debe llamarse antes de usar Table")}function y(r){let t=E.get(r);if(!t)throw new Error(`Metadata no encontrada para ${r.name}`);return t}var A=B(require("pluralize"));function s(r){let t=r.replace(/([a-z0-9])([A-Z])/g,"$1_$2").toLowerCase();return(0,A.default)(t)}function h(r){if(typeof r!="function")throw new TypeError("@Default requiere una funci\xF3n factory");return(t,e)=>{let n=t.constructor,o=f(n,s(n.name)),a=m(o,e,String(e));if(a.default)throw new Error(`@Default duplicado en '${String(e)}'`);a.default=r,Object.getOwnPropertyDescriptor(n.prototype,e)?.set||U(n.prototype,a,e)}}function U(r,t,e){Object.defineProperty(r,e,{get(){return(this[u]??{})[e]},set(n){let o=this[u]??={};if(n===void 0&&t.default!==void 0&&(n=typeof t.default=="function"?t.default():t.default),t.mutate)for(let a of t.mutate)n=a(n);if(t.validate)for(let a of t.validate){let i=a(n);if(i!==!0)throw new Error(typeof i=="string"?i:"Validaci\xF3n fallida")}o[e]=n},enumerable:!0,configurable:!0})}function g(){return(r,t)=>{let e=r.constructor,n=f(e,s(e.name)),o=[...n.columns.values()].find(i=>i.index);if(o&&o!==n.columns.get(t))throw new Error(`La tabla ${e.name} ya tiene PartitionKey (${o.name})`);let a=m(n,t,String(t));a.index=!0}}function b(){return(r,t)=>{let e=r.constructor,n=f(e,s(e.name));if(![...n.columns.values()].some(d=>d.index))throw new Error(`PartitionKey no definido en ${e.name}; declara @Index primero`);let a=[...n.columns.values()].find(d=>d.indexSort);if(a&&a!==n.columns.get(t))throw new Error(`La tabla ${e.name} ya tiene SortKey (${a.name})`);let i=m(n,t,String(t));i.indexSort=!0}}function x(r){if(typeof r!="function")throw new TypeError("@Mutate requiere funci\xF3n");return(t,e)=>{let n=t.constructor,o=f(n,s(n.name)),a=m(o,e,String(e));a.mutate??=[],a.mutate.push(r),Object.getOwnPropertyDescriptor(n.prototype,e)?.set||H(n.prototype,a,e)}}function H(r,t,e){Object.defineProperty(r,e,{get(){return(this[u]??{})[e]},set(n){let o=this[u]??={};if(n===void 0&&t.default!==void 0&&(n=typeof t.default=="function"?t.default():t.default),t.mutate)for(let a of t.mutate)n=a(n);if(t.validate)for(let a of t.validate){let i=a(n);if(i!==!0)throw new Error(typeof i=="string"?i:"Validaci\xF3n fallida")}o[e]=n},enumerable:!0,configurable:!0})}function D(r){if(!r||typeof r!="string")throw new TypeError("@Name requiere una cadena no vac\xEDa");return(t,e)=>{let n=e===void 0?t:t.constructor,o=f(n,s(n.name));if(e===void 0){let a=s(n.name);if(o.name!==a&&o.name!==r&&o.name)throw new Error(`La clase ${n.name} ya tiene un @Name distinto (${o.name})`);o.name=r}else{let a=m(o,e,r);if(a.name&&a.name!==r)throw new Error(`La columna '${String(e)}' ya tiene @Name distinto (${a.name})`);a.name=r}}}function S(r){let t=Array.isArray(r)?r:[r];if(!t.length||t.some(e=>typeof e!="function"))throw new TypeError("@Validate requiere funciones");return(e,n)=>{let o=e.constructor,a=f(o,s(o.name)),i=m(a,n,String(n));i.validate??=[],i.validate.push(...t),Object.getOwnPropertyDescriptor(o.prototype,n)?.set||J(o.prototype,i,n)}}function J(r,t,e){Object.defineProperty(r,e,{get(){return(this[u]??{})[e]},set(n){let o=this[u]??={};if(n===void 0&&t.default!==void 0&&(n=typeof t.default=="function"?t.default():t.default),t.mutate)for(let a of t.mutate)n=a(n);if(t.validate)for(let a of t.validate){let i=a(n);if(i!==!0)throw new Error(typeof i=="string"?i:"Validaci\xF3n fallida")}o[e]=n},enumerable:!0,configurable:!0})}function M(){return h(()=>new Date().toISOString())}function N(){return S((r,t)=>!(r==null||typeof r=="string"&&r.trim()===""))}function O(r="primary"){if(typeof r!="string"||!r.trim())throw new TypeError("@PrimaryKey requiere un nombre de \xEDndice v\xE1lido");return(t,e)=>{g()(t,e),b()(t,e)}}function k(){return x(()=>new Date().toISOString())}0&&(module.exports={CreatedAt,Default,Index,IndexSort,Mutate,Name,NotNull,PrimaryKey,Table,UpdatedAt,Validate,connect});
2
- //# sourceMappingURL=index.js.map
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.UpdatedAt = exports.PrimaryKey = exports.NotNull = exports.CreatedAt = exports.Validate = exports.Name = exports.Mutate = exports.IndexSort = exports.Index = exports.Default = exports.Table = exports.connect = void 0;
7
+ var table_1 = require("./core/table");
8
+ Object.defineProperty(exports, "connect", { enumerable: true, get: function () { return table_1.connect; } });
9
+ Object.defineProperty(exports, "Table", { enumerable: true, get: function () { return __importDefault(table_1).default; } });
10
+ // Decoradores
11
+ var default_1 = require("./decorators/default");
12
+ Object.defineProperty(exports, "Default", { enumerable: true, get: function () { return __importDefault(default_1).default; } });
13
+ var index_1 = require("./decorators/index");
14
+ Object.defineProperty(exports, "Index", { enumerable: true, get: function () { return __importDefault(index_1).default; } });
15
+ var index_sort_1 = require("./decorators/index_sort");
16
+ Object.defineProperty(exports, "IndexSort", { enumerable: true, get: function () { return __importDefault(index_sort_1).default; } });
17
+ var mutate_1 = require("./decorators/mutate");
18
+ Object.defineProperty(exports, "Mutate", { enumerable: true, get: function () { return __importDefault(mutate_1).default; } });
19
+ var name_1 = require("./decorators/name");
20
+ Object.defineProperty(exports, "Name", { enumerable: true, get: function () { return __importDefault(name_1).default; } });
21
+ var validate_1 = require("./decorators/validate");
22
+ Object.defineProperty(exports, "Validate", { enumerable: true, get: function () { return __importDefault(validate_1).default; } });
23
+ var created_at_1 = require("./decorators/created_at");
24
+ Object.defineProperty(exports, "CreatedAt", { enumerable: true, get: function () { return __importDefault(created_at_1).default; } });
25
+ var not_null_1 = require("./decorators/not_null");
26
+ Object.defineProperty(exports, "NotNull", { enumerable: true, get: function () { return __importDefault(not_null_1).default; } });
27
+ var primary_key_1 = require("./decorators/primary_key");
28
+ Object.defineProperty(exports, "PrimaryKey", { enumerable: true, get: function () { return __importDefault(primary_key_1).default; } });
29
+ var updated_at_1 = require("./decorators/updated_at");
30
+ Object.defineProperty(exports, "UpdatedAt", { enumerable: true, get: function () { return __importDefault(updated_at_1).default; } });
31
+ //# sourceMappingURL=index.js.map
@@ -1,7 +1 @@
1
- {
2
- "version": 3,
3
- "sources": ["../src/index.ts", "../src/core/table.ts", "../src/core/wrapper.ts", "../src/utils/naming.ts", "../src/decorators/default.ts", "../src/decorators/index.ts", "../src/decorators/index_sort.ts", "../src/decorators/mutate.ts", "../src/decorators/name.ts", "../src/decorators/validate.ts", "../src/decorators/created_at.ts", "../src/decorators/not_null.ts", "../src/decorators/primary_key.ts", "../src/decorators/updated_at.ts"],
4
- "sourcesContent": ["export { connect, default as Table } from \"./core/table\";\n\n// Decoradores\nexport { default as Default } from \"./decorators/default\";\nexport { default as Index } from \"./decorators/index\";\nexport { default as IndexSort } from \"./decorators/index_sort\";\nexport { default as Mutate } from \"./decorators/mutate\";\nexport { default as Name } from \"./decorators/name\";\nexport { default as Validate } from \"./decorators/validate\";\n\nexport { default as CreatedAt } from \"./decorators/created_at\";\nexport { default as NotNull } from \"./decorators/not_null\";\nexport { default as PrimaryKey } from \"./decorators/primary_key\";\nexport { default as UpdatedAt } from \"./decorators/updated_at\";\n", "/* src/core/table.ts\n * Dinamite ORM \u2014 runtime\n * --------------------------------------------------\n * CRUD + autocreaci\u00F3n de tablas (DynamoDB v3)\n * Serializaci\u00F3n estricta mediante toJSON()\n * \u00A9 2025 Miguel Alejandro\n */\nimport {\n CreateTableCommand,\n DeleteItemCommand,\n DynamoDBClient,\n DynamoDBClientConfig,\n PutItemCommand,\n ScanCommand,\n} from \"@aws-sdk/client-dynamodb\";\nimport { marshall, unmarshall } from \"@aws-sdk/util-dynamodb\";\nimport wrapper, { STORE, WrapperEntry } from \"./wrapper\";\n\n/* \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500 Conexi\u00F3n global \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500 */\nlet client: DynamoDBClient | undefined;\nexport function connect(cfg: DynamoDBClientConfig): void {\n client = new DynamoDBClient(cfg);\n}\n\n/* \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500 Creaci\u00F3n autom\u00E1tica de tablas a partir del wrapper \u2500\u2500\u2500\u2500\u2500\u2500 */\nasync function createTable(ctor: Function): Promise<void> {\n if (!client) throw new Error(\"connect() no llamado\");\n const meta = wrapper.get(ctor);\n if (!meta) throw new Error(`Clase ${ctor.name} no registrada en wrapper`);\n\n const cols = [...meta.columns.values()];\n const pk = cols.find((c) => c.index);\n if (!pk) throw new Error(`PartitionKey faltante en ${ctor.name}`);\n\n const sk = cols.find((c) => c.indexSort);\n\n const attr = new Map<string, \"S\" | \"N\" | \"B\">();\n attr.set(pk.name, \"S\");\n if (sk) attr.set(sk.name, \"S\");\n\n type KS = { AttributeName: string; KeyType: \"HASH\" | \"RANGE\" };\n const schema: KS[] = [{ AttributeName: pk.name, KeyType: \"HASH\" }];\n if (sk && sk.name !== pk.name)\n schema.push({ AttributeName: sk.name, KeyType: \"RANGE\" });\n\n await client.send(\n new CreateTableCommand({\n TableName: meta.name,\n BillingMode: \"PAY_PER_REQUEST\",\n AttributeDefinitions: [...attr].map(([AttributeName, AttributeType]) => ({\n AttributeName,\n AttributeType,\n })),\n KeySchema: schema,\n })\n );\n}\n\n/* \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500 Table \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500 */\nexport default class Table<T extends object = object> {\n // eslint-disable-next-line @typescript-eslint/consistent-type-assertions\n private [STORE]!: { [K in keyof T]?: T[K] };\n\n constructor(data: Partial<T> = {}) {\n requireClient();\n const meta = mustMeta(Object.getPrototypeOf(this).constructor);\n\n /* defaults via setters */\n meta.columns.forEach((c) => {\n if (!(c.name in data)) (this as any)[c.name] = undefined;\n });\n\n Object.assign(this, data);\n }\n\n /* -------- serializa SOLO columnas v\u00E1lidas -------- */\n toJSON(): Record<string, unknown> {\n const meta = mustMeta(Object.getPrototypeOf(this).constructor);\n const buf = (this as any)[STORE] ?? {};\n const out: Record<string, unknown> = {};\n\n for (const [prop, col] of meta.columns) {\n if (prop in buf) out[col.name] = buf[prop];\n else if (prop in this) out[col.name] = (this as any)[prop];\n }\n return out;\n }\n\n /* \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500 M\u00E9todos de instancia \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500 */\n async save(): Promise<this> {\n // @ts-ignore\n const id: unknown = this.id;\n const Ctor = this.constructor as typeof Table<any>;\n const record = this.toJSON();\n\n if (id === undefined || id === null) {\n delete (record as any).id;\n const fresh = await (Ctor as any).create(record);\n Object.assign(this, fresh);\n } else {\n await (Ctor as any).update(String(id), record);\n }\n return this;\n }\n\n async update(patch: Partial<T>): Promise<this> {\n // @ts-ignore\n const id: unknown = this.id;\n if (id === undefined || id === null)\n throw new Error(\"update() requiere id\");\n\n Object.assign(this, patch);\n const Ctor = this.constructor as typeof Table<any>;\n await (Ctor as any).update(String(id), this.toJSON());\n return this;\n }\n\n async destroy(): Promise<void> {\n // @ts-ignore\n const id: unknown = this.id;\n if (id === undefined || id === null)\n throw new Error(\"destroy() requiere id\");\n const Ctor = this.constructor as typeof Table<any>;\n await (Ctor as any).destroy(String(id));\n }\n\n /* \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500 CRUD est\u00E1ticos \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500 */\n\n static async create<M extends Table>(\n this: new (d?: Partial<M>) => M,\n data: Partial<M>\n ): Promise<M> {\n const meta = mustMeta(this);\n const payload = new this(data).toJSON(); // filtrado\n\n const put = () =>\n client!.send(\n new PutItemCommand({\n TableName: meta.name,\n Item: marshall(payload, { removeUndefinedValues: true }),\n })\n );\n\n try {\n await put();\n } catch (err: any) {\n if (err?.name === \"ResourceNotFoundException\") {\n await createTable(this);\n await put();\n } else throw err;\n }\n return new this(data);\n }\n\n static async update<M extends Table>(\n this: new (d?: Partial<M>) => M,\n id: string,\n record: Partial<M> // \u2190 ya es JSON completo desde instancia\n ): Promise<void> {\n const meta = mustMeta(this);\n const payload = { ...record, id };\n\n const put = () =>\n client!.send(\n new PutItemCommand({\n TableName: meta.name,\n Item: marshall(payload, { removeUndefinedValues: true }),\n })\n );\n\n try {\n await put();\n } catch (err: any) {\n if (err?.name === \"ResourceNotFoundException\") {\n await createTable(this);\n await put();\n } else throw err;\n }\n }\n\n static async destroy<M extends Table>(\n this: new () => M,\n id: string\n ): Promise<null> {\n requireClient();\n try {\n await client!.send(\n new DeleteItemCommand({\n TableName: mustMeta(this).name,\n Key: marshall({ id }),\n })\n );\n } catch (err: any) {\n if (err.name === \"ResourceNotFoundException\") return null;\n throw err;\n }\n return null;\n }\n\n static async where<M extends Table>(this: new (d?: any) => M): Promise<M[]> {\n requireClient();\n try {\n const res = await client!.send(\n new ScanCommand({ TableName: mustMeta(this).name })\n );\n return (res.Items ?? []).map((i) => new this(unmarshall(i)));\n } catch (err: any) {\n if (err.name === \"ResourceNotFoundException\") return [];\n throw err;\n }\n }\n}\n\n/* \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500 Utilidades internas \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500 */\nfunction requireClient(): void {\n if (!client) throw new Error(\"connect() debe llamarse antes de usar Table\");\n}\nfunction mustMeta(ctor: Function): WrapperEntry {\n const meta = wrapper.get(ctor);\n if (!meta) throw new Error(`Metadata no encontrada para ${ctor.name}`);\n return meta;\n}\n\n/* \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500 Exportaciones internas \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500 */\nexport { STORE };\nexport type { WrapperEntry };\n", "/* src/core/wrapper.ts\n * -------------------------------------------------\n * Registro central (in-memory) de la configuraci\u00F3n\n * declarativa de cada modelo. Agn\u00F3stico: no depende\n * de DynamoDB ni de otros m\u00F3dulos de la librer\u00EDa.\n *\n * \u00A9 2025 Miguel Alejandro\n */\n\n/* ------------------------------------------------------------------ */\n/* 1. Tipos utilitarios */\n/* ------------------------------------------------------------------ */\nexport type Inmutable = string | number | boolean | null | object;\n\nexport type Mutate = (value: any) => Inmutable;\nexport type Default = Inmutable | (() => Inmutable);\nexport type Validate = (value: any) => true | string;\n\n/* ------------------------------------------------------------------ */\n/* 2. Descripci\u00F3n de columna y tabla */\n/* ------------------------------------------------------------------ */\nexport interface Column {\n /** nombre f\u00EDsico en la tabla (DynamoDB) */\n name: string;\n\n /* Decoradores b\u00E1sicos */\n default?: Default;\n mutate?: Mutate[];\n validate?: Validate[];\n\n /* Metadatos de \u00EDndice / unicidad */\n index?: true; // Partition Key\n indexSort?: true; // Sort Key\n unique?: true; // constraint l\u00F3gico (no se valida en Dynamo)\n}\n\n/**\n * Configuraci\u00F3n completa por tabla\n */\nexport interface WrapperEntry {\n /** Nombre f\u00EDsico de la tabla (snake_plural o @Name) */\n name: string;\n\n /** Columnas asociadas a la clase. key = propiedad (string|symbol) */\n columns: Map<string | symbol, Column>;\n}\n\n/* ------------------------------------------------------------------ */\n/* 3. Contenedor global */\n/* ------------------------------------------------------------------ */\nexport type Wrapper = Map<Function, WrapperEntry>;\n\n/**\n * Mapa singleton (clase \u2192 configuraci\u00F3n)\n * Exportado como default para uso interno de la librer\u00EDa.\n */\nconst wrapper: Wrapper = new Map();\nexport default wrapper;\n\n/* ------------------------------------------------------------------ */\n/* 4. S\u00EDmbolo de almacenamiento de valores reales */\n/* ------------------------------------------------------------------ */\n/**\n * Buffer privado en cada instancia de Table donde se guardan\n * los valores procesados por los setters virtuales.\n *\n * Se exporta para que los decoradores puedan leer/escribir,\n * pero **NO** se vuelve a exportar desde la ra\u00EDz del paquete.\n */\nexport const STORE: unique symbol = Symbol(\"dynamite:values\");\n\n/* ------------------------------------------------------------------ */\n/* 5. Peque\u00F1os helpers opcionales */\n/* ------------------------------------------------------------------ */\n\n/**\n * Asegura que exista la entrada en el wrapper para la clase dada.\n * Devuelve la entrada (reci\u00E9n creada o existente).\n */\nexport function ensureConfig(ctor: Function, tableName: string): WrapperEntry {\n let entry = wrapper.get(ctor);\n if (!entry) {\n entry = { name: tableName, columns: new Map() };\n wrapper.set(ctor, entry);\n }\n return entry;\n}\n\n/**\n * Obtiene (o crea) el objeto Column para una propiedad concreta.\n */\nexport function ensureColumn(\n entry: WrapperEntry,\n prop: string | symbol,\n columnName: string\n): Column {\n let col = entry.columns.get(prop);\n if (!col) {\n col = { name: columnName, mutate: [], validate: [] };\n entry.columns.set(prop, col);\n }\n return col;\n}\n", "/* src/utils/naming.ts\n * -------------------------------------------------\n * Convierte Camel/Pascal \u2192 snake_case y pluraliza.\n * Se importa all\u00ED donde se necesite.\n */\nimport pluralize from \"pluralize\";\n\nexport function toSnakePlural(input: string): string {\n // camelCase / PascalCase \u2192 snake_case\n const snake = input.replace(/([a-z0-9])([A-Z])/g, \"$1_$2\").toLowerCase();\n return pluralize(snake); // \u201Cuser\u201D \u2192 \u201Cusers\u201D, \u201Cstatus\u201D \u2192 \u201Cstatuses\u201D\u2026\n}\n", "/*\n * Dinamite ORM \u2014 @Default\n * -----------------------\n * Registra un valor por defecto y crea (si falta) el\n * getter/setter virtual de la propiedad.\n */\n\nimport { Column, STORE, ensureColumn, ensureConfig } from \"../core/wrapper\";\nimport { toSnakePlural } from \"../utils/naming\";\n\nexport default function Default(factory: () => unknown): PropertyDecorator {\n if (typeof factory !== \"function\") {\n throw new TypeError(\"@Default requiere una funci\u00F3n factory\");\n }\n\n return (target: object, prop: string | symbol): void => {\n const ctor = (target as any).constructor;\n const entry = ensureConfig(ctor, toSnakePlural(ctor.name));\n const column = ensureColumn(entry, prop, String(prop));\n\n if (column.default)\n throw new Error(`@Default duplicado en '${String(prop)}'`);\n column.default = factory;\n\n if (!Object.getOwnPropertyDescriptor(ctor.prototype, prop)?.set) {\n defineVirtual(ctor.prototype, column, prop);\n }\n };\n}\n\n/* ------------------------------------------------------------------ */\nfunction defineVirtual(proto: any, col: Column, prop: string | symbol): void {\n Object.defineProperty(proto, prop, {\n get() {\n return (this[STORE] ?? {})[prop];\n },\n set(val: unknown) {\n const buf = (this[STORE] ??= {});\n\n if (val === undefined && col.default !== undefined) {\n val = typeof col.default === \"function\" ? col.default() : col.default;\n }\n if (col.mutate) for (const m of col.mutate) val = m(val);\n if (col.validate) {\n for (const v of col.validate) {\n const r = v(val);\n if (r !== true)\n throw new Error(typeof r === \"string\" ? r : \"Validaci\u00F3n fallida\");\n }\n }\n buf[prop] = val;\n },\n enumerable: true,\n configurable: true,\n });\n}\n", "/*\n * Dinamite ORM \u2014 @Index (Partition Key)\n * -------------------------------------\n * Marca la propiedad como clave de partici\u00F3n.\n */\n\nimport { ensureColumn, ensureConfig } from \"../core/wrapper\";\nimport { toSnakePlural } from \"../utils/naming\";\n\nexport default function Index(): PropertyDecorator {\n return (target: object, prop: string | symbol): void => {\n const ctor = (target as any).constructor;\n const entry = ensureConfig(ctor, toSnakePlural(ctor.name));\n\n /* Evitar duplicados */\n const already = [...entry.columns.values()].find((c) => c.index);\n if (already && already !== entry.columns.get(prop)) {\n throw new Error(\n `La tabla ${ctor.name} ya tiene PartitionKey (${already.name})`\n );\n }\n\n const col = ensureColumn(entry, prop, String(prop));\n col.index = true;\n };\n}\n", "/*\n * Dinamite ORM \u2014 @IndexSort (Sort Key)\n * ------------------------------------\n * Marca la propiedad como clave de ordenamiento.\n */\n\nimport { ensureColumn, ensureConfig } from \"../core/wrapper\";\nimport { toSnakePlural } from \"../utils/naming\";\n\nexport default function IndexSort(): PropertyDecorator {\n return (target: object, prop: string | symbol): void => {\n const ctor = (target as any).constructor;\n const entry = ensureConfig(ctor, toSnakePlural(ctor.name));\n\n const pkExists = [...entry.columns.values()].some((c) => c.index);\n if (!pkExists) {\n throw new Error(\n `PartitionKey no definido en ${ctor.name}; declara @Index primero`\n );\n }\n\n const already = [...entry.columns.values()].find((c) => c.indexSort);\n if (already && already !== entry.columns.get(prop)) {\n throw new Error(\n `La tabla ${ctor.name} ya tiene SortKey (${already.name})`\n );\n }\n\n const col = ensureColumn(entry, prop, String(prop));\n col.indexSort = true;\n };\n}\n", "/*\n * Dinamite ORM \u2014 @Mutate\n * ----------------------\n * Registra funciones transformadoras para un campo y virtualiza\n * la propiedad si a\u00FAn no existe.\n */\n\nimport type { Column, Mutate } from \"../core/wrapper\";\nimport { STORE, ensureColumn, ensureConfig } from \"../core/wrapper\";\nimport { toSnakePlural } from \"../utils/naming\";\n\nexport default function Mutate(fn: Mutate): PropertyDecorator {\n if (typeof fn !== \"function\") throw new TypeError(\"@Mutate requiere funci\u00F3n\");\n\n return (target: object, prop: string | symbol): void => {\n const ctor = (target as any).constructor;\n const entry = ensureConfig(ctor, toSnakePlural(ctor.name));\n const col = ensureColumn(entry, prop, String(prop));\n\n col.mutate ??= [];\n col.mutate.push(fn);\n\n if (!Object.getOwnPropertyDescriptor(ctor.prototype, prop)?.set) {\n defineVirtual(ctor.prototype, col, prop);\n }\n };\n}\n\n/* ------------------------------------------------------------------ */\nfunction defineVirtual(proto: any, col: Column, prop: string | symbol): void {\n Object.defineProperty(proto, prop, {\n get() {\n return (this[STORE] ?? {})[prop];\n },\n set(val: unknown) {\n const buf = (this[STORE] ??= {});\n\n if (val === undefined && col.default !== undefined) {\n val = typeof col.default === \"function\" ? col.default() : col.default;\n }\n if (col.mutate) for (const m of col.mutate) val = m(val);\n if (col.validate) {\n for (const v of col.validate) {\n const r = v(val);\n if (r !== true)\n throw new Error(typeof r === \"string\" ? r : \"Validaci\u00F3n fallida\");\n }\n }\n buf[prop] = val;\n },\n enumerable: true,\n configurable: true,\n });\n}\n", "/*\n * Dinamite ORM \u2014 @Name\n * --------------------\n * \u2022 @Name(\"tabla\") \u2192 nombre f\u00EDsico de la tabla\n * \u2022 @Name(\"columna\") \u2192 alias de columna\n *\n * Permite sobrescribir el nombre AUTO-generado (snake_plural)\n * sin lanzar conflicto.\n */\n\nimport { ensureColumn, ensureConfig } from \"../core/wrapper\";\nimport { toSnakePlural } from \"../utils/naming\";\n\nexport default function Name(\n label: string\n): ClassDecorator & PropertyDecorator {\n if (!label || typeof label !== \"string\") {\n throw new TypeError(\"@Name requiere una cadena no vac\u00EDa\");\n }\n\n return (target: any, prop?: string | symbol): void => {\n const ctor = prop === undefined ? target : target.constructor;\n const entry = ensureConfig(ctor, toSnakePlural(ctor.name));\n\n if (prop === undefined) {\n /* ---------- Nombre de la tabla ---------- */\n\n const auto = toSnakePlural(ctor.name);\n\n // Solo error si ya se modific\u00F3 conscientemente antes.\n if (entry.name !== auto && entry.name !== label && entry.name) {\n throw new Error(\n `La clase ${ctor.name} ya tiene un @Name distinto (${entry.name})`\n );\n }\n entry.name = label;\n } else {\n /* ---------- Alias de columna ---------- */\n\n const col = ensureColumn(entry, prop, label);\n\n if (col.name && col.name !== label) {\n throw new Error(\n `La columna '${String(prop)}' ya tiene @Name distinto (${col.name})`\n );\n }\n col.name = label;\n }\n };\n}\n", "/*\n * Dinamite ORM \u2014 @Validate\n * ------------------------\n * Registra validadores y crea virtual si falta.\n */\n\nimport { Column, STORE, ensureColumn, ensureConfig } from \"../core/wrapper\";\nimport { toSnakePlural } from \"../utils/naming\";\n\nexport default function Validate(\n validators:\n | ((v: unknown) => true | string)\n | ((v: unknown) => true | string)[]\n): PropertyDecorator {\n const list = Array.isArray(validators) ? validators : [validators];\n if (!list.length || list.some((v) => typeof v !== \"function\")) {\n throw new TypeError(\"@Validate requiere funciones\");\n }\n\n return (target: object, prop: string | symbol): void => {\n const ctor = (target as any).constructor;\n const entry = ensureConfig(ctor, toSnakePlural(ctor.name));\n const col = ensureColumn(entry, prop, String(prop));\n\n col.validate ??= [];\n col.validate.push(...list);\n\n if (!Object.getOwnPropertyDescriptor(ctor.prototype, prop)?.set) {\n defineVirtual(ctor.prototype, col, prop);\n }\n };\n}\n\n/* ------------------------------------------------------------------ */\nfunction defineVirtual(proto: any, col: Column, prop: string | symbol): void {\n Object.defineProperty(proto, prop, {\n get() {\n return (this[STORE] ?? {})[prop];\n },\n set(val: unknown) {\n const buf = (this[STORE] ??= {});\n\n if (val === undefined && col.default !== undefined) {\n val = typeof col.default === \"function\" ? col.default() : col.default;\n }\n if (col.mutate) for (const m of col.mutate) val = m(val);\n if (col.validate) {\n for (const v of col.validate) {\n const r = v(val);\n if (r !== true)\n throw new Error(typeof r === \"string\" ? r : \"Validaci\u00F3n fallida\");\n }\n }\n buf[prop] = val;\n },\n enumerable: true,\n configurable: true,\n });\n}\n", "/*\n * Dinamite ORM \u2014 @CreatedAt Decorator (wrapper)\n * -------------------------------------------\n * Establece un valor por defecto con la fecha/hora actual (ISO\u2011string)\n * usando @Default.\n *\n * \u00A9 2025 Miguel Alejandro\n */\n\nimport Default from \"./default\";\n\n/**\n * Asigna autom\u00E1ticamente la fecha de creaci\u00F3n en nuevas instancias.\n */\nexport default function CreatedAt(): PropertyDecorator {\n return Default(() => new Date().toISOString());\n}\n", "/*\n * Dinamite ORM \u2014 @NotNull Decorator (wrapper)\n * ------------------------------------------\n * Valida que el valor no sea null, undefined ni cadena vac\u00EDa.\n * Internamente aplica @Validate con una funci\u00F3n sincr\u00F3nica.\n *\n * \u00A9 2025 Miguel Alejandro\n */\n\nimport Validate from \"./validate\";\n\n/**\n * Decorador wrapper que asegura no-null / no-empty.\n */\nexport default function NotNull(): PropertyDecorator {\n return (Validate as any)((value, key) => {\n if (value === null || value === undefined) return false;\n if (typeof value === \"string\" && value.trim() === \"\") return false;\n return true;\n });\n}\n", "/*\n * Dinamite ORM \u2014 @PrimaryKey\n * --------------------------\n * Declara simult\u00E1neamente Partition Key y Sort Key\n * sobre la misma propiedad.\n */\n\nimport Index from \"./index\";\nimport IndexSort from \"./index_sort\";\n\n/**\n * Atajo para definir clave primaria compuesta (PK + SK).\n * El par\u00E1metro `name` queda reservado por si en el futuro\n * se almacena un identificador l\u00F3gico de \u00EDndice, pero hoy\n * NO se pasa a ning\u00FAn decorador interno.\n */\nexport default function PrimaryKey(name = \"primary\"): PropertyDecorator {\n if (typeof name !== \"string\" || !name.trim()) {\n throw new TypeError(\"@PrimaryKey requiere un nombre de \u00EDndice v\u00E1lido\");\n }\n\n return (target: object, prop: string | symbol): void => {\n Index()(target, prop); // Partition Key\n IndexSort()(target, prop); // Sort Key\n };\n}\n", "/*\n * Dinamite ORM \u2014 @UpdatedAt Decorator (wrapper)\n * --------------------------------------------\n * Actualiza la fecha/hora cada vez que la propiedad recibe un nuevo valor\n * (incluyendo actualizaciones mediante Model.save()).\n * Internamente aplica @Mutate con una factory de timestamp ISO.\n *\n * \u00A9 2025 Miguel Alejandro\n */\n\nimport Mutate from \"./mutate\";\n\n/**\n * Actualiza autom\u00E1ticamente la marca temporal en cada asignaci\u00F3n.\n */\nex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,OAAQC,EAAiB,CAACC,EAAOC,IAC3B,EAAAD,GAAU,MACV,OAAOA,GAAU,UAAYA,EAAM,KAAK,IAAM,GAEnD,CACH,CCJe,SAARE,EAA4BC,EAAO,UAA8B,CACtE,GAAI,OAAOA,GAAS,UAAY,CAACA,EAAK,KAAK,EACzC,MAAM,IAAI,UAAU,uDAAiD,EAGvE,MAAO,CAACC,EAAgBC,IAAgC,CACtDC,EAAM,EAAEF,EAAQC,CAAI,EACpBE,EAAU,EAAEH,EAAQC,CAAI,CAC1B,CACF,CCVe,SAARG,GAAgD,CACrD,OAAOC,EAAO,IAAM,IAAI,KAAK,EAAE,YAAY,CAAC,CAC9C",
6
- "names": ["index_exports", "__export", "CreatedAt", "Default", "Index", "IndexSort", "Mutate", "Name", "NotNull", "PrimaryKey", "Table", "UpdatedAt", "Validate", "connect", "__toCommonJS", "import_client_dynamodb", "import_util_dynamodb", "wrapper", "wrapper_default", "STORE", "ensureConfig", "ctor", "tableName", "entry", "ensureColumn", "prop", "columnName", "col", "client", "connect", "cfg", "createTable", "ctor", "meta", "wrapper_default", "cols", "pk", "c", "sk", "attr", "schema", "AttributeName", "AttributeType", "STORE", "Table", "data", "requireClient", "mustMeta", "buf", "out", "prop", "col", "id", "Ctor", "record", "fresh", "patch", "payload", "put", "err", "i", "import_pluralize", "toSnakePlural", "input", "snake", "pluralize", "Default", "factory", "target", "prop", "ctor", "entry", "ensureConfig", "toSnakePlural", "column", "ensureColumn", "defineVirtual", "proto", "col", "STORE", "val", "buf", "m", "v", "r", "Index", "target", "prop", "ctor", "entry", "ensureConfig", "toSnakePlural", "already", "c", "col", "ensureColumn", "IndexSort", "target", "prop", "ctor", "entry", "ensureConfig", "toSnakePlural", "c", "already", "col", "ensureColumn", "Mutate", "fn", "target", "prop", "ctor", "entry", "ensureConfig", "toSnakePlural", "col", "ensureColumn", "defineVirtual", "proto", "STORE", "val", "buf", "m", "v", "r", "Name", "label", "target", "prop", "ctor", "entry", "ensureConfig", "toSnakePlural", "auto", "col", "ensureColumn", "Validate", "validators", "list", "v", "target", "prop", "ctor", "entry", "ensureConfig", "toSnakePlural", "col", "ensureColumn", "defineVirtual", "proto", "STORE", "val", "buf", "m", "r", "CreatedAt", "Default", "NotNull", "Validate", "value", "key", "PrimaryKey", "name", "target", "prop", "Index", "IndexSort", "UpdatedAt", "Mutate"]
7
- }
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;AAAA,sCAAyD;AAAhD,gGAAA,OAAO,OAAA;AAAE,+GAAA,OAAO,OAAS;AAElC,cAAc;AACd,gDAA0D;AAAjD,mHAAA,OAAO,OAAW;AAC3B,4CAAsD;AAA7C,+GAAA,OAAO,OAAS;AACzB,sDAA+D;AAAtD,wHAAA,OAAO,OAAa;AAC7B,8CAAwD;AAA/C,iHAAA,OAAO,OAAU;AAC1B,0CAAoD;AAA3C,6GAAA,OAAO,OAAQ;AACxB,kDAA4D;AAAnD,qHAAA,OAAO,OAAY;AAE5B,sDAA+D;AAAtD,wHAAA,OAAO,OAAa;AAC7B,kDAA2D;AAAlD,oHAAA,OAAO,OAAW;AAC3B,wDAAiE;AAAxD,0HAAA,OAAO,OAAc;AAC9B,sDAA+D;AAAtD,wHAAA,OAAO,OAAa"}
@@ -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
+ "test": "jest",
49
+ "build": "tsc && tsc-alias",
50
+ "prepublishOnly": "yarn test && yarn build && npm version patch",
47
51
  "commit": "npm publish --access=public",
48
- "postpublish": "rm -rf build",
49
- "prepublishOnly": "yarn test && npm version patch",
50
- "test": "jest && yarn build"
52
+ "postpublish": "rm -rf build"
51
53
  },
52
- "version": "1.0.2"
54
+ "version": "1.0.4"
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
- }