@arcaelas/dynamite 1.0.0 → 1.0.1
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/__tests__/crud.spec.d.ts +1 -0
- package/build/__tests__/crud.spec.js +123 -0
- package/build/__tests__/crud.spec.js.map +1 -0
- package/build/__tests__/decorators.spec.d.ts +1 -0
- package/build/__tests__/decorators.spec.js +183 -0
- package/build/__tests__/decorators.spec.js.map +1 -0
- package/build/__tests__/instance-crud.spec.d.ts +1 -0
- package/build/__tests__/instance-crud.spec.js +82 -0
- package/build/__tests__/instance-crud.spec.js.map +1 -0
- package/build/index.js +2 -0
- package/build/index.js.map +7 -0
- package/build/src/core/table.d.ts +17 -0
- package/build/src/core/table.js +223 -0
- package/build/src/core/table.js.map +1 -0
- package/build/src/core/wrapper.d.ts +47 -0
- package/build/src/core/wrapper.js +57 -0
- package/build/src/core/wrapper.js.map +1 -0
- package/build/src/decorators/created_at.d.ts +4 -0
- package/build/src/decorators/created_at.js +22 -0
- package/build/src/decorators/created_at.js.map +1 -0
- package/build/src/decorators/default.d.ts +1 -0
- package/build/src/decorators/default.js +55 -0
- package/build/src/decorators/default.js.map +1 -0
- package/build/src/decorators/index.d.ts +1 -0
- package/build/src/decorators/index.js +24 -0
- package/build/src/decorators/index.js.map +1 -0
- package/build/src/decorators/index_sort.d.ts +1 -0
- package/build/src/decorators/index_sort.js +27 -0
- package/build/src/decorators/index_sort.js.map +1 -0
- package/build/src/decorators/mutate.d.ts +2 -0
- package/build/src/decorators/mutate.js +53 -0
- package/build/src/decorators/mutate.js.map +1 -0
- package/build/src/decorators/name.d.ts +1 -0
- package/build/src/decorators/name.js +41 -0
- package/build/src/decorators/name.js.map +1 -0
- package/build/src/decorators/not_null.d.ts +4 -0
- package/build/src/decorators/not_null.js +28 -0
- package/build/src/decorators/not_null.js.map +1 -0
- package/build/src/decorators/primary_key.d.ts +7 -0
- package/build/src/decorators/primary_key.js +30 -0
- package/build/src/decorators/primary_key.js.map +1 -0
- package/build/src/decorators/updated_at.d.ts +4 -0
- package/build/src/decorators/updated_at.js +23 -0
- package/build/src/decorators/updated_at.js.map +1 -0
- package/build/src/decorators/validate.d.ts +1 -0
- package/build/src/decorators/validate.js +54 -0
- package/build/src/decorators/validate.js.map +1 -0
- package/{src/index.ts → build/src/index.d.ts} +0 -3
- package/build/src/index.js +31 -0
- package/build/src/index.js.map +1 -0
- package/build/src/utils/naming.d.ts +1 -0
- package/build/src/utils/naming.js +18 -0
- package/build/src/utils/naming.js.map +1 -0
- package/build/tests/crud.spec.d.ts +1 -0
- package/build/tests/crud.spec.js +123 -0
- package/build/tests/crud.spec.js.map +1 -0
- package/build/tests/decorators.spec.d.ts +1 -0
- package/build/tests/decorators.spec.js +183 -0
- package/build/tests/decorators.spec.js.map +1 -0
- package/build/tests/instance-crud.spec.d.ts +1 -0
- package/build/tests/instance-crud.spec.js +82 -0
- package/build/tests/instance-crud.spec.js.map +1 -0
- package/package.json +35 -11
- 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/utils/naming.ts +0 -12
|
@@ -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/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
|
-
}
|