@arcaelas/dynamite 1.0.18 → 1.0.23

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 (34) hide show
  1. package/package.json +11 -42
  2. package/src/scripts/load_seed.d.ts +5 -0
  3. package/src/scripts/load_seed.js +54 -0
  4. package/src/src/@types/index.d.ts +188 -0
  5. package/src/src/@types/index.js +9 -0
  6. package/src/{core → src/core}/client.d.ts +4 -16
  7. package/src/{core → src/core}/client.js +115 -38
  8. package/src/{core → src/core}/decorator.d.ts +0 -15
  9. package/src/{core → src/core}/decorator.js +5 -35
  10. package/src/src/core/table.d.ts +81 -0
  11. package/src/src/core/table.js +892 -0
  12. package/src/{decorators → src/decorators}/indexes.d.ts +1 -1
  13. package/src/{decorators → src/decorators}/indexes.js +12 -20
  14. package/src/{decorators → src/decorators}/relations.d.ts +20 -1
  15. package/src/{decorators → src/decorators}/relations.js +32 -2
  16. package/src/{decorators → src/decorators}/timestamps.d.ts +4 -4
  17. package/src/{decorators → src/decorators}/timestamps.js +11 -6
  18. package/src/{decorators → src/decorators}/transforms.d.ts +17 -4
  19. package/src/{decorators → src/decorators}/transforms.js +40 -28
  20. package/src/{index.d.ts → src/index.d.ts} +4 -4
  21. package/src/{index.js → src/index.js} +3 -2
  22. package/src/src/index.test.d.ts +6 -0
  23. package/src/src/index.test.js +789 -0
  24. package/src/{utils → src/utils}/relations.d.ts +5 -3
  25. package/src/src/utils/relations.js +216 -0
  26. package/src/@types/index.d.ts +0 -102
  27. package/src/@types/index.js +0 -9
  28. package/src/core/method.d.ts +0 -73
  29. package/src/core/method.js +0 -140
  30. package/src/core/table.d.ts +0 -56
  31. package/src/core/table.js +0 -659
  32. package/src/index.test.d.ts +0 -13
  33. package/src/index.test.js +0 -1992
  34. package/src/utils/relations.js +0 -141
@@ -0,0 +1,81 @@
1
+ import type { InferAttributes, QueryOperator, WhereOptions } from "../@types/index";
2
+ import { TransactionContext } from "./client";
3
+ import { SCHEMA } from "./decorator";
4
+ type SimpleWhereOptions<M> = {
5
+ order?: "ASC" | "DESC" | {
6
+ [key: string]: "ASC" | "DESC";
7
+ };
8
+ offset?: number;
9
+ skip?: number;
10
+ limit?: number;
11
+ attributes?: (keyof InferAttributes<M>)[];
12
+ include?: NonNullable<WhereOptions<M>["include"]>;
13
+ _includeTrashed?: boolean;
14
+ };
15
+ type Noop = (...args: any) => any;
16
+ interface Schema {
17
+ name: string;
18
+ primary_key: string;
19
+ columns: {
20
+ [K: string]: {
21
+ get: Noop;
22
+ set: Noop;
23
+ store: {
24
+ [K: string]: any;
25
+ relation: {
26
+ type: "HasMany" | "HasOne" | "BelognsTo" | "ManyToMany";
27
+ local: string;
28
+ foreign: string;
29
+ pivot?: string;
30
+ };
31
+ };
32
+ };
33
+ };
34
+ }
35
+ export default class Table<T = any> {
36
+ static [SCHEMA]: Schema;
37
+ private readonly _relationCache;
38
+ constructor(props?: Partial<T>);
39
+ toJSON(): Record<string, unknown>;
40
+ /**
41
+ * @description Mapea nombres de propiedades TypeScript a nombres de columnas de DB
42
+ * @param data Objeto con propiedades TypeScript
43
+ * @returns Objeto con nombres de columnas de DB
44
+ */
45
+ private _mapPropertiesToDB;
46
+ /**
47
+ * @description Mapea nombres de columnas de DB a nombres de propiedades TypeScript
48
+ * @param data Objeto con nombres de columnas de DB
49
+ * @returns Objeto con propiedades TypeScript
50
+ */
51
+ private static _mapDBToProperties;
52
+ /**
53
+ * @description Convierte la instancia a un payload listo para DynamoDB
54
+ * @returns Objeto con nombres de columnas de DB y valores apropiados
55
+ */
56
+ private _toDBPayload;
57
+ toString(): string;
58
+ save(): Promise<boolean>;
59
+ update(data: Partial<InferAttributes<T>>): Promise<boolean>;
60
+ destroy(): Promise<null>;
61
+ forceDestroy(): Promise<null>;
62
+ attach<R>(RelatedModel: new () => R, related_id: string, pivot_data?: Record<string, any>): Promise<void>;
63
+ detach<R>(RelatedModel: new () => R, related_id: string): Promise<void>;
64
+ /**
65
+ * Sincronizar relación ManyToMany reemplazando todas las relaciones existentes
66
+ * @param RelatedModel Modelo relacionado
67
+ * @param related_ids Array de IDs a sincronizar
68
+ */
69
+ sync<R>(RelatedModel: new () => R, related_ids: string[]): Promise<void>;
70
+ static create<M extends Table>(this: new (data: any) => M, data: Partial<InferAttributes<M>>, tx?: TransactionContext): Promise<M>;
71
+ static update<M extends Table>(this: new (data: any) => M, updates: Partial<InferAttributes<M>>, filters: Partial<InferAttributes<M>>, tx?: TransactionContext): Promise<number>;
72
+ static delete<M extends Table>(this: new (data: any) => M, filters: Partial<InferAttributes<M>>, tx?: TransactionContext): Promise<number>;
73
+ static where<M extends Table>(this: new (props?: any) => M, key: keyof InferAttributes<M>, value: any, options?: SimpleWhereOptions<M>): Promise<M[]>;
74
+ static where<M extends Table>(this: new (props?: any) => M, key: keyof InferAttributes<M>, operator: QueryOperator, value: any, options?: SimpleWhereOptions<M>): Promise<M[]>;
75
+ static where<M extends Table>(this: new (props?: any) => M, query: object, options?: SimpleWhereOptions<M>): Promise<M[]>;
76
+ static first<M extends Table>(this: new (props?: any) => M, field_or_filters: any, operator_or_value?: any, value_or_options?: any): Promise<M | undefined>;
77
+ static last<M extends Table>(this: new (props?: any) => M, field_or_filters?: any, operator_or_value?: any): Promise<M | undefined>;
78
+ static withTrashed<M extends Table>(this: new (props?: any) => M, filters?: any, options?: WhereOptions<M>): Promise<M[]>;
79
+ static onlyTrashed<M extends Table>(this: new (props?: any) => M, filters?: any, options?: WhereOptions<M>): Promise<M[]>;
80
+ }
81
+ export {};