@arcaelas/dynamite 1.0.0 → 1.0.2
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.
- package/SECURITY.md +41 -0
- package/build/index.d.ts +130 -0
- package/build/index.js +2 -0
- package/build/index.js.map +7 -0
- package/package.json +35 -11
- package/tsconfig.json +5 -5
- package/.eslintrc.js +0 -0
- package/.prettierrc +0 -0
- package/__tests__/crud.spec.ts +0 -77
- package/__tests__/decorators.spec.ts +0 -134
- package/__tests__/instance-crud.spec.ts +0 -86
- package/jest.config.ts +0 -23
- package/src/core/table.ts +0 -226
- package/src/core/wrapper.ts +0 -103
- package/src/decorators/created_at.ts +0 -17
- package/src/decorators/default.ts +0 -56
- package/src/decorators/index.ts +0 -26
- package/src/decorators/index_sort.ts +0 -32
- package/src/decorators/mutate.ts +0 -54
- package/src/decorators/name.ts +0 -50
- package/src/decorators/not_null.ts +0 -21
- package/src/decorators/primary_key.ts +0 -26
- package/src/decorators/updated_at.ts +0 -18
- package/src/decorators/validate.ts +0 -59
- package/src/index.ts +0 -14
- package/src/utils/naming.ts +0 -12
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Dinamite ORM — @NotNull Decorator (wrapper)
|
|
3
|
-
* ------------------------------------------
|
|
4
|
-
* Valida que el valor no sea null, undefined ni cadena vacía.
|
|
5
|
-
* Internamente aplica @Validate con una función sincrónica.
|
|
6
|
-
*
|
|
7
|
-
* © 2025 Miguel Alejandro
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
import Validate from "./validate";
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* Decorador wrapper que asegura no-null / no-empty.
|
|
14
|
-
*/
|
|
15
|
-
export default function NotNull(): PropertyDecorator {
|
|
16
|
-
return (Validate as any)((value, key) => {
|
|
17
|
-
if (value === null || value === undefined) return false;
|
|
18
|
-
if (typeof value === "string" && value.trim() === "") return false;
|
|
19
|
-
return true;
|
|
20
|
-
});
|
|
21
|
-
}
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Dinamite ORM — @PrimaryKey
|
|
3
|
-
* --------------------------
|
|
4
|
-
* Declara simultáneamente Partition Key y Sort Key
|
|
5
|
-
* sobre la misma propiedad.
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
import Index from "./index";
|
|
9
|
-
import IndexSort from "./index_sort";
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* Atajo para definir clave primaria compuesta (PK + SK).
|
|
13
|
-
* El parámetro `name` queda reservado por si en el futuro
|
|
14
|
-
* se almacena un identificador lógico de índice, pero hoy
|
|
15
|
-
* NO se pasa a ningún decorador interno.
|
|
16
|
-
*/
|
|
17
|
-
export default function PrimaryKey(name = "primary"): PropertyDecorator {
|
|
18
|
-
if (typeof name !== "string" || !name.trim()) {
|
|
19
|
-
throw new TypeError("@PrimaryKey requiere un nombre de índice válido");
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
return (target: object, prop: string | symbol): void => {
|
|
23
|
-
Index()(target, prop); // Partition Key
|
|
24
|
-
IndexSort()(target, prop); // Sort Key
|
|
25
|
-
};
|
|
26
|
-
}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Dinamite ORM — @UpdatedAt Decorator (wrapper)
|
|
3
|
-
* --------------------------------------------
|
|
4
|
-
* Actualiza la fecha/hora cada vez que la propiedad recibe un nuevo valor
|
|
5
|
-
* (incluyendo actualizaciones mediante Model.save()).
|
|
6
|
-
* Internamente aplica @Mutate con una factory de timestamp ISO.
|
|
7
|
-
*
|
|
8
|
-
* © 2025 Miguel Alejandro
|
|
9
|
-
*/
|
|
10
|
-
|
|
11
|
-
import Mutate from "./mutate";
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* Actualiza automáticamente la marca temporal en cada asignación.
|
|
15
|
-
*/
|
|
16
|
-
export default function UpdatedAt(): PropertyDecorator {
|
|
17
|
-
return Mutate(() => new Date().toISOString());
|
|
18
|
-
}
|
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Dinamite ORM — @Validate
|
|
3
|
-
* ------------------------
|
|
4
|
-
* Registra validadores y crea virtual si falta.
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
import { Column, STORE, ensureColumn, ensureConfig } from "../core/wrapper";
|
|
8
|
-
import { toSnakePlural } from "../utils/naming";
|
|
9
|
-
|
|
10
|
-
export default function Validate(
|
|
11
|
-
validators:
|
|
12
|
-
| ((v: unknown) => true | string)
|
|
13
|
-
| ((v: unknown) => true | string)[]
|
|
14
|
-
): PropertyDecorator {
|
|
15
|
-
const list = Array.isArray(validators) ? validators : [validators];
|
|
16
|
-
if (!list.length || list.some((v) => typeof v !== "function")) {
|
|
17
|
-
throw new TypeError("@Validate requiere funciones");
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
return (target: object, prop: string | symbol): void => {
|
|
21
|
-
const ctor = (target as any).constructor;
|
|
22
|
-
const entry = ensureConfig(ctor, toSnakePlural(ctor.name));
|
|
23
|
-
const col = ensureColumn(entry, prop, String(prop));
|
|
24
|
-
|
|
25
|
-
col.validate ??= [];
|
|
26
|
-
col.validate.push(...list);
|
|
27
|
-
|
|
28
|
-
if (!Object.getOwnPropertyDescriptor(ctor.prototype, prop)?.set) {
|
|
29
|
-
defineVirtual(ctor.prototype, col, prop);
|
|
30
|
-
}
|
|
31
|
-
};
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
/* ------------------------------------------------------------------ */
|
|
35
|
-
function defineVirtual(proto: any, col: Column, prop: string | symbol): void {
|
|
36
|
-
Object.defineProperty(proto, prop, {
|
|
37
|
-
get() {
|
|
38
|
-
return (this[STORE] ?? {})[prop];
|
|
39
|
-
},
|
|
40
|
-
set(val: unknown) {
|
|
41
|
-
const buf = (this[STORE] ??= {});
|
|
42
|
-
|
|
43
|
-
if (val === undefined && col.default !== undefined) {
|
|
44
|
-
val = typeof col.default === "function" ? col.default() : col.default;
|
|
45
|
-
}
|
|
46
|
-
if (col.mutate) for (const m of col.mutate) val = m(val);
|
|
47
|
-
if (col.validate) {
|
|
48
|
-
for (const v of col.validate) {
|
|
49
|
-
const r = v(val);
|
|
50
|
-
if (r !== true)
|
|
51
|
-
throw new Error(typeof r === "string" ? r : "Validación fallida");
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
buf[prop] = val;
|
|
55
|
-
},
|
|
56
|
-
enumerable: true,
|
|
57
|
-
configurable: true,
|
|
58
|
-
});
|
|
59
|
-
}
|
package/src/index.ts
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
export { connect, default as Table } from "./core/table";
|
|
2
|
-
|
|
3
|
-
// Decoradores
|
|
4
|
-
export { default as Default } from "./decorators/default";
|
|
5
|
-
export { default as Index } from "./decorators/index";
|
|
6
|
-
export { default as IndexSort } from "./decorators/index_sort";
|
|
7
|
-
export { default as Mutate } from "./decorators/mutate";
|
|
8
|
-
export { default as Name } from "./decorators/name";
|
|
9
|
-
export { default as Validate } from "./decorators/validate";
|
|
10
|
-
|
|
11
|
-
export { default as CreatedAt } from "./decorators/created_at";
|
|
12
|
-
export { default as NotNull } from "./decorators/not_null";
|
|
13
|
-
export { default as PrimaryKey } from "./decorators/primary_key";
|
|
14
|
-
export { default as UpdatedAt } from "./decorators/updated_at";
|
package/src/utils/naming.ts
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
/* src/utils/naming.ts
|
|
2
|
-
* -------------------------------------------------
|
|
3
|
-
* Convierte Camel/Pascal → snake_case y pluraliza.
|
|
4
|
-
* Se importa allí donde se necesite.
|
|
5
|
-
*/
|
|
6
|
-
import pluralize from "pluralize";
|
|
7
|
-
|
|
8
|
-
export function toSnakePlural(input: string): string {
|
|
9
|
-
// camelCase / PascalCase → snake_case
|
|
10
|
-
const snake = input.replace(/([a-z0-9])([A-Z])/g, "$1_$2").toLowerCase();
|
|
11
|
-
return pluralize(snake); // “user” → “users”, “status” → “statuses”…
|
|
12
|
-
}
|